Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
<!-- markdownlint-disable MD024 -->
# 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
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
29 changes: 29 additions & 0 deletions packages/sdk/src/server/__tests__/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
16 changes: 15 additions & 1 deletion packages/sdk/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -600,9 +610,13 @@ export class BackendClient {
* console.log(account);
* ```
*/
public getAccountById(accountId: string): Promise<Account> {
public getAccountById(
accountId: string,
params: GetAccountByIdOpts = {},
): Promise<Account> {
return this.makeConnectRequest(`/accounts/${accountId}`, {
method: "GET",
params,
});
Comment on lines +613 to 620
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Update method documentation to reflect the new parameter.

The method implementation looks good, but the JSDoc comments need to be updated to:

  1. Document the new params parameter
  2. Add an example showing how to use include_credentials

Here's the suggested documentation update:

   /**
    * Retrieves a specific account by ID.
    *
    * @param accountId - The ID of the account to retrieve.
+   * @param params - Options for retrieving the account.
+   * @param params.include_credentials - Whether to include the account's credentials in the response.
    * @returns A promise resolving to the account.
    *
    * @example
    * ```typescript
    * const account = await client.getAccountById("account-id");
    * console.log(account);
    * ```
+   *
+   * @example
+   * ```typescript
+   * // Retrieve account with credentials
+   * const account = await client.getAccountById("account-id", { include_credentials: true });
+   * console.log(account.credentials);
+   * ```
    */

}

Expand Down
Loading