From 7af099edeb108463e941f2a9741f6c193b29f1b3 Mon Sep 17 00:00:00 2001 From: fern-api <115122769+fern-api[bot]@users.noreply.github.com> Date: Tue, 23 Jul 2024 15:43:52 +0000 Subject: [PATCH] SDK regeneration --- .mock/fern.config.json | 2 +- package.json | 4 +- reference.md | 90 ++++----------------- src/api/resources/checkout/client/Client.ts | 9 ++- src/core/fetcher/Fetcher.ts | 14 +++- src/core/fetcher/getFetchFn.ts | 8 +- src/core/fetcher/getRequestBody.ts | 38 +++------ src/core/fetcher/makeRequest.ts | 5 +- src/core/runtime/runtime.ts | 2 + yarn.lock | 32 ++++---- 10 files changed, 74 insertions(+), 130 deletions(-) diff --git a/.mock/fern.config.json b/.mock/fern.config.json index 197432e..4471af3 100644 --- a/.mock/fern.config.json +++ b/.mock/fern.config.json @@ -1,4 +1,4 @@ { "organization" : "crossmint", - "version" : "0.31.24" + "version" : "0.33.5" } \ No newline at end of file diff --git a/package.json b/package.json index a15ea95..ad8b09b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "crossmint", - "version": "0.1.7", + "version": "0.0.3", "private": false, "repository": "https://github.com/fern-demo/crossmint-typescript-sdk", "main": "./index.js", @@ -13,7 +13,7 @@ }, "dependencies": { "url-join": "4.0.1", - "form-data": "4.0.0", + "form-data": "^4.0.0", "formdata-node": "^6.0.3", "node-fetch": "2.7.0", "qs": "6.11.2" diff --git a/reference.md b/reference.md index f5b7041..6c8d62b 100644 --- a/reference.md +++ b/reference.md @@ -1,42 +1,35 @@ -## Checkout +# Reference -
client.checkout.createOrder({ ...params }) -> Crossmint.CreateOrderResponse +## Checkout +
client.checkout.createOrder({ ...params }) -> Crossmint.CreateOrderResponse
-
#### 📝 Description
-
-
Creates a new order that can be used to complete a headless checkout.
-
-
-
#### 🔌 Usage
-
-
-```ts +```typescript await client.checkout.createOrder({ payment: { method: Crossmint.EvmPaymentMethods.ArbitrumSepolia, @@ -49,228 +42,175 @@ await client.checkout.createOrder({ ```
-
-
-
#### ⚙️ Parameters
-
-
-**request: `Crossmint.CheckoutCreateOrderRequest`** +**request:** `Crossmint.CheckoutCreateOrderRequest`
-
-
-**requestOptions: `Checkout.RequestOptions`** +**requestOptions:** `Checkout.RequestOptions`
-
-
-
-
-
client.checkout.getOrder(orderId) -> Crossmint.OrderObject - +
client.checkout.getOrder(orderId) -> Crossmint.OrderObject
-
#### 📝 Description
-
-
Get specific order by ID
-
-
-
#### 🔌 Usage
-
-
-```ts +```typescript await client.checkout.getOrder("orderId"); ```
-
-
-
#### ⚙️ Parameters
-
-
-**orderId: `string`** +**orderId:** `string` This is the identifier for the order with UUID format. **Example:** `9c82ef99-617f-497d-9abb-fd355291681b`
-
-
-**requestOptions: `Checkout.RequestOptions`** +**requestOptions:** `Checkout.RequestOptions`
-
-
-
-
-
client.checkout.editOrder(orderId, { ...params }) -> Crossmint.OrderObject - +
client.checkout.editOrder(orderId, { ...params }) -> Crossmint.OrderObject
-
#### 📝 Description
-
-
Edit an existing order. You can update the recipient, the payment method, and/or the locale.
-
-
-
#### 🔌 Usage
-
-
-```ts +```typescript await client.checkout.editOrder("orderId"); ```
-
-
-
#### ⚙️ Parameters
-
-
-**orderId: `string`** +**orderId:** `string` This is the identifier for the order with UUID format. **Example:** `9c82ef99-617f-497d-9abb-fd355291681b`
-
-
-**request: `Crossmint.OrderDto`** +**request:** `Crossmint.OrderDto`
-
-
-**requestOptions: `Checkout.RequestOptions`** +**requestOptions:** `Checkout.RequestOptions`
-
-
-
-
diff --git a/src/api/resources/checkout/client/Client.ts b/src/api/resources/checkout/client/Client.ts index db435cb..610bef1 100644 --- a/src/api/resources/checkout/client/Client.ts +++ b/src/api/resources/checkout/client/Client.ts @@ -64,12 +64,13 @@ export class Checkout { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.1.7", + "X-Fern-SDK-Version": "0.0.3", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), }, contentType: "application/json", + requestType: "json", body: serializers.CheckoutCreateOrderRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, @@ -176,12 +177,13 @@ export class Checkout { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.1.7", + "X-Fern-SDK-Version": "0.0.3", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), }, contentType: "application/json", + requestType: "json", timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, abortSignal: requestOptions?.abortSignal, @@ -292,12 +294,13 @@ export class Checkout { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.1.7", + "X-Fern-SDK-Version": "0.0.3", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), }, contentType: "application/json", + requestType: "json", body: serializers.OrderDto.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, maxRetries: requestOptions?.maxRetries, diff --git a/src/core/fetcher/Fetcher.ts b/src/core/fetcher/Fetcher.ts index d368636..02af7dc 100644 --- a/src/core/fetcher/Fetcher.ts +++ b/src/core/fetcher/Fetcher.ts @@ -20,7 +20,9 @@ export declare namespace Fetcher { maxRetries?: number; withCredentials?: boolean; abortSignal?: AbortSignal; + requestType?: "json" | "file" | "bytes"; responseType?: "json" | "blob" | "streaming" | "text"; + duplex?: "half"; } export type Error = FailedStatusCodeError | NonJsonError | TimeoutError | UnknownError; @@ -62,7 +64,10 @@ export async function fetcherImpl(args: Fetcher.Args): Promise(args: Fetcher.Args): Promise= 200 && response.status < 400) { + if (args.duplex && args.responseType === "streaming") { + responseBody = (await import("stream")).Readable.from(responseBody as any); + } + return { ok: true, body: responseBody as R, diff --git a/src/core/fetcher/getFetchFn.ts b/src/core/fetcher/getFetchFn.ts index 68a2874..9fd9bfc 100644 --- a/src/core/fetcher/getFetchFn.ts +++ b/src/core/fetcher/getFetchFn.ts @@ -1,9 +1,15 @@ import { RUNTIME } from "../runtime"; + /** * Returns a fetch function based on the runtime */ export async function getFetchFn(): Promise { - // In Node.js environments, the SDK always uses`node-fetch`. + // In Node.js 18+ environments, use native fetch + if (RUNTIME.type === "node" && RUNTIME.parsedVersion != null && RUNTIME.parsedVersion >= 18) { + return fetch; + } + + // In Node.js 18 or lower environments, the SDK always uses`node-fetch`. if (RUNTIME.type === "node") { return (await import("node-fetch")).default as any; } diff --git a/src/core/fetcher/getRequestBody.ts b/src/core/fetcher/getRequestBody.ts index 9ad67ca..1138414 100644 --- a/src/core/fetcher/getRequestBody.ts +++ b/src/core/fetcher/getRequestBody.ts @@ -1,34 +1,14 @@ -import { RUNTIME } from "../runtime"; - -export async function getRequestBody(body: any, contentType: string): Promise { - let requestBody: BodyInit; - if (RUNTIME.type === "node") { - if (body instanceof (await import("formdata-node")).FormData) { - // @ts-expect-error - requestBody = body; - } else if (body instanceof (await import("stream")).Readable) { - // @ts-expect-error - requestBody = body; - } else { - requestBody = maybeStringifyBody(body, contentType ?? ""); - } - } else { - if (body instanceof (await import("form-data")).default) { - // @ts-expect-error - requestBody = body; - } else { - requestBody = maybeStringifyBody(body, contentType ?? ""); - } +export declare namespace GetRequestBody { + interface Args { + body: unknown; + type: "json" | "file" | "bytes" | "other"; } - return requestBody; } -export const maybeStringifyBody = (requestBody: any, contentType: string): Uint8Array | string => { - if (requestBody instanceof Uint8Array) { - return requestBody; - } else if (contentType === "application/x-www-form-urlencoded" && typeof requestBody === "string") { - return requestBody; +export async function getRequestBody({ body, type }: GetRequestBody.Args): Promise { + if (type.includes("json")) { + return JSON.stringify(body); } else { - return JSON.stringify(requestBody); + return body as BodyInit; } -}; +} diff --git a/src/core/fetcher/makeRequest.ts b/src/core/fetcher/makeRequest.ts index 1c1702b..8fb4bac 100644 --- a/src/core/fetcher/makeRequest.ts +++ b/src/core/fetcher/makeRequest.ts @@ -8,7 +8,8 @@ export const makeRequest = async ( requestBody: BodyInit | undefined, timeoutMs?: number, abortSignal?: AbortSignal, - withCredentials?: boolean + withCredentials?: boolean, + duplex?: "half" ): Promise => { const signals: AbortSignal[] = []; @@ -31,6 +32,8 @@ export const makeRequest = async ( body: requestBody, signal: newSignals, credentials: withCredentials ? "include" : undefined, + // @ts-ignore + duplex, }); if (timeoutAbortId != null) { diff --git a/src/core/runtime/runtime.ts b/src/core/runtime/runtime.ts index 30fe077..4d0687e 100644 --- a/src/core/runtime/runtime.ts +++ b/src/core/runtime/runtime.ts @@ -69,6 +69,7 @@ export const RUNTIME: Runtime = evaluateRuntime(); export interface Runtime { type: "browser" | "web-worker" | "deno" | "bun" | "node" | "react-native" | "unknown" | "workerd"; version?: string; + parsedVersion?: number; } function evaluateRuntime(): Runtime { @@ -109,6 +110,7 @@ function evaluateRuntime(): Runtime { return { type: "node", version: process.versions.node, + parsedVersion: Number(process.versions.node.split(".")[0]), }; } diff --git a/yarn.lock b/yarn.lock index 4b2afd2..cc6e63a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -912,9 +912,9 @@ camelcase@^6.2.0: integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA== caniuse-lite@^1.0.30001640: - version "1.0.30001642" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001642.tgz#6aa6610eb24067c246d30c57f055a9d0a7f8d05f" - integrity sha512-3XQ0DoRgLijXJErLSl+bLnJ+Et4KqV1PY6JJBGAFlsNsz31zeAIncyeZfLCabHK/jtSh+671RM9YMldxjUPZtA== + version "1.0.30001643" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001643.tgz#9c004caef315de9452ab970c3da71085f8241dbd" + integrity sha512-ERgWGNleEilSrHM6iUz/zJNSQTP8Mr21wDWpdgvRwcTXGAq6jMtOUPP4dqFPTdKqZ2wKTdtB+uucZ3MRpAUSmg== chalk@^2.4.2: version "2.4.2" @@ -1110,9 +1110,9 @@ domexception@^4.0.0: webidl-conversions "^7.0.0" electron-to-chromium@^1.4.820: - version "1.4.829" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.829.tgz#3034a865b5eac9064c9db8b38ba99b60a446bb73" - integrity sha512-5qp1N2POAfW0u1qGAxXEtz6P7bO1m6gpZr5hdf5ve6lxpLM7MpiM4jIPz7xcrNlClQMafbyUDDWjlIQZ1Mw0Rw== + version "1.5.0" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.5.0.tgz#0d3123a9f09189b9c7ab4b5d6848d71b3c1fd0e8" + integrity sha512-Vb3xHHYnLseK8vlMJQKJYXJ++t4u1/qJ3vykuVrVjvdiOEhYyT1AuP4x03G8EnPmYvYOhe9T+dADTmthjRQMkA== emittery@^0.13.1: version "0.13.1" @@ -1247,7 +1247,7 @@ find-up@^4.0.0, find-up@^4.1.0: locate-path "^5.0.0" path-exists "^4.0.0" -form-data@4.0.0, form-data@^4.0.0: +form-data@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452" integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww== @@ -1412,9 +1412,9 @@ iconv-lite@0.6.3: safer-buffer ">= 2.1.2 < 3.0.0" import-local@^3.0.2: - version "3.1.0" - resolved "https://registry.yarnpkg.com/import-local/-/import-local-3.1.0.tgz#b4479df8a5fd44f6cdce24070675676063c95cb4" - integrity sha512-ASB07uLtnDs1o6EHjKpX34BKYDSqnFerfTOJL2HvMqF70LnxpjkzDB8J44oT9pu4AMPkQwf8jl6szgvNd2tRIg== + version "3.2.0" + resolved "https://registry.yarnpkg.com/import-local/-/import-local-3.2.0.tgz#c3d5c745798c02a6f8b897726aba5100186ee260" + integrity sha512-2SPlun1JUPWoM6t3F0dw0FkCF/jWY8kttcY4f599GLTSjh2OCuuhdTkJQsEcZzBqbXZGKMK2OqW1oZsjtf/gQA== dependencies: pkg-dir "^4.2.0" resolve-cwd "^3.0.0" @@ -1443,9 +1443,9 @@ is-arrayish@^0.2.1: integrity sha512-zz06S8t0ozoDXMG+ube26zeCTNXcKIPJZJi8hBrF4idCLms4CG9QtK7qBl1boi5ODzFpjswb5JPmHCbMpjaYzg== is-core-module@^2.13.0: - version "2.14.0" - resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.14.0.tgz#43b8ef9f46a6a08888db67b1ffd4ec9e3dfd59d1" - integrity sha512-a5dFJih5ZLYlRtDc0dZWP7RiKr6xIKzmn/oAYCDvdLThadVgyJwlaoQPmRtMSpz+rk0OGAgIu+TcM9HUF0fk1A== + version "2.15.0" + resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.15.0.tgz#71c72ec5442ace7e76b306e9d48db361f22699ea" + integrity sha512-Dd+Lb2/zvk9SKy1TGCt1wFJFo/MWBPMX5x7KcvLajWTGuomczdQX61PvY5yK6SVACwpoexWo81IfFyoKY2QnTA== dependencies: hasown "^2.0.2" @@ -2077,9 +2077,9 @@ node-int64@^0.4.0: integrity sha512-O5lz91xSOeoXP6DulyHfllpq+Eg00MWitZIbtPfoSEvqIHdl5gfcY6hYzDWnj0qD5tz52PI08u9qUvSVeUBeHw== node-releases@^2.0.14: - version "2.0.17" - resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-2.0.17.tgz#d74bc4fec38d839eec5db2a3c9c963d4f33cb366" - integrity sha512-Ww6ZlOiEQfPfXM45v17oabk77Z7mg5bOt7AjDyzy7RjK9OrLrLC8dyZQoAPEOtFX9SaNf1Tdvr5gRJWdTJj7GA== + version "2.0.18" + resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-2.0.18.tgz#f010e8d35e2fe8d6b2944f03f70213ecedc4ca3f" + integrity sha512-d9VeXT4SJ7ZeOqGX6R5EM022wpL+eWPooLI+5UpWn2jCT1aosUQEhQP214x33Wkwx3JQMvIm+tIoVOdodFS40g== normalize-path@^3.0.0: version "3.0.0"