Skip to content

Commit b10bf01

Browse files
committed
2 parents 1d820e6 + aa5da5c commit b10bf01

File tree

150 files changed

+3307
-4185
lines changed

Some content is hidden

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

150 files changed

+3307
-4185
lines changed

config/appsettings.example.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,10 @@
2828
"roomsApiUrl": "https://demo.rooms.docusign.com",
2929
"clickAPIUrl": "https://demo.docusign.net/clickapi",
3030
"adminAPIUrl": "https://api-d.docusign.net/management",
31-
"monitorApiUrl": "https://lens-d.docusign.net"
31+
"monitorApiUrl": "https://lens-d.docusign.net",
32+
"eSignManifestUrl": "https://raw.githubusercontent.com/docusign/code-examples-csharp/master/manifest/eSignatureManifest.json",
33+
"clickManifestUrl": "https://raw.githubusercontent.com/docusign/code-examples-csharp/master/manifest/ClickManifest.json",
34+
"roomsManifestUrl": "https://raw.githubusercontent.com/docusign/code-examples-csharp/master/manifest/RoomsManifest.json",
35+
"adminManifestUrl": "https://raw.githubusercontent.com/docusign/code-examples-csharp/master/manifest/AdminManifest.json",
36+
"monitorManifestUrl": "https://raw.githubusercontent.com/docusign/code-examples-csharp/master/manifest/MonitorManifest.json"
3237
}

index.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const helmet = require('helmet'); // https://expressjs.com/en/advanced/best-prac
1919
const moment = require('moment');
2020
const csrf = require('csurf'); // https://www.npmjs.com/package/csurf
2121
const examplesApi = require('./config/examplesAPI.json');
22+
const { getManifest } = require('./lib/manifestService')
2223

2324
const eg001 = require('./lib/eSignature/controllers/eg001EmbeddedSigning');
2425

@@ -98,6 +99,35 @@ let app = express()
9899
}
99100
next()
100101
})
102+
.use(async (req, res, next) => {
103+
let manifestUrl;
104+
105+
switch(true) {
106+
case examplesApi.examplesApi.isRoomsApi:
107+
manifestUrl = dsConfig.roomsManifestUrl;
108+
break;
109+
110+
case examplesApi.examplesApi.isClickApi:
111+
manifestUrl = dsConfig.clickManifestUrl;
112+
break;
113+
114+
case examplesApi.examplesApi.isMonitorApi:
115+
manifestUrl = dsConfig.monitorManifestUrl;
116+
break;
117+
118+
case examplesApi.examplesApi.isAdminApi:
119+
manifestUrl = dsConfig.adminManifestUrl;
120+
break;
121+
122+
default:
123+
manifestUrl = dsConfig.eSignManifestUrl;
124+
}
125+
126+
const manifest = await getManifest(manifestUrl);
127+
res.locals.manifest = manifest;
128+
129+
next();
130+
})
101131
// Routes
102132
.get('/', commonControllers.indexController)
103133
.get('/ds/choose_api', commonControllers.chooseApi)

lib/admin/controllers/eg001CreateUser.js

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66

77
const path = require('path');
88
const { createUser, getPermissionProfilesAndGroups } = require('../examples/createUser');
9+
const { getExampleByNumber } = require("../../manifestService");
910
const dsConfig = require('../../../config/index.js').config;
1011
const validator = require('validator');
1112
const { getOrganizationId } = require("../getOrganizationId.js");
1213

1314
const eg001CreateUser = exports;
14-
const eg = 'eg001' // This example reference.;
15+
const exampleNumber = 1;
16+
const eg = `eg00${exampleNumber}`; // This example reference.
1517
const mustAuthenticate = '/ds/mustAuthenticate';
1618
const minimumBufferMin = 3;
1719

