Skip to content

Commit 4100c6e

Browse files
luancazarinelcaresia
authored andcommitted
New Components - papersign (#14423)
* papersign init * [Components] papersign #14412 Sources - New Event (Instant) - New Document Completed (Instant) - New Signer Signed (Instant) Actions - Copy Document - Get Document - Send Document * pnpm update * fix method call * remove optional true from scope
1 parent d42b323 commit 4100c6e

File tree

15 files changed

+599
-59
lines changed

15 files changed

+599
-59
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import papersign from "../../papersign.app.mjs";
2+
3+
export default {
4+
key: "papersign-copy-document",
5+
name: "Copy Document",
6+
description: "Duplicates a given document. [See the documentation](https://paperform.readme.io/reference/papersigncopydocument)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
papersign,
11+
documentId: {
12+
propDefinition: [
13+
papersign,
14+
"documentId",
15+
],
16+
},
17+
name: {
18+
type: "string",
19+
label: "Name",
20+
description: "The new name of the copied document",
21+
optional: true,
22+
},
23+
spaceId: {
24+
propDefinition: [
25+
papersign,
26+
"spaceId",
27+
],
28+
optional: true,
29+
},
30+
path: {
31+
type: "string",
32+
label: "Path",
33+
description: "The path to copy the document to. Maximum depth is 4 levels. Any missing folders will be created.",
34+
optional: true,
35+
},
36+
folderId: {
37+
propDefinition: [
38+
papersign,
39+
"folderId",
40+
],
41+
optional: true,
42+
},
43+
},
44+
async run({ $ }) {
45+
const data = {};
46+
if (this.folderId) {
47+
data.folder_id = this.folderId;
48+
} else {
49+
data.space_id = this.spaceId;
50+
data.path = this.path;
51+
}
52+
53+
const response = await this.papersign.duplicateDocument({
54+
$,
55+
documentId: this.documentId,
56+
data: {
57+
...data,
58+
name: this.name,
59+
},
60+
});
61+
62+
$.export("$summary", `Successfully copied document: ${response.results.document.name}`);
63+
return response;
64+
},
65+
};
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+
3+
export default {
4+
key: "papersign-get-document",
5+
name: "Get Document",
6+
description: "Retrieve a document using a specified ID. [See the documentation](https://paperform.readme.io/reference/getpapersigndocument)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
papersign,
11+
documentId: {
12+
propDefinition: [
13+
papersign,
14+
"documentId",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const response = await this.papersign.getDocument({
20+
$,
21+
documentId: this.documentId,
22+
});
23+
24+
$.export("$summary", `Successfully retrieved document with ID: ${this.documentId}`);
25+
return response;
26+
},
27+
};
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
import { parseObject } from "../../common/utils.mjs";
3+
import papersign from "../../papersign.app.mjs";
4+
5+
export default {
6+
key: "papersign-send-document",
7+
name: "Send Document",
8+
description: "Dispatches a document to a specified recipient. [See the documentation](https://paperform.readme.io/reference/papersignsenddocument)",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
papersign,
13+
documentId: {
14+
propDefinition: [
15+
papersign,
16+
"documentId",
17+
],
18+
},
19+
expiration: {
20+
type: "string",
21+
label: "Expiration",
22+
description: "The expiration date of the document. Must be at least 30 minutes in the future. **Format: YYYY-MM-DDTHH:MM:SS.SSSZ**",
23+
optional: true,
24+
},
25+
inviteMessage: {
26+
type: "string",
27+
label: "Invite Message",
28+
description: "The message to include in the invitation email, up to 1000 characters.",
29+
optional: true,
30+
},
31+
fromUserEmail: {
32+
type: "string",
33+
label: "From User Email",
34+
description: "The email address of a User on your team's account to send the document from.",
35+
optional: true,
36+
},
37+
documentRecipientEmails: {
38+
type: "string[]",
39+
label: "Document Recipient Emails",
40+
description: "An array of recipient emails for the document.",
41+
optional: true,
42+
},
43+
firstAfterDays: {
44+
type: "integer",
45+
label: "Automatic Reminder - First After Days",
46+
description: "The number of days after the document is sent to send the reminder.",
47+
optional: true,
48+
},
49+
followUpEveryDays: {
50+
type: "integer",
51+
label: "Automatic Reminder - Follow Up Every Days",
52+
description: "The number of days to wait between reminders.",
53+
optional: true,
54+
},
55+
signers: {
56+
type: "string[]",
57+
label: "Signers",
58+
description: "An array of objects of signers. **Object format: {\"key\": \"123\",\"name\": \"Jack Smith\",\"email\": \"[email protected]\",\"phone\": \"123 456 7899\",\"job_title\": \"Account Manager\",\"company\": \"Explosive Startup\",\"custom_attributes\": [{\"key\": \"Relationship\",\"label\": \"Relationship to the company\",\"value\": \"CEO\"}]}**",
59+
optional: true,
60+
},
61+
variables: {
62+
type: "object",
63+
label: "Variables",
64+
description: "The key: value of the document variables.",
65+
optional: true,
66+
},
67+
copy: {
68+
type: "boolean",
69+
label: "Copy",
70+
description: "Whether to copy before sending.",
71+
optional: true,
72+
},
73+
},
74+
async run({ $ }) {
75+
if (
76+
(this.firstAfterDays && !this.followUpEveryDays) ||
77+
(!this.firstAfterDays && this.followUpEveryDays)
78+
) {
79+
throw new ConfigurationError("You must fill in the fields 'First After Days' and 'Follow Up Every Days' or none of them");
80+
}
81+
82+
const automaticReminders = {};
83+
if (this.firstAfterDays) {
84+
automaticReminders.first_after_days = this.firstAfterDays;
85+
automaticReminders.follow_up_every_days = this.followUpEveryDays;
86+
}
87+
88+
const variables = [];
89+
if (this.variables) {
90+
for (const key of Object.keys(parseObject(this.variables))) {
91+
variables.push({
92+
key,
93+
value: this.variables[key],
94+
});
95+
}
96+
}
97+
98+
const response = await this.papersign.sendDocument({
99+
$,
100+
documentId: this.documentId,
101+
data: {
102+
expiration: this.expiration,
103+
inviteMessage: this.inviteMessage,
104+
fromUserEmail: this.fromUserEmail,
105+
documentRecipientEmails: parseObject(this.documentRecipientEmails),
106+
automaticReminders,
107+
signers: parseObject(this.signers),
108+
variables,
109+
copy: this.copy,
110+
},
111+
});
112+
$.export("$summary", `Document sent successfully with ID ${this.documentId}`);
113+
return response;
114+
},
115+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export const LIMIT = 100;
2+
3+
export const SCOPE_OPTIONS = [
4+
{
5+
label: "Direct Children",
6+
value: "folder.direct_children",
7+
},
8+
{
9+
label: "All Descendants",
10+
value: "folder.all_descendants",
11+
},
12+
];
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
export const parseObject = (obj) => {
2+
if (!obj) return undefined;
3+
4+
if (Array.isArray(obj)) {
5+
return obj.map((item) => {
6+
if (typeof item === "string") {
7+
try {
8+
return JSON.parse(item);
9+
} catch (e) {
10+
return parseObject(item);
11+
}
12+
}
13+
return item;
14+
});
15+
}
16+
if (typeof obj === "string") {
17+
try {
18+
return JSON.parse(obj);
19+
} catch (e) {
20+
return obj;
21+
}
22+
}
23+
if (typeof obj === "object") {
24+
for (const [
25+
key,
26+
value,
27+
] of Object.entries(obj)) {
28+
obj[key] = parseObject(value);
29+
}
30+
}
31+
return obj;
32+
};

components/papersign/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/papersign",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Papersign Components",
55
"main": "papersign.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
1417
}
15-
}
18+
}

0 commit comments

Comments
 (0)