Skip to content

Commit

Permalink
chore: 🐝 Update SDK - Generate (#91)
Browse files Browse the repository at this point in the history
# SDK update
Based on:
- OpenAPI Doc  
- Speakeasy CLI 1.335.0 (2.370.2)
https://github.com/speakeasy-api/speakeasy
## OpenAPI Change Summary


## TYPESCRIPT CHANGELOG
## nameOverrides: 2.81.2 - 2024-03-25
### 🐛 Bug Fixes
- x-speakeasy-name-overrides being missed when used under an allOf
*(commit by [@ThomasRooney](https://github.com/ThomasRooney))*



## core: 3.11.6 - 2024-07-09
### 🐛 Bug Fixes
- Use 0666 file mode for writing configuration and lock files *(commit
by [@bflad](https://github.com/bflad))*



## examples: 2.81.4 - 2024-04-30
### 🎨 Code Style Changes
- Remove unnecessary semicolon *(commit by
[@AshGodfrey](https://github.com/AshGodfrey))*



## constsAndDefaults: 0.1.5 - 2024-03-01
### 🐛 Bug Fixes
- null enums are coerced into null consts *(commit by
[@disintegrator](https://github.com/disintegrator))*



## serverIDs: 2.81.2 - 2023-10-23
### 🐛 Bug Fixes
- support both x-speakeasy-server-id and server variables *(commit by
[@ThomasRooney](https://github.com/ThomasRooney))*

## defaultEnabledRetries: 0.1.0 - 2024-07-11
### 🐝 New Features
- always allow users to pass a retry policy when calling an SDK methods
*(commit by [@disintegrator](https://github.com/disintegrator))*



## unions: 2.85.5 - 2024-05-16
### 🐛 Bug Fixes
- fixed handling of circular union references *(commit by
[@TristanSpeakEasy](https://github.com/tristanspeakeasy))*



## openEnums: 0.1.1 - 2024-06-27
### 🐛 Bug Fixes
- add missing imports for open enums in TS *(commit by
[@disintegrator](https://github.com/disintegrator))*



## globalServerURLs: 2.82.4 - 2024-03-06
### 🔧 Chores
- expand server selection test coverage *(commit by
[@2ynn](https://github.com/2ynn))*



## responseFormat: 0.2.3 - 2024-03-27
### 🐛 Bug Fixes
- flat response format to work when operations contain empty responses
*(commit by [@disintegrator](https://github.com/disintegrator))*



## retries: 2.83.0 - 2024-02-12
### 🐝 New Features
- read retry-after header in typescriptv2 *(commit by
[@ryan-timothy-albert](https://github.com/ryan-timothy-albert))*



## globalSecurity: 2.82.9 - 2024-04-01
### 🐛 Bug Fixes
- TSv2 security compilation *(commit by
[@chase-crumbaugh](https://github.com/chase-crumbaugh))*

Co-authored-by: speakeasybot <[email protected]>
  • Loading branch information
github-actions[bot] and speakeasybot authored Jul 13, 2024
1 parent 804a361 commit 1bbf695
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 69 deletions.
11 changes: 6 additions & 5 deletions .speakeasy/gen.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ id: f42cb8e6-e2ce-4565-b975-5a9f38b94d5a
management:
docChecksum: 3f2fbf3f00965b046a501b0642259d4e
docVersion: 1.0.39
speakeasyVersion: 1.330.0
generationVersion: 2.361.10
releaseVersion: 0.12.0
configChecksum: d7fea18f81ca96b0f79ee5eb84463306
speakeasyVersion: 1.335.0
generationVersion: 2.370.2
releaseVersion: 0.13.0
configChecksum: 42aa478608bdf1332898ea475f2c41ad
repoURL: https://github.com/Unstructured-IO/unstructured-js-client.git
repoSubDirectory: .
installationURL: https://github.com/Unstructured-IO/unstructured-js-client
Expand All @@ -15,7 +15,8 @@ features:
typescript:
additionalDependencies: 0.1.0
constsAndDefaults: 0.1.5
core: 3.11.5
core: 3.11.6
defaultEnabledRetries: 0.1.0
examples: 2.81.4
globalSecurity: 2.82.9
globalSecurityCallbacks: 0.1.0
Expand Down
10 changes: 5 additions & 5 deletions .speakeasy/workflow.lock
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
speakeasyVersion: 1.330.0
speakeasyVersion: 1.335.0
sources:
my-source:
sourceNamespace: my-source
sourceRevisionDigest: sha256:a6a17fc122fce52ae3601b08bffe8294b5d355d1b5370390192536c856f475da
sourceBlobDigest: sha256:c85052e891c341ae0a33a0bc0e21498d897649af7c1d1fa7638da4a857eb4d49
sourceRevisionDigest: sha256:1320eaa3fcc76a80f0eb1ae5b1911b76e3bf7027c01415145bfbd6bee3e3f853
sourceBlobDigest: sha256:f079320c7561160783552dcc1331f166de988922dd9bdb108df9625279ca3002
tags:
- latest
- main
targets:
unstructed-typescript:
source: my-source
sourceNamespace: my-source
sourceRevisionDigest: sha256:a6a17fc122fce52ae3601b08bffe8294b5d355d1b5370390192536c856f475da
sourceBlobDigest: sha256:c85052e891c341ae0a33a0bc0e21498d897649af7c1d1fa7638da4a857eb4d49
sourceRevisionDigest: sha256:1320eaa3fcc76a80f0eb1ae5b1911b76e3bf7027c01415145bfbd6bee3e3f853
sourceBlobDigest: sha256:f079320c7561160783552dcc1331f166de988922dd9bdb108df9625279ca3002
outLocation: /github/workspace/repo
workflow:
workflowVersion: 1.0.0
Expand Down
12 changes: 11 additions & 1 deletion RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,4 +364,14 @@ Based on:
### Generated
- [typescript v0.12.0] .
### Releases
- [NPM v0.12.0] https://www.npmjs.com/package/unstructured-client/v/0.12.0 - .
- [NPM v0.12.0] https://www.npmjs.com/package/unstructured-client/v/0.12.0 - .

## 2024-07-13 00:24:00
### Changes
Based on:
- OpenAPI Doc
- Speakeasy CLI 1.335.0 (2.370.2) https://github.com/speakeasy-api/speakeasy
### Generated
- [typescript v0.13.0] .
### Releases
- [NPM v0.13.0] https://www.npmjs.com/package/unstructured-client/v/0.13.0 - .
2 changes: 1 addition & 1 deletion gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ generation:
auth:
oAuth2ClientCredentialsEnabled: false
typescript:
version: 0.12.0
version: 0.13.0
additionalDependencies:
dependencies:
async: ^3.2.5
Expand Down
2 changes: 1 addition & 1 deletion jsr.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{
"name": "unstructured-client",
"version": "0.12.0",
"version": "0.13.0",
"exports": {
".": "./src/index.ts",
"./sdk/models/errors": "./src/sdk/models/errors/index.ts",
Expand Down
17 changes: 2 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "unstructured-client",
"version": "0.12.0",
"version": "0.13.0",
"author": "Unstructured",
"main": "./index.js",
"sideEffects": false,
Expand All @@ -20,7 +20,6 @@
"devDependencies": {
"@types/async": "^3.2.24",
"@types/jest": "^29.5.12",
"@types/jsonpath": "^0.2.4",
"@typescript-eslint/eslint-plugin": "^7.7.1",
"@typescript-eslint/parser": "^7.7.1",
"eslint": "^8.57.0",
Expand Down
7 changes: 4 additions & 3 deletions src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export type SDKOptions = {
* Allows overriding the default retry config used by the SDK
*/
retryConfig?: RetryConfig;
timeoutMs?: number;
};

export function serverURLFromOptions(options: SDKOptions): URL | null {
Expand All @@ -61,7 +62,7 @@ export function serverURLFromOptions(options: SDKOptions): URL | null {
export const SDK_METADATA = {
language: "typescript",
openapiDocVersion: "1.0.39",
sdkVersion: "0.12.0",
genVersion: "2.361.10",
userAgent: "speakeasy-sdk/typescript 0.12.0 2.361.10 1.0.39 unstructured-client",
sdkVersion: "0.13.0",
genVersion: "2.370.2",
userAgent: "speakeasy-sdk/typescript 0.13.0 2.370.2 1.0.39 unstructured-client",
} as const;
75 changes: 59 additions & 16 deletions src/lib/sdks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import { ResponseMatcher, HTTPClient, matchStatusCode } from "./http.js";
import { SecurityState, resolveSecurity, resolveGlobalSecurity } from "./security.js";
import { retry, RetryConfig } from "./retries.js";
import { pathToFunc } from "./url.js";
import { encodeForm } from "./encodings.js";
import { stringToBase64 } from "./base64.js";
Expand All @@ -12,6 +13,24 @@ import { SDKHooks } from "../hooks/hooks.js";
import { HookContext } from "../hooks/types.js";

export type RequestOptions = {
/**
* Sets a timeout, in milliseconds, on HTTP requests made by an SDK method. If
* `fetchOptions.signal` is set then it will take precedence over this option.
*/
timeoutMs?: number;
/**
* Set or override a retry policy on HTTP calls.
*/
retries?: RetryConfig;
/**
* Specifies the status codes which should be retried using the given retry policy.
*/
retryCodes?: string[];
/**
* Sets various request options on the `fetch` call made by an SDK method.
*
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options|Request}
*/
fetchOptions?: Omit<RequestInit, "method" | "body">;
};

Expand All @@ -24,6 +43,7 @@ type RequestConfig = {
headers?: HeadersInit;
security?: SecurityState | null;
uaHeader?: string;
timeoutMs?: number;
};

const gt: unknown = typeof globalThis === "undefined" ? null : globalThis;
Expand Down Expand Up @@ -119,10 +139,20 @@ export class ClientSDK {
headers.set(conf.uaHeader ?? "user-agent", SDK_METADATA.userAgent);
}

let fetchOptions = options?.fetchOptions;
if (!fetchOptions?.signal && conf.timeoutMs && conf.timeoutMs > 0) {
const timeoutSignal = AbortSignal.timeout(conf.timeoutMs);
if (!fetchOptions) {
fetchOptions = { signal: timeoutSignal };
} else {
fetchOptions.signal = timeoutSignal;
}
}

const input = this.hooks$.beforeCreateRequest(context, {
url: reqURL,
options: {
...options?.fetchOptions,
...fetchOptions,
body: conf.body ?? null,
headers,
method,
Expand All @@ -133,27 +163,40 @@ export class ClientSDK {
}

protected async do$(
req: Request,
request: Request,
options: {
context: HookContext;
errorCodes: number | string | (number | string)[];
retryConfig?: RetryConfig | undefined;
retryCodes?: string[] | undefined;
}
): Promise<Response> {
const { context, errorCodes } = options;

let response = await this.client.request(await this.hooks$.beforeRequest(context, req));

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);
}

return response;
const retryConfig = options.retryConfig || { strategy: "none" };
const retryCodes = options.retryCodes || [];

return retry(
async () => {
const req = request.clone();

let response = await this.client.request(
await this.hooks$.beforeRequest(context, req)
);

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);
}

return response;
},
{ config: retryConfig, statusCodes: retryCodes }
);
}

protected matcher<Result>(): ResponseMatcher<Result> {
Expand Down
37 changes: 17 additions & 20 deletions src/sdk/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { SDKHooks } from "../hooks/hooks.js";
import { SDKOptions, serverURLFromOptions } from "../lib/config.js";
import { encodeSimple as encodeSimple$ } from "../lib/encodings.js";
import { HTTPClient } from "../lib/http.js";
import * as retries$ from "../lib/retries.js";
import * as schemas$ from "../lib/schemas.js";
import { ClientSDK, RequestOptions } from "../lib/sdks.js";
import * as errors from "./models/errors/index.js";
Expand Down Expand Up @@ -48,7 +47,7 @@ export class General extends ClientSDK {
*/
async partition(
request: operations.PartitionRequest,
options?: RequestOptions & { retries?: retries$.RetryConfig }
options?: RequestOptions
): Promise<operations.PartitionResponse> {
const input$ = request;

Expand Down Expand Up @@ -228,29 +227,27 @@ export class General extends ClientSDK {
headers: headers$,
query: query$,
body: body$,
timeoutMs: options?.timeoutMs || this.options$.timeoutMs || -1,
},
options
);

const retryConfig = options?.retries ||
this.options$.retryConfig || {
strategy: "backoff",
backoff: {
initialInterval: 500,
maxInterval: 60000,
exponent: 1.5,
maxElapsedTime: 900000,
const response = await this.do$(request$, {
context,
errorCodes: ["422", "4XX", "5XX"],
retryConfig: options?.retries ||
this.options$.retryConfig || {
strategy: "backoff",
backoff: {
initialInterval: 500,
maxInterval: 60000,
exponent: 1.5,
maxElapsedTime: 900000,
},
retryConnectionErrors: true,
},
retryConnectionErrors: true,
};

const response = await retries$.retry(
() => {
const cloned = request$.clone();
return this.do$(cloned, { context, errorCodes: ["422", "4XX", "5XX"] });
},
{ config: retryConfig, statusCodes: ["5xx"] }
);
retryCodes: options?.retryCodes || ["5xx"],
});

const responseFields$ = {
ContentType: response.headers.get("content-type") ?? "application/octet-stream",
Expand Down

0 comments on commit 1bbf695

Please sign in to comment.