Skip to content

Commit 87cac62

Browse files
committed
[Components] signaturit #13223
Sources - New Signed Document Actions - Create Certified Email - Create Signature Request From Template - Send Signature Request Reminder
1 parent 29088ab commit 87cac62

File tree

12 files changed

+526
-343
lines changed

12 files changed

+526
-343
lines changed

components/signaturit/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

components/signaturit/actions/create-certified-email/create-certified-email.mjs

Lines changed: 68 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,20 @@
1+
import FormData from "form-data";
2+
import fs from "fs";
3+
import { TYPE_OPTIONS } from "../../common/constants.mjs";
4+
import {
5+
checkTmp,
6+
parseObject,
7+
} from "../../common/utils.mjs";
18
import signaturit from "../../signaturit.app.mjs";
2-
import { axios } from "@pipedream/platform";
39

410
export default {
511
key: "signaturit-create-certified-email",
612
name: "Create Certified Email",
7-
description: "Initiates the creation of a certified email. [See the documentation]()",
8-
version: "0.0.{{ts}}",
13+
description: "Initiates the creation of a certified email. [See the documentation](https://docs.signaturit.com/api/latest#emails_create_email)",
14+
version: "0.0.1",
915
type: "action",
1016
props: {
11-
signaturit: {
12-
type: "app",
13-
app: "signaturit",
14-
},
15-
attachments: {
16-
propDefinition: [
17-
signaturit,
18-
"attachments",
19-
],
20-
},
21-
recipients: {
22-
propDefinition: [
23-
signaturit,
24-
"recipients",
25-
],
26-
},
27-
type: {
28-
propDefinition: [
29-
signaturit,
30-
"type",
31-
],
32-
},
33-
templates: {
34-
propDefinition: [
35-
signaturit,
36-
"templates",
37-
],
38-
},
17+
signaturit,
3918
body: {
4019
propDefinition: [
4120
signaturit,
@@ -64,6 +43,26 @@ export default {
6443
],
6544
optional: true,
6645
},
46+
attachments: {
47+
propDefinition: [
48+
signaturit,
49+
"attachments",
50+
],
51+
optional: true,
52+
},
53+
recipients: {
54+
propDefinition: [
55+
signaturit,
56+
"recipients",
57+
],
58+
},
59+
type: {
60+
type: "string",
61+
label: "Type",
62+
description: "Type of certified email.",
63+
options: TYPE_OPTIONS,
64+
optional: true,
65+
},
6766
subject: {
6867
propDefinition: [
6968
signaturit,
@@ -73,7 +72,44 @@ export default {
7372
},
7473
},
7574
async run({ $ }) {
76-
const response = await this.signaturit.createCertifiedEmail();
75+
const formData = new FormData();
76+
77+
let i = 0;
78+
for (const recipient of parseObject(this.recipients)) {
79+
for (const [
80+
key,
81+
value,
82+
] of Object.entries(recipient)) {
83+
formData.append(`recipients[${i}][${key}]`, value);
84+
}
85+
i++;
86+
}
87+
if (this.data) {
88+
for (const [
89+
key,
90+
value,
91+
] of Object.entries(this.data)) {
92+
formData.append(`data[${key}]`, value);
93+
}
94+
i++;
95+
}
96+
if (this.body) formData.append("body", this.body);
97+
if (this.brandingId) formData.append("branding_id", this.brandingId);
98+
if (this.eventsUrl) formData.append("events_url", this.eventsUrl);
99+
if (this.type) formData.append("type", this.type);
100+
if (this.subject) formData.append("subject", this.subject);
101+
102+
if (this.attachments) {
103+
let j = 0;
104+
for (const file of parseObject(this.attachments)) {
105+
formData.append(`attachments[${j++}]`, fs.createReadStream(checkTmp(file)));
106+
}
107+
}
108+
const response = await this.signaturit.createCertifiedEmail({
109+
$,
110+
data: formData,
111+
headers: formData.getHeaders(),
112+
});
77113
$.export("$summary", `Created certified email with ID: ${response.id}`);
78114
return response;
79115
},

components/signaturit/actions/create-signature-request-from-template/create-signature-request-from-template.mjs

Lines changed: 151 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,30 @@
1+
import FormData from "form-data";
2+
import fs from "fs";
3+
import {
4+
DELIVERY_TYPE_OPTIONS,
5+
SIGNATURE_TYPE_OPTIONS,
6+
SIGNING_MODE_OPTIONS,
7+
} from "../../common/constants.mjs";
8+
import {
9+
checkTmp,
10+
parseObject,
11+
} from "../../common/utils.mjs";
112
import signaturit from "../../signaturit.app.mjs";
2-
import { axios } from "@pipedream/platform";
313

414
export default {
515
key: "signaturit-create-signature-request-from-template",
616
name: "Create Signature Request from Template",
7-
description: "Creates a signature request using a pre-existing template. [See the documentation]()",
8-
version: "0.0.{{ts}}",
17+
description: "Creates a signature request using a pre-existing template. [See the documentation](https://docs.signaturit.com/api/latest#signatures_create_signature)",
18+
version: "0.0.1",
919
type: "action",
1020
props: {
1121
signaturit,
12-
files: {
13-
propDefinition: [
14-
signaturit,
15-
"files",
16-
],
17-
},
18-
name: {
19-
propDefinition: [
20-
signaturit,
21-
"name",
22-
],
23-
},
24-
recipients: {
25-
propDefinition: [
26-
signaturit,
27-
"recipients",
28-
],
29-
},
3022
body: {
3123
propDefinition: [
3224
signaturit,
3325
"body",
3426
],
27+
description: "Email body (html code is allowed) for **email** and **sms** type requests. Note: For **sms** request types it will be truncated to 120 characters Note: For **sms** the body should contain the tag **{{url}}** where we will include the document url.",
3528
optional: true,
3629
},
3730
brandingId: {
@@ -42,10 +35,9 @@ export default {
4235
optional: true,
4336
},
4437
callbackUrl: {
45-
propDefinition: [
46-
signaturit,
47-
"callbackUrl",
48-
],
38+
type: "string",
39+
label: "Callback URL",
40+
description: "Url to redirect the user when finish the signature process.",
4941
optional: true,
5042
},
5143
data: {
@@ -56,17 +48,18 @@ export default {
5648
optional: true,
5749
},
5850
deliveryType: {
59-
propDefinition: [
60-
signaturit,
61-
"deliveryType",
62-
],
51+
type: "string",
52+
label: "Delivery Type",
53+
description: "Delivery type for signature request.",
54+
options: DELIVERY_TYPE_OPTIONS,
6355
optional: true,
6456
},
6557
expireTime: {
66-
propDefinition: [
67-
signaturit,
68-
"expireTime",
69-
],
58+
type: "integer",
59+
label: "Expiration Time (days)",
60+
description: "Expiration time of the document in days (max 365).",
61+
min: 1,
62+
max: 365,
7063
optional: true,
7164
},
7265
eventsUrl: {
@@ -76,25 +69,49 @@ export default {
7669
],
7770
optional: true,
7871
},
79-
replyTo: {
72+
files: {
8073
propDefinition: [
8174
signaturit,
82-
"replyTo",
75+
"attachments",
8376
],
77+
label: "Files",
8478
optional: true,
8579
},
86-
reminders: {
80+
name: {
81+
type: "string",
82+
label: "Name",
83+
description: "Name assigned to the signature request.",
84+
},
85+
recipients: {
8786
propDefinition: [
8887
signaturit,
89-
"reminders",
88+
"recipients",
9089
],
90+
description: "List of recipients in JSON format, e.g., '{\"name\": \"John Doe\", \"email\": \"[email protected]\", \"phone\": \"34555667788\"}'. [See the documentation](https://docs.signaturit.com/api/latest#signatures_create_signature) for further information.",
91+
},
92+
cc: {
93+
type: "string[]",
94+
label: "CC",
95+
description: "List with email recipients containing name and email for people that will receive a copy of the signed document when the process is completed. e.g., '{\"name\": \"John Doe\", \"email\": \"[email protected]\"}'.",
96+
optional: true,
97+
},
98+
replyTo: {
99+
type: "string",
100+
label: "Reply To",
101+
description: "Email Reply-To address.",
102+
optional: true,
103+
},
104+
reminders: {
105+
type: "string[]",
106+
label: "Reminders (days)",
107+
description: "Reminders in days to send automatic reminders. You can set it 0 to disable reminders. E.g. [1,3,4]",
91108
optional: true,
92109
},
93110
signingMode: {
94-
propDefinition: [
95-
signaturit,
96-
"signingMode",
97-
],
111+
type: "string",
112+
label: "Signing Mode",
113+
description: "The signing mode lets you control the order in which your recipients receive and sign your documents.",
114+
options: SIGNING_MODE_OPTIONS,
98115
optional: true,
99116
},
100117
subject: {
@@ -104,16 +121,106 @@ export default {
104121
],
105122
optional: true,
106123
},
107-
type: {
124+
templates: {
108125
propDefinition: [
109126
signaturit,
110-
"typeSignature",
127+
"templates",
111128
],
129+
},
130+
type: {
131+
type: "string",
132+
label: "Type",
133+
description: "The type of the signature.",
134+
options: SIGNATURE_TYPE_OPTIONS,
112135
optional: true,
113136
},
114137
},
138+
methods: {
139+
transformArray({
140+
arr, prefixBase, formData,
141+
}) {
142+
let result = [];
143+
function processObject(obj, prefix = "") {
144+
for (let key in obj) {
145+
if (Array.isArray(obj[key])) {
146+
obj[key].forEach((item, index) => {
147+
processObject(item, `${prefix}[${key}][${index}]`);
148+
});
149+
} else if (typeof obj[key] === "object") {
150+
processObject(obj[key], `${prefix}[${key}]`);
151+
} else {
152+
result.push({
153+
key: `${prefixBase}${prefix}[${key}]`,
154+
value: `${obj[key]}`,
155+
});
156+
}
157+
}
158+
}
159+
arr.map((item, index) => {
160+
processObject(item, `[${index}]`);
161+
});
162+
for (const {
163+
key, value,
164+
} of result) {
165+
formData.append(key, value);
166+
}
167+
return result;
168+
},
169+
},
115170
async run({ $ }) {
116-
const response = await this.signaturit.createSignatureRequest();
171+
const formData = new FormData();
172+
this.transformArray({
173+
arr: parseObject(this.recipients),
174+
prefixBase: "recipients",
175+
formData,
176+
});
177+
if (this.cc) {
178+
let j;
179+
for (const item of parseObject(this.cc)) {
180+
formData.append(`cc[${j++}]`, item);
181+
}
182+
}
183+
if (this.data) {
184+
for (const [
185+
key,
186+
value,
187+
] of Object.entries(parseObject(this.data))) {
188+
formData.append(`data[${key}]`, value);
189+
}
190+
}
191+
if (this.templates) {
192+
let k = 0;
193+
for (const templateId of parseObject(this.templates)) {
194+
formData.append(`templates[${k++}]`, templateId);
195+
}
196+
}
197+
if (this.reminders) {
198+
let m = 0;
199+
for (const reminder of parseObject(this.reminders)) {
200+
formData.append(`reminders[${m++}]`, reminder);
201+
}
202+
}
203+
if (this.body) formData.append("body", this.body);
204+
if (this.brandingId) formData.append("branding_id", this.brandingId);
205+
if (this.callbackUrl) formData.append("callback_url", this.callbackUrl);
206+
if (this.deliveryType) formData.append("delivery_type", this.deliveryType);
207+
if (this.expireTime) formData.append("expire_time", this.expireTime);
208+
if (this.eventsUrl) formData.append("events_url", this.eventsUrl);
209+
if (this.name) formData.append("name", this.name);
210+
if (this.replyTo) formData.append("reply_to", this.replyTo);
211+
if (this.type) formData.append("type", this.type);
212+
213+
if (this.files) {
214+
let k = 0;
215+
for (const file of parseObject(this.files)) {
216+
formData.append(`files[${k++}]`, fs.createReadStream(checkTmp(file)));
217+
}
218+
}
219+
const response = await this.signaturit.createSignatureRequest({
220+
$,
221+
data: formData,
222+
headers: formData.getHeaders(),
223+
});
117224
$.export("$summary", `Created signature request with ID: ${response.id}`);
118225
return response;
119226
},

0 commit comments

Comments
 (0)