@naturalpay/sdk 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +148 -0
- package/LICENSE +7 -0
- package/README.md +340 -26
- package/api-promise.d.mts +3 -0
- package/api-promise.d.mts.map +1 -0
- package/api-promise.d.ts +3 -0
- package/api-promise.d.ts.map +1 -0
- package/api-promise.js +6 -0
- package/api-promise.js.map +1 -0
- package/api-promise.mjs +3 -0
- package/api-promise.mjs.map +1 -0
- package/client.d.mts +267 -0
- package/client.d.mts.map +1 -0
- package/client.d.ts +267 -0
- package/client.d.ts.map +1 -0
- package/client.js +560 -0
- package/client.js.map +1 -0
- package/client.mjs +556 -0
- package/client.mjs.map +1 -0
- package/core/api-promise.d.mts +46 -0
- package/core/api-promise.d.mts.map +1 -0
- package/core/api-promise.d.ts +46 -0
- package/core/api-promise.d.ts.map +1 -0
- package/core/api-promise.js +74 -0
- package/core/api-promise.js.map +1 -0
- package/core/api-promise.mjs +70 -0
- package/core/api-promise.mjs.map +1 -0
- package/core/error.d.mts +46 -0
- package/core/error.d.mts.map +1 -0
- package/core/error.d.ts +46 -0
- package/core/error.d.ts.map +1 -0
- package/core/error.js +113 -0
- package/core/error.js.map +1 -0
- package/core/error.mjs +97 -0
- package/core/error.mjs.map +1 -0
- package/core/resource.d.mts +6 -0
- package/core/resource.d.mts.map +1 -0
- package/core/resource.d.ts +6 -0
- package/core/resource.d.ts.map +1 -0
- package/core/resource.js +11 -0
- package/core/resource.js.map +1 -0
- package/core/resource.mjs +7 -0
- package/core/resource.mjs.map +1 -0
- package/core/uploads.d.mts +3 -0
- package/core/uploads.d.mts.map +1 -0
- package/core/uploads.d.ts +3 -0
- package/core/uploads.d.ts.map +1 -0
- package/core/uploads.js +6 -0
- package/core/uploads.js.map +1 -0
- package/core/uploads.mjs +2 -0
- package/core/uploads.mjs.map +1 -0
- package/error.d.mts +3 -0
- package/error.d.mts.map +1 -0
- package/error.d.ts +3 -0
- package/error.d.ts.map +1 -0
- package/error.js +6 -0
- package/error.js.map +1 -0
- package/error.mjs +3 -0
- package/error.mjs.map +1 -0
- package/index.d.mts +6 -0
- package/index.d.mts.map +1 -0
- package/index.d.ts +6 -0
- package/index.d.ts.map +1 -0
- package/index.js +30 -0
- package/index.js.map +1 -0
- package/index.mjs +7 -0
- package/index.mjs.map +1 -0
- package/internal/builtin-types.d.mts +73 -0
- package/internal/builtin-types.d.mts.map +1 -0
- package/internal/builtin-types.d.ts +73 -0
- package/internal/builtin-types.d.ts.map +1 -0
- package/internal/builtin-types.js +4 -0
- package/internal/builtin-types.js.map +1 -0
- package/internal/builtin-types.mjs +3 -0
- package/internal/builtin-types.mjs.map +1 -0
- package/internal/detect-platform.d.mts +15 -0
- package/internal/detect-platform.d.mts.map +1 -0
- package/internal/detect-platform.d.ts +15 -0
- package/internal/detect-platform.d.ts.map +1 -0
- package/internal/detect-platform.js +162 -0
- package/internal/detect-platform.js.map +1 -0
- package/internal/detect-platform.mjs +157 -0
- package/internal/detect-platform.mjs.map +1 -0
- package/internal/errors.d.mts +3 -0
- package/internal/errors.d.mts.map +1 -0
- package/internal/errors.d.ts +3 -0
- package/internal/errors.d.ts.map +1 -0
- package/internal/errors.js +41 -0
- package/internal/errors.js.map +1 -0
- package/internal/errors.mjs +36 -0
- package/internal/errors.mjs.map +1 -0
- package/internal/headers.d.mts +20 -0
- package/internal/headers.d.mts.map +1 -0
- package/internal/headers.d.ts +20 -0
- package/internal/headers.d.ts.map +1 -0
- package/internal/headers.js +79 -0
- package/internal/headers.js.map +1 -0
- package/internal/headers.mjs +74 -0
- package/internal/headers.mjs.map +1 -0
- package/internal/parse.d.mts +12 -0
- package/internal/parse.d.mts.map +1 -0
- package/internal/parse.d.ts +12 -0
- package/internal/parse.d.ts.map +1 -0
- package/internal/parse.js +40 -0
- package/internal/parse.js.map +1 -0
- package/internal/parse.mjs +37 -0
- package/internal/parse.mjs.map +1 -0
- package/internal/qs/formats.d.mts +7 -0
- package/internal/qs/formats.d.mts.map +1 -0
- package/internal/qs/formats.d.ts +7 -0
- package/internal/qs/formats.d.ts.map +1 -0
- package/internal/qs/formats.js +13 -0
- package/internal/qs/formats.js.map +1 -0
- package/internal/qs/formats.mjs +9 -0
- package/internal/qs/formats.mjs.map +1 -0
- package/internal/qs/index.d.mts +10 -0
- package/internal/qs/index.d.mts.map +1 -0
- package/internal/qs/index.d.ts +10 -0
- package/internal/qs/index.d.ts.map +1 -0
- package/internal/qs/index.js +14 -0
- package/internal/qs/index.js.map +1 -0
- package/internal/qs/index.mjs +10 -0
- package/internal/qs/index.mjs.map +1 -0
- package/internal/qs/stringify.d.mts +3 -0
- package/internal/qs/stringify.d.mts.map +1 -0
- package/internal/qs/stringify.d.ts +3 -0
- package/internal/qs/stringify.d.ts.map +1 -0
- package/internal/qs/stringify.js +277 -0
- package/internal/qs/stringify.js.map +1 -0
- package/internal/qs/stringify.mjs +274 -0
- package/internal/qs/stringify.mjs.map +1 -0
- package/internal/qs/types.d.mts +57 -0
- package/internal/qs/types.d.mts.map +1 -0
- package/internal/qs/types.d.ts +57 -0
- package/internal/qs/types.d.ts.map +1 -0
- package/internal/qs/types.js +3 -0
- package/internal/qs/types.js.map +1 -0
- package/internal/qs/types.mjs +2 -0
- package/internal/qs/types.mjs.map +1 -0
- package/internal/qs/utils.d.mts +15 -0
- package/internal/qs/utils.d.mts.map +1 -0
- package/internal/qs/utils.d.ts +15 -0
- package/internal/qs/utils.d.ts.map +1 -0
- package/internal/qs/utils.js +230 -0
- package/internal/qs/utils.js.map +1 -0
- package/internal/qs/utils.mjs +217 -0
- package/internal/qs/utils.mjs.map +1 -0
- package/internal/request-options.d.mts +75 -0
- package/internal/request-options.d.mts.map +1 -0
- package/internal/request-options.d.ts +75 -0
- package/internal/request-options.d.ts.map +1 -0
- package/internal/request-options.js +14 -0
- package/internal/request-options.js.map +1 -0
- package/internal/request-options.mjs +10 -0
- package/internal/request-options.mjs.map +1 -0
- package/internal/shim-types.d.mts +17 -0
- package/internal/shim-types.d.mts.map +1 -0
- package/internal/shim-types.d.ts +17 -0
- package/internal/shim-types.d.ts.map +1 -0
- package/internal/shim-types.js +4 -0
- package/internal/shim-types.js.map +1 -0
- package/internal/shim-types.mjs +3 -0
- package/internal/shim-types.mjs.map +1 -0
- package/internal/shims.d.mts +26 -0
- package/internal/shims.d.mts.map +1 -0
- package/internal/shims.d.ts +26 -0
- package/internal/shims.d.ts.map +1 -0
- package/internal/shims.js +92 -0
- package/internal/shims.js.map +1 -0
- package/internal/shims.mjs +85 -0
- package/internal/shims.mjs.map +1 -0
- package/internal/to-file.d.mts +45 -0
- package/internal/to-file.d.mts.map +1 -0
- package/internal/to-file.d.ts +45 -0
- package/internal/to-file.d.ts.map +1 -0
- package/internal/to-file.js +91 -0
- package/internal/to-file.js.map +1 -0
- package/internal/to-file.mjs +88 -0
- package/internal/to-file.mjs.map +1 -0
- package/internal/tslib.js +81 -0
- package/internal/tslib.mjs +17 -0
- package/internal/types.d.mts +69 -0
- package/internal/types.d.mts.map +1 -0
- package/internal/types.d.ts +69 -0
- package/internal/types.d.ts.map +1 -0
- package/internal/types.js +4 -0
- package/internal/types.js.map +1 -0
- package/internal/types.mjs +3 -0
- package/internal/types.mjs.map +1 -0
- package/internal/uploads.d.mts +42 -0
- package/internal/uploads.d.mts.map +1 -0
- package/internal/uploads.d.ts +42 -0
- package/internal/uploads.d.ts.map +1 -0
- package/internal/uploads.js +141 -0
- package/internal/uploads.js.map +1 -0
- package/internal/uploads.mjs +131 -0
- package/internal/uploads.mjs.map +1 -0
- package/internal/utils/base64.d.mts +3 -0
- package/internal/utils/base64.d.mts.map +1 -0
- package/internal/utils/base64.d.ts +3 -0
- package/internal/utils/base64.d.ts.map +1 -0
- package/internal/utils/base64.js +38 -0
- package/internal/utils/base64.js.map +1 -0
- package/internal/utils/base64.mjs +33 -0
- package/internal/utils/base64.mjs.map +1 -0
- package/internal/utils/bytes.d.mts +4 -0
- package/internal/utils/bytes.d.mts.map +1 -0
- package/internal/utils/bytes.d.ts +4 -0
- package/internal/utils/bytes.d.ts.map +1 -0
- package/internal/utils/bytes.js +31 -0
- package/internal/utils/bytes.js.map +1 -0
- package/internal/utils/bytes.mjs +26 -0
- package/internal/utils/bytes.mjs.map +1 -0
- package/internal/utils/env.d.mts +9 -0
- package/internal/utils/env.d.mts.map +1 -0
- package/internal/utils/env.d.ts +9 -0
- package/internal/utils/env.d.ts.map +1 -0
- package/internal/utils/env.js +22 -0
- package/internal/utils/env.js.map +1 -0
- package/internal/utils/env.mjs +18 -0
- package/internal/utils/env.mjs.map +1 -0
- package/internal/utils/log.d.mts +37 -0
- package/internal/utils/log.d.mts.map +1 -0
- package/internal/utils/log.d.ts +37 -0
- package/internal/utils/log.d.ts.map +1 -0
- package/internal/utils/log.js +87 -0
- package/internal/utils/log.js.map +1 -0
- package/internal/utils/log.mjs +81 -0
- package/internal/utils/log.mjs.map +1 -0
- package/internal/utils/path.d.mts +15 -0
- package/internal/utils/path.d.mts.map +1 -0
- package/internal/utils/path.d.ts +15 -0
- package/internal/utils/path.d.ts.map +1 -0
- package/internal/utils/path.js +79 -0
- package/internal/utils/path.js.map +1 -0
- package/internal/utils/path.mjs +74 -0
- package/internal/utils/path.mjs.map +1 -0
- package/internal/utils/query.d.mts +2 -0
- package/internal/utils/query.d.mts.map +1 -0
- package/internal/utils/query.d.ts +2 -0
- package/internal/utils/query.d.ts.map +1 -0
- package/internal/utils/query.js +10 -0
- package/internal/utils/query.js.map +1 -0
- package/internal/utils/query.mjs +6 -0
- package/internal/utils/query.mjs.map +1 -0
- package/internal/utils/sleep.d.mts +2 -0
- package/internal/utils/sleep.d.mts.map +1 -0
- package/internal/utils/sleep.d.ts +2 -0
- package/internal/utils/sleep.d.ts.map +1 -0
- package/internal/utils/sleep.js +7 -0
- package/internal/utils/sleep.js.map +1 -0
- package/internal/utils/sleep.mjs +3 -0
- package/internal/utils/sleep.mjs.map +1 -0
- package/internal/utils/uuid.d.mts +5 -0
- package/internal/utils/uuid.d.mts.map +1 -0
- package/internal/utils/uuid.d.ts +5 -0
- package/internal/utils/uuid.d.ts.map +1 -0
- package/internal/utils/uuid.js +19 -0
- package/internal/utils/uuid.js.map +1 -0
- package/internal/utils/uuid.mjs +15 -0
- package/internal/utils/uuid.mjs.map +1 -0
- package/internal/utils/values.d.mts +18 -0
- package/internal/utils/values.d.mts.map +1 -0
- package/internal/utils/values.d.ts +18 -0
- package/internal/utils/values.d.ts.map +1 -0
- package/internal/utils/values.js +112 -0
- package/internal/utils/values.js.map +1 -0
- package/internal/utils/values.mjs +94 -0
- package/internal/utils/values.mjs.map +1 -0
- package/internal/utils.d.mts +8 -0
- package/internal/utils.d.mts.map +1 -0
- package/internal/utils.d.ts +8 -0
- package/internal/utils.d.ts.map +1 -0
- package/internal/utils.js +12 -0
- package/internal/utils.js.map +1 -0
- package/internal/utils.mjs +9 -0
- package/internal/utils.mjs.map +1 -0
- package/lib/envelope.d.mts +4 -0
- package/lib/envelope.d.mts.map +1 -0
- package/lib/envelope.d.ts +4 -0
- package/lib/envelope.d.ts.map +1 -0
- package/lib/envelope.js +43 -0
- package/lib/envelope.js.map +1 -0
- package/lib/envelope.mjs +39 -0
- package/lib/envelope.mjs.map +1 -0
- package/package.json +142 -76
- package/resource.d.mts +3 -0
- package/resource.d.mts.map +1 -0
- package/resource.d.ts +3 -0
- package/resource.d.ts.map +1 -0
- package/resource.js +6 -0
- package/resource.js.map +1 -0
- package/resource.mjs +3 -0
- package/resource.mjs.map +1 -0
- package/resources/agents.d.mts +1243 -0
- package/resources/agents.d.mts.map +1 -0
- package/resources/agents.d.ts +1243 -0
- package/resources/agents.d.ts.map +1 -0
- package/resources/agents.js +192 -0
- package/resources/agents.js.map +1 -0
- package/resources/agents.mjs +188 -0
- package/resources/agents.mjs.map +1 -0
- package/resources/api-keys.d.mts +539 -0
- package/resources/api-keys.d.mts.map +1 -0
- package/resources/api-keys.d.ts +539 -0
- package/resources/api-keys.d.ts.map +1 -0
- package/resources/api-keys.js +100 -0
- package/resources/api-keys.js.map +1 -0
- package/resources/api-keys.mjs +96 -0
- package/resources/api-keys.mjs.map +1 -0
- package/resources/counterparties.d.mts +89 -0
- package/resources/counterparties.d.mts.map +1 -0
- package/resources/counterparties.d.ts +89 -0
- package/resources/counterparties.d.ts.map +1 -0
- package/resources/counterparties.js +30 -0
- package/resources/counterparties.js.map +1 -0
- package/resources/counterparties.mjs +26 -0
- package/resources/counterparties.mjs.map +1 -0
- package/resources/customers.d.mts +272 -0
- package/resources/customers.d.mts.map +1 -0
- package/resources/customers.d.ts +272 -0
- package/resources/customers.d.ts.map +1 -0
- package/resources/customers.js +48 -0
- package/resources/customers.js.map +1 -0
- package/resources/customers.mjs +44 -0
- package/resources/customers.mjs.map +1 -0
- package/resources/delegations.d.mts +458 -0
- package/resources/delegations.d.mts.map +1 -0
- package/resources/delegations.d.ts +458 -0
- package/resources/delegations.d.ts.map +1 -0
- package/resources/delegations.js +47 -0
- package/resources/delegations.js.map +1 -0
- package/resources/delegations.mjs +43 -0
- package/resources/delegations.mjs.map +1 -0
- package/resources/external-accounts.d.mts +239 -0
- package/resources/external-accounts.d.mts.map +1 -0
- package/resources/external-accounts.d.ts +239 -0
- package/resources/external-accounts.d.ts.map +1 -0
- package/resources/external-accounts.js +47 -0
- package/resources/external-accounts.js.map +1 -0
- package/resources/external-accounts.mjs +43 -0
- package/resources/external-accounts.mjs.map +1 -0
- package/resources/index.d.mts +14 -0
- package/resources/index.d.mts.map +1 -0
- package/resources/index.d.ts +14 -0
- package/resources/index.d.ts.map +1 -0
- package/resources/index.js +31 -0
- package/resources/index.js.map +1 -0
- package/resources/index.mjs +15 -0
- package/resources/index.mjs.map +1 -0
- package/resources/invitations.d.mts +304 -0
- package/resources/invitations.d.mts.map +1 -0
- package/resources/invitations.d.ts +304 -0
- package/resources/invitations.d.ts.map +1 -0
- package/resources/invitations.js +85 -0
- package/resources/invitations.js.map +1 -0
- package/resources/invitations.mjs +81 -0
- package/resources/invitations.mjs.map +1 -0
- package/resources/parties.d.mts +364 -0
- package/resources/parties.d.mts.map +1 -0
- package/resources/parties.d.ts +364 -0
- package/resources/parties.d.ts.map +1 -0
- package/resources/parties.js +78 -0
- package/resources/parties.js.map +1 -0
- package/resources/parties.mjs +74 -0
- package/resources/parties.mjs.map +1 -0
- package/resources/payment-requests.d.mts +449 -0
- package/resources/payment-requests.d.mts.map +1 -0
- package/resources/payment-requests.d.ts +449 -0
- package/resources/payment-requests.d.ts.map +1 -0
- package/resources/payment-requests.js +86 -0
- package/resources/payment-requests.js.map +1 -0
- package/resources/payment-requests.mjs +82 -0
- package/resources/payment-requests.mjs.map +1 -0
- package/resources/payments.d.mts +174 -0
- package/resources/payments.d.mts.map +1 -0
- package/resources/payments.d.ts +174 -0
- package/resources/payments.d.ts.map +1 -0
- package/resources/payments.js +40 -0
- package/resources/payments.js.map +1 -0
- package/resources/payments.mjs +36 -0
- package/resources/payments.mjs.map +1 -0
- package/resources/transactions.d.mts +486 -0
- package/resources/transactions.d.mts.map +1 -0
- package/resources/transactions.d.ts +486 -0
- package/resources/transactions.d.ts.map +1 -0
- package/resources/transactions.js +48 -0
- package/resources/transactions.js.map +1 -0
- package/resources/transactions.mjs +44 -0
- package/resources/transactions.mjs.map +1 -0
- package/resources/wallet.d.mts +496 -0
- package/resources/wallet.d.mts.map +1 -0
- package/resources/wallet.d.ts +496 -0
- package/resources/wallet.d.ts.map +1 -0
- package/resources/wallet.js +114 -0
- package/resources/wallet.js.map +1 -0
- package/resources/wallet.mjs +110 -0
- package/resources/wallet.mjs.map +1 -0
- package/resources/webhooks.d.mts +775 -0
- package/resources/webhooks.d.mts.map +1 -0
- package/resources/webhooks.d.ts +775 -0
- package/resources/webhooks.d.ts.map +1 -0
- package/resources/webhooks.js +163 -0
- package/resources/webhooks.js.map +1 -0
- package/resources/webhooks.mjs +159 -0
- package/resources/webhooks.mjs.map +1 -0
- package/resources.d.mts +2 -0
- package/resources.d.mts.map +1 -0
- package/resources.d.ts +2 -0
- package/resources.d.ts.map +1 -0
- package/resources.js +5 -0
- package/resources.js.map +1 -0
- package/resources.mjs +2 -0
- package/resources.mjs.map +1 -0
- package/src/api-promise.ts +2 -0
- package/src/client.ts +1068 -0
- package/src/core/README.md +3 -0
- package/src/core/api-promise.ts +92 -0
- package/src/core/error.ts +130 -0
- package/src/core/resource.ts +11 -0
- package/src/core/uploads.ts +2 -0
- package/src/error.ts +2 -0
- package/src/index.ts +22 -0
- package/src/internal/README.md +3 -0
- package/src/internal/builtin-types.ts +93 -0
- package/src/internal/detect-platform.ts +196 -0
- package/src/internal/errors.ts +33 -0
- package/src/internal/headers.ts +97 -0
- package/src/internal/parse.ts +56 -0
- package/src/internal/qs/LICENSE.md +13 -0
- package/src/internal/qs/README.md +3 -0
- package/src/internal/qs/formats.ts +10 -0
- package/src/internal/qs/index.ts +13 -0
- package/src/internal/qs/stringify.ts +385 -0
- package/src/internal/qs/types.ts +71 -0
- package/src/internal/qs/utils.ts +265 -0
- package/src/internal/request-options.ts +91 -0
- package/src/internal/shim-types.ts +26 -0
- package/src/internal/shims.ts +107 -0
- package/src/internal/to-file.ts +154 -0
- package/src/internal/types.ts +93 -0
- package/src/internal/uploads.ts +187 -0
- package/src/internal/utils/base64.ts +40 -0
- package/src/internal/utils/bytes.ts +32 -0
- package/src/internal/utils/env.ts +18 -0
- package/src/internal/utils/log.ts +128 -0
- package/src/internal/utils/path.ts +88 -0
- package/src/internal/utils/query.ts +7 -0
- package/src/internal/utils/sleep.ts +3 -0
- package/src/internal/utils/uuid.ts +17 -0
- package/src/internal/utils/values.ts +105 -0
- package/src/internal/utils.ts +9 -0
- package/src/lib/.keep +4 -0
- package/src/lib/envelope.ts +32 -0
- package/src/resource.ts +2 -0
- package/src/resources/agents.ts +1605 -0
- package/src/resources/api-keys.ts +743 -0
- package/src/resources/counterparties.ts +128 -0
- package/src/resources/customers.ts +365 -0
- package/src/resources/delegations.ts +580 -0
- package/src/resources/external-accounts.ts +324 -0
- package/src/resources/index.ts +113 -0
- package/src/resources/invitations.ts +414 -0
- package/src/resources/parties.ts +493 -0
- package/src/resources/payment-requests.ts +611 -0
- package/src/resources/payments.ts +228 -0
- package/src/resources/transactions.ts +620 -0
- package/src/resources/wallet.ts +668 -0
- package/src/resources/webhooks.ts +1225 -0
- package/src/resources.ts +1 -0
- package/src/tsconfig.json +11 -0
- package/src/uploads.ts +2 -0
- package/src/version.ts +1 -0
- package/uploads.d.mts +3 -0
- package/uploads.d.mts.map +1 -0
- package/uploads.d.ts +3 -0
- package/uploads.d.ts.map +1 -0
- package/uploads.js +6 -0
- package/uploads.js.map +1 -0
- package/uploads.mjs +3 -0
- package/uploads.mjs.map +1 -0
- package/version.d.mts +2 -0
- package/version.d.mts.map +1 -0
- package/version.d.ts +2 -0
- package/version.d.ts.map +1 -0
- package/version.js +5 -0
- package/version.js.map +1 -0
- package/version.mjs +2 -0
- package/version.mjs.map +1 -0
- package/dist/index.cjs +0 -1737
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -929
- package/dist/index.d.ts +0 -929
- package/dist/index.js +0 -1705
- package/dist/index.js.map +0 -1
- package/dist/mcp/cli.cjs +0 -166
- package/dist/mcp/cli.cjs.map +0 -1
- package/dist/mcp/cli.d.cts +0 -1
- package/dist/mcp/cli.d.ts +0 -1
- package/dist/mcp/cli.js +0 -164
- package/dist/mcp/cli.js.map +0 -1
- package/dist/mcp/index.cjs +0 -8
- package/dist/mcp/index.cjs.map +0 -1
- package/dist/mcp/index.d.cts +0 -9
- package/dist/mcp/index.d.ts +0 -9
- package/dist/mcp/index.js +0 -6
- package/dist/mcp/index.js.map +0 -1
package/src/client.ts
ADDED
|
@@ -0,0 +1,1068 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import type { RequestInit, RequestInfo, BodyInit } from './internal/builtin-types';
|
|
4
|
+
import type { HTTPMethod, PromiseOrValue, MergedRequestInit, FinalizedRequestInit } from './internal/types';
|
|
5
|
+
import { uuid4 } from './internal/utils/uuid';
|
|
6
|
+
import { validatePositiveInteger, isAbsoluteURL, safeJSON } from './internal/utils/values';
|
|
7
|
+
import { sleep } from './internal/utils/sleep';
|
|
8
|
+
export type { Logger, LogLevel } from './internal/utils/log';
|
|
9
|
+
import { castToError, isAbortError } from './internal/errors';
|
|
10
|
+
import type { APIResponseProps } from './internal/parse';
|
|
11
|
+
import { getPlatformHeaders } from './internal/detect-platform';
|
|
12
|
+
import * as Shims from './internal/shims';
|
|
13
|
+
import * as Opts from './internal/request-options';
|
|
14
|
+
import { stringifyQuery } from './internal/utils/query';
|
|
15
|
+
import { VERSION } from './version';
|
|
16
|
+
import * as Errors from './core/error';
|
|
17
|
+
import * as Uploads from './core/uploads';
|
|
18
|
+
import * as API from './resources/index';
|
|
19
|
+
import { APIPromise } from './core/api-promise';
|
|
20
|
+
import { wrapIfNeeded as wrapEnvelopeBody } from './lib/envelope';
|
|
21
|
+
import {
|
|
22
|
+
AgentCreateInvitationsParams,
|
|
23
|
+
AgentCreateInvitationsResponse,
|
|
24
|
+
AgentCreateParams,
|
|
25
|
+
AgentCreateResponse,
|
|
26
|
+
AgentGetParams,
|
|
27
|
+
AgentGetResponse,
|
|
28
|
+
AgentListInvitationsForDeveloperParams,
|
|
29
|
+
AgentListInvitationsForDeveloperResponse,
|
|
30
|
+
AgentListParams,
|
|
31
|
+
AgentListResponse,
|
|
32
|
+
AgentRemoveParams,
|
|
33
|
+
AgentRemoveResponse,
|
|
34
|
+
AgentUpdateParams,
|
|
35
|
+
AgentUpdateResponse,
|
|
36
|
+
Agents,
|
|
37
|
+
} from './resources/agents';
|
|
38
|
+
import {
|
|
39
|
+
APIKeyCreateParams,
|
|
40
|
+
APIKeyCreateResponse,
|
|
41
|
+
APIKeyGetParams,
|
|
42
|
+
APIKeyGetResponse,
|
|
43
|
+
APIKeyListParams,
|
|
44
|
+
APIKeyListResponse,
|
|
45
|
+
APIKeyRevokeParams,
|
|
46
|
+
APIKeyRevokeResponse,
|
|
47
|
+
APIKeys,
|
|
48
|
+
} from './resources/api-keys';
|
|
49
|
+
import { Counterparties, CounterpartyListParams, CounterpartyListResponse } from './resources/counterparties';
|
|
50
|
+
import {
|
|
51
|
+
CustomerListInvitationsParams,
|
|
52
|
+
CustomerListInvitationsResponse,
|
|
53
|
+
CustomerListParams,
|
|
54
|
+
CustomerListResponse,
|
|
55
|
+
Customers,
|
|
56
|
+
} from './resources/customers';
|
|
57
|
+
import {
|
|
58
|
+
DelegationGetAgentDelegationParams,
|
|
59
|
+
DelegationGetAgentDelegationResponse,
|
|
60
|
+
DelegationListAgentDelegationsParams,
|
|
61
|
+
DelegationListAgentDelegationsResponse,
|
|
62
|
+
Delegations,
|
|
63
|
+
} from './resources/delegations';
|
|
64
|
+
import {
|
|
65
|
+
ExternalAccountListParams,
|
|
66
|
+
ExternalAccountListResponse,
|
|
67
|
+
ExternalAccountRemoveParams,
|
|
68
|
+
ExternalAccountRemoveResponse,
|
|
69
|
+
ExternalAccounts,
|
|
70
|
+
} from './resources/external-accounts';
|
|
71
|
+
import {
|
|
72
|
+
InvitationCreateParams,
|
|
73
|
+
InvitationCreateResponse,
|
|
74
|
+
InvitationListParams,
|
|
75
|
+
InvitationListResponse,
|
|
76
|
+
InvitationRevokeParams,
|
|
77
|
+
InvitationRevokeResponse,
|
|
78
|
+
Invitations,
|
|
79
|
+
} from './resources/invitations';
|
|
80
|
+
import {
|
|
81
|
+
Parties,
|
|
82
|
+
PartyGetParams,
|
|
83
|
+
PartyGetResponse,
|
|
84
|
+
PartyListMembersParams,
|
|
85
|
+
PartyListMembersResponse,
|
|
86
|
+
PartyUpdateParams,
|
|
87
|
+
PartyUpdateResponse,
|
|
88
|
+
} from './resources/parties';
|
|
89
|
+
import {
|
|
90
|
+
PaymentRequestCreateParams,
|
|
91
|
+
PaymentRequestCreateResponse,
|
|
92
|
+
PaymentRequestGetParams,
|
|
93
|
+
PaymentRequestGetResponse,
|
|
94
|
+
PaymentRequestListParams,
|
|
95
|
+
PaymentRequestListResponse,
|
|
96
|
+
PaymentRequests,
|
|
97
|
+
} from './resources/payment-requests';
|
|
98
|
+
import { PaymentCreateParams, PaymentCreateResponse, Payments } from './resources/payments';
|
|
99
|
+
import {
|
|
100
|
+
TransactionGetParams,
|
|
101
|
+
TransactionGetResponse,
|
|
102
|
+
TransactionListParams,
|
|
103
|
+
TransactionListResponse,
|
|
104
|
+
Transactions,
|
|
105
|
+
} from './resources/transactions';
|
|
106
|
+
import {
|
|
107
|
+
Wallet,
|
|
108
|
+
WalletGetParams,
|
|
109
|
+
WalletGetResponse,
|
|
110
|
+
WalletInitiateDepositParams,
|
|
111
|
+
WalletInitiateDepositResponse,
|
|
112
|
+
WalletInitiateWithdrawalParams,
|
|
113
|
+
WalletInitiateWithdrawalResponse,
|
|
114
|
+
WalletListParams,
|
|
115
|
+
WalletListResponse,
|
|
116
|
+
} from './resources/wallet';
|
|
117
|
+
import {
|
|
118
|
+
WebhookCreateParams,
|
|
119
|
+
WebhookCreateResponse,
|
|
120
|
+
WebhookGetParams,
|
|
121
|
+
WebhookGetResponse,
|
|
122
|
+
WebhookListParams,
|
|
123
|
+
WebhookListResponse,
|
|
124
|
+
WebhookRemoveParams,
|
|
125
|
+
WebhookRemoveResponse,
|
|
126
|
+
WebhookRotateSecretParams,
|
|
127
|
+
WebhookRotateSecretResponse,
|
|
128
|
+
WebhookUpdateParams,
|
|
129
|
+
WebhookUpdateResponse,
|
|
130
|
+
Webhooks,
|
|
131
|
+
} from './resources/webhooks';
|
|
132
|
+
import { type Fetch } from './internal/builtin-types';
|
|
133
|
+
import { HeadersLike, NullableHeaders, buildHeaders } from './internal/headers';
|
|
134
|
+
import { FinalRequestOptions, RequestOptions } from './internal/request-options';
|
|
135
|
+
import { readEnv } from './internal/utils/env';
|
|
136
|
+
import {
|
|
137
|
+
type LogLevel,
|
|
138
|
+
type Logger,
|
|
139
|
+
formatRequestDetails,
|
|
140
|
+
loggerFor,
|
|
141
|
+
parseLogLevel,
|
|
142
|
+
} from './internal/utils/log';
|
|
143
|
+
import { isEmptyObj } from './internal/utils/values';
|
|
144
|
+
|
|
145
|
+
const environments = {
|
|
146
|
+
production: 'https://api.natural.co',
|
|
147
|
+
dev: 'https://api.dev.natural.co',
|
|
148
|
+
};
|
|
149
|
+
type Environment = keyof typeof environments;
|
|
150
|
+
|
|
151
|
+
export interface ClientOptions {
|
|
152
|
+
/**
|
|
153
|
+
* Defaults to process.env['NATURAL_API_KEY'].
|
|
154
|
+
*/
|
|
155
|
+
apiKey?: string | undefined;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Specifies the environment to use for the API.
|
|
159
|
+
*
|
|
160
|
+
* Each environment maps to a different base URL:
|
|
161
|
+
* - `production` corresponds to `https://api.natural.co`
|
|
162
|
+
* - `dev` corresponds to `https://api.dev.natural.co`
|
|
163
|
+
*/
|
|
164
|
+
environment?: Environment | undefined;
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Override the default base URL for the API, e.g., "https://api.example.com/v2/"
|
|
168
|
+
*
|
|
169
|
+
* Defaults to process.env['NATURALPAY_BASE_URL'].
|
|
170
|
+
*/
|
|
171
|
+
baseURL?: string | null | undefined;
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* The maximum amount of time (in milliseconds) that the client should wait for a response
|
|
175
|
+
* from the server before timing out a single request.
|
|
176
|
+
*
|
|
177
|
+
* Note that request timeouts are retried by default, so in a worst-case scenario you may wait
|
|
178
|
+
* much longer than this timeout before the promise succeeds or fails.
|
|
179
|
+
*
|
|
180
|
+
* @unit milliseconds
|
|
181
|
+
*/
|
|
182
|
+
timeout?: number | undefined;
|
|
183
|
+
/**
|
|
184
|
+
* Additional `RequestInit` options to be passed to `fetch` calls.
|
|
185
|
+
* Properties will be overridden by per-request `fetchOptions`.
|
|
186
|
+
*/
|
|
187
|
+
fetchOptions?: MergedRequestInit | undefined;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Specify a custom `fetch` function implementation.
|
|
191
|
+
*
|
|
192
|
+
* If not provided, we expect that `fetch` is defined globally.
|
|
193
|
+
*/
|
|
194
|
+
fetch?: Fetch | undefined;
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* The maximum number of times that the client will retry a request in case of a
|
|
198
|
+
* temporary failure, like a network error or a 5XX error from the server.
|
|
199
|
+
*
|
|
200
|
+
* @default 2
|
|
201
|
+
*/
|
|
202
|
+
maxRetries?: number | undefined;
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Default headers to include with every request to the API.
|
|
206
|
+
*
|
|
207
|
+
* These can be removed in individual requests by explicitly setting the
|
|
208
|
+
* header to `null` in request options.
|
|
209
|
+
*/
|
|
210
|
+
defaultHeaders?: HeadersLike | undefined;
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Default query parameters to include with every request to the API.
|
|
214
|
+
*
|
|
215
|
+
* These can be removed in individual requests by explicitly setting the
|
|
216
|
+
* param to `undefined` in request options.
|
|
217
|
+
*/
|
|
218
|
+
defaultQuery?: Record<string, string | undefined> | undefined;
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Set the log level.
|
|
222
|
+
*
|
|
223
|
+
* Defaults to process.env['NATURALPAY_LOG'] or 'warn' if it isn't set.
|
|
224
|
+
*/
|
|
225
|
+
logLevel?: LogLevel | undefined;
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Set the logger.
|
|
229
|
+
*
|
|
230
|
+
* Defaults to globalThis.console.
|
|
231
|
+
*/
|
|
232
|
+
logger?: Logger | undefined;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* API Client for interfacing with the Naturalpay API.
|
|
237
|
+
*/
|
|
238
|
+
export class Natural {
|
|
239
|
+
apiKey: string;
|
|
240
|
+
|
|
241
|
+
baseURL: string;
|
|
242
|
+
maxRetries: number;
|
|
243
|
+
timeout: number;
|
|
244
|
+
logger: Logger;
|
|
245
|
+
logLevel: LogLevel | undefined;
|
|
246
|
+
fetchOptions: MergedRequestInit | undefined;
|
|
247
|
+
|
|
248
|
+
private fetch: Fetch;
|
|
249
|
+
#encoder: Opts.RequestEncoder;
|
|
250
|
+
protected idempotencyHeader?: string;
|
|
251
|
+
private _options: ClientOptions;
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* API Client for interfacing with the Naturalpay API.
|
|
255
|
+
*
|
|
256
|
+
* @param {string | undefined} [opts.apiKey=process.env['NATURAL_API_KEY'] ?? undefined]
|
|
257
|
+
* @param {Environment} [opts.environment=production] - Specifies the environment URL to use for the API.
|
|
258
|
+
* @param {string} [opts.baseURL=process.env['NATURALPAY_BASE_URL'] ?? https://api.natural.co] - Override the default base URL for the API.
|
|
259
|
+
* @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
|
|
260
|
+
* @param {MergedRequestInit} [opts.fetchOptions] - Additional `RequestInit` options to be passed to `fetch` calls.
|
|
261
|
+
* @param {Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
|
|
262
|
+
* @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
|
|
263
|
+
* @param {HeadersLike} opts.defaultHeaders - Default headers to include with every request to the API.
|
|
264
|
+
* @param {Record<string, string | undefined>} opts.defaultQuery - Default query parameters to include with every request to the API.
|
|
265
|
+
*/
|
|
266
|
+
constructor({
|
|
267
|
+
baseURL = readEnv('NATURALPAY_BASE_URL'),
|
|
268
|
+
apiKey = readEnv('NATURAL_API_KEY'),
|
|
269
|
+
...opts
|
|
270
|
+
}: ClientOptions = {}) {
|
|
271
|
+
if (apiKey === undefined) {
|
|
272
|
+
throw new Errors.NaturalError(
|
|
273
|
+
"The NATURAL_API_KEY environment variable is missing or empty; either provide it, or instantiate the Natural client with an apiKey option, like new Natural({ apiKey: 'My API Key' }).",
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const options: ClientOptions = {
|
|
278
|
+
apiKey,
|
|
279
|
+
...opts,
|
|
280
|
+
baseURL,
|
|
281
|
+
environment: opts.environment ?? 'production',
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
if (baseURL && opts.environment) {
|
|
285
|
+
throw new Errors.NaturalError(
|
|
286
|
+
'Ambiguous URL; The `baseURL` option (or NATURALPAY_BASE_URL env var) and the `environment` option are given. If you want to use the environment you must pass baseURL: null',
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
this.baseURL = options.baseURL || environments[options.environment || 'production'];
|
|
291
|
+
this.timeout = options.timeout ?? Natural.DEFAULT_TIMEOUT /* 1 minute */;
|
|
292
|
+
this.logger = options.logger ?? console;
|
|
293
|
+
const defaultLogLevel = 'warn';
|
|
294
|
+
// Set default logLevel early so that we can log a warning in parseLogLevel.
|
|
295
|
+
this.logLevel = defaultLogLevel;
|
|
296
|
+
this.logLevel =
|
|
297
|
+
parseLogLevel(options.logLevel, 'ClientOptions.logLevel', this) ??
|
|
298
|
+
parseLogLevel(readEnv('NATURALPAY_LOG'), "process.env['NATURALPAY_LOG']", this) ??
|
|
299
|
+
defaultLogLevel;
|
|
300
|
+
this.fetchOptions = options.fetchOptions;
|
|
301
|
+
this.maxRetries = options.maxRetries ?? 2;
|
|
302
|
+
this.fetch = options.fetch ?? Shims.getDefaultFetch();
|
|
303
|
+
this.#encoder = Opts.FallbackEncoder;
|
|
304
|
+
|
|
305
|
+
const customHeadersEnv = readEnv('NATURALPAY_CUSTOM_HEADERS');
|
|
306
|
+
if (customHeadersEnv) {
|
|
307
|
+
const parsed: Record<string, string> = {};
|
|
308
|
+
for (const line of customHeadersEnv.split('\n')) {
|
|
309
|
+
const colon = line.indexOf(':');
|
|
310
|
+
if (colon >= 0) {
|
|
311
|
+
parsed[line.substring(0, colon).trim()] = line.substring(colon + 1).trim();
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
options.defaultHeaders = { ...parsed, ...options.defaultHeaders };
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
this._options = options;
|
|
318
|
+
|
|
319
|
+
this.apiKey = apiKey;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Create a new client instance re-using the same options given to the current client with optional overriding.
|
|
324
|
+
*/
|
|
325
|
+
withOptions(options: Partial<ClientOptions>): this {
|
|
326
|
+
const client = new (this.constructor as any as new (props: ClientOptions) => typeof this)({
|
|
327
|
+
...this._options,
|
|
328
|
+
environment: options.environment ? options.environment : undefined,
|
|
329
|
+
baseURL: options.environment ? undefined : this.baseURL,
|
|
330
|
+
maxRetries: this.maxRetries,
|
|
331
|
+
timeout: this.timeout,
|
|
332
|
+
logger: this.logger,
|
|
333
|
+
logLevel: this.logLevel,
|
|
334
|
+
fetch: this.fetch,
|
|
335
|
+
fetchOptions: this.fetchOptions,
|
|
336
|
+
apiKey: this.apiKey,
|
|
337
|
+
...options,
|
|
338
|
+
});
|
|
339
|
+
return client;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Check whether the base URL is set to its default.
|
|
344
|
+
*/
|
|
345
|
+
#baseURLOverridden(): boolean {
|
|
346
|
+
return this.baseURL !== environments[this._options.environment || 'production'];
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
protected defaultQuery(): Record<string, string | undefined> | undefined {
|
|
350
|
+
return this._options.defaultQuery;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
protected validateHeaders({ values, nulls }: NullableHeaders) {
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
protected async authHeaders(opts: FinalRequestOptions): Promise<NullableHeaders | undefined> {
|
|
358
|
+
return buildHeaders([{ Authorization: `Bearer ${this.apiKey}` }]);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
protected stringifyQuery(query: object | Record<string, unknown>): string {
|
|
362
|
+
return stringifyQuery(query);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
private getUserAgent(): string {
|
|
366
|
+
return `${this.constructor.name}/JS ${VERSION}`;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
protected defaultIdempotencyKey(): string {
|
|
370
|
+
return `stainless-node-retry-${uuid4()}`;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
protected makeStatusError(
|
|
374
|
+
status: number,
|
|
375
|
+
error: Object,
|
|
376
|
+
message: string | undefined,
|
|
377
|
+
headers: Headers,
|
|
378
|
+
): Errors.APIError {
|
|
379
|
+
return Errors.APIError.generate(status, error, message, headers);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
buildURL(
|
|
383
|
+
path: string,
|
|
384
|
+
query: Record<string, unknown> | null | undefined,
|
|
385
|
+
defaultBaseURL?: string | undefined,
|
|
386
|
+
): string {
|
|
387
|
+
const baseURL = (!this.#baseURLOverridden() && defaultBaseURL) || this.baseURL;
|
|
388
|
+
const url =
|
|
389
|
+
isAbsoluteURL(path) ?
|
|
390
|
+
new URL(path)
|
|
391
|
+
: new URL(baseURL + (baseURL.endsWith('/') && path.startsWith('/') ? path.slice(1) : path));
|
|
392
|
+
|
|
393
|
+
const defaultQuery = this.defaultQuery();
|
|
394
|
+
const pathQuery = Object.fromEntries(url.searchParams);
|
|
395
|
+
if (!isEmptyObj(defaultQuery) || !isEmptyObj(pathQuery)) {
|
|
396
|
+
query = { ...pathQuery, ...defaultQuery, ...query };
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
if (typeof query === 'object' && query && !Array.isArray(query)) {
|
|
400
|
+
url.search = this.stringifyQuery(query);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
return url.toString();
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* Used as a callback for mutating the given `FinalRequestOptions` object.
|
|
408
|
+
*/
|
|
409
|
+
protected async prepareOptions(options: FinalRequestOptions): Promise<void> {}
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Used as a callback for mutating the given `RequestInit` object.
|
|
413
|
+
*
|
|
414
|
+
* This is useful for cases where you want to add certain headers based off of
|
|
415
|
+
* the request properties, e.g. `method` or `url`.
|
|
416
|
+
*/
|
|
417
|
+
protected async prepareRequest(
|
|
418
|
+
request: RequestInit,
|
|
419
|
+
{ url, options }: { url: string; options: FinalRequestOptions },
|
|
420
|
+
): Promise<void> {}
|
|
421
|
+
|
|
422
|
+
get<Rsp>(path: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp> {
|
|
423
|
+
return this.methodRequest('get', path, opts);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
post<Rsp>(path: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp> {
|
|
427
|
+
return this.methodRequest('post', path, opts);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
patch<Rsp>(path: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp> {
|
|
431
|
+
return this.methodRequest('patch', path, opts);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
put<Rsp>(path: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp> {
|
|
435
|
+
return this.methodRequest('put', path, opts);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
delete<Rsp>(path: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp> {
|
|
439
|
+
return this.methodRequest('delete', path, opts);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
private methodRequest<Rsp>(
|
|
443
|
+
method: HTTPMethod,
|
|
444
|
+
path: string,
|
|
445
|
+
opts?: PromiseOrValue<RequestOptions>,
|
|
446
|
+
): APIPromise<Rsp> {
|
|
447
|
+
return this.request(
|
|
448
|
+
Promise.resolve(opts).then((opts) => {
|
|
449
|
+
return { method, path, ...opts };
|
|
450
|
+
}),
|
|
451
|
+
);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
request<Rsp>(
|
|
455
|
+
options: PromiseOrValue<FinalRequestOptions>,
|
|
456
|
+
remainingRetries: number | null = null,
|
|
457
|
+
): APIPromise<Rsp> {
|
|
458
|
+
return new APIPromise(this, this.makeRequest(options, remainingRetries, undefined));
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
private async makeRequest(
|
|
462
|
+
optionsInput: PromiseOrValue<FinalRequestOptions>,
|
|
463
|
+
retriesRemaining: number | null,
|
|
464
|
+
retryOfRequestLogID: string | undefined,
|
|
465
|
+
): Promise<APIResponseProps> {
|
|
466
|
+
const options = await optionsInput;
|
|
467
|
+
const maxRetries = options.maxRetries ?? this.maxRetries;
|
|
468
|
+
if (retriesRemaining == null) {
|
|
469
|
+
retriesRemaining = maxRetries;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
await this.prepareOptions(options);
|
|
473
|
+
|
|
474
|
+
const { req, url, timeout } = await this.buildRequest(options, {
|
|
475
|
+
retryCount: maxRetries - retriesRemaining,
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
await this.prepareRequest(req, { url, options });
|
|
479
|
+
|
|
480
|
+
/** Not an API request ID, just for correlating local log entries. */
|
|
481
|
+
const requestLogID = 'log_' + ((Math.random() * (1 << 24)) | 0).toString(16).padStart(6, '0');
|
|
482
|
+
const retryLogStr = retryOfRequestLogID === undefined ? '' : `, retryOf: ${retryOfRequestLogID}`;
|
|
483
|
+
const startTime = Date.now();
|
|
484
|
+
|
|
485
|
+
loggerFor(this).debug(
|
|
486
|
+
`[${requestLogID}] sending request`,
|
|
487
|
+
formatRequestDetails({
|
|
488
|
+
retryOfRequestLogID,
|
|
489
|
+
method: options.method,
|
|
490
|
+
url,
|
|
491
|
+
options,
|
|
492
|
+
headers: req.headers,
|
|
493
|
+
}),
|
|
494
|
+
);
|
|
495
|
+
|
|
496
|
+
if (options.signal?.aborted) {
|
|
497
|
+
throw new Errors.APIUserAbortError();
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
const controller = new AbortController();
|
|
501
|
+
const response = await this.fetchWithTimeout(url, req, timeout, controller).catch(castToError);
|
|
502
|
+
const headersTime = Date.now();
|
|
503
|
+
|
|
504
|
+
if (response instanceof globalThis.Error) {
|
|
505
|
+
const retryMessage = `retrying, ${retriesRemaining} attempts remaining`;
|
|
506
|
+
if (options.signal?.aborted) {
|
|
507
|
+
throw new Errors.APIUserAbortError();
|
|
508
|
+
}
|
|
509
|
+
// detect native connection timeout errors
|
|
510
|
+
// deno throws "TypeError: error sending request for url (https://example/): client error (Connect): tcp connect error: Operation timed out (os error 60): Operation timed out (os error 60)"
|
|
511
|
+
// undici throws "TypeError: fetch failed" with cause "ConnectTimeoutError: Connect Timeout Error (attempted address: example:443, timeout: 1ms)"
|
|
512
|
+
// others do not provide enough information to distinguish timeouts from other connection errors
|
|
513
|
+
const isTimeout =
|
|
514
|
+
isAbortError(response) ||
|
|
515
|
+
/timed? ?out/i.test(String(response) + ('cause' in response ? String(response.cause) : ''));
|
|
516
|
+
if (retriesRemaining) {
|
|
517
|
+
loggerFor(this).info(
|
|
518
|
+
`[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} - ${retryMessage}`,
|
|
519
|
+
);
|
|
520
|
+
loggerFor(this).debug(
|
|
521
|
+
`[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} (${retryMessage})`,
|
|
522
|
+
formatRequestDetails({
|
|
523
|
+
retryOfRequestLogID,
|
|
524
|
+
url,
|
|
525
|
+
durationMs: headersTime - startTime,
|
|
526
|
+
message: response.message,
|
|
527
|
+
}),
|
|
528
|
+
);
|
|
529
|
+
return this.retryRequest(options, retriesRemaining, retryOfRequestLogID ?? requestLogID);
|
|
530
|
+
}
|
|
531
|
+
loggerFor(this).info(
|
|
532
|
+
`[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} - error; no more retries left`,
|
|
533
|
+
);
|
|
534
|
+
loggerFor(this).debug(
|
|
535
|
+
`[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} (error; no more retries left)`,
|
|
536
|
+
formatRequestDetails({
|
|
537
|
+
retryOfRequestLogID,
|
|
538
|
+
url,
|
|
539
|
+
durationMs: headersTime - startTime,
|
|
540
|
+
message: response.message,
|
|
541
|
+
}),
|
|
542
|
+
);
|
|
543
|
+
if (isTimeout) {
|
|
544
|
+
throw new Errors.APIConnectionTimeoutError();
|
|
545
|
+
}
|
|
546
|
+
throw new Errors.APIConnectionError({ cause: response });
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
const responseInfo = `[${requestLogID}${retryLogStr}] ${req.method} ${url} ${
|
|
550
|
+
response.ok ? 'succeeded' : 'failed'
|
|
551
|
+
} with status ${response.status} in ${headersTime - startTime}ms`;
|
|
552
|
+
|
|
553
|
+
if (!response.ok) {
|
|
554
|
+
const shouldRetry = await this.shouldRetry(response);
|
|
555
|
+
if (retriesRemaining && shouldRetry) {
|
|
556
|
+
const retryMessage = `retrying, ${retriesRemaining} attempts remaining`;
|
|
557
|
+
|
|
558
|
+
// We don't need the body of this response.
|
|
559
|
+
await Shims.CancelReadableStream(response.body);
|
|
560
|
+
loggerFor(this).info(`${responseInfo} - ${retryMessage}`);
|
|
561
|
+
loggerFor(this).debug(
|
|
562
|
+
`[${requestLogID}] response error (${retryMessage})`,
|
|
563
|
+
formatRequestDetails({
|
|
564
|
+
retryOfRequestLogID,
|
|
565
|
+
url: response.url,
|
|
566
|
+
status: response.status,
|
|
567
|
+
headers: response.headers,
|
|
568
|
+
durationMs: headersTime - startTime,
|
|
569
|
+
}),
|
|
570
|
+
);
|
|
571
|
+
return this.retryRequest(
|
|
572
|
+
options,
|
|
573
|
+
retriesRemaining,
|
|
574
|
+
retryOfRequestLogID ?? requestLogID,
|
|
575
|
+
response.headers,
|
|
576
|
+
);
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
const retryMessage = shouldRetry ? `error; no more retries left` : `error; not retryable`;
|
|
580
|
+
|
|
581
|
+
loggerFor(this).info(`${responseInfo} - ${retryMessage}`);
|
|
582
|
+
|
|
583
|
+
const errText = await response.text().catch((err: any) => castToError(err).message);
|
|
584
|
+
const errJSON = safeJSON(errText) as any;
|
|
585
|
+
const errMessage = errJSON ? undefined : errText;
|
|
586
|
+
|
|
587
|
+
loggerFor(this).debug(
|
|
588
|
+
`[${requestLogID}] response error (${retryMessage})`,
|
|
589
|
+
formatRequestDetails({
|
|
590
|
+
retryOfRequestLogID,
|
|
591
|
+
url: response.url,
|
|
592
|
+
status: response.status,
|
|
593
|
+
headers: response.headers,
|
|
594
|
+
message: errMessage,
|
|
595
|
+
durationMs: Date.now() - startTime,
|
|
596
|
+
}),
|
|
597
|
+
);
|
|
598
|
+
|
|
599
|
+
const err = this.makeStatusError(response.status, errJSON, errMessage, response.headers);
|
|
600
|
+
throw err;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
loggerFor(this).info(responseInfo);
|
|
604
|
+
loggerFor(this).debug(
|
|
605
|
+
`[${requestLogID}] response start`,
|
|
606
|
+
formatRequestDetails({
|
|
607
|
+
retryOfRequestLogID,
|
|
608
|
+
url: response.url,
|
|
609
|
+
status: response.status,
|
|
610
|
+
headers: response.headers,
|
|
611
|
+
durationMs: headersTime - startTime,
|
|
612
|
+
}),
|
|
613
|
+
);
|
|
614
|
+
|
|
615
|
+
return { response, options, controller, requestLogID, retryOfRequestLogID, startTime };
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
async fetchWithTimeout(
|
|
619
|
+
url: RequestInfo,
|
|
620
|
+
init: RequestInit | undefined,
|
|
621
|
+
ms: number,
|
|
622
|
+
controller: AbortController,
|
|
623
|
+
): Promise<Response> {
|
|
624
|
+
const { signal, method, ...options } = init || {};
|
|
625
|
+
const abort = this._makeAbort(controller);
|
|
626
|
+
if (signal) signal.addEventListener('abort', abort, { once: true });
|
|
627
|
+
|
|
628
|
+
const timeout = setTimeout(abort, ms);
|
|
629
|
+
|
|
630
|
+
const isReadableBody =
|
|
631
|
+
((globalThis as any).ReadableStream && options.body instanceof (globalThis as any).ReadableStream) ||
|
|
632
|
+
(typeof options.body === 'object' && options.body !== null && Symbol.asyncIterator in options.body);
|
|
633
|
+
|
|
634
|
+
const fetchOptions: RequestInit = {
|
|
635
|
+
signal: controller.signal as any,
|
|
636
|
+
...(isReadableBody ? { duplex: 'half' } : {}),
|
|
637
|
+
method: 'GET',
|
|
638
|
+
...options,
|
|
639
|
+
};
|
|
640
|
+
if (method) {
|
|
641
|
+
// Custom methods like 'patch' need to be uppercased
|
|
642
|
+
// See https://github.com/nodejs/undici/issues/2294
|
|
643
|
+
fetchOptions.method = method.toUpperCase();
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
try {
|
|
647
|
+
// use undefined this binding; fetch errors if bound to something else in browser/cloudflare
|
|
648
|
+
return await this.fetch.call(undefined, url, fetchOptions);
|
|
649
|
+
} finally {
|
|
650
|
+
clearTimeout(timeout);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
private async shouldRetry(response: Response): Promise<boolean> {
|
|
655
|
+
// Note this is not a standard header.
|
|
656
|
+
const shouldRetryHeader = response.headers.get('x-should-retry');
|
|
657
|
+
|
|
658
|
+
// If the server explicitly says whether or not to retry, obey.
|
|
659
|
+
if (shouldRetryHeader === 'true') return true;
|
|
660
|
+
if (shouldRetryHeader === 'false') return false;
|
|
661
|
+
|
|
662
|
+
// Retry on request timeouts.
|
|
663
|
+
if (response.status === 408) return true;
|
|
664
|
+
|
|
665
|
+
// Retry on lock timeouts.
|
|
666
|
+
if (response.status === 409) return true;
|
|
667
|
+
|
|
668
|
+
// Retry on rate limits.
|
|
669
|
+
if (response.status === 429) return true;
|
|
670
|
+
|
|
671
|
+
// Retry internal errors.
|
|
672
|
+
if (response.status >= 500) return true;
|
|
673
|
+
|
|
674
|
+
return false;
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
private async retryRequest(
|
|
678
|
+
options: FinalRequestOptions,
|
|
679
|
+
retriesRemaining: number,
|
|
680
|
+
requestLogID: string,
|
|
681
|
+
responseHeaders?: Headers | undefined,
|
|
682
|
+
): Promise<APIResponseProps> {
|
|
683
|
+
let timeoutMillis: number | undefined;
|
|
684
|
+
|
|
685
|
+
// Note the `retry-after-ms` header may not be standard, but is a good idea and we'd like proactive support for it.
|
|
686
|
+
const retryAfterMillisHeader = responseHeaders?.get('retry-after-ms');
|
|
687
|
+
if (retryAfterMillisHeader) {
|
|
688
|
+
const timeoutMs = parseFloat(retryAfterMillisHeader);
|
|
689
|
+
if (!Number.isNaN(timeoutMs)) {
|
|
690
|
+
timeoutMillis = timeoutMs;
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
// About the Retry-After header: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After
|
|
695
|
+
const retryAfterHeader = responseHeaders?.get('retry-after');
|
|
696
|
+
if (retryAfterHeader && !timeoutMillis) {
|
|
697
|
+
const timeoutSeconds = parseFloat(retryAfterHeader);
|
|
698
|
+
if (!Number.isNaN(timeoutSeconds)) {
|
|
699
|
+
timeoutMillis = timeoutSeconds * 1000;
|
|
700
|
+
} else {
|
|
701
|
+
timeoutMillis = Date.parse(retryAfterHeader) - Date.now();
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
// If the API asks us to wait a certain amount of time, just do what it
|
|
706
|
+
// says, but otherwise calculate a default
|
|
707
|
+
if (timeoutMillis === undefined) {
|
|
708
|
+
const maxRetries = options.maxRetries ?? this.maxRetries;
|
|
709
|
+
timeoutMillis = this.calculateDefaultRetryTimeoutMillis(retriesRemaining, maxRetries);
|
|
710
|
+
}
|
|
711
|
+
await sleep(timeoutMillis);
|
|
712
|
+
|
|
713
|
+
return this.makeRequest(options, retriesRemaining - 1, requestLogID);
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
private calculateDefaultRetryTimeoutMillis(retriesRemaining: number, maxRetries: number): number {
|
|
717
|
+
const initialRetryDelay = 0.5;
|
|
718
|
+
const maxRetryDelay = 8.0;
|
|
719
|
+
|
|
720
|
+
const numRetries = maxRetries - retriesRemaining;
|
|
721
|
+
|
|
722
|
+
// Apply exponential backoff, but not more than the max.
|
|
723
|
+
const sleepSeconds = Math.min(initialRetryDelay * Math.pow(2, numRetries), maxRetryDelay);
|
|
724
|
+
|
|
725
|
+
// Apply some jitter, take up to at most 25 percent of the retry time.
|
|
726
|
+
const jitter = 1 - Math.random() * 0.25;
|
|
727
|
+
|
|
728
|
+
return sleepSeconds * jitter * 1000;
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
async buildRequest(
|
|
732
|
+
inputOptions: FinalRequestOptions,
|
|
733
|
+
{ retryCount = 0 }: { retryCount?: number } = {},
|
|
734
|
+
): Promise<{ req: FinalizedRequestInit; url: string; timeout: number }> {
|
|
735
|
+
const options = { ...inputOptions };
|
|
736
|
+
const { method, path, query, defaultBaseURL } = options;
|
|
737
|
+
|
|
738
|
+
const url = this.buildURL(path!, query as Record<string, unknown>, defaultBaseURL);
|
|
739
|
+
if ('timeout' in options) validatePositiveInteger('timeout', options.timeout);
|
|
740
|
+
options.timeout = options.timeout ?? this.timeout;
|
|
741
|
+
options.body = wrapEnvelopeBody(options.body, options.headers);
|
|
742
|
+
const { bodyHeaders, body } = this.buildBody({ options });
|
|
743
|
+
const reqHeaders = await this.buildHeaders({ options: inputOptions, method, bodyHeaders, retryCount });
|
|
744
|
+
|
|
745
|
+
const req: FinalizedRequestInit = {
|
|
746
|
+
method,
|
|
747
|
+
headers: reqHeaders,
|
|
748
|
+
...(options.signal && { signal: options.signal }),
|
|
749
|
+
...((globalThis as any).ReadableStream &&
|
|
750
|
+
body instanceof (globalThis as any).ReadableStream && { duplex: 'half' }),
|
|
751
|
+
...(body && { body }),
|
|
752
|
+
...((this.fetchOptions as any) ?? {}),
|
|
753
|
+
...((options.fetchOptions as any) ?? {}),
|
|
754
|
+
};
|
|
755
|
+
|
|
756
|
+
return { req, url, timeout: options.timeout };
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
private async buildHeaders({
|
|
760
|
+
options,
|
|
761
|
+
method,
|
|
762
|
+
bodyHeaders,
|
|
763
|
+
retryCount,
|
|
764
|
+
}: {
|
|
765
|
+
options: FinalRequestOptions;
|
|
766
|
+
method: HTTPMethod;
|
|
767
|
+
bodyHeaders: HeadersLike;
|
|
768
|
+
retryCount: number;
|
|
769
|
+
}): Promise<Headers> {
|
|
770
|
+
let idempotencyHeaders: HeadersLike = {};
|
|
771
|
+
if (this.idempotencyHeader && method !== 'get') {
|
|
772
|
+
if (!options.idempotencyKey) options.idempotencyKey = this.defaultIdempotencyKey();
|
|
773
|
+
idempotencyHeaders[this.idempotencyHeader] = options.idempotencyKey;
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
const headers = buildHeaders([
|
|
777
|
+
idempotencyHeaders,
|
|
778
|
+
{
|
|
779
|
+
Accept: 'application/json',
|
|
780
|
+
'User-Agent': this.getUserAgent(),
|
|
781
|
+
'X-Stainless-Retry-Count': String(retryCount),
|
|
782
|
+
...(options.timeout ? { 'X-Stainless-Timeout': String(Math.trunc(options.timeout / 1000)) } : {}),
|
|
783
|
+
...getPlatformHeaders(),
|
|
784
|
+
},
|
|
785
|
+
await this.authHeaders(options),
|
|
786
|
+
this._options.defaultHeaders,
|
|
787
|
+
bodyHeaders,
|
|
788
|
+
options.headers,
|
|
789
|
+
]);
|
|
790
|
+
|
|
791
|
+
this.validateHeaders(headers);
|
|
792
|
+
|
|
793
|
+
return headers.values;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
private _makeAbort(controller: AbortController) {
|
|
797
|
+
// note: we can't just inline this method inside `fetchWithTimeout()` because then the closure
|
|
798
|
+
// would capture all request options, and cause a memory leak.
|
|
799
|
+
return () => controller.abort();
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
private buildBody({ options: { body, headers: rawHeaders } }: { options: FinalRequestOptions }): {
|
|
803
|
+
bodyHeaders: HeadersLike;
|
|
804
|
+
body: BodyInit | undefined;
|
|
805
|
+
} {
|
|
806
|
+
if (!body) {
|
|
807
|
+
return { bodyHeaders: undefined, body: undefined };
|
|
808
|
+
}
|
|
809
|
+
const headers = buildHeaders([rawHeaders]);
|
|
810
|
+
if (
|
|
811
|
+
// Pass raw type verbatim
|
|
812
|
+
ArrayBuffer.isView(body) ||
|
|
813
|
+
body instanceof ArrayBuffer ||
|
|
814
|
+
body instanceof DataView ||
|
|
815
|
+
(typeof body === 'string' &&
|
|
816
|
+
// Preserve legacy string encoding behavior for now
|
|
817
|
+
headers.values.has('content-type')) ||
|
|
818
|
+
// `Blob` is superset of `File`
|
|
819
|
+
((globalThis as any).Blob && body instanceof (globalThis as any).Blob) ||
|
|
820
|
+
// `FormData` -> `multipart/form-data`
|
|
821
|
+
body instanceof FormData ||
|
|
822
|
+
// `URLSearchParams` -> `application/x-www-form-urlencoded`
|
|
823
|
+
body instanceof URLSearchParams ||
|
|
824
|
+
// Send chunked stream (each chunk has own `length`)
|
|
825
|
+
((globalThis as any).ReadableStream && body instanceof (globalThis as any).ReadableStream)
|
|
826
|
+
) {
|
|
827
|
+
return { bodyHeaders: undefined, body: body as BodyInit };
|
|
828
|
+
} else if (
|
|
829
|
+
typeof body === 'object' &&
|
|
830
|
+
(Symbol.asyncIterator in body ||
|
|
831
|
+
(Symbol.iterator in body && 'next' in body && typeof body.next === 'function'))
|
|
832
|
+
) {
|
|
833
|
+
return { bodyHeaders: undefined, body: Shims.ReadableStreamFrom(body as AsyncIterable<Uint8Array>) };
|
|
834
|
+
} else if (
|
|
835
|
+
typeof body === 'object' &&
|
|
836
|
+
headers.values.get('content-type') === 'application/x-www-form-urlencoded'
|
|
837
|
+
) {
|
|
838
|
+
return {
|
|
839
|
+
bodyHeaders: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
840
|
+
body: this.stringifyQuery(body),
|
|
841
|
+
};
|
|
842
|
+
} else {
|
|
843
|
+
return this.#encoder({ body, headers });
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
static Natural = this;
|
|
848
|
+
static DEFAULT_TIMEOUT = 60000; // 1 minute
|
|
849
|
+
|
|
850
|
+
static NaturalError = Errors.NaturalError;
|
|
851
|
+
static APIError = Errors.APIError;
|
|
852
|
+
static APIConnectionError = Errors.APIConnectionError;
|
|
853
|
+
static APIConnectionTimeoutError = Errors.APIConnectionTimeoutError;
|
|
854
|
+
static APIUserAbortError = Errors.APIUserAbortError;
|
|
855
|
+
static NotFoundError = Errors.NotFoundError;
|
|
856
|
+
static ConflictError = Errors.ConflictError;
|
|
857
|
+
static RateLimitError = Errors.RateLimitError;
|
|
858
|
+
static BadRequestError = Errors.BadRequestError;
|
|
859
|
+
static AuthenticationError = Errors.AuthenticationError;
|
|
860
|
+
static InternalServerError = Errors.InternalServerError;
|
|
861
|
+
static PermissionDeniedError = Errors.PermissionDeniedError;
|
|
862
|
+
static UnprocessableEntityError = Errors.UnprocessableEntityError;
|
|
863
|
+
|
|
864
|
+
static toFile = Uploads.toFile;
|
|
865
|
+
|
|
866
|
+
/**
|
|
867
|
+
* Agent management
|
|
868
|
+
*/
|
|
869
|
+
agents: API.Agents = new API.Agents(this);
|
|
870
|
+
/**
|
|
871
|
+
* API key management
|
|
872
|
+
*/
|
|
873
|
+
apiKeys: API.APIKeys = new API.APIKeys(this);
|
|
874
|
+
/**
|
|
875
|
+
* Counterparty management
|
|
876
|
+
*/
|
|
877
|
+
counterparties: API.Counterparties = new API.Counterparties(this);
|
|
878
|
+
/**
|
|
879
|
+
* Customer management
|
|
880
|
+
*/
|
|
881
|
+
customers: API.Customers = new API.Customers(this);
|
|
882
|
+
/**
|
|
883
|
+
* Agent delegation management
|
|
884
|
+
*/
|
|
885
|
+
delegations: API.Delegations = new API.Delegations(this);
|
|
886
|
+
/**
|
|
887
|
+
* Party invitation management
|
|
888
|
+
*/
|
|
889
|
+
invitations: API.Invitations = new API.Invitations(this);
|
|
890
|
+
/**
|
|
891
|
+
* Party and organization management
|
|
892
|
+
*/
|
|
893
|
+
parties: API.Parties = new API.Parties(this);
|
|
894
|
+
/**
|
|
895
|
+
* Payment-request management
|
|
896
|
+
*/
|
|
897
|
+
paymentRequests: API.PaymentRequests = new API.PaymentRequests(this);
|
|
898
|
+
/**
|
|
899
|
+
* Payment and transaction operations
|
|
900
|
+
*/
|
|
901
|
+
payments: API.Payments = new API.Payments(this);
|
|
902
|
+
/**
|
|
903
|
+
* Payment and transaction operations
|
|
904
|
+
*/
|
|
905
|
+
transactions: API.Transactions = new API.Transactions(this);
|
|
906
|
+
/**
|
|
907
|
+
* Webhook endpoint management
|
|
908
|
+
*/
|
|
909
|
+
webhooks: API.Webhooks = new API.Webhooks(this);
|
|
910
|
+
/**
|
|
911
|
+
* Wallet balance, deposits, withdrawals, and external accounts
|
|
912
|
+
*/
|
|
913
|
+
wallet: API.Wallet = new API.Wallet(this);
|
|
914
|
+
/**
|
|
915
|
+
* Linked external bank accounts
|
|
916
|
+
*/
|
|
917
|
+
externalAccounts: API.ExternalAccounts = new API.ExternalAccounts(this);
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
Natural.Agents = Agents;
|
|
921
|
+
Natural.APIKeys = APIKeys;
|
|
922
|
+
Natural.Counterparties = Counterparties;
|
|
923
|
+
Natural.Customers = Customers;
|
|
924
|
+
Natural.Delegations = Delegations;
|
|
925
|
+
Natural.Invitations = Invitations;
|
|
926
|
+
Natural.Parties = Parties;
|
|
927
|
+
Natural.PaymentRequests = PaymentRequests;
|
|
928
|
+
Natural.Payments = Payments;
|
|
929
|
+
Natural.Transactions = Transactions;
|
|
930
|
+
Natural.Webhooks = Webhooks;
|
|
931
|
+
Natural.Wallet = Wallet;
|
|
932
|
+
Natural.ExternalAccounts = ExternalAccounts;
|
|
933
|
+
|
|
934
|
+
export declare namespace Natural {
|
|
935
|
+
export type RequestOptions = Opts.RequestOptions;
|
|
936
|
+
|
|
937
|
+
export {
|
|
938
|
+
Agents as Agents,
|
|
939
|
+
type AgentCreateResponse as AgentCreateResponse,
|
|
940
|
+
type AgentUpdateResponse as AgentUpdateResponse,
|
|
941
|
+
type AgentListResponse as AgentListResponse,
|
|
942
|
+
type AgentCreateInvitationsResponse as AgentCreateInvitationsResponse,
|
|
943
|
+
type AgentGetResponse as AgentGetResponse,
|
|
944
|
+
type AgentListInvitationsForDeveloperResponse as AgentListInvitationsForDeveloperResponse,
|
|
945
|
+
type AgentRemoveResponse as AgentRemoveResponse,
|
|
946
|
+
type AgentCreateParams as AgentCreateParams,
|
|
947
|
+
type AgentUpdateParams as AgentUpdateParams,
|
|
948
|
+
type AgentListParams as AgentListParams,
|
|
949
|
+
type AgentCreateInvitationsParams as AgentCreateInvitationsParams,
|
|
950
|
+
type AgentGetParams as AgentGetParams,
|
|
951
|
+
type AgentListInvitationsForDeveloperParams as AgentListInvitationsForDeveloperParams,
|
|
952
|
+
type AgentRemoveParams as AgentRemoveParams,
|
|
953
|
+
};
|
|
954
|
+
|
|
955
|
+
export {
|
|
956
|
+
APIKeys as APIKeys,
|
|
957
|
+
type APIKeyCreateResponse as APIKeyCreateResponse,
|
|
958
|
+
type APIKeyListResponse as APIKeyListResponse,
|
|
959
|
+
type APIKeyGetResponse as APIKeyGetResponse,
|
|
960
|
+
type APIKeyRevokeResponse as APIKeyRevokeResponse,
|
|
961
|
+
type APIKeyCreateParams as APIKeyCreateParams,
|
|
962
|
+
type APIKeyListParams as APIKeyListParams,
|
|
963
|
+
type APIKeyGetParams as APIKeyGetParams,
|
|
964
|
+
type APIKeyRevokeParams as APIKeyRevokeParams,
|
|
965
|
+
};
|
|
966
|
+
|
|
967
|
+
export {
|
|
968
|
+
Counterparties as Counterparties,
|
|
969
|
+
type CounterpartyListResponse as CounterpartyListResponse,
|
|
970
|
+
type CounterpartyListParams as CounterpartyListParams,
|
|
971
|
+
};
|
|
972
|
+
|
|
973
|
+
export {
|
|
974
|
+
Customers as Customers,
|
|
975
|
+
type CustomerListResponse as CustomerListResponse,
|
|
976
|
+
type CustomerListInvitationsResponse as CustomerListInvitationsResponse,
|
|
977
|
+
type CustomerListParams as CustomerListParams,
|
|
978
|
+
type CustomerListInvitationsParams as CustomerListInvitationsParams,
|
|
979
|
+
};
|
|
980
|
+
|
|
981
|
+
export {
|
|
982
|
+
Delegations as Delegations,
|
|
983
|
+
type DelegationGetAgentDelegationResponse as DelegationGetAgentDelegationResponse,
|
|
984
|
+
type DelegationListAgentDelegationsResponse as DelegationListAgentDelegationsResponse,
|
|
985
|
+
type DelegationGetAgentDelegationParams as DelegationGetAgentDelegationParams,
|
|
986
|
+
type DelegationListAgentDelegationsParams as DelegationListAgentDelegationsParams,
|
|
987
|
+
};
|
|
988
|
+
|
|
989
|
+
export {
|
|
990
|
+
Invitations as Invitations,
|
|
991
|
+
type InvitationCreateResponse as InvitationCreateResponse,
|
|
992
|
+
type InvitationListResponse as InvitationListResponse,
|
|
993
|
+
type InvitationRevokeResponse as InvitationRevokeResponse,
|
|
994
|
+
type InvitationCreateParams as InvitationCreateParams,
|
|
995
|
+
type InvitationListParams as InvitationListParams,
|
|
996
|
+
type InvitationRevokeParams as InvitationRevokeParams,
|
|
997
|
+
};
|
|
998
|
+
|
|
999
|
+
export {
|
|
1000
|
+
Parties as Parties,
|
|
1001
|
+
type PartyUpdateResponse as PartyUpdateResponse,
|
|
1002
|
+
type PartyGetResponse as PartyGetResponse,
|
|
1003
|
+
type PartyListMembersResponse as PartyListMembersResponse,
|
|
1004
|
+
type PartyUpdateParams as PartyUpdateParams,
|
|
1005
|
+
type PartyGetParams as PartyGetParams,
|
|
1006
|
+
type PartyListMembersParams as PartyListMembersParams,
|
|
1007
|
+
};
|
|
1008
|
+
|
|
1009
|
+
export {
|
|
1010
|
+
PaymentRequests as PaymentRequests,
|
|
1011
|
+
type PaymentRequestCreateResponse as PaymentRequestCreateResponse,
|
|
1012
|
+
type PaymentRequestListResponse as PaymentRequestListResponse,
|
|
1013
|
+
type PaymentRequestGetResponse as PaymentRequestGetResponse,
|
|
1014
|
+
type PaymentRequestCreateParams as PaymentRequestCreateParams,
|
|
1015
|
+
type PaymentRequestListParams as PaymentRequestListParams,
|
|
1016
|
+
type PaymentRequestGetParams as PaymentRequestGetParams,
|
|
1017
|
+
};
|
|
1018
|
+
|
|
1019
|
+
export {
|
|
1020
|
+
Payments as Payments,
|
|
1021
|
+
type PaymentCreateResponse as PaymentCreateResponse,
|
|
1022
|
+
type PaymentCreateParams as PaymentCreateParams,
|
|
1023
|
+
};
|
|
1024
|
+
|
|
1025
|
+
export {
|
|
1026
|
+
Transactions as Transactions,
|
|
1027
|
+
type TransactionListResponse as TransactionListResponse,
|
|
1028
|
+
type TransactionGetResponse as TransactionGetResponse,
|
|
1029
|
+
type TransactionListParams as TransactionListParams,
|
|
1030
|
+
type TransactionGetParams as TransactionGetParams,
|
|
1031
|
+
};
|
|
1032
|
+
|
|
1033
|
+
export {
|
|
1034
|
+
Webhooks as Webhooks,
|
|
1035
|
+
type WebhookCreateResponse as WebhookCreateResponse,
|
|
1036
|
+
type WebhookUpdateResponse as WebhookUpdateResponse,
|
|
1037
|
+
type WebhookListResponse as WebhookListResponse,
|
|
1038
|
+
type WebhookGetResponse as WebhookGetResponse,
|
|
1039
|
+
type WebhookRemoveResponse as WebhookRemoveResponse,
|
|
1040
|
+
type WebhookRotateSecretResponse as WebhookRotateSecretResponse,
|
|
1041
|
+
type WebhookCreateParams as WebhookCreateParams,
|
|
1042
|
+
type WebhookUpdateParams as WebhookUpdateParams,
|
|
1043
|
+
type WebhookListParams as WebhookListParams,
|
|
1044
|
+
type WebhookGetParams as WebhookGetParams,
|
|
1045
|
+
type WebhookRemoveParams as WebhookRemoveParams,
|
|
1046
|
+
type WebhookRotateSecretParams as WebhookRotateSecretParams,
|
|
1047
|
+
};
|
|
1048
|
+
|
|
1049
|
+
export {
|
|
1050
|
+
Wallet as Wallet,
|
|
1051
|
+
type WalletListResponse as WalletListResponse,
|
|
1052
|
+
type WalletGetResponse as WalletGetResponse,
|
|
1053
|
+
type WalletInitiateDepositResponse as WalletInitiateDepositResponse,
|
|
1054
|
+
type WalletInitiateWithdrawalResponse as WalletInitiateWithdrawalResponse,
|
|
1055
|
+
type WalletListParams as WalletListParams,
|
|
1056
|
+
type WalletGetParams as WalletGetParams,
|
|
1057
|
+
type WalletInitiateDepositParams as WalletInitiateDepositParams,
|
|
1058
|
+
type WalletInitiateWithdrawalParams as WalletInitiateWithdrawalParams,
|
|
1059
|
+
};
|
|
1060
|
+
|
|
1061
|
+
export {
|
|
1062
|
+
ExternalAccounts as ExternalAccounts,
|
|
1063
|
+
type ExternalAccountListResponse as ExternalAccountListResponse,
|
|
1064
|
+
type ExternalAccountRemoveResponse as ExternalAccountRemoveResponse,
|
|
1065
|
+
type ExternalAccountListParams as ExternalAccountListParams,
|
|
1066
|
+
type ExternalAccountRemoveParams as ExternalAccountRemoveParams,
|
|
1067
|
+
};
|
|
1068
|
+
}
|