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
53 changes: 53 additions & 0 deletions components/documerge/actions/combine-files/combine-files.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import documerge from "../../documerge.app.mjs";
import fs from "fs";

export default {
key: "documerge-combine-files",
name: "Combine Files",
description: "Merges multiple user-specified files into a single PDF or DOCX. [See the documentation](https://app.documerge.ai/api-docs/#tools-POSTapi-tools-combine)",
version: "0.0.1",
type: "action",
props: {
documerge,
name: {
type: "string",
label: "Name",
description: "Name of the new file",
},
output: {
type: "string",
label: "Output",
description: "The output file type",
options: [
"pdf",
"docx",
],
},
urls: {
type: "string[]",
label: "URLs",
description: "Array of URLs to combine",
},
},
async run({ $ }) {
const fileContent = await this.documerge.combineFiles({
$,
data: {
output: this.output,
files: this.urls.map((url) => ({
name: this.name,
url,
})),
},
});

const filename = this.name.includes(".pdf") || this.name.includes(".docx")
? this.name
: `${this.name}.${this.output}`;
const path = `/tmp/${filename}`;
await fs.writeFileSync(path, Buffer.from(fileContent));

$.export("$summary", "Successfully combined files");
return path;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import documerge from "../../documerge.app.mjs";
import fs from "fs";

export default {
key: "documerge-convert-file-to-pdf",
name: "Convert File to PDF",
description: "Converts a specified file into a PDF. [See the documentation](https://app.documerge.ai/api-docs/#tools-POSTapi-tools-pdf-convert)",
version: "0.0.1",
type: "action",
props: {
documerge,
name: {
type: "string",
label: "Name",
description: "Name of the new file",
},
url: {
type: "string",
label: "URL",
description: "The URL of the file to convert",
optional: true,
},
},
async run({ $ }) {
const fileContent = await this.documerge.convertToPdf({
$,
data: {
file: {
name: this.name,
url: this.url,
},
},
});

const filename = this.name.includes(".pdf")
? this.name
: `${this.name}.pdf`;
const path = `/tmp/${filename}`;
await fs.writeFileSync(path, Buffer.from(fileContent));

$.export("$summary", "Successfully converted file to PDF");
return path;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import documerge from "../../documerge.app.mjs";

export default {
key: "documerge-get-document-fields",
name: "Get Document Fields",
description: "Extracts and returns data from fields in a given document. [See the documentation](https://app.documerge.ai/api-docs/#documents-GETapi-documents-fields--document_id-)",
version: "0.0.1",
type: "action",
props: {
documerge,
documentId: {
propDefinition: [
documerge,
"documentId",
],
},
},
async run({ $ }) {
const response = await this.documerge.getDocumentFields({
$,
documentId: this.documentId,
});
$.export("$summary", `Successfully extracted field values from document with ID: ${this.documentId}`);
return response;
},
};
128 changes: 123 additions & 5 deletions components/documerge/documerge.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,129 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "documerge",
propDefinitions: {},
propDefinitions: {
documentId: {
type: "string",
label: "Document ID",
description: "Identifier of a document",
async options() {
const { data } = await this.listDocuments();
return data?.map(({
id: value, name: label,
}) => ({
value,
label,
})) || [];
},
},
routeId: {
type: "string",
label: "Routet ID",
description: "Identifier of a route",
async options() {
const { data } = await this.listRoutes();
return data?.map(({
id: value, name: label,
}) => ({
value,
label,
})) || [];
},
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://app.documerge.ai/api";
},
_makeRequest(opts = {}) {
const {
$ = this,
path,
...otherOpts
} = opts;
return axios($, {
...otherOpts,
url: `${this._baseUrl()}${path}`,
headers: {
"Authorization": `Bearer ${this.$auth.api_token}`,
"Content-Type": "application/json",
"Accept": "application/json",
},
});
},
listDocuments(opts = {}) {
return this._makeRequest({
path: "/documents",
...opts,
});
},
listRoutes(opts = {}) {
return this._makeRequest({
path: "/routes",
...opts,
});
},
getDocumentFields({
documentId, ...opts
}) {
return this._makeRequest({
path: `/documents/fields/${documentId}`,
...opts,
});
},
combineFiles(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/tools/combine",
responseType: "arraybuffer",
...opts,
});
},
convertToPdf(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/tools/pdf/convert",
responseType: "arraybuffer",
...opts,
});
},
createDocumentDeliveryMethod({
documentId, ...opts
}) {
return this._makeRequest({
method: "POST",
path: `/documents/delivery-methods/${documentId}`,
...opts,
});
},
deleteDocumentDeliveryMethod({
documentId, deliveryMethodId, ...opts
}) {
return this._makeRequest({
method: "DELETE",
path: `/documents/delivery-methods/${documentId}/${deliveryMethodId}`,
...opts,
});
},
createRouteDeliveryMethod({
routeId, ...opts
}) {
return this._makeRequest({
method: "POST",
path: `/routes/delivery-methods/${routeId}`,
...opts,
});
},
deleteRouteDeliveryMethod({
routeId, deliveryMethodId, ...opts
}) {
return this._makeRequest({
method: "DELETE",
path: `/routes/delivery-methods/${routeId}/${deliveryMethodId}`,
...opts,
});
},
},
};
};
7 changes: 5 additions & 2 deletions components/documerge/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/documerge",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream DocuMerge Components",
"main": "documerge.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.0"
}
}
}
44 changes: 44 additions & 0 deletions components/documerge/sources/common/base.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import documerge from "../../documerge.app.mjs";

