@@ -26,6 +26,7 @@ export declare namespace PipedreamClient {
2626 baseUrl ?: core . Supplier < string > ;
2727 clientId ?: core . Supplier < string > ;
2828 clientSecret ?: core . Supplier < string > ;
29+ tokenProvider ?: core . TokenProvider ;
2930 projectId : string ;
3031 /** Override the x-pd-environment header */
3132 projectEnvironment ?: core . Supplier < Pipedream . ProjectEnvironment | undefined > ;
@@ -51,7 +52,7 @@ export declare namespace PipedreamClient {
5152
5253export class PipedreamClient {
5354 protected readonly _options : PipedreamClient . Options ;
54- protected readonly _oauthTokenProvider : core . OAuthTokenProvider ;
55+ protected readonly _tokenProvider : core . TokenProvider ;
5556 protected _appCategories : AppCategories | undefined ;
5657 protected _apps : Apps | undefined ;
5758 protected _accounts : Accounts | undefined ;
@@ -82,6 +83,10 @@ export class PipedreamClient {
8283 ) ,
8384 } ;
8485
86+ this . _tokenProvider = this . _options . tokenProvider ?? this . newOAuthTokenProvider ( ) ;
87+ }
88+
89+ private newOAuthTokenProvider ( ) : core . OAuthTokenProvider {
8590 const clientId = this . _options . clientId ?? process . env [ "PIPEDREAM_CLIENT_ID" ] ;
8691 if ( clientId == null ) {
8792 throw new Error (
@@ -96,7 +101,7 @@ export class PipedreamClient {
96101 ) ;
97102 }
98103
99- this . _oauthTokenProvider = new core . OAuthTokenProvider ( {
104+ return new core . OAuthTokenProvider ( {
100105 clientId,
101106 clientSecret,
102107 authClient : new OauthTokens ( {
@@ -109,84 +114,84 @@ export class PipedreamClient {
109114 public get appCategories ( ) : AppCategories {
110115 return ( this . _appCategories ??= new AppCategories ( {
111116 ...this . _options ,
112- token : async ( ) => await this . _oauthTokenProvider . getToken ( ) ,
117+ token : async ( ) => await this . _tokenProvider . getToken ( ) ,
113118 } ) ) ;
114119 }
115120
116121 public get apps ( ) : Apps {
117122 return ( this . _apps ??= new Apps ( {
118123 ...this . _options ,
119- token : async ( ) => await this . _oauthTokenProvider . getToken ( ) ,
124+ token : async ( ) => await this . _tokenProvider . getToken ( ) ,
120125 } ) ) ;
121126 }
122127
123128 public get accounts ( ) : Accounts {
124129 return ( this . _accounts ??= new Accounts ( {
125130 ...this . _options ,
126- token : async ( ) => await this . _oauthTokenProvider . getToken ( ) ,
131+ token : async ( ) => await this . _tokenProvider . getToken ( ) ,
127132 } ) ) ;
128133 }
129134
130135 public get users ( ) : Users {
131136 return ( this . _users ??= new Users ( {
132137 ...this . _options ,
133- token : async ( ) => await this . _oauthTokenProvider . getToken ( ) ,
138+ token : async ( ) => await this . _tokenProvider . getToken ( ) ,
134139 } ) ) ;
135140 }
136141
137142 public get components ( ) : Components {
138143 return ( this . _components ??= new Components ( {
139144 ...this . _options ,
140- token : async ( ) => await this . _oauthTokenProvider . getToken ( ) ,
145+ token : async ( ) => await this . _tokenProvider . getToken ( ) ,
141146 } ) ) ;
142147 }
143148
144149 public get actions ( ) : Actions {
145150 return ( this . _actions ??= new Actions ( {
146151 ...this . _options ,
147- token : async ( ) => await this . _oauthTokenProvider . getToken ( ) ,
152+ token : async ( ) => await this . _tokenProvider . getToken ( ) ,
148153 } ) ) ;
149154 }
150155
151156 public get triggers ( ) : Triggers {
152157 return ( this . _triggers ??= new Triggers ( {
153158 ...this . _options ,
154- token : async ( ) => await this . _oauthTokenProvider . getToken ( ) ,
159+ token : async ( ) => await this . _tokenProvider . getToken ( ) ,
155160 } ) ) ;
156161 }
157162
158163 public get deployedTriggers ( ) : DeployedTriggers {
159164 return ( this . _deployedTriggers ??= new DeployedTriggers ( {
160165 ...this . _options ,
161- token : async ( ) => await this . _oauthTokenProvider . getToken ( ) ,
166+ token : async ( ) => await this . _tokenProvider . getToken ( ) ,
162167 } ) ) ;
163168 }
164169
165170 public get projects ( ) : Projects {
166171 return ( this . _projects ??= new Projects ( {
167172 ...this . _options ,
168- token : async ( ) => await this . _oauthTokenProvider . getToken ( ) ,
173+ token : async ( ) => await this . _tokenProvider . getToken ( ) ,
169174 } ) ) ;
170175 }
171176
172177 public get proxy ( ) : Proxy {
173178 return ( this . _proxy ??= new Proxy ( {
174179 ...this . _options ,
175- token : async ( ) => await this . _oauthTokenProvider . getToken ( ) ,
180+ token : async ( ) => await this . _tokenProvider . getToken ( ) ,
176181 } ) ) ;
177182 }
178183
179184 public get tokens ( ) : Tokens {
180185 return ( this . _tokens ??= new Tokens ( {
181186 ...this . _options ,
182- token : async ( ) => await this . _oauthTokenProvider . getToken ( ) ,
187+ token : async ( ) => await this . _tokenProvider . getToken ( ) ,
183188 } ) ) ;
184189 }
185190
186191 public get oauthTokens ( ) : OauthTokens {
187192 return ( this . _oauthTokens ??= new OauthTokens ( {
188193 ...this . _options ,
189- token : async ( ) => await this . _oauthTokenProvider . getToken ( ) ,
194+ token : async ( ) => await this . _tokenProvider . getToken ( ) ,
190195 } ) ) ;
191196 }
192197}
0 commit comments