From e13f2e60b09ef9eb1116ff7a37d3cd0ce5d35ba6 Mon Sep 17 00:00:00 2001 From: speakeasybot Date: Wed, 6 Nov 2024 00:26:51 +0000 Subject: [PATCH] ci: regenerated with OpenAPI Doc , Speakeasy CLI 1.431.0 --- .speakeasy/gen.lock | 25 +++--- .speakeasy/gen.yaml | 3 +- .speakeasy/workflow.lock | 12 +-- README.md | 4 +- RELEASES.md | 12 ++- docs/sdks/pet/README.md | 10 +-- jsr.json | 2 +- package-lock.json | 4 +- package.json | 2 +- src/funcs/petDeletePet.ts | 12 ++- src/funcs/petFindPetsByStatus.ts | 12 ++- src/funcs/petFindPetsByTags.ts | 12 ++- src/funcs/petGetPetById.ts | 12 ++- src/funcs/{petAddPet.ts => petMyPet.ts} | 16 ++-- src/funcs/petUpdatePet.ts | 12 ++- src/funcs/petUploadFile.ts | 12 ++- src/funcs/storeDeleteOrder.ts | 12 ++- src/funcs/storeGetInventory.ts | 12 ++- src/funcs/storeGetOrderById.ts | 12 ++- src/funcs/storePlaceOrder.ts | 12 ++- src/funcs/userCreateUser.ts | 12 ++- src/funcs/userCreateUsersWithListInput.ts | 12 ++- src/funcs/userDeleteUser.ts | 12 ++- src/funcs/userGetUserByName.ts | 12 ++- src/funcs/userLoginUser.ts | 12 ++- src/funcs/userLogoutUser.ts | 12 ++- src/funcs/userUpdateUser.ts | 12 ++- src/hooks/types.ts | 2 + src/lib/config.ts | 6 +- src/lib/retries.ts | 94 +++++++++++++++-------- src/lib/sdks.ts | 34 ++++---- src/sdk/pet.ts | 6 +- 32 files changed, 282 insertions(+), 154 deletions(-) rename src/funcs/{petAddPet.ts => petMyPet.ts} (93%) diff --git a/.speakeasy/gen.lock b/.speakeasy/gen.lock index acccb96..d76af37 100644 --- a/.speakeasy/gen.lock +++ b/.speakeasy/gen.lock @@ -1,12 +1,12 @@ lockVersion: 2.0.0 id: ede0e8e6-5a63-4cc3-bd29-551cf1036a60 management: - docChecksum: 7c524b4be7afdadc4b2f448072865ac4 + docChecksum: ad663a9a1829ad7aad87db01daf63b68 docVersion: 1.0.0 - speakeasyVersion: 1.424.0 - generationVersion: 2.445.1 - releaseVersion: 0.2.2 - configChecksum: c24de5394103ea6e7f2d76a694d39599 + speakeasyVersion: 1.431.0 + generationVersion: 2.451.0 + releaseVersion: 0.3.0 + configChecksum: f0c7fad458f2041c21196566143ebe5c repoURL: https://github.com/ryan-timothy-albert/simple-ts-sdk.git installationURL: https://github.com/ryan-timothy-albert/simple-ts-sdk published: true @@ -14,18 +14,18 @@ features: typescript: additionalDependencies: 0.1.0 constsAndDefaults: 0.1.11 - core: 3.18.2 + core: 3.18.3 defaultEnabledRetries: 0.1.0 devContainers: 2.90.0 enumUnions: 0.1.0 - envVarSecurityUsage: 0.1.1 + envVarSecurityUsage: 0.1.2 globalSecurity: 2.82.11 globalSecurityCallbacks: 0.1.0 globalSecurityFlattening: 0.1.0 globalServerURLs: 2.82.4 responseFormat: 0.2.3 retries: 2.83.0 - sdkHooks: 0.1.0 + sdkHooks: 0.2.0 tests: 0.7.0 uploadStreams: 0.1.0 generatedFiles: @@ -72,11 +72,11 @@ generatedFiles: - jsr.json - package.json - src/core.ts - - src/funcs/petAddPet.ts - src/funcs/petDeletePet.ts - src/funcs/petFindPetsByStatus.ts - src/funcs/petFindPetsByTags.ts - src/funcs/petGetPetById.ts + - src/funcs/petMyPet.ts - src/funcs/petUpdatePet.ts - src/funcs/petUploadFile.ts - src/funcs/storeDeleteOrder.ts @@ -337,3 +337,10 @@ examples: application/json: {"status": 401, "error": "Unauthorized"} "404": application/json: {"status": 404, "error": "Not Found", "code": "object_not_found"} + myPet: + speakeasy-default-my-pet: + requestBody: + application/json: {"id": 10, "name": "doggie", "category": {"id": 1, "name": "Dogs"}, "photoUrls": [""]} + responses: + "200": + application/json: {"id": 10, "name": "doggie", "category": {"id": 1, "name": "Dogs"}, "photoUrls": ["", "", ""]} diff --git a/.speakeasy/gen.yaml b/.speakeasy/gen.yaml index 4a02030..59f9951 100644 --- a/.speakeasy/gen.yaml +++ b/.speakeasy/gen.yaml @@ -14,8 +14,9 @@ generation: requestResponseComponentNamesFeb2024: true auth: oAuth2ClientCredentialsEnabled: true + oAuth2PasswordEnabled: false typescript: - version: 0.2.2 + version: 0.3.0 additionalDependencies: dependencies: {} devDependencies: {} diff --git a/.speakeasy/workflow.lock b/.speakeasy/workflow.lock index 0034fb5..4f48700 100644 --- a/.speakeasy/workflow.lock +++ b/.speakeasy/workflow.lock @@ -1,9 +1,9 @@ -speakeasyVersion: 1.424.0 +speakeasyVersion: 1.431.0 sources: petstore-oas: sourceNamespace: petstore-oas - sourceRevisionDigest: sha256:1417eff746788de6739d742a8014c8f78bb5d9859699e954ec3dedcc030f1fbe - sourceBlobDigest: sha256:849ab95113a7a54b7944402c86e88af54754f8ef15f449005e30ca17bac3f5a0 + sourceRevisionDigest: sha256:eadd04b227959619f017f2669743325c9b790d05e382048066a36511d9391c98 + sourceBlobDigest: sha256:79d4bec465be62dfc290bed016e16e2186dc5b82b50bdf76d80f099eff5a6071 tags: - latest - main @@ -11,10 +11,10 @@ targets: petstore: source: petstore-oas sourceNamespace: petstore-oas - sourceRevisionDigest: sha256:1417eff746788de6739d742a8014c8f78bb5d9859699e954ec3dedcc030f1fbe - sourceBlobDigest: sha256:849ab95113a7a54b7944402c86e88af54754f8ef15f449005e30ca17bac3f5a0 + sourceRevisionDigest: sha256:eadd04b227959619f017f2669743325c9b790d05e382048066a36511d9391c98 + sourceBlobDigest: sha256:79d4bec465be62dfc290bed016e16e2186dc5b82b50bdf76d80f099eff5a6071 codeSamplesNamespace: petstore-oas-code-samples - codeSamplesRevisionDigest: sha256:ffa10ae982d7dee6171a3fb1fcb56ac75b1cfea44b50934841c46726f4cf5c04 + codeSamplesRevisionDigest: sha256:fc0b6f04887b3fd1e246d8407fe4335dcd19c6535bca6414e4151d3c667ab8c5 workflow: workflowVersion: 1.0.0 speakeasyVersion: latest diff --git a/README.md b/README.md index 632c1a1..c3739a7 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ run(); ### [pet](docs/sdks/pet/README.md) * [updatePet](docs/sdks/pet/README.md#updatepet) - Update an existing pet -* [addPet](docs/sdks/pet/README.md#addpet) - Add a new pet to the store +* [myPet](docs/sdks/pet/README.md#mypet) - Add a new pet to the store * [findPetsByStatus](docs/sdks/pet/README.md#findpetsbystatus) - Finds Pets by status * [findPetsByTags](docs/sdks/pet/README.md#findpetsbytags) - Finds Pets by tags * [getPetById](docs/sdks/pet/README.md#getpetbyid) - Find pet by ID @@ -172,11 +172,11 @@ To read more about standalone functions, check [FUNCTIONS.md](./FUNCTIONS.md). Available standalone functions -- [`petAddPet`](docs/sdks/pet/README.md#addpet) - Add a new pet to the store - [`petDeletePet`](docs/sdks/pet/README.md#deletepet) - Deletes a pet - [`petFindPetsByStatus`](docs/sdks/pet/README.md#findpetsbystatus) - Finds Pets by status - [`petFindPetsByTags`](docs/sdks/pet/README.md#findpetsbytags) - Finds Pets by tags - [`petGetPetById`](docs/sdks/pet/README.md#getpetbyid) - Find pet by ID +- [`petMyPet`](docs/sdks/pet/README.md#mypet) - Add a new pet to the store - [`petUpdatePet`](docs/sdks/pet/README.md#updatepet) - Update an existing pet - [`petUploadFile`](docs/sdks/pet/README.md#uploadfile) - uploads an image - [`storeDeleteOrder`](docs/sdks/store/README.md#deleteorder) - Delete purchase order by ID diff --git a/RELEASES.md b/RELEASES.md index 18b7cda..f90f829 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -112,4 +112,14 @@ Based on: ### Generated - [typescript v0.2.2] . ### Releases -- [NPM v0.2.2] https://www.npmjs.com/package/ryan-simple-test-act/v/0.2.2 - . \ No newline at end of file +- [NPM v0.2.2] https://www.npmjs.com/package/ryan-simple-test-act/v/0.2.2 - . + +## 2024-11-06 00:26:22 +### Changes +Based on: +- OpenAPI Doc +- Speakeasy CLI 1.431.0 (2.451.0) https://github.com/speakeasy-api/speakeasy +### Generated +- [typescript v0.3.0] . +### Releases +- [NPM v0.3.0] https://www.npmjs.com/package/ryan-simple-test-act/v/0.3.0 - . \ No newline at end of file diff --git a/docs/sdks/pet/README.md b/docs/sdks/pet/README.md index 97f8ced..c9cf69e 100644 --- a/docs/sdks/pet/README.md +++ b/docs/sdks/pet/README.md @@ -11,7 +11,7 @@ Find out more ### Available Operations * [updatePet](#updatepet) - Update an existing pet -* [addPet](#addpet) - Add a new pet to the store +* [myPet](#mypet) - Add a new pet to the store * [findPetsByStatus](#findpetsbystatus) - Finds Pets by status * [findPetsByTags](#findpetsbytags) - Finds Pets by tags * [getPetById](#getpetbyid) - Find pet by ID @@ -115,7 +115,7 @@ run(); | errors.ApiErrorNotFound | 404 | application/json | | errors.SDKError | 4XX, 5XX | \*/\* | -## addPet +## myPet Add a new pet to the store @@ -129,7 +129,7 @@ const petstore = new Petstore({ }); async function run() { - const result = await petstore.pet.addPet({ + const result = await petstore.pet.myPet({ id: 10, name: "doggie", category: { @@ -154,7 +154,7 @@ The standalone function version of this method: ```typescript import { PetstoreCore } from "ryan-simple-test-act/core.js"; -import { petAddPet } from "ryan-simple-test-act/funcs/petAddPet.js"; +import { petMyPet } from "ryan-simple-test-act/funcs/petMyPet.js"; // Use `PetstoreCore` for best tree-shaking performance. // You can create one instance of it to use across an application. @@ -163,7 +163,7 @@ const petstore = new PetstoreCore({ }); async function run() { - const res = await petAddPet(petstore, { + const res = await petMyPet(petstore, { id: 10, name: "doggie", category: { diff --git a/jsr.json b/jsr.json index 0bc8976..d54a28c 100644 --- a/jsr.json +++ b/jsr.json @@ -2,7 +2,7 @@ { "name": "ryan-simple-test-act", - "version": "0.2.2", + "version": "0.3.0", "exports": { ".": "./src/index.ts", "./models/errors": "./src/models/errors/index.ts", diff --git a/package-lock.json b/package-lock.json index c1fe1ac..82c96fb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "ryan-simple-test-act", - "version": "0.2.2", + "version": "0.3.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "ryan-simple-test-act", - "version": "0.2.2", + "version": "0.3.0", "devDependencies": { "@typescript-eslint/eslint-plugin": "^7.7.1", "@typescript-eslint/parser": "^7.7.1", diff --git a/package.json b/package.json index 76e62ad..5acf053 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ryan-simple-test-act", - "version": "0.2.2", + "version": "0.3.0", "author": "ryan-timothy-albert", "main": "./index.js", "sideEffects": false, diff --git a/src/funcs/petDeletePet.ts b/src/funcs/petDeletePet.ts index ea1ed35..c464832 100644 --- a/src/funcs/petDeletePet.ts +++ b/src/funcs/petDeletePet.ts @@ -75,12 +75,17 @@ export async function petDeletePet( const secConfig = await extractSecurity(client._options.apiKey); const securityInput = secConfig == null ? {} : { apiKey: secConfig }; + const requestSecurity = resolveGlobalSecurity(securityInput); + const context = { operationID: "deletePet", oAuth2Scopes: [], securitySource: client._options.apiKey, + retryConfig: options?.retries + || client._options.retryConfig + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], }; - const requestSecurity = resolveGlobalSecurity(securityInput); const requestRes = client._createRequest(context, { security: requestSecurity, @@ -98,9 +103,8 @@ export async function petDeletePet( const doResult = await client._do(req, { context, errorCodes: ["400", "401", "404", "4XX", "5XX"], - retryConfig: options?.retries - || client._options.retryConfig, - retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, }); if (!doResult.ok) { return doResult; diff --git a/src/funcs/petFindPetsByStatus.ts b/src/funcs/petFindPetsByStatus.ts index 147bd53..0ff5272 100644 --- a/src/funcs/petFindPetsByStatus.ts +++ b/src/funcs/petFindPetsByStatus.ts @@ -72,12 +72,17 @@ export async function petFindPetsByStatus( const secConfig = await extractSecurity(client._options.apiKey); const securityInput = secConfig == null ? {} : { apiKey: secConfig }; + const requestSecurity = resolveGlobalSecurity(securityInput); + const context = { operationID: "findPetsByStatus", oAuth2Scopes: [], securitySource: client._options.apiKey, + retryConfig: options?.retries + || client._options.retryConfig + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], }; - const requestSecurity = resolveGlobalSecurity(securityInput); const requestRes = client._createRequest(context, { security: requestSecurity, @@ -96,9 +101,8 @@ export async function petFindPetsByStatus( const doResult = await client._do(req, { context, errorCodes: ["400", "401", "404", "4XX", "5XX"], - retryConfig: options?.retries - || client._options.retryConfig, - retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, }); if (!doResult.ok) { return doResult; diff --git a/src/funcs/petFindPetsByTags.ts b/src/funcs/petFindPetsByTags.ts index 058a68f..561575d 100644 --- a/src/funcs/petFindPetsByTags.ts +++ b/src/funcs/petFindPetsByTags.ts @@ -72,12 +72,17 @@ export async function petFindPetsByTags( const secConfig = await extractSecurity(client._options.apiKey); const securityInput = secConfig == null ? {} : { apiKey: secConfig }; + const requestSecurity = resolveGlobalSecurity(securityInput); + const context = { operationID: "findPetsByTags", oAuth2Scopes: [], securitySource: client._options.apiKey, + retryConfig: options?.retries + || client._options.retryConfig + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], }; - const requestSecurity = resolveGlobalSecurity(securityInput); const requestRes = client._createRequest(context, { security: requestSecurity, @@ -96,9 +101,8 @@ export async function petFindPetsByTags( const doResult = await client._do(req, { context, errorCodes: ["400", "401", "404", "4XX", "5XX"], - retryConfig: options?.retries - || client._options.retryConfig, - retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, }); if (!doResult.ok) { return doResult; diff --git a/src/funcs/petGetPetById.ts b/src/funcs/petGetPetById.ts index b395b7d..795e7c3 100644 --- a/src/funcs/petGetPetById.ts +++ b/src/funcs/petGetPetById.ts @@ -74,12 +74,17 @@ export async function petGetPetById( const secConfig = await extractSecurity(client._options.apiKey); const securityInput = secConfig == null ? {} : { apiKey: secConfig }; + const requestSecurity = resolveGlobalSecurity(securityInput); + const context = { operationID: "getPetById", oAuth2Scopes: [], securitySource: client._options.apiKey, + retryConfig: options?.retries + || client._options.retryConfig + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], }; - const requestSecurity = resolveGlobalSecurity(securityInput); const requestRes = client._createRequest(context, { security: requestSecurity, @@ -97,9 +102,8 @@ export async function petGetPetById( const doResult = await client._do(req, { context, errorCodes: ["400", "401", "404", "4XX", "5XX"], - retryConfig: options?.retries - || client._options.retryConfig, - retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, }); if (!doResult.ok) { return doResult; diff --git a/src/funcs/petAddPet.ts b/src/funcs/petMyPet.ts similarity index 93% rename from src/funcs/petAddPet.ts rename to src/funcs/petMyPet.ts index c7e018e..b5570e2 100644 --- a/src/funcs/petAddPet.ts +++ b/src/funcs/petMyPet.ts @@ -27,7 +27,7 @@ import { Result } from "../types/fp.js"; * @remarks * Add a new pet to the store */ -export async function petAddPet( +export async function petMyPet( client: PetstoreCore, request: components.Pet, options?: RequestOptions, @@ -63,12 +63,17 @@ export async function petAddPet( const secConfig = await extractSecurity(client._options.apiKey); const securityInput = secConfig == null ? {} : { apiKey: secConfig }; + const requestSecurity = resolveGlobalSecurity(securityInput); + const context = { - operationID: "addPet", + operationID: "myPet", oAuth2Scopes: [], securitySource: client._options.apiKey, + retryConfig: options?.retries + || client._options.retryConfig + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], }; - const requestSecurity = resolveGlobalSecurity(securityInput); const requestRes = client._createRequest(context, { security: requestSecurity, @@ -86,9 +91,8 @@ export async function petAddPet( const doResult = await client._do(req, { context, errorCodes: ["405", "4XX", "5XX"], - retryConfig: options?.retries - || client._options.retryConfig, - retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, }); if (!doResult.ok) { return doResult; diff --git a/src/funcs/petUpdatePet.ts b/src/funcs/petUpdatePet.ts index 66ca2b3..7ba20ba 100644 --- a/src/funcs/petUpdatePet.ts +++ b/src/funcs/petUpdatePet.ts @@ -67,12 +67,17 @@ export async function petUpdatePet( const secConfig = await extractSecurity(client._options.apiKey); const securityInput = secConfig == null ? {} : { apiKey: secConfig }; + const requestSecurity = resolveGlobalSecurity(securityInput); + const context = { operationID: "updatePet", oAuth2Scopes: [], securitySource: client._options.apiKey, + retryConfig: options?.retries + || client._options.retryConfig + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], }; - const requestSecurity = resolveGlobalSecurity(securityInput); const requestRes = client._createRequest(context, { security: requestSecurity, @@ -90,9 +95,8 @@ export async function petUpdatePet( const doResult = await client._do(req, { context, errorCodes: ["400", "401", "404", "4XX", "5XX"], - retryConfig: options?.retries - || client._options.retryConfig, - retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, }); if (!doResult.ok) { return doResult; diff --git a/src/funcs/petUploadFile.ts b/src/funcs/petUploadFile.ts index f2eb4f9..7ab39ba 100644 --- a/src/funcs/petUploadFile.ts +++ b/src/funcs/petUploadFile.ts @@ -72,12 +72,17 @@ export async function petUploadFile( const secConfig = await extractSecurity(client._options.apiKey); const securityInput = secConfig == null ? {} : { apiKey: secConfig }; + const requestSecurity = resolveGlobalSecurity(securityInput); + const context = { operationID: "uploadFile", oAuth2Scopes: [], securitySource: client._options.apiKey, + retryConfig: options?.retries + || client._options.retryConfig + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], }; - const requestSecurity = resolveGlobalSecurity(securityInput); const requestRes = client._createRequest(context, { security: requestSecurity, @@ -96,9 +101,8 @@ export async function petUploadFile( const doResult = await client._do(req, { context, errorCodes: ["4XX", "5XX"], - retryConfig: options?.retries - || client._options.retryConfig, - retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, }); if (!doResult.ok) { return doResult; diff --git a/src/funcs/storeDeleteOrder.ts b/src/funcs/storeDeleteOrder.ts index c3e07cd..c5fd504 100644 --- a/src/funcs/storeDeleteOrder.ts +++ b/src/funcs/storeDeleteOrder.ts @@ -74,12 +74,17 @@ export async function storeDeleteOrder( const secConfig = await extractSecurity(client._options.apiKey); const securityInput = secConfig == null ? {} : { apiKey: secConfig }; + const requestSecurity = resolveGlobalSecurity(securityInput); + const context = { operationID: "deleteOrder", oAuth2Scopes: [], securitySource: client._options.apiKey, + retryConfig: options?.retries + || client._options.retryConfig + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], }; - const requestSecurity = resolveGlobalSecurity(securityInput); const requestRes = client._createRequest(context, { security: requestSecurity, @@ -97,9 +102,8 @@ export async function storeDeleteOrder( const doResult = await client._do(req, { context, errorCodes: ["400", "401", "404", "4XX", "5XX"], - retryConfig: options?.retries - || client._options.retryConfig, - retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, }); if (!doResult.ok) { return doResult; diff --git a/src/funcs/storeGetInventory.ts b/src/funcs/storeGetInventory.ts index 9861326..f5eff4b 100644 --- a/src/funcs/storeGetInventory.ts +++ b/src/funcs/storeGetInventory.ts @@ -51,12 +51,17 @@ export async function storeGetInventory( const secConfig = await extractSecurity(client._options.apiKey); const securityInput = secConfig == null ? {} : { apiKey: secConfig }; + const requestSecurity = resolveGlobalSecurity(securityInput); + const context = { operationID: "getInventory", oAuth2Scopes: [], securitySource: client._options.apiKey, + retryConfig: options?.retries + || client._options.retryConfig + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], }; - const requestSecurity = resolveGlobalSecurity(securityInput); const requestRes = client._createRequest(context, { security: requestSecurity, @@ -73,9 +78,8 @@ export async function storeGetInventory( const doResult = await client._do(req, { context, errorCodes: ["401", "404", "4XX", "5XX"], - retryConfig: options?.retries - || client._options.retryConfig, - retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, }); if (!doResult.ok) { return doResult; diff --git a/src/funcs/storeGetOrderById.ts b/src/funcs/storeGetOrderById.ts index c92fe26..ba3ba59 100644 --- a/src/funcs/storeGetOrderById.ts +++ b/src/funcs/storeGetOrderById.ts @@ -74,12 +74,17 @@ export async function storeGetOrderById( const secConfig = await extractSecurity(client._options.apiKey); const securityInput = secConfig == null ? {} : { apiKey: secConfig }; + const requestSecurity = resolveGlobalSecurity(securityInput); + const context = { operationID: "getOrderById", oAuth2Scopes: [], securitySource: client._options.apiKey, + retryConfig: options?.retries + || client._options.retryConfig + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], }; - const requestSecurity = resolveGlobalSecurity(securityInput); const requestRes = client._createRequest(context, { security: requestSecurity, @@ -97,9 +102,8 @@ export async function storeGetOrderById( const doResult = await client._do(req, { context, errorCodes: ["400", "401", "404", "4XX", "5XX"], - retryConfig: options?.retries - || client._options.retryConfig, - retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, }); if (!doResult.ok) { return doResult; diff --git a/src/funcs/storePlaceOrder.ts b/src/funcs/storePlaceOrder.ts index ca684fd..5e4c397 100644 --- a/src/funcs/storePlaceOrder.ts +++ b/src/funcs/storePlaceOrder.ts @@ -68,12 +68,17 @@ export async function storePlaceOrder( const secConfig = await extractSecurity(client._options.apiKey); const securityInput = secConfig == null ? {} : { apiKey: secConfig }; + const requestSecurity = resolveGlobalSecurity(securityInput); + const context = { operationID: "placeOrder", oAuth2Scopes: [], securitySource: client._options.apiKey, + retryConfig: options?.retries + || client._options.retryConfig + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], }; - const requestSecurity = resolveGlobalSecurity(securityInput); const requestRes = client._createRequest(context, { security: requestSecurity, @@ -91,9 +96,8 @@ export async function storePlaceOrder( const doResult = await client._do(req, { context, errorCodes: ["401", "404", "405", "4XX", "5XX"], - retryConfig: options?.retries - || client._options.retryConfig, - retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, }); if (!doResult.ok) { return doResult; diff --git a/src/funcs/userCreateUser.ts b/src/funcs/userCreateUser.ts index 5b718cd..0eb6665 100644 --- a/src/funcs/userCreateUser.ts +++ b/src/funcs/userCreateUser.ts @@ -65,12 +65,17 @@ export async function userCreateUser( const secConfig = await extractSecurity(client._options.apiKey); const securityInput = secConfig == null ? {} : { apiKey: secConfig }; + const requestSecurity = resolveGlobalSecurity(securityInput); + const context = { operationID: "createUser", oAuth2Scopes: [], securitySource: client._options.apiKey, + retryConfig: options?.retries + || client._options.retryConfig + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], }; - const requestSecurity = resolveGlobalSecurity(securityInput); const requestRes = client._createRequest(context, { security: requestSecurity, @@ -88,9 +93,8 @@ export async function userCreateUser( const doResult = await client._do(req, { context, errorCodes: ["4XX", "5XX"], - retryConfig: options?.retries - || client._options.retryConfig, - retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, }); if (!doResult.ok) { return doResult; diff --git a/src/funcs/userCreateUsersWithListInput.ts b/src/funcs/userCreateUsersWithListInput.ts index e8f1a47..6bd538a 100644 --- a/src/funcs/userCreateUsersWithListInput.ts +++ b/src/funcs/userCreateUsersWithListInput.ts @@ -66,12 +66,17 @@ export async function userCreateUsersWithListInput( const secConfig = await extractSecurity(client._options.apiKey); const securityInput = secConfig == null ? {} : { apiKey: secConfig }; + const requestSecurity = resolveGlobalSecurity(securityInput); + const context = { operationID: "createUsersWithListInput", oAuth2Scopes: [], securitySource: client._options.apiKey, + retryConfig: options?.retries + || client._options.retryConfig + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], }; - const requestSecurity = resolveGlobalSecurity(securityInput); const requestRes = client._createRequest(context, { security: requestSecurity, @@ -89,9 +94,8 @@ export async function userCreateUsersWithListInput( const doResult = await client._do(req, { context, errorCodes: ["4XX", "5XX"], - retryConfig: options?.retries - || client._options.retryConfig, - retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, }); if (!doResult.ok) { return doResult; diff --git a/src/funcs/userDeleteUser.ts b/src/funcs/userDeleteUser.ts index da21f73..57afdfa 100644 --- a/src/funcs/userDeleteUser.ts +++ b/src/funcs/userDeleteUser.ts @@ -74,12 +74,17 @@ export async function userDeleteUser( const secConfig = await extractSecurity(client._options.apiKey); const securityInput = secConfig == null ? {} : { apiKey: secConfig }; + const requestSecurity = resolveGlobalSecurity(securityInput); + const context = { operationID: "deleteUser", oAuth2Scopes: [], securitySource: client._options.apiKey, + retryConfig: options?.retries + || client._options.retryConfig + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], }; - const requestSecurity = resolveGlobalSecurity(securityInput); const requestRes = client._createRequest(context, { security: requestSecurity, @@ -97,9 +102,8 @@ export async function userDeleteUser( const doResult = await client._do(req, { context, errorCodes: ["400", "401", "404", "4XX", "5XX"], - retryConfig: options?.retries - || client._options.retryConfig, - retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, }); if (!doResult.ok) { return doResult; diff --git a/src/funcs/userGetUserByName.ts b/src/funcs/userGetUserByName.ts index 5eabbd2..dc8c170 100644 --- a/src/funcs/userGetUserByName.ts +++ b/src/funcs/userGetUserByName.ts @@ -71,12 +71,17 @@ export async function userGetUserByName( const secConfig = await extractSecurity(client._options.apiKey); const securityInput = secConfig == null ? {} : { apiKey: secConfig }; + const requestSecurity = resolveGlobalSecurity(securityInput); + const context = { operationID: "getUserByName", oAuth2Scopes: [], securitySource: client._options.apiKey, + retryConfig: options?.retries + || client._options.retryConfig + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], }; - const requestSecurity = resolveGlobalSecurity(securityInput); const requestRes = client._createRequest(context, { security: requestSecurity, @@ -94,9 +99,8 @@ export async function userGetUserByName( const doResult = await client._do(req, { context, errorCodes: ["400", "401", "404", "4XX", "5XX"], - retryConfig: options?.retries - || client._options.retryConfig, - retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, }); if (!doResult.ok) { return doResult; diff --git a/src/funcs/userLoginUser.ts b/src/funcs/userLoginUser.ts index b7361b0..0af500c 100644 --- a/src/funcs/userLoginUser.ts +++ b/src/funcs/userLoginUser.ts @@ -68,12 +68,17 @@ export async function userLoginUser( const secConfig = await extractSecurity(client._options.apiKey); const securityInput = secConfig == null ? {} : { apiKey: secConfig }; + const requestSecurity = resolveGlobalSecurity(securityInput); + const context = { operationID: "loginUser", oAuth2Scopes: [], securitySource: client._options.apiKey, + retryConfig: options?.retries + || client._options.retryConfig + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], }; - const requestSecurity = resolveGlobalSecurity(securityInput); const requestRes = client._createRequest(context, { security: requestSecurity, @@ -92,9 +97,8 @@ export async function userLoginUser( const doResult = await client._do(req, { context, errorCodes: ["400", "401", "404", "4XX", "5XX"], - retryConfig: options?.retries - || client._options.retryConfig, - retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, }); if (!doResult.ok) { return doResult; diff --git a/src/funcs/userLogoutUser.ts b/src/funcs/userLogoutUser.ts index 0e9b51f..55b6c2b 100644 --- a/src/funcs/userLogoutUser.ts +++ b/src/funcs/userLogoutUser.ts @@ -45,12 +45,17 @@ export async function userLogoutUser( const secConfig = await extractSecurity(client._options.apiKey); const securityInput = secConfig == null ? {} : { apiKey: secConfig }; + const requestSecurity = resolveGlobalSecurity(securityInput); + const context = { operationID: "logoutUser", oAuth2Scopes: [], securitySource: client._options.apiKey, + retryConfig: options?.retries + || client._options.retryConfig + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], }; - const requestSecurity = resolveGlobalSecurity(securityInput); const requestRes = client._createRequest(context, { security: requestSecurity, @@ -67,9 +72,8 @@ export async function userLogoutUser( const doResult = await client._do(req, { context, errorCodes: ["4XX", "5XX"], - retryConfig: options?.retries - || client._options.retryConfig, - retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, }); if (!doResult.ok) { return doResult; diff --git a/src/funcs/userUpdateUser.ts b/src/funcs/userUpdateUser.ts index b9b3243..7511531 100644 --- a/src/funcs/userUpdateUser.ts +++ b/src/funcs/userUpdateUser.ts @@ -71,12 +71,17 @@ export async function userUpdateUser( const secConfig = await extractSecurity(client._options.apiKey); const securityInput = secConfig == null ? {} : { apiKey: secConfig }; + const requestSecurity = resolveGlobalSecurity(securityInput); + const context = { operationID: "updateUser", oAuth2Scopes: [], securitySource: client._options.apiKey, + retryConfig: options?.retries + || client._options.retryConfig + || { strategy: "none" }, + retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], }; - const requestSecurity = resolveGlobalSecurity(securityInput); const requestRes = client._createRequest(context, { security: requestSecurity, @@ -94,9 +99,8 @@ export async function userUpdateUser( const doResult = await client._do(req, { context, errorCodes: ["4XX", "5XX"], - retryConfig: options?.retries - || client._options.retryConfig, - retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], + retryConfig: context.retryConfig, + retryCodes: context.retryCodes, }); if (!doResult.ok) { return doResult; diff --git a/src/hooks/types.ts b/src/hooks/types.ts index 656b9e3..4079cc9 100644 --- a/src/hooks/types.ts +++ b/src/hooks/types.ts @@ -3,11 +3,13 @@ */ import { HTTPClient, RequestInput } from "../lib/http.js"; +import { RetryConfig } from "../lib/retries.js"; export type HookContext = { operationID: string; oAuth2Scopes?: string[]; securitySource?: any | (() => Promise); + retryConfig: RetryConfig; }; export type Awaitable = T | Promise; diff --git a/src/lib/config.ts b/src/lib/config.ts index 7eef544..a8a4d9d 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -81,8 +81,8 @@ export function serverURLFromOptions(options: SDKOptions): URL | null { export const SDK_METADATA = { language: "typescript", openapiDocVersion: "1.0.0", - sdkVersion: "0.2.2", - genVersion: "2.445.1", + sdkVersion: "0.3.0", + genVersion: "2.451.0", userAgent: - "speakeasy-sdk/typescript 0.2.2 2.445.1 1.0.0 ryan-simple-test-act", + "speakeasy-sdk/typescript 0.3.0 2.451.0 1.0.0 ryan-simple-test-act", } as const; diff --git a/src/lib/retries.ts b/src/lib/retries.ts index df3e0bc..93ebc8d 100644 --- a/src/lib/retries.ts +++ b/src/lib/retries.ts @@ -26,23 +26,44 @@ export type RetryConfig = retryConnectionErrors?: boolean; }; -class PermanentError extends Error { - inner: unknown; +/** + * PermanentError is an error that is not recoverable. Throwing this error will + * cause a retry loop to terminate. + */ +export class PermanentError extends Error { + /** The underlying cause of the error. */ + override readonly cause: unknown; + + constructor(message: string, options?: { cause?: unknown }) { + let msg = message; + if (options?.cause) { + msg += `: ${options.cause}`; + } - constructor(inner: unknown) { - super("Permanent error"); - this.inner = inner; + super(msg, options); + this.name = "PermanentError"; + // In older runtimes, the cause field would not have been assigned through + // the super() call. + if (typeof this.cause === "undefined") { + this.cause = options?.cause; + } Object.setPrototypeOf(this, PermanentError.prototype); } } -class TemporaryError extends Error { - res: Response; +/** + * TemporaryError is an error is used to signal that an HTTP request can be + * retried as part of a retry loop. If retry attempts are exhausted and this + * error is thrown, the response will be returned to the caller. + */ +export class TemporaryError extends Error { + response: Response; - constructor(res: Response) { - super("Temporary error"); - this.res = res; + constructor(message: string, response: Response) { + super(message); + this.response = response; + this.name = "TemporaryError"; Object.setPrototypeOf(this, TemporaryError.prototype); } @@ -80,11 +101,14 @@ function wrapFetcher( try { const res = await fn(); if (isRetryableResponse(res, options.statusCodes)) { - throw new TemporaryError(res); + throw new TemporaryError( + "Response failed with retryable status code", + res, + ); } return res; - } catch (err) { + } catch (err: unknown) { if (err instanceof TemporaryError) { throw err; } @@ -96,7 +120,7 @@ function wrapFetcher( throw err; } - throw new PermanentError(err); + throw new PermanentError("Permanent error", { cause: err }); } }; } @@ -139,37 +163,25 @@ async function retryBackoff( try { const res = await fn(); return res; - } catch (err) { + } catch (err: unknown) { if (err instanceof PermanentError) { - throw err.inner; + throw err.cause; } const elapsed = Date.now() - start; if (elapsed > maxElapsedTime) { if (err instanceof TemporaryError) { - return err.res; + return err.response; } throw err; } let retryInterval = 0; - if (err instanceof TemporaryError && err.res && err.res.headers) { - const retryVal = err.res.headers.get("retry-after") || ""; - if (retryVal != "") { - const parsedNumber = Number(retryVal); - if (!isNaN(parsedNumber) && Number.isInteger(parsedNumber)) { - retryInterval = parsedNumber * 1000; - } else { - const parsedDate = Date.parse(retryVal); - if (!isNaN(parsedDate)) { - const deltaMS = parsedDate - Date.now(); - retryInterval = deltaMS > 0 ? Math.ceil(deltaMS) : 0; - } - } - } + if (err instanceof TemporaryError) { + retryInterval = retryIntervalFromResponse(err.response); } - if (retryInterval == 0) { + if (retryInterval <= 0) { retryInterval = initialInterval * Math.pow(x, exponent) + Math.random() * 1000; } @@ -182,6 +194,26 @@ async function retryBackoff( } } +function retryIntervalFromResponse(res: Response): number { + const retryVal = res.headers.get("retry-after") || ""; + if (!retryVal) { + return 0; + } + + const parsedNumber = Number(retryVal); + if (Number.isInteger(parsedNumber)) { + return parsedNumber * 1000; + } + + const parsedDate = Date.parse(retryVal); + if (Number.isInteger(parsedDate)) { + const deltaMS = parsedDate - Date.now(); + return deltaMS > 0 ? Math.ceil(deltaMS) : 0; + } + + return 0; +} + async function delay(delay: number): Promise { return new Promise((resolve) => setTimeout(resolve, delay)); } diff --git a/src/lib/sdks.ts b/src/lib/sdks.ts index a0f4de1..2ce720a 100644 --- a/src/lib/sdks.ts +++ b/src/lib/sdks.ts @@ -220,8 +220,8 @@ export class ClientSDK { options: { context: HookContext; errorCodes: number | string | (number | string)[]; - retryConfig?: RetryConfig | undefined; - retryCodes?: string[] | undefined; + retryConfig: RetryConfig; + retryCodes: string[]; }, ): Promise< Result< @@ -233,8 +233,6 @@ export class ClientSDK { > > { const { context, errorCodes } = options; - const retryConfig = options.retryConfig || { strategy: "none" }; - const retryCodes = options.retryCodes || []; return retry( async () => { @@ -245,22 +243,28 @@ export class ClientSDK { let response = await this.#httpClient.request(req); - if (matchStatusCode(response, errorCodes)) { - const result = await this.#hooks.afterError(context, response, null); - if (result.error) { - throw result.error; + try { + if (matchStatusCode(response, errorCodes)) { + const result = await this.#hooks.afterError( + context, + response, + null, + ); + if (result.error) { + throw result.error; + } + response = result.response || response; + } else { + response = await this.#hooks.afterSuccess(context, response); } - response = result.response || response; - } else { - response = await this.#hooks.afterSuccess(context, response); + } finally { + await logResponse(this.#logger, response, req) + .catch(e => this.#logger?.log("Failed to log response:", e)); } - await logResponse(this.#logger, response, req) - .catch(e => this.#logger?.log("Failed to log response:", e)); - return response; }, - { config: retryConfig, statusCodes: retryCodes }, + { config: options.retryConfig, statusCodes: options.retryCodes }, ).then( (r) => OK(r), (err) => { diff --git a/src/sdk/pet.ts b/src/sdk/pet.ts index 71d3f61..84d221f 100644 --- a/src/sdk/pet.ts +++ b/src/sdk/pet.ts @@ -2,11 +2,11 @@ * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ -import { petAddPet } from "../funcs/petAddPet.js"; import { petDeletePet } from "../funcs/petDeletePet.js"; import { petFindPetsByStatus } from "../funcs/petFindPetsByStatus.js"; import { petFindPetsByTags } from "../funcs/petFindPetsByTags.js"; import { petGetPetById } from "../funcs/petGetPetById.js"; +import { petMyPet } from "../funcs/petMyPet.js"; import { petUpdatePet } from "../funcs/petUpdatePet.js"; import { petUploadFile } from "../funcs/petUploadFile.js"; import { ClientSDK, RequestOptions } from "../lib/sdks.js"; @@ -38,11 +38,11 @@ export class Pet extends ClientSDK { * @remarks * Add a new pet to the store */ - async addPet( + async myPet( request: components.Pet, options?: RequestOptions, ): Promise { - return unwrapAsync(petAddPet( + return unwrapAsync(petMyPet( this, request, options,