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