11import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform" ;
2- import fs from "fs" ;
32
43export default {
54 dedupe : "unique" ,
@@ -34,30 +33,6 @@ export default {
3433 "any" ,
3534 ] ,
3635 } ,
37- downloadEnvelopeDocuments : {
38- type : "string" ,
39- label : "Download Envelope Documents" ,
40- description : "Download envelope documents to the `/tmp` directory" ,
41- options : [
42- {
43- label : "All Documents (PDF)" ,
44- value : "combined" ,
45- } ,
46- {
47- label : "All Documents (Zip)" ,
48- value : "archive" ,
49- } ,
50- {
51- label : "Certificate (PDF)" ,
52- value : "certificate" ,
53- } ,
54- {
55- label : "Portfolio (PDF)" ,
56- value : "portfolio" ,
57- } ,
58- ] ,
59- optional : true ,
60- } ,
6136 } ,
6237 methods : {
6338 _getLastEvent ( ) {
@@ -81,23 +56,6 @@ export default {
8156 ts,
8257 } ;
8358 } ,
84- getFilePath ( envelopeId ) {
85- const extension = this . downloadEnvelopeDocuments === "archive"
86- ? "zip"
87- : "pdf" ;
88- return `/tmp/${ envelopeId } .${ extension } ` ;
89- } ,
90- async downloadToTmp ( baseUri , documentsUri , filePath ) {
91- const content = await this . docusign . _makeRequest ( {
92- config : {
93- url : `${ baseUri } ${ documentsUri . slice ( 1 ) } /${ this . downloadEnvelopeDocuments } ` ,
94- responseType : "arraybuffer" ,
95- } ,
96- } ) ;
97- const rawcontent = content . toString ( "base64" ) ;
98- const buffer = Buffer . from ( rawcontent , "base64" ) ;
99- fs . writeFileSync ( filePath , buffer ) ;
100- } ,
10159 } ,
10260 async run ( event ) {
10361 const { timestamp : ts } = event ;
@@ -110,9 +68,6 @@ export default {
11068 from_date : lastEvent ,
11169 status : this . status . join ( ) ,
11270 } ;
113-
114- const newEnvelopes = [ ] ;
115-
11671 do {
11772 const {
11873 envelopes = [ ] ,
@@ -123,22 +78,12 @@ export default {
12378 params . start_position += endPosition + 1 ;
12479 }
12580 else done = true ;
126- newEnvelopes . push ( ...envelopes ) ;
127- } while ( ! done ) ;
128-
129- this . _setLastEvent ( new Date ( ts * 1000 ) . toISOString ( ) ) ;
13081
131- for ( const envelope of newEnvelopes ) {
132- if ( this . downloadEnvelopeDocuments ) {
133- const filePath = this . getFilePath ( envelope . envelopeId ) ;
134- await this . downloadToTmp ( baseUri , envelope . documentsUri , filePath ) ;
135- envelope . documents = {
136- filePath,
137- } ;
82+ for ( const envelope of envelopes ) {
83+ const meta = this . generateMeta ( envelope ) ;
84+ this . $emit ( envelope , meta ) ;
13885 }
139- console . log ( fs . readdirSync ( "/tmp" ) ) ;
140- const meta = this . generateMeta ( envelope ) ;
141- this . $emit ( envelope , meta ) ;
142- }
86+ } while ( ! done ) ;
87+ this . _setLastEvent ( new Date ( ts * 1000 ) . toISOString ( ) ) ;
14388 } ,
14489} ;
0 commit comments