Skip to content

Commit a8feaa8

Browse files
committed
feat: added component for docnify
1 parent 179f54b commit a8feaa8

File tree

13 files changed

+452
-0
lines changed

13 files changed

+452
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import docnify from "../../docnify.app.mjs";
2+
3+
export default {
4+
key: "docnify-add-recipient-to-document",
5+
name: "Add Recipient To Document",
6+
description: "Add a recipient to an existing Docnify document. [See the documentation]([See the documentation](https://app.docnify.io/api/v1/openapi))",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
docnify,
11+
documentId: {
12+
propDefinition: [
13+
docnify,
14+
"documentId",
15+
],
16+
},
17+
name: {
18+
type: "string",
19+
label: "Name",
20+
description: "Name of the recipient",
21+
},
22+
email: {
23+
type: "string",
24+
label: "Email",
25+
description: "Email address of the recipient",
26+
},
27+
},
28+
async run({ $ }) {
29+
const response = await this.docnify.addRecipientToDocument({
30+
$,
31+
documentId: this.documentId,
32+
data: {
33+
name: this.name,
34+
email: this.email,
35+
role: "SIGNER",
36+
},
37+
});
38+
39+
$.export("$summary", `Successfully added recipient to document ${this.documentId}`);
40+
return response;
41+
},
42+
};
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import docnify from "../../docnify.app.mjs";
2+
3+
export default {
4+
key: "docnify-create-document-from-template",
5+
name: "Create Document From Template",
6+
description: "Create a new document in Docnify from a pre-existing template. [See the documentation](https://app.docnify.io/api/v1/openapi)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
docnify,
11+
templateId: {
12+
propDefinition: [
13+
docnify,
14+
"templateId",
15+
],
16+
},
17+
title: {
18+
type: "string",
19+
label: "Title",
20+
description: "Document title. Will override the original title defined in the template.",
21+
optional: true,
22+
},
23+
subject: {
24+
type: "string",
25+
label: "Subject",
26+
description: "Document subject. Will override the original subject defined in the template.",
27+
optional: true,
28+
},
29+
message: {
30+
type: "string",
31+
label: "Message",
32+
description: "Document message. Will override the original message defined in the template.",
33+
optional: true,
34+
},
35+
},
36+
async run({ $ }) {
37+
const response = await this.docnify.createDocumentFromTemplate({
38+
$,
39+
templateId: this.templateId,
40+
data: {
41+
title: this.title,
42+
recipients: [],
43+
meta: this.subject || this.message
44+
? {
45+
subject: this.subject,
46+
message: this.message,
47+
}
48+
: undefined,
49+
},
50+
});
51+
$.export("$summary", `Successfully created document with ID: ${response.documentId}`);
52+
return response;
53+
},
54+
};
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import docnify from "../../docnify.app.mjs";
2+
3+
export default {
4+
key: "docnify-send-document",
5+
name: "Send Document",
6+
description: "Send a document within Docnify for signing. [See the documentation](https://app.docnify.io/api/v1/openapi)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
docnify,
11+
documentId: {
12+
propDefinition: [
13+
docnify,
14+
"documentId",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const response = await this.docnify.sendDocumentForSigning({
20+
$,
21+
documentId: this.documentId,
22+
data: {
23+
sendEmail: true,
24+
},
25+
});
26+
$.export("$summary", `Document with ID ${this.documentId} sent successfully.`);
27+
return response;
28+
},
29+
};

components/docnify/docnify.app.mjs

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import { axios } from "@pipedream/platform";
2+
3+
export default {
4+
type: "app",
5+
app: "docnify",
6+
propDefinitions: {
7+
templateId: {
8+
type: "string",
9+
label: "Template ID",
10+
description: "The ID of the pre-existing template",
11+
async options({ page }) {
12+
const { templates } = await this.listTemplates({
13+
params: {
14+
page: page + 1,
15+
},
16+
});
17+
return templates?.map(({
18+
id: value, title: label,
19+
}) => ({
20+
value,
21+
label,
22+
})) || [];
23+
},
24+
},
25+
documentId: {
26+
type: "string",
27+
label: "Document ID",
28+
description: "The ID of the document",
29+
async options({ page }) {
30+
const { documents } = await this.listDocuments({
31+
params: {
32+
page: page + 1,
33+
},
34+
});
35+
return documents?.map(({
36+
id: value, title: label,
37+
}) => ({
38+
value,
39+
label,
40+
})) || [];
41+
},
42+
},
43+
},
44+
methods: {
45+
_baseUrl() {
46+
return `${this.$auth.url}/api/v1`;
47+
},
48+
_makeRequest(opts = {}) {
49+
const {
50+
$ = this,
51+
path,
52+
...otherOpts
53+
} = opts;
54+
return axios($, {
55+
...otherOpts,
56+
url: `${this._baseUrl()}${path}`,
57+
headers: {
58+
Authorization: `${this.$auth.api_token}`,
59+
},
60+
});
61+
},
62+
listTemplates(opts = {}) {
63+
return this._makeRequest({
64+
path: "/templates",
65+
...opts,
66+
});
67+
},
68+
listDocuments(opts = {}) {
69+
return this._makeRequest({
70+
path: "/documents",
71+
...opts,
72+
});
73+
},
74+
getDocument({
75+
documentId, ...opts
76+
}) {
77+
return this._makeRequest({
78+
path: `/documents/${documentId}`,
79+
...opts,
80+
});
81+
},
82+
createDocumentFromTemplate({
83+
templateId, ...opts
84+
}) {
85+
return this._makeRequest({
86+
method: "POST",
87+
path: `/templates/${templateId}/generate-document`,
88+
...opts,
89+
});
90+
},
91+
sendDocumentForSigning({
92+
documentId, ...opts
93+
}) {
94+
return this._makeRequest({
95+
method: "POST",
96+
path: `/documents/${documentId}/send`,
97+
...opts,
98+
});
99+
},
100+
addRecipientToDocument({
101+
documentId, ...opts
102+
}) {
103+
return this._makeRequest({
104+
method: "POST",
105+
path: `/documents/${documentId}/recipients`,
106+
...opts,
107+
});
108+
},
109+
},
110+
};

components/docnify/package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "@pipedream/docnify",
3+
"version": "0.1.0",
4+
"description": "Pipedream Docnify Components",
5+
"main": "docnify.app.mjs",
6+
"keywords": [
7+
"pipedream",
8+
"docnify"
9+
],
10+
"homepage": "https://pipedream.com/apps/docnify",
11+
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
12+
"publishConfig": {
13+
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.1"
17+
}
18+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import docnify from "../../docnify.app.mjs";
2+
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
3+
4+
export default {
5+
props: {
6+
docnify,
7+
db: "$.service.db",
8+
timer: {
9+
type: "$.interface.timer",
10+
default: {
11+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
12+
},
13+
},
14+
},
15+
methods: {
16+
_getLastTs() {
17+
return this.db.get("lastTs") || 0;
18+
},
19+
_setLastTs(lastTs) {
20+
this.db.set("lastTs", lastTs);
21+
},
22+
isRelevant() {
23+
return true;
24+
},
25+
generateMeta() {
26+
throw new Error("generateMeta is not implemented");
27+
},
28+
},
29+
async run() {
30+
const lastTs = this._getLastTs();
31+
let maxTs = lastTs;
32+
const tsField = this.getTsField();
33+
34+
const docs = [];
35+
let total;
36+
const params = {
37+
page: 1,
38+
};
39+
do {
40+
const { documents } = await this.docnify.listDocuments({
41+
params,
42+
});
43+
for (const doc of documents) {
44+
const ts = Date.parse(doc[tsField]);
45+
if (ts >= lastTs) {
46+
if (await this.isRelevant(doc, lastTs)) {
47+
docs.push(doc);
48+
}
49+
maxTs = Math.max(ts, maxTs);
50+
}
51+
}
52+
total = documents?.length;
53+
params.page++;
54+
} while (total > 0);
55+
56+
for (const doc of docs) {
57+
const meta = await this.generateMeta(doc);
58+
this.$emit(doc, meta);
59+
}
60+
61+
this._setLastTs(maxTs);
62+
},
63+
};
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import common from "../common/base.mjs";
2+
import sampleEmit from "./test-event.mjs";
3+
4+
export default {
5+
...common,
6+
key: "docnify-new-document-completed",
7+
name: "New Document Completed",
8+
description: "Emit new event when a document is signed by all recipients.",
9+
version: "0.0.1",
10+
type: "source",
11+
dedupe: "unique",
12+
methods: {
13+
...common.methods,
14+
getTsField() {
15+
return "updatedAt";
16+
},
17+
isRelevant(doc) {
18+
return doc.status === "COMPLETED";
19+
},
20+
generateMeta(doc) {
21+
return {
22+
id: doc.id,
23+
summary: `New Document Completed: ${doc.id}`,
24+
ts: Date.parse(doc[this.getTsField()]),
25+
};
26+
},
27+
},
28+
sampleEmit,
29+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export default {
2+
"id": 21983,
3+
"externalId": null,
4+
"userId": 6780,
5+
"teamId": null,
6+
"title": "file-sample_150kB.pdf",
7+
"status": "COMPLETED",
8+
"documentDataId": "cm0eaghs2002nl70cza7g41z1",
9+
"createdAt": "2024-08-28T20:08:22.289Z",
10+
"updatedAt": "2024-08-28T20:24:03.342Z",
11+
"completedAt": "2024-08-28T20:24:03.342Z"
12+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import common from "../common/base.mjs";
2+
import sampleEmit from "./test-event.mjs";
3+
4+
export default {
5+
...common,
6+
key: "docnify-new-document-created",
7+
name: "New Document Created",
8+
description: "Emit new event when a new document is created.",
9+
version: "0.0.1",
10+
type: "source",
11+
dedupe: "unique",
12+
methods: {
13+
...common.methods,
14+
getTsField() {
15+
return "createdAt";
16+
},
17+
generateMeta(doc) {
18+
return {
19+
id: doc.id,
20+
summary: `New Document Created: ${doc.id}`,
21+
ts: Date.parse(doc[this.getTsField()]),
22+
};
23+
},
24+
},
25+
sampleEmit,
26+
};

0 commit comments

Comments
 (0)