Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
3 changes: 0 additions & 3 deletions components/pdfmonkey/.gitignore

This file was deleted.

26 changes: 26 additions & 0 deletions components/pdfmonkey/actions/delete-document/delete-document.mjs
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 components/pdfmonkey/actions/find-document/find-document.mjs
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;
},
};
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,
},
},
});

$.export("$summary", `Successfully generated document with ID ${response.document.id}`);
return response;
},
};
13 changes: 0 additions & 13 deletions components/pdfmonkey/app/pdfmonkey.app.ts

This file was deleted.

10 changes: 10 additions & 0 deletions components/pdfmonkey/common/constants.mjs
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",
},
];
10 changes: 5 additions & 5 deletions components/pdfmonkey/package.json
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 <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3"
}
}
135 changes: 135 additions & 0 deletions components/pdfmonkey/pdfmonkey.app.mjs
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,
});
},
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({
params,
...opts,
});

for (const d of data) {
yield d;

if (maxResults && ++count === maxResults) {
return count;
}
}

hasMore = !(current_page == total_pages);

} while (hasMore);
},
},
};
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);
},
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,
},
});

let responseArray = [];
for await (const item of response) {
responseArray.push(item);
}

if (responseArray.length) {
this._setLastDate(Date.parse(responseArray[0].created_at));
}

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),
});
}
},
},
hooks: {
async deploy() {
await this.emitEvent(25);
},
},
async run() {
await this.emitEvent();
},
sampleEmit,
};
14 changes: 14 additions & 0 deletions components/pdfmonkey/sources/new-document-generated/test-event.mjs
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",
"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"
}
5 changes: 4 additions & 1 deletion pnpm-lock.yaml

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

Loading