-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy path_b2cVerify.js
More file actions
75 lines (54 loc) · 2.11 KB
/
_b2cVerify.js
File metadata and controls
75 lines (54 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
'use strict';
// Initialize constants
const config = require('config');
// Include the helper library to retrieve the environment details
const b2cAuthenticate = require('./_b2cAuthClientCredentials');
const verifySites = require('./_b2cSitesVerify');
const verifyCodeVersion = require('./_b2cCodeVersionVerify');
/**
* @function _b2cVerify
* @description Attempts to validate that the B2C Configuration, sites, and specified
* code version all exist and are valid representations of the specified B2C Commerce environment
*
* @param {Object} environmentDef Represents the already-validated environment details
* @returns {Promise} Returns the verification results for the sites provided via the environmentDef
*/
module.exports = environmentDef => new Promise(async (resolve, reject) => {
// Roll-up the validation results to a single object
const output = {
apiCalls: {
authenticate: {},
verifySites: {},
verifyCodeVersion: {}
},
outputDisplay: {
authenticate: {}
}
};
// Authenticate first
try {
// Audit the authorization token for future rest requests
const authResult = await b2cAuthenticate(environmentDef);
output.apiCalls.authenticate = authResult.apiCalls.authenticate;
output.outputDisplay.authenticate = authResult.outputDisplay;
} catch (e) {
reject(`${config.get('errors.b2c.unableToAuthenticate')}`);
return;
}
// Then verify sites
try {
const verifySitesResult = await verifySites(environmentDef);
output.outputDisplay.verifySites = verifySitesResult.outputDisplay.verifySites;
} catch (e) {
reject(`${config.get('errors.b2c.unableToVerifySites')}`);
return;
}
// Finally verify code version
try {
const verifyCodeVersionResult = await verifyCodeVersion(environmentDef);
output.outputDisplay.verifyCodeVersion = verifyCodeVersionResult.outputDisplay.codeVersionGet;
} catch (e) {
reject(`${config.get('errors.b2c.unableToVerifyCodeVersions')}`);
}
resolve(output);
});