Skip to content

Commit 3693a56

Browse files
committed
[Components] boldsign #14976
Sources - New Document Completed - New Document Sent - New Document Declined Actions - Send Document Template
1 parent a0a90cb commit 3693a56

File tree

12 files changed

+626
-817
lines changed

12 files changed

+626
-817
lines changed
Lines changed: 188 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
import fs from "fs";
13
import boldsign from "../../boldsign.app.mjs";
2-
import { axios } from "@pipedream/platform";
4+
import {
5+
checkTmp,
6+
parseObject,
7+
} from "../../common/utils.mjs";
8+
import { DOCUMENT_DOWNLOAD_OPTIONS } from "./common/constants.mjs";
39

410
export default {
511
key: "boldsign-send-document-template",
612
name: "Send Document Using Template",
713
description: "Send documents for e-signature using a BoldSign template. [See the documentation](https://developers.boldsign.com/documents/send-document-from-template/?region=us)",
8-
version: "0.0.{{ts}}",
14+
version: "0.0.1",
915
type: "action",
1016
props: {
1117
boldsign,
@@ -16,171 +22,249 @@ export default {
1622
],
1723
},
1824
title: {
19-
propDefinition: [
20-
boldsign,
21-
"title",
22-
],
25+
type: "string",
26+
label: "Title",
27+
description: "The title of the document.",
28+
optional: true,
2329
},
2430
message: {
25-
propDefinition: [
26-
boldsign,
27-
"message",
28-
],
31+
type: "string",
32+
label: "Message",
33+
description: "A message to include with the document.",
34+
optional: true,
2935
},
3036
roles: {
31-
propDefinition: [
32-
boldsign,
33-
"roles",
34-
],
37+
type: "string[]",
38+
label: "Roles",
39+
description: "Roles assigned to the signers. [See the documentation](https://developers.boldsign.com/documents/send-document-from-template) for further information.",
3540
},
3641
brandId: {
3742
propDefinition: [
3843
boldsign,
3944
"brandId",
4045
],
46+
optional: true,
4147
},
4248
labels: {
4349
propDefinition: [
4450
boldsign,
4551
"labels",
4652
],
53+
optional: true,
4754
},
4855
disableEmails: {
49-
propDefinition: [
50-
boldsign,
51-
"disableEmails",
52-
],
56+
type: "boolean",
57+
label: "Disable Emails",
58+
description: "Disable sending emails to recipients.",
59+
optional: true,
5360
},
5461
disableSMS: {
55-
propDefinition: [
56-
boldsign,
57-
"disableSMS",
58-
],
62+
type: "boolean",
63+
label: "Disable SMS",
64+
description: "Disable sending SMS to recipients.",
65+
optional: true,
5966
},
60-
hitDocumentId: {
61-
propDefinition: [
62-
boldsign,
63-
"hitDocumentId",
64-
],
67+
hideDocumentId: {
68+
type: "boolean",
69+
label: "Hide Document ID",
70+
description: "Decides whether the document ID should be hidden or not.",
71+
optional: true,
6572
},
6673
enableAutoReminder: {
67-
propDefinition: [
68-
boldsign,
69-
"enableAutoReminder",
70-
],
74+
type: "boolean",
75+
label: "Enable Auto Reminder",
76+
description: "Enable automatic reminders.",
77+
reloadProps: true,
78+
optional: true,
7179
},
7280
reminderDays: {
73-
propDefinition: [
74-
boldsign,
75-
"reminderDays",
76-
],
81+
type: "integer",
82+
label: "Reminder Days",
83+
description: "Number of days between reminders.",
84+
hidden: true,
85+
optional: true,
7786
},
7887
reminderCount: {
79-
propDefinition: [
80-
boldsign,
81-
"reminderCount",
82-
],
88+
type: "integer",
89+
label: "Reminder Count",
90+
description: "Number of reminder attempts.",
91+
hidden: true,
92+
optional: true,
8393
},
8494
cc: {
8595
propDefinition: [
8696
boldsign,
8797
"cc",
8898
],
99+
optional: true,
89100
},
90101
expiryDays: {
91-
propDefinition: [
92-
boldsign,
93-
"expiryDays",
94-
],
102+
type: "integer",
103+
label: "Expiry Days",
104+
description: "Number of days before document expires.",
105+
optional: true,
95106
},
96107
enablePrintAndSign: {
97-
propDefinition: [
98-
boldsign,
99-
"enablePrintAndSign",
100-
],
108+
type: "boolean",
109+
label: "Enable Print and Sign",
110+
description: "Allow signers to print and sign document.",
111+
optional: true,
101112
},
102113
enableReassign: {
103-
propDefinition: [
104-
boldsign,
105-
"enableReassign",
106-
],
114+
type: "boolean",
115+
label: "Enable Reassign",
116+
description: "Allow signers to reassign the document.",
117+
optional: true,
107118
},
108119
enableSigningOrder: {
109-
propDefinition: [
110-
boldsign,
111-
"enableSigningOrder",
112-
],
120+
type: "boolean",
121+
label: "Enable Signing Order",
122+
description: "Enable signing order for the document.",
123+
optional: true,
113124
},
114125
disableExpiryAlert: {
115-
propDefinition: [
116-
boldsign,
117-
"disableExpiryAlert",
118-
],
126+
type: "boolean",
127+
label: "Disable Expiry Alert",
128+
description: "Disable alerts before document expiry.",
129+
optional: true,
119130
},
120131
documentInfo: {
121-
propDefinition: [
122-
boldsign,
123-
"documentInfo",
124-
],
125-
},
126-
onBehalfOf: {
127-
propDefinition: [
128-
boldsign,
129-
"onBehalfOf",
130-
],
132+
type: "string[]",
133+
label: "Document Info",
134+
description: "Custom information fields for the document. [See the documentation](https://developers.boldsign.com/documents/send-document-from-template) for further information.",
135+
optional: true,
131136
},
132137
roleRemovalIndices: {
133-
propDefinition: [
134-
boldsign,
135-
"roleRemovalIndices",
136-
],
138+
type: "integer[]",
139+
label: "Role Removal Indices",
140+
description: "Removes the roles present in the template with their indices given in this property.",
141+
optional: true,
137142
},
138143
documentDownloadOption: {
139-
propDefinition: [
140-
boldsign,
141-
"documentDownloadOption",
142-
],
144+
type: "string",
145+
label: "Document Download Option",
146+
description: "Option for document download configuration.",
147+
options: DOCUMENT_DOWNLOAD_OPTIONS,
148+
optional: true,
143149
},
144150
formGroups: {
145-
propDefinition: [
146-
boldsign,
147-
"formGroups",
148-
],
151+
type: "string[]",
152+
label: "Form Groups",
153+
description: "Manages the rules and configuration of grouped form fields. [See the documentation](https://developers.boldsign.com/documents/send-document-from-template) for further information.",
154+
optional: true,
149155
},
150156
files: {
151-
propDefinition: [
152-
boldsign,
153-
"files",
154-
],
157+
type: "string[]",
158+
label: "Files",
159+
description: "Files to include in the document.",
160+
optional: true,
155161
},
156162
fileUrls: {
157-
propDefinition: [
158-
boldsign,
159-
"fileUrls",
160-
],
163+
type: "string[]",
164+
label: "File URLs",
165+
description: "URLs of files to include in the document.",
166+
optional: true,
161167
},
162168
recipientNotificationSettings: {
163-
propDefinition: [
164-
boldsign,
165-
"recipientNotificationSettings",
166-
],
169+
type: "object",
170+
label: "Recipient Notification Settings",
171+
description: "Settings for recipient notifications. [See the documentation](https://developers.boldsign.com/documents/send-document-from-template) for further information.",
172+
optional: true,
167173
},
168174
removeFormfields: {
169-
propDefinition: [
170-
boldsign,
171-
"removeFormfields",
172-
],
175+
type: "string[]",
176+
label: "Remove Formfields",
177+
description: "The removeFormFields property in API allows you to exclude specific form fields from a document before sending it. You provide a string array with the IDs of the existing form fields you want to remove. One or more values can be specified.",
178+
optional: true,
173179
},
174180
enableAuditTrailLocalization: {
175-
propDefinition: [
176-
boldsign,
177-
"enableAuditTrailLocalization",
178-
],
181+
type: "boolean",
182+
label: "Enable Audit Trail Localization",
183+
description: "Enable localization for audit trail based on the signer's language. If null is provided, the value will be inherited from the Business Profile settings. Only one additional language can be specified in the signer's languages besides English.",
184+
optional: true,
179185
},
180186
},
187+
async additionalProps(props) {
188+
props.reminderDays.hidden = !this.enableAutoReminder;
189+
props.reminderCount.hidden = !this.enableAutoReminder;
190+
return {};
191+
},
181192
async run({ $ }) {
182-
const response = await this.boldsign.sendDocument();
183-
$.export("$summary", `Document sent successfully using template ${this.templateId}`);
184-
return response;
193+
try {
194+
const files = [];
195+
if (this.files) {
196+
for (const file of parseObject(this.files)) {
197+
const filePath = fs.readFileSync(checkTmp(file), "base64");
198+
files.push(`data:application/${file.substr(file.length - 3)};base64,${filePath}`);
199+
}
200+
}
201+
202+
const additionalData = {};
203+
if (this.enableAutoReminder) {
204+
additionalData.reminderSettings = {
205+
enableAutoReminder: this.enableAutoReminder,
206+
reminderDays: this.reminderDays,
207+
reminderCount: this.reminderCount,
208+
};
209+
}
210+
211+
const response = await this.boldsign.sendDocument({
212+
$,
213+
headers: {
214+
"Content-Type": "application/json;odata.metadata=minimal;odata.streaming=true",
215+
},
216+
params: {
217+
templateId: this.templateId,
218+
},
219+
data: {
220+
title: this.title,
221+
message: this.message,
222+
roles: parseObject(this.roles),
223+
brandId: this.brandId,
224+
labels: parseObject(this.labels),
225+
disableEmails: this.disableEmails,
226+
disableSMS: this.disableSMS,
227+
hideDocumentId: this.hideDocumentId,
228+
reminderSettings: {
229+
enableAutoReminder: this.enableAutoReminder,
230+
reminderDays: this.reminderDays,
231+
reminderCount: this.reminderCount,
232+
},
233+
cc: this.cc ?? parseObject(this.cc)?.map((item) => ({
234+
emailAddress: item,
235+
})),
236+
expiryDays: this.expiryDays,
237+
enablePrintAndSign: this.enablePrintAndSign,
238+
enableReassign: this.enableReassign,
239+
enableSigningOrder: this.enableSigningOrder,
240+
disableExpiryAlert: this.disableExpiryAlert,
241+
documentInfo: parseObject(this.documentInfo),
242+
roleRemovalIndices: parseObject(this.roleRemovalIndices),
243+
documentDownloadOption: this.documentDownloadOption,
244+
formGroups: parseObject(this.formGroups),
245+
files,
246+
fileUrls: parseObject(this.fileUrls),
247+
recipientNotificationSettings: parseObject(this.recipientNotificationSettings),
248+
removeFormfields: parseObject(this.removeFormfields),
249+
enableAuditTrailLocalization: this.enableAuditTrailLocalization,
250+
...additionalData,
251+
},
252+
});
253+
$.export("$summary", `Document sent successfully using template ${this.templateId}`);
254+
return response;
255+
} catch ({ message }) {
256+
const parsedMessage = JSON.parse(message);
257+
let errorMessage = "";
258+
if (parsedMessage.error) errorMessage = parsedMessage.error;
259+
if (parsedMessage.errors) {
260+
Object.entries(parsedMessage.errors).map(([
261+
,
262+
value,
263+
]) => {
264+
errorMessage += `- ${value[0]}\n`;
265+
});
266+
}
267+
throw new ConfigurationError(errorMessage);
268+
}
185269
},
186270
};

0 commit comments

Comments
 (0)