@microsoft/applicationinsights-core-js 2.8.0-beta.2202-07 → 2.8.0-beta.2203-03

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 (128) hide show
  1. package/browser/applicationinsights-core-js.integrity.json +9 -9
  2. package/browser/applicationinsights-core-js.js +1137 -484
  3. package/browser/applicationinsights-core-js.js.map +1 -1
  4. package/browser/applicationinsights-core-js.min.js +2 -2
  5. package/browser/applicationinsights-core-js.min.js.map +1 -1
  6. package/dist/applicationinsights-core-js.api.json +6529 -2784
  7. package/dist/applicationinsights-core-js.api.md +290 -30
  8. package/dist/applicationinsights-core-js.d.ts +481 -89
  9. package/dist/applicationinsights-core-js.js +1137 -484
  10. package/dist/applicationinsights-core-js.js.map +1 -1
  11. package/dist/applicationinsights-core-js.min.js +2 -2
  12. package/dist/applicationinsights-core-js.min.js.map +1 -1
  13. package/dist/applicationinsights-core-js.rollup.d.ts +481 -89
  14. package/dist-esm/JavaScriptSDK/AppInsightsCore.js +1 -1
  15. package/dist-esm/JavaScriptSDK/BaseCore.js +248 -32
  16. package/dist-esm/JavaScriptSDK/BaseCore.js.map +1 -1
  17. package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js +50 -5
  18. package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js.map +1 -1
  19. package/dist-esm/JavaScriptSDK/ChannelController.js +105 -73
  20. package/dist-esm/JavaScriptSDK/ChannelController.js.map +1 -1
  21. package/dist-esm/JavaScriptSDK/Constants.js +1 -1
  22. package/dist-esm/JavaScriptSDK/CookieMgr.js +3 -4
  23. package/dist-esm/JavaScriptSDK/CookieMgr.js.map +1 -1
  24. package/dist-esm/JavaScriptSDK/CoreUtils.js +6 -122
  25. package/dist-esm/JavaScriptSDK/CoreUtils.js.map +1 -1
  26. package/dist-esm/JavaScriptSDK/DataCacheHelper.js +93 -0
  27. package/dist-esm/JavaScriptSDK/DataCacheHelper.js.map +1 -0
  28. package/dist-esm/JavaScriptSDK/DbgExtensionUtils.js +1 -1
  29. package/dist-esm/JavaScriptSDK/DiagnosticLogger.js +12 -12
  30. package/dist-esm/JavaScriptSDK/DiagnosticLogger.js.map +1 -1
  31. package/dist-esm/JavaScriptSDK/EnvUtils.js +8 -7
  32. package/dist-esm/JavaScriptSDK/EnvUtils.js.map +1 -1
  33. package/dist-esm/JavaScriptSDK/EventHelpers.js +472 -0
  34. package/dist-esm/JavaScriptSDK/EventHelpers.js.map +1 -0
  35. package/dist-esm/JavaScriptSDK/HelperFuncs.js +32 -59
  36. package/dist-esm/JavaScriptSDK/HelperFuncs.js.map +1 -1
  37. package/dist-esm/JavaScriptSDK/InstrumentHooks.js +1 -1
  38. package/dist-esm/JavaScriptSDK/InternalConstants.js +28 -0
  39. package/dist-esm/JavaScriptSDK/InternalConstants.js.map +1 -0
  40. package/dist-esm/JavaScriptSDK/NotificationManager.js +8 -11
  41. package/dist-esm/JavaScriptSDK/NotificationManager.js.map +1 -1
  42. package/dist-esm/JavaScriptSDK/PerfManager.js +1 -1
  43. package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js +195 -107
  44. package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js.map +1 -1
  45. package/dist-esm/JavaScriptSDK/RandomHelper.js +3 -2
  46. package/dist-esm/JavaScriptSDK/RandomHelper.js.map +1 -1
  47. package/dist-esm/JavaScriptSDK/TelemetryHelpers.js +32 -13
  48. package/dist-esm/JavaScriptSDK/TelemetryHelpers.js.map +1 -1
  49. package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js +4 -6
  50. package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js.map +1 -1
  51. package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js +32 -0
  52. package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js.map +1 -0
  53. package/dist-esm/JavaScriptSDK.Enums/EventsDiscardedReason.js +1 -1
  54. package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js +90 -96
  55. package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js.map +1 -1
  56. package/dist-esm/JavaScriptSDK.Enums/SendRequestReason.js +1 -1
  57. package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js +8 -0
  58. package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js.map +1 -0
  59. package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js +1 -1
  60. package/dist-esm/JavaScriptSDK.Interfaces/IChannelControls.js +1 -1
  61. package/dist-esm/JavaScriptSDK.Interfaces/IConfiguration.js +1 -1
  62. package/dist-esm/JavaScriptSDK.Interfaces/ICookieMgr.js +1 -1
  63. package/dist-esm/JavaScriptSDK.Interfaces/IDbgExtension.js +1 -1
  64. package/dist-esm/JavaScriptSDK.Interfaces/IDiagnosticLogger.js +1 -1
  65. package/dist-esm/JavaScriptSDK.Interfaces/IInstrumentHooks.js +1 -1
  66. package/dist-esm/JavaScriptSDK.Interfaces/INotificationListener.js +1 -1
  67. package/dist-esm/JavaScriptSDK.Interfaces/INotificationManager.js +1 -1
  68. package/dist-esm/JavaScriptSDK.Interfaces/IPerfEvent.js +1 -1
  69. package/dist-esm/JavaScriptSDK.Interfaces/IPerfManager.js +1 -1
  70. package/dist-esm/JavaScriptSDK.Interfaces/IProcessTelemetryContext.js +1 -1
  71. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js +1 -1
  72. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryItem.js +1 -1
  73. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPlugin.js +1 -1
  74. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js +1 -2
  75. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js.map +1 -1
  76. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js +8 -0
  77. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js.map +1 -0
  78. package/dist-esm/applicationinsights-core-js.js +9 -4
  79. package/dist-esm/applicationinsights-core-js.js.map +1 -1
  80. package/package.json +1 -1
  81. package/src/JavaScriptSDK/BaseCore.ts +312 -33
  82. package/src/JavaScriptSDK/BaseTelemetryPlugin.ts +90 -5
  83. package/src/JavaScriptSDK/ChannelController.ts +107 -61
  84. package/src/JavaScriptSDK/CookieMgr.ts +4 -4
  85. package/src/JavaScriptSDK/CoreUtils.ts +6 -143
  86. package/src/JavaScriptSDK/DataCacheHelper.ts +106 -0
  87. package/src/JavaScriptSDK/DiagnosticLogger.ts +12 -11
  88. package/src/JavaScriptSDK/EnvUtils.ts +7 -6
  89. package/src/JavaScriptSDK/EventHelpers.ts +542 -0
  90. package/src/JavaScriptSDK/HelperFuncs.ts +35 -54
  91. package/src/JavaScriptSDK/InternalConstants.ts +26 -0
  92. package/src/JavaScriptSDK/NotificationManager.ts +7 -11
  93. package/src/JavaScriptSDK/ProcessTelemetryContext.ts +248 -121
  94. package/src/JavaScriptSDK/RandomHelper.ts +2 -1
  95. package/src/JavaScriptSDK/TelemetryHelpers.ts +47 -15
  96. package/src/JavaScriptSDK/TelemetryInitializerPlugin.ts +5 -15
  97. package/src/JavaScriptSDK/UnloadHandlerContainer.ts +44 -0
  98. package/src/JavaScriptSDK.Enums/LoggingEnums.ts +184 -87
  99. package/src/JavaScriptSDK.Enums/SendRequestReason.ts +5 -0
  100. package/src/JavaScriptSDK.Enums/TelemetryUnloadReason.ts +27 -0
  101. package/src/JavaScriptSDK.Interfaces/IAppInsightsCore.ts +49 -2
  102. package/src/JavaScriptSDK.Interfaces/IChannelControls.ts +9 -2
  103. package/src/JavaScriptSDK.Interfaces/IProcessTelemetryContext.ts +55 -16
  104. package/src/JavaScriptSDK.Interfaces/ITelemetryPlugin.ts +16 -9
  105. package/src/JavaScriptSDK.Interfaces/ITelemetryPluginChain.ts +9 -11
  106. package/src/JavaScriptSDK.Interfaces/ITelemetryUnloadState.ts +10 -0
  107. package/types/JavaScriptSDK/BaseCore.d.ts +21 -1
  108. package/types/JavaScriptSDK/BaseTelemetryPlugin.d.ts +26 -1
  109. package/types/JavaScriptSDK/ChannelController.d.ts +4 -0
  110. package/types/JavaScriptSDK/CoreUtils.d.ts +1 -42
  111. package/types/JavaScriptSDK/DataCacheHelper.d.ts +13 -0
  112. package/types/JavaScriptSDK/EventHelpers.d.ts +152 -0
  113. package/types/JavaScriptSDK/HelperFuncs.d.ts +8 -17
  114. package/types/JavaScriptSDK/InternalConstants.d.ts +20 -0
  115. package/types/JavaScriptSDK/ProcessTelemetryContext.d.ts +12 -3
  116. package/types/JavaScriptSDK/TelemetryHelpers.d.ts +8 -0
  117. package/types/JavaScriptSDK/TelemetryInitializerPlugin.d.ts +0 -7
  118. package/types/JavaScriptSDK/UnloadHandlerContainer.d.ts +11 -0
  119. package/types/JavaScriptSDK.Enums/LoggingEnums.d.ts +91 -2
  120. package/types/JavaScriptSDK.Enums/SendRequestReason.d.ts +4 -0
  121. package/types/JavaScriptSDK.Enums/TelemetryUnloadReason.d.ts +21 -0
  122. package/types/JavaScriptSDK.Interfaces/IAppInsightsCore.d.ts +41 -1
  123. package/types/JavaScriptSDK.Interfaces/IChannelControls.d.ts +9 -2
  124. package/types/JavaScriptSDK.Interfaces/IProcessTelemetryContext.d.ts +49 -14
  125. package/types/JavaScriptSDK.Interfaces/ITelemetryPlugin.d.ts +15 -8
  126. package/types/JavaScriptSDK.Interfaces/ITelemetryPluginChain.d.ts +9 -10
  127. package/types/JavaScriptSDK.Interfaces/ITelemetryUnloadState.d.ts +6 -0
  128. package/types/applicationinsights-core-js.d.ts +7 -3
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Application Insights JavaScript SDK - Core, 2.8.0-beta.2202-07
2
+ * Application Insights JavaScript SDK - Core, 2.8.0-beta.2203-03
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
  (function (global, factory) {
@@ -340,101 +340,26 @@
340
340
  };
341
341
  dynamicProto[DynProtoDefaultOptions] = perfDefaults;
342
342
 
343
- exports.LoggingSeverity = void 0;
344
- (function (LoggingSeverity) {
345
- LoggingSeverity[LoggingSeverity["CRITICAL"] = 1] = "CRITICAL";
346
- LoggingSeverity[LoggingSeverity["WARNING"] = 2] = "WARNING";
347
- })(exports.LoggingSeverity || (exports.LoggingSeverity = {}));
348
- var _InternalMessageId = {
349
- BrowserDoesNotSupportLocalStorage: 0,
350
- BrowserCannotReadLocalStorage: 1,
351
- BrowserCannotReadSessionStorage: 2,
352
- BrowserCannotWriteLocalStorage: 3,
353
- BrowserCannotWriteSessionStorage: 4,
354
- BrowserFailedRemovalFromLocalStorage: 5,
355
- BrowserFailedRemovalFromSessionStorage: 6,
356
- CannotSendEmptyTelemetry: 7,
357
- ClientPerformanceMathError: 8,
358
- ErrorParsingAISessionCookie: 9,
359
- ErrorPVCalc: 10,
360
- ExceptionWhileLoggingError: 11,
361
- FailedAddingTelemetryToBuffer: 12,
362
- FailedMonitorAjaxAbort: 13,
363
- FailedMonitorAjaxDur: 14,
364
- FailedMonitorAjaxOpen: 15,
365
- FailedMonitorAjaxRSC: 16,
366
- FailedMonitorAjaxSend: 17,
367
- FailedMonitorAjaxGetCorrelationHeader: 18,
368
- FailedToAddHandlerForOnBeforeUnload: 19,
369
- FailedToSendQueuedTelemetry: 20,
370
- FailedToReportDataLoss: 21,
371
- FlushFailed: 22,
372
- MessageLimitPerPVExceeded: 23,
373
- MissingRequiredFieldSpecification: 24,
374
- NavigationTimingNotSupported: 25,
375
- OnError: 26,
376
- SessionRenewalDateIsZero: 27,
377
- SenderNotInitialized: 28,
378
- StartTrackEventFailed: 29,
379
- StopTrackEventFailed: 30,
380
- StartTrackFailed: 31,
381
- StopTrackFailed: 32,
382
- TelemetrySampledAndNotSent: 33,
383
- TrackEventFailed: 34,
384
- TrackExceptionFailed: 35,
385
- TrackMetricFailed: 36,
386
- TrackPVFailed: 37,
387
- TrackPVFailedCalc: 38,
388
- TrackTraceFailed: 39,
389
- TransmissionFailed: 40,
390
- FailedToSetStorageBuffer: 41,
391
- FailedToRestoreStorageBuffer: 42,
392
- InvalidBackendResponse: 43,
393
- FailedToFixDepricatedValues: 44,
394
- InvalidDurationValue: 45,
395
- TelemetryEnvelopeInvalid: 46,
396
- CreateEnvelopeError: 47,
397
- CannotSerializeObject: 48,
398
- CannotSerializeObjectNonSerializable: 49,
399
- CircularReferenceDetected: 50,
400
- ClearAuthContextFailed: 51,
401
- ExceptionTruncated: 52,
402
- IllegalCharsInName: 53,
403
- ItemNotInArray: 54,
404
- MaxAjaxPerPVExceeded: 55,
405
- MessageTruncated: 56,
406
- NameTooLong: 57,
407
- SampleRateOutOfRange: 58,
408
- SetAuthContextFailed: 59,
409
- SetAuthContextFailedAccountName: 60,
410
- StringValueTooLong: 61,
411
- StartCalledMoreThanOnce: 62,
412
- StopCalledWithoutStart: 63,
413
- TelemetryInitializerFailed: 64,
414
- TrackArgumentsNotSpecified: 65,
415
- UrlTooLong: 66,
416
- SessionStorageBufferFull: 67,
417
- CannotAccessCookie: 68,
418
- IdTooLong: 69,
419
- InvalidEvent: 70,
420
- FailedMonitorAjaxSetRequestHeader: 71,
421
- SendBrowserInfoOnUserInit: 72,
422
- PluginException: 73,
423
- NotificationException: 74,
424
- SnippetScriptLoadFailure: 99,
425
- InvalidInstrumentationKey: 100,
426
- CannotParseAiBlobValue: 101,
427
- InvalidContentBlob: 102,
428
- TrackPageActionEventFailed: 103,
429
- FailedAddingCustomDefinedRequestContext: 104,
430
- InMemoryStorageBufferFull: 105
431
- };
343
+ var strEmpty = "";
344
+ var strProcessTelemetry = "processTelemetry";
345
+ var strPriority = "priority";
346
+ var strSetNextPlugin = "setNextPlugin";
347
+ var strIsInitialized = "isInitialized";
348
+ var strTeardown = "teardown";
349
+ var strCore = "core";
350
+ var strDisabled = "disabled";
351
+ var strDoTeardown = "_doTeardown";
352
+ var strProcessNext = "processNext";
353
+ var strResume = "resume";
354
+ var strPause = "pause";
355
+ var strNotificationListener = "NotificationListener";
356
+ var strAddNotificationListener = "add" + strNotificationListener;
357
+ var strRemoveNotificationListener = "remove" + strNotificationListener;
358
+ var strEventsSent = "eventsSent";
359
+ var strEventsDiscarded = "eventsDiscarded";
360
+ var strEventsSendRequest = "eventsSendRequest";
361
+ var strPerfEvent = "perfEvent";
432
362
 
433
- var strOnPrefix = "on";
434
- var strAttachEvent = "attachEvent";
435
- var strAddEventHelper = "addEventListener";
436
- var strDetachEvent = "detachEvent";
437
- var strRemoveEventListener = "removeEventListener";
438
363
  var strToISOString = "toISOString";
439
364
  var cStrEndsWith = "endsWith";
440
365
  var cStrStartsWith = "startsWith";
@@ -445,7 +370,7 @@
445
370
  var strToString = "toString";
446
371
  var str__Proto = "__proto__";
447
372
  var strConstructor = "constructor";
448
- var _objDefineProperty = ObjDefineProperty;
373
+ var _objDefineProperty$1 = ObjDefineProperty;
449
374
  var _objFreeze = ObjClass.freeze;
450
375
  var _objSeal = ObjClass.seal;
451
376
  var _objKeys = ObjClass.keys;
@@ -499,40 +424,6 @@
499
424
  function isFunction(value) {
500
425
  return !!(value && typeof value === strShimFunction);
501
426
  }
502
- function attachEvent(obj, eventNameWithoutOn, handlerRef, useCapture) {
503
- if (useCapture === void 0) { useCapture = false; }
504
- var result = false;
505
- if (!isNullOrUndefined(obj)) {
506
- try {
507
- if (!isNullOrUndefined(obj[strAddEventHelper])) {
508
- obj[strAddEventHelper](eventNameWithoutOn, handlerRef, useCapture);
509
- result = true;
510
- }
511
- else if (!isNullOrUndefined(obj[strAttachEvent])) {
512
- obj[strAttachEvent](strOnPrefix + eventNameWithoutOn, handlerRef);
513
- result = true;
514
- }
515
- }
516
- catch (e) {
517
- }
518
- }
519
- return result;
520
- }
521
- function detachEvent(obj, eventNameWithoutOn, handlerRef, useCapture) {
522
- if (useCapture === void 0) { useCapture = false; }
523
- if (!isNullOrUndefined(obj)) {
524
- try {
525
- if (!isNullOrUndefined(obj[strRemoveEventListener])) {
526
- obj[strRemoveEventListener](eventNameWithoutOn, handlerRef, useCapture);
527
- }
528
- else if (!isNullOrUndefined(obj[strDetachEvent])) {
529
- obj[strDetachEvent](strOnPrefix + eventNameWithoutOn, handlerRef);
530
- }
531
- }
532
- catch (e) {
533
- }
534
- }
535
- }
536
427
  function normalizeJsName(name) {
537
428
  var value = name;
538
429
  if (value && isString(value)) {
@@ -787,7 +678,7 @@
787
678
  return result;
788
679
  }
789
680
  function objDefineAccessors(target, prop, getProp, setProp) {
790
- if (_objDefineProperty) {
681
+ if (_objDefineProperty$1) {
791
682
  try {
792
683
  var descriptor = {
793
684
  enumerable: true,
@@ -799,7 +690,7 @@
799
690
  if (setProp) {
800
691
  descriptor.set = setProp;
801
692
  }
802
- _objDefineProperty(target, prop, descriptor);
693
+ _objDefineProperty$1(target, prop, descriptor);
803
694
  return true;
804
695
  }
805
696
  catch (e) {
@@ -820,7 +711,7 @@
820
711
  if (isError(object)) {
821
712
  return object.name;
822
713
  }
823
- return "";
714
+ return strEmpty;
824
715
  }
825
716
  function setValue(target, field, value, valChk, srcChk) {
826
717
  var theValue = value;
@@ -937,6 +828,17 @@
937
828
  return class_1;
938
829
  }());
939
830
  }
831
+ function createEnumStyle(values) {
832
+ var enumClass = {};
833
+ objForEachKey(values, function (field, value) {
834
+ enumClass[field] = value;
835
+ if (!isUndefined(enumClass[value])) {
836
+ throwError("[" + value + "] exists for " + field);
837
+ }
838
+ enumClass[value] = field;
839
+ });
840
+ return objFreeze(enumClass);
841
+ }
940
842
  function optimizeObject(theObject) {
941
843
  if (theObject && ObjAssign) {
942
844
  theObject = ObjClass(ObjAssign({}, theObject));
@@ -1129,7 +1031,7 @@
1129
1031
  var nav = getNavigator();
1130
1032
  if (nav && (nav.userAgent !== _navUserAgentCheck || _isTrident === null)) {
1131
1033
  _navUserAgentCheck = nav.userAgent;
1132
- var userAgent = (_navUserAgentCheck || "").toLowerCase();
1034
+ var userAgent = (_navUserAgentCheck || strEmpty).toLowerCase();
1133
1035
  _isTrident = (strContains(userAgent, strMsie) || strContains(userAgent, strTrident));
1134
1036
  }
1135
1037
  return _isTrident;
@@ -1138,9 +1040,9 @@
1138
1040
  if (userAgentStr === void 0) { userAgentStr = null; }
1139
1041
  if (!userAgentStr) {
1140
1042
  var navigator_1 = getNavigator() || {};
1141
- userAgentStr = navigator_1 ? (navigator_1.userAgent || "").toLowerCase() : "";
1043
+ userAgentStr = navigator_1 ? (navigator_1.userAgent || strEmpty).toLowerCase() : strEmpty;
1142
1044
  }
1143
- var ua = (userAgentStr || "").toLowerCase();
1045
+ var ua = (userAgentStr || strEmpty).toLowerCase();
1144
1046
  if (strContains(ua, strMsie)) {
1145
1047
  var doc = getDocument() || {};
1146
1048
  return Math.max(parseInt(ua.split(strMsie)[1]), (doc[strDocumentMode] || 0));
@@ -1155,7 +1057,7 @@
1155
1057
  }
1156
1058
  function dumpObj(object) {
1157
1059
  var objectTypeDump = Object[strShimPrototype].toString.call(object);
1158
- var propertyValueDump = "";
1060
+ var propertyValueDump = strEmpty;
1159
1061
  if (objectTypeDump === "[object Error]") {
1160
1062
  propertyValueDump = "{ stack: '" + object.stack + "', message: '" + object.message + "', name: '" + object.name + "'";
1161
1063
  }
@@ -1167,9 +1069,9 @@
1167
1069
  function isSafari(userAgentStr) {
1168
1070
  if (!userAgentStr || !isString(userAgentStr)) {
1169
1071
  var navigator_2 = getNavigator() || {};
1170
- userAgentStr = navigator_2 ? (navigator_2.userAgent || "").toLowerCase() : "";
1072
+ userAgentStr = navigator_2 ? (navigator_2.userAgent || strEmpty).toLowerCase() : strEmpty;
1171
1073
  }
1172
- var ua = (userAgentStr || "").toLowerCase();
1074
+ var ua = (userAgentStr || strEmpty).toLowerCase();
1173
1075
  return (ua.indexOf("safari") >= 0);
1174
1076
  }
1175
1077
  function isBeaconsSupported() {
@@ -1257,9 +1159,9 @@
1257
1159
  var strWarnToConsole = "warnToConsole";
1258
1160
  function _sanitizeDiagnosticText(text) {
1259
1161
  if (text) {
1260
- return "\"" + text.replace(/\"/g, "") + "\"";
1162
+ return "\"" + text.replace(/\"/g, strEmpty) + "\"";
1261
1163
  }
1262
- return "";
1164
+ return strEmpty;
1263
1165
  }
1264
1166
  function _logToConsole(func, message) {
1265
1167
  var theConsole = getConsole();
@@ -1281,12 +1183,12 @@
1281
1183
  _self.message =
1282
1184
  (isUserAct ? AiUserActionablePrefix : AiNonUserActionablePrefix) +
1283
1185
  msgId;
1284
- var strProps = "";
1186
+ var strProps = strEmpty;
1285
1187
  if (hasJSON()) {
1286
1188
  strProps = getJSON().stringify(properties);
1287
1189
  }
1288
- var diagnosticText = (msg ? " message:" + _sanitizeDiagnosticText(msg) : "") +
1289
- (properties ? " props:" + _sanitizeDiagnosticText(strProps) : "");
1190
+ var diagnosticText = (msg ? " message:" + _sanitizeDiagnosticText(msg) : strEmpty) +
1191
+ (properties ? " props:" + _sanitizeDiagnosticText(strProps) : strEmpty);
1290
1192
  _self.message += diagnosticText;
1291
1193
  }
1292
1194
  _InternalLogMessage.dataType = "MessageData";
@@ -1316,7 +1218,7 @@
1316
1218
  throw message;
1317
1219
  }
1318
1220
  else {
1319
- var logFunc = severity === exports.LoggingSeverity.CRITICAL ? strErrorToConsole : strWarnToConsole;
1221
+ var logFunc = severity === 1 ? strErrorToConsole : strWarnToConsole;
1320
1222
  if (!isUndefined(message.message)) {
1321
1223
  var logLevel = _self.consoleLoggingLevel();
1322
1224
  if (isUserAct) {
@@ -1334,7 +1236,7 @@
1334
1236
  _self.logInternalMessage(severity, message);
1335
1237
  }
1336
1238
  else {
1337
- _debugExtMsg("throw" + (severity === exports.LoggingSeverity.CRITICAL ? "Critical" : "Warning"), message);
1239
+ _debugExtMsg("throw" + (severity === 1 ? "Critical" : "Warning"), message);
1338
1240
  }
1339
1241
  }
1340
1242
  };
@@ -1366,13 +1268,13 @@
1366
1268
  if (severity <= _self.telemetryLoggingLevel()) {
1367
1269
  _self.queue.push(message);
1368
1270
  _messageCount++;
1369
- _debugExtMsg((severity === exports.LoggingSeverity.CRITICAL ? "error" : "warn"), message);
1271
+ _debugExtMsg((severity === 1 ? "error" : "warn"), message);
1370
1272
  }
1371
1273
  if (_messageCount === _self.maxInternalMessageLimit()) {
1372
1274
  var throttleLimitMessage = "Internal events throttle limit per PageView reached for this app.";
1373
- var throttleMessage = new _InternalLogMessage(_InternalMessageId.MessageLimitPerPVExceeded, throttleLimitMessage, false);
1275
+ var throttleMessage = new _InternalLogMessage(23 , throttleLimitMessage, false);
1374
1276
  _self.queue.push(throttleMessage);
1375
- if (severity === exports.LoggingSeverity.CRITICAL) {
1277
+ if (severity === 1 ) {
1376
1278
  _self.errorToConsole(throttleLimitMessage);
1377
1279
  }
1378
1280
  else {
@@ -1549,6 +1451,217 @@
1549
1451
  return _defaultPerfManager;
1550
1452
  }
1551
1453
 
1454
+ var UInt32Mask = 0x100000000;
1455
+ var MaxUInt32 = 0xffffffff;
1456
+ var _mwcSeeded = false;
1457
+ var _mwcW = 123456789;
1458
+ var _mwcZ = 987654321;
1459
+ function _mwcSeed(seedValue) {
1460
+ if (seedValue < 0) {
1461
+ seedValue >>>= 0;
1462
+ }
1463
+ _mwcW = (123456789 + seedValue) & MaxUInt32;
1464
+ _mwcZ = (987654321 - seedValue) & MaxUInt32;
1465
+ _mwcSeeded = true;
1466
+ }
1467
+ function _autoSeedMwc() {
1468
+ try {
1469
+ var now = dateNow() & 0x7fffffff;
1470
+ _mwcSeed(((Math.random() * UInt32Mask) ^ now) + now);
1471
+ }
1472
+ catch (e) {
1473
+ }
1474
+ }
1475
+ function randomValue(maxValue) {
1476
+ if (maxValue > 0) {
1477
+ return Math.floor((random32() / MaxUInt32) * (maxValue + 1)) >>> 0;
1478
+ }
1479
+ return 0;
1480
+ }
1481
+ function random32(signed) {
1482
+ var value = 0;
1483
+ var c = getCrypto() || getMsCrypto();
1484
+ if (c && c.getRandomValues) {
1485
+ value = c.getRandomValues(new Uint32Array(1))[0] & MaxUInt32;
1486
+ }
1487
+ if (value === 0 && isIE()) {
1488
+ if (!_mwcSeeded) {
1489
+ _autoSeedMwc();
1490
+ }
1491
+ value = mwcRandom32() & MaxUInt32;
1492
+ }
1493
+ if (value === 0) {
1494
+ value = Math.floor((UInt32Mask * Math.random()) | 0);
1495
+ }
1496
+ if (!signed) {
1497
+ value >>>= 0;
1498
+ }
1499
+ return value;
1500
+ }
1501
+ function mwcRandomSeed(value) {
1502
+ if (!value) {
1503
+ _autoSeedMwc();
1504
+ }
1505
+ else {
1506
+ _mwcSeed(value);
1507
+ }
1508
+ }
1509
+ function mwcRandom32(signed) {
1510
+ _mwcZ = (36969 * (_mwcZ & 0xFFFF) + (_mwcZ >> 16)) & MaxUInt32;
1511
+ _mwcW = (18000 * (_mwcW & 0xFFFF) + (_mwcW >> 16)) & MaxUInt32;
1512
+ var value = (((_mwcZ << 16) + (_mwcW & 0xFFFF)) >>> 0) & MaxUInt32 | 0;
1513
+ if (!signed) {
1514
+ value >>>= 0;
1515
+ }
1516
+ return value;
1517
+ }
1518
+ function newId(maxLength) {
1519
+ if (maxLength === void 0) { maxLength = 22; }
1520
+ var base64chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
1521
+ var number = random32() >>> 0;
1522
+ var chars = 0;
1523
+ var result = strEmpty;
1524
+ while (result.length < maxLength) {
1525
+ chars++;
1526
+ result += base64chars.charAt(number & 0x3F);
1527
+ number >>>= 6;
1528
+ if (chars === 5) {
1529
+ number = (((random32() << 2) & 0xFFFFFFFF) | (number & 0x03)) >>> 0;
1530
+ chars = 0;
1531
+ }
1532
+ }
1533
+ return result;
1534
+ }
1535
+
1536
+ var _objDefineProperty = ObjDefineProperty;
1537
+ var version = "2.7.3";
1538
+ var instanceName = "." + newId(6);
1539
+ var _dataUid = 0;
1540
+ function _createAccessor(target, prop, value) {
1541
+ if (_objDefineProperty) {
1542
+ try {
1543
+ _objDefineProperty(target, prop, {
1544
+ value: value,
1545
+ enumerable: false,
1546
+ configurable: true
1547
+ });
1548
+ return true;
1549
+ }
1550
+ catch (e) {
1551
+ }
1552
+ }
1553
+ return false;
1554
+ }
1555
+ function _canAcceptData(target) {
1556
+ return target.nodeType === 1 || target.nodeType === 9 || !(+target.nodeType);
1557
+ }
1558
+ function _getCache(data, target) {
1559
+ var theCache = target[data.id];
1560
+ if (!theCache) {
1561
+ theCache = {};
1562
+ try {
1563
+ if (_canAcceptData(target)) {
1564
+ if (!_createAccessor(target, data.id, theCache)) {
1565
+ target[data.id] = theCache;
1566
+ }
1567
+ }
1568
+ }
1569
+ catch (e) {
1570
+ }
1571
+ }
1572
+ return theCache;
1573
+ }
1574
+ function createUniqueNamespace(name, includeVersion) {
1575
+ if (includeVersion === void 0) { includeVersion = false; }
1576
+ return normalizeJsName(name + (_dataUid++) + (includeVersion ? "." + version : "") + instanceName);
1577
+ }
1578
+ function createElmNodeData(name) {
1579
+ var data = {
1580
+ id: createUniqueNamespace("_aiData-" + (name || "") + "." + version),
1581
+ accept: function (target) {
1582
+ return _canAcceptData(target);
1583
+ },
1584
+ get: function (target, name, defValue, addDefault) {
1585
+ var theCache = target[data.id];
1586
+ if (!theCache) {
1587
+ if (addDefault) {
1588
+ theCache = _getCache(data, target);
1589
+ theCache[normalizeJsName(name)] = defValue;
1590
+ }
1591
+ return defValue;
1592
+ }
1593
+ return theCache[normalizeJsName(name)];
1594
+ },
1595
+ kill: function (target, name) {
1596
+ if (target && target[name]) {
1597
+ try {
1598
+ delete target[name];
1599
+ }
1600
+ catch (e) {
1601
+ }
1602
+ }
1603
+ }
1604
+ };
1605
+ return data;
1606
+ }
1607
+
1608
+ var pluginStateData = createElmNodeData("plugin");
1609
+ function _getPluginState(plugin) {
1610
+ return pluginStateData.get(plugin, "state", {}, true);
1611
+ }
1612
+ function initializePlugins(processContext, extensions) {
1613
+ var initPlugins = [];
1614
+ var lastPlugin = null;
1615
+ var proxy = processContext.getNext();
1616
+ var pluginState;
1617
+ while (proxy) {
1618
+ var thePlugin = proxy.getPlugin();
1619
+ if (thePlugin) {
1620
+ if (lastPlugin &&
1621
+ isFunction(lastPlugin[strSetNextPlugin]) &&
1622
+ isFunction(thePlugin[strProcessTelemetry])) {
1623
+ lastPlugin[strSetNextPlugin](thePlugin);
1624
+ }
1625
+ var isInitialized = false;
1626
+ if (isFunction(thePlugin[strIsInitialized])) {
1627
+ isInitialized = thePlugin[strIsInitialized]();
1628
+ }
1629
+ else {
1630
+ pluginState = _getPluginState(thePlugin);
1631
+ isInitialized = pluginState[strIsInitialized];
1632
+ }
1633
+ if (!isInitialized) {
1634
+ initPlugins.push(thePlugin);
1635
+ }
1636
+ lastPlugin = thePlugin;
1637
+ proxy = proxy.getNext();
1638
+ }
1639
+ }
1640
+ arrForEach(initPlugins, function (thePlugin) {
1641
+ var core = processContext.core();
1642
+ thePlugin.initialize(processContext.getCfg(), core, extensions, processContext.getNext());
1643
+ pluginState = _getPluginState(thePlugin);
1644
+ if (!thePlugin[strCore] && !pluginState[strCore]) {
1645
+ pluginState[strCore] = core;
1646
+ }
1647
+ pluginState[strIsInitialized] = true;
1648
+ delete pluginState[strTeardown];
1649
+ });
1650
+ }
1651
+ function sortPlugins(plugins) {
1652
+ return plugins.sort(function (extA, extB) {
1653
+ var result = 0;
1654
+ var bHasProcess = isFunction(extB[strProcessTelemetry]);
1655
+ if (isFunction(extA[strProcessTelemetry])) {
1656
+ result = bHasProcess ? extA[strPriority] - extB[strPriority] : 1;
1657
+ }
1658
+ else if (bHasProcess) {
1659
+ result = -1;
1660
+ }
1661
+ return result;
1662
+ });
1663
+ }
1664
+
1552
1665
  var strTelemetryPluginChain = "TelemetryPluginChain";
1553
1666
  var strHasRunFlags = "_hasRun";
1554
1667
  var strGetTelCtx = "_getTelCtx";
@@ -1562,53 +1675,69 @@
1562
1675
  }
1563
1676
  return createTelemetryProxyChain([startAt], config, core);
1564
1677
  }
1565
- function createProcessTelemetryContext(telemetryChain, config, core, startAt) {
1678
+ function _createInternalContext(telemetryChain, config, core, startAt) {
1566
1679
  var _nextProxy = null;
1567
- var _onComplete = null;
1568
- if (startAt) {
1569
- _nextProxy = _getNextProxyStart(telemetryChain, config, core, startAt);
1570
- }
1571
- else {
1572
- _nextProxy = telemetryChain;
1680
+ var _onComplete = [];
1681
+ if (startAt !== null) {
1682
+ _nextProxy = startAt ? _getNextProxyStart(telemetryChain, config, core, startAt) : telemetryChain;
1573
1683
  }
1574
1684
  var context = {
1575
- core: function () {
1576
- return core;
1577
- },
1578
- diagLog: function () {
1579
- return safeGetLogger(core, config);
1580
- },
1581
- getCfg: function () {
1582
- return config;
1583
- },
1584
- getExtCfg: _getExtCfg,
1585
- getConfig: _getConfig,
1586
- hasNext: function () {
1587
- return _nextProxy != null;
1588
- },
1589
- getNext: function () {
1590
- return _nextProxy;
1591
- },
1592
- setNext: function (nextPlugin) {
1593
- _nextProxy = nextPlugin;
1594
- },
1595
- processNext: function (env) {
1596
- _processChain(function (nextPlugin) {
1597
- nextPlugin.processTelemetry(env, context);
1685
+ _next: _moveNext,
1686
+ ctx: {
1687
+ core: function () { return core; },
1688
+ diagLog: function () {
1689
+ return safeGetLogger(core, config);
1690
+ },
1691
+ getCfg: function () {
1692
+ return config;
1693
+ },
1694
+ getExtCfg: _getExtCfg,
1695
+ getConfig: _getConfig,
1696
+ hasNext: function () {
1697
+ return !!_nextProxy;
1698
+ },
1699
+ getNext: function () {
1700
+ return _nextProxy;
1701
+ },
1702
+ setNext: function (nextPlugin) {
1703
+ _nextProxy = nextPlugin;
1704
+ },
1705
+ iterate: _iterateChain,
1706
+ onComplete: _addOnComplete
1707
+ }
1708
+ };
1709
+ function _addOnComplete(onComplete, that) {
1710
+ var args = [];
1711
+ for (var _i = 2; _i < arguments.length; _i++) {
1712
+ args[_i - 2] = arguments[_i];
1713
+ }
1714
+ if (onComplete) {
1715
+ _onComplete.push({
1716
+ func: onComplete,
1717
+ self: !isUndefined(that) ? that : context.ctx,
1718
+ args: args
1598
1719
  });
1599
- },
1600
- iterate: _iterateChain,
1601
- createNew: function (plugins, startAt) {
1602
- if (plugins === void 0) { plugins = null; }
1603
- if (isArray(plugins)) {
1604
- plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1720
+ }
1721
+ }
1722
+ function _moveNext() {
1723
+ var nextProxy = _nextProxy;
1724
+ _nextProxy = nextProxy ? nextProxy.getNext() : null;
1725
+ if (!nextProxy) {
1726
+ var onComplete = _onComplete;
1727
+ if (onComplete && onComplete.length > 0) {
1728
+ arrForEach(onComplete, function (completeDetails) {
1729
+ try {
1730
+ completeDetails.func.call(completeDetails.self, completeDetails.args);
1731
+ }
1732
+ catch (e) {
1733
+ core.logger.throwInternal(2 , 73 , "Unexpected Exception during onComplete - " + dumpObj(e));
1734
+ }
1735
+ });
1736
+ _onComplete = [];
1605
1737
  }
1606
- return createProcessTelemetryContext(plugins || _nextProxy, config, core, startAt);
1607
- },
1608
- onComplete: function (onComplete) {
1609
- _onComplete = onComplete;
1610
1738
  }
1611
- };
1739
+ return nextProxy;
1740
+ }
1612
1741
  function _getExtCfg(identifier, defaultValue, mergeDefault) {
1613
1742
  if (defaultValue === void 0) { defaultValue = {}; }
1614
1743
  if (mergeDefault === void 0) { mergeDefault = 0 ; }
@@ -1651,29 +1780,53 @@
1651
1780
  }
1652
1781
  return !isNullOrUndefined(theValue) ? theValue : defaultValue;
1653
1782
  }
1654
- function _processChain(cb) {
1655
- var nextPlugin = _nextProxy;
1656
- if (nextPlugin) {
1657
- _nextProxy = nextPlugin.getNext();
1658
- cb(nextPlugin);
1659
- }
1660
- else {
1661
- if (_onComplete) {
1662
- _onComplete();
1663
- _onComplete = null;
1783
+ function _iterateChain(cb) {
1784
+ var nextPlugin;
1785
+ while (!!(nextPlugin = context._next())) {
1786
+ var plugin = nextPlugin.getPlugin();
1787
+ if (plugin) {
1788
+ cb(plugin);
1664
1789
  }
1665
1790
  }
1666
1791
  }
1667
- function _iterateChain(cb) {
1668
- while (_nextProxy) {
1669
- _processChain(function (nextPlugin) {
1670
- var plugin = nextPlugin.getPlugin();
1671
- if (plugin) {
1672
- cb(plugin);
1673
- }
1674
- });
1792
+ return context;
1793
+ }
1794
+ function createProcessTelemetryContext(telemetryChain, config, core, startAt) {
1795
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1796
+ var context = internalContext.ctx;
1797
+ function _processNext(env) {
1798
+ var nextPlugin = internalContext._next();
1799
+ nextPlugin && nextPlugin.processTelemetry(env, context);
1800
+ return !nextPlugin;
1801
+ }
1802
+ function _createNew(plugins, startAt) {
1803
+ if (plugins === void 0) { plugins = null; }
1804
+ if (isArray(plugins)) {
1805
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1806
+ }
1807
+ return createProcessTelemetryContext(plugins || context.getNext(), config, core, startAt);
1808
+ }
1809
+ context.processNext = _processNext;
1810
+ context.createNew = _createNew;
1811
+ return context;
1812
+ }
1813
+ function createProcessTelemetryUnloadContext(telemetryChain, config, core, startAt) {
1814
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1815
+ var context = internalContext.ctx;
1816
+ function _processNext(unloadState) {
1817
+ var nextPlugin = internalContext._next();
1818
+ nextPlugin && nextPlugin.unload(context, unloadState);
1819
+ return !nextPlugin;
1820
+ }
1821
+ function _createNew(plugins, startAt) {
1822
+ if (plugins === void 0) { plugins = null; }
1823
+ if (isArray(plugins)) {
1824
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1675
1825
  }
1826
+ return createProcessTelemetryUnloadContext(plugins || context.getNext(), config, core, startAt);
1676
1827
  }
1828
+ context.processNext = _processNext;
1829
+ context.createNew = _createNew;
1677
1830
  return context;
1678
1831
  }
1679
1832
  function createTelemetryProxyChain(plugins, config, core, startAt) {
@@ -1721,32 +1874,35 @@
1721
1874
  return nextProxy;
1722
1875
  },
1723
1876
  processTelemetry: _processTelemetry,
1877
+ unload: _unloadPlugin,
1724
1878
  _id: chainId,
1725
1879
  _setNext: function (nextPlugin) {
1726
1880
  nextProxy = nextPlugin;
1727
1881
  }
1728
1882
  };
1729
- function _processChain(itemCtx, processPluginFn, processProxyFn, name, details, isAsync) {
1883
+ function _getTelCtx() {
1884
+ var itemCtx;
1885
+ if (plugin && isFunction(plugin[strGetTelCtx])) {
1886
+ itemCtx = plugin[strGetTelCtx]();
1887
+ }
1730
1888
  if (!itemCtx) {
1731
- if (plugin && isFunction(plugin[strGetTelCtx])) {
1732
- itemCtx = plugin[strGetTelCtx]();
1733
- }
1734
- if (!itemCtx) {
1735
- itemCtx = createProcessTelemetryContext(proxyChain, config, core);
1736
- }
1889
+ itemCtx = createProcessTelemetryContext(proxyChain, config, core);
1737
1890
  }
1891
+ return itemCtx;
1892
+ }
1893
+ function _processChain(itemCtx, processPluginFn, name, details, isAsync) {
1894
+ var hasRun = false;
1738
1895
  var identifier = plugin ? plugin.identifier : strTelemetryPluginChain;
1739
1896
  var hasRunContext = itemCtx[strHasRunFlags];
1740
1897
  if (!hasRunContext) {
1741
1898
  hasRunContext = itemCtx[strHasRunFlags] = {};
1742
1899
  }
1743
- doPerf(itemCtx.core(), function () { return identifier + ":" + name; }, function () {
1744
- hasRunContext[chainId] = true;
1745
- var hasRun = false;
1746
- itemCtx.setNext(nextProxy);
1747
- if (plugin) {
1900
+ itemCtx.setNext(nextProxy);
1901
+ if (plugin) {
1902
+ doPerf(itemCtx[strCore](), function () { return identifier + ":" + name; }, function () {
1903
+ hasRunContext[chainId] = true;
1748
1904
  try {
1749
- var nextId = nextProxy ? nextProxy._id : "";
1905
+ var nextId = nextProxy ? nextProxy._id : strEmpty;
1750
1906
  if (nextId) {
1751
1907
  hasRunContext[nextId] = false;
1752
1908
  }
@@ -1758,18 +1914,21 @@
1758
1914
  hasRun = true;
1759
1915
  }
1760
1916
  if (!nextProxy || !hasNextRun) {
1761
- itemCtx.diagLog().throwInternal(exports.LoggingSeverity.CRITICAL, _InternalMessageId.PluginException, "Plugin [" + plugin.identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
1917
+ itemCtx.diagLog().throwInternal(1 , 73 , "Plugin [" + plugin.identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
1762
1918
  }
1763
1919
  }
1764
- }
1765
- if (nextProxy && !hasRun) {
1766
- processProxyFn(itemCtx);
1767
- }
1768
- }, details, isAsync);
1920
+ }, details, isAsync);
1921
+ }
1922
+ return hasRun;
1769
1923
  }
1770
1924
  function _processTelemetry(env, itemCtx) {
1771
- _processChain(itemCtx, function (itemCtx) {
1772
- if (!hasProcessTelemetry) {
1925
+ itemCtx = itemCtx || _getTelCtx();
1926
+ function _callProcessTelemetry(itemCtx) {
1927
+ if (!plugin || !hasProcessTelemetry) {
1928
+ return false;
1929
+ }
1930
+ var pluginState = _getPluginState(plugin);
1931
+ if (pluginState[strTeardown] || pluginState[strDisabled]) {
1773
1932
  return false;
1774
1933
  }
1775
1934
  if (hasSetNext) {
@@ -1777,9 +1936,31 @@
1777
1936
  }
1778
1937
  plugin.processTelemetry(env, itemCtx);
1779
1938
  return true;
1780
- }, function (itemCtx) {
1781
- nextProxy.processTelemetry(env, itemCtx);
1782
- }, "processTelemetry", function () { return ({ item: env }); }, !(env.sync));
1939
+ }
1940
+ if (!_processChain(itemCtx, _callProcessTelemetry, "processTelemetry", function () { return ({ item: env }); }, !(env.sync))) {
1941
+ itemCtx.processNext(env);
1942
+ }
1943
+ }
1944
+ function _unloadPlugin(unloadCtx, unloadState) {
1945
+ function _callTeardown() {
1946
+ var hasRun = false;
1947
+ if (plugin) {
1948
+ var pluginState = _getPluginState(plugin);
1949
+ var pluginCore = plugin[strCore] || pluginState.core;
1950
+ if (plugin && (!pluginCore || pluginCore === unloadCtx[strCore]()) && !pluginState[strTeardown]) {
1951
+ pluginState[strCore] = null;
1952
+ pluginState[strTeardown] = true;
1953
+ pluginState[strIsInitialized] = false;
1954
+ if (plugin[strTeardown] && plugin[strTeardown](unloadCtx, unloadState) === true) {
1955
+ hasRun = true;
1956
+ }
1957
+ }
1958
+ }
1959
+ return hasRun;
1960
+ }
1961
+ if (!_processChain(unloadCtx, _callTeardown, "unload", function () { }, unloadState.isAsync)) {
1962
+ unloadCtx.processNext(unloadState);
1963
+ }
1783
1964
  }
1784
1965
  return objFreeze(proxyChain);
1785
1966
  }
@@ -1792,47 +1973,6 @@
1792
1973
  return ProcessTelemetryContext;
1793
1974
  }());
1794
1975
 
1795
- var processTelemetry = "processTelemetry";
1796
- var priority = "priority";
1797
- var setNextPlugin = "setNextPlugin";
1798
- var isInitialized = "isInitialized";
1799
- function initializePlugins(processContext, extensions) {
1800
- var initPlugins = [];
1801
- var lastPlugin = null;
1802
- var proxy = processContext.getNext();
1803
- while (proxy) {
1804
- var thePlugin = proxy.getPlugin();
1805
- if (thePlugin) {
1806
- if (lastPlugin &&
1807
- isFunction(lastPlugin[setNextPlugin]) &&
1808
- isFunction(thePlugin[processTelemetry])) {
1809
- lastPlugin[setNextPlugin](thePlugin);
1810
- }
1811
- if (!isFunction(thePlugin[isInitialized]) || !thePlugin[isInitialized]()) {
1812
- initPlugins.push(thePlugin);
1813
- }
1814
- lastPlugin = thePlugin;
1815
- proxy = proxy.getNext();
1816
- }
1817
- }
1818
- arrForEach(initPlugins, function (thePlugin) {
1819
- thePlugin.initialize(processContext.getCfg(), processContext.core(), extensions, processContext.getNext());
1820
- });
1821
- }
1822
- function sortPlugins(plugins) {
1823
- return plugins.sort(function (extA, extB) {
1824
- var result = 0;
1825
- var bHasProcess = isFunction(extB[processTelemetry]);
1826
- if (isFunction(extA[processTelemetry])) {
1827
- result = bHasProcess ? extA[priority] - extB[priority] : 1;
1828
- }
1829
- else if (bHasProcess) {
1830
- result = -1;
1831
- }
1832
- return result;
1833
- });
1834
- }
1835
-
1836
1976
  var strToGMTString = "toGMTString";
1837
1977
  var strToUTCString = "toUTCString";
1838
1978
  var strCookie = "cookie";
@@ -1841,7 +1981,6 @@
1841
1981
  var strIsCookieUseDisabled = "isCookieUseDisabled";
1842
1982
  var strDisableCookiesUsage = "disableCookiesUsage";
1843
1983
  var strConfigCookieMgr = "_ckMgr";
1844
- var strEmpty = "";
1845
1984
  var _supportsCookies = null;
1846
1985
  var _allowUaSameSite = null;
1847
1986
  var _parsedCookieValue = null;
@@ -2000,7 +2139,7 @@
2000
2139
  _supportsCookies = doc[strCookie] !== undefined;
2001
2140
  }
2002
2141
  catch (e) {
2003
- logger && logger.throwInternal(exports.LoggingSeverity.WARNING, _InternalMessageId.CannotAccessCookie, "Cannot access document.cookie - " + getExceptionName(e), { exception: dumpObj(e) });
2142
+ logger && logger.throwInternal(2 , 68 , "Cannot access document.cookie - " + getExceptionName(e), { exception: dumpObj(e) });
2004
2143
  }
2005
2144
  }
2006
2145
  return _supportsCookies;
@@ -2101,87 +2240,110 @@
2101
2240
  }
2102
2241
  }
2103
2242
  function createChannelControllerPlugin(channelQueue, core) {
2104
- function _getTelCtx(itemCtx) {
2105
- if (!itemCtx) {
2106
- itemCtx = createProcessTelemetryContext(null, core.config, core, null);
2243
+ var _a;
2244
+ function _getTelCtx() {
2245
+ return createProcessTelemetryContext(null, core.config, core, null);
2246
+ }
2247
+ function _processChannelQueue(theChannels, itemCtx, processFn, onComplete) {
2248
+ var waiting = theChannels ? (theChannels.length + 1) : 1;
2249
+ function _runChainOnComplete() {
2250
+ waiting--;
2251
+ if (waiting === 0) {
2252
+ onComplete && onComplete();
2253
+ onComplete = null;
2254
+ }
2107
2255
  }
2108
- return itemCtx;
2109
- }
2110
- function _processChannelQueue(itemCtx, processFn, onComplete) {
2111
- if (channelQueue && channelQueue.length > 0) {
2112
- var waiting_1 = channelQueue.length;
2113
- arrForEach(channelQueue, function (channels) {
2256
+ if (waiting > 0) {
2257
+ arrForEach(theChannels, function (channels) {
2114
2258
  if (channels && channels.queue.length > 0) {
2115
2259
  var channelChain = channels.chain;
2116
- var chainCtx = _getTelCtx(itemCtx).createNew(channelChain);
2117
- chainCtx.onComplete(function () {
2118
- waiting_1--;
2119
- if (waiting_1 === 0) {
2120
- onComplete && onComplete();
2121
- onComplete = null;
2122
- }
2123
- });
2260
+ var chainCtx = itemCtx.createNew(channelChain);
2261
+ chainCtx.onComplete(_runChainOnComplete);
2124
2262
  processFn(chainCtx);
2125
2263
  }
2126
2264
  else {
2127
- waiting_1--;
2265
+ waiting--;
2128
2266
  }
2129
2267
  });
2130
- if (waiting_1 === 0) {
2131
- onComplete && onComplete();
2132
- }
2133
- }
2134
- else {
2135
- onComplete && onComplete();
2136
2268
  }
2269
+ _runChainOnComplete();
2137
2270
  }
2138
- var isInitialized = false;
2139
- var channelController = {
2140
- identifier: "ChannelControllerPlugin",
2141
- priority: ChannelControllerPriority,
2142
- initialize: function (config, core, extensions, pluginChain) {
2143
- isInitialized = true;
2271
+ function _doTeardown(unloadCtx, unloadState) {
2272
+ var theUnloadState = unloadState || {
2273
+ reason: 0 ,
2274
+ isAsync: false
2275
+ };
2276
+ _processChannelQueue(channelQueue, unloadCtx, function (chainCtx) {
2277
+ chainCtx[strProcessNext](theUnloadState);
2278
+ }, function () {
2279
+ unloadCtx[strProcessNext](theUnloadState);
2280
+ isInitialized = false;
2281
+ });
2282
+ return true;
2283
+ }
2284
+ function _getChannel(pluginIdentifier) {
2285
+ var thePlugin = null;
2286
+ if (channelQueue && channelQueue.length > 0) {
2144
2287
  arrForEach(channelQueue, function (channels) {
2145
2288
  if (channels && channels.queue.length > 0) {
2146
- initializePlugins(createProcessTelemetryContext(channels.chain, config, core), extensions);
2289
+ arrForEach(channels.queue, function (ext) {
2290
+ if (ext.identifier === pluginIdentifier) {
2291
+ thePlugin = ext;
2292
+ return -1;
2293
+ }
2294
+ });
2295
+ if (thePlugin) {
2296
+ return -1;
2297
+ }
2147
2298
  }
2148
2299
  });
2149
- },
2150
- isInitialized: function () { return isInitialized; },
2151
- processTelemetry: function (item, itemCtx) {
2152
- _processChannelQueue(itemCtx, function (chainCtx) {
2153
- chainCtx.processNext(item);
2154
- }, function () {
2155
- itemCtx.processNext(item);
2156
- });
2157
- },
2158
- pause: function () {
2159
- _processChannelQueue(null, function (chainCtx) {
2160
- chainCtx.iterate(function (plugin) {
2161
- plugin.pause && plugin.pause();
2300
+ }
2301
+ return thePlugin;
2302
+ }
2303
+ var isInitialized = false;
2304
+ var channelController = (_a = {
2305
+ identifier: "ChannelControllerPlugin",
2306
+ priority: ChannelControllerPriority,
2307
+ initialize: function (config, core, extensions, pluginChain) {
2308
+ isInitialized = true;
2309
+ arrForEach(channelQueue, function (channels) {
2310
+ if (channels && channels.queue.length > 0) {
2311
+ initializePlugins(createProcessTelemetryContext(channels.chain, config, core), extensions);
2312
+ }
2162
2313
  });
2163
- });
2314
+ },
2315
+ isInitialized: function () { return isInitialized; },
2316
+ processTelemetry: function (item, itemCtx) {
2317
+ _processChannelQueue(channelQueue, itemCtx || _getTelCtx(), function (chainCtx) {
2318
+ chainCtx[strProcessNext](item);
2319
+ }, function () {
2320
+ itemCtx[strProcessNext](item);
2321
+ });
2322
+ }
2164
2323
  },
2165
- resume: function () {
2166
- _processChannelQueue(null, function (chainCtx) {
2324
+ _a[strPause] = function () {
2325
+ _processChannelQueue(channelQueue, _getTelCtx(), function (chainCtx) {
2167
2326
  chainCtx.iterate(function (plugin) {
2168
- plugin.resume && plugin.resume();
2327
+ plugin[strPause] && plugin[strPause]();
2169
2328
  });
2170
- });
2329
+ }, null);
2171
2330
  },
2172
- teardown: function () {
2173
- _processChannelQueue(null, function (chainCtx) {
2331
+ _a[strResume] = function () {
2332
+ _processChannelQueue(channelQueue, _getTelCtx(), function (chainCtx) {
2174
2333
  chainCtx.iterate(function (plugin) {
2175
- plugin.teardown && plugin.teardown();
2334
+ plugin[strResume] && plugin[strResume]();
2176
2335
  });
2177
- });
2336
+ }, null);
2178
2337
  },
2179
- flush: function (isAsync, callBack, sendReason, cbTimeout) {
2338
+ _a[strTeardown] = _doTeardown,
2339
+ _a.getChannel = _getChannel,
2340
+ _a.flush = function (isAsync, callBack, sendReason, cbTimeout) {
2341
+ var waiting = 1;
2180
2342
  var doneIterating = false;
2181
- var waiting = 0;
2182
2343
  var cbTimer = null;
2183
2344
  cbTimeout = cbTimeout || 5000;
2184
2345
  function doCallback() {
2346
+ waiting--;
2185
2347
  if (doneIterating && waiting === 0) {
2186
2348
  if (cbTimer) {
2187
2349
  clearTimeout(cbTimer);
@@ -2191,32 +2353,38 @@
2191
2353
  callBack = null;
2192
2354
  }
2193
2355
  }
2194
- waiting = 1;
2195
- _processChannelQueue(null, function (chainCtx) {
2356
+ _processChannelQueue(channelQueue, _getTelCtx(), function (chainCtx) {
2196
2357
  chainCtx.iterate(function (plugin) {
2197
2358
  if (plugin.flush) {
2198
2359
  waiting++;
2360
+ var handled_1 = false;
2199
2361
  if (!plugin.flush(isAsync, function () {
2200
- waiting--;
2362
+ handled_1 = true;
2201
2363
  doCallback();
2202
2364
  }, sendReason)) {
2203
- if (cbTimer == null) {
2204
- cbTimer = setTimeout(function () {
2205
- cbTimer = null;
2206
- callBack && callBack(false);
2207
- callBack = null;
2208
- }, cbTimeout);
2365
+ if (!handled_1) {
2366
+ if (isAsync && cbTimer == null) {
2367
+ cbTimer = setTimeout(function () {
2368
+ cbTimer = null;
2369
+ doCallback();
2370
+ }, cbTimeout);
2371
+ }
2372
+ else {
2373
+ doCallback();
2374
+ }
2209
2375
  }
2210
2376
  }
2211
2377
  }
2212
2378
  });
2213
2379
  }, function () {
2214
- waiting--;
2215
2380
  doneIterating = true;
2216
2381
  doCallback();
2217
2382
  });
2218
- }
2219
- };
2383
+ },
2384
+ _a._setQueue = function (queue) {
2385
+ channelQueue = queue;
2386
+ },
2387
+ _a);
2220
2388
  return channelController;
2221
2389
  }
2222
2390
  function createChannelQueues(channels, extensions, config, core) {
@@ -2236,6 +2404,30 @@
2236
2404
  return channelQueue;
2237
2405
  }
2238
2406
 
2407
+ function createUnloadHandlerContainer() {
2408
+ var handlers = [];
2409
+ function _addHandler(handler) {
2410
+ if (handler) {
2411
+ handlers.push(handler);
2412
+ }
2413
+ }
2414
+ function _runHandlers(unloadCtx, unloadState) {
2415
+ arrForEach(handlers, function (handler) {
2416
+ try {
2417
+ handler(unloadCtx, unloadState);
2418
+ }
2419
+ catch (e) {
2420
+ unloadCtx.diagLog().throwInternal(2 , 73 , "Unexpected error calling unload handler - " + dumpObj(e));
2421
+ }
2422
+ });
2423
+ handlers = [];
2424
+ }
2425
+ return {
2426
+ add: _addHandler,
2427
+ run: _runHandlers
2428
+ };
2429
+ }
2430
+
2239
2431
  var strGetPlugin = "getPlugin";
2240
2432
  var BaseTelemetryPlugin = /** @class */ (function () {
2241
2433
  function BaseTelemetryPlugin() {
@@ -2243,6 +2435,7 @@
2243
2435
  var _isinitialized;
2244
2436
  var _rootCtx;
2245
2437
  var _nextPlugin;
2438
+ var _unloadHandlerContainer;
2246
2439
  var _hooks;
2247
2440
  _initDefaults();
2248
2441
  dynamicProto(BaseTelemetryPlugin, _self, function (_self) {
@@ -2250,6 +2443,39 @@
2250
2443
  _setDefaults(config, core, pluginChain);
2251
2444
  _isinitialized = true;
2252
2445
  };
2446
+ _self.teardown = function (unloadCtx, unloadState) {
2447
+ if (!_self.core || (unloadCtx && _self.core !== unloadCtx.core())) {
2448
+ return;
2449
+ }
2450
+ var result;
2451
+ var unloadDone = false;
2452
+ var theUnloadCtx = unloadCtx || createProcessTelemetryUnloadContext(null, {}, _self.core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
2453
+ var theUnloadState = unloadState || {
2454
+ reason: 0 ,
2455
+ isAsync: false
2456
+ };
2457
+ function _unloadCallback() {
2458
+ if (!unloadDone) {
2459
+ unloadDone = true;
2460
+ _unloadHandlerContainer.run(theUnloadCtx, unloadState);
2461
+ arrForEach(_hooks, function (fn) {
2462
+ fn.rm();
2463
+ });
2464
+ _hooks = [];
2465
+ if (result === true) {
2466
+ theUnloadCtx.processNext(theUnloadState);
2467
+ }
2468
+ _initDefaults();
2469
+ }
2470
+ }
2471
+ if (!_self[strDoTeardown] || _self[strDoTeardown](theUnloadCtx, theUnloadState, _unloadCallback) !== true) {
2472
+ _unloadCallback();
2473
+ }
2474
+ else {
2475
+ result = true;
2476
+ }
2477
+ return result;
2478
+ };
2253
2479
  _self._addHook = function (hooks) {
2254
2480
  if (hooks) {
2255
2481
  if (isArray(hooks)) {
@@ -2260,17 +2486,18 @@
2260
2486
  }
2261
2487
  }
2262
2488
  };
2489
+ proxyFunctionAs(_self, "_addUnloadCb", function () { return _unloadHandlerContainer; }, "add");
2263
2490
  });
2264
2491
  _self.diagLog = function (itemCtx) {
2265
2492
  return _getTelCtx(itemCtx).diagLog();
2266
2493
  };
2267
- _self.isInitialized = function () {
2494
+ _self[strIsInitialized] = function () {
2268
2495
  return _isinitialized;
2269
2496
  };
2270
2497
  _self.setInitialized = function (isInitialized) {
2271
2498
  _isinitialized = isInitialized;
2272
2499
  };
2273
- _self.setNextPlugin = function (next) {
2500
+ _self[strSetNextPlugin] = function (next) {
2274
2501
  _nextPlugin = next;
2275
2502
  };
2276
2503
  _self.processNext = function (env, itemCtx) {
@@ -2316,6 +2543,7 @@
2316
2543
  _rootCtx = null;
2317
2544
  _nextPlugin = null;
2318
2545
  _hooks = [];
2546
+ _unloadHandlerContainer = createUnloadHandlerContainer();
2319
2547
  }
2320
2548
  }
2321
2549
  return BaseTelemetryPlugin;
@@ -2362,7 +2590,7 @@
2362
2590
  }
2363
2591
  }
2364
2592
  catch (e) {
2365
- itemCtx.diagLog().throwInternal(exports.LoggingSeverity.CRITICAL, _InternalMessageId.TelemetryInitializerFailed, "One of telemetry initializers failed, telemetry item will not be sent: " + getExceptionName(e), { exception: dumpObj(e) }, true);
2593
+ itemCtx.diagLog().throwInternal(1 , 64 , "One of telemetry initializers failed, telemetry item will not be sent: " + getExceptionName(e), { exception: dumpObj(e) }, true);
2366
2594
  }
2367
2595
  }
2368
2596
  }
@@ -2370,8 +2598,7 @@
2370
2598
  _self.processNext(item, itemCtx);
2371
2599
  }
2372
2600
  };
2373
- _self.unload = function (itemCtx, isAsync) {
2374
- _base.unload(itemCtx, isAsync);
2601
+ _self[strDoTeardown] = function () {
2375
2602
  _initDefaults();
2376
2603
  };
2377
2604
  });
@@ -2386,6 +2613,8 @@
2386
2613
 
2387
2614
  var strValidationError = "Plugins must provide initialize method";
2388
2615
  var strNotificationManager = "_notificationManager";
2616
+ var strSdkUnloadingError = "SDK is still unloading...";
2617
+ var strSdkNotInitialized = "SDK is not initialized";
2389
2618
  function _createPerfManager(core, notificationMgr) {
2390
2619
  return new PerfManager(notificationMgr);
2391
2620
  }
@@ -2415,6 +2644,26 @@
2415
2644
  core: coreExtensions
2416
2645
  };
2417
2646
  }
2647
+ function _isPluginPresent(thePlugin, plugins) {
2648
+ var exists = false;
2649
+ arrForEach(plugins, function (plugin) {
2650
+ if (plugin === thePlugin) {
2651
+ exists = true;
2652
+ return -1;
2653
+ }
2654
+ });
2655
+ return exists;
2656
+ }
2657
+ function _createDummyNotificationManager() {
2658
+ var _a;
2659
+ return objCreateFn((_a = {},
2660
+ _a[strAddNotificationListener] = function (listener) { },
2661
+ _a[strRemoveNotificationListener] = function (listener) { },
2662
+ _a[strEventsSent] = function (events) { },
2663
+ _a[strEventsDiscarded] = function (events, reason) { },
2664
+ _a[strEventsSendRequest] = function (sendReason, isAsync) { },
2665
+ _a));
2666
+ }
2418
2667
  var BaseCore = /** @class */ (function () {
2419
2668
  function BaseCore() {
2420
2669
  var _isInitialized;
@@ -2429,14 +2678,20 @@
2429
2678
  var _channelControl;
2430
2679
  var _channelConfig;
2431
2680
  var _channelQueue;
2681
+ var _isUnloading;
2432
2682
  var _telemetryInitializerPlugin;
2433
2683
  var _internalLogsEventName;
2684
+ var _evtNamespace;
2685
+ var _unloadHandlers;
2434
2686
  var _debugListener;
2435
2687
  var _internalLogPoller = 0;
2436
2688
  dynamicProto(BaseCore, this, function (_self) {
2437
2689
  _initDefaults();
2438
2690
  _self.isInitialized = function () { return _isInitialized; };
2439
2691
  _self.initialize = function (config, extensions, logger, notificationManager) {
2692
+ if (_isUnloading) {
2693
+ throwError(strSdkUnloadingError);
2694
+ }
2440
2695
  if (_self.isInitialized()) {
2441
2696
  throwError("Core should not be initialized more than once");
2442
2697
  }
@@ -2449,8 +2704,7 @@
2449
2704
  _initDebugListener(config);
2450
2705
  _initPerfManager(config);
2451
2706
  config.extensions = isNullOrUndefined(config.extensions) ? [] : config.extensions;
2452
- var extConfig = getSetValue(config, strExtensionConfig);
2453
- extConfig.NotificationManager = notificationManager;
2707
+ _initExtConfig(config);
2454
2708
  if (logger) {
2455
2709
  _self.logger = logger;
2456
2710
  }
@@ -2475,37 +2729,29 @@
2475
2729
  setValue(telemetryItem, strIKey, _self.config.instrumentationKey, null, isNotTruthy);
2476
2730
  setValue(telemetryItem, "time", toISOString(new Date()), null, isNotTruthy);
2477
2731
  setValue(telemetryItem, "ver", "4.0", null, isNullOrUndefined);
2478
- if (_self.isInitialized()) {
2479
- _self.getProcessTelContext().processNext(telemetryItem);
2732
+ if (!_isUnloading && _self.isInitialized()) {
2733
+ _createTelCtx().processNext(telemetryItem);
2480
2734
  }
2481
2735
  else {
2482
2736
  _eventQueue.push(telemetryItem);
2483
2737
  }
2484
2738
  };
2485
- _self.getProcessTelContext = function () {
2486
- return createProcessTelemetryContext(_getPluginChain(), _self.config, _self);
2487
- };
2739
+ _self.getProcessTelContext = _createTelCtx;
2488
2740
  _self.getNotifyMgr = function () {
2489
2741
  if (!_notificationManager) {
2490
- _notificationManager = objCreateFn({
2491
- addNotificationListener: function (listener) { },
2492
- removeNotificationListener: function (listener) { },
2493
- eventsSent: function (events) { },
2494
- eventsDiscarded: function (events, reason) { },
2495
- eventsSendRequest: function (sendReason, isAsync) { }
2496
- });
2742
+ _notificationManager = _createDummyNotificationManager();
2497
2743
  _self[strNotificationManager] = _notificationManager;
2498
2744
  }
2499
2745
  return _notificationManager;
2500
2746
  };
2501
- _self.addNotificationListener = function (listener) {
2747
+ _self[strAddNotificationListener] = function (listener) {
2502
2748
  if (_notificationManager) {
2503
- _notificationManager.addNotificationListener(listener);
2749
+ _notificationManager[strAddNotificationListener](listener);
2504
2750
  }
2505
2751
  };
2506
- _self.removeNotificationListener = function (listener) {
2752
+ _self[strRemoveNotificationListener] = function (listener) {
2507
2753
  if (_notificationManager) {
2508
- _notificationManager.removeNotificationListener(listener);
2754
+ _notificationManager[strRemoveNotificationListener](listener);
2509
2755
  }
2510
2756
  };
2511
2757
  _self.getCookieMgr = function () {
@@ -2536,7 +2782,7 @@
2536
2782
  var eventQueue = _eventQueue;
2537
2783
  _eventQueue = [];
2538
2784
  arrForEach(eventQueue, function (event) {
2539
- _self.getProcessTelContext().processNext(event);
2785
+ _createTelCtx().processNext(event);
2540
2786
  });
2541
2787
  }
2542
2788
  };
@@ -2562,10 +2808,83 @@
2562
2808
  }
2563
2809
  };
2564
2810
  proxyFunctions(_self, function () { return _telemetryInitializerPlugin; }, ["addTelemetryInitializer"]);
2811
+ _self.unload = function (isAsync, unloadComplete, cbTimeout) {
2812
+ if (isAsync === void 0) { isAsync = true; }
2813
+ if (!_isInitialized) {
2814
+ throwError(strSdkNotInitialized);
2815
+ }
2816
+ if (_isUnloading) {
2817
+ throwError(strSdkUnloadingError);
2818
+ }
2819
+ var unloadState = {
2820
+ reason: 50 ,
2821
+ isAsync: isAsync,
2822
+ flushComplete: false
2823
+ };
2824
+ var processUnloadCtx = createProcessTelemetryUnloadContext(_getPluginChain(), _self.config, _self);
2825
+ processUnloadCtx.onComplete(function () {
2826
+ _initDefaults();
2827
+ unloadComplete && unloadComplete(unloadState);
2828
+ }, _self);
2829
+ function _doUnload(flushComplete) {
2830
+ unloadState.flushComplete = flushComplete;
2831
+ _isUnloading = true;
2832
+ _unloadHandlers.run(processUnloadCtx, unloadState);
2833
+ _self.stopPollingInternalLogs();
2834
+ processUnloadCtx.processNext(unloadState);
2835
+ }
2836
+ if (_channelControl) {
2837
+ _channelControl.flush(isAsync, _doUnload, 6 , cbTimeout);
2838
+ }
2839
+ else {
2840
+ _doUnload(true);
2841
+ }
2842
+ };
2565
2843
  _self.getPlugin = _getPlugin;
2844
+ _self.addPlugin = function (plugin, replaceExisting, isAsync, addCb) {
2845
+ if (isAsync === void 0) { isAsync = true; }
2846
+ if (!plugin) {
2847
+ addCb && addCb(false);
2848
+ _logOrThrowError(strValidationError);
2849
+ return;
2850
+ }
2851
+ var existingPlugin = _getPlugin(plugin.identifier);
2852
+ if (existingPlugin && !replaceExisting) {
2853
+ addCb && addCb(false);
2854
+ _logOrThrowError("Plugin [" + plugin.identifier + "] is already loaded!");
2855
+ return;
2856
+ }
2857
+ function _addPlugin(removed) {
2858
+ _configExtensions.push(plugin);
2859
+ _initPluginChain(_self.config);
2860
+ addCb && addCb(true);
2861
+ }
2862
+ if (existingPlugin) {
2863
+ var removedPlugins = [existingPlugin.plugin];
2864
+ var unloadState = {
2865
+ reason: 2 ,
2866
+ isAsync: isAsync
2867
+ };
2868
+ _removePlugins(removedPlugins, unloadState, function (removed) {
2869
+ if (!removed) {
2870
+ addCb && addCb(false);
2871
+ }
2872
+ else {
2873
+ _addPlugin();
2874
+ }
2875
+ });
2876
+ }
2877
+ else {
2878
+ _addPlugin();
2879
+ }
2880
+ };
2881
+ _self.evtNamespace = function () {
2882
+ return _evtNamespace;
2883
+ };
2884
+ proxyFunctionAs(_self, "addUnloadCb", function () { return _unloadHandlers; }, "add");
2566
2885
  function _initDefaults() {
2567
2886
  _isInitialized = false;
2568
- _self.logger = new DiagnosticLogger({ loggingLevelConsole: exports.LoggingSeverity.CRITICAL });
2887
+ _self.logger = new DiagnosticLogger({ loggingLevelConsole: 1 });
2569
2888
  _self.config = null;
2570
2889
  _self._extensions = [];
2571
2890
  _telemetryInitializerPlugin = new TelemetryInitializerPlugin();
@@ -2580,7 +2899,13 @@
2580
2899
  _channelControl = null;
2581
2900
  _channelConfig = null;
2582
2901
  _channelQueue = null;
2902
+ _isUnloading = false;
2583
2903
  _internalLogsEventName = null;
2904
+ _evtNamespace = createUniqueNamespace("AIBaseCore", true);
2905
+ _unloadHandlers = createUnloadHandlerContainer();
2906
+ }
2907
+ function _createTelCtx() {
2908
+ return createProcessTelemetryContext(_getPluginChain(), _self.config, _self);
2584
2909
  }
2585
2910
  function _initPluginChain(config) {
2586
2911
  var theExtensions = _validateExtensions(_self.logger, ChannelControllerPriority, _configExtensions);
@@ -2588,26 +2913,63 @@
2588
2913
  _pluginChain = null;
2589
2914
  var allExtensions = theExtensions.all;
2590
2915
  _channelQueue = objFreeze(createChannelQueues(_channelConfig, allExtensions, config, _self));
2591
- _channelControl = createChannelControllerPlugin(_channelQueue, _self);
2916
+ if (_channelControl) {
2917
+ var idx = allExtensions.indexOf(_channelControl);
2918
+ if (idx !== -1) {
2919
+ allExtensions.splice(idx, 1);
2920
+ }
2921
+ idx = _coreExtensions.indexOf(_channelControl);
2922
+ if (idx !== -1) {
2923
+ _coreExtensions.splice(idx, 1);
2924
+ }
2925
+ _channelControl._setQueue(_channelQueue);
2926
+ }
2927
+ else {
2928
+ _channelControl = createChannelControllerPlugin(_channelQueue, _self);
2929
+ }
2592
2930
  allExtensions.push(_channelControl);
2593
2931
  _coreExtensions.push(_channelControl);
2594
2932
  _self._extensions = sortPlugins(allExtensions);
2595
2933
  _channelControl.initialize(config, _self, allExtensions);
2596
- initializePlugins(_self.getProcessTelContext(), allExtensions);
2934
+ initializePlugins(_createTelCtx(), allExtensions);
2597
2935
  _self._extensions = objFreeze(sortPlugins(_coreExtensions || [])).slice();
2598
2936
  }
2599
2937
  function _getPlugin(pluginIdentifier) {
2600
2938
  var theExt = null;
2601
2939
  var thePlugin = null;
2602
2940
  arrForEach(_self._extensions, function (ext) {
2603
- if (ext.identifier === pluginIdentifier) {
2941
+ if (ext.identifier === pluginIdentifier && ext !== _channelControl && ext !== _telemetryInitializerPlugin) {
2604
2942
  thePlugin = ext;
2605
2943
  return -1;
2606
2944
  }
2607
2945
  });
2946
+ if (!thePlugin && _channelControl) {
2947
+ thePlugin = _channelControl.getChannel(pluginIdentifier);
2948
+ }
2608
2949
  if (thePlugin) {
2609
2950
  theExt = {
2610
- plugin: thePlugin
2951
+ plugin: thePlugin,
2952
+ setEnabled: function (enabled) {
2953
+ _getPluginState(thePlugin)[strDisabled] = !enabled;
2954
+ },
2955
+ isEnabled: function () {
2956
+ var pluginState = _getPluginState(thePlugin);
2957
+ return !pluginState[strTeardown] && !pluginState[strDisabled];
2958
+ },
2959
+ remove: function (isAsync, removeCb) {
2960
+ if (isAsync === void 0) { isAsync = true; }
2961
+ var pluginsToRemove = [thePlugin];
2962
+ var unloadState = {
2963
+ reason: 1 ,
2964
+ isAsync: isAsync
2965
+ };
2966
+ _removePlugins(pluginsToRemove, unloadState, function (removed) {
2967
+ if (removed) {
2968
+ _initPluginChain(_self.config);
2969
+ }
2970
+ removeCb && removeCb(removed);
2971
+ });
2972
+ }
2611
2973
  };
2612
2974
  }
2613
2975
  return theExt;
@@ -2615,11 +2977,53 @@
2615
2977
  function _getPluginChain() {
2616
2978
  if (!_pluginChain) {
2617
2979
  var extensions = (_coreExtensions || []).slice();
2618
- extensions.push(_telemetryInitializerPlugin);
2980
+ if (extensions.indexOf(_telemetryInitializerPlugin) === -1) {
2981
+ extensions.push(_telemetryInitializerPlugin);
2982
+ }
2619
2983
  _pluginChain = createTelemetryProxyChain(sortPlugins(extensions), _self.config, _self);
2620
2984
  }
2621
2985
  return _pluginChain;
2622
2986
  }
2987
+ function _removePlugins(thePlugins, unloadState, removeComplete) {
2988
+ if (thePlugins && thePlugins.length > 0) {
2989
+ var unloadChain = createTelemetryProxyChain(thePlugins, _self.config, _self);
2990
+ var unloadCtx = createProcessTelemetryUnloadContext(unloadChain, _self.config, _self);
2991
+ unloadCtx.onComplete(function () {
2992
+ var removed = false;
2993
+ var newConfigExtensions = [];
2994
+ arrForEach(_configExtensions, function (plugin, idx) {
2995
+ if (!_isPluginPresent(plugin, thePlugins)) {
2996
+ newConfigExtensions.push(plugin);
2997
+ }
2998
+ else {
2999
+ removed = true;
3000
+ }
3001
+ });
3002
+ _configExtensions = newConfigExtensions;
3003
+ var newChannelConfig = [];
3004
+ if (_channelConfig) {
3005
+ arrForEach(_channelConfig, function (queue, idx) {
3006
+ var newQueue = [];
3007
+ arrForEach(queue, function (channel) {
3008
+ if (!_isPluginPresent(channel, thePlugins)) {
3009
+ newQueue.push(channel);
3010
+ }
3011
+ else {
3012
+ removed = true;
3013
+ }
3014
+ });
3015
+ newChannelConfig.push(newQueue);
3016
+ });
3017
+ _channelConfig = newChannelConfig;
3018
+ }
3019
+ removeComplete && removeComplete(removed);
3020
+ });
3021
+ unloadCtx.processNext(unloadState);
3022
+ }
3023
+ else {
3024
+ removeComplete(false);
3025
+ }
3026
+ }
2623
3027
  function _flushInternalLogs() {
2624
3028
  var queue = _self.logger ? _self.logger.queue : [];
2625
3029
  if (queue) {
@@ -2638,12 +3042,12 @@
2638
3042
  }
2639
3043
  function _initDebugListener(config) {
2640
3044
  if (config.disableDbgExt === true && _debugListener) {
2641
- _notificationManager.removeNotificationListener(_debugListener);
3045
+ _notificationManager[strRemoveNotificationListener](_debugListener);
2642
3046
  _debugListener = null;
2643
3047
  }
2644
3048
  if (_notificationManager && !_debugListener && config.disableDbgExt !== true) {
2645
3049
  _debugListener = getDebugListener(config);
2646
- _notificationManager.addNotificationListener(_debugListener);
3050
+ _notificationManager[strAddNotificationListener](_debugListener);
2647
3051
  }
2648
3052
  }
2649
3053
  function _initPerfManager(config) {
@@ -2654,15 +3058,24 @@
2654
3058
  setValue(_self.config, "createPerfMgr", _createPerfManager);
2655
3059
  }
2656
3060
  }
3061
+ function _initExtConfig(config) {
3062
+ var extConfig = getSetValue(config, strExtensionConfig);
3063
+ extConfig.NotificationManager = _notificationManager;
3064
+ }
3065
+ function _logOrThrowError(message) {
3066
+ var logger = _self.logger;
3067
+ if (logger) {
3068
+ logger.throwInternal(2 , 73 , message);
3069
+ }
3070
+ else {
3071
+ throwError(message);
3072
+ }
3073
+ }
2657
3074
  });
2658
3075
  }
2659
3076
  return BaseCore;
2660
3077
  }());
2661
3078
 
2662
- var strEventsSent = "eventsSent";
2663
- var strEventsDiscarded = "eventsDiscarded";
2664
- var strEventsSendRequest = "eventsSendRequest";
2665
- var strPerfEvent = "perfEvent";
2666
3079
  function _runListeners(listeners, name, isAsync, callback) {
2667
3080
  arrForEach(listeners, function (listener) {
2668
3081
  if (listener && listener[name]) {
@@ -2684,32 +3097,32 @@
2684
3097
  this.listeners = [];
2685
3098
  var perfEvtsSendAll = !!(config || {}).perfEvtsSendAll;
2686
3099
  dynamicProto(NotificationManager, this, function (_self) {
2687
- _self.addNotificationListener = function (listener) {
3100
+ _self[strAddNotificationListener] = function (listener) {
2688
3101
  _self.listeners.push(listener);
2689
3102
  };
2690
- _self.removeNotificationListener = function (listener) {
3103
+ _self[strRemoveNotificationListener] = function (listener) {
2691
3104
  var index = arrIndexOf(_self.listeners, listener);
2692
3105
  while (index > -1) {
2693
3106
  _self.listeners.splice(index, 1);
2694
3107
  index = arrIndexOf(_self.listeners, listener);
2695
3108
  }
2696
3109
  };
2697
- _self.eventsSent = function (events) {
3110
+ _self[strEventsSent] = function (events) {
2698
3111
  _runListeners(_self.listeners, strEventsSent, true, function (listener) {
2699
3112
  listener[strEventsSent](events);
2700
3113
  });
2701
3114
  };
2702
- _self.eventsDiscarded = function (events, reason) {
3115
+ _self[strEventsDiscarded] = function (events, reason) {
2703
3116
  _runListeners(_self.listeners, strEventsDiscarded, true, function (listener) {
2704
3117
  listener[strEventsDiscarded](events, reason);
2705
3118
  });
2706
3119
  };
2707
- _self.eventsSendRequest = function (sendReason, isAsync) {
3120
+ _self[strEventsSendRequest] = function (sendReason, isAsync) {
2708
3121
  _runListeners(_self.listeners, strEventsSendRequest, isAsync, function (listener) {
2709
3122
  listener[strEventsSendRequest](sendReason, isAsync);
2710
3123
  });
2711
3124
  };
2712
- _self.perfEvent = function (perfEvent) {
3125
+ _self[strPerfEvent] = function (perfEvent) {
2713
3126
  if (perfEvent) {
2714
3127
  if (perfEvtsSendAll || !perfEvent.isChildEvt()) {
2715
3128
  _runListeners(_self.listeners, strPerfEvent, false, function (listener) {
@@ -2764,168 +3177,304 @@
2764
3177
  return AppInsightsCore;
2765
3178
  }(BaseCore));
2766
3179
 
2767
- var UInt32Mask = 0x100000000;
2768
- var MaxUInt32 = 0xffffffff;
2769
- var _mwcSeeded = false;
2770
- var _mwcW = 123456789;
2771
- var _mwcZ = 987654321;
2772
- function _mwcSeed(seedValue) {
2773
- if (seedValue < 0) {
2774
- seedValue >>>= 0;
3180
+ var strOnPrefix = "on";
3181
+ var strAttachEvent = "attachEvent";
3182
+ var strAddEventHelper = "addEventListener";
3183
+ var strDetachEvent = "detachEvent";
3184
+ var strRemoveEventListener = "removeEventListener";
3185
+ var strEvents = "events";
3186
+ var strVisibilityChangeEvt = "visibilitychange";
3187
+ var strPageHide = "pagehide";
3188
+ var strPageShow = "pageshow";
3189
+ var strUnload = "unload";
3190
+ var strBeforeUnload = "beforeunload";
3191
+ var strPageHideNamespace = createUniqueNamespace("aiEvtPageHide");
3192
+ var strPageShowNamespace = createUniqueNamespace("aiEvtPageShow");
3193
+ var _guid = 1;
3194
+ var elmNodeData = createElmNodeData("events");
3195
+ var eventNamespace = /^([^.]*)(?:\.(.+)|)/;
3196
+ function _normalizeNamespace(name) {
3197
+ if (name && name.replace) {
3198
+ return name.replace(/^\s*\.*|\.*\s*$/g, "");
3199
+ }
3200
+ return name;
3201
+ }
3202
+ function _getEvtNamespace(eventName, namespaces) {
3203
+ if (namespaces) {
3204
+ var theNamespace_1 = "";
3205
+ if (isArray(namespaces)) {
3206
+ theNamespace_1 = "";
3207
+ arrForEach(namespaces, function (name) {
3208
+ name = _normalizeNamespace(name);
3209
+ if (name) {
3210
+ if (name[0] !== ".") {
3211
+ name = "." + name;
3212
+ }
3213
+ theNamespace_1 += name;
3214
+ }
3215
+ });
3216
+ }
3217
+ else {
3218
+ theNamespace_1 = _normalizeNamespace(namespaces);
3219
+ }
3220
+ if (theNamespace_1) {
3221
+ if (theNamespace_1[0] !== ".") {
3222
+ theNamespace_1 = "." + theNamespace_1;
3223
+ }
3224
+ eventName = (eventName || "") + theNamespace_1;
3225
+ }
2775
3226
  }
2776
- _mwcW = (123456789 + seedValue) & MaxUInt32;
2777
- _mwcZ = (987654321 - seedValue) & MaxUInt32;
2778
- _mwcSeeded = true;
3227
+ var parsedEvent = (eventNamespace.exec(eventName) || []);
3228
+ return {
3229
+ type: parsedEvent[1],
3230
+ ns: ((parsedEvent[2] || "").split(".").sort()).join(".")
3231
+ };
2779
3232
  }
2780
- function _autoSeedMwc() {
2781
- try {
2782
- var now = dateNow() & 0x7fffffff;
2783
- _mwcSeed(((Math.random() * UInt32Mask) ^ now) + now);
2784
- }
2785
- catch (e) {
3233
+ function __getRegisteredEvents(target, evtName) {
3234
+ var theEvents = [];
3235
+ var eventCache = elmNodeData.get(target, strEvents, {}, false);
3236
+ objForEachKey(eventCache, function (evtType, registeredEvents) {
3237
+ arrForEach(registeredEvents, function (value) {
3238
+ if (!evtName || evtName === value.evtName.type) {
3239
+ theEvents.push({
3240
+ name: value.evtName.type + (value.evtName.ns ? "." + value.evtName.ns : ""),
3241
+ handler: value.handler
3242
+ });
3243
+ }
3244
+ });
3245
+ });
3246
+ return theEvents;
3247
+ }
3248
+ function _getRegisteredEvents(target, evtName, addDefault) {
3249
+ if (addDefault === void 0) { addDefault = true; }
3250
+ var aiEvts = elmNodeData.get(target, strEvents, {}, addDefault);
3251
+ var registeredEvents = aiEvts[evtName];
3252
+ if (!registeredEvents) {
3253
+ registeredEvents = aiEvts[evtName] = [];
2786
3254
  }
3255
+ return registeredEvents;
2787
3256
  }
2788
- function randomValue(maxValue) {
2789
- if (maxValue > 0) {
2790
- return Math.floor((random32() / MaxUInt32) * (maxValue + 1)) >>> 0;
3257
+ function _doDetach(obj, evtName, handlerRef, useCapture) {
3258
+ if (obj && evtName && evtName.type) {
3259
+ if (obj[strRemoveEventListener]) {
3260
+ obj[strRemoveEventListener](evtName.type, handlerRef, useCapture);
3261
+ }
3262
+ else if (obj[strDetachEvent]) {
3263
+ obj[strDetachEvent](strOnPrefix + evtName.type, handlerRef);
3264
+ }
2791
3265
  }
2792
- return 0;
2793
3266
  }
2794
- function random32(signed) {
2795
- var value = 0;
2796
- var c = getCrypto() || getMsCrypto();
2797
- if (c && c.getRandomValues) {
2798
- value = c.getRandomValues(new Uint32Array(1))[0] & MaxUInt32;
3267
+ function _doAttach(obj, evtName, handlerRef, useCapture) {
3268
+ var result = false;
3269
+ if (obj && evtName && evtName.type && handlerRef) {
3270
+ if (obj[strAddEventHelper]) {
3271
+ obj[strAddEventHelper](evtName.type, handlerRef, useCapture);
3272
+ result = true;
3273
+ }
3274
+ else if (obj[strAttachEvent]) {
3275
+ obj[strAttachEvent](strOnPrefix + evtName.type, handlerRef);
3276
+ result = true;
3277
+ }
2799
3278
  }
2800
- if (value === 0 && isIE()) {
2801
- if (!_mwcSeeded) {
2802
- _autoSeedMwc();
3279
+ return result;
3280
+ }
3281
+ function _doUnregister(target, events, evtName, unRegFn) {
3282
+ var idx = events.length;
3283
+ while (idx--) {
3284
+ var theEvent = events[idx];
3285
+ if (theEvent) {
3286
+ if (!evtName.ns || evtName.ns === theEvent.evtName.ns) {
3287
+ if (!unRegFn || unRegFn(theEvent)) {
3288
+ _doDetach(target, theEvent.evtName, theEvent.handler, theEvent.capture);
3289
+ events.splice(idx, 1);
3290
+ }
3291
+ }
2803
3292
  }
2804
- value = mwcRandom32() & MaxUInt32;
2805
3293
  }
2806
- if (value === 0) {
2807
- value = Math.floor((UInt32Mask * Math.random()) | 0);
3294
+ }
3295
+ function _unregisterEvents(target, evtName, unRegFn) {
3296
+ if (evtName.type) {
3297
+ _doUnregister(target, _getRegisteredEvents(target, evtName.type), evtName, unRegFn);
2808
3298
  }
2809
- if (!signed) {
2810
- value >>>= 0;
3299
+ else {
3300
+ var eventCache = elmNodeData.get(target, strEvents, {});
3301
+ objForEachKey(eventCache, function (evtType, events) {
3302
+ _doUnregister(target, events, evtName, unRegFn);
3303
+ });
3304
+ if (objKeys(eventCache).length === 0) {
3305
+ elmNodeData.kill(target, strEvents);
3306
+ }
2811
3307
  }
2812
- return value;
2813
3308
  }
2814
- function mwcRandomSeed(value) {
2815
- if (!value) {
2816
- _autoSeedMwc();
3309
+ function mergeEvtNamespace(theNamespace, namespaces) {
3310
+ var newNamespaces;
3311
+ if (namespaces) {
3312
+ if (isArray(namespaces)) {
3313
+ newNamespaces = [theNamespace].concat(namespaces);
3314
+ }
3315
+ else {
3316
+ newNamespaces = [theNamespace, namespaces];
3317
+ }
2817
3318
  }
2818
3319
  else {
2819
- _mwcSeed(value);
3320
+ newNamespaces = theNamespace;
2820
3321
  }
3322
+ return newNamespaces;
2821
3323
  }
2822
- function mwcRandom32(signed) {
2823
- _mwcZ = (36969 * (_mwcZ & 0xFFFF) + (_mwcZ >> 16)) & MaxUInt32;
2824
- _mwcW = (18000 * (_mwcW & 0xFFFF) + (_mwcW >> 16)) & MaxUInt32;
2825
- var value = (((_mwcZ << 16) + (_mwcW & 0xFFFF)) >>> 0) & MaxUInt32 | 0;
2826
- if (!signed) {
2827
- value >>>= 0;
3324
+ function eventOn(target, eventName, handlerRef, evtNamespace, useCapture) {
3325
+ if (useCapture === void 0) { useCapture = false; }
3326
+ var result = false;
3327
+ if (target) {
3328
+ try {
3329
+ var evtName = _getEvtNamespace(eventName, evtNamespace);
3330
+ result = _doAttach(target, evtName, handlerRef, useCapture);
3331
+ if (result && elmNodeData.accept(target)) {
3332
+ var registeredEvent = {
3333
+ guid: _guid++,
3334
+ evtName: evtName,
3335
+ handler: handlerRef,
3336
+ capture: useCapture
3337
+ };
3338
+ _getRegisteredEvents(target, evtName.type).push(registeredEvent);
3339
+ }
3340
+ }
3341
+ catch (e) {
3342
+ }
2828
3343
  }
2829
- return value;
3344
+ return result;
2830
3345
  }
2831
- function newId(maxLength) {
2832
- if (maxLength === void 0) { maxLength = 22; }
2833
- var base64chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
2834
- var number = random32() >>> 0;
2835
- var chars = 0;
2836
- var result = "";
2837
- while (result.length < maxLength) {
2838
- chars++;
2839
- result += base64chars.charAt(number & 0x3F);
2840
- number >>>= 6;
2841
- if (chars === 5) {
2842
- number = (((random32() << 2) & 0xFFFFFFFF) | (number & 0x03)) >>> 0;
2843
- chars = 0;
3346
+ function eventOff(target, eventName, handlerRef, evtNamespace, useCapture) {
3347
+ if (useCapture === void 0) { useCapture = false; }
3348
+ if (target) {
3349
+ try {
3350
+ var evtName_1 = _getEvtNamespace(eventName, evtNamespace);
3351
+ var found_1 = false;
3352
+ _unregisterEvents(target, evtName_1, function (regEvent) {
3353
+ if ((evtName_1.ns && !handlerRef) || regEvent.handler === handlerRef) {
3354
+ found_1 = true;
3355
+ return true;
3356
+ }
3357
+ return false;
3358
+ });
3359
+ if (!found_1) {
3360
+ _doDetach(target, evtName_1, handlerRef, useCapture);
3361
+ }
3362
+ }
3363
+ catch (e) {
2844
3364
  }
2845
3365
  }
2846
- return result;
2847
3366
  }
2848
-
2849
- var strVisibilityChangeEvt = "visibilitychange";
2850
- var strPageHide = "pagehide";
2851
- var strPageShow = "pageshow";
2852
- var _cookieMgrs = null;
2853
- var _canUseCookies;
2854
- var Undefined = strShimUndefined;
2855
- function addEventHandler(eventName, callback) {
3367
+ function attachEvent(obj, eventNameWithoutOn, handlerRef, useCapture) {
3368
+ if (useCapture === void 0) { useCapture = false; }
3369
+ return eventOn(obj, eventNameWithoutOn, handlerRef, null, useCapture);
3370
+ }
3371
+ function detachEvent(obj, eventNameWithoutOn, handlerRef, useCapture) {
3372
+ if (useCapture === void 0) { useCapture = false; }
3373
+ eventOff(obj, eventNameWithoutOn, handlerRef, null, useCapture);
3374
+ }
3375
+ function addEventHandler(eventName, callback, evtNamespace) {
2856
3376
  var result = false;
2857
3377
  var w = getWindow();
2858
3378
  if (w) {
2859
- result = attachEvent(w, eventName, callback);
2860
- result = attachEvent(w["body"], eventName, callback) || result;
3379
+ result = eventOn(w, eventName, callback, evtNamespace);
3380
+ result = eventOn(w["body"], eventName, callback, evtNamespace) || result;
2861
3381
  }
2862
3382
  var doc = getDocument();
2863
3383
  if (doc) {
2864
- result = attachEvent(doc, eventName, callback) || result;
3384
+ result = eventOn(doc, eventName, callback, evtNamespace) || result;
2865
3385
  }
2866
3386
  return result;
2867
3387
  }
2868
- function addEventListeners(events, listener, excludeEvents) {
3388
+ function removeEventHandler(eventName, callback, evtNamespace) {
3389
+ var w = getWindow();
3390
+ if (w) {
3391
+ eventOff(w, eventName, callback, evtNamespace);
3392
+ eventOff(w["body"], eventName, callback, evtNamespace);
3393
+ }
3394
+ var doc = getDocument();
3395
+ if (doc) {
3396
+ eventOff(doc, eventName, callback, evtNamespace);
3397
+ }
3398
+ }
3399
+ function _addEventListeners(events, listener, excludeEvents, evtNamespace) {
2869
3400
  var added = false;
2870
- if (listener && events && isArray(events)) {
2871
- var excluded_1 = [];
3401
+ if (listener && events && events.length > 0) {
2872
3402
  arrForEach(events, function (name) {
2873
- if (isString(name)) {
3403
+ if (name) {
2874
3404
  if (!excludeEvents || arrIndexOf(excludeEvents, name) === -1) {
2875
- added = addEventHandler(name, listener) || added;
2876
- }
2877
- else {
2878
- excluded_1.push(name);
3405
+ added = addEventHandler(name, listener, evtNamespace) || added;
2879
3406
  }
2880
3407
  }
2881
3408
  });
2882
- if (!added && excluded_1.length > 0) {
2883
- added = addEventListeners(excluded_1, listener);
3409
+ }
3410
+ return added;
3411
+ }
3412
+ function addEventListeners(events, listener, excludeEvents, evtNamespace) {
3413
+ var added = false;
3414
+ if (listener && events && isArray(events)) {
3415
+ added = _addEventListeners(events, listener, excludeEvents, evtNamespace);
3416
+ if (!added && excludeEvents && excludeEvents.length > 0) {
3417
+ added = _addEventListeners(events, listener, null, evtNamespace);
2884
3418
  }
2885
3419
  }
2886
3420
  return added;
2887
3421
  }
2888
- function addPageUnloadEventListener(listener, excludeEvents) {
2889
- return addEventListeners(["beforeunload", "unload", "pagehide"], listener, excludeEvents);
3422
+ function removeEventListeners(events, listener, evtNamespace) {
3423
+ if (events && isArray(events)) {
3424
+ arrForEach(events, function (name) {
3425
+ if (name) {
3426
+ removeEventHandler(name, listener, evtNamespace);
3427
+ }
3428
+ });
3429
+ }
3430
+ }
3431
+ function addPageUnloadEventListener(listener, excludeEvents, evtNamespace) {
3432
+ return addEventListeners([strBeforeUnload, strUnload, strPageHide], listener, excludeEvents, evtNamespace);
3433
+ }
3434
+ function removePageUnloadEventListener(listener, evtNamespace) {
3435
+ removeEventListeners([strBeforeUnload, strUnload, strPageHide], listener, evtNamespace);
2890
3436
  }
2891
- function addPageHideEventListener(listener, excludeEvents) {
3437
+ function addPageHideEventListener(listener, excludeEvents, evtNamespace) {
2892
3438
  function _handlePageVisibility(evt) {
2893
3439
  var doc = getDocument();
2894
3440
  if (listener && doc && doc.visibilityState === "hidden") {
2895
3441
  listener(evt);
2896
3442
  }
2897
3443
  }
2898
- var pageUnloadAdded = false;
2899
- if (!excludeEvents || arrIndexOf(excludeEvents, strPageHide) === -1) {
2900
- pageUnloadAdded = addEventHandler(strPageHide, listener);
2901
- }
3444
+ var newNamespaces = mergeEvtNamespace(strPageHideNamespace, evtNamespace);
3445
+ var pageUnloadAdded = _addEventListeners([strPageHide], listener, excludeEvents, newNamespaces);
2902
3446
  if (!excludeEvents || arrIndexOf(excludeEvents, strVisibilityChangeEvt) === -1) {
2903
- pageUnloadAdded = addEventHandler(strVisibilityChangeEvt, _handlePageVisibility) || pageUnloadAdded;
3447
+ pageUnloadAdded = _addEventListeners([strVisibilityChangeEvt], _handlePageVisibility, excludeEvents, newNamespaces) || pageUnloadAdded;
2904
3448
  }
2905
3449
  if (!pageUnloadAdded && excludeEvents) {
2906
- pageUnloadAdded = addPageHideEventListener(listener);
3450
+ pageUnloadAdded = addPageHideEventListener(listener, null, evtNamespace);
2907
3451
  }
2908
3452
  return pageUnloadAdded;
2909
3453
  }
2910
- function addPageShowEventListener(listener, excludeEvents) {
3454
+ function removePageHideEventListener(listener, evtNamespace) {
3455
+ var newNamespaces = mergeEvtNamespace(strPageHideNamespace, evtNamespace);
3456
+ removeEventListeners([strPageHide], listener, newNamespaces);
3457
+ removeEventListeners([strVisibilityChangeEvt], null, newNamespaces);
3458
+ }
3459
+ function addPageShowEventListener(listener, excludeEvents, evtNamespace) {
2911
3460
  function _handlePageVisibility(evt) {
2912
3461
  var doc = getDocument();
2913
3462
  if (listener && doc && doc.visibilityState === "visible") {
2914
3463
  listener(evt);
2915
3464
  }
2916
3465
  }
2917
- var pageShowAdded = false;
2918
- if (!excludeEvents || arrIndexOf(excludeEvents, strPageShow) === -1) {
2919
- pageShowAdded = addEventHandler(strPageShow, listener);
2920
- }
2921
- if (!excludeEvents || arrIndexOf(excludeEvents, strVisibilityChangeEvt) === -1) {
2922
- pageShowAdded = addEventHandler(strVisibilityChangeEvt, _handlePageVisibility) || pageShowAdded;
2923
- }
3466
+ var newNamespaces = mergeEvtNamespace(strPageShowNamespace, evtNamespace);
3467
+ var pageShowAdded = _addEventListeners([strPageShow], listener, excludeEvents, newNamespaces);
3468
+ pageShowAdded = _addEventListeners([strVisibilityChangeEvt], _handlePageVisibility, excludeEvents, newNamespaces) || pageShowAdded;
2924
3469
  if (!pageShowAdded && excludeEvents) {
2925
- pageShowAdded = addPageShowEventListener(listener);
3470
+ pageShowAdded = addPageShowEventListener(listener, null, evtNamespace);
2926
3471
  }
2927
3472
  return pageShowAdded;
2928
3473
  }
3474
+
3475
+ var _cookieMgrs = null;
3476
+ var _canUseCookies;
3477
+ var Undefined = strShimUndefined;
2929
3478
  function newGuid() {
2930
3479
  function randomHexDigit() {
2931
3480
  return randomValue(15);
@@ -2944,7 +3493,7 @@
2944
3493
  }
2945
3494
  function generateW3CId() {
2946
3495
  var hexValues = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"];
2947
- var oct = "", tmp;
3496
+ var oct = strEmpty, tmp;
2948
3497
  for (var a = 0; a < 4; a++) {
2949
3498
  tmp = random32();
2950
3499
  oct +=
@@ -3045,6 +3594,95 @@
3045
3594
  return _legacyCookieMgr(null, logger).del(name);
3046
3595
  }
3047
3596
 
3597
+ var LoggingSeverity = createEnumStyle({
3598
+ CRITICAL: 1 ,
3599
+ WARNING: 2
3600
+ });
3601
+ var _InternalMessageId = createEnumStyle({
3602
+ BrowserDoesNotSupportLocalStorage: 0 ,
3603
+ BrowserCannotReadLocalStorage: 1 ,
3604
+ BrowserCannotReadSessionStorage: 2 ,
3605
+ BrowserCannotWriteLocalStorage: 3 ,
3606
+ BrowserCannotWriteSessionStorage: 4 ,
3607
+ BrowserFailedRemovalFromLocalStorage: 5 ,
3608
+ BrowserFailedRemovalFromSessionStorage: 6 ,
3609
+ CannotSendEmptyTelemetry: 7 ,
3610
+ ClientPerformanceMathError: 8 ,
3611
+ ErrorParsingAISessionCookie: 9 ,
3612
+ ErrorPVCalc: 10 ,
3613
+ ExceptionWhileLoggingError: 11 ,
3614
+ FailedAddingTelemetryToBuffer: 12 ,
3615
+ FailedMonitorAjaxAbort: 13 ,
3616
+ FailedMonitorAjaxDur: 14 ,
3617
+ FailedMonitorAjaxOpen: 15 ,
3618
+ FailedMonitorAjaxRSC: 16 ,
3619
+ FailedMonitorAjaxSend: 17 ,
3620
+ FailedMonitorAjaxGetCorrelationHeader: 18 ,
3621
+ FailedToAddHandlerForOnBeforeUnload: 19 ,
3622
+ FailedToSendQueuedTelemetry: 20 ,
3623
+ FailedToReportDataLoss: 21 ,
3624
+ FlushFailed: 22 ,
3625
+ MessageLimitPerPVExceeded: 23 ,
3626
+ MissingRequiredFieldSpecification: 24 ,
3627
+ NavigationTimingNotSupported: 25 ,
3628
+ OnError: 26 ,
3629
+ SessionRenewalDateIsZero: 27 ,
3630
+ SenderNotInitialized: 28 ,
3631
+ StartTrackEventFailed: 29 ,
3632
+ StopTrackEventFailed: 30 ,
3633
+ StartTrackFailed: 31 ,
3634
+ StopTrackFailed: 32 ,
3635
+ TelemetrySampledAndNotSent: 33 ,
3636
+ TrackEventFailed: 34 ,
3637
+ TrackExceptionFailed: 35 ,
3638
+ TrackMetricFailed: 36 ,
3639
+ TrackPVFailed: 37 ,
3640
+ TrackPVFailedCalc: 38 ,
3641
+ TrackTraceFailed: 39 ,
3642
+ TransmissionFailed: 40 ,
3643
+ FailedToSetStorageBuffer: 41 ,
3644
+ FailedToRestoreStorageBuffer: 42 ,
3645
+ InvalidBackendResponse: 43 ,
3646
+ FailedToFixDepricatedValues: 44 ,
3647
+ InvalidDurationValue: 45 ,
3648
+ TelemetryEnvelopeInvalid: 46 ,
3649
+ CreateEnvelopeError: 47 ,
3650
+ CannotSerializeObject: 48 ,
3651
+ CannotSerializeObjectNonSerializable: 49 ,
3652
+ CircularReferenceDetected: 50 ,
3653
+ ClearAuthContextFailed: 51 ,
3654
+ ExceptionTruncated: 52 ,
3655
+ IllegalCharsInName: 53 ,
3656
+ ItemNotInArray: 54 ,
3657
+ MaxAjaxPerPVExceeded: 55 ,
3658
+ MessageTruncated: 56 ,
3659
+ NameTooLong: 57 ,
3660
+ SampleRateOutOfRange: 58 ,
3661
+ SetAuthContextFailed: 59 ,
3662
+ SetAuthContextFailedAccountName: 60 ,
3663
+ StringValueTooLong: 61 ,
3664
+ StartCalledMoreThanOnce: 62 ,
3665
+ StopCalledWithoutStart: 63 ,
3666
+ TelemetryInitializerFailed: 64 ,
3667
+ TrackArgumentsNotSpecified: 65 ,
3668
+ UrlTooLong: 66 ,
3669
+ SessionStorageBufferFull: 67 ,
3670
+ CannotAccessCookie: 68 ,
3671
+ IdTooLong: 69 ,
3672
+ InvalidEvent: 70 ,
3673
+ FailedMonitorAjaxSetRequestHeader: 71 ,
3674
+ SendBrowserInfoOnUserInit: 72 ,
3675
+ PluginException: 73 ,
3676
+ NotificationException: 74 ,
3677
+ SnippetScriptLoadFailure: 99 ,
3678
+ InvalidInstrumentationKey: 100 ,
3679
+ CannotParseAiBlobValue: 101 ,
3680
+ InvalidContentBlob: 102 ,
3681
+ TrackPageActionEventFailed: 103 ,
3682
+ FailedAddingCustomDefinedRequestContext: 104 ,
3683
+ InMemoryStorageBufferFull: 105
3684
+ });
3685
+
3048
3686
  var aiInstrumentHooks = "_aiHooks";
3049
3687
  var cbNames = [
3050
3688
  "req", "rsp", "hkErr", "fnErr"
@@ -3219,6 +3857,7 @@
3219
3857
  exports.InstrumentFuncs = InstrumentFuncs;
3220
3858
  exports.InstrumentProto = InstrumentProto;
3221
3859
  exports.InstrumentProtos = InstrumentProtos;
3860
+ exports.LoggingSeverity = LoggingSeverity;
3222
3861
  exports.MinChannelPriorty = MinChannelPriorty;
3223
3862
  exports.NotificationManager = NotificationManager;
3224
3863
  exports.PerfEvent = PerfEvent;
@@ -3227,6 +3866,7 @@
3227
3866
  exports.Undefined = Undefined;
3228
3867
  exports._InternalLogMessage = _InternalLogMessage;
3229
3868
  exports._InternalMessageId = _InternalMessageId;
3869
+ exports.__getRegisteredEvents = __getRegisteredEvents;
3230
3870
  exports._legacyCookieMgr = _legacyCookieMgr;
3231
3871
  exports.addEventHandler = addEventHandler;
3232
3872
  exports.addEventListeners = addEventListeners;
@@ -3242,13 +3882,18 @@
3242
3882
  exports.canUseCookies = canUseCookies;
3243
3883
  exports.createClassFromInterface = createClassFromInterface;
3244
3884
  exports.createCookieMgr = createCookieMgr;
3885
+ exports.createEnumStyle = createEnumStyle;
3245
3886
  exports.createProcessTelemetryContext = createProcessTelemetryContext;
3887
+ exports.createUniqueNamespace = createUniqueNamespace;
3888
+ exports.createUnloadHandlerContainer = createUnloadHandlerContainer;
3246
3889
  exports.dateNow = dateNow;
3247
3890
  exports.deleteCookie = deleteCookie;
3248
3891
  exports.detachEvent = detachEvent;
3249
3892
  exports.disableCookies = disableCookies;
3250
3893
  exports.doPerf = doPerf;
3251
3894
  exports.dumpObj = dumpObj;
3895
+ exports.eventOff = eventOff;
3896
+ exports.eventOn = eventOn;
3252
3897
  exports.generateW3CId = generateW3CId;
3253
3898
  exports.getConsole = getConsole;
3254
3899
  exports.getCookie = getCookie;
@@ -3298,6 +3943,7 @@
3298
3943
  exports.isTypeof = isTypeof;
3299
3944
  exports.isUndefined = isUndefined;
3300
3945
  exports.isXhrSupported = isXhrSupported;
3946
+ exports.mergeEvtNamespace = mergeEvtNamespace;
3301
3947
  exports.mwcRandom32 = mwcRandom32;
3302
3948
  exports.mwcRandomSeed = mwcRandomSeed;
3303
3949
  exports.newGuid = newGuid;
@@ -3305,6 +3951,7 @@
3305
3951
  exports.normalizeJsName = normalizeJsName;
3306
3952
  exports.objCreate = objCreateFn;
3307
3953
  exports.objDefineAccessors = objDefineAccessors;
3954
+ exports.objExtend = objExtend;
3308
3955
  exports.objForEachKey = objForEachKey;
3309
3956
  exports.objFreeze = objFreeze;
3310
3957
  exports.objKeys = objKeys;
@@ -3312,8 +3959,14 @@
3312
3959
  exports.optimizeObject = optimizeObject;
3313
3960
  exports.perfNow = perfNow;
3314
3961
  exports.proxyAssign = proxyAssign;
3962
+ exports.proxyFunctionAs = proxyFunctionAs;
3963
+ exports.proxyFunctions = proxyFunctions;
3315
3964
  exports.random32 = random32;
3316
3965
  exports.randomValue = randomValue;
3966
+ exports.removeEventHandler = removeEventHandler;
3967
+ exports.removeEventListeners = removeEventListeners;
3968
+ exports.removePageHideEventListener = removePageHideEventListener;
3969
+ exports.removePageUnloadEventListener = removePageUnloadEventListener;
3317
3970
  exports.safeGetCookieMgr = safeGetCookieMgr;
3318
3971
  exports.safeGetLogger = safeGetLogger;
3319
3972
  exports.setCookie = setCookie;