@@ -26,6 +26,7 @@ export declare namespace PipedreamClient {
26
26
baseUrl ?: core . Supplier < string > ;
27
27
clientId ?: core . Supplier < string > ;
28
28
clientSecret ?: core . Supplier < string > ;
29
+ tokenProvider ?: core . TokenProvider ;
29
30
projectId : string ;
30
31
/** Override the x-pd-environment header */
31
32
projectEnvironment ?: core . Supplier < Pipedream . ProjectEnvironment | undefined > ;
@@ -51,7 +52,7 @@ export declare namespace PipedreamClient {
51
52
52
53
export class PipedreamClient {
53
54
protected readonly _options : PipedreamClient . Options ;
54
- protected readonly _oauthTokenProvider : core . OAuthTokenProvider ;
55
+ protected readonly _tokenProvider : core . TokenProvider ;
55
56
protected _appCategories : AppCategories | undefined ;
56
57
protected _apps : Apps | undefined ;
57
58
protected _accounts : Accounts | undefined ;
@@ -82,6 +83,10 @@ export class PipedreamClient {
82
83
) ,
83
84
} ;
84
85
86
+ this . _tokenProvider = this . _options . tokenProvider ?? this . newOAuthTokenProvider ( ) ;
87
+ }
88
+
89
+ private newOAuthTokenProvider ( ) : core . OAuthTokenProvider {
85
90
const clientId = this . _options . clientId ?? process . env [ "PIPEDREAM_CLIENT_ID" ] ;
86
91
if ( clientId == null ) {
87
92
throw new Error (
@@ -96,7 +101,7 @@ export class PipedreamClient {
96
101
) ;
97
102
}
98
103
99
- this . _oauthTokenProvider = new core . OAuthTokenProvider ( {
104
+ return new core . OAuthTokenProvider ( {
100
105
clientId,
101
106
clientSecret,
102
107
authClient : new OauthTokens ( {
@@ -109,84 +114,84 @@ export class PipedreamClient {
109
114
public get appCategories ( ) : AppCategories {
110
115
return ( this . _appCategories ??= new AppCategories ( {
111
116
...this . _options ,
112
- token : async ( ) => await this . _oauthTokenProvider . getToken ( ) ,
117
+ token : async ( ) => await this . _tokenProvider . getToken ( ) ,
113
118
} ) ) ;
114
119
}
115
120
116
121
public get apps ( ) : Apps {
117
122
return ( this . _apps ??= new Apps ( {
118
123
...this . _options ,
119
- token : async ( ) => await this . _oauthTokenProvider . getToken ( ) ,
124
+ token : async ( ) => await this . _tokenProvider . getToken ( ) ,
120
125
} ) ) ;
121
126
}
122
127
123
128
public get accounts ( ) : Accounts {
124
129
return ( this . _accounts ??= new Accounts ( {
125
130
...this . _options ,
126
- token : async ( ) => await this . _oauthTokenProvider . getToken ( ) ,
131
+ token : async ( ) => await this . _tokenProvider . getToken ( ) ,
127
132
} ) ) ;
128
133
}
129
134
130
135
public get users ( ) : Users {
131
136
return ( this . _users ??= new Users ( {
132
137
...this . _options ,
133
- token : async ( ) => await this . _oauthTokenProvider . getToken ( ) ,
138
+ token : async ( ) => await this . _tokenProvider . getToken ( ) ,
134
139
} ) ) ;
135
140
}
136
141
137
142
public get components ( ) : Components {
138
143
return ( this . _components ??= new Components ( {
139
144
...this . _options ,
140
- token : async ( ) => await this . _oauthTokenProvider . getToken ( ) ,
145
+ token : async ( ) => await this . _tokenProvider . getToken ( ) ,
141
146
} ) ) ;
142
147
}
143
148
144
149
public get actions ( ) : Actions {
145
150
return ( this . _actions ??= new Actions ( {
146
151
...this . _options ,
147
- token : async ( ) => await this . _oauthTokenProvider . getToken ( ) ,
152
+ token : async ( ) => await this . _tokenProvider . getToken ( ) ,
148
153
} ) ) ;
149
154
}
150
155
151
156
public get triggers ( ) : Triggers {
152
157
return ( this . _triggers ??= new Triggers ( {
153
158
...this . _options ,
154
- token : async ( ) => await this . _oauthTokenProvider . getToken ( ) ,
159
+ token : async ( ) => await this . _tokenProvider . getToken ( ) ,
155
160
} ) ) ;
156
161
}
157
162
158
163
public get deployedTriggers ( ) : DeployedTriggers {
159
164
return ( this . _deployedTriggers ??= new DeployedTriggers ( {
160
165
...this . _options ,
161
- token : async ( ) => await this . _oauthTokenProvider . getToken ( ) ,
166
+ token : async ( ) => await this . _tokenProvider . getToken ( ) ,
162
167
} ) ) ;
163
168
}
164
169
165
170
public get projects ( ) : Projects {
166
171
return ( this . _projects ??= new Projects ( {
167
172
...this . _options ,
168
- token : async ( ) => await this . _oauthTokenProvider . getToken ( ) ,
173
+ token : async ( ) => await this . _tokenProvider . getToken ( ) ,
169
174
} ) ) ;
170
175
}
171
176
172
177
public get proxy ( ) : Proxy {
173
178
return ( this . _proxy ??= new Proxy ( {
174
179
...this . _options ,
175
- token : async ( ) => await this . _oauthTokenProvider . getToken ( ) ,
180
+ token : async ( ) => await this . _tokenProvider . getToken ( ) ,
176
181
} ) ) ;
177
182
}
178
183
179
184
public get tokens ( ) : Tokens {
180
185
return ( this . _tokens ??= new Tokens ( {
181
186
...this . _options ,
182
- token : async ( ) => await this . _oauthTokenProvider . getToken ( ) ,
187
+ token : async ( ) => await this . _tokenProvider . getToken ( ) ,
183
188
} ) ) ;
184
189
}
185
190
186
191
public get oauthTokens ( ) : OauthTokens {
187
192
return ( this . _oauthTokens ??= new OauthTokens ( {
188
193
...this . _options ,
189
- token : async ( ) => await this . _oauthTokenProvider . getToken ( ) ,
194
+ token : async ( ) => await this . _tokenProvider . getToken ( ) ,
190
195
} ) ) ;
191
196
}
192
197
}
0 commit comments