Skip to content

Commit

Permalink
relase: launch release 4.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lucianopf committed Dec 15, 2022
1 parent ba34948 commit 52d3bc7
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 34 deletions.
74 changes: 62 additions & 12 deletions dist/cep-promise-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,55 @@
throw serviceError;
}

function fetchCorreiosAltAPIService(cepWithLeftPad, configurations) {
var url = 'https://buscacepinter.correios.com.br/app/cep/carrega-cep.php';
var options = {
method: 'POST',
mode: 'cors',
headers: {
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'
},
body: "cep=".concat(cepWithLeftPad),
timeout: configurations.timeout || 30000
};
return fetch(url, options).then(parseResponse).then(extractCepValuesFromResponse)["catch"](throwApplicationError$1);
}

function parseResponse(response) {
return response.json().then(function (result) {
if (result.total === 0 || result.erro || result.dados[0].cep === "") {
throw new Error('CEP não encontrado na base dos Correios.');
}

return result;
});
}

function extractCepValuesFromResponse(response) {
var firstCep = response.dados[0];
return {
cep: firstCep.cep,
state: firstCep.uf,
city: firstCep.localidade,
neighborhood: firstCep.bairro,
street: firstCep.logradouroDNEC,
service: 'correios-alt'
};
}

function throwApplicationError$1(error) {
var serviceError = new ServiceError({
message: error.message,
service: 'correios-alt'
});

if (error.name === 'FetchError') {
serviceError.message = 'Erro ao se conectar com o serviço dos Correios Alt.';
}

throw serviceError;
}

