@@ -8,7 +8,6 @@ const path = require('path')
88 , fs = require ( 'fs-extra' )
99 , docusign = require ( 'docusign-esign' )
1010 , validator = require ( 'validator' )
11- , { promisify} = require ( 'util' ) // http://2ality.com/2017/05/util-promisify.html
1211 , dsConfig = require ( '../../ds_configuration.js' ) . config
1312 ;
1413
@@ -23,29 +22,6 @@ const eg001EmbeddedSigning = exports
2322 , dsPingUrl = dsConfig . appUrl + '/' // Url that will be pinged by the DocuSign Signing Ceremony via Ajax
2423 ;
2524
26- /**
27- * Form page for this application
28- */
29- eg001EmbeddedSigning . getController = ( req , res ) => {
30- // Check that the authentication token is ok with a long buffer time.
31- // If needed, now is the best time to ask the user to authenticate
32- // since they have not yet entered any information into the form.
33- let tokenOK = req . dsAuthCodeGrant . checkToken ( ) ;
34- if ( tokenOK ) {
35- res . render ( 'pages/examples/eg001EmbeddedSigning' , {
36- csrfToken : req . csrfToken ( ) ,
37- title : "Embedded Signing Ceremony" ,
38- sourceFile : path . basename ( __filename ) ,
39- sourceUrl : dsConfig . githubExampleUrl + path . basename ( __filename ) ,
40- documentation : dsConfig . documentation + eg ,
41- showDoc : dsConfig . documentation
42- } ) ;
43- } else {
44- // Save the current operation so it will be resumed after authentication
45- req . dsAuthCodeGrant . setEg ( req , eg ) ;
46- res . redirect ( mustAuthenticate ) ;
47- }
48- }
4925
5026/**
5127 * Create the envelope, the Signing Ceremony, and then redirect to the Signing Ceremony
@@ -125,7 +101,6 @@ eg001EmbeddedSigning.createController = async (req, res) => {
125101// ***DS.worker.start ***DS.snippet.1.start
126102eg001EmbeddedSigning . worker = async ( args ) => {
127103 let envelopesApi = new docusign . EnvelopesApi ( args . dsAPIclient )
128- , createEnvelopeP = promisify ( envelopesApi . createEnvelope ) . bind ( envelopesApi )
129104 , results = null
130105 ;
131106
@@ -134,19 +109,16 @@ eg001EmbeddedSigning.worker = async (args) => {
134109
135110 // Step 2. call Envelopes::create API method
136111 // Exceptions will be caught by the calling function
137- results = await createEnvelopeP ( args . accountId , { envelopeDefinition : envelope } ) ;
138-
112+ results = await envelopesApi . createEnvelope ( args . accountId , { envelopeDefinition : envelope } ) ;
113+
139114 let envelopeId = results . envelopeId ;
140115 console . log ( `Envelope was created. EnvelopeId ${ envelopeId } ` ) ;
141116
142117 // Step 3. create the recipient view, the Signing Ceremony
143- let viewRequest = makeRecipientViewRequest ( args . envelopeArgs )
144- , createRecipientViewP = promisify ( envelopesApi . createRecipientView ) . bind ( envelopesApi )
145- ;
146-
118+ let viewRequest = makeRecipientViewRequest ( args . envelopeArgs ) ;
147119 // Call the CreateRecipientView API
148120 // Exceptions will be caught by the calling function
149- results = await createRecipientViewP ( args . accountId , envelopeId ,
121+ results = await envelopesApi . createRecipientView ( args . accountId , envelopeId ,
150122 { recipientViewRequest : viewRequest } ) ;
151123
152124 return ( { envelopeId : envelopeId , redirectUrl : results . url } )
@@ -267,3 +239,27 @@ function makeRecipientViewRequest(args) {
267239}
268240// ***DS.snippet.3.end
269241
242+
243+ /**
244+ * Form page for this application
245+ */
246+ eg001EmbeddedSigning . getController = ( req , res ) => {
247+ // Check that the authentication token is ok with a long buffer time.
248+ // If needed, now is the best time to ask the user to authenticate
249+ // since they have not yet entered any information into the form.
250+ let tokenOK = req . dsAuthCodeGrant . checkToken ( ) ;
251+ if ( tokenOK ) {
252+ res . render ( 'pages/examples/eg001EmbeddedSigning' , {
253+ csrfToken : req . csrfToken ( ) ,
254+ title : "Embedded Signing Ceremony" ,
255+ sourceFile : path . basename ( __filename ) ,
256+ sourceUrl : dsConfig . githubExampleUrl + path . basename ( __filename ) ,
257+ documentation : dsConfig . documentation + eg ,
258+ showDoc : dsConfig . documentation
259+ } ) ;
260+ } else {
261+ // Save the current operation so it will be resumed after authentication
262+ req . dsAuthCodeGrant . setEg ( req , eg ) ;
263+ res . redirect ( mustAuthenticate ) ;
264+ }
265+ }
0 commit comments