Skip to content

Commit 736411b

Browse files
committed
download-documents action
1 parent a7509c6 commit 736411b

File tree

3 files changed

+112
-2
lines changed

3 files changed

+112
-2
lines changed
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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+
config: {
89+
url: `${baseUri}${documentsUri.slice(1)}/${this.downloadType}`,
90+
responseType: "arraybuffer",
91+
},
92+
});
93+
const rawcontent = content.toString("base64");
94+
const buffer = Buffer.from(rawcontent, "base64");
95+
fs.writeFileSync(filePath, buffer);
96+
},
97+
},
98+
async run({ $ }) {
99+
const baseUri = await this.docusign.getBaseUri({
100+
accountId: this.account,
101+
});
102+
const envelope = await this.getEnvelope($, baseUri, this.envelopeId);
103+
const filePath = `/tmp/${this.filename}`;
104+
await this.downloadToTmp(baseUri, envelope.documentsUri, filePath);
105+
106+
$.export("$summary", `Successfully downloaded files to ${filePath}`);
107+
108+
return filePath;
109+
},
110+
};

components/docusign_developer/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_developer",
3-
"version": "0.2.1",
3+
"version": "0.2.0",
44
"description": "Pipedream Docusign_developer Components",
55
"main": "docusign_developer.app.mjs",
66
"keywords": [

components/docusign_developer/sources/new-change-in-envelope-status/new-change-in-envelope-status.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import common from "../../../docusign/sources/new-change-in-envelope-status/comm
44
export default {
55
...common,
66
key: "docusign_developer-new-change-in-envelope-status",
7-
version: "0.0.2",
7+
version: "0.0.1",
88
name: "New Change in Envelope Status",
99
description: "Emit new event when an envelope's status is updated",
1010
type: "source",

0 commit comments

Comments
 (0)