Skip to content

Commit 0282c90

Browse files
committed
papersign init
1 parent 8b0ffcd commit 0282c90

File tree

8 files changed

+530
-6
lines changed

8 files changed

+530
-6
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import papersign from "../../papersign.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "papersign-copy-document",
6+
name: "Copy Document",
7+
description: "Duplicates a given document. [See the documentation](https://paperform.readme.io/reference/papersigncopydocument)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
papersign,
12+
documentId: {
13+
propDefinition: [
14+
papersign,
15+
"documentId",
16+
],
17+
},
18+
name: {
19+
type: "string",
20+
label: "Name",
21+
description: "The new name of the copied document",
22+
optional: true,
23+
},
24+
spaceId: {
25+
propDefinition: [
26+
papersign,
27+
"spaceId",
28+
],
29+
optional: true,
30+
},
31+
path: {
32+
type: "string",
33+
label: "Path",
34+
description: "The path to copy the document to. Maximum depth is 4 levels.",
35+
optional: true,
36+
},
37+
folderId: {
38+
propDefinition: [
39+
papersign,
40+
"folderId",
41+
(c) => ({
42+
spaceId: c.spaceId,
43+
}),
44+
],
45+
optional: true,
46+
},
47+
},
48+
async run({ $ }) {
49+
const response = await this.papersign.duplicateDocument({
50+
documentId: this.documentId,
51+
name: this.name,
52+
spaceId: this.spaceId,
53+
path: this.path,
54+
folderId: this.folderId,
55+
});
56+
57+
$.export("$summary", `Successfully copied document: ${response.results.document.name}`);
58+
return response;
59+
},
60+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import papersign from "../../papersign.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "papersign-get-document",
6+
name: "Get Document",
7+
description: "Retrieve a document using a specified ID. [See the documentation](https://paperform.readme.io/reference/getpapersigndocument)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
papersign,
12+
documentId: {
13+
propDefinition: [
14+
papersign,
15+
"documentId",
16+
],
17+
},
18+
},
19+
async run({ $ }) {
20+
const response = await this.papersign.getDocument({
21+
documentId: this.documentId,
22+
});
23+
24+
$.export("$summary", `Successfully retrieved document with ID: ${this.documentId}`);
25+
return response;
26+
},
27+
};
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import papersign from "../../papersign.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "papersign-send-document",
6+
name: "Send Document",
7+
description: "Dispatches a document to a specified recipient. [See the documentation](https://paperform.readme.io/reference/papersignsenddocument)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
papersign,
12+
documentId: {
13+
propDefinition: [
14+
papersign,
15+
"documentId",
16+
],
17+
},
18+
expiration: {
19+
type: "string",
20+
label: "Expiration",
21+
description: "The expiration date of the document. Must be at least 30 minutes in the future.",
22+
optional: true,
23+
},
24+
inviteMessage: {
25+
type: "string",
26+
label: "Invite Message",
27+
description: "The message to include in the invitation email, up to 1000 characters.",
28+
optional: true,
29+
},
30+
fromUserEmail: {
31+
type: "string",
32+
label: "From User Email",
33+
description: "The email address of a User on your team's account to send the document from.",
34+
optional: true,
35+
},
36+
documentRecipientEmails: {
37+
type: "string[]",
38+
label: "Document Recipient Emails",
39+
description: "An array of recipient emails for the document.",
40+
optional: true,
41+
},
42+
automaticReminders: {
43+
type: "object",
44+
label: "Automatic Reminders",
45+
description: "An object for setting automatic reminders.",
46+
optional: true,
47+
},
48+
signers: {
49+
type: "string[]",
50+
label: "Signers",
51+
description: "An array of signer objects.",
52+
optional: true,
53+
},
54+
variables: {
55+
type: "string[]",
56+
label: "Variables",
57+
description: "An array of variable objects.",
58+
optional: true,
59+
},
60+
copy: {
61+
type: "boolean",
62+
label: "Copy",
63+
description: "Whether to copy before sending.",
64+
optional: true,
65+
},
66+
},
67+
async run({ $ }) {
68+
const response = await this.papersign.sendDocument({
69+
documentId: this.documentId,
70+
expiration: this.expiration,
71+
inviteMessage: this.inviteMessage,
72+
fromUserEmail: this.fromUserEmail,
73+
documentRecipientEmails: this.documentRecipientEmails,
74+
automaticReminders: this.automaticReminders,
75+
signers: this.signers,
76+
variables: this.variables,
77+
copy: this.copy,
78+
});
79+
$.export("$summary", `Document sent successfully with ID ${this.documentId}`);
80+
return response;
81+
},
82+
};

