Skip to content

Commit

Permalink
New Components - documenso (#13727)
Browse files Browse the repository at this point in the history
* documenso init

* new components

* pnpm-lock.yaml

* fix key

* updates

* pnpm-lock.yaml
  • Loading branch information
michelle0927 authored Sep 4, 2024
1 parent 1d10fc4 commit 3174491
Show file tree
Hide file tree
Showing 13 changed files with 430 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import documenso from "../../documenso.app.mjs";

export default {
key: "documenso-add-recipient-to-document",
name: "Add Recipient To Document",
description: "Add a recipient to an existing Documenso document. [See the documentation]([See the documentation](https://app.documenso.com/api/v1/openapi))",
version: "0.0.1",
type: "action",
props: {
documenso,
documentId: {
propDefinition: [
documenso,
"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.documenso.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 documenso from "../../documenso.app.mjs";

export default {
key: "documenso-create-document-from-template",
name: "Create Document From Template",
description: "Create a new document in Documenso from a pre-existing template. [See the documentation](https://app.documenso.com/api/v1/openapi)",
version: "0.0.1",
type: "action",
props: {
documenso,
templateId: {
propDefinition: [
documenso,
"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.documenso.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/documenso/actions/send-document/send-document.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import documenso from "../../documenso.app.mjs";

export default {
key: "documenso-send-document",
name: "Send Document",
description: "Send a document within Documenso for signing. [See the documentation](https://app.documenso.com/api/v1/openapi)",
version: "0.0.1",
type: "action",
props: {
documenso,
documentId: {
propDefinition: [
documenso,
"documentId",
],
},
},
async run({ $ }) {
const response = await this.documenso.sendDocumentForSigning({
$,
documentId: this.documentId,
data: {
sendEmail: true,
},
});
$.export("$summary", `Document with ID ${this.documentId} sent successfully.`);
return response;
},
};
107 changes: 103 additions & 4 deletions components/documenso/documenso.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: "documenso",
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/documenso/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/documenso",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Documenso Components",
"main": "documenso.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/documenso/sources/common/base.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import documenso from "../../documenso.app.mjs";
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";

export default {
props: {
documenso,
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.documenso.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: "documenso-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/documenso/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"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import common from "../common/base.mjs";
import sampleEmit from "./test-event.mjs";

export default {
...common,
key: "documenso-new-document-created",
name: "New Document Created",
description: "Emit new event when a new document is created.",
version: "0.0.1",
type: "source",
dedupe: "unique",
methods: {
...common.methods,
getTsField() {
return "createdAt";
},
generateMeta(doc) {
return {
id: doc.id,
summary: `New Document Created: ${doc.id}`,
ts: Date.parse(doc[this.getTsField()]),
};
},
},
sampleEmit,
};
Loading

0 comments on commit 3174491

Please sign in to comment.