Skip to content

Commit 8046eef

Browse files
committed
[Components] papersign #14412
Sources - New Event (Instant) - New Document Completed (Instant) - New Signer Signed (Instant) Actions - Copy Document - Get Document - Send Document
1 parent 0282c90 commit 8046eef

File tree

14 files changed

+313
-299
lines changed

14 files changed

+313
-299
lines changed

components/papersign/actions/copy-document/copy-document.mjs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import papersign from "../../papersign.app.mjs";
2-
import { axios } from "@pipedream/platform";
32

43
export default {
54
key: "papersign-copy-document",
65
name: "Copy Document",
76
description: "Duplicates a given document. [See the documentation](https://paperform.readme.io/reference/papersigncopydocument)",
8-
version: "0.0.{{ts}}",
7+
version: "0.0.1",
98
type: "action",
109
props: {
1110
papersign,
@@ -31,27 +30,33 @@ export default {
3130
path: {
3231
type: "string",
3332
label: "Path",
34-
description: "The path to copy the document to. Maximum depth is 4 levels.",
33+
description: "The path to copy the document to. Maximum depth is 4 levels. Any missing folders will be created.",
3534
optional: true,
3635
},
3736
folderId: {
3837
propDefinition: [
3938
papersign,
4039
"folderId",
41-
(c) => ({
42-
spaceId: c.spaceId,
43-
}),
4440
],
4541
optional: true,
4642
},
4743
},
4844
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+
4953
const response = await this.papersign.duplicateDocument({
54+
$,
5055
documentId: this.documentId,
51-
name: this.name,
52-
spaceId: this.spaceId,
53-
path: this.path,
54-
folderId: this.folderId,
56+
data: {
57+
...data,
58+
name: this.name,
59+
},
5560
});
5661

5762
$.export("$summary", `Successfully copied document: ${response.results.document.name}`);

components/papersign/actions/get-document/get-document.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import papersign from "../../papersign.app.mjs";
2-
import { axios } from "@pipedream/platform";
32

43
export default {
54
key: "papersign-get-document",
65
name: "Get Document",
76
description: "Retrieve a document using a specified ID. [See the documentation](https://paperform.readme.io/reference/getpapersigndocument)",
8-
version: "0.0.{{ts}}",
7+
version: "0.0.1",
98
type: "action",
109
props: {
1110
papersign,
@@ -18,6 +17,7 @@ export default {
1817
},
1918
async run({ $ }) {
2019
const response = await this.papersign.getDocument({
20+
$,
2121
documentId: this.documentId,
2222
});
2323

components/papersign/actions/send-document/send-document.mjs

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
import { parseObject } from "../../common/utils.mjs";
13
import papersign from "../../papersign.app.mjs";
2-
import { axios } from "@pipedream/platform";
34

45
export default {
56
key: "papersign-send-document",
@@ -18,7 +19,7 @@ export default {
1819
expiration: {
1920
type: "string",
2021
label: "Expiration",
21-
description: "The expiration date of the document. Must be at least 30 minutes in the future.",
22+
description: "The expiration date of the document. Must be at least 30 minutes in the future. **Format: YYYY-MM-DDTHH:MM:SS.SSSZ**",
2223
optional: true,
2324
},
2425
inviteMessage: {
@@ -39,22 +40,28 @@ export default {
3940
description: "An array of recipient emails for the document.",
4041
optional: true,
4142
},
42-
automaticReminders: {
43-
type: "object",
44-
label: "Automatic Reminders",
45-
description: "An object for setting automatic reminders.",
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.",
4653
optional: true,
4754
},
4855
signers: {
4956
type: "string[]",
5057
label: "Signers",
51-
description: "An array of signer objects.",
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\"}]}**",
5259
optional: true,
5360
},
5461
variables: {
55-
type: "string[]",
62+
type: "object",
5663
label: "Variables",
57-
description: "An array of variable objects.",
64+
description: "The key: value of the document variables.",
5865
optional: true,
5966
},
6067
copy: {
@@ -65,16 +72,42 @@ export default {
6572
},
6673
},
6774
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+
6898
const response = await this.papersign.sendDocument({
99+
$,
69100
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,
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+
},
78111
});
79112
$.export("$summary", `Document sent successfully with ID ${this.documentId}`);
80113
return response;
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: 4 additions & 1 deletion
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
}
1518
}

0 commit comments

Comments
 (0)