-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New Components - documerge #12900
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 - documerge #12900
Changes from all commits
Commits
Show all changes
4 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
53 changes: 53 additions & 0 deletions
53
components/documerge/actions/combine-files/combine-files.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,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; | ||
| }, | ||
| }; | ||
44 changes: 44 additions & 0 deletions
44
components/documerge/actions/convert-file-to-pdf/convert-file-to-pdf.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,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; | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| }; | ||
26 changes: 26 additions & 0 deletions
26
components/documerge/actions/get-document-fields/get-document-fields.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 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; | ||
| }, | ||
| }; |
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,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", | ||
| }, | ||
| }); | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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, | ||
| }); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
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,6 +1,6 @@ | ||
| { | ||
| "name": "@pipedream/documerge", | ||
| "version": "0.0.1", | ||
| "version": "0.1.0", | ||
| "description": "Pipedream DocuMerge Components", | ||
| "main": "documerge.app.mjs", | ||
| "keywords": [ | ||
|
|
@@ -11,5 +11,8 @@ | |
| "author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "@pipedream/platform": "^3.0.0" | ||
| } | ||
| } | ||
| } | ||
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,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); | ||
| }, | ||
| }; |
54 changes: 54 additions & 0 deletions
54
components/documerge/sources/new-merged-document-instant/new-merged-document-instant.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 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({}); | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| methods: { | ||
| ...common.methods, | ||
| getSummary(body) { | ||
| return `Merged Document: ${body.file_name}`; | ||
| }, | ||
| }, | ||
| sampleEmit, | ||
| }; | ||
12 changes: 12 additions & 0 deletions
12
components/documerge/sources/new-merged-document-instant/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,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 | ||
| } | ||
| } |
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.