@microsoft/applicationinsights-web-basic 2.8.0-beta.2203-01 → 2.8.0-beta.2203-02

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.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Application Insights JavaScript Web SDK - Basic, 2.8.0-beta.2203-01
2
+ * Application Insights JavaScript Web SDK - Basic, 2.8.0-beta.2203-02
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
  (function (global, factory) {
@@ -350,99 +350,26 @@
350
350
  };
351
351
  dynamicProto[DynProtoDefaultOptions] = perfDefaults;
352
352
 
353
- var LoggingSeverity;
354
- (function (LoggingSeverity) {
355
- LoggingSeverity[LoggingSeverity["CRITICAL"] = 1] = "CRITICAL";
356
- LoggingSeverity[LoggingSeverity["WARNING"] = 2] = "WARNING";
357
- })(LoggingSeverity || (LoggingSeverity = {}));
358
- var _InternalMessageId = {
359
- BrowserDoesNotSupportLocalStorage: 0,
360
- BrowserCannotReadLocalStorage: 1,
361
- BrowserCannotReadSessionStorage: 2,
362
- BrowserCannotWriteLocalStorage: 3,
363
- BrowserCannotWriteSessionStorage: 4,
364
- BrowserFailedRemovalFromLocalStorage: 5,
365
- BrowserFailedRemovalFromSessionStorage: 6,
366
- CannotSendEmptyTelemetry: 7,
367
- ClientPerformanceMathError: 8,
368
- ErrorParsingAISessionCookie: 9,
369
- ErrorPVCalc: 10,
370
- ExceptionWhileLoggingError: 11,
371
- FailedAddingTelemetryToBuffer: 12,
372
- FailedMonitorAjaxAbort: 13,
373
- FailedMonitorAjaxDur: 14,
374
- FailedMonitorAjaxOpen: 15,
375
- FailedMonitorAjaxRSC: 16,
376
- FailedMonitorAjaxSend: 17,
377
- FailedMonitorAjaxGetCorrelationHeader: 18,
378
- FailedToAddHandlerForOnBeforeUnload: 19,
379
- FailedToSendQueuedTelemetry: 20,
380
- FailedToReportDataLoss: 21,
381
- FlushFailed: 22,
382
- MessageLimitPerPVExceeded: 23,
383
- MissingRequiredFieldSpecification: 24,
384
- NavigationTimingNotSupported: 25,
385
- OnError: 26,
386
- SessionRenewalDateIsZero: 27,
387
- SenderNotInitialized: 28,
388
- StartTrackEventFailed: 29,
389
- StopTrackEventFailed: 30,
390
- StartTrackFailed: 31,
391
- StopTrackFailed: 32,
392
- TelemetrySampledAndNotSent: 33,
393
- TrackEventFailed: 34,
394
- TrackExceptionFailed: 35,
395
- TrackMetricFailed: 36,
396
- TrackPVFailed: 37,
397
- TrackPVFailedCalc: 38,
398
- TrackTraceFailed: 39,
399
- TransmissionFailed: 40,
400
- FailedToSetStorageBuffer: 41,
401
- FailedToRestoreStorageBuffer: 42,
402
- InvalidBackendResponse: 43,
403
- FailedToFixDepricatedValues: 44,
404
- InvalidDurationValue: 45,
405
- TelemetryEnvelopeInvalid: 46,
406
- CreateEnvelopeError: 47,
407
- CannotSerializeObject: 48,
408
- CannotSerializeObjectNonSerializable: 49,
409
- CircularReferenceDetected: 50,
410
- ClearAuthContextFailed: 51,
411
- ExceptionTruncated: 52,
412
- IllegalCharsInName: 53,
413
- ItemNotInArray: 54,
414
- MaxAjaxPerPVExceeded: 55,
415
- MessageTruncated: 56,
416
- NameTooLong: 57,
417
- SampleRateOutOfRange: 58,
418
- SetAuthContextFailed: 59,
419
- SetAuthContextFailedAccountName: 60,
420
- StringValueTooLong: 61,
421
- StartCalledMoreThanOnce: 62,
422
- StopCalledWithoutStart: 63,
423
- TelemetryInitializerFailed: 64,
424
- TrackArgumentsNotSpecified: 65,
425
- UrlTooLong: 66,
426
- SessionStorageBufferFull: 67,
427
- CannotAccessCookie: 68,
428
- IdTooLong: 69,
429
- InvalidEvent: 70,
430
- FailedMonitorAjaxSetRequestHeader: 71,
431
- SendBrowserInfoOnUserInit: 72,
432
- PluginException: 73,
433
- NotificationException: 74,
434
- SnippetScriptLoadFailure: 99,
435
- InvalidInstrumentationKey: 100,
436
- CannotParseAiBlobValue: 101,
437
- InvalidContentBlob: 102,
438
- TrackPageActionEventFailed: 103,
439
- FailedAddingCustomDefinedRequestContext: 104,
440
- InMemoryStorageBufferFull: 105
441
- };
353
+ var strEmpty$1 = "";
354
+ var strProcessTelemetry = "processTelemetry";
355
+ var strPriority = "priority";
356
+ var strSetNextPlugin = "setNextPlugin";
357
+ var strIsInitialized = "isInitialized";
358
+ var strTeardown = "teardown";
359
+ var strCore = "core";
360
+ var strDisabled = "disabled";
361
+ var strDoTeardown = "_doTeardown";
362
+ var strProcessNext = "processNext";
363
+ var strResume = "resume";
364
+ var strPause = "pause";
365
+ var strNotificationListener = "NotificationListener";
366
+ var strAddNotificationListener = "add" + strNotificationListener;
367
+ var strRemoveNotificationListener = "remove" + strNotificationListener;
368
+ var strEventsSent = "eventsSent";
369
+ var strEventsDiscarded = "eventsDiscarded";
370
+ var strEventsSendRequest = "eventsSendRequest";
371
+ var strPerfEvent = "perfEvent";
442
372
 
443
- var strOnPrefix = "on";
444
- var strAttachEvent = "attachEvent";
445
- var strAddEventHelper = "addEventListener";
446
373
  var strToISOString = "toISOString";
447
374
  var cStrEndsWith = "endsWith";
448
375
  var cStrStartsWith = "startsWith";
@@ -453,7 +380,7 @@
453
380
  var strToString = "toString";
454
381
  var str__Proto = "__proto__";
455
382
  var strConstructor = "constructor";
456
- var _objDefineProperty = ObjDefineProperty;
383
+ var _objDefineProperty$1 = ObjDefineProperty;
457
384
  var _objFreeze = ObjClass.freeze;
458
385
  ObjClass.seal;
459
386
  var _objKeys = ObjClass.keys;
@@ -467,6 +394,9 @@
467
394
  var _objToString = ObjProto[strToString];
468
395
  var _fnToString = ObjHasOwnProperty[strToString];
469
396
  var _objFunctionString = _fnToString.call(ObjClass);
397
+ var rCamelCase = /-([a-z])/g;
398
+ var rNormalizeInvalid = /([^\w\d_$])/g;
399
+ var rLeadingNumeric = /^(\d+[\w\d_$])/;
470
400
  var _objGetPrototypeOf = Object["getPrototypeOf"];
471
401
  function _getObjProto(target) {
472
402
  if (target) {
@@ -501,24 +431,18 @@
501
431
  function isFunction(value) {
502
432
  return !!(value && typeof value === strShimFunction);
503
433
  }
504
- function attachEvent(obj, eventNameWithoutOn, handlerRef, useCapture) {
505
- if (useCapture === void 0) { useCapture = false; }
506
- var result = false;
507
- if (!isNullOrUndefined(obj)) {
508
- try {
509
- if (!isNullOrUndefined(obj[strAddEventHelper])) {
510
- obj[strAddEventHelper](eventNameWithoutOn, handlerRef, useCapture);
511
- result = true;
512
- }
513
- else if (!isNullOrUndefined(obj[strAttachEvent])) {
514
- obj[strAttachEvent](strOnPrefix + eventNameWithoutOn, handlerRef);
515
- result = true;
516
- }
517
- }
518
- catch (e) {
519
- }
434
+ function normalizeJsName(name) {
435
+ var value = name;
436
+ if (value && isString(value)) {
437
+ value = value.replace(rCamelCase, function (_all, letter) {
438
+ return letter.toUpperCase();
439
+ });
440
+ value = value.replace(rNormalizeInvalid, "_");
441
+ value = value.replace(rLeadingNumeric, function (_all, match) {
442
+ return "_" + match;
443
+ });
520
444
  }
521
- return result;
445
+ return value;
522
446
  }
523
447
  function objForEachKey(target, callbackfn) {
524
448
  if (target) {
@@ -738,7 +662,7 @@
738
662
  return result;
739
663
  }
740
664
  function objDefineAccessors(target, prop, getProp, setProp) {
741
- if (_objDefineProperty) {
665
+ if (_objDefineProperty$1) {
742
666
  try {
743
667
  var descriptor = {
744
668
  enumerable: true,
@@ -750,7 +674,7 @@
750
674
  if (setProp) {
751
675
  descriptor.set = setProp;
752
676
  }
753
- _objDefineProperty(target, prop, descriptor);
677
+ _objDefineProperty$1(target, prop, descriptor);
754
678
  return true;
755
679
  }
756
680
  catch (e) {
@@ -770,7 +694,7 @@
770
694
  if (isError(object)) {
771
695
  return object.name;
772
696
  }
773
- return "";
697
+ return strEmpty$1;
774
698
  }
775
699
  function setValue(target, field, value, valChk, srcChk) {
776
700
  var theValue = value;
@@ -857,6 +781,17 @@
857
781
  return class_1;
858
782
  }());
859
783
  }
784
+ function createEnumStyle(values) {
785
+ var enumClass = {};
786
+ objForEachKey(values, function (field, value) {
787
+ enumClass[field] = value;
788
+ if (!isUndefined(enumClass[value])) {
789
+ throwError("Value: [" + value + "] already exists for " + field);
790
+ }
791
+ enumClass[value] = field;
792
+ });
793
+ return objFreeze(enumClass);
794
+ }
860
795
  function optimizeObject(theObject) {
861
796
  if (theObject && ObjAssign) {
862
797
  theObject = ObjClass(ObjAssign({}, theObject));
@@ -1028,7 +963,7 @@
1028
963
  var nav = getNavigator();
1029
964
  if (nav && (nav.userAgent !== _navUserAgentCheck || _isTrident === null)) {
1030
965
  _navUserAgentCheck = nav.userAgent;
1031
- var userAgent = (_navUserAgentCheck || "").toLowerCase();
966
+ var userAgent = (_navUserAgentCheck || strEmpty$1).toLowerCase();
1032
967
  _isTrident = (strContains(userAgent, strMsie) || strContains(userAgent, strTrident));
1033
968
  }
1034
969
  return _isTrident;
@@ -1037,9 +972,9 @@
1037
972
  if (userAgentStr === void 0) { userAgentStr = null; }
1038
973
  if (!userAgentStr) {
1039
974
  var navigator_1 = getNavigator() || {};
1040
- userAgentStr = navigator_1 ? (navigator_1.userAgent || "").toLowerCase() : "";
975
+ userAgentStr = navigator_1 ? (navigator_1.userAgent || strEmpty$1).toLowerCase() : strEmpty$1;
1041
976
  }
1042
- var ua = (userAgentStr || "").toLowerCase();
977
+ var ua = (userAgentStr || strEmpty$1).toLowerCase();
1043
978
  if (strContains(ua, strMsie)) {
1044
979
  var doc = getDocument() || {};
1045
980
  return Math.max(parseInt(ua.split(strMsie)[1]), (doc[strDocumentMode] || 0));
@@ -1054,7 +989,7 @@
1054
989
  }
1055
990
  function dumpObj(object) {
1056
991
  var objectTypeDump = Object[strShimPrototype].toString.call(object);
1057
- var propertyValueDump = "";
992
+ var propertyValueDump = strEmpty$1;
1058
993
  if (objectTypeDump === "[object Error]") {
1059
994
  propertyValueDump = "{ stack: '" + object.stack + "', message: '" + object.message + "', name: '" + object.name + "'";
1060
995
  }
@@ -1148,9 +1083,9 @@
1148
1083
  var strWarnToConsole = "warnToConsole";
1149
1084
  function _sanitizeDiagnosticText(text) {
1150
1085
  if (text) {
1151
- return "\"" + text.replace(/\"/g, "") + "\"";
1086
+ return "\"" + text.replace(/\"/g, strEmpty$1) + "\"";
1152
1087
  }
1153
- return "";
1088
+ return strEmpty$1;
1154
1089
  }
1155
1090
  function _logToConsole(func, message) {
1156
1091
  var theConsole = getConsole();
@@ -1172,12 +1107,12 @@
1172
1107
  _self.message =
1173
1108
  (isUserAct ? AiUserActionablePrefix : AiNonUserActionablePrefix) +
1174
1109
  msgId;
1175
- var strProps = "";
1110
+ var strProps = strEmpty$1;
1176
1111
  if (hasJSON()) {
1177
1112
  strProps = getJSON().stringify(properties);
1178
1113
  }
1179
- var diagnosticText = (msg ? " message:" + _sanitizeDiagnosticText(msg) : "") +
1180
- (properties ? " props:" + _sanitizeDiagnosticText(strProps) : "");
1114
+ var diagnosticText = (msg ? " message:" + _sanitizeDiagnosticText(msg) : strEmpty$1) +
1115
+ (properties ? " props:" + _sanitizeDiagnosticText(strProps) : strEmpty$1);
1181
1116
  _self.message += diagnosticText;
1182
1117
  }
1183
1118
  _InternalLogMessage.dataType = "MessageData";
@@ -1207,7 +1142,7 @@
1207
1142
  throw message;
1208
1143
  }
1209
1144
  else {
1210
- var logFunc = severity === LoggingSeverity.CRITICAL ? strErrorToConsole : strWarnToConsole;
1145
+ var logFunc = severity === 1 ? strErrorToConsole : strWarnToConsole;
1211
1146
  if (!isUndefined(message.message)) {
1212
1147
  var logLevel = _self.consoleLoggingLevel();
1213
1148
  if (isUserAct) {
@@ -1225,7 +1160,7 @@
1225
1160
  _self.logInternalMessage(severity, message);
1226
1161
  }
1227
1162
  else {
1228
- _debugExtMsg("throw" + (severity === LoggingSeverity.CRITICAL ? "Critical" : "Warning"), message);
1163
+ _debugExtMsg("throw" + (severity === 1 ? "Critical" : "Warning"), message);
1229
1164
  }
1230
1165
  }
1231
1166
  };
@@ -1257,13 +1192,13 @@
1257
1192
  if (severity <= _self.telemetryLoggingLevel()) {
1258
1193
  _self.queue.push(message);
1259
1194
  _messageCount++;
1260
- _debugExtMsg((severity === LoggingSeverity.CRITICAL ? "error" : "warn"), message);
1195
+ _debugExtMsg((severity === 1 ? "error" : "warn"), message);
1261
1196
  }
1262
1197
  if (_messageCount === _self.maxInternalMessageLimit()) {
1263
1198
  var throttleLimitMessage = "Internal events throttle limit per PageView reached for this app.";
1264
- var throttleMessage = new _InternalLogMessage(_InternalMessageId.MessageLimitPerPVExceeded, throttleLimitMessage, false);
1199
+ var throttleMessage = new _InternalLogMessage(23 , throttleLimitMessage, false);
1265
1200
  _self.queue.push(throttleMessage);
1266
- if (severity === LoggingSeverity.CRITICAL) {
1201
+ if (severity === 1 ) {
1267
1202
  _self.errorToConsole(throttleLimitMessage);
1268
1203
  }
1269
1204
  else {
@@ -1437,6 +1372,217 @@
1437
1372
  return _defaultPerfManager;
1438
1373
  }
1439
1374
 
1375
+ var UInt32Mask = 0x100000000;
1376
+ var MaxUInt32 = 0xffffffff;
1377
+ var _mwcSeeded = false;
1378
+ var _mwcW = 123456789;
1379
+ var _mwcZ = 987654321;
1380
+ function _mwcSeed(seedValue) {
1381
+ if (seedValue < 0) {
1382
+ seedValue >>>= 0;
1383
+ }
1384
+ _mwcW = (123456789 + seedValue) & MaxUInt32;
1385
+ _mwcZ = (987654321 - seedValue) & MaxUInt32;
1386
+ _mwcSeeded = true;
1387
+ }
1388
+ function _autoSeedMwc() {
1389
+ try {
1390
+ var now = dateNow() & 0x7fffffff;
1391
+ _mwcSeed(((Math.random() * UInt32Mask) ^ now) + now);
1392
+ }
1393
+ catch (e) {
1394
+ }
1395
+ }
1396
+ function randomValue(maxValue) {
1397
+ if (maxValue > 0) {
1398
+ return Math.floor((random32() / MaxUInt32) * (maxValue + 1)) >>> 0;
1399
+ }
1400
+ return 0;
1401
+ }
1402
+ function random32(signed) {
1403
+ var value = 0;
1404
+ var c = getCrypto() || getMsCrypto();
1405
+ if (c && c.getRandomValues) {
1406
+ value = c.getRandomValues(new Uint32Array(1))[0] & MaxUInt32;
1407
+ }
1408
+ if (value === 0 && isIE()) {
1409
+ if (!_mwcSeeded) {
1410
+ _autoSeedMwc();
1411
+ }
1412
+ value = mwcRandom32() & MaxUInt32;
1413
+ }
1414
+ if (value === 0) {
1415
+ value = Math.floor((UInt32Mask * Math.random()) | 0);
1416
+ }
1417
+ if (!signed) {
1418
+ value >>>= 0;
1419
+ }
1420
+ return value;
1421
+ }
1422
+ function mwcRandomSeed(value) {
1423
+ if (!value) {
1424
+ _autoSeedMwc();
1425
+ }
1426
+ else {
1427
+ _mwcSeed(value);
1428
+ }
1429
+ }
1430
+ function mwcRandom32(signed) {
1431
+ _mwcZ = (36969 * (_mwcZ & 0xFFFF) + (_mwcZ >> 16)) & MaxUInt32;
1432
+ _mwcW = (18000 * (_mwcW & 0xFFFF) + (_mwcW >> 16)) & MaxUInt32;
1433
+ var value = (((_mwcZ << 16) + (_mwcW & 0xFFFF)) >>> 0) & MaxUInt32 | 0;
1434
+ if (!signed) {
1435
+ value >>>= 0;
1436
+ }
1437
+ return value;
1438
+ }
1439
+ function newId(maxLength) {
1440
+ if (maxLength === void 0) { maxLength = 22; }
1441
+ var base64chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
1442
+ var number = random32() >>> 0;
1443
+ var chars = 0;
1444
+ var result = strEmpty$1;
1445
+ while (result.length < maxLength) {
1446
+ chars++;
1447
+ result += base64chars.charAt(number & 0x3F);
1448
+ number >>>= 6;
1449
+ if (chars === 5) {
1450
+ number = (((random32() << 2) & 0xFFFFFFFF) | (number & 0x03)) >>> 0;
1451
+ chars = 0;
1452
+ }
1453
+ }
1454
+ return result;
1455
+ }
1456
+
1457
+ var _objDefineProperty = ObjDefineProperty;
1458
+ var version = "2.7.3";
1459
+ var instanceName = "." + newId(6);
1460
+ var _dataUid = 0;
1461
+ function _createAccessor(target, prop, value) {
1462
+ if (_objDefineProperty) {
1463
+ try {
1464
+ _objDefineProperty(target, prop, {
1465
+ value: value,
1466
+ enumerable: false,
1467
+ configurable: true
1468
+ });
1469
+ return true;
1470
+ }
1471
+ catch (e) {
1472
+ }
1473
+ }
1474
+ return false;
1475
+ }
1476
+ function _canAcceptData(target) {
1477
+ return target.nodeType === 1 || target.nodeType === 9 || !(+target.nodeType);
1478
+ }
1479
+ function _getCache(data, target) {
1480
+ var theCache = target[data.id];
1481
+ if (!theCache) {
1482
+ theCache = {};
1483
+ try {
1484
+ if (_canAcceptData(target)) {
1485
+ if (!_createAccessor(target, data.id, theCache)) {
1486
+ target[data.id] = theCache;
1487
+ }
1488
+ }
1489
+ }
1490
+ catch (e) {
1491
+ }
1492
+ }
1493
+ return theCache;
1494
+ }
1495
+ function createUniqueNamespace(name, includeVersion) {
1496
+ if (includeVersion === void 0) { includeVersion = false; }
1497
+ return normalizeJsName(name + (_dataUid++) + (includeVersion ? "." + version : "") + instanceName);
1498
+ }
1499
+ function createElmNodeData(name) {
1500
+ var data = {
1501
+ id: createUniqueNamespace("_aiData-" + (name || "") + "." + version),
1502
+ accept: function (target) {
1503
+ return _canAcceptData(target);
1504
+ },
1505
+ get: function (target, name, defValue, addDefault) {
1506
+ var theCache = target[data.id];
1507
+ if (!theCache) {
1508
+ if (addDefault) {
1509
+ theCache = _getCache(data, target);
1510
+ theCache[normalizeJsName(name)] = defValue;
1511
+ }
1512
+ return defValue;
1513
+ }
1514
+ return theCache[normalizeJsName(name)];
1515
+ },
1516
+ kill: function (target, name) {
1517
+ if (target && target[name]) {
1518
+ try {
1519
+ delete target[name];
1520
+ }
1521
+ catch (e) {
1522
+ }
1523
+ }
1524
+ }
1525
+ };
1526
+ return data;
1527
+ }
1528
+
1529
+ var pluginStateData = createElmNodeData("plugin");
1530
+ function _getPluginState(plugin) {
1531
+ return pluginStateData.get(plugin, "state", {}, true);
1532
+ }
1533
+ function initializePlugins(processContext, extensions) {
1534
+ var initPlugins = [];
1535
+ var lastPlugin = null;
1536
+ var proxy = processContext.getNext();
1537
+ var pluginState;
1538
+ while (proxy) {
1539
+ var thePlugin = proxy.getPlugin();
1540
+ if (thePlugin) {
1541
+ if (lastPlugin &&
1542
+ isFunction(lastPlugin[strSetNextPlugin]) &&
1543
+ isFunction(thePlugin[strProcessTelemetry])) {
1544
+ lastPlugin[strSetNextPlugin](thePlugin);
1545
+ }
1546
+ var isInitialized = false;
1547
+ if (isFunction(thePlugin[strIsInitialized])) {
1548
+ isInitialized = thePlugin[strIsInitialized]();
1549
+ }
1550
+ else {
1551
+ pluginState = _getPluginState(thePlugin);
1552
+ isInitialized = pluginState[strIsInitialized];
1553
+ }
1554
+ if (!isInitialized) {
1555
+ initPlugins.push(thePlugin);
1556
+ }
1557
+ lastPlugin = thePlugin;
1558
+ proxy = proxy.getNext();
1559
+ }
1560
+ }
1561
+ arrForEach(initPlugins, function (thePlugin) {
1562
+ var core = processContext.core();
1563
+ thePlugin.initialize(processContext.getCfg(), core, extensions, processContext.getNext());
1564
+ pluginState = _getPluginState(thePlugin);
1565
+ if (!thePlugin[strCore] && !pluginState[strCore]) {
1566
+ pluginState[strCore] = core;
1567
+ }
1568
+ pluginState[strIsInitialized] = true;
1569
+ delete pluginState[strTeardown];
1570
+ });
1571
+ }
1572
+ function sortPlugins(plugins) {
1573
+ return plugins.sort(function (extA, extB) {
1574
+ var result = 0;
1575
+ var bHasProcess = isFunction(extB[strProcessTelemetry]);
1576
+ if (isFunction(extA[strProcessTelemetry])) {
1577
+ result = bHasProcess ? extA[strPriority] - extB[strPriority] : 1;
1578
+ }
1579
+ else if (bHasProcess) {
1580
+ result = -1;
1581
+ }
1582
+ return result;
1583
+ });
1584
+ }
1585
+
1440
1586
  var strTelemetryPluginChain = "TelemetryPluginChain";
1441
1587
  var strHasRunFlags = "_hasRun";
1442
1588
  var strGetTelCtx = "_getTelCtx";
@@ -1450,53 +1596,66 @@
1450
1596
  }
1451
1597
  return createTelemetryProxyChain([startAt], config, core);
1452
1598
  }
1453
- function createProcessTelemetryContext(telemetryChain, config, core, startAt) {
1454
- var _nextProxy = null;
1455
- var _onComplete = null;
1456
- if (startAt) {
1457
- _nextProxy = _getNextProxyStart(telemetryChain, config, core, startAt);
1458
- }
1459
- else {
1460
- _nextProxy = telemetryChain;
1461
- }
1599
+ function _createInternalContext(telemetryChain, config, core, startAt) {
1600
+ var _nextProxy = startAt ? _getNextProxyStart(telemetryChain, config, core, startAt) : telemetryChain;
1601
+ var _onComplete = [];
1462
1602
  var context = {
1463
- core: function () {
1464
- return core;
1465
- },
1466
- diagLog: function () {
1467
- return safeGetLogger(core, config);
1468
- },
1469
- getCfg: function () {
1470
- return config;
1471
- },
1472
- getExtCfg: _getExtCfg,
1473
- getConfig: _getConfig,
1474
- hasNext: function () {
1475
- return _nextProxy != null;
1476
- },
1477
- getNext: function () {
1478
- return _nextProxy;
1479
- },
1480
- setNext: function (nextPlugin) {
1481
- _nextProxy = nextPlugin;
1482
- },
1483
- processNext: function (env) {
1484
- _processChain(function (nextPlugin) {
1485
- nextPlugin.processTelemetry(env, context);
1603
+ _next: _moveNext,
1604
+ ctx: {
1605
+ core: function () { return core; },
1606
+ diagLog: function () {
1607
+ return safeGetLogger(core, config);
1608
+ },
1609
+ getCfg: function () {
1610
+ return config;
1611
+ },
1612
+ getExtCfg: _getExtCfg,
1613
+ getConfig: _getConfig,
1614
+ hasNext: function () {
1615
+ return !!_nextProxy;
1616
+ },
1617
+ getNext: function () {
1618
+ return _nextProxy;
1619
+ },
1620
+ setNext: function (nextPlugin) {
1621
+ _nextProxy = nextPlugin;
1622
+ },
1623
+ iterate: _iterateChain,
1624
+ onComplete: _addOnComplete
1625
+ }
1626
+ };
1627
+ function _addOnComplete(onComplete, that) {
1628
+ var args = [];
1629
+ for (var _i = 2; _i < arguments.length; _i++) {
1630
+ args[_i - 2] = arguments[_i];
1631
+ }
1632
+ if (onComplete) {
1633
+ _onComplete.push({
1634
+ func: onComplete,
1635
+ self: !isUndefined(that) ? that : context.ctx,
1636
+ args: args
1486
1637
  });
1487
- },
1488
- iterate: _iterateChain,
1489
- createNew: function (plugins, startAt) {
1490
- if (plugins === void 0) { plugins = null; }
1491
- if (isArray(plugins)) {
1492
- plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1638
+ }
1639
+ }
1640
+ function _moveNext() {
1641
+ var nextProxy = _nextProxy;
1642
+ _nextProxy = nextProxy ? nextProxy.getNext() : null;
1643
+ if (!nextProxy) {
1644
+ var onComplete = _onComplete;
1645
+ if (onComplete && onComplete.length > 0) {
1646
+ arrForEach(onComplete, function (completeDetails) {
1647
+ try {
1648
+ completeDetails.func.call(completeDetails.self, completeDetails.args);
1649
+ }
1650
+ catch (e) {
1651
+ core.logger.throwInternal(2 , 73 , "Unexpected Exception during onComplete - " + dumpObj(e));
1652
+ }
1653
+ });
1654
+ _onComplete = [];
1493
1655
  }
1494
- return createProcessTelemetryContext(plugins || _nextProxy, config, core, startAt);
1495
- },
1496
- onComplete: function (onComplete) {
1497
- _onComplete = onComplete;
1498
1656
  }
1499
- };
1657
+ return nextProxy;
1658
+ }
1500
1659
  function _getExtCfg(identifier, defaultValue, mergeDefault) {
1501
1660
  if (defaultValue === void 0) { defaultValue = {}; }
1502
1661
  if (mergeDefault === void 0) { mergeDefault = 0 ; }
@@ -1539,29 +1698,53 @@
1539
1698
  }
1540
1699
  return !isNullOrUndefined(theValue) ? theValue : defaultValue;
1541
1700
  }
1542
- function _processChain(cb) {
1543
- var nextPlugin = _nextProxy;
1544
- if (nextPlugin) {
1545
- _nextProxy = nextPlugin.getNext();
1546
- cb(nextPlugin);
1547
- }
1548
- else {
1549
- if (_onComplete) {
1550
- _onComplete();
1551
- _onComplete = null;
1701
+ function _iterateChain(cb) {
1702
+ var nextPlugin;
1703
+ while (!!(nextPlugin = context._next())) {
1704
+ var plugin = nextPlugin.getPlugin();
1705
+ if (plugin) {
1706
+ cb(plugin);
1552
1707
  }
1553
1708
  }
1554
1709
  }
1555
- function _iterateChain(cb) {
1556
- while (_nextProxy) {
1557
- _processChain(function (nextPlugin) {
1558
- var plugin = nextPlugin.getPlugin();
1559
- if (plugin) {
1560
- cb(plugin);
1561
- }
1562
- });
1710
+ return context;
1711
+ }
1712
+ function createProcessTelemetryContext(telemetryChain, config, core, startAt) {
1713
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1714
+ var context = internalContext.ctx;
1715
+ function _processNext(env) {
1716
+ var nextPlugin = internalContext._next();
1717
+ nextPlugin && nextPlugin.processTelemetry(env, context);
1718
+ return !nextPlugin;
1719
+ }
1720
+ function _createNew(plugins, startAt) {
1721
+ if (plugins === void 0) { plugins = null; }
1722
+ if (isArray(plugins)) {
1723
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1724
+ }
1725
+ return createProcessTelemetryContext(plugins || context.getNext(), config, core, startAt);
1726
+ }
1727
+ context.processNext = _processNext;
1728
+ context.createNew = _createNew;
1729
+ return context;
1730
+ }
1731
+ function createProcessTelemetryUnloadContext(telemetryChain, config, core, startAt) {
1732
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1733
+ var context = internalContext.ctx;
1734
+ function _processNext(unloadState) {
1735
+ var nextPlugin = internalContext._next();
1736
+ nextPlugin && nextPlugin.unload(context, unloadState);
1737
+ return !nextPlugin;
1738
+ }
1739
+ function _createNew(plugins, startAt) {
1740
+ if (plugins === void 0) { plugins = null; }
1741
+ if (isArray(plugins)) {
1742
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1563
1743
  }
1744
+ return createProcessTelemetryUnloadContext(plugins || context.getNext(), config, core, startAt);
1564
1745
  }
1746
+ context.processNext = _processNext;
1747
+ context.createNew = _createNew;
1565
1748
  return context;
1566
1749
  }
1567
1750
  function createTelemetryProxyChain(plugins, config, core, startAt) {
@@ -1609,32 +1792,35 @@
1609
1792
  return nextProxy;
1610
1793
  },
1611
1794
  processTelemetry: _processTelemetry,
1795
+ unload: _unloadPlugin,
1612
1796
  _id: chainId,
1613
1797
  _setNext: function (nextPlugin) {
1614
1798
  nextProxy = nextPlugin;
1615
1799
  }
1616
1800
  };
1617
- function _processChain(itemCtx, processPluginFn, processProxyFn, name, details, isAsync) {
1801
+ function _getTelCtx() {
1802
+ var itemCtx;
1803
+ if (plugin && isFunction(plugin[strGetTelCtx])) {
1804
+ itemCtx = plugin[strGetTelCtx]();
1805
+ }
1618
1806
  if (!itemCtx) {
1619
- if (plugin && isFunction(plugin[strGetTelCtx])) {
1620
- itemCtx = plugin[strGetTelCtx]();
1621
- }
1622
- if (!itemCtx) {
1623
- itemCtx = createProcessTelemetryContext(proxyChain, config, core);
1624
- }
1807
+ itemCtx = createProcessTelemetryContext(proxyChain, config, core);
1625
1808
  }
1809
+ return itemCtx;
1810
+ }
1811
+ function _processChain(itemCtx, processPluginFn, name, details, isAsync) {
1812
+ var hasRun = false;
1626
1813
  var identifier = plugin ? plugin.identifier : strTelemetryPluginChain;
1627
1814
  var hasRunContext = itemCtx[strHasRunFlags];
1628
1815
  if (!hasRunContext) {
1629
1816
  hasRunContext = itemCtx[strHasRunFlags] = {};
1630
1817
  }
1631
- doPerf(itemCtx.core(), function () { return identifier + ":" + name; }, function () {
1632
- hasRunContext[chainId] = true;
1633
- var hasRun = false;
1634
- itemCtx.setNext(nextProxy);
1635
- if (plugin) {
1818
+ itemCtx.setNext(nextProxy);
1819
+ if (plugin) {
1820
+ doPerf(itemCtx[strCore](), function () { return identifier + ":" + name; }, function () {
1821
+ hasRunContext[chainId] = true;
1636
1822
  try {
1637
- var nextId = nextProxy ? nextProxy._id : "";
1823
+ var nextId = nextProxy ? nextProxy._id : strEmpty$1;
1638
1824
  if (nextId) {
1639
1825
  hasRunContext[nextId] = false;
1640
1826
  }
@@ -1646,18 +1832,21 @@
1646
1832
  hasRun = true;
1647
1833
  }
1648
1834
  if (!nextProxy || !hasNextRun) {
1649
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.PluginException, "Plugin [" + plugin.identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
1835
+ itemCtx.diagLog().throwInternal(1 , 73 , "Plugin [" + plugin.identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
1650
1836
  }
1651
1837
  }
1652
- }
1653
- if (nextProxy && !hasRun) {
1654
- processProxyFn(itemCtx);
1655
- }
1656
- }, details, isAsync);
1838
+ }, details, isAsync);
1839
+ }
1840
+ return hasRun;
1657
1841
  }
1658
1842
  function _processTelemetry(env, itemCtx) {
1659
- _processChain(itemCtx, function (itemCtx) {
1660
- if (!hasProcessTelemetry) {
1843
+ itemCtx = itemCtx || _getTelCtx();
1844
+ function _callProcessTelemetry(itemCtx) {
1845
+ if (!plugin || !hasProcessTelemetry) {
1846
+ return false;
1847
+ }
1848
+ var pluginState = _getPluginState(plugin);
1849
+ if (pluginState[strTeardown] || pluginState[strDisabled]) {
1661
1850
  return false;
1662
1851
  }
1663
1852
  if (hasSetNext) {
@@ -1665,52 +1854,33 @@
1665
1854
  }
1666
1855
  plugin.processTelemetry(env, itemCtx);
1667
1856
  return true;
1668
- }, function (itemCtx) {
1669
- nextProxy.processTelemetry(env, itemCtx);
1670
- }, "processTelemetry", function () { return ({ item: env }); }, !(env.sync));
1671
- }
1672
- return objFreeze(proxyChain);
1673
- }
1674
-
1675
- var processTelemetry = "processTelemetry";
1676
- var priority = "priority";
1677
- var setNextPlugin = "setNextPlugin";
1678
- var isInitialized = "isInitialized";
1679
- function initializePlugins(processContext, extensions) {
1680
- var initPlugins = [];
1681
- var lastPlugin = null;
1682
- var proxy = processContext.getNext();
1683
- while (proxy) {
1684
- var thePlugin = proxy.getPlugin();
1685
- if (thePlugin) {
1686
- if (lastPlugin &&
1687
- isFunction(lastPlugin[setNextPlugin]) &&
1688
- isFunction(thePlugin[processTelemetry])) {
1689
- lastPlugin[setNextPlugin](thePlugin);
1690
- }
1691
- if (!isFunction(thePlugin[isInitialized]) || !thePlugin[isInitialized]()) {
1692
- initPlugins.push(thePlugin);
1693
- }
1694
- lastPlugin = thePlugin;
1695
- proxy = proxy.getNext();
1857
+ }
1858
+ if (!_processChain(itemCtx, _callProcessTelemetry, "processTelemetry", function () { return ({ item: env }); }, !(env.sync))) {
1859
+ itemCtx.processNext(env);
1696
1860
  }
1697
1861
  }
1698
- arrForEach(initPlugins, function (thePlugin) {
1699
- thePlugin.initialize(processContext.getCfg(), processContext.core(), extensions, processContext.getNext());
1700
- });
1701
- }
1702
- function sortPlugins(plugins) {
1703
- return plugins.sort(function (extA, extB) {
1704
- var result = 0;
1705
- var bHasProcess = isFunction(extB[processTelemetry]);
1706
- if (isFunction(extA[processTelemetry])) {
1707
- result = bHasProcess ? extA[priority] - extB[priority] : 1;
1862
+ function _unloadPlugin(unloadCtx, unloadState) {
1863
+ function _callTeardown() {
1864
+ var hasRun = false;
1865
+ if (plugin) {
1866
+ var pluginState = _getPluginState(plugin);
1867
+ var pluginCore = plugin[strCore] || pluginState.core;
1868
+ if (plugin && (!pluginCore || pluginCore === unloadCtx[strCore]()) && !pluginState[strTeardown]) {
1869
+ pluginState[strCore] = null;
1870
+ pluginState[strTeardown] = true;
1871
+ pluginState[strIsInitialized] = false;
1872
+ if (plugin[strTeardown] && plugin[strTeardown](unloadCtx, unloadState) === true) {
1873
+ hasRun = true;
1874
+ }
1875
+ }
1876
+ }
1877
+ return hasRun;
1708
1878
  }
1709
- else if (bHasProcess) {
1710
- result = -1;
1879
+ if (!_processChain(unloadCtx, _callTeardown, "unload", function () { }, unloadState.isAsync)) {
1880
+ unloadCtx.processNext(unloadState);
1711
1881
  }
1712
- return result;
1713
- });
1882
+ }
1883
+ return objFreeze(proxyChain);
1714
1884
  }
1715
1885
 
1716
1886
  var strToGMTString = "toGMTString";
@@ -1721,7 +1891,6 @@
1721
1891
  var strIsCookieUseDisabled = "isCookieUseDisabled";
1722
1892
  var strDisableCookiesUsage = "disableCookiesUsage";
1723
1893
  var strConfigCookieMgr = "_ckMgr";
1724
- var strEmpty = "";
1725
1894
  var _supportsCookies = null;
1726
1895
  var _allowUaSameSite = null;
1727
1896
  var _parsedCookieValue = null;
@@ -1779,7 +1948,7 @@
1779
1948
  var result = false;
1780
1949
  if (_isMgrEnabled(cookieMgr)) {
1781
1950
  var values = {};
1782
- var theValue = strTrim(value || strEmpty);
1951
+ var theValue = strTrim(value || strEmpty$1);
1783
1952
  var idx = theValue.indexOf(";");
1784
1953
  if (idx !== -1) {
1785
1954
  theValue = strTrim(value.substring(0, idx));
@@ -1794,11 +1963,11 @@
1794
1963
  if (expireMs > 0) {
1795
1964
  var expiry = new Date();
1796
1965
  expiry.setTime(expireMs);
1797
- setValue(values, strExpires, _formatDate(expiry, !_isIE ? strToUTCString : strToGMTString) || _formatDate(expiry, _isIE ? strToGMTString : strToUTCString) || strEmpty, isTruthy);
1966
+ setValue(values, strExpires, _formatDate(expiry, !_isIE ? strToUTCString : strToGMTString) || _formatDate(expiry, _isIE ? strToGMTString : strToUTCString) || strEmpty$1, isTruthy);
1798
1967
  }
1799
1968
  }
1800
1969
  if (!_isIE) {
1801
- setValue(values, "max-age", strEmpty + maxAgeSec, null, isUndefined);
1970
+ setValue(values, "max-age", strEmpty$1 + maxAgeSec, null, isUndefined);
1802
1971
  }
1803
1972
  }
1804
1973
  var location_1 = getLocation();
@@ -1819,7 +1988,7 @@
1819
1988
  return result;
1820
1989
  },
1821
1990
  get: function (name) {
1822
- var value = strEmpty;
1991
+ var value = strEmpty$1;
1823
1992
  if (_isMgrEnabled(cookieMgr)) {
1824
1993
  value = (cookieMgrConfig.getCookie || _getCookieValue)(name);
1825
1994
  }
@@ -1844,7 +2013,7 @@
1844
2013
  values["max-age"] = "0";
1845
2014
  }
1846
2015
  var delCookie = cookieMgrConfig.delCookie || _setCookieValue;
1847
- delCookie(name, _formatCookieValue(strEmpty, values));
2016
+ delCookie(name, _formatCookieValue(strEmpty$1, values));
1848
2017
  result = true;
1849
2018
  }
1850
2019
  return result;
@@ -1861,7 +2030,7 @@
1861
2030
  _supportsCookies = doc[strCookie] !== undefined;
1862
2031
  }
1863
2032
  catch (e) {
1864
- logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.CannotAccessCookie, "Cannot access document.cookie - " + getExceptionName(e), { exception: dumpObj(e) });
2033
+ logger && logger.throwInternal(2 , 68 , "Cannot access document.cookie - " + getExceptionName(e), { exception: dumpObj(e) });
1865
2034
  }
1866
2035
  }
1867
2036
  return _supportsCookies;
@@ -1871,7 +2040,7 @@
1871
2040
  if (theValue && theValue.length) {
1872
2041
  var parts = strTrim(theValue).split(";");
1873
2042
  arrForEach(parts, function (thePart) {
1874
- thePart = strTrim(thePart || strEmpty);
2043
+ thePart = strTrim(thePart || strEmpty$1);
1875
2044
  if (thePart) {
1876
2045
  var idx = thePart.indexOf("=");
1877
2046
  if (idx === -1) {
@@ -1892,21 +2061,21 @@
1892
2061
  return null;
1893
2062
  }
1894
2063
  function _formatCookieValue(value, values) {
1895
- var cookieValue = value || strEmpty;
2064
+ var cookieValue = value || strEmpty$1;
1896
2065
  objForEachKey(values, function (name, theValue) {
1897
- cookieValue += "; " + name + (!isNullOrUndefined(theValue) ? "=" + theValue : strEmpty);
2066
+ cookieValue += "; " + name + (!isNullOrUndefined(theValue) ? "=" + theValue : strEmpty$1);
1898
2067
  });
1899
2068
  return cookieValue;
1900
2069
  }
1901
2070
  function _getCookieValue(name) {
1902
- var cookieValue = strEmpty;
2071
+ var cookieValue = strEmpty$1;
1903
2072
  if (_doc) {
1904
- var theCookie = _doc[strCookie] || strEmpty;
2073
+ var theCookie = _doc[strCookie] || strEmpty$1;
1905
2074
  if (_parsedCookieValue !== theCookie) {
1906
2075
  _cookieCache = _extractParts(theCookie);
1907
2076
  _parsedCookieValue = theCookie;
1908
2077
  }
1909
- cookieValue = strTrim(_cookieCache[name] || strEmpty);
2078
+ cookieValue = strTrim(_cookieCache[name] || strEmpty$1);
1910
2079
  }
1911
2080
  return cookieValue;
1912
2081
  }
@@ -1962,87 +2131,110 @@
1962
2131
  }
1963
2132
  }
1964
2133
  function createChannelControllerPlugin(channelQueue, core) {
1965
- function _getTelCtx(itemCtx) {
1966
- if (!itemCtx) {
1967
- itemCtx = createProcessTelemetryContext(null, core.config, core, null);
2134
+ var _a;
2135
+ function _getTelCtx() {
2136
+ return createProcessTelemetryContext(null, core.config, core, null);
2137
+ }
2138
+ function _processChannelQueue(theChannels, itemCtx, processFn, onComplete) {
2139
+ var waiting = theChannels ? (theChannels.length + 1) : 1;
2140
+ function _runChainOnComplete() {
2141
+ waiting--;
2142
+ if (waiting === 0) {
2143
+ onComplete && onComplete();
2144
+ onComplete = null;
2145
+ }
1968
2146
  }
1969
- return itemCtx;
1970
- }
1971
- function _processChannelQueue(itemCtx, processFn, onComplete) {
1972
- if (channelQueue && channelQueue.length > 0) {
1973
- var waiting_1 = channelQueue.length;
1974
- arrForEach(channelQueue, function (channels) {
2147
+ if (waiting > 0) {
2148
+ arrForEach(theChannels, function (channels) {
1975
2149
  if (channels && channels.queue.length > 0) {
1976
2150
  var channelChain = channels.chain;
1977
- var chainCtx = _getTelCtx(itemCtx).createNew(channelChain);
1978
- chainCtx.onComplete(function () {
1979
- waiting_1--;
1980
- if (waiting_1 === 0) {
1981
- onComplete && onComplete();
1982
- onComplete = null;
1983
- }
1984
- });
2151
+ var chainCtx = itemCtx.createNew(channelChain);
2152
+ chainCtx.onComplete(_runChainOnComplete);
1985
2153
  processFn(chainCtx);
1986
2154
  }
1987
2155
  else {
1988
- waiting_1--;
2156
+ waiting--;
1989
2157
  }
1990
2158
  });
1991
- if (waiting_1 === 0) {
1992
- onComplete && onComplete();
1993
- }
1994
- }
1995
- else {
1996
- onComplete && onComplete();
1997
2159
  }
2160
+ _runChainOnComplete();
1998
2161
  }
1999
- var isInitialized = false;
2000
- var channelController = {
2001
- identifier: "ChannelControllerPlugin",
2002
- priority: ChannelControllerPriority,
2003
- initialize: function (config, core, extensions, pluginChain) {
2004
- isInitialized = true;
2162
+ function _doTeardown(unloadCtx, unloadState) {
2163
+ var theUnloadState = unloadState || {
2164
+ reason: 0 ,
2165
+ isAsync: false
2166
+ };
2167
+ _processChannelQueue(channelQueue, unloadCtx, function (chainCtx) {
2168
+ chainCtx[strProcessNext](theUnloadState);
2169
+ }, function () {
2170
+ unloadCtx[strProcessNext](theUnloadState);
2171
+ isInitialized = false;
2172
+ });
2173
+ return true;
2174
+ }
2175
+ function _getChannel(pluginIdentifier) {
2176
+ var thePlugin = null;
2177
+ if (channelQueue && channelQueue.length > 0) {
2005
2178
  arrForEach(channelQueue, function (channels) {
2006
2179
  if (channels && channels.queue.length > 0) {
2007
- initializePlugins(createProcessTelemetryContext(channels.chain, config, core), extensions);
2180
+ arrForEach(channels.queue, function (ext) {
2181
+ if (ext.identifier === pluginIdentifier) {
2182
+ thePlugin = ext;
2183
+ return -1;
2184
+ }
2185
+ });
2186
+ if (thePlugin) {
2187
+ return -1;
2188
+ }
2008
2189
  }
2009
2190
  });
2010
- },
2011
- isInitialized: function () { return isInitialized; },
2012
- processTelemetry: function (item, itemCtx) {
2013
- _processChannelQueue(itemCtx, function (chainCtx) {
2014
- chainCtx.processNext(item);
2015
- }, function () {
2016
- itemCtx.processNext(item);
2017
- });
2018
- },
2019
- pause: function () {
2020
- _processChannelQueue(null, function (chainCtx) {
2021
- chainCtx.iterate(function (plugin) {
2022
- plugin.pause && plugin.pause();
2191
+ }
2192
+ return thePlugin;
2193
+ }
2194
+ var isInitialized = false;
2195
+ var channelController = (_a = {
2196
+ identifier: "ChannelControllerPlugin",
2197
+ priority: ChannelControllerPriority,
2198
+ initialize: function (config, core, extensions, pluginChain) {
2199
+ isInitialized = true;
2200
+ arrForEach(channelQueue, function (channels) {
2201
+ if (channels && channels.queue.length > 0) {
2202
+ initializePlugins(createProcessTelemetryContext(channels.chain, config, core), extensions);
2203
+ }
2023
2204
  });
2024
- });
2205
+ },
2206
+ isInitialized: function () { return isInitialized; },
2207
+ processTelemetry: function (item, itemCtx) {
2208
+ _processChannelQueue(channelQueue, itemCtx || _getTelCtx(), function (chainCtx) {
2209
+ chainCtx[strProcessNext](item);
2210
+ }, function () {
2211
+ itemCtx[strProcessNext](item);
2212
+ });
2213
+ }
2025
2214
  },
2026
- resume: function () {
2027
- _processChannelQueue(null, function (chainCtx) {
2215
+ _a[strPause] = function () {
2216
+ _processChannelQueue(channelQueue, _getTelCtx(), function (chainCtx) {
2028
2217
  chainCtx.iterate(function (plugin) {
2029
- plugin.resume && plugin.resume();
2218
+ plugin[strPause] && plugin[strPause]();
2030
2219
  });
2031
- });
2220
+ }, null);
2032
2221
  },
2033
- teardown: function () {
2034
- _processChannelQueue(null, function (chainCtx) {
2222
+ _a[strResume] = function () {
2223
+ _processChannelQueue(channelQueue, _getTelCtx(), function (chainCtx) {
2035
2224
  chainCtx.iterate(function (plugin) {
2036
- plugin.teardown && plugin.teardown();
2225
+ plugin[strResume] && plugin[strResume]();
2037
2226
  });
2038
- });
2227
+ }, null);
2039
2228
  },
2040
- flush: function (isAsync, callBack, sendReason, cbTimeout) {
2229
+ _a[strTeardown] = _doTeardown,
2230
+ _a.getChannel = _getChannel,
2231
+ _a.flush = function (isAsync, callBack, sendReason, cbTimeout) {
2232
+ var waiting = 1;
2041
2233
  var doneIterating = false;
2042
- var waiting = 0;
2043
2234
  var cbTimer = null;
2044
2235
  cbTimeout = cbTimeout || 5000;
2045
2236
  function doCallback() {
2237
+ waiting--;
2046
2238
  if (doneIterating && waiting === 0) {
2047
2239
  if (cbTimer) {
2048
2240
  clearTimeout(cbTimer);
@@ -2052,32 +2244,38 @@
2052
2244
  callBack = null;
2053
2245
  }
2054
2246
  }
2055
- waiting = 1;
2056
- _processChannelQueue(null, function (chainCtx) {
2247
+ _processChannelQueue(channelQueue, _getTelCtx(), function (chainCtx) {
2057
2248
  chainCtx.iterate(function (plugin) {
2058
2249
  if (plugin.flush) {
2059
2250
  waiting++;
2251
+ var handled_1 = false;
2060
2252
  if (!plugin.flush(isAsync, function () {
2061
- waiting--;
2253
+ handled_1 = true;
2062
2254
  doCallback();
2063
2255
  }, sendReason)) {
2064
- if (cbTimer == null) {
2065
- cbTimer = setTimeout(function () {
2066
- cbTimer = null;
2067
- callBack && callBack(false);
2068
- callBack = null;
2069
- }, cbTimeout);
2256
+ if (!handled_1) {
2257
+ if (isAsync && cbTimer == null) {
2258
+ cbTimer = setTimeout(function () {
2259
+ cbTimer = null;
2260
+ doCallback();
2261
+ }, cbTimeout);
2262
+ }
2263
+ else {
2264
+ doCallback();
2265
+ }
2070
2266
  }
2071
2267
  }
2072
2268
  }
2073
2269
  });
2074
2270
  }, function () {
2075
- waiting--;
2076
2271
  doneIterating = true;
2077
2272
  doCallback();
2078
2273
  });
2079
- }
2080
- };
2274
+ },
2275
+ _a._setQueue = function (queue) {
2276
+ channelQueue = queue;
2277
+ },
2278
+ _a);
2081
2279
  return channelController;
2082
2280
  }
2083
2281
  function createChannelQueues(channels, extensions, config, core) {
@@ -2111,6 +2309,38 @@
2111
2309
  _setDefaults(config, core, pluginChain);
2112
2310
  _isinitialized = true;
2113
2311
  };
2312
+ _self.teardown = function (unloadCtx, unloadState) {
2313
+ if (!_self.core || (unloadCtx && _self.core !== unloadCtx.core())) {
2314
+ return;
2315
+ }
2316
+ var result;
2317
+ var unloadDone = false;
2318
+ var theUnloadCtx = unloadCtx || createProcessTelemetryUnloadContext(null, {}, _self.core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
2319
+ var theUnloadState = unloadState || {
2320
+ reason: 0 ,
2321
+ isAsync: false
2322
+ };
2323
+ function _unloadCallback() {
2324
+ if (!unloadDone) {
2325
+ unloadDone = true;
2326
+ arrForEach(_hooks, function (fn) {
2327
+ fn.rm();
2328
+ });
2329
+ _hooks = [];
2330
+ if (result === true) {
2331
+ theUnloadCtx.processNext(theUnloadState);
2332
+ }
2333
+ _initDefaults();
2334
+ }
2335
+ }
2336
+ if (!_self[strDoTeardown] || _self[strDoTeardown](theUnloadCtx, theUnloadState, _unloadCallback) !== true) {
2337
+ _unloadCallback();
2338
+ }
2339
+ else {
2340
+ result = true;
2341
+ }
2342
+ return result;
2343
+ };
2114
2344
  _self._addHook = function (hooks) {
2115
2345
  if (hooks) {
2116
2346
  if (isArray(hooks)) {
@@ -2125,13 +2355,13 @@
2125
2355
  _self.diagLog = function (itemCtx) {
2126
2356
  return _getTelCtx(itemCtx).diagLog();
2127
2357
  };
2128
- _self.isInitialized = function () {
2358
+ _self[strIsInitialized] = function () {
2129
2359
  return _isinitialized;
2130
2360
  };
2131
2361
  _self.setInitialized = function (isInitialized) {
2132
2362
  _isinitialized = isInitialized;
2133
2363
  };
2134
- _self.setNextPlugin = function (next) {
2364
+ _self[strSetNextPlugin] = function (next) {
2135
2365
  _nextPlugin = next;
2136
2366
  };
2137
2367
  _self.processNext = function (env, itemCtx) {
@@ -2223,7 +2453,7 @@
2223
2453
  }
2224
2454
  }
2225
2455
  catch (e) {
2226
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TelemetryInitializerFailed, "One of telemetry initializers failed, telemetry item will not be sent: " + getExceptionName(e), { exception: dumpObj(e) }, true);
2456
+ itemCtx.diagLog().throwInternal(1 , 64 , "One of telemetry initializers failed, telemetry item will not be sent: " + getExceptionName(e), { exception: dumpObj(e) }, true);
2227
2457
  }
2228
2458
  }
2229
2459
  }
@@ -2231,8 +2461,7 @@
2231
2461
  _self.processNext(item, itemCtx);
2232
2462
  }
2233
2463
  };
2234
- _self.unload = function (itemCtx, isAsync) {
2235
- _base.unload(itemCtx, isAsync);
2464
+ _self[strDoTeardown] = function () {
2236
2465
  _initDefaults();
2237
2466
  };
2238
2467
  });
@@ -2276,6 +2505,16 @@
2276
2505
  core: coreExtensions
2277
2506
  };
2278
2507
  }
2508
+ function _createDummyNotificationManager() {
2509
+ var _a;
2510
+ return objCreateFn((_a = {},
2511
+ _a[strAddNotificationListener] = function (listener) { },
2512
+ _a[strRemoveNotificationListener] = function (listener) { },
2513
+ _a[strEventsSent] = function (events) { },
2514
+ _a[strEventsDiscarded] = function (events, reason) { },
2515
+ _a[strEventsSendRequest] = function (sendReason, isAsync) { },
2516
+ _a));
2517
+ }
2279
2518
  var BaseCore = /** @class */ (function () {
2280
2519
  function BaseCore() {
2281
2520
  var _isInitialized;
@@ -2292,6 +2531,7 @@
2292
2531
  var _channelQueue;
2293
2532
  var _telemetryInitializerPlugin;
2294
2533
  var _internalLogsEventName;
2534
+ var _evtNamespace;
2295
2535
  var _debugListener;
2296
2536
  var _internalLogPoller = 0;
2297
2537
  dynamicProto(BaseCore, this, function (_self) {
@@ -2337,24 +2577,16 @@
2337
2577
  setValue(telemetryItem, "time", toISOString(new Date()), null, isNotTruthy);
2338
2578
  setValue(telemetryItem, "ver", "4.0", null, isNullOrUndefined);
2339
2579
  if (_self.isInitialized()) {
2340
- _self.getProcessTelContext().processNext(telemetryItem);
2580
+ _createTelCtx().processNext(telemetryItem);
2341
2581
  }
2342
2582
  else {
2343
2583
  _eventQueue.push(telemetryItem);
2344
2584
  }
2345
2585
  };
2346
- _self.getProcessTelContext = function () {
2347
- return createProcessTelemetryContext(_getPluginChain(), _self.config, _self);
2348
- };
2586
+ _self.getProcessTelContext = _createTelCtx;
2349
2587
  _self.getNotifyMgr = function () {
2350
2588
  if (!_notificationManager) {
2351
- _notificationManager = objCreateFn({
2352
- addNotificationListener: function (listener) { },
2353
- removeNotificationListener: function (listener) { },
2354
- eventsSent: function (events) { },
2355
- eventsDiscarded: function (events, reason) { },
2356
- eventsSendRequest: function (sendReason, isAsync) { }
2357
- });
2589
+ _notificationManager = _createDummyNotificationManager();
2358
2590
  _self[strNotificationManager] = _notificationManager;
2359
2591
  }
2360
2592
  return _notificationManager;
@@ -2397,7 +2629,7 @@
2397
2629
  var eventQueue = _eventQueue;
2398
2630
  _eventQueue = [];
2399
2631
  arrForEach(eventQueue, function (event) {
2400
- _self.getProcessTelContext().processNext(event);
2632
+ _createTelCtx().processNext(event);
2401
2633
  });
2402
2634
  }
2403
2635
  };
@@ -2424,9 +2656,12 @@
2424
2656
  };
2425
2657
  proxyFunctions(_self, function () { return _telemetryInitializerPlugin; }, ["addTelemetryInitializer"]);
2426
2658
  _self.getPlugin = _getPlugin;
2659
+ _self.evtNamespace = function () {
2660
+ return _evtNamespace;
2661
+ };
2427
2662
  function _initDefaults() {
2428
2663
  _isInitialized = false;
2429
- _self.logger = new DiagnosticLogger({ loggingLevelConsole: LoggingSeverity.CRITICAL });
2664
+ _self.logger = new DiagnosticLogger({ loggingLevelConsole: 1 });
2430
2665
  _self.config = null;
2431
2666
  _self._extensions = [];
2432
2667
  _telemetryInitializerPlugin = new TelemetryInitializerPlugin();
@@ -2442,6 +2677,10 @@
2442
2677
  _channelConfig = null;
2443
2678
  _channelQueue = null;
2444
2679
  _internalLogsEventName = null;
2680
+ _evtNamespace = createUniqueNamespace("AIBaseCore", true);
2681
+ }
2682
+ function _createTelCtx() {
2683
+ return createProcessTelemetryContext(_getPluginChain(), _self.config, _self);
2445
2684
  }
2446
2685
  function _initPluginChain(config) {
2447
2686
  var theExtensions = _validateExtensions(_self.logger, ChannelControllerPriority, _configExtensions);
@@ -2449,26 +2688,49 @@
2449
2688
  _pluginChain = null;
2450
2689
  var allExtensions = theExtensions.all;
2451
2690
  _channelQueue = objFreeze(createChannelQueues(_channelConfig, allExtensions, config, _self));
2452
- _channelControl = createChannelControllerPlugin(_channelQueue, _self);
2691
+ if (_channelControl) {
2692
+ var idx = allExtensions.indexOf(_channelControl);
2693
+ if (idx !== -1) {
2694
+ allExtensions.splice(idx, 1);
2695
+ }
2696
+ idx = _coreExtensions.indexOf(_channelControl);
2697
+ if (idx !== -1) {
2698
+ _coreExtensions.splice(idx, 1);
2699
+ }
2700
+ _channelControl._setQueue(_channelQueue);
2701
+ }
2702
+ else {
2703
+ _channelControl = createChannelControllerPlugin(_channelQueue, _self);
2704
+ }
2453
2705
  allExtensions.push(_channelControl);
2454
2706
  _coreExtensions.push(_channelControl);
2455
2707
  _self._extensions = sortPlugins(allExtensions);
2456
2708
  _channelControl.initialize(config, _self, allExtensions);
2457
- initializePlugins(_self.getProcessTelContext(), allExtensions);
2709
+ initializePlugins(_createTelCtx(), allExtensions);
2458
2710
  _self._extensions = objFreeze(sortPlugins(_coreExtensions || [])).slice();
2459
2711
  }
2460
2712
  function _getPlugin(pluginIdentifier) {
2461
2713
  var theExt = null;
2462
2714
  var thePlugin = null;
2463
2715
  arrForEach(_self._extensions, function (ext) {
2464
- if (ext.identifier === pluginIdentifier) {
2716
+ if (ext.identifier === pluginIdentifier && ext !== _channelControl && ext !== _telemetryInitializerPlugin) {
2465
2717
  thePlugin = ext;
2466
2718
  return -1;
2467
2719
  }
2468
2720
  });
2721
+ if (!thePlugin && _channelControl) {
2722
+ thePlugin = _channelControl.getChannel(pluginIdentifier);
2723
+ }
2469
2724
  if (thePlugin) {
2470
2725
  theExt = {
2471
- plugin: thePlugin
2726
+ plugin: thePlugin,
2727
+ setEnabled: function (enabled) {
2728
+ _getPluginState(thePlugin)[strDisabled] = !enabled;
2729
+ },
2730
+ isEnabled: function () {
2731
+ var pluginState = _getPluginState(thePlugin);
2732
+ return !pluginState[strTeardown] && !pluginState[strDisabled];
2733
+ }
2472
2734
  };
2473
2735
  }
2474
2736
  return theExt;
@@ -2476,7 +2738,9 @@
2476
2738
  function _getPluginChain() {
2477
2739
  if (!_pluginChain) {
2478
2740
  var extensions = (_coreExtensions || []).slice();
2479
- extensions.push(_telemetryInitializerPlugin);
2741
+ if (extensions.indexOf(_telemetryInitializerPlugin) === -1) {
2742
+ extensions.push(_telemetryInitializerPlugin);
2743
+ }
2480
2744
  _pluginChain = createTelemetryProxyChain(sortPlugins(extensions), _self.config, _self);
2481
2745
  }
2482
2746
  return _pluginChain;
@@ -2499,12 +2763,12 @@
2499
2763
  }
2500
2764
  function _initDebugListener(config) {
2501
2765
  if (config.disableDbgExt === true && _debugListener) {
2502
- _notificationManager.removeNotificationListener(_debugListener);
2766
+ _notificationManager[strRemoveNotificationListener](_debugListener);
2503
2767
  _debugListener = null;
2504
2768
  }
2505
2769
  if (_notificationManager && !_debugListener && config.disableDbgExt !== true) {
2506
2770
  _debugListener = getDebugListener(config);
2507
- _notificationManager.addNotificationListener(_debugListener);
2771
+ _notificationManager[strAddNotificationListener](_debugListener);
2508
2772
  }
2509
2773
  }
2510
2774
  function _initPerfManager(config) {
@@ -2520,10 +2784,6 @@
2520
2784
  return BaseCore;
2521
2785
  }());
2522
2786
 
2523
- var strEventsSent = "eventsSent";
2524
- var strEventsDiscarded = "eventsDiscarded";
2525
- var strEventsSendRequest = "eventsSendRequest";
2526
- var strPerfEvent = "perfEvent";
2527
2787
  function _runListeners(listeners, name, isAsync, callback) {
2528
2788
  arrForEach(listeners, function (listener) {
2529
2789
  if (listener && listener[name]) {
@@ -2545,32 +2805,32 @@
2545
2805
  this.listeners = [];
2546
2806
  var perfEvtsSendAll = !!(config || {}).perfEvtsSendAll;
2547
2807
  dynamicProto(NotificationManager, this, function (_self) {
2548
- _self.addNotificationListener = function (listener) {
2808
+ _self[strAddNotificationListener] = function (listener) {
2549
2809
  _self.listeners.push(listener);
2550
2810
  };
2551
- _self.removeNotificationListener = function (listener) {
2811
+ _self[strRemoveNotificationListener] = function (listener) {
2552
2812
  var index = arrIndexOf(_self.listeners, listener);
2553
2813
  while (index > -1) {
2554
2814
  _self.listeners.splice(index, 1);
2555
2815
  index = arrIndexOf(_self.listeners, listener);
2556
2816
  }
2557
2817
  };
2558
- _self.eventsSent = function (events) {
2818
+ _self[strEventsSent] = function (events) {
2559
2819
  _runListeners(_self.listeners, strEventsSent, true, function (listener) {
2560
2820
  listener[strEventsSent](events);
2561
2821
  });
2562
2822
  };
2563
- _self.eventsDiscarded = function (events, reason) {
2823
+ _self[strEventsDiscarded] = function (events, reason) {
2564
2824
  _runListeners(_self.listeners, strEventsDiscarded, true, function (listener) {
2565
2825
  listener[strEventsDiscarded](events, reason);
2566
2826
  });
2567
2827
  };
2568
- _self.eventsSendRequest = function (sendReason, isAsync) {
2828
+ _self[strEventsSendRequest] = function (sendReason, isAsync) {
2569
2829
  _runListeners(_self.listeners, strEventsSendRequest, isAsync, function (listener) {
2570
2830
  listener[strEventsSendRequest](sendReason, isAsync);
2571
2831
  });
2572
2832
  };
2573
- _self.perfEvent = function (perfEvent) {
2833
+ _self[strPerfEvent] = function (perfEvent) {
2574
2834
  if (perfEvent) {
2575
2835
  if (perfEvtsSendAll || !perfEvent.isChildEvt()) {
2576
2836
  _runListeners(_self.listeners, strPerfEvent, false, function (listener) {
@@ -2625,103 +2885,117 @@
2625
2885
  return AppInsightsCore;
2626
2886
  }(BaseCore));
2627
2887
 
2628
- var UInt32Mask = 0x100000000;
2629
- var MaxUInt32 = 0xffffffff;
2630
- var _mwcSeeded = false;
2631
- var _mwcW = 123456789;
2632
- var _mwcZ = 987654321;
2633
- function _mwcSeed(seedValue) {
2634
- if (seedValue < 0) {
2635
- seedValue >>>= 0;
2636
- }
2637
- _mwcW = (123456789 + seedValue) & MaxUInt32;
2638
- _mwcZ = (987654321 - seedValue) & MaxUInt32;
2639
- _mwcSeeded = true;
2640
- }
2641
- function _autoSeedMwc() {
2642
- try {
2643
- var now = dateNow() & 0x7fffffff;
2644
- _mwcSeed(((Math.random() * UInt32Mask) ^ now) + now);
2645
- }
2646
- catch (e) {
2647
- }
2648
- }
2649
- function randomValue(maxValue) {
2650
- if (maxValue > 0) {
2651
- return Math.floor((random32() / MaxUInt32) * (maxValue + 1)) >>> 0;
2652
- }
2653
- return 0;
2654
- }
2655
- function random32(signed) {
2656
- var value = 0;
2657
- var c = getCrypto() || getMsCrypto();
2658
- if (c && c.getRandomValues) {
2659
- value = c.getRandomValues(new Uint32Array(1))[0] & MaxUInt32;
2660
- }
2661
- if (value === 0 && isIE()) {
2662
- if (!_mwcSeeded) {
2663
- _autoSeedMwc();
2888
+ var strOnPrefix = "on";
2889
+ var strAttachEvent = "attachEvent";
2890
+ var strAddEventHelper = "addEventListener";
2891
+ var strEvents = "events";
2892
+ createUniqueNamespace("aiEvtPageHide");
2893
+ createUniqueNamespace("aiEvtPageShow");
2894
+ var _guid = 1;
2895
+ var elmNodeData = createElmNodeData("events");
2896
+ var eventNamespace = /^([^.]*)(?:\.(.+)|)/;
2897
+ function _normalizeNamespace(name) {
2898
+ if (name && name.replace) {
2899
+ return name.replace(/^\s*\.*|\.*\s*$/g, "");
2900
+ }
2901
+ return name;
2902
+ }
2903
+ function _getEvtNamespace(eventName, namespaces) {
2904
+ if (namespaces) {
2905
+ var theNamespace_1 = "";
2906
+ if (isArray(namespaces)) {
2907
+ theNamespace_1 = "";
2908
+ arrForEach(namespaces, function (name) {
2909
+ name = _normalizeNamespace(name);
2910
+ if (name) {
2911
+ if (name[0] !== ".") {
2912
+ name = "." + name;
2913
+ }
2914
+ theNamespace_1 += name;
2915
+ }
2916
+ });
2917
+ }
2918
+ else {
2919
+ theNamespace_1 = _normalizeNamespace(namespaces);
2920
+ }
2921
+ if (theNamespace_1) {
2922
+ if (theNamespace_1[0] !== ".") {
2923
+ theNamespace_1 = "." + theNamespace_1;
2924
+ }
2925
+ eventName = (eventName || "") + theNamespace_1;
2664
2926
  }
2665
- value = mwcRandom32() & MaxUInt32;
2666
- }
2667
- if (value === 0) {
2668
- value = Math.floor((UInt32Mask * Math.random()) | 0);
2669
- }
2670
- if (!signed) {
2671
- value >>>= 0;
2672
2927
  }
2673
- return value;
2928
+ var parsedEvent = (eventNamespace.exec(eventName) || []);
2929
+ return {
2930
+ type: parsedEvent[1],
2931
+ ns: ((parsedEvent[2] || "").split(".").sort()).join(".")
2932
+ };
2674
2933
  }
2675
- function mwcRandomSeed(value) {
2676
- if (!value) {
2677
- _autoSeedMwc();
2678
- }
2679
- else {
2680
- _mwcSeed(value);
2934
+ function _getRegisteredEvents(target, evtName, addDefault) {
2935
+ if (addDefault === void 0) { addDefault = true; }
2936
+ var aiEvts = elmNodeData.get(target, strEvents, {}, addDefault);
2937
+ var registeredEvents = aiEvts[evtName];
2938
+ if (!registeredEvents) {
2939
+ registeredEvents = aiEvts[evtName] = [];
2681
2940
  }
2941
+ return registeredEvents;
2682
2942
  }
2683
- function mwcRandom32(signed) {
2684
- _mwcZ = (36969 * (_mwcZ & 0xFFFF) + (_mwcZ >> 16)) & MaxUInt32;
2685
- _mwcW = (18000 * (_mwcW & 0xFFFF) + (_mwcW >> 16)) & MaxUInt32;
2686
- var value = (((_mwcZ << 16) + (_mwcW & 0xFFFF)) >>> 0) & MaxUInt32 | 0;
2687
- if (!signed) {
2688
- value >>>= 0;
2943
+ function _doAttach(obj, evtName, handlerRef, useCapture) {
2944
+ var result = false;
2945
+ if (obj && evtName && evtName.type && handlerRef) {
2946
+ if (obj[strAddEventHelper]) {
2947
+ obj[strAddEventHelper](evtName.type, handlerRef, useCapture);
2948
+ result = true;
2949
+ }
2950
+ else if (obj[strAttachEvent]) {
2951
+ obj[strAttachEvent](strOnPrefix + evtName.type, handlerRef);
2952
+ result = true;
2953
+ }
2689
2954
  }
2690
- return value;
2955
+ return result;
2691
2956
  }
2692
- function newId(maxLength) {
2693
- if (maxLength === void 0) { maxLength = 22; }
2694
- var base64chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
2695
- var number = random32() >>> 0;
2696
- var chars = 0;
2697
- var result = "";
2698
- while (result.length < maxLength) {
2699
- chars++;
2700
- result += base64chars.charAt(number & 0x3F);
2701
- number >>>= 6;
2702
- if (chars === 5) {
2703
- number = (((random32() << 2) & 0xFFFFFFFF) | (number & 0x03)) >>> 0;
2704
- chars = 0;
2957
+ function eventOn(target, eventName, handlerRef, evtNamespace, useCapture) {
2958
+ if (useCapture === void 0) { useCapture = false; }
2959
+ var result = false;
2960
+ if (target) {
2961
+ try {
2962
+ var evtName = _getEvtNamespace(eventName, evtNamespace);
2963
+ result = _doAttach(target, evtName, handlerRef, useCapture);
2964
+ if (result && elmNodeData.accept(target)) {
2965
+ var registeredEvent = {
2966
+ guid: _guid++,
2967
+ evtName: evtName,
2968
+ handler: handlerRef,
2969
+ capture: useCapture
2970
+ };
2971
+ _getRegisteredEvents(target, evtName.type).push(registeredEvent);
2972
+ }
2973
+ }
2974
+ catch (e) {
2705
2975
  }
2706
2976
  }
2707
2977
  return result;
2708
2978
  }
2709
-
2710
- var _cookieMgrs = null;
2711
- var _canUseCookies;
2712
- function addEventHandler(eventName, callback) {
2979
+ function attachEvent(obj, eventNameWithoutOn, handlerRef, useCapture) {
2980
+ if (useCapture === void 0) { useCapture = false; }
2981
+ return eventOn(obj, eventNameWithoutOn, handlerRef, null, useCapture);
2982
+ }
2983
+ function addEventHandler(eventName, callback, evtNamespace) {
2713
2984
  var result = false;
2714
2985
  var w = getWindow();
2715
2986
  if (w) {
2716
- result = attachEvent(w, eventName, callback);
2717
- result = attachEvent(w["body"], eventName, callback) || result;
2987
+ result = eventOn(w, eventName, callback, evtNamespace);
2988
+ result = eventOn(w["body"], eventName, callback, evtNamespace) || result;
2718
2989
  }
2719
2990
  var doc = getDocument();
2720
2991
  if (doc) {
2721
- result = attachEvent(doc, eventName, callback) || result;
2992
+ result = eventOn(doc, eventName, callback, evtNamespace) || result;
2722
2993
  }
2723
2994
  return result;
2724
2995
  }
2996
+
2997
+ var _cookieMgrs = null;
2998
+ var _canUseCookies;
2725
2999
  function newGuid() {
2726
3000
  function randomHexDigit() {
2727
3001
  return randomValue(15);
@@ -2740,7 +3014,7 @@
2740
3014
  }
2741
3015
  function generateW3CId() {
2742
3016
  var hexValues = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"];
2743
- var oct = "", tmp;
3017
+ var oct = strEmpty$1, tmp;
2744
3018
  for (var a = 0; a < 4; a++) {
2745
3019
  tmp = random32();
2746
3020
  oct +=
@@ -2823,6 +3097,95 @@
2823
3097
  _legacyCookieMgr().setEnabled(false);
2824
3098
  }
2825
3099
 
3100
+ var LoggingSeverity = createEnumStyle({
3101
+ CRITICAL: 1 ,
3102
+ WARNING: 2
3103
+ });
3104
+ var _InternalMessageId = createEnumStyle({
3105
+ BrowserDoesNotSupportLocalStorage: 0 ,
3106
+ BrowserCannotReadLocalStorage: 1 ,
3107
+ BrowserCannotReadSessionStorage: 2 ,
3108
+ BrowserCannotWriteLocalStorage: 3 ,
3109
+ BrowserCannotWriteSessionStorage: 4 ,
3110
+ BrowserFailedRemovalFromLocalStorage: 5 ,
3111
+ BrowserFailedRemovalFromSessionStorage: 6 ,
3112
+ CannotSendEmptyTelemetry: 7 ,
3113
+ ClientPerformanceMathError: 8 ,
3114
+ ErrorParsingAISessionCookie: 9 ,
3115
+ ErrorPVCalc: 10 ,
3116
+ ExceptionWhileLoggingError: 11 ,
3117
+ FailedAddingTelemetryToBuffer: 12 ,
3118
+ FailedMonitorAjaxAbort: 13 ,
3119
+ FailedMonitorAjaxDur: 14 ,
3120
+ FailedMonitorAjaxOpen: 15 ,
3121
+ FailedMonitorAjaxRSC: 16 ,
3122
+ FailedMonitorAjaxSend: 17 ,
3123
+ FailedMonitorAjaxGetCorrelationHeader: 18 ,
3124
+ FailedToAddHandlerForOnBeforeUnload: 19 ,
3125
+ FailedToSendQueuedTelemetry: 20 ,
3126
+ FailedToReportDataLoss: 21 ,
3127
+ FlushFailed: 22 ,
3128
+ MessageLimitPerPVExceeded: 23 ,
3129
+ MissingRequiredFieldSpecification: 24 ,
3130
+ NavigationTimingNotSupported: 25 ,
3131
+ OnError: 26 ,
3132
+ SessionRenewalDateIsZero: 27 ,
3133
+ SenderNotInitialized: 28 ,
3134
+ StartTrackEventFailed: 29 ,
3135
+ StopTrackEventFailed: 30 ,
3136
+ StartTrackFailed: 31 ,
3137
+ StopTrackFailed: 32 ,
3138
+ TelemetrySampledAndNotSent: 33 ,
3139
+ TrackEventFailed: 34 ,
3140
+ TrackExceptionFailed: 35 ,
3141
+ TrackMetricFailed: 36 ,
3142
+ TrackPVFailed: 37 ,
3143
+ TrackPVFailedCalc: 38 ,
3144
+ TrackTraceFailed: 39 ,
3145
+ TransmissionFailed: 40 ,
3146
+ FailedToSetStorageBuffer: 41 ,
3147
+ FailedToRestoreStorageBuffer: 42 ,
3148
+ InvalidBackendResponse: 43 ,
3149
+ FailedToFixDepricatedValues: 44 ,
3150
+ InvalidDurationValue: 45 ,
3151
+ TelemetryEnvelopeInvalid: 46 ,
3152
+ CreateEnvelopeError: 47 ,
3153
+ CannotSerializeObject: 48 ,
3154
+ CannotSerializeObjectNonSerializable: 49 ,
3155
+ CircularReferenceDetected: 50 ,
3156
+ ClearAuthContextFailed: 51 ,
3157
+ ExceptionTruncated: 52 ,
3158
+ IllegalCharsInName: 53 ,
3159
+ ItemNotInArray: 54 ,
3160
+ MaxAjaxPerPVExceeded: 55 ,
3161
+ MessageTruncated: 56 ,
3162
+ NameTooLong: 57 ,
3163
+ SampleRateOutOfRange: 58 ,
3164
+ SetAuthContextFailed: 59 ,
3165
+ SetAuthContextFailedAccountName: 60 ,
3166
+ StringValueTooLong: 61 ,
3167
+ StartCalledMoreThanOnce: 62 ,
3168
+ StopCalledWithoutStart: 63 ,
3169
+ TelemetryInitializerFailed: 64 ,
3170
+ TrackArgumentsNotSpecified: 65 ,
3171
+ UrlTooLong: 66 ,
3172
+ SessionStorageBufferFull: 67 ,
3173
+ CannotAccessCookie: 68 ,
3174
+ IdTooLong: 69 ,
3175
+ InvalidEvent: 70 ,
3176
+ FailedMonitorAjaxSetRequestHeader: 71 ,
3177
+ SendBrowserInfoOnUserInit: 72 ,
3178
+ PluginException: 73 ,
3179
+ NotificationException: 74 ,
3180
+ SnippetScriptLoadFailure: 99 ,
3181
+ InvalidInstrumentationKey: 100 ,
3182
+ CannotParseAiBlobValue: 101 ,
3183
+ InvalidContentBlob: 102 ,
3184
+ TrackPageActionEventFailed: 103 ,
3185
+ FailedAddingCustomDefinedRequestContext: 104 ,
3186
+ InMemoryStorageBufferFull: 105
3187
+ });
3188
+
2826
3189
  var RequestHeaders = {
2827
3190
  requestContextHeader: "Request-Context",
2828
3191
  requestContextTargetKey: "appId",
@@ -2855,7 +3218,7 @@
2855
3218
  name = strTrim(name.toString());
2856
3219
  if (name.length > 150 ) {
2857
3220
  nameTrunc = name.substring(0, 150 );
2858
- logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.NameTooLong, "name is too long. It has been truncated to " + 150 + " characters.", { name: name }, true);
3221
+ logger && logger.throwInternal(2 , _InternalMessageId.NameTooLong, "name is too long. It has been truncated to " + 150 + " characters.", { name: name }, true);
2859
3222
  }
2860
3223
  }
2861
3224
  return nameTrunc || name;
@@ -2868,7 +3231,7 @@
2868
3231
  value = strTrim(value);
2869
3232
  if (value.toString().length > maxLength) {
2870
3233
  valueTrunc = value.toString().substring(0, maxLength);
2871
- logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.StringValueTooLong, "string value is too long. It has been truncated to " + maxLength + " characters.", { value: value }, true);
3234
+ logger && logger.throwInternal(2 , _InternalMessageId.StringValueTooLong, "string value is too long. It has been truncated to " + maxLength + " characters.", { value: value }, true);
2872
3235
  }
2873
3236
  }
2874
3237
  return valueTrunc || value;
@@ -2881,7 +3244,7 @@
2881
3244
  if (message) {
2882
3245
  if (message.length > 32768 ) {
2883
3246
  messageTrunc = message.substring(0, 32768 );
2884
- logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.MessageTruncated, "message is too long, it has been truncated to " + 32768 + " characters.", { message: message }, true);
3247
+ logger && logger.throwInternal(2 , _InternalMessageId.MessageTruncated, "message is too long, it has been truncated to " + 32768 + " characters.", { message: message }, true);
2885
3248
  }
2886
3249
  }
2887
3250
  return messageTrunc || message;
@@ -2892,7 +3255,7 @@
2892
3255
  var value = "" + exception;
2893
3256
  if (value.length > 32768 ) {
2894
3257
  exceptionTrunc = value.substring(0, 32768 );
2895
- logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.ExceptionTruncated, "exception is too long, it has been truncated to " + 32768 + " characters.", { exception: exception }, true);
3258
+ logger && logger.throwInternal(2 , _InternalMessageId.ExceptionTruncated, "exception is too long, it has been truncated to " + 32768 + " characters.", { exception: exception }, true);
2896
3259
  }
2897
3260
  }
2898
3261
  return exceptionTrunc || exception;
@@ -2906,7 +3269,7 @@
2906
3269
  value = getJSON().stringify(value);
2907
3270
  }
2908
3271
  catch (e) {
2909
- logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.CannotSerializeObjectNonSerializable, "custom property is not valid", { exception: e }, true);
3272
+ logger && logger.throwInternal(2 , _InternalMessageId.CannotSerializeObjectNonSerializable, "custom property is not valid", { exception: e }, true);
2910
3273
  }
2911
3274
  }
2912
3275
  value = dataSanitizeString(logger, value, 8192 );
@@ -2937,7 +3300,7 @@
2937
3300
  input = strTrim(input);
2938
3301
  if (input.length > maxLength) {
2939
3302
  inputTrunc = input.substring(0, maxLength);
2940
- logger && logger.throwInternal(LoggingSeverity.WARNING, _msgId, "input is too long, it has been truncated to " + maxLength + " characters.", { data: input }, true);
3303
+ logger && logger.throwInternal(2 , _msgId, "input is too long, it has been truncated to " + maxLength + " characters.", { data: input }, true);
2941
3304
  }
2942
3305
  }
2943
3306
  return inputTrunc || input;
@@ -2947,21 +3310,22 @@
2947
3310
  return s.substr(s.length - 3);
2948
3311
  }
2949
3312
 
3313
+ var strEmpty = "";
2950
3314
  function msToTimeSpan(totalms) {
2951
3315
  if (isNaN(totalms) || totalms < 0) {
2952
3316
  totalms = 0;
2953
3317
  }
2954
3318
  totalms = Math.round(totalms);
2955
- var ms = "" + totalms % 1000;
2956
- var sec = "" + Math.floor(totalms / 1000) % 60;
2957
- var min = "" + Math.floor(totalms / (1000 * 60)) % 60;
2958
- var hour = "" + Math.floor(totalms / (1000 * 60 * 60)) % 24;
3319
+ var ms = strEmpty + totalms % 1000;
3320
+ var sec = strEmpty + Math.floor(totalms / 1000) % 60;
3321
+ var min = strEmpty + Math.floor(totalms / (1000 * 60)) % 60;
3322
+ var hour = strEmpty + Math.floor(totalms / (1000 * 60 * 60)) % 24;
2959
3323
  var days = Math.floor(totalms / (1000 * 60 * 60 * 24));
2960
3324
  ms = ms.length === 1 ? "00" + ms : ms.length === 2 ? "0" + ms : ms;
2961
3325
  sec = sec.length < 2 ? "0" + sec : sec;
2962
3326
  min = min.length < 2 ? "0" + min : min;
2963
3327
  hour = hour.length < 2 ? "0" + hour : hour;
2964
- return (days > 0 ? days + "." : "") + hour + ":" + min + ":" + sec + "." + ms;
3328
+ return (days > 0 ? days + "." : strEmpty) + hour + ":" + min + ":" + sec + "." + ms;
2965
3329
  }
2966
3330
 
2967
3331
  var DisabledPropertyName = "Microsoft_ApplicationInsights_BypassAjaxInstrumentation";
@@ -2970,17 +3334,15 @@
2970
3334
  var HttpMethod = "http.method";
2971
3335
  var strNotSpecified = "not_specified";
2972
3336
 
2973
- var StorageType;
2974
- (function (StorageType) {
2975
- StorageType[StorageType["LocalStorage"] = 0] = "LocalStorage";
2976
- StorageType[StorageType["SessionStorage"] = 1] = "SessionStorage";
2977
- })(StorageType || (StorageType = {}));
2978
- var DistributedTracingModes;
2979
- (function (DistributedTracingModes) {
2980
- DistributedTracingModes[DistributedTracingModes["AI"] = 0] = "AI";
2981
- DistributedTracingModes[DistributedTracingModes["AI_AND_W3C"] = 1] = "AI_AND_W3C";
2982
- DistributedTracingModes[DistributedTracingModes["W3C"] = 2] = "W3C";
2983
- })(DistributedTracingModes || (DistributedTracingModes = {}));
3337
+ var StorageType = createEnumStyle({
3338
+ LocalStorage: 0 ,
3339
+ SessionStorage: 1
3340
+ });
3341
+ createEnumStyle({
3342
+ AI: 0 ,
3343
+ AI_AND_W3C: 1 ,
3344
+ W3C: 2
3345
+ });
2984
3346
 
2985
3347
  var _canUseSessionStorage = undefined;
2986
3348
  function _getVerifiedStorageObject(storageType) {
@@ -3021,7 +3383,7 @@
3021
3383
  }
3022
3384
  catch (e) {
3023
3385
  _canUseSessionStorage = false;
3024
- logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.BrowserCannotReadSessionStorage, "Browser failed read of session storage. " + getExceptionName(e), { exception: dumpObj(e) });
3386
+ logger.throwInternal(2 , _InternalMessageId.BrowserCannotReadSessionStorage, "Browser failed read of session storage. " + getExceptionName(e), { exception: dumpObj(e) });
3025
3387
  }
3026
3388
  }
3027
3389
  return null;
@@ -3035,7 +3397,7 @@
3035
3397
  }
3036
3398
  catch (e) {
3037
3399
  _canUseSessionStorage = false;
3038
- logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.BrowserCannotWriteSessionStorage, "Browser failed write to session storage. " + getExceptionName(e), { exception: dumpObj(e) });
3400
+ logger.throwInternal(2 , _InternalMessageId.BrowserCannotWriteSessionStorage, "Browser failed write to session storage. " + getExceptionName(e), { exception: dumpObj(e) });
3039
3401
  }
3040
3402
  }
3041
3403
  return false;
@@ -4321,7 +4683,7 @@
4321
4683
  }
4322
4684
  }
4323
4685
  var EnvelopeCreator = {
4324
- Version: "2.8.0-beta.2203-01"
4686
+ Version: "2.8.0-beta.2203-02"
4325
4687
  };
4326
4688
  function DependencyEnvelopeCreator(logger, telemetryItem, customUndefinedValue) {
4327
4689
  EnvelopeCreatorInit(logger, telemetryItem);
@@ -5491,4 +5853,4 @@
5491
5853
  (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 });
5492
5854
 
5493
5855
  }));
5494
- //# sourceMappingURL=aib.2.8.0-beta.2203-01.js.map
5856
+ //# sourceMappingURL=aib.2.8.0-beta.2203-02.js.map