Skip to content

Conversation

@jverce
Copy link
Contributor

@jverce jverce commented Jan 24, 2025

Changelog

  • Add missing SDK examples for the triggers API
  • Document the deployed trigger events API
  • Document the new endpoints to manipulate listeners of a deployed trigger

WHY

To keep the docs up to date.

Summary by CodeRabbit

  • Documentation
    • Enhanced Pipedream Connect API documentation with comprehensive guides for:
      • Retrieving events emitted by deployed triggers
      • Listing and updating webhooks associated with deployed triggers
      • Retrieving and updating workflows linked to deployed triggers
      • Included TypeScript, JavaScript, and cURL examples for new methods
  • Chores
    • Updated the version of the @pipedream/sdk package from 1.2.0 to 1.2.1.
    • Updated changelog to reflect new version and type additions.
    • Introduced new types for API paginated responses and prop configuration options.

* Add missing SDK examples for the triggers API
* Document the deployed trigger events API
* Document the new endpoints to manipulate listeners of a deployed
  trigger
@jverce jverce added enhancement New feature or request docs javascript Pull requests that update Javascript code tracked internally Issue is also tracked in our internal issue tracker prioritized Prioritized issue labels Jan 24, 2025
@jverce jverce self-assigned this Jan 24, 2025
@vercel
Copy link

vercel bot commented Jan 24, 2025

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

2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
docs-v2 ⬜️ Ignored (Inspect) Visit Preview Jan 27, 2025 7:59pm
pipedream-docs-redirect-do-not-edit ⬜️ Ignored (Inspect) Jan 27, 2025 7:59pm

@vercel
Copy link

vercel bot commented Jan 24, 2025

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

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 24, 2025

Walkthrough

This pull request enhances the Pipedream Connect API documentation by introducing methods for managing deployed triggers. It includes detailed guidance and examples for retrieving and updating information related to deployed triggers, such as their emitted events, associated webhooks, and workflows. The changes also introduce new types and interfaces to support the updated functionality, ensuring clarity and usability for developers.

Changes

File Change Summary
docs-v2/pages/connect/api.mdx Added 5 new methods to PipedreamClient:
- getTriggerEvents(): Retrieve last events emitted by a deployed trigger.
- getTriggerWebhooks(): List webhook URLs associated with a deployed trigger.
- updateTriggerWebhooks(): Modify webhook URLs for a deployed trigger.
- getTriggerWorkflows(): Retrieve workflow IDs associated with a deployed trigger.
- updateTriggerWorkflows(): Update workflows listening to a deployed trigger.
packages/sdk/CHANGELOG.md Updated changelog to version [1.2.1], added new types for API paginated responses and prop configuration options, and corrected method signatures for trigger retrieval.
packages/sdk/package.json Updated version of @pipedream/sdk from 1.2.0 to 1.2.1.
packages/sdk/src/shared/index.ts Added new types: PropOption, ResponsePageInfo, PaginationResponse, DeployTriggerResponse, GetTriggerResponse, GetTriggersResponse. Updated return types for methods related to triggers.

Possibly related PRs

  • update connect API docs  #13145: This PR updates the documentation for the Connect API, which is directly related to the changes made in the main PR that enhance the Connect API documentation, particularly around deployed triggers.
  • Document the Connect component API #14931: This PR documents the Connect component API, which is relevant to the main PR's updates on the Connect API and its methods for managing triggers.
  • Rev to component docs for Connect #14983: This PR updates the Connect API documentation to include new endpoints for managing deployed triggers, directly related to the changes in the main PR.

Poem

🐰 Triggers dancing, API so bright,
Methods hopping with technical might!
List, delete, webhook's sweet embrace,
Connect's power now shows its grace.
Rabbit's code hops with pure delight! 🚀


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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: 2

🧹 Nitpick comments (9)
docs-v2/pages/connect/api.mdx (9)

