-
Notifications
You must be signed in to change notification settings - Fork 0
/
clevertap.js
5426 lines (4394 loc) · 185 KB
/
clevertap.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.clevertap = factory());
}(this, (function () { 'use strict';
function _typeof(obj) {
"@babel/helpers - typeof";
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
_typeof = function (obj) {
return typeof obj;
};
} else {
_typeof = function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};
}
return _typeof(obj);
}
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
}
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly) symbols = symbols.filter(function (sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
});
keys.push.apply(keys, symbols);
}
return keys;
}
function _objectSpread2(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
if (i % 2) {
ownKeys(Object(source), true).forEach(function (key) {
_defineProperty(target, key, source[key]);
});
} else if (Object.getOwnPropertyDescriptors) {
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
} else {
ownKeys(Object(source)).forEach(function (key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
}
return target;
}
function _inherits(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function");
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
writable: true,
configurable: true
}
});
if (superClass) _setPrototypeOf(subClass, superClass);
}
function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o);
};
return _getPrototypeOf(o);
}
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
function _isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
return true;
} catch (e) {
return false;
}
}
function _construct(Parent, args, Class) {
if (_isNativeReflectConstruct()) {
_construct = Reflect.construct;
} else {
_construct = function _construct(Parent, args, Class) {
var a = [null];
a.push.apply(a, args);
var Constructor = Function.bind.apply(Parent, a);
var instance = new Constructor();
if (Class) _setPrototypeOf(instance, Class.prototype);
return instance;
};
}
return _construct.apply(null, arguments);
}
function _isNativeFunction(fn) {
return Function.toString.call(fn).indexOf("[native code]") !== -1;
}
function _wrapNativeSuper(Class) {
var _cache = typeof Map === "function" ? new Map() : undefined;
_wrapNativeSuper = function _wrapNativeSuper(Class) {
if (Class === null || !_isNativeFunction(Class)) return Class;
if (typeof Class !== "function") {
throw new TypeError("Super expression must either be null or a function");
}
if (typeof _cache !== "undefined") {
if (_cache.has(Class)) return _cache.get(Class);
_cache.set(Class, Wrapper);
}
function Wrapper() {
return _construct(Class, arguments, _getPrototypeOf(this).constructor);
}
Wrapper.prototype = Object.create(Class.prototype, {
constructor: {
value: Wrapper,
enumerable: false,
writable: true,
configurable: true
}
});
return _setPrototypeOf(Wrapper, Class);
};
return _wrapNativeSuper(Class);
}
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return self;
}
function _possibleConstructorReturn(self, call) {
if (call && (typeof call === "object" || typeof call === "function")) {
return call;
}
return _assertThisInitialized(self);
}
function _createSuper(Derived) {
var hasNativeReflectConstruct = _isNativeReflectConstruct();
return function _createSuperInternal() {
var Super = _getPrototypeOf(Derived),
result;
if (hasNativeReflectConstruct) {
var NewTarget = _getPrototypeOf(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return _possibleConstructorReturn(this, result);
};
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _createForOfIteratorHelper(o, allowArrayLike) {
var it;
if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
if (it) o = it;
var i = 0;
var F = function () {};
return {
s: F,
n: function () {
if (i >= o.length) return {
done: true
};
return {
done: false,
value: o[i++]
};
},
e: function (e) {
throw e;
},
f: F
};
}
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
var normalCompletion = true,
didErr = false,
err;
return {
s: function () {
it = o[Symbol.iterator]();
},
n: function () {
var step = it.next();
normalCompletion = step.done;
return step;
},
e: function (e) {
didErr = true;
err = e;
},
f: function () {
try {
if (!normalCompletion && it.return != null) it.return();
} finally {
if (didErr) throw err;
}
}
};
}
var id = 0;
function _classPrivateFieldLooseKey(name) {
return "__private_" + id++ + "_" + name;
}
function _classPrivateFieldLooseBase(receiver, privateKey) {
if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) {
throw new TypeError("attempted to use private field on non-instance");
}
return receiver;
}
var TARGET_DOMAIN = 'clevertap-prod.com';
var TARGET_PROTOCOL = 'https:';
var DEFAULT_REGION = 'eu1';
var _accountId = _classPrivateFieldLooseKey("accountId");
var _region = _classPrivateFieldLooseKey("region");
var _targetDomain = _classPrivateFieldLooseKey("targetDomain");
var Account = /*#__PURE__*/function () {
function Account() {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
id = _ref.id;
var region = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
var targetDomain = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : TARGET_DOMAIN;
_classCallCheck(this, Account);
Object.defineProperty(this, _accountId, {
writable: true,
value: void 0
});
Object.defineProperty(this, _region, {
writable: true,
value: ''
});
Object.defineProperty(this, _targetDomain, {
writable: true,
value: TARGET_DOMAIN
});
this.id = id;
if (region) {
this.region = region;
}
if (targetDomain) {
this.targetDomain = targetDomain;
}
}
_createClass(Account, [{
key: "id",
get: function get() {
return _classPrivateFieldLooseBase(this, _accountId)[_accountId];
},
set: function set(accountId) {
_classPrivateFieldLooseBase(this, _accountId)[_accountId] = accountId;
}
}, {
key: "region",
get: function get() {
return _classPrivateFieldLooseBase(this, _region)[_region];
},
set: function set(region) {
_classPrivateFieldLooseBase(this, _region)[_region] = region;
}
}, {
key: "targetDomain",
get: function get() {
return _classPrivateFieldLooseBase(this, _targetDomain)[_targetDomain];
},
set: function set(targetDomain) {
_classPrivateFieldLooseBase(this, _targetDomain)[_targetDomain] = targetDomain;
}
}, {
key: "finalTargetDomain",
get: function get() {
if (this.region) {
return "".concat(this.region, ".").concat(this.targetDomain);
} else {
if (this.targetDomain === TARGET_DOMAIN) {
return "".concat(DEFAULT_REGION, ".").concat(this.targetDomain);
}
return this.targetDomain;
}
}
}, {
key: "dataPostURL",
get: function get() {
return "".concat(TARGET_PROTOCOL, "//").concat(this.finalTargetDomain, "/a?t=96");
}
}, {
key: "recorderURL",
get: function get() {
return "".concat(TARGET_PROTOCOL, "//").concat(this.finalTargetDomain, "/r?r=1");
}
}, {
key: "emailURL",
get: function get() {
return "".concat(TARGET_PROTOCOL, "//").concat(this.finalTargetDomain, "/e?r=1");
}
}]);
return Account;
}();
var unsupportedKeyCharRegex = new RegExp('^\\s+|\\\.|\:|\\\$|\'|\"|\\\\|\\s+$', 'g');
var unsupportedValueCharRegex = new RegExp("^\\s+|\'|\"|\\\\|\\s+$", 'g');
var singleQuoteRegex = new RegExp('\'', 'g');
var CLEAR = 'clear';
var CHARGED_ID = 'Charged ID';
var CHARGEDID_COOKIE_NAME = 'WZRK_CHARGED_ID';
var GCOOKIE_NAME = 'WZRK_G';
var KCOOKIE_NAME = 'WZRK_K';
var CAMP_COOKIE_NAME = 'WZRK_CAMP';
var SCOOKIE_PREFIX = 'WZRK_S';
var SCOOKIE_EXP_TIME_IN_SECS = 60 * 20; // 20 mins
var EV_COOKIE = 'WZRK_EV';
var META_COOKIE = 'WZRK_META';
var PR_COOKIE = 'WZRK_PR';
var ARP_COOKIE = 'WZRK_ARP';
var LCOOKIE_NAME = 'WZRK_L';
var GLOBAL = 'global';
var DISPLAY = 'display';
var WEBPUSH_LS_KEY = 'WZRK_WPR';
var OPTOUT_KEY = 'optOut';
var CT_OPTOUT_KEY = 'ct_optout';
var OPTOUT_COOKIE_ENDSWITH = ':OO';
var USEIP_KEY = 'useIP';
var LRU_CACHE = 'WZRK_X';
var LRU_CACHE_SIZE = 100;
var IS_OUL = 'isOUL';
var EVT_PUSH = 'push';
var EVT_PING = 'ping';
var COOKIE_EXPIRY = 86400 * 365 * 10; // 10 Years in seconds
var MAX_TRIES = 50; // API tries
var FIRST_PING_FREQ_IN_MILLIS = 2 * 60 * 1000; // 2 mins
var CONTINUOUS_PING_FREQ_IN_MILLIS = 5 * 60 * 1000; // 5 mins
var GROUP_SUBSCRIPTION_REQUEST_ID = '2';
var categoryLongKey = 'cUsY';
var WZRK_PREFIX = 'wzrk_';
var WZRK_ID = 'wzrk_id';
var NOTIFICATION_VIEWED = 'Notification Viewed';
var NOTIFICATION_CLICKED = 'Notification Clicked';
var FIRE_PUSH_UNREGISTERED = 'WZRK_FPU';
var PUSH_SUBSCRIPTION_DATA = 'WZRK_PSD'; // PUSH SUBSCRIPTION DATA FOR REGISTER/UNREGISTER TOKEN
var SYSTEM_EVENTS = ['Stayed', 'UTM Visited', 'App Launched', 'Notification Sent', NOTIFICATION_VIEWED, NOTIFICATION_CLICKED];
var isString = function isString(input) {
return typeof input === 'string' || input instanceof String;
};
var isObject = function isObject(input) {
// TODO: refine
return Object.prototype.toString.call(input) === '[object Object]';
};
var isDateObject = function isDateObject(input) {
return _typeof(input) === 'object' && input instanceof Date;
};
var isObjectEmpty = function isObjectEmpty(obj) {
for (var prop in obj) {
if (obj.hasOwnProperty(prop)) {
return false;
}
}
return true;
};
var isConvertibleToNumber = function isConvertibleToNumber(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
};
var isNumber = function isNumber(n) {
return /^-?[\d.]+(?:e-?\d+)?$/.test(n) && typeof n === 'number';
};
var isValueValid = function isValueValid(value) {
if (value === null || value === undefined || value === 'undefined') {
return false;
}
return true;
};
var removeUnsupportedChars = function removeUnsupportedChars(o, logger) {
// keys can't be greater than 1024 chars, values can't be greater than 1024 chars
if (_typeof(o) === 'object') {
for (var key in o) {
if (o.hasOwnProperty(key)) {
var sanitizedVal = removeUnsupportedChars(o[key], logger);
var sanitizedKey = void 0;
sanitizedKey = sanitize(key, unsupportedKeyCharRegex);
if (sanitizedKey.length > 1024) {
sanitizedKey = sanitizedKey.substring(0, 1024);
logger.reportError(520, sanitizedKey + '... length exceeded 1024 chars. Trimmed.');
}
delete o[key];
o[sanitizedKey] = sanitizedVal;
}
}
} else {
var val;
if (isString(o)) {
val = sanitize(o, unsupportedValueCharRegex);
if (val.length > 1024) {
val = val.substring(0, 1024);
logger.reportError(521, val + '... length exceeded 1024 chars. Trimmed.');
}
} else {
val = o;
}
return val;
}
return o;
};
var sanitize = function sanitize(input, regex) {
return input.replace(regex, '');
};
var getToday = function getToday() {
var today = new Date();
return today.getFullYear() + '' + today.getMonth() + '' + today.getDay();
};
var getNow = function getNow() {
return Math.floor(new Date().getTime() / 1000);
};
var convertToWZRKDate = function convertToWZRKDate(dateObj) {
return '$D_' + Math.round(dateObj.getTime() / 1000);
};
var setDate = function setDate(dt) {
// expecting yyyymmdd format either as a number or a string
if (isDateValid(dt)) {
return '$D_' + dt;
}
};
var isDateValid = function isDateValid(date) {
var matches = /^(\d{4})(\d{2})(\d{2})$/.exec(date);
if (matches == null) return false;
var d = matches[3];
var m = matches[2] - 1;
var y = matches[1];
var composedDate = new Date(y, m, d); // eslint-disable-next-line eqeqeq
return composedDate.getDate() == d && composedDate.getMonth() == m && composedDate.getFullYear() == y;
};
var StorageManager$1 = /*#__PURE__*/function () {
function StorageManager() {
_classCallCheck(this, StorageManager);
}
_createClass(StorageManager, null, [{
key: "save",
value: function save(key, value) {
if (!key || !value) {
return false;
}
if (this._isLocalStorageSupported()) {
localStorage.setItem(key, typeof value === 'string' ? value : JSON.stringify(value));
return true;
}
}
}, {
key: "read",
value: function read(key) {
if (!key) {
return false;
}
var data = null;
if (this._isLocalStorageSupported()) {
data = localStorage.getItem(key);
}
if (data != null) {
try {
data = JSON.parse(data);
} catch (e) {}
}
return data;
}
}, {
key: "remove",
value: function remove(key) {
if (!key) {
return false;
}
if (this._isLocalStorageSupported()) {
localStorage.removeItem(key);
return true;
}
}
}, {
key: "removeCookie",
value: function removeCookie(name, domain) {
var cookieStr = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
if (domain) {
cookieStr = cookieStr + ' domain=' + domain + '; path=/';
}
document.cookie = cookieStr;
}
}, {
key: "createCookie",
value: function createCookie(name, value, seconds, domain) {
var expires = '';
var domainStr = '';
if (seconds) {
var date = new Date();
date.setTime(date.getTime() + seconds * 1000);
expires = '; expires=' + date.toGMTString();
}
if (domain) {
domainStr = '; domain=' + domain;
}
value = encodeURIComponent(value);
document.cookie = name + '=' + value + expires + domainStr + '; path=/';
}
}, {
key: "readCookie",
value: function readCookie(name) {
var nameEQ = name + '=';
var ca = document.cookie.split(';');
for (var idx = 0; idx < ca.length; idx++) {
var c = ca[idx];
while (c.charAt(0) === ' ') {
c = c.substring(1, c.length);
} // eslint-disable-next-line eqeqeq
if (c.indexOf(nameEQ) == 0) {
return decodeURIComponent(c.substring(nameEQ.length, c.length));
}
}
return null;
}
}, {
key: "_isLocalStorageSupported",
value: function _isLocalStorageSupported() {
return 'localStorage' in window && window.localStorage !== null && typeof window.localStorage.setItem === 'function';
}
}, {
key: "saveToLSorCookie",
value: function saveToLSorCookie(property, value) {
if (value == null) {
return;
}
try {
if (this._isLocalStorageSupported()) {
this.save(property, encodeURIComponent(JSON.stringify(value)));
} else {
if (property === GCOOKIE_NAME) {
this.createCookie(property, encodeURIComponent(value), 0, window.location.hostname);
} else {
this.createCookie(property, encodeURIComponent(JSON.stringify(value)), 0, window.location.hostname);
}
}
$ct.globalCache[property] = value;
} catch (e) {}
}
}, {
key: "readFromLSorCookie",
value: function readFromLSorCookie(property) {
var data;
if ($ct.globalCache.hasOwnProperty(property)) {
return $ct.globalCache[property];
}
if (this._isLocalStorageSupported()) {
data = this.read(property);
} else {
data = this.readCookie(property);
}
if (data !== null && data !== undefined && !(typeof data.trim === 'function' && data.trim() === '')) {
var value;
try {
value = JSON.parse(decodeURIComponent(data));
} catch (err) {
value = decodeURIComponent(data);
}
$ct.globalCache[property] = value;
return value;
}
}
}, {
key: "createBroadCookie",
value: function createBroadCookie(name, value, seconds, domain) {
// sets cookie on the base domain. e.g. if domain is baz.foo.bar.com, set cookie on ".bar.com"
// To update an existing "broad domain" cookie, we need to know what domain it was actually set on.
// since a retrieved cookie never tells which domain it was set on, we need to set another test cookie
// to find out which "broadest" domain the cookie was set on. Then delete the test cookie, and use that domain
// for updating the actual cookie.
if (domain) {
var broadDomain = $ct.broadDomain;
if (broadDomain == null) {
// if we don't know the broadDomain yet, then find out
var domainParts = domain.split('.');
var testBroadDomain = '';
for (var idx = domainParts.length - 1; idx >= 0; idx--) {
if (idx === 0) {
testBroadDomain = domainParts[idx] + testBroadDomain;
} else {
testBroadDomain = '.' + domainParts[idx] + testBroadDomain;
} // only needed if the cookie already exists and needs to be updated. See note above.
if (this.readCookie(name)) {
// no guarantee that browser will delete cookie, hence create short lived cookies
var testCookieName = 'test_' + name + idx;
this.createCookie(testCookieName, value, 10, testBroadDomain); // self-destruct after 10 seconds
if (!this.readCookie(testCookieName)) {
// if test cookie not set, then the actual cookie wouldn't have been set on this domain either.
continue;
} else {
// else if cookie set, then delete the test and the original cookie
this.removeCookie(testCookieName, testBroadDomain);
}
}
this.createCookie(name, value, seconds, testBroadDomain);
var tempCookie = this.readCookie(name); // eslint-disable-next-line eqeqeq
if (tempCookie == value) {
broadDomain = testBroadDomain;
$ct.broadDomain = broadDomain;
break;
}
}
} else {
this.createCookie(name, value, seconds, broadDomain);
}
} else {
this.createCookie(name, value, seconds, domain);
}
}
}, {
key: "getMetaProp",
value: function getMetaProp(property) {
var metaObj = this.readFromLSorCookie(META_COOKIE);
if (metaObj != null) {
return metaObj[property];
}
}
}, {
key: "setMetaProp",
value: function setMetaProp(property, value) {
if (this._isLocalStorageSupported()) {
var wzrkMetaObj = this.readFromLSorCookie(META_COOKIE);
if (wzrkMetaObj == null) {
wzrkMetaObj = {};
}
if (value === undefined) {
delete wzrkMetaObj[property];
} else {
wzrkMetaObj[property] = value;
}
this.saveToLSorCookie(META_COOKIE, wzrkMetaObj);
}
}
}, {
key: "getAndClearMetaProp",
value: function getAndClearMetaProp(property) {
var value = this.getMetaProp(property);
this.setMetaProp(property, undefined);
return value;
}
}, {
key: "setInstantDeleteFlagInK",
value: function setInstantDeleteFlagInK() {
var k = this.readFromLSorCookie(KCOOKIE_NAME);
if (k == null) {
k = {};
}
k.flag = true;
this.saveToLSorCookie(KCOOKIE_NAME, k);
}
}, {
key: "backupEvent",
value: function backupEvent(data, reqNo, logger) {
var backupArr = this.readFromLSorCookie(LCOOKIE_NAME);
if (typeof backupArr === 'undefined') {
backupArr = {};
}
backupArr[reqNo] = {
q: data
};
this.saveToLSorCookie(LCOOKIE_NAME, backupArr);
logger.debug("stored in ".concat(LCOOKIE_NAME, " reqNo : ").concat(reqNo, " -> ").concat(data));
}
}, {
key: "removeBackup",
value: function removeBackup(respNo, logger) {
var backupMap = this.readFromLSorCookie(LCOOKIE_NAME);
if (typeof backupMap !== 'undefined' && backupMap !== null && typeof backupMap[respNo] !== 'undefined') {
logger.debug("del event: ".concat(respNo, " data-> ").concat(backupMap[respNo].q));
delete backupMap[respNo];
this.saveToLSorCookie(LCOOKIE_NAME, backupMap);
}
}
}]);
return StorageManager;
}();
var $ct = {
globalCache: {
gcookie: null,
REQ_N: 0,
RESP_N: 0
},
LRU_cache: null,
globalProfileMap: undefined,
globalEventsMap: undefined,
blockRequest: false,
isOptInRequest: false,
broadDomain: null,
webPushEnabled: null,
campaignDivMap: {},
currentSessionId: null,
wiz_counter: 0,
// to keep track of number of times we load the body
notifApi: {
notifEnabledFromApi: false
},
// helper variable to handle race condition and check when notifications were called
unsubGroups: [],
updatedCategoryLong: null // domain: window.location.hostname, url -> getHostName()
// gcookie: -> device
};
var _keyOrder = _classPrivateFieldLooseKey("keyOrder");
var _deleteFromObject = _classPrivateFieldLooseKey("deleteFromObject");
var LRUCache = /*#__PURE__*/function () {
function LRUCache(max) {
_classCallCheck(this, LRUCache);
Object.defineProperty(this, _deleteFromObject, {
value: _deleteFromObject2
});
Object.defineProperty(this, _keyOrder, {
writable: true,
value: void 0
});
this.max = max;
var lruCache = StorageManager$1.readFromLSorCookie(LRU_CACHE);
if (lruCache) {
var tempLruCache = {};
_classPrivateFieldLooseBase(this, _keyOrder)[_keyOrder] = [];
lruCache = lruCache.cache;
for (var entry in lruCache) {
if (lruCache.hasOwnProperty(entry)) {
tempLruCache[lruCache[entry][0]] = lruCache[entry][1];
_classPrivateFieldLooseBase(this, _keyOrder)[_keyOrder].push(lruCache[entry][0]);
}
}
this.cache = tempLruCache;
} else {
this.cache = {};
_classPrivateFieldLooseBase(this, _keyOrder)[_keyOrder] = [];
}
}
_createClass(LRUCache, [{
key: "get",
value: function get(key) {
var item = this.cache[key];
if (item) {
this.cache = _classPrivateFieldLooseBase(this, _deleteFromObject)[_deleteFromObject](key, this.cache);
this.cache[key] = item;
_classPrivateFieldLooseBase(this, _keyOrder)[_keyOrder].push(key);
}
this.saveCacheToLS(this.cache);
return item;
}
}, {
key: "set",
value: function set(key, value) {
var item = this.cache[key];
var allKeys = _classPrivateFieldLooseBase(this, _keyOrder)[_keyOrder];
if (item != null) {
this.cache = _classPrivateFieldLooseBase(this, _deleteFromObject)[_deleteFromObject](key, this.cache);
} else if (allKeys.length === this.max) {
this.cache = _classPrivateFieldLooseBase(this, _deleteFromObject)[_deleteFromObject](allKeys[0], this.cache);
}
this.cache[key] = value;
if (_classPrivateFieldLooseBase(this, _keyOrder)[_keyOrder][_classPrivateFieldLooseBase(this, _keyOrder)[_keyOrder] - 1] !== key) {
_classPrivateFieldLooseBase(this, _keyOrder)[_keyOrder].push(key);
}
this.saveCacheToLS(this.cache);
}
}, {
key: "saveCacheToLS",
value: function saveCacheToLS(cache) {
var objToArray = [];
var allKeys = _classPrivateFieldLooseBase(this, _keyOrder)[_keyOrder];
for (var index in allKeys) {
if (allKeys.hasOwnProperty(index)) {
var temp = [];
temp.push(allKeys[index]);
temp.push(cache[allKeys[index]]);
objToArray.push(temp);
}
}
StorageManager$1.saveToLSorCookie(LRU_CACHE, {
cache: objToArray
});
}
}, {
key: "getKey",
value: function getKey(value) {
if (value === null) {
return null;
}
var allKeys = _classPrivateFieldLooseBase(this, _keyOrder)[_keyOrder];
for (var index in allKeys) {
if (allKeys.hasOwnProperty(index)) {
if (this.cache[allKeys[index]] === value) {
return allKeys[index];
}
}
}
return null;
}
}, {
key: "getSecondLastKey",
value: function getSecondLastKey() {
var keysArr = _classPrivateFieldLooseBase(this, _keyOrder)[_keyOrder];
if (keysArr != null && keysArr.length > 1) {
return keysArr[keysArr.length - 2];
}
return -1;
}