-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New Components - customjs #14086
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
Merged
Merged
New Components - customjs #14086
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const normalizeFilepath = (filename, ext = "pdf") => { | ||
let filepath = filename.includes("/tmp") | ||
? filename | ||
: `/tmp/${filename}`; | ||
filepath = filepath.includes(`.${ext}`) | ||
? filepath | ||
: `${filepath}.${ext}`; | ||
return filepath; | ||
}; | ||
|
||
export { | ||
normalizeFilepath, | ||
}; |
44 changes: 44 additions & 0 deletions
44
components/customjs/actions/convert-html-to-pdf/convert-html-to-pdf.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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-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", | ||
type: "action", | ||
props: { | ||
customjs, | ||
html: { | ||
type: "string", | ||
label: "HTML", | ||
description: "The HTML string to be converted to a PDF", | ||
}, | ||
filename: { | ||
propDefinition: [ | ||
customjs, | ||
"filename", | ||
], | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const fileContent = await this.customjs.convertHtmlToPdf({ | ||
$, | ||
data: { | ||
input: this.html, | ||
code: "const { HTML2PDF } = require(\"./utils\"); return HTML2PDF(input);", | ||
returnBinary: "true", | ||
}, | ||
}); | ||
|
||
const filepath = normalizeFilepath(this.filename); | ||
fs.writeFileSync(filepath, Buffer.from(fileContent)); | ||
|
||
$.export("$summary", "Successfully converted HTML to PDF"); | ||
return { | ||
filename: this.filename, | ||
filepath, | ||
}; | ||
}, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; |
44 changes: 44 additions & 0 deletions
44
components/customjs/actions/create-screenshot/create-screenshot.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import customjs from "../../customjs.app.mjs"; | ||
import fs from "fs"; | ||
import { normalizeFilepath } from "../common/utils.mjs"; | ||
|
||
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", | ||
type: "action", | ||
props: { | ||
customjs, | ||
url: { | ||
type: "string", | ||
label: "URL", | ||
description: "The URL of the website to take a screenshot of", | ||
}, | ||
filename: { | ||
propDefinition: [ | ||
customjs, | ||
"filename", | ||
], | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const fileContent = await this.customjs.createScreenshot({ | ||
$, | ||
data: { | ||
input: this.url, | ||
code: "const { SCREENSHOT } = require(\"./utils\"); return SCREENSHOT(input);", | ||
returnBinary: "true", | ||
}, | ||
}); | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const filepath = normalizeFilepath(this.filename, "png"); | ||
fs.writeFileSync(filepath, Buffer.from(fileContent)); | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
$.export("$summary", `Successfully created screenshot of ${this.url}`); | ||
return { | ||
filename: this.filename, | ||
filepath, | ||
}; | ||
}, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import customjs from "../../customjs.app.mjs"; | ||
import fs from "fs"; | ||
import { normalizeFilepath } from "../common/utils.mjs"; | ||
|
||
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", | ||
type: "action", | ||
props: { | ||
customjs, | ||
pdfs: { | ||
type: "string[]", | ||
label: "PDFs", | ||
description: "The array of URLs to the PDF documents to merge", | ||
}, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
filename: { | ||
propDefinition: [ | ||
customjs, | ||
"filename", | ||
], | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const pdfs = typeof this.pdfs === "string" | ||
? JSON.parse(this.pdfs) | ||
: this.pdfs; | ||
|
||
const fileContent = await this.customjs.mergePdfs({ | ||
$, | ||
data: { | ||
input: pdfs, | ||
code: "const { PDF_MERGE } = require(\"./utils\"); const axios = require(\"axios\"); const pdfBuffers = await Promise.all(input.map(async file => { const res = await axios.get(file, { responseType: \"arraybuffer\" }); return Buffer.from(res.data).toString(\"base64\"); })); return PDF_MERGE(pdfBuffers);", | ||
returnBinary: "true", | ||
}, | ||
}); | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const filepath = normalizeFilepath(this.filename); | ||
fs.writeFileSync(filepath, Buffer.from(fileContent)); | ||
|
||
$.export("$summary", "Successfully merged PDFs"); | ||
return { | ||
filename: this.filename, | ||
filepath, | ||
}; | ||
}, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,56 @@ | ||
import { axios } from "@pipedream/platform"; | ||
|
||
export default { | ||
type: "app", | ||
app: "customjs", | ||
propDefinitions: {}, | ||
propDefinitions: { | ||
filename: { | ||
type: "string", | ||
label: "Filename", | ||
description: "Download the file to the `/tmp` directory with the specified filename.", | ||
}, | ||
}, | ||
methods: { | ||
// this.$auth contains connected account data | ||
authKeys() { | ||
console.log(Object.keys(this.$auth)); | ||
_makeRequest(opts = {}) { | ||
const { | ||
$ = this, | ||
headers, | ||
...otherOpts | ||
} = opts; | ||
return axios($, { | ||
...otherOpts, | ||
method: "POST", | ||
url: `https://e.customjs.io/__js1-${this.$auth.api_key}`, | ||
headers: { | ||
...headers, | ||
"Content-Type": "application/json", | ||
}, | ||
responseType: "arraybuffer", | ||
}); | ||
}, | ||
convertHtmlToPdf(opts = {}) { | ||
return this._makeRequest({ | ||
headers: { | ||
"customjs-origin": "zapier/generatePDF", | ||
}, | ||
...opts, | ||
}); | ||
}, | ||
createScreenshot(opts = {}) { | ||
return this._makeRequest({ | ||
headers: { | ||
"customjs-origin": "zapier/screenshot", | ||
}, | ||
...opts, | ||
}); | ||
}, | ||
mergePdfs(opts = {}) { | ||
return this._makeRequest({ | ||
headers: { | ||
"customjs-origin": "zapier/mergePDFs", | ||
}, | ||
...opts, | ||
}); | ||
}, | ||
}, | ||
}; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@pipedream/customjs", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Pipedream CustomJS Components", | ||
"main": "customjs.app.mjs", | ||
"keywords": [ | ||
|
@@ -11,5 +11,8 @@ | |
"author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"@pipedream/platform": "^3.0.3" | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.