Skip to content

Commit 5e85ef5

Browse files
committed
Updating all names to noun-verb form.
New AccountsGetParams type
1 parent faf0f8d commit 5e85ef5

File tree

2 files changed

+59
-81
lines changed

2 files changed

+59
-81
lines changed

packages/sdk/src/server/__tests__/server.test.ts

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ describe("BackendClient", () => {
289289
});
290290
});
291291

292-
describe("getAccounts", () => {
292+
describe("accountsGet", () => {
293293
it("should retrieve accounts", async () => {
294294
fetchMock.mockResponseOnce(
295295
JSON.stringify([
@@ -305,7 +305,7 @@ describe("BackendClient", () => {
305305
},
306306
);
307307

308-
const result = await client.getAccounts({
308+
const result = await client.accountsGet({
309309
include_credentials: 1,
310310
});
311311

@@ -322,7 +322,7 @@ describe("BackendClient", () => {
322322
});
323323
});
324324

325-
describe("getAccount", () => {
325+
describe("accountsGetById", () => {
326326
it("should retrieve a specific account by ID", async () => {
327327
fetchMock.mockResponseOnce(
328328
JSON.stringify({
@@ -336,7 +336,7 @@ describe("BackendClient", () => {
336336
},
337337
);
338338

339-
const result = await client.getAccount("account-1");
339+
const result = await client.accountsGetById("account-1");
340340

341341
expect(result).toEqual({
342342
id: "account-1",
@@ -349,7 +349,7 @@ describe("BackendClient", () => {
349349
});
350350
});
351351

352-
describe("getAccountsByApp", () => {
352+
describe("Get accounts by app", () => {
353353
it("should retrieve accounts associated with a specific app", async () => {
354354
fetchMock.mockResponseOnce(
355355
JSON.stringify([
@@ -365,7 +365,9 @@ describe("BackendClient", () => {
365365
},
366366
);
367367

368-
const result = await client.getAccountsByApp("app-1");
368+
const result = await client.accountsGet({
369+
app: "app-1",
370+
});
369371

370372
expect(result).toEqual([
371373
{
@@ -374,13 +376,13 @@ describe("BackendClient", () => {
374376
},
375377
]);
376378
expect(fetchMock).toHaveBeenCalledWith(
377-
`https://api.pipedream.com/v1/connect/${projectId}/accounts/app/app-1`,
379+
`https://api.pipedream.com/v1/connect/${projectId}/accounts?app=app-1`,
378380
expect.any(Object),
379381
);
380382
});
381383
});
382384

383-
describe("getAccountsByExternalId", () => {
385+
describe("Get accounts by external user ID", () => {
384386
it("should retrieve accounts associated with a specific external ID", async () => {
385387
fetchMock.mockResponseOnce(
386388
JSON.stringify([
@@ -396,7 +398,9 @@ describe("BackendClient", () => {
396398
},
397399
);
398400

399-
const result = await client.getAccountsByExternalId("external-id-1");
401+
const result = await client.accountsGet({
402+
external_user_id: "external-id-1",
403+
});
400404

401405
expect(result).toEqual([
402406
{
@@ -405,7 +409,7 @@ describe("BackendClient", () => {
405409
},
406410
]);
407411
expect(fetchMock).toHaveBeenCalledWith(
408-
`https://api.pipedream.com/v1/connect/${projectId}/users/external-id-1/accounts`,
412+
`https://api.pipedream.com/v1/connect/${projectId}/accounts?external_user_id=external-id-1`,
409413
expect.any(Object),
410414
);
411415
});
@@ -417,7 +421,7 @@ describe("BackendClient", () => {
417421
status: 204,
418422
});
419423

420-
await client.deleteAccount("account-1");
424+
await client.accountDelete("account-1");
421425

422426
expect(fetchMock).toHaveBeenCalledWith(
423427
`https://api.pipedream.com/v1/connect/${projectId}/accounts/account-1`,
@@ -428,13 +432,13 @@ describe("BackendClient", () => {
428432
});
429433
});
430434

431-
describe("deleteAccountsByApp", () => {
435+
describe("accountsDeleteByApp", () => {
432436
it("should delete all accounts associated with a specific app", async () => {
433437
fetchMock.mockResponseOnce("", {
434438
status: 204,
435439
});
436440

437-
await client.deleteAccountsByApp("app-1");
441+
await client.accountsDeleteByApp("app-1");
438442

439443
expect(fetchMock).toHaveBeenCalledWith(
440444
`https://api.pipedream.com/v1/connect/${projectId}/accounts/app/app-1`,
@@ -445,13 +449,13 @@ describe("BackendClient", () => {
445449
});
446450
});
447451

448-
describe("deleteExternalUser", () => {
452+
describe("accountsDeleteByExternalUser", () => {
449453
it("should delete all accounts associated with a specific external ID", async () => {
450454
fetchMock.mockResponseOnce("", {
451455
status: 204,
452456
});
453457

454-
await client.deleteExternalUser("external-id-1");
458+
await client.accountsDeleteByExternalUser("external-id-1");
455459

456460
expect(fetchMock).toHaveBeenCalledWith(
457461
`https://api.pipedream.com/v1/connect/${projectId}/users/external-id-1`,
@@ -462,7 +466,7 @@ describe("BackendClient", () => {
462466
});
463467
});
464468

465-
describe("getProjectInfo", () => {
469+
describe("projectGetInfo", () => {
466470
it("should retrieve project info", async () => {
467471
fetchMock.mockResponseOnce(
468472
JSON.stringify({
@@ -480,7 +484,7 @@ describe("BackendClient", () => {
480484
},
481485
);
482486

483-
const result = await client.getProjectInfo();
487+
const result = await client.projectGetInfo();
484488

485489
expect(result).toEqual({
486490
apps: [
@@ -499,7 +503,7 @@ describe("BackendClient", () => {
499503
});
500504
});
501505

502-
describe("invokeWorkflow", () => {
506+
describe("workflowInvoke", () => {
503507
it("should invoke a workflow with provided URL and body, with no auth type", async () => {
504508
fetchMock.mockResponseOnce(
505509
JSON.stringify({
@@ -512,7 +516,7 @@ describe("BackendClient", () => {
512516
},
513517
);
514518

515-
const result = await client.invokeWorkflow("https://example.com/workflow", {
519+
const result = await client.workflowInvoke("https://example.com/workflow", {
516520
body: {
517521
foo: "bar",
518522
},
@@ -548,7 +552,7 @@ describe("BackendClient", () => {
548552
},
549553
);
550554

551-
const result = await client.invokeWorkflow("https://example.com/workflow", {}, HTTPAuthType.OAuth);
555+
const result = await client.workflowInvoke("https://example.com/workflow", {}, HTTPAuthType.OAuth);
552556

553557
expect(result).toEqual({
554558
result: "workflow-response",
@@ -576,7 +580,7 @@ describe("BackendClient", () => {
576580
},
577581
);
578582

579-
const result = await client.invokeWorkflow("https://example.com/workflow", {
583+
const result = await client.workflowInvoke("https://example.com/workflow", {
580584
headers: {
581585
"Authorization": "Bearer static-token",
582586
},
@@ -722,7 +726,7 @@ describe("BackendClient", () => {
722726
},
723727
);
724728

725-
const result = await client.invokeWorkflowForExternalUser("https://example.com/workflow", "external-user-id", {
729+
const result = await client.workflowInvokeForExternalUser("https://example.com/workflow", "external-user-id", {
726730
body: {
727731
foo: "bar",
728732
},
@@ -744,7 +748,7 @@ describe("BackendClient", () => {
744748
});
745749

746750
it("should throw error when externalUserId is missing", async () => {
747-
await expect(client.invokeWorkflowForExternalUser("https://example.com/workflow", "", {
751+
await expect(client.workflowInvokeForExternalUser("https://example.com/workflow", "", {
748752
body: {
749753
foo: "bar",
750754
},

packages/sdk/src/server/index.ts

Lines changed: 32 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,23 @@ export type ConnectTokenResponse = {
125125
};
126126

127127
/**
128-
* Parameters for the Connect API.
128+
* Parameters for the Connect Accounts API
129129
*/
130-
export type ConnectParams = {
130+
export type AccountsGetParams = {
131+
/**
132+
* The name slug of the app.
133+
*/
134+
app?: string;
135+
136+
/**
137+
* The external user ID associated with the account.
138+
*/
139+
external_user_id?: string;
140+
141+
/**
142+
* The name of the account.
143+
*/
144+
oauth_app_id?: string;
131145
/**
132146
* Whether to include credentials in the request (1 to include, 0 to exclude).
133147
*/
@@ -574,11 +588,11 @@ export class BackendClient {
574588
* @example
575589
*
576590
* ```typescript
577-
* const accounts = await client.getAccounts({ include_credentials: 1 });
591+
* const accounts = await client.accountsGet({ include_credentials: 1 });
578592
* console.log(accounts);
579593
* ```
580594
*/
581-
public async getAccounts(params: ConnectParams = {}): Promise<Account[]> {
595+
public async accountsGet(params: AccountsGetParams = {}): Promise<Account[]> {
582596
return this.makeConnectRequest<Account[]>("/accounts", {
583597
params,
584598
});
@@ -594,56 +608,16 @@ export class BackendClient {
594608
* @example
595609
*
596610
* ```typescript
597-
* const account = await client.getAccount("account-id");
611+
* const account = await client.accountsGetById("account-id");
598612
* console.log(account);
599613
* ```
600614
*/
601-
public async getAccount(accountId: string, params: ConnectParams = {}): Promise<Account> {
615+
public async accountsGetById(accountId: string, params: AccountsGetParams = {}): Promise<Account> {
602616
return this.makeConnectRequest<Account>(`/accounts/${accountId}`, {
603617
params,
604618
});
605619
}
606620

607-
/**
608-
* Retrieves accounts associated with a specific app.
609-
*
610-
* @param appId - The ID of the app.
611-
* @param params - The query parameters for retrieving accounts.
612-
* @returns A promise resolving to a list of accounts.
613-
*
614-
* @example
615-
*
616-
* ```typescript
617-
* const accounts = await client.getAccountsByApp("app-id");
618-
* console.log(accounts);
619-
* ```
620-
*/
621-
public async getAccountsByApp(appId: string, params: ConnectParams = {}): Promise<Account[]> {
622-
return this.makeConnectRequest<Account[]>(`/accounts/app/${appId}`, {
623-
params,
624-
});
625-
}
626-
627-
/**
628-
* Retrieves accounts associated with a specific external ID.
629-
*
630-
* @param externalId - The external ID associated with the accounts.
631-
* @param params - The query parameters for retrieving accounts.
632-
* @returns A promise resolving to a list of accounts.
633-
*
634-
* @example
635-
*
636-
* ```typescript
637-
* const accounts = await client.getAccountsByExternalId("external-id");
638-
* console.log(accounts);
639-
* ```
640-
*/
641-
public async getAccountsByExternalId(externalId: string, params: ConnectParams = {}): Promise<Account[]> {
642-
return this.makeConnectRequest<Account[]>(`/users/${externalId}/accounts`, {
643-
params,
644-
});
645-
}
646-
647621
/**
648622
* Deletes a specific account by ID.
649623
*
@@ -653,11 +627,11 @@ export class BackendClient {
653627
* @example
654628
*
655629
* ```typescript
656-
* await client.deleteAccount("account-id");
630+
* await client.accountDelete("account-id");
657631
* console.log("Account deleted");
658632
* ```
659633
*/
660-
public async deleteAccount(accountId: string): Promise<void> {
634+
public async accountDelete(accountId: string): Promise<void> {
661635
await this.makeConnectRequest(`/accounts/${accountId}`, {
662636
method: "DELETE",
663637
});
@@ -672,11 +646,11 @@ export class BackendClient {
672646
* @example
673647
*
674648
* ```typescript
675-
* await client.deleteAccountsByApp("app-id");
649+
* await client.accountsDeleteByApp("app-id");
676650
* console.log("All accounts deleted");
677651
* ```
678652
*/
679-
public async deleteAccountsByApp(appId: string): Promise<void> {
653+
public async accountsDeleteByApp(appId: string): Promise<void> {
680654
await this.makeConnectRequest(`/accounts/app/${appId}`, {
681655
method: "DELETE",
682656
});
@@ -691,11 +665,11 @@ export class BackendClient {
691665
* @example
692666
*
693667
* ```typescript
694-
* await client.deleteExternalUser("external-id");
668+
* await client.accountsDeleteByExternalUser("external-id");
695669
* console.log("All accounts deleted");
696670
* ```
697671
*/
698-
public async deleteExternalUser(externalId: string): Promise<void> {
672+
public async accountsDeleteByExternalUser(externalId: string): Promise<void> {
699673
await this.makeConnectRequest(`/users/${externalId}`, {
700674
method: "DELETE",
701675
});
@@ -709,11 +683,11 @@ export class BackendClient {
709683
* @example
710684
*
711685
* ```typescript
712-
* const projectInfo = await client.getProjectInfo();
686+
* const projectInfo = await client.projectGetInfo();
713687
* console.log(projectInfo);
714688
* ```
715689
*/
716-
public async getProjectInfo(): Promise<ProjectInfoResponse> {
690+
public async projectGetInfo(): Promise<ProjectInfoResponse> {
717691
return this.makeConnectRequest<ProjectInfoResponse>("/projects/info", {
718692
method: "GET",
719693
});
@@ -784,7 +758,7 @@ export class BackendClient {
784758
* @example
785759
*
786760
* ```typescript
787-
* const response = await client.invokeWorkflow(
761+
* const response = await client.workflowInvoke(
788762
* "https://your-workflow-url.m.pipedream.net",
789763
* {
790764
* body: {
@@ -801,7 +775,7 @@ export class BackendClient {
801775
* console.log(response);
802776
* ```
803777
*/
804-
public async invokeWorkflow(urlOrEndpoint: string, opts: RequestOptions = {}, authType: HTTPAuthType = HTTPAuthType.None): Promise<unknown> {
778+
public async workflowInvoke(urlOrEndpoint: string, opts: RequestOptions = {}, authType: HTTPAuthType = HTTPAuthType.None): Promise<unknown> {
805779
const {
806780
body,
807781
headers = {},
@@ -870,7 +844,7 @@ export class BackendClient {
870844
* console.log(response);
871845
* ```
872846
*/
873-
public async invokeWorkflowForExternalUser(url: string, externalUserId: string, opts: RequestOptions = {}): Promise<unknown> {
847+
public async workflowInvokeForExternalUser(url: string, externalUserId: string, opts: RequestOptions = {}): Promise<unknown> {
874848
const { headers = {} } = opts;
875849

876850
if (!externalUserId) {
@@ -881,7 +855,7 @@ export class BackendClient {
881855
throw new Error("OAuth is required for invoking workflows for external users. Please pass credentials for a valid OAuth client");
882856
}
883857

884-
return this.invokeWorkflow(url, {
858+
return this.workflowInvoke(url, {
885859
...opts,
886860
headers: {
887861
...headers,

0 commit comments

Comments
 (0)