diff --git a/components/pdf_munk/actions/capture-website-screenshot-into-image/capture-website-screenshot-into-image.mjs b/components/pdf_munk/actions/capture-website-screenshot-into-image/capture-website-screenshot-into-image.mjs new file mode 100644 index 0000000000000..6ec396a337f4c --- /dev/null +++ b/components/pdf_munk/actions/capture-website-screenshot-into-image/capture-website-screenshot-into-image.mjs @@ -0,0 +1,28 @@ +import app from "../../pdf_munk.app.mjs"; + +export default { + key: "pdf_munk-capture-website-screenshot-into-image", + name: "Capture Website Screenshot into Image", + description: "Capture Screenshot of a Website URL into an image. [See documentation](https://pdfmunk.com/api-docs#:~:text=Image%20Generation)", + version: "0.0.1", + type: "action", + props: { + app, + url: { + type: "string", + label: "Website URL", + description: "The URL of the website to capture as a screenshot", + }, + }, + async run({ $ }) { + const { url } = this; + + const response = await this.app.captureWebsiteScreenshot({ + $, + url, + }); + + $.export("$summary", `Successfully captured screenshot of ${url}`); + return response; + }, +}; diff --git a/components/pdf_munk/actions/capture-website-screenshot-into-pdf/capture-website-screenshot-into-pdf.mjs b/components/pdf_munk/actions/capture-website-screenshot-into-pdf/capture-website-screenshot-into-pdf.mjs new file mode 100644 index 0000000000000..4d69159eb9ee8 --- /dev/null +++ b/components/pdf_munk/actions/capture-website-screenshot-into-pdf/capture-website-screenshot-into-pdf.mjs @@ -0,0 +1,96 @@ +import app from "../../pdf_munk.app.mjs"; + +export default { + key: "pdf_munk-capture-website-screenshot-into-pdf", + name: "Capture Website Screenshot into PDF", + description: "Converts a URL to a PDF file with customizable options. [See documentation](https://pdfmunk.com/api-docs#:~:text=Operations%20related%20to%20PDF)", + version: "0.0.1", + type: "action", + props: { + app, + url: { + type: "string", + label: "Website URL", + description: "The URL of the website to convert to PDF", + }, + paper_size: { + type: "string", + label: "Paper Size", + description: "The paper size for the PDF", + options: [ + { + label: "A4", + value: "A4", + }, + { + label: "A3", + value: "A3", + }, + { + label: "A5", + value: "A5", + }, + { + label: "Letter", + value: "Letter", + }, + { + label: "Legal", + value: "Legal", + }, + { + label: "Tabloid", + value: "Tabloid", + }, + ], + default: "A4", + }, + landscape: { + type: "boolean", + label: "Landscape", + description: "Whether to use landscape orientation", + default: false, + }, + displayHeaderFooter: { + type: "boolean", + label: "Display Header Footer", + description: "Whether to display header and footer", + default: false, + }, + page_size: { + type: "integer", + label: "Page Size", + description: "The page size in points", + default: 5, + }, + printBackground: { + type: "boolean", + label: "Print Background", + description: "Whether to print background graphics", + default: true, + }, + }, + async run({ $ }) { + const { + url, + paper_size, + landscape, + displayHeaderFooter, + page_size, + printBackground, + } = this; + + const response = await this.app.captureWebsiteToPdf({ + $, + url, + paper_size, + landscape, + displayHeaderFooter, + page_size, + printBackground, + }); + + $.export("$summary", `Successfully converted ${url} to PDF`); + return response; + }, +}; diff --git a/components/pdf_munk/actions/convert-html-to-image/convert-html-to-image.mjs b/components/pdf_munk/actions/convert-html-to-image/convert-html-to-image.mjs new file mode 100644 index 0000000000000..c4bbe633d1f90 --- /dev/null +++ b/components/pdf_munk/actions/convert-html-to-image/convert-html-to-image.mjs @@ -0,0 +1,54 @@ +import app from "../../pdf_munk.app.mjs"; + +export default { + key: "pdf_munk-convert-html-to-image", + name: "Convert HTML to Image", + description: "Converts HTML/CSS content to an image. [See documentation](https://pdfmunk.com/api-docs#:~:text=Image%20Generation)", + version: "0.0.1", + type: "action", + props: { + app, + html_content: { + type: "string", + label: "HTML Content", + description: "The HTML content to convert to an image", + }, + css_content: { + type: "string", + label: "CSS Content", + description: "The CSS content to style the HTML", + optional: true, + }, + width: { + type: "integer", + label: "Width", + description: "The width of the generated image in pixels", + default: 800, + }, + height: { + type: "integer", + label: "Height", + description: "The height of the generated image in pixels", + default: 600, + }, + }, + async run({ $ }) { + const { + html_content, + css_content, + width, + height, + } = this; + + const response = await this.app.convertHtmlToImage({ + $, + html_content, + css_content, + width, + height, + }); + + $.export("$summary", "Successfully converted HTML to image"); + return response; + }, +}; diff --git a/components/pdf_munk/actions/convert-html-to-pdf/convert-html-to-pdf.mjs b/components/pdf_munk/actions/convert-html-to-pdf/convert-html-to-pdf.mjs new file mode 100644 index 0000000000000..8e452f4bd29bb --- /dev/null +++ b/components/pdf_munk/actions/convert-html-to-pdf/convert-html-to-pdf.mjs @@ -0,0 +1,80 @@ +import app from "../../pdf_munk.app.mjs"; + +export default { + key: "pdf_munk-convert-html-to-pdf", + name: "Convert HTML to PDF", + description: "Converts HTML/CSS content to a PDF file with customizable options. [See documentation](https://pdfmunk.com/api-docs#:~:text=Operations%20related%20to%20PDF)", + version: "0.0.1", + type: "action", + props: { + app, + html_content: { + type: "string", + label: "HTML Content", + description: "The HTML content to convert to PDF", + }, + css_content: { + type: "string", + label: "CSS Content", + description: "The CSS content to style the HTML", + optional: true, + }, + paper_size: { + type: "string", + label: "Paper Size", + description: "The paper size for the PDF", + options: [ + { + label: "A4", + value: "A4", + }, + { + label: "A3", + value: "A3", + }, + { + label: "A5", + value: "A5", + }, + { + label: "Letter", + value: "Letter", + }, + { + label: "Legal", + value: "Legal", + }, + { + label: "Tabloid", + value: "Tabloid", + }, + ], + default: "A4", + }, + page_size: { + type: "integer", + label: "Page Size", + description: "The page size in points", + default: 2, + }, + }, + async run({ $ }) { + const { + html_content, + css_content, + paper_size, + page_size, + } = this; + + const response = await this.app.convertHtmlToPdf({ + $, + html_content, + css_content, + paper_size, + page_size, + }); + + $.export("$summary", "Successfully converted HTML to PDF"); + return response; + }, +}; diff --git a/components/pdf_munk/package.json b/components/pdf_munk/package.json index 2011c7a757ef0..94d459c0f6928 100644 --- a/components/pdf_munk/package.json +++ b/components/pdf_munk/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/pdf_munk", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream PDF Munk Components", "main": "pdf_munk.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.1.0" } -} \ No newline at end of file +} diff --git a/components/pdf_munk/pdf_munk.app.mjs b/components/pdf_munk/pdf_munk.app.mjs index f079b11571e9a..50b3618183550 100644 --- a/components/pdf_munk/pdf_munk.app.mjs +++ b/components/pdf_munk/pdf_munk.app.mjs @@ -1,11 +1,120 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "pdf_munk", propDefinitions: {}, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://www.pdfmunk.com/api"; + }, + _getHeaders() { + return { + "accept": "application/json", + "client-api-key": `${this.$auth.api_key}`, + "content-type": "application/json", + }; + }, + async _makeRequest({ + $ = this, + method = "POST", + path, + data, + ...opts + }) { + const { + headers: userHeaders, + ...rest + } = opts; + const config = { + method, + ...rest, + url: `${this._baseUrl()}${path}`, + headers: { + ...this._getHeaders(), + ...(userHeaders || {}), + }, + data, + }; + return await axios($, config); + }, + async captureWebsiteScreenshot({ + $, + url, + }) { + const data = await this._makeRequest({ + $, + method: "POST", + path: "/v1/generateImage", + data: { + url, + }, + }); + return data; + }, + async captureWebsiteToPdf({ + $, + url, + paper_size, + landscape, + displayHeaderFooter, + page_size, + printBackground, + }) { + const data = await this._makeRequest({ + $, + method: "POST", + path: "/v1/generatePdf", + data: { + url, + paper_size, + landscape, + displayHeaderFooter, + page_size, + printBackground, + }, + }); + return data; + }, + async convertHtmlToImage({ + $, + html_content, + css_content, + width, + height, + }) { + const data = await this._makeRequest({ + $, + method: "POST", + path: "/v1/generateImage", + data: { + html_content, + css_content, + width, + height, + }, + }); + return data; + }, + async convertHtmlToPdf({ + $, + html_content, + css_content, + paper_size, + page_size, + }) { + const data = await this._makeRequest({ + $, + method: "POST", + path: "/v1/generatePdf", + data: { + html_content, + css_content, + paper_size, + page_size, + }, + }); + return data; }, }, -}; \ No newline at end of file +}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 062c1df861b93..21f007d96c8af 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -10451,7 +10451,11 @@ importers: specifier: ^0.10.0 version: 0.10.0 - components/pdf_munk: {} + components/pdf_munk: + dependencies: + '@pipedream/platform': + specifier: ^3.1.0 + version: 3.1.0 components/pdffiller: dependencies: @@ -30980,22 +30984,22 @@ packages: superagent@3.8.1: resolution: {integrity: sha512-VMBFLYgFuRdfeNQSMLbxGSLfmXL/xc+OO+BZp41Za/NRDBet/BNbkRJrYzCUu0u4GU0i/ml2dtT8b9qgkw9z6Q==} engines: {node: '>= 4.0'} - deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net + deprecated: Please upgrade to superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net superagent@4.1.0: resolution: {integrity: sha512-FT3QLMasz0YyCd4uIi5HNe+3t/onxMyEho7C3PSqmti3Twgy2rXT4fmkTz6wRL6bTF4uzPcfkUCa8u4JWHw8Ag==} engines: {node: '>= 6.0'} - deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net + deprecated: Please upgrade to superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net superagent@5.3.1: resolution: {integrity: sha512-wjJ/MoTid2/RuGCOFtlacyGNxN9QLMgcpYLDQlWFIhhdJ93kNscFonGvrpAHSCVjRVj++DGCglocF7Aej1KHvQ==} engines: {node: '>= 7.0.0'} - deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net + deprecated: Please upgrade to superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net superagent@7.1.6: resolution: {integrity: sha512-gZkVCQR1gy/oUXr+kxJMLDjla434KmSOKbx5iGD30Ql+AkJQ/YlPKECJy2nhqOsHLjGHzoDTXNSjhnvWhzKk7g==} engines: {node: '>=6.4.0 <13 || >=14'} - deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net + deprecated: Please upgrade to superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net supports-color@10.0.0: resolution: {integrity: sha512-HRVVSbCCMbj7/kdWF9Q+bbckjBHLtHMEoJWlkmYzzdwhYMkjkOwubLM6t7NbWKjgKamGDrWL1++KrjUO1t9oAQ==}