Skip to content

Commit

Permalink
Merge pull request #2 from stone-ton/release/4.3.3
Browse files Browse the repository at this point in the history
Release/4.3.3
  • Loading branch information
ericksprengel authored Nov 22, 2023
2 parents 455e93b + 7e66c10 commit 220cdaf
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 18 deletions.
12 changes: 9 additions & 3 deletions dist/cep-promise-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@
return CepPromiseError;
}( /*#__PURE__*/_wrapNativeSuper(Error));

function fetch (e, n) {
function fetchDefault (e, n) {
return n = n || {}, new Promise(function (t, r) {
var s = new XMLHttpRequest(),
o = [],
Expand Down Expand Up @@ -362,6 +362,7 @@
},
timeout: configurations.timeout || 30000
};
var fetch = configurations.fetch || fetchDefault;
return fetch(url, options).then(analyzeAndParseResponse)["catch"](throwApplicationError);
}

Expand Down Expand Up @@ -445,6 +446,7 @@
body: "cep=".concat(cepWithLeftPad),
timeout: configurations.timeout || 30000
};
var fetch = configurations.fetch || fetchDefault;
return fetch(url, options).then(parseResponse).then(extractCepValuesFromResponse)["catch"](throwApplicationError$1);
}

Expand Down Expand Up @@ -498,6 +500,7 @@
options.headers['user-agent'] = 'cep-promise';
}

var fetch = configurations.fetch || fetchDefault;
return fetch(url, options).then(analyzeAndParseResponse$1).then(checkForViaCepError).then(extractCepValuesFromResponse$1)["catch"](throwApplicationError$2);
}

Expand Down Expand Up @@ -542,15 +545,17 @@
}

function fetchWideNetService(cepWithLeftPad, configurations) {
var url = "https://ws.apicep.com/busca-cep/api/cep/".concat(cepWithLeftPad, ".json");
var cepWithDash = "".concat(cepWithLeftPad.slice(0, 5), "-").concat(cepWithLeftPad.slice(5));
var url = "https://cdn.apicep.com/file/apicep/".concat(cepWithDash, ".json");
var options = {
method: 'GET',
mode: 'cors',
headers: {
'content-type': 'application/json;charset=utf-8'
accept: 'application/json'
},
timeout: configurations.timeout || 30000
};
var fetch = configurations.fetch || fetchDefault;
return fetch(url, options).then(analyzeAndParseResponse$2).then(checkForWideNetError).then(extractCepValuesFromResponse$2)["catch"](throwApplicationError$3);
}

Expand Down Expand Up @@ -604,6 +609,7 @@
},
timeout: configurations.timeout || 30000
};
var fetch = configurations.fetch || fetchDefault;
return fetch(url, options).then(parseResponse$1).then(extractCepValuesFromResponse$3)["catch"](throwApplicationError$4);
}

Expand Down
2 changes: 1 addition & 1 deletion dist/cep-promise-browser.min.js

Large diffs are not rendered by default.

16 changes: 11 additions & 5 deletions dist/cep-promise.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('node-fetch')) :
typeof define === 'function' && define.amd ? define(['node-fetch'], factory) :
(global = global || self, global.cep = factory(global.fetch));
}(this, (function (fetch) { 'use strict';
(global = global || self, global.cep = factory(global.fetchDefault));
}(this, (function (fetchDefault) { 'use strict';

fetch = fetch && Object.prototype.hasOwnProperty.call(fetch, 'default') ? fetch['default'] : fetch;
fetchDefault = fetchDefault && Object.prototype.hasOwnProperty.call(fetchDefault, 'default') ? fetchDefault['default'] : fetchDefault;

function _typeof(obj) {
"@babel/helpers - typeof";
Expand Down Expand Up @@ -313,6 +313,7 @@
},
timeout: configurations.timeout || 30000
};
var fetch = configurations.fetch || fetchDefault;
return fetch(url, options).then(analyzeAndParseResponse)["catch"](throwApplicationError);
}

Expand Down Expand Up @@ -396,6 +397,7 @@
body: "cep=".concat(cepWithLeftPad),
timeout: configurations.timeout || 30000
};
var fetch = configurations.fetch || fetchDefault;
return fetch(url, options).then(parseResponse).then(extractCepValuesFromResponse)["catch"](throwApplicationError$1);
}

Expand Down Expand Up @@ -449,6 +451,7 @@
options.headers['user-agent'] = 'cep-promise';
}

var fetch = configurations.fetch || fetchDefault;
return fetch(url, options).then(analyzeAndParseResponse$1).then(checkForViaCepError).then(extractCepValuesFromResponse$1)["catch"](throwApplicationError$2);
}

Expand Down Expand Up @@ -493,15 +496,17 @@
}

