Skip to content

Commit 8e98bbc

Browse files
RomanBachaloSigmaSoftwarepaigesrossipmacklemeihDS
authored
Set document visibility code example (#88)
* added example * update page * fixes * fixes * add example * update title * fixes * removing numbering and reorganizing homepage * change description to be consistent with c# example * fixed number ex 39 and made esignature default * removed Host name field on code example page * signer emails * fix hostname issue * update comment for clarity * reordering embed the docusign ui example Co-authored-by: Paige Rossi <paige.rossi@docusign.com> Co-authored-by: Patrick Mackle <pimackle@ucdavis.edu> Co-authored-by: meihDS <70775251+meihDS@users.noreply.github.com>
1 parent aa51201 commit 8e98bbc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+957
-208
lines changed

config/examplesApi.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"examplesApi":{"isESignatureApi":true,"isRoomsApi":false,"isClickApi":false,"isMonitorApi":false,"isAdminApi":false}}

index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const {
2828
eg016, eg017, eg018, eg019, eg020, eg022, eg023,
2929
eg024, eg025, eg026, eg027, eg028, eg029, eg030,
3030
eg031, eg032, eg033, eg034, eg035, eg036, eg037,
31-
eg038
31+
eg038, eg039, eg040
3232
} = require("./lib/eSignature/controllers");
3333

