Skip to content

Je/add scopes to connect sdk #17452

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Conversation

jsendo
Copy link
Contributor

@jsendo jsendo commented Jul 3, 2025

WHY

Summary by CodeRabbit

  • Chores

    • Added missing newline characters at the end of several component files for consistency.
    • Updated the SDK package version to 1.7.0 and added a corresponding changelog entry.
  • New Features

    • Introduced support for specifying OAuth scopes in the SDK when creating a backend client.
    • Added a method to indicate if a static access token is used in the backend client.
  • Bug Fixes

    • Enhanced error handling and diagnostics for OAuth token retrieval in the SDK.

Copy link

vercel bot commented Jul 3, 2025

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

3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
docs-v2 ⬜️ Ignored (Inspect) Visit Preview Jul 3, 2025 9:49pm
pipedream-docs ⬜️ Ignored (Inspect) Jul 3, 2025 9:49pm
pipedream-docs-redirect-do-not-edit ⬜️ Ignored (Inspect) Jul 3, 2025 9:49pm

Copy link
Contributor

coderabbitai bot commented Jul 3, 2025

Walkthrough

This update introduces an optional scope parameter to the BackendClient in the SDK, refines OAuth token retrieval logic with improved error handling, and documents these changes in the changelog and version bump. Additionally, several component files receive a newline character at the end of the file, with no functional code changes.

Changes

Files Change Summary
components/bitget/bitget.app.mjs
components/explorium/explorium.app.mjs
components/hana/hana.app.mjs
components/indiefunnels/indiefunnels.app.mjs
components/joggai/joggai.app.mjs
components/mumble/mumble.app.mjs
components/sign_plus/sign_plus.app.mjs
components/webscrape_ai/webscrape_ai.app.mjs
Added a newline character at end of file; no code or functional changes.
packages/sdk/CHANGELOG.md Added changelog entry for version 1.7.0, documenting the new scope parameter for backendClient.
packages/sdk/package.json Updated version from 1.6.11 to 1.7.0.
packages/sdk/src/server/index.ts Added optional scope to BackendClientOpts, new isStaticAccessToken() method, improved OAuth logic & errors.
packages/sdk/src/shared/index.ts Extended ErrorResponse type with optional wwwAuthenticate and headers fields.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant BackendClient
    participant OAuthServer

    User->>BackendClient: Create BackendClient({ scope })
    BackendClient->>OAuthServer: Request token (with optional scope)
    OAuthServer-->>BackendClient: Respond with token or error
    alt Token retrieval fails (up to 3 attempts)
        BackendClient->>OAuthServer: Retry with scope
        OAuthServer-->>BackendClient: Respond with error (status, www-authenticate)
        BackendClient-->>User: Throw detailed error
    else Token retrieval succeeds
        BackendClient-->>User: Return token
    end
Loading

Poem

A hop, a skip, a scope anew,
The backend client knows what to do!
With tokens fetched and errors clear,
The changelog marks a brand new year.
A newline here, a version bump there—
Rabbits code with thoughtful care!
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/sdk/src/server/index.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'jsonc-eslint-parser' imported from /eslint.config.mjs
at Object.getPackageJSONURL (node:internal/modules/package_json_reader:255:9)
at packageResolve (node:internal/modules/esm/resolve:767:81)
at moduleResolve (node:internal/modules/esm/resolve:853:18)
at defaultResolve (node:internal/modules/esm/resolve:983:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:801:12)
at #cachedDefaultResolve (node:internal/modules/esm/loader:725:25)
at ModuleLoader.resolve (node:internal/modules/esm/loader:708:38)
at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:309:38)
at #link (node:internal/modules/esm/module_job:202:49)


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 90f4f85 and dcb774a.