2062-2085: Consider demonstrating error handling for a more robust example.
This snippet effectively illustrates how to list deployed triggers. However, adding a quick try/catch or promise rejection handling example in the documentation would help developers understand how best to manage unexpected errors.


2088-2109: Consider demonstrating error handling for a more robust example.
This snippet effectively illustrates how to list deployed triggers in Node.js code. However, adding a quick try/catch or error-handling snippet would help users manage HTTP or network failures gracefully.


2306-2355: Consider demonstrating error handling for a more robust example.
The snippet for retrieving a single deployed trigger is correct. Demonstrating how to handle errors (e.g., a missing trigger) would provide additional clarity and completeness.


2480-2527: Consider demonstrating error handling for a more robust example.
The snippet for deleting a deployed trigger is concise and clear. Providing minimal error handling guidance (e.g., checking for invalid IDs) would strengthen the example.


2588-2637: Consider demonstrating error handling for a more robust example.
The snippet for retrieving emitted events is straightforward. Showing how to handle scenarios when no events are found or network errors occur would make it more comprehensive.


2772-2817: Consider demonstrating error handling for a more robust example.
Retrieving webhooks listening to a deployed trigger appears to work well. An example that handles missing triggers or permission errors would be beneficial.


2886-2914: Consider demonstrating error handling for a more robust example.
The code for updating webhooks is accurate. Including a quick snippet on dealing with invalid webhook URLs or network errors would help users build robust applications.


2917-2945: Consider demonstrating error handling for a more robust example.
Similarly, this Node.js snippet for updating webhooks is correct. Adding advice on how to handle any unexpected response from the server would improve usability.


3008-3053: Consider demonstrating error handling for a more robust example.
This snippet for retrieving workflows listening to a trigger is functionally correct. Including error handling (e.g., dealing with invalid workflow IDs) would make the example more robust.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 29d795a and a6cc97e.

