diff --git a/.mock/definition/api.yml b/.mock/definition/api.yml index b969c6b..f9919dc 100644 --- a/.mock/definition/api.yml +++ b/.mock/definition/api.yml @@ -6,6 +6,11 @@ default-environment: Staging environments: Staging: https://staging.crossmint.com/api Production: https://www.crossmint.com/api +headers: + Authorization: + name: clientSecret + env: CROSSMINT_CLIENT_SECRET + type: optional auth-schemes: apiKey: header: X-API-KEY diff --git a/.mock/definition/headless.yml b/.mock/definition/headless.yml index e2d8da7..00c8be9 100644 --- a/.mock/definition/headless.yml +++ b/.mock/definition/headless.yml @@ -119,7 +119,7 @@ service: edit-order: path: /2022-06-09/orders/{orderId} method: PATCH - auth: true + auth: false docs: >- Edit an existing order. You can update the recipient, the payment method, and/or the locale. diff --git a/.mock/fern.config.json b/.mock/fern.config.json index 55f8356..bfb5794 100644 --- a/.mock/fern.config.json +++ b/.mock/fern.config.json @@ -1,4 +1,4 @@ { "organization" : "crossmint", - "version" : "0.36.0" + "version" : "0.37.0" } \ No newline at end of file diff --git a/README.md b/README.md index cefd982..881977f 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Instantiate and use the client with the following: ```typescript import { CrossmintClient, Crossmint } from "crossmint"; -const client = new CrossmintClient({ apiKey: "YOUR_API_KEY" }); +const client = new CrossmintClient({ apiKey: "YOUR_API_KEY", clientSecret: "YOUR_CLIENT_SECRET" }); await client.wallets({}); ``` diff --git a/package.json b/package.json index 06330a3..57df8b1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "crossmint", - "version": "0.2.1", + "version": "0.2.2", "private": false, "repository": "https://github.com/Paella-Labs/typescript-sdk", "main": "./index.js", diff --git a/src/Client.ts b/src/Client.ts index e8520e4..b446357 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -23,7 +23,9 @@ import { Sign } from "./api/resources/sign/client/Client"; export declare namespace CrossmintClient { interface Options { environment?: core.Supplier; - apiKey: core.Supplier; + apiKey?: core.Supplier; + /** Override the Authorization header */ + clientSecret?: core.Supplier; fetcher?: core.FetchFunction; } @@ -34,11 +36,13 @@ export declare namespace CrossmintClient { maxRetries?: number; /** A hook to abort the request. */ abortSignal?: AbortSignal; + /** Override the Authorization header */ + clientSecret?: string | undefined; } } export class CrossmintClient { - constructor(protected readonly _options: CrossmintClient.Options) {} + constructor(protected readonly _options: CrossmintClient.Options = {}) {} /** * Get usage data for a project. @@ -80,7 +84,7 @@ export class CrossmintClient { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -161,7 +165,7 @@ export class CrossmintClient { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -241,7 +245,7 @@ export class CrossmintClient { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -353,7 +357,8 @@ export class CrossmintClient { } protected async _getCustomAuthorizationHeaders() { + const clientSecretValue = await core.Supplier.get(this._options.clientSecret); const apiKeyValue = await core.Supplier.get(this._options.apiKey); - return { "X-API-KEY": apiKeyValue }; + return { Authorization: clientSecretValue, "X-API-KEY": apiKeyValue }; } } diff --git a/src/api/resources/actions/client/Client.ts b/src/api/resources/actions/client/Client.ts index 3dd641b..3162592 100644 --- a/src/api/resources/actions/client/Client.ts +++ b/src/api/resources/actions/client/Client.ts @@ -12,7 +12,9 @@ import * as errors from "../../../../errors/index"; export declare namespace Actions { interface Options { environment?: core.Supplier; - apiKey: core.Supplier; + apiKey?: core.Supplier; + /** Override the Authorization header */ + clientSecret?: core.Supplier; fetcher?: core.FetchFunction; } @@ -23,11 +25,13 @@ export declare namespace Actions { maxRetries?: number; /** A hook to abort the request. */ abortSignal?: AbortSignal; + /** Override the Authorization header */ + clientSecret?: string | undefined; } } export class Actions { - constructor(protected readonly _options: Actions.Options) {} + constructor(protected readonly _options: Actions.Options = {}) {} /** * Use this API to poll for the status of asynchonous actions such as NFT mints, transfers, etc. @@ -56,7 +60,7 @@ export class Actions { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -107,7 +111,8 @@ export class Actions { } protected async _getCustomAuthorizationHeaders() { + const clientSecretValue = await core.Supplier.get(this._options.clientSecret); const apiKeyValue = await core.Supplier.get(this._options.apiKey); - return { "X-API-KEY": apiKeyValue }; + return { Authorization: clientSecretValue, "X-API-KEY": apiKeyValue }; } } diff --git a/src/api/resources/checkout/client/Client.ts b/src/api/resources/checkout/client/Client.ts index 2980b03..5785162 100644 --- a/src/api/resources/checkout/client/Client.ts +++ b/src/api/resources/checkout/client/Client.ts @@ -12,7 +12,9 @@ import * as errors from "../../../../errors/index"; export declare namespace Checkout { interface Options { environment?: core.Supplier; - apiKey: core.Supplier; + apiKey?: core.Supplier; + /** Override the Authorization header */ + clientSecret?: core.Supplier; fetcher?: core.FetchFunction; } @@ -23,11 +25,13 @@ export declare namespace Checkout { maxRetries?: number; /** A hook to abort the request. */ abortSignal?: AbortSignal; + /** Override the Authorization header */ + clientSecret?: string | undefined; } } export class Checkout { - constructor(protected readonly _options: Checkout.Options) {} + constructor(protected readonly _options: Checkout.Options = {}) {} /** * **API scope required**: `nfts.checkout` Begin the checkout process for a mint @@ -58,7 +62,7 @@ export class Checkout { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -110,7 +114,8 @@ export class Checkout { } protected async _getCustomAuthorizationHeaders() { + const clientSecretValue = await core.Supplier.get(this._options.clientSecret); const apiKeyValue = await core.Supplier.get(this._options.apiKey); - return { "X-API-KEY": apiKeyValue }; + return { Authorization: clientSecretValue, "X-API-KEY": apiKeyValue }; } } diff --git a/src/api/resources/headless/client/Client.ts b/src/api/resources/headless/client/Client.ts index e798715..36dbbf5 100644 --- a/src/api/resources/headless/client/Client.ts +++ b/src/api/resources/headless/client/Client.ts @@ -12,7 +12,9 @@ import * as errors from "../../../../errors/index"; export declare namespace Headless { interface Options { environment?: core.Supplier; - apiKey: core.Supplier; + apiKey?: core.Supplier; + /** Override the Authorization header */ + clientSecret?: core.Supplier; fetcher?: core.FetchFunction; } @@ -23,11 +25,13 @@ export declare namespace Headless { maxRetries?: number; /** A hook to abort the request. */ abortSignal?: AbortSignal; + /** Override the Authorization header */ + clientSecret?: string | undefined; } } export class Headless { - constructor(protected readonly _options: Headless.Options) {} + constructor(protected readonly _options: Headless.Options = {}) {} /** * Creates a new order that can be used to complete a headless checkout. @@ -64,7 +68,7 @@ export class Headless { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -145,7 +149,7 @@ export class Headless { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -230,7 +234,7 @@ export class Headless { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -286,7 +290,8 @@ export class Headless { } protected async _getCustomAuthorizationHeaders() { + const clientSecretValue = await core.Supplier.get(this._options.clientSecret); const apiKeyValue = await core.Supplier.get(this._options.apiKey); - return { "X-API-KEY": apiKeyValue }; + return { Authorization: clientSecretValue, "X-API-KEY": apiKeyValue }; } } diff --git a/src/api/resources/nfTs/client/Client.ts b/src/api/resources/nfTs/client/Client.ts index 4472513..2af1759 100644 --- a/src/api/resources/nfTs/client/Client.ts +++ b/src/api/resources/nfTs/client/Client.ts @@ -12,7 +12,9 @@ import * as errors from "../../../../errors/index"; export declare namespace NfTs { interface Options { environment?: core.Supplier; - apiKey: core.Supplier; + apiKey?: core.Supplier; + /** Override the Authorization header */ + clientSecret?: core.Supplier; fetcher?: core.FetchFunction; } @@ -23,11 +25,13 @@ export declare namespace NfTs { maxRetries?: number; /** A hook to abort the request. */ abortSignal?: AbortSignal; + /** Override the Authorization header */ + clientSecret?: string | undefined; } } export class NfTs { - constructor(protected readonly _options: NfTs.Options) {} + constructor(protected readonly _options: NfTs.Options = {}) {} /** * Mint multiple NFTs with a single call and deliver them to a web3 wallet or an email address @@ -67,7 +71,7 @@ export class NfTs { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -167,7 +171,7 @@ export class NfTs { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -265,7 +269,7 @@ export class NfTs { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -361,7 +365,7 @@ export class NfTs { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, "x-idempotency-key": idempotencyKey != null ? idempotencyKey : undefined, @@ -454,7 +458,7 @@ export class NfTs { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -555,7 +559,7 @@ export class NfTs { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -647,7 +651,7 @@ export class NfTs { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -748,7 +752,7 @@ export class NfTs { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -833,7 +837,7 @@ export class NfTs { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -936,7 +940,7 @@ export class NfTs { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -1002,7 +1006,8 @@ export class NfTs { } protected async _getCustomAuthorizationHeaders() { + const clientSecretValue = await core.Supplier.get(this._options.clientSecret); const apiKeyValue = await core.Supplier.get(this._options.apiKey); - return { "X-API-KEY": apiKeyValue }; + return { Authorization: clientSecretValue, "X-API-KEY": apiKeyValue }; } } diff --git a/src/api/resources/nftCollections/client/Client.ts b/src/api/resources/nftCollections/client/Client.ts index 2616111..7e433af 100644 --- a/src/api/resources/nftCollections/client/Client.ts +++ b/src/api/resources/nftCollections/client/Client.ts @@ -12,7 +12,9 @@ import * as errors from "../../../../errors/index"; export declare namespace NftCollections { interface Options { environment?: core.Supplier; - apiKey: core.Supplier; + apiKey?: core.Supplier; + /** Override the Authorization header */ + clientSecret?: core.Supplier; fetcher?: core.FetchFunction; } @@ -23,11 +25,13 @@ export declare namespace NftCollections { maxRetries?: number; /** A hook to abort the request. */ abortSignal?: AbortSignal; + /** Override the Authorization header */ + clientSecret?: string | undefined; } } export class NftCollections { - constructor(protected readonly _options: NftCollections.Options) {} + constructor(protected readonly _options: NftCollections.Options = {}) {} /** * List all collections created under the current Crossmint project @@ -56,7 +60,7 @@ export class NftCollections { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -145,7 +149,7 @@ export class NftCollections { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -235,7 +239,7 @@ export class NftCollections { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -333,7 +337,7 @@ export class NftCollections { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -425,7 +429,7 @@ export class NftCollections { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -522,7 +526,7 @@ export class NftCollections { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -616,7 +620,7 @@ export class NftCollections { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -704,7 +708,7 @@ export class NftCollections { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -787,7 +791,7 @@ export class NftCollections { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -885,7 +889,7 @@ export class NftCollections { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -975,7 +979,7 @@ export class NftCollections { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -1072,7 +1076,7 @@ export class NftCollections { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -1124,7 +1128,8 @@ export class NftCollections { } protected async _getCustomAuthorizationHeaders() { + const clientSecretValue = await core.Supplier.get(this._options.clientSecret); const apiKeyValue = await core.Supplier.get(this._options.apiKey); - return { "X-API-KEY": apiKeyValue }; + return { Authorization: clientSecretValue, "X-API-KEY": apiKeyValue }; } } diff --git a/src/api/resources/nftTemplates/client/Client.ts b/src/api/resources/nftTemplates/client/Client.ts index 26ee425..465722f 100644 --- a/src/api/resources/nftTemplates/client/Client.ts +++ b/src/api/resources/nftTemplates/client/Client.ts @@ -12,7 +12,9 @@ import * as errors from "../../../../errors/index"; export declare namespace NftTemplates { interface Options { environment?: core.Supplier; - apiKey: core.Supplier; + apiKey?: core.Supplier; + /** Override the Authorization header */ + clientSecret?: core.Supplier; fetcher?: core.FetchFunction; } @@ -23,11 +25,13 @@ export declare namespace NftTemplates { maxRetries?: number; /** A hook to abort the request. */ abortSignal?: AbortSignal; + /** Override the Authorization header */ + clientSecret?: string | undefined; } } export class NftTemplates { - constructor(protected readonly _options: NftTemplates.Options) {} + constructor(protected readonly _options: NftTemplates.Options = {}) {} /** * Get all of the templates for a collection @@ -76,7 +80,7 @@ export class NftTemplates { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -163,7 +167,7 @@ export class NftTemplates { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -265,7 +269,7 @@ export class NftTemplates { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -359,7 +363,7 @@ export class NftTemplates { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -461,7 +465,7 @@ export class NftTemplates { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -547,7 +551,7 @@ export class NftTemplates { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -595,7 +599,8 @@ export class NftTemplates { } protected async _getCustomAuthorizationHeaders() { + const clientSecretValue = await core.Supplier.get(this._options.clientSecret); const apiKeyValue = await core.Supplier.get(this._options.apiKey); - return { "X-API-KEY": apiKeyValue }; + return { Authorization: clientSecretValue, "X-API-KEY": apiKeyValue }; } } diff --git a/src/api/resources/quotePrice/client/Client.ts b/src/api/resources/quotePrice/client/Client.ts index 7decaba..7d01a92 100644 --- a/src/api/resources/quotePrice/client/Client.ts +++ b/src/api/resources/quotePrice/client/Client.ts @@ -12,7 +12,9 @@ import * as errors from "../../../../errors/index"; export declare namespace QuotePrice { interface Options { environment?: core.Supplier; - apiKey: core.Supplier; + apiKey?: core.Supplier; + /** Override the Authorization header */ + clientSecret?: core.Supplier; fetcher?: core.FetchFunction; } @@ -23,11 +25,13 @@ export declare namespace QuotePrice { maxRetries?: number; /** A hook to abort the request. */ abortSignal?: AbortSignal; + /** Override the Authorization header */ + clientSecret?: string | undefined; } } export class QuotePrice { - constructor(protected readonly _options: QuotePrice.Options) {} + constructor(protected readonly _options: QuotePrice.Options = {}) {} /** * Get the price of a transaction hosted through Crossmint, inclusive of all fees. @@ -62,7 +66,7 @@ export class QuotePrice { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -112,7 +116,8 @@ export class QuotePrice { } protected async _getCustomAuthorizationHeaders() { + const clientSecretValue = await core.Supplier.get(this._options.clientSecret); const apiKeyValue = await core.Supplier.get(this._options.apiKey); - return { "X-API-KEY": apiKeyValue }; + return { Authorization: clientSecretValue, "X-API-KEY": apiKeyValue }; } } diff --git a/src/api/resources/registration/client/Client.ts b/src/api/resources/registration/client/Client.ts index 8ec72df..056faf2 100644 --- a/src/api/resources/registration/client/Client.ts +++ b/src/api/resources/registration/client/Client.ts @@ -12,7 +12,9 @@ import * as errors from "../../../../errors/index"; export declare namespace Registration { interface Options { environment?: core.Supplier; - apiKey: core.Supplier; + apiKey?: core.Supplier; + /** Override the Authorization header */ + clientSecret?: core.Supplier; fetcher?: core.FetchFunction; } @@ -23,11 +25,13 @@ export declare namespace Registration { maxRetries?: number; /** A hook to abort the request. */ abortSignal?: AbortSignal; + /** Override the Authorization header */ + clientSecret?: string | undefined; } } export class Registration { - constructor(protected readonly _options: Registration.Options) {} + constructor(protected readonly _options: Registration.Options = {}) {} /** * Register your NFT collection with Crossmint @@ -69,7 +73,7 @@ export class Registration { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -144,7 +148,7 @@ export class Registration { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -188,7 +192,8 @@ export class Registration { } protected async _getCustomAuthorizationHeaders() { + const clientSecretValue = await core.Supplier.get(this._options.clientSecret); const apiKeyValue = await core.Supplier.get(this._options.apiKey); - return { "X-API-KEY": apiKeyValue }; + return { Authorization: clientSecretValue, "X-API-KEY": apiKeyValue }; } } diff --git a/src/api/resources/sign/client/Client.ts b/src/api/resources/sign/client/Client.ts index fa6aa98..f30b15d 100644 --- a/src/api/resources/sign/client/Client.ts +++ b/src/api/resources/sign/client/Client.ts @@ -12,7 +12,9 @@ import * as errors from "../../../../errors/index"; export declare namespace Sign { interface Options { environment?: core.Supplier; - apiKey: core.Supplier; + apiKey?: core.Supplier; + /** Override the Authorization header */ + clientSecret?: core.Supplier; fetcher?: core.FetchFunction; } @@ -23,11 +25,13 @@ export declare namespace Sign { maxRetries?: number; /** A hook to abort the request. */ abortSignal?: AbortSignal; + /** Override the Authorization header */ + clientSecret?: string | undefined; } } export class Sign { - constructor(protected readonly _options: Sign.Options) {} + constructor(protected readonly _options: Sign.Options = {}) {} /** * Sign a message using a custodial wallet's key @@ -65,7 +69,7 @@ export class Sign { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -119,7 +123,8 @@ export class Sign { } protected async _getCustomAuthorizationHeaders() { + const clientSecretValue = await core.Supplier.get(this._options.clientSecret); const apiKeyValue = await core.Supplier.get(this._options.apiKey); - return { "X-API-KEY": apiKeyValue }; + return { Authorization: clientSecretValue, "X-API-KEY": apiKeyValue }; } } diff --git a/src/api/resources/verifiableCredentials/client/Client.ts b/src/api/resources/verifiableCredentials/client/Client.ts index 502ac0c..c3a421a 100644 --- a/src/api/resources/verifiableCredentials/client/Client.ts +++ b/src/api/resources/verifiableCredentials/client/Client.ts @@ -12,7 +12,9 @@ import * as errors from "../../../../errors/index"; export declare namespace VerifiableCredentials { interface Options { environment?: core.Supplier; - apiKey: core.Supplier; + apiKey?: core.Supplier; + /** Override the Authorization header */ + clientSecret?: core.Supplier; fetcher?: core.FetchFunction; } @@ -23,11 +25,13 @@ export declare namespace VerifiableCredentials { maxRetries?: number; /** A hook to abort the request. */ abortSignal?: AbortSignal; + /** Override the Authorization header */ + clientSecret?: string | undefined; } } export class VerifiableCredentials { - constructor(protected readonly _options: VerifiableCredentials.Options) {} + constructor(protected readonly _options: VerifiableCredentials.Options = {}) {} /** * Verify that a credential is valid. @@ -59,7 +63,7 @@ export class VerifiableCredentials { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -142,7 +146,7 @@ export class VerifiableCredentials { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -225,7 +229,7 @@ export class VerifiableCredentials { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -304,7 +308,7 @@ export class VerifiableCredentials { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -385,7 +389,7 @@ export class VerifiableCredentials { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -467,7 +471,7 @@ export class VerifiableCredentials { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -556,7 +560,7 @@ export class VerifiableCredentials { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -646,7 +650,7 @@ export class VerifiableCredentials { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -721,7 +725,7 @@ export class VerifiableCredentials { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -808,7 +812,7 @@ export class VerifiableCredentials { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -858,7 +862,8 @@ export class VerifiableCredentials { } protected async _getCustomAuthorizationHeaders() { + const clientSecretValue = await core.Supplier.get(this._options.clientSecret); const apiKeyValue = await core.Supplier.get(this._options.apiKey); - return { "X-API-KEY": apiKeyValue }; + return { Authorization: clientSecretValue, "X-API-KEY": apiKeyValue }; } } diff --git a/src/api/resources/wallet/client/Client.ts b/src/api/resources/wallet/client/Client.ts index dacbee5..fd69a4a 100644 --- a/src/api/resources/wallet/client/Client.ts +++ b/src/api/resources/wallet/client/Client.ts @@ -12,7 +12,9 @@ import * as errors from "../../../../errors/index"; export declare namespace Wallet { interface Options { environment?: core.Supplier; - apiKey: core.Supplier; + apiKey?: core.Supplier; + /** Override the Authorization header */ + clientSecret?: core.Supplier; fetcher?: core.FetchFunction; } @@ -23,11 +25,13 @@ export declare namespace Wallet { maxRetries?: number; /** A hook to abort the request. */ abortSignal?: AbortSignal; + /** Override the Authorization header */ + clientSecret?: string | undefined; } } export class Wallet { - constructor(protected readonly _options: Wallet.Options) {} + constructor(protected readonly _options: Wallet.Options = {}) {} /** * Fetch the addresses of a user's Crossmint custodial wallets @@ -66,7 +70,7 @@ export class Wallet { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -147,7 +151,7 @@ export class Wallet { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -233,7 +237,7 @@ export class Wallet { headers: { "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "crossmint", - "X-Fern-SDK-Version": "0.2.1", + "X-Fern-SDK-Version": "0.2.2", "X-Fern-Runtime": core.RUNTIME.type, "X-Fern-Runtime-Version": core.RUNTIME.version, ...(await this._getCustomAuthorizationHeaders()), @@ -283,7 +287,8 @@ export class Wallet { } protected async _getCustomAuthorizationHeaders() { + const clientSecretValue = await core.Supplier.get(this._options.clientSecret); const apiKeyValue = await core.Supplier.get(this._options.apiKey); - return { "X-API-KEY": apiKeyValue }; + return { Authorization: clientSecretValue, "X-API-KEY": apiKeyValue }; } } diff --git a/src/core/fetcher/Fetcher.ts b/src/core/fetcher/Fetcher.ts index ef36c97..d67bc04 100644 --- a/src/core/fetcher/Fetcher.ts +++ b/src/core/fetcher/Fetcher.ts @@ -5,7 +5,6 @@ import { getRequestBody } from "./getRequestBody"; import { getResponseBody } from "./getResponseBody"; import { makeRequest } from "./makeRequest"; import { requestWithRetries } from "./requestWithRetries"; -import { chooseStreamWrapper } from "./stream-wrappers/chooseStreamWrapper"; export type FetchFunction = (args: Fetcher.Args) => Promise>; @@ -22,7 +21,7 @@ export declare namespace Fetcher { withCredentials?: boolean; abortSignal?: AbortSignal; requestType?: "json" | "file" | "bytes"; - responseType?: "json" | "blob" | "streaming" | "text"; + responseType?: "json" | "blob" | "sse" | "streaming" | "text"; duplex?: "half"; } @@ -90,10 +89,6 @@ export async function fetcherImpl(args: Fetcher.Args): Promise= 200 && response.status < 400) { - if (args.duplex && args.responseType === "streaming") { - responseBody = chooseStreamWrapper(responseBody); - } - return { ok: true, body: responseBody as R, diff --git a/src/core/fetcher/getResponseBody.ts b/src/core/fetcher/getResponseBody.ts index 2015356..a7a9c50 100644 --- a/src/core/fetcher/getResponseBody.ts +++ b/src/core/fetcher/getResponseBody.ts @@ -1,8 +1,12 @@ +import { chooseStreamWrapper } from "./stream-wrappers/chooseStreamWrapper"; + export async function getResponseBody(response: Response, responseType?: string): Promise { if (response.body != null && responseType === "blob") { return await response.blob(); - } else if (response.body != null && responseType === "streaming") { + } else if (response.body != null && responseType === "sse") { return response.body; + } else if (response.body != null && responseType === "streaming") { + return chooseStreamWrapper(response.body); } else if (response.body != null && responseType === "text") { return await response.text(); } else { diff --git a/src/core/fetcher/stream-wrappers/Node18UniversalStreamWrapper.ts b/src/core/fetcher/stream-wrappers/Node18UniversalStreamWrapper.ts index e274a32..5cc74b6 100644 --- a/src/core/fetcher/stream-wrappers/Node18UniversalStreamWrapper.ts +++ b/src/core/fetcher/stream-wrappers/Node18UniversalStreamWrapper.ts @@ -1,4 +1,3 @@ -// this should be transpiled away as a type import type { Writable } from "stream"; import { EventCallback, StreamWrapper } from "./chooseStreamWrapper"; @@ -78,6 +77,12 @@ export class Node18UniversalStreamWrapper return dest; } + public pipeTo( + dest: Node18UniversalStreamWrapper | Writable | WritableStream + ): Node18UniversalStreamWrapper | Writable | WritableStream { + return this.pipe(dest); + } + public unpipe(dest: Node18UniversalStreamWrapper | Writable | WritableStream): void { this.off("data", async (chunk) => { if (dest instanceof Node18UniversalStreamWrapper) { diff --git a/src/core/fetcher/stream-wrappers/NodePre18StreamWrapper.ts b/src/core/fetcher/stream-wrappers/NodePre18StreamWrapper.ts index 78aa4e4..d73daba 100644 --- a/src/core/fetcher/stream-wrappers/NodePre18StreamWrapper.ts +++ b/src/core/fetcher/stream-wrappers/NodePre18StreamWrapper.ts @@ -1,4 +1,3 @@ -// this should be transpiled away as a type import type { Readable, Writable } from "stream"; import { EventCallback, StreamWrapper } from "./chooseStreamWrapper"; @@ -23,6 +22,10 @@ export class NodePre18StreamWrapper implements StreamWrapper { return dest; } + public pipeTo(dest: Writable): Writable { + return this.pipe(dest); + } + public unpipe(dest?: Writable): void { if (dest) { this.readableStream.unpipe(dest); diff --git a/src/core/fetcher/stream-wrappers/UndiciStreamWrapper.ts b/src/core/fetcher/stream-wrappers/UndiciStreamWrapper.ts index 083edb4..55c0487 100644 --- a/src/core/fetcher/stream-wrappers/UndiciStreamWrapper.ts +++ b/src/core/fetcher/stream-wrappers/UndiciStreamWrapper.ts @@ -2,17 +2,17 @@ import { StreamWrapper } from "./chooseStreamWrapper"; type EventCallback = (data?: any) => void; -export class UndiciStreamWrapper - implements StreamWrapper, Uint8Array> +export class UndiciStreamWrapper + implements StreamWrapper | WritableStream, ReadFormat> { - private readableStream: ReadableStream; - private reader: ReadableStreamDefaultReader; + private readableStream: ReadableStream; + private reader: ReadableStreamDefaultReader; private events: Record; private paused: boolean; private resumeCallback: ((value?: unknown) => void) | null; private encoding: string | null; - constructor(readableStream: ReadableStream) { + constructor(readableStream: ReadableStream) { this.readableStream = readableStream; this.reader = this.readableStream.getReader(); this.events = { @@ -38,8 +38,8 @@ export class UndiciStreamWrapper } public pipe( - dest: UndiciStreamWrapper | WritableStream - ): UndiciStreamWrapper | WritableStream { + dest: UndiciStreamWrapper | WritableStream + ): UndiciStreamWrapper | WritableStream { this.on("data", (chunk) => { if (dest instanceof UndiciStreamWrapper) { dest._write(chunk); @@ -72,7 +72,13 @@ export class UndiciStreamWrapper return dest; } - public unpipe(dest: UndiciStreamWrapper | WritableStream): void { + public pipeTo( + dest: UndiciStreamWrapper | WritableStream + ): UndiciStreamWrapper | WritableStream { + return this.pipe(dest); + } + + public unpipe(dest: UndiciStreamWrapper | WritableStream): void { this.off("data", (chunk) => { if (dest instanceof UndiciStreamWrapper) { dest._write(chunk); @@ -132,7 +138,7 @@ export class UndiciStreamWrapper return this.paused; } - public async read(): Promise { + public async read(): Promise { if (this.paused) { await new Promise((resolve) => { this.resumeCallback = resolve; @@ -150,7 +156,7 @@ export class UndiciStreamWrapper } public async text(): Promise { - const chunks: Uint8Array[] = []; + const chunks: BlobPart[] = []; while (true) { const { done, value } = await this.reader.read(); @@ -167,7 +173,7 @@ export class UndiciStreamWrapper return JSON.parse(text); } - private _write(chunk: Uint8Array): void { + private _write(chunk: ReadFormat): void { this._emit("data", chunk); } diff --git a/src/core/fetcher/stream-wrappers/chooseStreamWrapper.ts b/src/core/fetcher/stream-wrappers/chooseStreamWrapper.ts index 5a8e3e1..3295582 100644 --- a/src/core/fetcher/stream-wrappers/chooseStreamWrapper.ts +++ b/src/core/fetcher/stream-wrappers/chooseStreamWrapper.ts @@ -1,4 +1,3 @@ -// this should be transpiled away during compilation import type { Readable } from "stream"; import { RUNTIME } from "../../runtime"; @@ -9,6 +8,7 @@ export interface StreamWrapper { on(event: string, callback: EventCallback): void; off(event: string, callback: EventCallback): void; pipe(dest: WritableStream): WritableStream; + pipeTo(dest: WritableStream): WritableStream; unpipe(dest?: WritableStream): void; destroy(error?: Error): void; pause(): void; diff --git a/tests/unit/fetcher/getResponseBody.test.ts b/tests/unit/fetcher/getResponseBody.test.ts index f3563ff..3510779 100644 --- a/tests/unit/fetcher/getResponseBody.test.ts +++ b/tests/unit/fetcher/getResponseBody.test.ts @@ -1,5 +1,6 @@ import { RUNTIME } from "../../../src/core/runtime"; import { getResponseBody } from "../../../src/core/fetcher/getResponseBody"; +import { chooseStreamWrapper } from "../../../src/core/fetcher/stream-wrappers/chooseStreamWrapper"; if (RUNTIME.type === "browser") { require("jest-fetch-mock").enableMocks(); @@ -14,12 +15,22 @@ describe("Test getResponseBody", () => { expect(result.constructor.name).toBe("Blob"); }); + it("should handle sse response type", async () => { + if (RUNTIME.type === "node") { + const mockStream = new ReadableStream(); + const mockResponse = new Response(mockStream); + const result = await getResponseBody(mockResponse, "sse"); + expect(result).toBe(mockStream); + } + }); + it("should handle streaming response type", async () => { if (RUNTIME.type === "node") { const mockStream = new ReadableStream(); const mockResponse = new Response(mockStream); const result = await getResponseBody(mockResponse, "streaming"); - expect(result).toBe(mockStream); + // need to reinstantiate string as a result of locked state in Readable Stream after registration with Response + expect(JSON.stringify(result)).toBe(JSON.stringify(await chooseStreamWrapper(new ReadableStream()))); } }); diff --git a/yarn.lock b/yarn.lock index 939f6b3..167c348 100644 --- a/yarn.lock +++ b/yarn.lock @@ -18,33 +18,33 @@ "@babel/highlight" "^7.24.7" picocolors "^1.0.0" -"@babel/compat-data@^7.24.8": - version "7.25.0" - resolved "https://registry.yarnpkg.com/@babel/compat-data/-/compat-data-7.25.0.tgz#6b226a5da3a686db3c30519750e071dce292ad95" - integrity sha512-P4fwKI2mjEb3ZU5cnMJzvRsRKGBUcs8jvxIoRmr6ufAY9Xk2Bz7JubRTTivkw55c7WQJfTECeqYVa+HZ0FzREg== +"@babel/compat-data@^7.25.2": + version "7.25.2" + resolved "https://registry.yarnpkg.com/@babel/compat-data/-/compat-data-7.25.2.tgz#e41928bd33475305c586f6acbbb7e3ade7a6f7f5" + integrity sha512-bYcppcpKBvX4znYaPEeFau03bp89ShqNMLs+rmdptMw+heSZh9+z84d2YG+K7cYLbWwzdjtDoW/uqZmPjulClQ== "@babel/core@^7.11.6", "@babel/core@^7.12.3", "@babel/core@^7.23.9": - version "7.24.9" - resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.24.9.tgz#dc07c9d307162c97fa9484ea997ade65841c7c82" - integrity sha512-5e3FI4Q3M3Pbr21+5xJwCv6ZT6KmGkI0vw3Tozy5ODAQFTIWe37iT8Cr7Ice2Ntb+M3iSKCEWMB1MBgKrW3whg== + version "7.25.2" + resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.25.2.tgz#ed8eec275118d7613e77a352894cd12ded8eba77" + integrity sha512-BBt3opiCOxUr9euZ5/ro/Xv8/V7yJ5bjYMqG/C1YAo8MIKAnumZalCN+msbci3Pigy4lIQfPUpfMM27HMGaYEA== dependencies: "@ampproject/remapping" "^2.2.0" "@babel/code-frame" "^7.24.7" - "@babel/generator" "^7.24.9" - "@babel/helper-compilation-targets" "^7.24.8" - "@babel/helper-module-transforms" "^7.24.9" - "@babel/helpers" "^7.24.8" - "@babel/parser" "^7.24.8" - "@babel/template" "^7.24.7" - "@babel/traverse" "^7.24.8" - "@babel/types" "^7.24.9" + "@babel/generator" "^7.25.0" + "@babel/helper-compilation-targets" "^7.25.2" + "@babel/helper-module-transforms" "^7.25.2" + "@babel/helpers" "^7.25.0" + "@babel/parser" "^7.25.0" + "@babel/template" "^7.25.0" + "@babel/traverse" "^7.25.2" + "@babel/types" "^7.25.2" convert-source-map "^2.0.0" debug "^4.1.0" gensync "^1.0.0-beta.2" json5 "^2.2.3" semver "^6.3.1" -"@babel/generator@^7.24.9", "@babel/generator@^7.25.0", "@babel/generator@^7.7.2": +"@babel/generator@^7.25.0", "@babel/generator@^7.7.2": version "7.25.0" resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.25.0.tgz#f858ddfa984350bc3d3b7f125073c9af6988f18e" integrity sha512-3LEEcj3PVW8pW2R1SR1M89g/qrYk/m/mB/tLqn7dn4sbBUQyTqnlod+II2U4dqiGtUmkcnAmkMDralTFZttRiw== @@ -54,12 +54,12 @@ "@jridgewell/trace-mapping" "^0.3.25" jsesc "^2.5.1" -"@babel/helper-compilation-targets@^7.24.8": - version "7.24.8" - resolved "https://registry.yarnpkg.com/@babel/helper-compilation-targets/-/helper-compilation-targets-7.24.8.tgz#b607c3161cd9d1744977d4f97139572fe778c271" - integrity sha512-oU+UoqCHdp+nWVDkpldqIQL/i/bvAv53tRqLG/s+cOXxe66zOYLU7ar/Xs3LdmBihrUMEUhwu6dMZwbNOYDwvw== +"@babel/helper-compilation-targets@^7.25.2": + version "7.25.2" + resolved "https://registry.yarnpkg.com/@babel/helper-compilation-targets/-/helper-compilation-targets-7.25.2.tgz#e1d9410a90974a3a5a66e84ff55ef62e3c02d06c" + integrity sha512-U2U5LsSaZ7TAt3cfaymQ8WHh0pxvdHoEk6HVpaexxixjyEquMh0L0YNJNM6CTGKMXV1iksi0iZkGw4AcFkPaaw== dependencies: - "@babel/compat-data" "^7.24.8" + "@babel/compat-data" "^7.25.2" "@babel/helper-validator-option" "^7.24.8" browserslist "^4.23.1" lru-cache "^5.1.1" @@ -73,15 +73,15 @@ "@babel/traverse" "^7.24.7" "@babel/types" "^7.24.7" -"@babel/helper-module-transforms@^7.24.9": - version "7.25.0" - resolved "https://registry.yarnpkg.com/@babel/helper-module-transforms/-/helper-module-transforms-7.25.0.tgz#3ffc23c473a2769a7e40d3274495bd559fdd2ecc" - integrity sha512-bIkOa2ZJYn7FHnepzr5iX9Kmz8FjIz4UKzJ9zhX3dnYuVW0xul9RuR3skBfoLu+FPTQw90EHW9rJsSZhyLQ3fQ== +"@babel/helper-module-transforms@^7.25.2": + version "7.25.2" + resolved "https://registry.yarnpkg.com/@babel/helper-module-transforms/-/helper-module-transforms-7.25.2.tgz#ee713c29768100f2776edf04d4eb23b8d27a66e6" + integrity sha512-BjyRAbix6j/wv83ftcVJmBt72QtHI56C7JXZoG2xATiLpmoC7dpd8WnkikExHDVPpi/3qCmO6WY1EaXOluiecQ== dependencies: "@babel/helper-module-imports" "^7.24.7" "@babel/helper-simple-access" "^7.24.7" "@babel/helper-validator-identifier" "^7.24.7" - "@babel/traverse" "^7.25.0" + "@babel/traverse" "^7.25.2" "@babel/helper-plugin-utils@^7.0.0", "@babel/helper-plugin-utils@^7.10.4", "@babel/helper-plugin-utils@^7.12.13", "@babel/helper-plugin-utils@^7.14.5", "@babel/helper-plugin-utils@^7.24.7", "@babel/helper-plugin-utils@^7.8.0": version "7.24.8" @@ -111,7 +111,7 @@ resolved "https://registry.yarnpkg.com/@babel/helper-validator-option/-/helper-validator-option-7.24.8.tgz#3725cdeea8b480e86d34df15304806a06975e33d" integrity sha512-xb8t9tD1MHLungh/AIoWYN+gVHaB9kwlu8gffXGSt3FFEIT7RjS+xWbc2vUD1UTZdIpKj/ab3rdqJ7ufngyi2Q== -"@babel/helpers@^7.24.8": +"@babel/helpers@^7.25.0": version "7.25.0" resolved "https://registry.yarnpkg.com/@babel/helpers/-/helpers-7.25.0.tgz#e69beb7841cb93a6505531ede34f34e6a073650a" integrity sha512-MjgLZ42aCm0oGjJj8CtSM3DB8NOOf8h2l7DCTePJs29u+v7yO/RBX9nShlKMgFnRks/Q4tBAe7Hxnov9VkGwLw== @@ -129,10 +129,12 @@ js-tokens "^4.0.0" picocolors "^1.0.0" -"@babel/parser@^7.1.0", "@babel/parser@^7.14.7", "@babel/parser@^7.20.7", "@babel/parser@^7.23.9", "@babel/parser@^7.24.8", "@babel/parser@^7.25.0": - version "7.25.0" - resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.25.0.tgz#9fdc9237504d797b6e7b8f66e78ea7f570d256ad" - integrity sha512-CzdIU9jdP0dg7HdyB+bHvDJGagUv+qtzZt5rYCWwW6tITNqV9odjp6Qu41gkG0ca5UfdDUWrKkiAnHHdGRnOrA== +"@babel/parser@^7.1.0", "@babel/parser@^7.14.7", "@babel/parser@^7.20.7", "@babel/parser@^7.23.9", "@babel/parser@^7.25.0", "@babel/parser@^7.25.3": + version "7.25.3" + resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.25.3.tgz#91fb126768d944966263f0657ab222a642b82065" + integrity sha512-iLTJKDbJ4hMvFPgQwwsVoxtHyWpKKPBrxkANrSYewDPaPpT5py5yeVkgPIJ7XYXhndxJpaA3PyALSXQ7u8e/Dw== + dependencies: + "@babel/types" "^7.25.2" "@babel/plugin-syntax-async-generators@^7.8.4": version "7.8.4" @@ -232,7 +234,7 @@ dependencies: "@babel/helper-plugin-utils" "^7.24.7" -"@babel/template@^7.24.7", "@babel/template@^7.25.0", "@babel/template@^7.3.3": +"@babel/template@^7.25.0", "@babel/template@^7.3.3": version "7.25.0" resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.25.0.tgz#e733dc3134b4fede528c15bc95e89cb98c52592a" integrity sha512-aOOgh1/5XzKvg1jvVz7AVrx2piJ2XBi227DHmbY6y+bM9H2FlN+IfecYu4Xl0cNiiVejlsCri89LUsbj8vJD9Q== @@ -241,23 +243,23 @@ "@babel/parser" "^7.25.0" "@babel/types" "^7.25.0" -"@babel/traverse@^7.24.7", "@babel/traverse@^7.24.8", "@babel/traverse@^7.25.0": - version "7.25.1" - resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.25.1.tgz#64dbc31effc5f3fa3cf10d19df0e6310214743f5" - integrity sha512-LrHHoWq08ZpmmFqBAzN+hUdWwy5zt7FGa/hVwMcOqW6OVtwqaoD5utfuGYU87JYxdZgLUvktAsn37j/sYR9siA== +"@babel/traverse@^7.24.7", "@babel/traverse@^7.25.2": + version "7.25.3" + resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.25.3.tgz#f1b901951c83eda2f3e29450ce92743783373490" + integrity sha512-HefgyP1x754oGCsKmV5reSmtV7IXj/kpaE1XYY+D9G5PvKKoFfSbiS4M77MdjuwlZKDIKFCffq9rPU+H/s3ZdQ== dependencies: "@babel/code-frame" "^7.24.7" "@babel/generator" "^7.25.0" - "@babel/parser" "^7.25.0" + "@babel/parser" "^7.25.3" "@babel/template" "^7.25.0" - "@babel/types" "^7.25.0" + "@babel/types" "^7.25.2" debug "^4.3.1" globals "^11.1.0" -"@babel/types@^7.0.0", "@babel/types@^7.20.7", "@babel/types@^7.24.7", "@babel/types@^7.24.9", "@babel/types@^7.25.0", "@babel/types@^7.3.3": - version "7.25.0" - resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.25.0.tgz#e6e3656c581f28da8452ed4f69e38008ec0ba41b" - integrity sha512-LcnxQSsd9aXOIgmmSpvZ/1yo46ra2ESYyqLcryaBZOghxy5qqOBjvCWP5JfkI8yl9rlxRgdLTTMCQQRcN2hdCg== +"@babel/types@^7.0.0", "@babel/types@^7.20.7", "@babel/types@^7.24.7", "@babel/types@^7.25.0", "@babel/types@^7.25.2", "@babel/types@^7.3.3": + version "7.25.2" + resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.25.2.tgz#55fb231f7dc958cd69ea141a4c2997e819646125" + integrity sha512-YTnYtra7W9e6/oAZEHj0bJehPRUlLH9/fbpT5LfB0NhQXyALCRkRs3zH9v07IYhkgpqX6Z78FnuccZr/l4Fs4Q== dependencies: "@babel/helper-string-parser" "^7.24.8" "@babel/helper-validator-identifier" "^7.24.7" @@ -617,9 +619,9 @@ form-data "^4.0.0" "@types/node@*": - version "22.0.0" - resolved "https://registry.yarnpkg.com/@types/node/-/node-22.0.0.tgz#04862a2a71e62264426083abe1e27e87cac05a30" - integrity sha512-VT7KSYudcPOzP5Q0wfbowyNLaVR8QWUdw+088uFWwfvpY6uCWaXpqV6ieLAu9WBcnTa7H4Z5RLK8I5t2FuOcqw== + version "22.0.2" + resolved "https://registry.yarnpkg.com/@types/node/-/node-22.0.2.tgz#9fb1a2b31970871e8bf696f0e8a40d2e6d2bd04e" + integrity sha512-yPL6DyFwY5PiMVEwymNeqUTKsDczQBJ/5T7W/46RwLU/VH+AA8aT5TZkvBviLKLbbm0hlfftEkGrNzfRk/fofQ== dependencies: undici-types "~6.11.1" @@ -879,9 +881,9 @@ camelcase@^6.2.0: integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA== caniuse-lite@^1.0.30001640: - version "1.0.30001643" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001643.tgz#9c004caef315de9452ab970c3da71085f8241dbd" - integrity sha512-ERgWGNleEilSrHM6iUz/zJNSQTP8Mr21wDWpdgvRwcTXGAq6jMtOUPP4dqFPTdKqZ2wKTdtB+uucZ3MRpAUSmg== + version "1.0.30001646" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001646.tgz#d472f2882259ba032dd73ee069ff01bfd059b25d" + integrity sha512-dRg00gudiBDDTmUhClSdv3hqRfpbOnU28IpI1T6PBTLWa+kOj0681C8uML3PifYfREuBrVjDGhL3adYpBT6spw== chalk@^2.4.2: version "2.4.2" @@ -1077,9 +1079,9 @@ domexception@^4.0.0: webidl-conversions "^7.0.0" electron-to-chromium@^1.4.820: - version "1.5.2" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.5.2.tgz#6126ad229ce45e781ec54ca40db0504787f23d19" - integrity sha512-kc4r3U3V3WLaaZqThjYz/Y6z8tJe+7K0bbjUVo3i+LWIypVdMx5nXCkwRe6SWbY6ILqLdc1rKcKmr3HoH7wjSQ== + version "1.5.4" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.5.4.tgz#cd477c830dd6fca41fbd5465c1ff6ce08ac22343" + integrity sha512-orzA81VqLyIGUEA77YkVA1D+N+nNfl2isJVjjmOyrlxuooZ19ynb+dOlaDTqd/idKRS9lDCSBmtzM+kyCsMnkA== emittery@^0.13.1: version "0.13.1"