Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend request improvements #14642

Conversation

jverce
Copy link
Contributor

@jverce jverce commented Nov 13, 2024

Changelog

  • Add the fullResponse flag as an option for makeRequest to return the raw HTTP response
  • Deprecate the environment_name field when creating a Connect token, in favour of the environment name in the client's constructor

WHY

To provide customers with more flexibility when making requests against the Connect API.

Summary by CodeRabbit

  • New Features

    • Introduced an optional fullResponse property in the RequestOptions interface, allowing users to receive complete HTTP response objects.
    • Deprecated the environment_name field in ConnectTokenOpts, streamlining the configuration process for connect tokens.
  • Bug Fixes

    • Adjusted error handling in the makeRequest method to support the new fullResponse functionality.
  • Chores

    • Updated the version number of the @pipedream/sdk package to 1.0.2.

* Add the `fullResponse` flag as an option for `makeRequest` to return
  the raw HTTP response
* Deprecate the `environment_name` field when creating a Connect token,
  in favour of the `environment` name in the client's constructor
@jverce jverce added enhancement New feature or request pd-api Pipedream API requests javascript Pull requests that update Javascript code tracked internally Issue is also tracked in our internal issue tracker prioritized Prioritized issue labels Nov 13, 2024
@jverce jverce self-assigned this Nov 13, 2024
Copy link

vercel bot commented Nov 13, 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 5:04pm

Copy link

vercel bot commented Nov 13, 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 13, 2024

Walkthrough

The pull request includes updates to the @pipedream/sdk package's package.json file, changing the version from "1.0.1" to "1.0.2". The index.ts file in the packages/sdk/src/server directory has been modified to enhance the RequestOptions interface with a new optional property, fullResponse, and to deprecate the environment_name field in the ConnectTokenOpts type in favor of the environment field. The changelog has also been updated to reflect these changes and provide context for the version increment.

Changes

File Path Change Summary
packages/sdk/package.json Updated version from "1.0.1" to "1.0.2".
packages/sdk/src/server/index.ts Added fullResponse property to RequestOptions interface; deprecated environment_name in ConnectTokenOpts.
packages/sdk/CHANGELOG.md Updated version to 1.0.2, noted deprecation of environment_name, and added fullResponse flag.

Possibly related PRs

Suggested labels

dependencies, strategic-app

Suggested reviewers

  • dylburger

Poem

In the code, a change so bright,
A version bump, a new delight.
With options wide, the requests can flow,
Full responses now, watch them glow!
Deprecated fields, we bid adieu,
A cleaner path for me and you! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 90b5658 and f25f4b0.

⛔ Files ignored due to path filters (1)
  • packages/sdk/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • packages/sdk/CHANGELOG.md (1 hunks)
  • packages/sdk/package.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/sdk/CHANGELOG.md
  • packages/sdk/package.json

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: 0

🧹 Outside diff range and nitpick comments (2)
packages/sdk/src/server/index.ts (2)

298-305: LGTM! Well-documented feature addition.

The fullResponse option is well-documented, with clear explanation of its behavior and implications for error handling. Consider adding a code example in the documentation to demonstrate the difference in error handling between fullResponse: true and false.

Example addition to the documentation:

   * code in the response object. Defaults to false.
   */
  fullResponse?: boolean;
+  /**
+   * @example
+   * ```typescript
+   * // With fullResponse: false (default)
+   * try {
+   *   const result = await client.makeRequest('/api/data');
+   *   // result contains parsed response body
+   * } catch (error) {
+   *   // error thrown for non-200 responses
+   * }
+   * 
+   * // With fullResponse: true
+   * const response = await client.makeRequest('/api/data', { fullResponse: true });
+   * if (!response.ok) {
+   *   // handle error case
+   * }
+   * const data = await response.json();
+   * ```
+   */

Line range hint 436-489: Improve type safety for fullResponse option.

While the implementation works, the current type casting approach might hide type errors. Consider using a generic type parameter with a conditional type to provide better type safety.

Here's a suggested improvement:

-  public async makeRequest<T>(
+  public async makeRequest<T, R = T>(
     path: string,
-    opts: RequestOptions = {},
+    opts: RequestOptions & { fullResponse?: false } | RequestOptions & { fullResponse: true },
-  ): Promise<T> {
+  ): Promise<opts extends { fullResponse: true } ? Response : T> {
     const {
       params,
       headers: customHeaders,
       body,
       method = "GET",
       baseURL = this.baseApiUrl,
       fullResponse = false,
       ...fetchOpts
     } = opts;

     // ... rest of the implementation ...

     const response: Response = await fetch(url.toString(), requestOptions);
     if (fullResponse) {
-      return response as unknown as T;
+      return response as any; // Type assertion needed due to TypeScript limitations
     }

     // ... rest of the implementation ...
   }

This change will:

  1. Provide proper type hints to TypeScript users
  2. Make it clear that fullResponse: true returns a Response object
  3. Maintain type safety for the default case
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 70aca9e and eb039dd.

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

90-92: LGTM! Clear deprecation notice.

The deprecation message clearly indicates that users should use the environment field in BackendClientOpts instead, and explicitly states that this field is ignored.

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: 0

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

8-11: Consider adding a migration example.

The deprecation notice is clear but would benefit from a brief example showing how to migrate from environment_name to using environment in the client constructor.

Example addition:

  is no longer used by the SDK nor the Connect API. The environment name is now
  exclusively determined by the `environment` field in the `BackendClientOpts`
  type, read during the client creation.
+ 
+ Migration example:
+ ```typescript
+ // Before
+ const token = await client.createConnectToken({ environment_name: 'prod' });
+ 
+ // After
+ const client = new BackendClient({ environment: 'prod' });
+ const token = await client.createConnectToken();
+ ```

15-17: Consider adding a usage example and response type details.

While the new feature is well documented, it would be more helpful with a usage example and specific details about the response type.

Example addition:

  allows the user to get the full HTTP response object, including the headers
  and status code.
+
+ Example:
+ ```typescript
+ // Before
+ const data = await client.makeRequest('/api/v1/resource');
+ 
+ // After
+ const response = await client.makeRequest('/api/v1/resource', { fullResponse: true });
+ console.log(response.status); // 200
+ console.log(response.headers); // Response headers
+ console.log(response.data);   // Response body
+ ```
+
+ The full response object follows the standard HTTP response interface with:
+ - `status`: number
+ - `headers`: Record<string, string>
+ - `data`: any
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between eb039dd and 90b5658.

📒 Files selected for processing (1)
  • packages/sdk/CHANGELOG.md (1 hunks)
🔇 Additional comments (1)
packages/sdk/CHANGELOG.md (1)

4-5: LGTM! Version bump follows semver.

The version increment to 1.0.1 is appropriate for these backward-compatible changes.

@jverce jverce merged commit d77b45c into PipedreamHQ:master Nov 14, 2024
11 of 12 checks passed
@jverce jverce deleted the jay/dj-2654-return-full-fetch-response-in-makerequest-method-from-sdk branch November 14, 2024 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request javascript Pull requests that update Javascript code pd-api Pipedream API requests prioritized Prioritized issue 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