Skip to content

Commit 4756b93

Browse files
New Components - signaturit (#14855)
* signaturit init * [Components] signaturit #13223 Sources - New Signed Document Actions - Create Certified Email - Create Signature Request From Template - Send Signature Request Reminder * pnpm update * Update components/signaturit/actions/create-signature-request-from-template/create-signature-request-from-template.mjs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * some adjusts * pnpm update --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 49d72a8 commit 4756b93

File tree

13 files changed

+758
-24
lines changed

13 files changed

+758
-24
lines changed

components/signaturit/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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";
8+
import signaturit from "../../signaturit.app.mjs";
9+
10+
export default {
11+
key: "signaturit-create-certified-email",
12+
name: "Create Certified Email",
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",
15+
type: "action",
16+
props: {
17+
signaturit,
18+
body: {
19+
propDefinition: [
20+
signaturit,
21+
"body",
22+
],
23+
optional: true,
24+
},
25+
brandingId: {
26+
propDefinition: [
27+
signaturit,
28+
"brandingId",
29+
],
30+
optional: true,
31+
},
32+
eventsUrl: {
33+
propDefinition: [
34+
signaturit,
35+
"eventsUrl",
36+
],
37+
optional: true,
38+
},
39+
data: {
40+
propDefinition: [
41+
signaturit,
42+
"data",
43+
],
44+
optional: true,
45+
},
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+
},
66+
subject: {
67+
propDefinition: [
68+
signaturit,
69+
"subject",
70+
],
71+
optional: true,
72+
},
73+
},
74+
async run({ $ }) {
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+
});
113+
$.export("$summary", `Created certified email with ID: ${response.id}`);
114+
return response;
115+
},
116+
};
Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
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";
12+
import signaturit from "../../signaturit.app.mjs";
13+
14+
export default {
15+
key: "signaturit-create-signature-request-from-template",
16+
name: "Create Signature Request from Template",
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",
19+
type: "action",
20+
props: {
21+
signaturit,
22+
body: {
23+
propDefinition: [
24+
signaturit,
25+
"body",
26+
],
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.",
28+
optional: true,
29+
},
30+
brandingId: {
31+
propDefinition: [
32+
signaturit,
33+
"brandingId",
34+
],
35+
optional: true,
36+
},
37+
callbackUrl: {
38+
type: "string",
39+
label: "Callback URL",
40+
description: "Url to redirect the user when finish the signature process.",
41+
optional: true,
42+
},
43+
data: {
44+
propDefinition: [
45+
signaturit,
46+
"data",
47+
],
48+
optional: true,
49+
},
50+
deliveryType: {
51+
type: "string",
52+
label: "Delivery Type",
53+
description: "Delivery type for signature request.",
54+
options: DELIVERY_TYPE_OPTIONS,
55+
optional: true,
56+
},
57+
expireTime: {
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,
63+
optional: true,
64+
},
65+
eventsUrl: {
66+
propDefinition: [
67+
signaturit,
68+
"eventsUrl",
69+
],
70+
optional: true,
71+
},
72+
files: {
73+
propDefinition: [
74+
signaturit,
75+
"attachments",
76+
],
77+
label: "Files",
78+
optional: true,
79+
},
80+
name: {
81+
type: "string",
82+
label: "Name",
83+
description: "Name assigned to the signature request.",
84+
},
85+
recipients: {
86+
propDefinition: [
87+
signaturit,
88+
"recipients",
89+
],
90+
description: "List of recipients in JSON format, e.g., '{\"name\": \"John Doe\", \"email\": \"john@example.com\", \"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\": \"john@example.com\"}'.",
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]",
108+
optional: true,
109+
},
110+
signingMode: {
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,
115+
optional: true,
116+
},
117+
subject: {
118+
propDefinition: [
119+
signaturit,
120+
"subject",
121+
],
122+
optional: true,
123+
},
124+
templates: {
125+
propDefinition: [
126+
signaturit,
127+
"templates",
128+
],
129+
},
130+
type: {
131+
type: "string",
132+
label: "Type",
133+
description: "The type of the signature.",
134+
options: SIGNATURE_TYPE_OPTIONS,
135+
optional: true,
136+
},
137+
},
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+
},
170+
async run({ $ }) {
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 = 0;
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+
});
224+
$.export("$summary", `Created signature request with ID: ${response.id}`);
225+
return response;
226+
},
227+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import signaturit from "../../signaturit.app.mjs";
2+
3+
export default {
4+
key: "signaturit-send-signature-request-reminder",
5+
name: "Send Signature Request Reminder",
6+
description: "Sends a reminder for a pending signature request. [See the documentation](https://docs.signaturit.com/api/latest#signatures_send_reminder)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
signaturit,
11+
signatureRequestId: {
12+
propDefinition: [
13+
signaturit,
14+
"signatureRequestId",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const response = await this.signaturit.sendReminder({
20+
$,
21+
signatureRequestId: this.signatureRequestId,
22+
});
23+
$.export("$summary", `Sent reminder for signature request ${this.signatureRequestId}`);
24+
return response;
25+
},
26+
};

components/signaturit/app/signaturit.app.ts

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

0 commit comments

Comments
 (0)