Skip to content

Commit b5ba2f9

Browse files
committed
DEVDOCS-554 Unroll the makePromise helper function
1 parent a8cfbec commit b5ba2f9

15 files changed

+39
-90
lines changed

.idea/workspace.xml

Lines changed: 10 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/DSAuthCodeGrant.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ const moment = require('moment')
1717
, docusign = require('docusign-esign')
1818
, dsConfig = require('../ds_configuration.js').config
1919
, passport = require('passport')
20-
, {promisify} = require('util') // http://2ality.com/2017/05/util-promisify.html
2120
, baseUriSuffix = '/restapi'
2221
, tokenReplaceMinGet = 60; // For a form Get, the token must expire at least this number of
2322
// minutes later or it will be replaced
@@ -219,24 +218,6 @@ DSAuthCodeGrant.prototype.getDefaultAccountInfo = function _getDefaultAccountInf
219218
console.log(`Using account ${this._accountId}: ${this._accountName}`);
220219
}
221220

222-
/**
223-
* Returns a promise method, {methodName}_promise, that is a
224-
* promisfied version of the method parameter.
225-
* The promise method is created if it doesn't already exist.
226-
* It is cached via attachment to the parent object.
227-
* @function
228-
* @param obj An object that has method methodName
229-
* @param methodName The string name of the existing method
230-
* @returns {promise} a promise version of the <tt>methodName</tt>.
231-
*/
232-
DSAuthCodeGrant.prototype.makePromise = function _makePromise(obj, methodName){
233-
let promiseName = methodName + '_promise';
234-
if (!(promiseName in obj)) {
235-
obj[promiseName] = promisify(obj[methodName]).bind(obj)
236-
}
237-
return obj[promiseName]
238-
}
239-
240221
/**
241222
* This is the key method for the object.
242223
* It should be called before any API call to DocuSign.

lib/examples/eg001EmbeddedSigning.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ 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
1112
, dsConfig = require('../../ds_configuration.js').config
1213
;
1314

@@ -82,7 +83,6 @@ eg001EmbeddedSigning.createController = async (req, res) => {
8283
, dsAPIclient = req.dsAuthCodeGrant.getDSApi()
8384
, args = {
8485
dsAPIclient: dsAPIclient,
85-
makePromise: req.dsAuthCodeGrant.makePromise, // this is a function
8686
accountId: accountId,
8787
envelopeArgs: envelopeArgs
8888
}
@@ -125,7 +125,7 @@ eg001EmbeddedSigning.createController = async (req, res) => {
125125
// ***DS.worker.start ***DS.snippet.1.start
126126
eg001EmbeddedSigning.worker = async (args) => {
127127
let envelopesApi = new docusign.EnvelopesApi(args.dsAPIclient)
128-
, createEnvelopeP = args.makePromise(envelopesApi, 'createEnvelope')
128+
, createEnvelopeP = promisify(envelopesApi.createEnvelope).bind(envelopesApi)
129129
, results = null
130130
;
131131

@@ -141,7 +141,7 @@ eg001EmbeddedSigning.worker = async (args) => {
141141

142142
// Step 3. create the recipient view, the Signing Ceremony
143143
let viewRequest = makeRecipientViewRequest(args.envelopeArgs)
144-
, createRecipientViewP = args.makePromise(envelopesApi, 'createRecipientView')
144+
, createRecipientViewP = promisify(envelopesApi.createRecipientView).bind(envelopesApi)
145145
;
146146

147147
// Call the CreateRecipientView API

lib/examples/eg002SigningViaEmail.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ 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
1112
, dsConfig = require('../../ds_configuration.js').config
1213
;
1314

@@ -83,7 +84,6 @@ eg002SigningViaEmail.createController = async (req, res) => {
8384
, dsAPIclient = req.dsAuthCodeGrant.getDSApi()
8485
, args = {
8586
dsAPIclient: dsAPIclient,
86-
makePromise: req.dsAuthCodeGrant.makePromise, // this is a function
8787
accountId: accountId,
8888
envelopeArgs: envelopeArgs
8989
}
@@ -127,7 +127,7 @@ eg002SigningViaEmail.createController = async (req, res) => {
127127
// ***DS.worker.start ***DS.snippet.1.start
128128
eg002SigningViaEmail.worker = async (args) => {
129129
let envelopesApi = new docusign.EnvelopesApi(args.dsAPIclient)
130-
, createEnvelopeP = args.makePromise(envelopesApi, 'createEnvelope')
130+
, createEnvelopeP = promisify(envelopesApi.createEnvelope).bind(envelopesApi)
131131
, results = null
132132
;
133133

lib/examples/eg003ListEnvelopes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ 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
1112
;
1213

1314
const eg003ListEnvelopes = exports
@@ -65,7 +66,6 @@ eg003ListEnvelopes.createController = async (req, res) => {
6566
, dsAPIclient = req.dsAuthCodeGrant.getDSApi()
6667
, args = {
6768
dsAPIclient: dsAPIclient,
68-
makePromise: req.dsAuthCodeGrant.makePromise, // this is a function
6969
accountId: accountId,
7070
}
7171
, results = null
@@ -104,7 +104,7 @@ eg003ListEnvelopes.createController = async (req, res) => {
104104
// ***DS.worker.start ***DS.snippet.1.start
105105
eg003ListEnvelopes.worker = async (args) => {
106106
let envelopesApi = new docusign.EnvelopesApi(args.dsAPIclient)
107-
, listStatusChangesP = args.makePromise(envelopesApi, 'listStatusChanges')
107+
, listStatusChangesP = promisify(envelopesApi.listStatusChanges).bind(envelopesApi)
108108
, results = null
109109
;
110110

lib/examples/eg004EnvelopeInfo.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

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

@@ -75,7 +76,6 @@ eg004EnvelopeInfo.createController = async (req, res) => {
7576
, dsAPIclient = req.dsAuthCodeGrant.getDSApi()
7677
, args = {
7778
dsAPIclient: dsAPIclient,
78-
makePromise: req.dsAuthCodeGrant.makePromise, // this is a function
7979
accountId: accountId,
8080
envelopeId: req.session.envelopeId
8181
}
@@ -116,7 +116,7 @@ eg004EnvelopeInfo.createController = async (req, res) => {
116116
// ***DS.worker.start ***DS.snippet.1.start
117117
eg004EnvelopeInfo.worker = async (args) => {
118118
let envelopesApi = new docusign.EnvelopesApi(args.dsAPIclient)
119-
, getEnvelopeP = args.makePromise(envelopesApi, 'getEnvelope')
119+
, getEnvelopeP = promisify(envelopesApi.getEnvelope).bind(envelopesApi)
120120
, results = null
121121
;
122122

lib/examples/eg005EnvelopeRecipients.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

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

@@ -75,7 +76,6 @@ eg005EnvelopeRecipients.createController = async (req, res) => {
7576
, dsAPIclient = req.dsAuthCodeGrant.getDSApi()
7677
, args = {
7778
dsAPIclient: dsAPIclient,
78-
makePromise: req.dsAuthCodeGrant.makePromise, // this is a function
7979
accountId: accountId,
8080
envelopeId: req.session.envelopeId
8181
}
@@ -116,7 +116,7 @@ eg005EnvelopeRecipients.createController = async (req, res) => {
116116
// ***DS.worker.start ***DS.snippet.1.start
117117
eg005EnvelopeRecipients.worker = async (args) => {
118118
let envelopesApi = new docusign.EnvelopesApi(args.dsAPIclient)
119-
, listRecipientsP = args.makePromise(envelopesApi, 'listRecipients')
119+
, listRecipientsP = promisify(envelopesApi.listRecipients).bind(envelopesApi)
120120
, results = null
121121
;
122122

lib/examples/eg006EnvelopeDocs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

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

@@ -75,7 +76,6 @@ eg006EnvelopeDocs.createController = async (req, res) => {
7576
, dsAPIclient = req.dsAuthCodeGrant.getDSApi()
7677
, args = {
7778
dsAPIclient: dsAPIclient,
78-
makePromise: req.dsAuthCodeGrant.makePromise, // this is a function
7979
accountId: accountId,
8080
envelopeId: req.session.envelopeId
8181
}
@@ -134,7 +134,7 @@ eg006EnvelopeDocs.createController = async (req, res) => {
134134
// ***DS.worker.start ***DS.snippet.1.start
135135
eg006EnvelopeDocs.worker = async (args) => {
136136
let envelopesApi = new docusign.EnvelopesApi(args.dsAPIclient)
137-
, listEnvelopeDocumentsP = args.makePromise(envelopesApi, 'listDocuments')
137+
, listEnvelopeDocumentsP = promisify(envelopesApi.listDocuments).bind(envelopesApi)
138138
, results = null
139139
;
140140

lib/examples/eg007EnvelopeGetDoc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const path = require('path')
99
, dsConfig = require('../../ds_configuration.js').config
1010
, validator = require('validator')
1111
, stream = require('stream')
12+
, {promisify} = require('util') // http://2ality.com/2017/05/util-promisify.html
1213
;
1314

1415
const eg007EnvelopeGetDoc = exports
@@ -90,7 +91,6 @@ eg007EnvelopeGetDoc.createController = async (req, res) => {
9091
, documentId = validator.escape(req.body.docSelect)
9192
, args = {
9293
dsAPIclient: dsAPIclient,
93-
makePromise: req.dsAuthCodeGrant.makePromise, // this is a function
9494
accountId: accountId,
9595
documentId: documentId,
9696
envelopeDocuments: envelopeDocuments
@@ -135,7 +135,7 @@ eg007EnvelopeGetDoc.createController = async (req, res) => {
135135
// ***DS.worker.start ***DS.snippet.1.start
136136
eg007EnvelopeGetDoc.worker = async (args) => {
137137
let envelopesApi = new docusign.EnvelopesApi(args.dsAPIclient)
138-
, getEnvelopeDocumentP = args.makePromise(envelopesApi, 'getDocument')
138+
, getEnvelopeDocumentP = promisify(envelopesApi.getDocument).bind(envelopesApi)
139139
, results = null
140140
;
141141

lib/examples/eg008CreateTemplate.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
const path = require('path')
88
, docusign = require('docusign-esign')
9+
, {promisify} = require('util') // http://2ality.com/2017/05/util-promisify.html
910
, dsConfig = require('../../ds_configuration.js').config
1011
, fs = require('fs-extra')
1112
;
@@ -68,7 +69,6 @@ eg008CreateTemplate.createController = async (req, res) => {
6869
, dsAPIclient = req.dsAuthCodeGrant.getDSApi()
6970
, args = {
7071
dsAPIclient: dsAPIclient,
71-
makePromise: req.dsAuthCodeGrant.makePromise, // this is a function
7272
accountId: accountId,
7373
templateName: templateName
7474
}
@@ -114,8 +114,8 @@ eg008CreateTemplate.createController = async (req, res) => {
114114
// ***DS.worker.start ***DS.snippet.1.start
115115
eg008CreateTemplate.worker = async (args) => {
116116
let templatesApi = new docusign.TemplatesApi(args.dsAPIclient)
117-
, createTemplateP = args.makePromise(templatesApi, 'createTemplate')
118-
, listTemplateP = args.makePromise(templatesApi, 'listTemplates')
117+
, createTemplateP = promisify(templatesApi.createTemplate).bind(templatesApi)
118+
, listTemplateP = promisify(templatesApi.listTemplates).bind(templatesApi)
119119
, results = null
120120
, templateId = null // the template that exists or will be created.
121121
, resultsTemplateName = null

0 commit comments

Comments
 (0)