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

CustomJS: Add Run Puppoteer and HTML to PNG actions #14117

Merged
merged 8 commits into from
Oct 1, 2024

Conversation

hamadawan
Copy link
Contributor

@hamadawan hamadawan commented Sep 26, 2024

Add the following actions in CustomJS.

1: Run Puppeteer.
2: HTML to PNG.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added new entries to the word list: CustomJS and Puppeteer.
    • Introduced an action for converting HTML to PNG images.
    • Added functionality to execute Puppeteer scripts in a custom JavaScript environment.
    • New methods for converting HTML to PNG and running Puppeteer scripts in the customjs module.
  • Bug Fixes

    • Updated request headers for several methods to reflect a change in service origin.
  • Version Updates

    • Incremented version numbers for modules related to creating screenshots, converting HTML to PDF, and merging PDFs.
    • Updated the package version for @pipedream/customjs from 0.1.0 to 0.2.0.

Copy link

vercel bot commented Sep 26, 2024

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

A member of the Team first needs to authorize it.

Copy link

vercel bot commented Sep 26, 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) Sep 30, 2024 7:13pm

Copy link
Contributor

coderabbitai bot commented Sep 26, 2024

Walkthrough

The pull request introduces new functionalities to the customjs module, adding two actions: one for converting HTML to PNG and another for executing Puppeteer scripts. It also updates the customjs-origin header values for existing methods to reflect a new service origin. Additionally, two new entries are added to the .wordlist.txt file, enhancing the documentation of terms used within the module.

Changes

Files Change Summary
.wordlist.txt Added new entries: CustomJS and Puppoteer.
components/customjs/actions/convert-html-to-png/convert-html-to-png.mjs Introduced a new action customjs-convert-html-to-png for converting HTML to PNG images.
components/customjs/actions/run-puppeteer/run-puppeteer.mjs Added a new action for executing Puppeteer scripts, with a run method that processes Puppeteer code.
components/customjs/customjs.app.mjs Updated customjs-origin headers for several methods and added two new methods: convertHtmlToPng and runPuppeteer.
components/customjs/actions/convert-html-to-pdf/convert-html-to-pdf.mjs Updated version from 0.0.1 to 0.0.2.
components/customjs/actions/create-screenshot/create-screenshot.mjs Updated version from 0.0.1 to 0.0.2.
components/customjs/actions/merge-pdfs/merge-pdfs.mjs Updated version from 0.0.1 to 0.0.2.
components/customjs/package.json Updated package version from 0.1.0 to 0.2.0.

Possibly related PRs

  • New Components - customjs #14086: The main PR introduces new actions for creating checks, email checks, and payees in the Online Check Writer application, which aligns with the objectives of the retrieved PR that focuses on implementing various actions related to the OnlineCheckWriter API.
  • [Components] OnlineCheckWriter: New action components #14119: This PR also addresses the introduction of new action components for the Online Check Writer, specifically aimed at enhancing check creation and management functionalities, which is consistent with the changes made in the main PR.

Suggested labels

action

Suggested reviewers

  • vunguyenhung

Poem

🐇 In the land of code where rabbits play,
New actions hop in, brightening the day.
HTML to PNG, a magical sight,
Puppeteer scripts take flight in the night.
With headers updated, we cheer and we sing,
In our custom world, let the changes bring! 🌟


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 9a2778d and 17d0a05.

📒 Files selected for processing (1)
  • components/customjs/actions/run-puppeteer/run-puppeteer.mjs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/customjs/actions/run-puppeteer/run-puppeteer.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.

@dylburger dylburger added the User submitted Submitted by a user label Sep 26, 2024
@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:

@michelle0927 michelle0927 marked this pull request as ready for review September 26, 2024 20:32
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: 8

🧹 Outside diff range and nitpick comments (2)
components/customjs/actions/convert-html-to-png/convert-html-to-png.mjs (1)

5-24: LGTM: Action definition is well-structured. Consider making the filename prop optional.

The action definition follows the guidelines mentioned in the PR objectives:

  • The key format is correct: customjs-convert-html-to-png.
  • The description includes a link to the documentation.
  • The version is set appropriately for a new component.

The props are well-defined, but consider the following suggestion:

Make the filename prop optional with a default value. This allows users to run the action without specifying a filename, which could default to a timestamp-based name. Here's a suggested modification:

filename: {
  propDefinition: [
    customjs,
    "filename",
  ],
  optional: true,
  default: () => `html_to_png_${Date.now()}.png`,
},

This change aligns with the PR objective of using optional props with default values where applicable.

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

Line range hint 1-73: Suggestions for code organization and documentation

While the individual changes look good and align with the PR objectives, consider the following suggestions to improve code organization and documentation:

  1. Add JSDoc comments for each method to describe their functionality, parameters, and return values. This aligns with the PR objectives mentioned in the comments summary.

  2. Consider extracting the customjs-origin header values into constants at the top of the file for easier maintenance and consistency.

  3. If these methods are intended to be used externally, consider adding them to the propDefinitions object with appropriate descriptions and labels.

Here's an example of how you could implement these suggestions:

import { axios } from "@pipedream/platform";

const ORIGINS = {
  PDF: "pipedream/generatePDF",
  PNG: "pipedream/generatePNG",
  SCREENSHOT: "pipedream/screenshot",
  MERGE_PDFS: "pipedream/mergePDFs",
  PUPPETEER: "pipedream/puppeteer",
};

export default {
  type: "app",
  app: "customjs",
  propDefinitions: {
    filename: {
      type: "string",
      label: "Filename",
      description: "Download the file to the `/tmp` directory with the specified filename.",
    },
    // Add other prop definitions here
  },
  methods: {
    // ... existing _makeRequest method ...

    /**
     * Converts HTML to PDF
     * @param {Object} opts - Options for the conversion
     * @returns {Promise<ArrayBuffer>} The PDF file as an ArrayBuffer
     */
    convertHtmlToPdf(opts = {}) {
      return this._makeRequest({
        headers: {
          "customjs-origin": ORIGINS.PDF,
        },
        ...opts,
      });
    },

    // Add similar JSDoc comments and use ORIGINS constant for other methods
  },
};
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between fab4297 and d9ed5f4.

📒 Files selected for processing (4)
  • .wordlist.txt (2 hunks)
  • components/customjs/actions/convert-html-to-png/convert-html-to-png.mjs (1 hunks)
  • components/customjs/actions/run-puppoteer/run-puppoteer.mjs (1 hunks)
  • components/customjs/customjs.app.mjs (1 hunks)
🔇 Additional comments (6)
components/customjs/actions/run-puppoteer/run-puppoteer.mjs (1)

1-3: LGTM: Imports are appropriate and consistent.

The imports from customjs.app.mjs, fs, and utils.mjs are relevant to the action's functionality. The use of ES modules (.mjs extension) is consistent with modern JavaScript practices.

components/customjs/actions/convert-html-to-png/convert-html-to-png.mjs (1)

1-3: LGTM: Imports are appropriate and use modern syntax.

The imports are well-chosen for the action's requirements:

  • customjs for the main functionality
  • fs for file system operations
  • normalizeFilepath utility for file path handling

The use of ES6 import syntax is consistent with modern JavaScript practices.

components/customjs/customjs.app.mjs (4)

34-37: LGTM: Header update for convertHtmlToPdf

The customjs-origin header has been correctly updated to "pipedream/generatePDF", which accurately reflects the Pipedream origin and the PDF generation functionality. This change aligns with the PR objectives of updating the CustomJS framework.


39-44: LGTM: New method convertHtmlToPng added

The new convertHtmlToPng method has been successfully added, following the same structure as other methods in the file. The customjs-origin header is correctly set to "pipedream/generatePNG", which accurately reflects the Pipedream origin and the PNG generation functionality. This addition aligns with the PR objectives of introducing new actions to the CustomJS framework.


50-50: LGTM: Header update for createScreenshot

The customjs-origin header has been correctly updated to "pipedream/screenshot", which accurately reflects the Pipedream origin and the screenshot functionality. This change aligns with the PR objectives of updating the CustomJS framework.


58-61: LGTM: Header update for mergePdfs

The customjs-origin header has been correctly updated to "pipedream/mergePDFs", which accurately reflects the Pipedream origin and the PDF merging functionality. This change aligns with the PR objectives of updating the CustomJS framework.

components/customjs/customjs.app.mjs Outdated Show resolved Hide resolved
.wordlist.txt Outdated Show resolved Hide resolved
.wordlist.txt Outdated Show resolved Hide resolved
Copy link
Collaborator

