Skip to content

Commit 31e6d6a

Browse files
committed
rm promisify calls
1 parent 5645a08 commit 31e6d6a

15 files changed

+394
-411
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ npm-debug.log*
55
yarn-debug.log*
66
yarn-error.log*
77

8+
.idea/*
9+
810
# Runtime data
911
pids
1012
*.pid

lib/examples/eg001EmbeddedSigning.js

+28-32
Original file line numberDiff line numberDiff line change
@@ -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
126102
eg001EmbeddedSigning.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+
}

lib/examples/eg002SigningViaEmail.js

+27-26
Original file line numberDiff line numberDiff line change
@@ -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 eg002SigningViaEmail = 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-
eg002SigningViaEmail.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/eg002SigningViaEmail', {
36-
csrfToken: req.csrfToken(),
37-
title: "Signing request by email",
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
@@ -127,7 +103,6 @@ eg002SigningViaEmail.createController = async (req, res) => {
127103
// ***DS.worker.start ***DS.snippet.1.start
128104
eg002SigningViaEmail.worker = async (args) => {
129105
let envelopesApi = new docusign.EnvelopesApi(args.dsAPIclient)
130-
, createEnvelopeP = promisify(envelopesApi.createEnvelope).bind(envelopesApi)
131106
, results = null
132107
;
133108

@@ -136,7 +111,8 @@ eg002SigningViaEmail.worker = async (args) => {
136111

137112
// Step 2. call Envelopes::create API method
138113
// Exceptions will be caught by the calling function
139-
results = await createEnvelopeP(args.accountId, {envelopeDefinition: envelope});
114+
results = await envelopesApi.createEnvelope(args.accountId,
115+
{envelopeDefinition: envelope});
140116
let envelopeId = results.envelopeId;
141117

142118
console.log(`Envelope was created. EnvelopeId ${envelopeId}`);
@@ -300,6 +276,31 @@ function document1(args) {
300276
}
301277
// ***DS.snippet.3.end
302278

279+
/**
280+
* Form page for this application
281+
*/
282+
eg002SigningViaEmail.getController = (req, res) => {
283+
// Check that the authentication token is ok with a long buffer time.
284+
// If needed, now is the best time to ask the user to authenticate
285+
// since they have not yet entered any information into the form.
286+
let tokenOK = req.dsAuthCodeGrant.checkToken();
287+
if (tokenOK) {
288+
res.render('pages/examples/eg002SigningViaEmail', {
289+
csrfToken: req.csrfToken(),
290+
title: "Signing request by email",
291+
sourceFile: path.basename(__filename),
292+
sourceUrl: dsConfig.githubExampleUrl + path.basename(__filename),
293+
documentation: dsConfig.documentation + eg,
294+
showDoc: dsConfig.documentation
295+
});
296+
} else {
297+
// Save the current operation so it will be resumed after authentication
298+
req.dsAuthCodeGrant.setEg(req, eg);
299+
res.redirect(mustAuthenticate);
300+
}
301+
}
302+
303+
303304

304305

305306

lib/examples/eg003ListEnvelopes.js

+25-27
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const docusign = require('docusign-esign')
88
, dsConfig = require('../../ds_configuration.js').config
99
, moment = require('moment')
1010
, path = require('path')
11-
, {promisify} = require('util') // http://2ality.com/2017/05/util-promisify.html
1211
;
1312

1413
const eg003ListEnvelopes = exports
@@ -17,30 +16,6 @@ const eg003ListEnvelopes = exports
1716
, minimumBufferMin = 3
1817
;
1918

20-
/**
21-
* Form page for this application
22-
*/
23-
eg003ListEnvelopes.getController = (req, res) => {
24-
// Check that the authentication token is ok with a long buffer time.
25-
// If needed, now is the best time to ask the user to authenticate
26-
// since they have not yet entered any information into the form.
27-
let tokenOK = req.dsAuthCodeGrant.checkToken();
28-
if (tokenOK) {
29-
res.render('pages/examples/eg003ListEnvelopes', {
30-
csrfToken: req.csrfToken(),
31-
title: "List envelopes",
32-
sourceFile: path.basename(__filename),
33-
sourceUrl: dsConfig.githubExampleUrl + path.basename(__filename),
34-
documentation: dsConfig.documentation + eg,
35-
showDoc: dsConfig.documentation
36-
});
37-
} else {
38-
// Save the current operation so it will be resumed after authentication
39-
req.dsAuthCodeGrant.setEg(req, eg);
40-
res.redirect(mustAuthenticate);
41-
}
42-
}
43-
4419
/**
4520
* List envelopes in the user's account
4621
* @param {object} req Request obj
@@ -104,7 +79,6 @@ eg003ListEnvelopes.createController = async (req, res) => {
10479
// ***DS.worker.start ***DS.snippet.1.start
10580
eg003ListEnvelopes.worker = async (args) => {
10681
let envelopesApi = new docusign.EnvelopesApi(args.dsAPIclient)
107-
, listStatusChangesP = promisify(envelopesApi.listStatusChanges).bind(envelopesApi)
10882
, results = null
10983
;
11084

@@ -119,8 +93,32 @@ eg003ListEnvelopes.worker = async (args) => {
11993
let options = {fromDate: moment().subtract(30, 'days').format()};
12094

12195
// Exceptions will be caught by the calling function
122-
results = await listStatusChangesP(args.accountId, options);
96+
results = await envelopesApi.listStatusChanges(args.accountId, options);
12397
return results;
12498
}
12599
// ***DS.worker.end ***DS.snippet.1.end
126100

101+
/**
102+
* Form page for this application
103+
*/
104+
eg003ListEnvelopes.getController = (req, res) => {
105+
// Check that the authentication token is ok with a long buffer time.
106+
// If needed, now is the best time to ask the user to authenticate
107+
// since they have not yet entered any information into the form.
108+
let tokenOK = req.dsAuthCodeGrant.checkToken();
109+
if (tokenOK) {
110+
res.render('pages/examples/eg003ListEnvelopes', {
111+
csrfToken: req.csrfToken(),
112+
title: "List envelopes",
113+
sourceFile: path.basename(__filename),
114+
sourceUrl: dsConfig.githubExampleUrl + path.basename(__filename),
115+
documentation: dsConfig.documentation + eg,
116+
showDoc: dsConfig.documentation
117+
});
118+
} else {
119+
// Save the current operation so it will be resumed after authentication
120+
req.dsAuthCodeGrant.setEg(req, eg);
121+
res.redirect(mustAuthenticate);
122+
}
123+
}
124+