function fetchWideNetService(cepWithLeftPad, configurations) {
var url = "https://ws.apicep.com/busca-cep/api/cep/".concat(cepWithLeftPad, ".json");
var cepWithDash = "".concat(cepWithLeftPad.slice(0, 5), "-").concat(cepWithLeftPad.slice(5));
var url = "https://cdn.apicep.com/file/apicep/".concat(cepWithDash, ".json");
var options = {
method: 'GET',
mode: 'cors',
headers: {
'content-type': 'application/json;charset=utf-8'
accept: 'application/json'
},
timeout: configurations.timeout || 30000
};
var fetch = configurations.fetch || fetchDefault;
return fetch(url, options).then(analyzeAndParseResponse$2).then(checkForWideNetError).then(extractCepValuesFromResponse$2)["catch"](throwApplicationError$3);
}

Expand Down Expand Up @@ -555,6 +560,7 @@
},
timeout: configurations.timeout || 30000
};
var fetch = configurations.fetch || fetchDefault;
return fetch(url, options).then(parseResponse$1).then(extractCepValuesFromResponse$3)["catch"](throwApplicationError$4);
}

Expand Down
2 changes: 1 addition & 1 deletion dist/cep-promise.min.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ declare module 'cep-promise' {

export interface Configurations {
providers?: AvailableProviders[],
timeout?: number
timeout?: number,
fetch: (url: RequestInfo, init?: RequestInit) => Promise<Response>,
}

export function cep(cep: string | number, configurations?: Configurations): Promise<CEP>
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cep-promise",
"version": "4.3.0",
"version": "4.3.3",
"description": "Busca por CEP integrado diretamente aos serviços dos Correios e ViaCEP",
"main": "dist/cep-promise.min.js",
"module": "dist/cep-promise.min.js",
Expand Down
4 changes: 3 additions & 1 deletion src/services/brasilapi.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

import fetch from 'node-fetch'
import fetchDefault from 'node-fetch'
import ServiceError from '../errors/service.js'

export default function fetchBrasilAPIService (cepWithLeftPad, configurations) {
Expand All @@ -14,6 +14,8 @@ export default function fetchBrasilAPIService (cepWithLeftPad, configurations) {
timeout: configurations.timeout || 30000
}

const fetch = configurations.fetch || fetchDefault

return fetch(url, options)
.then(parseResponse)
.then(extractCepValuesFromResponse)
Expand Down
4 changes: 3 additions & 1 deletion src/services/correios-alt.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

import fetch from 'node-fetch'
import fetchDefault from 'node-fetch'
import ServiceError from '../errors/service.js'

export default function fetchCorreiosAltAPIService(
Expand All @@ -18,6 +18,8 @@ export default function fetchCorreiosAltAPIService(
timeout: configurations.timeout || 30000
}

const fetch = configurations.fetch || fetchDefault

return fetch(url, options)
.then(parseResponse)
.then(extractCepValuesFromResponse)
Expand Down
4 changes: 3 additions & 1 deletion src/services/correios.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

import fetch from 'node-fetch'
import fetchDefault from 'node-fetch'
import ServiceError from '../errors/service.js'

export default function fetchCorreiosService (cepWithLeftPad, configurations) {
Expand All @@ -15,6 +15,8 @@ export default function fetchCorreiosService (cepWithLeftPad, configurations) {
timeout: configurations.timeout || 30000
}

const fetch = configurations.fetch || fetchDefault

return fetch(url, options)
.then(analyzeAndParseResponse)
.catch(throwApplicationError)
Expand Down
4 changes: 3 additions & 1 deletion src/services/viacep.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

import fetch from 'node-fetch'
import fetchDefault from 'node-fetch'
import ServiceError from '../errors/service.js'

export default function fetchViaCepService (cepWithLeftPad, configurations) {
Expand All @@ -18,6 +18,8 @@ export default function fetchViaCepService (cepWithLeftPad, configurations) {
options.headers['user-agent'] = 'cep-promise'
}

const fetch = configurations.fetch || fetchDefault

return fetch(url, options)
.then(analyzeAndParseResponse)
.then(checkForViaCepError)
Expand Down
4 changes: 3 additions & 1 deletion src/services/widenet.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

import fetch from 'node-fetch'
import fetchDefault from 'node-fetch'
import ServiceError from '../errors/service.js'

export default function fetchWideNetService(cepWithLeftPad, configurations) {
Expand All @@ -15,6 +15,8 @@ export default function fetchWideNetService(cepWithLeftPad, configurations) {
timeout: configurations.timeout || 30000
}

const fetch = configurations.fetch || fetchDefault

return fetch(url, options)
.then(analyzeAndParseResponse)
.then(checkForWideNetError)
Expand Down

0 comments on commit 220cdaf

Please sign in to comment.