@microsoft/1ds-post-js 3.1.11 → 3.2.2

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.
Files changed (56) hide show
  1. package/README.md +2 -2
  2. package/bundle/{ms.post-3.1.11.gbl.js → ms.post-3.2.2.gbl.js} +1278 -548
  3. package/bundle/ms.post-3.2.2.gbl.js.map +1 -0
  4. package/bundle/ms.post-3.2.2.gbl.min.js +7 -0
  5. package/bundle/ms.post-3.2.2.gbl.min.js.map +1 -0
  6. package/bundle/ms.post-3.2.2.integrity.json +46 -0
  7. package/bundle/{ms.post-3.1.11.js → ms.post-3.2.2.js} +1278 -548
  8. package/bundle/ms.post-3.2.2.js.map +1 -0
  9. package/bundle/ms.post-3.2.2.min.js +7 -0
  10. package/bundle/ms.post-3.2.2.min.js.map +1 -0
  11. package/bundle/ms.post.gbl.js +1277 -547
  12. package/bundle/ms.post.gbl.js.map +1 -1
  13. package/bundle/ms.post.gbl.min.js +2 -2
  14. package/bundle/ms.post.gbl.min.js.map +1 -1
  15. package/bundle/ms.post.integrity.json +17 -17
  16. package/bundle/ms.post.js +1277 -547
  17. package/bundle/ms.post.js.map +1 -1
  18. package/bundle/ms.post.min.js +2 -2
  19. package/bundle/ms.post.min.js.map +1 -1
  20. package/dist/ms.post.js +212 -128
  21. package/dist/ms.post.js.map +1 -1
  22. package/dist/ms.post.min.js +2 -2
  23. package/dist/ms.post.min.js.map +1 -1
  24. package/dist-esm/src/BatchNotificationActions.js +1 -1
  25. package/dist-esm/src/ClockSkewManager.js +1 -1
  26. package/dist-esm/src/Constants.js +1 -1
  27. package/dist-esm/src/DataModels.js +1 -1
  28. package/dist-esm/src/EventBatch.js +1 -1
  29. package/dist-esm/src/HttpManager.d.ts +2 -1
  30. package/dist-esm/src/HttpManager.js +45 -40
  31. package/dist-esm/src/HttpManager.js.map +1 -1
  32. package/dist-esm/src/Index.js +1 -1
  33. package/dist-esm/src/KillSwitch.js +1 -1
  34. package/dist-esm/src/PostChannel.d.ts +2 -9
  35. package/dist-esm/src/PostChannel.js +151 -97
  36. package/dist-esm/src/PostChannel.js.map +1 -1
  37. package/dist-esm/src/RetryPolicy.d.ts +20 -25
  38. package/dist-esm/src/RetryPolicy.js +35 -44
  39. package/dist-esm/src/RetryPolicy.js.map +1 -1
  40. package/dist-esm/src/Serializer.js +1 -1
  41. package/dist-esm/src/TimeoutOverrideWrapper.d.ts +18 -0
  42. package/dist-esm/src/TimeoutOverrideWrapper.js +28 -0
  43. package/dist-esm/src/TimeoutOverrideWrapper.js.map +1 -0
  44. package/dist-esm/src/typings/XDomainRequest.js +1 -1
  45. package/package.json +3 -3
  46. package/src/HttpManager.ts +48 -51
  47. package/src/PostChannel.ts +186 -119
  48. package/src/RetryPolicy.ts +33 -38
  49. package/src/TimeoutOverrideWrapper.ts +29 -0
  50. package/bundle/ms.post-3.1.11.gbl.js.map +0 -1
  51. package/bundle/ms.post-3.1.11.gbl.min.js +0 -7
  52. package/bundle/ms.post-3.1.11.gbl.min.js.map +0 -1
  53. package/bundle/ms.post-3.1.11.integrity.json +0 -46
  54. package/bundle/ms.post-3.1.11.js.map +0 -1
  55. package/bundle/ms.post-3.1.11.min.js +0 -7
  56. package/bundle/ms.post-3.1.11.min.js.map +0 -1
package/bundle/ms.post.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * 1DS JS SDK POST plugin, 3.1.11
2
+ * 1DS JS SDK POST plugin, 3.2.2
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  * (Microsoft Internal Only)
5
5
  */
@@ -62,18 +62,6 @@
62
62
 
63
63
  (getGlobal() || {})["Symbol"];
64
64
  (getGlobal() || {})["Reflect"];
65
- var __objAssignFnImpl = function (t) {
66
- for (var s, i = 1, n = arguments.length; i < n; i++) {
67
- s = arguments[i];
68
- for (var p in s) {
69
- if (ObjProto[strShimHasOwnProperty].call(s, p)) {
70
- t[p] = s[p];
71
- }
72
- }
73
- }
74
- return t;
75
- };
76
- var __assignFn = ObjAssign || __objAssignFnImpl;
77
65
  var extendStaticsFn = function (d, b) {
78
66
  extendStaticsFn = ObjClass["setPrototypeOf"] ||
79
67
  ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
@@ -95,17 +83,8 @@
95
83
  d[strShimPrototype] = b === null ? objCreateFn(b) : (__[strShimPrototype] = b[strShimPrototype], new __());
96
84
  }
97
85
 
98
- var EventsDiscardedReason = {
99
- Unknown: 0,
100
- NonRetryableStatus: 1,
101
- InvalidEvent: 2,
102
- SizeLimitExceeded: 3,
103
- KillSwitch: 4,
104
- QueueFull: 5
105
- };
106
-
107
86
  /*!
108
- * Microsoft Dynamic Proto Utility, 1.1.4
87
+ * Microsoft Dynamic Proto Utility, 1.1.6
109
88
  * Copyright (c) Microsoft and contributors. All rights reserved.
110
89
  */
111
90
  var Constructor = 'constructor';
@@ -119,11 +98,14 @@
119
98
  var DynAllowInstChkTag = DynInstChkTag;
120
99
  var DynProtoDefaultOptions = '_dfOpts';
121
100
  var UnknownValue = '_unknown_';
122
- var str__Proto = "__proto__";
101
+ var str__Proto$1 = "__proto__";
102
+ var DynProtoBaseProto = "_dyn" + str__Proto$1;
103
+ var DynProtoCurrent = "_dynInstProto";
123
104
  var strUseBaseInst = 'useBaseInst';
124
105
  var strSetInstFuncs = 'setInstFuncs';
125
106
  var Obj = Object;
126
- var _objGetPrototypeOf = Obj["getPrototypeOf"];
107
+ var _objGetPrototypeOf$1 = Obj["getPrototypeOf"];
108
+ var _objGetOwnProps = Obj["getOwnPropertyNames"];
127
109
  var _dynamicNames = 0;
