From 7f79e0a3a59e502578076c5534a5a8fd7ba5b8e8 Mon Sep 17 00:00:00 2001 From: Jay Vercellone Date: Thu, 14 Nov 2024 14:49:24 -0800 Subject: [PATCH] Retrieve credentials for a single account Accept the `include_credentials` parameter in the `getAccountById` method so that clients can retrieve the credentials of a single account. --- packages/sdk/CHANGELOG.md | 7 +++++ packages/sdk/package-lock.json | 4 +-- packages/sdk/package.json | 2 +- .../sdk/src/server/__tests__/server.test.ts | 29 +++++++++++++++++++ packages/sdk/src/server/index.ts | 16 +++++++++- 5 files changed, 54 insertions(+), 4 deletions(-) diff --git a/packages/sdk/CHANGELOG.md b/packages/sdk/CHANGELOG.md index de87a18edcd2d..94ae6cff02d47 100644 --- a/packages/sdk/CHANGELOG.md +++ b/packages/sdk/CHANGELOG.md @@ -1,6 +1,13 @@ # Changelog +## [1.0.3] - 2024-11-14 + +### Added + +- Added a new argument to the `getAccountById` method in the backend client to + allow the client to retrieve the credentials of the corresponding account. + ## [1.0.2] - 2024-11-14 ### Changed diff --git a/packages/sdk/package-lock.json b/packages/sdk/package-lock.json index b7c59eef29b5d..0d2ba982c6373 100644 --- a/packages/sdk/package-lock.json +++ b/packages/sdk/package-lock.json @@ -1,12 +1,12 @@ { "name": "@pipedream/sdk", - "version": "1.0.2", + "version": "1.0.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@pipedream/sdk", - "version": "1.0.2", + "version": "1.0.3", "license": "SEE LICENSE IN LICENSE", "dependencies": { "simple-oauth2": "^5.1.0" diff --git a/packages/sdk/package.json b/packages/sdk/package.json index e56bb2c947e0a..33ad516fb8835 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/sdk", - "version": "1.0.2", + "version": "1.0.3", "description": "Pipedream SDK", "main": "dist/server/index.js", "module": "dist/server/index.js", diff --git a/packages/sdk/src/server/__tests__/server.test.ts b/packages/sdk/src/server/__tests__/server.test.ts index d89e4fc6d0705..9aa9c1081032f 100644 --- a/packages/sdk/src/server/__tests__/server.test.ts +++ b/packages/sdk/src/server/__tests__/server.test.ts @@ -352,6 +352,35 @@ describe("BackendClient", () => { expect.any(Object), ); }); + + it("should include credentials when the flag is set", async () => { + fetchMock.mockResponseOnce( + JSON.stringify({ + id: "account-1", + name: "Test Account", + credentials: {}, + }), + { + headers: { + "Content-Type": "application/json", + }, + }, + ); + + const result = await client.getAccountById("account-1", { + include_credentials: true, + }); + + expect(result).toEqual({ + id: "account-1", + name: "Test Account", + credentials: {}, + }); + expect(fetchMock).toHaveBeenCalledWith( + `https://api.pipedream.com/v1/connect/${projectId}/accounts/account-1?include_credentials=true`, + expect.any(Object), + ); + }); }); describe("Get accounts by app", () => { diff --git a/packages/sdk/src/server/index.ts b/packages/sdk/src/server/index.ts index 0616c32fefb21..cf88843f7df8f 100644 --- a/packages/sdk/src/server/index.ts +++ b/packages/sdk/src/server/index.ts @@ -204,6 +204,16 @@ export type GetAccountOpts = { include_credentials?: boolean; }; +/** + * Parameters for the retrieval of an account from the Connect API + */ +export type GetAccountByIdOpts = { + /** + * Whether to retrieve the account's credentials or not. + */ + include_credentials?: boolean; +}; + /** * End user account data, returned from the API. */ @@ -600,9 +610,13 @@ export class BackendClient { * console.log(account); * ``` */ - public getAccountById(accountId: string): Promise { + public getAccountById( + accountId: string, + params: GetAccountByIdOpts = {}, + ): Promise { return this.makeConnectRequest(`/accounts/${accountId}`, { method: "GET", + params, }); }