📒 Files selected for processing (1)
  • packages/sdk/src/server/index.ts (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/sdk/src/server/index.ts
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Publish TypeScript components
  • GitHub Check: Verify TypeScript components
  • GitHub Check: test
  • GitHub Check: Lint Code Base
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

@pipedream-component-development
Copy link
Collaborator

Thank you so much for submitting this! We've added it to our backlog to review, and our team has been notified.

@pipedream-component-development
Copy link
Collaborator

Thanks for submitting this PR! When we review PRs, we follow the Pipedream component guidelines. If you're not familiar, here's a quick checklist:

@jsendo jsendo requested a review from jverce July 3, 2025 20:18
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: 2

🧹 Nitpick comments (3)
packages/sdk/src/server/index.ts (3)

59-64: OAuth scope implementation looks good.

The scope parameter is correctly implemented as an optional string array and properly passed to the OAuth token request. Consider adding validation for scope values in the future to ensure they match expected formats.

Also applies to: 205-205, 218-218, 311-313


305-308: Consider increasing the retry delay.

A 100ms delay between OAuth token request retries might be too short, especially if the OAuth server is experiencing temporary issues.

-          await new Promise((resolve) => setTimeout(resolve, 100));
+          await new Promise((resolve) => setTimeout(resolve, 500 + attempts * 500)); // Progressive backoff

336-352: Improve type safety in error handling.

The error handling uses (e as any) which bypasses TypeScript's type checking. Consider defining a proper error type or using type guards.

-          if (e && typeof e === 'object' && 'response' in e) {
-            const errorResponse = (e as any).response;
+          interface OAuthError extends Error {
+            response?: {
+              status?: number;
+              headers?: Headers | Record<string, string>;
+            };
+          }
+          
+          if (e && typeof e === 'object' && 'response' in e) {
+            const errorResponse = (e as OAuthError).response;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bea9956 and 4192b82.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (12)
  • components/bitget/bitget.app.mjs (1 hunks)
  • components/explorium/explorium.app.mjs (1 hunks)
  • components/hana/hana.app.mjs (1 hunks)
  • components/indiefunnels/indiefunnels.app.mjs (1 hunks)
  • components/joggai/joggai.app.mjs (1 hunks)
  • components/mumble/mumble.app.mjs (1 hunks)
  • components/sign_plus/sign_plus.app.mjs (1 hunks)
  • components/webscrape_ai/webscrape_ai.app.mjs (1 hunks)
  • packages/sdk/CHANGELOG.md (1 hunks)
  • packages/sdk/package.json (1 hunks)
  • packages/sdk/src/server/index.ts (5 hunks)
  • packages/sdk/src/shared/index.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
packages/sdk/package.json (1)
Learnt from: jcortes
PR: PipedreamHQ/pipedream#14935
File: components/sailpoint/package.json:15-18
Timestamp: 2024-12-12T19:23:09.039Z
Learning: When developing Pipedream components, do not add built-in Node.js modules like `fs` to `package.json` dependencies, as they are native modules provided by the Node.js runtime.
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: pnpm publish
  • GitHub Check: test
  • GitHub Check: Publish TypeScript components
  • GitHub Check: Verify TypeScript components
  • GitHub Check: Lint Code Base
🔇 Additional comments (11)
components/joggai/joggai.app.mjs (1)

11-11: Trailing newline added – LGTM

Adding a newline at EOF brings the file in line with POSIX conventions and prevents unnecessary diffs in future edits. No functional impact.

components/webscrape_ai/webscrape_ai.app.mjs (1)

11-11: Consistent EOF newline – looks good

The added newline improves formatting consistency across the codebase. No further action needed.

components/sign_plus/sign_plus.app.mjs (1)

11-11: EOF newline addition – approved

Maintains standard formatting; no logical changes introduced.

components/hana/hana.app.mjs (1)

11-11: Formatting fix acknowledged

Trailing newline ensures clean diffs and editor compatibility. All good here.

components/indiefunnels/indiefunnels.app.mjs (1)

11-11: EOF newline – fine

Keeps formatting uniform; nothing else to note.

components/explorium/explorium.app.mjs (1)

11-11: Trailing newline LGTM

Consistent newline at EOF improves POSIX-tool compatibility and aligns with repo formatting conventions.

components/bitget/bitget.app.mjs (1)

11-11: EOF newline added – all good

Keeps formatting uniform with the rest of the codebase.

components/mumble/mumble.app.mjs (1)

11-11: Formatting only, no functional impact

Nothing else to add.

packages/sdk/CHANGELOG.md (1)

5-10: Changelog entry clear and matches implementation

Version 1.7.0 notes the new optional scope parameter—concise and complete. ✔️

packages/sdk/package.json (1)

4-4: Version bump matches changelog

Package version updated to 1.7.0; no other metadata changes. Synchronization looks correct.

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

868-876: LGTM! Useful additions for enhanced error diagnostics.

The new optional properties wwwAuthenticate and headers on the ErrorResponse type will help capture important error context from HTTP responses, particularly useful for OAuth authentication flows.

Comment on lines 301 to +304
const maxAttempts = 2;

while (!this.oauthAccessToken || this.oauthAccessToken.expiresAt - Date.now() < 1000) {
if (attempts > maxAttempts) {
throw new Error("ran out of attempts trying to retrieve oauth access token");
}
if (attempts > 0) {
// Wait for a short duration before retrying to avoid rapid retries
await new Promise((resolve) => setTimeout(resolve, 100));
for (let attempts = 0; attempts <= maxAttempts; attempts++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Clarify the retry attempt count.

The variable is named maxAttempts = 2 but the loop condition attempts <= maxAttempts means it will actually attempt 3 times (0, 1, 2). This is confusing.

Either rename the variable or adjust the loop condition:

-    const maxAttempts = 2;
+    const maxAttempts = 3; // Total attempts including the initial one

Or:

-      for (let attempts = 0; attempts <= maxAttempts; attempts++) {
+      for (let attempts = 0; attempts < maxAttempts; attempts++) {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const maxAttempts = 2;
while (!this.oauthAccessToken || this.oauthAccessToken.expiresAt - Date.now() < 1000) {
if (attempts > maxAttempts) {
throw new Error("ran out of attempts trying to retrieve oauth access token");
}
if (attempts > 0) {
// Wait for a short duration before retrying to avoid rapid retries
await new Promise((resolve) => setTimeout(resolve, 100));
for (let attempts = 0; attempts <= maxAttempts; attempts++) {
const maxAttempts = 2;
while (!this.oauthAccessToken || this.oauthAccessToken.expiresAt - Date.now() < 1000) {
for (let attempts = 0; attempts < maxAttempts; attempts++) {
🤖 Prompt for AI Agents
In packages/sdk/src/server/index.ts around lines 301 to 304, the retry loop uses
maxAttempts = 2 but the loop condition attempts <= maxAttempts causes three
attempts (0, 1, 2), which is confusing. To fix this, either rename maxAttempts
to maxAttemptIndex or change the loop condition to attempts < maxAttempts so the
number of attempts matches the variable name and intent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants