Skip to content

Commit 6cd6d9d

Browse files
authored
Retrieve credentials for a single account (#14657)
Accept the `include_credentials` parameter in the `getAccountById` method so that clients can retrieve the credentials of a single account.
1 parent 8b37319 commit 6cd6d9d

File tree

5 files changed

+54
-4
lines changed

5 files changed

+54
-4
lines changed

packages/sdk/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
<!-- markdownlint-disable MD024 -->
22
# Changelog
33

4+
## [1.0.3] - 2024-11-14
5+
6+
### Added
7+
8+
- Added a new argument to the `getAccountById` method in the backend client to
9+
allow the client to retrieve the credentials of the corresponding account.
10+
411
## [1.0.2] - 2024-11-14
512

613
### Changed

packages/sdk/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/sdk",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "Pipedream SDK",
55
"main": "dist/server/index.js",
66
"module": "dist/server/index.js",

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,35 @@ describe("BackendClient", () => {
352352
expect.any(Object),
353353
);
354354
});
355+
356+
it("should include credentials when the flag is set", async () => {
357+
fetchMock.mockResponseOnce(
358+
JSON.stringify({
359+
id: "account-1",
360+
name: "Test Account",
361+
credentials: {},
362+
}),
363+
{
364+
headers: {
365+
"Content-Type": "application/json",
366+
},
367+
},
368+
);
369+
370+
const result = await client.getAccountById("account-1", {
371+
include_credentials: true,
372+
});
373+
374+
expect(result).toEqual({
375+
id: "account-1",
376+
name: "Test Account",
377+
credentials: {},
378+
});
379+
expect(fetchMock).toHaveBeenCalledWith(
380+
`https://api.pipedream.com/v1/connect/${projectId}/accounts/account-1?include_credentials=true`,
381+
expect.any(Object),
382+
);
383+
});
355384
});
356385

357386
describe("Get accounts by app", () => {

packages/sdk/src/server/index.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,16 @@ export type GetAccountOpts = {
204204
include_credentials?: boolean;
205205
};
206206

207+
/**
208+
* Parameters for the retrieval of an account from the Connect API
209+
*/
210+
export type GetAccountByIdOpts = {
211+
/**
212+
* Whether to retrieve the account's credentials or not.
213+
*/
214+
include_credentials?: boolean;
215+
};
216+
207217
/**
208218
* End user account data, returned from the API.
209219
*/
@@ -600,9 +610,13 @@ export class BackendClient {
600610
* console.log(account);
601611
* ```
602612
*/
603-
public getAccountById(accountId: string): Promise<Account> {
613+
public getAccountById(
614+
accountId: string,
615+
params: GetAccountByIdOpts = {},
616+
): Promise<Account> {
604617
return this.makeConnectRequest(`/accounts/${accountId}`, {
605618
method: "GET",
619+
params,
606620
});
607621
}
608622

0 commit comments

Comments
 (0)