Skip to content

Commit 52d3bc7

Browse files
committed
relase: launch release 4.3.0
1 parent ba34948 commit 52d3bc7

6 files changed

+134
-34
lines changed

dist/cep-promise-browser.js

+62-12
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,55 @@
434434
throw serviceError;
435435
}
436436

437+
function fetchCorreiosAltAPIService(cepWithLeftPad, configurations) {
438+
var url = 'https://buscacepinter.correios.com.br/app/cep/carrega-cep.php';
439+
var options = {
440+
method: 'POST',
441+
mode: 'cors',
442+
headers: {
443+
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'
444+
},
445+
body: "cep=".concat(cepWithLeftPad),
446+
timeout: configurations.timeout || 30000
447+
};
448+
return fetch(url, options).then(parseResponse).then(extractCepValuesFromResponse)["catch"](throwApplicationError$1);
449+
}
450+
451+
function parseResponse(response) {
452+
return response.json().then(function (result) {
453+
if (result.total === 0 || result.erro || result.dados[0].cep === "") {
454+
throw new Error('CEP não encontrado na base dos Correios.');
455+
}
456+
457+
return result;
458+
});
459+
}
460+
461+
function extractCepValuesFromResponse(response) {
462+
var firstCep = response.dados[0];
463+
return {
464+
cep: firstCep.cep,
465+
state: firstCep.uf,
466+
city: firstCep.localidade,
467+
neighborhood: firstCep.bairro,
468+
street: firstCep.logradouroDNEC,
469+
service: 'correios-alt'
470+
};
471+
}
472+
473+
function throwApplicationError$1(error) {
474+
var serviceError = new ServiceError({
475+
message: error.message,
476+
service: 'correios-alt'
477+
});
478+
479+
if (error.name === 'FetchError') {
480+
serviceError.message = 'Erro ao se conectar com o serviço dos Correios Alt.';
481+
}
482+
483+
throw serviceError;
484+
}
485+
437486
function fetchViaCepService(cepWithLeftPad, configurations) {
438487
var url = "https://viacep.com.br/ws/".concat(cepWithLeftPad, "/json/");
439488
var options = {
@@ -449,7 +498,7 @@
449498
options.headers['user-agent'] = 'cep-promise';
450499
}
451500

452-
return fetch(url, options).then(analyzeAndParseResponse$1).then(checkForViaCepError).then(extractCepValuesFromResponse)["catch"](throwApplicationError$1);
501+
return fetch(url, options).then(analyzeAndParseResponse$1).then(checkForViaCepError).then(extractCepValuesFromResponse$1)["catch"](throwApplicationError$2);
453502
}
454503

455504
function analyzeAndParseResponse$1(response) {
@@ -468,7 +517,7 @@
468517
return responseObject;
469518
}
470519