@@ -24,12 +26,12 @@ eg001CreateUser.createController = async(req, res) => {
2426
// Step 1. Check the token
2527
// At this point we should have a good token. But we
2628
// double-check here to enable a better UX to the user.
27-
const tokenOK = req.dsAuth.checkToken(minimumBufferMin);
28-
if (!tokenOK) {
29+
const isTokenOK = req.dsAuth.checkToken(minimumBufferMin);
30+
if (!isTokenOK) {
2931
req.flash('info', 'Sorry, you need to re-authenticate.');
3032
// Save the current operation so it will be resumed after authentication
3133
req.dsAuth.setEg(req, eg);
32-
res.redirect(mustAuthenticate);
34+
return res.redirect(mustAuthenticate);
3335
}
3436

3537
const { body } = req;
@@ -61,10 +63,10 @@ eg001CreateUser.createController = async(req, res) => {
6163
res.render('pages/error', { err: error, errorCode, errorMessage });
6264
}
6365
if (results) {
66+
const example = getExampleByNumber(res.locals.manifest, exampleNumber);
6467
res.render('pages/example_done', {
65-
title: "Create a new active eSignature user",
66-
h1: "Create a new active eSignature user",
67-
message: "Results from eSignUserManagement:createUser method:",
68+
title: example.ExampleName,
69+
message: example.ResultsPageText,
6870
json: JSON.stringify(results)
6971
});
7072
}
@@ -78,46 +80,45 @@ eg001CreateUser.getController = async (req, res) => {
7880
// If needed, now is the best time to ask the user to authenticate
7981
// since they have not yet entered any information into the form.
8082

81-
let tokenOK = req.dsAuth.checkToken();
82-
if (tokenOK) {
83-
try {
84-
await getOrganizationId(req);
83+
let isTokenOK = req.dsAuth.checkToken();
84+
if (!isTokenOK) {
85+
// Save the current operation so it will be resumed after authentication
86+
req.dsAuth.setEg(req, eg);
87+
return res.redirect(mustAuthenticate);
88+
}
8589

86-
const args = {
87-
accessToken: req.user.accessToken,
88-
accountId: req.session.accountId,
89-
basePath: req.session.basePath,
90-
organizationId: req.session.organizationId
91-
};
90+
try {
91+
await getOrganizationId(req);
9292

93-
const { profiles, groups } = await getPermissionProfilesAndGroups(args);
93+
const args = {
94+
accessToken: req.user.accessToken,
95+
accountId: req.session.accountId,
96+
basePath: req.session.basePath,
97+
organizationId: req.session.organizationId
98+
};
9499

95-
sourceFile = (path.basename(__filename))[5].toLowerCase() + (path.basename(__filename)).substr(6);
96-
res.render('pages/admin-examples/eg001CreateUser', {
97-
eg: eg,
98-
csrfToken: req.csrfToken(),
99-
title: "Creating a new user",
100-
permissionProfiles: profiles.permissionProfiles,
101-
groups: groups.groups,
102-
sourceFile: sourceFile,
103-
sourceUrl: dsConfig.githubExampleUrl + "admin/examples/" + sourceFile,
104-
documentation: dsConfig.documentation + eg,
105-
showDoc: dsConfig.documentation
106-
});
107-
}
108-
catch (error) {
109-
const errorBody = error && error.response && error.response.body;
110-
const errorCode = errorBody && errorBody.errorCode;
111-
const errorMessage = errorBody && errorBody.message;
100+
const { profiles, groups } = await getPermissionProfilesAndGroups(args);
112101

113-
// In production, may want to provide customized error messages and
114-
// remediation advice to the user.
115-
res.render('pages/error', { err: error, errorCode, errorMessage });
116-
}
102+
const example = getExampleByNumber(res.locals.manifest, exampleNumber);
103+
const sourceFile = (path.basename(__filename))[5].toLowerCase() + (path.basename(__filename)).substr(6);
104+
res.render('pages/admin-examples/eg001CreateUser', {
105+
eg: eg,
106+
csrfToken: req.csrfToken(),
107+
example: example,
108+
permissionProfiles: profiles.permissionProfiles,
109+
groups: groups.groups,
110+
sourceFile: sourceFile,
111+
sourceUrl: dsConfig.githubExampleUrl + "admin/examples/" + sourceFile,
112+
documentation: dsConfig.documentation + eg,
113+
showDoc: dsConfig.documentation
114+
});
115+
} catch (error) {
116+
const errorBody = error && error.response && error.response.body;
117+
const errorCode = errorBody && errorBody.errorCode;
118+
const errorMessage = errorBody && errorBody.message;
117119

118-
} else {
119-
// Save the current operation so it will be resumed after authentication
120-
req.dsAuth.setEg(req, eg);
121-
res.redirect(mustAuthenticate);
120+
// In production, may want to provide customized error messages and
121+
// remediation advice to the user.
122+
res.render('pages/error', { err: error, errorCode, errorMessage });
122123
}
123124
}

lib/admin/controllers/eg002CreateCLMESignUser.js

Lines changed: 50 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66

77
const path = require('path')
88
const { createCLMESignUser, getProductPermissionProfiles, getDSAdminGroups } = require('../examples/createCLMESignUser');
9+
const { getExampleByNumber } = require("../../manifestService");
910
const dsConfig = require('../../../config/index.js').config;
1011
const validator = require('validator');
1112
const { getOrganizationId } = require("../getOrganizationId.js");
1213

1314
const eg002CreateCLMESignUser = exports;
14-
const eg = 'eg002' // This example reference.;
15+
const exampleNumber = 2;
16+
const eg = `eg00${exampleNumber}`; // This example reference.
1517
const mustAuthenticate = '/ds/mustAuthenticate';
1618
const minimumBufferMin = 3;
1719

@@ -23,12 +25,12 @@ const minimumBufferMin = 3;
2325
eg002CreateCLMESignUser.createController = async (req, res) => {
2426
// At this point we should have a good token. But we
2527
// double-check here to enable a better UX to the user.
26-
let tokenOK = req.dsAuth.checkToken(minimumBufferMin);
27-
if (!tokenOK) {
28+
let isTokenOK = req.dsAuth.checkToken(minimumBufferMin);
29+
if (!isTokenOK) {
2830
req.flash("info", "Sorry, you need to re-authenticate.");
2931
// Save the current operation so it will be resumed after authentication
3032
req.dsAuth.setEg(req, eg);
31-
res.redirect(mustAuthenticate);
33+
return res.redirect(mustAuthenticate);
3234
}
3335

3436
let results = null;
@@ -51,8 +53,7 @@ eg002CreateCLMESignUser.createController = async (req, res) => {
5153

5254
try {
5355
results = await createCLMESignUser(args)
54-
}
55-
catch (error) {
56+
} catch (error) {
5657
let errorBody = error && error.response && error.response.body
5758
// we can pull the DocuSign error code and message from the response body
5859
, errorCode = errorBody && errorBody.errorCode
@@ -65,10 +66,10 @@ eg002CreateCLMESignUser.createController = async (req, res) => {
6566
if (results) {
6667
req.session.clmEmail = validator.escape(body.email);
6768

69+
const example = getExampleByNumber(res.locals.manifest, exampleNumber);
6870
res.render("pages/example_done", {
69-
title: "Create active user for CLM and eSignature",
70-
h1: "Create active user for CLM and eSignature",
71-
message: "Results from MultiProductUserManagement:addOrUpdateUser method:",
71+
title: example.ExampleName,
72+
message: example.ResultsPageText,
7273
json: JSON.stringify(results).replace(/'/g, '')
7374
});
7475
}
@@ -81,47 +82,47 @@ eg002CreateCLMESignUser.getController = async (req, res) => {
8182
// Check that the authentication token is ok with a long buffer time.
8283
// If needed, now is the best time to ask the user to authenticate
8384
// since they have not yet entered any information into the form.
84-
let tokenOK = req.dsAuth.checkToken();
85-
if (tokenOK) {
86-
try {
87-
await getOrganizationId(req)
88-
const args = {
89-
accessToken: req.user.accessToken,
90-
accountId: req.session.accountId,
91-
organizationId: req.session.organizationId
92-
};
93-
94-
let productPermissionProfiles = await getProductPermissionProfiles(args);
95-
let dsGroups = await getDSAdminGroups(args);
96-
97-
sourceFile = (path.basename(__filename))[5].toLowerCase() + (path.basename(__filename)).substr(6);
98-
res.render("pages/admin-examples/eg002CreateCLMESignUser", {
99-
eg: eg, csrfToken: req.csrfToken(),
100-
title: "Create active user for CLM and eSignature",
101-
clmPermissionProfiles: productPermissionProfiles.clmPermissionProfiles,
102-
eSignPermissionProfiles: productPermissionProfiles.eSignPermissionProfiles,
103-
dsGroups,
104-
clmProductId: productPermissionProfiles.clmProductId,
105-
eSignProductId: productPermissionProfiles.eSignProductId,
106-
sourceFile: sourceFile,
107-
sourceUrl: dsConfig.githubExampleUrl + 'admin/examples/' + sourceFile,
108-
documentation: dsConfig.documentation + eg,
109-
showDoc: dsConfig.documentation
110-
});
111-
}
112-
catch (error) {
113-
let errorBody = error && error.response && error.response.body
114-
// we can pull the DocuSign error code and message from the response body
115-
, errorCode = errorBody && errorBody.errorCode
116-
, errorMessage = errorBody && errorBody.message
117-
;
118-
// In production, may want to provide customized error messages and
119-
// remediation advice to the user.
120-
res.render("pages/error", { err: error, errorCode: errorCode, errorMessage: errorMessage });
121-
}
122-
} else {
85+
let isTokenOK = req.dsAuth.checkToken();
86+
if (!isTokenOK) {
12387
// Save the current operation so it will be resumed after authentication
12488
req.dsAuth.setEg(req, eg);
125-
res.redirect(mustAuthenticate);
89+
return res.redirect(mustAuthenticate);
90+
}
91+
92+
try {
93+
await getOrganizationId(req)
94+
const args = {
95+
accessToken: req.user.accessToken,
96+
accountId: req.session.accountId,
97+
organizationId: req.session.organizationId
98+
};
99+
100+
let productPermissionProfiles = await getProductPermissionProfiles(args);
101+
let dsGroups = await getDSAdminGroups(args);
102+
103+
const example = getExampleByNumber(res.locals.manifest, exampleNumber);
104+
const sourceFile = (path.basename(__filename))[5].toLowerCase() + (path.basename(__filename)).substr(6);
105+
res.render("pages/admin-examples/eg002CreateCLMESignUser", {
106+
eg: eg, csrfToken: req.csrfToken(),
107+
example: example,
108+
clmPermissionProfiles: productPermissionProfiles.clmPermissionProfiles,
109+
eSignPermissionProfiles: productPermissionProfiles.eSignPermissionProfiles,
110+
dsGroups,
111+
clmProductId: productPermissionProfiles.clmProductId,
112+
eSignProductId: productPermissionProfiles.eSignProductId,
113+
sourceFile: sourceFile,
114+
sourceUrl: dsConfig.githubExampleUrl + 'admin/examples/' + sourceFile,
115+
documentation: dsConfig.documentation + eg,
116+
showDoc: dsConfig.documentation
117+
});
118+
} catch (error) {
119+
let errorBody = error && error.response && error.response.body
120+
// we can pull the DocuSign error code and message from the response body
121+
, errorCode = errorBody && errorBody.errorCode
122+
, errorMessage = errorBody && errorBody.message
123+
;
124+
// In production, may want to provide customized error messages and
125+
// remediation advice to the user.
126+
res.render("pages/error", { err: error, errorCode: errorCode, errorMessage: errorMessage });
126127
}
127128
}

0 commit comments

Comments
 (0)