|
584 | 584 | throw serviceError; |
585 | 585 | } |
586 | 586 |
|
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 | + } |
596 | 597 |
|
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 |
600 | 603 | }; |
601 | 604 | } |
602 | 605 |
|
603 | | - var CorreiosService = isBrowser() ? injectProxy(fetchCorreiosService) : fetchCorreiosService; |
604 | | - var ViaCepService = fetchViaCepService; |
605 | | - var WideNetService = fetchWideNetService; |
606 | | - var BrasilAPIService = fetchBrasilAPIService; |
607 | | - |
608 | 606 | var reverse = function reverse(promise) { |
609 | 607 | return new Promise(function (resolve, reject) { |
610 | 608 | return Promise.resolve(promise).then(reject, resolve); |
|
711 | 709 | } |
712 | 710 |
|
713 | 711 | function fetchCepFromServices(cepWithLeftPad, configurations) { |
714 | | - var providersServices = { |
715 | | - brasilapi: BrasilAPIService, |
716 | | - viacep: ViaCepService, |
717 | | - widenet: WideNetService, |
718 | | - correios: CorreiosService |
719 | | - }; |
| 712 | + var providersServices = getAvailableServices(); |
720 | 713 |
|
721 | 714 | if (configurations.providers.length === 0) { |
722 | 715 | return Promise$1.any(Object.values(providersServices).map(function (provider) { |
|
0 commit comments