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

Docusign - Download Documents #14831

Merged
merged 4 commits into from
Dec 5, 2024
Merged

Docusign - Download Documents #14831

merged 4 commits into from
Dec 5, 2024

Conversation

michelle0927
Copy link
Collaborator

@michelle0927 michelle0927 commented Dec 4, 2024

Created new action "Download Documents" instead of adding a prop to New Change in Envelope Status because sources/triggers do not have access to the /tmp directory for a workflow.

Resolves #14805

Summary by CodeRabbit

  • New Features

    • Introduced a module for downloading documents from DocuSign envelopes, allowing users to download documents in various formats.
    • Users can dynamically select envelope IDs and specify filenames for downloaded documents.
  • Bug Fixes

    • Improved error handling during document downloads.
  • Chores

    • Updated the version of the @pipedream/docusign package from 0.2.0 to 0.2.1.

Copy link

vercel bot commented Dec 4, 2024

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 Dec 4, 2024 5:11pm
pipedream-docs ⬜️ Ignored (Inspect) Dec 4, 2024 5:11pm
pipedream-docs-redirect-do-not-edit ⬜️ Ignored (Inspect) Dec 4, 2024 5:11pm

Copy link
Contributor

coderabbitai bot commented Dec 4, 2024

Walkthrough

A new module named download-documents.mjs has been introduced to facilitate the downloading of documents from DocuSign envelopes. This module allows users to specify an envelope ID and choose the format for downloading documents, including options for combined PDFs, ZIP archives, certificates, and portfolios. The module includes methods to retrieve envelope details and manage the download process, saving the files to the /tmp directory. Additionally, the version of the @pipedream/docusign package has been updated from 0.2.0 to 0.2.1.

Changes

File Path Change Summary
components/docusign/actions/download-documents.mjs Introduced a new module for downloading documents, added properties for configuration, and defined methods for retrieving envelopes and downloading files.
components/docusign/package.json Updated the version from 0.2.0 to 0.2.1.

Assessment against linked issues

Objective Addressed Explanation
Add a new action called Download Envelope Documents (#14805)
Enable the end-user to download envelope documents to /tmp (#14805)
Provide download options for various document formats (#14805)

Possibly related PRs

Suggested labels

ai-assisted

Suggested reviewers

  • jcortes
  • GTFalcao

Poem

In the land of DocuSign, so bright and grand,
A new module hops in, with a file in hand.
Downloading documents, oh what a delight,
To the /tmp they go, out of sight!
With options galore, in formats so fine,
This rabbit is happy, all thanks to the design! 🐰📄


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1fa2077 and 2fd4ff7.

📒 Files selected for processing (1)
  • components/docusign/actions/download-documents/download-documents.mjs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/docusign/actions/download-documents/download-documents.mjs

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 (3)
components/docusign/actions/download-documents/download-documents.mjs (3)

93-95: Simplify the file writing process by writing content directly

Currently, the code converts content to a base64 string and then back to a buffer before writing. You can simplify this by writing content directly to the file since it's already in a buffer format.

Apply this diff to streamline the code:

const content = await this.docusign._makeRequest({
  // existing code
});
- const rawcontent = content.toString("base64");
- const buffer = Buffer.from(rawcontent, "base64");
- fs.writeFileSync(filePath, buffer);
+ fs.writeFileSync(filePath, content);

71-75: Validate filename extension based on download type

To prevent user errors, add validation to ensure the filename extension matches the selected download type. For example, if downloadType is "combined" (PDF), the filename should end with .pdf; if it's "archive" (ZIP), it should end with .zip.

Consider implementing a validator in the filename property:

filename: {
  type: "string",
  label: "Filename",
  description: "The filename to save the file as in the `/tmp` directory including the file extension (.pdf or .zip)",
+  async validate(value) {
+    const expectedExtension = this.downloadType === "archive" ? ".zip" : ".pdf";
+    if (!value.endsWith(expectedExtension)) {
+      throw new Error(`Filename must end with ${expectedExtension} for the selected download type.`);
+    }
+  },
},

98-109: Handle potential errors in the run method

Add error handling in the run method to catch and handle any exceptions that might occur during the execution, such as network issues or API errors.

Consider wrapping the code in a try-catch block:

async run({ $ }) {
+ try {
    const baseUri = await this.docusign.getBaseUri({
      accountId: this.account,
    });
    const envelope = await this.getEnvelope($, baseUri, this.envelopeId);
    const filePath = `/tmp/${this.filename}`;
    await this.downloadToTmp($, baseUri, envelope.documentsUri, filePath);

    $.export("$summary", `Successfully downloaded files to ${filePath}`);

    return filePath;
+ } catch (error) {
+   $.export("$summary", `Failed to download documents: ${error.message}`);
+   throw error;
+ }
  },
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between e2445aa and 1fa2077.

📒 Files selected for processing (2)
  • components/docusign/actions/download-documents/download-documents.mjs (1 hunks)
  • components/docusign/package.json (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • components/docusign/package.json
🔇 Additional comments (2)
components/docusign/actions/download-documents/download-documents.mjs (2)

89-89: Verify the construction of the download URL

Ensure that slicing the first character of documentsUri correctly handles the leading slash. If documentsUri doesn't start with a slash, this could lead to incorrect URLs.

Please confirm that documentsUri always starts with a /, and adjust the code if necessary.


22-46: 🛠️ Refactor suggestion

Handle pagination correctly when listing envelopes

In the options method for envelopeId, ensure that pagination is handled correctly. The current implementation may not properly fetch additional envelopes beyond the first page.

Consider updating the pagination logic to use nextUri or increment start_position. You might need to adjust how startPosition is updated:

const { startPosition = 0 } = prevContext || {};
// existing code
return {
  options: envelopes.map(/* existing mapping */),
  context: {
-   startPosition: nextUri
+   startPosition: nextUri 
      ? endPosition + 1
      : undefined,
  },
};

Ensure that this logic correctly moves through the pages of results.

Likely invalid or redundant comment.

Copy link
Collaborator

@luancazarine luancazarine left a comment

Choose a reason for hiding this comment

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

Hi @michelle0927, LGTM! Ready for QA!

@michelle0927 michelle0927 merged commit 4785f9e into master Dec 5, 2024
11 checks passed
@michelle0927 michelle0927 deleted the issue-14805 branch December 5, 2024 15:25
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.

[Action] Docusign - Download Envelope Documents
2 participants