@@ -2,14 +2,17 @@ const docusign = require('docusign-esign');
2
2
const signingViaEmail = require ( '../lib/eSignature/examples/signingViaEmail' ) ;
3
3
const fs = require ( 'fs' ) ;
4
4
const path = require ( 'path' ) ;
5
- const prompt = require ( 'prompt-sync' ) ( ) ;
6
5
7
6
const jwtConfig = require ( './jwtConfig.json' ) ;
8
- const { ProvisioningInformation } = require ( 'docusign-esign' ) ;
9
7
const demoDocsPath = path . resolve ( __dirname , '../demo_documents' ) ;
10
8
const doc2File = 'World_Wide_Corp_Battle_Plan_Trafalgar.docx' ;
11
9
const doc3File = 'World_Wide_Corp_lorem.pdf' ;
12
10
11
+ const readline = require ( 'readline' ) . createInterface ( {
12
+ input : process . stdin ,
13
+ output : process . stdout
14
+ } ) ;
15
+
13
16
14
17
const SCOPES = [
15
18
'signature' , 'impersonation'
@@ -62,11 +65,11 @@ async function authenticate(){
62
65
} ;
63
66
} catch ( e ) {
64
67
console . log ( e ) ;
65
- let body = e . response && e . response . body ;
68
+ let body = e ? .response ?. body || e ? .response ?. data ;
66
69
// Determine the source of the error
67
70
if ( body ) {
68
71
// The user needs to grant consent
69
- if ( body . error && body . error === 'consent_required' ) {
72
+ if ( body ? .error === 'consent_required' ) {
70
73
if ( getConsent ( ) ) { return authenticate ( ) ; } ;
71
74
} else {
72
75
// Consent has been granted. Show status code for DocuSign API error
@@ -77,11 +80,11 @@ async function authenticate(){
77
80
}
78
81
}
79
82
80
- function getArgs ( apiAccountId , accessToken , basePath ) {
81
- signerEmail = prompt ( "Enter the signer's email address: " ) ;
82
- signerName = prompt ( "Enter the signer's name: " ) ;
83
- ccEmail = prompt ( "Enter the carbon copy's email address: " ) ;
84
- ccName = prompt ( "Enter the carbon copy's name: " ) ;
83
+ async function getArgs ( apiAccountId , accessToken , basePath ) {
84
+ signerEmail = await prompt ( "Enter the signer's email address: " ) ;
85
+ signerName = await prompt ( "Enter the signer's name: " ) ;
86
+ ccEmail = await prompt ( "Enter the carbon copy's email address: " ) ;
87
+ ccName = await prompt ( "Enter the carbon copy's name: " ) ;
85
88
86
89
const envelopeArgs = {
87
90
signerEmail : signerEmail ,
@@ -102,10 +105,18 @@ function getArgs(apiAccountId, accessToken, basePath){
102
105
return args ;
103
106
}
104
107
108
+ function prompt ( prompt ) {
109
+ return new Promise ( ( resolve ) => {
110
+ readline . question ( prompt , ( answer ) => {
111
+ resolve ( answer ) ;
112
+ } ) ;
113
+ } ) ;
114
+ }
115
+
105
116
106
117
async function main ( ) {
107
118
let accountInfo = await authenticate ( ) ;
108
- let args = getArgs ( accountInfo . apiAccountId , accountInfo . accessToken , accountInfo . basePath ) ;
119
+ let args = await getArgs ( accountInfo . apiAccountId , accountInfo . accessToken , accountInfo . basePath ) ;
109
120
let envelopeId = await signingViaEmail . sendEnvelope ( args ) ;
110
121
console . log ( envelopeId ) ;
111
122
}
0 commit comments