diff --git a/.gitignore b/.gitignore index 47d65d5..3b0d668 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +/react-query /funcs /core.* /__tests__ diff --git a/.npmignore b/.npmignore index 06cd8ab..9ad259e 100644 --- a/.npmignore +++ b/.npmignore @@ -1,4 +1,7 @@ **/* +!/FUNCTIONS.md +!/RUNTIMES.md +!/REACT_QUERY.md !/**/*.ts !/**/*.js !/**/*.map diff --git a/.speakeasy/gen.lock b/.speakeasy/gen.lock index 626eada..a2ee931 100755 --- a/.speakeasy/gen.lock +++ b/.speakeasy/gen.lock @@ -1,12 +1,12 @@ lockVersion: 2.0.0 id: 79fa0df9-852a-493c-b998-1d82654b5f18 management: - docChecksum: 8ff3e37e3bcdf4b0ef72f37df29c2c47 - docVersion: 3.3.0 - speakeasyVersion: 1.449.0 - generationVersion: 2.467.4 - releaseVersion: 0.23.0 - configChecksum: d60a73c628ceca172cfcceb6dc5ad337 + docChecksum: cd02dacb5ea03529426acee148b52684 + docVersion: 3.3.1 + speakeasyVersion: 1.454.2 + generationVersion: 2.477.4 + releaseVersion: 0.23.1 + configChecksum: b0966968c7e705fe09976d316aa62073 repoURL: https://github.com/BoltApp/Bolt-Typescript-SDK.git repoSubDirectory: . installationURL: https://github.com/BoltApp/Bolt-Typescript-SDK @@ -14,12 +14,12 @@ management: features: typescript: additionalDependencies: 0.1.0 - core: 3.18.7 + core: 3.18.9 defaultEnabledRetries: 0.1.0 enumUnions: 0.1.0 envVarSecurityUsage: 0.1.2 errorUnions: 0.1.1 - flattening: 2.82.0 + flattening: 2.82.1 globalSecurity: 2.82.11 globalSecurityCallbacks: 0.1.0 globalServerURLs: 2.82.4 diff --git a/.speakeasy/workflow.lock b/.speakeasy/workflow.lock index 2a9fecb..b88734e 100644 --- a/.speakeasy/workflow.lock +++ b/.speakeasy/workflow.lock @@ -1,21 +1,21 @@ -speakeasyVersion: 1.449.0 +speakeasyVersion: 1.454.2 sources: my-source: sourceNamespace: my-source - sourceRevisionDigest: sha256:564817516826aa870a4ec6daa86a0e6edc44a45a6eece5da503f62be38bbd61d - sourceBlobDigest: sha256:51c81ecaaa90446ad8968d89a42a84bcd2b3bfa0f97ba4cb8aae067637538117 + sourceRevisionDigest: sha256:62a85f15193c9b727b646641ae7cd60bcf0799f5522f545dd5212207c7a77cc1 + sourceBlobDigest: sha256:13a47f75ea523066457c04434bb9431410e7b4b9454d7d0049f421cab0a1ebd8 tags: - latest - - speakeasy-sdk-regen-1733185446 - - 3.3.0 + - speakeasy-sdk-regen-1734049410 + - 3.3.1 targets: bolt-typescript: source: my-source sourceNamespace: my-source - sourceRevisionDigest: sha256:564817516826aa870a4ec6daa86a0e6edc44a45a6eece5da503f62be38bbd61d - sourceBlobDigest: sha256:51c81ecaaa90446ad8968d89a42a84bcd2b3bfa0f97ba4cb8aae067637538117 + sourceRevisionDigest: sha256:62a85f15193c9b727b646641ae7cd60bcf0799f5522f545dd5212207c7a77cc1 + sourceBlobDigest: sha256:13a47f75ea523066457c04434bb9431410e7b4b9454d7d0049f421cab0a1ebd8 codeSamplesNamespace: my-source-typescript-code-samples - codeSamplesRevisionDigest: sha256:1e67a4d948be1746b0c30a78421cbaf9fd9683468f988851b5f358405dd45cee + codeSamplesRevisionDigest: sha256:0f7a81ea5668c61b27ec3454f2c7551aa3354b01104bcc0375972617103c0c86 workflow: workflowVersion: 1.0.0 speakeasyVersion: latest diff --git a/README.md b/README.md index 602b52a..5364b23 100644 --- a/README.md +++ b/README.md @@ -143,19 +143,7 @@ run(); ## Error Handling -All SDK methods return a response object or throw an error. By default, an API error will throw a `errors.SDKError`. - -If a HTTP request fails, an operation my also throw an error from the `models/errors/httpclienterrors.ts` module: - -| HTTP Client Error | Description | -| ---------------------------------------------------- | ---------------------------------------------------- | -| RequestAbortedError | HTTP request was aborted by the client | -| RequestTimeoutError | HTTP request timed out due to an AbortSignal signal | -| ConnectionError | HTTP client was unable to make a request to a server | -| InvalidRequestError | Any input used to create a request is invalid | -| UnexpectedClientError | Unrecognised or unexpected error | - -In addition, when custom error responses are specified for an operation, the SDK may throw their associated Error type. You can refer to respective *Errors* tables in SDK docs for more details on possible error types for each operation. For example, the `getDetails` method may throw the following errors: +Some methods specify known errors which can be thrown. All the known errors are enumerated in the `models/errors/errors.ts` module. The known errors for a method are documented under the *Errors* tables in SDK docs. For example, the `getDetails` method may throw the following errors: | Error Type | Status Code | Content Type | | ----------------- | ----------- | ---------------- | @@ -163,6 +151,8 @@ In addition, when custom error responses are specified for an operation, the SDK | errors.FieldError | 4XX | application/json | | errors.SDKError | 5XX | \*/\* | +If the method throws an error and it is not captured by the known errors, it will default to throwing a `SDKError`. + ```typescript import { BoltTypescriptSDK } from "@boltpay/bolt-typescript-sdk"; import { @@ -187,8 +177,9 @@ async function run() { console.log(result); } catch (err) { switch (true) { + // The server response does not match the expected SDK schema case (err instanceof SDKValidationError): { - // Validation errors can be pretty-printed + // Pretty-print will provide a human-readable multi-line error message console.error(err.pretty()); // Raw value may also be inspected console.error(err.rawValue); @@ -203,6 +194,7 @@ async function run() { return; } default: { + // Other errors such as network errors, see HTTPClientErrors for more details throw err; } } @@ -213,7 +205,17 @@ run(); ``` -Validation errors can also occur when either method arguments or data returned from the server do not match the expected format. The `SDKValidationError` that is thrown as a result will capture the raw value that failed validation in an attribute called `rawValue`. Additionally, a `pretty()` method is available on this error that can be used to log a nicely formatted string since validation errors can list many issues and the plain error string may be difficult read when debugging. +Validation errors can also occur when either method arguments or data returned from the server do not match the expected format. The `SDKValidationError` that is thrown as a result will capture the raw value that failed validation in an attribute called `rawValue`. Additionally, a `pretty()` method is available on this error that can be used to log a nicely formatted multi-line string since validation errors can list many issues and the plain error string may be difficult read when debugging. + +In some rare cases, the SDK can fail to get a response from the server or even make the request due to unexpected circumstances such as network conditions. These types of errors are captured in the `models/errors/httpclienterrors.ts` module: + +| HTTP Client Error | Description | +| ---------------------------------------------------- | ---------------------------------------------------- | +| RequestAbortedError | HTTP request was aborted by the client | +| RequestTimeoutError | HTTP request timed out due to an AbortSignal signal | +| ConnectionError | HTTP client was unable to make a request to a server | +| InvalidRequestError | Any input used to create a request is invalid | +| UnexpectedClientError | Unrecognised or unexpected error | diff --git a/RELEASES.md b/RELEASES.md index a7bc192..d0e70bc 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -598,4 +598,14 @@ Based on: ### Generated - [typescript v0.23.0] . ### Releases -- [NPM v0.23.0] https://www.npmjs.com/package/@boltpay/bolt-typescript-sdk/v/0.23.0 - . \ No newline at end of file +- [NPM v0.23.0] https://www.npmjs.com/package/@boltpay/bolt-typescript-sdk/v/0.23.0 - . + +## 2024-12-13 00:23:27 +### Changes +Based on: +- OpenAPI Doc +- Speakeasy CLI 1.454.2 (2.477.4) https://github.com/speakeasy-api/speakeasy +### Generated +- [typescript v0.23.1] . +### Releases +- [NPM v0.23.1] https://www.npmjs.com/package/@boltpay/bolt-typescript-sdk/v/0.23.1 - . \ No newline at end of file diff --git a/gen.yaml b/gen.yaml index 36f229d..5ac38a3 100644 --- a/gen.yaml +++ b/gen.yaml @@ -13,7 +13,7 @@ generation: oAuth2ClientCredentialsEnabled: false oAuth2PasswordEnabled: false typescript: - version: 0.23.0 + version: 0.23.1 additionalDependencies: dependencies: {} devDependencies: {} diff --git a/jsr.json b/jsr.json index f7b8835..cfd5815 100644 --- a/jsr.json +++ b/jsr.json @@ -2,7 +2,7 @@ { "name": "@boltpay/bolt-typescript-sdk", - "version": "0.23.0", + "version": "0.23.1", "exports": { ".": "./src/index.ts", "./models/errors": "./src/models/errors/index.ts", diff --git a/package-lock.json b/package-lock.json index 4045958..85d066b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@boltpay/bolt-typescript-sdk", - "version": "0.23.0", + "version": "0.23.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@boltpay/bolt-typescript-sdk", - "version": "0.23.0", + "version": "0.23.1", "devDependencies": { "@typescript-eslint/eslint-plugin": "^7.7.1", "@typescript-eslint/parser": "^7.7.1", @@ -17,8 +17,6 @@ "zod": "^3.23.4" }, "peerDependencies": { - "react": "^18 || ^19", - "react-dom": "^18 || ^19", "zod": ">= 3" } }, @@ -2023,13 +2021,6 @@ "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", "dev": true }, - "node_modules/js-tokens": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", - "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", - "license": "MIT", - "peer": true - }, "node_modules/js-yaml": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", @@ -2115,19 +2106,6 @@ "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==", "dev": true }, - "node_modules/loose-envify": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", - "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==", - "license": "MIT", - "peer": true, - "dependencies": { - "js-tokens": "^3.0.0 || ^4.0.0" - }, - "bin": { - "loose-envify": "cli.js" - } - }, "node_modules/merge2": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", @@ -2438,33 +2416,6 @@ } ] }, - "node_modules/react": { - "version": "18.3.1", - "resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz", - "integrity": "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==", - "license": "MIT", - "peer": true, - "dependencies": { - "loose-envify": "^1.1.0" - }, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/react-dom": { - "version": "18.3.1", - "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.3.1.tgz", - "integrity": "sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==", - "license": "MIT", - "peer": true, - "dependencies": { - "loose-envify": "^1.1.0", - "scheduler": "^0.23.2" - }, - "peerDependencies": { - "react": "^18.3.1" - } - }, "node_modules/regexp.prototype.flags": { "version": "1.5.2", "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.5.2.tgz", @@ -2601,16 +2552,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/scheduler": { - "version": "0.23.2", - "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.2.tgz", - "integrity": "sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ==", - "license": "MIT", - "peer": true, - "dependencies": { - "loose-envify": "^1.1.0" - } - }, "node_modules/semver": { "version": "7.6.1", "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.1.tgz", @@ -4513,12 +4454,6 @@ "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", "dev": true }, - "js-tokens": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", - "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", - "peer": true - }, "js-yaml": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", @@ -4589,15 +4524,6 @@ "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==", "dev": true }, - "loose-envify": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", - "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==", - "peer": true, - "requires": { - "js-tokens": "^3.0.0 || ^4.0.0" - } - }, "merge2": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", @@ -4810,25 +4736,6 @@ "integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==", "dev": true }, - "react": { - "version": "18.3.1", - "resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz", - "integrity": "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==", - "peer": true, - "requires": { - "loose-envify": "^1.1.0" - } - }, - "react-dom": { - "version": "18.3.1", - "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.3.1.tgz", - "integrity": "sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==", - "peer": true, - "requires": { - "loose-envify": "^1.1.0", - "scheduler": "^0.23.2" - } - }, "regexp.prototype.flags": { "version": "1.5.2", "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.5.2.tgz", @@ -4911,15 +4818,6 @@ "is-regex": "^1.1.4" } }, - "scheduler": { - "version": "0.23.2", - "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.2.tgz", - "integrity": "sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ==", - "peer": true, - "requires": { - "loose-envify": "^1.1.0" - } - }, "semver": { "version": "7.6.1", "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.1.tgz", diff --git a/package.json b/package.json index fba689d..cc3eb41 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@boltpay/bolt-typescript-sdk", - "version": "0.23.0", + "version": "0.23.1", "author": "BoltPublicAPI", "main": "./index.js", "sideEffects": false, @@ -15,8 +15,6 @@ "prepublishOnly": "npm run build" }, "peerDependencies": { - "react": "^18 || ^19", - "react-dom": "^18 || ^19", "zod": ">= 3" }, "devDependencies": { diff --git a/src/hooks/hooks.ts b/src/hooks/hooks.ts index e892d77..fc9b13b 100644 --- a/src/hooks/hooks.ts +++ b/src/hooks/hooks.ts @@ -12,6 +12,7 @@ import { BeforeCreateRequestHook, BeforeRequestContext, BeforeRequestHook, + Hook, Hooks, SDKInitHook, SDKInitOptions, @@ -25,6 +26,25 @@ export class SDKHooks implements Hooks { afterErrorHooks: AfterErrorHook[] = []; constructor() { + const presetHooks: Array = []; + + for (const hook of presetHooks) { + if ("sdkInit" in hook) { + this.registerSDKInitHook(hook); + } + if ("beforeCreateRequest" in hook) { + this.registerBeforeCreateRequestHook(hook); + } + if ("beforeRequest" in hook) { + this.registerBeforeRequestHook(hook); + } + if ("afterSuccess" in hook) { + this.registerAfterSuccessHook(hook); + } + if ("afterError" in hook) { + this.registerAfterErrorHook(hook); + } + } } registerSDKInitHook(hook: SDKInitHook) { diff --git a/src/hooks/types.ts b/src/hooks/types.ts index df5237d..8a27c65 100644 --- a/src/hooks/types.ts +++ b/src/hooks/types.ts @@ -100,3 +100,10 @@ export interface Hooks { /** Registers a hook to be used by the SDK for the after error event. */ registerAfterErrorHook(hook: AfterErrorHook): void; } + +export type Hook = + | SDKInitHook + | BeforeCreateRequestHook + | BeforeRequestHook + | AfterSuccessHook + | AfterErrorHook; diff --git a/src/lib/config.ts b/src/lib/config.ts index fe29484..fe9fca0 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -74,9 +74,9 @@ export function serverURLFromOptions(options: SDKOptions): URL | null { export const SDK_METADATA = { language: "typescript", - openapiDocVersion: "3.3.0", - sdkVersion: "0.23.0", - genVersion: "2.467.4", + openapiDocVersion: "3.3.1", + sdkVersion: "0.23.1", + genVersion: "2.477.4", userAgent: - "speakeasy-sdk/typescript 0.23.0 2.467.4 3.3.0 @boltpay/bolt-typescript-sdk", + "speakeasy-sdk/typescript 0.23.1 2.477.4 3.3.1 @boltpay/bolt-typescript-sdk", } as const;