Skip to content

Commit 490693a

Browse files
Merge pull request #183 from filipedeschamps/remove-proxier
Remove o uso do proxier do projeto
2 parents 86c9150 + 88938ab commit 490693a

File tree

9 files changed

+489
-76
lines changed

9 files changed

+489
-76
lines changed

dist/cep-promise-browser.js

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -584,27 +584,25 @@
584584
throw serviceError;
585585
}
586586

587-
var PROXY_URL = 'https://proxier.now.sh/api?url=';
588-
589-
/* istanbul ignore next */
590-
591-
function isBrowser() {
592-
return typeof window !== 'undefined';
593-
}
594-
/* istanbul ignore next */
595-
587+
function getAvailableServices() {
588+
var isBrowser = typeof window !== 'undefined';
589+
590+
if (isBrowser) {
591+
return {
592+
brasilapi: fetchBrasilAPIService,
593+
viacep: fetchViaCepService,
594+
widenet: fetchWideNetService
595+
};
596+
}
596597

597-
function injectProxy(Service) {
598-
return function (cepWithLeftPad) {
599-
return Service(cepWithLeftPad, PROXY_URL);
598+
return {
599+
brasilapi: fetchBrasilAPIService,
600+
viacep: fetchViaCepService,
601+
widenet: fetchWideNetService,
602+
correios: fetchCorreiosService
600603
};
601604
}
602605

603-
var CorreiosService = isBrowser() ? injectProxy(fetchCorreiosService) : fetchCorreiosService;
604-
var ViaCepService = fetchViaCepService;
605-
var WideNetService = fetchWideNetService;
606-
var BrasilAPIService = fetchBrasilAPIService;
607-
608606
var reverse = function reverse(promise) {
609607
return new Promise(function (resolve, reject) {
610608
return Promise.resolve(promise).then(reject, resolve);
@@ -711,12 +709,7 @@
711709
}
712710

713711
function fetchCepFromServices(cepWithLeftPad, configurations) {
714-
var providersServices = {
715-
brasilapi: BrasilAPIService,
716-
viacep: ViaCepService,
717-
widenet: WideNetService,
718-
correios: CorreiosService
719-
};
712+
var providersServices = getAvailableServices();
720713

721714
if (configurations.providers.length === 0) {
722715
return Promise$1.any(Object.values(providersServices).map(function (provider) {

dist/cep-promise-browser.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/cep-promise.js

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -535,27 +535,25 @@
535535
throw serviceError;
536536
}
537537

538-
var PROXY_URL = 'https://proxier.now.sh/api?url=';
539-
540-
/* istanbul ignore next */
541-
542-
function isBrowser() {
543-
return typeof window !== 'undefined';
544-
}
545-
/* istanbul ignore next */
546-
538+
function getAvailableServices() {
539+
var isBrowser = typeof window !== 'undefined';
540+
541+
if (isBrowser) {
542+
return {
543+
brasilapi: fetchBrasilAPIService,
544+
viacep: fetchViaCepService,
545+
widenet: fetchWideNetService
546+
};
547+
}
547548

548-
function injectProxy(Service) {
549-
return function (cepWithLeftPad) {
550-
return Service(cepWithLeftPad, PROXY_URL);
549+
return {
550+
brasilapi: fetchBrasilAPIService,
551+
viacep: fetchViaCepService,
552+
widenet: fetchWideNetService,
553+
correios: fetchCorreiosService
551554
};
552555
}
553556

554-
var CorreiosService = isBrowser() ? injectProxy(fetchCorreiosService) : fetchCorreiosService;
555-
var ViaCepService = fetchViaCepService;
556-
var WideNetService = fetchWideNetService;
557-
var BrasilAPIService = fetchBrasilAPIService;
558-
559557
var reverse = function reverse(promise) {
560558
return new Promise(function (resolve, reject) {
561559
return Promise.resolve(promise).then(reject, resolve);
@@ -662,12 +660,7 @@
662660
}
663661

664662
function fetchCepFromServices(cepWithLeftPad, configurations) {
665-
var providersServices = {
666-
brasilapi: BrasilAPIService,
667-
viacep: ViaCepService,
668-
widenet: WideNetService,
669-
correios: CorreiosService
670-
};
663+
var providersServices = getAvailableServices();
671664

672665
if (configurations.providers.length === 0) {
673666
return Promise$1.any(Object.values(providersServices).map(function (provider) {

dist/cep-promise.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cep-promise.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
'use strict'
22

33
import CepPromiseError from './errors/cep-promise.js'
4-
import {
5-
CorreiosService,
6-
ViaCepService,
7-
WideNetService,
8-
BrasilAPIService
9-
} from './services/index.js'
4+
import { getAvailableServices } from './services/index.js'
105
import Promise from './utils/promise-any.js'
116

127
const CEP_SIZE = 8
@@ -112,12 +107,7 @@ function validateInputLength (cepWithLeftPad) {
112107
}
113108

114109
function fetchCepFromServices (cepWithLeftPad, configurations) {
115-
const providersServices = {
116-
brasilapi: BrasilAPIService,
117-
viacep: ViaCepService,
118-
widenet: WideNetService,
119-
correios: CorreiosService
120-
}
110+
let providersServices = getAvailableServices()
121111

122112
if (configurations.providers.length === 0) {
123113
return Promise.any(

src/services/index.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,22 @@ import Correios from './correios'
22
import ViaCep from './viacep'
33
import WideNet from './widenet'
44
import BrasilAPI from './brasilapi.js'
5-
import { PROXY_URL } from '../utils/consts'
65

7-
/* istanbul ignore next */
8-
function isBrowser () {
9-
return typeof window !== 'undefined'
10-
}
6+
export function getAvailableServices () {
7+
const isBrowser = typeof window !== 'undefined'
118

12-
/* istanbul ignore next */
13-
function injectProxy (Service) {
14-
return cepWithLeftPad => Service(cepWithLeftPad, PROXY_URL)
15-
}
9+
if (isBrowser) {
10+
return {
11+
brasilapi: BrasilAPI,
12+
viacep: ViaCep,
13+
widenet: WideNet,
14+
}
15+
}
1616

17-
export const CorreiosService = isBrowser() ? injectProxy(Correios) : Correios
18-
export const ViaCepService = ViaCep
19-
export const WideNetService = WideNet
20-
export const BrasilAPIService = BrasilAPI
17+
return {
18+
brasilapi: BrasilAPI,
19+
viacep: ViaCep,
20+
widenet: WideNet,
21+
correios: Correios
22+
}
23+
}

src/utils/consts.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)