modern-treasury 2.6.0 → 2.7.2
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/CHANGELOG.md +33 -0
- package/README.md +8 -4
- package/_shims/MultipartBody.d.ts +9 -0
- package/_shims/MultipartBody.d.ts.map +1 -0
- package/_shims/MultipartBody.js +16 -0
- package/_shims/MultipartBody.js.map +1 -0
- package/_shims/MultipartBody.mjs +12 -0
- package/_shims/MultipartBody.mjs.map +1 -0
- package/_shims/README.md +46 -0
- package/{src/_shims/ReadableStream-node.ts → _shims/auto/runtime-bun.d.ts} +2 -3
- package/_shims/auto/runtime-bun.d.ts.map +1 -0
- package/_shims/auto/runtime-bun.js +21 -0
- package/_shims/auto/runtime-bun.js.map +1 -0
- package/_shims/auto/runtime-bun.mjs +2 -0
- package/_shims/auto/runtime-bun.mjs.map +1 -0
- package/_shims/auto/runtime-node.d.ts +5 -0
- package/_shims/auto/runtime-node.d.ts.map +1 -0
- package/_shims/auto/runtime-node.js +21 -0
- package/_shims/auto/runtime-node.js.map +1 -0
- package/_shims/auto/runtime-node.mjs +2 -0
- package/_shims/auto/runtime-node.mjs.map +1 -0
- package/_shims/auto/runtime.d.ts +5 -0
- package/_shims/auto/runtime.d.ts.map +1 -0
- package/_shims/auto/runtime.js +21 -0
- package/_shims/auto/runtime.js.map +1 -0
- package/_shims/auto/runtime.mjs +2 -0
- package/_shims/auto/runtime.mjs.map +1 -0
- package/_shims/auto/types-node.d.ts +5 -0
- package/_shims/auto/types-node.d.ts.map +1 -0
- package/_shims/auto/types-node.js +21 -0
- package/_shims/auto/types-node.js.map +1 -0
- package/_shims/auto/types-node.mjs +2 -0
- package/_shims/auto/types-node.mjs.map +1 -0
- package/_shims/auto/types.d.ts +99 -0
- package/_shims/{ReadableStream.js → auto/types.js} +0 -2
- package/{src/_shims/ReadableStream.js → _shims/auto/types.mjs} +0 -2
- package/_shims/bun-runtime.d.ts +6 -0
- package/_shims/bun-runtime.d.ts.map +1 -0
- package/_shims/bun-runtime.js +14 -0
- package/_shims/bun-runtime.js.map +1 -0
- package/_shims/bun-runtime.mjs +10 -0
- package/_shims/bun-runtime.mjs.map +1 -0
- package/_shims/index.d.ts +79 -0
- package/_shims/index.js +13 -0
- package/_shims/index.mjs +7 -0
- package/_shims/manual-types.d.ts +12 -0
- package/_shims/manual-types.js +3 -0
- package/_shims/manual-types.mjs +3 -0
- package/_shims/node-runtime.d.ts +3 -0
- package/_shims/node-runtime.d.ts.map +1 -0
- package/_shims/node-runtime.js +87 -0
- package/_shims/node-runtime.js.map +1 -0
- package/_shims/node-runtime.mjs +54 -0
- package/_shims/node-runtime.mjs.map +1 -0
- package/_shims/node-types.d.ts +42 -0
- package/_shims/node-types.js +3 -0
- package/_shims/node-types.mjs +3 -0
- package/_shims/registry.d.ts +35 -0
- package/_shims/registry.d.ts.map +1 -0
- package/_shims/registry.js +39 -0
- package/_shims/registry.js.map +1 -0
- package/_shims/registry.mjs +35 -0
- package/_shims/registry.mjs.map +1 -0
- package/_shims/web-runtime.d.ts +5 -0
- package/_shims/web-runtime.d.ts.map +1 -0
- package/_shims/web-runtime.js +70 -0
- package/_shims/web-runtime.js.map +1 -0
- package/_shims/web-runtime.mjs +63 -0
- package/_shims/web-runtime.mjs.map +1 -0
- package/_shims/web-types.d.ts +82 -0
- package/_shims/web-types.js +3 -0
- package/_shims/web-types.mjs +3 -0
- package/core.d.ts +170 -223
- package/core.d.ts.map +1 -1
- package/core.js +678 -731
- package/core.js.map +1 -1
- package/core.mjs +672 -682
- package/core.mjs.map +1 -1
- package/error.d.ts +32 -32
- package/error.d.ts.map +1 -1
- package/error.js +95 -106
- package/error.js.map +1 -1
- package/error.mjs +91 -91
- package/error.mjs.map +1 -1
- package/index.d.mts +323 -333
- package/index.d.ts +323 -333
- package/index.d.ts.map +1 -1
- package/index.js +190 -243
- package/index.js.map +1 -1
- package/index.mjs +167 -190
- package/index.mjs.map +1 -1
- package/package.json +32 -58
- package/pagination.d.ts +11 -11
- package/pagination.js +30 -26
- package/pagination.mjs +28 -24
- package/resource.d.ts +10 -10
- package/resource.js +12 -12
- package/resource.mjs +10 -10
- package/resources/account-collection-flows.d.ts +71 -116
- package/resources/account-collection-flows.js +52 -62
- package/resources/account-collection-flows.js.map +1 -1
- package/resources/account-collection-flows.mjs +47 -55
- package/resources/account-collection-flows.mjs.map +1 -1
- package/resources/account-details.d.ts +59 -81
- package/resources/account-details.js +47 -50
- package/resources/account-details.js.map +1 -1
- package/resources/account-details.mjs +42 -45
- package/resources/account-details.mjs.map +1 -1
- package/resources/connections.d.ts +42 -44
- package/resources/connections.js +15 -13
- package/resources/connections.mjs +10 -8
- package/resources/counterparties.d.ts +400 -466
- package/resources/counterparties.js +63 -71
- package/resources/counterparties.js.map +1 -1
- package/resources/counterparties.mjs +58 -66
- package/resources/counterparties.mjs.map +1 -1
- package/resources/documents.d.ts +88 -120
- package/resources/documents.js +36 -42
- package/resources/documents.js.map +1 -1
- package/resources/documents.mjs +30 -36
- package/resources/documents.mjs.map +1 -1
- package/resources/events.d.ts +56 -55
- package/resources/events.js +21 -19
- package/resources/events.mjs +16 -14
- package/resources/expected-payments.d.ts +321 -373
- package/resources/expected-payments.js +46 -51
- package/resources/expected-payments.js.map +1 -1
- package/resources/expected-payments.mjs +41 -44
- package/resources/expected-payments.mjs.map +1 -1
- package/resources/external-accounts.d.ts +295 -373
- package/resources/external-accounts.js +76 -91
- package/resources/external-accounts.js.map +1 -1
- package/resources/external-accounts.mjs +71 -84
- package/resources/external-accounts.mjs.map +1 -1
- package/resources/incoming-payment-details.d.ts +200 -222
- package/resources/incoming-payment-details.js +42 -47
- package/resources/incoming-payment-details.js.map +1 -1
- package/resources/incoming-payment-details.mjs +37 -40
- package/resources/incoming-payment-details.mjs.map +1 -1
- package/resources/index.d.ts +35 -212
- package/resources/index.js +111 -484
- package/resources/index.mjs +34 -37
- package/resources/internal-accounts/balance-reports.d.ts +74 -113
- package/resources/internal-accounts/balance-reports.js +21 -23
- package/resources/internal-accounts/balance-reports.mjs +16 -18
- package/resources/internal-accounts/index.d.ts +3 -15
- package/resources/internal-accounts/index.js +10 -34
- package/resources/internal-accounts/index.mjs +3 -3
- package/resources/internal-accounts/internal-accounts.d.ts +203 -233
- package/resources/internal-accounts/internal-accounts.js +65 -86
- package/resources/internal-accounts/internal-accounts.js.map +1 -1
- package/resources/internal-accounts/internal-accounts.mjs +41 -45
- package/resources/internal-accounts/internal-accounts.mjs.map +1 -1
- package/resources/invoices/index.d.ts +3 -17
- package/resources/invoices/index.js +9 -29
- package/resources/invoices/index.mjs +3 -3
- package/resources/invoices/invoices.d.ts +509 -549
- package/resources/invoices/invoices.js +74 -95
- package/resources/invoices/invoices.js.map +1 -1
- package/resources/invoices/invoices.mjs +50 -54
- package/resources/invoices/invoices.mjs.map +1 -1
- package/resources/invoices/line-items.d.ts +119 -133
- package/resources/invoices/line-items.js +49 -52
- package/resources/invoices/line-items.js.map +1 -1
- package/resources/invoices/line-items.mjs +44 -47
- package/resources/invoices/line-items.mjs.map +1 -1
- package/resources/ledger-account-balance-monitors.d.ts +213 -224
- package/resources/ledger-account-balance-monitors.js +49 -55
- package/resources/ledger-account-balance-monitors.js.map +1 -1
- package/resources/ledger-account-balance-monitors.mjs +44 -49
- package/resources/ledger-account-balance-monitors.mjs.map +1 -1
- package/resources/ledger-account-categories.d.ts +255 -276
- package/resources/ledger-account-categories.js +84 -89
- package/resources/ledger-account-categories.js.map +1 -1
- package/resources/ledger-account-categories.mjs +79 -82
- package/resources/ledger-account-categories.mjs.map +1 -1
- package/resources/ledger-account-payouts.d.ts +151 -160
- package/resources/ledger-account-payouts.js +45 -50
- package/resources/ledger-account-payouts.js.map +1 -1
- package/resources/ledger-account-payouts.mjs +40 -43
- package/resources/ledger-account-payouts.mjs.map +1 -1
- package/resources/ledger-account-statements.d.ts +455 -461
- package/resources/ledger-account-statements.js +26 -32
- package/resources/ledger-account-statements.js.map +1 -1
- package/resources/ledger-account-statements.mjs +23 -27
- package/resources/ledger-account-statements.mjs.map +1 -1
- package/resources/ledger-accounts.d.ts +347 -357
- package/resources/ledger-accounts.js +45 -48
- package/resources/ledger-accounts.js.map +1 -1
- package/resources/ledger-accounts.mjs +40 -43
- package/resources/ledger-accounts.mjs.map +1 -1
- package/resources/ledger-entries.d.ts +244 -250
- package/resources/ledger-entries.js +20 -18
- package/resources/ledger-entries.mjs +15 -13
- package/resources/ledger-event-handlers.d.ts +369 -376
- package/resources/ledger-event-handlers.js +44 -49
- package/resources/ledger-event-handlers.js.map +1 -1
- package/resources/ledger-event-handlers.mjs +39 -42
- package/resources/ledger-event-handlers.mjs.map +1 -1
- package/resources/ledger-transactions/index.d.ts +3 -16
- package/resources/ledger-transactions/index.js +10 -34
- package/resources/ledger-transactions/index.mjs +3 -3
- package/resources/ledger-transactions/ledger-transactions.d.ts +335 -389
- package/resources/ledger-transactions/ledger-transactions.js +70 -91
- package/resources/ledger-transactions/ledger-transactions.js.map +1 -1
- package/resources/ledger-transactions/ledger-transactions.mjs +46 -50
- package/resources/ledger-transactions/ledger-transactions.mjs.map +1 -1
- package/resources/ledger-transactions/versions.d.ts +199 -214
- package/resources/ledger-transactions/versions.js +18 -16
- package/resources/ledger-transactions/versions.mjs +13 -11
- package/resources/ledgerable-events.d.ts +96 -99
- package/resources/ledgerable-events.js +27 -33
- package/resources/ledgerable-events.js.map +1 -1
- package/resources/ledgerable-events.mjs +24 -28
- package/resources/ledgerable-events.mjs.map +1 -1
- package/resources/ledgers.d.ts +98 -97
- package/resources/ledgers.js +46 -49
- package/resources/ledgers.js.map +1 -1
- package/resources/ledgers.mjs +41 -44
- package/resources/ledgers.mjs.map +1 -1
- package/resources/line-items.d.ts +78 -101
- package/resources/line-items.js +29 -27
- package/resources/line-items.mjs +24 -22
- package/resources/paper-items.d.ts +91 -93
- package/resources/paper-items.js +21 -19
- package/resources/paper-items.mjs +16 -14
- package/resources/payment-flows.d.ts +132 -138
- package/resources/payment-flows.js +49 -57
- package/resources/payment-flows.js.map +1 -1
- package/resources/payment-flows.mjs +44 -52
- package/resources/payment-flows.mjs.map +1 -1
- package/resources/payment-orders/index.d.ts +3 -13
- package/resources/payment-orders/index.js +9 -29
- package/resources/payment-orders/index.mjs +3 -3
- package/resources/payment-orders/payment-orders.d.ts +1416 -1696
- package/resources/payment-orders/payment-orders.js +80 -109
- package/resources/payment-orders/payment-orders.js.map +1 -1
- package/resources/payment-orders/payment-orders.mjs +55 -67
- package/resources/payment-orders/payment-orders.mjs.map +1 -1
- package/resources/payment-orders/reversals.d.ts +153 -183
- package/resources/payment-orders/reversals.js +38 -41
- package/resources/payment-orders/reversals.js.map +1 -1
- package/resources/payment-orders/reversals.mjs +33 -36
- package/resources/payment-orders/reversals.mjs.map +1 -1
- package/resources/payment-references.d.ts +61 -118
- package/resources/payment-references.js +26 -26
- package/resources/payment-references.mjs +21 -19
- package/resources/returns.d.ts +167 -324
- package/resources/returns.js +35 -38
- package/resources/returns.js.map +1 -1
- package/resources/returns.mjs +30 -33
- package/resources/returns.mjs.map +1 -1
- package/resources/routing-details.d.ts +83 -173
- package/resources/routing-details.js +47 -50
- package/resources/routing-details.js.map +1 -1
- package/resources/routing-details.mjs +42 -45
- package/resources/routing-details.mjs.map +1 -1
- package/resources/shared.d.ts +4 -194
- package/resources/shared.js +3 -3
- package/resources/shared.mjs +1 -1
- package/resources/top-level.d.ts +4 -4
- package/resources/top-level.js +5 -4
- package/resources/top-level.mjs +3 -2
- package/resources/transactions/index.d.ts +3 -14
- package/resources/transactions/index.js +10 -34
- package/resources/transactions/index.mjs +3 -3
- package/resources/transactions/line-items.d.ts +69 -78
- package/resources/transactions/line-items.js +21 -19
- package/resources/transactions/line-items.mjs +16 -14
- package/resources/transactions/transactions.d.ts +163 -211
- package/resources/transactions/transactions.js +51 -67
- package/resources/transactions/transactions.mjs +27 -26
- package/resources/validations.d.ts +67 -111
- package/resources/validations.js +13 -12
- package/resources/validations.mjs +10 -9
- package/resources/virtual-accounts.d.ts +161 -201
- package/resources/virtual-accounts.js +46 -51
- package/resources/virtual-accounts.js.map +1 -1
- package/resources/virtual-accounts.mjs +41 -44
- package/resources/virtual-accounts.mjs.map +1 -1
- package/resources/webhooks.d.ts +21 -28
- package/resources/webhooks.js +35 -37
- package/resources/webhooks.js.map +1 -1
- package/resources/webhooks.mjs +30 -31
- package/resources/webhooks.mjs.map +1 -1
- package/shims/node.d.ts +29 -0
- package/shims/node.d.ts.map +1 -0
- package/shims/node.js +31 -0
- package/shims/node.js.map +1 -0
- package/shims/node.mjs +5 -0
- package/shims/node.mjs.map +1 -0
- package/shims/web.d.ts +26 -0
- package/shims/web.d.ts.map +1 -0
- package/shims/web.js +31 -0
- package/shims/web.js.map +1 -0
- package/shims/web.mjs +5 -0
- package/shims/web.mjs.map +1 -0
- package/src/_shims/MultipartBody.ts +9 -0
- package/src/_shims/README.md +46 -0
- package/src/_shims/auto/runtime-bun.ts +4 -0
- package/src/_shims/auto/runtime-node.ts +4 -0
- package/src/_shims/auto/runtime.ts +4 -0
- package/src/_shims/auto/types-node.ts +4 -0
- package/src/_shims/auto/types.d.ts +99 -0
- package/src/_shims/auto/types.js +3 -0
- package/src/_shims/auto/types.mjs +3 -0
- package/src/_shims/bun-runtime.ts +14 -0
- package/src/_shims/index.d.ts +79 -0
- package/src/_shims/index.js +13 -0
- package/src/_shims/index.mjs +7 -0
- package/src/_shims/manual-types.d.ts +12 -0
- package/src/_shims/manual-types.js +3 -0
- package/src/_shims/manual-types.mjs +3 -0
- package/src/_shims/node-runtime.ts +79 -0
- package/src/_shims/node-types.d.ts +42 -0
- package/src/_shims/node-types.js +3 -0
- package/src/_shims/node-types.mjs +3 -0
- package/src/_shims/registry.ts +64 -0
- package/src/_shims/web-runtime.ts +91 -0
- package/src/_shims/web-types.d.ts +82 -0
- package/src/_shims/web-types.js +3 -0
- package/src/_shims/web-types.mjs +3 -0
- package/src/core.ts +72 -43
- package/src/error.ts +4 -2
- package/src/index.ts +10 -8
- package/src/pagination.ts +1 -1
- package/src/resource.ts +1 -1
- package/src/resources/account-collection-flows.ts +5 -5
- package/src/resources/account-details.ts +6 -6
- package/src/resources/connections.ts +5 -5
- package/src/resources/counterparties.ts +8 -8
- package/src/resources/documents.ts +6 -6
- package/src/resources/events.ts +5 -5
- package/src/resources/expected-payments.ts +6 -6
- package/src/resources/external-accounts.ts +8 -8
- package/src/resources/incoming-payment-details.ts +7 -7
- package/src/resources/index.ts +34 -40
- package/src/resources/internal-accounts/balance-reports.ts +6 -6
- package/src/resources/internal-accounts/index.ts +2 -2
- package/src/resources/internal-accounts/internal-accounts.ts +10 -10
- package/src/resources/invoices/index.ts +2 -2
- package/src/resources/invoices/invoices.ts +8 -8
- package/src/resources/invoices/line-items.ts +5 -5
- package/src/resources/ledger-account-balance-monitors.ts +5 -5
- package/src/resources/ledger-account-categories.ts +5 -5
- package/src/resources/ledger-account-payouts.ts +5 -5
- package/src/resources/ledger-account-statements.ts +3 -3
- package/src/resources/ledger-accounts.ts +5 -5
- package/src/resources/ledger-entries.ts +5 -5
- package/src/resources/ledger-event-handlers.ts +5 -5
- package/src/resources/ledger-transactions/index.ts +2 -2
- package/src/resources/ledger-transactions/ledger-transactions.ts +7 -7
- package/src/resources/ledger-transactions/versions.ts +5 -5
- package/src/resources/ledgerable-events.ts +3 -3
- package/src/resources/ledgers.ts +5 -5
- package/src/resources/line-items.ts +5 -5
- package/src/resources/paper-items.ts +6 -6
- package/src/resources/payment-flows.ts +5 -5
- package/src/resources/payment-orders/index.ts +2 -2
- package/src/resources/payment-orders/payment-orders.ts +10 -10
- package/src/resources/payment-orders/reversals.ts +5 -5
- package/src/resources/payment-references.ts +5 -5
- package/src/resources/returns.ts +6 -6
- package/src/resources/routing-details.ts +6 -6
- package/src/resources/top-level.ts +1 -1
- package/src/resources/transactions/index.ts +2 -7
- package/src/resources/transactions/line-items.ts +5 -5
- package/src/resources/transactions/transactions.ts +7 -7
- package/src/resources/validations.ts +3 -3
- package/src/resources/virtual-accounts.ts +7 -7
- package/src/resources/webhooks.ts +3 -3
- package/src/shims/node.ts +50 -0
- package/src/shims/web.ts +50 -0
- package/src/uploads.ts +12 -16
- package/src/version.ts +1 -1
- package/uploads.d.ts +23 -39
- package/uploads.d.ts.map +1 -1
- package/uploads.js +111 -157
- package/uploads.js.map +1 -1
- package/uploads.mjs +107 -133
- package/uploads.mjs.map +1 -1
- package/version.d.ts +2 -2
- package/version.js +4 -4
- package/version.mjs +2 -2
- package/_shims/ReadableStream-node.d.ts +0 -6
- package/_shims/ReadableStream-node.d.ts.map +0 -1
- package/_shims/ReadableStream-node.js +0 -14
- package/_shims/ReadableStream-node.js.map +0 -1
- package/_shims/ReadableStream-node.mjs +0 -3
- package/_shims/ReadableStream-node.mjs.map +0 -1
- package/_shims/ReadableStream.d.ts +0 -38
- package/_shims/ReadableStream.mjs +0 -7
- package/_shims/agent-node.d.ts +0 -7
- package/_shims/agent-node.d.ts.map +0 -1
- package/_shims/agent-node.js +0 -28
- package/_shims/agent-node.js.map +0 -1
- package/_shims/agent-node.mjs +0 -16
- package/_shims/agent-node.mjs.map +0 -1
- package/_shims/agent.d.ts +0 -9
- package/_shims/agent.d.ts.map +0 -1
- package/_shims/agent.js +0 -14
- package/_shims/agent.js.map +0 -1
- package/_shims/agent.mjs +0 -10
- package/_shims/agent.mjs.map +0 -1
- package/_shims/fetch-node.d.ts +0 -64
- package/_shims/fetch-node.js +0 -12
- package/_shims/fetch-node.mjs +0 -14
- package/_shims/fetch.d.ts +0 -60
- package/_shims/fetch.js +0 -13
- package/_shims/fetch.mjs +0 -15
- package/_shims/fileFromPath-node.d.ts +0 -17
- package/_shims/fileFromPath-node.d.ts.map +0 -1
- package/_shims/fileFromPath-node.js +0 -17
- package/_shims/fileFromPath-node.js.map +0 -1
- package/_shims/fileFromPath-node.mjs +0 -13
- package/_shims/fileFromPath-node.mjs.map +0 -1
- package/_shims/fileFromPath.d.ts +0 -22
- package/_shims/fileFromPath.d.ts.map +0 -1
- package/_shims/fileFromPath.js +0 -16
- package/_shims/fileFromPath.js.map +0 -1
- package/_shims/fileFromPath.mjs +0 -12
- package/_shims/fileFromPath.mjs.map +0 -1
- package/_shims/form-data-node.d.ts +0 -45
- package/_shims/form-data-node.js +0 -11
- package/_shims/form-data-node.mjs +0 -9
- package/_shims/form-data.d.ts +0 -43
- package/_shims/form-data.js +0 -17
- package/_shims/form-data.mjs +0 -20
- package/_shims/getMultipartRequestOptions-node.d.ts +0 -10
- package/_shims/getMultipartRequestOptions-node.d.ts.map +0 -1
- package/_shims/getMultipartRequestOptions-node.js +0 -22
- package/_shims/getMultipartRequestOptions-node.js.map +0 -1
- package/_shims/getMultipartRequestOptions-node.mjs +0 -18
- package/_shims/getMultipartRequestOptions-node.mjs.map +0 -1
- package/_shims/getMultipartRequestOptions.d.ts +0 -10
- package/_shims/getMultipartRequestOptions.d.ts.map +0 -1
- package/_shims/getMultipartRequestOptions.js +0 -12
- package/_shims/getMultipartRequestOptions.js.map +0 -1
- package/_shims/getMultipartRequestOptions.mjs +0 -8
- package/_shims/getMultipartRequestOptions.mjs.map +0 -1
- package/_shims/node-readable-node.d.ts +0 -8
- package/_shims/node-readable-node.d.ts.map +0 -1
- package/_shims/node-readable-node.js +0 -9
- package/_shims/node-readable-node.js.map +0 -1
- package/_shims/node-readable-node.mjs +0 -5
- package/_shims/node-readable-node.mjs.map +0 -1
- package/_shims/node-readable.d.ts +0 -23
- package/_shims/node-readable.d.ts.map +0 -1
- package/_shims/node-readable.js +0 -11
- package/_shims/node-readable.js.map +0 -1
- package/_shims/node-readable.mjs +0 -7
- package/_shims/node-readable.mjs.map +0 -1
- package/src/_shims/ReadableStream.d.ts +0 -38
- package/src/_shims/ReadableStream.mjs +0 -7
- package/src/_shims/agent-node.ts +0 -22
- package/src/_shims/agent.ts +0 -12
- package/src/_shims/fetch-node.d.ts +0 -64
- package/src/_shims/fetch-node.js +0 -12
- package/src/_shims/fetch-node.mjs +0 -14
- package/src/_shims/fetch.d.ts +0 -60
- package/src/_shims/fetch.js +0 -13
- package/src/_shims/fetch.mjs +0 -15
- package/src/_shims/fileFromPath-node.ts +0 -29
- package/src/_shims/fileFromPath.ts +0 -29
- package/src/_shims/form-data-node.d.ts +0 -45
- package/src/_shims/form-data-node.js +0 -11
- package/src/_shims/form-data-node.mjs +0 -9
- package/src/_shims/form-data.d.ts +0 -43
- package/src/_shims/form-data.js +0 -17
- package/src/_shims/form-data.mjs +0 -20
- package/src/_shims/getMultipartRequestOptions-node.ts +0 -25
- package/src/_shims/getMultipartRequestOptions.ts +0 -14
- package/src/_shims/node-readable-node.ts +0 -10
- package/src/_shims/node-readable.ts +0 -30
package/core.js
CHANGED
|
@@ -1,517 +1,454 @@
|
|
|
1
|
-
|
|
2
|
-
var __classPrivateFieldSet =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
value
|
|
14
|
-
);
|
|
15
|
-
};
|
|
16
|
-
var __classPrivateFieldGet =
|
|
17
|
-
(this && this.__classPrivateFieldGet) ||
|
|
18
|
-
function (receiver, state, kind, f) {
|
|
19
|
-
if (kind === 'a' && !f) throw new TypeError('Private accessor was defined without a getter');
|
|
20
|
-
if (typeof state === 'function' ? receiver !== state || !f : !state.has(receiver))
|
|
21
|
-
throw new TypeError('Cannot read private member from an object whose class did not declare it');
|
|
22
|
-
return (
|
|
23
|
-
kind === 'm' ? f
|
|
24
|
-
: kind === 'a' ? f.call(receiver)
|
|
25
|
-
: f ? f.value
|
|
26
|
-
: state.get(receiver)
|
|
27
|
-
);
|
|
28
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
29
13
|
var _AbstractPage_client;
|
|
30
|
-
Object.defineProperty(exports,
|
|
31
|
-
exports.toBase64 =
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
exports.maybeCoerceInteger =
|
|
41
|
-
exports.coerceBoolean =
|
|
42
|
-
exports.coerceFloat =
|
|
43
|
-
exports.coerceInteger =
|
|
44
|
-
exports.readEnv =
|
|
45
|
-
exports.ensurePresent =
|
|
46
|
-
exports.castToError =
|
|
47
|
-
exports.sleep =
|
|
48
|
-
exports.safeJSON =
|
|
49
|
-
exports.isRequestOptions =
|
|
50
|
-
exports.createResponseHeaders =
|
|
51
|
-
exports.PagePromise =
|
|
52
|
-
exports.AbstractPage =
|
|
53
|
-
exports.APIResource =
|
|
54
|
-
exports.APIClient =
|
|
55
|
-
exports.APIPromise =
|
|
56
|
-
exports.createForm =
|
|
57
|
-
exports.multipartFormRequestOptions =
|
|
58
|
-
exports.maybeMultipartFormRequestOptions =
|
|
59
|
-
void 0;
|
|
60
|
-
const version_1 = require('./version.js');
|
|
61
|
-
const error_1 = require('./error.js');
|
|
62
|
-
const agent_1 = require('modern-treasury/_shims/agent');
|
|
63
|
-
const fetch_1 = require('modern-treasury/_shims/fetch');
|
|
64
|
-
const uploads_1 = require('./uploads.js');
|
|
65
|
-
var uploads_2 = require('./uploads.js');
|
|
66
|
-
Object.defineProperty(exports, 'maybeMultipartFormRequestOptions', {
|
|
67
|
-
enumerable: true,
|
|
68
|
-
get: function () {
|
|
69
|
-
return uploads_2.maybeMultipartFormRequestOptions;
|
|
70
|
-
},
|
|
71
|
-
});
|
|
72
|
-
Object.defineProperty(exports, 'multipartFormRequestOptions', {
|
|
73
|
-
enumerable: true,
|
|
74
|
-
get: function () {
|
|
75
|
-
return uploads_2.multipartFormRequestOptions;
|
|
76
|
-
},
|
|
77
|
-
});
|
|
78
|
-
Object.defineProperty(exports, 'createForm', {
|
|
79
|
-
enumerable: true,
|
|
80
|
-
get: function () {
|
|
81
|
-
return uploads_2.createForm;
|
|
82
|
-
},
|
|
83
|
-
});
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.toBase64 = exports.getHeader = exports.isHeadersProtocol = exports.isRunningInBrowser = exports.debug = exports.hasOwn = exports.isEmptyObj = exports.maybeCoerceBoolean = exports.maybeCoerceFloat = exports.maybeCoerceInteger = exports.coerceBoolean = exports.coerceFloat = exports.coerceInteger = exports.readEnv = exports.ensurePresent = exports.castToError = exports.sleep = exports.safeJSON = exports.isRequestOptions = exports.createResponseHeaders = exports.PagePromise = exports.AbstractPage = exports.APIResource = exports.APIClient = exports.APIPromise = exports.createForm = exports.multipartFormRequestOptions = exports.maybeMultipartFormRequestOptions = void 0;
|
|
16
|
+
const version_1 = require("./version.js");
|
|
17
|
+
const error_1 = require("./error.js");
|
|
18
|
+
const index_1 = require("./_shims/index.js");
|
|
19
|
+
const uploads_1 = require("./uploads.js");
|
|
20
|
+
var uploads_2 = require("./uploads.js");
|
|
21
|
+
Object.defineProperty(exports, "maybeMultipartFormRequestOptions", { enumerable: true, get: function () { return uploads_2.maybeMultipartFormRequestOptions; } });
|
|
22
|
+
Object.defineProperty(exports, "multipartFormRequestOptions", { enumerable: true, get: function () { return uploads_2.multipartFormRequestOptions; } });
|
|
23
|
+
Object.defineProperty(exports, "createForm", { enumerable: true, get: function () { return uploads_2.createForm; } });
|
|
84
24
|
const MAX_RETRIES = 2;
|
|
85
25
|
async function defaultParseResponse(props) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
26
|
+
const { response } = props;
|
|
27
|
+
const contentType = response.headers.get('content-type');
|
|
28
|
+
if (contentType?.includes('application/json')) {
|
|
29
|
+
const json = await response.json();
|
|
30
|
+
debug('response', response.status, response.url, response.headers, json);
|
|
31
|
+
return json;
|
|
32
|
+
}
|
|
33
|
+
// TODO handle blob, arraybuffer, other content types, etc.
|
|
34
|
+
const text = await response.text();
|
|
35
|
+
debug('response', response.status, response.url, response.headers, text);
|
|
36
|
+
return text;
|
|
97
37
|
}
|
|
98
38
|
/**
|
|
99
39
|
* A subclass of `Promise` providing additional helper methods
|
|
100
40
|
* for interacting with the SDK.
|
|
101
41
|
*/
|
|
102
42
|
class APIPromise extends Promise {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
43
|
+
constructor(responsePromise, parseResponse = defaultParseResponse) {
|
|
44
|
+
super((resolve) => {
|
|
45
|
+
// this is maybe a bit weird but this has to be a no-op to not implicitly
|
|
46
|
+
// parse the response body; instead .then, .catch, .finally are overridden
|
|
47
|
+
// to parse the response
|
|
48
|
+
resolve(null);
|
|
49
|
+
});
|
|
50
|
+
this.responsePromise = responsePromise;
|
|
51
|
+
this.parseResponse = parseResponse;
|
|
52
|
+
}
|
|
53
|
+
_thenUnwrap(transform) {
|
|
54
|
+
return new APIPromise(this.responsePromise, async (props) => transform(await this.parseResponse(props)));
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Gets the raw `Response` instance instead of parsing the response
|
|
58
|
+
* data.
|
|
59
|
+
*
|
|
60
|
+
* If you want to parse the response body but still get the `Response`
|
|
61
|
+
* instance, you can use {@link withResponse()}.
|
|
62
|
+
*
|
|
63
|
+
* 👋 Getting the wrong TypeScript type for `Response`?
|
|
64
|
+
* Try setting `"moduleResolution": "NodeNext"` if you can,
|
|
65
|
+
* or add one of these imports before your first `import … from 'modern-treasury'`:
|
|
66
|
+
* - `import 'modern-treasury/shims/node'` (if you're running on Node)
|
|
67
|
+
* - `import 'modern-treasury/shims/web'` (otherwise)
|
|
68
|
+
*/
|
|
69
|
+
asResponse() {
|
|
70
|
+
return this.responsePromise.then((p) => p.response);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Gets the parsed response data and the raw `Response` instance.
|
|
74
|
+
*
|
|
75
|
+
* If you just want to get the raw `Response` instance without parsing it,
|
|
76
|
+
* you can use {@link asResponse()}.
|
|
77
|
+
*
|
|
78
|
+
*
|
|
79
|
+
* 👋 Getting the wrong TypeScript type for `Response`?
|
|
80
|
+
* Try setting `"moduleResolution": "NodeNext"` if you can,
|
|
81
|
+
* or add one of these imports before your first `import … from 'modern-treasury'`:
|
|
82
|
+
* - `import 'modern-treasury/shims/node'` (if you're running on Node)
|
|
83
|
+
* - `import 'modern-treasury/shims/web'` (otherwise)
|
|
84
|
+
*/
|
|
85
|
+
async withResponse() {
|
|
86
|
+
const [data, response] = await Promise.all([this.parse(), this.asResponse()]);
|
|
87
|
+
return { data, response };
|
|
88
|
+
}
|
|
89
|
+
parse() {
|
|
90
|
+
if (!this.parsedPromise) {
|
|
91
|
+
this.parsedPromise = this.responsePromise.then(this.parseResponse);
|
|
92
|
+
}
|
|
93
|
+
return this.parsedPromise;
|
|
94
|
+
}
|
|
95
|
+
then(onfulfilled, onrejected) {
|
|
96
|
+
return this.parse().then(onfulfilled, onrejected);
|
|
97
|
+
}
|
|
98
|
+
catch(onrejected) {
|
|
99
|
+
return this.parse().catch(onrejected);
|
|
100
|
+
}
|
|
101
|
+
finally(onfinally) {
|
|
102
|
+
return this.parse().finally(onfinally);
|
|
103
|
+
}
|
|
151
104
|
}
|
|
152
105
|
exports.APIPromise = APIPromise;
|
|
153
106
|
class APIClient {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
this.baseURL = baseURL;
|
|
162
|
-
this.maxRetries = validatePositiveInteger(
|
|
163
|
-
'maxRetries',
|
|
164
|
-
maxRetries !== null && maxRetries !== void 0 ? maxRetries : MAX_RETRIES,
|
|
165
|
-
);
|
|
166
|
-
this.timeout = validatePositiveInteger('timeout', timeout);
|
|
167
|
-
this.httpAgent = httpAgent;
|
|
168
|
-
this.fetch = overridenFetch !== null && overridenFetch !== void 0 ? overridenFetch : fetch_1.fetch;
|
|
169
|
-
}
|
|
170
|
-
authHeaders(opts) {
|
|
171
|
-
return {};
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Override this to add your own default headers, for example:
|
|
175
|
-
*
|
|
176
|
-
* {
|
|
177
|
-
* ...super.defaultHeaders(),
|
|
178
|
-
* Authorization: 'Bearer 123',
|
|
179
|
-
* }
|
|
180
|
-
*/
|
|
181
|
-
defaultHeaders(opts) {
|
|
182
|
-
return {
|
|
183
|
-
Accept: 'application/json',
|
|
184
|
-
'Content-Type': 'application/json',
|
|
185
|
-
'User-Agent': this.getUserAgent(),
|
|
186
|
-
...getPlatformHeaders(),
|
|
187
|
-
...this.authHeaders(opts),
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* Override this to add your own headers validation:
|
|
192
|
-
*/
|
|
193
|
-
validateHeaders(headers, customHeaders) {}
|
|
194
|
-
defaultIdempotencyKey() {
|
|
195
|
-
return `stainless-node-retry-${uuid4()}`;
|
|
196
|
-
}
|
|
197
|
-
get(path, opts) {
|
|
198
|
-
return this.methodRequest('get', path, opts);
|
|
199
|
-
}
|
|
200
|
-
post(path, opts) {
|
|
201
|
-
return this.methodRequest('post', path, opts);
|
|
202
|
-
}
|
|
203
|
-
patch(path, opts) {
|
|
204
|
-
return this.methodRequest('patch', path, opts);
|
|
205
|
-
}
|
|
206
|
-
put(path, opts) {
|
|
207
|
-
return this.methodRequest('put', path, opts);
|
|
208
|
-
}
|
|
209
|
-
delete(path, opts) {
|
|
210
|
-
return this.methodRequest('delete', path, opts);
|
|
211
|
-
}
|
|
212
|
-
methodRequest(method, path, opts) {
|
|
213
|
-
return this.request(Promise.resolve(opts).then((opts) => ({ method, path, ...opts })));
|
|
214
|
-
}
|
|
215
|
-
getAPIList(path, Page, opts) {
|
|
216
|
-
return this.requestAPIList(Page, { method: 'get', path, ...opts });
|
|
217
|
-
}
|
|
218
|
-
calculateContentLength(body) {
|
|
219
|
-
if (typeof body === 'string') {
|
|
220
|
-
if (typeof Buffer !== 'undefined') {
|
|
221
|
-
return Buffer.byteLength(body, 'utf8').toString();
|
|
222
|
-
}
|
|
223
|
-
if (typeof TextEncoder !== 'undefined') {
|
|
224
|
-
const encoder = new TextEncoder();
|
|
225
|
-
const encoded = encoder.encode(body);
|
|
226
|
-
return encoded.length.toString();
|
|
227
|
-
}
|
|
107
|
+
constructor({ baseURL, maxRetries, timeout = 60000, // 1 minute
|
|
108
|
+
httpAgent, fetch: overridenFetch, }) {
|
|
109
|
+
this.baseURL = baseURL;
|
|
110
|
+
this.maxRetries = validatePositiveInteger('maxRetries', maxRetries ?? MAX_RETRIES);
|
|
111
|
+
this.timeout = validatePositiveInteger('timeout', timeout);
|
|
112
|
+
this.httpAgent = httpAgent;
|
|
113
|
+
this.fetch = overridenFetch ?? index_1.fetch;
|
|
228
114
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
}
|
|
368
|
-
return url.toString();
|
|
369
|
-
}
|
|
370
|
-
stringifyQuery(query) {
|
|
371
|
-
return Object.entries(query)
|
|
372
|
-
.filter(([_, value]) => typeof value !== 'undefined')
|
|
373
|
-
.map(([key, value]) => {
|
|
374
|
-
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
|
375
|
-
return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
|
115
|
+
authHeaders(opts) {
|
|
116
|
+
return {};
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Override this to add your own default headers, for example:
|
|
120
|
+
*
|
|
121
|
+
* {
|
|
122
|
+
* ...super.defaultHeaders(),
|
|
123
|
+
* Authorization: 'Bearer 123',
|
|
124
|
+
* }
|
|
125
|
+
*/
|
|
126
|
+
defaultHeaders(opts) {
|
|
127
|
+
return {
|
|
128
|
+
Accept: 'application/json',
|
|
129
|
+
'Content-Type': 'application/json',
|
|
130
|
+
'User-Agent': this.getUserAgent(),
|
|
131
|
+
...getPlatformHeaders(),
|
|
132
|
+
...this.authHeaders(opts),
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Override this to add your own headers validation:
|
|
137
|
+
*/
|
|
138
|
+
validateHeaders(headers, customHeaders) { }
|
|
139
|
+
defaultIdempotencyKey() {
|
|
140
|
+
return `stainless-node-retry-${uuid4()}`;
|
|
141
|
+
}
|
|
142
|
+
get(path, opts) {
|
|
143
|
+
return this.methodRequest('get', path, opts);
|
|
144
|
+
}
|
|
145
|
+
post(path, opts) {
|
|
146
|
+
return this.methodRequest('post', path, opts);
|
|
147
|
+
}
|
|
148
|
+
patch(path, opts) {
|
|
149
|
+
return this.methodRequest('patch', path, opts);
|
|
150
|
+
}
|
|
151
|
+
put(path, opts) {
|
|
152
|
+
return this.methodRequest('put', path, opts);
|
|
153
|
+
}
|
|
154
|
+
delete(path, opts) {
|
|
155
|
+
return this.methodRequest('delete', path, opts);
|
|
156
|
+
}
|
|
157
|
+
methodRequest(method, path, opts) {
|
|
158
|
+
return this.request(Promise.resolve(opts).then((opts) => ({ method, path, ...opts })));
|
|
159
|
+
}
|
|
160
|
+
getAPIList(path, Page, opts) {
|
|
161
|
+
return this.requestAPIList(Page, { method: 'get', path, ...opts });
|
|
162
|
+
}
|
|
163
|
+
calculateContentLength(body) {
|
|
164
|
+
if (typeof body === 'string') {
|
|
165
|
+
if (typeof Buffer !== 'undefined') {
|
|
166
|
+
return Buffer.byteLength(body, 'utf8').toString();
|
|
167
|
+
}
|
|
168
|
+
if (typeof TextEncoder !== 'undefined') {
|
|
169
|
+
const encoder = new TextEncoder();
|
|
170
|
+
const encoded = encoder.encode(body);
|
|
171
|
+
return encoded.length.toString();
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
buildRequest(options) {
|
|
177
|
+
const { method, path, query, headers: headers = {} } = options;
|
|
178
|
+
const body = (0, uploads_1.isMultipartBody)(options.body) ? options.body.body
|
|
179
|
+
: options.body ? JSON.stringify(options.body, null, 2)
|
|
180
|
+
: null;
|
|
181
|
+
const contentLength = this.calculateContentLength(body);
|
|
182
|
+
const url = this.buildURL(path, query);
|
|
183
|
+
if ('timeout' in options)
|
|
184
|
+
validatePositiveInteger('timeout', options.timeout);
|
|
185
|
+
const timeout = options.timeout ?? this.timeout;
|
|
186
|
+
const httpAgent = options.httpAgent ?? this.httpAgent ?? (0, index_1.getDefaultAgent)(url);
|
|
187
|
+
const minAgentTimeout = timeout + 1000;
|
|
188
|
+
if (typeof httpAgent?.options?.timeout === 'number' &&
|
|
189
|
+
minAgentTimeout > (httpAgent.options.timeout ?? 0)) {
|
|
190
|
+
// Allow any given request to bump our agent active socket timeout.
|
|
191
|
+
// This may seem strange, but leaking active sockets should be rare and not particularly problematic,
|
|
192
|
+
// and without mutating agent we would need to create more of them.
|
|
193
|
+
// This tradeoff optimizes for performance.
|
|
194
|
+
httpAgent.options.timeout = minAgentTimeout;
|
|
195
|
+
}
|
|
196
|
+
if (this.idempotencyHeader && method !== 'get') {
|
|
197
|
+
if (!options.idempotencyKey)
|
|
198
|
+
options.idempotencyKey = this.defaultIdempotencyKey();
|
|
199
|
+
headers[this.idempotencyHeader] = options.idempotencyKey;
|
|
200
|
+
}
|
|
201
|
+
const reqHeaders = {
|
|
202
|
+
...(contentLength && { 'Content-Length': contentLength }),
|
|
203
|
+
...this.defaultHeaders(options),
|
|
204
|
+
...headers,
|
|
205
|
+
};
|
|
206
|
+
// let builtin fetch set the Content-Type for multipart bodies
|
|
207
|
+
if ((0, uploads_1.isMultipartBody)(options.body) && index_1.kind !== 'node') {
|
|
208
|
+
delete reqHeaders['Content-Type'];
|
|
209
|
+
}
|
|
210
|
+
// Strip any headers being explicitly omitted with null
|
|
211
|
+
Object.keys(reqHeaders).forEach((key) => reqHeaders[key] === null && delete reqHeaders[key]);
|
|
212
|
+
const req = {
|
|
213
|
+
method,
|
|
214
|
+
...(body && { body: body }),
|
|
215
|
+
headers: reqHeaders,
|
|
216
|
+
...(httpAgent && { agent: httpAgent }),
|
|
217
|
+
// @ts-ignore node-fetch uses a custom AbortSignal type that is
|
|
218
|
+
// not compatible with standard web types
|
|
219
|
+
signal: options.signal ?? null,
|
|
220
|
+
};
|
|
221
|
+
this.validateHeaders(reqHeaders, headers);
|
|
222
|
+
return { req, url, timeout };
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Used as a callback for mutating the given `RequestInit` object.
|
|
226
|
+
*
|
|
227
|
+
* This is useful for cases where you want to add certain headers based off of
|
|
228
|
+
* the request properties, e.g. `method` or `url`.
|
|
229
|
+
*/
|
|
230
|
+
async prepareRequest(request, { url, options }) { }
|
|
231
|
+
parseHeaders(headers) {
|
|
232
|
+
return (!headers ? {}
|
|
233
|
+
: Symbol.iterator in headers ?
|
|
234
|
+
Object.fromEntries(Array.from(headers).map((header) => [...header]))
|
|
235
|
+
: { ...headers });
|
|
236
|
+
}
|
|
237
|
+
makeStatusError(status, error, message, headers) {
|
|
238
|
+
return error_1.APIError.generate(status, error, message, headers);
|
|
239
|
+
}
|
|
240
|
+
request(options, remainingRetries = null) {
|
|
241
|
+
return new APIPromise(this.makeRequest(options, remainingRetries));
|
|
242
|
+
}
|
|
243
|
+
async makeRequest(optionsInput, retriesRemaining) {
|
|
244
|
+
const options = await optionsInput;
|
|
245
|
+
if (retriesRemaining == null) {
|
|
246
|
+
retriesRemaining = options.maxRetries ?? this.maxRetries;
|
|
247
|
+
}
|
|
248
|
+
const { req, url, timeout } = this.buildRequest(options);
|
|
249
|
+
await this.prepareRequest(req, { url, options });
|
|
250
|
+
debug('request', url, options, req.headers);
|
|
251
|
+
if (options.signal?.aborted) {
|
|
252
|
+
throw new error_1.APIUserAbortError();
|
|
376
253
|
}
|
|
377
|
-
|
|
378
|
-
|
|
254
|
+
const controller = new AbortController();
|
|
255
|
+
const response = await this.fetchWithTimeout(url, req, timeout, controller).catch(exports.castToError);
|
|
256
|
+
if (response instanceof Error) {
|
|
257
|
+
if (options.signal?.aborted) {
|
|
258
|
+
throw new error_1.APIUserAbortError();
|
|
259
|
+
}
|
|
260
|
+
if (retriesRemaining) {
|
|
261
|
+
return this.retryRequest(options, retriesRemaining);
|
|
262
|
+
}
|
|
263
|
+
if (response.name === 'AbortError') {
|
|
264
|
+
throw new error_1.APIConnectionTimeoutError();
|
|
265
|
+
}
|
|
266
|
+
throw new error_1.APIConnectionError({ cause: response });
|
|
379
267
|
}
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
)
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
268
|
+
const responseHeaders = (0, exports.createResponseHeaders)(response.headers);
|
|
269
|
+
if (!response.ok) {
|
|
270
|
+
if (retriesRemaining && this.shouldRetry(response)) {
|
|
271
|
+
return this.retryRequest(options, retriesRemaining, responseHeaders);
|
|
272
|
+
}
|
|
273
|
+
const errText = await response.text().catch((e) => (0, exports.castToError)(e).message);
|
|
274
|
+
const errJSON = (0, exports.safeJSON)(errText);
|
|
275
|
+
const errMessage = errJSON ? undefined : errText;
|
|
276
|
+
debug('response', response.status, url, responseHeaders, errMessage);
|
|
277
|
+
const err = this.makeStatusError(response.status, errJSON, errMessage, responseHeaders);
|
|
278
|
+
throw err;
|
|
279
|
+
}
|
|
280
|
+
return { response, options, controller };
|
|
281
|
+
}
|
|
282
|
+
requestAPIList(Page, options) {
|
|
283
|
+
const request = this.makeRequest(options, null);
|
|
284
|
+
return new PagePromise(this, request, Page);
|
|
285
|
+
}
|
|
286
|
+
buildURL(path, query) {
|
|
287
|
+
const url = isAbsoluteURL(path) ?
|
|
288
|
+
new URL(path)
|
|
289
|
+
: new URL(this.baseURL + (this.baseURL.endsWith('/') && path.startsWith('/') ? path.slice(1) : path));
|
|
290
|
+
const defaultQuery = this.defaultQuery();
|
|
291
|
+
if (!isEmptyObj(defaultQuery)) {
|
|
292
|
+
query = { ...defaultQuery, ...query };
|
|
293
|
+
}
|
|
294
|
+
if (query) {
|
|
295
|
+
url.search = this.stringifyQuery(query);
|
|
296
|
+
}
|
|
297
|
+
return url.toString();
|
|
298
|
+
}
|
|
299
|
+
stringifyQuery(query) {
|
|
300
|
+
return Object.entries(query)
|
|
301
|
+
.filter(([_, value]) => typeof value !== 'undefined')
|
|
302
|
+
.map(([key, value]) => {
|
|
303
|
+
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
|
304
|
+
return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
|
305
|
+
}
|
|
306
|
+
if (value === null) {
|
|
307
|
+
return `${encodeURIComponent(key)}=`;
|
|
308
|
+
}
|
|
309
|
+
throw new error_1.ModernTreasuryError(`Cannot stringify type ${typeof value}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`);
|
|
310
|
+
})
|
|
311
|
+
.join('&');
|
|
312
|
+
}
|
|
313
|
+
async fetchWithTimeout(url, init, ms, controller) {
|
|
314
|
+
const { signal, ...options } = init || {};
|
|
315
|
+
if (signal)
|
|
316
|
+
signal.addEventListener('abort', () => controller.abort());
|
|
317
|
+
const timeout = setTimeout(() => controller.abort(), ms);
|
|
318
|
+
return (this.getRequestClient()
|
|
319
|
+
// use undefined this binding; fetch errors if bound to something else in browser/cloudflare
|
|
320
|
+
.fetch.call(undefined, url, { signal: controller.signal, ...options })
|
|
321
|
+
.finally(() => {
|
|
322
|
+
clearTimeout(timeout);
|
|
323
|
+
}));
|
|
324
|
+
}
|
|
325
|
+
getRequestClient() {
|
|
326
|
+
return { fetch: this.fetch };
|
|
327
|
+
}
|
|
328
|
+
shouldRetry(response) {
|
|
329
|
+
// Note this is not a standard header.
|
|
330
|
+
const shouldRetryHeader = response.headers.get('x-should-retry');
|
|
331
|
+
// If the server explicitly says whether or not to retry, obey.
|
|
332
|
+
if (shouldRetryHeader === 'true')
|
|
333
|
+
return true;
|
|
334
|
+
if (shouldRetryHeader === 'false')
|
|
335
|
+
return false;
|
|
336
|
+
// Retry on request timeouts.
|
|
337
|
+
if (response.status === 408)
|
|
338
|
+
return true;
|
|
339
|
+
// Retry on lock timeouts.
|
|
340
|
+
if (response.status === 409)
|
|
341
|
+
return true;
|
|
342
|
+
// Retry on rate limits.
|
|
343
|
+
if (response.status === 429)
|
|
344
|
+
return true;
|
|
345
|
+
// Retry internal errors.
|
|
346
|
+
if (response.status >= 500)
|
|
347
|
+
return true;
|
|
348
|
+
return false;
|
|
349
|
+
}
|
|
350
|
+
async retryRequest(options, retriesRemaining, responseHeaders) {
|
|
351
|
+
retriesRemaining -= 1;
|
|
352
|
+
// About the Retry-After header: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After
|
|
353
|
+
let timeoutMillis;
|
|
354
|
+
const retryAfterHeader = responseHeaders?.['retry-after'];
|
|
355
|
+
if (retryAfterHeader) {
|
|
356
|
+
const timeoutSeconds = parseInt(retryAfterHeader);
|
|
357
|
+
if (!Number.isNaN(timeoutSeconds)) {
|
|
358
|
+
timeoutMillis = timeoutSeconds * 1000;
|
|
359
|
+
}
|
|
360
|
+
else {
|
|
361
|
+
timeoutMillis = Date.parse(retryAfterHeader) - Date.now();
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
// If the API asks us to wait a certain amount of time (and it's a reasonable amount),
|
|
365
|
+
// just do what it says, but otherwise calculate a default
|
|
366
|
+
if (!timeoutMillis ||
|
|
367
|
+
!Number.isInteger(timeoutMillis) ||
|
|
368
|
+
timeoutMillis <= 0 ||
|
|
369
|
+
timeoutMillis > 60 * 1000) {
|
|
370
|
+
const maxRetries = options.maxRetries ?? this.maxRetries;
|
|
371
|
+
timeoutMillis = this.calculateDefaultRetryTimeoutMillis(retriesRemaining, maxRetries);
|
|
372
|
+
}
|
|
373
|
+
await (0, exports.sleep)(timeoutMillis);
|
|
374
|
+
return this.makeRequest(options, retriesRemaining);
|
|
375
|
+
}
|
|
376
|
+
calculateDefaultRetryTimeoutMillis(retriesRemaining, maxRetries) {
|
|
377
|
+
const initialRetryDelay = 0.5;
|
|
378
|
+
const maxRetryDelay = 2;
|
|
379
|
+
const numRetries = maxRetries - retriesRemaining;
|
|
380
|
+
// Apply exponential backoff, but not more than the max.
|
|
381
|
+
const sleepSeconds = Math.min(initialRetryDelay * Math.pow(numRetries - 1, 2), maxRetryDelay);
|
|
382
|
+
// Apply some jitter, plus-or-minus half a second.
|
|
383
|
+
const jitter = Math.random() - 0.5;
|
|
384
|
+
return (sleepSeconds + jitter) * 1000;
|
|
385
|
+
}
|
|
386
|
+
getUserAgent() {
|
|
387
|
+
return `${this.constructor.name}/JS ${version_1.VERSION}`;
|
|
388
|
+
}
|
|
449
389
|
}
|
|
450
390
|
exports.APIClient = APIClient;
|
|
451
391
|
class APIResource {
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
392
|
+
constructor(client) {
|
|
393
|
+
this.client = client;
|
|
394
|
+
this.get = client.get.bind(client);
|
|
395
|
+
this.post = client.post.bind(client);
|
|
396
|
+
this.patch = client.patch.bind(client);
|
|
397
|
+
this.put = client.put.bind(client);
|
|
398
|
+
this.delete = client.delete.bind(client);
|
|
399
|
+
this.getAPIList = client.getAPIList.bind(client);
|
|
400
|
+
}
|
|
461
401
|
}
|
|
462
402
|
exports.APIResource = APIResource;
|
|
463
403
|
class AbstractPage {
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
}
|
|
404
|
+
constructor(client, response, body, options) {
|
|
405
|
+
_AbstractPage_client.set(this, void 0);
|
|
406
|
+
__classPrivateFieldSet(this, _AbstractPage_client, client, "f");
|
|
407
|
+
this.options = options;
|
|
408
|
+
this.response = response;
|
|
409
|
+
this.body = body;
|
|
410
|
+
}
|
|
411
|
+
hasNextPage() {
|
|
412
|
+
const items = this.getPaginatedItems();
|
|
413
|
+
if (!items.length)
|
|
414
|
+
return false;
|
|
415
|
+
return this.nextPageInfo() != null;
|
|
416
|
+
}
|
|
417
|
+
async getNextPage() {
|
|
418
|
+
const nextInfo = this.nextPageInfo();
|
|
419
|
+
if (!nextInfo) {
|
|
420
|
+
throw new error_1.ModernTreasuryError('No next page expected; please check `.hasNextPage()` before calling `.getNextPage()`.');
|
|
421
|
+
}
|
|
422
|
+
const nextOptions = { ...this.options };
|
|
423
|
+
if ('params' in nextInfo) {
|
|
424
|
+
nextOptions.query = { ...nextOptions.query, ...nextInfo.params };
|
|
425
|
+
}
|
|
426
|
+
else if ('url' in nextInfo) {
|
|
427
|
+
const params = [...Object.entries(nextOptions.query || {}), ...nextInfo.url.searchParams.entries()];
|
|
428
|
+
for (const [key, value] of params) {
|
|
429
|
+
nextInfo.url.searchParams.set(key, value);
|
|
430
|
+
}
|
|
431
|
+
nextOptions.query = undefined;
|
|
432
|
+
nextOptions.path = nextInfo.url.toString();
|
|
433
|
+
}
|
|
434
|
+
return await __classPrivateFieldGet(this, _AbstractPage_client, "f").requestAPIList(this.constructor, nextOptions);
|
|
435
|
+
}
|
|
436
|
+
async *iterPages() {
|
|
437
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
438
|
+
let page = this;
|
|
439
|
+
yield page;
|
|
440
|
+
while (page.hasNextPage()) {
|
|
441
|
+
page = await page.getNextPage();
|
|
442
|
+
yield page;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
async *[(_AbstractPage_client = new WeakMap(), Symbol.asyncIterator)]() {
|
|
446
|
+
for await (const page of this.iterPages()) {
|
|
447
|
+
for (const item of page.getPaginatedItems()) {
|
|
448
|
+
yield item;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
}
|
|
515
452
|
}
|
|
516
453
|
exports.AbstractPage = AbstractPage;
|
|
517
454
|
/**
|
|
@@ -524,217 +461,222 @@ exports.AbstractPage = AbstractPage;
|
|
|
524
461
|
* }
|
|
525
462
|
*/
|
|
526
463
|
class PagePromise extends APIPromise {
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
yield item;
|
|
544
|
-
}
|
|
545
|
-
}
|
|
464
|
+
constructor(client, request, Page) {
|
|
465
|
+
super(request, async (props) => new Page(client, props.response, await defaultParseResponse(props), props.options));
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Allow auto-paginating iteration on an unawaited list call, eg:
|
|
469
|
+
*
|
|
470
|
+
* for await (const item of client.items.list()) {
|
|
471
|
+
* console.log(item)
|
|
472
|
+
* }
|
|
473
|
+
*/
|
|
474
|
+
async *[Symbol.asyncIterator]() {
|
|
475
|
+
const page = await this;
|
|
476
|
+
for await (const item of page) {
|
|
477
|
+
yield item;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
546
480
|
}
|
|
547
481
|
exports.PagePromise = PagePromise;
|
|
548
482
|
const createResponseHeaders = (headers) => {
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
return target[key.toLowerCase()] || target[key];
|
|
558
|
-
},
|
|
559
|
-
},
|
|
560
|
-
);
|
|
483
|
+
return new Proxy(Object.fromEntries(
|
|
484
|
+
// @ts-ignore
|
|
485
|
+
headers.entries()), {
|
|
486
|
+
get(target, name) {
|
|
487
|
+
const key = name.toString();
|
|
488
|
+
return target[key.toLowerCase()] || target[key];
|
|
489
|
+
},
|
|
490
|
+
});
|
|
561
491
|
};
|
|
562
492
|
exports.createResponseHeaders = createResponseHeaders;
|
|
563
493
|
// This is required so that we can determine if a given object matches the RequestOptions
|
|
564
494
|
// type at runtime. While this requires duplication, it is enforced by the TypeScript
|
|
565
495
|
// compiler such that any missing / extraneous keys will cause an error.
|
|
566
496
|
const requestOptionsKeys = {
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
497
|
+
method: true,
|
|
498
|
+
path: true,
|
|
499
|
+
query: true,
|
|
500
|
+
body: true,
|
|
501
|
+
headers: true,
|
|
502
|
+
maxRetries: true,
|
|
503
|
+
stream: true,
|
|
504
|
+
timeout: true,
|
|
505
|
+
httpAgent: true,
|
|
506
|
+
signal: true,
|
|
507
|
+
idempotencyKey: true,
|
|
578
508
|
};
|
|
579
509
|
const isRequestOptions = (obj) => {
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
Object.keys(obj).every((k) => hasOwn(requestOptionsKeys, k))
|
|
585
|
-
);
|
|
510
|
+
return (typeof obj === 'object' &&
|
|
511
|
+
obj !== null &&
|
|
512
|
+
!isEmptyObj(obj) &&
|
|
513
|
+
Object.keys(obj).every((k) => hasOwn(requestOptionsKeys, k)));
|
|
586
514
|
};
|
|
587
515
|
exports.isRequestOptions = isRequestOptions;
|
|
588
516
|
const getPlatformProperties = () => {
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
517
|
+
if (typeof Deno !== 'undefined' && Deno.build != null) {
|
|
518
|
+
return {
|
|
519
|
+
'X-Stainless-Lang': 'js',
|
|
520
|
+
'X-Stainless-Package-Version': version_1.VERSION,
|
|
521
|
+
'X-Stainless-OS': normalizePlatform(Deno.build.os),
|
|
522
|
+
'X-Stainless-Arch': normalizeArch(Deno.build.arch),
|
|
523
|
+
'X-Stainless-Runtime': 'deno',
|
|
524
|
+
'X-Stainless-Runtime-Version': Deno.version,
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
if (typeof EdgeRuntime !== 'undefined') {
|
|
528
|
+
return {
|
|
529
|
+
'X-Stainless-Lang': 'js',
|
|
530
|
+
'X-Stainless-Package-Version': version_1.VERSION,
|
|
531
|
+
'X-Stainless-OS': 'Unknown',
|
|
532
|
+
'X-Stainless-Arch': `other:${EdgeRuntime}`,
|
|
533
|
+
'X-Stainless-Runtime': 'edge',
|
|
534
|
+
'X-Stainless-Runtime-Version': process.version,
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
// Check if Node.js
|
|
538
|
+
if (Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]') {
|
|
539
|
+
return {
|
|
540
|
+
'X-Stainless-Lang': 'js',
|
|
541
|
+
'X-Stainless-Package-Version': version_1.VERSION,
|
|
542
|
+
'X-Stainless-OS': normalizePlatform(process.platform),
|
|
543
|
+
'X-Stainless-Arch': normalizeArch(process.arch),
|
|
544
|
+
'X-Stainless-Runtime': 'node',
|
|
545
|
+
'X-Stainless-Runtime-Version': process.version,
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
const browserInfo = getBrowserInfo();
|
|
549
|
+
if (browserInfo) {
|
|
550
|
+
return {
|
|
551
|
+
'X-Stainless-Lang': 'js',
|
|
552
|
+
'X-Stainless-Package-Version': version_1.VERSION,
|
|
553
|
+
'X-Stainless-OS': 'Unknown',
|
|
554
|
+
'X-Stainless-Arch': 'unknown',
|
|
555
|
+
'X-Stainless-Runtime': `browser:${browserInfo.browser}`,
|
|
556
|
+
'X-Stainless-Runtime-Version': browserInfo.version,
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
// TODO add support for Cloudflare workers, etc.
|
|
622
560
|
return {
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
561
|
+
'X-Stainless-Lang': 'js',
|
|
562
|
+
'X-Stainless-Package-Version': version_1.VERSION,
|
|
563
|
+
'X-Stainless-OS': 'Unknown',
|
|
564
|
+
'X-Stainless-Arch': 'unknown',
|
|
565
|
+
'X-Stainless-Runtime': 'unknown',
|
|
566
|
+
'X-Stainless-Runtime-Version': 'unknown',
|
|
629
567
|
};
|
|
630
|
-
}
|
|
631
|
-
// TODO add support for Cloudflare workers, etc.
|
|
632
|
-
return {
|
|
633
|
-
'X-Stainless-Lang': 'js',
|
|
634
|
-
'X-Stainless-Package-Version': version_1.VERSION,
|
|
635
|
-
'X-Stainless-OS': 'Unknown',
|
|
636
|
-
'X-Stainless-Arch': 'unknown',
|
|
637
|
-
'X-Stainless-Runtime': 'unknown',
|
|
638
|
-
'X-Stainless-Runtime-Version': 'unknown',
|
|
639
|
-
};
|
|
640
568
|
};
|
|
641
569
|
// Note: modified from https://github.com/JS-DevTools/host-environment/blob/b1ab79ecde37db5d6e163c050e54fe7d287d7c92/src/isomorphic.browser.ts
|
|
642
570
|
function getBrowserInfo() {
|
|
643
|
-
|
|
571
|
+
if (typeof navigator === 'undefined' || !navigator) {
|
|
572
|
+
return null;
|
|
573
|
+
}
|
|
574
|
+
// NOTE: The order matters here!
|
|
575
|
+
const browserPatterns = [
|
|
576
|
+
{ key: 'edge', pattern: /Edge(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
577
|
+
{ key: 'ie', pattern: /MSIE(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
578
|
+
{ key: 'ie', pattern: /Trident(?:.*rv\:(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
579
|
+
{ key: 'chrome', pattern: /Chrome(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
580
|
+
{ key: 'firefox', pattern: /Firefox(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
581
|
+
{ key: 'safari', pattern: /(?:Version\W+(\d+)\.(\d+)(?:\.(\d+))?)?(?:\W+Mobile\S*)?\W+Safari/ },
|
|
582
|
+
];
|
|
583
|
+
// Find the FIRST matching browser
|
|
584
|
+
for (const { key, pattern } of browserPatterns) {
|
|
585
|
+
const match = pattern.exec(navigator.userAgent);
|
|
586
|
+
if (match) {
|
|
587
|
+
const major = match[1] || 0;
|
|
588
|
+
const minor = match[2] || 0;
|
|
589
|
+
const patch = match[3] || 0;
|
|
590
|
+
return { browser: key, version: `${major}.${minor}.${patch}` };
|
|
591
|
+
}
|
|
592
|
+
}
|
|
644
593
|
return null;
|
|
645
|
-
}
|
|
646
|
-
// NOTE: The order matters here!
|
|
647
|
-
const browserPatterns = [
|
|
648
|
-
{ key: 'edge', pattern: /Edge(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
649
|
-
{ key: 'ie', pattern: /MSIE(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
650
|
-
{ key: 'ie', pattern: /Trident(?:.*rv\:(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
651
|
-
{ key: 'chrome', pattern: /Chrome(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
652
|
-
{ key: 'firefox', pattern: /Firefox(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
|
|
653
|
-
{ key: 'safari', pattern: /(?:Version\W+(\d+)\.(\d+)(?:\.(\d+))?)?(?:\W+Mobile\S*)?\W+Safari/ },
|
|
654
|
-
];
|
|
655
|
-
// Find the FIRST matching browser
|
|
656
|
-
for (const { key, pattern } of browserPatterns) {
|
|
657
|
-
const match = pattern.exec(navigator.userAgent);
|
|
658
|
-
if (match) {
|
|
659
|
-
const major = match[1] || 0;
|
|
660
|
-
const minor = match[2] || 0;
|
|
661
|
-
const patch = match[3] || 0;
|
|
662
|
-
return { browser: key, version: `${major}.${minor}.${patch}` };
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
return null;
|
|
666
594
|
}
|
|
667
595
|
const normalizeArch = (arch) => {
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
596
|
+
// Node docs:
|
|
597
|
+
// - https://nodejs.org/api/process.html#processarch
|
|
598
|
+
// Deno docs:
|
|
599
|
+
// - https://doc.deno.land/deno/stable/~/Deno.build
|
|
600
|
+
if (arch === 'x32')
|
|
601
|
+
return 'x32';
|
|
602
|
+
if (arch === 'x86_64' || arch === 'x64')
|
|
603
|
+
return 'x64';
|
|
604
|
+
if (arch === 'arm')
|
|
605
|
+
return 'arm';
|
|
606
|
+
if (arch === 'aarch64' || arch === 'arm64')
|
|
607
|
+
return 'arm64';
|
|
608
|
+
if (arch)
|
|
609
|
+
return `other:${arch}`;
|
|
610
|
+
return 'unknown';
|
|
678
611
|
};
|
|
679
612
|
const normalizePlatform = (platform) => {
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
613
|
+
// Node platforms:
|
|
614
|
+
// - https://nodejs.org/api/process.html#processplatform
|
|
615
|
+
// Deno platforms:
|
|
616
|
+
// - https://doc.deno.land/deno/stable/~/Deno.build
|
|
617
|
+
// - https://github.com/denoland/deno/issues/14799
|
|
618
|
+
platform = platform.toLowerCase();
|
|
619
|
+
// NOTE: this iOS check is untested and may not work
|
|
620
|
+
// Node does not work natively on IOS, there is a fork at
|
|
621
|
+
// https://github.com/nodejs-mobile/nodejs-mobile
|
|
622
|
+
// however it is unknown at the time of writing how to detect if it is running
|
|
623
|
+
if (platform.includes('ios'))
|
|
624
|
+
return 'iOS';
|
|
625
|
+
if (platform === 'android')
|
|
626
|
+
return 'Android';
|
|
627
|
+
if (platform === 'darwin')
|
|
628
|
+
return 'MacOS';
|
|
629
|
+
if (platform === 'win32')
|
|
630
|
+
return 'Windows';
|
|
631
|
+
if (platform === 'freebsd')
|
|
632
|
+
return 'FreeBSD';
|
|
633
|
+
if (platform === 'openbsd')
|
|
634
|
+
return 'OpenBSD';
|
|
635
|
+
if (platform === 'linux')
|
|
636
|
+
return 'Linux';
|
|
637
|
+
if (platform)
|
|
638
|
+
return `Other:${platform}`;
|
|
639
|
+
return 'Unknown';
|
|
699
640
|
};
|
|
700
641
|
let _platformHeaders;
|
|
701
642
|
const getPlatformHeaders = () => {
|
|
702
|
-
|
|
703
|
-
_platformHeaders
|
|
704
|
-
: (_platformHeaders = getPlatformProperties());
|
|
643
|
+
return (_platformHeaders ?? (_platformHeaders = getPlatformProperties()));
|
|
705
644
|
};
|
|
706
645
|
const safeJSON = (text) => {
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
646
|
+
try {
|
|
647
|
+
return JSON.parse(text);
|
|
648
|
+
}
|
|
649
|
+
catch (err) {
|
|
650
|
+
return undefined;
|
|
651
|
+
}
|
|
712
652
|
};
|
|
713
653
|
exports.safeJSON = safeJSON;
|
|
714
654
|
// https://stackoverflow.com/a/19709846
|
|
715
655
|
const startsWithSchemeRegexp = new RegExp('^(?:[a-z]+:)?//', 'i');
|
|
716
656
|
const isAbsoluteURL = (url) => {
|
|
717
|
-
|
|
657
|
+
return startsWithSchemeRegexp.test(url);
|
|
718
658
|
};
|
|
719
659
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
720
660
|
exports.sleep = sleep;
|
|
721
661
|
const validatePositiveInteger = (name, n) => {
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
662
|
+
if (typeof n !== 'number' || !Number.isInteger(n)) {
|
|
663
|
+
throw new error_1.ModernTreasuryError(`${name} must be an integer`);
|
|
664
|
+
}
|
|
665
|
+
if (n < 0) {
|
|
666
|
+
throw new error_1.ModernTreasuryError(`${name} must be a positive integer`);
|
|
667
|
+
}
|
|
668
|
+
return n;
|
|
729
669
|
};
|
|
730
670
|
const castToError = (err) => {
|
|
731
|
-
|
|
732
|
-
|
|
671
|
+
if (err instanceof Error)
|
|
672
|
+
return err;
|
|
673
|
+
return new Error(err);
|
|
733
674
|
};
|
|
734
675
|
exports.castToError = castToError;
|
|
735
676
|
const ensurePresent = (value) => {
|
|
736
|
-
|
|
737
|
-
|
|
677
|
+
if (value == null)
|
|
678
|
+
throw new error_1.ModernTreasuryError(`Expected a value to be given but received ${value} instead.`);
|
|
679
|
+
return value;
|
|
738
680
|
};
|
|
739
681
|
exports.ensurePresent = ensurePresent;
|
|
740
682
|
/**
|
|
@@ -743,126 +685,131 @@ exports.ensurePresent = ensurePresent;
|
|
|
743
685
|
* Will return undefined if the environment variable doesn't exist or cannot be accessed.
|
|
744
686
|
*/
|
|
745
687
|
const readEnv = (env) => {
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
return (_d = (_c = Deno.env) === null || _c === void 0 ? void 0 : _c.get) === null || _d === void 0 ?
|
|
754
|
-
void 0
|
|
755
|
-
: _d.call(_c, env);
|
|
756
|
-
}
|
|
757
|
-
return undefined;
|
|
688
|
+
if (typeof process !== 'undefined') {
|
|
689
|
+
return process.env?.[env] ?? undefined;
|
|
690
|
+
}
|
|
691
|
+
if (typeof Deno !== 'undefined') {
|
|
692
|
+
return Deno.env?.get?.(env);
|
|
693
|
+
}
|
|
694
|
+
return undefined;
|
|
758
695
|
};
|
|
759
696
|
exports.readEnv = readEnv;
|
|
760
697
|
const coerceInteger = (value) => {
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
698
|
+
if (typeof value === 'number')
|
|
699
|
+
return Math.round(value);
|
|
700
|
+
if (typeof value === 'string')
|
|
701
|
+
return parseInt(value, 10);
|
|
702
|
+
throw new error_1.ModernTreasuryError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
|
|
764
703
|
};
|
|
765
704
|
exports.coerceInteger = coerceInteger;
|
|
766
705
|
const coerceFloat = (value) => {
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
706
|
+
if (typeof value === 'number')
|
|
707
|
+
return value;
|
|
708
|
+
if (typeof value === 'string')
|
|
709
|
+
return parseFloat(value);
|
|
710
|
+
throw new error_1.ModernTreasuryError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
|
|
770
711
|
};
|
|
771
712
|
exports.coerceFloat = coerceFloat;
|
|
772
713
|
const coerceBoolean = (value) => {
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
714
|
+
if (typeof value === 'boolean')
|
|
715
|
+
return value;
|
|
716
|
+
if (typeof value === 'string')
|
|
717
|
+
return value === 'true';
|
|
718
|
+
return Boolean(value);
|
|
776
719
|
};
|
|
777
720
|
exports.coerceBoolean = coerceBoolean;
|
|
778
721
|
const maybeCoerceInteger = (value) => {
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
722
|
+
if (value === undefined) {
|
|
723
|
+
return undefined;
|
|
724
|
+
}
|
|
725
|
+
return (0, exports.coerceInteger)(value);
|
|
783
726
|
};
|
|
784
727
|
exports.maybeCoerceInteger = maybeCoerceInteger;
|
|
785
728
|
const maybeCoerceFloat = (value) => {
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
729
|
+
if (value === undefined) {
|
|
730
|
+
return undefined;
|
|
731
|
+
}
|
|
732
|
+
return (0, exports.coerceFloat)(value);
|
|
790
733
|
};
|
|
791
734
|
exports.maybeCoerceFloat = maybeCoerceFloat;
|
|
792
735
|
const maybeCoerceBoolean = (value) => {
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
736
|
+
if (value === undefined) {
|
|
737
|
+
return undefined;
|
|
738
|
+
}
|
|
739
|
+
return (0, exports.coerceBoolean)(value);
|
|
797
740
|
};
|
|
798
741
|
exports.maybeCoerceBoolean = maybeCoerceBoolean;
|
|
799
742
|
// https://stackoverflow.com/a/34491287
|
|
800
743
|
function isEmptyObj(obj) {
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
744
|
+
if (!obj)
|
|
745
|
+
return true;
|
|
746
|
+
for (const _k in obj)
|
|
747
|
+
return false;
|
|
748
|
+
return true;
|
|
804
749
|
}
|
|
805
750
|
exports.isEmptyObj = isEmptyObj;
|
|
806
751
|
// https://eslint.org/docs/latest/rules/no-prototype-builtins
|
|
807
752
|
function hasOwn(obj, key) {
|
|
808
|
-
|
|
753
|
+
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
809
754
|
}
|
|
810
755
|
exports.hasOwn = hasOwn;
|
|
811
756
|
function debug(action, ...args) {
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
757
|
+
if (typeof process !== 'undefined' && process.env['DEBUG'] === 'true') {
|
|
758
|
+
console.log(`ModernTreasury:DEBUG:${action}`, ...args);
|
|
759
|
+
}
|
|
815
760
|
}
|
|
816
761
|
exports.debug = debug;
|
|
817
762
|
/**
|
|
818
763
|
* https://stackoverflow.com/a/2117523
|
|
819
764
|
*/
|
|
820
765
|
const uuid4 = () => {
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
766
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
|
767
|
+
const r = (Math.random() * 16) | 0;
|
|
768
|
+
const v = c === 'x' ? r : (r & 0x3) | 0x8;
|
|
769
|
+
return v.toString(16);
|
|
770
|
+
});
|
|
826
771
|
};
|
|
827
772
|
const isRunningInBrowser = () => {
|
|
828
|
-
|
|
773
|
+
return (
|
|
829
774
|
// @ts-ignore
|
|
830
775
|
typeof window !== 'undefined' &&
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
);
|
|
776
|
+
// @ts-ignore
|
|
777
|
+
typeof window.document !== 'undefined' &&
|
|
778
|
+
// @ts-ignore
|
|
779
|
+
typeof navigator !== 'undefined');
|
|
836
780
|
};
|
|
837
781
|
exports.isRunningInBrowser = isRunningInBrowser;
|
|
838
782
|
const isHeadersProtocol = (headers) => {
|
|
839
|
-
|
|
783
|
+
return typeof headers?.get === 'function';
|
|
840
784
|
};
|
|
841
785
|
exports.isHeadersProtocol = isHeadersProtocol;
|
|
842
786
|
const getHeader = (headers, key) => {
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
if (value
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
787
|
+
const lowerKey = key.toLowerCase();
|
|
788
|
+
if ((0, exports.isHeadersProtocol)(headers))
|
|
789
|
+
return headers.get(key) || headers.get(lowerKey);
|
|
790
|
+
const value = headers[key] || headers[lowerKey];
|
|
791
|
+
if (Array.isArray(value)) {
|
|
792
|
+
if (value.length <= 1)
|
|
793
|
+
return value[0];
|
|
794
|
+
console.warn(`Received ${value.length} entries for the ${key} header, using the first entry.`);
|
|
795
|
+
return value[0];
|
|
796
|
+
}
|
|
797
|
+
return value;
|
|
852
798
|
};
|
|
853
799
|
exports.getHeader = getHeader;
|
|
854
800
|
/**
|
|
855
801
|
* Encodes a string to Base64 format.
|
|
856
802
|
*/
|
|
857
803
|
const toBase64 = (str) => {
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
804
|
+
if (!str)
|
|
805
|
+
return '';
|
|
806
|
+
if (typeof Buffer !== 'undefined') {
|
|
807
|
+
return Buffer.from(str).toString('base64');
|
|
808
|
+
}
|
|
809
|
+
if (typeof btoa !== 'undefined') {
|
|
810
|
+
return btoa(str);
|
|
811
|
+
}
|
|
812
|
+
throw new error_1.ModernTreasuryError('Cannot generate b64 string; Expected `Buffer` or `btoa` to be defined');
|
|
866
813
|
};
|
|
867
814
|
exports.toBase64 = toBase64;
|
|
868
|
-
//# sourceMappingURL=core.js.map
|
|
815
|
+
//# sourceMappingURL=core.js.map
|