|
| 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 | +}; |
0 commit comments