@magicpixel/rn-mp-client-sdk 0.12.0 → 1.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/common/app-types.js.map +1 -1
- package/lib/commonjs/common/constants.js +5 -26
- package/lib/commonjs/common/constants.js.map +1 -1
- package/lib/commonjs/common/data-store.js +36 -117
- package/lib/commonjs/common/data-store.js.map +1 -1
- package/lib/commonjs/common/event-bus.js +3 -10
- package/lib/commonjs/common/event-bus.js.map +1 -1
- package/lib/commonjs/common/logger.js +9 -18
- package/lib/commonjs/common/logger.js.map +1 -1
- package/lib/commonjs/common/network-service.js +4 -21
- package/lib/commonjs/common/network-service.js.map +1 -1
- package/lib/commonjs/common/reporter.js +8 -31
- package/lib/commonjs/common/reporter.js.map +1 -1
- package/lib/commonjs/common/utils.js +64 -65
- package/lib/commonjs/common/utils.js.map +1 -1
- package/lib/commonjs/coverage/lcov-report/block-navigation.js +6 -19
- package/lib/commonjs/coverage/lcov-report/block-navigation.js.map +1 -1
- package/lib/commonjs/coverage/lcov-report/prettify.js +2 -182
- package/lib/commonjs/coverage/lcov-report/prettify.js.map +1 -1
- package/lib/commonjs/coverage/lcov-report/sorter.js +64 -94
- package/lib/commonjs/coverage/lcov-report/sorter.js.map +1 -1
- package/lib/commonjs/eedl/eedl.js +207 -84
- package/lib/commonjs/eedl/eedl.js.map +1 -1
- package/lib/commonjs/index.js +104 -95
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/models/geo-api-response.js +2 -0
- package/lib/commonjs/models/geo-api-response.js.map +1 -0
- package/lib/commonjs/models/mp-client-sdk.js +3 -11
- package/lib/commonjs/models/mp-client-sdk.js.map +1 -1
- package/lib/commonjs/processors/data-element.processor.js +85 -80
- package/lib/commonjs/processors/data-element.processor.js.map +1 -1
- package/lib/commonjs/processors/geo-location.processor.js +70 -0
- package/lib/commonjs/processors/geo-location.processor.js.map +1 -0
- package/lib/commonjs/processors/qc.processor.js +2 -25
- package/lib/commonjs/processors/qc.processor.js.map +1 -1
- package/lib/commonjs/processors/tag.processor.js +17 -86
- package/lib/commonjs/processors/tag.processor.js.map +1 -1
- package/lib/commonjs/processors/trans-function.processor.js +5 -23
- package/lib/commonjs/processors/trans-function.processor.js.map +1 -1
- package/lib/commonjs/processors/visit-id.processor.js +4 -50
- package/lib/commonjs/processors/visit-id.processor.js.map +1 -1
- package/lib/module/common/app-types.js.map +1 -1
- package/lib/module/common/constants.js +4 -22
- package/lib/module/common/constants.js.map +1 -1
- package/lib/module/common/data-store.js +35 -108
- package/lib/module/common/data-store.js.map +1 -1
- package/lib/module/common/event-bus.js +3 -6
- package/lib/module/common/event-bus.js.map +1 -1
- package/lib/module/common/logger.js +9 -16
- package/lib/module/common/logger.js.map +1 -1
- package/lib/module/common/network-service.js +4 -11
- package/lib/module/common/network-service.js.map +1 -1
- package/lib/module/common/reporter.js +8 -19
- package/lib/module/common/reporter.js.map +1 -1
- package/lib/module/common/utils.js +63 -56
- package/lib/module/common/utils.js.map +1 -1
- package/lib/module/coverage/lcov-report/block-navigation.js +6 -19
- package/lib/module/coverage/lcov-report/block-navigation.js.map +1 -1
- package/lib/module/coverage/lcov-report/prettify.js +2 -182
- package/lib/module/coverage/lcov-report/prettify.js.map +1 -1
- package/lib/module/coverage/lcov-report/sorter.js +64 -94
- package/lib/module/coverage/lcov-report/sorter.js.map +1 -1
- package/lib/module/eedl/eedl.js +206 -76
- package/lib/module/eedl/eedl.js.map +1 -1
- package/lib/module/index.js +102 -57
- package/lib/module/index.js.map +1 -1
- package/lib/module/models/geo-api-response.js +2 -0
- package/lib/module/models/geo-api-response.js.map +1 -0
- package/lib/module/models/mp-client-sdk.js +0 -5
- package/lib/module/models/mp-client-sdk.js.map +1 -1
- package/lib/module/processors/data-element.processor.js +82 -71
- package/lib/module/processors/data-element.processor.js.map +1 -1
- package/lib/module/processors/geo-location.processor.js +63 -0
- package/lib/module/processors/geo-location.processor.js.map +1 -0
- package/lib/module/processors/qc.processor.js +2 -11
- package/lib/module/processors/qc.processor.js.map +1 -1
- package/lib/module/processors/tag.processor.js +17 -57
- package/lib/module/processors/tag.processor.js.map +1 -1
- package/lib/module/processors/trans-function.processor.js +5 -12
- package/lib/module/processors/trans-function.processor.js.map +1 -1
- package/lib/module/processors/visit-id.processor.js +4 -27
- package/lib/module/processors/visit-id.processor.js.map +1 -1
- package/lib/typescript/common/app-types.d.ts +3 -0
- package/lib/typescript/common/constants.d.ts +1 -0
- package/lib/typescript/common/data-store.d.ts +8 -0
- package/lib/typescript/common/utils.d.ts +19 -0
- package/lib/typescript/eedl/eedl.d.ts +16 -5
- package/lib/typescript/index.d.ts +53 -0
- package/lib/typescript/models/geo-api-response.d.ts +12 -0
- package/lib/typescript/processors/data-element.processor.d.ts +10 -1
- package/lib/typescript/processors/geo-location.processor.d.ts +10 -0
- package/package.json +25 -15
- package/src/common/app-types.ts +3 -0
- package/src/common/constants.ts +2 -0
- package/src/common/data-store.ts +38 -0
- package/src/common/utils.ts +58 -0
- package/src/eedl/eedl.ts +241 -18
- package/src/index.tsx +98 -3
- package/src/models/geo-api-response.ts +13 -0
- package/src/processors/data-element.processor.ts +140 -70
- package/src/processors/geo-location.processor.ts +91 -0
package/lib/module/eedl/eedl.js
CHANGED
|
@@ -1,41 +1,43 @@
|
|
|
1
|
-
function _defineProperty(
|
|
2
|
-
|
|
1
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
2
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
3
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
3
4
|
import { Utils } from '../common/utils';
|
|
4
5
|
import { Logger } from '../common/logger';
|
|
6
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
7
|
+
import { customAlphabet } from 'nanoid/non-secure';
|
|
8
|
+
const eventsToPersist = {
|
|
9
|
+
user_info: '_mpPendingUserInfo',
|
|
10
|
+
mp_purchase: '_mpPendingPurchase'
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// UUID v4 generator for React Native
|
|
14
|
+
const getUUIDV4 = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 36);
|
|
5
15
|
export class MpDataLayerHelper {
|
|
6
|
-
constructor(dlEventName, dlInitMode, dlInitEvent) {
|
|
16
|
+
constructor(dlEventName, dlInitMode, dlInitEvent, storageKeyName = '_mpdls') {
|
|
7
17
|
this.dlEventName = dlEventName;
|
|
8
18
|
this.dlInitMode = dlInitMode;
|
|
9
|
-
|
|
19
|
+
this.storageKeyName = storageKeyName;
|
|
10
20
|
_defineProperty(this, "isReady", false);
|
|
11
|
-
|
|
12
21
|
_defineProperty(this, "_masterDataLayer", {});
|
|
13
|
-
|
|
22
|
+
_defineProperty(this, "_persistedVars", {});
|
|
14
23
|
_defineProperty(this, "eventProcessors", {});
|
|
15
|
-
|
|
16
24
|
_defineProperty(this, "stateTracker", []);
|
|
17
|
-
|
|
18
25
|
_defineProperty(this, "dlInitEvent", void 0);
|
|
19
|
-
|
|
20
26
|
_defineProperty(this, "receivedInitialEvent", false);
|
|
21
|
-
|
|
22
27
|
_defineProperty(this, "eventQueue", []);
|
|
23
|
-
|
|
28
|
+
_defineProperty(this, "isEntryPoint", 0);
|
|
24
29
|
this.dlInitEvent = dlInitEvent;
|
|
25
|
-
|
|
30
|
+
this.resetEntryPointInfo();
|
|
26
31
|
if (this.dlInitMode !== 'manual') {
|
|
27
32
|
this.isReady = true;
|
|
28
33
|
}
|
|
29
|
-
|
|
30
34
|
if (this.isReady) {
|
|
31
35
|
this.ready();
|
|
32
36
|
}
|
|
33
37
|
}
|
|
34
|
-
|
|
35
|
-
init(globalEventListeners) {
|
|
38
|
+
async init(globalEventListeners) {
|
|
36
39
|
// register any global event listeners passed through to the init command
|
|
37
40
|
const globalEventListenerKeys = Object.keys(globalEventListeners || {});
|
|
38
|
-
|
|
39
41
|
if ((globalEventListenerKeys === null || globalEventListenerKeys === void 0 ? void 0 : globalEventListenerKeys.length) > 0) {
|
|
40
42
|
for (const key of globalEventListenerKeys) {
|
|
41
43
|
if (typeof globalEventListeners[key] !== 'undefined') {
|
|
@@ -43,207 +45,335 @@ export class MpDataLayerHelper {
|
|
|
43
45
|
}
|
|
44
46
|
}
|
|
45
47
|
}
|
|
46
|
-
}
|
|
47
48
|
|
|
49
|
+
// Load persisted events from AsyncStorage
|
|
50
|
+
for (const key of Object.keys(eventsToPersist)) {
|
|
51
|
+
try {
|
|
52
|
+
const persistedEvent = await AsyncStorage.getItem(eventsToPersist[key]);
|
|
53
|
+
if (persistedEvent) {
|
|
54
|
+
const event = JSON.parse(persistedEvent);
|
|
55
|
+
this.pushEvent(event.eventName, event.eventPayload);
|
|
56
|
+
}
|
|
57
|
+
} catch (err) {
|
|
58
|
+
Logger.logError('Error parsing persisted event', err);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
48
62
|
pushEvent(eventName, payload) {
|
|
49
63
|
Logger.logDbg('EV Push Event:: ', JSON.stringify(payload));
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
this.processQItems(eventName, payload);
|
|
64
|
+
if (eventName === 'set' || eventName === 'persist' || eventName === 'clear' || eventName === 'user_info') {
|
|
65
|
+
// process regardless - fire and forget for async operations
|
|
66
|
+
this.processQItems(eventName, payload).catch(err => Logger.logError('Error processing event', err));
|
|
54
67
|
} else {
|
|
55
68
|
if (!this.receivedInitialEvent) {
|
|
56
69
|
// set only if this is not true already
|
|
57
70
|
this.receivedInitialEvent = eventName === this.dlInitEvent;
|
|
58
71
|
this.eventQueue.push([eventName, payload]);
|
|
59
|
-
|
|
60
72
|
if (this.isReady && this.receivedInitialEvent) {
|
|
61
73
|
this.ready();
|
|
62
74
|
}
|
|
63
75
|
} else if (!this.isReady) {
|
|
64
76
|
this.eventQueue.push([eventName, payload]);
|
|
65
77
|
} else {
|
|
66
|
-
|
|
78
|
+
// fire and forget for async operations
|
|
79
|
+
this.processQItems(eventName, payload).catch(err => Logger.logError('Error processing event', err));
|
|
67
80
|
}
|
|
68
81
|
}
|
|
69
82
|
}
|
|
70
|
-
|
|
71
|
-
processQItems(eventName, payload) {
|
|
83
|
+
async processQItems(eventName, payload) {
|
|
72
84
|
try {
|
|
73
85
|
if (eventName === 'set') {
|
|
74
86
|
this.setDl(payload);
|
|
87
|
+
} else if (eventName === 'persist') {
|
|
88
|
+
await this.storeData(payload === null || payload === void 0 ? void 0 : payload.key, payload === null || payload === void 0 ? void 0 : payload.value);
|
|
89
|
+
} else if (eventName === 'clear') {
|
|
90
|
+
if (Array.isArray(payload) && payload.length > 0) {
|
|
91
|
+
await this.deleteData(payload);
|
|
92
|
+
}
|
|
93
|
+
} else if (eventName === 'user_info') {
|
|
94
|
+
this.setUserData(payload);
|
|
75
95
|
} else {
|
|
76
|
-
this.eventProcessor(eventName, payload);
|
|
96
|
+
await this.eventProcessor(eventName, payload);
|
|
77
97
|
}
|
|
78
98
|
/* Make sure nothing is written below this line. If you do so, remember to return on error conditions above */
|
|
79
|
-
|
|
80
99
|
} catch (err) {
|
|
81
100
|
Logger.logError('Error performing init setup on dl', err);
|
|
82
101
|
}
|
|
83
102
|
}
|
|
103
|
+
|
|
84
104
|
/**
|
|
85
105
|
* Private Processor for 'set' command object
|
|
86
106
|
*/
|
|
87
|
-
|
|
88
|
-
|
|
89
107
|
setDl(obj) {
|
|
90
108
|
if (!obj) {
|
|
91
109
|
return false;
|
|
92
110
|
}
|
|
93
|
-
|
|
94
111
|
const _tmp = Utils.flattenObject(obj);
|
|
95
|
-
|
|
96
112
|
this._masterDataLayer = Object.assign({}, this._masterDataLayer, _tmp);
|
|
97
113
|
return true;
|
|
98
114
|
}
|
|
99
|
-
|
|
100
115
|
getDl() {
|
|
101
116
|
return this._masterDataLayer;
|
|
102
117
|
}
|
|
118
|
+
setUserData(payload) {
|
|
119
|
+
var _payload$zip, _payload$zip2;
|
|
120
|
+
if (payload !== null && payload !== void 0 && payload.zip && (payload === null || payload === void 0 ? void 0 : (_payload$zip = payload.zip) === null || _payload$zip === void 0 ? void 0 : _payload$zip.length) > 0 && (payload === null || payload === void 0 ? void 0 : (_payload$zip2 = payload.zip) === null || _payload$zip2 === void 0 ? void 0 : _payload$zip2.indexOf('-')) > -1) {
|
|
121
|
+
payload.zip = payload.zip.split('-')[0].trim();
|
|
122
|
+
}
|
|
123
|
+
const uif = {};
|
|
124
|
+
this._persistedVars = this._persistedVars || {};
|
|
125
|
+
this._persistedVars.uif = this._persistedVars.uif || {};
|
|
126
|
+
if (payload.pid) {
|
|
127
|
+
this._persistedVars.uif.user_pid = payload.pid;
|
|
128
|
+
uif.pid = payload.pid;
|
|
129
|
+
}
|
|
130
|
+
if (payload.email) {
|
|
131
|
+
this._persistedVars.uif.user_email = payload.email;
|
|
132
|
+
uif.e = payload.email;
|
|
133
|
+
}
|
|
134
|
+
if (payload.phone) {
|
|
135
|
+
this._persistedVars.uif.user_phone = payload.phone;
|
|
136
|
+
uif.p = payload.phone;
|
|
137
|
+
}
|
|
138
|
+
if (payload.country) {
|
|
139
|
+
this._persistedVars.uif.user_country = payload.country;
|
|
140
|
+
uif.cy = payload.country;
|
|
141
|
+
}
|
|
142
|
+
if (payload.city) {
|
|
143
|
+
this._persistedVars.uif.user_city = payload.city;
|
|
144
|
+
uif.ct = payload.city;
|
|
145
|
+
}
|
|
146
|
+
if (payload.state) {
|
|
147
|
+
this._persistedVars.uif.user_state = payload.state;
|
|
148
|
+
uif.st = payload.state;
|
|
149
|
+
}
|
|
150
|
+
if (payload.fName) {
|
|
151
|
+
this._persistedVars.uif.fn = payload.fName;
|
|
152
|
+
uif.fn = payload.fName;
|
|
153
|
+
}
|
|
154
|
+
if (payload.lName) {
|
|
155
|
+
this._persistedVars.uif.ln = payload.lName;
|
|
156
|
+
uif.ln = payload.lName;
|
|
157
|
+
}
|
|
158
|
+
if (payload.zip) {
|
|
159
|
+
this._persistedVars.uif.zip_code = payload.zip;
|
|
160
|
+
uif.z = payload.zip;
|
|
161
|
+
}
|
|
162
|
+
if (Object.keys(uif).length > 0) {
|
|
163
|
+
this.storeData('uif', uif);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
async deleteData(chips) {
|
|
167
|
+
const fullData = await this.getFullData();
|
|
168
|
+
for (const chip of chips) {
|
|
169
|
+
if (typeof chip === 'string') {
|
|
170
|
+
delete fullData[chip];
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
await this.storeFullData(fullData);
|
|
174
|
+
}
|
|
175
|
+
async storeData(chip, value) {
|
|
176
|
+
if (typeof chip !== 'undefined' && typeof value !== 'undefined') {
|
|
177
|
+
const fullData = await this.getFullData();
|
|
178
|
+
fullData[chip] = value;
|
|
179
|
+
await this.storeFullData(fullData);
|
|
180
|
+
this._persistedVars[chip] = value;
|
|
181
|
+
} else {
|
|
182
|
+
Logger.logError('Both key and value are required for persisting data');
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
async reloadPersistedVars() {
|
|
186
|
+
this._persistedVars = await this.getFullData();
|
|
187
|
+
}
|
|
188
|
+
async getFullData() {
|
|
189
|
+
try {
|
|
190
|
+
const storedData = await AsyncStorage.getItem(this.storageKeyName);
|
|
191
|
+
if (storedData) {
|
|
192
|
+
return JSON.parse(storedData);
|
|
193
|
+
}
|
|
194
|
+
} catch (err) {
|
|
195
|
+
Logger.logError('Error reloading persisted variables', err);
|
|
196
|
+
}
|
|
197
|
+
return {};
|
|
198
|
+
}
|
|
199
|
+
async storeFullData(fullData) {
|
|
200
|
+
this._persistedVars = fullData;
|
|
201
|
+
try {
|
|
202
|
+
await AsyncStorage.setItem(this.storageKeyName, JSON.stringify(fullData));
|
|
203
|
+
} catch (err) {
|
|
204
|
+
Logger.logError('Error storing data', err);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// private async getStoredData<T = any>(chip: string, defValue: T): Promise<T> {
|
|
209
|
+
// let value: T;
|
|
210
|
+
// try {
|
|
211
|
+
// const storedData = await AsyncStorage.getItem(this.storageKeyName);
|
|
212
|
+
// if (storedData) {
|
|
213
|
+
// const parsedData = JSON.parse(storedData);
|
|
214
|
+
// value = parsedData[chip];
|
|
215
|
+
// }
|
|
216
|
+
// } catch (err) {
|
|
217
|
+
// Logger.logError('Error parsing stored data', err);
|
|
218
|
+
// }
|
|
219
|
+
// return value ?? defValue;
|
|
220
|
+
// }
|
|
221
|
+
|
|
103
222
|
/**
|
|
104
223
|
* Private event processor. Idea is that whenever an event is detected, we create a copy of the master data layer,
|
|
105
224
|
* add the event variables, and trigger the event requested when initializing the data layer helper
|
|
106
225
|
* @param eventName
|
|
107
226
|
* @param model
|
|
108
227
|
*/
|
|
228
|
+
async eventProcessor(eventName, model) {
|
|
229
|
+
model = model ?? {};
|
|
109
230
|
|
|
110
|
-
|
|
111
|
-
eventProcessor(eventName, model) {
|
|
112
231
|
/**
|
|
113
232
|
* The following If block clears the data layer when the initial event is received.
|
|
114
233
|
* This is done to prevent value carry overs from one page to another in single page apps
|
|
115
234
|
*/
|
|
116
235
|
if (eventName === 'reset' || eventName === this.dlInitEvent) {
|
|
117
236
|
this.reset();
|
|
237
|
+
|
|
238
|
+
// add an init event based uuid to the core data model
|
|
239
|
+
model['page_load_uid'] = getUUIDV4();
|
|
240
|
+
model['is_entry_point'] = this.getIsEntryPointValue();
|
|
241
|
+
if (model['is_entry_point'] === 1) {
|
|
242
|
+
// Note: In React Native, we don't have document.referrer, so we'll use a placeholder
|
|
243
|
+
model['entry_point_referrer'] = '';
|
|
244
|
+
}
|
|
118
245
|
this.setDl(model);
|
|
119
246
|
model = undefined;
|
|
120
247
|
}
|
|
121
|
-
|
|
122
248
|
if (model) {
|
|
123
249
|
model = {
|
|
124
250
|
ev: model || {}
|
|
125
251
|
};
|
|
126
252
|
} else {
|
|
127
253
|
model = {};
|
|
128
|
-
}
|
|
254
|
+
}
|
|
255
|
+
await this.reloadPersistedVars();
|
|
129
256
|
|
|
257
|
+
// get persisted values and add them into the event model
|
|
258
|
+
model['p'] = this._persistedVars ?? {};
|
|
130
259
|
|
|
131
|
-
|
|
260
|
+
// generate a unique id for each event automatically
|
|
261
|
+
model['ev._id'] = Utils.getUniqueID();
|
|
132
262
|
|
|
263
|
+
// add the event ts also for every event
|
|
133
264
|
model['ev._tsMs'] = Date.now();
|
|
134
265
|
model['ev._eventName'] = eventName;
|
|
135
|
-
model =
|
|
266
|
+
model['ev._persistKey'] = eventsToPersist[eventName] || null;
|
|
267
|
+
model = Utils.flattenObject(model);
|
|
136
268
|
|
|
269
|
+
// create a clone of master data layer and merge event model to it
|
|
137
270
|
const _clone = Object.assign({}, this._masterDataLayer, model);
|
|
138
|
-
|
|
139
271
|
const eventTs = Date.now();
|
|
140
|
-
const eventPayload = {
|
|
272
|
+
const eventPayload = JSON.parse(JSON.stringify({
|
|
141
273
|
eventName: eventName,
|
|
142
274
|
eventTs: eventTs,
|
|
143
275
|
model: _clone
|
|
144
|
-
};
|
|
276
|
+
}));
|
|
145
277
|
|
|
146
|
-
|
|
278
|
+
// add to state tracker
|
|
279
|
+
this.stateTracker.push(eventPayload);
|
|
147
280
|
|
|
148
|
-
|
|
281
|
+
// trigger an event that can be listened to by other listeners
|
|
282
|
+
Utils.triggerEvent(this.dlEventName, eventPayload);
|
|
149
283
|
|
|
284
|
+
// see if there are any other registered processors and invoke them
|
|
150
285
|
if (this.eventProcessors[eventName]) {
|
|
151
286
|
for (const processor of this.eventProcessors[eventName]) {
|
|
152
287
|
Utils.safeExecute(processor, eventPayload);
|
|
153
288
|
}
|
|
154
289
|
}
|
|
155
290
|
}
|
|
156
|
-
|
|
157
291
|
overrideDlInitEvent(eventName) {
|
|
158
292
|
if (eventName && eventName.length > 0) {
|
|
159
293
|
this.dlInitEvent = eventName;
|
|
160
294
|
return 'Dl Init Event Override Successful';
|
|
161
295
|
}
|
|
162
|
-
|
|
163
296
|
return 'Dl Init Event Override Failed';
|
|
164
297
|
}
|
|
298
|
+
|
|
165
299
|
/**
|
|
166
300
|
* Exposed method for registering custom processors for events
|
|
167
301
|
* @param eventType
|
|
168
302
|
* @param fn
|
|
169
303
|
*/
|
|
170
|
-
|
|
171
|
-
|
|
172
304
|
registerProcessor(eventType, fn) {
|
|
173
305
|
if (!eventType || !fn || typeof fn !== 'function') {
|
|
174
306
|
Logger.logError('EventType and Fn are mandatory');
|
|
175
307
|
return;
|
|
176
308
|
}
|
|
177
|
-
|
|
178
309
|
if (!this.eventProcessors[eventType]) {
|
|
179
310
|
this.eventProcessors[eventType] = [];
|
|
180
311
|
}
|
|
181
|
-
|
|
182
312
|
this.eventProcessors[eventType].push(fn);
|
|
183
313
|
}
|
|
314
|
+
|
|
184
315
|
/**
|
|
185
316
|
* Exposed getter for getting values from data layer
|
|
186
317
|
* @param key
|
|
187
318
|
* @returns {*|undefined}
|
|
188
319
|
*/
|
|
189
|
-
|
|
190
|
-
|
|
191
320
|
get(key) {
|
|
192
321
|
return this._masterDataLayer[key] || undefined;
|
|
193
322
|
}
|
|
194
|
-
|
|
195
323
|
getState() {
|
|
196
324
|
return this.stateTracker;
|
|
197
325
|
}
|
|
198
|
-
|
|
199
326
|
hasEventHappened(key) {
|
|
200
327
|
return !!this.stateTracker.find(i => i.eventName === key);
|
|
201
328
|
}
|
|
202
|
-
|
|
203
329
|
reset() {
|
|
204
330
|
this._masterDataLayer = {};
|
|
205
331
|
return true;
|
|
206
332
|
}
|
|
207
|
-
|
|
208
333
|
ready() {
|
|
209
334
|
this.isReady = true;
|
|
210
|
-
|
|
211
335
|
if (this.receivedInitialEvent) {
|
|
212
|
-
Logger.logDbg('Initial event received: ', this.dlInitEvent);
|
|
336
|
+
Logger.logDbg('Initial event received: ', this.dlInitEvent);
|
|
337
|
+
// drain queue only if the initial configured event has been received,
|
|
213
338
|
// otherwise mark isReady but dont drain the queue. queue will be drained first when the init
|
|
214
339
|
// event is received
|
|
215
|
-
|
|
216
|
-
this.drainQueue();
|
|
340
|
+
this.drainQueue().catch(err => Logger.logError('Error draining queue', err));
|
|
217
341
|
} else {
|
|
218
342
|
Logger.logDbg(`Initial event (${this.dlInitEvent}) NOT received. Events will be queued`);
|
|
219
343
|
}
|
|
220
344
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
345
|
+
async drainQueue() {
|
|
346
|
+
Logger.logDbg('drainQueue...');
|
|
347
|
+
// create a copy of the array
|
|
348
|
+
const _temp = [...this.eventQueue];
|
|
349
|
+
// clean the array
|
|
350
|
+
this.eventQueue.splice(0, this.eventQueue.length);
|
|
351
|
+
// find the event with dlInit event and execute it first, rest continues
|
|
229
352
|
const initialEventObjectIndex = _temp.findIndex(e => {
|
|
230
353
|
var _;
|
|
231
|
-
|
|
232
354
|
return ((_ = [e][0]) === null || _ === void 0 ? void 0 : _[0]) === this.dlInitEvent;
|
|
233
355
|
});
|
|
234
|
-
|
|
235
356
|
if (initialEventObjectIndex > -1) {
|
|
236
357
|
// splice and execute it
|
|
237
|
-
this.processQItems(_temp[initialEventObjectIndex][0], _temp[initialEventObjectIndex][1]);
|
|
238
|
-
|
|
358
|
+
await this.processQItems(_temp[initialEventObjectIndex][0], _temp[initialEventObjectIndex][1]);
|
|
239
359
|
_temp.splice(initialEventObjectIndex, 1);
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
|
|
360
|
+
}
|
|
361
|
+
// continue with other items
|
|
243
362
|
for (const item of _temp) {
|
|
244
|
-
this.processQItems(item[0], item[1]);
|
|
363
|
+
await this.processQItems(item[0], item[1]);
|
|
245
364
|
}
|
|
246
365
|
}
|
|
247
|
-
|
|
366
|
+
getIsEntryPointValue() {
|
|
367
|
+
// In React Native, we'll use a simple approach for entry point tracking
|
|
368
|
+
// This could be enhanced with proper session storage implementation
|
|
369
|
+
const currentValue = this.isEntryPoint;
|
|
370
|
+
this.isEntryPoint = 0; // Reset after first use
|
|
371
|
+
return currentValue;
|
|
372
|
+
}
|
|
373
|
+
resetEntryPointInfo() {
|
|
374
|
+
// In React Native, we'll default to entry point = 1 for the first session
|
|
375
|
+
// This could be enhanced with proper referrer tracking if needed
|
|
376
|
+
this.isEntryPoint = 1;
|
|
377
|
+
}
|
|
248
378
|
}
|
|
249
379
|
//# sourceMappingURL=eedl.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Utils","Logger","MpDataLayerHelper","constructor","dlEventName","dlInitMode","dlInitEvent","isReady","ready","init","globalEventListeners","globalEventListenerKeys","Object","keys","length","key","registerProcessor","pushEvent","eventName","payload","logDbg","JSON","stringify","processQItems","receivedInitialEvent","eventQueue","push","setDl","eventProcessor","err","logError","obj","_tmp","flattenObject","_masterDataLayer","assign","getDl","model","reset","undefined","ev","getUniqueID","Date","now","_clone","eventTs","eventPayload","stateTracker","triggerEvent","eventProcessors","processor","safeExecute","overrideDlInitEvent","eventType","fn","get","getState","hasEventHappened","find","i","drainQueue","_temp","splice","initialEventObjectIndex","findIndex","e","item"],"sources":["eedl.ts"],"sourcesContent":["import { Utils } from '../common/utils';\nimport type { EventProcessorFn, MapLike, TypedAny } from '../common/app-types';\nimport { Logger } from '../common/logger';\n\nexport class MpDataLayerHelper {\n isReady = false;\n _masterDataLayer: MapLike = {};\n eventProcessors: Record<string, any> = {};\n stateTracker: Array<any> = [];\n dlInitEvent: string;\n receivedInitialEvent = false;\n eventQueue: Array<any> = [];\n\n constructor(\n private readonly dlEventName: string,\n private readonly dlInitMode: string,\n dlInitEvent: string\n ) {\n this.dlInitEvent = dlInitEvent;\n\n if (this.dlInitMode !== 'manual') {\n this.isReady = true;\n }\n\n if (this.isReady) {\n this.ready();\n }\n }\n\n init(globalEventListeners: Record<string, EventProcessorFn>): void {\n // register any global event listeners passed through to the init command\n const globalEventListenerKeys = Object.keys(globalEventListeners || {});\n if (globalEventListenerKeys?.length > 0) {\n for (const key of globalEventListenerKeys) {\n if (typeof globalEventListeners[key] !== 'undefined') {\n this.registerProcessor(key, globalEventListeners[key] as any);\n }\n }\n }\n }\n\n pushEvent(eventName: string, payload: MapLike): void {\n Logger.logDbg('EV Push Event:: ', JSON.stringify(payload));\n if (eventName === 'set') {\n // process regardless\n this.processQItems(eventName, payload);\n } else {\n if (!this.receivedInitialEvent) {\n // set only if this is not true already\n this.receivedInitialEvent = eventName === this.dlInitEvent;\n this.eventQueue.push([eventName, payload]);\n if (this.isReady && this.receivedInitialEvent) {\n this.ready();\n }\n } else if (!this.isReady) {\n this.eventQueue.push([eventName, payload]);\n } else {\n this.processQItems(eventName, payload);\n }\n }\n }\n\n processQItems(eventName: string, payload: MapLike): void {\n try {\n if (eventName === 'set') {\n this.setDl(payload);\n } else {\n this.eventProcessor(eventName, payload);\n }\n /* Make sure nothing is written below this line. If you do so, remember to return on error conditions above */\n } catch (err) {\n Logger.logError('Error performing init setup on dl', err);\n }\n }\n\n /**\n * Private Processor for 'set' command object\n */\n setDl(obj: TypedAny | undefined): boolean {\n if (!obj) {\n return false;\n }\n const _tmp = Utils.flattenObject(obj);\n this._masterDataLayer = Object.assign({}, this._masterDataLayer, _tmp);\n return true;\n }\n\n getDl(): TypedAny {\n return this._masterDataLayer;\n }\n\n /**\n * Private event processor. Idea is that whenever an event is detected, we create a copy of the master data layer,\n * add the event variables, and trigger the event requested when initializing the data layer helper\n * @param eventName\n * @param model\n */\n eventProcessor(eventName: string, model: TypedAny | undefined): void {\n /**\n * The following If block clears the data layer when the initial event is received.\n * This is done to prevent value carry overs from one page to another in single page apps\n */\n if (eventName === 'reset' || eventName === this.dlInitEvent) {\n this.reset();\n this.setDl(model);\n model = undefined;\n }\n\n if (model) {\n model = {\n ev: (model || {}) as any,\n };\n } else {\n model = {};\n }\n\n // generate a unique id for each event automatically\n model['ev._id'] = Utils.getUniqueID();\n\n // add the event ts also for every event\n model['ev._tsMs'] = Date.now();\n\n model['ev._eventName'] = eventName;\n\n model = Utils.flattenObject(model);\n\n // create a clone of master data layer and merge event model to it\n const _clone = Object.assign({}, this._masterDataLayer, model);\n const eventTs = Date.now();\n\n const eventPayload = {\n eventName: eventName,\n eventTs: eventTs,\n model: _clone,\n };\n\n // add to state tracker\n this.stateTracker.push(eventPayload);\n\n // trigger an event that can be listened to by other listeners\n Utils.triggerEvent(this.dlEventName, eventPayload);\n\n // see if there are any other registered processors and invoke them\n if (this.eventProcessors[eventName]) {\n for (const processor of this.eventProcessors[eventName]) {\n Utils.safeExecute(processor, eventPayload);\n }\n }\n }\n\n overrideDlInitEvent(eventName: string): string {\n if (eventName && eventName.length > 0) {\n this.dlInitEvent = eventName;\n return 'Dl Init Event Override Successful';\n }\n return 'Dl Init Event Override Failed';\n }\n\n /**\n * Exposed method for registering custom processors for events\n * @param eventType\n * @param fn\n */\n registerProcessor(eventType: string, fn: EventProcessorFn): void {\n if (!eventType || !fn || typeof fn !== 'function') {\n Logger.logError('EventType and Fn are mandatory');\n return;\n }\n if (!this.eventProcessors[eventType]) {\n this.eventProcessors[eventType] = [];\n }\n\n this.eventProcessors[eventType].push(fn);\n }\n\n /**\n * Exposed getter for getting values from data layer\n * @param key\n * @returns {*|undefined}\n */\n get(key: string): MapLike | undefined {\n return this._masterDataLayer[key] || undefined;\n }\n\n getState(): TypedAny[] {\n return this.stateTracker;\n }\n\n hasEventHappened(key: string): boolean {\n return !!this.stateTracker.find((i) => i.eventName === key);\n }\n\n reset(): boolean {\n this._masterDataLayer = {};\n return true;\n }\n\n ready(): void {\n this.isReady = true;\n if (this.receivedInitialEvent) {\n Logger.logDbg('Initial event received: ', this.dlInitEvent);\n // drain queue only if the initial configured event has been received,\n // otherwise mark isReady but dont drain the queue. queue will be drained first when the init\n // event is received\n this.drainQueue();\n } else {\n Logger.logDbg(\n `Initial event (${this.dlInitEvent}) NOT received. Events will be queued`\n );\n }\n }\n\n drainQueue(): void {\n Logger.logDbg('drainQueue...');\n // create a copy of the array\n const _temp = [...this.eventQueue];\n // clean the array\n this.eventQueue.splice(0, this.eventQueue.length);\n // find the event with dlInit event and execute it first, rest continues\n const initialEventObjectIndex = _temp.findIndex(\n (e) => [e][0]?.[0] === this.dlInitEvent\n );\n if (initialEventObjectIndex > -1) {\n // splice and execute it\n this.processQItems(\n _temp[initialEventObjectIndex][0],\n _temp[initialEventObjectIndex][1]\n );\n _temp.splice(initialEventObjectIndex, 1);\n }\n // continue with other items\n for (const item of _temp) {\n this.processQItems(item[0], item[1]);\n }\n }\n}\n"],"mappings":";;AAAA,SAASA,KAAT,QAAsB,iBAAtB;AAEA,SAASC,MAAT,QAAuB,kBAAvB;AAEA,OAAO,MAAMC,iBAAN,CAAwB;EAS7BC,WAAW,CACQC,WADR,EAEQC,UAFR,EAGTC,WAHS,EAIT;IAAA,KAHiBF,WAGjB,GAHiBA,WAGjB;IAAA,KAFiBC,UAEjB,GAFiBA,UAEjB;;IAAA,iCAZQ,KAYR;;IAAA,0CAX0B,EAW1B;;IAAA,yCAVqC,EAUrC;;IAAA,sCATyB,EASzB;;IAAA;;IAAA,8CAPqB,KAOrB;;IAAA,oCANuB,EAMvB;;IACA,KAAKC,WAAL,GAAmBA,WAAnB;;IAEA,IAAI,KAAKD,UAAL,KAAoB,QAAxB,EAAkC;MAChC,KAAKE,OAAL,GAAe,IAAf;IACD;;IAED,IAAI,KAAKA,OAAT,EAAkB;MAChB,KAAKC,KAAL;IACD;EACF;;EAEDC,IAAI,CAACC,oBAAD,EAA+D;IACjE;IACA,MAAMC,uBAAuB,GAAGC,MAAM,CAACC,IAAP,CAAYH,oBAAoB,IAAI,EAApC,CAAhC;;IACA,IAAI,CAAAC,uBAAuB,SAAvB,IAAAA,uBAAuB,WAAvB,YAAAA,uBA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G,IAAX,IAAmBL,KAAnB,EAA0B;MACxB,KAAKtC,aAAL,CAAmB2C,IAAI,CAAC,CAAD,CAAvB,EAA4BA,IAAI,CAAC,CAAD,CAAhC;IACD;EACF;;AAtO4B"}
|
|
1
|
+
{"version":3,"names":["Utils","Logger","AsyncStorage","customAlphabet","eventsToPersist","user_info","mp_purchase","getUUIDV4","MpDataLayerHelper","constructor","dlEventName","dlInitMode","dlInitEvent","storageKeyName","_defineProperty","resetEntryPointInfo","isReady","ready","init","globalEventListeners","globalEventListenerKeys","Object","keys","length","key","registerProcessor","persistedEvent","getItem","event","JSON","parse","pushEvent","eventName","eventPayload","err","logError","payload","logDbg","stringify","processQItems","catch","receivedInitialEvent","eventQueue","push","setDl","storeData","value","Array","isArray","deleteData","setUserData","eventProcessor","obj","_tmp","flattenObject","_masterDataLayer","assign","getDl","_payload$zip","_payload$zip2","zip","indexOf","split","trim","uif","_persistedVars","pid","user_pid","email","user_email","e","phone","user_phone","p","country","user_country","cy","city","user_city","ct","state","user_state","st","fName","fn","lName","ln","zip_code","z","chips","fullData","getFullData","chip","storeFullData","reloadPersistedVars","storedData","setItem","model","reset","getIsEntryPointValue","undefined","ev","getUniqueID","Date","now","_clone","eventTs","stateTracker","triggerEvent","eventProcessors","processor","safeExecute","overrideDlInitEvent","eventType","get","getState","hasEventHappened","find","i","drainQueue","_temp","splice","initialEventObjectIndex","findIndex","_","item","currentValue","isEntryPoint"],"sources":["eedl.ts"],"sourcesContent":["import { Utils } from '../common/utils';\nimport type { EventProcessorFn, MapLike, TypedAny } from '../common/app-types';\nimport { Logger } from '../common/logger';\nimport AsyncStorage from '@react-native-async-storage/async-storage';\nimport { customAlphabet } from 'nanoid/non-secure';\n\nconst eventsToPersist: Record<string, string> = {\n user_info: '_mpPendingUserInfo',\n mp_purchase: '_mpPendingPurchase',\n};\n\n// UUID v4 generator for React Native\nconst getUUIDV4 = customAlphabet(\n '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',\n 36\n);\n\nexport class MpDataLayerHelper {\n isReady = false;\n _masterDataLayer: MapLike = {};\n _persistedVars: MapLike = {};\n eventProcessors: Record<string, any> = {};\n stateTracker: Array<any> = [];\n dlInitEvent: string;\n receivedInitialEvent = false;\n eventQueue: Array<any> = [];\n private isEntryPoint = 0;\n\n constructor(\n private readonly dlEventName: string,\n private readonly dlInitMode: string,\n dlInitEvent: string,\n private readonly storageKeyName: string = '_mpdls'\n ) {\n this.dlInitEvent = dlInitEvent;\n this.resetEntryPointInfo();\n\n if (this.dlInitMode !== 'manual') {\n this.isReady = true;\n }\n\n if (this.isReady) {\n this.ready();\n }\n }\n\n async init(\n globalEventListeners: Record<string, EventProcessorFn>\n ): Promise<void> {\n // register any global event listeners passed through to the init command\n const globalEventListenerKeys = Object.keys(globalEventListeners || {});\n if (globalEventListenerKeys?.length > 0) {\n for (const key of globalEventListenerKeys) {\n if (typeof globalEventListeners[key] !== 'undefined') {\n this.registerProcessor(key, globalEventListeners[key] as any);\n }\n }\n }\n\n // Load persisted events from AsyncStorage\n for (const key of Object.keys(eventsToPersist)) {\n try {\n const persistedEvent = await AsyncStorage.getItem(eventsToPersist[key]);\n if (persistedEvent) {\n const event: { eventName: string; eventPayload: any } =\n JSON.parse(persistedEvent);\n this.pushEvent(event.eventName, event.eventPayload);\n }\n } catch (err) {\n Logger.logError('Error parsing persisted event', err);\n }\n }\n }\n\n pushEvent(eventName: string, payload: MapLike): void {\n Logger.logDbg('EV Push Event:: ', JSON.stringify(payload));\n if (\n eventName === 'set' ||\n eventName === 'persist' ||\n eventName === 'clear' ||\n eventName === 'user_info'\n ) {\n // process regardless - fire and forget for async operations\n this.processQItems(eventName, payload).catch((err) =>\n Logger.logError('Error processing event', err)\n );\n } else {\n if (!this.receivedInitialEvent) {\n // set only if this is not true already\n this.receivedInitialEvent = eventName === this.dlInitEvent;\n this.eventQueue.push([eventName, payload]);\n if (this.isReady && this.receivedInitialEvent) {\n this.ready();\n }\n } else if (!this.isReady) {\n this.eventQueue.push([eventName, payload]);\n } else {\n // fire and forget for async operations\n this.processQItems(eventName, payload).catch((err) =>\n Logger.logError('Error processing event', err)\n );\n }\n }\n }\n\n async processQItems(eventName: string, payload: MapLike): Promise<void> {\n try {\n if (eventName === 'set') {\n this.setDl(payload);\n } else if (eventName === 'persist') {\n await this.storeData(payload?.key, payload?.value);\n } else if (eventName === 'clear') {\n if (Array.isArray(payload) && payload.length > 0) {\n await this.deleteData(payload as string[]);\n }\n } else if (eventName === 'user_info') {\n this.setUserData(payload);\n } else {\n await this.eventProcessor(eventName, payload);\n }\n /* Make sure nothing is written below this line. If you do so, remember to return on error conditions above */\n } catch (err) {\n Logger.logError('Error performing init setup on dl', err);\n }\n }\n\n /**\n * Private Processor for 'set' command object\n */\n setDl(obj: TypedAny | undefined): boolean {\n if (!obj) {\n return false;\n }\n const _tmp = Utils.flattenObject(obj);\n this._masterDataLayer = Object.assign({}, this._masterDataLayer, _tmp);\n return true;\n }\n\n getDl(): TypedAny {\n return this._masterDataLayer;\n }\n\n private setUserData(payload: {\n pid?: string;\n email?: string;\n phone?: string;\n country?: string;\n city?: string;\n state?: string;\n fName?: string;\n lName?: string;\n zip?: string;\n }): void {\n if (\n payload?.zip &&\n payload?.zip?.length > 0 &&\n payload?.zip?.indexOf('-') > -1\n ) {\n payload.zip = payload.zip.split('-')[0].trim();\n }\n\n const uif: any = {};\n this._persistedVars = this._persistedVars || {};\n this._persistedVars.uif = this._persistedVars.uif || {};\n\n if (payload.pid) {\n this._persistedVars.uif.user_pid = payload.pid;\n uif.pid = payload.pid;\n }\n\n if (payload.email) {\n this._persistedVars.uif.user_email = payload.email;\n uif.e = payload.email;\n }\n\n if (payload.phone) {\n this._persistedVars.uif.user_phone = payload.phone;\n uif.p = payload.phone;\n }\n\n if (payload.country) {\n this._persistedVars.uif.user_country = payload.country;\n uif.cy = payload.country;\n }\n\n if (payload.city) {\n this._persistedVars.uif.user_city = payload.city;\n uif.ct = payload.city;\n }\n\n if (payload.state) {\n this._persistedVars.uif.user_state = payload.state;\n uif.st = payload.state;\n }\n\n if (payload.fName) {\n this._persistedVars.uif.fn = payload.fName;\n uif.fn = payload.fName;\n }\n\n if (payload.lName) {\n this._persistedVars.uif.ln = payload.lName;\n uif.ln = payload.lName;\n }\n\n if (payload.zip) {\n this._persistedVars.uif.zip_code = payload.zip;\n uif.z = payload.zip;\n }\n\n if (Object.keys(uif).length > 0) {\n this.storeData('uif', uif);\n }\n }\n\n private async deleteData(chips: string[]): Promise<void> {\n const fullData = await this.getFullData();\n for (const chip of chips) {\n if (typeof chip === 'string') {\n delete fullData[chip];\n }\n }\n await this.storeFullData(fullData);\n }\n\n private async storeData(chip: string, value: any): Promise<void> {\n if (typeof chip !== 'undefined' && typeof value !== 'undefined') {\n const fullData = await this.getFullData();\n fullData[chip] = value;\n await this.storeFullData(fullData);\n this._persistedVars[chip] = value;\n } else {\n Logger.logError('Both key and value are required for persisting data');\n }\n }\n\n private async reloadPersistedVars(): Promise<void> {\n this._persistedVars = await this.getFullData();\n }\n\n private async getFullData(): Promise<MapLike> {\n try {\n const storedData = await AsyncStorage.getItem(this.storageKeyName);\n if (storedData) {\n return JSON.parse(storedData);\n }\n } catch (err) {\n Logger.logError('Error reloading persisted variables', err);\n }\n return {};\n }\n\n private async storeFullData(fullData: MapLike): Promise<void> {\n this._persistedVars = fullData;\n try {\n await AsyncStorage.setItem(this.storageKeyName, JSON.stringify(fullData));\n } catch (err) {\n Logger.logError('Error storing data', err);\n }\n }\n\n // private async getStoredData<T = any>(chip: string, defValue: T): Promise<T> {\n // let value: T;\n // try {\n // const storedData = await AsyncStorage.getItem(this.storageKeyName);\n // if (storedData) {\n // const parsedData = JSON.parse(storedData);\n // value = parsedData[chip];\n // }\n // } catch (err) {\n // Logger.logError('Error parsing stored data', err);\n // }\n // return value ?? defValue;\n // }\n\n /**\n * Private event processor. Idea is that whenever an event is detected, we create a copy of the master data layer,\n * add the event variables, and trigger the event requested when initializing the data layer helper\n * @param eventName\n * @param model\n */\n async eventProcessor(\n eventName: string,\n model: TypedAny | undefined\n ): Promise<void> {\n model = model ?? {};\n\n /**\n * The following If block clears the data layer when the initial event is received.\n * This is done to prevent value carry overs from one page to another in single page apps\n */\n if (eventName === 'reset' || eventName === this.dlInitEvent) {\n this.reset();\n\n // add an init event based uuid to the core data model\n model['page_load_uid'] = getUUIDV4();\n model['is_entry_point'] = this.getIsEntryPointValue();\n if (model['is_entry_point'] === 1) {\n // Note: In React Native, we don't have document.referrer, so we'll use a placeholder\n model['entry_point_referrer'] = '';\n }\n\n this.setDl(model);\n model = undefined;\n }\n\n if (model) {\n model = {\n ev: (model || {}) as any,\n };\n } else {\n model = {};\n }\n\n await this.reloadPersistedVars();\n\n // get persisted values and add them into the event model\n model['p'] = this._persistedVars ?? {};\n\n // generate a unique id for each event automatically\n model['ev._id'] = Utils.getUniqueID();\n\n // add the event ts also for every event\n model['ev._tsMs'] = Date.now();\n\n model['ev._eventName'] = eventName;\n\n model['ev._persistKey'] = eventsToPersist[eventName] || null;\n\n model = Utils.flattenObject(model);\n\n // create a clone of master data layer and merge event model to it\n const _clone = Object.assign({}, this._masterDataLayer, model);\n const eventTs = Date.now();\n\n const eventPayload = JSON.parse(\n JSON.stringify({\n eventName: eventName,\n eventTs: eventTs,\n model: _clone,\n })\n );\n\n // add to state tracker\n this.stateTracker.push(eventPayload);\n\n // trigger an event that can be listened to by other listeners\n Utils.triggerEvent(this.dlEventName, eventPayload);\n\n // see if there are any other registered processors and invoke them\n if (this.eventProcessors[eventName]) {\n for (const processor of this.eventProcessors[eventName]) {\n Utils.safeExecute(processor, eventPayload);\n }\n }\n }\n\n overrideDlInitEvent(eventName: string): string {\n if (eventName && eventName.length > 0) {\n this.dlInitEvent = eventName;\n return 'Dl Init Event Override Successful';\n }\n return 'Dl Init Event Override Failed';\n }\n\n /**\n * Exposed method for registering custom processors for events\n * @param eventType\n * @param fn\n */\n registerProcessor(eventType: string, fn: EventProcessorFn): void {\n if (!eventType || !fn || typeof fn !== 'function') {\n Logger.logError('EventType and Fn are mandatory');\n return;\n }\n if (!this.eventProcessors[eventType]) {\n this.eventProcessors[eventType] = [];\n }\n\n this.eventProcessors[eventType].push(fn);\n }\n\n /**\n * Exposed getter for getting values from data layer\n * @param key\n * @returns {*|undefined}\n */\n get(key: string): MapLike | undefined {\n return this._masterDataLayer[key] || undefined;\n }\n\n getState(): TypedAny[] {\n return this.stateTracker;\n }\n\n hasEventHappened(key: string): boolean {\n return !!this.stateTracker.find((i) => i.eventName === key);\n }\n\n reset(): boolean {\n this._masterDataLayer = {};\n return true;\n }\n\n ready(): void {\n this.isReady = true;\n if (this.receivedInitialEvent) {\n Logger.logDbg('Initial event received: ', this.dlInitEvent);\n // drain queue only if the initial configured event has been received,\n // otherwise mark isReady but dont drain the queue. queue will be drained first when the init\n // event is received\n this.drainQueue().catch((err) =>\n Logger.logError('Error draining queue', err)\n );\n } else {\n Logger.logDbg(\n `Initial event (${this.dlInitEvent}) NOT received. Events will be queued`\n );\n }\n }\n\n async drainQueue(): Promise<void> {\n Logger.logDbg('drainQueue...');\n // create a copy of the array\n const _temp = [...this.eventQueue];\n // clean the array\n this.eventQueue.splice(0, this.eventQueue.length);\n // find the event with dlInit event and execute it first, rest continues\n const initialEventObjectIndex = _temp.findIndex(\n (e) => [e][0]?.[0] === this.dlInitEvent\n );\n if (initialEventObjectIndex > -1) {\n // splice and execute it\n await this.processQItems(\n _temp[initialEventObjectIndex][0],\n _temp[initialEventObjectIndex][1]\n );\n _temp.splice(initialEventObjectIndex, 1);\n }\n // continue with other items\n for (const item of _temp) {\n await this.processQItems(item[0], item[1]);\n }\n }\n\n getIsEntryPointValue(): number {\n // In React Native, we'll use a simple approach for entry point tracking\n // This could be enhanced with proper session storage implementation\n const currentValue = this.isEntryPoint;\n this.isEntryPoint = 0; // Reset after first use\n return currentValue;\n }\n\n resetEntryPointInfo(): void {\n // In React Native, we'll default to entry point = 1 for the first session\n // This could be enhanced with proper referrer tracking if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