471-
function extractCepValuesFromResponse(responseObject) {
520+
function extractCepValuesFromResponse$1(responseObject) {
472521
return {
473522
cep: responseObject.cep.replace('-', ''),
474523
state: responseObject.uf,
@@ -479,7 +528,7 @@
479528
};
480529
}
481530

482-
function throwApplicationError$1(error) {
531+
function throwApplicationError$2(error) {
483532
var serviceError = new ServiceError({
484533
message: error.message,
485534
service: 'viacep'
@@ -502,7 +551,7 @@
502551
},
503552
timeout: configurations.timeout || 30000
504553
};
505-
return fetch(url, options).then(analyzeAndParseResponse$2).then(checkForWideNetError).then(extractCepValuesFromResponse$1)["catch"](throwApplicationError$2);
554+
return fetch(url, options).then(analyzeAndParseResponse$2).then(checkForWideNetError).then(extractCepValuesFromResponse$2)["catch"](throwApplicationError$3);
506555
}
507556

508557
function analyzeAndParseResponse$2(response) {
@@ -521,7 +570,7 @@
521570
return object;
522571
}
523572

524-
function extractCepValuesFromResponse$1(object) {
573+
function extractCepValuesFromResponse$2(object) {
525574
return {
526575
cep: object.code.replace('-', ''),
527576
state: object.state,
@@ -532,7 +581,7 @@
532581
};
533582
}
534583

535-
function throwApplicationError$2(error) {
584+
function throwApplicationError$3(error) {
536585
var serviceError = new ServiceError({
537586
message: error.message,
538587
service: 'widenet'
@@ -555,18 +604,18 @@
555604
},
556605
timeout: configurations.timeout || 30000
557606
};
558-
return fetch(url, options).then(parseResponse).then(extractCepValuesFromResponse$2)["catch"](throwApplicationError$3);
607+
return fetch(url, options).then(parseResponse$1).then(extractCepValuesFromResponse$3)["catch"](throwApplicationError$4);
559608
}
560609

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

566615
return response.json();
567616
}
568617

569-
function extractCepValuesFromResponse$2(response) {
618+
function extractCepValuesFromResponse$3(response) {
570619
return {
571620
cep: response.cep,
572621
state: response.state,
@@ -577,7 +626,7 @@
577626
};
578627
}
579628

580-
function throwApplicationError$3(error) {
629+
function throwApplicationError$4(error) {
581630
var serviceError = new ServiceError({
582631
message: error.message,
583632
service: 'brasilapi'
@@ -603,6 +652,7 @@
603652

604653
return {
605654
correios: fetchCorreiosService,
655+
'correios-alt': fetchCorreiosAltAPIService,
606656
viacep: fetchViaCepService,
607657
widenet: fetchWideNetService,
608658
brasilapi: fetchBrasilAPIService
@@ -630,7 +680,7 @@
630680
return cepRawValue;
631681
}).then(removeSpecialCharacters).then(validateInputLength).then(leftPadWithZeros).then(function (cepWithLeftPad) {
632682
return fetchCepFromServices(cepWithLeftPad, configurations);
633-
})["catch"](handleServicesError)["catch"](throwApplicationError$4);
683+
})["catch"](handleServicesError)["catch"](throwApplicationError$5);
634684
}
635685

636686
function validateProviders(providers) {
@@ -738,7 +788,7 @@
738788
throw aggregatedErrors;
739789
}
740790

741-
function throwApplicationError$4(_ref) {
791+
function throwApplicationError$5(_ref) {
742792
var message = _ref.message,
743793
type = _ref.type,
744794
errors = _ref.errors;

dist/cep-promise-browser.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/cep-promise.js

+62-12
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,55 @@
385385
throw serviceError;
386386
}
387387

388+
function fetchCorreiosAltAPIService(cepWithLeftPad, configurations) {
389+
var url = 'https://buscacepinter.correios.com.br/app/cep/carrega-cep.php';
390+
var options = {
391+
method: 'POST',
392+
mode: 'cors',
393+
headers: {
394+
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'
395+
},
396+
body: "cep=".concat(cepWithLeftPad),
397+
timeout: configurations.timeout || 30000
398+
};
399+
return fetch(url, options).then(parseResponse).then(extractCepValuesFromResponse)["catch"](throwApplicationError$1);
400+
}
401+
402+
function parseResponse(response) {
403+
return response.json().then(function (result) {
404+
if (result.total === 0 || result.erro || result.dados[0].cep === "") {
405+
throw new Error('CEP não encontrado na base dos Correios.');
406+
}
407+
408+
return result;
409+
});
410+
}
411+
412+
function extractCepValuesFromResponse(response) {
413+
var firstCep = response.dados[0];
414+
return {
415+
cep: firstCep.cep,
416+
state: firstCep.uf,
417+
city: firstCep.localidade,
418+
neighborhood: firstCep.bairro,
419+
street: firstCep.logradouroDNEC,
420+
service: 'correios-alt'
421+
};
422+
}
423+
424+
function throwApplicationError$1(error) {
425+
var serviceError = new ServiceError({
426+
message: error.message,
427+
service: 'correios-alt'
428+
});
429+
430+
if (error.name === 'FetchError') {
431+
serviceError.message = 'Erro ao se conectar com o serviço dos Correios Alt.';
432+
}
433+
434+
throw serviceError;
435+
}
436+
388437
function fetchViaCepService(cepWithLeftPad, configurations) {
389438
var url = "https://viacep.com.br/ws/".concat(cepWithLeftPad, "/json/");
390439
var options = {
@@ -400,7 +449,7 @@
400449
options.headers['user-agent'] = 'cep-promise';
401450
}
402451

403-
return fetch(url, options).then(analyzeAndParseResponse$1).then(checkForViaCepError).then(extractCepValuesFromResponse)["catch"](throwApplicationError$1);
452+
return fetch(url, options).then(analyzeAndParseResponse$1).then(checkForViaCepError).then(extractCepValuesFromResponse$1)["catch"](throwApplicationError$2);
404453
}
405454

406455
function analyzeAndParseResponse$1(response) {
@@ -419,7 +468,7 @@
419468
return responseObject;
420469
}
421470

422-
function extractCepValuesFromResponse(responseObject) {
471+
function extractCepValuesFromResponse$1(responseObject) {
423472
return {
424473
cep: responseObject.cep.replace('-', ''),
425474
state: responseObject.uf,
@@ -430,7 +479,7 @@
430479
};
431480
}
432481

433-
function throwApplicationError$1(error) {
482+
function throwApplicationError$2(error) {
434483
var serviceError = new ServiceError({
435484
message: error.message,
436485
service: 'viacep'
@@ -453,7 +502,7 @@
453502
},
454503
timeout: configurations.timeout || 30000
455504
};
456-
return fetch(url, options).then(analyzeAndParseResponse$2).then(checkForWideNetError).then(extractCepValuesFromResponse$1)["catch"](throwApplicationError$2);
505+
return fetch(url, options).then(analyzeAndParseResponse$2).then(checkForWideNetError).then(extractCepValuesFromResponse$2)["catch"](throwApplicationError$3);
457506
}
458507

459508
function analyzeAndParseResponse$2(response) {
@@ -472,7 +521,7 @@
472521
return object;
473522
}
474523

475-
function extractCepValuesFromResponse$1(object) {
524+
function extractCepValuesFromResponse$2(object) {
476525
return {
477526
cep: object.code.replace('-', ''),
478527
state: object.state,
@@ -483,7 +532,7 @@
483532
};
484533
}
485534

486-
function throwApplicationError$2(error) {
535+
function throwApplicationError$3(error) {
487536
var serviceError = new ServiceError({
488537
message: error.message,
489538
service: 'widenet'
@@ -506,18 +555,18 @@
506555
},
507556
timeout: configurations.timeout || 30000
508557
};
509-
return fetch(url, options).then(parseResponse).then(extractCepValuesFromResponse$2)["catch"](throwApplicationError$3);
558+
return fetch(url, options).then(parseResponse$1).then(extractCepValuesFromResponse$3)["catch"](throwApplicationError$4);
510559
}
511560

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

517566
return response.json();
518567
}
519568

520-
function extractCepValuesFromResponse$2(response) {
569+
function extractCepValuesFromResponse$3(response) {
521570
return {
522571
cep: response.cep,
523572
state: response.state,
@@ -528,7 +577,7 @@
528577
};
529578
}
530579

531-
function throwApplicationError$3(error) {
580+
function throwApplicationError$4(error) {
532581
var serviceError = new ServiceError({
533582
message: error.message,
534583
service: 'brasilapi'
@@ -554,6 +603,7 @@
554603

555604
return {
556605
correios: fetchCorreiosService,
606+
'correios-alt': fetchCorreiosAltAPIService,
557607
viacep: fetchViaCepService,
558608
widenet: fetchWideNetService,
559609
brasilapi: fetchBrasilAPIService
@@ -581,7 +631,7 @@
581631
return cepRawValue;
582632
}).then(removeSpecialCharacters).then(validateInputLength).then(leftPadWithZeros).then(function (cepWithLeftPad) {
583633
return fetchCepFromServices(cepWithLeftPad, configurations);
584-
})["catch"](handleServicesError)["catch"](throwApplicationError$4);
634+
})["catch"](handleServicesError)["catch"](throwApplicationError$5);
585635
}
586636

587637
function validateProviders(providers) {
@@ -689,7 +739,7 @@
689739
throw aggregatedErrors;
690740
}
691741

692-
function throwApplicationError$4(_ref) {
742+
function throwApplicationError$5(_ref) {
693743
var message = _ref.message,
694744
type = _ref.type,
695745
errors = _ref.errors;

0 commit comments

Comments
 (0)