@magicpixel/rn-mp-client-sdk 0.12.0 → 1.12.1
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 +6 -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 +6 -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 -10
- 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/network-service.ts +2 -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
|
@@ -4,47 +4,47 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.MpDataLayerHelper = void 0;
|
|
7
|
-
|
|
8
7
|
var _utils = require("../common/utils");
|
|
9
|
-
|
|
10
8
|
var _logger = require("../common/logger");
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
var _asyncStorage = _interopRequireDefault(require("@react-native-async-storage/async-storage"));
|
|
10
|
+
var _nonSecure = require("nanoid/non-secure");
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
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; }
|
|
13
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
14
|
+
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); }
|
|
15
|
+
const eventsToPersist = {
|
|
16
|
+
user_info: '_mpPendingUserInfo',
|
|
17
|
+
mp_purchase: '_mpPendingPurchase'
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// UUID v4 generator for React Native
|
|
21
|
+
const getUUIDV4 = (0, _nonSecure.customAlphabet)('1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 36);
|
|
14
22
|
class MpDataLayerHelper {
|
|
15
|
-
constructor(dlEventName, dlInitMode, dlInitEvent) {
|
|
23
|
+
constructor(dlEventName, dlInitMode, dlInitEvent, storageKeyName = '_mpdls') {
|
|
16
24
|
this.dlEventName = dlEventName;
|
|
17
25
|
this.dlInitMode = dlInitMode;
|
|
18
|
-
|
|
26
|
+
this.storageKeyName = storageKeyName;
|
|
19
27
|
_defineProperty(this, "isReady", false);
|
|
20
|
-
|
|
21
28
|
_defineProperty(this, "_masterDataLayer", {});
|
|
22
|
-
|
|
29
|
+
_defineProperty(this, "_persistedVars", {});
|
|
23
30
|
_defineProperty(this, "eventProcessors", {});
|
|
24
|
-
|
|
25
31
|
_defineProperty(this, "stateTracker", []);
|
|
26
|
-
|
|
27
32
|
_defineProperty(this, "dlInitEvent", void 0);
|
|
28
|
-
|
|
29
33
|
_defineProperty(this, "receivedInitialEvent", false);
|
|
30
|
-
|
|
31
34
|
_defineProperty(this, "eventQueue", []);
|
|
32
|
-
|
|
35
|
+
_defineProperty(this, "isEntryPoint", 0);
|
|
33
36
|
this.dlInitEvent = dlInitEvent;
|
|
34
|
-
|
|
37
|
+
this.resetEntryPointInfo();
|
|
35
38
|
if (this.dlInitMode !== 'manual') {
|
|
36
39
|
this.isReady = true;
|
|
37
40
|
}
|
|
38
|
-
|
|
39
41
|
if (this.isReady) {
|
|
40
42
|
this.ready();
|
|
41
43
|
}
|
|
42
44
|
}
|
|
43
|
-
|
|
44
|
-
init(globalEventListeners) {
|
|
45
|
+
async init(globalEventListeners) {
|
|
45
46
|
// register any global event listeners passed through to the init command
|
|
46
47
|
const globalEventListenerKeys = Object.keys(globalEventListeners || {});
|
|
47
|
-
|
|
48
48
|
if ((globalEventListenerKeys === null || globalEventListenerKeys === void 0 ? void 0 : globalEventListenerKeys.length) > 0) {
|
|
49
49
|
for (const key of globalEventListenerKeys) {
|
|
50
50
|
if (typeof globalEventListeners[key] !== 'undefined') {
|
|
@@ -52,213 +52,336 @@ class MpDataLayerHelper {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
-
}
|
|
56
55
|
|
|
56
|
+
// Load persisted events from AsyncStorage
|
|
57
|
+
for (const key of Object.keys(eventsToPersist)) {
|
|
58
|
+
try {
|
|
59
|
+
const persistedEvent = await _asyncStorage.default.getItem(eventsToPersist[key]);
|
|
60
|
+
if (persistedEvent) {
|
|
61
|
+
const event = JSON.parse(persistedEvent);
|
|
62
|
+
this.pushEvent(event.eventName, event.eventPayload);
|
|
63
|
+
}
|
|
64
|
+
} catch (err) {
|
|
65
|
+
_logger.Logger.logError('Error parsing persisted event', err);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
57
69
|
pushEvent(eventName, payload) {
|
|
58
70
|
_logger.Logger.logDbg('EV Push Event:: ', JSON.stringify(payload));
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
this.processQItems(eventName, payload);
|
|
71
|
+
if (eventName === 'set' || eventName === 'persist' || eventName === 'clear' || eventName === 'user_info') {
|
|
72
|
+
// process regardless - fire and forget for async operations
|
|
73
|
+
this.processQItems(eventName, payload).catch(err => _logger.Logger.logError('Error processing event', err));
|
|
63
74
|
} else {
|
|
64
75
|
if (!this.receivedInitialEvent) {
|
|
65
76
|
// set only if this is not true already
|
|
66
77
|
this.receivedInitialEvent = eventName === this.dlInitEvent;
|
|
67
78
|
this.eventQueue.push([eventName, payload]);
|
|
68
|
-
|
|
69
79
|
if (this.isReady && this.receivedInitialEvent) {
|
|
70
80
|
this.ready();
|
|
71
81
|
}
|
|
72
82
|
} else if (!this.isReady) {
|
|
73
83
|
this.eventQueue.push([eventName, payload]);
|
|
74
84
|
} else {
|
|
75
|
-
|
|
85
|
+
// fire and forget for async operations
|
|
86
|
+
this.processQItems(eventName, payload).catch(err => _logger.Logger.logError('Error processing event', err));
|
|
76
87
|
}
|
|
77
88
|
}
|
|
78
89
|
}
|
|
79
|
-
|
|
80
|
-
processQItems(eventName, payload) {
|
|
90
|
+
async processQItems(eventName, payload) {
|
|
81
91
|
try {
|
|
82
92
|
if (eventName === 'set') {
|
|
83
93
|
this.setDl(payload);
|
|
94
|
+
} else if (eventName === 'persist') {
|
|
95
|
+
await this.storeData(payload === null || payload === void 0 ? void 0 : payload.key, payload === null || payload === void 0 ? void 0 : payload.value);
|
|
96
|
+
} else if (eventName === 'clear') {
|
|
97
|
+
if (Array.isArray(payload) && payload.length > 0) {
|
|
98
|
+
await this.deleteData(payload);
|
|
99
|
+
}
|
|
100
|
+
} else if (eventName === 'user_info') {
|
|
101
|
+
this.setUserData(payload);
|
|
84
102
|
} else {
|
|
85
|
-
this.eventProcessor(eventName, payload);
|
|
103
|
+
await this.eventProcessor(eventName, payload);
|
|
86
104
|
}
|
|
87
105
|
/* Make sure nothing is written below this line. If you do so, remember to return on error conditions above */
|
|
88
|
-
|
|
89
106
|
} catch (err) {
|
|
90
107
|
_logger.Logger.logError('Error performing init setup on dl', err);
|
|
91
108
|
}
|
|
92
109
|
}
|
|
110
|
+
|
|
93
111
|
/**
|
|
94
112
|
* Private Processor for 'set' command object
|
|
95
113
|
*/
|
|
96
|
-
|
|
97
|
-
|
|
98
114
|
setDl(obj) {
|
|
99
115
|
if (!obj) {
|
|
100
116
|
return false;
|
|
101
117
|
}
|
|
102
|
-
|
|
103
118
|
const _tmp = _utils.Utils.flattenObject(obj);
|
|
104
|
-
|
|
105
119
|
this._masterDataLayer = Object.assign({}, this._masterDataLayer, _tmp);
|
|
106
120
|
return true;
|
|
107
121
|
}
|
|
108
|
-
|
|
109
122
|
getDl() {
|
|
110
123
|
return this._masterDataLayer;
|
|
111
124
|
}
|
|
125
|
+
setUserData(payload) {
|
|
126
|
+
var _payload$zip, _payload$zip2;
|
|
127
|
+
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) {
|
|
128
|
+
payload.zip = payload.zip.split('-')[0].trim();
|
|
129
|
+
}
|
|
130
|
+
const uif = {};
|
|
131
|
+
this._persistedVars = this._persistedVars || {};
|
|
132
|
+
this._persistedVars.uif = this._persistedVars.uif || {};
|
|
133
|
+
if (payload.pid) {
|
|
134
|
+
this._persistedVars.uif.user_pid = payload.pid;
|
|
135
|
+
uif.pid = payload.pid;
|
|
136
|
+
}
|
|
137
|
+
if (payload.email) {
|
|
138
|
+
this._persistedVars.uif.user_email = payload.email;
|
|
139
|
+
uif.e = payload.email;
|
|
140
|
+
}
|
|
141
|
+
if (payload.phone) {
|
|
142
|
+
this._persistedVars.uif.user_phone = payload.phone;
|
|
143
|
+
uif.p = payload.phone;
|
|
144
|
+
}
|
|
145
|
+
if (payload.country) {
|
|
146
|
+
this._persistedVars.uif.user_country = payload.country;
|
|
147
|
+
uif.cy = payload.country;
|
|
148
|
+
}
|
|
149
|
+
if (payload.city) {
|
|
150
|
+
this._persistedVars.uif.user_city = payload.city;
|
|
151
|
+
uif.ct = payload.city;
|
|
152
|
+
}
|
|
153
|
+
if (payload.state) {
|
|
154
|
+
this._persistedVars.uif.user_state = payload.state;
|
|
155
|
+
uif.st = payload.state;
|
|
156
|
+
}
|
|
157
|
+
if (payload.fName) {
|
|
158
|
+
this._persistedVars.uif.fn = payload.fName;
|
|
159
|
+
uif.fn = payload.fName;
|
|
160
|
+
}
|
|
161
|
+
if (payload.lName) {
|
|
162
|
+
this._persistedVars.uif.ln = payload.lName;
|
|
163
|
+
uif.ln = payload.lName;
|
|
164
|
+
}
|
|
165
|
+
if (payload.zip) {
|
|
166
|
+
this._persistedVars.uif.zip_code = payload.zip;
|
|
167
|
+
uif.z = payload.zip;
|
|
168
|
+
}
|
|
169
|
+
if (Object.keys(uif).length > 0) {
|
|
170
|
+
this.storeData('uif', uif);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
async deleteData(chips) {
|
|
174
|
+
const fullData = await this.getFullData();
|
|
175
|
+
for (const chip of chips) {
|
|
176
|
+
if (typeof chip === 'string') {
|
|
177
|
+
delete fullData[chip];
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
await this.storeFullData(fullData);
|
|
181
|
+
}
|
|
182
|
+
async storeData(chip, value) {
|
|
183
|
+
if (typeof chip !== 'undefined' && typeof value !== 'undefined') {
|
|
184
|
+
const fullData = await this.getFullData();
|
|
185
|
+
fullData[chip] = value;
|
|
186
|
+
await this.storeFullData(fullData);
|
|
187
|
+
this._persistedVars[chip] = value;
|
|
188
|
+
} else {
|
|
189
|
+
_logger.Logger.logError('Both key and value are required for persisting data');
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
async reloadPersistedVars() {
|
|
193
|
+
this._persistedVars = await this.getFullData();
|
|
194
|
+
}
|
|
195
|
+
async getFullData() {
|
|
196
|
+
try {
|
|
197
|
+
const storedData = await _asyncStorage.default.getItem(this.storageKeyName);
|
|
198
|
+
if (storedData) {
|
|
199
|
+
return JSON.parse(storedData);
|
|
200
|
+
}
|
|
201
|
+
} catch (err) {
|
|
202
|
+
_logger.Logger.logError('Error reloading persisted variables', err);
|
|
203
|
+
}
|
|
204
|
+
return {};
|
|
205
|
+
}
|
|
206
|
+
async storeFullData(fullData) {
|
|
207
|
+
this._persistedVars = fullData;
|
|
208
|
+
try {
|
|
209
|
+
await _asyncStorage.default.setItem(this.storageKeyName, JSON.stringify(fullData));
|
|
210
|
+
} catch (err) {
|
|
211
|
+
_logger.Logger.logError('Error storing data', err);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// private async getStoredData<T = any>(chip: string, defValue: T): Promise<T> {
|
|
216
|
+
// let value: T;
|
|
217
|
+
// try {
|
|
218
|
+
// const storedData = await AsyncStorage.getItem(this.storageKeyName);
|
|
219
|
+
// if (storedData) {
|
|
220
|
+
// const parsedData = JSON.parse(storedData);
|
|
221
|
+
// value = parsedData[chip];
|
|
222
|
+
// }
|
|
223
|
+
// } catch (err) {
|
|
224
|
+
// Logger.logError('Error parsing stored data', err);
|
|
225
|
+
// }
|
|
226
|
+
// return value ?? defValue;
|
|
227
|
+
// }
|
|
228
|
+
|
|
112
229
|
/**
|
|
113
230
|
* Private event processor. Idea is that whenever an event is detected, we create a copy of the master data layer,
|
|
114
231
|
* add the event variables, and trigger the event requested when initializing the data layer helper
|
|
115
232
|
* @param eventName
|
|
116
233
|
* @param model
|
|
117
234
|
*/
|
|
235
|
+
async eventProcessor(eventName, model) {
|
|
236
|
+
model = model ?? {};
|
|
118
237
|
|
|
119
|
-
|
|
120
|
-
eventProcessor(eventName, model) {
|
|
121
238
|
/**
|
|
122
239
|
* The following If block clears the data layer when the initial event is received.
|
|
123
240
|
* This is done to prevent value carry overs from one page to another in single page apps
|
|
124
241
|
*/
|
|
125
242
|
if (eventName === 'reset' || eventName === this.dlInitEvent) {
|
|
126
243
|
this.reset();
|
|
244
|
+
|
|
245
|
+
// add an init event based uuid to the core data model
|
|
246
|
+
model['page_load_uid'] = getUUIDV4();
|
|
247
|
+
model['is_entry_point'] = this.getIsEntryPointValue();
|
|
248
|
+
if (model['is_entry_point'] === 1) {
|
|
249
|
+
// Note: In React Native, we don't have document.referrer, so we'll use a placeholder
|
|
250
|
+
model['entry_point_referrer'] = '';
|
|
251
|
+
}
|
|
127
252
|
this.setDl(model);
|
|
128
253
|
model = undefined;
|
|
129
254
|
}
|
|
130
|
-
|
|
131
255
|
if (model) {
|
|
132
256
|
model = {
|
|
133
257
|
ev: model || {}
|
|
134
258
|
};
|
|
135
259
|
} else {
|
|
136
260
|
model = {};
|
|
137
|
-
}
|
|
261
|
+
}
|
|
262
|
+
await this.reloadPersistedVars();
|
|
138
263
|
|
|
264
|
+
// get persisted values and add them into the event model
|
|
265
|
+
model['p'] = this._persistedVars ?? {};
|
|
139
266
|
|
|
140
|
-
|
|
267
|
+
// generate a unique id for each event automatically
|
|
268
|
+
model['ev._id'] = _utils.Utils.getUniqueID();
|
|
141
269
|
|
|
270
|
+
// add the event ts also for every event
|
|
142
271
|
model['ev._tsMs'] = Date.now();
|
|
143
272
|
model['ev._eventName'] = eventName;
|
|
144
|
-
model =
|
|
273
|
+
model['ev._persistKey'] = eventsToPersist[eventName] || null;
|
|
274
|
+
model = _utils.Utils.flattenObject(model);
|
|
145
275
|
|
|
276
|
+
// create a clone of master data layer and merge event model to it
|
|
146
277
|
const _clone = Object.assign({}, this._masterDataLayer, model);
|
|
147
|
-
|
|
148
278
|
const eventTs = Date.now();
|
|
149
|
-
const eventPayload = {
|
|
279
|
+
const eventPayload = JSON.parse(JSON.stringify({
|
|
150
280
|
eventName: eventName,
|
|
151
281
|
eventTs: eventTs,
|
|
152
282
|
model: _clone
|
|
153
|
-
};
|
|
283
|
+
}));
|
|
154
284
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
_utils.Utils.triggerEvent(this.dlEventName, eventPayload); // see if there are any other registered processors and invoke them
|
|
285
|
+
// add to state tracker
|
|
286
|
+
this.stateTracker.push(eventPayload);
|
|
158
287
|
|
|
288
|
+
// trigger an event that can be listened to by other listeners
|
|
289
|
+
_utils.Utils.triggerEvent(this.dlEventName, eventPayload);
|
|
159
290
|
|
|
291
|
+
// see if there are any other registered processors and invoke them
|
|
160
292
|
if (this.eventProcessors[eventName]) {
|
|
161
293
|
for (const processor of this.eventProcessors[eventName]) {
|
|
162
294
|
_utils.Utils.safeExecute(processor, eventPayload);
|
|
163
295
|
}
|
|
164
296
|
}
|
|
165
297
|
}
|
|
166
|
-
|
|
167
298
|
overrideDlInitEvent(eventName) {
|
|
168
299
|
if (eventName && eventName.length > 0) {
|
|
169
300
|
this.dlInitEvent = eventName;
|
|
170
301
|
return 'Dl Init Event Override Successful';
|
|
171
302
|
}
|
|
172
|
-
|
|
173
303
|
return 'Dl Init Event Override Failed';
|
|
174
304
|
}
|
|
305
|
+
|
|
175
306
|
/**
|
|
176
307
|
* Exposed method for registering custom processors for events
|
|
177
308
|
* @param eventType
|
|
178
309
|
* @param fn
|
|
179
310
|
*/
|
|
180
|
-
|
|
181
|
-
|
|
182
311
|
registerProcessor(eventType, fn) {
|
|
183
312
|
if (!eventType || !fn || typeof fn !== 'function') {
|
|
184
313
|
_logger.Logger.logError('EventType and Fn are mandatory');
|
|
185
|
-
|
|
186
314
|
return;
|
|
187
315
|
}
|
|
188
|
-
|
|
189
316
|
if (!this.eventProcessors[eventType]) {
|
|
190
317
|
this.eventProcessors[eventType] = [];
|
|
191
318
|
}
|
|
192
|
-
|
|
193
319
|
this.eventProcessors[eventType].push(fn);
|
|
194
320
|
}
|
|
321
|
+
|
|
195
322
|
/**
|
|
196
323
|
* Exposed getter for getting values from data layer
|
|
197
324
|
* @param key
|
|
198
325
|
* @returns {*|undefined}
|
|
199
326
|
*/
|
|
200
|
-
|
|
201
|
-
|
|
202
327
|
get(key) {
|
|
203
328
|
return this._masterDataLayer[key] || undefined;
|
|
204
329
|
}
|
|
205
|
-
|
|
206
330
|
getState() {
|
|
207
331
|
return this.stateTracker;
|
|
208
332
|
}
|
|
209
|
-
|
|
210
333
|
hasEventHappened(key) {
|
|
211
334
|
return !!this.stateTracker.find(i => i.eventName === key);
|
|
212
335
|
}
|
|
213
|
-
|
|
214
336
|
reset() {
|
|
215
337
|
this._masterDataLayer = {};
|
|
216
338
|
return true;
|
|
217
339
|
}
|
|
218
|
-
|
|
219
340
|
ready() {
|
|
220
341
|
this.isReady = true;
|
|
221
|
-
|
|
222
342
|
if (this.receivedInitialEvent) {
|
|
223
|
-
_logger.Logger.logDbg('Initial event received: ', this.dlInitEvent);
|
|
343
|
+
_logger.Logger.logDbg('Initial event received: ', this.dlInitEvent);
|
|
344
|
+
// drain queue only if the initial configured event has been received,
|
|
224
345
|
// otherwise mark isReady but dont drain the queue. queue will be drained first when the init
|
|
225
346
|
// event is received
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
this.drainQueue();
|
|
347
|
+
this.drainQueue().catch(err => _logger.Logger.logError('Error draining queue', err));
|
|
229
348
|
} else {
|
|
230
349
|
_logger.Logger.logDbg(`Initial event (${this.dlInitEvent}) NOT received. Events will be queued`);
|
|
231
350
|
}
|
|
232
351
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
this.eventQueue.splice(0, this.eventQueue.length); // find the event with dlInit event and execute it first, rest continues
|
|
241
|
-
|
|
352
|
+
async drainQueue() {
|
|
353
|
+
_logger.Logger.logDbg('drainQueue...');
|
|
354
|
+
// create a copy of the array
|
|
355
|
+
const _temp = [...this.eventQueue];
|
|
356
|
+
// clean the array
|
|
357
|
+
this.eventQueue.splice(0, this.eventQueue.length);
|
|
358
|
+
// find the event with dlInit event and execute it first, rest continues
|
|
242
359
|
const initialEventObjectIndex = _temp.findIndex(e => {
|
|
243
360
|
var _;
|
|
244
|
-
|
|
245
361
|
return ((_ = [e][0]) === null || _ === void 0 ? void 0 : _[0]) === this.dlInitEvent;
|
|
246
362
|
});
|
|
247
|
-
|
|
248
363
|
if (initialEventObjectIndex > -1) {
|
|
249
364
|
// splice and execute it
|
|
250
|
-
this.processQItems(_temp[initialEventObjectIndex][0], _temp[initialEventObjectIndex][1]);
|
|
251
|
-
|
|
365
|
+
await this.processQItems(_temp[initialEventObjectIndex][0], _temp[initialEventObjectIndex][1]);
|
|
252
366
|
_temp.splice(initialEventObjectIndex, 1);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
|
|
367
|
+
}
|
|
368
|
+
// continue with other items
|
|
256
369
|
for (const item of _temp) {
|
|
257
|
-
this.processQItems(item[0], item[1]);
|
|
370
|
+
await this.processQItems(item[0], item[1]);
|
|
258
371
|
}
|
|
259
372
|
}
|
|
260
|
-
|
|
373
|
+
getIsEntryPointValue() {
|
|
374
|
+
// In React Native, we'll use a simple approach for entry point tracking
|
|
375
|
+
// This could be enhanced with proper session storage implementation
|
|
376
|
+
const currentValue = this.isEntryPoint;
|
|
377
|
+
this.isEntryPoint = 0; // Reset after first use
|
|
378
|
+
return currentValue;
|
|
379
|
+
}
|
|
380
|
+
resetEntryPointInfo() {
|
|
381
|
+
// In React Native, we'll default to entry point = 1 for the first session
|
|
382
|
+
// This could be enhanced with proper referrer tracking if needed
|
|
383
|
+
this.isEntryPoint = 1;
|
|
384
|
+
}
|
|
261
385
|
}
|
|
262
|
-
|
|
263
386
|
exports.MpDataLayerHelper = MpDataLayerHelper;
|
|
264
387
|
//# sourceMappingURL=eedl.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["MpDataLayerHelper","constructor","dlEventName","dlInitMode","dlInitEvent","isReady","ready","init","globalEventListeners","globalEventListenerKeys","Object","keys","length","key","registerProcessor","pushEvent","eventName","payload","Logger","logDbg","JSON","stringify","processQItems","receivedInitialEvent","eventQueue","push","setDl","eventProcessor","err","logError","obj","_tmp","Utils","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;;AAEA;;;;AAEO,MAAMA,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,EAUr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,CAMjB;;IACA,MAAMmD,uBAAuB,GAAGF,KAAK,CAACG,SAAN,CAC7BC,CAAD;MAAA;;MAAA,OAAO,OAACA,CAAD,EAAI,CAAJ,yCAAS,CAAT,OAAgB,KAAK7D,WAA5B;IAAA,CAD8B,CAAhC;;IAGA,IAAI2D,uBAAuB,GAAG,CAAC,CAA/B,EAAkC;MAChC;MACA,KAAKzC,aAAL,CACEuC,KAAK,CAACE,uBAAD,CAAL,CAA+B,CAA/B,CADF,EAEEF,KAAK,CAACE,uBAAD,CAAL,CAA+B,CAA/B,CAFF;;MAIAF,KAAK,CAACC,MAAN,CAAaC,uBAAb,EAAsC,CAAtC;IACD,CAjBgB,CAkBjB;;;IACA,KAAK,MAAMG,IAAX,IAAmBL,KAAnB,EAA0B;MACxB,KAAKvC,aAAL,CAAmB4C,IAAI,CAAC,CAAD,CAAvB,EAA4BA,IAAI,CAAC,CAAD,CAAhC;IACD;EACF;;AAtO4B"}
|
|
1
|
+
{"version":3,"names":["_utils","require","_logger","_asyncStorage","_interopRequireDefault","_nonSecure","e","__esModule","default","_defineProperty","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","eventsToPersist","user_info","mp_purchase","getUUIDV4","customAlphabet","MpDataLayerHelper","constructor","dlEventName","dlInitMode","dlInitEvent","storageKeyName","resetEntryPointInfo","isReady","ready","init","globalEventListeners","globalEventListenerKeys","keys","length","key","registerProcessor","persistedEvent","AsyncStorage","getItem","event","JSON","parse","pushEvent","eventName","eventPayload","err","Logger","logError","payload","logDbg","stringify","processQItems","catch","receivedInitialEvent","eventQueue","push","setDl","storeData","Array","isArray","deleteData","setUserData","eventProcessor","obj","_tmp","Utils","flattenObject","_masterDataLayer","assign","getDl","_payload$zip","_payload$zip2","zip","indexOf","split","trim","uif","_persistedVars","pid","user_pid","email","user_email","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","drainQueue","_temp","splice","initialEventObjectIndex","findIndex","_","item","currentValue","isEntryPoint","exports"],"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 needed\n this.isEntryPoint = 1;\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,aAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,UAAA,GAAAJ,OAAA;AAAmD,SAAAG,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAG,gBAAAH,CAAA,EAAAI,CAAA,EAAAC,CAAA,YAAAD,CAAA,GAAAE,cAAA,CAAAF,CAAA,MAAAJ,CAAA,GAAAO,MAAA,CAAAC,cAAA,CAAAR,CAAA,EAAAI,CAAA,IAAAK,KAAA,EAAAJ,CAAA,EAAAK,UAAA,MAAAC,YAAA,MAAAC,QAAA,UAAAZ,CAAA,CAAAI,CAAA,IAAAC,CAAA,EAAAL,CAAA;AAAA,SAAAM,eAAAD,CAAA,QAAAQ,CAAA,GAAAC,YAAA,CAAAT,CAAA,uCAAAQ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