diff --git a/packages/sdk/CHANGELOG.md b/packages/sdk/CHANGELOG.md index 44968696fbee9..833e880b3b2db 100644 --- a/packages/sdk/CHANGELOG.md +++ b/packages/sdk/CHANGELOG.md @@ -2,6 +2,12 @@ # Changelog +## [1.6.2] - 2025-05-20a + +### Added + +- Added ability to create a `BackendClient` with just an `AccessToken` + ## [1.6.1] - 2025-05-20 ### Added diff --git a/packages/sdk/package.json b/packages/sdk/package.json index bc22bd1bc6a5b..153ba0e2e4737 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -1,7 +1,7 @@ { "name": "@pipedream/sdk", "type": "module", - "version": "1.6.1", + "version": "1.6.2", "description": "Pipedream SDK", "main": "./dist/server.js", "module": "./dist/server.js", diff --git a/packages/sdk/src/server/index.ts b/packages/sdk/src/server/index.ts index d7f23a5c5f4fe..5b89ff358f50e 100644 --- a/packages/sdk/src/server/index.ts +++ b/packages/sdk/src/server/index.ts @@ -36,7 +36,9 @@ export type BackendClientOpts = { /** * The credentials to use for authentication against the Pipedream API. */ - credentials: OAuthCredentials; + credentials: OAuthCredentials | { + accessToken: string; + }; /** * The base project ID tied to relevant API requests @@ -188,12 +190,13 @@ export class BackendClient extends BaseClient { client: oauth.Client clientAuth: oauth.ClientAuth as: oauth.AuthorizationServer - }; + } | undefined; private oauthAccessToken?: { token: string expiresAt: number }; protected override projectId: string = ""; + private staticAccessToken?: string; /** * Constructs a new ServerClient instance. @@ -206,7 +209,11 @@ export class BackendClient extends BaseClient { this.ensureValidEnvironment(opts.environment); this.projectId = opts.projectId; - this.oauthClient = this.newOauthClient(opts.credentials, this.apiHost); + if ("accessToken" in opts.credentials) { + this.staticAccessToken = opts.credentials.accessToken; + } else { + this.oauthClient = this.newOauthClient(opts.credentials, this.apiHost); + } } private ensureValidEnvironment(environment?: string) { @@ -245,10 +252,16 @@ export class BackendClient extends BaseClient { } protected authHeaders(): string | Promise { + if (this.staticAccessToken) { + return `Bearer ${this.staticAccessToken}`; + } return this.oauthAuthorizationHeader(); } private async ensureValidOauthAccessToken(): Promise { + if (!this.oauthClient) { + throw new Error("OAuth client not configured") + } const { client, clientAuth, @@ -286,10 +299,6 @@ export class BackendClient extends BaseClient { } private async oauthAuthorizationHeader(): Promise { - if (!this.oauthClient) { - throw new Error("OAuth client not configured") - } - const accessToken = await this.ensureValidOauthAccessToken(); return `Bearer ${accessToken}`;