Skip to content

Commit dd5ddbc

Browse files
add Admin 4 step 4 and update text (#37)
* add Admin 4 step 4 and update text
1 parent 37e1818 commit dd5ddbc

File tree

67 files changed

+349
-187
lines changed

Some content is hidden

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

67 files changed

+349
-187
lines changed

README.md

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

33
### GitHub repo: [code-examples-node](./README.md)
44

5-
This GitHub repo includes code examples for the DocuSign eSignature REST API, Rooms API, Click API, and Monitor API. To switch between API code examples, modify the `examplesApi` setting in the appsettings.json file. Change the value of either `isESignatureApi`, `isRoomsApi`, `isClickApi`, or `isMonitorApi` to `true` to use the corresponding API. Set only one API type to `true` and set the remaining to `false`.
5+
This GitHub repo includes code examples for the DocuSign Admin API, Click API, eSignature REST API, Monitor API, and Rooms API. To switch between API code examples, modify the `examplesApi` setting in the appsettings.json file. Set only one API type to `true` and set the remaining to `false`.
66

77
If none of the API types are set to `true`, the DocuSign eSignature REST API code examples will be shown. If multiple API types are set to `true`, only the first will be shown.
88

@@ -43,11 +43,11 @@ For information about the scopes used for obtaining authorization to use the Mon
4343
For a list of code examples that use the Monitor API, select the Node.js tab under [Examples and languages](https://developers.docusign.com/docs/monitor-api/how-to/code-launchers/#examples-and-languages) on the DocuSign Developer Center.
4444

4545
## Admin API
46-
**Note:** To use the Admin API, you must [create an organization](https://support.docusign.com/en/guides/org-admin-guide-create-org) in your DocuSign account. Also, to run the DocuSign CLM code example, [CLM must be enabled for your organization](https://support.docusign.com/en/articles/DocuSign-and-SpringCM).
46+
**Note:** To use the Admin API, you must [create an organization](https://support.docusign.com/en/guides/org-admin-guide-create-org) in your DocuSign developer account. Also, to run the DocuSign CLM code example, [CLM must be enabled for your organization](https://support.docusign.com/en/articles/DocuSign-and-SpringCM).
4747

48-
For information about the scopes used for obtaining authorization to use the Admin API, see the [scopes section](https://developers.docusign.com/docs/admin-api/admin101/auth/).
48+
For more information about the scopes used for obtaining authorization to use the Admin API, see the [scopes section](https://developers.docusign.com/docs/admin-api/admin101/auth/).
4949

50-
For a list of code examples that use the Monitor API, select the Node.js tab under [Examples and languages](hhttps://developers.docusign.com/docs/admin-api/how-to/code-launchers/#examples-and-languages) on the DocuSign Developer Center.
50+
For a list of code examples that use the Admin API, select the Node.js tab under [Examples and languages](https://developers.docusign.com/docs/admin-api/how-to/code-launchers/#examples-and-languages) on the DocuSign Developer Center.
5151

5252
## Installation
5353

index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@ const csrf = require('csurf'); // https://www.npmjs.com/package/csurf
2121

2222
const eg001 = require('./eg001EmbeddedSigning');
2323

24-
const {
25-
eg002, eg003, eg004, eg005, eg006, eg007, eg008,
24+
const {
25+
eg002, eg003, eg004, eg005, eg006, eg007, eg008,
2626
eg009, eg010, eg011, eg012, eg013, eg014, eg015,
2727
eg016, eg017, eg018, eg019, eg020, eg021, eg022,
2828
eg023, eg024, eg025, eg026, eg027, eg028, eg029,
2929
eg030, eg031, eg032, eg033, eg034, eg035,
3030
} = require("./lib/eSignature/controllers");
3131

32-
const {
32+
const {
3333
eg001click, eg002click, eg003click,
3434
eg004click, eg005click,
3535
} = require("./lib/click/controllers");
3636

37-
const {
37+
const {
3838
eg001rooms, eg002rooms, eg003rooms,
3939
eg004rooms, eg005rooms, eg006rooms,
4040
eg007rooms, eg008rooms, eg009rooms,
@@ -143,6 +143,7 @@ if (dsConfig.examplesApi.isRoomsApi) {
143143
.post('/eg003', eg003admin.createController)
144144
.get('/eg004', eg004admin.getController)
145145
.post('/eg004', eg004admin.createController)
146+
.get('/eg004status', eg004admin.checkStatus)
146147
.get('/eg005', eg005admin.getController)
147148
.post('/eg005', eg005admin.createController)
148149
} else {

lib/admin/controllers/eg001CreateUser.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ eg001CreateUser.createController = async(req, res) => {
6464
res.render('pages/example_done', {
6565
title: "Create a new active eSignature user",
6666
h1: "Create a new active eSignature user",
67-
message: `Results from Users::createUser method:`,
67+
message: "Results from eSignUserManagement:createUser method:",
6868
json: JSON.stringify(results)
6969
});
7070
}
@@ -91,14 +91,16 @@ eg001CreateUser.getController = async (req, res) => {
9191
};
9292

9393
const { profiles, groups } = await getPermissionProfilesAndGroups(args);
94+
95+
sourceFile = (path.basename(__filename))[5].toLowerCase() + (path.basename(__filename)).substr(6);
9496
res.render('pages/admin-examples/eg001CreateUser', {
9597
eg: eg,
9698
csrfToken: req.csrfToken(),
9799
title: "Creating a new user",
98100
permissionProfiles: profiles.permissionProfiles,
99101
groups: groups.groups,
100-
sourceFile: path.basename(__filename),
101-
sourceUrl: dsConfig.githubExampleUrl + "admin/" + path.basename(__filename),
102+
sourceFile: sourceFile,
103+
sourceUrl: dsConfig.githubExampleUrl + "admin/examples/" + sourceFile,
102104
documentation: dsConfig.documentation + eg,
103105
showDoc: dsConfig.documentation
104106
});

lib/admin/controllers/eg002CreateCLMESignUser.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ eg002CreateCLMESignUser.getController = async (req, res) => {
9292
let productPermissionProfiles = await getProductPermissionProfiles(args);
9393
let dsGroups = await getDSAdminGroups(args);
9494

95+
sourceFile = (path.basename(__filename))[5].toLowerCase() + (path.basename(__filename)).substr(6);
9596
res.render("pages/admin-examples/eg002CreateCLMESignUser", {
9697
eg: eg, csrfToken: req.csrfToken(),
9798
title: "Create active user for CLM and eSignature",
@@ -100,8 +101,8 @@ eg002CreateCLMESignUser.getController = async (req, res) => {
100101
dsGroups,
101102
clmProductId: productPermissionProfiles.clmProductId,
102103
eSignProductId: productPermissionProfiles.eSignProductId,
103-
sourceFile: path.basename(__filename),
104-
sourceUrl: dsConfig.githubExampleUrl + path.basename(__filename),
104+
sourceFile: sourceFile,
105+
sourceUrl: dsConfig.githubExampleUrl + 'admin/examples/' + sourceFile,
105106
documentation: dsConfig.documentation + eg,
106107
showDoc: dsConfig.documentation
107108
});

lib/admin/controllers/eg003BulkExportUserData.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ eg003BulkExportUserData.createController = async(req, res) => {
5757
res.render('pages/example_done', {
5858
title: "Bulk-export user data",
5959
h1: "Bulk-export user data",
60-
message: `Results from UserExport::getUserListExport method: `,
60+
message: `User data exported to ${args.filePath}. </br> Results from UserExport:getUserListExport method:`,
6161
json: JSON.stringify(results)
6262
});
6363
}
@@ -76,12 +76,13 @@ eg003BulkExportUserData.getController = async (req, res) => {
7676
try {
7777
await getOrganizationId(req);
7878

79+
sourceFile = (path.basename(__filename))[5].toLowerCase() + (path.basename(__filename)).substr(6);
7980
res.render('pages/admin-examples/eg003BulkExportUserData', {
8081
eg: eg,
8182
csrfToken: req.csrfToken(),
8283
title: "Create bulk-export user data request",
83-
sourceFile: path.basename(__filename),
84-
sourceUrl: dsConfig.githubExampleUrl + "admin/" + path.basename(__filename),
84+
sourceFile: sourceFile,
85+
sourceUrl: dsConfig.githubExampleUrl + "admin/examples/" + sourceFile,
8586
documentation: dsConfig.documentation + eg,
8687
showDoc: dsConfig.documentation
8788
});

lib/admin/controllers/eg004ImportUser.js

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @author DocuSign
55
*/
66
const path = require('path');
7-
const { createBulkImportRequest } = require('../examples/importUser');
7+
const { createBulkImportRequest, checkStatus } = require('../examples/importUser');
88
const dsConfig = require('../../../config/index.js').config;
99
const { getOrganizationId } = require("../getOrganizationId.js");
1010

@@ -43,7 +43,9 @@ eg004ImportUser.createController = async(req, res) => {
4343
let results = null;
4444

4545
try {
46-
results = await createBulkImportRequest(args)
46+
results = await createBulkImportRequest(args);
47+
req.session.importId = results.id;
48+
console.log(req.session.importId);
4749
} catch (error) {
4850
// we can pull the DocuSign error code and message from the response body
4951
const errorBody = error && error.response && error.response.body;
@@ -58,12 +60,63 @@ eg004ImportUser.createController = async(req, res) => {
5860
res.render('pages/example_done', {
5961
title: "Add users via bulk import",
6062
h1: "Add users via bulk import",
63+
checkStatus: true,
6164
message: `Results from UserImport:addBulkUserImport method:`,
6265
json: JSON.stringify(results)
6366
});
6467
}
6568
}
6669

70+
/**
71+
* Add user via bulk import
72+
* @param {object} req Request obj
73+
* @param {object} res Response obj
74+
*/
75+
eg004ImportUser.checkStatus = async(req, res) => {
76+
// Step 1. Check the token
77+
// At this point we should have a good token. But we
78+
// double-check here to enable a better UX to the user.
79+
const tokenOK = req.dsAuth.checkToken(minimumBufferMin);
80+
if (!tokenOK) {
81+
req.flash('info', 'Sorry, you need to re-authenticate.');
82+
// Save the current operation so it will be resumed after authentication
83+
req.dsAuth.setEg(req, eg);
84+
res.redirect(mustAuthenticate);
85+
}
86+
87+
const args = {
88+
accessToken: req.user.accessToken,
89+
accountId: req.session.accountId,
90+
importId: req.session.importId,
91+
organizationId: req.session.organizationId,
92+
basePath: dsConfig.adminAPIUrl
93+
};
94+
95+
let results = null;
96+
97+
try {
98+
results = await checkStatus(args)
99+
} catch (error) {
100+
// we can pull the DocuSign error code and message from the response body
101+
const errorBody = error && error.response && error.response.body;
102+
const errorCode = errorBody && errorBody.errorCode;
103+
const errorMessage = errorBody && errorBody.message;
104+
105+
// In production, may want to provide customized error messages and
106+
// remediation advice to the user.
107+
res.render('pages/error', { err: error, errorCode, errorMessage });
108+
}
109+
if (results) {
110+
res.render('pages/admin-examples/eg004CheckStatus', {
111+
title: "Add users via bulk import",
112+
h1: "Add users via bulk import",
113+
status: results.status,
114+
message: "Results from UserImport:getBulkUserImportRequest method:",
115+
json: JSON.stringify(results)
116+
});
117+
}
118+
}
119+
67120
/**
68121
* Form page for this application
69122
*/
@@ -77,12 +130,13 @@ eg004ImportUser.getController = async (req, res) => {
77130
try {
78131
await getOrganizationId(req);
79132

133+
sourceFile = (path.basename(__filename))[5].toLowerCase() + (path.basename(__filename)).substr(6);
80134
res.render('pages/admin-examples/eg004ImportUser', {
81135
eg: eg,
82136
csrfToken: req.csrfToken(),
83137
title: "Add user via bulk import",
84-
sourceFile: path.basename(__filename),
85-
sourceUrl: dsConfig.githubExampleUrl + "admin/" + path.basename(__filename),
138+
sourceFile: sourceFile,
139+
sourceUrl: dsConfig.githubExampleUrl + "admin/examples/" + sourceFile,
86140
documentation: dsConfig.documentation + eg,
87141
showDoc: dsConfig.documentation
88142
});

lib/admin/controllers/eg005AuditUsers.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ eg005AuditUsers.createController = async (req, res) => {
4545
res.render("pages/example_done", {
4646
title: "Audit users",
4747
h1: "Audit users",
48-
message: "Results from Users::getUserProfiles method:",
48+
message: "Results from eSignUserManagement:getUserProfiles method:",
4949
json: JSON.stringify(results).replace(/'/g, '')
5050
});
5151
}
@@ -71,11 +71,12 @@ eg005AuditUsers.getController = async (req, res) => {
7171
let tokenOK = req.dsAuth.checkToken();
7272
if (tokenOK) {
7373
try {
74+
sourceFile = (path.basename(__filename))[5].toLowerCase() + (path.basename(__filename)).substr(6);
7475
res.render("pages/admin-examples/eg005AuditUsers", {
7576
eg: eg, csrfToken: req.csrfToken(),
7677
title: "Audit Users",
77-
sourceFile: path.basename(__filename),
78-
sourceUrl: dsConfig.githubExampleUrl + path.basename(__filename),
78+
sourceFile: sourceFile,
79+
sourceUrl: dsConfig.githubExampleUrl + 'admin/examples/' + sourceFile,
7980
documentation: dsConfig.documentation + eg,
8081
showDoc: dsConfig.documentation
8182
});

lib/admin/examples/importUser.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,16 @@ const createBulkImportRequest = async(args) => {
2121
// Step 3 end
2222
}
2323

24-
module.exports = { createBulkImportRequest };
24+
const checkStatus = async(args) => {
25+
const apiClient = new docusign.ApiClient();
26+
apiClient.setBasePath(args.basePath);
27+
apiClient.addDefaultHeader("Authorization", "Bearer " + args.accessToken);
28+
29+
const bulkImportsApi = new docusign.BulkImportsApi(apiClient);
30+
31+
// Step 4 start
32+
return await bulkImportsApi.getBulkUserImportRequest(args.organizationId, args.importId);
33+
// Step 4 end
34+
}
35+
36+
module.exports = { createBulkImportRequest, checkStatus};

lib/click/controllers/eg001CreateClickwrap.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,12 @@ eg001CreateClickwrap.getController = async (req, res) => {
8181
// since they have not yet entered any information into the form
8282
const tokenOK = req.dsAuth.checkToken();
8383
if (tokenOK){
84+
sourceFile = (path.basename(__filename))[5].toLowerCase() + (path.basename(__filename)).substr(6);
8485
res.render("pages/click-examples/eg001CreateClickwrap", {
8586
eg: eg, csrfToken: req.csrfToken(),
8687
title: "Creating a new clickwrap",
87-
sourceFile: path.basename(__filename),
88-
sourceUrl: dsConfig.githubExampleUrl + path.basename(__filename),
88+
sourceFile: sourceFile,
89+
sourceUrl: dsConfig.githubExampleUrl + 'click/examples/' + sourceFile,
8990
documentation: dsConfig.documentation + eg,
9091
showDoc: dsConfig.documentation
9192
});

lib/click/controllers/eg002ActivateClickwrap.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,13 @@ eg002ActivateClickwrap.getController = async (req, res) => {
7777
// since they have not yet entered any information into the form
7878
const tokenOK = req.dsAuth.checkToken();
7979
if (tokenOK){
80+
sourceFile = (path.basename(__filename))[5].toLowerCase() + (path.basename(__filename)).substr(6);
8081
res.render("pages/click-examples/eg002ActivateClickwrap", {
8182
eg: eg, csrfToken: req.csrfToken(),
8283
title: "Activating a new clickwrap",
8384
clickwrapOk: req.session.hasOwnProperty("clickwrapId"),
84-
sourceFile: path.basename(__filename),
85-
sourceUrl: dsConfig.githubExampleUrl + path.basename(__filename),
85+
sourceFile: sourceFile,
86+
sourceUrl: dsConfig.githubExampleUrl + 'click/examples/' + sourceFile,
8687
documentation: dsConfig.documentation + eg,
8788
showDoc: dsConfig.documentation
8889
});

0 commit comments

Comments
 (0)