diff --git a/components/customjs/actions/convert-html-to-pdf/convert-html-to-pdf.mjs b/components/customjs/actions/convert-html-to-pdf/convert-html-to-pdf.mjs index 7db489dfae338..3efbfb3c3357a 100644 --- a/components/customjs/actions/convert-html-to-pdf/convert-html-to-pdf.mjs +++ b/components/customjs/actions/convert-html-to-pdf/convert-html-to-pdf.mjs @@ -6,7 +6,7 @@ export default { key: "customjs-convert-html-to-pdf", name: "Convert HTML to PDF", description: "Converts an HTML string to a PDF document. [See the documentation](https://www.customjs.space/api/docs#_1-html-to-pdf)", - version: "0.0.1", + version: "0.0.2", type: "action", props: { customjs, diff --git a/components/customjs/actions/convert-html-to-png/convert-html-to-png.mjs b/components/customjs/actions/convert-html-to-png/convert-html-to-png.mjs new file mode 100644 index 0000000000000..48c7a499f558b --- /dev/null +++ b/components/customjs/actions/convert-html-to-png/convert-html-to-png.mjs @@ -0,0 +1,44 @@ +import customjs from "../../customjs.app.mjs"; +import fs from "fs"; +import { normalizeFilepath } from "../common/utils.mjs"; + +export default { + key: "customjs-convert-html-to-png", + name: "Convert HTML to PNG", + description: "Converts an HTML string to a PNG image. [See the documentation](https://www.customjs.space/api/docs#_4-html-to-png)", + version: "0.0.1", + type: "action", + props: { + customjs, + html: { + type: "string", + label: "HTML", + description: "The HTML string to be converted to a PNG", + }, + filename: { + propDefinition: [ + customjs, + "filename", + ], + }, + }, + async run({ $ }) { + const fileContent = await this.customjs.convertHtmlToPng({ + $, + data: { + input: this.html, + code: "const { HTML2PNG } = require('./utils'); return HTML2PNG(input);", + returnBinary: "true", + }, + }); + + const filepath = normalizeFilepath(this.filename, "png"); + fs.writeFileSync(filepath, Buffer.from(fileContent)); + + $.export("$summary", "Successfully converted HTML to PNG"); + return { + filename: this.filename, + filepath, + }; + }, +}; diff --git a/components/customjs/actions/create-screenshot/create-screenshot.mjs b/components/customjs/actions/create-screenshot/create-screenshot.mjs index 020ec88cb817a..284a696b6ccc7 100644 --- a/components/customjs/actions/create-screenshot/create-screenshot.mjs +++ b/components/customjs/actions/create-screenshot/create-screenshot.mjs @@ -6,7 +6,7 @@ export default { key: "customjs-create-screenshot", name: "Create Screenshot", description: "Create a screenshot of a website. [See the documentation](https://www.customjs.space/api/docs#_3-create-screenshot)", - version: "0.0.1", + version: "0.0.2", type: "action", props: { customjs, @@ -20,6 +20,7 @@ export default { customjs, "filename", ], + description: "Download the PNG file to the `/tmp` directory with the specified filename.", }, }, async run({ $ }) { diff --git a/components/customjs/actions/merge-pdfs/merge-pdfs.mjs b/components/customjs/actions/merge-pdfs/merge-pdfs.mjs index fa19e37cd5a0b..7f38cb6fce82a 100644 --- a/components/customjs/actions/merge-pdfs/merge-pdfs.mjs +++ b/components/customjs/actions/merge-pdfs/merge-pdfs.mjs @@ -6,7 +6,7 @@ export default { key: "customjs-merge-pdfs", name: "Merge PDFs", description: "Merges multiple PDF documents into one. [See the documentation](https://www.customjs.space/api/docs#_2-merge-pdfs)", - version: "0.0.1", + version: "0.0.2", type: "action", props: { customjs, diff --git a/components/customjs/actions/run-puppeteer/run-puppeteer.mjs b/components/customjs/actions/run-puppeteer/run-puppeteer.mjs new file mode 100644 index 0000000000000..1eb69bad1411b --- /dev/null +++ b/components/customjs/actions/run-puppeteer/run-puppeteer.mjs @@ -0,0 +1,45 @@ +import customjs from "../../customjs.app.mjs"; +import fs from "fs"; +import { normalizeFilepath } from "../common/utils.mjs"; + +export default { + key: "customjs-run-puppeteer", + name: "Run Puppeteer", + description: "Run Puppeteer. [See the documentation](https://www.customjs.space/api/docs#_5-run-puppeteer)", + version: "0.0.1", + type: "action", + props: { + customjs, + code: { + type: "string", + label: "Code", + description: "Enter the code you want to run on puppeteer. For example: `await page.goto(\"https://example.com\");` will return a screenshot of https://example.com.", + }, + filename: { + propDefinition: [ + customjs, + "filename", + ], + description: "Download the PNG file to the `/tmp` directory with the specified filename.", + }, + }, + async run({ $ }) { + const fileContent = await this.customjs.runPuppeteer({ + $, + data: { + input: this.code, + code: "const { PUPPETEER } = require('./utils'); return PUPPETEER(input);", + returnBinary: "true", + }, + }); + + const filepath = normalizeFilepath(this.filename, "png"); + fs.writeFileSync(filepath, Buffer.from(fileContent)); + + $.export("$summary", "Successfully ran the puppeteer code."); + return { + filename: this.filename, + filepath, + }; + }, +}; diff --git a/components/customjs/customjs.app.mjs b/components/customjs/customjs.app.mjs index 986e175cec562..40afd8fe0b0c2 100644 --- a/components/customjs/customjs.app.mjs +++ b/components/customjs/customjs.app.mjs @@ -31,7 +31,15 @@ export default { convertHtmlToPdf(opts = {}) { return this._makeRequest({ headers: { - "customjs-origin": "zapier/generatePDF", + "customjs-origin": "pipedream/generatePDF", + }, + ...opts, + }); + }, + convertHtmlToPng(opts = {}) { + return this._makeRequest({ + headers: { + "customjs-origin": "pipedream/generatePNG", }, ...opts, }); @@ -39,7 +47,7 @@ export default { createScreenshot(opts = {}) { return this._makeRequest({ headers: { - "customjs-origin": "zapier/screenshot", + "customjs-origin": "pipedream/screenshot", }, ...opts, }); @@ -47,7 +55,15 @@ export default { mergePdfs(opts = {}) { return this._makeRequest({ headers: { - "customjs-origin": "zapier/mergePDFs", + "customjs-origin": "pipedream/mergePDFs", + }, + ...opts, + }); + }, + runPuppeteer(opts = {}) { + return this._makeRequest({ + headers: { + "customjs-origin": "pipedream/puppeteer", }, ...opts, }); diff --git a/components/customjs/package.json b/components/customjs/package.json index 36e17d4b7f2b4..7e6c726641592 100644 --- a/components/customjs/package.json +++ b/components/customjs/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/customjs", - "version": "0.1.0", + "version": "0.2.0", "description": "Pipedream CustomJS Components", "main": "customjs.app.mjs", "keywords": [