forked from SalesforceCommerceCloud/b2c-crm-sync
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_b2cAuthClientCredentials.js
More file actions
34 lines (30 loc) · 1.07 KB
/
_b2cAuthClientCredentials.js
File metadata and controls
34 lines (30 loc) · 1.07 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
'use strict';
// Initialize constants
const config = require('config');
// Include B2C Commerce API functions
const b2cAuthenticate = require('../apis/ci/_authenticate');
/**
* @function _b2cAuthClientCredentials
* @description Attempts to authenticate against the B2C Commerce instance -- and returns
* the results of the request via the CLI.
*
* @param {Object} environmentDef Represents the already-validated environment details to
* use when performing the actions
* @returns {Promise} Returns the authentication-attempt results
*/
module.exports = environmentDef => new Promise(async (resolve, reject) => {
// Roll-up the validation results to a single object
const output = {
apiCalls: {
authenticate: {}
},
outputDisplay: {}
};
try {
output.apiCalls.authenticate.authToken = await b2cAuthenticate(environmentDef);
output.outputDisplay.authToken = output.apiCalls.authenticate.authToken;
resolve(output);
} catch (e) {
reject(`${config.get('errors.b2c.unableToAuthenticate')}`);
}
});