@@ -2,14 +2,17 @@ const docusign = require('docusign-esign');
22const signingViaEmail = require ( '../lib/eSignature/examples/signingViaEmail' ) ;
33const fs = require ( 'fs' ) ;
44const path = require ( 'path' ) ;
5- const prompt = require ( 'prompt-sync' ) ( ) ;
65
76const jwtConfig = require ( './jwtConfig.json' ) ;
8- const { ProvisioningInformation } = require ( 'docusign-esign' ) ;
97const demoDocsPath = path . resolve ( __dirname , '../demo_documents' ) ;
108const doc2File = 'World_Wide_Corp_Battle_Plan_Trafalgar.docx' ;
119const doc3File = 'World_Wide_Corp_lorem.pdf' ;
1210
11+ const readline = require ( 'readline' ) . createInterface ( {
12+ input : process . stdin ,
13+ output : process . stdout
14+ } ) ;
15+
1316
1417const SCOPES = [
1518 'signature' , 'impersonation'
@@ -62,11 +65,11 @@ async function authenticate(){
6265 } ;
6366 } catch ( e ) {
6467 console . log ( e ) ;
65- let body = e . response && e . response . body ;
68+ let body = e ? .response ?. body || e ? .response ?. data ;
6669 // Determine the source of the error
6770 if ( body ) {
6871 // The user needs to grant consent
69- if ( body . error && body . error === 'consent_required' ) {
72+ if ( body ? .error === 'consent_required' ) {
7073 if ( getConsent ( ) ) { return authenticate ( ) ; } ;
7174 } else {
7275 // Consent has been granted. Show status code for DocuSign API error
@@ -77,11 +80,11 @@ async function authenticate(){
7780 }
7881}
7982
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: " ) ;
8588
8689 const envelopeArgs = {
8790 signerEmail : signerEmail ,
@@ -102,10 +105,18 @@ function getArgs(apiAccountId, accessToken, basePath){
102105 return args ;
103106}
104107
108+ function prompt ( prompt ) {
109+ return new Promise ( ( resolve ) => {
110+ readline . question ( prompt , ( answer ) => {
111+ resolve ( answer ) ;
112+ } ) ;
113+ } ) ;
114+ }
115+
105116
106117async function main ( ) {
107118 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 ) ;
109120 let envelopeId = await signingViaEmail . sendEnvelope ( args ) ;
110121 console . log ( envelopeId ) ;
111122}
0 commit comments