@microsoft/applicationinsights-web 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 (51) hide show
  1. package/README.md +1 -0
  2. package/browser/{ai.2.8.0-beta.2202-07.cjs.js → ai.2.8.0-beta.2203-03.cjs.js} +1069 -522
  3. package/browser/ai.2.8.0-beta.2203-03.cjs.js.map +1 -0
  4. package/browser/ai.2.8.0-beta.2203-03.cjs.min.js +6 -0
  5. package/browser/ai.2.8.0-beta.2203-03.cjs.min.js.map +1 -0
  6. package/browser/{ai.2.8.0-beta.2202-07.gbl.js → ai.2.8.0-beta.2203-03.gbl.js} +1069 -522
  7. package/browser/ai.2.8.0-beta.2203-03.gbl.js.map +1 -0
  8. package/browser/ai.2.8.0-beta.2203-03.gbl.min.js +6 -0
  9. package/browser/ai.2.8.0-beta.2203-03.gbl.min.js.map +1 -0
  10. package/browser/ai.2.8.0-beta.2203-03.integrity.json +66 -0
  11. package/browser/{ai.2.8.0-beta.2202-07.js → ai.2.8.0-beta.2203-03.js} +1069 -522
  12. package/browser/ai.2.8.0-beta.2203-03.js.map +1 -0
  13. package/browser/ai.2.8.0-beta.2203-03.min.js +6 -0
  14. package/browser/ai.2.8.0-beta.2203-03.min.js.map +1 -0
  15. package/browser/ai.2.cjs.js +1068 -521
  16. package/browser/ai.2.cjs.js.map +1 -1
  17. package/browser/ai.2.cjs.min.js +2 -2
  18. package/browser/ai.2.cjs.min.js.map +1 -1
  19. package/browser/ai.2.gbl.js +1068 -521
  20. package/browser/ai.2.gbl.js.map +1 -1
  21. package/browser/ai.2.gbl.min.js +2 -2
  22. package/browser/ai.2.gbl.min.js.map +1 -1
  23. package/browser/ai.2.js +1068 -521
  24. package/browser/ai.2.js.map +1 -1
  25. package/browser/ai.2.min.js +2 -2
  26. package/browser/ai.2.min.js.map +1 -1
  27. package/dist/applicationinsights-web.api.json +925 -660
  28. package/dist/applicationinsights-web.api.md +53 -32
  29. package/dist/applicationinsights-web.d.ts +358 -93
  30. package/dist/applicationinsights-web.js +1134 -585
  31. package/dist/applicationinsights-web.js.map +1 -1
  32. package/dist/applicationinsights-web.min.js +2 -2
  33. package/dist/applicationinsights-web.min.js.map +1 -1
  34. package/dist/applicationinsights-web.rollup.d.ts +358 -93
  35. package/dist-esm/ApplicationInsightsContainer.js +1 -1
  36. package/dist-esm/ApplicationInsightsDeprecated.js +1 -1
  37. package/dist-esm/Init.js +1 -1
  38. package/dist-esm/Initialization.js +1 -1
  39. package/dist-esm/applicationinsights-web.js +1 -1
  40. package/package.json +7 -7
  41. package/types/Initialization.d.ts +6 -2
  42. package/browser/ai.2.8.0-beta.2202-07.cjs.js.map +0 -1
  43. package/browser/ai.2.8.0-beta.2202-07.cjs.min.js +0 -6
  44. package/browser/ai.2.8.0-beta.2202-07.cjs.min.js.map +0 -1
  45. package/browser/ai.2.8.0-beta.2202-07.gbl.js.map +0 -1
  46. package/browser/ai.2.8.0-beta.2202-07.gbl.min.js +0 -6
  47. package/browser/ai.2.8.0-beta.2202-07.gbl.min.js.map +0 -1
  48. package/browser/ai.2.8.0-beta.2202-07.integrity.json +0 -66
  49. package/browser/ai.2.8.0-beta.2202-07.js.map +0 -1
  50. package/browser/ai.2.8.0-beta.2202-07.min.js +0 -6
  51. package/browser/ai.2.8.0-beta.2202-07.min.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Application Insights JavaScript SDK - Web, 2.8.0-beta.2202-07
2
+ * Application Insights JavaScript SDK - Web, 2.8.0-beta.2203-03
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
  this.Microsoft = this.Microsoft || {};
@@ -348,99 +348,26 @@ this.Microsoft = this.Microsoft || {};
348
348
  };
349
349
  dynamicProto[DynProtoDefaultOptions] = perfDefaults;
350
350
 
351
- var LoggingSeverity;
352
- (function (LoggingSeverity) {
353
- LoggingSeverity[LoggingSeverity["CRITICAL"] = 1] = "CRITICAL";
354
- LoggingSeverity[LoggingSeverity["WARNING"] = 2] = "WARNING";
355
- })(LoggingSeverity || (LoggingSeverity = {}));
356
- var _InternalMessageId = {
357
- BrowserDoesNotSupportLocalStorage: 0,
358
- BrowserCannotReadLocalStorage: 1,
359
- BrowserCannotReadSessionStorage: 2,
360
- BrowserCannotWriteLocalStorage: 3,
361
- BrowserCannotWriteSessionStorage: 4,
362
- BrowserFailedRemovalFromLocalStorage: 5,
363
- BrowserFailedRemovalFromSessionStorage: 6,
364
- CannotSendEmptyTelemetry: 7,
365
- ClientPerformanceMathError: 8,
366
- ErrorParsingAISessionCookie: 9,
367
- ErrorPVCalc: 10,
368
- ExceptionWhileLoggingError: 11,
369
- FailedAddingTelemetryToBuffer: 12,
370
- FailedMonitorAjaxAbort: 13,
371
- FailedMonitorAjaxDur: 14,
372
- FailedMonitorAjaxOpen: 15,
373
- FailedMonitorAjaxRSC: 16,
374
- FailedMonitorAjaxSend: 17,
375
- FailedMonitorAjaxGetCorrelationHeader: 18,
376
- FailedToAddHandlerForOnBeforeUnload: 19,
377
- FailedToSendQueuedTelemetry: 20,
378
- FailedToReportDataLoss: 21,
379
- FlushFailed: 22,
380
- MessageLimitPerPVExceeded: 23,
381
- MissingRequiredFieldSpecification: 24,
382
- NavigationTimingNotSupported: 25,
383
- OnError: 26,
384
- SessionRenewalDateIsZero: 27,
385
- SenderNotInitialized: 28,
386
- StartTrackEventFailed: 29,
387
- StopTrackEventFailed: 30,
388
- StartTrackFailed: 31,
389
- StopTrackFailed: 32,
390
- TelemetrySampledAndNotSent: 33,
391
- TrackEventFailed: 34,
392
- TrackExceptionFailed: 35,
393
- TrackMetricFailed: 36,
394
- TrackPVFailed: 37,
395
- TrackPVFailedCalc: 38,
396
- TrackTraceFailed: 39,
397
- TransmissionFailed: 40,
398
- FailedToSetStorageBuffer: 41,
399
- FailedToRestoreStorageBuffer: 42,
400
- InvalidBackendResponse: 43,
401
- FailedToFixDepricatedValues: 44,
402
- InvalidDurationValue: 45,
403
- TelemetryEnvelopeInvalid: 46,
404
- CreateEnvelopeError: 47,
405
- CannotSerializeObject: 48,
406
- CannotSerializeObjectNonSerializable: 49,
407
- CircularReferenceDetected: 50,
408
- ClearAuthContextFailed: 51,
409
- ExceptionTruncated: 52,
410
- IllegalCharsInName: 53,
411
- ItemNotInArray: 54,
412
- MaxAjaxPerPVExceeded: 55,
413
- MessageTruncated: 56,
414
- NameTooLong: 57,
415
- SampleRateOutOfRange: 58,
416
- SetAuthContextFailed: 59,
417
- SetAuthContextFailedAccountName: 60,
418
- StringValueTooLong: 61,
419
- StartCalledMoreThanOnce: 62,
420
- StopCalledWithoutStart: 63,
421
- TelemetryInitializerFailed: 64,
422
- TrackArgumentsNotSpecified: 65,
423
- UrlTooLong: 66,
424
- SessionStorageBufferFull: 67,
425
- CannotAccessCookie: 68,
426
- IdTooLong: 69,
427
- InvalidEvent: 70,
428
- FailedMonitorAjaxSetRequestHeader: 71,
429
- SendBrowserInfoOnUserInit: 72,
430
- PluginException: 73,
431
- NotificationException: 74,
432
- SnippetScriptLoadFailure: 99,
433
- InvalidInstrumentationKey: 100,
434
- CannotParseAiBlobValue: 101,
435
- InvalidContentBlob: 102,
436
- TrackPageActionEventFailed: 103,
437
- FailedAddingCustomDefinedRequestContext: 104,
438
- InMemoryStorageBufferFull: 105
439
- };
351
+ var strEmpty$1 = "";
352
+ var strProcessTelemetry = "processTelemetry";
353
+ var strPriority = "priority";
354
+ var strSetNextPlugin = "setNextPlugin";
355
+ var strIsInitialized = "isInitialized";
356
+ var strTeardown = "teardown";
357
+ var strCore = "core";
358
+ var strDisabled = "disabled";
359
+ var strDoTeardown = "_doTeardown";
360
+ var strProcessNext = "processNext";
361
+ var strResume = "resume";
362
+ var strPause = "pause";
363
+ var strNotificationListener = "NotificationListener";
364
+ var strAddNotificationListener = "add" + strNotificationListener;
365
+ var strRemoveNotificationListener = "remove" + strNotificationListener;
366
+ var strEventsSent = "eventsSent";
367
+ var strEventsDiscarded = "eventsDiscarded";
368
+ var strEventsSendRequest = "eventsSendRequest";
369
+ var strPerfEvent = "perfEvent";
440
370
 
441
- var strOnPrefix = "on";
442
- var strAttachEvent = "attachEvent";
443
- var strAddEventHelper = "addEventListener";
444
371
  var strToISOString = "toISOString";
445
372
  var cStrEndsWith = "endsWith";
446
373
  var strIndexOf = "indexOf";
@@ -450,7 +377,7 @@ this.Microsoft = this.Microsoft || {};
450
377
  var strToString = "toString";
451
378
  var str__Proto = "__proto__";
452
379
  var strConstructor = "constructor";
453
- var _objDefineProperty = ObjDefineProperty;
380
+ var _objDefineProperty$1 = ObjDefineProperty;
454
381
  var _objFreeze = ObjClass.freeze;
455
382
  var _objKeys = ObjClass.keys;
456
383
  var StringProto = String[strShimPrototype];
