-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New Components - pdfmonkey #14237
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 - pdfmonkey #14237
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
dfb8d8d
pdfmonkey init
luancazarine 625c3bc
[Components] pdfmonkey #13201
luancazarine 2c6ce20
pnpm update
luancazarine ce6755a
Merge branch 'master' into issue-13201
luancazarine 367ba02
Merge branch 'master' into issue-13201
luancazarine 544baf3
adjust paginate method
luancazarine 9d6e710
Merge branch 'master' into issue-13201
luancazarine 60474aa
Merge branch 'master' into issue-13201
luancazarine 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 was deleted.
Oops, something went wrong.
26 changes: 26 additions & 0 deletions
26
components/pdfmonkey/actions/delete-document/delete-document.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,26 @@ | ||
| import pdfmonkey from "../../pdfmonkey.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "pdfmonkey-delete-document", | ||
| name: "Delete Document", | ||
| description: "Deletes a specific document using its ID. [See the documentation](https://docs.pdfmonkey.io/references/api/documents)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| pdfmonkey, | ||
| documentId: { | ||
| propDefinition: [ | ||
| pdfmonkey, | ||
| "documentId", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.pdfmonkey.deleteDocument({ | ||
| $, | ||
| documentId: this.documentId, | ||
| }); | ||
| $.export("$summary", `Deleted document with ID ${this.documentId}`); | ||
| return response; | ||
| }, | ||
| }; |
26 changes: 26 additions & 0 deletions
26
components/pdfmonkey/actions/find-document/find-document.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,26 @@ | ||
| import pdfmonkey from "../../pdfmonkey.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "pdfmonkey-find-document", | ||
| name: "Find Document", | ||
| description: "Find a document within PDFMonkey. [See the documentation](https://docs.pdfmonkey.io/references/api/documents)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| pdfmonkey, | ||
| documentId: { | ||
| propDefinition: [ | ||
| pdfmonkey, | ||
| "documentId", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const document = await this.pdfmonkey.getDocument({ | ||
| $, | ||
| documentId: this.documentId, | ||
| }); | ||
| $.export("$summary", `Successfully found document with ID ${this.documentId}`); | ||
| return document; | ||
| }, | ||
| }; | ||
54 changes: 54 additions & 0 deletions
54
components/pdfmonkey/actions/generate-document/generate-document.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,54 @@ | ||
| import { STATUS_OPTIONS } from "../../common/constants.mjs"; | ||
| import pdfmonkey from "../../pdfmonkey.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "pdfmonkey-generate-document", | ||
| name: "Generate Document", | ||
| description: "Generates a new document using a specified template. [See the documentation](https://docs.pdfmonkey.io/references/api/documents)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| pdfmonkey, | ||
| templateId: { | ||
| propDefinition: [ | ||
| pdfmonkey, | ||
| "templateId", | ||
| ], | ||
| }, | ||
| payload: { | ||
| type: "object", | ||
| label: "Payload", | ||
| description: "Data to use for the Document generation.", | ||
| optional: true, | ||
| }, | ||
| meta: { | ||
| type: "object", | ||
| label: "Meta", | ||
| description: "Meta-Data to attach to the Document.", | ||
| optional: true, | ||
| }, | ||
| status: { | ||
| type: "string", | ||
| label: "Status", | ||
| description: "The status of the document", | ||
| options: STATUS_OPTIONS, | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.pdfmonkey.createDocument({ | ||
| $, | ||
| data: { | ||
| document: { | ||
| document_template_id: this.templateId, | ||
| payload: this.payload, | ||
| meta: this.meta, | ||
| status: this.status, | ||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| $.export("$summary", `Successfully generated document with ID ${response.document.id}`); | ||
| return response; | ||
| }, | ||
| }; | ||
This file was deleted.
Oops, something went wrong.
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,10 @@ | ||
| export const STATUS_OPTIONS = [ | ||
| { | ||
| label: "Draft (Default)", | ||
| value: "draft", | ||
| }, | ||
| { | ||
| label: "Pending (To trigger generation)", | ||
| value: "pending", | ||
| }, | ||
| ]; | ||
luancazarine 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,18 +1,18 @@ | ||
| { | ||
| "name": "@pipedream/pdfmonkey", | ||
| "version": "0.0.3", | ||
| "version": "0.1.0", | ||
| "description": "Pipedream PDFMonkey Components", | ||
| "main": "dist/app/pdfmonkey.app.mjs", | ||
| "main": "pdfmonkey.app.mjs", | ||
| "keywords": [ | ||
| "pipedream", | ||
| "pdfmonkey" | ||
| ], | ||
| "files": [ | ||
| "dist" | ||
| ], | ||
| "homepage": "https://pipedream.com/apps/pdfmonkey", | ||
| "author": "Pipedream <support@pipedream.com> (https://pipedream.com/)", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "@pipedream/platform": "^3.0.3" | ||
| } | ||
| } |
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,135 @@ | ||
| import { axios } from "@pipedream/platform"; | ||
|
|
||
| export default { | ||
| type: "app", | ||
| app: "pdfmonkey", | ||
| propDefinitions: { | ||
| templateId: { | ||
| type: "string", | ||
| label: "Template ID", | ||
| description: "The unique identifier of the document template.", | ||
| async options({ page }) { | ||
| const { document_template_cards: data } = await this.listTemplates({ | ||
| params: { | ||
| "page[number]": page, | ||
| }, | ||
| }); | ||
|
|
||
| return data.map(({ | ||
| id: value, identifier: label, | ||
| }) => ({ | ||
| label, | ||
| value, | ||
| })); | ||
| }, | ||
| }, | ||
| documentId: { | ||
| type: "string", | ||
| label: "Document ID", | ||
| description: "The unique identifier of the document.", | ||
| async options({ page }) { | ||
| const { document_cards: data } = await this.listDocuments({ | ||
| params: { | ||
| "page[number]": page, | ||
| }, | ||
| }); | ||
|
|
||
| return data.map(({ | ||
| id: value, filename, | ||
| }) => ({ | ||
| label: `${value}${filename | ||
| ? ` - ${filename}` | ||
| : ""}`, | ||
| value, | ||
| })); | ||
| }, | ||
| }, | ||
| }, | ||
| methods: { | ||
| _baseUrl() { | ||
| return "https://api.pdfmonkey.io/api/v1"; | ||
| }, | ||
| _headers() { | ||
| return { | ||
| "Authorization": `Bearer ${this.$auth.api_key}`, | ||
| }; | ||
| }, | ||
| _makeRequest({ | ||
| $ = this, path, ...opts | ||
| }) { | ||
| return axios($, { | ||
| url: this._baseUrl() + path, | ||
| headers: this._headers(), | ||
| ...opts, | ||
| }); | ||
| }, | ||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| createDocument(opts = {}) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| path: "/documents", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| deleteDocument({ | ||
| documentId, ...opts | ||
| }) { | ||
| return this._makeRequest({ | ||
| method: "DELETE", | ||
| path: `/documents/${documentId}`, | ||
| ...opts, | ||
| }); | ||
| }, | ||
| getDocument({ | ||
| documentId, ...opts | ||
| }) { | ||
| return this._makeRequest({ | ||
| path: `/documents/${documentId}`, | ||
| ...opts, | ||
| }); | ||
| }, | ||
| listDocuments(opts = {}) { | ||
| return this._makeRequest({ | ||
| path: "/document_cards", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| listTemplates(opts = {}) { | ||
| return this._makeRequest({ | ||
| path: "/document_template_cards", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| async *paginate({ | ||
| fn, params = {}, maxResults = null, ...opts | ||
| }) { | ||
| let hasMore = false; | ||
| let count = 0; | ||
| let page = 0; | ||
|
|
||
| do { | ||
| params["page[number]"] = ++page; | ||
|
|
||
| const { | ||
| document_cards: data, | ||
| meta: { | ||
| current_page, total_pages, | ||
| }, | ||
| } = await fn({ | ||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| params, | ||
| ...opts, | ||
| }); | ||
|
|
||
| for (const d of data) { | ||
| yield d; | ||
|
|
||
| if (maxResults && ++count === maxResults) { | ||
| return count; | ||
| } | ||
| } | ||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| hasMore = current_page < total_pages; | ||
|
|
||
| } while (hasMore); | ||
| }, | ||
| }, | ||
| }; | ||
67 changes: 67 additions & 0 deletions
67
components/pdfmonkey/sources/new-document-generated/new-document-generated.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,67 @@ | ||
| import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; | ||
| import pdfmonkey from "../../pdfmonkey.app.mjs"; | ||
| import sampleEmit from "./test-event.mjs"; | ||
|
|
||
| export default { | ||
| key: "pdfmonkey-new-document-generated", | ||
| name: "New Document Generated", | ||
| description: "Emit new event when a document's generation is completed.", | ||
| version: "0.0.1", | ||
| type: "source", | ||
| dedupe: "unique", | ||
| props: { | ||
| pdfmonkey, | ||
| db: "$.service.db", | ||
| timer: { | ||
| type: "$.interface.timer", | ||
| default: { | ||
| intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, | ||
| }, | ||
| }, | ||
| }, | ||
| methods: { | ||
| _getLastDate() { | ||
| return this.db.get("lastDate") || 0; | ||
| }, | ||
| _setLastDate(lastDate) { | ||
| this.db.set("lastDate", lastDate); | ||
| }, | ||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| async emitEvent(maxResults = false) { | ||
| const lastDate = this._getLastDate(); | ||
| const response = this.pdfmonkey.paginate({ | ||
| fn: this.pdfmonkey.listDocuments, | ||
| maxResults, | ||
| params: { | ||
| "q[status]": "success", | ||
| "q[updated_since]": lastDate, | ||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| }); | ||
|
|
||
| let responseArray = []; | ||
| for await (const item of response) { | ||
| responseArray.push(item); | ||
| } | ||
|
|
||
| if (responseArray.length) { | ||
| this._setLastDate(Date.parse(responseArray[0].created_at)); | ||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| for (const item of responseArray.reverse()) { | ||
| this.$emit(item, { | ||
| id: item.id, | ||
| summary: `Document ${item.filename || item.id} Generation Completed`, | ||
| ts: Date.parse(item.created_at), | ||
| }); | ||
| } | ||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| }, | ||
| hooks: { | ||
| async deploy() { | ||
| await this.emitEvent(25); | ||
| }, | ||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| async run() { | ||
| await this.emitEvent(); | ||
| }, | ||
| sampleEmit, | ||
| }; | ||
14 changes: 14 additions & 0 deletions
14
components/pdfmonkey/sources/new-document-generated/test-event.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,14 @@ | ||
| export default { | ||
| "id": "11475e57-0334-4ad5-8896-9462a2243957", | ||
| "app_id": "c2b67b84-4aac-49ea-bed8-69a15d7a65d3", | ||
| "created_at": "2022-04-07T11:01:38.201+02:00", | ||
| "document_template_id": "96611e9e-ab03-4ac3-8551-1b485210c892", | ||
| "document_template_identifier": "My Awesome Template", | ||
| "download_url": "https://pdfmonkey.s3.eu-west-1.amazonaws.com/production/backend/document/11475e57-0334-4ad5-8896-9462a2243957/my-test-document.pdf?response-content-disposition=attachment&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJ2ZTKW4HMOLK63IQ%2F20220406%2Feu-west-1%2Fs3%2Faws4_request&X-Amz-Date=20220407T204150Z&X-Amz-Expires=900&X-Amz-SignedHeaders=host&X-Amz-Signature=24e3a8c0801ad8d1efd6aaa22d946ee70f5c8d5b55c586f346a094afa5046c77", | ||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "failure_cause": null, | ||
| "filename": "my-test-document.pdf", | ||
| "meta": "{ \"_filename\":\"my-test-document.pdf\" }", | ||
| "public_share_link": "https://files.pdfmonkey.io/share/5CEA8C37-D130-4C19-9E11-72BE2293C82B/my-test-document.pdf", | ||
| "status": "success", | ||
| "updated_at": "2022-04-03T11:12:56.023+02:00" | ||
| } | ||
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.