11import {
2- ServerClient , createClient , HTTPAuthType ,
2+ BackendClient , createClient , HTTPAuthType ,
33} from "../index" ;
44import fetchMock from "jest-fetch-mock" ;
55import { ClientCredentials } from "simple-oauth2" ;
66
7- let client : ServerClient ;
8- let customDomainClient : ServerClient ;
7+ let client : BackendClient ;
8+ let customDomainClient : BackendClient ;
99let oauthClientMock : ClientCredentials ;
10+ const projectId = "proj_abc123" ;
1011
1112beforeEach ( ( ) => {
1213 const getTokenMock = jest . fn ( ) . mockResolvedValue ( {
@@ -20,25 +21,23 @@ beforeEach(() => {
2021 getToken : getTokenMock ,
2122 } as unknown as ClientCredentials ;
2223
23- client = new ServerClient (
24+ client = new BackendClient (
2425 {
25- publicKey : "test-public-key" ,
26- secretKey : "test-secret-key" ,
2726 oauth : {
2827 clientId : "test-client-id" ,
2928 clientSecret : "test-client-secret" ,
3029 } ,
30+ projectId,
3131 } ,
3232 oauthClientMock ,
3333 ) ;
3434
35- customDomainClient = new ServerClient ( {
36- publicKey : "test-public-key" ,
37- secretKey : "test-secret-key" ,
35+ customDomainClient = new BackendClient ( {
3836 oauth : {
3937 clientId : "test-client-id" ,
4038 clientSecret : "test-client-secret" ,
4139 } ,
40+ projectId,
4241 baseWorkflowDomain : "example.com" ,
4342 } ) ;
4443} ) ;
@@ -48,20 +47,23 @@ afterEach(() => {
4847 jest . clearAllMocks ( ) ;
4948} ) ;
5049
51- describe ( "ServerClient " , ( ) => {
50+ describe ( "BackendClient " , ( ) => {
5251 beforeEach ( ( ) => {
5352 fetchMock . resetMocks ( ) ;
5453 } ) ;
5554
5655 describe ( "createClient" , ( ) => {
57- it ( "should mock the createClient method and return a ServerClient instance" , ( ) => {
56+ it ( "should mock the createClient method and return a BackendClient instance" , ( ) => {
5857 const params = {
59- publicKey : "test-public-key" ,
60- secretKey : "test-secret-key" ,
58+ oauth : {
59+ clientId : "test-client-id" ,
60+ clientSecret : "test" ,
61+ } ,
62+ projectId,
6163 } ;
6264
6365 client = createClient ( params ) ;
64- expect ( client ) . toBeInstanceOf ( ServerClient ) ;
66+ expect ( client ) . toBeInstanceOf ( BackendClient ) ;
6567 } ) ;
6668 } ) ;
6769
@@ -143,7 +145,7 @@ describe("ServerClient", () => {
143145 } ) ;
144146 } ) ;
145147
146- describe ( "makeApiRequest " , ( ) => {
148+ describe ( "makeAuthorizedRequest " , ( ) => {
147149 it ( "should include OAuth Authorization header and make an API request" , async ( ) => {
148150 fetchMock . mockResponseOnce (
149151 JSON . stringify ( {
@@ -156,7 +158,7 @@ describe("ServerClient", () => {
156158 } ,
157159 ) ;
158160
159- const result = await client [ "makeApiRequest " ] ( "/test-path" ) ;
161+ const result = await client [ "makeAuthorizedRequest " ] ( "/test-path" ) ;
160162
161163 expect ( result ) . toEqual ( {
162164 success : true ,
@@ -174,7 +176,7 @@ describe("ServerClient", () => {
174176
175177 it ( "should handle OAuth token retrieval failure" , async ( ) => {
176178 oauthClientMock . getToken = jest . fn ( ) . mockRejectedValue ( new Error ( "Invalid credentials" ) ) ;
177- await expect ( client [ "makeApiRequest " ] ( "/test-path" ) ) . rejects . toThrow ( "Failed to obtain OAuth token: Invalid credentials" ) ;
179+ await expect ( client [ "makeAuthorizedRequest " ] ( "/test-path" ) ) . rejects . toThrow ( "Failed to obtain OAuth token: Invalid credentials" ) ;
178180 } ) ;
179181 } ) ;
180182
@@ -197,10 +199,10 @@ describe("ServerClient", () => {
197199 success : true ,
198200 } ) ;
199201 expect ( fetchMock ) . toHaveBeenCalledWith (
200- " https://api.pipedream.com/v1/connect/test-path" ,
202+ ` https://api.pipedream.com/v1/connect/${ projectId } / test-path` ,
201203 expect . objectContaining ( {
202204 headers : expect . objectContaining ( {
203- "Authorization" : expect . stringContaining ( "Basic " ) ,
205+ "Authorization" : expect . stringContaining ( "Bearer " ) ,
204206 } ) ,
205207 } ) ,
206208 ) ;
@@ -230,7 +232,7 @@ describe("ServerClient", () => {
230232 expires_at : "2024-01-01T00:00:00Z" ,
231233 } ) ;
232234 expect ( fetchMock ) . toHaveBeenCalledWith (
233- " https://api.pipedream.com/v1/connect/tokens" ,
235+ ` https://api.pipedream.com/v1/connect/${ projectId } / tokens` ,
234236 expect . objectContaining ( {
235237 method : "POST" ,
236238 body : JSON . stringify ( {
@@ -269,7 +271,7 @@ describe("ServerClient", () => {
269271 expires_at : "2024-01-01T00:00:00Z" ,
270272 } ) ;
271273 expect ( fetchMock ) . toHaveBeenCalledWith (
272- " https://api.pipedream.com/v1/connect/tokens" ,
274+ ` https://api.pipedream.com/v1/connect/${ projectId } / tokens` ,
273275 expect . objectContaining ( {
274276 method : "POST" ,
275277 body : JSON . stringify ( {
@@ -314,7 +316,7 @@ describe("ServerClient", () => {
314316 } ,
315317 ] ) ;
316318 expect ( fetchMock ) . toHaveBeenCalledWith (
317- " https://api.pipedream.com/v1/connect/accounts?include_credentials=1" ,
319+ ` https://api.pipedream.com/v1/connect/${ projectId } / accounts?include_credentials=1` ,
318320 expect . any ( Object ) ,
319321 ) ;
320322 } ) ;
@@ -341,7 +343,7 @@ describe("ServerClient", () => {
341343 name : "Test Account" ,
342344 } ) ;
343345 expect ( fetchMock ) . toHaveBeenCalledWith (
344- " https://api.pipedream.com/v1/connect/accounts/account-1" ,
346+ ` https://api.pipedream.com/v1/connect/${ projectId } / accounts/account-1` ,
345347 expect . any ( Object ) ,
346348 ) ;
347349 } ) ;
@@ -372,7 +374,7 @@ describe("ServerClient", () => {
372374 } ,
373375 ] ) ;
374376 expect ( fetchMock ) . toHaveBeenCalledWith (
375- " https://api.pipedream.com/v1/connect/accounts/app/app-1" ,
377+ ` https://api.pipedream.com/v1/connect/${ projectId } / accounts/app/app-1` ,
376378 expect . any ( Object ) ,
377379 ) ;
378380 } ) ;
@@ -403,7 +405,7 @@ describe("ServerClient", () => {
403405 } ,
404406 ] ) ;
405407 expect ( fetchMock ) . toHaveBeenCalledWith (
406- " https://api.pipedream.com/v1/connect/users/external-id-1/accounts" ,
408+ ` https://api.pipedream.com/v1/connect/${ projectId } / users/external-id-1/accounts` ,
407409 expect . any ( Object ) ,
408410 ) ;
409411 } ) ;
@@ -418,7 +420,7 @@ describe("ServerClient", () => {
418420 await client . deleteAccount ( "account-1" ) ;
419421
420422 expect ( fetchMock ) . toHaveBeenCalledWith (
421- " https://api.pipedream.com/v1/connect/accounts/account-1" ,
423+ ` https://api.pipedream.com/v1/connect/${ projectId } / accounts/account-1` ,
422424 expect . objectContaining ( {
423425 method : "DELETE" ,
424426 } ) ,
@@ -435,7 +437,7 @@ describe("ServerClient", () => {
435437 await client . deleteAccountsByApp ( "app-1" ) ;
436438
437439 expect ( fetchMock ) . toHaveBeenCalledWith (
438- " https://api.pipedream.com/v1/connect/accounts/app/app-1" ,
440+ ` https://api.pipedream.com/v1/connect/${ projectId } / accounts/app/app-1` ,
439441 expect . objectContaining ( {
440442 method : "DELETE" ,
441443 } ) ,
@@ -452,7 +454,7 @@ describe("ServerClient", () => {
452454 await client . deleteExternalUser ( "external-id-1" ) ;
453455
454456 expect ( fetchMock ) . toHaveBeenCalledWith (
455- " https://api.pipedream.com/v1/connect/users/external-id-1" ,
457+ ` https://api.pipedream.com/v1/connect/${ projectId } / users/external-id-1` ,
456458 expect . objectContaining ( {
457459 method : "DELETE" ,
458460 } ) ,
@@ -489,7 +491,7 @@ describe("ServerClient", () => {
489491 ] ,
490492 } ) ;
491493 expect ( fetchMock ) . toHaveBeenCalledWith (
492- " https://api.pipedream.com/v1/connect/projects/info" ,
494+ ` https://api.pipedream.com/v1/connect/${ projectId } / projects/info` ,
493495 expect . objectContaining ( {
494496 method : "GET" ,
495497 } ) ,
@@ -621,14 +623,13 @@ describe("ServerClient", () => {
621623 getToken : getTokenMock ,
622624 } as unknown as ClientCredentials ;
623625
624- const client = new ServerClient (
626+ const client = new BackendClient (
625627 {
626- publicKey : "test-public-key" ,
627- secretKey : "test" ,
628628 oauth : {
629629 clientId : "test-client-id" ,
630630 clientSecret : "test-client-secret" ,
631631 } ,
632+ projectId : "proj_abc123" ,
632633 } ,
633634 oauthClientMock ,
634635 ) ;
@@ -645,7 +646,7 @@ describe("ServerClient", () => {
645646 ) ;
646647
647648 // First request will get the expired token and fetch a new one
648- const result1 = await client [ "makeApiRequest " ] ( "/test-path" ) ;
649+ const result1 = await client [ "makeAuthorizedRequest " ] ( "/test-path" ) ;
649650
650651 expect ( result1 ) . toEqual ( {
651652 success : true ,
@@ -663,7 +664,7 @@ describe("ServerClient", () => {
663664 } ) ;
664665
665666 describe ( "invokeWorkflowForExternalUser" , ( ) => {
666- let client : ServerClient ;
667+ let client : BackendClient ;
667668
668669 beforeEach ( ( ) => {
669670 fetchMock . resetMocks ( ) ;
@@ -692,14 +693,13 @@ describe("ServerClient", () => {
692693 const oauthClientMock = {
693694 getToken : getTokenMock ,
694695 } as unknown as ClientCredentials ;
695- client = new ServerClient (
696+ client = new BackendClient (
696697 {
697- publicKey : "test-public-key" ,
698- secretKey : "test" ,
699698 oauth : {
700699 clientId : "test-client-id" ,
701700 clientSecret : "test-client-secret" ,
702701 } ,
702+ projectId,
703703 } ,
704704 oauthClientMock ,
705705 ) ;
@@ -752,7 +752,7 @@ describe("ServerClient", () => {
752752 } ) ;
753753 } ) ;
754754
755- describe ( "ServerClient - buildWorkflowUrl" , ( ) => {
755+ describe ( "BackendClient - buildWorkflowUrl" , ( ) => {
756756 describe ( "Default domain (m.pipedream.net)" , ( ) => {
757757 it ( "should return full URL if input is a full URL with protocol" , ( ) => {
758758 const input = "https://en123.m.pipedream.net" ;
0 commit comments