Skip to content

Commit 4785f9e

Browse files
authored
Docusign - Download Documents (#14831)
* wip * download-documents action * revert source changes * add $ variable
1 parent 184654d commit 4785f9e

File tree

2 files changed

+112
-1
lines changed

2 files changed

+112
-1
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import docusign from "../../docusign.app.mjs";
2+
import fs from "fs";
3+
4+
export default {
5+
key: "docusign-download-documents",
6+
name: "Download Documents",
7+
description: "Download the documents of an envelope to the /tmp directory. [See the documentation here](https://developers.docusign.com/docs/esign-rest-api/how-to/download-envelope-documents/)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
docusign,
12+
account: {
13+
propDefinition: [
14+
docusign,
15+
"account",
16+
],
17+
},
18+
envelopeId: {
19+
type: "string",
20+
label: "Envelope ID",
21+
description: "Identifier of the envelope to download documents from",
22+
async options({ prevContext }) {
23+
const baseUri = await this.docusign.getBaseUri({
24+
accountId: this.account,
25+
});
26+
const { startPosition } = prevContext;
27+
const {
28+
envelopes = [], nextUri, endPosition,
29+
} = await this.docusign.listEnvelopes(baseUri, {
30+
start_position: startPosition,
31+
from_date: "2000-01-01",
32+
});
33+
return {
34+
options: envelopes.map(({
35+
envelopeId: value, emailSubject: label,
36+
}) => ({
37+
label,
38+
value,
39+
})),
40+
context: {
41+
startPosition: nextUri
42+
? endPosition + 1
43+
: undefined,
44+
},
45+
};
46+
},
47+
},
48+
downloadType: {
49+
type: "string",
50+
label: "Download Type",
51+
description: "Download envelope documents to the `/tmp` directory",
52+
options: [
53+
{
54+
label: "All Documents (PDF)",
55+
value: "combined",
56+
},
57+
{
58+
label: "All Documents (Zip)",
59+
value: "archive",
60+
},
61+
{
62+
label: "Certificate (PDF)",
63+
value: "certificate",
64+
},
65+
{
66+
label: "Portfolio (PDF)",
67+
value: "portfolio",
68+
},
69+
],
70+
},
71+
filename: {
72+
type: "string",
73+
label: "Filename",
74+
description: "The filename to save the file as in the `/tmp` directory including the file extension (.pdf or .zip)",
75+
},
76+
},
77+
methods: {
78+
getEnvelope($, baseUri, envelopeId) {
79+
return this.docusign._makeRequest({
80+
$,
81+
config: {
82+
url: `${baseUri}envelopes/${envelopeId}`,
83+
},
84+
});
85+
},
86+
async downloadToTmp($, baseUri, documentsUri, filePath) {
87+
const content = await this.docusign._makeRequest({
88+
$,
89+
config: {
90+
url: `${baseUri}${documentsUri.slice(1)}/${this.downloadType}`,
91+
responseType: "arraybuffer",
92+
},
93+
});
94+
const rawcontent = content.toString("base64");
95+
const buffer = Buffer.from(rawcontent, "base64");
96+
fs.writeFileSync(filePath, buffer);
97+
},
98+
},
99+
async run({ $ }) {
100+
const baseUri = await this.docusign.getBaseUri({
101+
accountId: this.account,
102+
});
103+
const envelope = await this.getEnvelope($, baseUri, this.envelopeId);
104+
const filePath = `/tmp/${this.filename}`;
105+
await this.downloadToTmp($, baseUri, envelope.documentsUri, filePath);
106+
107+
$.export("$summary", `Successfully downloaded files to ${filePath}`);
108+
109+
return filePath;
110+
},
111+
};

components/docusign/package.json

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

0 commit comments

Comments
 (0)