Skip to content

Commit 29e0da8

Browse files
committed
[Components] flexisign #14491
Actions - Send Document Using Template
1 parent 2789621 commit 29e0da8

File tree

4 files changed

+78
-55
lines changed

4 files changed

+78
-55
lines changed

components/flexisign/actions/send-document-using-template/send-document-using-template.mjs

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { snakeCaseToTitleCase } from "../../common/utils.mjs";
12
import flexisign from "../../flexisign.app.mjs";
23

34
export default {
@@ -13,26 +14,51 @@ export default {
1314
flexisign,
1415
"templateId",
1516
],
17+
reloadProps: true,
1618
},
17-
recipients: {
18-
propDefinition: [
19-
flexisign,
20-
"recipients",
21-
],
22-
},
23-
message: {
24-
propDefinition: [
25-
flexisign,
26-
"message",
27-
],
28-
optional: true,
29-
},
19+
},
20+
async additionalProps() {
21+
const props = {};
22+
if (this.templateId) {
23+
const { data: { bodyStructure } } = await this.flexisign.getTemplateDetails({
24+
params: {
25+
templateId: this.templateId,
26+
},
27+
});
28+
29+
for (const [
30+
key,
31+
value,
32+
] of Object.entries(bodyStructure)) {
33+
if ([
34+
"templateId",
35+
"recipientsCount",
36+
].includes(key)) continue;
37+
38+
const title = snakeCaseToTitleCase(key);
39+
props[key] = {
40+
type: typeof value === "number"
41+
? "integer"
42+
: "string",
43+
label: title,
44+
description: title,
45+
default: typeof value === "number"
46+
? value
47+
: undefined,
48+
};
49+
}
50+
}
51+
return props;
3052
},
3153
async run({ $ }) {
32-
const response = await this.flexisign.sendSignatureRequest({
33-
templateId: this.templateId,
34-
recipients: this.recipients,
35-
message: this.message,
54+
const {
55+
flexisign,
56+
...data
57+
} = this;
58+
59+
const response = await flexisign.sendSignatureRequest({
60+
$,
61+
data,
3662
});
3763

3864
$.export("$summary", `Signature request sent for template ID: ${this.templateId}`);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const snakeCaseToTitleCase = (s) =>
2+
s.replace(/^_*(.)|_+(.)/g, (s, c, d) => c
3+
? c.toUpperCase()
4+
: " " + d.toUpperCase());

components/flexisign/flexisign.app.mjs

Lines changed: 27 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,61 +9,51 @@ export default {
99
label: "Template ID",
1010
description: "The ID of the template to generate the document from",
1111
async options() {
12-
const templates = await this.listTemplates();
13-
return templates.map((template) => ({
14-
label: template.name,
15-
value: template.id,
12+
const { data: { list } } = await this.listTemplates();
13+
return list.map(({
14+
_id: value, name: label,
15+
}) => ({
16+
label,
17+
value,
1618
}));
1719
},
1820
},
19-
recipients: {
20-
type: "string[]",
21-
label: "Recipients",
22-
description: "An array of recipient objects, with each recipient specified as a JSON string (e.g., '[{\"email\": \"[email protected]\"}]')",
23-
},
24-
message: {
25-
type: "string",
26-
label: "Message",
27-
description: "A personalized message for the recipients",
28-
optional: true,
29-
},
3021
},
3122
methods: {
3223
_baseUrl() {
3324
return "https://api.flexisign.io/v1";
3425
},
35-
async _makeRequest(opts = {}) {
36-
const {
37-
$ = this, method = "GET", path = "/", headers, ...otherOpts
38-
} = opts;
26+
_headers() {
27+
return {
28+
"api-key": `${this.$auth.api_key}`,
29+
};
30+
},
31+
_makeRequest({
32+
$ = this, path, ...opts
33+
}) {
3934
return axios($, {
40-
...otherOpts,
41-
method,
4235
url: this._baseUrl() + path,
43-
headers: {
44-
...headers,
45-
Authorization: `Bearer ${this.$auth.api_key}`,
46-
},
36+
headers: this._headers(),
37+
...opts,
4738
});
4839
},
49-
async listTemplates(opts = {}) {
40+
listTemplates(opts = {}) {
5041
return this._makeRequest({
51-
path: "/templates",
42+
path: "/templates/all",
5243
...opts,
5344
});
5445
},
55-
async sendSignatureRequest(opts = {}) {
56-
const {
57-
templateId, recipients, message,
58-
} = opts;
46+
getTemplateDetails(opts = {}) {
47+
return this._makeRequest({
48+
path: "/template",
49+
...opts,
50+
});
51+
},
52+
sendSignatureRequest(opts = {}) {
5953
return this._makeRequest({
6054
method: "POST",
61-
path: "/signature/send",
62-
data: {
63-
template_id: templateId,
64-
recipients: recipients.map(JSON.parse),
65-
message,
66-
},
55+
path: "/template/create-document",
56+
...opts,
6757
});
6858
},
6959
},

components/flexisign/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/flexisign",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream FlexiSign Components",
55
"main": "flexisign.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)