@@ -7,9 +7,13 @@ import {
77 ClientCredentials ,
88} from "simple-oauth2" ;
99
10- export type ProjectKeys = {
11- publicKey : string ;
12- secretKey : string ;
10+ export type Project = {
11+ id : string ;
12+ } ;
13+
14+ export type ProjectEnvironment = {
15+ project : Project ;
16+ environment : string ;
1317} ;
1418
1519export type PipedreamOAuthClient = {
@@ -34,6 +38,11 @@ export type CreateServerClientOpts = {
3438 */
3539 secretKey ?: string ;
3640
41+ /**
42+ * The environment in which the server client is running (e.g., "production", "development").
43+ */
44+ environment ?: string ;
45+
3746 /**
3847 * @deprecated Use the `oauth` object instead.
3948 * The client ID of your workspace's OAuth application.
@@ -46,11 +55,6 @@ export type CreateServerClientOpts = {
4655 */
4756 oauthClientSecret ?: string ;
4857
49- /**
50- * The project object, containing publicKey and secretKey.
51- */
52- project ?: ProjectKeys ;
53-
5458 /**
5559 * The OAuth object, containing client ID and client secret.
5660 */
@@ -62,6 +66,15 @@ export type CreateServerClientOpts = {
6266 apiHost ?: string ;
6367} ;
6468
69+ /**
70+ * Different types of ways customers can authorize requests to HTTP endpoints
71+ */
72+ export enum HTTPAuthType {
73+ None = "none" ,
74+ StaticBearer = "static-bearer" ,
75+ OAuth = "oauth"
76+ }
77+
6578/**
6679 * Options for creating a Connect token.
6780 */
@@ -136,7 +149,7 @@ export type ConnectParams = {
136149/**
137150 * The authentication type for the app.
138151 */
139- export enum AuthType {
152+ export enum AppAuthType {
140153 OAuth = "oauth" ,
141154 Keys = "keys" ,
142155 None = "none" ,
@@ -164,7 +177,7 @@ export type AppResponse = {
164177 /**
165178 * The authentication type used by the app.
166179 */
167- auth_type : AuthType ;
180+ auth_type : AppAuthType ;
168181
169182 /**
170183 * The URL to the app's logo.
@@ -322,6 +335,7 @@ export function createClient(opts: CreateServerClientOpts) {
322335export class ServerClient {
323336 private secretKey ?: string ;
324337 private publicKey ?: string ;
338+ private environment : string ;
325339 private oauthClient ?: ClientCredentials ;
326340 private oauthToken ?: AccessToken ;
327341 private readonly baseURL : string ;
@@ -336,12 +350,9 @@ export class ServerClient {
336350 opts : CreateServerClientOpts ,
337351 oauthClient ?: ClientCredentials ,
338352 ) {
353+ this . environment = opts . environment ?? "production" ;
339354 this . secretKey = opts . secretKey ;
340355 this . publicKey = opts . publicKey ;
341- if ( opts . project ) {
342- this . publicKey = opts . project . publicKey ;
343- this . secretKey = opts . project . secretKey ;
344- }
345356
346357 const { apiHost = "api.pipedream.com" } = opts ;
347358 this . baseURL = `https://${ apiHost } /v1` ;
@@ -460,8 +471,9 @@ export class ServerClient {
460471 }
461472 }
462473
463- const headers = {
474+ const headers : Record < string , string > = {
464475 ...customHeaders ,
476+ "X-PD-Environment" : this . environment ,
465477 } ;
466478
467479 let processedBody : string | Buffer | URLSearchParams | FormData | null = null ;
@@ -571,7 +583,8 @@ export class ServerClient {
571583 }
572584
573585 /**
574- * Creates a new connect token.
586+ * Creates a new Pipedream Connect token.
587+ * See https://pipedream.com/docs/connect/quickstart#connect-to-the-pipedream-api-from-your-server-and-create-a-token
575588 *
576589 * @param opts - The options for creating the connect token.
577590 * @returns A promise resolving to the connect token response.
@@ -782,20 +795,35 @@ export class ServerClient {
782795 * console.log(response);
783796 * ```
784797 */
785- public async invokeWorkflow ( url : string , opts : RequestOptions = { } ) : Promise < unknown > {
798+ public async invokeWorkflow ( url : string , opts : RequestOptions = { } , authType : HTTPAuthType = HTTPAuthType . None ) : Promise < unknown > {
786799 const {
787800 body,
788801 headers = { } ,
789802 } = opts ;
790803
804+ let authHeader : string | undefined ;
805+ switch ( authType ) {
806+ // It's expected that users will pass their own Authorization header in the static bearer case
807+ case HTTPAuthType . StaticBearer :
808+ authHeader = headers [ "Authorization" ] ;
809+ break ;
810+ case HTTPAuthType . OAuth :
811+ authHeader = await this . oauthAuthorizationHeader ( ) ;
812+ break ;
813+ default :
814+ break ;
815+ }
816+
791817 return this . makeRequest ( "" , {
792818 ...opts ,
793819 baseURL : url ,
794820 method : opts . method || "POST" , // Default to POST if not specified
795- headers : {
796- ...headers ,
797- "Authorization" : await this . oauthAuthorizationHeader ( ) ,
798- } ,
821+ headers : authHeader
822+ ? {
823+ ...headers ,
824+ "Authorization" : authHeader ,
825+ }
826+ : headers ,
799827 body,
800828 } ) ;
801829 }
@@ -850,7 +878,6 @@ export class ServerClient {
850878 headers : {
851879 ...headers ,
852880 "X-PD-External-User-ID" : externalUserId ,
853- "X-PD-Project-Public-Key" : this . publicKey ,
854881 } ,
855882 } ) ;
856883 }
0 commit comments