diff --git a/components/screenshotbase/actions/take-screenshot/take-screenshot.mjs b/components/screenshotbase/actions/take-screenshot/take-screenshot.mjs new file mode 100644 index 0000000000000..fbe12f0023852 --- /dev/null +++ b/components/screenshotbase/actions/take-screenshot/take-screenshot.mjs @@ -0,0 +1,100 @@ +import screenshotbase from "../../screenshotbase.app.mjs"; +import { ConfigurationError } from "@pipedream/platform"; +import fs from "fs"; + +export default { + key: "screenshotbase-take-screenshot", + name: "Take a Screenshot", + description: "Take a screenshot with ScreenshotBase. [See the documentation](https://screenshotbase.com/docs/take)", + version: "0.0.1", + type: "action", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: false, + }, + props: { + screenshotbase, + url: { + propDefinition: [ + screenshotbase, + "url", + ], + }, + format: { + propDefinition: [ + screenshotbase, + "format", + ], + }, + filename: { + propDefinition: [ + screenshotbase, + "filename", + ], + }, + quality: { + propDefinition: [ + screenshotbase, + "quality", + ], + }, + fullPage: { + propDefinition: [ + screenshotbase, + "fullPage", + ], + }, + viewportWidth: { + propDefinition: [ + screenshotbase, + "viewportWidth", + ], + }, + viewportHeight: { + propDefinition: [ + screenshotbase, + "viewportHeight", + ], + }, + syncDir: { + type: "dir", + accessMode: "write", + sync: true, + }, + }, + async run({ $ }) { + if (this.quality && this.format !== "jpg" && this.format !== "jpeg") { + throw new ConfigurationError("**Quality** is only supported when the format is `jpg` or `jpeg`"); + } + + try { + const response = await this.screenshotbase.takeScreenshot({ + $, + params: { + url: this.url, + format: this.format, + quality: this.quality, + full_page: this.fullPage + ? 1 + : undefined, + viewport_width: this.viewportWidth, + viewport_height: this.viewportHeight, + }, + }); + + const downloadedFilepath = `/tmp/${this.filename}`; + fs.writeFileSync(downloadedFilepath, response); + + const filedata = [ + this.filename, + downloadedFilepath, + ]; + + $.export("$summary", `Successfully took the screenshot from ${this.url}`); + return filedata; + } catch (error) { + throw new Error(`Unable to take screenshot from ${this.url}: ${error.name}`); + } + }, +}; diff --git a/components/screenshotbase/package.json b/components/screenshotbase/package.json index 05ff395afb858..5c76866e537f3 100644 --- a/components/screenshotbase/package.json +++ b/components/screenshotbase/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/screenshotbase", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream screenshotbase Components", "main": "screenshotbase.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/screenshotbase/screenshotbase.app.mjs b/components/screenshotbase/screenshotbase.app.mjs index 199175d136895..96dfb2bc18b32 100644 --- a/components/screenshotbase/screenshotbase.app.mjs +++ b/components/screenshotbase/screenshotbase.app.mjs @@ -1,11 +1,75 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "screenshotbase", - propDefinitions: {}, + propDefinitions: { + url: { + label: "URL", + type: "string", + description: "Website to render", + }, + filename: { + type: "string", + label: "Target Filename", + description: "The filename (including extension) that will be used to save the file in /tmp", + }, + format: { + type: "string", + label: "Format", + description: "The format of the image returned", + options: [ + "jpg", + "png", + "webp", + ], + }, + quality: { + type: "integer", + label: "Quality", + description: "The quality of the image returned. Only supported when the format is `jpg` or `jpeg`", + optional: true, + }, + fullPage: { + type: "boolean", + label: "Full Page", + description: "Whether to take a screenshot of the full page", + optional: true, + }, + viewportWidth: { + type: "integer", + label: "Viewport Width", + description: "The width of the browser viewport in pixels. The browser's viewport is the window area where you can see the website. Default value is 1280.", + optional: true, + }, + viewportHeight: { + type: "integer", + label: "Viewport Height", + description: "The height of the browser viewport in pixels. The browser's viewport is the window area where you can see the website. Default value is 800.", + optional: true, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://api.screenshotbase.com/v1"; + }, + _makeRequest({ + $ = this, path, ...opts + }) { + return axios($, { + url: `${this._baseUrl()}${path}`, + headers: { + "apikey": `${this.$auth.api_key}`, + }, + ...opts, + }); + }, + takeScreenshot(opts = {}) { + return this._makeRequest({ + path: "/take", + responseType: "arraybuffer", + ...opts, + }); }, }, }; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 931f07d548291..0e6d15421624f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1367,8 +1367,7 @@ importers: components/azure_api_for_fhir: {} - components/azure_cosmos_db: - specifiers: {} + components/azure_cosmos_db: {} components/azure_devops: dependencies: @@ -1673,8 +1672,7 @@ importers: components/billsby: {} - components/binalyze_air: - specifiers: {} + components/binalyze_air: {} components/bingx: dependencies: @@ -6064,8 +6062,7 @@ importers: specifier: ^8.8.0 version: 8.9.0 - components/google_perspective: - specifiers: {} + components/google_perspective: {} components/google_photos: dependencies: @@ -12629,7 +12626,11 @@ importers: specifier: ^3.0.3 version: 3.0.3 - components/screenshotbase: {} + components/screenshotbase: + dependencies: + '@pipedream/platform': + specifier: ^3.1.0 + version: 3.1.0 components/screenshotone: dependencies: @@ -31322,22 +31323,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==}