Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions components/pdf_api_io/actions/get-template/get-template.mjs
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 components/pdf_api_io/actions/list-templates/list-templates.mjs
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 components/pdf_api_io/actions/merge-templates/merge-templates.mjs
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 components/pdf_api_io/actions/render-template/render-template.mjs
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;
},
};
25 changes: 25 additions & 0 deletions components/pdf_api_io/common/utils.mjs
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;
};
5 changes: 4 additions & 1 deletion components/pdf_api_io/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/pdf_api_io",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream PDF-API.io Components",
"main": "pdf_api_io.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.1.1"
}
}
65 changes: 60 additions & 5 deletions components/pdf_api_io/pdf_api_io.app.mjs
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,
})) || [];
},
},
},
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,
});
},
},
};
};
6 changes: 5 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.