function fetchViaCepService(cepWithLeftPad, configurations) {
var url = "https://viacep.com.br/ws/".concat(cepWithLeftPad, "/json/");
var options = {
Expand All @@ -449,7 +498,7 @@
options.headers['user-agent'] = 'cep-promise';
}

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

function analyzeAndParseResponse$1(response) {
Expand All @@ -468,7 +517,7 @@
return responseObject;
}

function extractCepValuesFromResponse(responseObject) {
function extractCepValuesFromResponse$1(responseObject) {
return {
cep: responseObject.cep.replace('-', ''),
state: responseObject.uf,
Expand All @@ -479,7 +528,7 @@
};
}

function throwApplicationError$1(error) {
function throwApplicationError$2(error) {
var serviceError = new ServiceError({
message: error.message,
service: 'viacep'
Expand All @@ -502,7 +551,7 @@
},
timeout: configurations.timeout || 30000
};
return fetch(url, options).then(analyzeAndParseResponse$2).then(checkForWideNetError).then(extractCepValuesFromResponse$1)["catch"](throwApplicationError$2);
return fetch(url, options).then(analyzeAndParseResponse$2).then(checkForWideNetError).then(extractCepValuesFromResponse$2)["catch"](throwApplicationError$3);
}

function analyzeAndParseResponse$2(response) {
Expand All @@ -521,7 +570,7 @@
return object;
}

function extractCepValuesFromResponse$1(object) {
function extractCepValuesFromResponse$2(object) {
return {
cep: object.code.replace('-', ''),
state: object.state,
Expand All @@ -532,7 +581,7 @@
};
}

function throwApplicationError$2(error) {
function throwApplicationError$3(error) {
var serviceError = new ServiceError({
message: error.message,
service: 'widenet'
Expand All @@ -555,18 +604,18 @@
},
timeout: configurations.timeout || 30000
};
return fetch(url, options).then(parseResponse).then(extractCepValuesFromResponse$2)["catch"](throwApplicationError$3);
return fetch(url, options).then(parseResponse$1).then(extractCepValuesFromResponse$3)["catch"](throwApplicationError$4);
}

function parseResponse(response) {
function parseResponse$1(response) {
if (response.ok === false || response.status !== 200) {
throw new Error('CEP não encontrado na base do BrasilAPI.');
}

return response.json();
}

function extractCepValuesFromResponse$2(response) {
function extractCepValuesFromResponse$3(response) {
return {
cep: response.cep,
state: response.state,
Expand All @@ -577,7 +626,7 @@
};
}

function throwApplicationError$3(error) {
function throwApplicationError$4(error) {
var serviceError = new ServiceError({
message: error.message,
service: 'brasilapi'
Expand All @@ -603,6 +652,7 @@

return {
correios: fetchCorreiosService,
'correios-alt': fetchCorreiosAltAPIService,
viacep: fetchViaCepService,
widenet: fetchWideNetService,
brasilapi: fetchBrasilAPIService
Expand Down Expand Up @@ -630,7 +680,7 @@
return cepRawValue;
}).then(removeSpecialCharacters).then(validateInputLength).then(leftPadWithZeros).then(function (cepWithLeftPad) {
return fetchCepFromServices(cepWithLeftPad, configurations);
})["catch"](handleServicesError)["catch"](throwApplicationError$4);
})["catch"](handleServicesError)["catch"](throwApplicationError$5);
}

function validateProviders(providers) {
Expand Down Expand Up @@ -738,7 +788,7 @@
throw aggregatedErrors;
}

function throwApplicationError$4(_ref) {
function throwApplicationError$5(_ref) {
var message = _ref.message,
type = _ref.type,
errors = _ref.errors;
Expand Down
2 changes: 1 addition & 1 deletion dist/cep-promise-browser.min.js

Large diffs are not rendered by default.

74 changes: 62 additions & 12 deletions dist/cep-promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,55 @@
throw serviceError;
}

function fetchCorreiosAltAPIService(cepWithLeftPad, configurations) {
var url = 'https://buscacepinter.correios.com.br/app/cep/carrega-cep.php';
var options = {
method: 'POST',
mode: 'cors',
headers: {
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'
},
body: "cep=".concat(cepWithLeftPad),
timeout: configurations.timeout || 30000
};
return fetch(url, options).then(parseResponse).then(extractCepValuesFromResponse)["catch"](throwApplicationError$1);
}

function parseResponse(response) {
return response.json().then(function (result) {
if (result.total === 0 || result.erro || result.dados[0].cep === "") {
throw new Error('CEP não encontrado na base dos Correios.');
}

return result;
});
}

function extractCepValuesFromResponse(response) {
var firstCep = response.dados[0];
return {
cep: firstCep.cep,
state: firstCep.uf,
city: firstCep.localidade,
neighborhood: firstCep.bairro,
street: firstCep.logradouroDNEC,
service: 'correios-alt'
};
}

function throwApplicationError$1(error) {
var serviceError = new ServiceError({
message: error.message,
service: 'correios-alt'
});

if (error.name === 'FetchError') {
serviceError.message = 'Erro ao se conectar com o serviço dos Correios Alt.';
}

throw serviceError;
}

function fetchViaCepService(cepWithLeftPad, configurations) {
var url = "https://viacep.com.br/ws/".concat(cepWithLeftPad, "/json/");
var options = {
Expand All @@ -400,7 +449,7 @@
options.headers['user-agent'] = 'cep-promise';
}

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

function analyzeAndParseResponse$1(response) {
Expand All @@ -419,7 +468,7 @@
return responseObject;
}

function extractCepValuesFromResponse(responseObject) {
function extractCepValuesFromResponse$1(responseObject) {
return {
cep: responseObject.cep.replace('-', ''),
state: responseObject.uf,
Expand All @@ -430,7 +479,7 @@
};
}

function throwApplicationError$1(error) {
function throwApplicationError$2(error) {
var serviceError = new ServiceError({
message: error.message,
service: 'viacep'
Expand All @@ -453,7 +502,7 @@
},
timeout: configurations.timeout || 30000
};
return fetch(url, options).then(analyzeAndParseResponse$2).then(checkForWideNetError).then(extractCepValuesFromResponse$1)["catch"](throwApplicationError$2);
return fetch(url, options).then(analyzeAndParseResponse$2).then(checkForWideNetError).then(extractCepValuesFromResponse$2)["catch"](throwApplicationError$3);
}

function analyzeAndParseResponse$2(response) {
Expand All @@ -472,7 +521,7 @@
return object;
}

function extractCepValuesFromResponse$1(object) {
function extractCepValuesFromResponse$2(object) {
return {
cep: object.code.replace('-', ''),
state: object.state,
Expand All @@ -483,7 +532,7 @@
};
}

function throwApplicationError$2(error) {
function throwApplicationError$3(error) {
var serviceError = new ServiceError({
message: error.message,
service: 'widenet'
Expand All @@ -506,18 +555,18 @@
},
timeout: configurations.timeout || 30000
};
return fetch(url, options).then(parseResponse).then(extractCepValuesFromResponse$2)["catch"](throwApplicationError$3);
return fetch(url, options).then(parseResponse$1).then(extractCepValuesFromResponse$3)["catch"](throwApplicationError$4);
}

function parseResponse(response) {
function parseResponse$1(response) {
if (response.ok === false || response.status !== 200) {
throw new Error('CEP não encontrado na base do BrasilAPI.');
}

return response.json();
}

function extractCepValuesFromResponse$2(response) {
function extractCepValuesFromResponse$3(response) {
return {
cep: response.cep,
state: response.state,
Expand All @@ -528,7 +577,7 @@
};
}

function throwApplicationError$3(error) {
function throwApplicationError$4(error) {
var serviceError = new ServiceError({
message: error.message,
service: 'brasilapi'
Expand All @@ -554,6 +603,7 @@

return {
correios: fetchCorreiosService,
'correios-alt': fetchCorreiosAltAPIService,
viacep: fetchViaCepService,
widenet: fetchWideNetService,
brasilapi: fetchBrasilAPIService
Expand Down Expand Up @@ -581,7 +631,7 @@
return cepRawValue;
}).then(removeSpecialCharacters).then(validateInputLength).then(leftPadWithZeros).then(function (cepWithLeftPad) {
return fetchCepFromServices(cepWithLeftPad, configurations);
})["catch"](handleServicesError)["catch"](throwApplicationError$4);
})["catch"](handleServicesError)["catch"](throwApplicationError$5);
}

function validateProviders(providers) {
Expand Down Expand Up @@ -689,7 +739,7 @@
throw aggregatedErrors;
}

function throwApplicationError$4(_ref) {
function throwApplicationError$5(_ref) {
var message = _ref.message,
type = _ref.type,
errors = _ref.errors;
Expand Down
Loading

0 comments on commit 52d3bc7

Please sign in to comment.