@@ -499,25 +426,6 @@ this.Microsoft = this.Microsoft || {};
499
426
  function isFunction(value) {
500
427
  return !!(value && typeof value === strShimFunction);
501
428
  }
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
429
  function normalizeJsName(name) {
522
430
  var value = name;
523
431
  if (value && isString(value)) {
@@ -749,7 +657,7 @@ this.Microsoft = this.Microsoft || {};
749
657
  return result;
750
658
  }
751
659
  function objDefineAccessors(target, prop, getProp, setProp) {
752
- if (_objDefineProperty) {
660
+ if (_objDefineProperty$1) {
753
661
  try {
754
662
  var descriptor = {
755
663
  enumerable: true,
@@ -761,7 +669,7 @@ this.Microsoft = this.Microsoft || {};
761
669
  if (setProp) {
762
670
  descriptor.set = setProp;
763
671
  }
764
- _objDefineProperty(target, prop, descriptor);
672
+ _objDefineProperty$1(target, prop, descriptor);
765
673
  return true;
766
674
  }
767
675
  catch (e) {
@@ -781,7 +689,7 @@ this.Microsoft = this.Microsoft || {};
781
689
  if (isError(object)) {
782
690
  return object.name;
783
691
  }
784
- return "";
692
+ return strEmpty$1;
785
693
  }
786
694
  function setValue(target, field, value, valChk, srcChk) {
787
695
  var theValue = value;
@@ -898,6 +806,17 @@ this.Microsoft = this.Microsoft || {};
898
806
  return class_1;
899
807
  }());
900
808
  }
809
+ function createEnumStyle(values) {
810
+ var enumClass = {};
811
+ objForEachKey(values, function (field, value) {
812
+ enumClass[field] = value;
813
+ if (!isUndefined(enumClass[value])) {
814
+ throwError("[" + value + "] exists for " + field);
815
+ }
816
+ enumClass[value] = field;
817
+ });
818
+ return objFreeze(enumClass);
819
+ }
901
820
  function optimizeObject(theObject) {
902
821
  if (theObject && ObjAssign) {
903
822
  theObject = ObjClass(ObjAssign({}, theObject));
@@ -1087,7 +1006,7 @@ this.Microsoft = this.Microsoft || {};
1087
1006
  var nav = getNavigator();
1088
1007
  if (nav && (nav.userAgent !== _navUserAgentCheck || _isTrident === null)) {
1089
1008
  _navUserAgentCheck = nav.userAgent;
1090
- var userAgent = (_navUserAgentCheck || "").toLowerCase();
1009
+ var userAgent = (_navUserAgentCheck || strEmpty$1).toLowerCase();
1091
1010
  _isTrident = (strContains(userAgent, strMsie) || strContains(userAgent, strTrident));
1092
1011
  }
1093
1012
  return _isTrident;
@@ -1096,9 +1015,9 @@ this.Microsoft = this.Microsoft || {};
1096
1015
  if (userAgentStr === void 0) { userAgentStr = null; }
1097
1016
  if (!userAgentStr) {
1098
1017
  var navigator_1 = getNavigator() || {};
1099
- userAgentStr = navigator_1 ? (navigator_1.userAgent || "").toLowerCase() : "";
1018
+ userAgentStr = navigator_1 ? (navigator_1.userAgent || strEmpty$1).toLowerCase() : strEmpty$1;
1100
1019
  }
1101
- var ua = (userAgentStr || "").toLowerCase();
1020
+ var ua = (userAgentStr || strEmpty$1).toLowerCase();
1102
1021
  if (strContains(ua, strMsie)) {
1103
1022
  var doc = getDocument() || {};
1104
1023
  return Math.max(parseInt(ua.split(strMsie)[1]), (doc[strDocumentMode] || 0));
@@ -1113,7 +1032,7 @@ this.Microsoft = this.Microsoft || {};
1113
1032
  }
1114
1033
  function dumpObj(object) {
1115
1034
  var objectTypeDump = Object[strShimPrototype].toString.call(object);
1116
- var propertyValueDump = "";
1035
+ var propertyValueDump = strEmpty$1;
1117
1036
  if (objectTypeDump === "[object Error]") {
1118
1037
  propertyValueDump = "{ stack: '" + object.stack + "', message: '" + object.message + "', name: '" + object.name + "'";
1119
1038
  }
@@ -1207,9 +1126,9 @@ this.Microsoft = this.Microsoft || {};
1207
1126
  var strWarnToConsole = "warnToConsole";
1208
1127
  function _sanitizeDiagnosticText(text) {
1209
1128
  if (text) {
1210
- return "\"" + text.replace(/\"/g, "") + "\"";
1129
+ return "\"" + text.replace(/\"/g, strEmpty$1) + "\"";
1211
1130
  }
1212
- return "";
1131
+ return strEmpty$1;
1213
1132
  }
1214
1133
  function _logToConsole(func, message) {
1215
1134
  var theConsole = getConsole();
@@ -1231,12 +1150,12 @@ this.Microsoft = this.Microsoft || {};
1231
1150
  _self.message =
1232
1151
  (isUserAct ? AiUserActionablePrefix : AiNonUserActionablePrefix) +
1233
1152
  msgId;
1234
- var strProps = "";
1153
+ var strProps = strEmpty$1;
1235
1154
  if (hasJSON()) {
1236
1155
  strProps = getJSON().stringify(properties);
1237
1156
  }
1238
- var diagnosticText = (msg ? " message:" + _sanitizeDiagnosticText(msg) : "") +
1239
- (properties ? " props:" + _sanitizeDiagnosticText(strProps) : "");
1157
+ var diagnosticText = (msg ? " message:" + _sanitizeDiagnosticText(msg) : strEmpty$1) +
1158
+ (properties ? " props:" + _sanitizeDiagnosticText(strProps) : strEmpty$1);
1240
1159
  _self.message += diagnosticText;
1241
1160
  }
1242
1161
  _InternalLogMessage.dataType = "MessageData";
@@ -1266,7 +1185,7 @@ this.Microsoft = this.Microsoft || {};
1266
1185
  throw message;
1267
1186
  }
1268
1187
  else {
1269
- var logFunc = severity === LoggingSeverity.CRITICAL ? strErrorToConsole : strWarnToConsole;
1188
+ var logFunc = severity === 1 ? strErrorToConsole : strWarnToConsole;
1270
1189
  if (!isUndefined(message.message)) {
1271
1190
  var logLevel = _self.consoleLoggingLevel();
1272
1191
  if (isUserAct) {
@@ -1284,7 +1203,7 @@ this.Microsoft = this.Microsoft || {};
1284
1203
  _self.logInternalMessage(severity, message);
1285
1204
  }
1286
1205
  else {
1287
- _debugExtMsg("throw" + (severity === LoggingSeverity.CRITICAL ? "Critical" : "Warning"), message);
1206
+ _debugExtMsg("throw" + (severity === 1 ? "Critical" : "Warning"), message);
1288
1207
  }
1289
1208
  }
1290
1209
  };
@@ -1316,13 +1235,13 @@ this.Microsoft = this.Microsoft || {};
1316
1235
  if (severity <= _self.telemetryLoggingLevel()) {
1317
1236
  _self.queue.push(message);
1318
1237
  _messageCount++;
1319
- _debugExtMsg((severity === LoggingSeverity.CRITICAL ? "error" : "warn"), message);
1238
+ _debugExtMsg((severity === 1 ? "error" : "warn"), message);
1320
1239
  }
1321
1240
  if (_messageCount === _self.maxInternalMessageLimit()) {
1322
1241
  var throttleLimitMessage = "Internal events throttle limit per PageView reached for this app.";
1323
- var throttleMessage = new _InternalLogMessage(_InternalMessageId.MessageLimitPerPVExceeded, throttleLimitMessage, false);
1242
+ var throttleMessage = new _InternalLogMessage(23 , throttleLimitMessage, false);
1324
1243
  _self.queue.push(throttleMessage);
1325
- if (severity === LoggingSeverity.CRITICAL) {
1244
+ if (severity === 1 ) {
1326
1245
  _self.errorToConsole(throttleLimitMessage);
1327
1246
  }
1328
1247
  else {
@@ -1496,6 +1415,217 @@ this.Microsoft = this.Microsoft || {};
1496
1415
  return _defaultPerfManager;
1497
1416
  }
1498
1417
 
1418
+ var UInt32Mask = 0x100000000;
1419
+ var MaxUInt32 = 0xffffffff;
1420
+ var _mwcSeeded = false;
1421
+ var _mwcW = 123456789;
1422
+ var _mwcZ = 987654321;
1423
+ function _mwcSeed(seedValue) {
1424
+ if (seedValue < 0) {
1425
+ seedValue >>>= 0;
1426
+ }
1427
+ _mwcW = (123456789 + seedValue) & MaxUInt32;
1428
+ _mwcZ = (987654321 - seedValue) & MaxUInt32;
1429
+ _mwcSeeded = true;
1430
+ }
1431
+ function _autoSeedMwc() {
1432
+ try {
1433
+ var now = dateNow() & 0x7fffffff;
1434
+ _mwcSeed(((Math.random() * UInt32Mask) ^ now) + now);
1435
+ }
1436
+ catch (e) {
1437
+ }
1438
+ }
1439
+ function randomValue(maxValue) {
1440
+ if (maxValue > 0) {
1441
+ return Math.floor((random32() / MaxUInt32) * (maxValue + 1)) >>> 0;
1442
+ }
1443
+ return 0;
1444
+ }
1445
+ function random32(signed) {
1446
+ var value = 0;
1447
+ var c = getCrypto() || getMsCrypto();
1448
+ if (c && c.getRandomValues) {
1449
+ value = c.getRandomValues(new Uint32Array(1))[0] & MaxUInt32;
1450
+ }
1451
+ if (value === 0 && isIE()) {
1452
+ if (!_mwcSeeded) {
1453
+ _autoSeedMwc();
1454
+ }
1455
+ value = mwcRandom32() & MaxUInt32;
1456
+ }
1457
+ if (value === 0) {
1458
+ value = Math.floor((UInt32Mask * Math.random()) | 0);
1459
+ }
1460
+ if (!signed) {
1461
+ value >>>= 0;
1462
+ }
1463
+ return value;
1464
+ }
1465
+ function mwcRandomSeed(value) {
1466
+ if (!value) {
1467
+ _autoSeedMwc();
1468
+ }
1469
+ else {
1470
+ _mwcSeed(value);
1471
+ }
1472
+ }
1473
+ function mwcRandom32(signed) {
1474
+ _mwcZ = (36969 * (_mwcZ & 0xFFFF) + (_mwcZ >> 16)) & MaxUInt32;
1475
+ _mwcW = (18000 * (_mwcW & 0xFFFF) + (_mwcW >> 16)) & MaxUInt32;
1476
+ var value = (((_mwcZ << 16) + (_mwcW & 0xFFFF)) >>> 0) & MaxUInt32 | 0;
1477
+ if (!signed) {
1478
+ value >>>= 0;
1479
+ }
1480
+ return value;
1481
+ }
1482
+ function newId(maxLength) {
1483
+ if (maxLength === void 0) { maxLength = 22; }
1484
+ var base64chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
1485
+ var number = random32() >>> 0;
1486
+ var chars = 0;
1487
+ var result = strEmpty$1;
1488
+ while (result.length < maxLength) {
1489
+ chars++;
1490
+ result += base64chars.charAt(number & 0x3F);
1491
+ number >>>= 6;
1492
+ if (chars === 5) {
1493
+ number = (((random32() << 2) & 0xFFFFFFFF) | (number & 0x03)) >>> 0;
1494
+ chars = 0;
1495
+ }
1496
+ }
1497
+ return result;
1498
+ }
1499
+
1500
+ var _objDefineProperty = ObjDefineProperty;
1501
+ var version = "2.7.3";
1502
+ var instanceName = "." + newId(6);
1503
+ var _dataUid = 0;
1504
+ function _createAccessor(target, prop, value) {
1505
+ if (_objDefineProperty) {
1506
+ try {
1507
+ _objDefineProperty(target, prop, {
1508
+ value: value,
1509
+ enumerable: false,
1510
+ configurable: true
1511
+ });
1512
+ return true;
1513
+ }
1514
+ catch (e) {
1515
+ }
1516
+ }
1517
+ return false;
1518
+ }
1519
+ function _canAcceptData(target) {
1520
+ return target.nodeType === 1 || target.nodeType === 9 || !(+target.nodeType);
1521
+ }
1522
+ function _getCache(data, target) {
1523
+ var theCache = target[data.id];
1524
+ if (!theCache) {
1525
+ theCache = {};
1526
+ try {
1527
+ if (_canAcceptData(target)) {
1528
+ if (!_createAccessor(target, data.id, theCache)) {
1529
+ target[data.id] = theCache;
1530
+ }
1531
+ }
1532
+ }
1533
+ catch (e) {
1534
+ }
1535
+ }
1536
+ return theCache;
1537
+ }
1538
+ function createUniqueNamespace(name, includeVersion) {
1539
+ if (includeVersion === void 0) { includeVersion = false; }
1540
+ return normalizeJsName(name + (_dataUid++) + (includeVersion ? "." + version : "") + instanceName);
1541
+ }
1542
+ function createElmNodeData(name) {
1543
+ var data = {
1544
+ id: createUniqueNamespace("_aiData-" + (name || "") + "." + version),
1545
+ accept: function (target) {
1546
+ return _canAcceptData(target);
1547
+ },
1548
+ get: function (target, name, defValue, addDefault) {
1549
+ var theCache = target[data.id];
1550
+ if (!theCache) {
1551
+ if (addDefault) {
1552
+ theCache = _getCache(data, target);
1553
+ theCache[normalizeJsName(name)] = defValue;
1554
+ }
1555
+ return defValue;
1556
+ }
1557
+ return theCache[normalizeJsName(name)];
1558
+ },
1559
+ kill: function (target, name) {
1560
+ if (target && target[name]) {
1561
+ try {
1562
+ delete target[name];
1563
+ }
1564
+ catch (e) {
1565
+ }
1566
+ }
1567
+ }
1568
+ };
1569
+ return data;
1570
+ }
1571
+
1572
+ var pluginStateData = createElmNodeData("plugin");
1573
+ function _getPluginState(plugin) {
1574
+ return pluginStateData.get(plugin, "state", {}, true);
1575
+ }
1576
+ function initializePlugins(processContext, extensions) {
1577
+ var initPlugins = [];
1578
+ var lastPlugin = null;
1579
+ var proxy = processContext.getNext();
1580
+ var pluginState;
1581
+ while (proxy) {
1582
+ var thePlugin = proxy.getPlugin();
1583
+ if (thePlugin) {
1584
+ if (lastPlugin &&
1585
+ isFunction(lastPlugin[strSetNextPlugin]) &&
1586
+ isFunction(thePlugin[strProcessTelemetry])) {
1587
+ lastPlugin[strSetNextPlugin](thePlugin);
1588
+ }
1589
+ var isInitialized = false;
1590
+ if (isFunction(thePlugin[strIsInitialized])) {
1591
+ isInitialized = thePlugin[strIsInitialized]();
1592
+ }
1593
+ else {
1594
+ pluginState = _getPluginState(thePlugin);
1595
+ isInitialized = pluginState[strIsInitialized];
1596
+ }
1597
+ if (!isInitialized) {
1598
+ initPlugins.push(thePlugin);
1599
+ }
1600
+ lastPlugin = thePlugin;
1601
+ proxy = proxy.getNext();
1602
+ }
1603
+ }
1604
+ arrForEach(initPlugins, function (thePlugin) {
1605
+ var core = processContext.core();
1606
+ thePlugin.initialize(processContext.getCfg(), core, extensions, processContext.getNext());
1607
+ pluginState = _getPluginState(thePlugin);
1608
+ if (!thePlugin[strCore] && !pluginState[strCore]) {
1609
+ pluginState[strCore] = core;
1610
+ }
1611
+ pluginState[strIsInitialized] = true;
1612
+ delete pluginState[strTeardown];
1613
+ });
1614
+ }
1615
+ function sortPlugins(plugins) {
1616
+ return plugins.sort(function (extA, extB) {
1617
+ var result = 0;
1618
+ var bHasProcess = isFunction(extB[strProcessTelemetry]);
1619
+ if (isFunction(extA[strProcessTelemetry])) {
1620
+ result = bHasProcess ? extA[strPriority] - extB[strPriority] : 1;
1621
+ }
1622
+ else if (bHasProcess) {
1623
+ result = -1;
1624
+ }
1625
+ return result;
1626
+ });
1627
+ }
1628
+
1499
1629
  var strTelemetryPluginChain = "TelemetryPluginChain";
1500
1630
  var strHasRunFlags = "_hasRun";
1501
1631
  var strGetTelCtx = "_getTelCtx";
@@ -1509,53 +1639,69 @@ this.Microsoft = this.Microsoft || {};
1509
1639
  }
1510
1640
  return createTelemetryProxyChain([startAt], config, core);
1511
1641
  }
1512
- function createProcessTelemetryContext(telemetryChain, config, core, startAt) {
1642
+ function _createInternalContext(telemetryChain, config, core, startAt) {
1513
1643
  var _nextProxy = null;
1514
- var _onComplete = null;
1515
- if (startAt) {
1516
- _nextProxy = _getNextProxyStart(telemetryChain, config, core, startAt);
1517
- }
1518
- else {
1519
- _nextProxy = telemetryChain;
1644
+ var _onComplete = [];
1645
+ if (startAt !== null) {
1646
+ _nextProxy = startAt ? _getNextProxyStart(telemetryChain, config, core, startAt) : telemetryChain;
1520
1647
  }
1521
1648
  var context = {
1522
- core: function () {
1523
- return core;
1524
- },
1525
- diagLog: function () {
1526
- return safeGetLogger(core, config);
1527
- },
1528
- getCfg: function () {
1529
- return config;
1530
- },
1531
- getExtCfg: _getExtCfg,
1532
- getConfig: _getConfig,
1533
- hasNext: function () {
1534
- return _nextProxy != null;
1535
- },
1536
- getNext: function () {
1537
- return _nextProxy;
1538
- },
1539
- setNext: function (nextPlugin) {
1540
- _nextProxy = nextPlugin;
1541
- },
1542
- processNext: function (env) {
1543
- _processChain(function (nextPlugin) {
1544
- nextPlugin.processTelemetry(env, context);
1649
+ _next: _moveNext,
1650
+ ctx: {
1651
+ core: function () { return core; },
1652
+ diagLog: function () {
1653
+ return safeGetLogger(core, config);
1654
+ },
1655
+ getCfg: function () {
1656
+ return config;
1657
+ },
1658
+ getExtCfg: _getExtCfg,
1659
+ getConfig: _getConfig,
1660
+ hasNext: function () {
1661
+ return !!_nextProxy;
1662
+ },
1663
+ getNext: function () {
1664
+ return _nextProxy;
1665
+ },
1666
+ setNext: function (nextPlugin) {
1667
+ _nextProxy = nextPlugin;
1668
+ },
1669
+ iterate: _iterateChain,
1670
+ onComplete: _addOnComplete
1671
+ }
1672
+ };
1673
+ function _addOnComplete(onComplete, that) {
1674
+ var args = [];
1675
+ for (var _i = 2; _i < arguments.length; _i++) {
1676
+ args[_i - 2] = arguments[_i];
1677
+ }
1678
+ if (onComplete) {
1679
+ _onComplete.push({
1680
+ func: onComplete,
1681
+ self: !isUndefined(that) ? that : context.ctx,
1682
+ args: args
1545
1683
  });
1546
- },
1547
- iterate: _iterateChain,
1548
- createNew: function (plugins, startAt) {
1549
- if (plugins === void 0) { plugins = null; }
1550
- if (isArray(plugins)) {
1551
- plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1684
+ }
1685
+ }
1686
+ function _moveNext() {
1687
+ var nextProxy = _nextProxy;
1688
+ _nextProxy = nextProxy ? nextProxy.getNext() : null;
1689
+ if (!nextProxy) {
1690
+ var onComplete = _onComplete;
1691
+ if (onComplete && onComplete.length > 0) {
1692
+ arrForEach(onComplete, function (completeDetails) {
1693
+ try {
1694
+ completeDetails.func.call(completeDetails.self, completeDetails.args);
1695
+ }
1696
+ catch (e) {
1697
+ core.logger.throwInternal(2 , 73 , "Unexpected Exception during onComplete - " + dumpObj(e));
1698
+ }
1699
+ });
1700
+ _onComplete = [];
1552
1701
  }
1553
- return createProcessTelemetryContext(plugins || _nextProxy, config, core, startAt);
1554
- },
1555
- onComplete: function (onComplete) {
1556
- _onComplete = onComplete;
1557
1702
  }
1558
- };
1703
+ return nextProxy;
1704
+ }
1559
1705
  function _getExtCfg(identifier, defaultValue, mergeDefault) {
1560
1706
  if (defaultValue === void 0) { defaultValue = {}; }
1561
1707
  if (mergeDefault === void 0) { mergeDefault = 0 ; }
@@ -1598,29 +1744,53 @@ this.Microsoft = this.Microsoft || {};
1598
1744
  }
1599
1745
  return !isNullOrUndefined(theValue) ? theValue : defaultValue;
1600
1746
  }
1601
- function _processChain(cb) {
1602
- var nextPlugin = _nextProxy;
1603
- if (nextPlugin) {
1604
- _nextProxy = nextPlugin.getNext();
1605
- cb(nextPlugin);
1606
- }
1607
- else {
1608
- if (_onComplete) {
1609
- _onComplete();
1610
- _onComplete = null;
1747
+ function _iterateChain(cb) {
1748
+ var nextPlugin;
1749
+ while (!!(nextPlugin = context._next())) {
1750
+ var plugin = nextPlugin.getPlugin();
1751
+ if (plugin) {
1752
+ cb(plugin);
1611
1753
  }
1612
1754
  }
1613
1755
  }
1614
- function _iterateChain(cb) {
1615
- while (_nextProxy) {
1616
- _processChain(function (nextPlugin) {
1617
- var plugin = nextPlugin.getPlugin();
1618
- if (plugin) {
1619
- cb(plugin);
1620
- }
1621
- });
1756
+ return context;
1757
+ }
1758
+ function createProcessTelemetryContext(telemetryChain, config, core, startAt) {
1759
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1760
+ var context = internalContext.ctx;
1761
+ function _processNext(env) {
1762
+ var nextPlugin = internalContext._next();
1763
+ nextPlugin && nextPlugin.processTelemetry(env, context);
1764
+ return !nextPlugin;
1765
+ }
1766
+ function _createNew(plugins, startAt) {
1767
+ if (plugins === void 0) { plugins = null; }
1768
+ if (isArray(plugins)) {
1769
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1770
+ }
1771
+ return createProcessTelemetryContext(plugins || context.getNext(), config, core, startAt);
1772
+ }
1773
+ context.processNext = _processNext;
1774
+ context.createNew = _createNew;
1775
+ return context;
1776
+ }
1777
+ function createProcessTelemetryUnloadContext(telemetryChain, config, core, startAt) {
1778
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1779
+ var context = internalContext.ctx;
1780
+ function _processNext(unloadState) {
1781
+ var nextPlugin = internalContext._next();
1782
+ nextPlugin && nextPlugin.unload(context, unloadState);
1783
+ return !nextPlugin;
1784
+ }
1785
+ function _createNew(plugins, startAt) {
1786
+ if (plugins === void 0) { plugins = null; }
1787
+ if (isArray(plugins)) {
1788
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1622
1789
  }
1790
+ return createProcessTelemetryUnloadContext(plugins || context.getNext(), config, core, startAt);
1623
1791
  }
1792
+ context.processNext = _processNext;
1793
+ context.createNew = _createNew;
1624
1794
  return context;
1625
1795
  }
1626
1796
  function createTelemetryProxyChain(plugins, config, core, startAt) {
@@ -1668,32 +1838,35 @@ this.Microsoft = this.Microsoft || {};
1668
1838
  return nextProxy;
1669
1839
  },
1670
1840
  processTelemetry: _processTelemetry,
1841
+ unload: _unloadPlugin,
1671
1842
  _id: chainId,
1672
1843
  _setNext: function (nextPlugin) {
1673
1844
  nextProxy = nextPlugin;
1674
1845
  }
1675
1846
  };
1676
- function _processChain(itemCtx, processPluginFn, processProxyFn, name, details, isAsync) {
1847
+ function _getTelCtx() {
1848
+ var itemCtx;
1849
+ if (plugin && isFunction(plugin[strGetTelCtx])) {
1850
+ itemCtx = plugin[strGetTelCtx]();
1851
+ }
1677
1852
  if (!itemCtx) {
1678
- if (plugin && isFunction(plugin[strGetTelCtx])) {
1679
- itemCtx = plugin[strGetTelCtx]();
1680
- }
1681
- if (!itemCtx) {
1682
- itemCtx = createProcessTelemetryContext(proxyChain, config, core);
1683
- }
1853
+ itemCtx = createProcessTelemetryContext(proxyChain, config, core);
1684
1854
  }
1855
+ return itemCtx;
1856
+ }
1857
+ function _processChain(itemCtx, processPluginFn, name, details, isAsync) {
1858
+ var hasRun = false;
1685
1859
  var identifier = plugin ? plugin.identifier : strTelemetryPluginChain;
1686
1860
  var hasRunContext = itemCtx[strHasRunFlags];
1687
1861
  if (!hasRunContext) {
1688
1862
  hasRunContext = itemCtx[strHasRunFlags] = {};
1689
1863
  }
1690
- doPerf(itemCtx.core(), function () { return identifier + ":" + name; }, function () {
1691
- hasRunContext[chainId] = true;
1692
- var hasRun = false;
1693
- itemCtx.setNext(nextProxy);
1694
- if (plugin) {
1864
+ itemCtx.setNext(nextProxy);
1865
+ if (plugin) {
1866
+ doPerf(itemCtx[strCore](), function () { return identifier + ":" + name; }, function () {
1867
+ hasRunContext[chainId] = true;
1695
1868
  try {
1696
- var nextId = nextProxy ? nextProxy._id : "";
1869
+ var nextId = nextProxy ? nextProxy._id : strEmpty$1;
1697
1870
  if (nextId) {
1698
1871
  hasRunContext[nextId] = false;
1699
1872
  }
@@ -1705,18 +1878,21 @@ this.Microsoft = this.Microsoft || {};
1705
1878
  hasRun = true;
1706
1879
  }
1707
1880
  if (!nextProxy || !hasNextRun) {
1708
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.PluginException, "Plugin [" + plugin.identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
1881
+ itemCtx.diagLog().throwInternal(1 , 73 , "Plugin [" + plugin.identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
1709
1882
  }
1710
1883
  }
1711
- }
1712
- if (nextProxy && !hasRun) {
1713
- processProxyFn(itemCtx);
1714
- }
1715
- }, details, isAsync);
1884
+ }, details, isAsync);
1885
+ }
1886
+ return hasRun;
1716
1887
  }
1717
1888
  function _processTelemetry(env, itemCtx) {
1718
- _processChain(itemCtx, function (itemCtx) {
1719
- if (!hasProcessTelemetry) {
1889
+ itemCtx = itemCtx || _getTelCtx();
1890
+ function _callProcessTelemetry(itemCtx) {
1891
+ if (!plugin || !hasProcessTelemetry) {
1892
+ return false;
1893
+ }
1894
+ var pluginState = _getPluginState(plugin);
1895
+ if (pluginState[strTeardown] || pluginState[strDisabled]) {
1720
1896
  return false;
1721
1897
  }
1722
1898
  if (hasSetNext) {
@@ -1724,52 +1900,33 @@ this.Microsoft = this.Microsoft || {};
1724
1900
  }
1725
1901
  plugin.processTelemetry(env, itemCtx);
1726
1902
  return true;
1727
- }, function (itemCtx) {
1728
- nextProxy.processTelemetry(env, itemCtx);
1729
- }, "processTelemetry", function () { return ({ item: env }); }, !(env.sync));
1730
- }
1731
- return objFreeze(proxyChain);
1732
- }
1733
-
1734
- var processTelemetry = "processTelemetry";
1735
- var priority = "priority";
1736
- var setNextPlugin = "setNextPlugin";
1737
- var isInitialized = "isInitialized";
1738
- function initializePlugins(processContext, extensions) {
1739
- var initPlugins = [];
1740
- var lastPlugin = null;
1741
- var proxy = processContext.getNext();
1742
- while (proxy) {
1743
- var thePlugin = proxy.getPlugin();
1744
- if (thePlugin) {
1745
- if (lastPlugin &&
1746
- isFunction(lastPlugin[setNextPlugin]) &&
1747
- isFunction(thePlugin[processTelemetry])) {
1748
- lastPlugin[setNextPlugin](thePlugin);
1749
- }
1750
- if (!isFunction(thePlugin[isInitialized]) || !thePlugin[isInitialized]()) {
1751
- initPlugins.push(thePlugin);
1752
- }
1753
- lastPlugin = thePlugin;
1754
- proxy = proxy.getNext();
1903
+ }
1904
+ if (!_processChain(itemCtx, _callProcessTelemetry, "processTelemetry", function () { return ({ item: env }); }, !(env.sync))) {
1905
+ itemCtx.processNext(env);
1755
1906
  }
1756
1907
  }
1757
- arrForEach(initPlugins, function (thePlugin) {
1758
- thePlugin.initialize(processContext.getCfg(), processContext.core(), extensions, processContext.getNext());
1759
- });
1760
- }
1761
- function sortPlugins(plugins) {
1762
- return plugins.sort(function (extA, extB) {
1763
- var result = 0;
1764
- var bHasProcess = isFunction(extB[processTelemetry]);
1765
- if (isFunction(extA[processTelemetry])) {
1766
- result = bHasProcess ? extA[priority] - extB[priority] : 1;
1908
+ function _unloadPlugin(unloadCtx, unloadState) {
1909
+ function _callTeardown() {
1910
+ var hasRun = false;
1911
+ if (plugin) {
1912
+ var pluginState = _getPluginState(plugin);
1913
+ var pluginCore = plugin[strCore] || pluginState.core;
1914
+ if (plugin && (!pluginCore || pluginCore === unloadCtx[strCore]()) && !pluginState[strTeardown]) {
1915
+ pluginState[strCore] = null;
1916
+ pluginState[strTeardown] = true;
1917
+ pluginState[strIsInitialized] = false;
1918
+ if (plugin[strTeardown] && plugin[strTeardown](unloadCtx, unloadState) === true) {
1919
+ hasRun = true;
1920
+ }
1921
+ }
1922
+ }
1923
+ return hasRun;
1767
1924
  }
1768
- else if (bHasProcess) {
1769
- result = -1;
1925
+ if (!_processChain(unloadCtx, _callTeardown, "unload", function () { }, unloadState.isAsync)) {
1926
+ unloadCtx.processNext(unloadState);
1770
1927
  }
1771
- return result;
1772
- });
1928
+ }
1929
+ return objFreeze(proxyChain);
1773
1930
  }
1774
1931
 
1775
1932
  var strToGMTString = "toGMTString";
@@ -1780,7 +1937,6 @@ this.Microsoft = this.Microsoft || {};
1780
1937
  var strIsCookieUseDisabled = "isCookieUseDisabled";
1781
1938
  var strDisableCookiesUsage = "disableCookiesUsage";
1782
1939
  var strConfigCookieMgr = "_ckMgr";
1783
- var strEmpty = "";
1784
1940
  var _supportsCookies = null;
1785
1941
  var _allowUaSameSite = null;
1786
1942
  var _parsedCookieValue = null;
@@ -1857,7 +2013,7 @@ this.Microsoft = this.Microsoft || {};
1857
2013
  var result = false;
1858
2014
  if (_isMgrEnabled(cookieMgr)) {
1859
2015
  var values = {};
1860
- var theValue = strTrim(value || strEmpty);
2016
+ var theValue = strTrim(value || strEmpty$1);
1861
2017
  var idx = theValue.indexOf(";");
1862
2018
  if (idx !== -1) {
1863
2019
  theValue = strTrim(value.substring(0, idx));
@@ -1872,11 +2028,11 @@ this.Microsoft = this.Microsoft || {};
1872
2028
  if (expireMs > 0) {
1873
2029
  var expiry = new Date();
1874
2030
  expiry.setTime(expireMs);
1875
- setValue(values, strExpires, _formatDate(expiry, !_isIE ? strToUTCString : strToGMTString) || _formatDate(expiry, _isIE ? strToGMTString : strToUTCString) || strEmpty, isTruthy);
2031
+ setValue(values, strExpires, _formatDate(expiry, !_isIE ? strToUTCString : strToGMTString) || _formatDate(expiry, _isIE ? strToGMTString : strToUTCString) || strEmpty$1, isTruthy);
1876
2032
  }
1877
2033
  }
1878
2034
  if (!_isIE) {
1879
- setValue(values, "max-age", strEmpty + maxAgeSec, null, isUndefined);
2035
+ setValue(values, "max-age", strEmpty$1 + maxAgeSec, null, isUndefined);
1880
2036
  }
1881
2037
  }
1882
2038
  var location_1 = getLocation();
@@ -1897,7 +2053,7 @@ this.Microsoft = this.Microsoft || {};
1897
2053
  return result;
1898
2054
  },
1899
2055
  get: function (name) {
1900
- var value = strEmpty;
2056
+ var value = strEmpty$1;
1901
2057
  if (_isMgrEnabled(cookieMgr)) {
1902
2058
  value = (cookieMgrConfig.getCookie || _getCookieValue)(name);
1903
2059
  }
@@ -1922,7 +2078,7 @@ this.Microsoft = this.Microsoft || {};
1922
2078
  values["max-age"] = "0";
1923
2079
  }
1924
2080
  var delCookie = cookieMgrConfig.delCookie || _setCookieValue;
1925
- delCookie(name, _formatCookieValue(strEmpty, values));
2081
+ delCookie(name, _formatCookieValue(strEmpty$1, values));
1926
2082
  result = true;
1927
2083
  }
1928
2084
  return result;
@@ -1939,7 +2095,7 @@ this.Microsoft = this.Microsoft || {};
1939
2095
  _supportsCookies = doc[strCookie] !== undefined;
1940
2096
  }
1941
2097
  catch (e) {
1942
- logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.CannotAccessCookie, "Cannot access document.cookie - " + getExceptionName(e), { exception: dumpObj(e) });
2098
+ logger && logger.throwInternal(2 , 68 , "Cannot access document.cookie - " + getExceptionName(e), { exception: dumpObj(e) });
1943
2099
  }
1944
2100
  }
1945
2101
  return _supportsCookies;
@@ -1949,7 +2105,7 @@ this.Microsoft = this.Microsoft || {};
1949
2105
  if (theValue && theValue.length) {
1950
2106
  var parts = strTrim(theValue).split(";");
1951
2107
  arrForEach(parts, function (thePart) {
1952
- thePart = strTrim(thePart || strEmpty);
2108
+ thePart = strTrim(thePart || strEmpty$1);
1953
2109
  if (thePart) {
1954
2110
  var idx = thePart.indexOf("=");
1955
2111
  if (idx === -1) {
@@ -1970,21 +2126,21 @@ this.Microsoft = this.Microsoft || {};
1970
2126
  return null;
1971
2127
  }
1972
2128
  function _formatCookieValue(value, values) {
1973
- var cookieValue = value || strEmpty;
2129
+ var cookieValue = value || strEmpty$1;
1974
2130
  objForEachKey(values, function (name, theValue) {
1975
- cookieValue += "; " + name + (!isNullOrUndefined(theValue) ? "=" + theValue : strEmpty);
2131
+ cookieValue += "; " + name + (!isNullOrUndefined(theValue) ? "=" + theValue : strEmpty$1);
1976
2132
  });
1977
2133
  return cookieValue;
1978
2134
  }
1979
2135
  function _getCookieValue(name) {
1980
- var cookieValue = strEmpty;
2136
+ var cookieValue = strEmpty$1;
1981
2137
  if (_doc) {
1982
- var theCookie = _doc[strCookie] || strEmpty;
2138
+ var theCookie = _doc[strCookie] || strEmpty$1;
1983
2139
  if (_parsedCookieValue !== theCookie) {
1984
2140
  _cookieCache = _extractParts(theCookie);
1985
2141
  _parsedCookieValue = theCookie;
1986
2142
  }
1987
- cookieValue = strTrim(_cookieCache[name] || strEmpty);
2143
+ cookieValue = strTrim(_cookieCache[name] || strEmpty$1);
1988
2144
  }
1989
2145
  return cookieValue;
1990
2146
  }
@@ -2040,87 +2196,110 @@ this.Microsoft = this.Microsoft || {};
2040
2196
  }
2041
2197
  }
2042
2198
  function createChannelControllerPlugin(channelQueue, core) {
2043
- function _getTelCtx(itemCtx) {
2044
- if (!itemCtx) {
2045
- itemCtx = createProcessTelemetryContext(null, core.config, core, null);
2199
+ var _a;
2200
+ function _getTelCtx() {
2201
+ return createProcessTelemetryContext(null, core.config, core, null);
2202
+ }
2203
+ function _processChannelQueue(theChannels, itemCtx, processFn, onComplete) {
2204
+ var waiting = theChannels ? (theChannels.length + 1) : 1;
2205
+ function _runChainOnComplete() {
2206
+ waiting--;
2207
+ if (waiting === 0) {
2208
+ onComplete && onComplete();
2209
+ onComplete = null;
2210
+ }
2046
2211
  }
2047
- return itemCtx;
2212
+ if (waiting > 0) {
2213
+ arrForEach(theChannels, function (channels) {
2214
+ if (channels && channels.queue.length > 0) {
2215
+ var channelChain = channels.chain;
2216
+ var chainCtx = itemCtx.createNew(channelChain);
2217
+ chainCtx.onComplete(_runChainOnComplete);
2218
+ processFn(chainCtx);
2219
+ }
2220
+ else {
2221
+ waiting--;
2222
+ }
2223
+ });
2224
+ }
2225
+ _runChainOnComplete();
2226
+ }
2227
+ function _doTeardown(unloadCtx, unloadState) {
2228
+ var theUnloadState = unloadState || {
2229
+ reason: 0 ,
2230
+ isAsync: false
2231
+ };
2232
+ _processChannelQueue(channelQueue, unloadCtx, function (chainCtx) {
2233
+ chainCtx[strProcessNext](theUnloadState);
2234
+ }, function () {
2235
+ unloadCtx[strProcessNext](theUnloadState);
2236
+ isInitialized = false;
2237
+ });
2238
+ return true;
2048
2239
  }
2049
- function _processChannelQueue(itemCtx, processFn, onComplete) {
2240
+ function _getChannel(pluginIdentifier) {
2241
+ var thePlugin = null;
2050
2242
  if (channelQueue && channelQueue.length > 0) {
2051
- var waiting_1 = channelQueue.length;
2052
2243
  arrForEach(channelQueue, function (channels) {
2053
2244
  if (channels && channels.queue.length > 0) {
2054
- var channelChain = channels.chain;
2055
- var chainCtx = _getTelCtx(itemCtx).createNew(channelChain);
2056
- chainCtx.onComplete(function () {
2057
- waiting_1--;
2058
- if (waiting_1 === 0) {
2059
- onComplete && onComplete();
2060
- onComplete = null;
2245
+ arrForEach(channels.queue, function (ext) {
2246
+ if (ext.identifier === pluginIdentifier) {
2247
+ thePlugin = ext;
2248
+ return -1;
2061
2249
  }
2062
2250
  });
2063
- processFn(chainCtx);
2064
- }
2065
- else {
2066
- waiting_1--;
2251
+ if (thePlugin) {
2252
+ return -1;
2253
+ }
2067
2254
  }
2068
2255
  });
2069
- if (waiting_1 === 0) {
2070
- onComplete && onComplete();
2071
- }
2072
- }
2073
- else {
2074
- onComplete && onComplete();
2075
2256
  }
2257
+ return thePlugin;
2076
2258
  }
2077
2259
  var isInitialized = false;
2078
- var channelController = {
2079
- identifier: "ChannelControllerPlugin",
2080
- priority: ChannelControllerPriority,
2081
- initialize: function (config, core, extensions, pluginChain) {
2082
- isInitialized = true;
2083
- arrForEach(channelQueue, function (channels) {
2084
- if (channels && channels.queue.length > 0) {
2085
- initializePlugins(createProcessTelemetryContext(channels.chain, config, core), extensions);
2086
- }
2087
- });
2088
- },
2089
- isInitialized: function () { return isInitialized; },
2090
- processTelemetry: function (item, itemCtx) {
2091
- _processChannelQueue(itemCtx, function (chainCtx) {
2092
- chainCtx.processNext(item);
2093
- }, function () {
2094
- itemCtx.processNext(item);
2095
- });
2096
- },
2097
- pause: function () {
2098
- _processChannelQueue(null, function (chainCtx) {
2099
- chainCtx.iterate(function (plugin) {
2100
- plugin.pause && plugin.pause();
2260
+ var channelController = (_a = {
2261
+ identifier: "ChannelControllerPlugin",
2262
+ priority: ChannelControllerPriority,
2263
+ initialize: function (config, core, extensions, pluginChain) {
2264
+ isInitialized = true;
2265
+ arrForEach(channelQueue, function (channels) {
2266
+ if (channels && channels.queue.length > 0) {
2267
+ initializePlugins(createProcessTelemetryContext(channels.chain, config, core), extensions);
2268
+ }
2101
2269
  });
2102
- });
2270
+ },
2271
+ isInitialized: function () { return isInitialized; },
2272
+ processTelemetry: function (item, itemCtx) {
2273
+ _processChannelQueue(channelQueue, itemCtx || _getTelCtx(), function (chainCtx) {
2274
+ chainCtx[strProcessNext](item);
2275
+ }, function () {
2276
+ itemCtx[strProcessNext](item);
2277
+ });
2278
+ }
2103
2279
  },
2104
- resume: function () {
2105
- _processChannelQueue(null, function (chainCtx) {
2280
+ _a[strPause] = function () {
2281
+ _processChannelQueue(channelQueue, _getTelCtx(), function (chainCtx) {
2106
2282
  chainCtx.iterate(function (plugin) {
2107
- plugin.resume && plugin.resume();
2283
+ plugin[strPause] && plugin[strPause]();
2108
2284
  });
2109
- });
2285
+ }, null);
2110
2286
  },
2111
- teardown: function () {
2112
- _processChannelQueue(null, function (chainCtx) {
2287
+ _a[strResume] = function () {
2288
+ _processChannelQueue(channelQueue, _getTelCtx(), function (chainCtx) {
2113
2289
  chainCtx.iterate(function (plugin) {
2114
- plugin.teardown && plugin.teardown();
2290
+ plugin[strResume] && plugin[strResume]();
2115
2291
  });
2116
- });
2292
+ }, null);
2117
2293
  },
2118
- flush: function (isAsync, callBack, sendReason, cbTimeout) {
2294
+ _a[strTeardown] = _doTeardown,
2295
+ _a.getChannel = _getChannel,
2296
+ _a.flush = function (isAsync, callBack, sendReason, cbTimeout) {
2297
+ var waiting = 1;
2119
2298
  var doneIterating = false;
2120
- var waiting = 0;
2121
2299
  var cbTimer = null;
2122
2300
  cbTimeout = cbTimeout || 5000;
2123
2301
  function doCallback() {
2302
+ waiting--;
2124
2303
  if (doneIterating && waiting === 0) {
2125
2304
  if (cbTimer) {
2126
2305
  clearTimeout(cbTimer);
@@ -2130,32 +2309,38 @@ this.Microsoft = this.Microsoft || {};
2130
2309
  callBack = null;
2131
2310
  }
2132
2311
  }
2133
- waiting = 1;
2134
- _processChannelQueue(null, function (chainCtx) {
2312
+ _processChannelQueue(channelQueue, _getTelCtx(), function (chainCtx) {
2135
2313
  chainCtx.iterate(function (plugin) {
2136
2314
  if (plugin.flush) {
2137
2315
  waiting++;
2316
+ var handled_1 = false;
2138
2317
  if (!plugin.flush(isAsync, function () {
2139
- waiting--;
2318
+ handled_1 = true;
2140
2319
  doCallback();
2141
2320
  }, sendReason)) {
2142
- if (cbTimer == null) {
2143
- cbTimer = setTimeout(function () {
2144
- cbTimer = null;
2145
- callBack && callBack(false);
2146
- callBack = null;
2147
- }, cbTimeout);
2321
+ if (!handled_1) {
2322
+ if (isAsync && cbTimer == null) {
2323
+ cbTimer = setTimeout(function () {
2324
+ cbTimer = null;
2325
+ doCallback();
2326
+ }, cbTimeout);
2327
+ }
2328
+ else {
2329
+ doCallback();
2330
+ }
2148
2331
  }
2149
2332
  }
2150
2333
  }
2151
2334
  });
2152
2335
  }, function () {
2153
- waiting--;
2154
2336
  doneIterating = true;
2155
2337
  doCallback();
2156
2338
  });
2157
- }
2158
- };
2339
+ },
2340
+ _a._setQueue = function (queue) {
2341
+ channelQueue = queue;
2342
+ },
2343
+ _a);
2159
2344
  return channelController;
2160
2345
  }
2161
2346
  function createChannelQueues(channels, extensions, config, core) {
@@ -2175,6 +2360,30 @@ this.Microsoft = this.Microsoft || {};
2175
2360
  return channelQueue;
2176
2361
  }
2177
2362
 
2363
+ function createUnloadHandlerContainer() {
2364
+ var handlers = [];
2365
+ function _addHandler(handler) {
2366
+ if (handler) {
2367
+ handlers.push(handler);
2368
+ }
2369
+ }
2370
+ function _runHandlers(unloadCtx, unloadState) {
2371
+ arrForEach(handlers, function (handler) {
2372
+ try {
2373
+ handler(unloadCtx, unloadState);
2374
+ }
2375
+ catch (e) {
2376
+ unloadCtx.diagLog().throwInternal(2 , 73 , "Unexpected error calling unload handler - " + dumpObj(e));
2377
+ }
2378
+ });
2379
+ handlers = [];
2380
+ }
2381
+ return {
2382
+ add: _addHandler,
2383
+ run: _runHandlers
2384
+ };
2385
+ }
2386
+
2178
2387
  var strGetPlugin = "getPlugin";
2179
2388
  var BaseTelemetryPlugin = /** @class */ (function () {
2180
2389
  function BaseTelemetryPlugin() {
@@ -2182,6 +2391,7 @@ this.Microsoft = this.Microsoft || {};
2182
2391
  var _isinitialized;
2183
2392
  var _rootCtx;
2184
2393
  var _nextPlugin;
2394
+ var _unloadHandlerContainer;
2185
2395
  var _hooks;
2186
2396
  _initDefaults();
2187
2397
  dynamicProto(BaseTelemetryPlugin, _self, function (_self) {
@@ -2189,6 +2399,39 @@ this.Microsoft = this.Microsoft || {};
2189
2399
  _setDefaults(config, core, pluginChain);
2190
2400
  _isinitialized = true;
2191
2401
  };
2402
+ _self.teardown = function (unloadCtx, unloadState) {
2403
+ if (!_self.core || (unloadCtx && _self.core !== unloadCtx.core())) {
2404
+ return;
2405
+ }
2406
+ var result;
2407
+ var unloadDone = false;
2408
+ var theUnloadCtx = unloadCtx || createProcessTelemetryUnloadContext(null, {}, _self.core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
2409
+ var theUnloadState = unloadState || {
2410
+ reason: 0 ,
2411
+ isAsync: false
2412
+ };
2413
+ function _unloadCallback() {
2414
+ if (!unloadDone) {
2415
+ unloadDone = true;
2416
+ _unloadHandlerContainer.run(theUnloadCtx, unloadState);
2417
+ arrForEach(_hooks, function (fn) {
2418
+ fn.rm();
2419
+ });
2420
+ _hooks = [];
2421
+ if (result === true) {
2422
+ theUnloadCtx.processNext(theUnloadState);
2423
+ }
2424
+ _initDefaults();
2425
+ }
2426
+ }
2427
+ if (!_self[strDoTeardown] || _self[strDoTeardown](theUnloadCtx, theUnloadState, _unloadCallback) !== true) {
2428
+ _unloadCallback();
2429
+ }
2430
+ else {
2431
+ result = true;
2432
+ }
2433
+ return result;
2434
+ };
2192
2435
  _self._addHook = function (hooks) {
2193
2436
  if (hooks) {
2194
2437
  if (isArray(hooks)) {
@@ -2199,17 +2442,18 @@ this.Microsoft = this.Microsoft || {};
2199
2442
  }
2200
2443
  }
2201
2444
  };
2445
+ proxyFunctionAs(_self, "_addUnloadCb", function () { return _unloadHandlerContainer; }, "add");
2202
2446
  });
2203
2447
  _self.diagLog = function (itemCtx) {
2204
2448
  return _getTelCtx(itemCtx).diagLog();
2205
2449
  };
2206
- _self.isInitialized = function () {
2450
+ _self[strIsInitialized] = function () {
2207
2451
  return _isinitialized;
2208
2452
  };
2209
2453
  _self.setInitialized = function (isInitialized) {
2210
2454
  _isinitialized = isInitialized;
2211
2455
  };
2212
- _self.setNextPlugin = function (next) {
2456
+ _self[strSetNextPlugin] = function (next) {
2213
2457
  _nextPlugin = next;
2214
2458
  };
2215
2459
  _self.processNext = function (env, itemCtx) {
@@ -2255,6 +2499,7 @@ this.Microsoft = this.Microsoft || {};
2255
2499
  _rootCtx = null;
2256
2500
  _nextPlugin = null;
2257
2501
  _hooks = [];
2502
+ _unloadHandlerContainer = createUnloadHandlerContainer();
2258
2503
  }
2259
2504
  }
2260
2505
  return BaseTelemetryPlugin;
@@ -2301,7 +2546,7 @@ this.Microsoft = this.Microsoft || {};
2301
2546
  }
2302
2547
  }
2303
2548
  catch (e) {
2304
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TelemetryInitializerFailed, "One of telemetry initializers failed, telemetry item will not be sent: " + getExceptionName(e), { exception: dumpObj(e) }, true);
2549
+ itemCtx.diagLog().throwInternal(1 , 64 , "One of telemetry initializers failed, telemetry item will not be sent: " + getExceptionName(e), { exception: dumpObj(e) }, true);
2305
2550
  }
2306
2551
  }
2307
2552
  }
@@ -2309,8 +2554,7 @@ this.Microsoft = this.Microsoft || {};
2309
2554
  _self.processNext(item, itemCtx);
2310
2555
  }
2311
2556
  };
2312
- _self.unload = function (itemCtx, isAsync) {
2313
- _base.unload(itemCtx, isAsync);
2557
+ _self[strDoTeardown] = function () {
2314
2558
  _initDefaults();
2315
2559
  };
2316
2560
  });
@@ -2325,6 +2569,8 @@ this.Microsoft = this.Microsoft || {};
2325
2569
 
2326
2570
  var strValidationError = "Plugins must provide initialize method";
2327
2571
  var strNotificationManager = "_notificationManager";
2572
+ var strSdkUnloadingError = "SDK is still unloading...";
2573
+ var strSdkNotInitialized = "SDK is not initialized";
2328
2574
  function _createPerfManager(core, notificationMgr) {
2329
2575
  return new PerfManager(notificationMgr);
2330
2576
  }
@@ -2354,6 +2600,26 @@ this.Microsoft = this.Microsoft || {};
2354
2600
  core: coreExtensions
2355
2601
  };
2356
2602
  }
2603
+ function _isPluginPresent(thePlugin, plugins) {
2604
+ var exists = false;
2605
+ arrForEach(plugins, function (plugin) {
2606
+ if (plugin === thePlugin) {
2607
+ exists = true;
2608
+ return -1;
2609
+ }
2610
+ });
2611
+ return exists;
2612
+ }
2613
+ function _createDummyNotificationManager() {
2614
+ var _a;
2615
+ return objCreateFn((_a = {},
2616
+ _a[strAddNotificationListener] = function (listener) { },
2617
+ _a[strRemoveNotificationListener] = function (listener) { },
2618
+ _a[strEventsSent] = function (events) { },
2619
+ _a[strEventsDiscarded] = function (events, reason) { },
2620
+ _a[strEventsSendRequest] = function (sendReason, isAsync) { },
2621
+ _a));
2622
+ }
2357
2623
  var BaseCore = /** @class */ (function () {
2358
2624
  function BaseCore() {
2359
2625
  var _isInitialized;
@@ -2368,14 +2634,20 @@ this.Microsoft = this.Microsoft || {};
2368
2634
  var _channelControl;
2369
2635
  var _channelConfig;
2370
2636
  var _channelQueue;
2637
+ var _isUnloading;
2371
2638
  var _telemetryInitializerPlugin;
2372
2639
  var _internalLogsEventName;
2640
+ var _evtNamespace;
2641
+ var _unloadHandlers;
2373
2642
  var _debugListener;
2374
2643
  var _internalLogPoller = 0;
2375
2644
  dynamicProto(BaseCore, this, function (_self) {
2376
2645
  _initDefaults();
2377
2646
  _self.isInitialized = function () { return _isInitialized; };
2378
2647
  _self.initialize = function (config, extensions, logger, notificationManager) {
2648
+ if (_isUnloading) {
2649
+ throwError(strSdkUnloadingError);
2650
+ }
2379
2651
  if (_self.isInitialized()) {
2380
2652
  throwError("Core should not be initialized more than once");
2381
2653
  }
@@ -2388,8 +2660,7 @@ this.Microsoft = this.Microsoft || {};
2388
2660
  _initDebugListener(config);
2389
2661
  _initPerfManager(config);
2390
2662
  config.extensions = isNullOrUndefined(config.extensions) ? [] : config.extensions;
2391
- var extConfig = getSetValue(config, strExtensionConfig);
2392
- extConfig.NotificationManager = notificationManager;
2663
+ _initExtConfig(config);
2393
2664
  if (logger) {
2394
2665
  _self.logger = logger;
2395
2666
  }
@@ -2414,37 +2685,29 @@ this.Microsoft = this.Microsoft || {};
2414
2685
  setValue(telemetryItem, strIKey, _self.config.instrumentationKey, null, isNotTruthy);
2415
2686
  setValue(telemetryItem, "time", toISOString(new Date()), null, isNotTruthy);
2416
2687
  setValue(telemetryItem, "ver", "4.0", null, isNullOrUndefined);
2417
- if (_self.isInitialized()) {
2418
- _self.getProcessTelContext().processNext(telemetryItem);
2688
+ if (!_isUnloading && _self.isInitialized()) {
2689
+ _createTelCtx().processNext(telemetryItem);
2419
2690
  }
2420
2691
  else {
2421
2692
  _eventQueue.push(telemetryItem);
2422
2693
  }
2423
2694
  };
2424
- _self.getProcessTelContext = function () {
2425
- return createProcessTelemetryContext(_getPluginChain(), _self.config, _self);
2426
- };
2695
+ _self.getProcessTelContext = _createTelCtx;
2427
2696
  _self.getNotifyMgr = function () {
2428
2697
  if (!_notificationManager) {
2429
- _notificationManager = objCreateFn({
2430
- addNotificationListener: function (listener) { },
2431
- removeNotificationListener: function (listener) { },
2432
- eventsSent: function (events) { },
2433
- eventsDiscarded: function (events, reason) { },
2434
- eventsSendRequest: function (sendReason, isAsync) { }
2435
- });
2698
+ _notificationManager = _createDummyNotificationManager();
2436
2699
  _self[strNotificationManager] = _notificationManager;
2437
2700
  }
2438
2701
  return _notificationManager;
2439
2702
  };
2440
- _self.addNotificationListener = function (listener) {
2703
+ _self[strAddNotificationListener] = function (listener) {
2441
2704
  if (_notificationManager) {
2442
- _notificationManager.addNotificationListener(listener);
2705
+ _notificationManager[strAddNotificationListener](listener);
2443
2706
  }
2444
2707
  };
2445
- _self.removeNotificationListener = function (listener) {
2708
+ _self[strRemoveNotificationListener] = function (listener) {
2446
2709
  if (_notificationManager) {
2447
- _notificationManager.removeNotificationListener(listener);
2710
+ _notificationManager[strRemoveNotificationListener](listener);
2448
2711
  }
2449
2712
  };
2450
2713
  _self.getCookieMgr = function () {
@@ -2475,7 +2738,7 @@ this.Microsoft = this.Microsoft || {};
2475
2738
  var eventQueue = _eventQueue;
2476
2739
  _eventQueue = [];
2477
2740
  arrForEach(eventQueue, function (event) {
2478
- _self.getProcessTelContext().processNext(event);
2741
+ _createTelCtx().processNext(event);
2479
2742
  });
2480
2743
  }
2481
2744
  };
@@ -2501,10 +2764,83 @@ this.Microsoft = this.Microsoft || {};
2501
2764
  }
2502
2765
  };
2503
2766
  proxyFunctions(_self, function () { return _telemetryInitializerPlugin; }, ["addTelemetryInitializer"]);
2767
+ _self.unload = function (isAsync, unloadComplete, cbTimeout) {
2768
+ if (isAsync === void 0) { isAsync = true; }
2769
+ if (!_isInitialized) {
2770
+ throwError(strSdkNotInitialized);
2771
+ }
2772
+ if (_isUnloading) {
2773
+ throwError(strSdkUnloadingError);
2774
+ }
2775
+ var unloadState = {
2776
+ reason: 50 ,
2777
+ isAsync: isAsync,
2778
+ flushComplete: false
2779
+ };
2780
+ var processUnloadCtx = createProcessTelemetryUnloadContext(_getPluginChain(), _self.config, _self);
2781
+ processUnloadCtx.onComplete(function () {
2782
+ _initDefaults();
2783
+ unloadComplete && unloadComplete(unloadState);
2784
+ }, _self);
2785
+ function _doUnload(flushComplete) {
2786
+ unloadState.flushComplete = flushComplete;
2787
+ _isUnloading = true;
2788
+ _unloadHandlers.run(processUnloadCtx, unloadState);
2789
+ _self.stopPollingInternalLogs();
2790
+ processUnloadCtx.processNext(unloadState);
2791
+ }
2792
+ if (_channelControl) {
2793
+ _channelControl.flush(isAsync, _doUnload, 6 , cbTimeout);
2794
+ }
2795
+ else {
2796
+ _doUnload(true);
2797
+ }
2798
+ };
2504
2799
  _self.getPlugin = _getPlugin;
2800
+ _self.addPlugin = function (plugin, replaceExisting, isAsync, addCb) {
2801
+ if (isAsync === void 0) { isAsync = true; }
2802
+ if (!plugin) {
2803
+ addCb && addCb(false);
2804
+ _logOrThrowError(strValidationError);
2805
+ return;
2806
+ }
2807
+ var existingPlugin = _getPlugin(plugin.identifier);
2808
+ if (existingPlugin && !replaceExisting) {
2809
+ addCb && addCb(false);
2810
+ _logOrThrowError("Plugin [" + plugin.identifier + "] is already loaded!");
2811
+ return;
2812
+ }
2813
+ function _addPlugin(removed) {
2814
+ _configExtensions.push(plugin);
2815
+ _initPluginChain(_self.config);
2816
+ addCb && addCb(true);
2817
+ }
2818
+ if (existingPlugin) {
2819
+ var removedPlugins = [existingPlugin.plugin];
2820
+ var unloadState = {
2821
+ reason: 2 ,
2822
+ isAsync: isAsync
2823
+ };
2824
+ _removePlugins(removedPlugins, unloadState, function (removed) {
2825
+ if (!removed) {
2826
+ addCb && addCb(false);
2827
+ }
2828
+ else {
2829
+ _addPlugin();
2830
+ }
2831
+ });
2832
+ }
2833
+ else {
2834
+ _addPlugin();
2835
+ }
2836
+ };
2837
+ _self.evtNamespace = function () {
2838
+ return _evtNamespace;
2839
+ };
2840
+ proxyFunctionAs(_self, "addUnloadCb", function () { return _unloadHandlers; }, "add");
2505
2841
  function _initDefaults() {
2506
2842
  _isInitialized = false;
2507
- _self.logger = new DiagnosticLogger({ loggingLevelConsole: LoggingSeverity.CRITICAL });
2843
+ _self.logger = new DiagnosticLogger({ loggingLevelConsole: 1 });
2508
2844
  _self.config = null;
2509
2845
  _self._extensions = [];
2510
2846
  _telemetryInitializerPlugin = new TelemetryInitializerPlugin();
@@ -2519,7 +2855,13 @@ this.Microsoft = this.Microsoft || {};
2519
2855
  _channelControl = null;
2520
2856
  _channelConfig = null;
2521
2857
  _channelQueue = null;
2858
+ _isUnloading = false;
2522
2859
  _internalLogsEventName = null;
2860
+ _evtNamespace = createUniqueNamespace("AIBaseCore", true);
2861
+ _unloadHandlers = createUnloadHandlerContainer();
2862
+ }
2863
+ function _createTelCtx() {
2864
+ return createProcessTelemetryContext(_getPluginChain(), _self.config, _self);
2523
2865
  }
2524
2866
  function _initPluginChain(config) {
2525
2867
  var theExtensions = _validateExtensions(_self.logger, ChannelControllerPriority, _configExtensions);
@@ -2527,26 +2869,63 @@ this.Microsoft = this.Microsoft || {};
2527
2869
  _pluginChain = null;
2528
2870
  var allExtensions = theExtensions.all;
2529
2871
  _channelQueue = objFreeze(createChannelQueues(_channelConfig, allExtensions, config, _self));
2530
- _channelControl = createChannelControllerPlugin(_channelQueue, _self);
2872
+ if (_channelControl) {
2873
+ var idx = allExtensions.indexOf(_channelControl);
2874
+ if (idx !== -1) {
2875
+ allExtensions.splice(idx, 1);
2876
+ }
2877
+ idx = _coreExtensions.indexOf(_channelControl);
2878
+ if (idx !== -1) {
2879
+ _coreExtensions.splice(idx, 1);
2880
+ }
2881
+ _channelControl._setQueue(_channelQueue);
2882
+ }
2883
+ else {
2884
+ _channelControl = createChannelControllerPlugin(_channelQueue, _self);
2885
+ }
2531
2886
  allExtensions.push(_channelControl);
2532
2887
  _coreExtensions.push(_channelControl);
2533
2888
  _self._extensions = sortPlugins(allExtensions);
2534
2889
  _channelControl.initialize(config, _self, allExtensions);
2535
- initializePlugins(_self.getProcessTelContext(), allExtensions);
2890
+ initializePlugins(_createTelCtx(), allExtensions);
2536
2891
  _self._extensions = objFreeze(sortPlugins(_coreExtensions || [])).slice();
2537
2892
  }
2538
2893
  function _getPlugin(pluginIdentifier) {
2539
2894
  var theExt = null;
2540
2895
  var thePlugin = null;
2541
2896
  arrForEach(_self._extensions, function (ext) {
2542
- if (ext.identifier === pluginIdentifier) {
2897
+ if (ext.identifier === pluginIdentifier && ext !== _channelControl && ext !== _telemetryInitializerPlugin) {
2543
2898
  thePlugin = ext;
2544
2899
  return -1;
2545
2900
  }
2546
2901
  });
2902
+ if (!thePlugin && _channelControl) {
2903
+ thePlugin = _channelControl.getChannel(pluginIdentifier);
2904
+ }
2547
2905
  if (thePlugin) {
2548
2906
  theExt = {
2549
- plugin: thePlugin
2907
+ plugin: thePlugin,
2908
+ setEnabled: function (enabled) {
2909
+ _getPluginState(thePlugin)[strDisabled] = !enabled;
2910
+ },
2911
+ isEnabled: function () {
2912
+ var pluginState = _getPluginState(thePlugin);
2913
+ return !pluginState[strTeardown] && !pluginState[strDisabled];
2914
+ },
2915
+ remove: function (isAsync, removeCb) {
2916
+ if (isAsync === void 0) { isAsync = true; }
2917
+ var pluginsToRemove = [thePlugin];
2918
+ var unloadState = {
2919
+ reason: 1 ,
2920
+ isAsync: isAsync
2921
+ };
2922
+ _removePlugins(pluginsToRemove, unloadState, function (removed) {
2923
+ if (removed) {
2924
+ _initPluginChain(_self.config);
2925
+ }
2926
+ removeCb && removeCb(removed);
2927
+ });
2928
+ }
2550
2929
  };
2551
2930
  }
2552
2931
  return theExt;
@@ -2554,11 +2933,53 @@ this.Microsoft = this.Microsoft || {};
2554
2933
  function _getPluginChain() {
2555
2934
  if (!_pluginChain) {
2556
2935
  var extensions = (_coreExtensions || []).slice();
2557
- extensions.push(_telemetryInitializerPlugin);
2936
+ if (extensions.indexOf(_telemetryInitializerPlugin) === -1) {
2937
+ extensions.push(_telemetryInitializerPlugin);
2938
+ }
2558
2939
  _pluginChain = createTelemetryProxyChain(sortPlugins(extensions), _self.config, _self);
2559
2940
  }
2560
2941
  return _pluginChain;
2561
2942
  }
2943
+ function _removePlugins(thePlugins, unloadState, removeComplete) {
2944
+ if (thePlugins && thePlugins.length > 0) {
2945
+ var unloadChain = createTelemetryProxyChain(thePlugins, _self.config, _self);
2946
+ var unloadCtx = createProcessTelemetryUnloadContext(unloadChain, _self.config, _self);
2947
+ unloadCtx.onComplete(function () {
2948
+ var removed = false;
2949
+ var newConfigExtensions = [];
2950
+ arrForEach(_configExtensions, function (plugin, idx) {
2951
+ if (!_isPluginPresent(plugin, thePlugins)) {
2952
+ newConfigExtensions.push(plugin);
2953
+ }
2954
+ else {
2955
+ removed = true;
2956
+ }
2957
+ });
2958
+ _configExtensions = newConfigExtensions;
2959
+ var newChannelConfig = [];
2960
+ if (_channelConfig) {
2961
+ arrForEach(_channelConfig, function (queue, idx) {
2962
+ var newQueue = [];
2963
+ arrForEach(queue, function (channel) {
2964
+ if (!_isPluginPresent(channel, thePlugins)) {
2965
+ newQueue.push(channel);
2966
+ }
2967
+ else {
2968
+ removed = true;
2969
+ }
2970
+ });
2971
+ newChannelConfig.push(newQueue);
2972
+ });
2973
+ _channelConfig = newChannelConfig;
2974
+ }
2975
+ removeComplete && removeComplete(removed);
2976
+ });
2977
+ unloadCtx.processNext(unloadState);
2978
+ }
2979
+ else {
2980
+ removeComplete(false);
2981
+ }
2982
+ }
2562
2983
  function _flushInternalLogs() {
2563
2984
  var queue = _self.logger ? _self.logger.queue : [];
2564
2985
  if (queue) {
@@ -2577,12 +2998,12 @@ this.Microsoft = this.Microsoft || {};
2577
2998
  }
2578
2999
  function _initDebugListener(config) {
2579
3000
  if (config.disableDbgExt === true && _debugListener) {
2580
- _notificationManager.removeNotificationListener(_debugListener);
3001
+ _notificationManager[strRemoveNotificationListener](_debugListener);
2581
3002
  _debugListener = null;
2582
3003
  }
2583
3004
  if (_notificationManager && !_debugListener && config.disableDbgExt !== true) {
2584
3005
  _debugListener = getDebugListener(config);
2585
- _notificationManager.addNotificationListener(_debugListener);
3006
+ _notificationManager[strAddNotificationListener](_debugListener);
2586
3007
  }
2587
3008
  }
2588
3009
  function _initPerfManager(config) {
@@ -2593,15 +3014,24 @@ this.Microsoft = this.Microsoft || {};
2593
3014
  setValue(_self.config, "createPerfMgr", _createPerfManager);
2594
3015
  }
2595
3016
  }
3017
+ function _initExtConfig(config) {
3018
+ var extConfig = getSetValue(config, strExtensionConfig);
3019
+ extConfig.NotificationManager = _notificationManager;
3020
+ }
3021
+ function _logOrThrowError(message) {
3022
+ var logger = _self.logger;
3023
+ if (logger) {
3024
+ logger.throwInternal(2 , 73 , message);
3025
+ }
3026
+ else {
3027
+ throwError(message);
3028
+ }
3029
+ }
2596
3030
  });
2597
3031
  }
2598
3032
  return BaseCore;
2599
3033
  }());
2600
3034
 
2601
- var strEventsSent = "eventsSent";
2602
- var strEventsDiscarded = "eventsDiscarded";
2603
- var strEventsSendRequest = "eventsSendRequest";
2604
- var strPerfEvent = "perfEvent";
2605
3035
  function _runListeners(listeners, name, isAsync, callback) {
2606
3036
  arrForEach(listeners, function (listener) {
2607
3037
  if (listener && listener[name]) {
@@ -2623,32 +3053,32 @@ this.Microsoft = this.Microsoft || {};
2623
3053
  this.listeners = [];
2624
3054
  var perfEvtsSendAll = !!(config || {}).perfEvtsSendAll;
2625
3055
  dynamicProto(NotificationManager, this, function (_self) {
2626
- _self.addNotificationListener = function (listener) {
3056
+ _self[strAddNotificationListener] = function (listener) {
2627
3057
  _self.listeners.push(listener);
2628
3058
  };
2629
- _self.removeNotificationListener = function (listener) {
3059
+ _self[strRemoveNotificationListener] = function (listener) {
2630
3060
  var index = arrIndexOf(_self.listeners, listener);
2631
3061
  while (index > -1) {
2632
3062
  _self.listeners.splice(index, 1);
2633
3063
  index = arrIndexOf(_self.listeners, listener);
2634
3064
  }
2635
3065
  };
2636
- _self.eventsSent = function (events) {
3066
+ _self[strEventsSent] = function (events) {
2637
3067
  _runListeners(_self.listeners, strEventsSent, true, function (listener) {
2638
3068
  listener[strEventsSent](events);
2639
3069
  });
2640
3070
  };
2641
- _self.eventsDiscarded = function (events, reason) {
3071
+ _self[strEventsDiscarded] = function (events, reason) {
2642
3072
  _runListeners(_self.listeners, strEventsDiscarded, true, function (listener) {
2643
3073
  listener[strEventsDiscarded](events, reason);
2644
3074
  });
2645
3075
  };
2646
- _self.eventsSendRequest = function (sendReason, isAsync) {
3076
+ _self[strEventsSendRequest] = function (sendReason, isAsync) {
2647
3077
  _runListeners(_self.listeners, strEventsSendRequest, isAsync, function (listener) {
2648
3078
  listener[strEventsSendRequest](sendReason, isAsync);
2649
3079
  });
2650
3080
  };
2651
- _self.perfEvent = function (perfEvent) {
3081
+ _self[strPerfEvent] = function (perfEvent) {
2652
3082
  if (perfEvent) {
2653
3083
  if (perfEvtsSendAll || !perfEvent.isChildEvt()) {
2654
3084
  _runListeners(_self.listeners, strPerfEvent, false, function (listener) {
@@ -2703,147 +3133,179 @@ this.Microsoft = this.Microsoft || {};
2703
3133
  return AppInsightsCore;
2704
3134
  }(BaseCore));
2705
3135
 
2706
- var UInt32Mask = 0x100000000;
2707
- var MaxUInt32 = 0xffffffff;
2708
- var _mwcSeeded = false;
2709
- var _mwcW = 123456789;
2710
- var _mwcZ = 987654321;
2711
- function _mwcSeed(seedValue) {
2712
- if (seedValue < 0) {
2713
- seedValue >>>= 0;
2714
- }
2715
- _mwcW = (123456789 + seedValue) & MaxUInt32;
2716
- _mwcZ = (987654321 - seedValue) & MaxUInt32;
2717
- _mwcSeeded = true;
2718
- }
2719
- function _autoSeedMwc() {
2720
- try {
2721
- var now = dateNow() & 0x7fffffff;
2722
- _mwcSeed(((Math.random() * UInt32Mask) ^ now) + now);
2723
- }
2724
- catch (e) {
3136
+ var strOnPrefix = "on";
3137
+ var strAttachEvent = "attachEvent";
3138
+ var strAddEventHelper = "addEventListener";
3139
+ var strEvents = "events";
3140
+ var strVisibilityChangeEvt = "visibilitychange";
3141
+ var strPageHide = "pagehide";
3142
+ var strUnload = "unload";
3143
+ var strBeforeUnload = "beforeunload";
3144
+ var strPageHideNamespace = createUniqueNamespace("aiEvtPageHide");
3145
+ createUniqueNamespace("aiEvtPageShow");
3146
+ var _guid = 1;
3147
+ var elmNodeData = createElmNodeData("events");
3148
+ var eventNamespace = /^([^.]*)(?:\.(.+)|)/;
3149
+ function _normalizeNamespace(name) {
3150
+ if (name && name.replace) {
3151
+ return name.replace(/^\s*\.*|\.*\s*$/g, "");
3152
+ }
3153
+ return name;
3154
+ }
3155
+ function _getEvtNamespace(eventName, namespaces) {
3156
+ if (namespaces) {
3157
+ var theNamespace_1 = "";
3158
+ if (isArray(namespaces)) {
3159
+ theNamespace_1 = "";
3160
+ arrForEach(namespaces, function (name) {
3161
+ name = _normalizeNamespace(name);
3162
+ if (name) {
3163
+ if (name[0] !== ".") {
3164
+ name = "." + name;
3165
+ }
3166
+ theNamespace_1 += name;
3167
+ }
3168
+ });
3169
+ }
3170
+ else {
3171
+ theNamespace_1 = _normalizeNamespace(namespaces);
3172
+ }
3173
+ if (theNamespace_1) {
3174
+ if (theNamespace_1[0] !== ".") {
3175
+ theNamespace_1 = "." + theNamespace_1;
3176
+ }
3177
+ eventName = (eventName || "") + theNamespace_1;
3178
+ }
2725
3179
  }
3180
+ var parsedEvent = (eventNamespace.exec(eventName) || []);
3181
+ return {
3182
+ type: parsedEvent[1],
3183
+ ns: ((parsedEvent[2] || "").split(".").sort()).join(".")
3184
+ };
2726
3185
  }
2727
- function randomValue(maxValue) {
2728
- if (maxValue > 0) {
2729
- return Math.floor((random32() / MaxUInt32) * (maxValue + 1)) >>> 0;
3186
+ function _getRegisteredEvents(target, evtName, addDefault) {
3187
+ if (addDefault === void 0) { addDefault = true; }
3188
+ var aiEvts = elmNodeData.get(target, strEvents, {}, addDefault);
3189
+ var registeredEvents = aiEvts[evtName];
3190
+ if (!registeredEvents) {
3191
+ registeredEvents = aiEvts[evtName] = [];
2730
3192
  }
2731
- return 0;
3193
+ return registeredEvents;
2732
3194
  }
2733
- function random32(signed) {
2734
- var value = 0;
2735
- var c = getCrypto() || getMsCrypto();
2736
- if (c && c.getRandomValues) {
2737
- value = c.getRandomValues(new Uint32Array(1))[0] & MaxUInt32;
2738
- }
2739
- if (value === 0 && isIE()) {
2740
- if (!_mwcSeeded) {
2741
- _autoSeedMwc();
3195
+ function _doAttach(obj, evtName, handlerRef, useCapture) {
3196
+ var result = false;
3197
+ if (obj && evtName && evtName.type && handlerRef) {
3198
+ if (obj[strAddEventHelper]) {
3199
+ obj[strAddEventHelper](evtName.type, handlerRef, useCapture);
3200
+ result = true;
3201
+ }
3202
+ else if (obj[strAttachEvent]) {
3203
+ obj[strAttachEvent](strOnPrefix + evtName.type, handlerRef);
3204
+ result = true;
2742
3205
  }
2743
- value = mwcRandom32() & MaxUInt32;
2744
- }
2745
- if (value === 0) {
2746
- value = Math.floor((UInt32Mask * Math.random()) | 0);
2747
- }
2748
- if (!signed) {
2749
- value >>>= 0;
2750
3206
  }
2751
- return value;
3207
+ return result;
2752
3208
  }
2753
- function mwcRandomSeed(value) {
2754
- if (!value) {
2755
- _autoSeedMwc();
3209
+ function mergeEvtNamespace(theNamespace, namespaces) {
3210
+ var newNamespaces;
3211
+ if (namespaces) {
3212
+ if (isArray(namespaces)) {
3213
+ newNamespaces = [theNamespace].concat(namespaces);
3214
+ }
3215
+ else {
3216
+ newNamespaces = [theNamespace, namespaces];
3217
+ }
2756
3218
  }
2757
3219
  else {
2758
- _mwcSeed(value);
2759
- }
2760
- }
2761
- function mwcRandom32(signed) {
2762
- _mwcZ = (36969 * (_mwcZ & 0xFFFF) + (_mwcZ >> 16)) & MaxUInt32;
2763
- _mwcW = (18000 * (_mwcW & 0xFFFF) + (_mwcW >> 16)) & MaxUInt32;
2764
- var value = (((_mwcZ << 16) + (_mwcW & 0xFFFF)) >>> 0) & MaxUInt32 | 0;
2765
- if (!signed) {
2766
- value >>>= 0;
3220
+ newNamespaces = theNamespace;
2767
3221
  }
2768
- return value;
3222
+ return newNamespaces;
2769
3223
  }
2770
- function newId(maxLength) {
2771
- if (maxLength === void 0) { maxLength = 22; }
2772
- var base64chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
2773
- var number = random32() >>> 0;
2774
- var chars = 0;
2775
- var result = "";
2776
- while (result.length < maxLength) {
2777
- chars++;
2778
- result += base64chars.charAt(number & 0x3F);
2779
- number >>>= 6;
2780
- if (chars === 5) {
2781
- number = (((random32() << 2) & 0xFFFFFFFF) | (number & 0x03)) >>> 0;
2782
- chars = 0;
3224
+ function eventOn(target, eventName, handlerRef, evtNamespace, useCapture) {
3225
+ if (useCapture === void 0) { useCapture = false; }
3226
+ var result = false;
3227
+ if (target) {
3228
+ try {
3229
+ var evtName = _getEvtNamespace(eventName, evtNamespace);
3230
+ result = _doAttach(target, evtName, handlerRef, useCapture);
3231
+ if (result && elmNodeData.accept(target)) {
3232
+ var registeredEvent = {
3233
+ guid: _guid++,
3234
+ evtName: evtName,
3235
+ handler: handlerRef,
3236
+ capture: useCapture
3237
+ };
3238
+ _getRegisteredEvents(target, evtName.type).push(registeredEvent);
3239
+ }
3240
+ }
3241
+ catch (e) {
2783
3242
  }
2784
3243
  }
2785
3244
  return result;
2786
3245
  }
2787
-
2788
- var strVisibilityChangeEvt = "visibilitychange";
2789
- var strPageHide = "pagehide";
2790
- var _cookieMgrs = null;
2791
- var _canUseCookies;
2792
- function addEventHandler(eventName, callback) {
3246
+ function attachEvent(obj, eventNameWithoutOn, handlerRef, useCapture) {
3247
+ if (useCapture === void 0) { useCapture = false; }
3248
+ return eventOn(obj, eventNameWithoutOn, handlerRef, null, useCapture);
3249
+ }
3250
+ function addEventHandler(eventName, callback, evtNamespace) {
2793
3251
  var result = false;
2794
3252
  var w = getWindow();
2795
3253
  if (w) {
2796
- result = attachEvent(w, eventName, callback);
2797
- result = attachEvent(w["body"], eventName, callback) || result;
3254
+ result = eventOn(w, eventName, callback, evtNamespace);
3255
+ result = eventOn(w["body"], eventName, callback, evtNamespace) || result;
2798
3256
  }
2799
3257
  var doc = getDocument();
2800
3258
  if (doc) {
2801
- result = attachEvent(doc, eventName, callback) || result;
3259
+ result = eventOn(doc, eventName, callback, evtNamespace) || result;
2802
3260
  }
2803
3261
  return result;
2804
3262
  }
2805
- function addEventListeners(events, listener, excludeEvents) {
3263
+ function _addEventListeners(events, listener, excludeEvents, evtNamespace) {
2806
3264
  var added = false;
2807
- if (listener && events && isArray(events)) {
2808
- var excluded_1 = [];
3265
+ if (listener && events && events.length > 0) {
2809
3266
  arrForEach(events, function (name) {
2810
- if (isString(name)) {
3267
+ if (name) {
2811
3268
  if (!excludeEvents || arrIndexOf(excludeEvents, name) === -1) {
2812
- added = addEventHandler(name, listener) || added;
2813
- }
2814
- else {
2815
- excluded_1.push(name);
3269
+ added = addEventHandler(name, listener, evtNamespace) || added;
2816
3270
  }
2817
3271
  }
2818
3272
  });
2819
- if (!added && excluded_1.length > 0) {
2820
- added = addEventListeners(excluded_1, listener);
3273
+ }
3274
+ return added;
3275
+ }
3276
+ function addEventListeners(events, listener, excludeEvents, evtNamespace) {
3277
+ var added = false;
3278
+ if (listener && events && isArray(events)) {
3279
+ added = _addEventListeners(events, listener, excludeEvents, evtNamespace);
3280
+ if (!added && excludeEvents && excludeEvents.length > 0) {
3281
+ added = _addEventListeners(events, listener, null, evtNamespace);
2821
3282
  }
2822
3283
  }
2823
3284
  return added;
2824
3285
  }
2825
- function addPageUnloadEventListener(listener, excludeEvents) {
2826
- return addEventListeners(["beforeunload", "unload", "pagehide"], listener, excludeEvents);
3286
+ function addPageUnloadEventListener(listener, excludeEvents, evtNamespace) {
3287
+ return addEventListeners([strBeforeUnload, strUnload, strPageHide], listener, excludeEvents, evtNamespace);
2827
3288
  }
2828
- function addPageHideEventListener(listener, excludeEvents) {
3289
+ function addPageHideEventListener(listener, excludeEvents, evtNamespace) {
2829
3290
  function _handlePageVisibility(evt) {
2830
3291
  var doc = getDocument();
2831
3292
  if (listener && doc && doc.visibilityState === "hidden") {
2832
3293
  listener(evt);
2833
3294
  }
2834
3295
  }
2835
- var pageUnloadAdded = false;
2836
- if (!excludeEvents || arrIndexOf(excludeEvents, strPageHide) === -1) {
2837
- pageUnloadAdded = addEventHandler(strPageHide, listener);
2838
- }
3296
+ var newNamespaces = mergeEvtNamespace(strPageHideNamespace, evtNamespace);
3297
+ var pageUnloadAdded = _addEventListeners([strPageHide], listener, excludeEvents, newNamespaces);
2839
3298
  if (!excludeEvents || arrIndexOf(excludeEvents, strVisibilityChangeEvt) === -1) {
2840
- pageUnloadAdded = addEventHandler(strVisibilityChangeEvt, _handlePageVisibility) || pageUnloadAdded;
3299
+ pageUnloadAdded = _addEventListeners([strVisibilityChangeEvt], _handlePageVisibility, excludeEvents, newNamespaces) || pageUnloadAdded;
2841
3300
  }
2842
3301
  if (!pageUnloadAdded && excludeEvents) {
2843
- pageUnloadAdded = addPageHideEventListener(listener);
3302
+ pageUnloadAdded = addPageHideEventListener(listener, null, evtNamespace);
2844
3303
  }
2845
3304
  return pageUnloadAdded;
2846
3305
  }
3306
+
3307
+ var _cookieMgrs = null;
3308
+ var _canUseCookies;
2847
3309
  function newGuid() {
2848
3310
  function randomHexDigit() {
2849
3311
  return randomValue(15);
@@ -2862,7 +3324,7 @@ this.Microsoft = this.Microsoft || {};
2862
3324
  }
2863
3325
  function generateW3CId() {
2864
3326
  var hexValues = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"];
2865
- var oct = "", tmp;
3327
+ var oct = strEmpty$1, tmp;
2866
3328
  for (var a = 0; a < 4; a++) {
2867
3329
  tmp = random32();
2868
3330
  oct +=
@@ -2957,6 +3419,95 @@ this.Microsoft = this.Microsoft || {};
2957
3419
  return _legacyCookieMgr(null, logger).del(name);
2958
3420
  }
2959
3421
 
3422
+ var LoggingSeverity = createEnumStyle({
3423
+ CRITICAL: 1 ,
3424
+ WARNING: 2
3425
+ });
3426
+ var _InternalMessageId = createEnumStyle({
3427
+ BrowserDoesNotSupportLocalStorage: 0 ,
3428
+ BrowserCannotReadLocalStorage: 1 ,
3429
+ BrowserCannotReadSessionStorage: 2 ,
3430
+ BrowserCannotWriteLocalStorage: 3 ,
3431
+ BrowserCannotWriteSessionStorage: 4 ,
3432
+ BrowserFailedRemovalFromLocalStorage: 5 ,
3433
+ BrowserFailedRemovalFromSessionStorage: 6 ,
3434
+ CannotSendEmptyTelemetry: 7 ,
3435
+ ClientPerformanceMathError: 8 ,
3436
+ ErrorParsingAISessionCookie: 9 ,
3437
+ ErrorPVCalc: 10 ,
3438
+ ExceptionWhileLoggingError: 11 ,
3439
+ FailedAddingTelemetryToBuffer: 12 ,
3440
+ FailedMonitorAjaxAbort: 13 ,
3441
+ FailedMonitorAjaxDur: 14 ,
3442
+ FailedMonitorAjaxOpen: 15 ,
3443
+ FailedMonitorAjaxRSC: 16 ,
3444
+ FailedMonitorAjaxSend: 17 ,
3445
+ FailedMonitorAjaxGetCorrelationHeader: 18 ,
3446
+ FailedToAddHandlerForOnBeforeUnload: 19 ,
3447
+ FailedToSendQueuedTelemetry: 20 ,
3448
+ FailedToReportDataLoss: 21 ,
3449
+ FlushFailed: 22 ,
3450
+ MessageLimitPerPVExceeded: 23 ,
3451
+ MissingRequiredFieldSpecification: 24 ,
3452
+ NavigationTimingNotSupported: 25 ,
3453
+ OnError: 26 ,
3454
+ SessionRenewalDateIsZero: 27 ,
3455
+ SenderNotInitialized: 28 ,
3456
+ StartTrackEventFailed: 29 ,
3457
+ StopTrackEventFailed: 30 ,
3458
+ StartTrackFailed: 31 ,
3459
+ StopTrackFailed: 32 ,
3460
+ TelemetrySampledAndNotSent: 33 ,
3461
+ TrackEventFailed: 34 ,
3462
+ TrackExceptionFailed: 35 ,
3463
+ TrackMetricFailed: 36 ,
3464
+ TrackPVFailed: 37 ,
3465
+ TrackPVFailedCalc: 38 ,
3466
+ TrackTraceFailed: 39 ,
3467
+ TransmissionFailed: 40 ,
3468
+ FailedToSetStorageBuffer: 41 ,
3469
+ FailedToRestoreStorageBuffer: 42 ,
3470
+ InvalidBackendResponse: 43 ,
3471
+ FailedToFixDepricatedValues: 44 ,
3472
+ InvalidDurationValue: 45 ,
3473
+ TelemetryEnvelopeInvalid: 46 ,
3474
+ CreateEnvelopeError: 47 ,
3475
+ CannotSerializeObject: 48 ,
3476
+ CannotSerializeObjectNonSerializable: 49 ,
3477
+ CircularReferenceDetected: 50 ,
3478
+ ClearAuthContextFailed: 51 ,
3479
+ ExceptionTruncated: 52 ,
3480
+ IllegalCharsInName: 53 ,
3481
+ ItemNotInArray: 54 ,
3482
+ MaxAjaxPerPVExceeded: 55 ,
3483
+ MessageTruncated: 56 ,
3484
+ NameTooLong: 57 ,
3485
+ SampleRateOutOfRange: 58 ,
3486
+ SetAuthContextFailed: 59 ,
3487
+ SetAuthContextFailedAccountName: 60 ,
3488
+ StringValueTooLong: 61 ,
3489
+ StartCalledMoreThanOnce: 62 ,
3490
+ StopCalledWithoutStart: 63 ,
3491
+ TelemetryInitializerFailed: 64 ,
3492
+ TrackArgumentsNotSpecified: 65 ,
3493
+ UrlTooLong: 66 ,
3494
+ SessionStorageBufferFull: 67 ,
3495
+ CannotAccessCookie: 68 ,
3496
+ IdTooLong: 69 ,
3497
+ InvalidEvent: 70 ,
3498
+ FailedMonitorAjaxSetRequestHeader: 71 ,
3499
+ SendBrowserInfoOnUserInit: 72 ,
3500
+ PluginException: 73 ,
3501
+ NotificationException: 74 ,
3502
+ SnippetScriptLoadFailure: 99 ,
3503
+ InvalidInstrumentationKey: 100 ,
3504
+ CannotParseAiBlobValue: 101 ,
3505
+ InvalidContentBlob: 102 ,
3506
+ TrackPageActionEventFailed: 103 ,
3507
+ FailedAddingCustomDefinedRequestContext: 104 ,
3508
+ InMemoryStorageBufferFull: 105
3509
+ });
3510
+
2960
3511
  var aiInstrumentHooks = "_aiHooks";
2961
3512
  var cbNames = [
2962
3513
  "req", "rsp", "hkErr", "fnErr"
@@ -3132,7 +3683,7 @@ this.Microsoft = this.Microsoft || {};
3132
3683
  name = strTrim(name.toString());
3133
3684
  if (name.length > 150 ) {
3134
3685
  nameTrunc = name.substring(0, 150 );
3135
- logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.NameTooLong, "name is too long. It has been truncated to " + 150 + " characters.", { name: name }, true);
3686
+ logger && logger.throwInternal(2 , _InternalMessageId.NameTooLong, "name is too long. It has been truncated to " + 150 + " characters.", { name: name }, true);
3136
3687
  }
3137
3688
  }
3138
3689
  return nameTrunc || name;
@@ -3145,7 +3696,7 @@ this.Microsoft = this.Microsoft || {};
3145
3696
  value = strTrim(value);
3146
3697
  if (value.toString().length > maxLength) {
3147
3698
  valueTrunc = value.toString().substring(0, maxLength);
3148
- logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.StringValueTooLong, "string value is too long. It has been truncated to " + maxLength + " characters.", { value: value }, true);
3699
+ logger && logger.throwInternal(2 , _InternalMessageId.StringValueTooLong, "string value is too long. It has been truncated to " + maxLength + " characters.", { value: value }, true);
3149
3700
  }
3150
3701
  }
3151
3702
  return valueTrunc || value;
@@ -3158,7 +3709,7 @@ this.Microsoft = this.Microsoft || {};
3158
3709
  if (message) {
3159
3710
  if (message.length > 32768 ) {
3160
3711
  messageTrunc = message.substring(0, 32768 );
3161
- logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.MessageTruncated, "message is too long, it has been truncated to " + 32768 + " characters.", { message: message }, true);
3712
+ logger && logger.throwInternal(2 , _InternalMessageId.MessageTruncated, "message is too long, it has been truncated to " + 32768 + " characters.", { message: message }, true);
3162
3713
  }
3163
3714
  }
3164
3715
  return messageTrunc || message;
@@ -3169,7 +3720,7 @@ this.Microsoft = this.Microsoft || {};
3169
3720
  var value = "" + exception;
3170
3721
  if (value.length > 32768 ) {
3171
3722
  exceptionTrunc = value.substring(0, 32768 );
3172
- logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.ExceptionTruncated, "exception is too long, it has been truncated to " + 32768 + " characters.", { exception: exception }, true);
3723
+ logger && logger.throwInternal(2 , _InternalMessageId.ExceptionTruncated, "exception is too long, it has been truncated to " + 32768 + " characters.", { exception: exception }, true);
3173
3724
  }
3174
3725
  }
3175
3726
  return exceptionTrunc || exception;
@@ -3183,7 +3734,7 @@ this.Microsoft = this.Microsoft || {};
3183
3734
  value = getJSON().stringify(value);
3184
3735
  }
3185
3736
  catch (e) {
3186
- logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.CannotSerializeObjectNonSerializable, "custom property is not valid", { exception: e }, true);
3737
+ logger && logger.throwInternal(2 , _InternalMessageId.CannotSerializeObjectNonSerializable, "custom property is not valid", { exception: e }, true);
3187
3738
  }
3188
3739
  }
3189
3740
  value = dataSanitizeString(logger, value, 8192 );
@@ -3214,7 +3765,7 @@ this.Microsoft = this.Microsoft || {};
3214
3765
  input = strTrim(input);
3215
3766
  if (input.length > maxLength) {
3216
3767
  inputTrunc = input.substring(0, maxLength);
3217
- logger && logger.throwInternal(LoggingSeverity.WARNING, _msgId, "input is too long, it has been truncated to " + maxLength + " characters.", { data: input }, true);
3768
+ logger && logger.throwInternal(2 , _msgId, "input is too long, it has been truncated to " + maxLength + " characters.", { data: input }, true);
3218
3769
  }
3219
3770
  }
3220
3771
  return inputTrunc || input;
@@ -3260,6 +3811,7 @@ this.Microsoft = this.Microsoft || {};
3260
3811
  return event;
3261
3812
  }
3262
3813
 
3814
+ var strEmpty = "";
3263
3815
  function stringToBoolOrDefault(str, defaultValue) {
3264
3816
  if (defaultValue === void 0) { defaultValue = false; }
3265
3817
  if (str === undefined || str === null) {
@@ -3272,16 +3824,16 @@ this.Microsoft = this.Microsoft || {};
3272
3824
  totalms = 0;
3273
3825
  }
3274
3826
  totalms = Math.round(totalms);
3275
- var ms = "" + totalms % 1000;
3276
- var sec = "" + Math.floor(totalms / 1000) % 60;
3277
- var min = "" + Math.floor(totalms / (1000 * 60)) % 60;
3278
- var hour = "" + Math.floor(totalms / (1000 * 60 * 60)) % 24;
3827
+ var ms = strEmpty + totalms % 1000;
3828
+ var sec = strEmpty + Math.floor(totalms / 1000) % 60;
3829
+ var min = strEmpty + Math.floor(totalms / (1000 * 60)) % 60;
3830
+ var hour = strEmpty + Math.floor(totalms / (1000 * 60 * 60)) % 24;
3279
3831
  var days = Math.floor(totalms / (1000 * 60 * 60 * 24));
3280
3832
  ms = ms.length === 1 ? "00" + ms : ms.length === 2 ? "0" + ms : ms;
3281
3833
  sec = sec.length < 2 ? "0" + sec : sec;
3282
3834
  min = min.length < 2 ? "0" + min : min;
3283
3835
  hour = hour.length < 2 ? "0" + hour : hour;
3284
- return (days > 0 ? days + "." : "") + hour + ":" + min + ":" + sec + "." + ms;
3836
+ return (days > 0 ? days + "." : strEmpty) + hour + ":" + min + ":" + sec + "." + ms;
3285
3837
  }
3286
3838
  function getExtensionByName(extensions, identifier) {
3287
3839
  var extension = null;
@@ -3305,17 +3857,15 @@ this.Microsoft = this.Microsoft || {};
3305
3857
  var strNotSpecified = "not_specified";
3306
3858
  var strIkey = "iKey";
3307
3859
 
3308
- var StorageType;
3309
- (function (StorageType) {
3310
- StorageType[StorageType["LocalStorage"] = 0] = "LocalStorage";
3311
- StorageType[StorageType["SessionStorage"] = 1] = "SessionStorage";
3312
- })(StorageType || (StorageType = {}));
3313
- var DistributedTracingModes;
3314
- (function (DistributedTracingModes) {
3315
- DistributedTracingModes[DistributedTracingModes["AI"] = 0] = "AI";
3316
- DistributedTracingModes[DistributedTracingModes["AI_AND_W3C"] = 1] = "AI_AND_W3C";
3317
- DistributedTracingModes[DistributedTracingModes["W3C"] = 2] = "W3C";
3318
- })(DistributedTracingModes || (DistributedTracingModes = {}));
3860
+ var StorageType = createEnumStyle({
3861
+ LocalStorage: 0 ,
3862
+ SessionStorage: 1
3863
+ });
3864
+ var DistributedTracingModes = createEnumStyle({
3865
+ AI: 0 ,
3866
+ AI_AND_W3C: 1 ,
3867
+ W3C: 2
3868
+ });
3319
3869
 
3320
3870
  var _canUseLocalStorage = undefined;
3321
3871
  var _canUseSessionStorage = undefined;
@@ -3367,7 +3917,7 @@ this.Microsoft = this.Microsoft || {};
3367
3917
  }
3368
3918
  catch (e) {
3369
3919
  _canUseLocalStorage = false;
3370
- logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.BrowserCannotReadLocalStorage, "Browser failed read of local storage. " + getExceptionName(e), { exception: dumpObj(e) });
3920
+ logger.throwInternal(2 , _InternalMessageId.BrowserCannotReadLocalStorage, "Browser failed read of local storage. " + getExceptionName(e), { exception: dumpObj(e) });
3371
3921
  }
3372
3922
  }
3373
3923
  return null;
@@ -3381,7 +3931,7 @@ this.Microsoft = this.Microsoft || {};
3381
3931
  }
3382
3932
  catch (e) {
3383
3933
  _canUseLocalStorage = false;
3384
- logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.BrowserCannotWriteLocalStorage, "Browser failed write to local storage. " + getExceptionName(e), { exception: dumpObj(e) });
3934
+ logger.throwInternal(2 , _InternalMessageId.BrowserCannotWriteLocalStorage, "Browser failed write to local storage. " + getExceptionName(e), { exception: dumpObj(e) });
3385
3935
  }
3386
3936
  }
3387
3937
  return false;
@@ -3395,7 +3945,7 @@ this.Microsoft = this.Microsoft || {};
3395
3945
  }
3396
3946
  catch (e) {
3397
3947
  _canUseLocalStorage = false;
3398
- logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.BrowserFailedRemovalFromLocalStorage, "Browser failed removal of local storage item. " + getExceptionName(e), { exception: dumpObj(e) });
3948
+ logger.throwInternal(2 , _InternalMessageId.BrowserFailedRemovalFromLocalStorage, "Browser failed removal of local storage item. " + getExceptionName(e), { exception: dumpObj(e) });
3399
3949
  }
3400
3950
  }
3401
3951
  return false;
@@ -3423,7 +3973,7 @@ this.Microsoft = this.Microsoft || {};
3423
3973
  }
3424
3974
  catch (e) {
3425
3975
  _canUseSessionStorage = false;
3426
- logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.BrowserCannotReadSessionStorage, "Browser failed read of session storage. " + getExceptionName(e), { exception: dumpObj(e) });
3976
+ logger.throwInternal(2 , _InternalMessageId.BrowserCannotReadSessionStorage, "Browser failed read of session storage. " + getExceptionName(e), { exception: dumpObj(e) });
3427
3977
  }
3428
3978
  }
3429
3979
  return null;
@@ -3437,7 +3987,7 @@ this.Microsoft = this.Microsoft || {};
3437
3987
  }
3438
3988
  catch (e) {
3439
3989
  _canUseSessionStorage = false;
3440
- logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.BrowserCannotWriteSessionStorage, "Browser failed write to session storage. " + getExceptionName(e), { exception: dumpObj(e) });
3990
+ logger.throwInternal(2 , _InternalMessageId.BrowserCannotWriteSessionStorage, "Browser failed write to session storage. " + getExceptionName(e), { exception: dumpObj(e) });
3441
3991
  }
3442
3992
  }
3443
3993
  return false;
@@ -3451,7 +4001,7 @@ this.Microsoft = this.Microsoft || {};
3451
4001
  }
3452
4002
  catch (e) {
3453
4003
  _canUseSessionStorage = false;
3454
- logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.BrowserFailedRemovalFromSessionStorage, "Browser failed removal of session storage item. " + getExceptionName(e), { exception: dumpObj(e) });
4004
+ logger.throwInternal(2 , _InternalMessageId.BrowserFailedRemovalFromSessionStorage, "Browser failed removal of session storage item. " + getExceptionName(e), { exception: dumpObj(e) });
3455
4005
  }
3456
4006
  }
3457
4007
  return false;
@@ -5610,7 +6160,7 @@ this.Microsoft = this.Microsoft || {};
5610
6160
  config.disableFlushOnUnload = stringToBoolOrDefault(config.disableFlushOnUnload, config.disableFlushOnBeforeUnload);
5611
6161
  return config;
5612
6162
  };
5613
- ApplicationInsights.Version = "2.8.0-beta.2202-07";
6163
+ ApplicationInsights.Version = "2.8.0-beta.2203-03";
5614
6164
  return ApplicationInsights;
5615
6165
  }(BaseTelemetryPlugin));
5616
6166
  var Timing = /** @class */ (function () {
@@ -5917,7 +6467,7 @@ this.Microsoft = this.Microsoft || {};
5917
6467
  }
5918
6468
  }
5919
6469
  var EnvelopeCreator = {
5920
- Version: "2.8.0-beta.2202-07"
6470
+ Version: "2.8.0-beta.2203-03"
5921
6471
  };
5922
6472
  function DependencyEnvelopeCreator(logger, telemetryItem, customUndefinedValue) {
5923
6473
  EnvelopeCreatorInit(logger, telemetryItem);
@@ -7186,7 +7736,7 @@ this.Microsoft = this.Microsoft || {};
7186
7736
  return Device;
7187
7737
  }());
7188
7738
 
7189
- var Version = "2.8.0-beta.2202-07";
7739
+ var Version = "2.8.0-beta.2203-03";
7190
7740
  var Internal = /** @class */ (function () {
7191
7741
  function Internal(config) {
7192
7742
  this.sdkVersion = (config.sdkExtension && config.sdkExtension() ? config.sdkExtension() + "_" : "") + "javascript:" + Version;
@@ -7870,19 +8420,21 @@ this.Microsoft = this.Microsoft || {};
7870
8420
  var _enableAjaxPerfTracking = false;
7871
8421
  var _maxAjaxCallsPerView = 0;
7872
8422
  var _enableResponseHeaderTracking = false;
7873
- var _hooks = [];
7874
8423
  var _disabledUrls = {};
7875
8424
  var _excludeRequestFromAutoTrackingPatterns;
7876
8425
  var _addRequestContext;
7877
- dynamicProto(AjaxMonitor, _this, function (_self, base) {
8426
+ var _evtNamespace;
8427
+ dynamicProto(AjaxMonitor, _this, function (_self, _base) {
8428
+ var _addHook = _base._addHook;
7878
8429
  _self.initialize = function (config, core, extensions, pluginChain) {
7879
8430
  if (!_self.isInitialized()) {
7880
- base.initialize(config, core, extensions, pluginChain);
8431
+ _base.initialize(config, core, extensions, pluginChain);
7881
8432
  var ctx_1 = _self._getTelCtx();
7882
8433
  var defaultConfig = AjaxMonitor.getDefaultConfig();
7883
8434
  objForEachKey(defaultConfig, function (field, value) {
7884
8435
  _config[field] = ctx_1.getConfig(AjaxMonitor.identifier, field, value);
7885
8436
  });
8437
+ _evtNamespace = mergeEvtNamespace(createUniqueNamespace("ajax"), core && core.evtNamespace && core.evtNamespace());
7886
8438
  var distributedTracingMode = _config.distributedTracingMode;
7887
8439
  _enableRequestHeaderTracking = _config.enableRequestHeaderTracking;
7888
8440
  _enableAjaxErrorStatusText = _config.enableAjaxErrorStatusText;
@@ -7891,8 +8443,8 @@ this.Microsoft = this.Microsoft || {};
7891
8443
  _enableResponseHeaderTracking = _config.enableResponseHeaderTracking;
7892
8444
  _excludeRequestFromAutoTrackingPatterns = _config.excludeRequestFromAutoTrackingPatterns;
7893
8445
  _addRequestContext = _config.addRequestContext;
7894
- _isUsingAIHeaders = distributedTracingMode === DistributedTracingModes.AI || distributedTracingMode === DistributedTracingModes.AI_AND_W3C;
7895
- _isUsingW3CHeaders = distributedTracingMode === DistributedTracingModes.AI_AND_W3C || distributedTracingMode === DistributedTracingModes.W3C;
8446
+ _isUsingAIHeaders = distributedTracingMode === 0 || distributedTracingMode === 1 ;
8447
+ _isUsingW3CHeaders = distributedTracingMode === 1 || distributedTracingMode === 2 ;
7896
8448
  if (_enableAjaxPerfTracking) {
7897
8449
  var iKey = config.instrumentationKey || "unkwn";
7898
8450
  if (iKey.length > 5) {
@@ -7920,14 +8472,9 @@ this.Microsoft = this.Microsoft || {};
7920
8472
  }
7921
8473
  }
7922
8474
  };
7923
- _self.teardown = function () {
7924
- arrForEach(_hooks, function (fn) {
7925
- fn.rm();
7926
- });
7927
- _hooks = [];
8475
+ _self._doTeardown = function () {
7928
8476
  _fetchInitialized = false;
7929
8477
  _xhrInitialized = false;
7930
- _self.setInitialized(false);
7931
8478
  };
7932
8479
  _self.trackDependencyData = function (dependency, properties) {
7933
8480
  _self[strTrackDependencyDataInternal](dependency, properties);
@@ -7994,8 +8541,8 @@ this.Microsoft = this.Microsoft || {};
7994
8541
  };
7995
8542
  _self[strTrackDependencyDataInternal] = function (dependency, properties, systemProperties) {
7996
8543
  if (_maxAjaxCallsPerView === -1 || _trackAjaxAttempts < _maxAjaxCallsPerView) {
7997
- if ((_config.distributedTracingMode === DistributedTracingModes.W3C
7998
- || _config.distributedTracingMode === DistributedTracingModes.AI_AND_W3C)
8544
+ if ((_config.distributedTracingMode === 2
8545
+ || _config.distributedTracingMode === 1 )
7999
8546
  && typeof dependency.id === "string" && dependency.id[dependency.id.length - 1] !== ".") {
8000
8547
  dependency.id += ".";
8001
8548
  }
@@ -8030,7 +8577,7 @@ this.Microsoft = this.Microsoft || {};
8030
8577
  var global = getGlobal();
8031
8578
  var isPolyfill = fetch.polyfill;
8032
8579
  if (_config.disableFetchTracking === false) {
8033
- _hooks.push(InstrumentFunc(global, strFetch, {
8580
+ _addHook(InstrumentFunc(global, strFetch, {
8034
8581
  req: function (callDetails, input, init) {
8035
8582
  var fetchData;
8036
8583
  if (_fetchInitialized &&
@@ -8078,7 +8625,7 @@ this.Microsoft = this.Microsoft || {};
8078
8625
  _fetchInitialized = true;
8079
8626
  }
8080
8627
  else if (isPolyfill) {
8081
- _hooks.push(InstrumentFunc(global, strFetch, {
8628
+ _addHook(InstrumentFunc(global, strFetch, {
8082
8629
  req: function (callDetails, input, init) {
8083
8630
  _isDisabledRequest(null, input, init);
8084
8631
  }
@@ -8089,7 +8636,7 @@ this.Microsoft = this.Microsoft || {};
8089
8636
  }
8090
8637
  }
8091
8638
  function _hookProto(target, funcName, callbacks) {
8092
- _hooks.push(InstrumentProto(target, funcName, callbacks));
8639
+ _addHook(InstrumentProto(target, funcName, callbacks));
8093
8640
  }
8094
8641
  function _instrumentXhr() {
8095
8642
  if (_supportsAjaxMonitoring(_self) && !_xhrInitialized) {
@@ -8211,7 +8758,7 @@ this.Microsoft = this.Microsoft || {};
8211
8758
  xhr[strAjaxData] = ajaxData;
8212
8759
  }
8213
8760
  function _attachToOnReadyStateChange(xhr) {
8214
- xhr[strAjaxData].xhrMonitoringState.stateChangeAttached = attachEvent(xhr, "readystatechange", function () {
8761
+ xhr[strAjaxData].xhrMonitoringState.stateChangeAttached = eventOn(xhr, "readystatechange", function () {
8215
8762
  try {
8216
8763
  if (xhr && xhr.readyState === 4 && _isMonitoredXhrInstance(xhr)) {
8217
8764
  _onAjaxComplete(xhr);
@@ -8226,7 +8773,7 @@ this.Microsoft = this.Microsoft || {};
8226
8773
  });
8227
8774
  }
8228
8775
  }
8229
- });
8776
+ }, _evtNamespace);
8230
8777
  }
8231
8778
  function _getResponseText(xhr) {
8232
8779
  try {
@@ -8511,7 +9058,7 @@ this.Microsoft = this.Microsoft || {};
8511
9058
  disableFetchTracking: true,
8512
9059
  excludeRequestFromAutoTrackingPatterns: undefined,
8513
9060
  disableCorrelationHeaders: false,
8514
- distributedTracingMode: DistributedTracingModes.AI_AND_W3C,
9061
+ distributedTracingMode: 1 ,
8515
9062
  correlationHeaderExcludedDomains: [
8516
9063
  "*.blob.core.windows.net",
8517
9064
  "*.blob.core.chinacloudapi.cn",
@@ -8916,4 +9463,4 @@ this.Microsoft = this.Microsoft || {};
8916
9463
  (function(obj, prop, descriptor) { /* ai_es3_polyfil defineProperty */ var func = Object["defineProperty"]; if (func) { try { return func(obj, prop, descriptor); } catch(e) { /* IE8 defines defineProperty, but will throw */ } } if (descriptor && typeof descriptor.value !== undefined) { obj[prop] = descriptor.value; } return obj; })(exports, '__esModule', { value: true });
8917
9464
 
8918
9465
  })(this.Microsoft.ApplicationInsights = this.Microsoft.ApplicationInsights || {});
8919
- //# sourceMappingURL=ai.2.8.0-beta.2202-07.gbl.js.map
9466
+ //# sourceMappingURL=ai.2.8.0-beta.2203-03.gbl.js.map