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
2 changes: 1 addition & 1 deletion components/attio/attio.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
2 changes: 1 addition & 1 deletion components/bitbadges/bitbadges.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
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;
},
};
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 components/docnify/actions/send-document/send-document.mjs
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",
],
},
},
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;
},
};
109 changes: 104 additions & 5 deletions components/docnify/docnify.app.mjs
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,
})) || [];
},
},
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`;
},
_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,
});
},
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,
});
},
},
};
};
7 changes: 5 additions & 2 deletions components/docnify/package.json
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": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.1"
}
}
}
63 changes: 63 additions & 0 deletions components/docnify/sources/common/base.mjs
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";

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;
},
generateMeta() {
throw new Error("generateMeta is not implemented");
},
},
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);
},
};
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";
},
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 components/docnify/sources/new-document-completed/test-event.mjs
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"
}
Loading
Loading