128
110
  function _hasOwnProperty(obj, prop) {
129
111
  return obj && Obj[Prototype].hasOwnProperty.call(obj, prop);
@@ -134,23 +116,26 @@
134
116
  function _isObjectArrayOrFunctionPrototype(target) {
135
117
  return _isObjectOrArrayPrototype(target) || target === Function[Prototype];
136
118
  }
137
- function _getObjProto(target) {
119
+ function _getObjProto$1(target) {
120
+ var newProto;
138
121
  if (target) {
139
- if (_objGetPrototypeOf) {
140
- return _objGetPrototypeOf(target);
122
+ if (_objGetPrototypeOf$1) {
123
+ return _objGetPrototypeOf$1(target);
141
124
  }
142
- var newProto = target[str__Proto] || target[Prototype] || (target[Constructor] ? target[Constructor][Prototype] : null);
143
- if (newProto) {
144
- return newProto;
125
+ var curProto = target[str__Proto$1] || target[Prototype] || (target[Constructor] ? target[Constructor][Prototype] : null);
126
+ newProto = target[DynProtoBaseProto] || curProto;
127
+ if (!_hasOwnProperty(target, DynProtoBaseProto)) {
128
+ delete target[DynProtoCurrent];
129
+ newProto = target[DynProtoBaseProto] = target[DynProtoCurrent] || target[DynProtoBaseProto];
130
+ target[DynProtoCurrent] = curProto;
145
131
  }
146
132
  }
147
- return null;
133
+ return newProto;
148
134
  }
149
135
  function _forEachProp(target, func) {
150
136
  var props = [];
151
- var getOwnProps = Obj["getOwnPropertyNames"];
152
- if (getOwnProps) {
153
- props = getOwnProps(target);
137
+ if (_objGetOwnProps) {
138
+ props = _objGetOwnProps(target);
154
139
  }
155
140
  else {
156
141
  for (var name_1 in target) {
@@ -205,16 +190,16 @@
205
190
  _forEachProp(instFuncs, function (name) {
206
191
  baseFuncs[name] = _instFuncProxy(thisTarget, instFuncs, name);
207
192
  });
208
- var baseProto = _getObjProto(classProto);
193
+ var baseProto = _getObjProto$1(classProto);
209
194
  var visited = [];
210
195
  while (baseProto && !_isObjectArrayOrFunctionPrototype(baseProto) && !_hasVisited(visited, baseProto)) {
211
196
  _forEachProp(baseProto, function (name) {
212
- if (!baseFuncs[name] && _isDynamicCandidate(baseProto, name, !_objGetPrototypeOf)) {
197
+ if (!baseFuncs[name] && _isDynamicCandidate(baseProto, name, !_objGetPrototypeOf$1)) {
213
198
  baseFuncs[name] = _instFuncProxy(thisTarget, baseProto, name);
214
199
  }
215
200
  });
216
201
  visited.push(baseProto);
217
- baseProto = _getObjProto(baseProto);
202
+ baseProto = _getObjProto$1(baseProto);
218
203
  }
219
204
  return baseFuncs;
220
205
  }
@@ -228,7 +213,7 @@
228
213
  }
229
214
  if (!instFunc[DynInstChkTag] && instFuncTable[DynAllowInstChkTag] !== false) {
230
215
  var canAddInst = !_hasOwnProperty(target, funcName);
231
- var objProto = _getObjProto(target);
216
+ var objProto = _getObjProto$1(target);
232
217
  var visited = [];
233
218
  while (canAddInst && objProto && !_isObjectArrayOrFunctionPrototype(objProto) && !_hasVisited(visited, objProto)) {
234
219
  var protoFunc = objProto[funcName];
@@ -237,7 +222,7 @@
237
222
  break;
238
223
  }
239
224
  visited.push(objProto);
240
- objProto = _getObjProto(objProto);
225
+ objProto = _getObjProto$1(objProto);
241
226
  }
242
227
  try {
243
228
  if (canAddInst) {
@@ -255,7 +240,7 @@
255
240
  function _getProtoFunc(funcName, proto, currentDynProtoProxy) {
256
241
  var protoFunc = proto[funcName];
257
242
  if (protoFunc === currentDynProtoProxy) {
258
- protoFunc = _getObjProto(proto)[funcName];
243
+ protoFunc = _getObjProto$1(proto)[funcName];
259
244
  }
260
245
  if (typeof protoFunc !== strFunction) {
261
246
  _throwTypeError("[" + funcName + "] is not a " + strFunction);
@@ -289,18 +274,19 @@
289
274
  }
290
275
  }
291
276
  function _checkPrototype(classProto, thisTarget) {
292
- if (_objGetPrototypeOf) {
277
+ if (_objGetPrototypeOf$1) {
293
278
  var visited = [];
294
- var thisProto = _getObjProto(thisTarget);
279
+ var thisProto = _getObjProto$1(thisTarget);
295
280
  while (thisProto && !_isObjectArrayOrFunctionPrototype(thisProto) && !_hasVisited(visited, thisProto)) {
296
281
  if (thisProto === classProto) {
297
282
  return true;
298
283
  }
299
284
  visited.push(thisProto);
300
- thisProto = _getObjProto(thisProto);
285
+ thisProto = _getObjProto$1(thisProto);
301
286
  }
287
+ return false;
302
288
  }
303
- return false;
289
+ return true;
304
290
  }
305
291
  function _getObjName(target, unknownValue) {
306
292
  if (_hasOwnProperty(target, Prototype)) {
@@ -333,7 +319,7 @@
333
319
  var instFuncs = _getInstanceFuncs(target);
334
320
  var baseFuncs = _getBaseFuncs(classProto, target, instFuncs, useBaseInst);
335
321
  delegateFunc(target, baseFuncs);
336
- var setInstanceFunc = !!_objGetPrototypeOf && !!perfOptions[strSetInstFuncs];
322
+ var setInstanceFunc = !!_objGetPrototypeOf$1 && !!perfOptions[strSetInstFuncs];
337
323
  if (setInstanceFunc && options) {
338
324
  setInstanceFunc = !!options[strSetInstFuncs];
339
325
  }
@@ -345,104 +331,23 @@
345
331
  };
346
332
  dynamicProto[DynProtoDefaultOptions] = perfDefaults;
347
333
 
348
- var LoggingSeverity;
349
- (function (LoggingSeverity) {
350
- LoggingSeverity[LoggingSeverity["CRITICAL"] = 1] = "CRITICAL";
351
- LoggingSeverity[LoggingSeverity["WARNING"] = 2] = "WARNING";
352
- })(LoggingSeverity || (LoggingSeverity = {}));
353
- var _InternalMessageId = {
354
- BrowserDoesNotSupportLocalStorage: 0,
355
- BrowserCannotReadLocalStorage: 1,
356
- BrowserCannotReadSessionStorage: 2,
357
- BrowserCannotWriteLocalStorage: 3,
358
- BrowserCannotWriteSessionStorage: 4,
359
- BrowserFailedRemovalFromLocalStorage: 5,
360
- BrowserFailedRemovalFromSessionStorage: 6,
361
- CannotSendEmptyTelemetry: 7,
362
- ClientPerformanceMathError: 8,
363
- ErrorParsingAISessionCookie: 9,
364
- ErrorPVCalc: 10,
365
- ExceptionWhileLoggingError: 11,
366
- FailedAddingTelemetryToBuffer: 12,
367
- FailedMonitorAjaxAbort: 13,
368
- FailedMonitorAjaxDur: 14,
369
- FailedMonitorAjaxOpen: 15,
370
- FailedMonitorAjaxRSC: 16,
371
- FailedMonitorAjaxSend: 17,
372
- FailedMonitorAjaxGetCorrelationHeader: 18,
373
- FailedToAddHandlerForOnBeforeUnload: 19,
374
- FailedToSendQueuedTelemetry: 20,
375
- FailedToReportDataLoss: 21,
376
- FlushFailed: 22,
377
- MessageLimitPerPVExceeded: 23,
378
- MissingRequiredFieldSpecification: 24,
379
- NavigationTimingNotSupported: 25,
380
- OnError: 26,
381
- SessionRenewalDateIsZero: 27,
382
- SenderNotInitialized: 28,
383
- StartTrackEventFailed: 29,
384
- StopTrackEventFailed: 30,
385
- StartTrackFailed: 31,
386
- StopTrackFailed: 32,
387
- TelemetrySampledAndNotSent: 33,
388
- TrackEventFailed: 34,
389
- TrackExceptionFailed: 35,
390
- TrackMetricFailed: 36,
391
- TrackPVFailed: 37,
392
- TrackPVFailedCalc: 38,
393
- TrackTraceFailed: 39,
394
- TransmissionFailed: 40,
395
- FailedToSetStorageBuffer: 41,
396
- FailedToRestoreStorageBuffer: 42,
397
- InvalidBackendResponse: 43,
398
- FailedToFixDepricatedValues: 44,
399
- InvalidDurationValue: 45,
400
- TelemetryEnvelopeInvalid: 46,
401
- CreateEnvelopeError: 47,
402
- CannotSerializeObject: 48,
403
- CannotSerializeObjectNonSerializable: 49,
404
- CircularReferenceDetected: 50,
405
- ClearAuthContextFailed: 51,
406
- ExceptionTruncated: 52,
407
- IllegalCharsInName: 53,
408
- ItemNotInArray: 54,
409
- MaxAjaxPerPVExceeded: 55,
410
- MessageTruncated: 56,
411
- NameTooLong: 57,
412
- SampleRateOutOfRange: 58,
413
- SetAuthContextFailed: 59,
414
- SetAuthContextFailedAccountName: 60,
415
- StringValueTooLong: 61,
416
- StartCalledMoreThanOnce: 62,
417
- StopCalledWithoutStart: 63,
418
- TelemetryInitializerFailed: 64,
419
- TrackArgumentsNotSpecified: 65,
420
- UrlTooLong: 66,
421
- SessionStorageBufferFull: 67,
422
- CannotAccessCookie: 68,
423
- IdTooLong: 69,
424
- InvalidEvent: 70,
425
- FailedMonitorAjaxSetRequestHeader: 71,
426
- SendBrowserInfoOnUserInit: 72,
427
- PluginException: 73,
428
- NotificationException: 74,
429
- SnippetScriptLoadFailure: 99,
430
- InvalidInstrumentationKey: 100,
431
- CannotParseAiBlobValue: 101,
432
- InvalidContentBlob: 102,
433
- TrackPageActionEventFailed: 103,
434
- FailedAddingCustomDefinedRequestContext: 104,
435
- InMemoryStorageBufferFull: 105
436
- };
334
+ var strEmpty = "";
335
+ var strSetNextPlugin = "setNextPlugin";
336
+ var strIsInitialized = "isInitialized";
337
+ var strTeardown = "teardown";
338
+ var strCore = "core";
339
+ var strUpdate = "update";
340
+ var strDisabled = "disabled";
341
+ var strDoTeardown = "_doTeardown";
437
342
 
438
- var strOnPrefix = "on";
439
- var strAttachEvent = "attachEvent";
440
- var strAddEventHelper = "addEventListener";
441
343
  var cStrStartsWith = "startsWith";
442
344
  var strIndexOf = "indexOf";
443
345
  var cStrTrim = "trim";
444
346
  var strToString = "toString";
445
- var _objDefineProperty = ObjDefineProperty;
347
+ var str__Proto = "__proto__";
348
+ var strConstructor = "constructor";
349
+ var _objDefineProperty$1 = ObjDefineProperty;
350
+ var _objFreeze = ObjClass.freeze;
446
351
  var _objKeys = ObjClass.keys;
447
352
  var StringProto = String[strShimPrototype];
448
353
  var _strTrim = StringProto[cStrTrim];
@@ -450,7 +355,23 @@
450
355
  var _isArray = Array.isArray;
451
356
  var _objToString = ObjProto[strToString];
452
357
  var _fnToString = ObjHasOwnProperty[strToString];
453
- _fnToString.call(ObjClass);
358
+ var _objFunctionString = _fnToString.call(ObjClass);
359
+ var rCamelCase = /-([a-z])/g;
360
+ var rNormalizeInvalid = /([^\w\d_$])/g;
361
+ var rLeadingNumeric = /^(\d+[\w\d_$])/;
362
+ var _objGetPrototypeOf = Object["getPrototypeOf"];
363
+ function _getObjProto(target) {
364
+ if (target) {
365
+ if (_objGetPrototypeOf) {
366
+ return _objGetPrototypeOf(target);
367
+ }
368
+ var newProto = target[str__Proto] || target[strShimPrototype] || target[strConstructor];
369
+ if (newProto) {
370
+ return newProto;
371
+ }
372
+ }
373
+ return null;
374
+ }
454
375
  function isUndefined(value) {
455
376
  return value === undefined || typeof value === strShimUndefined;
456
377
  }
@@ -466,24 +387,18 @@
466
387
  function isFunction(value) {
467
388
  return !!(value && typeof value === strShimFunction);
468
389
  }
469
- function attachEvent(obj, eventNameWithoutOn, handlerRef, useCapture) {
470
- if (useCapture === void 0) { useCapture = false; }
471
- var result = false;
472
- if (!isNullOrUndefined(obj)) {
473
- try {
474
- if (!isNullOrUndefined(obj[strAddEventHelper])) {
475
- obj[strAddEventHelper](eventNameWithoutOn, handlerRef, useCapture);
476
- result = true;
477
- }
478
- else if (!isNullOrUndefined(obj[strAttachEvent])) {
479
- obj[strAttachEvent](strOnPrefix + eventNameWithoutOn, handlerRef);
480
- result = true;
481
- }
482
- }
483
- catch (e) {
484
- }
390
+ function normalizeJsName(name) {
391
+ var value = name;
392
+ if (value && isString(value)) {
393
+ value = value.replace(rCamelCase, function (_all, letter) {
394
+ return letter.toUpperCase();
395
+ });
396
+ value = value.replace(rNormalizeInvalid, "_");
397
+ value = value.replace(rLeadingNumeric, function (_all, match) {
398
+ return "_" + match;
399
+ });
485
400
  }
486
- return result;
401
+ return value;
487
402
  }
488
403
  function objForEachKey(target, callbackfn) {
489
404
  if (target) {
@@ -514,6 +429,12 @@
514
429
  }
515
430
  return result;
516
431
  }
432
+ function strContains(value, search) {
433
+ if (value && search) {
434
+ return value.indexOf(search) !== -1;
435
+ }
436
+ return false;
437
+ }
517
438
  var isArray = _isArray || _isArrayPoly;
518
439
  function _isArrayPoly(obj) {
519
440
  return !!(obj && _objToString.call(obj) === "[object Array]");
@@ -527,6 +448,22 @@
527
448
  function isBoolean(value) {
528
449
  return typeof value === "boolean";
529
450
  }
451
+ function isPlainObject(value) {
452
+ var result = false;
453
+ if (value && typeof value === "object") {
454
+ var proto = _objGetPrototypeOf ? _objGetPrototypeOf(value) : _getObjProto(value);
455
+ if (!proto) {
456
+ result = true;
457
+ }
458
+ else {
459
+ if (proto[strConstructor] && ObjHasOwnProperty.call(proto, strConstructor)) {
460
+ proto = proto[strConstructor];
461
+ }
462
+ result = typeof proto === strShimFunction && _fnToString.call(proto) === _objFunctionString;
463
+ }
464
+ }
465
+ return result;
466
+ }
530
467
  function arrForEach(arr, callbackfn, thisArg) {
531
468
  var len = arr.length;
532
469
  try {
@@ -601,7 +538,7 @@
601
538
  return result;
602
539
  }
603
540
  function objDefineAccessors(target, prop, getProp, setProp) {
604
- if (_objDefineProperty) {
541
+ if (_objDefineProperty$1) {
605
542
  try {
606
543
  var descriptor = {
607
544
  enumerable: true,
@@ -613,7 +550,7 @@
613
550
  if (setProp) {
614
551
  descriptor.set = setProp;
615
552
  }
616
- _objDefineProperty(target, prop, descriptor);
553
+ _objDefineProperty$1(target, prop, descriptor);
617
554
  return true;
618
555
  }
619
556
  catch (e) {
@@ -621,6 +558,20 @@
621
558
  }
622
559
  return false;
623
560
  }
561
+ function _doNothing(value) {
562
+ return value;
563
+ }
564
+ function deepFreeze(obj) {
565
+ if (_objFreeze) {
566
+ objForEachKey(obj, function (name, value) {
567
+ if (isArray(value) || isObject(value)) {
568
+ _objFreeze(value);
569
+ }
570
+ });
571
+ }
572
+ return objFreeze(obj);
573
+ }
574
+ var objFreeze = _objFreeze || _doNothing;
624
575
  function dateNow() {
625
576
  var dt = Date;
626
577
  return dt.now ? dt.now() : new dt().getTime();
@@ -636,12 +587,100 @@
636
587
  }
637
588
  return theValue;
638
589
  }
590
+ function _createProxyFunction(source, funcName) {
591
+ var srcFunc = null;
592
+ var src = null;
593
+ if (isFunction(source)) {
594
+ srcFunc = source;
595
+ }
596
+ else {
597
+ src = source;
598
+ }
599
+ return function () {
600
+ var originalArguments = arguments;
601
+ if (srcFunc) {
602
+ src = srcFunc();
603
+ }
604
+ if (src) {
605
+ return src[funcName].apply(src, originalArguments);
606
+ }
607
+ };
608
+ }
609
+ function proxyFunctionAs(target, name, source, theFunc, overwriteTarget) {
610
+ if (target && name && source) {
611
+ if (overwriteTarget !== false || isUndefined(target[name])) {
612
+ target[name] = _createProxyFunction(source, theFunc);
613
+ }
614
+ }
615
+ }
639
616
  function optimizeObject(theObject) {
640
617
  if (theObject && ObjAssign) {
641
618
  theObject = ObjClass(ObjAssign({}, theObject));
642
619
  }
643
620
  return theObject;
644
621
  }
622
+ function objExtend(obj1, obj2, obj3, obj4, obj5, obj6) {
623
+ var theArgs = arguments;
624
+ var extended = theArgs[0] || {};
625
+ var argLen = theArgs.length;
626
+ var deep = false;
627
+ var idx = 1;
628
+ if (argLen > 0 && isBoolean(extended)) {
629
+ deep = extended;
630
+ extended = theArgs[idx] || {};
631
+ idx++;
632
+ }
633
+ if (!isObject(extended)) {
634
+ extended = {};
635
+ }
636
+ for (; idx < argLen; idx++) {
637
+ var arg = theArgs[idx];
638
+ var isArgArray = isArray(arg);
639
+ var isArgObj = isObject(arg);
640
+ for (var prop in arg) {
641
+ var propOk = (isArgArray && (prop in arg)) || (isArgObj && (ObjHasOwnProperty.call(arg, prop)));
642
+ if (!propOk) {
643
+ continue;
644
+ }
645
+ var newValue = arg[prop];
646
+ var isNewArray = void 0;
647
+ if (deep && newValue && ((isNewArray = isArray(newValue)) || isPlainObject(newValue))) {
648
+ var clone = extended[prop];
649
+ if (isNewArray) {
650
+ if (!isArray(clone)) {
651
+ clone = [];
652
+ }
653
+ }
654
+ else if (!isPlainObject(clone)) {
655
+ clone = {};
656
+ }
657
+ newValue = objExtend(deep, clone, newValue);
658
+ }
659
+ if (newValue !== undefined) {
660
+ extended[prop] = newValue;
661
+ }
662
+ }
663
+ }
664
+ return extended;
665
+ }
666
+
667
+ function createEnumStyle(values) {
668
+ var enumClass = {};
669
+ objForEachKey(values, function (field, value) {
670
+ enumClass[field] = value;
671
+ enumClass[value] = field;
672
+ });
673
+ return deepFreeze(enumClass);
674
+ }
675
+
676
+ var EventsDiscardedReason = createEnumStyle({
677
+ Unknown: 0 ,
678
+ NonRetryableStatus: 1 ,
679
+ InvalidEvent: 2 ,
680
+ SizeLimitExceeded: 3 ,
681
+ KillSwitch: 4 ,
682
+ QueueFull: 5
683
+ });
645
684
 
646
685
  var strWindow = "window";
647
686
  var strDocument = "document";
@@ -650,7 +689,14 @@
650
689
  var strConsole = "console";
651
690
  var strPerformance = "performance";
652
691
  var strJSON = "JSON";
692
+ var strCrypto = "crypto";
693
+ var strMsCrypto = "msCrypto";
653
694
  var strReactNative = "ReactNative";
695
+ var strMsie = "msie";
696
+ var strTrident = "trident/";
697
+ var strXMLHttpRequest = "XMLHttpRequest";
698
+ var _isTrident = null;
699
+ var _navUserAgentCheck = null;
654
700
  var _enableMocks = false;
655
701
  var _useXDomainRequest = null;
656
702
  var _beaconsSupported = null;
@@ -746,6 +792,12 @@
746
792
  }
747
793
  return null;
748
794
  }
795
+ function getCrypto() {
796
+ return getGlobalInst(strCrypto);
797
+ }
798
+ function getMsCrypto() {
799
+ return getGlobalInst(strMsCrypto);
800
+ }
749
801
  function isReactNative() {
750
802
  var nav = getNavigator();
751
803
  if (nav && nav.product) {
@@ -753,9 +805,18 @@
753
805
  }
754
806
  return false;
755
807
  }
808
+ function isIE() {
809
+ var nav = getNavigator();
810
+ if (nav && (nav.userAgent !== _navUserAgentCheck || _isTrident === null)) {
811
+ _navUserAgentCheck = nav.userAgent;
812
+ var userAgent = (_navUserAgentCheck || strEmpty).toLowerCase();
813
+ _isTrident = (strContains(userAgent, strMsie) || strContains(userAgent, strTrident));
814
+ }
815
+ return _isTrident;
816
+ }
756
817
  function dumpObj(object) {
757
818
  var objectTypeDump = Object[strShimPrototype].toString.call(object);
758
- var propertyValueDump = "";
819
+ var propertyValueDump = strEmpty;
759
820
  if (objectTypeDump === "[object Error]") {
760
821
  propertyValueDump = "{ stack: '" + object.stack + "', message: '" + object.message + "', name: '" + object.name + "'";
761
822
  }
@@ -773,8 +834,7 @@
773
834
  function isFetchSupported(withKeepAlive) {
774
835
  var isSupported = false;
775
836
  try {
776
- var fetchApi = getGlobalInst("fetch");
777
- isSupported = !!fetchApi;
837
+ isSupported = !!getGlobalInst("fetch");
778
838
  var request = getGlobalInst("Request");
779
839
  if (isSupported && withKeepAlive && request) {
780
840
  isSupported = _hasProperty(request, "keepalive");
@@ -786,9 +846,9 @@
786
846
  }
787
847
  function useXDomainRequest() {
788
848
  if (_useXDomainRequest === null) {
789
- _useXDomainRequest = (typeof XDomainRequest !== "undefined");
849
+ _useXDomainRequest = (typeof XDomainRequest !== strShimUndefined);
790
850
  if (_useXDomainRequest && isXhrSupported()) {
791
- _useXDomainRequest = _useXDomainRequest && !_hasProperty(getGlobalInst("XMLHttpRequest"), "withCredentials");
851
+ _useXDomainRequest = _useXDomainRequest && !_hasProperty(getGlobalInst(strXMLHttpRequest), "withCredentials");
792
852
  }
793
853
  }
794
854
  return _useXDomainRequest;
@@ -796,7 +856,7 @@
796
856
  function isXhrSupported() {
797
857
  var isSupported = false;
798
858
  try {
799
- var xmlHttpRequest = getGlobalInst("XMLHttpRequest");
859
+ var xmlHttpRequest = getGlobalInst(strXMLHttpRequest);
800
860
  isSupported = !!xmlHttpRequest;
801
861
  }
802
862
  catch (e) {
@@ -827,9 +887,9 @@
827
887
  var strWarnToConsole = "warnToConsole";
828
888
  function _sanitizeDiagnosticText(text) {
829
889
  if (text) {
830
- return "\"" + text.replace(/\"/g, "") + "\"";
890
+ return "\"" + text.replace(/\"/g, strEmpty) + "\"";
831
891
  }
832
- return "";
892
+ return strEmpty;
833
893
  }
834
894
  function _logToConsole(func, message) {
835
895
  var theConsole = getConsole();
@@ -851,12 +911,12 @@
851
911
  _self.message =
852
912
  (isUserAct ? AiUserActionablePrefix : AiNonUserActionablePrefix) +
853
913
  msgId;
854
- var strProps = "";
914
+ var strProps = strEmpty;
855
915
  if (hasJSON()) {
856
916
  strProps = getJSON().stringify(properties);
857
917
  }
858
- var diagnosticText = (msg ? " message:" + _sanitizeDiagnosticText(msg) : "") +
859
- (properties ? " props:" + _sanitizeDiagnosticText(strProps) : "");
918
+ var diagnosticText = (msg ? " message:" + _sanitizeDiagnosticText(msg) : strEmpty) +
919
+ (properties ? " props:" + _sanitizeDiagnosticText(strProps) : strEmpty);
860
920
  _self.message += diagnosticText;
861
921
  }
862
922
  _InternalLogMessage.dataType = "MessageData";
@@ -883,10 +943,10 @@
883
943
  if (isUserAct === void 0) { isUserAct = false; }
884
944
  var message = new _InternalLogMessage(msgId, msg, isUserAct, properties);
885
945
  if (_self.enableDebugExceptions()) {
886
- throw message;
946
+ throw dumpObj(message);
887
947
  }
888
948
  else {
889
- var logFunc = severity === LoggingSeverity.CRITICAL ? strErrorToConsole : strWarnToConsole;
949
+ var logFunc = severity === 1 ? strErrorToConsole : strWarnToConsole;
890
950
  if (!isUndefined(message.message)) {
891
951
  var logLevel = _self.consoleLoggingLevel();
892
952
  if (isUserAct) {
@@ -904,7 +964,7 @@
904
964
  _self.logInternalMessage(severity, message);
905
965
  }
906
966
  else {
907
- _debugExtMsg("throw" + (severity === LoggingSeverity.CRITICAL ? "Critical" : "Warning"), message);
967
+ _debugExtMsg("throw" + (severity === 1 ? "Critical" : "Warning"), message);
908
968
  }
909
969
  }
910
970
  };
@@ -936,13 +996,13 @@
936
996
  if (severity <= _self.telemetryLoggingLevel()) {
937
997
  _self.queue.push(message);
938
998
  _messageCount++;
939
- _debugExtMsg((severity === LoggingSeverity.CRITICAL ? "error" : "warn"), message);
999
+ _debugExtMsg((severity === 1 ? "error" : "warn"), message);
940
1000
  }
941
1001
  if (_messageCount === _self.maxInternalMessageLimit()) {
942
1002
  var throttleLimitMessage = "Internal events throttle limit per PageView reached for this app.";
943
- var throttleMessage = new _InternalLogMessage(_InternalMessageId.MessageLimitPerPVExceeded, throttleLimitMessage, false);
1003
+ var throttleMessage = new _InternalLogMessage(23 , throttleLimitMessage, false);
944
1004
  _self.queue.push(throttleMessage);
945
- if (severity === LoggingSeverity.CRITICAL) {
1005
+ if (severity === 1 ) {
946
1006
  _self.errorToConsole(throttleLimitMessage);
947
1007
  }
948
1008
  else {
@@ -971,6 +1031,10 @@
971
1031
  }
972
1032
  return DiagnosticLogger;
973
1033
  }());
1034
+ function _throwInternal(logger, severity, msgId, msg, properties, isUserAct) {
1035
+ if (isUserAct === void 0) { isUserAct = false; }
1036
+ (logger || new DiagnosticLogger()).throwInternal(severity, msgId, msg, properties, isUserAct);
1037
+ }
974
1038
 
975
1039
  var strExecutionContextKey = "ctx";
976
1040
  var PerfEvent = /** @class */ (function () {
@@ -1084,207 +1148,621 @@
1084
1148
  return func();
1085
1149
  }
1086
1150
 
1087
- var TelemetryPluginChain = /** @class */ (function () {
1088
- function TelemetryPluginChain(plugin, defItemCtx) {
1089
- var _self = this;
1090
- var _nextProxy = null;
1091
- var _hasProcessTelemetry = isFunction(plugin.processTelemetry);
1092
- var _hasSetNext = isFunction(plugin.setNextPlugin);
1093
- _self._hasRun = false;
1094
- _self.getPlugin = function () {
1095
- return plugin;
1096
- };
1097
- _self.getNext = function () {
1098
- return _nextProxy;
1099
- };
1100
- _self.setNext = function (nextPlugin) {
1101
- _nextProxy = nextPlugin;
1102
- };
1103
- _self.processTelemetry = function (env, itemCtx) {
1104
- if (!itemCtx) {
1105
- itemCtx = defItemCtx;
1151
+ var UInt32Mask = 0x100000000;
1152
+ var MaxUInt32 = 0xffffffff;
1153
+ var _mwcSeeded = false;
1154
+ var _mwcW = 123456789;
1155
+ var _mwcZ = 987654321;
1156
+ function _mwcSeed(seedValue) {
1157
+ if (seedValue < 0) {
1158
+ seedValue >>>= 0;
1159
+ }
1160
+ _mwcW = (123456789 + seedValue) & MaxUInt32;
1161
+ _mwcZ = (987654321 - seedValue) & MaxUInt32;
1162
+ _mwcSeeded = true;
1163
+ }
1164
+ function _autoSeedMwc() {
1165
+ try {
1166
+ var now = dateNow() & 0x7fffffff;
1167
+ _mwcSeed(((Math.random() * UInt32Mask) ^ now) + now);
1168
+ }
1169
+ catch (e) {
1170
+ }
1171
+ }
1172
+ function random32(signed) {
1173
+ var value = 0;
1174
+ var c = getCrypto() || getMsCrypto();
1175
+ if (c && c.getRandomValues) {
1176
+ value = c.getRandomValues(new Uint32Array(1))[0] & MaxUInt32;
1177
+ }
1178
+ if (value === 0 && isIE()) {
1179
+ if (!_mwcSeeded) {
1180
+ _autoSeedMwc();
1181
+ }
1182
+ value = mwcRandom32() & MaxUInt32;
1183
+ }
1184
+ if (value === 0) {
1185
+ value = Math.floor((UInt32Mask * Math.random()) | 0);
1186
+ }
1187
+ if (!signed) {
1188
+ value >>>= 0;
1189
+ }
1190
+ return value;
1191
+ }
1192
+ function mwcRandom32(signed) {
1193
+ _mwcZ = (36969 * (_mwcZ & 0xFFFF) + (_mwcZ >> 16)) & MaxUInt32;
1194
+ _mwcW = (18000 * (_mwcW & 0xFFFF) + (_mwcW >> 16)) & MaxUInt32;
1195
+ var value = (((_mwcZ << 16) + (_mwcW & 0xFFFF)) >>> 0) & MaxUInt32 | 0;
1196
+ if (!signed) {
1197
+ value >>>= 0;
1198
+ }
1199
+ return value;
1200
+ }
1201
+ function newId(maxLength) {
1202
+ if (maxLength === void 0) { maxLength = 22; }
1203
+ var base64chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
1204
+ var number = random32() >>> 0;
1205
+ var chars = 0;
1206
+ var result = strEmpty;
1207
+ while (result.length < maxLength) {
1208
+ chars++;
1209
+ result += base64chars.charAt(number & 0x3F);
1210
+ number >>>= 6;
1211
+ if (chars === 5) {
1212
+ number = (((random32() << 2) & 0xFFFFFFFF) | (number & 0x03)) >>> 0;
1213
+ chars = 0;
1214
+ }
1215
+ }
1216
+ return result;
1217
+ }
1218
+
1219
+ var _objDefineProperty = ObjDefineProperty;
1220
+ var version = "2.8.3";
1221
+ var instanceName = "." + newId(6);
1222
+ var _dataUid = 0;
1223
+ function _createAccessor(target, prop, value) {
1224
+ if (_objDefineProperty) {
1225
+ try {
1226
+ _objDefineProperty(target, prop, {
1227
+ value: value,
1228
+ enumerable: false,
1229
+ configurable: true
1230
+ });
1231
+ return true;
1232
+ }
1233
+ catch (e) {
1234
+ }
1235
+ }
1236
+ return false;
1237
+ }
1238
+ function _canAcceptData(target) {
1239
+ return target.nodeType === 1 || target.nodeType === 9 || !(+target.nodeType);
1240
+ }
1241
+ function _getCache(data, target) {
1242
+ var theCache = target[data.id];
1243
+ if (!theCache) {
1244
+ theCache = {};
1245
+ try {
1246
+ if (_canAcceptData(target)) {
1247
+ if (!_createAccessor(target, data.id, theCache)) {
1248
+ target[data.id] = theCache;
1249
+ }
1250
+ }
1251
+ }
1252
+ catch (e) {
1253
+ }
1254
+ }
1255
+ return theCache;
1256
+ }
1257
+ function createUniqueNamespace(name, includeVersion) {
1258
+ if (includeVersion === void 0) { includeVersion = false; }
1259
+ return normalizeJsName(name + (_dataUid++) + (includeVersion ? "." + version : "") + instanceName);
1260
+ }
1261
+ function createElmNodeData(name) {
1262
+ var data = {
1263
+ id: createUniqueNamespace("_aiData-" + (name || "") + "." + version),
1264
+ accept: function (target) {
1265
+ return _canAcceptData(target);
1266
+ },
1267
+ get: function (target, name, defValue, addDefault) {
1268
+ var theCache = target[data.id];
1269
+ if (!theCache) {
1270
+ if (addDefault) {
1271
+ theCache = _getCache(data, target);
1272
+ theCache[normalizeJsName(name)] = defValue;
1273
+ }
1274
+ return defValue;
1275
+ }
1276
+ return theCache[normalizeJsName(name)];
1277
+ },
1278
+ kill: function (target, name) {
1279
+ if (target && target[name]) {
1280
+ try {
1281
+ delete target[name];
1282
+ }
1283
+ catch (e) {
1284
+ }
1106
1285
  }
1107
- var identifier = plugin ? plugin.identifier : "TelemetryPluginChain";
1108
- doPerf(itemCtx ? itemCtx.core() : null, function () { return identifier + ":processTelemetry"; }, function () {
1109
- if (plugin && _hasProcessTelemetry) {
1110
- _self._hasRun = true;
1286
+ }
1287
+ };
1288
+ return data;
1289
+ }
1290
+
1291
+ var pluginStateData = createElmNodeData("plugin");
1292
+ function _getPluginState(plugin) {
1293
+ return pluginStateData.get(plugin, "state", {}, true);
1294
+ }
1295
+
1296
+ var strTelemetryPluginChain = "TelemetryPluginChain";
1297
+ var strHasRunFlags = "_hasRun";
1298
+ var strGetTelCtx = "_getTelCtx";
1299
+ var _chainId = 0;
1300
+ function _getNextProxyStart(proxy, core, startAt) {
1301
+ while (proxy) {
1302
+ if (proxy.getPlugin() === startAt) {
1303
+ return proxy;
1304
+ }
1305
+ proxy = proxy.getNext();
1306
+ }
1307
+ return createTelemetryProxyChain([startAt], core.config || {}, core);
1308
+ }
1309
+ function _createInternalContext(telemetryChain, config, core, startAt) {
1310
+ var _nextProxy = null;
1311
+ var _onComplete = [];
1312
+ if (startAt !== null) {
1313
+ _nextProxy = startAt ? _getNextProxyStart(telemetryChain, core, startAt) : telemetryChain;
1314
+ }
1315
+ var context = {
1316
+ _next: _moveNext,
1317
+ ctx: {
1318
+ core: function () {
1319
+ return core;
1320
+ },
1321
+ diagLog: function () {
1322
+ return safeGetLogger(core, config);
1323
+ },
1324
+ getCfg: function () {
1325
+ return config;
1326
+ },
1327
+ getExtCfg: _getExtCfg,
1328
+ getConfig: _getConfig,
1329
+ hasNext: function () {
1330
+ return !!_nextProxy;
1331
+ },
1332
+ getNext: function () {
1333
+ return _nextProxy;
1334
+ },
1335
+ setNext: function (nextPlugin) {
1336
+ _nextProxy = nextPlugin;
1337
+ },
1338
+ iterate: _iterateChain,
1339
+ onComplete: _addOnComplete
1340
+ }
1341
+ };
1342
+ function _addOnComplete(onComplete, that) {
1343
+ var args = [];
1344
+ for (var _i = 2; _i < arguments.length; _i++) {
1345
+ args[_i - 2] = arguments[_i];
1346
+ }
1347
+ if (onComplete) {
1348
+ _onComplete.push({
1349
+ func: onComplete,
1350
+ self: !isUndefined(that) ? that : context.ctx,
1351
+ args: args
1352
+ });
1353
+ }
1354
+ }
1355
+ function _moveNext() {
1356
+ var nextProxy = _nextProxy;
1357
+ _nextProxy = nextProxy ? nextProxy.getNext() : null;
1358
+ if (!nextProxy) {
1359
+ var onComplete = _onComplete;
1360
+ if (onComplete && onComplete.length > 0) {
1361
+ arrForEach(onComplete, function (completeDetails) {
1111
1362
  try {
1112
- itemCtx.setNext(_nextProxy);
1113
- if (_hasSetNext) {
1114
- plugin.setNextPlugin(_nextProxy);
1115
- }
1116
- _nextProxy && (_nextProxy._hasRun = false);
1117
- plugin.processTelemetry(env, itemCtx);
1363
+ completeDetails.func.call(completeDetails.self, completeDetails.args);
1118
1364
  }
1119
- catch (error) {
1120
- var hasRun = _nextProxy && _nextProxy._hasRun;
1121
- if (!_nextProxy || !hasRun) {
1122
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.PluginException, "Plugin [" + plugin.identifier + "] failed during processTelemetry - " + dumpObj(error));
1123
- }
1124
- if (_nextProxy && !hasRun) {
1125
- _nextProxy.processTelemetry(env, itemCtx);
1126
- }
1365
+ catch (e) {
1366
+ _throwInternal(core.logger, 2 , 73 , "Unexpected Exception during onComplete - " + dumpObj(e));
1127
1367
  }
1128
- }
1129
- else if (_nextProxy) {
1130
- _self._hasRun = true;
1131
- _nextProxy.processTelemetry(env, itemCtx);
1132
- }
1133
- }, function () { return ({ item: env }); }, !(env.sync));
1134
- };
1368
+ });
1369
+ _onComplete = [];
1370
+ }
1371
+ }
1372
+ return nextProxy;
1135
1373
  }
1136
- return TelemetryPluginChain;
1137
- }());
1138
-
1139
- function _createProxyChain(plugins, itemCtx) {
1140
- var proxies = [];
1141
- if (plugins && plugins.length > 0) {
1142
- var lastProxy = null;
1143
- for (var idx = 0; idx < plugins.length; idx++) {
1144
- var thePlugin = plugins[idx];
1145
- if (thePlugin && isFunction(thePlugin.processTelemetry)) {
1146
- var newProxy = new TelemetryPluginChain(thePlugin, itemCtx);
1147
- proxies.push(newProxy);
1148
- if (lastProxy) {
1149
- lastProxy.setNext(newProxy);
1374
+ function _getExtCfg(identifier, defaultValue, mergeDefault) {
1375
+ if (defaultValue === void 0) { defaultValue = {}; }
1376
+ if (mergeDefault === void 0) { mergeDefault = 0 ; }
1377
+ var theConfig;
1378
+ if (config) {
1379
+ var extConfig = config.extensionConfig;
1380
+ if (extConfig && identifier) {
1381
+ theConfig = extConfig[identifier];
1382
+ }
1383
+ }
1384
+ if (!theConfig) {
1385
+ theConfig = defaultValue;
1386
+ }
1387
+ else if (isObject(defaultValue)) {
1388
+ if (mergeDefault !== 0 ) {
1389
+ var newConfig_1 = objExtend(true, defaultValue, theConfig);
1390
+ if (config && mergeDefault === 2 ) {
1391
+ objForEachKey(defaultValue, function (field) {
1392
+ if (isNullOrUndefined(newConfig_1[field])) {
1393
+ var cfgValue = config[field];
1394
+ if (!isNullOrUndefined(cfgValue)) {
1395
+ newConfig_1[field] = cfgValue;
1396
+ }
1397
+ }
1398
+ });
1150
1399
  }
1151
- lastProxy = newProxy;
1400
+ theConfig = newConfig_1;
1152
1401
  }
1153
1402
  }
1403
+ return theConfig;
1154
1404
  }
1155
- return proxies.length > 0 ? proxies[0] : null;
1156
- }
1157
- function _copyProxyChain(proxy, itemCtx, startAt) {
1158
- var plugins = [];
1159
- var add = startAt ? false : true;
1160
- if (proxy) {
1161
- while (proxy) {
1162
- var thePlugin = proxy.getPlugin();
1163
- if (add || thePlugin === startAt) {
1164
- add = true;
1165
- plugins.push(thePlugin);
1405
+ function _getConfig(identifier, field, defaultValue) {
1406
+ if (defaultValue === void 0) { defaultValue = false; }
1407
+ var theValue;
1408
+ var extConfig = _getExtCfg(identifier, null);
1409
+ if (extConfig && !isNullOrUndefined(extConfig[field])) {
1410
+ theValue = extConfig[field];
1411
+ }
1412
+ else if (config && !isNullOrUndefined(config[field])) {
1413
+ theValue = config[field];
1414
+ }
1415
+ return !isNullOrUndefined(theValue) ? theValue : defaultValue;
1416
+ }
1417
+ function _iterateChain(cb) {
1418
+ var nextPlugin;
1419
+ while (!!(nextPlugin = context._next())) {
1420
+ var plugin = nextPlugin.getPlugin();
1421
+ if (plugin) {
1422
+ cb(plugin);
1166
1423
  }
1167
- proxy = proxy.getNext();
1168
1424
  }
1169
1425
  }
1170
- if (!add) {
1171
- plugins.push(startAt);
1426
+ return context;
1427
+ }
1428
+ function createProcessTelemetryContext(telemetryChain, config, core, startAt) {
1429
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1430
+ var context = internalContext.ctx;
1431
+ function _processNext(env) {
1432
+ var nextPlugin = internalContext._next();
1433
+ nextPlugin && nextPlugin.processTelemetry(env, context);
1434
+ return !nextPlugin;
1435
+ }
1436
+ function _createNew(plugins, startAt) {
1437
+ if (plugins === void 0) { plugins = null; }
1438
+ if (isArray(plugins)) {
1439
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1440
+ }
1441
+ return createProcessTelemetryContext(plugins || context.getNext(), config, core, startAt);
1172
1442
  }
1173
- return _createProxyChain(plugins, itemCtx);
1443
+ context.processNext = _processNext;
1444
+ context.createNew = _createNew;
1445
+ return context;
1174
1446
  }
1175
- function _copyPluginChain(srcPlugins, itemCtx, startAt) {
1176
- var plugins = srcPlugins;
1177
- var add = false;
1178
- if (startAt && srcPlugins) {
1179
- plugins = [];
1180
- arrForEach(srcPlugins, function (thePlugin) {
1181
- if (add || thePlugin === startAt) {
1182
- add = true;
1183
- plugins.push(thePlugin);
1447
+ function createProcessTelemetryUnloadContext(telemetryChain, core, startAt) {
1448
+ var config = core.config || {};
1449
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1450
+ var context = internalContext.ctx;
1451
+ function _processNext(unloadState) {
1452
+ var nextPlugin = internalContext._next();
1453
+ nextPlugin && nextPlugin.unload(context, unloadState);
1454
+ return !nextPlugin;
1455
+ }
1456
+ function _createNew(plugins, startAt) {
1457
+ if (plugins === void 0) { plugins = null; }
1458
+ if (isArray(plugins)) {
1459
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1460
+ }
1461
+ return createProcessTelemetryUnloadContext(plugins || context.getNext(), core, startAt);
1462
+ }
1463
+ context.processNext = _processNext;
1464
+ context.createNew = _createNew;
1465
+ return context;
1466
+ }
1467
+ function createProcessTelemetryUpdateContext(telemetryChain, core, startAt) {
1468
+ var config = core.config || {};
1469
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1470
+ var context = internalContext.ctx;
1471
+ function _processNext(updateState) {
1472
+ return context.iterate(function (plugin) {
1473
+ if (isFunction(plugin.update)) {
1474
+ plugin.update(context, updateState);
1184
1475
  }
1185
1476
  });
1186
1477
  }
1187
- if (startAt && !add) {
1188
- if (!plugins) {
1189
- plugins = [];
1478
+ function _createNew(plugins, startAt) {
1479
+ if (plugins === void 0) { plugins = null; }
1480
+ if (isArray(plugins)) {
1481
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1190
1482
  }
1191
- plugins.push(startAt);
1483
+ return createProcessTelemetryUpdateContext(plugins || context.getNext(), core, startAt);
1192
1484
  }
1193
- return _createProxyChain(plugins, itemCtx);
1485
+ context.processNext = _processNext;
1486
+ context.createNew = _createNew;
1487
+ return context;
1194
1488
  }
1195
- var ProcessTelemetryContext = /** @class */ (function () {
1196
- function ProcessTelemetryContext(plugins, config, core, startAt) {
1197
- var _self = this;
1198
- var _nextProxy = null;
1199
- if (startAt !== null) {
1200
- if (plugins && isFunction(plugins.getPlugin)) {
1201
- _nextProxy = _copyProxyChain(plugins, _self, startAt || plugins.getPlugin());
1489
+ function createTelemetryProxyChain(plugins, config, core, startAt) {
1490
+ var firstProxy = null;
1491
+ var add = startAt ? false : true;
1492
+ if (isArray(plugins) && plugins.length > 0) {
1493
+ var lastProxy_1 = null;
1494
+ arrForEach(plugins, function (thePlugin) {
1495
+ if (!add && startAt === thePlugin) {
1496
+ add = true;
1202
1497
  }
1203
- else {
1204
- if (startAt) {
1205
- _nextProxy = _copyPluginChain(plugins, _self, startAt);
1498
+ if (add && thePlugin && isFunction(thePlugin.processTelemetry)) {
1499
+ var newProxy = createTelemetryPluginProxy(thePlugin, config, core);
1500
+ if (!firstProxy) {
1501
+ firstProxy = newProxy;
1206
1502
  }
1207
- else if (isUndefined(startAt)) {
1208
- _nextProxy = _createProxyChain(plugins, _self);
1503
+ if (lastProxy_1) {
1504
+ lastProxy_1._setNext(newProxy);
1209
1505
  }
1506
+ lastProxy_1 = newProxy;
1210
1507
  }
1508
+ });
1509
+ }
1510
+ if (startAt && !firstProxy) {
1511
+ return createTelemetryProxyChain([startAt], config, core);
1512
+ }
1513
+ return firstProxy;
1514
+ }
1515
+ function createTelemetryPluginProxy(plugin, config, core) {
1516
+ var nextProxy = null;
1517
+ var hasProcessTelemetry = isFunction(plugin.processTelemetry);
1518
+ var hasSetNext = isFunction(plugin.setNextPlugin);
1519
+ var chainId;
1520
+ if (plugin) {
1521
+ chainId = plugin.identifier + "-" + plugin.priority + "-" + _chainId++;
1522
+ }
1523
+ else {
1524
+ chainId = "Unknown-0-" + _chainId++;
1525
+ }
1526
+ var proxyChain = {
1527
+ getPlugin: function () {
1528
+ return plugin;
1529
+ },
1530
+ getNext: function () {
1531
+ return nextProxy;
1532
+ },
1533
+ processTelemetry: _processTelemetry,
1534
+ unload: _unloadPlugin,
1535
+ update: _updatePlugin,
1536
+ _id: chainId,
1537
+ _setNext: function (nextPlugin) {
1538
+ nextProxy = nextPlugin;
1211
1539
  }
1212
- _self.core = function () {
1213
- return core;
1214
- };
1215
- _self.diagLog = function () {
1216
- return safeGetLogger(core, config);
1217
- };
1218
- _self.getCfg = function () {
1219
- return config;
1220
- };
1221
- _self.getExtCfg = function (identifier, defaultValue) {
1222
- if (defaultValue === void 0) { defaultValue = {}; }
1223
- var theConfig;
1224
- if (config) {
1225
- var extConfig = config.extensionConfig;
1226
- if (extConfig && identifier) {
1227
- theConfig = extConfig[identifier];
1540
+ };
1541
+ function _getTelCtx() {
1542
+ var itemCtx;
1543
+ if (plugin && isFunction(plugin[strGetTelCtx])) {
1544
+ itemCtx = plugin[strGetTelCtx]();
1545
+ }
1546
+ if (!itemCtx) {
1547
+ itemCtx = createProcessTelemetryContext(proxyChain, config, core);
1548
+ }
1549
+ return itemCtx;
1550
+ }
1551
+ function _processChain(itemCtx, processPluginFn, name, details, isAsync) {
1552
+ var hasRun = false;
1553
+ var identifier = plugin ? plugin.identifier : strTelemetryPluginChain;
1554
+ var hasRunContext = itemCtx[strHasRunFlags];
1555
+ if (!hasRunContext) {
1556
+ hasRunContext = itemCtx[strHasRunFlags] = {};
1557
+ }
1558
+ itemCtx.setNext(nextProxy);
1559
+ if (plugin) {
1560
+ doPerf(itemCtx[strCore](), function () { return identifier + ":" + name; }, function () {
1561
+ hasRunContext[chainId] = true;
1562
+ try {
1563
+ var nextId = nextProxy ? nextProxy._id : strEmpty;
1564
+ if (nextId) {
1565
+ hasRunContext[nextId] = false;
1566
+ }
1567
+ hasRun = processPluginFn(itemCtx);
1228
1568
  }
1569
+ catch (error) {
1570
+ var hasNextRun = nextProxy ? hasRunContext[nextProxy._id] : true;
1571
+ if (hasNextRun) {
1572
+ hasRun = true;
1573
+ }
1574
+ if (!nextProxy || !hasNextRun) {
1575
+ _throwInternal(itemCtx.diagLog(), 1 , 73 , "Plugin [" + identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
1576
+ }
1577
+ }
1578
+ }, details, isAsync);
1579
+ }
1580
+ return hasRun;
1581
+ }
1582
+ function _processTelemetry(env, itemCtx) {
1583
+ itemCtx = itemCtx || _getTelCtx();
1584
+ function _callProcessTelemetry(itemCtx) {
1585
+ if (!plugin || !hasProcessTelemetry) {
1586
+ return false;
1229
1587
  }
1230
- return (theConfig ? theConfig : defaultValue);
1231
- };
1232
- _self.getConfig = function (identifier, field, defaultValue) {
1233
- if (defaultValue === void 0) { defaultValue = false; }
1234
- var theValue;
1235
- var extConfig = _self.getExtCfg(identifier, null);
1236
- if (extConfig && !isNullOrUndefined(extConfig[field])) {
1237
- theValue = extConfig[field];
1588
+ var pluginState = _getPluginState(plugin);
1589
+ if (pluginState.teardown || pluginState[strDisabled]) {
1590
+ return false;
1238
1591
  }
1239
- else if (config && !isNullOrUndefined(config[field])) {
1240
- theValue = config[field];
1592
+ if (hasSetNext) {
1593
+ plugin.setNextPlugin(nextProxy);
1241
1594
  }
1242
- return !isNullOrUndefined(theValue) ? theValue : defaultValue;
1243
- };
1244
- _self.hasNext = function () {
1245
- return _nextProxy != null;
1246
- };
1247
- _self.getNext = function () {
1248
- return _nextProxy;
1249
- };
1250
- _self.setNext = function (nextPlugin) {
1251
- _nextProxy = nextPlugin;
1252
- };
1253
- _self.processNext = function (env) {
1254
- var nextPlugin = _nextProxy;
1255
- if (nextPlugin) {
1256
- _nextProxy = nextPlugin.getNext();
1257
- nextPlugin.processTelemetry(env, _self);
1595
+ plugin.processTelemetry(env, itemCtx);
1596
+ return true;
1597
+ }
1598
+ if (!_processChain(itemCtx, _callProcessTelemetry, "processTelemetry", function () { return ({ item: env }); }, !(env.sync))) {
1599
+ itemCtx.processNext(env);
1600
+ }
1601
+ }
1602
+ function _unloadPlugin(unloadCtx, unloadState) {
1603
+ function _callTeardown() {
1604
+ var hasRun = false;
1605
+ if (plugin) {
1606
+ var pluginState = _getPluginState(plugin);
1607
+ var pluginCore = plugin[strCore] || pluginState.core;
1608
+ if (plugin && (!pluginCore || pluginCore === unloadCtx[strCore]()) && !pluginState[strTeardown]) {
1609
+ pluginState[strCore] = null;
1610
+ pluginState[strTeardown] = true;
1611
+ pluginState[strIsInitialized] = false;
1612
+ if (plugin[strTeardown] && plugin[strTeardown](unloadCtx, unloadState) === true) {
1613
+ hasRun = true;
1614
+ }
1615
+ }
1258
1616
  }
1259
- };
1260
- _self.createNew = function (plugins, startAt) {
1261
- if (plugins === void 0) { plugins = null; }
1262
- return new ProcessTelemetryContext(plugins || _nextProxy, config, core, startAt);
1263
- };
1617
+ return hasRun;
1618
+ }
1619
+ if (!_processChain(unloadCtx, _callTeardown, "unload", function () { }, unloadState.isAsync)) {
1620
+ unloadCtx.processNext(unloadState);
1621
+ }
1264
1622
  }
1265
- return ProcessTelemetryContext;
1266
- }());
1623
+ function _updatePlugin(updateCtx, updateState) {
1624
+ function _callUpdate() {
1625
+ var hasRun = false;
1626
+ if (plugin) {
1627
+ var pluginState = _getPluginState(plugin);
1628
+ var pluginCore = plugin[strCore] || pluginState.core;
1629
+ if (plugin && (!pluginCore || pluginCore === updateCtx[strCore]()) && !pluginState[strTeardown]) {
1630
+ if (plugin[strUpdate] && plugin[strUpdate](updateCtx, updateState) === true) {
1631
+ hasRun = true;
1632
+ }
1633
+ }
1634
+ }
1635
+ return hasRun;
1636
+ }
1637
+ if (!_processChain(updateCtx, _callUpdate, "update", function () { }, false)) {
1638
+ updateCtx.processNext(updateState);
1639
+ }
1640
+ }
1641
+ return objFreeze(proxyChain);
1642
+ }
1267
1643
 
1268
1644
  var strExtensionConfig = "extensionConfig";
1269
1645
 
1646
+ function createUnloadHandlerContainer() {
1647
+ var handlers = [];
1648
+ function _addHandler(handler) {
1649
+ if (handler) {
1650
+ handlers.push(handler);
1651
+ }
1652
+ }
1653
+ function _runHandlers(unloadCtx, unloadState) {
1654
+ arrForEach(handlers, function (handler) {
1655
+ try {
1656
+ handler(unloadCtx, unloadState);
1657
+ }
1658
+ catch (e) {
1659
+ _throwInternal(unloadCtx.diagLog(), 2 , 73 , "Unexpected error calling unload handler - " + dumpObj(e));
1660
+ }
1661
+ });
1662
+ handlers = [];
1663
+ }
1664
+ return {
1665
+ add: _addHandler,
1666
+ run: _runHandlers
1667
+ };
1668
+ }
1669
+
1270
1670
  var strGetPlugin = "getPlugin";
1271
1671
  var BaseTelemetryPlugin = /** @class */ (function () {
1272
1672
  function BaseTelemetryPlugin() {
1273
1673
  var _self = this;
1274
- var _isinitialized = false;
1275
- var _rootCtx = null;
1276
- var _nextPlugin = null;
1277
- _self.core = null;
1674
+ var _isinitialized;
1675
+ var _rootCtx;
1676
+ var _nextPlugin;
1677
+ var _unloadHandlerContainer;
1678
+ var _hooks;
1679
+ _initDefaults();
1680
+ dynamicProto(BaseTelemetryPlugin, _self, function (_self) {
1681
+ _self.initialize = function (config, core, extensions, pluginChain) {
1682
+ _setDefaults(config, core, pluginChain);
1683
+ _isinitialized = true;
1684
+ };
1685
+ _self.teardown = function (unloadCtx, unloadState) {
1686
+ var core = _self.core;
1687
+ if (!core || (unloadCtx && core !== unloadCtx.core())) {
1688
+ return;
1689
+ }
1690
+ var result;
1691
+ var unloadDone = false;
1692
+ var theUnloadCtx = unloadCtx || createProcessTelemetryUnloadContext(null, core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
1693
+ var theUnloadState = unloadState || {
1694
+ reason: 0 ,
1695
+ isAsync: false
1696
+ };
1697
+ function _unloadCallback() {
1698
+ if (!unloadDone) {
1699
+ unloadDone = true;
1700
+ _unloadHandlerContainer.run(theUnloadCtx, unloadState);
1701
+ arrForEach(_hooks, function (fn) {
1702
+ fn.rm();
1703
+ });
1704
+ _hooks = [];
1705
+ if (result === true) {
1706
+ theUnloadCtx.processNext(theUnloadState);
1707
+ }
1708
+ _initDefaults();
1709
+ }
1710
+ }
1711
+ if (!_self[strDoTeardown] || _self[strDoTeardown](theUnloadCtx, theUnloadState, _unloadCallback) !== true) {
1712
+ _unloadCallback();
1713
+ }
1714
+ else {
1715
+ result = true;
1716
+ }
1717
+ return result;
1718
+ };
1719
+ _self.update = function (updateCtx, updateState) {
1720
+ var core = _self.core;
1721
+ if (!core || (updateCtx && core !== updateCtx.core())) {
1722
+ return;
1723
+ }
1724
+ var result;
1725
+ var updateDone = false;
1726
+ var theUpdateCtx = updateCtx || createProcessTelemetryUpdateContext(null, core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
1727
+ var theUpdateState = updateState || {
1728
+ reason: 0
1729
+ };
1730
+ function _updateCallback() {
1731
+ if (!updateDone) {
1732
+ updateDone = true;
1733
+ _setDefaults(theUpdateCtx.getCfg(), theUpdateCtx.core(), theUpdateCtx.getNext());
1734
+ }
1735
+ }
1736
+ if (!_self._doUpdate || _self._doUpdate(theUpdateCtx, theUpdateState, _updateCallback) !== true) {
1737
+ _updateCallback();
1738
+ }
1739
+ else {
1740
+ result = true;
1741
+ }
1742
+ return result;
1743
+ };
1744
+ _self._addHook = function (hooks) {
1745
+ if (hooks) {
1746
+ if (isArray(hooks)) {
1747
+ _hooks = _hooks.concat(hooks);
1748
+ }
1749
+ else {
1750
+ _hooks.push(hooks);
1751
+ }
1752
+ }
1753
+ };
1754
+ proxyFunctionAs(_self, "_addUnloadCb", function () { return _unloadHandlerContainer; }, "add");
1755
+ });
1278
1756
  _self.diagLog = function (itemCtx) {
1279
- return _self._getTelCtx(itemCtx).diagLog();
1757
+ return _getTelCtx(itemCtx).diagLog();
1280
1758
  };
1281
- _self.isInitialized = function () {
1759
+ _self[strIsInitialized] = function () {
1282
1760
  return _isinitialized;
1283
1761
  };
1284
1762
  _self.setInitialized = function (isInitialized) {
1285
1763
  _isinitialized = isInitialized;
1286
1764
  };
1287
- _self.setNextPlugin = function (next) {
1765
+ _self[strSetNextPlugin] = function (next) {
1288
1766
  _nextPlugin = next;
1289
1767
  };
1290
1768
  _self.processNext = function (env, itemCtx) {
@@ -1295,11 +1773,12 @@
1295
1773
  _nextPlugin.processTelemetry(env, null);
1296
1774
  }
1297
1775
  };
1298
- _self._getTelCtx = function (currentCtx) {
1776
+ _self._getTelCtx = _getTelCtx;
1777
+ function _getTelCtx(currentCtx) {
1299
1778
  if (currentCtx === void 0) { currentCtx = null; }
1300
1779
  var itemCtx = currentCtx;
1301
1780
  if (!itemCtx) {
1302
- var rootCtx = _rootCtx || new ProcessTelemetryContext(null, {}, _self.core);
1781
+ var rootCtx = _rootCtx || createProcessTelemetryContext(null, {}, _self.core);
1303
1782
  if (_nextPlugin && _nextPlugin[strGetPlugin]) {
1304
1783
  itemCtx = rootCtx.createNew(null, _nextPlugin[strGetPlugin]);
1305
1784
  }
@@ -1308,8 +1787,8 @@
1308
1787
  }
1309
1788
  }
1310
1789
  return itemCtx;
1311
- };
1312
- _self._baseTelInit = function (config, core, extensions, pluginChain) {
1790
+ }
1791
+ function _setDefaults(config, core, pluginChain) {
1313
1792
  if (config) {
1314
1793
  setValue(config, strExtensionConfig, [], null, isNullOrUndefined);
1315
1794
  }
@@ -1321,93 +1800,300 @@
1321
1800
  nextPlugin = _nextPlugin[strGetPlugin]();
1322
1801
  }
1323
1802
  _self.core = core;
1324
- _rootCtx = new ProcessTelemetryContext(pluginChain, config, core, nextPlugin);
1325
- _isinitialized = true;
1326
- };
1803
+ _rootCtx = createProcessTelemetryContext(pluginChain, config, core, nextPlugin);
1804
+ }
1805
+ function _initDefaults() {
1806
+ _isinitialized = false;
1807
+ _self.core = null;
1808
+ _rootCtx = null;
1809
+ _nextPlugin = null;
1810
+ _hooks = [];
1811
+ _unloadHandlerContainer = createUnloadHandlerContainer();
1812
+ }
1327
1813
  }
1328
- BaseTelemetryPlugin.prototype.initialize = function (config, core, extensions, pluginChain) {
1329
- this._baseTelInit(config, core, extensions, pluginChain);
1330
- };
1331
1814
  return BaseTelemetryPlugin;
1332
1815
  }());
1333
1816
 
1817
+ var strOnPrefix = "on";
1818
+ var strAttachEvent = "attachEvent";
1819
+ var strAddEventHelper = "addEventListener";
1820
+ var strDetachEvent = "detachEvent";
1821
+ var strRemoveEventListener = "removeEventListener";
1822
+ var strEvents = "events";
1334
1823
  var strVisibilityChangeEvt = "visibilitychange";
1335
1824
  var strPageHide = "pagehide";
1336
1825
  var strPageShow = "pageshow";
1337
- function addEventHandler(eventName, callback) {
1826
+ var strUnload = "unload";
1827
+ var strBeforeUnload = "beforeunload";
1828
+ var strPageHideNamespace = createUniqueNamespace("aiEvtPageHide");
1829
+ var strPageShowNamespace = createUniqueNamespace("aiEvtPageShow");
1830
+ var rRemoveEmptyNs = /\.[\.]+/g;
1831
+ var rRemoveTrailingEmptyNs = /[\.]+$/;
1832
+ var _guid = 1;
1833
+ var elmNodeData = createElmNodeData("events");
1834
+ var eventNamespace = /^([^.]*)(?:\.(.+)|)/;
1835
+ function _normalizeNamespace(name) {
1836
+ if (name && name.replace) {
1837
+ return name.replace(/^\s*\.*|\.*\s*$/g, "");
1838
+ }
1839
+ return name;
1840
+ }
1841
+ function _getEvtNamespace(eventName, evtNamespace) {
1842
+ if (evtNamespace) {
1843
+ var theNamespace_1 = "";
1844
+ if (isArray(evtNamespace)) {
1845
+ theNamespace_1 = "";
1846
+ arrForEach(evtNamespace, function (name) {
1847
+ name = _normalizeNamespace(name);
1848
+ if (name) {
1849
+ if (name[0] !== ".") {
1850
+ name = "." + name;
1851
+ }
1852
+ theNamespace_1 += name;
1853
+ }
1854
+ });
1855
+ }
1856
+ else {
1857
+ theNamespace_1 = _normalizeNamespace(evtNamespace);
1858
+ }
1859
+ if (theNamespace_1) {
1860
+ if (theNamespace_1[0] !== ".") {
1861
+ theNamespace_1 = "." + theNamespace_1;
1862
+ }
1863
+ eventName = (eventName || "") + theNamespace_1;
1864
+ }
1865
+ }
1866
+ var parsedEvent = (eventNamespace.exec(eventName || "") || []);
1867
+ return {
1868
+ type: parsedEvent[1],
1869
+ ns: ((parsedEvent[2] || "").replace(rRemoveEmptyNs, ".").replace(rRemoveTrailingEmptyNs, "").split(".").sort()).join(".")
1870
+ };
1871
+ }
1872
+ function _getRegisteredEvents(target, evtName, addDefault) {
1873
+ if (addDefault === void 0) { addDefault = true; }
1874
+ var aiEvts = elmNodeData.get(target, strEvents, {}, addDefault);
1875
+ var registeredEvents = aiEvts[evtName];
1876
+ if (!registeredEvents) {
1877
+ registeredEvents = aiEvts[evtName] = [];
1878
+ }
1879
+ return registeredEvents;
1880
+ }
1881
+ function _doDetach(obj, evtName, handlerRef, useCapture) {
1882
+ if (obj && evtName && evtName.type) {
1883
+ if (obj[strRemoveEventListener]) {
1884
+ obj[strRemoveEventListener](evtName.type, handlerRef, useCapture);
1885
+ }
1886
+ else if (obj[strDetachEvent]) {
1887
+ obj[strDetachEvent](strOnPrefix + evtName.type, handlerRef);
1888
+ }
1889
+ }
1890
+ }
1891
+ function _doAttach(obj, evtName, handlerRef, useCapture) {
1892
+ var result = false;
1893
+ if (obj && evtName && evtName.type && handlerRef) {
1894
+ if (obj[strAddEventHelper]) {
1895
+ obj[strAddEventHelper](evtName.type, handlerRef, useCapture);
1896
+ result = true;
1897
+ }
1898
+ else if (obj[strAttachEvent]) {
1899
+ obj[strAttachEvent](strOnPrefix + evtName.type, handlerRef);
1900
+ result = true;
1901
+ }
1902
+ }
1903
+ return result;
1904
+ }
1905
+ function _doUnregister(target, events, evtName, unRegFn) {
1906
+ var idx = events.length;
1907
+ while (idx--) {
1908
+ var theEvent = events[idx];
1909
+ if (theEvent) {
1910
+ if (!evtName.ns || evtName.ns === theEvent.evtName.ns) {
1911
+ if (!unRegFn || unRegFn(theEvent)) {
1912
+ _doDetach(target, theEvent.evtName, theEvent.handler, theEvent.capture);
1913
+ events.splice(idx, 1);
1914
+ }
1915
+ }
1916
+ }
1917
+ }
1918
+ }
1919
+ function _unregisterEvents(target, evtName, unRegFn) {
1920
+ if (evtName.type) {
1921
+ _doUnregister(target, _getRegisteredEvents(target, evtName.type), evtName, unRegFn);
1922
+ }
1923
+ else {
1924
+ var eventCache = elmNodeData.get(target, strEvents, {});
1925
+ objForEachKey(eventCache, function (evtType, events) {
1926
+ _doUnregister(target, events, evtName, unRegFn);
1927
+ });
1928
+ if (objKeys(eventCache).length === 0) {
1929
+ elmNodeData.kill(target, strEvents);
1930
+ }
1931
+ }
1932
+ }
1933
+ function mergeEvtNamespace(theNamespace, namespaces) {
1934
+ var newNamespaces;
1935
+ if (namespaces) {
1936
+ if (isArray(namespaces)) {
1937
+ newNamespaces = [theNamespace].concat(namespaces);
1938
+ }
1939
+ else {
1940
+ newNamespaces = [theNamespace, namespaces];
1941
+ }
1942
+ newNamespaces = (_getEvtNamespace("xx", newNamespaces).ns).split(".");
1943
+ }
1944
+ else {
1945
+ newNamespaces = theNamespace;
1946
+ }
1947
+ return newNamespaces;
1948
+ }
1949
+ function eventOn(target, eventName, handlerRef, evtNamespace, useCapture) {
1950
+ if (useCapture === void 0) { useCapture = false; }
1951
+ var result = false;
1952
+ if (target) {
1953
+ try {
1954
+ var evtName = _getEvtNamespace(eventName, evtNamespace);
1955
+ result = _doAttach(target, evtName, handlerRef, useCapture);
1956
+ if (result && elmNodeData.accept(target)) {
1957
+ var registeredEvent = {
1958
+ guid: _guid++,
1959
+ evtName: evtName,
1960
+ handler: handlerRef,
1961
+ capture: useCapture
1962
+ };
1963
+ _getRegisteredEvents(target, evtName.type).push(registeredEvent);
1964
+ }
1965
+ }
1966
+ catch (e) {
1967
+ }
1968
+ }
1969
+ return result;
1970
+ }
1971
+ function eventOff(target, eventName, handlerRef, evtNamespace, useCapture) {
1972
+ if (useCapture === void 0) { useCapture = false; }
1973
+ if (target) {
1974
+ try {
1975
+ var evtName_1 = _getEvtNamespace(eventName, evtNamespace);
1976
+ var found_1 = false;
1977
+ _unregisterEvents(target, evtName_1, function (regEvent) {
1978
+ if ((evtName_1.ns && !handlerRef) || regEvent.handler === handlerRef) {
1979
+ found_1 = true;
1980
+ return true;
1981
+ }
1982
+ return false;
1983
+ });
1984
+ if (!found_1) {
1985
+ _doDetach(target, evtName_1, handlerRef, useCapture);
1986
+ }
1987
+ }
1988
+ catch (e) {
1989
+ }
1990
+ }
1991
+ }
1992
+ function addEventHandler(eventName, callback, evtNamespace) {
1338
1993
  var result = false;
1339
1994
  var w = getWindow();
1340
1995
  if (w) {
1341
- result = attachEvent(w, eventName, callback);
1342
- result = attachEvent(w["body"], eventName, callback) || result;
1996
+ result = eventOn(w, eventName, callback, evtNamespace);
1997
+ result = eventOn(w["body"], eventName, callback, evtNamespace) || result;
1343
1998
  }
1344
1999
  var doc = getDocument();
1345
2000
  if (doc) {
1346
- result = attachEvent(doc, eventName, callback) || result;
2001
+ result = eventOn(doc, eventName, callback, evtNamespace) || result;
1347
2002
  }
1348
2003
  return result;
1349
2004
  }
1350
- function addEventListeners(events, listener, excludeEvents) {
2005
+ function removeEventHandler(eventName, callback, evtNamespace) {
2006
+ var w = getWindow();
2007
+ if (w) {
2008
+ eventOff(w, eventName, callback, evtNamespace);
2009
+ eventOff(w["body"], eventName, callback, evtNamespace);
2010
+ }
2011
+ var doc = getDocument();
2012
+ if (doc) {
2013
+ eventOff(doc, eventName, callback, evtNamespace);
2014
+ }
2015
+ }
2016
+ function _addEventListeners(events, listener, excludeEvents, evtNamespace) {
1351
2017
  var added = false;
1352
- if (listener && events && isArray(events)) {
1353
- var excluded_1 = [];
2018
+ if (listener && events && events.length > 0) {
1354
2019
  arrForEach(events, function (name) {
1355
- if (isString(name)) {
2020
+ if (name) {
1356
2021
  if (!excludeEvents || arrIndexOf(excludeEvents, name) === -1) {
1357
- added = addEventHandler(name, listener) || added;
1358
- }
1359
- else {
1360
- excluded_1.push(name);
2022
+ added = addEventHandler(name, listener, evtNamespace) || added;
1361
2023
  }
1362
2024
  }
1363
2025
  });
1364
- if (!added && excluded_1.length > 0) {
1365
- added = addEventListeners(excluded_1, listener);
2026
+ }
2027
+ return added;
2028
+ }
2029
+ function addEventListeners(events, listener, excludeEvents, evtNamespace) {
2030
+ var added = false;
2031
+ if (listener && events && isArray(events)) {
2032
+ added = _addEventListeners(events, listener, excludeEvents, evtNamespace);
2033
+ if (!added && excludeEvents && excludeEvents.length > 0) {
2034
+ added = _addEventListeners(events, listener, null, evtNamespace);
1366
2035
  }
1367
2036
  }
1368
2037
  return added;
1369
2038
  }
1370
- function addPageUnloadEventListener(listener, excludeEvents) {
1371
- return addEventListeners(["beforeunload", "unload", "pagehide"], listener, excludeEvents);
2039
+ function removeEventListeners(events, listener, evtNamespace) {
2040
+ if (events && isArray(events)) {
2041
+ arrForEach(events, function (name) {
2042
+ if (name) {
2043
+ removeEventHandler(name, listener, evtNamespace);
2044
+ }
2045
+ });
2046
+ }
2047
+ }
2048
+ function addPageUnloadEventListener(listener, excludeEvents, evtNamespace) {
2049
+ return addEventListeners([strBeforeUnload, strUnload, strPageHide], listener, excludeEvents, evtNamespace);
2050
+ }
2051
+ function removePageUnloadEventListener(listener, evtNamespace) {
2052
+ removeEventListeners([strBeforeUnload, strUnload, strPageHide], listener, evtNamespace);
1372
2053
  }
1373
- function addPageHideEventListener(listener, excludeEvents) {
2054
+ function addPageHideEventListener(listener, excludeEvents, evtNamespace) {
1374
2055
  function _handlePageVisibility(evt) {
1375
2056
  var doc = getDocument();
1376
2057
  if (listener && doc && doc.visibilityState === "hidden") {
1377
2058
  listener(evt);
1378
2059
  }
1379
2060
  }
1380
- var pageUnloadAdded = false;
1381
- if (!excludeEvents || arrIndexOf(excludeEvents, strPageHide) === -1) {
1382
- pageUnloadAdded = addEventHandler(strPageHide, listener);
1383
- }
2061
+ var newNamespaces = mergeEvtNamespace(strPageHideNamespace, evtNamespace);
2062
+ var pageUnloadAdded = _addEventListeners([strPageHide], listener, excludeEvents, newNamespaces);
1384
2063
  if (!excludeEvents || arrIndexOf(excludeEvents, strVisibilityChangeEvt) === -1) {
1385
- pageUnloadAdded = addEventHandler(strVisibilityChangeEvt, _handlePageVisibility) || pageUnloadAdded;
2064
+ pageUnloadAdded = _addEventListeners([strVisibilityChangeEvt], _handlePageVisibility, excludeEvents, newNamespaces) || pageUnloadAdded;
1386
2065
  }
1387
2066
  if (!pageUnloadAdded && excludeEvents) {
1388
- pageUnloadAdded = addPageHideEventListener(listener);
2067
+ pageUnloadAdded = addPageHideEventListener(listener, null, evtNamespace);
1389
2068
  }
1390
2069
  return pageUnloadAdded;
1391
2070
  }
1392
- function addPageShowEventListener(listener, excludeEvents) {
2071
+ function removePageHideEventListener(listener, evtNamespace) {
2072
+ var newNamespaces = mergeEvtNamespace(strPageHideNamespace, evtNamespace);
2073
+ removeEventListeners([strPageHide], listener, newNamespaces);
2074
+ removeEventListeners([strVisibilityChangeEvt], null, newNamespaces);
2075
+ }
2076
+ function addPageShowEventListener(listener, excludeEvents, evtNamespace) {
1393
2077
  function _handlePageVisibility(evt) {
1394
2078
  var doc = getDocument();
1395
2079
  if (listener && doc && doc.visibilityState === "visible") {
1396
2080
  listener(evt);
1397
2081
  }
1398
2082
  }
1399
- var pageShowAdded = false;
1400
- if (!excludeEvents || arrIndexOf(excludeEvents, strPageShow) === -1) {
1401
- pageShowAdded = addEventHandler(strPageShow, listener);
1402
- }
1403
- if (!excludeEvents || arrIndexOf(excludeEvents, strVisibilityChangeEvt) === -1) {
1404
- pageShowAdded = addEventHandler(strVisibilityChangeEvt, _handlePageVisibility) || pageShowAdded;
1405
- }
2083
+ var newNamespaces = mergeEvtNamespace(strPageShowNamespace, evtNamespace);
2084
+ var pageShowAdded = _addEventListeners([strPageShow], listener, excludeEvents, newNamespaces);
2085
+ pageShowAdded = _addEventListeners([strVisibilityChangeEvt], _handlePageVisibility, excludeEvents, newNamespaces) || pageShowAdded;
1406
2086
  if (!pageShowAdded && excludeEvents) {
1407
- pageShowAdded = addPageShowEventListener(listener);
2087
+ pageShowAdded = addPageShowEventListener(listener, null, evtNamespace);
1408
2088
  }
1409
2089
  return pageShowAdded;
1410
2090
  }
2091
+ function removePageShowEventListener(listener, evtNamespace) {
2092
+ var newNamespaces = mergeEvtNamespace(strPageShowNamespace, evtNamespace);
2093
+ removeEventListeners([strPageShow], listener, newNamespaces);
2094
+ removeEventListeners([strVisibilityChangeEvt], null, newNamespaces);
2095
+ }
2096
+
1411
2097
  function perfNow() {
1412
2098
  var perf = getPerformance();
1413
2099
  if (perf && perf.now) {
@@ -1416,60 +2102,23 @@
1416
2102
  return dateNow();
1417
2103
  }
1418
2104
 
1419
- var ValueKind = {
1420
- NotSet: 0,
1421
- Pii_DistinguishedName: 1,
1422
- Pii_GenericData: 2,
1423
- Pii_IPV4Address: 3,
1424
- Pii_IPv6Address: 4,
1425
- Pii_MailSubject: 5,
1426
- Pii_PhoneNumber: 6,
1427
- Pii_QueryString: 7,
1428
- Pii_SipAddress: 8,
1429
- Pii_SmtpAddress: 9,
1430
- Pii_Identity: 10,
1431
- Pii_Uri: 11,
1432
- Pii_Fqdn: 12,
1433
- Pii_IPV4AddressLegacy: 13,
1434
- CustomerContent_GenericContent: 32
1435
- };
1436
- var EventLatency = {
1437
- Normal: 1 ,
1438
- CostDeferred: 2 ,
1439
- RealTime: 3 ,
1440
- Immediate: 4
1441
- };
1442
- var EventPropertyType = {
1443
- Unspecified: 0,
1444
- String: 1,
1445
- Int32: 2,
1446
- UInt32: 3,
1447
- Int64: 4,
1448
- UInt64: 5,
1449
- Double: 6,
1450
- Bool: 7,
1451
- Guid: 8,
1452
- DateTime: 9
1453
- };
1454
- var _ExtendedInternalMessageId = __assignFn(__assignFn({}, _InternalMessageId), { AuthHandShakeError: 501, AuthRedirectFail: 502, BrowserCannotReadLocalStorage: 503, BrowserCannotWriteLocalStorage: 504, BrowserDoesNotSupportLocalStorage: 505, CannotParseBiBlobValue: 506, CannotParseDataAttribute: 507, CVPluginNotAvailable: 508, DroppedEvent: 509, ErrorParsingAISessionCookie: 510, ErrorProvidedChannels: 511, FailedToGetCookies: 512, FailedToInitializeCorrelationVector: 513, FailedToInitializeSDK: 514, InvalidContentBlob: 515, InvalidCorrelationValue: 516, SessionRenewalDateIsZero: 517, SendPostOnCompleteFailure: 518, PostResponseHandler: 519, SDKNotInitialized: 520 });
1455
-
1456
2105
  var _a$1;
1457
- var Version = '3.1.11';
2106
+ var Version = '3.2.2';
1458
2107
  var FullVersionString = "1DS-Web-JS-" + Version;
1459
2108
  var strDisabledPropertyName = "Microsoft_ApplicationInsights_BypassAjaxInstrumentation";
1460
2109
  var strWithCredentials = "withCredentials";
1461
2110
  var strTimeout = "timeout";
1462
2111
  var _fieldTypeEventPropMap = (_a$1 = {},
1463
- _a$1[0 ] = EventPropertyType.Unspecified,
1464
- _a$1[2 ] = EventPropertyType.Double,
1465
- _a$1[1 ] = EventPropertyType.String,
1466
- _a$1[3 ] = EventPropertyType.Bool,
1467
- _a$1[4096 | 2 ] = EventPropertyType.Double,
1468
- _a$1[4096 | 1 ] = EventPropertyType.String,
1469
- _a$1[4096 | 3 ] = EventPropertyType.Bool,
2112
+ _a$1[0 ] = 0 ,
2113
+ _a$1[2 ] = 6 ,
2114
+ _a$1[1 ] = 1 ,
2115
+ _a$1[3 ] = 7 ,
2116
+ _a$1[4096 | 2 ] = 6 ,
2117
+ _a$1[4096 | 1 ] = 1 ,
2118
+ _a$1[4096 | 3 ] = 7 ,
1470
2119
  _a$1);
1471
2120
  Boolean(getDocument());
1472
- var isWindowObjectAvailable = Boolean(getWindow());
2121
+ Boolean(getWindow());
1473
2122
  function isValueAssigned(value) {
1474
2123
  return !(value === "" || isNullOrUndefined(value));
1475
2124
  }
@@ -1533,7 +2182,7 @@
1533
2182
  if (encodedTypeValue !== -1 && propType !== -1) {
1534
2183
  encodedTypeValue |= propType;
1535
2184
  }
1536
- else if (propType === EventPropertyType.Double) {
2185
+ else if (propType === 6 ) {
1537
2186
  encodedTypeValue = propType;
1538
2187
  }
1539
2188
  }
@@ -1579,7 +2228,7 @@
1579
2228
  }
1580
2229
  var getTime = perfNow;
1581
2230
  function isValueKind(value) {
1582
- if (value === ValueKind.NotSet || ((value > ValueKind.NotSet && value <= ValueKind.Pii_IPV4AddressLegacy) || value === ValueKind.CustomerContent_GenericContent)) {
2231
+ if (value === 0 || ((value > 0 && value <= 13 ) || value === 32 )) {
1583
2232
  return true;
1584
2233
  }
1585
2234
  return false;
@@ -1682,6 +2331,7 @@
1682
2331
  var strUploadTime = "upload-time";
1683
2332
  var strApiKey = "apikey";
1684
2333
  var strMsaDeviceTicket = "AuthMsaDeviceTicket";
2334
+ var strAuthXToken = "AuthXToken";
1685
2335
  var strNoResponseBody = "NoResponseBody";
1686
2336
  var strMsfpc = "msfpc";
1687
2337
 
@@ -1994,25 +2644,19 @@
1994
2644
  var RandomizationUpperThreshold = 1.2;
1995
2645
  var BaseBackoff = 3000;
1996
2646
  var MaxBackoff = 600000;
1997
- var RetryPolicy = /** @class */ (function () {
1998
- function RetryPolicy() {
1999
- }
2000
- RetryPolicy.shouldRetryForStatus = function (httpStatusCode) {
2001
- return !((httpStatusCode >= 300 && httpStatusCode < 500 && httpStatusCode != 408 && httpStatusCode != 429)
2002
- || (httpStatusCode == 501)
2003
- || (httpStatusCode == 505));
2004
- };
2005
- RetryPolicy.getMillisToBackoffForRetry = function (retriesSoFar) {
2006
- var waitDuration = 0;
2007
- var minBackoff = BaseBackoff * RandomizationLowerThreshold;
2008
- var maxBackoff = BaseBackoff * RandomizationUpperThreshold;
2009
- var randomBackoff = Math.floor(Math.random() * (maxBackoff - minBackoff)) + minBackoff;
2010
- waitDuration = Math.pow(2, retriesSoFar) * randomBackoff;
2011
- return Math.min(waitDuration, MaxBackoff);
2012
- };
2013
- return RetryPolicy;
2014
- }());
2015
- var RetryPolicy$1 = RetryPolicy;
2647
+ function retryPolicyShouldRetryForStatus(httpStatusCode) {
2648
+ return !((httpStatusCode >= 300 && httpStatusCode < 500 && httpStatusCode != 408 && httpStatusCode != 429)
2649
+ || (httpStatusCode == 501)
2650
+ || (httpStatusCode == 505));
2651
+ }
2652
+ function retryPolicyGetMillisToBackoffForRetry(retriesSoFar) {
2653
+ var waitDuration = 0;
2654
+ var minBackoff = BaseBackoff * RandomizationLowerThreshold;
2655
+ var maxBackoff = BaseBackoff * RandomizationUpperThreshold;
2656
+ var randomBackoff = Math.floor(Math.random() * (maxBackoff - minBackoff)) + minBackoff;
2657
+ waitDuration = Math.pow(2, retriesSoFar) * randomBackoff;
2658
+ return Math.min(waitDuration, MaxBackoff);
2659
+ }
2016
2660
 
2017
2661
  var SecToMsMultiplier = 1000;
2018
2662
  var KillSwitch = /** @class */ (function () {
@@ -2117,11 +2761,19 @@
2117
2761
  _a);
2118
2762
  var _collectorQsHeaders = {};
2119
2763
  var _collectorHeaderToQs = {};
2120
- function _addCollectorHeaderQsMapping(qsName, headerName) {
2764
+ function _addCollectorHeaderQsMapping(qsName, headerName, allowQs) {
2121
2765
  _collectorQsHeaders[qsName] = headerName;
2122
- _collectorHeaderToQs[headerName] = qsName;
2766
+ if (allowQs !== false) {
2767
+ _collectorHeaderToQs[headerName] = qsName;
2768
+ }
2123
2769
  }
2124
- _addCollectorHeaderQsMapping(strMsaDeviceTicket, strMsaDeviceTicket);
2770
+ _addCollectorHeaderQsMapping(strMsaDeviceTicket, strMsaDeviceTicket, false);
2771
+ _addCollectorHeaderQsMapping(strClientVersion, strClientVersion);
2772
+ _addCollectorHeaderQsMapping(strClientId, "Client-Id");
2773
+ _addCollectorHeaderQsMapping(strApiKey, strApiKey);
2774
+ _addCollectorHeaderQsMapping(strTimeDeltaToApply, strTimeDeltaToApply);
2775
+ _addCollectorHeaderQsMapping(strUploadTime, strUploadTime);
2776
+ _addCollectorHeaderQsMapping(strAuthXToken, strAuthXToken);
2125
2777
  function _getResponseText(xhr) {
2126
2778
  try {
2127
2779
  return xhr.responseText;
@@ -2160,7 +2812,7 @@
2160
2812
  }
2161
2813
  }
2162
2814
  var HttpManager = /** @class */ (function () {
2163
- function HttpManager(maxEventsPerBatch, maxConnections, maxRequestRetriesBeforeBackoff, actions) {
2815
+ function HttpManager(maxEventsPerBatch, maxConnections, maxRequestRetriesBeforeBackoff, actions, timeoutOverride) {
2164
2816
  this._responseHandlers = [];
2165
2817
  var _urlString = "?cors=true&" + strContentTypeHeader.toLowerCase() + "=" + defaultContentType;
2166
2818
  var _killSwitch = new EVTKillSwitch();
@@ -2190,7 +2842,7 @@
2190
2842
  channelConfig = {};
2191
2843
  }
2192
2844
  _urlString = endpointUrl + _urlString;
2193
- _useHeaders = !isUndefined(channelConfig.avoidOptions) ? !channelConfig.avoidOptions : false;
2845
+ _useHeaders = !isUndefined(channelConfig.avoidOptions) ? !channelConfig.avoidOptions : true;
2194
2846
  _core = core;
2195
2847
  _cookieMgr = core.getCookieMgr();
2196
2848
  _enableEventTimings = !_core.config.disableEventTimings;
@@ -2299,7 +2951,7 @@
2299
2951
  xdr.send(payload.data);
2300
2952
  }
2301
2953
  else {
2302
- _postManager._setTimeoutOverride(function () {
2954
+ timeoutOverride.set(function () {
2303
2955
  xdr.send(payload.data);
2304
2956
  }, 0);
2305
2957
  }
@@ -2357,7 +3009,7 @@
2357
3009
  _doOnComplete(oncomplete, 200, {});
2358
3010
  }
2359
3011
  if (!responseHandled && payload.timeout > 0) {
2360
- _postManager._setTimeoutOverride(function () {
3012
+ timeoutOverride.set(function () {
2361
3013
  if (!responseHandled) {
2362
3014
  responseHandled = true;
2363
3015
  _doOnComplete(oncomplete, 500, {});
@@ -2416,7 +3068,7 @@
2416
3068
  oncomplete(status, headers, response);
2417
3069
  }
2418
3070
  catch (e) {
2419
- _postManager.diagLog().throwInternal(LoggingSeverity.WARNING, _ExtendedInternalMessageId.SendPostOnCompleteFailure, dumpObj(e));
3071
+ _throwInternal(_postManager.diagLog(), 2 , 518 , dumpObj(e));
2420
3072
  }
2421
3073
  }
2422
3074
  function _beaconSendPost(payload, oncomplete, sync) {
@@ -2451,7 +3103,7 @@
2451
3103
  }
2452
3104
  }
2453
3105
  catch (ex) {
2454
- _postManager.diagLog().warnToConsole("Failed to send telemetry using sendBeacon API. Ex:" + ex);
3106
+ _postManager.diagLog().warnToConsole("Failed to send telemetry using sendBeacon API. Ex:" + dumpObj(ex));
2455
3107
  status = 0;
2456
3108
  }
2457
3109
  finally {
@@ -2615,7 +3267,7 @@
2615
3267
  }, function () { return ({ batches: _createDebugBatches(orgBatches_1), retryCount: retryCount, isTeardown: isTeardown, isSynchronous: isSynchronous_1, sendReason: sendReason, useSendBeacon: _isBeaconPayload(sendType), sendType: sendType }); }, !isSynchronous_1);
2616
3268
  }
2617
3269
  catch (ex) {
2618
- _postManager.diagLog().throwInternal(LoggingSeverity.WARNING, _ExtendedInternalMessageId.CannotSerializeObject, "Unexpected Exception sending batch: " + dumpObj(ex));
3270
+ _throwInternal(_postManager.diagLog(), 2 , 48 , "Unexpected Exception sending batch: " + dumpObj(ex));
2619
3271
  }
2620
3272
  }
2621
3273
  function _buildRequestDetails(thePayload, useHeaders) {
@@ -2624,8 +3276,21 @@
2624
3276
  hdrs: {},
2625
3277
  useHdrs: false
2626
3278
  };
2627
- requestDetails.hdrs = extend(requestDetails.hdrs, _headers);
2628
- requestDetails.useHdrs = (objKeys(requestDetails.hdrs).length > 0);
3279
+ if (!useHeaders) {
3280
+ objForEachKey(_headers, function (name, value) {
3281
+ if (_collectorHeaderToQs[name]) {
3282
+ _addRequestDetails(requestDetails, _collectorHeaderToQs[name], value, false);
3283
+ }
3284
+ else {
3285
+ requestDetails.hdrs[name] = value;
3286
+ requestDetails.useHdrs = true;
3287
+ }
3288
+ });
3289
+ }
3290
+ else {
3291
+ requestDetails.hdrs = extend(requestDetails.hdrs, _headers);
3292
+ requestDetails.useHdrs = (objKeys(requestDetails.hdrs).length > 0);
3293
+ }
2629
3294
  _addRequestDetails(requestDetails, strClientId, "NO_AUTH", useHeaders);
2630
3295
  _addRequestDetails(requestDetails, strClientVersion, FullVersionString, useHeaders);
2631
3296
  var apiQsKeys = "";
@@ -2811,7 +3476,7 @@
2811
3476
  reason = 200 ;
2812
3477
  return;
2813
3478
  }
2814
- if (!RetryPolicy$1.shouldRetryForStatus(status) || thePayload.numEvents <= 0) {
3479
+ if (!retryPolicyShouldRetryForStatus(status) || thePayload.numEvents <= 0) {
2815
3480
  shouldRetry = false;
2816
3481
  }
2817
3482
  reason = 9000 + (status % 1000);
@@ -2827,7 +3492,7 @@
2827
3492
  _outstandingRequests--;
2828
3493
  }
2829
3494
  _sendBatches(thePayload.batches, retryCount_1 + 1, thePayload.isTeardown, _isUnloading ? 2 : thePayload.sendType, 5 );
2830
- }, _isUnloading, RetryPolicy$1.getMillisToBackoffForRetry(retryCount_1));
3495
+ }, _isUnloading, retryPolicyGetMillisToBackoffForRetry(retryCount_1));
2831
3496
  }
2832
3497
  else {
2833
3498
  backOffTrans = true;
@@ -2883,7 +3548,7 @@
2883
3548
  cb();
2884
3549
  }
2885
3550
  else {
2886
- _postManager._setTimeoutOverride(cb, interval);
3551
+ timeoutOverride.set(cb, interval);
2887
3552
  }
2888
3553
  }
2889
3554
  function _convertAllHeadersToMap(headersString) {
@@ -2923,7 +3588,7 @@
2923
3588
  responseHandlers[i](responseText);
2924
3589
  }
2925
3590
  catch (e) {
2926
- _postManager.diagLog().throwInternal(LoggingSeverity.CRITICAL, _ExtendedInternalMessageId.PostResponseHandler, "Response handler failed: " + e);
3591
+ _throwInternal(_postManager.diagLog(), 1 , 519 , "Response handler failed: " + e);
2927
3592
  }
2928
3593
  }
2929
3594
  if (responseText) {
@@ -2947,7 +3612,7 @@
2947
3612
  theAction_1.call(actions, theBatches, batchReason, isSyncRequest_1, sendType);
2948
3613
  }
2949
3614
  catch (e) {
2950
- _postManager.diagLog().throwInternal(LoggingSeverity.CRITICAL, _ExtendedInternalMessageId.NotificationException, "send request notification failed: " + e);
3615
+ _throwInternal(_postManager.diagLog(), 1 , 74 , "send request notification failed: " + e);
2951
3616
  }
2952
3617
  }, sendSync || isSyncRequest_1, 0);
2953
3618
  }, function () { return ({ batches: _createDebugBatches(theBatches), reason: batchReason, isSync: isSyncRequest_1, sendSync: sendSync, sendType: sendType }); }, !isSyncRequest_1);
@@ -2975,26 +3640,43 @@
2975
3640
  return HttpManager;
2976
3641
  }());
2977
3642
 
3643
+ function defaultSetTimeout(callback, ms) {
3644
+ var args = [];
3645
+ for (var _i = 2; _i < arguments.length; _i++) {
3646
+ args[_i - 2] = arguments[_i];
3647
+ }
3648
+ return setTimeout(callback, ms, args);
3649
+ }
3650
+ function defaultClearTimeout(timeoutId) {
3651
+ clearTimeout(timeoutId);
3652
+ }
3653
+ function createTimeoutWrapper(argSetTimeout, argClearTimeout) {
3654
+ return {
3655
+ set: argSetTimeout || defaultSetTimeout,
3656
+ clear: argClearTimeout || defaultClearTimeout
3657
+ };
3658
+ }
3659
+
2978
3660
  var FlushCheckTimer = 0.250;
2979
3661
  var MaxNumberEventPerBatch = 500;
2980
3662
  var EventsDroppedAtOneTime = 20;
2981
3663
  var MaxSendAttempts = 6;
2982
3664
  var MaxSyncUnloadSendAttempts = 2;
2983
3665
  var MaxBackoffCount = 4;
2984
- var globalContext = isWindowObjectAvailable ? window : undefined;
2985
3666
  var MaxConnections = 2;
2986
3667
  var MaxRequestRetriesBeforeBackoff = 1;
2987
3668
  var strEventsDiscarded = "eventsDiscarded";
2988
3669
  var strOverrideInstrumentationKey = "overrideInstrumentationKey";
2989
3670
  var strMaxEventRetryAttempts = "maxEventRetryAttempts";
2990
3671
  var strMaxUnloadEventRetryAttempts = "maxUnloadEventRetryAttempts";
3672
+ var strAddUnloadCb = "addUnloadCb";
2991
3673
  var PostChannel = /** @class */ (function (_super) {
2992
3674
  __extendsFn(PostChannel, _super);
2993
3675
  function PostChannel() {
2994
3676
  var _this = _super.call(this) || this;
2995
3677
  _this.identifier = "PostChannel";
2996
3678
  _this.priority = 1011;
2997
- _this.version = '3.1.11';
3679
+ _this.version = '3.2.2';
2998
3680
  var _config;
2999
3681
  var _isTeardownCalled = false;
3000
3682
  var _flushCallbackQueue = [];
@@ -3022,18 +3704,10 @@
3022
3704
  var _disableXhrSync = false;
3023
3705
  var _maxEventSendAttempts = MaxSendAttempts;
3024
3706
  var _maxUnloadEventSendAttempts = MaxSyncUnloadSendAttempts;
3707
+ var _evtNamespace;
3708
+ var _timeoutWrapper;
3025
3709
  dynamicProto(PostChannel, _this, function (_self, _base) {
3026
- _initializeProfiles();
3027
- _clearQueues();
3028
- _setAutoLimits();
3029
- _httpManager = new HttpManager(MaxNumberEventPerBatch, MaxConnections, MaxRequestRetriesBeforeBackoff, {
3030
- requeue: _requeueEvents,
3031
- send: _sendingEvent,
3032
- sent: _eventsSentEvent,
3033
- drop: _eventsDropped,
3034
- rspFail: _eventsResponseFail,
3035
- oth: _otherEvent
3036
- });
3710
+ _initDefaults();
3037
3711
  _self["_getDbgPlgTargets"] = function () {
3038
3712
  return [_httpManager];
3039
3713
  };
@@ -3041,47 +3715,52 @@
3041
3715
  doPerf(core, function () { return "PostChannel:initialize"; }, function () {
3042
3716
  var extendedCore = core;
3043
3717
  _base.initialize(coreConfig, core, extensions);
3044
- _self.setInitialized(false);
3045
- var ctx = _self._getTelCtx();
3046
- coreConfig.extensionConfig[_self.identifier] = coreConfig.extensionConfig[_self.identifier] || {};
3047
- _config = ctx.getExtCfg(_self.identifier);
3048
- _self._setTimeoutOverride = _config.setTimeoutOverride ? _config.setTimeoutOverride : setTimeout.bind(globalContext);
3049
- _self._clearTimeoutOverride = _config.clearTimeoutOverride ? _config.clearTimeoutOverride : clearTimeout.bind(globalContext);
3050
- _optimizeObject = !_config.disableOptimizeObj && isChromium();
3051
- _hookWParam(extendedCore);
3052
- if (_config.eventsLimitInMem > 0) {
3053
- _queueSizeLimit = _config.eventsLimitInMem;
3054
- }
3055
- if (_config.immediateEventLimit > 0) {
3056
- _immediateQueueSizeLimit = _config.immediateEventLimit;
3057
- }
3058
- if (_config.autoFlushEventsLimit > 0) {
3059
- _autoFlushEventsLimit = _config.autoFlushEventsLimit;
3060
- }
3061
- _disableXhrSync = _config.disableXhrSync;
3062
- if (isNumber(_config[strMaxEventRetryAttempts])) {
3063
- _maxEventSendAttempts = _config[strMaxEventRetryAttempts];
3064
- }
3065
- if (isNumber(_config[strMaxUnloadEventRetryAttempts])) {
3066
- _maxUnloadEventSendAttempts = _config[strMaxUnloadEventRetryAttempts];
3067
- }
3068
- _setAutoLimits();
3069
- if (_config.httpXHROverride && _config.httpXHROverride.sendPOST) {
3070
- _xhrOverride = _config.httpXHROverride;
3071
- }
3072
- if (isValueAssigned(coreConfig.anonCookieName)) {
3073
- _httpManager.addQueryStringParameter("anoncknm", coreConfig.anonCookieName);
3074
- }
3075
- _httpManager.sendHook = _config.payloadPreprocessor;
3076
- _httpManager.sendListener = _config.payloadListener;
3077
- var endpointUrl = _config.overrideEndpointUrl ? _config.overrideEndpointUrl : coreConfig.endpointUrl;
3078
- _self._notificationManager = coreConfig.extensionConfig.NotificationManager;
3079
- _httpManager.initialize(endpointUrl, _self.core, _self, _xhrOverride, _config);
3080
- var excludePageUnloadEvents = coreConfig.disablePageUnloadEvents || [];
3081
- addPageUnloadEventListener(_handleUnloadEvents, excludePageUnloadEvents);
3082
- addPageHideEventListener(_handleUnloadEvents, excludePageUnloadEvents);
3083
- addPageShowEventListener(_handleShowEvents, coreConfig.disablePageShowEvents);
3084
- _self.setInitialized(true);
3718
+ try {
3719
+ var hasAddUnloadCb = !!core[strAddUnloadCb];
3720
+ _evtNamespace = mergeEvtNamespace(createUniqueNamespace(_self.identifier), core.evtNamespace && core.evtNamespace());
3721
+ var ctx = _self._getTelCtx();
3722
+ coreConfig.extensionConfig[_self.identifier] = coreConfig.extensionConfig[_self.identifier] || {};
3723
+ _config = ctx.getExtCfg(_self.identifier);
3724
+ _timeoutWrapper = createTimeoutWrapper(_config.setTimeoutOverride, _config.clearTimeoutOverride);
3725
+ _optimizeObject = !_config.disableOptimizeObj && isChromium();
3726
+ _hookWParam(extendedCore);
3727
+ if (_config.eventsLimitInMem > 0) {
3728
+ _queueSizeLimit = _config.eventsLimitInMem;
3729
+ }
3730
+ if (_config.immediateEventLimit > 0) {
3731
+ _immediateQueueSizeLimit = _config.immediateEventLimit;
3732
+ }
3733
+ if (_config.autoFlushEventsLimit > 0) {
3734
+ _autoFlushEventsLimit = _config.autoFlushEventsLimit;
3735
+ }
3736
+ _disableXhrSync = _config.disableXhrSync;
3737
+ if (isNumber(_config[strMaxEventRetryAttempts])) {
3738
+ _maxEventSendAttempts = _config[strMaxEventRetryAttempts];
3739
+ }
3740
+ if (isNumber(_config[strMaxUnloadEventRetryAttempts])) {
3741
+ _maxUnloadEventSendAttempts = _config[strMaxUnloadEventRetryAttempts];
3742
+ }
3743
+ _setAutoLimits();
3744
+ if (_config.httpXHROverride && _config.httpXHROverride.sendPOST) {
3745
+ _xhrOverride = _config.httpXHROverride;
3746
+ }
3747
+ if (isValueAssigned(coreConfig.anonCookieName)) {
3748
+ _httpManager.addQueryStringParameter("anoncknm", coreConfig.anonCookieName);
3749
+ }
3750
+ _httpManager.sendHook = _config.payloadPreprocessor;
3751
+ _httpManager.sendListener = _config.payloadListener;
3752
+ var endpointUrl = _config.overrideEndpointUrl ? _config.overrideEndpointUrl : coreConfig.endpointUrl;
3753
+ _self._notificationManager = coreConfig.extensionConfig.NotificationManager;
3754
+ _httpManager.initialize(endpointUrl, _self.core, _self, _xhrOverride, _config);
3755
+ var excludePageUnloadEvents = coreConfig.disablePageUnloadEvents || [];
3756
+ addPageUnloadEventListener(_handleUnloadEvents, excludePageUnloadEvents, _evtNamespace);
3757
+ addPageHideEventListener(_handleUnloadEvents, excludePageUnloadEvents, _evtNamespace);
3758
+ addPageShowEventListener(_handleShowEvents, coreConfig.disablePageShowEvents, _evtNamespace);
3759
+ }
3760
+ catch (e) {
3761
+ _self.setInitialized(false);
3762
+ throw e;
3763
+ }
3085
3764
  }, function () { return ({ coreConfig: coreConfig, core: core, extensions: extensions }); });
3086
3765
  };
3087
3766
  _self.processTelemetry = function (ev, itemCtx) {
@@ -3110,6 +3789,15 @@
3110
3789
  }
3111
3790
  _self.processNext(event, itemCtx);
3112
3791
  };
3792
+ _self._doTeardown = function (unloadCtx, unloadState) {
3793
+ _releaseAllQueues(2 , 2 );
3794
+ _isTeardownCalled = true;
3795
+ _httpManager.teardown();
3796
+ removePageUnloadEventListener(null, _evtNamespace);
3797
+ removePageHideEventListener(null, _evtNamespace);
3798
+ removePageShowEventListener(null, _evtNamespace);
3799
+ _initDefaults();
3800
+ };
3113
3801
  function _hookWParam(extendedCore) {
3114
3802
  var existingGetWParamMethod = extendedCore.getWParam;
3115
3803
  extendedCore.getWParam = function () {
@@ -3137,7 +3825,7 @@
3137
3825
  event.sendAttempt = 0;
3138
3826
  }
3139
3827
  if (!event.latency) {
3140
- event.latency = EventLatency.Normal;
3828
+ event.latency = 1 ;
3141
3829
  }
3142
3830
  if (event.ext && event.ext["trace"]) {
3143
3831
  delete (event.ext["trace"]);
@@ -3156,7 +3844,7 @@
3156
3844
  }
3157
3845
  if (event.sync) {
3158
3846
  if (_currentBackoffCount || _paused) {
3159
- event.latency = EventLatency.RealTime;
3847
+ event.latency = 3 ;
3160
3848
  event.sync = false;
3161
3849
  }
3162
3850
  else {
@@ -3172,7 +3860,7 @@
3172
3860
  var evtLatency = event.latency;
3173
3861
  var queueSize = _queueSize;
3174
3862
  var queueLimit = _queueSizeLimit;
3175
- if (evtLatency === EventLatency.Immediate) {
3863
+ if (evtLatency === 4 ) {
3176
3864
  queueSize = _immediateQueueSize;
3177
3865
  queueLimit = _immediateQueueSizeLimit;
3178
3866
  }
@@ -3181,10 +3869,10 @@
3181
3869
  eventDropped = !_addEventToProperQueue(event, append);
3182
3870
  }
3183
3871
  else {
3184
- var dropLatency = EventLatency.Normal;
3872
+ var dropLatency = 1 ;
3185
3873
  var dropNumber = EventsDroppedAtOneTime;
3186
- if (evtLatency === EventLatency.Immediate) {
3187
- dropLatency = EventLatency.Immediate;
3874
+ if (evtLatency === 4 ) {
3875
+ dropLatency = 4 ;
3188
3876
  dropNumber = 1;
3189
3877
  }
3190
3878
  eventDropped = true;
@@ -3202,7 +3890,7 @@
3202
3890
  _setAutoLimits();
3203
3891
  var doFlush = _queueSize > eventLimit;
3204
3892
  if (!doFlush && _autoFlushBatchLimit > 0) {
3205
- for (var latency = EventLatency.Normal; !doFlush && latency <= EventLatency.RealTime; latency++) {
3893
+ for (var latency = 1 ; !doFlush && latency <= 3 ; latency++) {
3206
3894
  var batchQueue = _batchQueues[latency];
3207
3895
  if (batchQueue && batchQueue.batches) {
3208
3896
  arrForEach(batchQueue.batches, function (theBatch) {
@@ -3215,11 +3903,6 @@
3215
3903
  }
3216
3904
  _performAutoFlush(true, doFlush);
3217
3905
  };
3218
- _self.teardown = function () {
3219
- _releaseAllQueues(2 , 2 );
3220
- _isTeardownCalled = true;
3221
- _httpManager.teardown();
3222
- };
3223
3906
  _self.pause = function () {
3224
3907
  _clearScheduledTimer();
3225
3908
  _paused = true;
@@ -3261,7 +3944,7 @@
3261
3944
  _clearScheduledTimer();
3262
3945
  sendReason = sendReason || 1 ;
3263
3946
  if (async) {
3264
- _queueBatches(EventLatency.Normal, 0 , sendReason);
3947
+ _queueBatches(1 , 0 , sendReason);
3265
3948
  _resetQueueCounts();
3266
3949
  if (_flushCallbackTimerId == null) {
3267
3950
  _flushCallbackTimerId = _createTimer(function () {
@@ -3273,7 +3956,7 @@
3273
3956
  }
3274
3957
  }
3275
3958
  else {
3276
- _sendEventsForLatencyAndAbove(EventLatency.Normal, 1 , sendReason);
3959
+ _sendEventsForLatencyAndAbove(1 , 1 , sendReason);
3277
3960
  if (callback !== null && callback !== undefined) {
3278
3961
  callback();
3279
3962
  }
@@ -3308,7 +3991,7 @@
3308
3991
  if (immediateTimeOut >= 0) {
3309
3992
  _immediateTimerId = _createTimer(function () {
3310
3993
  _immediateTimerId = null;
3311
- _sendEventsForLatencyAndAbove(EventLatency.Immediate, 0 , 1 );
3994
+ _sendEventsForLatencyAndAbove(4 , 0 , 1 );
3312
3995
  _scheduleTimer();
3313
3996
  }, immediateTimeOut);
3314
3997
  }
@@ -3318,7 +4001,7 @@
3318
4001
  if (_hasEvents()) {
3319
4002
  _scheduledTimerId = _createTimer(function () {
3320
4003
  _scheduledTimerId = null;
3321
- _sendEventsForLatencyAndAbove(_timerCount === 0 ? EventLatency.RealTime : EventLatency.Normal, 0 , 1 );
4004
+ _sendEventsForLatencyAndAbove(_timerCount === 0 ? 3 : 1 , 0 , 1 );
3322
4005
  _timerCount++;
3323
4006
  _timerCount %= 2;
3324
4007
  _scheduleTimer();
@@ -3343,19 +4026,60 @@
3343
4026
  _scheduleTimer();
3344
4027
  }
3345
4028
  };
4029
+ function _initDefaults() {
4030
+ _config = null;
4031
+ _isTeardownCalled = false;
4032
+ _flushCallbackQueue = [];
4033
+ _flushCallbackTimerId = null;
4034
+ _paused = false;
4035
+ _immediateQueueSize = 0;
4036
+ _immediateQueueSizeLimit = 500;
4037
+ _queueSize = 0;
4038
+ _queueSizeLimit = 10000;
4039
+ _profiles = {};
4040
+ _currentProfile = RT_PROFILE;
4041
+ _scheduledTimerId = null;
4042
+ _immediateTimerId = null;
4043
+ _currentBackoffCount = 0;
4044
+ _timerCount = 0;
4045
+ _xhrOverride = null;
4046
+ _batchQueues = {};
4047
+ _autoFlushEventsLimit = undefined;
4048
+ _autoFlushBatchLimit = 0;
4049
+ _delayedBatchSendLatency = -1;
4050
+ _delayedBatchReason = null;
4051
+ _optimizeObject = true;
4052
+ _isPageUnloadTriggered = false;
4053
+ _disableXhrSync = false;
4054
+ _maxEventSendAttempts = MaxSendAttempts;
4055
+ _maxUnloadEventSendAttempts = MaxSyncUnloadSendAttempts;
4056
+ _evtNamespace = null;
4057
+ _timeoutWrapper = createTimeoutWrapper();
4058
+ _httpManager = new HttpManager(MaxNumberEventPerBatch, MaxConnections, MaxRequestRetriesBeforeBackoff, {
4059
+ requeue: _requeueEvents,
4060
+ send: _sendingEvent,
4061
+ sent: _eventsSentEvent,
4062
+ drop: _eventsDropped,
4063
+ rspFail: _eventsResponseFail,
4064
+ oth: _otherEvent
4065
+ }, _timeoutWrapper);
4066
+ _initializeProfiles();
4067
+ _clearQueues();
4068
+ _setAutoLimits();
4069
+ }
3346
4070
  function _createTimer(theTimerFunc, timeOut) {
3347
4071
  if (timeOut === 0 && _currentBackoffCount) {
3348
4072
  timeOut = 1;
3349
4073
  }
3350
4074
  var timerMultiplier = 1000;
3351
4075
  if (_currentBackoffCount) {
3352
- timerMultiplier = RetryPolicy$1.getMillisToBackoffForRetry(_currentBackoffCount - 1);
4076
+ timerMultiplier = retryPolicyGetMillisToBackoffForRetry(_currentBackoffCount - 1);
3353
4077
  }
3354
- return _self._setTimeoutOverride(theTimerFunc, timeOut * timerMultiplier);
4078
+ return _timeoutWrapper.set(theTimerFunc, timeOut * timerMultiplier);
3355
4079
  }
3356
4080
  function _clearScheduledTimer() {
3357
4081
  if (_scheduledTimerId !== null) {
3358
- _self._clearTimeoutOverride(_scheduledTimerId);
4082
+ _timeoutWrapper.clear(_scheduledTimerId);
3359
4083
  _scheduledTimerId = null;
3360
4084
  _timerCount = 0;
3361
4085
  }
@@ -3363,27 +4087,27 @@
3363
4087
  function _releaseAllQueues(sendType, sendReason) {
3364
4088
  _clearScheduledTimer();
3365
4089
  if (_flushCallbackTimerId) {
3366
- _self._clearTimeoutOverride(_flushCallbackTimerId);
4090
+ _timeoutWrapper.clear(_flushCallbackTimerId);
3367
4091
  _flushCallbackTimerId = null;
3368
4092
  }
3369
4093
  if (!_paused) {
3370
- _sendEventsForLatencyAndAbove(EventLatency.Normal, sendType, sendReason);
4094
+ _sendEventsForLatencyAndAbove(1 , sendType, sendReason);
3371
4095
  }
3372
4096
  }
3373
4097
  function _clearQueues() {
3374
- _batchQueues[EventLatency.Immediate] = {
4098
+ _batchQueues[4 ] = {
3375
4099
  batches: [],
3376
4100
  iKeyMap: {}
3377
4101
  };
3378
- _batchQueues[EventLatency.RealTime] = {
4102
+ _batchQueues[3 ] = {
3379
4103
  batches: [],
3380
4104
  iKeyMap: {}
3381
4105
  };
3382
- _batchQueues[EventLatency.CostDeferred] = {
4106
+ _batchQueues[2 ] = {
3383
4107
  batches: [],
3384
4108
  iKeyMap: {}
3385
4109
  };
3386
- _batchQueues[EventLatency.Normal] = {
4110
+ _batchQueues[1 ] = {
3387
4111
  batches: [],
3388
4112
  iKeyMap: {}
3389
4113
  };
@@ -3391,7 +4115,7 @@
3391
4115
  function _getEventBatch(iKey, latency, create) {
3392
4116
  var batchQueue = _batchQueues[latency];
3393
4117
  if (!batchQueue) {
3394
- latency = EventLatency.Normal;
4118
+ latency = 1 ;
3395
4119
  batchQueue = _batchQueues[latency];
3396
4120
  }
3397
4121
  var eventBatch = batchQueue.iKeyMap[iKey];
@@ -3419,7 +4143,7 @@
3419
4143
  var latency = event.latency;
3420
4144
  var eventBatch = _getEventBatch(event.iKey, latency, true);
3421
4145
  if (eventBatch.addEvent(event)) {
3422
- if (latency !== EventLatency.Immediate) {
4146
+ if (latency !== 4 ) {
3423
4147
  _queueSize++;
3424
4148
  if (append && event.sendAttempt === 0) {
3425
4149
  _performAutoFlush(!event.sync, _autoFlushBatchLimit > 0 && eventBatch.count() >= _autoFlushBatchLimit);
@@ -3439,7 +4163,7 @@
3439
4163
  var droppedEvents = eventBatch.split(0, dropNumber);
3440
4164
  var droppedCount = droppedEvents.count();
3441
4165
  if (droppedCount > 0) {
3442
- if (currentLatency === EventLatency.Immediate) {
4166
+ if (currentLatency === 4 ) {
3443
4167
  _immediateQueueSize -= droppedCount;
3444
4168
  }
3445
4169
  else {
@@ -3461,7 +4185,7 @@
3461
4185
  var batchQueue = _batchQueues[latency];
3462
4186
  if (batchQueue && batchQueue.batches) {
3463
4187
  arrForEach(batchQueue.batches, function (theBatch) {
3464
- if (latency === EventLatency.Immediate) {
4188
+ if (latency === 4 ) {
3465
4189
  immediateQueue += theBatch.count();
3466
4190
  }
3467
4191
  else {
@@ -3470,7 +4194,7 @@
3470
4194
  });
3471
4195
  }
3472
4196
  };
3473
- for (var latency = EventLatency.Normal; latency <= EventLatency.Immediate; latency++) {
4197
+ for (var latency = 1 ; latency <= 4 ; latency++) {
3474
4198
  _loop_1(latency);
3475
4199
  }
3476
4200
  _queueSize = normalQueue;
@@ -3482,7 +4206,7 @@
3482
4206
  if (!isAsync || _httpManager.canSendRequest()) {
3483
4207
  doPerf(_self.core, function () { return "PostChannel._queueBatches"; }, function () {
3484
4208
  var droppedEvents = [];
3485
- var latencyToProcess = EventLatency.Immediate;
4209
+ var latencyToProcess = 4 ;
3486
4210
  while (latencyToProcess >= latency) {
3487
4211
  var batchQueue = _batchQueues[latencyToProcess];
3488
4212
  if (batchQueue && batchQueue.batches && batchQueue.batches.length > 0) {
@@ -3493,7 +4217,7 @@
3493
4217
  else {
3494
4218
  eventsQueued = eventsQueued || (theBatch && theBatch.count() > 0);
3495
4219
  }
3496
- if (latencyToProcess === EventLatency.Immediate) {
4220
+ if (latencyToProcess === 4 ) {
3497
4221
  _immediateQueueSize -= theBatch.count();
3498
4222
  }
3499
4223
  else {
@@ -3521,7 +4245,7 @@
3521
4245
  return eventsQueued;
3522
4246
  }
3523
4247
  function _flushImpl(callback, sendReason) {
3524
- _sendEventsForLatencyAndAbove(EventLatency.Normal, 0 , sendReason);
4248
+ _sendEventsForLatencyAndAbove(1 , 0 , sendReason);
3525
4249
  _waitForIdleManager(function () {
3526
4250
  if (callback) {
3527
4251
  callback();
@@ -3570,7 +4294,7 @@
3570
4294
  arrForEach(theBatch.events(), function (theEvent) {
3571
4295
  if (theEvent) {
3572
4296
  if (theEvent.sync) {
3573
- theEvent.latency = EventLatency.Immediate;
4297
+ theEvent.latency = 4 ;
3574
4298
  theEvent.sync = false;
3575
4299
  }
3576
4300
  if (theEvent.sendAttempt < maxSendAttempts) {
@@ -3599,7 +4323,7 @@
3599
4323
  notifyFunc.apply(manager, theArgs);
3600
4324
  }
3601
4325
  catch (e) {
3602
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _ExtendedInternalMessageId.NotificationException, evtName + " notification failed: " + e);
4326
+ _throwInternal(_self.diagLog(), 1 , 74 , evtName + " notification failed: " + e);
3603
4327
  }
3604
4328
  }
3605
4329
  }
@@ -3657,6 +4381,12 @@
3657
4381
  _autoFlushBatchLimit = 0;
3658
4382
  }
3659
4383
  }
4384
+ objDefineAccessors(_self, "_setTimeoutOverride", function () { return _timeoutWrapper.set; }, function (value) {
4385
+ _timeoutWrapper = createTimeoutWrapper(value, _timeoutWrapper.clear);
4386
+ });
4387
+ objDefineAccessors(_self, "_clearTimeoutOverride", function () { return _timeoutWrapper.clear; }, function (value) {
4388
+ _timeoutWrapper = createTimeoutWrapper(_timeoutWrapper.set, value);
4389
+ });
3660
4390
  });
3661
4391
  return _this;
3662
4392
  }