@michelle0927 michelle0927 left a comment

Choose a reason for hiding this comment

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

Thank you so much for your contribution! Looks good. You'll just need to update the versions of convert-html-to-pdf.mjs, create-screenshot.mjs, merge-pdfs.mjs, and package.json, remove a couple unnecessary lines (commented below), and then it should be ready to test.

.wordlist.txt Outdated Show resolved Hide resolved
.wordlist.txt Outdated Show resolved Hide resolved
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: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d9ed5f4 and 24e0b62.

📒 Files selected for processing (2)
  • components/customjs/actions/run-puppeteer/run-puppeteer.mjs (1 hunks)
  • components/customjs/customjs.app.mjs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/customjs/customjs.app.mjs
🔇 Additional comments (2)
components/customjs/actions/run-puppeteer/run-puppeteer.mjs (2)

1-3: LGTM: Imports are appropriate and use modern syntax.

The imports are well-structured and include necessary modules for the action's functionality.


1-44: Overall assessment: Good implementation with room for improvement.

The "Run Puppeteer" action is well-structured and implements the required functionality. However, there are a few areas for improvement:

  1. Update the component key format to align with guidelines.
  2. Consider making the 'code' prop optional with a default value.
  3. Implement error handling in the run method.
  4. Use asynchronous file writing to avoid potential event loop blocking.

Addressing these points will enhance the robustness and efficiency of the action while aligning it more closely with Pipedream's component guidelines.

@hamadawan
Copy link
Contributor Author

@michelle0927 I have resolved the comments, Kindly review and merge. Thank you

michelle0927
michelle0927 previously approved these changes Sep 27, 2024
Copy link
Collaborator

@michelle0927 michelle0927 left a comment

Choose a reason for hiding this comment

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

Approved! Ready for QA!

@vunguyenhung
Copy link
Collaborator

Hello everyone, I have tested this PR and there're some test cases failed or needed improvement.

Please check the test report below for more information
https://vunguyenhung.notion.site/CustomJS-Add-Run-Puppoteer-and-HTML-to-PNG-actions-10ebf548bb5e810483f9ebfc38ed8138

@michelle0927
Copy link
Collaborator

@hamadawan I'm not able to get the "Run Puppeteer" action to run successfully. Can you provide an example of what should be entered in the "Code" prop?

@hamadawan
Copy link
Contributor Author

hamadawan commented Sep 30, 2024 via email

@michelle0927
Copy link
Collaborator

Hi, guys sorry for the inconvenience, Here is the CustomJS doc. https://www.customjs.space/api/docs#_5-run-puppoteer According to docs. we should pass this input: { "input": "const page = await browser.newPage(); await page.goto("https://example.com\"); return await page.screenshot({ encoding: "binary" });", "code": "const { PUPPETEER } = require("./utils"); return PUPPETEER(input);", "returnBinary": "true"}

@hamadawan And that works for you when testing the action? For me, it was creating a blank .png file. Would you mind sharing screenshot(s) of the component working successfully for you and the resulting .png file?

@hamadawan
Copy link
Contributor Author

hamadawan commented Sep 30, 2024

@michelle0927 I just rechecked; it is not working for me as well. But I found that we need to pass this in as input.

{ "input": "await page.goto("https://example.com");", "code": "const { PUPPETEER } = require(\"./utils\"); return PUPPETEER(input);", "returnBinary": "true" }

This will work.

I'll update the CustomJS docs as well.

@hamadawan
Copy link
Contributor Author

@michelle0927 I just rechecked; it is not working for me as well. But I found that we need to pass this in as input.

{ "input": "await page.goto("https://example.com");", "code": "const { PUPPETEER } = require(\"./utils\"); return PUPPETEER(input);", "returnBinary": "true" }

This will work.

@vunguyenhung
Copy link
Collaborator

Hi everyone, all test cases are passed! Ready for release!

Test report
https://vunguyenhung.notion.site/CustomJS-Add-Run-Puppoteer-and-HTML-to-PNG-actions-10ebf548bb5e810483f9ebfc38ed8138

@michelle0927 michelle0927 merged commit 678ba7c into PipedreamHQ:master Oct 1, 2024
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
User submitted Submitted by a user
Projects
Development

Successfully merging this pull request may close these issues.

5 participants