From b29da77dd3f036d465ea685a5e5cf3295b996c75 Mon Sep 17 00:00:00 2001 From: fern-api <115122769+fern-api[bot]@users.noreply.github.com> Date: Wed, 12 Jul 2023 22:09:59 +0000 Subject: [PATCH] Release v0.0.33 --- package.json | 5 +-- src/Client.ts | 2 +- src/api/resources/agent/client/Client.ts | 35 ++++++++++++------- .../resources/agentDocuments/client/Client.ts | 27 +++++++++----- src/api/resources/agentTools/client/Client.ts | 27 +++++++++----- src/api/resources/apiToken/client/Client.ts | 27 +++++++++----- src/api/resources/auth/client/Client.ts | 19 +++++++--- src/api/resources/documents/client/Client.ts | 27 +++++++++----- src/api/resources/prompts/client/Client.ts | 31 ++++++++++------ src/api/resources/tools/client/Client.ts | 27 +++++++++----- src/api/resources/traces/client/Client.ts | 15 ++++++-- src/api/resources/user/client/Client.ts | 19 +++++++--- src/core/auth/BasicAuth.ts | 31 ++++++++++++++++ src/core/auth/BearerToken.ts | 15 ++++++++ src/core/auth/index.ts | 2 ++ src/core/index.ts | 1 + yarn.lock | 5 +++ 17 files changed, 230 insertions(+), 85 deletions(-) create mode 100644 src/core/auth/BasicAuth.ts create mode 100644 src/core/auth/BearerToken.ts create mode 100644 src/core/auth/index.ts diff --git a/package.json b/package.json index 2ac40c4..a0840b1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "superagentai-js", - "version": "v0.0.32", + "version": "v0.0.33", "private": false, "repository": "https://github.com/homanp/superagent-js", "main": "./index.js", @@ -14,7 +14,8 @@ "url-join": "4.0.1", "@types/url-join": "4.0.1", "@ungap/url-search-params": "0.2.2", - "axios": "1.4.0" + "axios": "1.4.0", + "js-base64": "3.7.2" }, "devDependencies": { "@types/node": "17.0.33", diff --git a/src/Client.ts b/src/Client.ts index daad277..80639db 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -17,7 +17,7 @@ import { Traces } from "./api/resources/traces/client/Client"; export declare namespace SuperAgentClient { interface Options { environment: core.Supplier; - apiKey?: core.Supplier; + token?: core.Supplier; } } diff --git a/src/api/resources/agent/client/Client.ts b/src/api/resources/agent/client/Client.ts index 01629ae..01a7afd 100644 --- a/src/api/resources/agent/client/Client.ts +++ b/src/api/resources/agent/client/Client.ts @@ -11,7 +11,7 @@ import * as serializers from "../../../../serialization"; export declare namespace Agent { interface Options { environment: core.Supplier; - apiKey?: core.Supplier; + token?: core.Supplier; } } @@ -26,10 +26,10 @@ export class Agent { url: urlJoin(await core.Supplier.get(this._options.environment), "api/v1/agents"), method: "GET", headers: { - X_SUPERAGENT_API_KEY: await core.Supplier.get(this._options.apiKey), + Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "superagentai-js", - "X-Fern-SDK-Version": "v0.0.32", + "X-Fern-SDK-Version": "v0.0.33", }, contentType: "application/json", timeoutMs: 60000, @@ -69,10 +69,10 @@ export class Agent { url: urlJoin(await core.Supplier.get(this._options.environment), "api/v1/agents"), method: "POST", headers: { - X_SUPERAGENT_API_KEY: await core.Supplier.get(this._options.apiKey), + Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "superagentai-js", - "X-Fern-SDK-Version": "v0.0.32", + "X-Fern-SDK-Version": "v0.0.33", }, contentType: "application/json", body: await serializers.Agent.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), @@ -125,10 +125,10 @@ export class Agent { url: urlJoin(await core.Supplier.get(this._options.environment), `api/v1/agents/${agentId}`), method: "GET", headers: { - X_SUPERAGENT_API_KEY: await core.Supplier.get(this._options.apiKey), + Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "superagentai-js", - "X-Fern-SDK-Version": "v0.0.32", + "X-Fern-SDK-Version": "v0.0.33", }, contentType: "application/json", timeoutMs: 60000, @@ -180,10 +180,10 @@ export class Agent { url: urlJoin(await core.Supplier.get(this._options.environment), `api/v1/agents/${agentId}`), method: "PATCH", headers: { - X_SUPERAGENT_API_KEY: await core.Supplier.get(this._options.apiKey), + Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "superagentai-js", - "X-Fern-SDK-Version": "v0.0.32", + "X-Fern-SDK-Version": "v0.0.33", }, contentType: "application/json", body: await serializers.agent.patchAgent.Request.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), @@ -236,10 +236,10 @@ export class Agent { url: urlJoin(await core.Supplier.get(this._options.environment), `api/v1/agents/${agentId}`), method: "DELETE", headers: { - X_SUPERAGENT_API_KEY: await core.Supplier.get(this._options.apiKey), + Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "superagentai-js", - "X-Fern-SDK-Version": "v0.0.32", + "X-Fern-SDK-Version": "v0.0.33", }, contentType: "application/json", timeoutMs: 60000, @@ -291,10 +291,10 @@ export class Agent { url: urlJoin(await core.Supplier.get(this._options.environment), `api/v1/agents/${agentId}/predict`), method: "POST", headers: { - X_SUPERAGENT_API_KEY: await core.Supplier.get(this._options.apiKey), + Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "superagentai-js", - "X-Fern-SDK-Version": "v0.0.32", + "X-Fern-SDK-Version": "v0.0.33", }, contentType: "application/json", body: await serializers.PredictAgent.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), @@ -337,4 +337,13 @@ export class Agent { }); } } + + protected async _getAuthorizationHeader() { + const bearer = await core.Supplier.get(this._options.token); + if (bearer != null) { + return `Bearer ${bearer}`; + } + + return undefined; + } } diff --git a/src/api/resources/agentDocuments/client/Client.ts b/src/api/resources/agentDocuments/client/Client.ts index aba827d..d29edd0 100644 --- a/src/api/resources/agentDocuments/client/Client.ts +++ b/src/api/resources/agentDocuments/client/Client.ts @@ -12,7 +12,7 @@ import * as serializers from "../../../../serialization"; export declare namespace AgentDocuments { interface Options { environment: core.Supplier; - apiKey?: core.Supplier; + token?: core.Supplier; } } @@ -36,10 +36,10 @@ export class AgentDocuments { url: urlJoin(await core.Supplier.get(this._options.environment), "api/v1/agent-documents"), method: "GET", headers: { - X_SUPERAGENT_API_KEY: await core.Supplier.get(this._options.apiKey), + Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "superagentai-js", - "X-Fern-SDK-Version": "v0.0.32", + "X-Fern-SDK-Version": "v0.0.33", }, contentType: "application/json", queryParameters: _queryParams, @@ -92,10 +92,10 @@ export class AgentDocuments { url: urlJoin(await core.Supplier.get(this._options.environment), "api/v1/agent-documents"), method: "POST", headers: { - X_SUPERAGENT_API_KEY: await core.Supplier.get(this._options.apiKey), + Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "superagentai-js", - "X-Fern-SDK-Version": "v0.0.32", + "X-Fern-SDK-Version": "v0.0.33", }, contentType: "application/json", body: await serializers.AgentDocument.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), @@ -151,10 +151,10 @@ export class AgentDocuments { ), method: "GET", headers: { - X_SUPERAGENT_API_KEY: await core.Supplier.get(this._options.apiKey), + Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "superagentai-js", - "X-Fern-SDK-Version": "v0.0.32", + "X-Fern-SDK-Version": "v0.0.33", }, contentType: "application/json", timeoutMs: 60000, @@ -209,10 +209,10 @@ export class AgentDocuments { ), method: "DELETE", headers: { - X_SUPERAGENT_API_KEY: await core.Supplier.get(this._options.apiKey), + Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "superagentai-js", - "X-Fern-SDK-Version": "v0.0.32", + "X-Fern-SDK-Version": "v0.0.33", }, contentType: "application/json", timeoutMs: 60000, @@ -254,4 +254,13 @@ export class AgentDocuments { }); } } + + protected async _getAuthorizationHeader() { + const bearer = await core.Supplier.get(this._options.token); + if (bearer != null) { + return `Bearer ${bearer}`; + } + + return undefined; + } } diff --git a/src/api/resources/agentTools/client/Client.ts b/src/api/resources/agentTools/client/Client.ts index f7f4fe3..4aef787 100644 --- a/src/api/resources/agentTools/client/Client.ts +++ b/src/api/resources/agentTools/client/Client.ts @@ -12,7 +12,7 @@ import * as serializers from "../../../../serialization"; export declare namespace AgentTools { interface Options { environment: core.Supplier; - apiKey?: core.Supplier; + token?: core.Supplier; } } @@ -34,10 +34,10 @@ export class AgentTools { url: urlJoin(await core.Supplier.get(this._options.environment), "api/v1/agent-tools"), method: "GET", headers: { - X_SUPERAGENT_API_KEY: await core.Supplier.get(this._options.apiKey), + Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "superagentai-js", - "X-Fern-SDK-Version": "v0.0.32", + "X-Fern-SDK-Version": "v0.0.33", }, contentType: "application/json", queryParameters: _queryParams, @@ -90,10 +90,10 @@ export class AgentTools { url: urlJoin(await core.Supplier.get(this._options.environment), "api/v1/agent-tools"), method: "POST", headers: { - X_SUPERAGENT_API_KEY: await core.Supplier.get(this._options.apiKey), + Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "superagentai-js", - "X-Fern-SDK-Version": "v0.0.32", + "X-Fern-SDK-Version": "v0.0.33", }, contentType: "application/json", body: await serializers.AgentTool.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), @@ -146,10 +146,10 @@ export class AgentTools { url: urlJoin(await core.Supplier.get(this._options.environment), `api/v1/agent-tools/${agentToolId}`), method: "GET", headers: { - X_SUPERAGENT_API_KEY: await core.Supplier.get(this._options.apiKey), + Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "superagentai-js", - "X-Fern-SDK-Version": "v0.0.32", + "X-Fern-SDK-Version": "v0.0.33", }, contentType: "application/json", timeoutMs: 60000, @@ -201,10 +201,10 @@ export class AgentTools { url: urlJoin(await core.Supplier.get(this._options.environment), `api/v1/agent-tools/${agentToolId}`), method: "DELETE", headers: { - X_SUPERAGENT_API_KEY: await core.Supplier.get(this._options.apiKey), + Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "superagentai-js", - "X-Fern-SDK-Version": "v0.0.32", + "X-Fern-SDK-Version": "v0.0.33", }, contentType: "application/json", timeoutMs: 60000, @@ -246,4 +246,13 @@ export class AgentTools { }); } } + + protected async _getAuthorizationHeader() { + const bearer = await core.Supplier.get(this._options.token); + if (bearer != null) { + return `Bearer ${bearer}`; + } + + return undefined; + } } diff --git a/src/api/resources/apiToken/client/Client.ts b/src/api/resources/apiToken/client/Client.ts index cdd2fbb..72c87a3 100644 --- a/src/api/resources/apiToken/client/Client.ts +++ b/src/api/resources/apiToken/client/Client.ts @@ -11,7 +11,7 @@ import * as serializers from "../../../../serialization"; export declare namespace ApiToken { interface Options { environment: core.Supplier; - apiKey?: core.Supplier; + token?: core.Supplier; } } @@ -26,10 +26,10 @@ export class ApiToken { url: urlJoin(await core.Supplier.get(this._options.environment), "api/v1/api-tokens"), method: "GET", headers: { - X_SUPERAGENT_API_KEY: await core.Supplier.get(this._options.apiKey), + Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "superagentai-js", - "X-Fern-SDK-Version": "v0.0.32", + "X-Fern-SDK-Version": "v0.0.33", }, contentType: "application/json", timeoutMs: 60000, @@ -69,10 +69,10 @@ export class ApiToken { url: urlJoin(await core.Supplier.get(this._options.environment), "api/v1/api-tokens"), method: "POST", headers: { - X_SUPERAGENT_API_KEY: await core.Supplier.get(this._options.apiKey), + Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "superagentai-js", - "X-Fern-SDK-Version": "v0.0.32", + "X-Fern-SDK-Version": "v0.0.33", }, contentType: "application/json", body: await serializers.ApiToken.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), @@ -125,10 +125,10 @@ export class ApiToken { url: urlJoin(await core.Supplier.get(this._options.environment), `api/v1/api-tokens/${tokenId}`), method: "GET", headers: { - X_SUPERAGENT_API_KEY: await core.Supplier.get(this._options.apiKey), + Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "superagentai-js", - "X-Fern-SDK-Version": "v0.0.32", + "X-Fern-SDK-Version": "v0.0.33", }, contentType: "application/json", timeoutMs: 60000, @@ -180,10 +180,10 @@ export class ApiToken { url: urlJoin(await core.Supplier.get(this._options.environment), `api/v1/api-tokens/${tokenId}`), method: "DELETE", headers: { - X_SUPERAGENT_API_KEY: await core.Supplier.get(this._options.apiKey), + Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "superagentai-js", - "X-Fern-SDK-Version": "v0.0.32", + "X-Fern-SDK-Version": "v0.0.33", }, contentType: "application/json", timeoutMs: 60000, @@ -225,4 +225,13 @@ export class ApiToken { }); } } + + protected async _getAuthorizationHeader() { + const bearer = await core.Supplier.get(this._options.token); + if (bearer != null) { + return `Bearer ${bearer}`; + } + + return undefined; + } } diff --git a/src/api/resources/auth/client/Client.ts b/src/api/resources/auth/client/Client.ts index 3c7e9a9..447ac27 100644 --- a/src/api/resources/auth/client/Client.ts +++ b/src/api/resources/auth/client/Client.ts @@ -11,7 +11,7 @@ import * as errors from "../../../../errors"; export declare namespace Auth { interface Options { environment: core.Supplier; - apiKey?: core.Supplier; + token?: core.Supplier; } } @@ -26,10 +26,10 @@ export class Auth { url: urlJoin(await core.Supplier.get(this._options.environment), "api/v1/auth/sign-in"), method: "POST", headers: { - X_SUPERAGENT_API_KEY: await core.Supplier.get(this._options.apiKey), + Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "superagentai-js", - "X-Fern-SDK-Version": "v0.0.32", + "X-Fern-SDK-Version": "v0.0.33", }, contentType: "application/json", body: await serializers.SignIn.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), @@ -81,10 +81,10 @@ export class Auth { url: urlJoin(await core.Supplier.get(this._options.environment), "api/v1/auth/sign-up"), method: "POST", headers: { - X_SUPERAGENT_API_KEY: await core.Supplier.get(this._options.apiKey), + Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "superagentai-js", - "X-Fern-SDK-Version": "v0.0.32", + "X-Fern-SDK-Version": "v0.0.33", }, contentType: "application/json", body: await serializers.SignUp.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), @@ -127,4 +127,13 @@ export class Auth { }); } } + + protected async _getAuthorizationHeader() { + const bearer = await core.Supplier.get(this._options.token); + if (bearer != null) { + return `Bearer ${bearer}`; + } + + return undefined; + } } diff --git a/src/api/resources/documents/client/Client.ts b/src/api/resources/documents/client/Client.ts index 2bdc652..040b394 100644 --- a/src/api/resources/documents/client/Client.ts +++ b/src/api/resources/documents/client/Client.ts @@ -11,7 +11,7 @@ import * as serializers from "../../../../serialization"; export declare namespace Documents { interface Options { environment: core.Supplier; - apiKey?: core.Supplier; + token?: core.Supplier; } } @@ -26,10 +26,10 @@ export class Documents { url: urlJoin(await core.Supplier.get(this._options.environment), "api/v1/documents"), method: "GET", headers: { - X_SUPERAGENT_API_KEY: await core.Supplier.get(this._options.apiKey), + Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "superagentai-js", - "X-Fern-SDK-Version": "v0.0.32", + "X-Fern-SDK-Version": "v0.0.33", }, contentType: "application/json", timeoutMs: 60000, @@ -69,10 +69,10 @@ export class Documents { url: urlJoin(await core.Supplier.get(this._options.environment), "api/v1/documents"), method: "POST", headers: { - X_SUPERAGENT_API_KEY: await core.Supplier.get(this._options.apiKey), + Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "superagentai-js", - "X-Fern-SDK-Version": "v0.0.32", + "X-Fern-SDK-Version": "v0.0.33", }, contentType: "application/json", body: await serializers.Document.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), @@ -125,10 +125,10 @@ export class Documents { url: urlJoin(await core.Supplier.get(this._options.environment), `api/v1/documents/${documentId}`), method: "GET", headers: { - X_SUPERAGENT_API_KEY: await core.Supplier.get(this._options.apiKey), + Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "superagentai-js", - "X-Fern-SDK-Version": "v0.0.32", + "X-Fern-SDK-Version": "v0.0.33", }, contentType: "application/json", timeoutMs: 60000, @@ -180,10 +180,10 @@ export class Documents { url: urlJoin(await core.Supplier.get(this._options.environment), `api/v1/documents/${documentId}`), method: "DELETE", headers: { - X_SUPERAGENT_API_KEY: await core.Supplier.get(this._options.apiKey), + Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "superagentai-js", - "X-Fern-SDK-Version": "v0.0.32", + "X-Fern-SDK-Version": "v0.0.33", }, contentType: "application/json", timeoutMs: 60000, @@ -225,4 +225,13 @@ export class Documents { }); } } + + protected async _getAuthorizationHeader() { + const bearer = await core.Supplier.get(this._options.token); + if (bearer != null) { + return `Bearer ${bearer}`; + } + + return undefined; + } } diff --git a/src/api/resources/prompts/client/Client.ts b/src/api/resources/prompts/client/Client.ts index 32f20b2..1461720 100644 --- a/src/api/resources/prompts/client/Client.ts +++ b/src/api/resources/prompts/client/Client.ts @@ -11,7 +11,7 @@ import * as serializers from "../../../../serialization"; export declare namespace Prompts { interface Options { environment: core.Supplier; - apiKey?: core.Supplier; + token?: core.Supplier; } } @@ -26,10 +26,10 @@ export class Prompts { url: urlJoin(await core.Supplier.get(this._options.environment), "api/v1/prompts"), method: "GET", headers: { - X_SUPERAGENT_API_KEY: await core.Supplier.get(this._options.apiKey), + Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "superagentai-js", - "X-Fern-SDK-Version": "v0.0.32", + "X-Fern-SDK-Version": "v0.0.33", }, contentType: "application/json", timeoutMs: 60000, @@ -69,10 +69,10 @@ export class Prompts { url: urlJoin(await core.Supplier.get(this._options.environment), "api/v1/prompts"), method: "POST", headers: { - X_SUPERAGENT_API_KEY: await core.Supplier.get(this._options.apiKey), + Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "superagentai-js", - "X-Fern-SDK-Version": "v0.0.32", + "X-Fern-SDK-Version": "v0.0.33", }, contentType: "application/json", body: await serializers.Prompt.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), @@ -125,10 +125,10 @@ export class Prompts { url: urlJoin(await core.Supplier.get(this._options.environment), `api/v1/prompts/${promptId}`), method: "GET", headers: { - X_SUPERAGENT_API_KEY: await core.Supplier.get(this._options.apiKey), + Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "superagentai-js", - "X-Fern-SDK-Version": "v0.0.32", + "X-Fern-SDK-Version": "v0.0.33", }, contentType: "application/json", timeoutMs: 60000, @@ -180,10 +180,10 @@ export class Prompts { url: urlJoin(await core.Supplier.get(this._options.environment), `api/v1/prompts/${promptId}`), method: "PATCH", headers: { - X_SUPERAGENT_API_KEY: await core.Supplier.get(this._options.apiKey), + Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "superagentai-js", - "X-Fern-SDK-Version": "v0.0.32", + "X-Fern-SDK-Version": "v0.0.33", }, contentType: "application/json", body: await serializers.prompts.patchPrompt.Request.jsonOrThrow(request, { @@ -238,10 +238,10 @@ export class Prompts { url: urlJoin(await core.Supplier.get(this._options.environment), `api/v1/prompts/${promptId}`), method: "DELETE", headers: { - X_SUPERAGENT_API_KEY: await core.Supplier.get(this._options.apiKey), + Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "superagentai-js", - "X-Fern-SDK-Version": "v0.0.32", + "X-Fern-SDK-Version": "v0.0.33", }, contentType: "application/json", timeoutMs: 60000, @@ -283,4 +283,13 @@ export class Prompts { }); } } + + protected async _getAuthorizationHeader() { + const bearer = await core.Supplier.get(this._options.token); + if (bearer != null) { + return `Bearer ${bearer}`; + } + + return undefined; + } } diff --git a/src/api/resources/tools/client/Client.ts b/src/api/resources/tools/client/Client.ts index a60e53d..bf1d6aa 100644 --- a/src/api/resources/tools/client/Client.ts +++ b/src/api/resources/tools/client/Client.ts @@ -11,7 +11,7 @@ import * as serializers from "../../../../serialization"; export declare namespace Tools { interface Options { environment: core.Supplier; - apiKey?: core.Supplier; + token?: core.Supplier; } } @@ -26,10 +26,10 @@ export class Tools { url: urlJoin(await core.Supplier.get(this._options.environment), "api/v1/tools"), method: "GET", headers: { - X_SUPERAGENT_API_KEY: await core.Supplier.get(this._options.apiKey), + Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "superagentai-js", - "X-Fern-SDK-Version": "v0.0.32", + "X-Fern-SDK-Version": "v0.0.33", }, contentType: "application/json", timeoutMs: 60000, @@ -69,10 +69,10 @@ export class Tools { url: urlJoin(await core.Supplier.get(this._options.environment), "api/v1/tools"), method: "POST", headers: { - X_SUPERAGENT_API_KEY: await core.Supplier.get(this._options.apiKey), + Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "superagentai-js", - "X-Fern-SDK-Version": "v0.0.32", + "X-Fern-SDK-Version": "v0.0.33", }, contentType: "application/json", body: await serializers.Tool.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), @@ -125,10 +125,10 @@ export class Tools { url: urlJoin(await core.Supplier.get(this._options.environment), `api/v1/tools/${toolId}`), method: "GET", headers: { - X_SUPERAGENT_API_KEY: await core.Supplier.get(this._options.apiKey), + Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "superagentai-js", - "X-Fern-SDK-Version": "v0.0.32", + "X-Fern-SDK-Version": "v0.0.33", }, contentType: "application/json", timeoutMs: 60000, @@ -180,10 +180,10 @@ export class Tools { url: urlJoin(await core.Supplier.get(this._options.environment), `api/v1/tools/${toolId}`), method: "DELETE", headers: { - X_SUPERAGENT_API_KEY: await core.Supplier.get(this._options.apiKey), + Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "superagentai-js", - "X-Fern-SDK-Version": "v0.0.32", + "X-Fern-SDK-Version": "v0.0.33", }, contentType: "application/json", timeoutMs: 60000, @@ -225,4 +225,13 @@ export class Tools { }); } } + + protected async _getAuthorizationHeader() { + const bearer = await core.Supplier.get(this._options.token); + if (bearer != null) { + return `Bearer ${bearer}`; + } + + return undefined; + } } diff --git a/src/api/resources/traces/client/Client.ts b/src/api/resources/traces/client/Client.ts index e83e0d0..61d29b3 100644 --- a/src/api/resources/traces/client/Client.ts +++ b/src/api/resources/traces/client/Client.ts @@ -9,7 +9,7 @@ import * as errors from "../../../../errors"; export declare namespace Traces { interface Options { environment: core.Supplier; - apiKey?: core.Supplier; + token?: core.Supplier; } } @@ -24,10 +24,10 @@ export class Traces { url: urlJoin(await core.Supplier.get(this._options.environment), "api/v1/traces"), method: "GET", headers: { - X_SUPERAGENT_API_KEY: await core.Supplier.get(this._options.apiKey), + Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "superagentai-js", - "X-Fern-SDK-Version": "v0.0.32", + "X-Fern-SDK-Version": "v0.0.33", }, contentType: "application/json", timeoutMs: 60000, @@ -57,4 +57,13 @@ export class Traces { }); } } + + protected async _getAuthorizationHeader() { + const bearer = await core.Supplier.get(this._options.token); + if (bearer != null) { + return `Bearer ${bearer}`; + } + + return undefined; + } } diff --git a/src/api/resources/user/client/Client.ts b/src/api/resources/user/client/Client.ts index c84c28a..d8e0dba 100644 --- a/src/api/resources/user/client/Client.ts +++ b/src/api/resources/user/client/Client.ts @@ -11,7 +11,7 @@ import * as serializers from "../../../../serialization"; export declare namespace User { interface Options { environment: core.Supplier; - apiKey?: core.Supplier; + token?: core.Supplier; } } @@ -23,10 +23,10 @@ export class User { url: urlJoin(await core.Supplier.get(this._options.environment), "api/v1/users/me"), method: "GET", headers: { - X_SUPERAGENT_API_KEY: await core.Supplier.get(this._options.apiKey), + Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "superagentai-js", - "X-Fern-SDK-Version": "v0.0.32", + "X-Fern-SDK-Version": "v0.0.33", }, contentType: "application/json", timeoutMs: 60000, @@ -65,10 +65,10 @@ export class User { url: urlJoin(await core.Supplier.get(this._options.environment), `api/v1/users/${userId}`), method: "GET", headers: { - X_SUPERAGENT_API_KEY: await core.Supplier.get(this._options.apiKey), + Authorization: await this._getAuthorizationHeader(), "X-Fern-Language": "JavaScript", "X-Fern-SDK-Name": "superagentai-js", - "X-Fern-SDK-Version": "v0.0.32", + "X-Fern-SDK-Version": "v0.0.33", }, contentType: "application/json", timeoutMs: 60000, @@ -110,4 +110,13 @@ export class User { }); } } + + protected async _getAuthorizationHeader() { + const bearer = await core.Supplier.get(this._options.token); + if (bearer != null) { + return `Bearer ${bearer}`; + } + + return undefined; + } } diff --git a/src/core/auth/BasicAuth.ts b/src/core/auth/BasicAuth.ts new file mode 100644 index 0000000..146df21 --- /dev/null +++ b/src/core/auth/BasicAuth.ts @@ -0,0 +1,31 @@ +import { Base64 } from "js-base64"; + +export interface BasicAuth { + username: string; + password: string; +} + +const BASIC_AUTH_HEADER_PREFIX = /^Basic /i; + +export const BasicAuth = { + toAuthorizationHeader: (basicAuth: BasicAuth | undefined): string | undefined => { + if (basicAuth == null) { + return undefined; + } + const token = Base64.encode(`${basicAuth.username}:${basicAuth.password}`); + return `Basic ${token}`; + }, + fromAuthorizationHeader: (header: string): BasicAuth => { + const credentials = header.replace(BASIC_AUTH_HEADER_PREFIX, ""); + const decoded = Base64.decode(credentials); + const [username, password] = decoded.split(":", 2); + + if (username == null || password == null) { + throw new Error("Invalid basic auth"); + } + return { + username, + password, + }; + }, +}; diff --git a/src/core/auth/BearerToken.ts b/src/core/auth/BearerToken.ts new file mode 100644 index 0000000..fe987fc --- /dev/null +++ b/src/core/auth/BearerToken.ts @@ -0,0 +1,15 @@ +export type BearerToken = string; + +const BEARER_AUTH_HEADER_PREFIX = /^Bearer /i; + +export const BearerToken = { + toAuthorizationHeader: (token: BearerToken | undefined): string | undefined => { + if (token == null) { + return undefined; + } + return `Bearer ${token}`; + }, + fromAuthorizationHeader: (header: string): BearerToken => { + return header.replace(BEARER_AUTH_HEADER_PREFIX, "").trim() as BearerToken; + }, +}; diff --git a/src/core/auth/index.ts b/src/core/auth/index.ts new file mode 100644 index 0000000..ee293b3 --- /dev/null +++ b/src/core/auth/index.ts @@ -0,0 +1,2 @@ +export { BasicAuth } from "./BasicAuth"; +export { BearerToken } from "./BearerToken"; diff --git a/src/core/index.ts b/src/core/index.ts index bdd3645..82528c9 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -1,2 +1,3 @@ export * as serialization from "./schemas"; export * from "./fetcher"; +export * from "./auth"; diff --git a/yarn.lock b/yarn.lock index c3072d5..a79fdb4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -57,6 +57,11 @@ form-data@^4.0.0: combined-stream "^1.0.8" mime-types "^2.1.12" +js-base64@3.7.2: + version "3.7.2" + resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-3.7.2.tgz#816d11d81a8aff241603d19ce5761e13e41d7745" + integrity sha512-NnRs6dsyqUXejqk/yv2aiXlAvOs56sLkX6nUdeaNezI5LFFLlsZjOThmwnrcwh5ZZRwZlCMnVAY3CvhIhoVEKQ== + mime-db@1.52.0: version "1.52.0" resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.52.0.tgz#bbabcdc02859f4987301c856e3387ce5ec43bf70"