-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy path_sfB2CInstanceSetup.js
More file actions
78 lines (63 loc) · 3.35 KB
/
_sfB2CInstanceSetup.js
File metadata and controls
78 lines (63 loc) · 3.35 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
76
77
78
'use strict';
// Include local libraries
const flowAPI = require('../../lib/apis/sfdc/flow');
/**
* @function _sfB2CInstanceSetup
* @description Attempts to create the child B2C Instance records (CustomerLists and Sites)
* from the Salesforce Org by invoking a Flow-based REST API.
*
* @param {Object} environmentDef Represents the environment definition to use during processing
* @param {Object} sfAuth Describes the Salesforce authCredentials to use
*
* @returns {Object} Returns the instance-setup processing results
*/
module.exports = async (environmentDef, sfAuth) => {
// Initialize local variables
let output = {
apiResults: {},
outputDisplay: {},
customerLists: {},
sites: {}
};
// Process the instance setup and return the results
output.apiResults = await flowAPI.b2cInstanceSetup(environmentDef, sfAuth.accessToken);
// Shorthand the data elements
output.data = output.apiResults.data[0];
// Evaluate the output results
if (output.data.outputValues.success === true) {
// Build-out the site and customerList collections (combining the customerList / site results)
output.customerLists = output.data.outputValues.createdB2CCustomerLists.concat(
output.data.outputValues.updatedB2CCustomerLists);
output.sites = output.data.outputValues.createdB2CSites.concat(output.data.outputValues.updatedB2CSites);
// Shorthand the sites and customerlists that were created
let createdB2CCustomerLists = output.data.outputValues.createdB2CCustomerLists.map(thisObj => thisObj.CustomerList_ID__c),
createdB2CSites = output.data.outputValues.createdB2CSites.map(thisObj => thisObj.Name),
updatedB2CCustomerLists = output.data.outputValues.updatedB2CCustomerLists.map(thisObj => thisObj.CustomerList_ID__c),
updatedB2CSites = output.data.outputValues.updatedB2CSites.map(thisObj => thisObj.Name);
// Provide defaults for each of the status variables
if (createdB2CCustomerLists.toString().length === 0) { createdB2CCustomerLists = '---'; }
if (createdB2CSites.toString().length === 0) { createdB2CSites = '---'; }
if (updatedB2CCustomerLists.toString().length === 0) { updatedB2CCustomerLists = '---'; }
if (updatedB2CSites.toString().length === 0) { updatedB2CSites = '---'; }
// Build the output success-display
output.outputDisplay = [
['b2cInstance', environmentDef.b2cInstanceName],
['b2cInstanceId', output.data.outputValues.b2cInstance.Id],
['instanceType', output.data.outputValues.b2cInstance.Instance_Type__c],
['success', output.data.outputValues.success],
['created customerLists', createdB2CCustomerLists.toString()],
['created sites', createdB2CSites.toString()],
['updated customerLists', updatedB2CCustomerLists.toString()],
['updated sites', updatedB2CSites.toString()]
];
} else {
// Build the output error-display
output.outputDisplay = [
['b2cInstance', environmentDef.b2cInstanceName],
['success', output.data.outputValues.success],
['error message', (output.data.outputValues.errorMessage === null) ? '' : output.data.outputValues.errorMessage]
];
}
// Return the output details
return output;
};