increase 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +10 -0
- package/.prettierrc +6 -0
- package/.stats.yml +1 -0
- package/LICENSE +201 -0
- package/README.md +211 -0
- package/api.md +477 -0
- package/bin/check-test-server +50 -0
- package/build +12 -0
- package/check-version.ts +15 -0
- package/core.ts +908 -0
- package/dist/cjs/check-version.d.ts +1 -0
- package/dist/cjs/check-version.js +21 -0
- package/dist/cjs/check-version.js.map +1 -0
- package/dist/cjs/core.d.ts +262 -0
- package/dist/cjs/core.js +978 -0
- package/dist/cjs/core.js.map +1 -0
- package/dist/cjs/fetch-polyfill.d.ts +5 -0
- package/dist/cjs/fetch-polyfill.js +55 -0
- package/dist/cjs/fetch-polyfill.js.map +1 -0
- package/dist/cjs/index.d.ts +201 -0
- package/dist/cjs/index.js +180 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/pagination.d.ts +28 -0
- package/dist/cjs/pagination.js +30 -0
- package/dist/cjs/pagination.js.map +1 -0
- package/dist/cjs/resource.d.ts +11 -0
- package/dist/cjs/resource.js +17 -0
- package/dist/cjs/resource.js.map +1 -0
- package/dist/cjs/resources/account-numbers.d.ts +103 -0
- package/dist/cjs/resources/account-numbers.js +37 -0
- package/dist/cjs/resources/account-numbers.js.map +1 -0
- package/dist/cjs/resources/account-statements.d.ts +99 -0
- package/dist/cjs/resources/account-statements.js +25 -0
- package/dist/cjs/resources/account-statements.js.map +1 -0
- package/dist/cjs/resources/account-transfers.d.ts +189 -0
- package/dist/cjs/resources/account-transfers.js +43 -0
- package/dist/cjs/resources/account-transfers.js.map +1 -0
- package/dist/cjs/resources/accounts.d.ts +133 -0
- package/dist/cjs/resources/accounts.js +43 -0
- package/dist/cjs/resources/accounts.js.map +1 -0
- package/dist/cjs/resources/ach-prenotifications.d.ts +188 -0
- package/dist/cjs/resources/ach-prenotifications.js +35 -0
- package/dist/cjs/resources/ach-prenotifications.js.map +1 -0
- package/dist/cjs/resources/ach-transfers.d.ts +375 -0
- package/dist/cjs/resources/ach-transfers.js +43 -0
- package/dist/cjs/resources/ach-transfers.js.map +1 -0
- package/dist/cjs/resources/card-disputes.d.ts +143 -0
- package/dist/cjs/resources/card-disputes.js +31 -0
- package/dist/cjs/resources/card-disputes.js.map +1 -0
- package/dist/cjs/resources/card-profiles.d.ts +183 -0
- package/dist/cjs/resources/card-profiles.js +31 -0
- package/dist/cjs/resources/card-profiles.js.map +1 -0
- package/dist/cjs/resources/cards.d.ts +316 -0
- package/dist/cjs/resources/cards.js +43 -0
- package/dist/cjs/resources/cards.js.map +1 -0
- package/dist/cjs/resources/check-deposits.d.ts +241 -0
- package/dist/cjs/resources/check-deposits.js +31 -0
- package/dist/cjs/resources/check-deposits.js.map +1 -0
- package/dist/cjs/resources/check-transfers.d.ts +331 -0
- package/dist/cjs/resources/check-transfers.js +49 -0
- package/dist/cjs/resources/check-transfers.js.map +1 -0
- package/dist/cjs/resources/declined-transactions.d.ts +424 -0
- package/dist/cjs/resources/declined-transactions.js +29 -0
- package/dist/cjs/resources/declined-transactions.js.map +1 -0
- package/dist/cjs/resources/digital-wallet-tokens.d.ts +85 -0
- package/dist/cjs/resources/digital-wallet-tokens.js +29 -0
- package/dist/cjs/resources/digital-wallet-tokens.js.map +1 -0
- package/dist/cjs/resources/documents.d.ts +87 -0
- package/dist/cjs/resources/documents.js +25 -0
- package/dist/cjs/resources/documents.js.map +1 -0
- package/dist/cjs/resources/entities/entities.d.ts +1383 -0
- package/dist/cjs/resources/entities/entities.js +36 -0
- package/dist/cjs/resources/entities/entities.js.map +1 -0
- package/dist/cjs/resources/entities/index.d.ts +2 -0
- package/dist/cjs/resources/entities/index.js +12 -0
- package/dist/cjs/resources/entities/index.js.map +1 -0
- package/dist/cjs/resources/entities/supplemental-documents.d.ts +19 -0
- package/dist/cjs/resources/entities/supplemental-documents.js +15 -0
- package/dist/cjs/resources/entities/supplemental-documents.js.map +1 -0
- package/dist/cjs/resources/event-subscriptions.d.ts +196 -0
- package/dist/cjs/resources/event-subscriptions.js +37 -0
- package/dist/cjs/resources/event-subscriptions.js.map +1 -0
- package/dist/cjs/resources/events.d.ts +183 -0
- package/dist/cjs/resources/events.js +25 -0
- package/dist/cjs/resources/events.js.map +1 -0
- package/dist/cjs/resources/external-accounts.d.ts +121 -0
- package/dist/cjs/resources/external-accounts.js +37 -0
- package/dist/cjs/resources/external-accounts.js.map +1 -0
- package/dist/cjs/resources/files.d.ts +148 -0
- package/dist/cjs/resources/files.js +34 -0
- package/dist/cjs/resources/files.js.map +1 -0
- package/dist/cjs/resources/groups.d.ts +37 -0
- package/dist/cjs/resources/groups.js +15 -0
- package/dist/cjs/resources/groups.js.map +1 -0
- package/dist/cjs/resources/inbound-ach-transfer-returns.d.ts +106 -0
- package/dist/cjs/resources/inbound-ach-transfer-returns.js +35 -0
- package/dist/cjs/resources/inbound-ach-transfer-returns.js.map +1 -0
- package/dist/cjs/resources/inbound-wire-drawdown-requests.d.ts +124 -0
- package/dist/cjs/resources/inbound-wire-drawdown-requests.js +29 -0
- package/dist/cjs/resources/inbound-wire-drawdown-requests.js.map +1 -0
- package/dist/cjs/resources/index.d.ts +163 -0
- package/dist/cjs/resources/index.js +478 -0
- package/dist/cjs/resources/index.js.map +1 -0
- package/dist/cjs/resources/limits.d.ts +105 -0
- package/dist/cjs/resources/limits.js +37 -0
- package/dist/cjs/resources/limits.js.map +1 -0
- package/dist/cjs/resources/oauth-connections.d.ts +50 -0
- package/dist/cjs/resources/oauth-connections.js +25 -0
- package/dist/cjs/resources/oauth-connections.js.map +1 -0
- package/dist/cjs/resources/pending-transactions.d.ts +397 -0
- package/dist/cjs/resources/pending-transactions.js +29 -0
- package/dist/cjs/resources/pending-transactions.js.map +1 -0
- package/dist/cjs/resources/real-time-decisions.d.ts +289 -0
- package/dist/cjs/resources/real-time-decisions.js +21 -0
- package/dist/cjs/resources/real-time-decisions.js.map +1 -0
- package/dist/cjs/resources/routing-numbers.d.ts +49 -0
- package/dist/cjs/resources/routing-numbers.js +21 -0
- package/dist/cjs/resources/routing-numbers.js.map +1 -0
- package/dist/cjs/resources/shared.d.ts +15 -0
- package/dist/cjs/resources/shared.js +4 -0
- package/dist/cjs/resources/shared.js.map +1 -0
- package/dist/cjs/resources/simulations/account-statements.d.ts +19 -0
- package/dist/cjs/resources/simulations/account-statements.js +16 -0
- package/dist/cjs/resources/simulations/account-statements.js.map +1 -0
- package/dist/cjs/resources/simulations/account-transfers.d.ts +15 -0
- package/dist/cjs/resources/simulations/account-transfers.js +18 -0
- package/dist/cjs/resources/simulations/account-transfers.js.map +1 -0
- package/dist/cjs/resources/simulations/ach-transfers.d.ts +1488 -0
- package/dist/cjs/resources/simulations/ach-transfers.js +39 -0
- package/dist/cjs/resources/simulations/ach-transfers.js.map +1 -0
- package/dist/cjs/resources/simulations/card-disputes.d.ts +26 -0
- package/dist/cjs/resources/simulations/card-disputes.js +18 -0
- package/dist/cjs/resources/simulations/card-disputes.js.map +1 -0
- package/dist/cjs/resources/simulations/card-refunds.d.ts +20 -0
- package/dist/cjs/resources/simulations/card-refunds.js +16 -0
- package/dist/cjs/resources/simulations/card-refunds.js.map +1 -0
- package/dist/cjs/resources/simulations/cards.d.ts +793 -0
- package/dist/cjs/resources/simulations/cards.js +31 -0
- package/dist/cjs/resources/simulations/cards.js.map +1 -0
- package/dist/cjs/resources/simulations/check-deposits.d.ts +30 -0
- package/dist/cjs/resources/simulations/check-deposits.js +31 -0
- package/dist/cjs/resources/simulations/check-deposits.js.map +1 -0
- package/dist/cjs/resources/simulations/check-transfers.d.ts +22 -0
- package/dist/cjs/resources/simulations/check-transfers.js +24 -0
- package/dist/cjs/resources/simulations/check-transfers.js.map +1 -0
- package/dist/cjs/resources/simulations/digital-wallet-token-requests.d.ts +43 -0
- package/dist/cjs/resources/simulations/digital-wallet-token-requests.js +16 -0
- package/dist/cjs/resources/simulations/digital-wallet-token-requests.js.map +1 -0
- package/dist/cjs/resources/simulations/documents.d.ts +18 -0
- package/dist/cjs/resources/simulations/documents.js +15 -0
- package/dist/cjs/resources/simulations/documents.js.map +1 -0
- package/dist/cjs/resources/simulations/inbound-wire-drawdown-requests.d.ts +101 -0
- package/dist/cjs/resources/simulations/inbound-wire-drawdown-requests.js +16 -0
- package/dist/cjs/resources/simulations/inbound-wire-drawdown-requests.js.map +1 -0
- package/dist/cjs/resources/simulations/index.d.ts +20 -0
- package/dist/cjs/resources/simulations/index.js +4 -0
- package/dist/cjs/resources/simulations/index.js.map +1 -0
- package/dist/cjs/resources/simulations/real-time-payments-transfers.d.ts +1431 -0
- package/dist/cjs/resources/simulations/real-time-payments-transfers.js +16 -0
- package/dist/cjs/resources/simulations/real-time-payments-transfers.js.map +1 -0
- package/dist/cjs/resources/simulations/simulations.d.ts +29 -0
- package/dist/cjs/resources/simulations/simulations.js +44 -0
- package/dist/cjs/resources/simulations/simulations.js.map +1 -0
- package/dist/cjs/resources/simulations/wire-transfers.d.ts +1104 -0
- package/dist/cjs/resources/simulations/wire-transfers.js +15 -0
- package/dist/cjs/resources/simulations/wire-transfers.js.map +1 -0
- package/dist/cjs/resources/transactions.d.ts +1101 -0
- package/dist/cjs/resources/transactions.js +25 -0
- package/dist/cjs/resources/transactions.js.map +1 -0
- package/dist/cjs/resources/wire-drawdown-requests.d.ts +148 -0
- package/dist/cjs/resources/wire-drawdown-requests.js +35 -0
- package/dist/cjs/resources/wire-drawdown-requests.js.map +1 -0
- package/dist/cjs/resources/wire-transfers.d.ts +310 -0
- package/dist/cjs/resources/wire-transfers.js +60 -0
- package/dist/cjs/resources/wire-transfers.js.map +1 -0
- package/dist/cjs/tests/api-resources/account-numbers.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/account-numbers.test.js +104 -0
- package/dist/cjs/tests/api-resources/account-numbers.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/account-statements.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/account-statements.test.js +101 -0
- package/dist/cjs/tests/api-resources/account-statements.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/account-transfers.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/account-transfers.test.js +146 -0
- package/dist/cjs/tests/api-resources/account-transfers.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/accounts.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/accounts.test.js +119 -0
- package/dist/cjs/tests/api-resources/accounts.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/ach-prenotifications.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/ach-prenotifications.test.js +125 -0
- package/dist/cjs/tests/api-resources/ach-prenotifications.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/ach-transfers.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/ach-transfers.test.js +159 -0
- package/dist/cjs/tests/api-resources/ach-transfers.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/card-disputes.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/card-disputes.test.js +108 -0
- package/dist/cjs/tests/api-resources/card-disputes.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/card-profiles.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/card-profiles.test.js +97 -0
- package/dist/cjs/tests/api-resources/card-profiles.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/cards.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/cards.test.js +138 -0
- package/dist/cjs/tests/api-resources/cards.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/check-deposits.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/check-deposits.test.js +113 -0
- package/dist/cjs/tests/api-resources/check-deposits.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/check-transfers.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/check-transfers.test.js +172 -0
- package/dist/cjs/tests/api-resources/check-transfers.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/declined-transactions.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/declined-transactions.test.js +105 -0
- package/dist/cjs/tests/api-resources/declined-transactions.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/digital-wallet-tokens.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/digital-wallet-tokens.test.js +103 -0
- package/dist/cjs/tests/api-resources/digital-wallet-tokens.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/documents.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/documents.test.js +101 -0
- package/dist/cjs/tests/api-resources/documents.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/entities/entities.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/entities/entities.test.js +280 -0
- package/dist/cjs/tests/api-resources/entities/entities.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/entities/supplemental-documents.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/entities/supplemental-documents.test.js +49 -0
- package/dist/cjs/tests/api-resources/entities/supplemental-documents.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/event-subscriptions.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/event-subscriptions.test.js +109 -0
- package/dist/cjs/tests/api-resources/event-subscriptions.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/events.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/events.test.js +101 -0
- package/dist/cjs/tests/api-resources/events.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/external-accounts.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/external-accounts.test.js +113 -0
- package/dist/cjs/tests/api-resources/external-accounts.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/files.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/files.test.js +117 -0
- package/dist/cjs/tests/api-resources/files.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/groups.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/groups.test.js +54 -0
- package/dist/cjs/tests/api-resources/groups.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/inbound-ach-transfer-returns.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/inbound-ach-transfer-returns.test.js +90 -0
- package/dist/cjs/tests/api-resources/inbound-ach-transfer-returns.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/inbound-wire-drawdown-requests.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/inbound-wire-drawdown-requests.test.js +83 -0
- package/dist/cjs/tests/api-resources/inbound-wire-drawdown-requests.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/limits.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/limits.test.js +100 -0
- package/dist/cjs/tests/api-resources/limits.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/oauth-connections.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/oauth-connections.test.js +78 -0
- package/dist/cjs/tests/api-resources/oauth-connections.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/pending-transactions.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/pending-transactions.test.js +97 -0
- package/dist/cjs/tests/api-resources/pending-transactions.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/real-time-decisions.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/real-time-decisions.test.js +71 -0
- package/dist/cjs/tests/api-resources/real-time-decisions.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/routing-numbers.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/routing-numbers.test.js +55 -0
- package/dist/cjs/tests/api-resources/routing-numbers.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/simulations/account-statements.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/simulations/account-statements.test.js +49 -0
- package/dist/cjs/tests/api-resources/simulations/account-statements.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/simulations/account-transfers.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/simulations/account-transfers.test.js +60 -0
- package/dist/cjs/tests/api-resources/simulations/account-transfers.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/simulations/ach-transfers.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/simulations/ach-transfers.test.js +92 -0
- package/dist/cjs/tests/api-resources/simulations/ach-transfers.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/simulations/card-disputes.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/simulations/card-disputes.test.js +56 -0
- package/dist/cjs/tests/api-resources/simulations/card-disputes.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/simulations/card-refunds.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/simulations/card-refunds.test.js +49 -0
- package/dist/cjs/tests/api-resources/simulations/card-refunds.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/simulations/cards.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/simulations/cards.test.js +70 -0
- package/dist/cjs/tests/api-resources/simulations/cards.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/simulations/check-deposits.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/simulations/check-deposits.test.js +86 -0
- package/dist/cjs/tests/api-resources/simulations/check-deposits.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/simulations/check-transfers.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/simulations/check-transfers.test.js +73 -0
- package/dist/cjs/tests/api-resources/simulations/check-transfers.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/simulations/digital-wallet-token-requests.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/simulations/digital-wallet-token-requests.test.js +49 -0
- package/dist/cjs/tests/api-resources/simulations/digital-wallet-token-requests.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/simulations/documents.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/simulations/documents.test.js +49 -0
- package/dist/cjs/tests/api-resources/simulations/documents.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/simulations/inbound-wire-drawdown-requests.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/simulations/inbound-wire-drawdown-requests.test.js +81 -0
- package/dist/cjs/tests/api-resources/simulations/inbound-wire-drawdown-requests.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/simulations/real-time-payments-transfers.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/simulations/real-time-payments-transfers.test.js +62 -0
- package/dist/cjs/tests/api-resources/simulations/real-time-payments-transfers.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/simulations/wire-transfers.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/simulations/wire-transfers.test.js +70 -0
- package/dist/cjs/tests/api-resources/simulations/wire-transfers.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/transactions.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/transactions.test.js +109 -0
- package/dist/cjs/tests/api-resources/transactions.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/wire-drawdown-requests.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/wire-drawdown-requests.test.js +110 -0
- package/dist/cjs/tests/api-resources/wire-drawdown-requests.test.js.map +1 -0
- package/dist/cjs/tests/api-resources/wire-transfers.test.d.ts +1 -0
- package/dist/cjs/tests/api-resources/wire-transfers.test.js +184 -0
- package/dist/cjs/tests/api-resources/wire-transfers.test.js.map +1 -0
- package/dist/cjs/tests/form.test.d.ts +1 -0
- package/dist/cjs/tests/form.test.js +60 -0
- package/dist/cjs/tests/form.test.js.map +1 -0
- package/dist/cjs/tests/index.test.d.ts +1 -0
- package/dist/cjs/tests/index.test.js +44 -0
- package/dist/cjs/tests/index.test.js.map +1 -0
- package/dist/cjs/tests/responses.test.d.ts +1 -0
- package/dist/cjs/tests/responses.test.js +59 -0
- package/dist/cjs/tests/responses.test.js.map +1 -0
- package/dist/cjs/version.d.ts +1 -0
- package/dist/cjs/version.js +5 -0
- package/dist/cjs/version.js.map +1 -0
- package/fetch-polyfill.ts +69 -0
- package/index.ts +276 -0
- package/jest.config.js +8 -0
- package/package.json +47 -0
- package/pagination.ts +58 -0
- package/resource.ts +24 -0
- package/resources/account-numbers.ts +141 -0
- package/resources/account-statements.ts +132 -0
- package/resources/account-transfers.ts +244 -0
- package/resources/accounts.ts +179 -0
- package/resources/ach-prenotifications.ts +242 -0
- package/resources/ach-transfers.ts +465 -0
- package/resources/card-disputes.ts +187 -0
- package/resources/card-profiles.ts +236 -0
- package/resources/cards.ts +398 -0
- package/resources/check-deposits.ts +303 -0
- package/resources/check-transfers.ts +422 -0
- package/resources/declined-transactions.ts +547 -0
- package/resources/digital-wallet-tokens.ts +115 -0
- package/resources/documents.ts +119 -0
- package/resources/entities/entities.ts +1668 -0
- package/resources/entities/index.ts +4 -0
- package/resources/entities/supplemental-documents.ts +25 -0
- package/resources/event-subscriptions.ts +232 -0
- package/resources/events.ts +215 -0
- package/resources/external-accounts.ts +162 -0
- package/resources/files.ts +188 -0
- package/resources/groups.ts +47 -0
- package/resources/inbound-ach-transfer-returns.ts +142 -0
- package/resources/inbound-wire-drawdown-requests.ts +168 -0
- package/resources/index.ts +165 -0
- package/resources/limits.ts +144 -0
- package/resources/oauth-connections.ts +74 -0
- package/resources/pending-transactions.ts +491 -0
- package/resources/real-time-decisions.ts +345 -0
- package/resources/routing-numbers.ts +62 -0
- package/resources/shared.ts +17 -0
- package/resources/simulations/account-statements.ts +25 -0
- package/resources/simulations/account-transfers.ts +20 -0
- package/resources/simulations/ach-transfers.ts +1873 -0
- package/resources/simulations/card-disputes.ts +33 -0
- package/resources/simulations/card-refunds.ts +26 -0
- package/resources/simulations/cards.ts +979 -0
- package/resources/simulations/check-deposits.ts +41 -0
- package/resources/simulations/check-transfers.ts +30 -0
- package/resources/simulations/digital-wallet-token-requests.ts +52 -0
- package/resources/simulations/documents.ts +24 -0
- package/resources/simulations/inbound-wire-drawdown-requests.ts +126 -0
- package/resources/simulations/index.ts +22 -0
- package/resources/simulations/real-time-payments-transfers.ts +1809 -0
- package/resources/simulations/simulations.ts +32 -0
- package/resources/simulations/wire-transfers.ts +1391 -0
- package/resources/transactions.ts +1393 -0
- package/resources/wire-drawdown-requests.ts +195 -0
- package/resources/wire-transfers.ts +399 -0
- package/tests/api-resources/account-numbers.test.ts +67 -0
- package/tests/api-resources/account-statements.test.ts +64 -0
- package/tests/api-resources/account-transfers.test.ts +109 -0
- package/tests/api-resources/accounts.test.ts +82 -0
- package/tests/api-resources/ach-prenotifications.test.ts +86 -0
- package/tests/api-resources/ach-transfers.test.ts +120 -0
- package/tests/api-resources/card-disputes.test.ts +71 -0
- package/tests/api-resources/card-profiles.test.ts +60 -0
- package/tests/api-resources/cards.test.ts +101 -0
- package/tests/api-resources/check-deposits.test.ts +74 -0
- package/tests/api-resources/check-transfers.test.ts +135 -0
- package/tests/api-resources/declined-transactions.test.ts +68 -0
- package/tests/api-resources/digital-wallet-tokens.test.ts +64 -0
- package/tests/api-resources/documents.test.ts +64 -0
- package/tests/api-resources/entities/entities.test.ts +243 -0
- package/tests/api-resources/entities/supplemental-documents.test.ts +12 -0
- package/tests/api-resources/event-subscriptions.test.ts +69 -0
- package/tests/api-resources/events.test.ts +64 -0
- package/tests/api-resources/external-accounts.test.ts +76 -0
- package/tests/api-resources/files.test.ts +81 -0
- package/tests/api-resources/groups.test.ts +17 -0
- package/tests/api-resources/inbound-ach-transfer-returns.test.ts +53 -0
- package/tests/api-resources/inbound-wire-drawdown-requests.test.ts +46 -0
- package/tests/api-resources/limits.test.ts +63 -0
- package/tests/api-resources/oauth-connections.test.ts +41 -0
- package/tests/api-resources/pending-transactions.test.ts +58 -0
- package/tests/api-resources/real-time-decisions.test.ts +34 -0
- package/tests/api-resources/routing-numbers.test.ts +18 -0
- package/tests/api-resources/simulations/account-statements.test.ts +12 -0
- package/tests/api-resources/simulations/account-transfers.test.ts +23 -0
- package/tests/api-resources/simulations/ach-transfers.test.ts +52 -0
- package/tests/api-resources/simulations/card-disputes.test.ts +19 -0
- package/tests/api-resources/simulations/card-refunds.test.ts +12 -0
- package/tests/api-resources/simulations/cards.test.ts +33 -0
- package/tests/api-resources/simulations/check-deposits.test.ts +49 -0
- package/tests/api-resources/simulations/check-transfers.test.ts +34 -0
- package/tests/api-resources/simulations/digital-wallet-token-requests.test.ts +12 -0
- package/tests/api-resources/simulations/documents.test.ts +12 -0
- package/tests/api-resources/simulations/inbound-wire-drawdown-requests.test.ts +44 -0
- package/tests/api-resources/simulations/real-time-payments-transfers.test.ts +25 -0
- package/tests/api-resources/simulations/wire-transfers.test.ts +33 -0
- package/tests/api-resources/transactions.test.ts +70 -0
- package/tests/api-resources/wire-drawdown-requests.test.ts +73 -0
- package/tests/api-resources/wire-transfers.test.ts +147 -0
- package/tests/form.test.ts +27 -0
- package/tests/index.test.ts +47 -0
- package/tests/responses.test.ts +25 -0
- package/tsconfig.cjs.json +8 -0
- package/tsconfig.json +37 -0
- package/typings/digest-fetch/index.d.ts +33 -0
- package/version.ts +1 -0
package/dist/cjs/core.js
ADDED
|
@@ -0,0 +1,978 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __awaiter =
|
|
3
|
+
(this && this.__awaiter) ||
|
|
4
|
+
function (thisArg, _arguments, P, generator) {
|
|
5
|
+
function adopt(value) {
|
|
6
|
+
return value instanceof P ? value
|
|
7
|
+
: new P(function (resolve) {
|
|
8
|
+
resolve(value);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
12
|
+
function fulfilled(value) {
|
|
13
|
+
try {
|
|
14
|
+
step(generator.next(value));
|
|
15
|
+
} catch (e) {
|
|
16
|
+
reject(e);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function rejected(value) {
|
|
20
|
+
try {
|
|
21
|
+
step(generator['throw'](value));
|
|
22
|
+
} catch (e) {
|
|
23
|
+
reject(e);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function step(result) {
|
|
27
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
28
|
+
}
|
|
29
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
var __classPrivateFieldSet =
|
|
33
|
+
(this && this.__classPrivateFieldSet) ||
|
|
34
|
+
function (receiver, state, value, kind, f) {
|
|
35
|
+
if (kind === 'm') throw new TypeError('Private method is not writable');
|
|
36
|
+
if (kind === 'a' && !f) throw new TypeError('Private accessor was defined without a setter');
|
|
37
|
+
if (typeof state === 'function' ? receiver !== state || !f : !state.has(receiver))
|
|
38
|
+
throw new TypeError('Cannot write private member to an object whose class did not declare it');
|
|
39
|
+
return (
|
|
40
|
+
kind === 'a' ? f.call(receiver, value)
|
|
41
|
+
: f ? (f.value = value)
|
|
42
|
+
: state.set(receiver, value),
|
|
43
|
+
value
|
|
44
|
+
);
|
|
45
|
+
};
|
|
46
|
+
var __classPrivateFieldGet =
|
|
47
|
+
(this && this.__classPrivateFieldGet) ||
|
|
48
|
+
function (receiver, state, kind, f) {
|
|
49
|
+
if (kind === 'a' && !f) throw new TypeError('Private accessor was defined without a getter');
|
|
50
|
+
if (typeof state === 'function' ? receiver !== state || !f : !state.has(receiver))
|
|
51
|
+
throw new TypeError('Cannot read private member from an object whose class did not declare it');
|
|
52
|
+
return (
|
|
53
|
+
kind === 'm' ? f
|
|
54
|
+
: kind === 'a' ? f.call(receiver)
|
|
55
|
+
: f ? f.value
|
|
56
|
+
: state.get(receiver)
|
|
57
|
+
);
|
|
58
|
+
};
|
|
59
|
+
var __rest =
|
|
60
|
+
(this && this.__rest) ||
|
|
61
|
+
function (s, e) {
|
|
62
|
+
var t = {};
|
|
63
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
64
|
+
if (s != null && typeof Object.getOwnPropertySymbols === 'function')
|
|
65
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
66
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
67
|
+
}
|
|
68
|
+
return t;
|
|
69
|
+
};
|
|
70
|
+
var __await =
|
|
71
|
+
(this && this.__await) ||
|
|
72
|
+
function (v) {
|
|
73
|
+
return this instanceof __await ? ((this.v = v), this) : new __await(v);
|
|
74
|
+
};
|
|
75
|
+
var __asyncGenerator =
|
|
76
|
+
(this && this.__asyncGenerator) ||
|
|
77
|
+
function (thisArg, _arguments, generator) {
|
|
78
|
+
if (!Symbol.asyncIterator) throw new TypeError('Symbol.asyncIterator is not defined.');
|
|
79
|
+
var g = generator.apply(thisArg, _arguments || []),
|
|
80
|
+
i,
|
|
81
|
+
q = [];
|
|
82
|
+
return (
|
|
83
|
+
(i = {}),
|
|
84
|
+
verb('next'),
|
|
85
|
+
verb('throw'),
|
|
86
|
+
verb('return'),
|
|
87
|
+
(i[Symbol.asyncIterator] = function () {
|
|
88
|
+
return this;
|
|
89
|
+
}),
|
|
90
|
+
i
|
|
91
|
+
);
|
|
92
|
+
function verb(n) {
|
|
93
|
+
if (g[n])
|
|
94
|
+
i[n] = function (v) {
|
|
95
|
+
return new Promise(function (a, b) {
|
|
96
|
+
q.push([n, v, a, b]) > 1 || resume(n, v);
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function resume(n, v) {
|
|
101
|
+
try {
|
|
102
|
+
step(g[n](v));
|
|
103
|
+
} catch (e) {
|
|
104
|
+
settle(q[0][3], e);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function step(r) {
|
|
108
|
+
r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r);
|
|
109
|
+
}
|
|
110
|
+
function fulfill(value) {
|
|
111
|
+
resume('next', value);
|
|
112
|
+
}
|
|
113
|
+
function reject(value) {
|
|
114
|
+
resume('throw', value);
|
|
115
|
+
}
|
|
116
|
+
function settle(f, v) {
|
|
117
|
+
if ((f(v), q.shift(), q.length)) resume(q[0][0], q[0][1]);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
var __asyncValues =
|
|
121
|
+
(this && this.__asyncValues) ||
|
|
122
|
+
function (o) {
|
|
123
|
+
if (!Symbol.asyncIterator) throw new TypeError('Symbol.asyncIterator is not defined.');
|
|
124
|
+
var m = o[Symbol.asyncIterator],
|
|
125
|
+
i;
|
|
126
|
+
return m ? m.call(o)
|
|
127
|
+
: ((o = typeof __values === 'function' ? __values(o) : o[Symbol.iterator]()),
|
|
128
|
+
(i = {}),
|
|
129
|
+
verb('next'),
|
|
130
|
+
verb('throw'),
|
|
131
|
+
verb('return'),
|
|
132
|
+
(i[Symbol.asyncIterator] = function () {
|
|
133
|
+
return this;
|
|
134
|
+
}),
|
|
135
|
+
i);
|
|
136
|
+
function verb(n) {
|
|
137
|
+
i[n] =
|
|
138
|
+
o[n] &&
|
|
139
|
+
function (v) {
|
|
140
|
+
return new Promise(function (resolve, reject) {
|
|
141
|
+
(v = o[n](v)), settle(resolve, reject, v.done, v.value);
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
function settle(resolve, reject, d, v) {
|
|
146
|
+
Promise.resolve(v).then(function (v) {
|
|
147
|
+
resolve({ value: v, done: d });
|
|
148
|
+
}, reject);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
var __importDefault =
|
|
152
|
+
(this && this.__importDefault) ||
|
|
153
|
+
function (mod) {
|
|
154
|
+
return mod && mod.__esModule ? mod : { default: mod };
|
|
155
|
+
};
|
|
156
|
+
var _AbstractPage_client;
|
|
157
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
158
|
+
exports.getHeader =
|
|
159
|
+
exports.isHeadersProtocol =
|
|
160
|
+
exports.hasOwn =
|
|
161
|
+
exports.isEmptyObj =
|
|
162
|
+
exports.coerceBoolean =
|
|
163
|
+
exports.coerceFloat =
|
|
164
|
+
exports.coerceInteger =
|
|
165
|
+
exports.ensurePresent =
|
|
166
|
+
exports.multipartFormRequestOptions =
|
|
167
|
+
exports.maybeMultipartFormRequestOptions =
|
|
168
|
+
exports.APIConnectionTimeoutError =
|
|
169
|
+
exports.APIConnectionError =
|
|
170
|
+
exports.InternalServerError =
|
|
171
|
+
exports.RateLimitError =
|
|
172
|
+
exports.UnprocessableEntityError =
|
|
173
|
+
exports.ConflictError =
|
|
174
|
+
exports.NotFoundError =
|
|
175
|
+
exports.PermissionDeniedError =
|
|
176
|
+
exports.AuthenticationError =
|
|
177
|
+
exports.BadRequestError =
|
|
178
|
+
exports.APIError =
|
|
179
|
+
exports.isRequestOptions =
|
|
180
|
+
exports.createResponseHeaders =
|
|
181
|
+
exports.Stream =
|
|
182
|
+
exports.PagePromise =
|
|
183
|
+
exports.AbstractPage =
|
|
184
|
+
exports.APIResource =
|
|
185
|
+
exports.APIClient =
|
|
186
|
+
void 0;
|
|
187
|
+
const qs_1 = __importDefault(require('qs'));
|
|
188
|
+
const formdata_node_1 = require('formdata-node');
|
|
189
|
+
const form_data_encoder_1 = require('form-data-encoder');
|
|
190
|
+
const stream_1 = require('stream');
|
|
191
|
+
const version_1 = require('./version');
|
|
192
|
+
const fetch_polyfill_1 = require('./fetch-polyfill');
|
|
193
|
+
class APIClient {
|
|
194
|
+
constructor({
|
|
195
|
+
baseURL,
|
|
196
|
+
maxRetries = 2,
|
|
197
|
+
timeout = 60 * 1000, // 60s
|
|
198
|
+
httpAgent,
|
|
199
|
+
}) {
|
|
200
|
+
this.baseURL = baseURL;
|
|
201
|
+
this.maxRetries = validatePositiveInteger('maxRetries', maxRetries);
|
|
202
|
+
this.timeout = validatePositiveInteger('timeout', timeout);
|
|
203
|
+
this.httpAgent = httpAgent;
|
|
204
|
+
this.fetch = (0, fetch_polyfill_1.getFetch)();
|
|
205
|
+
}
|
|
206
|
+
authHeaders() {
|
|
207
|
+
return {};
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Override this to add your own default headers, for example:
|
|
211
|
+
*
|
|
212
|
+
* {
|
|
213
|
+
* ...super.defaultHeaders(),
|
|
214
|
+
* Authorization: 'Bearer 123',
|
|
215
|
+
* }
|
|
216
|
+
*/
|
|
217
|
+
defaultHeaders() {
|
|
218
|
+
return Object.assign(
|
|
219
|
+
Object.assign(
|
|
220
|
+
{ Accept: 'application/json', 'Content-Type': 'application/json', 'User-Agent': this.getUserAgent() },
|
|
221
|
+
getPlatformHeaders(),
|
|
222
|
+
),
|
|
223
|
+
this.authHeaders(),
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Override this to add your own headers validation:
|
|
228
|
+
*/
|
|
229
|
+
validateHeaders(headers, customHeaders) {}
|
|
230
|
+
/**
|
|
231
|
+
* Override this to add your own qs.stringify options, for example:
|
|
232
|
+
*
|
|
233
|
+
* {
|
|
234
|
+
* ...super.qsOptions(),
|
|
235
|
+
* strictNullHandling: true,
|
|
236
|
+
* }
|
|
237
|
+
*/
|
|
238
|
+
qsOptions() {
|
|
239
|
+
return {};
|
|
240
|
+
}
|
|
241
|
+
defaultIdempotencyKey() {
|
|
242
|
+
return `stainless-node-retry-${uuid4()}`;
|
|
243
|
+
}
|
|
244
|
+
get(path, opts) {
|
|
245
|
+
return this.request(Object.assign({ method: 'get', path }, opts));
|
|
246
|
+
}
|
|
247
|
+
post(path, opts) {
|
|
248
|
+
return this.request(Object.assign({ method: 'post', path }, opts));
|
|
249
|
+
}
|
|
250
|
+
patch(path, opts) {
|
|
251
|
+
return this.request(Object.assign({ method: 'patch', path }, opts));
|
|
252
|
+
}
|
|
253
|
+
put(path, opts) {
|
|
254
|
+
return this.request(Object.assign({ method: 'put', path }, opts));
|
|
255
|
+
}
|
|
256
|
+
delete(path, opts) {
|
|
257
|
+
return this.request(Object.assign({ method: 'delete', path }, opts));
|
|
258
|
+
}
|
|
259
|
+
getAPIList(path, Page, opts) {
|
|
260
|
+
return this.requestAPIList(Page, Object.assign({ method: 'get', path }, opts));
|
|
261
|
+
}
|
|
262
|
+
buildRequest(options) {
|
|
263
|
+
var _a, _b, _c;
|
|
264
|
+
const { method, path, query, headers: headers = {} } = options;
|
|
265
|
+
const body =
|
|
266
|
+
options.body instanceof stream_1.Readable ? options.body
|
|
267
|
+
: options.body ? JSON.stringify(options.body, null, 2)
|
|
268
|
+
: null;
|
|
269
|
+
const contentLength = typeof body === 'string' ? body.length.toString() : null;
|
|
270
|
+
const url = this.buildURL(path, query);
|
|
271
|
+
const httpAgent = (
|
|
272
|
+
(_b = (_a = options.httpAgent) !== null && _a !== void 0 ? _a : this.httpAgent) !== null &&
|
|
273
|
+
_b !== void 0
|
|
274
|
+
) ?
|
|
275
|
+
_b
|
|
276
|
+
: (0, fetch_polyfill_1.getDefaultAgent)(url);
|
|
277
|
+
const timeout = (_c = options.timeout) !== null && _c !== void 0 ? _c : this.timeout;
|
|
278
|
+
validatePositiveInteger('timeout', timeout);
|
|
279
|
+
if (this.idempotencyHeader && method !== 'get') {
|
|
280
|
+
if (!options.idempotencyKey) options.idempotencyKey = this.defaultIdempotencyKey();
|
|
281
|
+
headers[this.idempotencyHeader] = options.idempotencyKey;
|
|
282
|
+
}
|
|
283
|
+
const reqHeaders = Object.assign(
|
|
284
|
+
Object.assign(
|
|
285
|
+
Object.assign({}, contentLength && { 'Content-Length': contentLength }),
|
|
286
|
+
this.defaultHeaders(),
|
|
287
|
+
),
|
|
288
|
+
headers,
|
|
289
|
+
);
|
|
290
|
+
// Strip any headers being explicitly omitted with null
|
|
291
|
+
Object.keys(reqHeaders).forEach((key) => reqHeaders[key] === null && delete reqHeaders[key]);
|
|
292
|
+
const req = Object.assign(
|
|
293
|
+
Object.assign(Object.assign({ method }, body && { body }), { headers: reqHeaders }),
|
|
294
|
+
httpAgent && { agent: httpAgent },
|
|
295
|
+
);
|
|
296
|
+
this.validateHeaders(reqHeaders, headers);
|
|
297
|
+
return { req, url, timeout };
|
|
298
|
+
}
|
|
299
|
+
request(options, retriesRemaining) {
|
|
300
|
+
var _a;
|
|
301
|
+
if (retriesRemaining === void 0) {
|
|
302
|
+
retriesRemaining = (_a = options.maxRetries) !== null && _a !== void 0 ? _a : this.maxRetries;
|
|
303
|
+
}
|
|
304
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
305
|
+
const { req, url, timeout } = this.buildRequest(options);
|
|
306
|
+
this.debug('request', url, options, req.headers);
|
|
307
|
+
const controller = new AbortController();
|
|
308
|
+
const response = yield this.fetchWithTimeout(url, req, timeout, controller).catch(castToError);
|
|
309
|
+
if (response instanceof Error) {
|
|
310
|
+
if (retriesRemaining) return this.retryRequest(options, retriesRemaining);
|
|
311
|
+
if (response.name === 'AbortError') throw new APIConnectionTimeoutError();
|
|
312
|
+
throw new APIConnectionError({ cause: response });
|
|
313
|
+
}
|
|
314
|
+
const responseHeaders = (0, exports.createResponseHeaders)(response.headers);
|
|
315
|
+
if (!response.ok) {
|
|
316
|
+
if (retriesRemaining && this.shouldRetry(response)) {
|
|
317
|
+
return this.retryRequest(options, retriesRemaining, responseHeaders);
|
|
318
|
+
}
|
|
319
|
+
const errText = yield response.text().catch(() => 'Unknown');
|
|
320
|
+
const errJSON = safeJSON(errText);
|
|
321
|
+
const errMessage = errJSON ? undefined : errText;
|
|
322
|
+
this.debug('response', response.status, url, responseHeaders, errMessage);
|
|
323
|
+
const err = APIError.generate(response.status, errJSON, errMessage, responseHeaders);
|
|
324
|
+
throw err;
|
|
325
|
+
}
|
|
326
|
+
if (options.stream) {
|
|
327
|
+
// TODO: see if any cast can be removed
|
|
328
|
+
return new Stream(response, controller);
|
|
329
|
+
}
|
|
330
|
+
const contentType = response.headers.get('content-type');
|
|
331
|
+
if (
|
|
332
|
+
contentType === null || contentType === void 0 ? void 0 : contentType.includes('application/json')
|
|
333
|
+
) {
|
|
334
|
+
const json = yield response.json();
|
|
335
|
+
if (typeof json === 'object' && json != null) {
|
|
336
|
+
/** @deprecated – we expect to change this interface in the near future. */
|
|
337
|
+
Object.defineProperty(json, 'responseHeaders', {
|
|
338
|
+
enumerable: false,
|
|
339
|
+
writable: false,
|
|
340
|
+
value: responseHeaders,
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
this.debug('response', response.status, url, responseHeaders, json);
|
|
344
|
+
return json;
|
|
345
|
+
}
|
|
346
|
+
// TODO handle blob, arraybuffer, other content types, etc.
|
|
347
|
+
const text = response.text();
|
|
348
|
+
this.debug('response', response.status, url, responseHeaders, text);
|
|
349
|
+
return text;
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
requestAPIList(Page, options) {
|
|
353
|
+
const requestPromise = this.request(options);
|
|
354
|
+
return new PagePromise(this, requestPromise, options, Page);
|
|
355
|
+
}
|
|
356
|
+
buildURL(path, query) {
|
|
357
|
+
const url = isAbsoluteURL(path) ? new URL(path) : new URL(this.baseURL + path);
|
|
358
|
+
if (query) {
|
|
359
|
+
url.search = qs_1.default.stringify(query, this.qsOptions());
|
|
360
|
+
}
|
|
361
|
+
return url.toString();
|
|
362
|
+
}
|
|
363
|
+
fetchWithTimeout(url, _a = {}, ms, controller) {
|
|
364
|
+
var { signal } = _a,
|
|
365
|
+
options = __rest(_a, ['signal']);
|
|
366
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
367
|
+
if (signal) signal.addEventListener('abort', controller.abort);
|
|
368
|
+
const timeout = setTimeout(() => controller.abort(), ms);
|
|
369
|
+
return this.getRequestClient()
|
|
370
|
+
.fetch(url, Object.assign({ signal: controller.signal }, options))
|
|
371
|
+
.finally(() => {
|
|
372
|
+
clearTimeout(timeout);
|
|
373
|
+
});
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
getRequestClient() {
|
|
377
|
+
return { fetch: this.fetch };
|
|
378
|
+
}
|
|
379
|
+
shouldRetry(response) {
|
|
380
|
+
// Note this is not a standard header.
|
|
381
|
+
const shouldRetryHeader = response.headers.get('x-should-retry');
|
|
382
|
+
// If the server explicitly says whether or not to retry, obey.
|
|
383
|
+
if (shouldRetryHeader === 'true') return true;
|
|
384
|
+
if (shouldRetryHeader === 'false') return false;
|
|
385
|
+
// Retry on lock timeouts.
|
|
386
|
+
if (response.status === 409) return true;
|
|
387
|
+
// Retry on rate limits.
|
|
388
|
+
if (response.status === 429) return true;
|
|
389
|
+
// Retry internal errors.
|
|
390
|
+
if (response.status >= 500) return true;
|
|
391
|
+
return false;
|
|
392
|
+
}
|
|
393
|
+
retryRequest(options, retriesRemaining, responseHeaders) {
|
|
394
|
+
var _a;
|
|
395
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
396
|
+
retriesRemaining -= 1;
|
|
397
|
+
// About the Retry-After header: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After
|
|
398
|
+
//
|
|
399
|
+
// TODO: we may want to handle the case where the header is using the http-date syntax: "Retry-After: <http-date>".
|
|
400
|
+
// See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After#syntax for details.
|
|
401
|
+
const retryAfter = parseInt(
|
|
402
|
+
(responseHeaders === null || responseHeaders === void 0 ? void 0 : responseHeaders['retry-after']) ||
|
|
403
|
+
'',
|
|
404
|
+
);
|
|
405
|
+
const maxRetries = (_a = options.maxRetries) !== null && _a !== void 0 ? _a : this.maxRetries;
|
|
406
|
+
const timeout = this.calculateRetryTimeoutSeconds(retriesRemaining, retryAfter, maxRetries) * 1000;
|
|
407
|
+
yield sleep(timeout);
|
|
408
|
+
return this.request(options, retriesRemaining);
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
calculateRetryTimeoutSeconds(retriesRemaining, retryAfter, maxRetries) {
|
|
412
|
+
const initialRetryDelay = 0.5;
|
|
413
|
+
const maxRetryDelay = 2;
|
|
414
|
+
// If the API asks us to wait a certain amount of time (and it's a reasonable amount),
|
|
415
|
+
// just do what it says.
|
|
416
|
+
if (Number.isInteger(retryAfter) && retryAfter <= 60) {
|
|
417
|
+
return retryAfter;
|
|
418
|
+
}
|
|
419
|
+
const numRetries = maxRetries - retriesRemaining;
|
|
420
|
+
// Apply exponential backoff, but not more than the max.
|
|
421
|
+
const sleepSeconds = Math.min(initialRetryDelay * Math.pow(numRetries - 1, 2), maxRetryDelay);
|
|
422
|
+
// Apply some jitter, plus-or-minus half a second.
|
|
423
|
+
const jitter = Math.random() - 0.5;
|
|
424
|
+
return sleepSeconds + jitter;
|
|
425
|
+
}
|
|
426
|
+
getUserAgent() {
|
|
427
|
+
return `${this.constructor.name}/JS ${version_1.VERSION}`;
|
|
428
|
+
}
|
|
429
|
+
debug(action, ...args) {
|
|
430
|
+
if (process.env['DEBUG'] === 'true') {
|
|
431
|
+
console.log(`${this.constructor.name}:DEBUG:${action}`, ...args);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
exports.APIClient = APIClient;
|
|
436
|
+
class APIResource {
|
|
437
|
+
constructor(client) {
|
|
438
|
+
this.client = client;
|
|
439
|
+
this.get = client.get.bind(client);
|
|
440
|
+
this.post = client.post.bind(client);
|
|
441
|
+
this.patch = client.patch.bind(client);
|
|
442
|
+
this.put = client.put.bind(client);
|
|
443
|
+
this.delete = client.delete.bind(client);
|
|
444
|
+
this.getAPIList = client.getAPIList.bind(client);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
exports.APIResource = APIResource;
|
|
448
|
+
class AbstractPage {
|
|
449
|
+
constructor(client, response, options) {
|
|
450
|
+
_AbstractPage_client.set(this, void 0);
|
|
451
|
+
__classPrivateFieldSet(this, _AbstractPage_client, client, 'f');
|
|
452
|
+
this.options = options;
|
|
453
|
+
}
|
|
454
|
+
hasNextPage() {
|
|
455
|
+
const items = this.getPaginatedItems();
|
|
456
|
+
if (!items.length) return false;
|
|
457
|
+
return this.nextPageInfo() != null;
|
|
458
|
+
}
|
|
459
|
+
getNextPage() {
|
|
460
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
461
|
+
const nextInfo = this.nextPageInfo();
|
|
462
|
+
if (!nextInfo) {
|
|
463
|
+
throw new Error(
|
|
464
|
+
'No next page expected; please check `.hasNextPage()` before calling `.getNextPage()`.',
|
|
465
|
+
);
|
|
466
|
+
}
|
|
467
|
+
const nextOptions = Object.assign({}, this.options);
|
|
468
|
+
if ('params' in nextInfo) {
|
|
469
|
+
nextOptions.query = Object.assign(Object.assign({}, nextOptions.query), nextInfo.params);
|
|
470
|
+
} else if ('url' in nextInfo) {
|
|
471
|
+
const params = [...Object.entries(nextOptions.query || {}), ...nextInfo.url.searchParams.entries()];
|
|
472
|
+
for (const [key, value] of params) {
|
|
473
|
+
nextInfo.url.searchParams.set(key, value);
|
|
474
|
+
}
|
|
475
|
+
nextOptions.query = undefined;
|
|
476
|
+
nextOptions.path = nextInfo.url.toString();
|
|
477
|
+
}
|
|
478
|
+
return yield __classPrivateFieldGet(this, _AbstractPage_client, 'f').requestAPIList(
|
|
479
|
+
this.constructor,
|
|
480
|
+
nextOptions,
|
|
481
|
+
);
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
iterPages() {
|
|
485
|
+
return __asyncGenerator(this, arguments, function* iterPages_1() {
|
|
486
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
487
|
+
let page = this;
|
|
488
|
+
yield yield __await(page);
|
|
489
|
+
while (page.hasNextPage()) {
|
|
490
|
+
page = yield __await(page.getNextPage());
|
|
491
|
+
yield yield __await(page);
|
|
492
|
+
}
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
[((_AbstractPage_client = new WeakMap()), Symbol.asyncIterator)]() {
|
|
496
|
+
return __asyncGenerator(this, arguments, function* _a() {
|
|
497
|
+
var _b, e_1, _c, _d;
|
|
498
|
+
try {
|
|
499
|
+
for (
|
|
500
|
+
var _e = true, _f = __asyncValues(this.iterPages()), _g;
|
|
501
|
+
(_g = yield __await(_f.next())), (_b = _g.done), !_b;
|
|
502
|
+
|
|
503
|
+
) {
|
|
504
|
+
_d = _g.value;
|
|
505
|
+
_e = false;
|
|
506
|
+
try {
|
|
507
|
+
const page = _d;
|
|
508
|
+
for (const item of page.getPaginatedItems()) {
|
|
509
|
+
yield yield __await(item);
|
|
510
|
+
}
|
|
511
|
+
} finally {
|
|
512
|
+
_e = true;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
} catch (e_1_1) {
|
|
516
|
+
e_1 = { error: e_1_1 };
|
|
517
|
+
} finally {
|
|
518
|
+
try {
|
|
519
|
+
if (!_e && !_b && (_c = _f.return)) yield __await(_c.call(_f));
|
|
520
|
+
} finally {
|
|
521
|
+
if (e_1) throw e_1.error;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
exports.AbstractPage = AbstractPage;
|
|
528
|
+
class PagePromise extends Promise {
|
|
529
|
+
/**
|
|
530
|
+
* This subclass of Promise will resolve to an instantiated Page once the request completes.
|
|
531
|
+
*/
|
|
532
|
+
constructor(client, requestPromise, options, Page) {
|
|
533
|
+
super((resolve, reject) =>
|
|
534
|
+
requestPromise.then((response) => resolve(new Page(client, response, options))).catch(reject),
|
|
535
|
+
);
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* Enable subclassing Promise.
|
|
539
|
+
* Ref: https://stackoverflow.com/a/60328122
|
|
540
|
+
*/
|
|
541
|
+
static get [Symbol.species]() {
|
|
542
|
+
return Promise;
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* Allow auto-paginating iteration on an unawaited list call, eg:
|
|
546
|
+
*
|
|
547
|
+
* for await (const item of client.items.list()) {
|
|
548
|
+
* console.log(item)
|
|
549
|
+
* }
|
|
550
|
+
*/
|
|
551
|
+
[Symbol.asyncIterator]() {
|
|
552
|
+
return __asyncGenerator(this, arguments, function* _a() {
|
|
553
|
+
var _b, e_2, _c, _d;
|
|
554
|
+
const page = yield __await(this);
|
|
555
|
+
try {
|
|
556
|
+
for (
|
|
557
|
+
var _e = true, page_1 = __asyncValues(page), page_1_1;
|
|
558
|
+
(page_1_1 = yield __await(page_1.next())), (_b = page_1_1.done), !_b;
|
|
559
|
+
|
|
560
|
+
) {
|
|
561
|
+
_d = page_1_1.value;
|
|
562
|
+
_e = false;
|
|
563
|
+
try {
|
|
564
|
+
const item = _d;
|
|
565
|
+
yield yield __await(item);
|
|
566
|
+
} finally {
|
|
567
|
+
_e = true;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
} catch (e_2_1) {
|
|
571
|
+
e_2 = { error: e_2_1 };
|
|
572
|
+
} finally {
|
|
573
|
+
try {
|
|
574
|
+
if (!_e && !_b && (_c = page_1.return)) yield __await(_c.call(page_1));
|
|
575
|
+
} finally {
|
|
576
|
+
if (e_2) throw e_2.error;
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
exports.PagePromise = PagePromise;
|
|
583
|
+
class Stream {
|
|
584
|
+
constructor(response, controller) {
|
|
585
|
+
this.response = response;
|
|
586
|
+
this.controller = controller;
|
|
587
|
+
this.responseHeaders = (0, exports.createResponseHeaders)(response.headers);
|
|
588
|
+
}
|
|
589
|
+
[Symbol.asyncIterator]() {
|
|
590
|
+
return __asyncGenerator(this, arguments, function* _a() {
|
|
591
|
+
var _b, e_3, _c, _d;
|
|
592
|
+
if (!this.response.body) {
|
|
593
|
+
// TODO: abort?
|
|
594
|
+
throw new Error(`Attempted to iterate over a response with no body`);
|
|
595
|
+
}
|
|
596
|
+
try {
|
|
597
|
+
for (
|
|
598
|
+
var _e = true, _f = __asyncValues(this.response.body), _g;
|
|
599
|
+
(_g = yield __await(_f.next())), (_b = _g.done), !_b;
|
|
600
|
+
|
|
601
|
+
) {
|
|
602
|
+
_d = _g.value;
|
|
603
|
+
_e = false;
|
|
604
|
+
try {
|
|
605
|
+
const chunk = _d;
|
|
606
|
+
let text;
|
|
607
|
+
if (chunk instanceof Buffer) {
|
|
608
|
+
text = chunk.toString();
|
|
609
|
+
} else {
|
|
610
|
+
text = chunk;
|
|
611
|
+
}
|
|
612
|
+
if (text.startsWith('data: ')) {
|
|
613
|
+
text = text.substring(6);
|
|
614
|
+
}
|
|
615
|
+
if (text.startsWith('[DONE]')) {
|
|
616
|
+
break;
|
|
617
|
+
}
|
|
618
|
+
yield yield __await(JSON.parse(text));
|
|
619
|
+
} finally {
|
|
620
|
+
_e = true;
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
} catch (e_3_1) {
|
|
624
|
+
e_3 = { error: e_3_1 };
|
|
625
|
+
} finally {
|
|
626
|
+
try {
|
|
627
|
+
if (!_e && !_b && (_c = _f.return)) yield __await(_c.call(_f));
|
|
628
|
+
} finally {
|
|
629
|
+
if (e_3) throw e_3.error;
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
this.controller.abort();
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
exports.Stream = Stream;
|
|
637
|
+
const createResponseHeaders = (headers) => {
|
|
638
|
+
return new Proxy(Object.fromEntries(headers.entries()), {
|
|
639
|
+
get(target, name) {
|
|
640
|
+
const key = name.toString();
|
|
641
|
+
return target[key.toLowerCase()] || target[key];
|
|
642
|
+
},
|
|
643
|
+
});
|
|
644
|
+
};
|
|
645
|
+
exports.createResponseHeaders = createResponseHeaders;
|
|
646
|
+
// This is required so that we can determine if a given object matches the RequestOptions
|
|
647
|
+
// type at runtime. While this requires duplication, it is enforced by the TypeScript
|
|
648
|
+
// compiler such that any missing / extraneous keys will cause an error.
|
|
649
|
+
const requestOptionsKeys = {
|
|
650
|
+
method: true,
|
|
651
|
+
path: true,
|
|
652
|
+
query: true,
|
|
653
|
+
body: true,
|
|
654
|
+
headers: true,
|
|
655
|
+
maxRetries: true,
|
|
656
|
+
stream: true,
|
|
657
|
+
timeout: true,
|
|
658
|
+
httpAgent: true,
|
|
659
|
+
idempotencyKey: true,
|
|
660
|
+
};
|
|
661
|
+
const isRequestOptions = (obj) => {
|
|
662
|
+
return (
|
|
663
|
+
typeof obj === 'object' &&
|
|
664
|
+
obj !== null &&
|
|
665
|
+
!isEmptyObj(obj) &&
|
|
666
|
+
Object.keys(obj).every((k) => hasOwn(requestOptionsKeys, k))
|
|
667
|
+
);
|
|
668
|
+
};
|
|
669
|
+
exports.isRequestOptions = isRequestOptions;
|
|
670
|
+
class APIError extends Error {
|
|
671
|
+
constructor(status, error, message, headers) {
|
|
672
|
+
super(message || (error === null || error === void 0 ? void 0 : error.message));
|
|
673
|
+
this.status = status;
|
|
674
|
+
this.headers = headers;
|
|
675
|
+
this.error = error;
|
|
676
|
+
}
|
|
677
|
+
static generate(status, error, message, headers) {
|
|
678
|
+
if (!status) return new APIConnectionError({ cause: castToError(error) });
|
|
679
|
+
if (status === 400) return new BadRequestError(status, error, message, headers);
|
|
680
|
+
if (status === 401) return new AuthenticationError(status, error, message, headers);
|
|
681
|
+
if (status === 403) return new PermissionDeniedError(status, error, message, headers);
|
|
682
|
+
if (status === 404) return new NotFoundError(status, error, message, headers);
|
|
683
|
+
if (status === 409) return new ConflictError(status, error, message, headers);
|
|
684
|
+
if (status === 422) return new UnprocessableEntityError(status, error, message, headers);
|
|
685
|
+
if (status === 429) return new RateLimitError(status, error, message, headers);
|
|
686
|
+
if (status >= 500) return new InternalServerError(status, error, message, headers);
|
|
687
|
+
return new APIError(status, error, message, headers);
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
exports.APIError = APIError;
|
|
691
|
+
class BadRequestError extends APIError {
|
|
692
|
+
constructor() {
|
|
693
|
+
super(...arguments);
|
|
694
|
+
this.status = 400;
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
exports.BadRequestError = BadRequestError;
|
|
698
|
+
class AuthenticationError extends APIError {
|
|
699
|
+
constructor() {
|
|
700
|
+
super(...arguments);
|
|
701
|
+
this.status = 401;
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
exports.AuthenticationError = AuthenticationError;
|
|
705
|
+
class PermissionDeniedError extends APIError {
|
|
706
|
+
constructor() {
|
|
707
|
+
super(...arguments);
|
|
708
|
+
this.status = 403;
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
exports.PermissionDeniedError = PermissionDeniedError;
|
|
712
|
+
class NotFoundError extends APIError {
|
|
713
|
+
constructor() {
|
|
714
|
+
super(...arguments);
|
|
715
|
+
this.status = 404;
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
exports.NotFoundError = NotFoundError;
|
|
719
|
+
class ConflictError extends APIError {
|
|
720
|
+
constructor() {
|
|
721
|
+
super(...arguments);
|
|
722
|
+
this.status = 409;
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
exports.ConflictError = ConflictError;
|
|
726
|
+
class UnprocessableEntityError extends APIError {
|
|
727
|
+
constructor() {
|
|
728
|
+
super(...arguments);
|
|
729
|
+
this.status = 422;
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
exports.UnprocessableEntityError = UnprocessableEntityError;
|
|
733
|
+
class RateLimitError extends APIError {
|
|
734
|
+
constructor() {
|
|
735
|
+
super(...arguments);
|
|
736
|
+
this.status = 429;
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
exports.RateLimitError = RateLimitError;
|
|
740
|
+
class InternalServerError extends APIError {}
|
|
741
|
+
exports.InternalServerError = InternalServerError;
|
|
742
|
+
class APIConnectionError extends APIError {
|
|
743
|
+
constructor({ message, cause }) {
|
|
744
|
+
super(undefined, undefined, message || 'Connection error.', undefined);
|
|
745
|
+
this.status = undefined;
|
|
746
|
+
// eslint-disable-next-line
|
|
747
|
+
// @ts-ignore
|
|
748
|
+
if (cause) this.cause = cause;
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
exports.APIConnectionError = APIConnectionError;
|
|
752
|
+
class APIConnectionTimeoutError extends APIConnectionError {
|
|
753
|
+
constructor() {
|
|
754
|
+
super({ message: 'Request timed out.' });
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
exports.APIConnectionTimeoutError = APIConnectionTimeoutError;
|
|
758
|
+
const getPlatformProperties = () => {
|
|
759
|
+
if (typeof Deno !== 'undefined' && Deno.build != null) {
|
|
760
|
+
return {
|
|
761
|
+
'X-Stainless-Lang': 'js',
|
|
762
|
+
'X-Stainless-Package-Version': version_1.VERSION,
|
|
763
|
+
'X-Stainless-OS': normalizePlatform(Deno.build.os),
|
|
764
|
+
'X-Stainless-Arch': normalizeArch(Deno.build.arch),
|
|
765
|
+
'X-Stainless-Runtime': 'deno',
|
|
766
|
+
'X-Stainless-Runtime-Version': Deno.version,
|
|
767
|
+
};
|
|
768
|
+
}
|
|
769
|
+
if (typeof process !== 'undefined') {
|
|
770
|
+
return {
|
|
771
|
+
'X-Stainless-Lang': 'js',
|
|
772
|
+
'X-Stainless-Package-Version': version_1.VERSION,
|
|
773
|
+
'X-Stainless-OS': normalizePlatform(process.platform),
|
|
774
|
+
'X-Stainless-Arch': normalizeArch(process.arch),
|
|
775
|
+
'X-Stainless-Runtime': 'node',
|
|
776
|
+
'X-Stainless-Runtime-Version': process.version,
|
|
777
|
+
};
|
|
778
|
+
}
|
|
779
|
+
// TODO add support for Cloudflare workers, browsers, etc.
|
|
780
|
+
return {
|
|
781
|
+
'X-Stainless-Lang': 'js',
|
|
782
|
+
'X-Stainless-Package-Version': version_1.VERSION,
|
|
783
|
+
'X-Stainless-OS': 'Unknown',
|
|
784
|
+
'X-Stainless-Arch': 'unknown',
|
|
785
|
+
'X-Stainless-Runtime': 'unknown',
|
|
786
|
+
'X-Stainless-Runtime-Version': 'unknown',
|
|
787
|
+
};
|
|
788
|
+
};
|
|
789
|
+
const normalizeArch = (arch) => {
|
|
790
|
+
// Node docs:
|
|
791
|
+
// - https://nodejs.org/api/process.html#processarch
|
|
792
|
+
// Deno docs:
|
|
793
|
+
// - https://doc.deno.land/deno/stable/~/Deno.build
|
|
794
|
+
if (arch === 'x32') return 'x32';
|
|
795
|
+
if (arch === 'x86_64' || arch === 'x64') return 'x64';
|
|
796
|
+
if (arch === 'arm') return 'arm';
|
|
797
|
+
if (arch === 'aarch64' || arch === 'arm64') return 'arm64';
|
|
798
|
+
if (arch) return `other:${arch}`;
|
|
799
|
+
return 'unknown';
|
|
800
|
+
};
|
|
801
|
+
const normalizePlatform = (platform) => {
|
|
802
|
+
// Node platforms:
|
|
803
|
+
// - https://nodejs.org/api/process.html#processplatform
|
|
804
|
+
// Deno platforms:
|
|
805
|
+
// - https://doc.deno.land/deno/stable/~/Deno.build
|
|
806
|
+
// - https://github.com/denoland/deno/issues/14799
|
|
807
|
+
platform = platform.toLowerCase();
|
|
808
|
+
// NOTE: this iOS check is untested and may not work
|
|
809
|
+
// Node does not work natively on IOS, there is a fork at
|
|
810
|
+
// https://github.com/nodejs-mobile/nodejs-mobile
|
|
811
|
+
// however it is unknown at the time of writing how to detect if it is running
|
|
812
|
+
if (platform.includes('ios')) return 'iOS';
|
|
813
|
+
if (platform === 'android') return 'Android';
|
|
814
|
+
if (platform === 'darwin') return 'MacOS';
|
|
815
|
+
if (platform === 'win32') return 'Windows';
|
|
816
|
+
if (platform === 'freebsd') return 'FreeBSD';
|
|
817
|
+
if (platform === 'openbsd') return 'OpenBSD';
|
|
818
|
+
if (platform === 'linux') return 'Linux';
|
|
819
|
+
if (platform) return `Other:${platform}`;
|
|
820
|
+
return 'Unknown';
|
|
821
|
+
};
|
|
822
|
+
let _platformHeaders;
|
|
823
|
+
const getPlatformHeaders = () => {
|
|
824
|
+
return _platformHeaders !== null && _platformHeaders !== void 0 ?
|
|
825
|
+
_platformHeaders
|
|
826
|
+
: (_platformHeaders = getPlatformProperties());
|
|
827
|
+
};
|
|
828
|
+
const safeJSON = (text) => {
|
|
829
|
+
try {
|
|
830
|
+
return JSON.parse(text);
|
|
831
|
+
} catch (err) {
|
|
832
|
+
return undefined;
|
|
833
|
+
}
|
|
834
|
+
};
|
|
835
|
+
// https://stackoverflow.com/a/19709846
|
|
836
|
+
const startsWithSchemeRegexp = new RegExp('^(?:[a-z]+:)?//', 'i');
|
|
837
|
+
const isAbsoluteURL = (url) => {
|
|
838
|
+
return startsWithSchemeRegexp.test(url);
|
|
839
|
+
};
|
|
840
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
841
|
+
const validatePositiveInteger = (name, n) => {
|
|
842
|
+
if (!Number.isInteger(n)) {
|
|
843
|
+
throw new Error(`${name} must be an integer`);
|
|
844
|
+
}
|
|
845
|
+
if (n < 0) {
|
|
846
|
+
throw new Error(`${name} must be a positive integer`);
|
|
847
|
+
}
|
|
848
|
+
return n;
|
|
849
|
+
};
|
|
850
|
+
const castToError = (err) => {
|
|
851
|
+
if (err instanceof Error) return err;
|
|
852
|
+
return new Error(err);
|
|
853
|
+
};
|
|
854
|
+
/**
|
|
855
|
+
* Returns a multipart/form-data request if any part of the given request body contains a File / Blob value.
|
|
856
|
+
* Otherwise returns the request as is.
|
|
857
|
+
*/
|
|
858
|
+
const maybeMultipartFormRequestOptions = (opts) => {
|
|
859
|
+
// TODO: does this add unreasonable overhead in the case where we shouldn't use multipart/form-data?
|
|
860
|
+
const form = createForm(opts.body);
|
|
861
|
+
for (const [_, entry] of form.entries()) {
|
|
862
|
+
const value = entry.valueOf();
|
|
863
|
+
if (value instanceof formdata_node_1.File || value instanceof formdata_node_1.Blob) {
|
|
864
|
+
return getMultipartRequestOptions(form, opts);
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
return opts;
|
|
868
|
+
};
|
|
869
|
+
exports.maybeMultipartFormRequestOptions = maybeMultipartFormRequestOptions;
|
|
870
|
+
const multipartFormRequestOptions = (opts) => {
|
|
871
|
+
return getMultipartRequestOptions(createForm(opts.body), opts);
|
|
872
|
+
};
|
|
873
|
+
exports.multipartFormRequestOptions = multipartFormRequestOptions;
|
|
874
|
+
const createForm = (body) => {
|
|
875
|
+
const form = new formdata_node_1.FormData();
|
|
876
|
+
Object.entries(body || {}).forEach(([key, value]) => addFormValue(form, key, value));
|
|
877
|
+
return form;
|
|
878
|
+
};
|
|
879
|
+
const getMultipartRequestOptions = (form, opts) => {
|
|
880
|
+
const encoder = new form_data_encoder_1.FormDataEncoder(form);
|
|
881
|
+
return Object.assign(Object.assign({}, opts), {
|
|
882
|
+
headers: Object.assign(Object.assign(Object.assign({}, opts.headers), encoder.headers), {
|
|
883
|
+
'Content-Length': encoder.contentLength,
|
|
884
|
+
}),
|
|
885
|
+
body: stream_1.Readable.from(encoder),
|
|
886
|
+
});
|
|
887
|
+
};
|
|
888
|
+
const addFormValue = (form, key, value) => {
|
|
889
|
+
if (value == null) {
|
|
890
|
+
throw new TypeError(
|
|
891
|
+
`null is not a valid form data value, if you want to pass null then you need to use the string 'null'`,
|
|
892
|
+
);
|
|
893
|
+
}
|
|
894
|
+
// TODO: make nested formats configurable
|
|
895
|
+
if (
|
|
896
|
+
typeof value === 'string' ||
|
|
897
|
+
typeof value === 'number' ||
|
|
898
|
+
typeof value === 'boolean' ||
|
|
899
|
+
value instanceof formdata_node_1.File ||
|
|
900
|
+
value instanceof formdata_node_1.Blob
|
|
901
|
+
) {
|
|
902
|
+
form.append(key, value);
|
|
903
|
+
} else if (Array.isArray(value)) {
|
|
904
|
+
value.forEach((entry) => {
|
|
905
|
+
addFormValue(form, key + '[]', entry);
|
|
906
|
+
});
|
|
907
|
+
} else if (typeof value === 'object') {
|
|
908
|
+
Object.entries(value).forEach(([name, prop]) => {
|
|
909
|
+
addFormValue(form, `${key}[${name}]`, prop);
|
|
910
|
+
});
|
|
911
|
+
} else {
|
|
912
|
+
throw new TypeError(
|
|
913
|
+
`Invalid value given to form, expected a string, number, boolean, object, Array, File or Blob but got ${value} instead`,
|
|
914
|
+
);
|
|
915
|
+
}
|
|
916
|
+
};
|
|
917
|
+
const ensurePresent = (value) => {
|
|
918
|
+
if (value == null) throw new Error(`Expected a value to be given but received ${value} instead.`);
|
|
919
|
+
return value;
|
|
920
|
+
};
|
|
921
|
+
exports.ensurePresent = ensurePresent;
|
|
922
|
+
const coerceInteger = (value) => {
|
|
923
|
+
if (typeof value === 'number') return Math.round(value);
|
|
924
|
+
if (typeof value === 'string') return parseInt(value, 10);
|
|
925
|
+
throw new Error(`Could not coerce ${value} (type: ${typeof value}) into a number`);
|
|
926
|
+
};
|
|
927
|
+
exports.coerceInteger = coerceInteger;
|
|
928
|
+
const coerceFloat = (value) => {
|
|
929
|
+
if (typeof value === 'number') return value;
|
|
930
|
+
if (typeof value === 'string') return parseFloat(value);
|
|
931
|
+
throw new Error(`Could not coerce ${value} (type: ${typeof value}) into a number`);
|
|
932
|
+
};
|
|
933
|
+
exports.coerceFloat = coerceFloat;
|
|
934
|
+
const coerceBoolean = (value) => {
|
|
935
|
+
if (typeof value === 'boolean') return value;
|
|
936
|
+
if (typeof value === 'string') return value === 'true';
|
|
937
|
+
return Boolean(value);
|
|
938
|
+
};
|
|
939
|
+
exports.coerceBoolean = coerceBoolean;
|
|
940
|
+
// https://stackoverflow.com/a/34491287
|
|
941
|
+
function isEmptyObj(obj) {
|
|
942
|
+
if (!obj) return true;
|
|
943
|
+
for (const _k in obj) return false;
|
|
944
|
+
return true;
|
|
945
|
+
}
|
|
946
|
+
exports.isEmptyObj = isEmptyObj;
|
|
947
|
+
// https://eslint.org/docs/latest/rules/no-prototype-builtins
|
|
948
|
+
function hasOwn(obj, key) {
|
|
949
|
+
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
950
|
+
}
|
|
951
|
+
exports.hasOwn = hasOwn;
|
|
952
|
+
/**
|
|
953
|
+
* https://stackoverflow.com/a/2117523
|
|
954
|
+
*/
|
|
955
|
+
const uuid4 = () => {
|
|
956
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
|
957
|
+
const r = (Math.random() * 16) | 0;
|
|
958
|
+
const v = c === 'x' ? r : (r & 0x3) | 0x8;
|
|
959
|
+
return v.toString(16);
|
|
960
|
+
});
|
|
961
|
+
};
|
|
962
|
+
const isHeadersProtocol = (headers) => {
|
|
963
|
+
return typeof (headers === null || headers === void 0 ? void 0 : headers.get) === 'function';
|
|
964
|
+
};
|
|
965
|
+
exports.isHeadersProtocol = isHeadersProtocol;
|
|
966
|
+
const getHeader = (headers, key) => {
|
|
967
|
+
const lowerKey = key.toLowerCase();
|
|
968
|
+
if ((0, exports.isHeadersProtocol)(headers)) return headers.get(key) || headers.get(lowerKey);
|
|
969
|
+
const value = headers[key] || headers[lowerKey];
|
|
970
|
+
if (Array.isArray(value)) {
|
|
971
|
+
if (value.length <= 1) return value[0];
|
|
972
|
+
console.warn(`Received ${value.length} entries for the ${key} header, using the first entry.`);
|
|
973
|
+
return value[0];
|
|
974
|
+
}
|
|
975
|
+
return value;
|
|
976
|
+
};
|
|
977
|
+
exports.getHeader = getHeader;
|
|
978
|
+
//# sourceMappingURL=core.js.map
|