-
Notifications
You must be signed in to change notification settings - Fork 5.6k
PDF API IO - new components #19815
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
PDF API IO - new components #19815
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
31 changes: 31 additions & 0 deletions
31
components/pdf_api_io/actions/get-template/get-template.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,31 @@ | ||
| import pdfApiIo from "../../pdf_api_io.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "pdf_api_io-get-template", | ||
| name: "Get Template", | ||
| description: "Get a template by its ID. [See the documentation](https://pdf-api.io/en/docs/api/get-template)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| annotations: { | ||
| destructiveHint: false, | ||
| openWorldHint: true, | ||
| readOnlyHint: true, | ||
| }, | ||
| props: { | ||
| pdfApiIo, | ||
| templateId: { | ||
| propDefinition: [ | ||
| pdfApiIo, | ||
| "templateId", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const template = await this.pdfApiIo.getTemplate({ | ||
| $, | ||
| templateId: this.templateId, | ||
| }); | ||
| $.export("$summary", `Successfully retrieved template with ID: ${this.templateId}`); | ||
| return template; | ||
| }, | ||
| }; |
28 changes: 28 additions & 0 deletions
28
components/pdf_api_io/actions/list-templates/list-templates.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,28 @@ | ||
| import pdfApiIo from "../../pdf_api_io.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "pdf_api_io-list-templates", | ||
| name: "List Templates", | ||
| description: "List all templates of a user on PDF-API.io. [See the documentation](https://pdf-api.io/en/docs/api/templates)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| annotations: { | ||
| destructiveHint: false, | ||
| openWorldHint: true, | ||
| readOnlyHint: true, | ||
| }, | ||
| props: { | ||
| pdfApiIo, | ||
| }, | ||
| async run({ $ }) { | ||
| const templates = await this.pdfApiIo.listTemplates({ | ||
| $, | ||
| }); | ||
|
|
||
| $.export("$summary", `Successfully listed ${templates?.length ?? 0} template${templates?.length === 1 | ||
| ? "" | ||
| : "s"}`); | ||
|
|
||
| return templates; | ||
| }, | ||
| }; |
64 changes: 64 additions & 0 deletions
64
components/pdf_api_io/actions/merge-templates/merge-templates.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,64 @@ | ||
| import pdfApiIo from "../../pdf_api_io.app.mjs"; | ||
| import { parseObject } from "../../common/utils.mjs"; | ||
|
|
||
| export default { | ||
| key: "pdf_api_io-merge-templates", | ||
| name: "Merge Templates", | ||
| description: "Merge two templates into a single PDF document. Returns a URL to the PDF document. [See the documentation](https://pdf-api.io/en/docs/api/merge-templates)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| annotations: { | ||
| destructiveHint: false, | ||
| openWorldHint: true, | ||
| readOnlyHint: false, | ||
| }, | ||
| props: { | ||
| pdfApiIo, | ||
| template1: { | ||
| propDefinition: [ | ||
| pdfApiIo, | ||
| "templateId", | ||
| ], | ||
| label: "Template 1", | ||
| description: "The first template to merge", | ||
| }, | ||
| data1: { | ||
| type: "object", | ||
| label: "Data 1", | ||
| description: "An object containing key-value pairs representing the data to be used in the first template. The keys should match the placeholders you defined in the PDF template.", | ||
| }, | ||
| template2: { | ||
| propDefinition: [ | ||
| pdfApiIo, | ||
| "templateId", | ||
| ], | ||
| label: "Template 2", | ||
| description: "The second template to merge", | ||
| }, | ||
| data2: { | ||
| type: "object", | ||
| label: "Data 2", | ||
| description: "An object containing key-value pairs representing the data to be used in the second template. The keys should match the placeholders you defined in the PDF template.", | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.pdfApiIo.mergeTemplates({ | ||
| $, | ||
| data: { | ||
| templates: [ | ||
| { | ||
| id: this.template1, | ||
| data: parseObject(this.data1), | ||
| }, | ||
| { | ||
| id: this.template2, | ||
| data: parseObject(this.data2), | ||
| }, | ||
| ], | ||
| output: "url", | ||
| }, | ||
| }); | ||
| $.export("$summary", "Successfully merged templates"); | ||
| return response; | ||
| }, | ||
| }; |
41 changes: 41 additions & 0 deletions
41
components/pdf_api_io/actions/render-template/render-template.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,41 @@ | ||
| import pdfApiIo from "../../pdf_api_io.app.mjs"; | ||
| import { parseObject } from "../../common/utils.mjs"; | ||
|
|
||
| export default { | ||
| key: "pdf_api_io-render-template", | ||
| name: "Render Template", | ||
| description: "Dynamically create a PDF document from a template. Returns a URL to the PDF document. [See the documentation](https://pdf-api.io/en/docs/api/render-pdf)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| annotations: { | ||
| destructiveHint: false, | ||
| openWorldHint: true, | ||
| readOnlyHint: false, | ||
| }, | ||
| props: { | ||
| pdfApiIo, | ||
| templateId: { | ||
| propDefinition: [ | ||
| pdfApiIo, | ||
| "templateId", | ||
| ], | ||
| }, | ||
| data: { | ||
| type: "object", | ||
| label: "Data", | ||
| description: "An object containing key-value pairs representing the data to be replaced in the template. The keys should match the placeholders you defined in the PDF template.", | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.pdfApiIo.renderTemplate({ | ||
| $, | ||
| templateId: this.templateId, | ||
| data: { | ||
| data: parseObject(this.data), | ||
| output: "url", | ||
| }, | ||
| }); | ||
| $.export("$summary", `Successfully rendered template with ID: ${this.templateId}`); | ||
| return response; | ||
| }, | ||
| }; |
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,25 @@ | ||
| export const parseObject = (obj) => { | ||
| if (!obj) return undefined; | ||
|
|
||
| if (typeof obj === "string") { | ||
| try { | ||
| return JSON.parse(obj); | ||
| } catch (e) { | ||
| return obj; | ||
| } | ||
| } | ||
|
|
||
| if (Array.isArray(obj)) { | ||
| return obj.map((item) => parseObject(item)); | ||
| } | ||
|
|
||
| if (typeof obj === "object") { | ||
| for (const [ | ||
| key, | ||
| value, | ||
| ] of Object.entries(obj)) { | ||
| obj[key] = parseObject(value); | ||
| } | ||
| } | ||
| return obj; | ||
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
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,66 @@ | ||
| import { axios } from "@pipedream/platform"; | ||
|
|
||
| export default { | ||
| type: "app", | ||
| app: "pdf_api_io", | ||
| propDefinitions: {}, | ||
| propDefinitions: { | ||
| templateId: { | ||
| type: "string", | ||
| label: "Template ID", | ||
| description: "The ID of the template", | ||
| async options() { | ||
| const templates = await this.listTemplates(); | ||
| return templates?.map((template) => ({ | ||
| label: template.name, | ||
| value: template.id, | ||
| })) || []; | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| }, | ||
| methods: { | ||
| // this.$auth contains connected account data | ||
| authKeys() { | ||
| console.log(Object.keys(this.$auth)); | ||
| _baseUrl() { | ||
| return "https://pdf-api.io/api"; | ||
| }, | ||
| _makeRequest({ | ||
| $ = this, path, ...opts | ||
| }) { | ||
| return axios($, { | ||
| url: `${this._baseUrl()}${path}`, | ||
| headers: { | ||
| Authorization: `Bearer ${this.$auth.api_token}`, | ||
| }, | ||
| ...opts, | ||
| }); | ||
| }, | ||
| getTemplate({ | ||
| templateId, ...opts | ||
| }) { | ||
| return this._makeRequest({ | ||
| path: `/templates/${templateId}`, | ||
| ...opts, | ||
| }); | ||
| }, | ||
| listTemplates(opts = {}) { | ||
| return this._makeRequest({ | ||
| path: "/templates", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| renderTemplate({ | ||
| templateId, ...opts | ||
| }) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| path: `/templates/${templateId}/pdf`, | ||
| ...opts, | ||
| }); | ||
| }, | ||
| mergeTemplates(opts = {}) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| path: "/templates/merge", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.