-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New Components - Docnify #14203
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 - Docnify #14203
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
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 |
|---|---|---|
|
|
@@ -8,4 +8,4 @@ export default { | |
| console.log(Object.keys(this.$auth)); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
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 |
|---|---|---|
|
|
@@ -8,4 +8,4 @@ export default { | |
| console.log(Object.keys(this.$auth)); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
42 changes: 42 additions & 0 deletions
42
components/docnify/actions/add-recipient-to-document/add-recipient-to-document.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,42 @@ | ||
| import docnify from "../../docnify.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "docnify-add-recipient-to-document", | ||
| name: "Add Recipient To Document", | ||
| description: "Add a recipient to an existing Docnify document. [See the documentation]([See the documentation](https://app.docnify.io/api/v1/openapi))", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| docnify, | ||
| documentId: { | ||
| propDefinition: [ | ||
| docnify, | ||
| "documentId", | ||
| ], | ||
| }, | ||
| name: { | ||
| type: "string", | ||
| label: "Name", | ||
| description: "Name of the recipient", | ||
| }, | ||
| email: { | ||
| type: "string", | ||
| label: "Email", | ||
| description: "Email address of the recipient", | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.docnify.addRecipientToDocument({ | ||
| $, | ||
| documentId: this.documentId, | ||
| data: { | ||
| name: this.name, | ||
| email: this.email, | ||
| role: "SIGNER", | ||
| }, | ||
| }); | ||
|
|
||
| $.export("$summary", `Successfully added recipient to document ${this.documentId}`); | ||
| return response; | ||
| }, | ||
| }; | ||
54 changes: 54 additions & 0 deletions
54
components/docnify/actions/create-document-from-template/create-document-from-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,54 @@ | ||
| import docnify from "../../docnify.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "docnify-create-document-from-template", | ||
| name: "Create Document From Template", | ||
| description: "Create a new document in Docnify from a pre-existing template. [See the documentation](https://app.docnify.io/api/v1/openapi)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| docnify, | ||
| templateId: { | ||
| propDefinition: [ | ||
| docnify, | ||
| "templateId", | ||
| ], | ||
| }, | ||
| title: { | ||
| type: "string", | ||
| label: "Title", | ||
| description: "Document title. Will override the original title defined in the template.", | ||
| optional: true, | ||
| }, | ||
| subject: { | ||
| type: "string", | ||
| label: "Subject", | ||
| description: "Document subject. Will override the original subject defined in the template.", | ||
| optional: true, | ||
| }, | ||
| message: { | ||
| type: "string", | ||
| label: "Message", | ||
| description: "Document message. Will override the original message defined in the template.", | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.docnify.createDocumentFromTemplate({ | ||
| $, | ||
| templateId: this.templateId, | ||
| data: { | ||
| title: this.title, | ||
| recipients: [], | ||
| meta: this.subject || this.message | ||
| ? { | ||
| subject: this.subject, | ||
| message: this.message, | ||
| } | ||
| : undefined, | ||
| }, | ||
| }); | ||
| $.export("$summary", `Successfully created document with ID: ${response.documentId}`); | ||
| return response; | ||
| }, | ||
| }; |
29 changes: 29 additions & 0 deletions
29
components/docnify/actions/send-document/send-document.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,29 @@ | ||
| import docnify from "../../docnify.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "docnify-send-document", | ||
| name: "Send Document", | ||
| description: "Send a document within Docnify for signing. [See the documentation](https://app.docnify.io/api/v1/openapi)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| docnify, | ||
| documentId: { | ||
| propDefinition: [ | ||
| docnify, | ||
| "documentId", | ||
| ], | ||
| }, | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| async run({ $ }) { | ||
| const response = await this.docnify.sendDocumentForSigning({ | ||
| $, | ||
| documentId: this.documentId, | ||
| data: { | ||
| sendEmail: true, | ||
| }, | ||
| }); | ||
| $.export("$summary", `Document with ID ${this.documentId} sent successfully.`); | ||
| return response; | ||
| }, | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,110 @@ | ||
| import { axios } from "@pipedream/platform"; | ||
|
|
||
| export default { | ||
| type: "app", | ||
| app: "docnify", | ||
| propDefinitions: {}, | ||
| propDefinitions: { | ||
| templateId: { | ||
| type: "string", | ||
| label: "Template ID", | ||
| description: "The ID of the pre-existing template", | ||
| async options({ page }) { | ||
| const { templates } = await this.listTemplates({ | ||
| params: { | ||
| page: page + 1, | ||
| }, | ||
| }); | ||
| return templates?.map(({ | ||
| id: value, title: label, | ||
| }) => ({ | ||
| value, | ||
| label, | ||
| })) || []; | ||
| }, | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| documentId: { | ||
| type: "string", | ||
| label: "Document ID", | ||
| description: "The ID of the document", | ||
| async options({ page }) { | ||
| const { documents } = await this.listDocuments({ | ||
| params: { | ||
| page: page + 1, | ||
| }, | ||
| }); | ||
| return documents?.map(({ | ||
| id: value, title: label, | ||
| }) => ({ | ||
| value, | ||
| label, | ||
| })) || []; | ||
| }, | ||
| }, | ||
| }, | ||
| methods: { | ||
| // this.$auth contains connected account data | ||
| authKeys() { | ||
| console.log(Object.keys(this.$auth)); | ||
| _baseUrl() { | ||
| return `${this.$auth.url}/api/v1`; | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| _makeRequest(opts = {}) { | ||
| const { | ||
| $ = this, | ||
| path, | ||
| ...otherOpts | ||
| } = opts; | ||
| return axios($, { | ||
| ...otherOpts, | ||
| url: `${this._baseUrl()}${path}`, | ||
| headers: { | ||
| Authorization: `${this.$auth.api_token}`, | ||
| }, | ||
| }); | ||
| }, | ||
| listTemplates(opts = {}) { | ||
| return this._makeRequest({ | ||
| path: "/templates", | ||
| ...opts, | ||
| }); | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| listDocuments(opts = {}) { | ||
| return this._makeRequest({ | ||
| path: "/documents", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| getDocument({ | ||
| documentId, ...opts | ||
| }) { | ||
| return this._makeRequest({ | ||
| path: `/documents/${documentId}`, | ||
| ...opts, | ||
| }); | ||
| }, | ||
| createDocumentFromTemplate({ | ||
| templateId, ...opts | ||
| }) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| path: `/templates/${templateId}/generate-document`, | ||
| ...opts, | ||
| }); | ||
| }, | ||
| sendDocumentForSigning({ | ||
| documentId, ...opts | ||
| }) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| path: `/documents/${documentId}/send`, | ||
| ...opts, | ||
| }); | ||
| }, | ||
| addRecipientToDocument({ | ||
| documentId, ...opts | ||
| }) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| path: `/documents/${documentId}/recipients`, | ||
| ...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/docnify", | ||
| "version": "0.0.1", | ||
| "version": "0.1.0", | ||
| "description": "Pipedream Docnify Components", | ||
| "main": "docnify.app.mjs", | ||
| "keywords": [ | ||
|
|
@@ -11,5 +11,8 @@ | |
| "author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "@pipedream/platform": "^3.0.1" | ||
| } | ||
| } | ||
| } | ||
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,63 @@ | ||
| import docnify from "../../docnify.app.mjs"; | ||
| import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export default { | ||
| props: { | ||
| docnify, | ||
| db: "$.service.db", | ||
| timer: { | ||
| type: "$.interface.timer", | ||
| default: { | ||
| intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, | ||
| }, | ||
| }, | ||
| }, | ||
| methods: { | ||
| _getLastTs() { | ||
| return this.db.get("lastTs") || 0; | ||
| }, | ||
| _setLastTs(lastTs) { | ||
| this.db.set("lastTs", lastTs); | ||
| }, | ||
| isRelevant() { | ||
| return true; | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| generateMeta() { | ||
| throw new Error("generateMeta is not implemented"); | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| async run() { | ||
| const lastTs = this._getLastTs(); | ||
| let maxTs = lastTs; | ||
| const tsField = this.getTsField(); | ||
|
|
||
| const docs = []; | ||
| let total; | ||
| const params = { | ||
| page: 1, | ||
| }; | ||
| do { | ||
| const { documents } = await this.docnify.listDocuments({ | ||
| params, | ||
| }); | ||
| for (const doc of documents) { | ||
| const ts = Date.parse(doc[tsField]); | ||
| if (ts >= lastTs) { | ||
| if (await this.isRelevant(doc, lastTs)) { | ||
| docs.push(doc); | ||
| } | ||
| maxTs = Math.max(ts, maxTs); | ||
| } | ||
| } | ||
| total = documents?.length; | ||
| params.page++; | ||
| } while (total > 0); | ||
|
|
||
| for (const doc of docs) { | ||
| const meta = await this.generateMeta(doc); | ||
| this.$emit(doc, meta); | ||
| } | ||
|
|
||
| this._setLastTs(maxTs); | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
29 changes: 29 additions & 0 deletions
29
components/docnify/sources/new-document-completed/new-document-completed.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,29 @@ | ||
| import common from "../common/base.mjs"; | ||
| import sampleEmit from "./test-event.mjs"; | ||
|
|
||
| export default { | ||
| ...common, | ||
| key: "docnify-new-document-completed", | ||
| name: "New Document Completed", | ||
| description: "Emit new event when a document is signed by all recipients.", | ||
| version: "0.0.1", | ||
| type: "source", | ||
| dedupe: "unique", | ||
| methods: { | ||
| ...common.methods, | ||
| getTsField() { | ||
| return "updatedAt"; | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| isRelevant(doc) { | ||
| return doc.status === "COMPLETED"; | ||
| }, | ||
| generateMeta(doc) { | ||
| return { | ||
| id: doc.id, | ||
| summary: `New Document Completed: ${doc.id}`, | ||
| ts: Date.parse(doc[this.getTsField()]), | ||
| }; | ||
| }, | ||
| }, | ||
| sampleEmit, | ||
| }; | ||
12 changes: 12 additions & 0 deletions
12
components/docnify/sources/new-document-completed/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 { | ||
| "id": 21983, | ||
| "externalId": null, | ||
| "userId": 6780, | ||
| "teamId": null, | ||
| "title": "file-sample_150kB.pdf", | ||
| "status": "COMPLETED", | ||
| "documentDataId": "cm0eaghs2002nl70cza7g41z1", | ||
| "createdAt": "2024-08-28T20:08:22.289Z", | ||
| "updatedAt": "2024-08-28T20:24:03.342Z", | ||
| "completedAt": "2024-08-28T20:24:03.342Z" | ||
| } |
Oops, something went wrong.
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.