Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
23 changes: 16 additions & 7 deletions packages/sdk/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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) {
Expand Down Expand Up @@ -245,10 +252,16 @@ export class BackendClient extends BaseClient {
}

protected authHeaders(): string | Promise<string> {
if (this.staticAccessToken) {
return `Bearer ${this.staticAccessToken}`;
}
return this.oauthAuthorizationHeader();
}

private async ensureValidOauthAccessToken(): Promise<string> {
if (!this.oauthClient) {
throw new Error("OAuth client not configured")
}
const {
client,
clientAuth,
Expand Down Expand Up @@ -286,10 +299,6 @@ export class BackendClient extends BaseClient {
}

private async oauthAuthorizationHeader(): Promise<string> {
if (!this.oauthClient) {
throw new Error("OAuth client not configured")
}

const accessToken = await this.ensureValidOauthAccessToken();

return `Bearer ${accessToken}`;
Expand Down
Loading