export default {
props: {
documerge,
http: "$.interface.http",
db: "$.service.db",
},
methods: {
_getDeliveryMethodIds() {
return this.db.get("deliveryMethodIds") || {};
},
_setDeliveryMethodIds(deliveryMethodIds) {
this.db.set("deliveryMethodIds", deliveryMethodIds);
},
getWebhookSettings() {
return {
type: "webhook",
settings: {
url: this.http.endpoint,
always_send: true,
send_temporary_download_url: true,
send_data_using_json: true,
send_merge_data: true,
},
};
},
generateMeta(body) {
return {
id: body.merge_id,
summary: this.getSummary(body),
ts: Date.now(),
};
},
getSummary() {
throw new Error("getSummary is not implemented");
},
},
async run(event) {
const { body } = event;
const meta = this.generateMeta(body);
this.$emit(body, meta);
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import common from "../common/base.mjs";
import sampleEmit from "./test-event.mjs";

export default {
...common,
key: "documerge-new-merged-document-instant",
name: "New Merged Document (Instant)",
description: "Emit new event when a merged document is created in documerge.",
version: "0.0.1",
type: "source",
dedupe: "unique",
props: {
...common.props,
documentIds: {
propDefinition: [
common.props.documerge,
"documentId",
],
type: "string[]",
label: "Document IDs",
description: "An array of document identifiers of the documents to watch",
},
},
hooks: {
async activate() {
const deliveryMethodIds = {};
for (const documentId of this.documentIds) {
const { data: { id } } = await this.documerge.createDocumentDeliveryMethod({
documentId,
data: this.getWebhookSettings(),
});
deliveryMethodIds[documentId] = id;
}
this._setDeliveryMethodIds(deliveryMethodIds);
},
async deactivate() {
const deliveryMethodIds = this._getDeliveryMethodIds();
for (const documentId of this.documentIds) {
await this.documerge.deleteDocumentDeliveryMethod({
documentId,
deliveryMethodId: deliveryMethodIds[documentId],
});
}
this._setDeliveryMethodIds({});
},
},
methods: {
...common.methods,
getSummary(body) {
return `Merged Document: ${body.file_name}`;
},
},
sampleEmit,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default {
"file_url": "https://documerge.blob.core.windows.net/documerge/documentMerges/408/294186/doc1_-_test.pdf?sv=2017-11-09&sr=b&se=2024-07-18T17:16:51Z&sp=r&spr=https&sig=%2F02yOVeuTEB66AihSptlTg7a7GYfxz3JGkxKE2kt94Y%3D",
"file_name": "doc1 - test.pdf",
"merge_id": 320214,
"fields": {
"field1": "test",
"_date": "2024-07-18",
"_datetime": "2024-07-18 12:16 pm",
"_ip": "10.1.0.4",
"_auto_number": null
}
}
Loading