@@ -78,7 +78,7 @@ var index = typeof fetch == 'function' ? fetch.bind() : function (url, options)
7878 return new Promise ( function ( resolve , reject ) {
7979 var request = new XMLHttpRequest ( ) ;
8080
81- request . open ( options . method || 'get' , url ) ;
81+ request . open ( options . method || 'get' , url , true ) ;
8282
8383 for ( var i in options . headers ) {
8484 request . setRequestHeader ( i , options . headers [ i ] ) ;
@@ -92,23 +92,23 @@ var index = typeof fetch == 'function' ? fetch.bind() : function (url, options)
9292
9393 request . onerror = reject ;
9494
95- request . send ( options . body ) ;
95+ request . send ( options . body || null ) ;
9696
9797 function response ( ) {
9898 var _keys = [ ] ,
9999 all = [ ] ,
100100 headers = { } ,
101101 header ;
102102
103- request . getAllResponseHeaders ( ) . replace ( / ^ ( .* ?) : \s * ( [ \s \S ] * ?) $ / gm, function ( m , key , value ) {
103+ request . getAllResponseHeaders ( ) . replace ( / ^ ( .* ?) : [ ^ \S \n ] * ( [ \s \S ] * ?) $ / gm, function ( m , key , value ) {
104104 _keys . push ( key = key . toLowerCase ( ) ) ;
105105 all . push ( [ key , value ] ) ;
106106 header = headers [ key ] ;
107107 headers [ key ] = header ? header + "," + value : value ;
108108 } ) ;
109109
110110 return {
111- ok : ( request . status / 200 | 0 ) == 1 , // 200-299
111+ ok : ( request . status / 100 | 0 ) == 2 , // 200-299
112112 status : request . status ,
113113 statusText : request . statusText ,
114114 url : request . responseURL ,
@@ -358,15 +358,20 @@ function throwApplicationError$2(error) {
358358 throw serviceError ;
359359}
360360
361+ /* istanbul ignore next */
362+ function isBrowser ( ) {
363+ return typeof window !== 'undefined' ;
364+ }
365+
361366/* istanbul ignore next */
362367function injectProxy ( Service ) {
363368 return function ( cepWithLeftPad ) {
364369 return Service ( cepWithLeftPad , PROXY_URL ) ;
365370 } ;
366371}
367372
368- var CepAbertoService = typeof process === 'undefined' ? injectProxy ( fetchCepAbertoService ) : fetchCepAbertoService ;
369- var CorreiosService = typeof process === 'undefined' ? injectProxy ( fetchCorreiosService ) : fetchCorreiosService ;
373+ var CepAbertoService = isBrowser ( ) ? injectProxy ( fetchCepAbertoService ) : fetchCepAbertoService ;
374+ var CorreiosService = isBrowser ( ) ? injectProxy ( fetchCorreiosService ) : fetchCorreiosService ;
370375var ViaCepService = fetchViaCepService ;
371376
372377var reverse = function reverse ( promise ) {
0 commit comments