-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.txt
124 lines (99 loc) · 4.15 KB
/
index.txt
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//
var config = {
"pageURL": "",
"host": "",
"url": "https://www.westpac.com.au",
"qs": {
"client": ""
},
"batchUrl": "",
"imsOrgID": "3A4B7BAF56F01DA67F000101@AdobeOrg",
"apiClientId": "",
"enableDTM": false,
"dtmTagUrl": ""
};
var cookie = require("cookie");
// 1. Require Visitor:
var Visitor = require("@adobe-mcid/visitor-js-server");
var AuthState = Visitor.AuthState;
module.exports = {
CreatePayload: function (receivedHeaderCookies, mboxName, mBoxNames) {
// 2. Instantiate Visitor by passing your Org ID:
var visitor = new Visitor(config.imsOrgID);
var cookies = cookie.parse(receivedHeaderCookies || "");
var cookieName = visitor.getCookieName();
var amcvCookie = cookies[cookieName];
var visitorPayload;
// 3. Optionally, set custom Customer IDS:
// setting customer id has to be on the basis of cookies and the userid object has to be {brandCode}id
// doing only for wbc now
// var custId = cookies['s_wbc-ti']
// visitor.setCustomerIDs({
// wbcid: {
// id: "1234567890",
// authState: AuthState.UNKNOWN
// }
// });
visitor.setCustomerIDs({
wbcid: {
id: "1234567890",
authState: AuthState.UNKNOWN
}
});
var targetPayload = {
requestLocation: {
"pageURL": config.pageURL,
"impressionId": "1",
"host": config.host
},
thirdPartyId: "2047337005",
tntId: "123455"
};
var fullPayload;
// var createRequestFor = function(targetPayload, amcvCookie, mboxName) {
// return function () {
// 4. Generate Visitor Payload by passing sdidConsumerID (mbox name/id) and AMCV Cookie if found in Req:
// later even if it's one mbox... we'll set mBoxNames rather than mBoxName and change below conditional logic
// for multiple mBox how do we set sdidconsumerID??
if (mBoxNames.length == 0) {
console.log('mboxNames lenght is zero',mBoxNames);
visitorPayload = visitor.generatePayload({
sdidConsumerID: mboxName,
mboxName: mboxName,
amcvCookie: amcvCookie
});
fullPayload = Object.assign({}, targetPayload, { mbox: mboxName }, visitorPayload);
} else if (mBoxNames.length > 0) {
console.log('mboxNames lenght is greater than zero',mBoxNames);
visitorPayload = visitor.generateBatchPayload({
sdidConsumerID: "servertesco",
amcvCookie: amcvCookie,
mboxNames: mBoxNames
});
fullPayload = Object.assign({}, targetPayload, { mboxes: mBoxNames }, visitorPayload);
}
console.log('visitorPayload is -->',visitorPayload);
console.log('fullPayload for target is -->',fullPayload);
// var fullPayload = Object.assign({}, targetPayload, { mbox: mboxName }, visitorPayload);
var payloadToTarget = {
payload: fullPayload
};
// var serverSideResponseScript = {
// script: "var visitor = Visitor.getInstance('3A4B7BAF56F01DA67F000101@AdobeOrg', {serverState: " + JSON.stringify(visitor.getState()) + " });"
// };
var serverSideResponseScript = {
script: "var serverState = " + JSON.stringify(visitor.getState()) + ";"
};
var responsePayload = Object.assign({}, payloadToTarget, serverSideResponseScript);
console.log('payload to aem service', responsePayload);
return responsePayload;
// payloads[mboxName] = fullPayload;
// var fullPayload = {test: "payload generated"};
// return fullPayload;
// }
// };
// payloads = createRequestFor(targetPayload, amcvCookie, mboxName);
// console.log('payload to target', payloads);
// return payloads;
}
};