components/papersign/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
"publishConfig": {
1313
"access": "public"
1414
}
15-
}
15+
}
Lines changed: 118 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,124 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "papersign",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
documentId: {
8+
type: "string",
9+
label: "Document ID",
10+
description: "Enter the ID of the Papersign document",
11+
async options() {
12+
const documents = await this.listDocuments();
13+
return documents.map((doc) => ({
14+
value: doc.id,
15+
label: doc.name,
16+
}));
17+
},
18+
},
19+
spaceId: {
20+
type: "string",
21+
label: "Space ID",
22+
description: "Enter the ID of the Papersign space",
23+
async options() {
24+
const spaces = await this.listSpaces();
25+
return spaces.map((space) => ({
26+
value: space.id,
27+
label: space.name,
28+
}));
29+
},
30+
},
31+
folderId: {
32+
type: "string",
33+
label: "Folder ID",
34+
description: "Enter the ID of the Papersign folder",
35+
async options() {
36+
const folders = await this.listFolders();
37+
return folders.map((folder) => ({
38+
value: folder.id,
39+
label: folder.name,
40+
}));
41+
},
42+
},
43+
},
544
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
45+
_baseUrl() {
46+
return "https://api.paperform.co/v1/papersign";
47+
},
48+
async _makeRequest(opts = {}) {
49+
const {
50+
$ = this, method = "GET", path = "/", headers, ...otherOpts
51+
} = opts;
52+
return axios($, {
53+
...otherOpts,
54+
method,
55+
url: this._baseUrl() + path,
56+
headers: {
57+
...headers,
58+
Authorization: `Bearer ${this.$auth.api_key}`,
59+
},
60+
});
61+
},
62+
async listDocuments(opts = {}) {
63+
return this._makeRequest({
64+
path: "/documents",
65+
...opts,
66+
});
67+
},
68+
async listSpaces(opts = {}) {
69+
return this._makeRequest({
70+
path: "/spaces",
71+
...opts,
72+
});
73+
},
74+
async listFolders(opts = {}) {
75+
const { spaceId } = opts;
76+
return this._makeRequest({
77+
path: "/folders",
78+
params: spaceId
79+
? {
80+
space_id: spaceId,
81+
}
82+
: {},
83+
...opts,
84+
});
85+
},
86+
async duplicateDocument({
87+
documentId, name, spaceId, path, folderId,
88+
}) {
89+
return this._makeRequest({
90+
method: "POST",
91+
path: `/documents/${documentId}/copy`,
92+
data: {
93+
name,
94+
space_id: spaceId,
95+
path,
96+
folder_id: folderId,
97+
},
98+
});
99+
},
100+
async getDocument({ documentId }) {
101+
return this._makeRequest({
102+
path: `/documents/${documentId}`,
103+
});
104+
},
105+
async sendDocument({
106+
documentId, expiration, inviteMessage, fromUserEmail, documentRecipientEmails, automaticReminders, signers, variables, copy,
107+
}) {
108+
return this._makeRequest({
109+
method: "POST",
110+
path: `/documents/${documentId}/send`,
111+
data: {
112+
expiration,
113+
invite_message: inviteMessage,
114+
from_user_email: fromUserEmail,
115+
document_recipient_emails: documentRecipientEmails,
116+
automatic_reminders: automaticReminders,
117+
signers,
118+
variables,
119+
copy,
120+
},
121+
});
9122
},
10123
},
11-
};
124+
};
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import papersign from "../../papersign.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "papersign-new-document-completed-instant",
6+
name: "New Document Completed (Instant)",
7+
description: "Emit new event when a document is completed, i.e., all signers have signed. [See the documentation](https://paperform.readme.io/reference/getting-started-1)",
8+
version: "0.0.{{ts}}",
9+
type: "source",
10+
dedupe: "unique",
11+
props: {
12+
papersign,
13+
http: {
14+
type: "$.interface.http",
15+
customResponse: false,
16+
},
17+
db: "$.service.db",
18+
},
19+
hooks: {
20+
async deploy() {
21+
const documents = await this.papersign.listDocuments();
22+
const completedDocs = documents.filter((doc) => doc.status === "completed");
23+
for (const doc of completedDocs) {
24+
this.$emit(doc, {
25+
id: doc.id,
26+
summary: `Document ${doc.name} completed`,
27+
ts: Date.parse(doc.updated_at),
28+
});
29+
}
30+
},
31+
async activate() {
32+
const webhookData = {
33+
name: "Document Completed Webhook",
34+
target_url: this.http.endpoint,
35+
triggers: [
36+
"document.completed",
37+
],
38+
};
39+
const response = await axios(this, {
40+
method: "POST",
41+
url: `${this.papersign._baseUrl()}/webhooks`,
42+
headers: {
43+
Authorization: `Bearer ${this.papersign.$auth.api_key}`,
44+
},
45+
data: webhookData,
46+
});
47+
this.db.set("webhookId", response.webhook.id);
48+
},
49+
async deactivate() {
50+
const webhookId = this.db.get("webhookId");
51+
if (webhookId) {
52+
await axios(this, {
53+
method: "DELETE",
54+
url: `${this.papersign._baseUrl()}/webhooks/${webhookId}`,
55+
headers: {
56+
Authorization: `Bearer ${this.papersign.$auth.api_key}`,
57+
},
58+
});
59+
this.db.set("webhookId", null);
60+
}
61+
},
62+
},
63+
async run(event) {
64+
const doc = event.body;
65+
this.$emit(doc, {
66+
id: doc.id,
67+
summary: `Document ${doc.name} completed`,
68+
ts: Date.parse(doc.updated_at),
69+
});
70+
},
71+
};

0 commit comments

Comments
 (0)