📒 Files selected for processing (1)
  • docs-v2/pages/connect/api.mdx (6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Lint Code Base
  • GitHub Check: validate-links

Comment on lines 3156 to 3184
```javascript
import {
createBackendClient,
} from "@pipedream/sdk/server";

const pd = createBackendClient({
environment: "development", // change to production if running for a test production account, or in production
credentials: {
clientId: "{oauth_client_id}",
clientSecret: "{oauth_client_secret}",
},
projectId: "{your_project_id}"
});

// The new list of workflow IDs that will listen to the deployed trigger
const workflowIds = [
"p_ERRCzw",
"p_2LniLm",
];

// Update the list of workflows listening to the deployed trigger
const { workflow_ids: confirmedIds } = await pd.updateTriggerWorkflows({
id: "dc_gzumK2e",
externalUserId: "jverce",
webhookUrls,
});

// `workflowIds` will match `confirmedIds` if the update was successful
```
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

Fix incorrect parameter name for updating workflows.
This Node.js version of the same snippet also contains the same mismatch (webhookUrls instead of workflowIds). Replace the incorrect reference to avoid runtime errors.

Apply this diff to correct the code:

-const { workflow_ids: confirmedIds } = await pd.updateTriggerWorkflows({
-  id: "dc_gzumK2e",
-  externalUserId: "jverce",
-  webhookUrls,
-});
+const { workflow_ids: confirmedIds } = await pd.updateTriggerWorkflows({
+  id: "dc_gzumK2e",
+  externalUserId: "jverce",
+  workflowIds,
+});

Comment on lines 3123 to 3152
<Tabs.Tab>
```typescript
import {
createBackendClient,
} from "@pipedream/sdk/server";

const pd = createBackendClient({
environment: "development", // change to production if running for a test production account, or in production
credentials: {
clientId: "{oauth_client_id}",
clientSecret: "{oauth_client_secret}",
},
projectId: "{your_project_id}"
});

// The new list of workflow IDs that will listen to the deployed trigger
const workflowIds = [
"p_ERRCzw",
"p_2LniLm",
];

// Update the list of workflows listening to the deployed trigger
const { workflow_ids: confirmedIds } = await pd.updateTriggerWorkflows({
id: "dc_gzumK2e",
externalUserId: "jverce",
webhookUrls,
});

// `workflowIds` will match `confirmedIds` if the update was successful
```
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

Fix incorrect parameter name for updating workflows.
In this snippet, the code mistakenly passes webhookUrls instead of workflowIds, which will cause a runtime error. Use workflowIds to match the method signature and variable name.

Apply this diff to correct the code:

-const { workflow_ids: confirmedIds } = await pd.updateTriggerWorkflows({
-  id: "dc_gzumK2e",
-  externalUserId: "jverce",
-  webhookUrls,
-});
+const { workflow_ids: confirmedIds } = await pd.updateTriggerWorkflows({
+  id: "dc_gzumK2e",
+  externalUserId: "jverce",
+  workflowIds,
+});
📝 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
<Tabs.Tab>
```typescript
import {
createBackendClient,
} from "@pipedream/sdk/server";
const pd = createBackendClient({
environment: "development", // change to production if running for a test production account, or in production
credentials: {
clientId: "{oauth_client_id}",
clientSecret: "{oauth_client_secret}",
},
projectId: "{your_project_id}"
});
// The new list of workflow IDs that will listen to the deployed trigger
const workflowIds = [
"p_ERRCzw",
"p_2LniLm",
];
// Update the list of workflows listening to the deployed trigger
const { workflow_ids: confirmedIds } = await pd.updateTriggerWorkflows({
id: "dc_gzumK2e",
externalUserId: "jverce",
webhookUrls,
});
// `workflowIds` will match `confirmedIds` if the update was successful
```
<Tabs.Tab>

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

♻️ Duplicate comments (1)
docs-v2/pages/connect/api.mdx (1)

3371-3375: ⚠️ Potential issue

Fix incorrect parameter name for updating workflows.

The example uses webhookUrls instead of workflowIds in the updateTriggerWorkflows method call, which will cause a runtime error.

Apply this diff to fix the parameter name:

-const { workflow_ids: confirmedIds } = await pd.updateTriggerWorkflows({
-  id: "dc_gzumK2e",
-  externalUserId: "jverce",
-  webhookUrls,
-});
+const { workflow_ids: confirmedIds } = await pd.updateTriggerWorkflows({
+  id: "dc_gzumK2e",
+  externalUserId: "jverce",
+  workflowIds,
+});
🧹 Nitpick comments (3)
docs-v2/pages/connect/api.mdx (3)

362-391: Consider adding error handling examples.

While the account management examples are well-documented, it would be beneficial to include examples of error handling scenarios (e.g., handling non-existent accounts, network errors, etc.).

Add error handling examples like this:

try {
  const response: GetAccountsResponse = await pd.getAccounts(requestOpts);
  // Handle success
} catch (error) {
  if (error.response?.status === 404) {
    console.error('Account not found');
  } else {
    console.error('Failed to fetch accounts:', error.message);
  }
}

1055-1084: Add pagination handling examples.

The component listing examples should demonstrate how to handle pagination using the page_info object returned in the response.

Add pagination handling example:

async function getAllComponents(pd: BackendClient, opts: GetComponentsOpts) {
  let allComponents: V1Component[] = [];
  let hasMore = true;
  let cursor = undefined;

  while (hasMore) {
    const response = await pd.getComponents({
      ...opts,
      after: cursor,
    });
    
    allComponents = [...allComponents, ...response.data];
    cursor = response.page_info.end_cursor;
    hasMore = response.data.length === response.page_info.count;
  }

  return allComponents;
}

Line range hint 1788-1828: Add input validation examples.

The action invocation examples would benefit from showing how to validate inputs before making the API call.

Add input validation example:

function validateActionInput(opts: RunActionOpts) {
  if (!opts.actionId?.key) {
    throw new Error('Action ID is required');
  }
  if (!opts.externalUserId) {
    throw new Error('External user ID is required');
  }
  if (!opts.configuredProps) {
    throw new Error('Configured props are required');
  }
}

// Usage
const requestOpts: RunActionOpts = {
  actionId: { key: "gitlab-list-commits" },
  configuredProps: {/*...*/},
  externalUserId: "jverce",
};

validateActionInput(requestOpts);
const response = await pd.runAction(requestOpts);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a44dc28 and 3da1925.

📒 Files selected for processing (1)
  • docs-v2/pages/connect/api.mdx (25 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Lint Code Base
  • GitHub Check: test
  • GitHub Check: pnpm publish
  • GitHub Check: validate-links
🔇 Additional comments (2)
docs-v2/pages/connect/api.mdx (2)

222-223: Well-structured type declarations!

The TypeScript type declarations are clear, well-organized, and provide good type safety for the SDK client configuration.

Also applies to: 229-255


Line range hint 2170-3414: Comprehensive trigger management documentation!

The documentation for trigger management is thorough and well-structured, covering all aspects of deployed triggers including events, webhooks, and workflows.

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)
docs-v2/pages/connect/api.mdx (3)

316-321: Consider adding URL validation for allowed origins.

While the implementation is correct, consider adding validation to ensure that the allowed origins are valid URLs and follow the required format (e.g., proper protocol, no trailing slashes).

const validateUrl = (url: string): boolean => {
  try {
    new URL(url);
    return true;
  } catch {
    return false;
  }
};

const requestOpts: ConnectTokenCreateOpts = {
  external_user_id: "{your_external_user_id}",
  allowed_origins: ["http://localhost:3000", "https://example.com"].filter(validateUrl),
};

Line range hint 2077-2089: Consider making the webhook URL configurable.

Instead of hardcoding the webhook URL, consider:

  1. Loading it from environment variables
  2. Making it configurable through a configuration file
  3. Generating it dynamically based on the environment
const requestOpts: DeployTriggerOpts = {
  triggerId: {
    key: "gitlab-new-issue",
  },
  configuredProps: {
    gitlab: {
      authProvisionId: "apn_kVh9AoD",
    },
    projectId: 45672541,
  },
  externalUserId: "jverce",
  webhookUrl: process.env.WEBHOOK_URL || "https://events.example.com/gitlab-new-issue",
};

3417-3422: Add explicit validation for workflow update success.

Consider adding explicit validation to ensure that all provided workflow IDs were successfully updated:

const response: UpdateTriggerWorkflowsResponse = await pd.updateTriggerWorkflows(requestOpts);

const {
  workflow_ids: confirmedIds,
}: {
  workflow_ids: string[],
} = response;

// Verify that all workflow IDs were successfully updated
const missingIds = workflowIds.filter(id => !confirmedIds.includes(id));
if (missingIds.length) {
  console.warn(`Some workflow IDs were not updated: ${missingIds.join(', ')}`);
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3da1925 and 086b36c.

📒 Files selected for processing (1)
  • docs-v2/pages/connect/api.mdx (25 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: pnpm publish
  • GitHub Check: test
  • GitHub Check: Lint Code Base
  • GitHub Check: validate-links
🔇 Additional comments (5)
docs-v2/pages/connect/api.mdx (5)

299-300: LGTM!

The type declarations follow TypeScript naming conventions and provide proper type safety for the backend client.


306-313: LGTM!

The client configuration is well-structured with clear comments about environment settings and required credentials.


324-332: LGTM!

The response handling is well-typed and follows TypeScript best practices for object destructuring.


3485-3490: LGTM!

The example response correctly demonstrates the expected format with realistic workflow IDs.


456-460: Handle credentials with caution when include_credentials is true.

When include_credentials is set to true, ensure that:

  1. The credentials are never exposed in client-side code or logs
  2. The credentials are stored securely
  3. Access to the credentials is properly authenticated and authorized
✅ Verification successful

Secure credential handling practices verified

The codebase implements proper security measures for handling credentials:

  • Credentials are processed server-side only
  • OAuth and token-based authentication are properly implemented
  • No evidence of credentials being exposed in logs or client-side code
  • Documentation emphasizes secure credential handling practices
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for potential credential leaks in console.log statements
rg -i "console\.(log|debug|info|warn|error).*credentials" 

Length of output: 59


Script:

#!/bin/bash
# Search for credential-related patterns in code
echo "=== Searching for credential handling patterns ==="
rg -i "credentials?" -A 2 -B 2

echo "=== Checking security-related files ==="
fd -i "security|auth" --type f --exec cat {}

echo "=== Checking documentation for credential handling ==="
fd "README|SECURITY" --type f --exec cat {}

Length of output: 67529

Comment on lines +3403 to +3412
// The new list of workflow IDs that will listen to the deployed trigger
const workflowIds: string[] = [
"p_ERRCzw",
"p_2LniLm",
];
const requestOpts: UpdateTriggerWorkflowsOpts = {
id: "dc_gzumK2e",
externalUserId: "jverce",
workflowIds,
};
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

Add validation for workflow IDs.

Consider adding validation to ensure that:

  1. The workflow IDs array is not empty
  2. Each workflow ID follows the expected format (e.g., starts with 'p_')
  3. The workflow IDs exist in the system
const validateWorkflowId = (id: string): boolean => /^p_[A-Za-z0-9]{6}$/.test(id);

const workflowIds = [
  "p_ERRCzw",
  "p_2LniLm",
].filter(validateWorkflowId);

if (!workflowIds.length) {
  throw new Error("No valid workflow IDs provided");
}

Comment on lines +3472 to +3477
curl -X PUT \
"https://api.pipedream.com/v1/connect/{your_project_id}/deployed-triggers/{dcid}/webhooks/" \
-H "Authorization: Bearer {access_token}" \
-H "Content-Type: application/json" \
-H "x-pd-environment: development" \
-d '{"external_user_id": "{external_user_id}", "workflow_ids": ["p_ERRCzw", "p_2LniLm"]}'
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

Fix incorrect endpoint path in cURL example.

The cURL command uses /webhooks/ in the endpoint path but should use /workflows/ since this is updating workflow IDs:

-  "https://api.pipedream.com/v1/connect/{your_project_id}/deployed-triggers/{dcid}/webhooks/" \
+  "https://api.pipedream.com/v1/connect/{your_project_id}/deployed-triggers/{dcid}/workflows/" \
📝 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
curl -X PUT \
"https://api.pipedream.com/v1/connect/{your_project_id}/deployed-triggers/{dcid}/webhooks/" \
-H "Authorization: Bearer {access_token}" \
-H "Content-Type: application/json" \
-H "x-pd-environment: development" \
-d '{"external_user_id": "{external_user_id}", "workflow_ids": ["p_ERRCzw", "p_2LniLm"]}'
curl -X PUT \
"https://api.pipedream.com/v1/connect/{your_project_id}/deployed-triggers/{dcid}/workflows/" \
-H "Authorization: Bearer {access_token}" \
-H "Content-Type: application/json" \
-H "x-pd-environment: development" \
-d '{"external_user_id": "{external_user_id}", "workflow_ids": ["p_ERRCzw", "p_2LniLm"]}'

@jverce jverce merged commit 7f5e223 into PipedreamHQ:master Jan 27, 2025
11 of 13 checks passed
@jverce jverce deleted the jay/dj-2828-update-docs branch January 27, 2025 20:03
@coderabbitai coderabbitai bot mentioned this pull request Feb 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs enhancement New feature or request javascript Pull requests that update Javascript code 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