apxor-qe 1.1.9-qa → 1.1.10-qa.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.
@@ -0,0 +1,1403 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('apxor')) :
3
+ typeof define === 'function' && define.amd ? define(['apxor'], factory) :
4
+ (global = global || self, global['apxor-qe'] = factory(global.Apxor));
5
+ }(this, function (Apxor) { 'use strict';
6
+
7
+ Apxor = Apxor && Apxor.hasOwnProperty('default') ? Apxor['default'] : Apxor;
8
+
9
+ function ownKeys(object, enumerableOnly) {
10
+ var keys = Object.keys(object);
11
+ if (Object.getOwnPropertySymbols) {
12
+ var symbols = Object.getOwnPropertySymbols(object);
13
+ enumerableOnly && (symbols = symbols.filter(function (sym) {
14
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
15
+ })), keys.push.apply(keys, symbols);
16
+ }
17
+ return keys;
18
+ }
19
+ function _objectSpread2(target) {
20
+ for (var i = 1; i < arguments.length; i++) {
21
+ var source = null != arguments[i] ? arguments[i] : {};
22
+ i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
23
+ _defineProperty(target, key, source[key]);
24
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
25
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
26
+ });
27
+ }
28
+ return target;
29
+ }
30
+ function _typeof(obj) {
31
+ "@babel/helpers - typeof";
32
+
33
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
34
+ return typeof obj;
35
+ } : function (obj) {
36
+ return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
37
+ }, _typeof(obj);
38
+ }
39
+ function _classCallCheck(instance, Constructor) {
40
+ if (!(instance instanceof Constructor)) {
41
+ throw new TypeError("Cannot call a class as a function");
42
+ }
43
+ }
44
+ function _defineProperties(target, props) {
45
+ for (var i = 0; i < props.length; i++) {
46
+ var descriptor = props[i];
47
+ descriptor.enumerable = descriptor.enumerable || false;
48
+ descriptor.configurable = true;
49
+ if ("value" in descriptor) descriptor.writable = true;
50
+ Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
51
+ }
52
+ }
53
+ function _createClass(Constructor, protoProps, staticProps) {
54
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
55
+ if (staticProps) _defineProperties(Constructor, staticProps);
56
+ Object.defineProperty(Constructor, "prototype", {
57
+ writable: false
58
+ });
59
+ return Constructor;
60
+ }
61
+ function _defineProperty(obj, key, value) {
62
+ key = _toPropertyKey(key);
63
+ if (key in obj) {
64
+ Object.defineProperty(obj, key, {
65
+ value: value,
66
+ enumerable: true,
67
+ configurable: true,
68
+ writable: true
69
+ });
70
+ } else {
71
+ obj[key] = value;
72
+ }
73
+ return obj;
74
+ }
75
+ function _toConsumableArray(arr) {
76
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
77
+ }
78
+ function _arrayWithoutHoles(arr) {
79
+ if (Array.isArray(arr)) return _arrayLikeToArray(arr);
80
+ }
81
+ function _iterableToArray(iter) {
82
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
83
+ }
84
+ function _unsupportedIterableToArray(o, minLen) {
85
+ if (!o) return;
86
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
87
+ var n = Object.prototype.toString.call(o).slice(8, -1);
88
+ if (n === "Object" && o.constructor) n = o.constructor.name;
89
+ if (n === "Map" || n === "Set") return Array.from(o);
90
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
91
+ }
92
+ function _arrayLikeToArray(arr, len) {
93
+ if (len == null || len > arr.length) len = arr.length;
94
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
95
+ return arr2;
96
+ }
97
+ function _nonIterableSpread() {
98
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
99
+ }
100
+ function _toPrimitive(input, hint) {
101
+ if (typeof input !== "object" || input === null) return input;
102
+ var prim = input[Symbol.toPrimitive];
103
+ if (prim !== undefined) {
104
+ var res = prim.call(input, hint || "default");
105
+ if (typeof res !== "object") return res;
106
+ throw new TypeError("@@toPrimitive must return a primitive value.");
107
+ }
108
+ return (hint === "string" ? String : Number)(input);
109
+ }
110
+ function _toPropertyKey(arg) {
111
+ var key = _toPrimitive(arg, "string");
112
+ return typeof key === "symbol" ? key : String(key);
113
+ }
114
+
115
+ /**
116
+ *
117
+ * @param term
118
+ * @returns {boolean}
119
+ */
120
+ var isNull = function isNull(term) {
121
+ return term === null;
122
+ };
123
+
124
+ /**
125
+ *
126
+ * @param term
127
+ * @returns {boolean}
128
+ */
129
+ var isDefined = function isDefined(term) {
130
+ return typeof term !== "undefined" && !isNull(term);
131
+ };
132
+ var isFunction = function isFunction(fn) {
133
+ return typeof fn === "function";
134
+ };
135
+ var b64_table = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
136
+ function b64_decode(data) {
137
+ var o1,
138
+ o2,
139
+ o3,
140
+ h1,
141
+ h2,
142
+ h3,
143
+ h4,
144
+ bits,
145
+ i = 0,
146
+ result = [];
147
+ if (!data) {
148
+ return data;
149
+ }
150
+ data += "";
151
+ do {
152
+ h1 = b64_table.indexOf(data.charAt(i++));
153
+ h2 = b64_table.indexOf(data.charAt(i++));
154
+ h3 = b64_table.indexOf(data.charAt(i++));
155
+ h4 = b64_table.indexOf(data.charAt(i++));
156
+ bits = h1 << 18 | h2 << 12 | h3 << 6 | h4;
157
+ o1 = bits >> 16 & 0xff;
158
+ o2 = bits >> 8 & 0xff;
159
+ o3 = bits & 0xff;
160
+ result.push(o1);
161
+ if (h3 !== 64) {
162
+ result.push(o2);
163
+ if (h4 !== 64) {
164
+ result.push(o3);
165
+ }
166
+ }
167
+ } while (i < data.length);
168
+ return result;
169
+ }
170
+ function keyCharAt(key, i) {
171
+ return key.charCodeAt(Math.floor(i % key.length));
172
+ }
173
+ function xor_decrypt(key, data) {
174
+ return Array.from(data).map(function (c, i) {
175
+ return String.fromCharCode(c ^ keyCharAt(key, i));
176
+ }).join("");
177
+ }
178
+ var decode = function decode(key, data) {
179
+ data = b64_decode(data);
180
+ return xor_decrypt(key, data);
181
+ };
182
+ var generateKey = function generateKey(key) {
183
+ switch (key) {
184
+ case "app_event":
185
+ return "AE";
186
+ case "client_event":
187
+ return "CE";
188
+ case "activity_time":
189
+ return "AE";
190
+ case "activity_event":
191
+ return "AE";
192
+ }
193
+ return "Unknown";
194
+ };
195
+ var toUpperCase = function toUpperCase(key) {
196
+ return key.toUpperCase();
197
+ };
198
+ var compare = function compare(actual, expected, operator) {
199
+ switch (operator) {
200
+ case "EQ":
201
+ return actual === expected;
202
+ case "GT":
203
+ return actual > expected;
204
+ case "GTE":
205
+ return actual >= expected;
206
+ case "LT":
207
+ return actual < expected;
208
+ case "LTE":
209
+ return actual <= expected;
210
+ case "NEQ":
211
+ return actual !== expected;
212
+ case "R":
213
+ var regex = regExpFromString(expected);
214
+ return regex.test(actual);
215
+ default:
216
+ return false;
217
+ }
218
+ };
219
+ var regExpFromString = function regExpFromString(input) {
220
+ var flags = input.replace(/.*\/([gimuy]*)$/, "$1");
221
+ if (flags === input) flags = "";
222
+ var pattern = flags ? input.replace(new RegExp("^/(.*?)/" + flags + "$"), "$1") : input;
223
+ return new RegExp(pattern, flags);
224
+ };
225
+
226
+ /**
227
+ * @function getDateInDDMMYYYY
228
+ * @description Returns the current date in DD/MM/YYYY Format
229
+ * @returns {string}
230
+ */
231
+ var getDateInDDMMYYYY = function getDateInDDMMYYYY() {
232
+ var currentDate = new Date();
233
+ var dateDDMMYYYY = currentDate.getDate() + "/" + currentDate.getMonth() + "/" + currentDate.getFullYear();
234
+ return dateDDMMYYYY;
235
+ };
236
+
237
+ var Logger = window.ApxorLogger;
238
+ var Audience = /*#__PURE__*/_createClass(function Audience() {
239
+ var _this = this;
240
+ _classCallCheck(this, Audience);
241
+ _defineProperty(this, "jyXB", "ALL");
242
+ _defineProperty(this, "lZth", []);
243
+ _defineProperty(this, "iosT", []);
244
+ _defineProperty(this, "parse", function () {
245
+ var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
246
+ try {
247
+ _this.jyXB = config.audience.audience_type;
248
+ _this.lZth = config.audience.attributes.user;
249
+ _this.iosT = config.audience.attributes.session;
250
+ if (!Array.isArray(_this.lZth) || !Array.isArray(_this.iosT)) {
251
+ Logger.error("No attributes");
252
+ return false;
253
+ }
254
+ } catch (error) {
255
+ Logger.error(error);
256
+ return false;
257
+ }
258
+ return true;
259
+ });
260
+ _defineProperty(this, "validate", function (user, session) {
261
+ var status = true;
262
+ if (_this.jyXB === "FTU") {
263
+ status = Apxor.getController().getSessionInfo().is_first_session;
264
+ }
265
+ return status && _this.OYnt(user, _this.lZth) && _this.OYnt(session, _this.iosT);
266
+ });
267
+ _defineProperty(this, "OYnt", function (attributes, expected) {
268
+ var length = expected.length;
269
+ var status = true;
270
+ try {
271
+ var _loop = function _loop() {
272
+ var item = expected[index];
273
+ if (!attributes[item.name] || status === false) {
274
+ return {
275
+ v: false
276
+ };
277
+ }
278
+ var operator = item.operator;
279
+ var type = item.type;
280
+ var values = item.value.map(function (value) {
281
+ if (type === "s") {
282
+ return value;
283
+ } else if (type === "l") {
284
+ return parseInt(value);
285
+ } else if (type === "f") {
286
+ return parseFloat(value);
287
+ }
288
+ });
289
+ var loggedValues = [];
290
+ if (Array.isArray(attributes[item.name])) {
291
+ loggedValues = attributes[item.name];
292
+ } else {
293
+ loggedValues = [attributes[item.name]];
294
+ }
295
+ var match = loggedValues.some(function (loggedValue) {
296
+ return values.some(function (configValue) {
297
+ return compare(loggedValue, configValue, operator);
298
+ });
299
+ });
300
+ status = status && match;
301
+ };
302
+ for (var index = 0; index < length; index++) {
303
+ var _ret = _loop();
304
+ if (_typeof(_ret) === "object") return _ret.v;
305
+ }
306
+ } catch (error) {
307
+ Logger.error(error);
308
+ status = false;
309
+ }
310
+ return status;
311
+ });
312
+ });
313
+
314
+ var Logger$1 = window.ApxorLogger;
315
+ var Frequency = /*#__PURE__*/_createClass(function Frequency() {
316
+ var _this = this;
317
+ _classCallCheck(this, Frequency);
318
+ _defineProperty(this, "KkoD", 0);
319
+ _defineProperty(this, "mBSu", 0);
320
+ _defineProperty(this, "hDCI", "SESSION");
321
+ _defineProperty(this, "moQB", 0);
322
+ _defineProperty(this, "PQZP", 0);
323
+ _defineProperty(this, "xmdK", 0);
324
+ _defineProperty(this, "parse", function () {
325
+ var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
326
+ try {
327
+ _this.KkoD = config.frequency.count;
328
+ _this.xmdK = _this.KkoD;
329
+ _this.mBSu = config.frequency.time_interval;
330
+ _this.hDCI = config.frequency.validity;
331
+ _this.PQZP = config.frequency.ses_lmt;
332
+ _this._dayCount = config.frequency.day_lmt;
333
+ // let data = Apxor.getController().getFromStorage(QE_STATE);
334
+ // let qe_state = JSON.parse(decode(Apxor.getSiteId(), data));
335
+ var qe_state = CE.getInstance().getQeState();
336
+ if (!isDefined(qe_state) || !isDefined(qe_state[config._id])) return true;
337
+ if (_this.hDCI === "SESSION") {
338
+ _this.KkoD = parseInt(_this.KkoD) - parseInt(qe_state[config._id]["SESSION"]);
339
+ if (_this.KkoD <= 0) {
340
+ console.warn("Max count limit reached for session:" + config._id);
341
+ return false;
342
+ }
343
+ } else if (_this.hDCI === "OVERALL") {
344
+ _this.KkoD = parseInt(_this.KkoD) - parseInt(qe_state[config._id]["OVERALL"]);
345
+ if (_this.KkoD <= 0) {
346
+ console.warn("Max count limit reached for overall:" + config._id);
347
+ return false;
348
+ }
349
+ } else {
350
+ Logger$1.info("Invalid config.");
351
+ return false;
352
+ }
353
+ } catch (error) {
354
+ Logger$1.error(error);
355
+ return false;
356
+ }
357
+ return true;
358
+ });
359
+ _defineProperty(this, "lSfk", function () {
360
+ _this.KkoD = _this.KkoD - 1;
361
+ });
362
+ _defineProperty(this, "getFrequencyCount", function () {
363
+ return _this.KkoD;
364
+ });
365
+ _defineProperty(this, "REfq", function () {
366
+ if (_this.hDCI === "SESSION") {
367
+ _this.KkoD = _this.xmdK;
368
+ Logger$1.info("Campaign Limit reset");
369
+ }
370
+ });
371
+ /**
372
+ * @function JglD
373
+ * @description Validates if the campaign count is with in the limits set in the config.
374
+ * @param {string} Config id
375
+ * @returns {boolean} true - If the Campaign limits are not reached
376
+ * false - Otherwise
377
+ */
378
+ _defineProperty(this, "JglD", function (id) {
379
+ try {
380
+ if (_this.KkoD <= 0) {
381
+ return false;
382
+ }
383
+
384
+ // let data = Apxor.getController().getFromStorage(QE_STATE);
385
+ // let qe_state = JSON.parse(decode(Apxor.getSiteId(), data));
386
+ var qe_state = CE.getInstance().getQeState();
387
+ //If the frequency counts are not stored no validity checks are needed.
388
+ if (!isDefined(qe_state) || !isDefined(qe_state[id])) return true;
389
+
390
+ //If the config has a session count limit set
391
+ if (_this.PQZP !== 0) {
392
+ var sessionCountInConfig = parseInt(_this.PQZP);
393
+ var thisSessionCount = parseInt(qe_state[id]["SESSION"]);
394
+ if (sessionCountInConfig - thisSessionCount <= 0) {
395
+ return false;
396
+ }
397
+ }
398
+
399
+ //If the config has a day count limit set
400
+ if (_this._dayCount !== 0) {
401
+ var _qe_state$id;
402
+ var date = getDateInDDMMYYYY();
403
+ var dayCountInConfig = parseInt(_this._dayCount);
404
+ var thisDayCount = parseInt(((_qe_state$id = qe_state[id]) === null || _qe_state$id === void 0 ? void 0 : _qe_state$id.DATES[date]) || 0);
405
+ if (dayCountInConfig - thisDayCount <= 0) {
406
+ return false;
407
+ }
408
+ }
409
+ } catch (e) {
410
+ Logger$1.error("Error validating the frequency:" + e);
411
+ }
412
+ return true;
413
+ });
414
+ });
415
+
416
+ var Meta = /*#__PURE__*/_createClass(function Meta() {
417
+ var _this = this;
418
+ _classCallCheck(this, Meta);
419
+ _defineProperty(this, "yaFV", "");
420
+ _defineProperty(this, "jyXB", "");
421
+ _defineProperty(this, "parse", function () {
422
+ var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
423
+ try {
424
+ var _config$meta;
425
+ _this.yaFV = config.meta.name;
426
+ _this.jyXB = config.meta.type;
427
+ _this._only_context = config.meta.only_context;
428
+ _this._attr = ((_config$meta = config.meta) === null || _config$meta === void 0 ? void 0 : _config$meta.attr) || {};
429
+ } catch (error) {
430
+ window.ApxorLogger.error(error);
431
+ return false;
432
+ }
433
+ return true;
434
+ });
435
+ });
436
+
437
+ var Logger$2 = window.ApxorLogger;
438
+ var Validity = /*#__PURE__*/_createClass(function Validity() {
439
+ var _this = this;
440
+ _classCallCheck(this, Validity);
441
+ _defineProperty(this, "LKPg", -1);
442
+ _defineProperty(this, "rbaj", -1);
443
+ _defineProperty(this, "aRKQ", -1);
444
+ _defineProperty(this, "kDES", -1);
445
+ _defineProperty(this, "EGEc", false);
446
+ _defineProperty(this, "parse", function () {
447
+ var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
448
+ try {
449
+ if (isNaN(Date.parse(config.validity.start_date)) || isNaN(Date.parse(config.validity.end_date))) {
450
+ Logger$2.error("Not valid dates");
451
+ return false;
452
+ }
453
+ _this.LKPg = Date.parse(config.validity.start_date);
454
+ _this.rbaj = Date.parse(config.validity.end_date);
455
+ if (isDefined(config.time_limits_in_day)) {
456
+ _this.EGEc = config.time_limits_in_day;
457
+ if (_this.EGEc && isDefined(config.time_limits)) {
458
+ var currentDate = new Date().toISOString().split("T")[0];
459
+ _this.aRKQ = Date.parse(currentDate + "T" + config.time_limits.start_time + ".000Z");
460
+ _this.kDES = Date.parse(currentDate + "T" + config.time_limits.end_time + ".000Z");
461
+
462
+ // If invalid format is passed, return false
463
+ if (isNaN(_this.aRKQ) || isNaN(_this.kDES)) {
464
+ Logger$2.error("Not valid times");
465
+ return false;
466
+ }
467
+ }
468
+ }
469
+ } catch (error) {
470
+ Logger$2.error(error);
471
+ return false;
472
+ }
473
+ return true;
474
+ });
475
+ _defineProperty(this, "validate", function () {
476
+ var currentTime = Date.now();
477
+ if (currentTime > _this.LKPg && currentTime < _this.rbaj) {
478
+ return !_this.EGEc || currentTime >= _this.aRKQ && currentTime <= _this.kDES;
479
+ }
480
+ return false;
481
+ });
482
+ });
483
+
484
+ var Details = /*#__PURE__*/_createClass(function Details() {
485
+ var _this = this;
486
+ _classCallCheck(this, Details);
487
+ _defineProperty(this, "yaFV", "");
488
+ _defineProperty(this, "GizD", {});
489
+ _defineProperty(this, "parse", function () {
490
+ var details = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
491
+ try {
492
+ _this.yaFV = details.name;
493
+ _this.GizD = details.additional_info;
494
+ } catch (error) {
495
+ return false;
496
+ }
497
+ return true;
498
+ });
499
+ });
500
+
501
+ var Timebounds = /*#__PURE__*/_createClass(function Timebounds() {
502
+ var _this = this;
503
+ _classCallCheck(this, Timebounds);
504
+ _defineProperty(this, "rrCh", 0);
505
+ _defineProperty(this, "gDCR", 0);
506
+ _defineProperty(this, "parse", function () {
507
+ var timeBounds = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
508
+ try {
509
+ _this.rrCh = Number(timeBounds.lower);
510
+ _this.gDCR = Number(timeBounds.upper);
511
+ if (isNaN(_this.rrCh) || isNaN(_this.gDCR)) {
512
+ return false;
513
+ }
514
+ } catch (error) {
515
+ return false;
516
+ }
517
+ return true;
518
+ });
519
+ });
520
+
521
+ var PreCondition = /*#__PURE__*/_createClass(function PreCondition() {
522
+ var _this = this;
523
+ _classCallCheck(this, PreCondition);
524
+ _defineProperty(this, "kVxJ", 0);
525
+ _defineProperty(this, "cWDi", "");
526
+ _defineProperty(this, "uiSd", "");
527
+ _defineProperty(this, "ebLm", new Details());
528
+ _defineProperty(this, "aAiV", new Timebounds());
529
+ _defineProperty(this, "parse", function () {
530
+ var precondition = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
531
+ try {
532
+ _this.cWDi = precondition.event_type;
533
+ _this.uiSd = precondition.activity;
534
+ return _this.ebLm.parse(precondition.details) && _this.aAiV.parse(precondition.time_bounds);
535
+ } catch (error) {
536
+ return false;
537
+ }
538
+ });
539
+ });
540
+
541
+ var Logger$3 = window.ApxorLogger;
542
+ var Condition = /*#__PURE__*/_createClass(function Condition() {
543
+ var _this = this;
544
+ _classCallCheck(this, Condition);
545
+ _defineProperty(this, "kVxJ", 0);
546
+ _defineProperty(this, "svLj", -1);
547
+ _defineProperty(this, "KkoD", 0);
548
+ _defineProperty(this, "ZVZY", "");
549
+ _defineProperty(this, "uiSd", "");
550
+ _defineProperty(this, "cWDi", "");
551
+ _defineProperty(this, "aAiV", new Timebounds());
552
+ _defineProperty(this, "ebLm", new Details());
553
+ _defineProperty(this, "MgEa", new PreCondition());
554
+ _defineProperty(this, "bRor", "AND");
555
+ _defineProperty(this, "EpOC", false);
556
+ _defineProperty(this, "jyXB", void 0);
557
+ _defineProperty(this, "parse", function () {
558
+ var condition = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
559
+ try {
560
+ _this.svLj = condition.sequence;
561
+ _this.KkoD = condition.count_config.count;
562
+ _this.ZVZY = condition.count_config.operator;
563
+ _this.uiSd = condition.activity;
564
+ _this.cWDi = condition.event_type;
565
+ _this.bRor = condition.combine_operator;
566
+ _this.jyXB = condition.type;
567
+ return _this.ebLm.parse(condition.details) && _this.MgEa.parse(condition.trigger) && _this.aAiV.parse(condition.time_bounds);
568
+ } catch (error) {
569
+ Logger$3.error(error);
570
+ return false;
571
+ }
572
+ });
573
+ });
574
+
575
+ /* eslint-disable no-unused-vars */
576
+ var Logger$4 = window.ApxorLogger;
577
+ var ConditionValidator = /*#__PURE__*/function () {
578
+ function ConditionValidator() {
579
+ var _this = this;
580
+ _classCallCheck(this, ConditionValidator);
581
+ _defineProperty(this, "yqph", 0);
582
+ _defineProperty(this, "zNLA", "");
583
+ _defineProperty(this, "wMtN", new Condition());
584
+ _defineProperty(this, "NKqT", false);
585
+ _defineProperty(this, "mJlk", false);
586
+ _defineProperty(this, "RfKK", 0);
587
+ _defineProperty(this, "bRor", "AND");
588
+ _defineProperty(this, "GQSy", -1);
589
+ _defineProperty(this, "gIUZ", []);
590
+ _defineProperty(this, "aOME", {});
591
+ _defineProperty(this, "iqOO", false);
592
+ /**
593
+ * If respectSequence is true, don't auto-gINm to events except for the condition whose index is 0
594
+ *
595
+ * @param condition
596
+ * @param type
597
+ * @param id
598
+ * @param index
599
+ * @param respectSequence
600
+ * @returns {boolean}
601
+ */
602
+ _defineProperty(this, "initialize", function () {
603
+ var condition = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
604
+ var id = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
605
+ var index = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
606
+ var respectSequence = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
607
+ var noKpiArray = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [];
608
+ _this.zNLA = id;
609
+ _this.RfKK = index;
610
+ _this.gIUZ = noKpiArray;
611
+ var result = _this.wMtN.parse(condition);
612
+ if (result) {
613
+ _this.bRor = _this.wMtN.bRor;
614
+
615
+ // FIXME: Why this code is written? Don't see any usecase
616
+ if (_this.wMtN.EpOC) {
617
+ var eventName = _this.wMtN.ebLm.yaFV;
618
+ if (eventName === "APX_PAGE_OPENED") {
619
+ eventName = _this.wMtN.ebLm.GizD["navigation_id"];
620
+ eventName = isDefined(eventName) ? eventName : _this.wMtN.ebLm.yaFV;
621
+ }
622
+ _this.GQSy = Apxor.getController().getEventCount(eventName);
623
+ var count = _this.wMtN.KkoD;
624
+ var operator = _this.wMtN.ZVZY;
625
+ _this.mJlk = _this.pqqV(_this.GQSy - 1, count, operator, false);
626
+ _this.NKqT = _this.mJlk;
627
+ // If the condition is already satisfied and if it is page view, no need to gINm
628
+ // This only applies for NAVIGATION_EVENTS
629
+ if (_this.mJlk && _this.wMtN.ebLm.yaFV === "APX_PAGE_OPENED") {
630
+ return true;
631
+ }
632
+ }
633
+ if (!respectSequence || index === 0) {
634
+ _this.gINm();
635
+ }
636
+ return true;
637
+ }
638
+ return false;
639
+ });
640
+ _defineProperty(this, "gINm", function () {
641
+ var condition = _this.wMtN;
642
+ var precondition = condition.MgEa;
643
+ var ceInstance = CE.getInstance();
644
+ if (precondition.cWDi === "app_start") {
645
+ _this.NKqT = true;
646
+ ceInstance.registerForEvent(generateKey(condition.cWDi) + "___" + condition.ebLm.yaFV, _this.SnBK);
647
+ } else {
648
+ ceInstance.registerForEvent(generateKey(condition.cWDi) + "___" + precondition.ebLm.yaFV, _this.SnBK);
649
+ }
650
+ });
651
+ _defineProperty(this, "gjCB", function (type, name, time, additionalInfo) {
652
+ var _this$wMtN, _this$wMtN$_det, _this$wMtN$_det2;
653
+ var eventTime = Date.now();
654
+ var time_differnce = (eventTime - _this.aOME[name]) / 1000;
655
+ var time_fromConfig = ((_this$wMtN = _this.wMtN) === null || _this$wMtN === void 0 ? void 0 : (_this$wMtN$_det = _this$wMtN.ebLm) === null || _this$wMtN$_det === void 0 ? void 0 : (_this$wMtN$_det2 = _this$wMtN$_det.GizD) === null || _this$wMtN$_det2 === void 0 ? void 0 : _this$wMtN$_det2.time) / 1000;
656
+ if (time_fromConfig > time_differnce) {
657
+ _this._displayCampaign(time);
658
+ }
659
+ });
660
+ _defineProperty(this, "MhsE", function (type, name, time, additionalInfo) {
661
+ var _this$_condition2, _this$_condition2$_pr, _this$_condition3, _this$_condition3$_de, _this$_condition3$_de2;
662
+ _this.iqOO = true;
663
+ var currentTime = Date.now();
664
+ var eventName = (_this$_condition2 = _this.wMtN) === null || _this$_condition2 === void 0 ? void 0 : (_this$_condition2$_pr = _this$_condition2.MgEa) === null || _this$_condition2$_pr === void 0 ? void 0 : _this$_condition2$_pr.ebLm.yaFV;
665
+ var eventTime = _this.aOME[eventName];
666
+ var time_differnce = (currentTime - eventTime) / 1000;
667
+ var time_fromConfig = (_this$_condition3 = _this.wMtN) === null || _this$_condition3 === void 0 ? void 0 : (_this$_condition3$_de = _this$_condition3.ebLm) === null || _this$_condition3$_de === void 0 ? void 0 : (_this$_condition3$_de2 = _this$_condition3$_de.GizD) === null || _this$_condition3$_de2 === void 0 ? void 0 : _this$_condition3$_de2.time;
668
+ time_fromConfig = time_fromConfig / 1000;
669
+ if (time_fromConfig > time_differnce) {
670
+ _this._displayCampaign(time);
671
+ }
672
+ //unregister the event
673
+ });
674
+ _defineProperty(this, "SnBK", function (type, name, time, additionalInfo) {
675
+ var ceInstance = CE.getInstance();
676
+ if (!_this.NKqT) {
677
+ // Validate Precondition
678
+ _this.NKqT = _this.mTyq(type, name, time, additionalInfo);
679
+ if (_this.NKqT) {
680
+ var condition = _this.wMtN;
681
+ var precondition = condition.MgEa;
682
+ precondition.kVxJ = time;
683
+ //events will be registred by its type activity event_type: "activity_time"
684
+ if ((condition === null || condition === void 0 ? void 0 : condition.cWDi) === "activity_time") {
685
+ var wMtN$ebLm, wMtN$ebLm$_, wMtN$_details2, wMtN$_details2$, wMtN$_details3, wMtN$_details3$;
686
+ var event_time = condition === null || condition === void 0 ? void 0 : (wMtN$ebLm = condition.ebLm) === null || wMtN$ebLm === void 0 ? void 0 : (wMtN$ebLm$_ = wMtN$ebLm.GizD) === null || wMtN$ebLm$_ === void 0 ? void 0 : wMtN$ebLm$_.time;
687
+ if ((condition === null || condition === void 0 ? void 0 : (wMtN$_details2 = condition.ebLm) === null || wMtN$_details2 === void 0 ? void 0 : (wMtN$_details2$ = wMtN$_details2.GizD) === null || wMtN$_details2$ === void 0 ? void 0 : wMtN$_details2$.nkpi.length) > 0) {
688
+ setTimeout(function () {
689
+ if (!_this.iqOO) {
690
+ _this.mJlk = true;
691
+ if (_this.mJlk) {
692
+ _this.yqph += 1;
693
+ _this.mJlk = _this.pqqV(_this.yqph, _this.wMtN.KkoD, _this.wMtN.ZVZY);
694
+ if (_this.mJlk) {
695
+ _this.wMtN.kVxJ = time;
696
+ ceInstance.validate(_this.zNLA, _this.RfKK);
697
+ }
698
+ }
699
+ }
700
+ condition.ebLm.GizD.nkpi.map(function (nokpi) {
701
+ ceInstance.unregisterFromEvent(toUpperCase(condition.ebLm.GizD.et) + "___" + nokpi, _this);
702
+ });
703
+ }, event_time);
704
+ condition.ebLm.GizD.nkpi.map(function (nokpi) {
705
+ ceInstance.registerForEvent(toUpperCase(condition.ebLm.GizD.et) + "___" + nokpi, _this.MhsE);
706
+ });
707
+ }
708
+ //it is for unregistering the events did case after completing the time imit
709
+ if ((condition === null || condition === void 0 ? void 0 : (wMtN$_details3 = condition.ebLm) === null || wMtN$_details3 === void 0 ? void 0 : (wMtN$_details3$ = wMtN$_details3.GizD) === null || wMtN$_details3$ === void 0 ? void 0 : wMtN$_details3$.kpi.length) > 0) {
710
+ setTimeout(function () {
711
+ condition.ebLm.GizD.kpi.map(function (kpi) {
712
+ ceInstance.unregisterFromEvent(toUpperCase(condition.ebLm.GizD.et) + "___" + kpi, _this);
713
+ });
714
+ }, event_time);
715
+ condition.ebLm.GizD.kpi.map(function (kpi) {
716
+ if (kpi === condition.MgEa.ebLm.yaFV) {
717
+ //unregister the previous event
718
+ ceInstance.unregisterFromEvent(generateKey(precondition.cWDi) + "___" + precondition.ebLm.yaFV, _this);
719
+ ceInstance.registerForEvent(toUpperCase(condition.ebLm.GizD.et) + "___" + kpi, _this.gjCB);
720
+ } else {
721
+ ceInstance.registerForEvent(toUpperCase(condition.ebLm.GizD.et) + "___" + kpi, _this.MhsE);
722
+ }
723
+ });
724
+ }
725
+ } else {
726
+ ceInstance.unregisterFromEvent(generateKey(precondition.cWDi) + "___" + precondition.ebLm.yaFV, _this);
727
+ ceInstance.registerForEvent(generateKey(condition.cWDi) + "___" + condition.ebLm.yaFV, _this);
728
+ }
729
+ _this.aOME[name] = Date.now();
730
+ }
731
+ return;
732
+ }
733
+
734
+ // Validate Condition
735
+ var validationStatus = generateKey(_this.wMtN.cWDi) === type && _this.dLxA(time - _this.wMtN.MgEa.kVxJ, _this.wMtN.aAiV) && _this.wMtN.ebLm.yaFV === name && _this.eFNk(_this.wMtN.ebLm.GizD, additionalInfo);
736
+ if (validationStatus) {
737
+ _this.yqph += 1;
738
+ _this.mJlk = _this.pqqV(_this.yqph, _this.wMtN.KkoD, _this.wMtN.ZVZY);
739
+ if (_this.mJlk) {
740
+ _this.wMtN.kVxJ = time;
741
+ ceInstance.validate(_this.zNLA, _this.RfKK);
742
+ }
743
+ }
744
+ });
745
+ _defineProperty(this, "mTyq", function (type, name, time, additionalInfo) {
746
+ var precondition = _this.wMtN.MgEa;
747
+ return generateKey(precondition.cWDi) === type && precondition.ebLm.yaFV === name && _this.dLxA(time, precondition.aAiV) && _this.eFNk(precondition.ebLm.GizD, additionalInfo);
748
+ });
749
+ _defineProperty(this, "dLxA", function (time, timeBounds) {
750
+ var currentTime = Math.ceil(time);
751
+ return currentTime > timeBounds.rrCh && currentTime < timeBounds.gDCR;
752
+ });
753
+ _defineProperty(this, "pqqV", function (current, required, operator) {
754
+ var checkOld = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
755
+ if (checkOld && _this.wMtN.EpOC) {
756
+ current = current + _this.GQSy;
757
+ }
758
+ switch (operator) {
759
+ case "EQ":
760
+ return current === required;
761
+ case "GT":
762
+ return current > required;
763
+ case "GTE":
764
+ return current >= required;
765
+ case "LT":
766
+ return current < required;
767
+ case "LTE":
768
+ return current <= required;
769
+ default:
770
+ return false;
771
+ }
772
+ });
773
+ _defineProperty(this, "eFNk", function (expected, received) {
774
+ var status = true;
775
+ try {
776
+ var _loop = function _loop() {
777
+ if (!received[item] || status === false) {
778
+ return {
779
+ v: false
780
+ };
781
+ }
782
+ if (_typeof(expected[item]) === "object") {
783
+ var operator = expected[item].op;
784
+ var type = expected[item].t;
785
+ var expectedValue;
786
+ if (type === "s") {
787
+ expectedValue = expected[item].val;
788
+ } else if (type === "l" || type === "f") {
789
+ expectedValue = parseFloat(expected[item].val);
790
+ }
791
+ var loggedValues = [];
792
+ if (Array.isArray(received[item])) {
793
+ loggedValues = received[item];
794
+ } else {
795
+ loggedValues = [received[item]];
796
+ }
797
+ var match = loggedValues.some(function (loggedValue) {
798
+ return compare(loggedValue, expectedValue, operator);
799
+ });
800
+ status = status && match;
801
+ } else {
802
+ status = status && compare(received[item], expected[item], "EQ");
803
+ }
804
+ };
805
+ for (var item in expected) {
806
+ var _ret = _loop();
807
+ if (_typeof(_ret) === "object") return _ret.v;
808
+ }
809
+ } catch (error) {
810
+ Logger$4.error(error);
811
+ status = false;
812
+ }
813
+ return status;
814
+ });
815
+ }
816
+ _createClass(ConditionValidator, [{
817
+ key: "_displayCampaign",
818
+ value: function _displayCampaign(time) {
819
+ var ceInstance = CE.getInstance();
820
+ this.mJlk = true;
821
+ if (this.mJlk) {
822
+ this.yqph += 1;
823
+ this.mJlk = this.pqqV(this.yqph, this.wMtN.KkoD, this.wMtN.ZVZY);
824
+ if (this.mJlk) {
825
+ this.wMtN.kVxJ = time;
826
+ ceInstance.validate(this.zNLA, this.RfKK);
827
+ }
828
+ }
829
+ }
830
+ }]);
831
+ return ConditionValidator;
832
+ }();
833
+
834
+ var QE_STATE = "qe_state";
835
+ var APX_RETAINED_SESSIONS = "apx_retained_session";
836
+ var APX_RETAINED_DAYS = "apx_retained_days";
837
+ var APX_CONTEXT_EVALUATED = "apx_context_evaluated";
838
+
839
+ var Logger$5 = window.ApxorLogger;
840
+ var OverallConfig = /*#__PURE__*/_createClass(function OverallConfig() {
841
+ var _this = this;
842
+ _classCallCheck(this, OverallConfig);
843
+ _defineProperty(this, "JHaZ", []);
844
+ _defineProperty(this, "_ret_day", {});
845
+ _defineProperty(this, "Gbfo", {});
846
+ _defineProperty(this, "sYjx", false);
847
+ _defineProperty(this, "JxBs", false);
848
+ _defineProperty(this, "parse", function () {
849
+ var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
850
+ try {
851
+ _this.JHaZ = config.overall_cfg.events;
852
+ _this._ret_day = config.overall_cfg.ret_day;
853
+ _this.Gbfo = config.overall_cfg.session;
854
+ _this.sYjx = config.overall_cfg.toggleRetDay;
855
+ _this.JHaZ = config.overall_cfg.events;
856
+ _this.JxBs = config.overall_cfg.toggleSession;
857
+ } catch (error) {
858
+ Logger$5.error(error);
859
+ return false;
860
+ }
861
+ return true;
862
+ });
863
+ _defineProperty(this, "validate", function () {
864
+ var retainedDays = parseInt(Apxor.getController().getFromStorage(APX_RETAINED_DAYS));
865
+ var retainedSession = parseInt(Apxor.getController().getFromStorage(APX_RETAINED_SESSIONS));
866
+ if (_this.sYjx && !isNaN(retainedDays) && !(retainedDays >= _this._ret_day.from && retainedDays <= _this._ret_day.to)) {
867
+ return false;
868
+ }
869
+ if (_this.JxBs && !isNaN(retainedSession) && !(retainedSession >= _this.Gbfo.from && retainedSession <= _this.Gbfo.to)) {
870
+ return false;
871
+ }
872
+ try {
873
+ // particular event not happened in Life time
874
+ var data = Apxor.getController().getFromStorage("_apx_lt_count");
875
+ var siteid = Apxor.getSiteId();
876
+ var LtCountObjDecoded = JSON.parse(decode(siteid, data));
877
+ for (var i = 0; i < _this.JHaZ.length; i++) {
878
+ var evName = _this.JHaZ[i].name.replace("'", "").replace("’", "");
879
+ if (LtCountObjDecoded[evName]) {
880
+ return false;
881
+ }
882
+ }
883
+ } catch (e) {
884
+ Logger$5.error("Failed to validate the lt count:" + e);
885
+ }
886
+ return true;
887
+ });
888
+ });
889
+
890
+ var Logger$6 = window.ApxorLogger;
891
+ var ConfigItem = /*#__PURE__*/_createClass(function ConfigItem() {
892
+ var _this = this;
893
+ _classCallCheck(this, ConfigItem);
894
+ _defineProperty(this, "IuXx", []);
895
+ _defineProperty(this, "zNLA", "");
896
+ _defineProperty(this, "SOrm", new Meta());
897
+ _defineProperty(this, "aTkp", new Audience());
898
+ _defineProperty(this, "hDCI", new Validity());
899
+ _defineProperty(this, "UnuD", new Frequency());
900
+ _defineProperty(this, "IEfn", new OverallConfig());
901
+ _defineProperty(this, "PiMM", false);
902
+ _defineProperty(this, "JyrV", []);
903
+ _defineProperty(this, "parse", function () {
904
+ var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
905
+ try {
906
+ // If ID is not present, throw it out
907
+ if (!isDefined(config._id)) {
908
+ Logger$6.error("No Id");
909
+ return false;
910
+ }
911
+
912
+ // If config is disabled, throw it out
913
+ if (!isDefined(config.enabled) || !config.enabled) {
914
+ Logger$6.error("Not enabled");
915
+ return false;
916
+ }
917
+
918
+ // If META, VALIDITY, FREQUENCY and AUDIENCE is not parsed properly, throw it out
919
+ if (!(_this.SOrm.parse(config) && _this.hDCI.parse(config) && _this.UnuD.parse(config) && _this.aTkp.parse(config) && _this.IEfn.parse(config))) {
920
+ return false;
921
+ }
922
+
923
+ // If there are no conditions, throw it out
924
+ if (!isDefined(config.conditions) || !Array.isArray(config.conditions)) {
925
+ Logger$6.error("No valid conditions", config.conditions);
926
+ return false;
927
+ }
928
+ _this.zNLA = config._id;
929
+ _this.PiMM = isDefined(config.sequence_enabled) ? config.sequence_enabled : false;
930
+ if (_this.PiMM) {
931
+ // iff respectSequence is true, Sort the Conditions by their sequence order
932
+ // We need to sort, if server sends them in orderless manner
933
+ config.conditions.sort(function (prev, current) {
934
+ return prev.sequence < current.sequence;
935
+ });
936
+ }
937
+
938
+ // Parse all conditions now
939
+ var conditions = config.conditions;
940
+ var length = conditions.length;
941
+ for (var index = 0; index < length; index++) {
942
+ _this.JyrV = [];
943
+ var condition = conditions[index];
944
+ if (condition.type === "didn't") {
945
+ var wMtN$details, wMtN$details$ad;
946
+ var obj = {
947
+ trigger_key: condition.trigger.details.name,
948
+ no_kpi_array: condition === null || condition === void 0 ? void 0 : (wMtN$details = condition.details) === null || wMtN$details === void 0 ? void 0 : (wMtN$details$ad = wMtN$details.additional_info) === null || wMtN$details$ad === void 0 ? void 0 : wMtN$details$ad.nkpi,
949
+ condition_id: condition === null || condition === void 0 ? void 0 : condition._id,
950
+ time_bounds: condition.time_bounds.upper
951
+ };
952
+ _this.JyrV = [].concat(_toConsumableArray(_this.JyrV), [obj]);
953
+ //this will be the key
954
+ //when event occur check this array and then then check the time
955
+ //check the time diffrence
956
+ //to delete the condion from the nkpi array if the time limit exceeded
957
+ //create an array of objects y=using all these;
958
+ }
959
+
960
+ var conditionValidator = new ConditionValidator();
961
+ if (conditionValidator.initialize(condition, _this.zNLA, index, _this.PiMM, _this.JyrV)) {
962
+ _this.IuXx.push(conditionValidator);
963
+ }
964
+ }
965
+ return _this.IuXx.length > 0;
966
+ } catch (error) {
967
+ Logger$6.error(error);
968
+ return false;
969
+ }
970
+ });
971
+ _defineProperty(this, "PffH", function (index) {
972
+ if (index < 0) {
973
+ return;
974
+ }
975
+ if (_this.PiMM) {
976
+ var conditionValidator = _this.IuXx[index];
977
+ if (isDefined(conditionValidator) && conditionValidator.mJlk) {
978
+ // Check if previous validator is satisfied
979
+ var prevValidator = _this.IuXx[index - 1];
980
+ if (isDefined(prevValidator) && !prevValidator.mJlk) {
981
+ // TODO: If current index is satisfied before previous one, do something
982
+ // either unregister all conditions or remove this item from ConfigLookup
983
+ return;
984
+ }
985
+ var nextValidator = _this.IuXx[index + 1];
986
+ if (!isDefined(nextValidator)) {
987
+ // It means this is the last condition
988
+ // Validate all conditions
989
+ _this.nhnX();
990
+ } else {
991
+ nextValidator.gINm();
992
+ }
993
+ }
994
+ } else {
995
+ // Validate all conditions
996
+ _this.nhnX();
997
+ }
998
+ });
999
+ _defineProperty(this, "nhnX", function () {
1000
+ // Check If Audience, Validity is satisfied or not
1001
+ var userAttributes = Apxor.getController().getUserAttributes();
1002
+ var sessionAttributes = Apxor.getController().getSessionAttributes();
1003
+ if (!_this.hDCI.validate() || !_this.aTkp.validate(userAttributes, sessionAttributes) || !_this.IEfn.validate()) {
1004
+ return;
1005
+ }
1006
+ var length = _this.IuXx.length;
1007
+ var isSatisfied = length < 1;
1008
+ var combineOperator = "";
1009
+ for (var index = 0; index < length; index++) {
1010
+ var validator = _this.IuXx[index];
1011
+ var currentResult = validator.mJlk;
1012
+ if (combineOperator.trim() === "") {
1013
+ isSatisfied = currentResult;
1014
+ } else {
1015
+ switch (combineOperator) {
1016
+ case "AND":
1017
+ isSatisfied = isSatisfied && currentResult;
1018
+ break;
1019
+ case "OR":
1020
+ isSatisfied = isSatisfied || currentResult;
1021
+ break;
1022
+ }
1023
+ }
1024
+ combineOperator = validator.bRor;
1025
+ }
1026
+ if (isSatisfied) {
1027
+ console.debug("onCondition satisfied");
1028
+ // Check if count reached it's maximum
1029
+ if (!_this.UnuD.JglD(_this.zNLA)) {
1030
+ console.warn("Maximum limit reached", _this.zNLA);
1031
+ return;
1032
+ }
1033
+ console.log("Dispatching event", _this.SOrm.jyXB);
1034
+ if (_this.SOrm._only_context === true) {
1035
+ Apxor.logEvent(APX_CONTEXT_EVALUATED, _objectSpread2(_objectSpread2({}, _this.SOrm._attr), {}, {
1036
+ message_name: _this.SOrm.yaFV,
1037
+ id: _this.zNLA
1038
+ }));
1039
+ }
1040
+ // Emit event
1041
+ Apxor.getController().dispatchEvent(_this.SOrm.jyXB, {
1042
+ name: _this.SOrm.jyXB,
1043
+ additional_info: {
1044
+ uuid: _this.zNLA,
1045
+ name: _this.SOrm.yaFV
1046
+ }
1047
+ });
1048
+ }
1049
+ });
1050
+ _defineProperty(this, "lSfk", function () {
1051
+ _this.UnuD.lSfk();
1052
+ });
1053
+ _defineProperty(this, "getFrequencyCount", function () {
1054
+ return _this.UnuD.getFrequencyCount();
1055
+ });
1056
+ _defineProperty(this, "cajt", function () {
1057
+ return _this.UnuD.REfq();
1058
+ });
1059
+ });
1060
+
1061
+ var ConfigLookup = /*#__PURE__*/_createClass(function ConfigLookup() {
1062
+ var _this = this;
1063
+ _classCallCheck(this, ConfigLookup);
1064
+ _defineProperty(this, "ZhRR", {});
1065
+ _defineProperty(this, "parse", function () {
1066
+ var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
1067
+ configs: []
1068
+ };
1069
+ if (isDefined(config) && isDefined(config.configs)) {
1070
+ var configs = config.configs;
1071
+ if (!Array.isArray(configs)) {
1072
+ return;
1073
+ }
1074
+
1075
+ // Sorts the configs by the priority number
1076
+ configs.sort(function (a, b) {
1077
+ var _a$prio, _b$prio;
1078
+ var priority1 = (_a$prio = a.prio) !== null && _a$prio !== void 0 ? _a$prio : -1;
1079
+ var priority2 = (_b$prio = b.prio) !== null && _b$prio !== void 0 ? _b$prio : -1;
1080
+ return priority1 - priority2;
1081
+ });
1082
+ for (var index = 0; index < configs.length; index++) {
1083
+ var _config = configs[index];
1084
+ var configId = _config._id;
1085
+ var configItem = new ConfigItem();
1086
+ if (configItem.parse(_config)) {
1087
+ _this.ZhRR[configId] = configItem;
1088
+ } else {
1089
+ console.warn("Failed to parse cfg", configId);
1090
+ }
1091
+ }
1092
+ }
1093
+ });
1094
+ _defineProperty(this, "validate", function (id, index) {
1095
+ if (_this.ZhRR[id]) {
1096
+ var configItem = _this.ZhRR[id];
1097
+ configItem.PffH(index);
1098
+ }
1099
+ });
1100
+ _defineProperty(this, "lSfk", function (id) {
1101
+ var campiagnConfig = _this.ZhRR[id];
1102
+ campiagnConfig.lSfk();
1103
+ });
1104
+ _defineProperty(this, "getFrequencyCount", function (id) {
1105
+ var campiagnConfig = _this.ZhRR[id];
1106
+ return campiagnConfig.getFrequencyCount();
1107
+ });
1108
+ _defineProperty(this, "resetFrequencyCounts", function () {
1109
+ var configs = _this.ZhRR;
1110
+ for (var configId in configs) {
1111
+ configs[configId].cajt();
1112
+ }
1113
+ });
1114
+ _defineProperty(this, "Suhh", function (campaignId) {
1115
+ try {
1116
+ if (_this.ZhRR) {
1117
+ var configItem = _this.ZhRR[campaignId];
1118
+ if (configItem && configItem.SOrm) {
1119
+ return configItem.SOrm;
1120
+ }
1121
+ }
1122
+ } catch (e) {
1123
+ console.log("Error in getting the campaign meta ".concat(e));
1124
+ }
1125
+ return {};
1126
+ });
1127
+ });
1128
+
1129
+ var APP_EVENT = "APP_EVENT";
1130
+ var CLIENT_EVENT = "CLIENT_EVENT";
1131
+ var Logger$7 = window.ApxorLogger;
1132
+ var EventsListener = /*#__PURE__*/_createClass(function EventsListener() {
1133
+ var _this = this;
1134
+ _classCallCheck(this, EventsListener);
1135
+ _defineProperty(this, "ihqx", {});
1136
+ _defineProperty(this, "sXGF", []);
1137
+ _defineProperty(this, "mBTm", false);
1138
+ _defineProperty(this, "initialize", function () {
1139
+ var controller = Apxor.getController();
1140
+ controller.registerForEvent(APP_EVENT, function (event) {
1141
+ return _this.DHyY(event, "AE");
1142
+ });
1143
+ controller.registerForEvent(CLIENT_EVENT, function (event) {
1144
+ return _this.DHyY(event, "CE");
1145
+ });
1146
+ });
1147
+ _defineProperty(this, "sQAT", function () {
1148
+ // Clear Buffer
1149
+ for (var item in _this.sXGF) {
1150
+ _this.QsuK(item.event, item.key, item.type);
1151
+ }
1152
+ _this.mBTm = true;
1153
+ });
1154
+ _defineProperty(this, "GvAJ", function (event, callback) {
1155
+ if (!isFunction(callback)) {
1156
+ return;
1157
+ }
1158
+ var listeners;
1159
+ if (_this.ihqx[event]) {
1160
+ listeners = _this.ihqx[event];
1161
+ } else {
1162
+ listeners = [];
1163
+ }
1164
+ listeners.push(callback);
1165
+ _this.ihqx[event] = listeners;
1166
+ Logger$7.debug("Listeners list: ", _this.ihqx);
1167
+ });
1168
+ _defineProperty(this, "unregisterFromEvent", function (event, callback) {
1169
+ if (_this.ihqx[event]) {
1170
+ var listeners = _this.ihqx[event];
1171
+ var updatedListeners = [];
1172
+ for (var index = 0; index < listeners.length; index++) {
1173
+ var listener = listeners[index];
1174
+ if (listener !== callback) {
1175
+ updatedListeners.push(listener);
1176
+ }
1177
+ }
1178
+ _this.ihqx[event] = updatedListeners;
1179
+ }
1180
+ });
1181
+ _defineProperty(this, "DHyY", function (event) {
1182
+ var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "AE";
1183
+ var key = type + "___" + event.name;
1184
+ _this.QsuK(event, key, type);
1185
+ });
1186
+ _defineProperty(this, "QsuK", function (event, key, type) {
1187
+ if (!_this.mBTm) {
1188
+ _this.sXGF.push({
1189
+ event: event,
1190
+ key: key,
1191
+ type: type
1192
+ });
1193
+ } else {
1194
+ Logger$7.debug("Notifying listeners for event: " + event + ", " + key, _this.ihqx);
1195
+ if (_this.ihqx[key]) {
1196
+ var listeners = _this.ihqx[key];
1197
+ var time = Apxor.getController().getSDKRunningTimeInSec();
1198
+ for (var index = 0; index < listeners.length; index++) {
1199
+ var listener = listeners[index];
1200
+ listener(type, event.name, time, event.additional_info);
1201
+ }
1202
+ }
1203
+ }
1204
+ });
1205
+ });
1206
+
1207
+ var Logger$8 = window.ApxorLogger;
1208
+ var CE = /*#__PURE__*/function () {
1209
+ function CE() {
1210
+ var _this = this;
1211
+ _classCallCheck(this, CE);
1212
+ _defineProperty(this, "ansf", false);
1213
+ _defineProperty(this, "wpgz", null);
1214
+ _defineProperty(this, "ngyZ", getDateInDDMMYYYY());
1215
+ _defineProperty(this, "dymD", new EventsListener());
1216
+ _defineProperty(this, "Hdaj", Apxor.getSiteId());
1217
+ _defineProperty(this, "_qeState", {});
1218
+ _defineProperty(this, "getQeState", function () {
1219
+ try {
1220
+ var data = Apxor.getController().getFromStorage(QE_STATE);
1221
+ if (data) {
1222
+ return JSON.parse(decode(_this.Hdaj, data));
1223
+ } else {
1224
+ _this._qeState = {};
1225
+ return _this.setQeState();
1226
+ }
1227
+ } catch (e) {
1228
+ _this._qeState = {};
1229
+ return _this.setQeState();
1230
+ }
1231
+ });
1232
+ _defineProperty(this, "setQeState", function () {
1233
+ var id = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
1234
+ try {
1235
+ Apxor.getController().persistToStorage(QE_STATE, _this._qeState, true);
1236
+ } catch (e) {
1237
+ if (id === "") {
1238
+ _this._qeState = {};
1239
+ } else {
1240
+ _this._qeState[id] = {
1241
+ SESSION: 0,
1242
+ OVERALL: 0,
1243
+ DATES: {}
1244
+ };
1245
+ }
1246
+ Apxor.getController().persistToStorage(QE_STATE, _this._qeState, true);
1247
+ }
1248
+ return _this._qeState;
1249
+ });
1250
+ _defineProperty(this, "initialize", function () {
1251
+ if (!_this.ansf) {
1252
+ _this.ansf = true;
1253
+ _this.wpgz = new ConfigLookup();
1254
+ _this.dymD.initialize();
1255
+ _this._qeState = _this.getQeState();
1256
+ Logger$8.info("QE Initialized..");
1257
+ }
1258
+ });
1259
+ /**
1260
+ * Parses the given configuration
1261
+ *
1262
+ * @param config
1263
+ */
1264
+ _defineProperty(this, "parse", function (config) {
1265
+ if (!_this.iQUj()) {
1266
+ Logger$8.warn("Must call init first. Unable to proceed");
1267
+ return;
1268
+ }
1269
+ _this.wpgz.parse(config);
1270
+ _this.dymD.sQAT();
1271
+ });
1272
+ /**
1273
+ * Validates all conditions for given config ID
1274
+ *
1275
+ * @param id
1276
+ * @param index
1277
+ */
1278
+ _defineProperty(this, "validate", function (id, index) {
1279
+ if (!_this.iQUj()) {
1280
+ return;
1281
+ }
1282
+ _this.wpgz.validate(id, index);
1283
+ });
1284
+ _defineProperty(this, "updateCount", function (id) {
1285
+ try {
1286
+ if (!isDefined(_this._qeState[id])) {
1287
+ _this.createObjConfig(id);
1288
+ }
1289
+ _this.incrementFrequencies(id);
1290
+ _this.setQeState(id);
1291
+ _this.wpgz.lSfk(id);
1292
+ } catch (e) {
1293
+ console.log("Could not update the count config:".concat(e));
1294
+ }
1295
+ });
1296
+ _defineProperty(this, "resetFrequencyCounts", function () {
1297
+ _this.wpgz.resetFrequencyCounts();
1298
+ });
1299
+ _defineProperty(this, "getFrequencyCount", function (id) {
1300
+ return _this.wpgz.getFrequencyCount(id);
1301
+ });
1302
+ _defineProperty(this, "registerForEvent", function (event, callback) {
1303
+ _this.dymD.GvAJ(event, callback);
1304
+ });
1305
+ _defineProperty(this, "unregisterFromEvent", function (event, callback) {
1306
+ _this.dymD.unregisterFromEvent(event, callback);
1307
+ });
1308
+ /**
1309
+ * Fetches the config from Server
1310
+ *
1311
+ * @param type
1312
+ * @param validateUrl
1313
+ * @param apiUrl
1314
+ * @param callback
1315
+ */
1316
+ _defineProperty(this, "fetch", function (type, validateUrl, apiUrl, callback) {
1317
+ Apxor.getController().fetchConfiguration(type, validateUrl, apiUrl, callback);
1318
+ });
1319
+ _defineProperty(this, "iQUj", function () {
1320
+ return _this.ansf;
1321
+ });
1322
+ _defineProperty(this, "getCampaignMetaFromQueryEngine", function (campaignId) {
1323
+ return _this.wpgz.Suhh(campaignId);
1324
+ });
1325
+ _defineProperty(this, "ngye", function () {
1326
+ return _this.ngyZ;
1327
+ });
1328
+ if (!CE.instance) {
1329
+ CE.instance = this;
1330
+ }
1331
+ return CE.instance;
1332
+ }
1333
+ _createClass(CE, [{
1334
+ key: "createObjConfig",
1335
+ value:
1336
+ /**
1337
+ * Fetches the count from ConfigLookup and updates it in state for the given ID
1338
+ *
1339
+ * @param id
1340
+ */
1341
+ function createObjConfig(id) {
1342
+ try {
1343
+ this._qeState = this.getQeState();
1344
+ if (!isDefined(this._qeState[id])) {
1345
+ this._qeState[id] = {
1346
+ SESSION: 0,
1347
+ OVERALL: 0,
1348
+ DATES: {}
1349
+ };
1350
+ if (this.ngyZ) this._qeState[id].DATES[this.ngyZ] = 0;
1351
+ this.setQeState(id);
1352
+ }
1353
+ } catch (e) {
1354
+ Logger$8.error("Can not create the frequency count object:" + e);
1355
+ }
1356
+ }
1357
+ }, {
1358
+ key: "incrementFrequencies",
1359
+ value: function incrementFrequencies(id) {
1360
+ this._qeState = this.getQeState();
1361
+ var configFrequency = this._qeState[id];
1362
+ // Increment the SESSION count by 1
1363
+ configFrequency.SESSION = configFrequency.SESSION + 1;
1364
+ // Increment the OVERALL count by 1
1365
+ configFrequency.OVERALL = configFrequency.OVERALL + 1;
1366
+
1367
+ // Increment the DATES count for this particular date by 1. If the date changes reset.
1368
+ var currentDate = getDateInDDMMYYYY();
1369
+ if (currentDate !== this.ngyZ || !(configFrequency.DATES && configFrequency.DATES[currentDate])) {
1370
+ this.ngyZ = currentDate;
1371
+ configFrequency.DATES = {};
1372
+ configFrequency.DATES[this.ngyZ] = 0;
1373
+ }
1374
+ configFrequency.DATES[this.ngyZ] = configFrequency.DATES[this.ngyZ] + 1;
1375
+ }
1376
+ }], [{
1377
+ key: "getInstance",
1378
+ value: function getInstance() {
1379
+ if (!CE.instance) {
1380
+ CE.instance = new CE();
1381
+ }
1382
+ return CE.instance;
1383
+ }
1384
+ }]);
1385
+ return CE;
1386
+ }();
1387
+ _defineProperty(CE, "instance", void 0);
1388
+
1389
+ // const ce = new CE();
1390
+
1391
+ /* eslint-disable no-empty */
1392
+
1393
+ window.ceVersion = 119;
1394
+ try {
1395
+ if (exports !== undefined || exports !== null) {
1396
+ exports["default"] = CE;
1397
+ module.exports = exports["default"];
1398
+ }
1399
+ } catch (e) {}
1400
+
1401
+ return CE;
1402
+
1403
+ }));