Skip to content

Conversation

jverce
Copy link
Contributor

@jverce jverce commented Nov 14, 2024

Description

Accept the include_credentials parameter in the getAccountById method so that clients can retrieve the credentials of a single account.

Summary by CodeRabbit

  • New Features

    • Introduced an optional parameter in the getAccountById method to include associated credentials in the response.
    • Added a new flag, fullResponse, to RequestOptions for receiving complete HTTP response details.
  • Bug Fixes

    • Deprecated the environment_name field, streamlining environment determination.
  • Documentation

    • Updated changelog and method documentation to reflect new features and changes.
  • Tests

    • Enhanced test coverage for the getAccountById method, including scenarios for credential retrieval.

Accept the `include_credentials` parameter in the `getAccountById`
method so that clients can retrieve the credentials of a single
account.
@jverce jverce added bug Something isn't working javascript Pull requests that update Javascript code tracked internally Issue is also tracked in our internal issue tracker labels Nov 14, 2024
@jverce jverce self-assigned this Nov 14, 2024
Copy link

vercel bot commented Nov 14, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
pipedream-docs-redirect-do-not-edit ⬜️ Ignored (Inspect) Nov 14, 2024 10:58pm

Copy link

vercel bot commented Nov 14, 2024

@jverce is attempting to deploy a commit to the Pipedreamers Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Nov 14, 2024

Walkthrough

The pull request introduces several changes to the SDK, including a new version entry (1.0.3) in the changelog. Key modifications include an updated method signature for getAccountById in the BackendClient, which now accepts an optional argument for including account credentials. The environment_name field in the ConnectTokenOpts type has been deprecated, while a new fullResponse flag has been added to RequestOptions. Additionally, test cases have been updated to validate the new functionality.

Changes

File Path Change Summary
packages/sdk/CHANGELOG.md Updated to version 1.0.3, documenting changes including new getAccountById argument, deprecation of environment_name, and addition of fullResponse flag.
packages/sdk/package.json Version updated from 1.0.2 to 1.0.3.
packages/sdk/src/server/tests/server.test.ts Added test case for getAccountById with include_credentials parameter; updated method signature in tests.
packages/sdk/src/server/index.ts Introduced GetAccountByIdOpts type; updated getAccountById method to accept new parameters and modified documentation accordingly.

Possibly related PRs

  • Abstract OAuth implementation in the SDK #13983: This PR enhances the ServerClient class and introduces OAuth capabilities, which is relevant to the changes in the BackendClient class in the main PR that also deals with authentication and client methods.
  • Backend request improvements #14642: This PR introduces the fullResponse option in the makeRequest function and deprecates the environment_name field, which directly relates to the changes in the main PR regarding the same fields and functionality.

Suggested labels

enhancement, pd-api, prioritized

Suggested reviewers

  • dylburger
  • jcortes

🐇 In the code, we hop and play,
New features come out to brighten the day!
With credentials now in sight,
Our methods shine so bright!
Changelog updated, tests in line,
Hooray for progress, oh how divine! 🎉


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (2)
packages/sdk/CHANGELOG.md (1)

8-9: Enhance the changelog entry with more specific details.

The changelog entry could be more specific about the new parameter. Consider revising to include:

  • The parameter name (include_credentials)
  • That it's an optional parameter
  • The parameter type (boolean)
- Added a new argument to the `getAccountById` method in the backend client to
-   allow the client to retrieve the credentials of the corresponding account.
+ Added an optional boolean parameter `include_credentials` to the `getAccountById`
+   method in the backend client to allow retrieving account credentials when needed.
packages/sdk/src/server/__tests__/server.test.ts (1)

356-383: Test implementation looks good, but coverage could be improved.

The test case effectively verifies the basic functionality of the include_credentials flag. However, consider adding the following test cases for better coverage:

  1. Edge cases for credentials field (null/undefined)
  2. Error scenarios (e.g., unauthorized access to credentials)

Here's a suggested implementation of additional test cases:

it("should handle null credentials in response", async () => {
  fetchMock.mockResponseOnce(
    JSON.stringify({
      id: "account-1",
      name: "Test Account",
      credentials: null,
    }),
    {
      headers: {
        "Content-Type": "application/json",
      },
    },
  );

  const result = await client.getAccountById("account-1", {
    include_credentials: true,
  });

  expect(result.credentials).toBeNull();
});

it("should handle unauthorized access to credentials", async () => {
  fetchMock.mockResponseOnce(
    JSON.stringify({
      error: "Unauthorized access to credentials",
    }),
    {
      status: 403,
      headers: {
        "Content-Type": "application/json",
      },
    },
  );

  await expect(
    client.getAccountById("account-1", {
      include_credentials: true,
    })
  ).rejects.toThrow("HTTP error! status: 403");
});
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 8b37319 and 7f79e0a.

⛔ Files ignored due to path filters (1)
  • packages/sdk/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (4)
  • packages/sdk/CHANGELOG.md (1 hunks)
  • packages/sdk/package.json (1 hunks)
  • packages/sdk/src/server/__tests__/server.test.ts (1 hunks)
  • packages/sdk/src/server/index.ts (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/sdk/package.json
🔇 Additional comments (2)
packages/sdk/CHANGELOG.md (1)

4-4: Verify version release dates.

Both versions 1.0.2 and 1.0.3 are dated 2024-11-14. Please verify if these versions should be released on the same date or if one of the dates needs to be adjusted.

Also applies to: 10-10

✅ Verification successful

Based on the git history output, I can now generate a final response:

Both version dates are correct - these are separate releases on the same day

The git history confirms that both version 1.0.2 and 1.0.3 were legitimately released on 2024-11-14:

  • Version 1.0.2 introduced changes related to deprecating environment_name and adding fullResponse flag
  • Version 1.0.3 added new functionality to getAccountById method

Having multiple releases on the same day is valid when different features or changes need to be published separately.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check git history for version bumps to verify dates

# Look for version number changes in package.json
git log -p -- "packages/sdk/package.json" | grep -A 5 -B 5 "version"

# Look for previous changelog entries
git log -p -- "packages/sdk/CHANGELOG.md" | grep -A 5 -B 5 "\[1\.0\."

Length of output: 1848

packages/sdk/src/server/index.ts (1)

207-215: LGTM! Clean type definition with clear documentation.

The new GetAccountByIdOpts type is well-structured and consistent with the codebase's patterns.

Comment on lines +613 to 620
public getAccountById(
accountId: string,
params: GetAccountByIdOpts = {},
): Promise<Account> {
return this.makeConnectRequest(`/accounts/${accountId}`, {
method: "GET",
params,
});
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);
+   * ```
    */

@jverce jverce merged commit 6cd6d9d into PipedreamHQ:master Nov 14, 2024
11 of 12 checks passed
@jverce jverce deleted the fix/get-credentials-for-single-account branch November 14, 2024 23:11
lcaresia pushed a commit that referenced this pull request Dec 3, 2024
Accept the `include_credentials` parameter in the `getAccountById`
method so that clients can retrieve the credentials of a single
account.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working javascript Pull requests that update Javascript code tracked internally Issue is also tracked in our internal issue tracker
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants