-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy path_b2cCodeVersionVerify.js
More file actions
74 lines (59 loc) · 2.43 KB
/
_b2cCodeVersionVerify.js
File metadata and controls
74 lines (59 loc) · 2.43 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
'use strict';
// Initialize constants
const config = require('config');
// Include local libraries
const common = require('../../lib/cli-api/_common');
// Include B2C Commerce API functions
const b2cAuthenticate = require('../apis/ci/_authenticate');
const codeVersionAPI = require('../apis/ci/code-versions');
/**
* @function _b2cCodeVersionVerify
* @description Attempts to retrieve the B2C Commerce code versions configured for the specified
* environment -- leveraging SFCC-CI's API to do the work.
*
* @param {Object} environmentDef Represents the already-validated environment details to use when performing the actions
* @returns {Promise} Returns a promise containing the codeVersion validation results
*/
module.exports = environmentDef => new Promise(async (resolve, reject) => {
// Roll-up the validation results to a single object
const output = {
apiCalls: {
authenticate: {},
codeVersionGet: {}
},
outputDisplay: {
authenticate: {}
}
};
// Authenticate first
try {
// Audit the authorization token for future rest requests
output.apiCalls.authenticate.authToken = await b2cAuthenticate(environmentDef);
output.outputDisplay.authenticate.authToken = output.apiCalls.authenticate.authToken;
} catch (e) {
reject(`${config.get('errors.b2c.unableToAuthenticate')}`);
return;
}
// Then activate the code version
try {
// Get the code-version details
const getDetailResults = await codeVersionAPI.getDetail(
environmentDef, output.apiCalls.authenticate.authToken);
// Build out the code-version summary
output.apiCalls.codeVersionGet.getDetailResults = common.createCodeVersionSummary(
[getDetailResults.data])[0];
// Prepare the data to be displayed in the output
output.outputDisplay.codeVersionGet = [
output.apiCalls.codeVersionGet.getDetailResults.id,
output.apiCalls.codeVersionGet.getDetailResults.active,
output.apiCalls.codeVersionGet.getDetailResults.lastModificationTime,
output.apiCalls.codeVersionGet.getDetailResults.compatibilityMode,
output.apiCalls.codeVersionGet.getDetailResults.webDavUrl
];
} catch (e) {
console.log(e);
reject(`${config.get('errors.b2c.unableToRetrieveCodeVersion')}`);
} finally {
resolve(output);
}
});