@@ -36,7 +36,9 @@ export type BackendClientOpts = {
3636 /**
3737 * The credentials to use for authentication against the Pipedream API.
3838 */
39- credentials : OAuthCredentials ;
39+ credentials : OAuthCredentials | {
40+ accessToken : string ;
41+ } ;
4042
4143 /**
4244 * The base project ID tied to relevant API requests
@@ -188,12 +190,13 @@ export class BackendClient extends BaseClient {
188190 client : oauth . Client
189191 clientAuth : oauth . ClientAuth
190192 as : oauth . AuthorizationServer
191- } ;
193+ } | undefined ;
192194 private oauthAccessToken ?: {
193195 token : string
194196 expiresAt : number
195197 } ;
196198 protected override projectId : string = "" ;
199+ private staticAccessToken ?: string ;
197200
198201 /**
199202 * Constructs a new ServerClient instance.
@@ -206,7 +209,11 @@ export class BackendClient extends BaseClient {
206209
207210 this . ensureValidEnvironment ( opts . environment ) ;
208211 this . projectId = opts . projectId ;
209- this . oauthClient = this . newOauthClient ( opts . credentials , this . apiHost ) ;
212+ if ( "accessToken" in opts . credentials ) {
213+ this . staticAccessToken = opts . credentials . accessToken ;
214+ } else {
215+ this . oauthClient = this . newOauthClient ( opts . credentials , this . apiHost ) ;
216+ }
210217 }
211218
212219 private ensureValidEnvironment ( environment ?: string ) {
@@ -245,10 +252,16 @@ export class BackendClient extends BaseClient {
245252 }
246253
247254 protected authHeaders ( ) : string | Promise < string > {
255+ if ( this . staticAccessToken ) {
256+ return `Bearer ${ this . staticAccessToken } ` ;
257+ }
248258 return this . oauthAuthorizationHeader ( ) ;
249259 }
250260
251261 private async ensureValidOauthAccessToken ( ) : Promise < string > {
262+ if ( ! this . oauthClient ) {
263+ throw new Error ( "OAuth client not configured" )
264+ }
252265 const {
253266 client,
254267 clientAuth,
@@ -286,10 +299,6 @@ export class BackendClient extends BaseClient {
286299 }
287300
288301 private async oauthAuthorizationHeader ( ) : Promise < string > {
289- if ( ! this . oauthClient ) {
290- throw new Error ( "OAuth client not configured" )
291- }
292-
293302 const accessToken = await this . ensureValidOauthAccessToken ( ) ;
294303
295304 return `Bearer ${ accessToken } ` ;
0 commit comments