lib/examples/eg004EnvelopeInfo.js

+28-28
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
const path = require('path')
88
, docusign = require('docusign-esign')
9-
, {promisify} = require('util') // http://2ality.com/2017/05/util-promisify.html
109
, dsConfig = require('../../ds_configuration.js').config
1110
;
1211

@@ -16,30 +15,6 @@ const eg004EnvelopeInfo = exports
1615
, minimumBufferMin = 3
1716
;
1817

19-
/**
20-
* Form page for this application
21-
*/
22-
eg004EnvelopeInfo.getController = (req, res) => {
23-
// Check that the authentication token is ok with a long buffer time.
24-
// If needed, now is the best time to ask the user to authenticate
25-
// since they have not yet entered any information into the form.
26-
let tokenOK = req.dsAuthCodeGrant.checkToken();
27-
if (tokenOK) {
28-
res.render('pages/examples/eg004EnvelopeInfo', {
29-
csrfToken: req.csrfToken(),
30-
title: "Get envelope information",
31-
envelopeOk: req.session.envelopeId,
32-
sourceFile: path.basename(__filename),
33-
sourceUrl: dsConfig.githubExampleUrl + path.basename(__filename),
34-
documentation: dsConfig.documentation + eg,
35-
showDoc: dsConfig.documentation
36-
});
37-
} else {
38-
// Save the current operation so it will be resumed after authentication
39-
req.dsAuthCodeGrant.setEg(req, eg);
40-
res.redirect(mustAuthenticate);
41-
}
42-
}
4318

4419
/**
4520
* Get the envelope
@@ -117,13 +92,38 @@ eg004EnvelopeInfo.createController = async (req, res) => {
11792
// ***DS.worker.start ***DS.snippet.1.start
11893
eg004EnvelopeInfo.worker = async (args) => {
11994
let envelopesApi = new docusign.EnvelopesApi(args.dsAPIclient)
120-
, getEnvelopeP = promisify(envelopesApi.getEnvelope).bind(envelopesApi)
12195
, results = null
12296
;
12397

12498
// Step 1. Call Envelopes::get
12599
// Exceptions will be caught by the calling function
126-
results = await getEnvelopeP(args.accountId, args.envelopeId, null);
100+
results = await envelopesApi.getEnvelope(args.accountId, args.envelopeId, null);
127101
return results;
128102
}
129-
// ***DS.worker.end ***DS.snippet.1.end
103+
// ***DS.worker.end ***DS.snippet.1.end
104+
105+
106+
/**
107+
* Form page for this application
108+
*/
109+
eg004EnvelopeInfo.getController = (req, res) => {
110+
// Check that the authentication token is ok with a long buffer time.
111+
// If needed, now is the best time to ask the user to authenticate
112+
// since they have not yet entered any information into the form.
113+
let tokenOK = req.dsAuthCodeGrant.checkToken();
114+
if (tokenOK) {
115+
res.render('pages/examples/eg004EnvelopeInfo', {
116+
csrfToken: req.csrfToken(),
117+
title: "Get envelope information",
118+
envelopeOk: req.session.envelopeId,
119+
sourceFile: path.basename(__filename),
120+
sourceUrl: dsConfig.githubExampleUrl + path.basename(__filename),
121+
documentation: dsConfig.documentation + eg,
122+
showDoc: dsConfig.documentation
123+
});
124+
} else {
125+
// Save the current operation so it will be resumed after authentication
126+
req.dsAuthCodeGrant.setEg(req, eg);
127+
res.redirect(mustAuthenticate);
128+
}
129+
}

0 commit comments

Comments
 (0)