3434
const {
@@ -240,6 +240,10 @@ if (examplesApi.examplesApi.isRoomsApi) {
240240
.post('/eg037', eg037.createController)
241241
.get('/eg038', eg038.getController)
242242
.post('/eg038', eg038.createController)
243+
.get('/eg039', eg039.getController)
244+
.post('/eg039', eg039.createController)
245+
.get('/eg040', eg040.getController)
246+
.post('/eg040', eg040.createController)
243247
}
244248

245249
function dsLoginCB1(req, res, next) { req.dsAuthCodeGrant.oauth_callback1(req, res, next) }
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/**
2+
* @file
3+
* Example 039: Send an envelope to an In Person Signer
4+
* @author DocuSign
5+
*/
6+
7+
const path = require('path');
8+
const { sendEnvelopeForInPersonSigning } = require('../examples/signingInPerson');
9+
const validator = require('validator');
10+
const dsConfig = require('../../../config/index.js').config;
11+
const { getUserInfo } = require('../getData');
12+
13+
const eg039SigningInPerson = exports;
14+
const eg = 'eg039'; // This example reference.
15+
const mustAuthenticate = '/ds/mustAuthenticate';
16+
const minimumBufferMin = 3;
17+
const demoDocsPath = path.resolve(__dirname, '../../../demo_documents');
18+
const pdf1File = 'World_Wide_Corp_lorem.pdf';
19+
const dsReturnUrl = dsConfig.appUrl + '/ds-return';
20+
const dsPingUrl = dsConfig.appUrl + '/'; // Url that will be pinged by the DocuSign signing via Ajax
21+
22+
/**
23+
* Create the envelope, the embedded signing, and then redirect to the DocuSign signing
24+
* @param {object} req Request obj
25+
* @param {object} res Response obj
26+
*/
27+
eg039SigningInPerson.createController = async (req, res) => {
28+
// Step 1. Check the token
29+
// At this point we should have a good token. But we
30+
// double-check here to enable a better UX to the user.
31+
const isTokenOK = req.dsAuth.checkToken(minimumBufferMin);
32+
if (!isTokenOK) {
33+
req.flash('info', 'Sorry, you need to re-authenticate.');
34+
// Save the current operation so it will be resumed after authentication
35+
req.dsAuth.setEg(req, eg);
36+
return res.redirect(mustAuthenticate);
37+
}
38+
39+
// Step 2. Get the email and name of the current user
40+
const user = await getUserInfo(req.user.accessToken, req.session.basePath);
41+
const email = user.email;
42+
const hostName = user.name;
43+
44+
// Step 3. Call the worker method
45+
const { body } = req;
46+
const envelopeArgs = {
47+
hostEmail: email,
48+
hostName: hostName,
49+
signerName: validator.escape(body.signerName),
50+
dsReturnUrl: dsReturnUrl,
51+
dsPingUrl: dsPingUrl,
52+
docFile: path.resolve(demoDocsPath, pdf1File)
53+
};
54+
const args = {
55+
accessToken: req.user.accessToken,
56+
basePath: req.session.basePath,
57+
accountId: req.session.accountId,
58+
envelopeArgs: envelopeArgs
59+
};
60+
let results = null;
61+
62+
try {
63+
results = await sendEnvelopeForInPersonSigning(args);
64+
}
65+
catch (error) {
66+
const errorBody = error && error.response && error.response.body;
67+
// we can pull the DocuSign error code and message from the response body
68+
const errorCode = error && error.status || errorBody && errorBody.errorCode;
69+
const errorMessage = errorBody && errorBody.error_description || errorBody.message;
70+
// In production, may want to provide customized error messages and
71+
// remediation advice to the user.
72+
res.render('pages/error', {err: error, errorCode, errorMessage});
73+
}
74+
if (results) {
75+
// Redirect the user to the embedded signing
76+
// Don't use an iFrame!
77+
// State can be stored/recovered using the framework's session or a
78+
// query parameter on the returnUrl (see the makeRecipientViewRequest method)
79+
res.redirect(results.redirectUrl);
80+
}
81+
}
82+
83+
/**
84+
* Form page for this application
85+
*/
86+
eg039SigningInPerson.getController = (req, res) => {
87+
// Check that the authentication token is ok with a long buffer time.
88+
// If needed, now is the best time to ask the user to authenticate
89+
// since they have not yet entered any information into the form.
90+
const isTokenOK = req.dsAuth.checkToken();
91+
if (!isTokenOK) {
92+
// Save the current operation so it will be resumed after authentication
93+
req.dsAuth.setEg(req, eg);
94+
return res.redirect(mustAuthenticate);
95+
}
96+
97+
const sourceFile = (path.basename(__filename))[5].toLowerCase() + (path.basename(__filename)).substr(6);
98+
res.render('pages/examples/eg039SigningInPerson', {
99+
eg: eg, csrfToken: req.csrfToken(),
100+
title: "Send an envelope to an In Person Signer",
101+
sourceFile: path.basename(__filename),
102+
sourceUrl: dsConfig.githubExampleUrl + 'eSignature/examples/' + sourceFile,
103+
documentation: dsConfig.documentation + eg,
104+
showDoc: dsConfig.documentation
105+
});
106+
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/**
2+
* @file
3+
* Example 040: Set document visibility for envelope recipients
4+
* @author DocuSign
5+
*/
6+
7+
const path = require('path');
8+
const validator = require('validator');
9+
const dsConfig = require('../../../config/index.js').config;
10+
const { sendEnvelope } = require('../examples/setDocumentVisibility');
11+
12+
const eg040SetDocumentVisibility = exports;
13+
const eg = 'eg040'; // This example reference.
14+
const mustAuthenticate = '/ds/mustAuthenticate';
15+
const minimumBufferMin = 3;
16+
const demoDocsPath = path.resolve(__dirname, '../../../demo_documents');
17+
const doc2File = 'World_Wide_Corp_Battle_Plan_Trafalgar.docx';
18+
const doc3File = 'World_Wide_Corp_lorem.pdf';
19+
20+
/**
21+
* Create the envelope and set document visibility for envelope recipients
22+
* @param {object} req Request obj
23+
* @param {object} res Response obj
24+
*/
25+
eg040SetDocumentVisibility.createController = async (req, res) => {
26+
// Step 1. Check the token
27+
// At this point we should have a good token. But we
28+
// double-check here to enable a better UX to the user.
29+
const isTokenOK = req.dsAuth.checkToken(minimumBufferMin);
30+
if (!isTokenOK) {
31+
req.flash('info', 'Sorry, you need to re-authenticate.');
32+
// Save the current operation so it will be resumed after authentication
33+
req.dsAuth.setEg(req, eg);
34+
return res.redirect(mustAuthenticate);
35+
}
36+
37+
// Step 2. Call the worker method
38+
const { body } = req;
39+
const envelopeArgs = {
40+
signer1Email: validator.escape(body.signer1Email),
41+
signer1Name: validator.escape(body.signer1Name),
42+
signer2Email: validator.escape(body.signer2Email),
43+
signer2Name: validator.escape(body.signer2Name),
44+
ccEmail: validator.escape(body.ccEmail),
45+
ccName: validator.escape(body.ccName),
46+
status: "sent",
47+
doc2File: path.resolve(demoDocsPath, doc2File),
48+
doc3File: path.resolve(demoDocsPath, doc3File)
49+
};
50+
const args = {
51+
accessToken: req.user.accessToken,
52+
basePath: req.session.basePath,
53+
accountId: req.session.accountId,
54+
envelopeArgs: envelopeArgs
55+
};
56+
let results = null;
57+
58+
try {
59+
results = await sendEnvelope(args);
60+
} catch (error) {
61+
const errorBody = error && error.response && error.response.body;
62+
// we can pull the DocuSign error code and message from the response body
63+
const errorCode = errorBody && errorBody.errorCode;
64+
const errorMessage = errorBody && errorBody.message;
65+
66+
let errorData = { err: error, errorCode, errorMessage }
67+
68+
if (errorCode && errorCode === "ACCOUNT_LACKS_PERMISSIONS") {
69+
errorData.errorInfo = `<p>See <a href="https://developers.docusign.com/docs/esign-rest-api/how-to/set-document-visibility/">How to set document visibility for envelope recipients</a> in
70+
the DocuSign Developer Center for instructions on how to
71+
enable document visibility in your developer account.</p>`
72+
}
73+
// In production, may want to provide customized error messages and
74+
// remediation advice to the user.
75+
res.render('pages/error', errorData);
76+
}
77+
if (results) {
78+
res.render('pages/example_done', {
79+
title: "Set document visibility for envelope recipients",
80+
h1: "Set document visibility for envelope recipients",
81+
message: `The envelope has been created and sent!<br/>Envelope ID ${results.envelopeId}.`
82+
});
83+
}
84+
}
85+
86+
/**
87+
* Form page for this application
88+
*/
89+
eg040SetDocumentVisibility.getController = (req, res) => {
90+
/**
91+
* Check that the authentication token is ok with a long buffer time.
92+
* If needed, now is the best time to ask the user to authenticate
93+
* since they have not yet entered any information into the form.
94+
*/
95+
const isTokenOK = req.dsAuth.checkToken();
96+
if (!isTokenOK) {
97+
// Save the current operation so it will be resumed after authentication
98+
req.dsAuth.setEg(req, eg);
99+
return res.redirect(mustAuthenticate);
100+
}
101+
102+
const sourceFile = (path.basename(__filename))[5].toLowerCase() + (path.basename(__filename)).substr(6);
103+
res.render('pages/examples/eg040SetDocumentVisibility', {
104+
eg: eg, csrfToken: req.csrfToken(),
105+
title: "Set document visibility for envelope recipients",
106+
sourceFile: sourceFile,
107+
sourceUrl: dsConfig.githubExampleUrl + 'eSignature/examples/' + sourceFile,
108+
documentation: dsConfig.documentation + eg,
109+
showDoc: dsConfig.documentation
110+
});
111+
}

lib/eSignature/controllers/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ module.exports.eg035 = require('./eg035ScheduledSending');
3535
module.exports.eg036 = require('./eg036DelayedRouting');
3636
module.exports.eg037 = require('./eg037SmsDelivery');
3737
module.exports.eg038 = require('./eg038ResponsiveSigning');
38+
module.exports.eg039 = require('./eg039SigningInPerson')
39+
module.exports.eg040 = require('./eg040SetDocumentVisibility');

0 commit comments

Comments
 (0)