Skip to content

Commit 1f3a659

Browse files
GTFalcaolcaresia
andauthored
Merging pull request #18001
* package/pnpm update * Adding 'create sign request' action --------- Co-authored-by: Lucas Caresia <[email protected]>
1 parent 20c3032 commit 1f3a659

File tree

4 files changed

+143
-1
lines changed

4 files changed

+143
-1
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
import app from "../../box.app.mjs";
3+
import utils from "../../common/utils.mjs";
4+
5+
export default {
6+
name: "Create Box Sign Request",
7+
description: "Creates a signature request. This involves preparing a document for signing and sending the signature request to signers. [See the documentation](https://developer.box.com/reference/post-sign-requests/).",
8+
key: "box-create-sign-request",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
app,
13+
signers: {
14+
type: "string[]",
15+
label: "Signers",
16+
description: "Array of signers for the signature request. Each signer should be a JSON object with at least an email property. [See the documentation](https://developer.box.com/reference/post-sign-requests/#param-signers) for more information. Example: `{\"email\": \"[email protected]\", \"role\": \"signer\"}`",
17+
},
18+
name: {
19+
type: "string",
20+
label: "Request Name",
21+
description: "Name of the signature request",
22+
optional: true,
23+
},
24+
parentFolder: {
25+
propDefinition: [
26+
app,
27+
"parentId",
28+
],
29+
label: "Parent Folder",
30+
description: "The destination folder to place final, signed document and signing log. Uses root folder (0) if not specified",
31+
optional: true,
32+
},
33+
emailSubject: {
34+
type: "string",
35+
label: "Email Subject",
36+
description: "Subject of sign request email. If not provided, a default subject will be used",
37+
optional: true,
38+
},
39+
emailMessage: {
40+
type: "string",
41+
label: "Email Message",
42+
description: "Message to include in sign request email. If not provided, a default message will be used",
43+
optional: true,
44+
},
45+
redirectUrl: {
46+
type: "string",
47+
label: "Redirect URL",
48+
description: "The URI that a signer will be redirected to after signing a document",
49+
optional: true,
50+
},
51+
declinedRedirectUrl: {
52+
type: "string",
53+
label: "Declined Redirect URL",
54+
description: "The URI that a signer will be redirected to after declining to sign a document",
55+
optional: true,
56+
},
57+
additionalOptions: {
58+
type: "object",
59+
label: "Additional Options",
60+
description: "Additional parameters to send in the request. See the [documentation](https://developer.box.com/reference/post-sign-requests/) for all available parameters. Values will be parsed as JSON where applicable",
61+
optional: true,
62+
},
63+
},
64+
async run({ $ }) {
65+
const {
66+
signers,
67+
name,
68+
parentFolder,
69+
emailSubject,
70+
emailMessage,
71+
redirectUrl,
72+
declinedRedirectUrl,
73+
additionalOptions,
74+
} = this;
75+
76+
const parsedSigners = signers.map((signer) => {
77+
try {
78+
return typeof signer === "string"
79+
? JSON.parse(signer)
80+
: signer;
81+
} catch (error) {
82+
throw new ConfigurationError(`Error parsing signer as JSON: ${error}`);
83+
}
84+
});
85+
86+
const data = {
87+
signers: parsedSigners,
88+
name,
89+
email_subject: emailSubject,
90+
email_message: emailMessage,
91+
redirect_url: redirectUrl,
92+
declined_redirect_url: declinedRedirectUrl,
93+
...(additionalOptions
94+
? utils.parseObjectEntries(additionalOptions)
95+
: {}),
96+
};
97+
98+
if (parentFolder) {
99+
data.parent_folder = {
100+
id: parentFolder,
101+
type: "folder",
102+
};
103+
}
104+
105+
const response = await this.app.createSignRequest({
106+
$,
107+
data,
108+
});
109+
110+
$.export("$summary", `Successfully created Box sign request (ID: ${response.id})`);
111+
return response;
112+
},
113+
};

components/box/box.app.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,5 +319,12 @@ export default {
319319
...args,
320320
});
321321
},
322+
async createSignRequest(args = {}) {
323+
return this._makeRequest({
324+
method: "POST",
325+
path: "/sign_requests",
326+
...args,
327+
});
328+
},
322329
},
323330
};

components/box/common/utils.mjs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,29 @@
11
import constants from "./constants.mjs";
22
import { getFileStreamAndMetadata } from "@pipedream/platform";
33

4+
function optionalParseAsJSON(value) {
5+
try {
6+
return JSON.parse(value);
7+
} catch (e) {
8+
return value;
9+
}
10+
}
11+
412
export default {
13+
parseObjectEntries(value = {}) {
14+
const obj = typeof value === "string"
15+
? JSON.parse(value)
16+
: value;
17+
return Object.fromEntries(
18+
Object.entries(obj).map(([
19+
key,
20+
value,
21+
]) => [
22+
key,
23+
optionalParseAsJSON(value),
24+
]),
25+
);
26+
},
527
async getFileData(filePath) {
628
const {
729
stream, metadata,

components/box/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/box",
3-
"version": "0.4.1",
3+
"version": "0.5.0",
44
"description": "Pipedream Box Components",
55
"main": "box.app.mjs",
66
"keywords": [

0 commit comments

Comments
 (0)