@microsoft/1ds-core-js 3.2.0 → 3.2.3

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 -1
  2. package/bundle/{ms.core-3.2.0.gbl.js → ms.core-3.2.3.gbl.js} +1552 -1349
  3. package/bundle/ms.core-3.2.3.gbl.js.map +1 -0
  4. package/bundle/ms.core-3.2.3.gbl.min.js +7 -0
  5. package/bundle/ms.core-3.2.3.gbl.min.js.map +1 -0
  6. package/bundle/ms.core-3.2.3.integrity.json +46 -0
  7. package/bundle/{ms.core-3.2.0.js → ms.core-3.2.3.js} +1552 -1349
  8. package/bundle/ms.core-3.2.3.js.map +1 -0
  9. package/bundle/ms.core-3.2.3.min.js +7 -0
  10. package/bundle/ms.core-3.2.3.min.js.map +1 -0
  11. package/bundle/ms.core.gbl.js +1551 -1348
  12. package/bundle/ms.core.gbl.js.map +1 -1
  13. package/bundle/ms.core.gbl.min.js +2 -2
  14. package/bundle/ms.core.gbl.min.js.map +1 -1
  15. package/bundle/ms.core.integrity.json +17 -17
  16. package/bundle/ms.core.js +1551 -1348
  17. package/bundle/ms.core.js.map +1 -1
  18. package/bundle/ms.core.min.js +2 -2
  19. package/bundle/ms.core.min.js.map +1 -1
  20. package/dist/ms.core.js +10 -2
  21. package/dist/ms.core.js.map +1 -1
  22. package/dist/ms.core.min.js +2 -2
  23. package/dist/ms.core.min.js.map +1 -1
  24. package/dist-esm/src/AppInsightsCore.js +4 -4
  25. package/dist-esm/src/AppInsightsCore.js.map +1 -1
  26. package/dist-esm/src/BaseCore.js +2 -2
  27. package/dist-esm/src/BaseCore.js.map +1 -1
  28. package/dist-esm/src/DataModels.js +1 -1
  29. package/dist-esm/src/ESPromise.js +9 -9
  30. package/dist-esm/src/ESPromise.js.map +1 -1
  31. package/dist-esm/src/ESPromiseScheduler.js +1 -1
  32. package/dist-esm/src/Enums.d.ts +1 -0
  33. package/dist-esm/src/Enums.js +56 -56
  34. package/dist-esm/src/Enums.js.map +1 -1
  35. package/dist-esm/src/Index.d.ts +1 -1
  36. package/dist-esm/src/Index.js +2 -2
  37. package/dist-esm/src/Index.js.map +1 -1
  38. package/dist-esm/src/Utils.d.ts +1 -1
  39. package/dist-esm/src/Utils.js +23 -23
  40. package/dist-esm/src/Utils.js.map +1 -1
  41. package/dist-esm/src/ValueSanitizer.js +15 -15
  42. package/dist-esm/src/ValueSanitizer.js.map +1 -1
  43. package/package.json +3 -4
  44. package/src/Index.ts +2 -2
  45. package/bundle/ms.core-3.2.0.gbl.js.map +0 -1
  46. package/bundle/ms.core-3.2.0.gbl.min.js +0 -7
  47. package/bundle/ms.core-3.2.0.gbl.min.js.map +0 -1
  48. package/bundle/ms.core-3.2.0.integrity.json +0 -46
  49. package/bundle/ms.core-3.2.0.js.map +0 -1
  50. package/bundle/ms.core-3.2.0.min.js +0 -7
  51. package/bundle/ms.core-3.2.0.min.js.map +0 -1
package/bundle/ms.core.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * 1DS JS SDK Core, 3.2.0
2
+ * 1DS JS SDK Core, 3.2.3
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  * (Microsoft Internal Only)
5
5
  */
@@ -651,7 +651,7 @@
651
651
  });
652
652
 
653
653
  /*!
654
- * Microsoft Dynamic Proto Utility, 1.1.4
654
+ * Microsoft Dynamic Proto Utility, 1.1.6
655
655
  * Copyright (c) Microsoft and contributors. All rights reserved.
656
656
  */
657
657
  var Constructor = 'constructor';
@@ -666,10 +666,13 @@
666
666
  var DynProtoDefaultOptions = '_dfOpts';
667
667
  var UnknownValue = '_unknown_';
668
668
  var str__Proto = "__proto__";
669
+ var DynProtoBaseProto = "_dyn" + str__Proto;
670
+ var DynProtoCurrent = "_dynInstProto";
669
671
  var strUseBaseInst = 'useBaseInst';
670
672
  var strSetInstFuncs = 'setInstFuncs';
671
673
  var Obj = Object;
672
674
  var _objGetPrototypeOf = Obj["getPrototypeOf"];
675
+ var _objGetOwnProps = Obj["getOwnPropertyNames"];
673
676
  var _dynamicNames = 0;
674
677
  function _hasOwnProperty(obj, prop) {
675
678
  return obj && Obj[Prototype].hasOwnProperty.call(obj, prop);
@@ -681,22 +684,25 @@
681
684
  return _isObjectOrArrayPrototype(target) || target === Function[Prototype];
682
685
  }
683
686
  function _getObjProto(target) {
687
+ var newProto;
684
688
  if (target) {
685
689
  if (_objGetPrototypeOf) {
686
690
  return _objGetPrototypeOf(target);
687
691
  }
688
- var newProto = target[str__Proto] || target[Prototype] || (target[Constructor] ? target[Constructor][Prototype] : null);
689
- if (newProto) {
690
- return newProto;
692
+ var curProto = target[str__Proto] || target[Prototype] || (target[Constructor] ? target[Constructor][Prototype] : null);
693
+ newProto = target[DynProtoBaseProto] || curProto;
694
+ if (!_hasOwnProperty(target, DynProtoBaseProto)) {
695
+ delete target[DynProtoCurrent];
696
+ newProto = target[DynProtoBaseProto] = target[DynProtoCurrent] || target[DynProtoBaseProto];
697
+ target[DynProtoCurrent] = curProto;
691
698
  }
692
699
  }
693
- return null;
700
+ return newProto;
694
701
  }
695
702
  function _forEachProp(target, func) {
696
703
  var props = [];
697
- var getOwnProps = Obj["getOwnPropertyNames"];
698
- if (getOwnProps) {
699
- props = getOwnProps(target);
704
+ if (_objGetOwnProps) {
705
+ props = _objGetOwnProps(target);
700
706
  }
701
707
  else {
702
708
  for (var name_1 in target) {
@@ -845,8 +851,9 @@
845
851
  visited.push(thisProto);
846
852
  thisProto = _getObjProto(thisProto);
847
853
  }
854
+ return false;
848
855
  }
849
- return false;
856
+ return true;
850
857
  }
851
858
  function _getObjName(target, unknownValue) {
852
859
  if (_hasOwnProperty(target, Prototype)) {
@@ -1105,6 +1112,35 @@
1105
1112
  }
1106
1113
  return isSupported;
1107
1114
  }
1115
+ function _getNamedValue(values, name) {
1116
+ if (values) {
1117
+ for (var i = 0; i < values.length; i++) {
1118
+ var value = values[i];
1119
+ if (value.name) {
1120
+ if (value.name === name) {
1121
+ return value;
1122
+ }
1123
+ }
1124
+ }
1125
+ }
1126
+ return {};
1127
+ }
1128
+ function findMetaTag(name) {
1129
+ var doc = getDocument();
1130
+ if (doc && name) {
1131
+ return _getNamedValue(doc.querySelectorAll("meta"), name).content;
1132
+ }
1133
+ return null;
1134
+ }
1135
+ function findNamedServerTiming(name) {
1136
+ var value;
1137
+ var perf = getPerformance();
1138
+ if (perf) {
1139
+ var navPerf = perf.getEntriesByType("navigation") || [];
1140
+ value = _getNamedValue((navPerf.length > 0 ? navPerf[0] : {}).serverTiming, name).description;
1141
+ }
1142
+ return value;
1143
+ }
1108
1144
 
1109
1145
  var listenerFuncs = ["eventsSent", "eventsDiscarded", "eventsSendRequest", "perfEvent"];
1110
1146
  var _aiNamespace = null;
@@ -1208,7 +1244,7 @@
1208
1244
  if (isUserAct === void 0) { isUserAct = false; }
1209
1245
  var message = new _InternalLogMessage(msgId, msg, isUserAct, properties);
1210
1246
  if (_self.enableDebugExceptions()) {
1211
- throw message;
1247
+ throw dumpObj(message);
1212
1248
  }
1213
1249
  else {
1214
1250
  var logFunc = severity === 1 ? strErrorToConsole : strWarnToConsole;
@@ -1534,7 +1570,7 @@
1534
1570
  }
1535
1571
 
1536
1572
  var _objDefineProperty = ObjDefineProperty;
1537
- var version = "2.8.0";
1573
+ var version = "2.8.4";
1538
1574
  var instanceName = "." + newId(6);
1539
1575
  var _dataUid = 0;
1540
1576
  function _createAccessor(target, prop, value) {
@@ -1605,913 +1641,1408 @@
1605
1641
  return data;
1606
1642
  }
1607
1643
 
1608
- var pluginStateData = createElmNodeData("plugin");
1609
- function _getPluginState(plugin) {
1610
- return pluginStateData.get(plugin, "state", {}, true);
1644
+ var strToGMTString = "toGMTString";
1645
+ var strToUTCString = "toUTCString";
1646
+ var strCookie = "cookie";
1647
+ var strExpires = "expires";
1648
+ var strEnabled = "enabled";
1649
+ var strIsCookieUseDisabled = "isCookieUseDisabled";
1650
+ var strDisableCookiesUsage = "disableCookiesUsage";
1651
+ var strConfigCookieMgr = "_ckMgr";
1652
+ var _supportsCookies = null;
1653
+ var _allowUaSameSite = null;
1654
+ var _parsedCookieValue = null;
1655
+ var _doc = getDocument();
1656
+ var _cookieCache = {};
1657
+ var _globalCookieConfig = {};
1658
+ function _gblCookieMgr(config, logger) {
1659
+ var inst = createCookieMgr[strConfigCookieMgr] || _globalCookieConfig[strConfigCookieMgr];
1660
+ if (!inst) {
1661
+ inst = createCookieMgr[strConfigCookieMgr] = createCookieMgr(config, logger);
1662
+ _globalCookieConfig[strConfigCookieMgr] = inst;
1663
+ }
1664
+ return inst;
1611
1665
  }
1612
- function initializePlugins(processContext, extensions) {
1613
- var initPlugins = [];
1614
- var lastPlugin = null;
1615
- var proxy = processContext.getNext();
1616
- var pluginState;
1617
- while (proxy) {
1618
- var thePlugin = proxy.getPlugin();
1619
- if (thePlugin) {
1620
- if (lastPlugin &&
1621
- isFunction(lastPlugin[strSetNextPlugin]) &&
1622
- isFunction(thePlugin[strProcessTelemetry])) {
1623
- lastPlugin[strSetNextPlugin](thePlugin);
1624
- }
1625
- var isInitialized = false;
1626
- if (isFunction(thePlugin[strIsInitialized])) {
1627
- isInitialized = thePlugin[strIsInitialized]();
1628
- }
1629
- else {
1630
- pluginState = _getPluginState(thePlugin);
1631
- isInitialized = pluginState[strIsInitialized];
1632
- }
1633
- if (!isInitialized) {
1634
- initPlugins.push(thePlugin);
1635
- }
1636
- lastPlugin = thePlugin;
1637
- proxy = proxy.getNext();
1638
- }
1666
+ function _isMgrEnabled(cookieMgr) {
1667
+ if (cookieMgr) {
1668
+ return cookieMgr.isEnabled();
1639
1669
  }
1640
- arrForEach(initPlugins, function (thePlugin) {
1641
- var core = processContext.core();
1642
- thePlugin.initialize(processContext.getCfg(), core, extensions, processContext.getNext());
1643
- pluginState = _getPluginState(thePlugin);
1644
- if (!thePlugin[strCore] && !pluginState[strCore]) {
1645
- pluginState[strCore] = core;
1646
- }
1647
- pluginState[strIsInitialized] = true;
1648
- delete pluginState[strTeardown];
1649
- });
1670
+ return true;
1650
1671
  }
1651
- function sortPlugins(plugins) {
1652
- return plugins.sort(function (extA, extB) {
1653
- var result = 0;
1654
- var bHasProcess = isFunction(extB[strProcessTelemetry]);
1655
- if (isFunction(extA[strProcessTelemetry])) {
1656
- result = bHasProcess ? extA[strPriority] - extB[strPriority] : 1;
1657
- }
1658
- else if (bHasProcess) {
1659
- result = -1;
1672
+ function _createCookieMgrConfig(rootConfig) {
1673
+ var cookieMgrCfg = rootConfig.cookieCfg = rootConfig.cookieCfg || {};
1674
+ setValue(cookieMgrCfg, "domain", rootConfig.cookieDomain, isNotNullOrUndefined, isNullOrUndefined);
1675
+ setValue(cookieMgrCfg, "path", rootConfig.cookiePath || "/", null, isNullOrUndefined);
1676
+ if (isNullOrUndefined(cookieMgrCfg[strEnabled])) {
1677
+ var cookieEnabled = void 0;
1678
+ if (!isUndefined(rootConfig[strIsCookieUseDisabled])) {
1679
+ cookieEnabled = !rootConfig[strIsCookieUseDisabled];
1660
1680
  }
1661
- return result;
1662
- });
1663
- }
1664
-
1665
- var strTelemetryPluginChain = "TelemetryPluginChain";
1666
- var strHasRunFlags = "_hasRun";
1667
- var strGetTelCtx = "_getTelCtx";
1668
- var _chainId = 0;
1669
- function _getNextProxyStart(proxy, core, startAt) {
1670
- while (proxy) {
1671
- if (proxy.getPlugin() === startAt) {
1672
- return proxy;
1681
+ if (!isUndefined(rootConfig[strDisableCookiesUsage])) {
1682
+ cookieEnabled = !rootConfig[strDisableCookiesUsage];
1673
1683
  }
1674
- proxy = proxy.getNext();
1684
+ cookieMgrCfg[strEnabled] = cookieEnabled;
1675
1685
  }
1676
- return createTelemetryProxyChain([startAt], core.config || {}, core);
1686
+ return cookieMgrCfg;
1677
1687
  }
1678
- function _createInternalContext(telemetryChain, config, core, startAt) {
1679
- var _nextProxy = null;
1680
- var _onComplete = [];
1681
- if (startAt !== null) {
1682
- _nextProxy = startAt ? _getNextProxyStart(telemetryChain, core, startAt) : telemetryChain;
1688
+ function safeGetCookieMgr(core, config) {
1689
+ var cookieMgr;
1690
+ if (core) {
1691
+ cookieMgr = core.getCookieMgr();
1683
1692
  }
1684
- var context = {
1685
- _next: _moveNext,
1686
- ctx: {
1687
- core: function () {
1688
- return core;
1689
- },
1690
- diagLog: function () {
1691
- return safeGetLogger(core, config);
1692
- },
1693
- getCfg: function () {
1694
- return config;
1695
- },
1696
- getExtCfg: _getExtCfg,
1697
- getConfig: _getConfig,
1698
- hasNext: function () {
1699
- return !!_nextProxy;
1700
- },
1701
- getNext: function () {
1702
- return _nextProxy;
1703
- },
1704
- setNext: function (nextPlugin) {
1705
- _nextProxy = nextPlugin;
1706
- },
1707
- iterate: _iterateChain,
1708
- onComplete: _addOnComplete
1709
- }
1710
- };
1711
- function _addOnComplete(onComplete, that) {
1712
- var args = [];
1713
- for (var _i = 2; _i < arguments.length; _i++) {
1714
- args[_i - 2] = arguments[_i];
1693
+ else if (config) {
1694
+ var cookieCfg = config.cookieCfg;
1695
+ if (cookieCfg[strConfigCookieMgr]) {
1696
+ cookieMgr = cookieCfg[strConfigCookieMgr];
1715
1697
  }
1716
- if (onComplete) {
1717
- _onComplete.push({
1718
- func: onComplete,
1719
- self: !isUndefined(that) ? that : context.ctx,
1720
- args: args
1721
- });
1698
+ else {
1699
+ cookieMgr = createCookieMgr(config);
1722
1700
  }
1723
1701
  }
1724
- function _moveNext() {
1725
- var nextProxy = _nextProxy;
1726
- _nextProxy = nextProxy ? nextProxy.getNext() : null;
1727
- if (!nextProxy) {
1728
- var onComplete = _onComplete;
1729
- if (onComplete && onComplete.length > 0) {
1730
- arrForEach(onComplete, function (completeDetails) {
1731
- try {
1732
- completeDetails.func.call(completeDetails.self, completeDetails.args);
1733
- }
1734
- catch (e) {
1735
- _throwInternal(core.logger, 2 , 73 , "Unexpected Exception during onComplete - " + dumpObj(e));
1736
- }
1737
- });
1738
- _onComplete = [];
1739
- }
1740
- }
1741
- return nextProxy;
1702
+ if (!cookieMgr) {
1703
+ cookieMgr = _gblCookieMgr(config, (core || {}).logger);
1742
1704
  }
1743
- function _getExtCfg(identifier, defaultValue, mergeDefault) {
1744
- if (defaultValue === void 0) { defaultValue = {}; }
1745
- if (mergeDefault === void 0) { mergeDefault = 0 ; }
1746
- var theConfig;
1747
- if (config) {
1748
- var extConfig = config.extensionConfig;
1749
- if (extConfig && identifier) {
1750
- theConfig = extConfig[identifier];
1705
+ return cookieMgr;
1706
+ }
1707
+ function createCookieMgr(rootConfig, logger) {
1708
+ var cookieMgrConfig = _createCookieMgrConfig(rootConfig || _globalCookieConfig);
1709
+ var _path = cookieMgrConfig.path || "/";
1710
+ var _domain = cookieMgrConfig.domain;
1711
+ var _enabled = cookieMgrConfig[strEnabled] !== false;
1712
+ var cookieMgr = {
1713
+ isEnabled: function () {
1714
+ var enabled = _enabled && areCookiesSupported(logger);
1715
+ var gblManager = _globalCookieConfig[strConfigCookieMgr];
1716
+ if (enabled && gblManager && cookieMgr !== gblManager) {
1717
+ enabled = _isMgrEnabled(gblManager);
1751
1718
  }
1752
- }
1753
- if (!theConfig) {
1754
- theConfig = defaultValue;
1755
- }
1756
- else if (isObject(defaultValue)) {
1757
- if (mergeDefault !== 0 ) {
1758
- var newConfig_1 = objExtend(true, defaultValue, theConfig);
1759
- if (config && mergeDefault === 2 ) {
1760
- objForEachKey(defaultValue, function (field) {
1761
- if (isNullOrUndefined(newConfig_1[field])) {
1762
- var cfgValue = config[field];
1763
- if (!isNullOrUndefined(cfgValue)) {
1764
- newConfig_1[field] = cfgValue;
1765
- }
1719
+ return enabled;
1720
+ },
1721
+ setEnabled: function (value) {
1722
+ _enabled = value !== false;
1723
+ },
1724
+ set: function (name, value, maxAgeSec, domain, path) {
1725
+ var result = false;
1726
+ if (_isMgrEnabled(cookieMgr)) {
1727
+ var values = {};
1728
+ var theValue = strTrim(value || strEmpty);
1729
+ var idx = theValue.indexOf(";");
1730
+ if (idx !== -1) {
1731
+ theValue = strTrim(value.substring(0, idx));
1732
+ values = _extractParts(value.substring(idx + 1));
1733
+ }
1734
+ setValue(values, "domain", domain || _domain, isTruthy, isUndefined);
1735
+ if (!isNullOrUndefined(maxAgeSec)) {
1736
+ var _isIE = isIE();
1737
+ if (isUndefined(values[strExpires])) {
1738
+ var nowMs = dateNow();
1739
+ var expireMs = nowMs + (maxAgeSec * 1000);
1740
+ if (expireMs > 0) {
1741
+ var expiry = new Date();
1742
+ expiry.setTime(expireMs);
1743
+ setValue(values, strExpires, _formatDate(expiry, !_isIE ? strToUTCString : strToGMTString) || _formatDate(expiry, _isIE ? strToGMTString : strToUTCString) || strEmpty, isTruthy);
1766
1744
  }
1767
- });
1745
+ }
1746
+ if (!_isIE) {
1747
+ setValue(values, "max-age", strEmpty + maxAgeSec, null, isUndefined);
1748
+ }
1768
1749
  }
1769
- theConfig = newConfig_1;
1770
- }
1771
- }
1772
- return theConfig;
1773
- }
1774
- function _getConfig(identifier, field, defaultValue) {
1775
- if (defaultValue === void 0) { defaultValue = false; }
1776
- var theValue;
1777
- var extConfig = _getExtCfg(identifier, null);
1778
- if (extConfig && !isNullOrUndefined(extConfig[field])) {
1779
- theValue = extConfig[field];
1750
+ var location_1 = getLocation();
1751
+ if (location_1 && location_1.protocol === "https:") {
1752
+ setValue(values, "secure", null, null, isUndefined);
1753
+ if (_allowUaSameSite === null) {
1754
+ _allowUaSameSite = !uaDisallowsSameSiteNone((getNavigator() || {}).userAgent);
1755
+ }
1756
+ if (_allowUaSameSite) {
1757
+ setValue(values, "SameSite", "None", null, isUndefined);
1758
+ }
1759
+ }
1760
+ setValue(values, "path", path || _path, null, isUndefined);
1761
+ var setCookieFn = cookieMgrConfig.setCookie || _setCookieValue;
1762
+ setCookieFn(name, _formatCookieValue(theValue, values));
1763
+ result = true;
1764
+ }
1765
+ return result;
1766
+ },
1767
+ get: function (name) {
1768
+ var value = strEmpty;
1769
+ if (_isMgrEnabled(cookieMgr)) {
1770
+ value = (cookieMgrConfig.getCookie || _getCookieValue)(name);
1771
+ }
1772
+ return value;
1773
+ },
1774
+ del: function (name, path) {
1775
+ var result = false;
1776
+ if (_isMgrEnabled(cookieMgr)) {
1777
+ result = cookieMgr.purge(name, path);
1778
+ }
1779
+ return result;
1780
+ },
1781
+ purge: function (name, path) {
1782
+ var _a;
1783
+ var result = false;
1784
+ if (areCookiesSupported(logger)) {
1785
+ var values = (_a = {},
1786
+ _a["path"] = path ? path : "/",
1787
+ _a[strExpires] = "Thu, 01 Jan 1970 00:00:01 GMT",
1788
+ _a);
1789
+ if (!isIE()) {
1790
+ values["max-age"] = "0";
1791
+ }
1792
+ var delCookie = cookieMgrConfig.delCookie || _setCookieValue;
1793
+ delCookie(name, _formatCookieValue(strEmpty, values));
1794
+ result = true;
1795
+ }
1796
+ return result;
1780
1797
  }
1781
- else if (config && !isNullOrUndefined(config[field])) {
1782
- theValue = config[field];
1798
+ };
1799
+ cookieMgr[strConfigCookieMgr] = cookieMgr;
1800
+ return cookieMgr;
1801
+ }
1802
+ function areCookiesSupported(logger) {
1803
+ if (_supportsCookies === null) {
1804
+ _supportsCookies = false;
1805
+ try {
1806
+ var doc = _doc || {};
1807
+ _supportsCookies = doc[strCookie] !== undefined;
1808
+ }
1809
+ catch (e) {
1810
+ _throwInternal(logger, 2 , 68 , "Cannot access document.cookie - " + getExceptionName(e), { exception: dumpObj(e) });
1783
1811
  }
1784
- return !isNullOrUndefined(theValue) ? theValue : defaultValue;
1785
1812
  }
1786
- function _iterateChain(cb) {
1787
- var nextPlugin;
1788
- while (!!(nextPlugin = context._next())) {
1789
- var plugin = nextPlugin.getPlugin();
1790
- if (plugin) {
1791
- cb(plugin);
1813
+ return _supportsCookies;
1814
+ }
1815
+ function _extractParts(theValue) {
1816
+ var values = {};
1817
+ if (theValue && theValue.length) {
1818
+ var parts = strTrim(theValue).split(";");
1819
+ arrForEach(parts, function (thePart) {
1820
+ thePart = strTrim(thePart || strEmpty);
1821
+ if (thePart) {
1822
+ var idx = thePart.indexOf("=");
1823
+ if (idx === -1) {
1824
+ values[thePart] = null;
1825
+ }
1826
+ else {
1827
+ values[strTrim(thePart.substring(0, idx))] = strTrim(thePart.substring(idx + 1));
1828
+ }
1792
1829
  }
1793
- }
1830
+ });
1794
1831
  }
1795
- return context;
1832
+ return values;
1796
1833
  }
1797
- function createProcessTelemetryContext(telemetryChain, config, core, startAt) {
1798
- var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1799
- var context = internalContext.ctx;
1800
- function _processNext(env) {
1801
- var nextPlugin = internalContext._next();
1802
- nextPlugin && nextPlugin.processTelemetry(env, context);
1803
- return !nextPlugin;
1834
+ function _formatDate(theDate, func) {
1835
+ if (isFunction(theDate[func])) {
1836
+ return theDate[func]();
1804
1837
  }
1805
- function _createNew(plugins, startAt) {
1806
- if (plugins === void 0) { plugins = null; }
1807
- if (isArray(plugins)) {
1808
- plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1838
+ return null;
1839
+ }
1840
+ function _formatCookieValue(value, values) {
1841
+ var cookieValue = value || strEmpty;
1842
+ objForEachKey(values, function (name, theValue) {
1843
+ cookieValue += "; " + name + (!isNullOrUndefined(theValue) ? "=" + theValue : strEmpty);
1844
+ });
1845
+ return cookieValue;
1846
+ }
1847
+ function _getCookieValue(name) {
1848
+ var cookieValue = strEmpty;
1849
+ if (_doc) {
1850
+ var theCookie = _doc[strCookie] || strEmpty;
1851
+ if (_parsedCookieValue !== theCookie) {
1852
+ _cookieCache = _extractParts(theCookie);
1853
+ _parsedCookieValue = theCookie;
1809
1854
  }
1810
- return createProcessTelemetryContext(plugins || context.getNext(), config, core, startAt);
1855
+ cookieValue = strTrim(_cookieCache[name] || strEmpty);
1811
1856
  }
1812
- context.processNext = _processNext;
1813
- context.createNew = _createNew;
1814
- return context;
1857
+ return cookieValue;
1815
1858
  }
1816
- function createProcessTelemetryUnloadContext(telemetryChain, core, startAt) {
1817
- var config = core.config || {};
1818
- var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1819
- var context = internalContext.ctx;
1820
- function _processNext(unloadState) {
1821
- var nextPlugin = internalContext._next();
1822
- nextPlugin && nextPlugin.unload(context, unloadState);
1823
- return !nextPlugin;
1824
- }
1825
- function _createNew(plugins, startAt) {
1826
- if (plugins === void 0) { plugins = null; }
1827
- if (isArray(plugins)) {
1828
- plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1829
- }
1830
- return createProcessTelemetryUnloadContext(plugins || context.getNext(), core, startAt);
1859
+ function _setCookieValue(name, cookieValue) {
1860
+ if (_doc) {
1861
+ _doc[strCookie] = name + "=" + cookieValue;
1831
1862
  }
1832
- context.processNext = _processNext;
1833
- context.createNew = _createNew;
1834
- return context;
1835
1863
  }
1836
- function createProcessTelemetryUpdateContext(telemetryChain, core, startAt) {
1837
- var config = core.config || {};
1838
- var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1839
- var context = internalContext.ctx;
1840
- function _processNext(updateState) {
1841
- return context.iterate(function (plugin) {
1842
- if (isFunction(plugin.update)) {
1843
- plugin.update(context, updateState);
1844
- }
1845
- });
1864
+ function uaDisallowsSameSiteNone(userAgent) {
1865
+ if (!isString(userAgent)) {
1866
+ return false;
1846
1867
  }
1847
- function _createNew(plugins, startAt) {
1848
- if (plugins === void 0) { plugins = null; }
1849
- if (isArray(plugins)) {
1850
- plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1851
- }
1852
- return createProcessTelemetryUpdateContext(plugins || context.getNext(), core, startAt);
1868
+ if (strContains(userAgent, "CPU iPhone OS 12") || strContains(userAgent, "iPad; CPU OS 12")) {
1869
+ return true;
1853
1870
  }
1854
- context.processNext = _processNext;
1855
- context.createNew = _createNew;
1856
- return context;
1857
- }
1858
- function createTelemetryProxyChain(plugins, config, core, startAt) {
1859
- var firstProxy = null;
1860
- var add = startAt ? false : true;
1861
- if (isArray(plugins) && plugins.length > 0) {
1862
- var lastProxy_1 = null;
1863
- arrForEach(plugins, function (thePlugin) {
1864
- if (!add && startAt === thePlugin) {
1865
- add = true;
1866
- }
1867
- if (add && thePlugin && isFunction(thePlugin.processTelemetry)) {
1868
- var newProxy = createTelemetryPluginProxy(thePlugin, config, core);
1869
- if (!firstProxy) {
1870
- firstProxy = newProxy;
1871
- }
1872
- if (lastProxy_1) {
1873
- lastProxy_1._setNext(newProxy);
1874
- }
1875
- lastProxy_1 = newProxy;
1876
- }
1877
- });
1871
+ if (strContains(userAgent, "Macintosh; Intel Mac OS X 10_14") && strContains(userAgent, "Version/") && strContains(userAgent, "Safari")) {
1872
+ return true;
1878
1873
  }
1879
- if (startAt && !firstProxy) {
1880
- return createTelemetryProxyChain([startAt], config, core);
1874
+ if (strContains(userAgent, "Macintosh; Intel Mac OS X 10_14") && strEndsWith(userAgent, "AppleWebKit/605.1.15 (KHTML, like Gecko)")) {
1875
+ return true;
1881
1876
  }
1882
- return firstProxy;
1883
- }
1884
- function createTelemetryPluginProxy(plugin, config, core) {
1885
- var nextProxy = null;
1886
- var hasProcessTelemetry = isFunction(plugin.processTelemetry);
1887
- var hasSetNext = isFunction(plugin.setNextPlugin);
1888
- var chainId;
1889
- if (plugin) {
1890
- chainId = plugin.identifier + "-" + plugin.priority + "-" + _chainId++;
1877
+ if (strContains(userAgent, "Chrome/5") || strContains(userAgent, "Chrome/6")) {
1878
+ return true;
1891
1879
  }
1892
- else {
1893
- chainId = "Unknown-0-" + _chainId++;
1880
+ if (strContains(userAgent, "UnrealEngine") && !strContains(userAgent, "Chrome")) {
1881
+ return true;
1894
1882
  }
1895
- var proxyChain = {
1896
- getPlugin: function () {
1897
- return plugin;
1898
- },
1899
- getNext: function () {
1900
- return nextProxy;
1901
- },
1902
- processTelemetry: _processTelemetry,
1903
- unload: _unloadPlugin,
1904
- update: _updatePlugin,
1905
- _id: chainId,
1906
- _setNext: function (nextPlugin) {
1907
- nextProxy = nextPlugin;
1908
- }
1909
- };
1910
- function _getTelCtx() {
1911
- var itemCtx;
1912
- if (plugin && isFunction(plugin[strGetTelCtx])) {
1913
- itemCtx = plugin[strGetTelCtx]();
1914
- }
1915
- if (!itemCtx) {
1916
- itemCtx = createProcessTelemetryContext(proxyChain, config, core);
1917
- }
1918
- return itemCtx;
1883
+ if (strContains(userAgent, "UCBrowser/12") || strContains(userAgent, "UCBrowser/11")) {
1884
+ return true;
1919
1885
  }
1920
- function _processChain(itemCtx, processPluginFn, name, details, isAsync) {
1921
- var hasRun = false;
1922
- var identifier = plugin ? plugin.identifier : strTelemetryPluginChain;
1923
- var hasRunContext = itemCtx[strHasRunFlags];
1924
- if (!hasRunContext) {
1925
- hasRunContext = itemCtx[strHasRunFlags] = {};
1926
- }
1927
- itemCtx.setNext(nextProxy);
1928
- if (plugin) {
1929
- doPerf(itemCtx[strCore](), function () { return identifier + ":" + name; }, function () {
1930
- hasRunContext[chainId] = true;
1931
- try {
1932
- var nextId = nextProxy ? nextProxy._id : strEmpty;
1933
- if (nextId) {
1934
- hasRunContext[nextId] = false;
1935
- }
1936
- hasRun = processPluginFn(itemCtx);
1937
- }
1938
- catch (error) {
1939
- var hasNextRun = nextProxy ? hasRunContext[nextProxy._id] : true;
1940
- if (hasNextRun) {
1941
- hasRun = true;
1942
- }
1943
- if (!nextProxy || !hasNextRun) {
1944
- _throwInternal(itemCtx.diagLog(), 1 , 73 , "Plugin [" + identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
1886
+ return false;
1887
+ }
1888
+
1889
+ var strOnPrefix = "on";
1890
+ var strAttachEvent = "attachEvent";
1891
+ var strAddEventHelper = "addEventListener";
1892
+ var strDetachEvent = "detachEvent";
1893
+ var strRemoveEventListener = "removeEventListener";
1894
+ var strEvents = "events";
1895
+ var strVisibilityChangeEvt = "visibilitychange";
1896
+ var strPageHide = "pagehide";
1897
+ var strPageShow = "pageshow";
1898
+ var strUnload = "unload";
1899
+ var strBeforeUnload = "beforeunload";
1900
+ var strPageHideNamespace = createUniqueNamespace("aiEvtPageHide");
1901
+ var strPageShowNamespace = createUniqueNamespace("aiEvtPageShow");
1902
+ var rRemoveEmptyNs = /\.[\.]+/g;
1903
+ var rRemoveTrailingEmptyNs = /[\.]+$/;
1904
+ var _guid = 1;
1905
+ var elmNodeData = createElmNodeData("events");
1906
+ var eventNamespace = /^([^.]*)(?:\.(.+)|)/;
1907
+ function _normalizeNamespace(name) {
1908
+ if (name && name.replace) {
1909
+ return name.replace(/^\s*\.*|\.*\s*$/g, "");
1910
+ }
1911
+ return name;
1912
+ }
1913
+ function _getEvtNamespace(eventName, evtNamespace) {
1914
+ if (evtNamespace) {
1915
+ var theNamespace_1 = "";
1916
+ if (isArray(evtNamespace)) {
1917
+ theNamespace_1 = "";
1918
+ arrForEach(evtNamespace, function (name) {
1919
+ name = _normalizeNamespace(name);
1920
+ if (name) {
1921
+ if (name[0] !== ".") {
1922
+ name = "." + name;
1945
1923
  }
1924
+ theNamespace_1 += name;
1946
1925
  }
1947
- }, details, isAsync);
1926
+ });
1948
1927
  }
1949
- return hasRun;
1950
- }
1951
- function _processTelemetry(env, itemCtx) {
1952
- itemCtx = itemCtx || _getTelCtx();
1953
- function _callProcessTelemetry(itemCtx) {
1954
- if (!plugin || !hasProcessTelemetry) {
1955
- return false;
1956
- }
1957
- var pluginState = _getPluginState(plugin);
1958
- if (pluginState.teardown || pluginState[strDisabled]) {
1959
- return false;
1960
- }
1961
- if (hasSetNext) {
1962
- plugin.setNextPlugin(nextProxy);
1963
- }
1964
- plugin.processTelemetry(env, itemCtx);
1965
- return true;
1928
+ else {
1929
+ theNamespace_1 = _normalizeNamespace(evtNamespace);
1966
1930
  }
1967
- if (!_processChain(itemCtx, _callProcessTelemetry, "processTelemetry", function () { return ({ item: env }); }, !(env.sync))) {
1968
- itemCtx.processNext(env);
1931
+ if (theNamespace_1) {
1932
+ if (theNamespace_1[0] !== ".") {
1933
+ theNamespace_1 = "." + theNamespace_1;
1934
+ }
1935
+ eventName = (eventName || "") + theNamespace_1;
1969
1936
  }
1970
1937
  }
1971
- function _unloadPlugin(unloadCtx, unloadState) {
1972
- function _callTeardown() {
1973
- var hasRun = false;
1974
- if (plugin) {
1975
- var pluginState = _getPluginState(plugin);
1976
- var pluginCore = plugin[strCore] || pluginState.core;
1977
- if (plugin && (!pluginCore || pluginCore === unloadCtx[strCore]()) && !pluginState[strTeardown]) {
1978
- pluginState[strCore] = null;
1979
- pluginState[strTeardown] = true;
1980
- pluginState[strIsInitialized] = false;
1981
- if (plugin[strTeardown] && plugin[strTeardown](unloadCtx, unloadState) === true) {
1982
- hasRun = true;
1983
- }
1938
+ var parsedEvent = (eventNamespace.exec(eventName || "") || []);
1939
+ return {
1940
+ type: parsedEvent[1],
1941
+ ns: ((parsedEvent[2] || "").replace(rRemoveEmptyNs, ".").replace(rRemoveTrailingEmptyNs, "").split(".").sort()).join(".")
1942
+ };
1943
+ }
1944
+ function __getRegisteredEvents(target, eventName, evtNamespace) {
1945
+ var theEvents = [];
1946
+ var eventCache = elmNodeData.get(target, strEvents, {}, false);
1947
+ var evtName = _getEvtNamespace(eventName, evtNamespace);
1948
+ objForEachKey(eventCache, function (evtType, registeredEvents) {
1949
+ arrForEach(registeredEvents, function (value) {
1950
+ if (!evtName.type || evtName.type === value.evtName.type) {
1951
+ if (!evtName.ns || evtName.ns === evtName.ns) {
1952
+ theEvents.push({
1953
+ name: value.evtName.type + (value.evtName.ns ? "." + value.evtName.ns : ""),
1954
+ handler: value.handler
1955
+ });
1984
1956
  }
1985
1957
  }
1986
- return hasRun;
1958
+ });
1959
+ });
1960
+ return theEvents;
1961
+ }
1962
+ function _getRegisteredEvents(target, evtName, addDefault) {
1963
+ if (addDefault === void 0) { addDefault = true; }
1964
+ var aiEvts = elmNodeData.get(target, strEvents, {}, addDefault);
1965
+ var registeredEvents = aiEvts[evtName];
1966
+ if (!registeredEvents) {
1967
+ registeredEvents = aiEvts[evtName] = [];
1968
+ }
1969
+ return registeredEvents;
1970
+ }
1971
+ function _doDetach(obj, evtName, handlerRef, useCapture) {
1972
+ if (obj && evtName && evtName.type) {
1973
+ if (obj[strRemoveEventListener]) {
1974
+ obj[strRemoveEventListener](evtName.type, handlerRef, useCapture);
1987
1975
  }
1988
- if (!_processChain(unloadCtx, _callTeardown, "unload", function () { }, unloadState.isAsync)) {
1989
- unloadCtx.processNext(unloadState);
1976
+ else if (obj[strDetachEvent]) {
1977
+ obj[strDetachEvent](strOnPrefix + evtName.type, handlerRef);
1990
1978
  }
1991
1979
  }
1992
- function _updatePlugin(updateCtx, updateState) {
1993
- function _callUpdate() {
1994
- var hasRun = false;
1995
- if (plugin) {
1996
- var pluginState = _getPluginState(plugin);
1997
- var pluginCore = plugin[strCore] || pluginState.core;
1998
- if (plugin && (!pluginCore || pluginCore === updateCtx[strCore]()) && !pluginState[strTeardown]) {
1999
- if (plugin[strUpdate] && plugin[strUpdate](updateCtx, updateState) === true) {
2000
- hasRun = true;
2001
- }
2002
- }
2003
- }
2004
- return hasRun;
1980
+ }
1981
+ function _doAttach(obj, evtName, handlerRef, useCapture) {
1982
+ var result = false;
1983
+ if (obj && evtName && evtName.type && handlerRef) {
1984
+ if (obj[strAddEventHelper]) {
1985
+ obj[strAddEventHelper](evtName.type, handlerRef, useCapture);
1986
+ result = true;
2005
1987
  }
2006
- if (!_processChain(updateCtx, _callUpdate, "update", function () { }, false)) {
2007
- updateCtx.processNext(updateState);
1988
+ else if (obj[strAttachEvent]) {
1989
+ obj[strAttachEvent](strOnPrefix + evtName.type, handlerRef);
1990
+ result = true;
2008
1991
  }
2009
1992
  }
2010
- return objFreeze(proxyChain);
1993
+ return result;
2011
1994
  }
2012
- var ProcessTelemetryContext = /** @class */ (function () {
2013
- function ProcessTelemetryContext(pluginChain, config, core, startAt) {
2014
- var _self = this;
2015
- var context = createProcessTelemetryContext(pluginChain, config, core, startAt);
2016
- proxyFunctions(_self, context, objKeys(context));
2017
- }
2018
- return ProcessTelemetryContext;
2019
- }());
2020
-
2021
- var strToGMTString = "toGMTString";
2022
- var strToUTCString = "toUTCString";
2023
- var strCookie = "cookie";
2024
- var strExpires = "expires";
2025
- var strEnabled = "enabled";
2026
- var strIsCookieUseDisabled = "isCookieUseDisabled";
2027
- var strDisableCookiesUsage = "disableCookiesUsage";
2028
- var strConfigCookieMgr = "_ckMgr";
2029
- var _supportsCookies = null;
2030
- var _allowUaSameSite = null;
2031
- var _parsedCookieValue = null;
2032
- var _doc = getDocument();
2033
- var _cookieCache = {};
2034
- var _globalCookieConfig = {};
2035
- function _gblCookieMgr(config, logger) {
2036
- var inst = createCookieMgr[strConfigCookieMgr] || _globalCookieConfig[strConfigCookieMgr];
2037
- if (!inst) {
2038
- inst = createCookieMgr[strConfigCookieMgr] = createCookieMgr(config, logger);
2039
- _globalCookieConfig[strConfigCookieMgr] = inst;
1995
+ function _doUnregister(target, events, evtName, unRegFn) {
1996
+ var idx = events.length;
1997
+ while (idx--) {
1998
+ var theEvent = events[idx];
1999
+ if (theEvent) {
2000
+ if (!evtName.ns || evtName.ns === theEvent.evtName.ns) {
2001
+ if (!unRegFn || unRegFn(theEvent)) {
2002
+ _doDetach(target, theEvent.evtName, theEvent.handler, theEvent.capture);
2003
+ events.splice(idx, 1);
2004
+ }
2005
+ }
2006
+ }
2040
2007
  }
2041
- return inst;
2042
2008
  }
2043
- function _isMgrEnabled(cookieMgr) {
2044
- if (cookieMgr) {
2045
- return cookieMgr.isEnabled();
2009
+ function _unregisterEvents(target, evtName, unRegFn) {
2010
+ if (evtName.type) {
2011
+ _doUnregister(target, _getRegisteredEvents(target, evtName.type), evtName, unRegFn);
2046
2012
  }
2047
- return true;
2048
- }
2049
- function _createCookieMgrConfig(rootConfig) {
2050
- var cookieMgrCfg = rootConfig.cookieCfg = rootConfig.cookieCfg || {};
2051
- setValue(cookieMgrCfg, "domain", rootConfig.cookieDomain, isNotNullOrUndefined, isNullOrUndefined);
2052
- setValue(cookieMgrCfg, "path", rootConfig.cookiePath || "/", null, isNullOrUndefined);
2053
- if (isNullOrUndefined(cookieMgrCfg[strEnabled])) {
2054
- var cookieEnabled = void 0;
2055
- if (!isUndefined(rootConfig[strIsCookieUseDisabled])) {
2056
- cookieEnabled = !rootConfig[strIsCookieUseDisabled];
2057
- }
2058
- if (!isUndefined(rootConfig[strDisableCookiesUsage])) {
2059
- cookieEnabled = !rootConfig[strDisableCookiesUsage];
2013
+ else {
2014
+ var eventCache = elmNodeData.get(target, strEvents, {});
2015
+ objForEachKey(eventCache, function (evtType, events) {
2016
+ _doUnregister(target, events, evtName, unRegFn);
2017
+ });
2018
+ if (objKeys(eventCache).length === 0) {
2019
+ elmNodeData.kill(target, strEvents);
2060
2020
  }
2061
- cookieMgrCfg[strEnabled] = cookieEnabled;
2062
2021
  }
2063
- return cookieMgrCfg;
2064
2022
  }
2065
- function safeGetCookieMgr(core, config) {
2066
- var cookieMgr;
2067
- if (core) {
2068
- cookieMgr = core.getCookieMgr();
2069
- }
2070
- else if (config) {
2071
- var cookieCfg = config.cookieCfg;
2072
- if (cookieCfg[strConfigCookieMgr]) {
2073
- cookieMgr = cookieCfg[strConfigCookieMgr];
2023
+ function mergeEvtNamespace(theNamespace, namespaces) {
2024
+ var newNamespaces;
2025
+ if (namespaces) {
2026
+ if (isArray(namespaces)) {
2027
+ newNamespaces = [theNamespace].concat(namespaces);
2074
2028
  }
2075
2029
  else {
2076
- cookieMgr = createCookieMgr(config);
2030
+ newNamespaces = [theNamespace, namespaces];
2077
2031
  }
2032
+ newNamespaces = (_getEvtNamespace("xx", newNamespaces).ns).split(".");
2078
2033
  }
2079
- if (!cookieMgr) {
2080
- cookieMgr = _gblCookieMgr(config, (core || {}).logger);
2034
+ else {
2035
+ newNamespaces = theNamespace;
2081
2036
  }
2082
- return cookieMgr;
2037
+ return newNamespaces;
2083
2038
  }
2084
- function createCookieMgr(rootConfig, logger) {
2085
- var cookieMgrConfig = _createCookieMgrConfig(rootConfig || _globalCookieConfig);
2086
- var _path = cookieMgrConfig.path || "/";
2087
- var _domain = cookieMgrConfig.domain;
2088
- var _enabled = cookieMgrConfig[strEnabled] !== false;
2089
- var cookieMgr = {
2090
- isEnabled: function () {
2091
- var enabled = _enabled && areCookiesSupported(logger);
2092
- var gblManager = _globalCookieConfig[strConfigCookieMgr];
2093
- if (enabled && gblManager && cookieMgr !== gblManager) {
2094
- enabled = _isMgrEnabled(gblManager);
2095
- }
2096
- return enabled;
2097
- },
2098
- setEnabled: function (value) {
2099
- _enabled = value !== false;
2100
- },
2101
- set: function (name, value, maxAgeSec, domain, path) {
2102
- var result = false;
2103
- if (_isMgrEnabled(cookieMgr)) {
2104
- var values = {};
2105
- var theValue = strTrim(value || strEmpty);
2106
- var idx = theValue.indexOf(";");
2107
- if (idx !== -1) {
2108
- theValue = strTrim(value.substring(0, idx));
2109
- values = _extractParts(value.substring(idx + 1));
2110
- }
2111
- setValue(values, "domain", domain || _domain, isTruthy, isUndefined);
2112
- if (!isNullOrUndefined(maxAgeSec)) {
2113
- var _isIE = isIE();
2114
- if (isUndefined(values[strExpires])) {
2115
- var nowMs = dateNow();
2116
- var expireMs = nowMs + (maxAgeSec * 1000);
2117
- if (expireMs > 0) {
2118
- var expiry = new Date();
2119
- expiry.setTime(expireMs);
2120
- setValue(values, strExpires, _formatDate(expiry, !_isIE ? strToUTCString : strToGMTString) || _formatDate(expiry, _isIE ? strToGMTString : strToUTCString) || strEmpty, isTruthy);
2121
- }
2122
- }
2123
- if (!_isIE) {
2124
- setValue(values, "max-age", strEmpty + maxAgeSec, null, isUndefined);
2125
- }
2126
- }
2127
- var location_1 = getLocation();
2128
- if (location_1 && location_1.protocol === "https:") {
2129
- setValue(values, "secure", null, null, isUndefined);
2130
- if (_allowUaSameSite === null) {
2131
- _allowUaSameSite = !uaDisallowsSameSiteNone((getNavigator() || {}).userAgent);
2132
- }
2133
- if (_allowUaSameSite) {
2134
- setValue(values, "SameSite", "None", null, isUndefined);
2135
- }
2136
- }
2137
- setValue(values, "path", path || _path, null, isUndefined);
2138
- var setCookieFn = cookieMgrConfig.setCookie || _setCookieValue;
2139
- setCookieFn(name, _formatCookieValue(theValue, values));
2140
- result = true;
2141
- }
2142
- return result;
2143
- },
2144
- get: function (name) {
2145
- var value = strEmpty;
2146
- if (_isMgrEnabled(cookieMgr)) {
2147
- value = (cookieMgrConfig.getCookie || _getCookieValue)(name);
2148
- }
2149
- return value;
2150
- },
2151
- del: function (name, path) {
2152
- var result = false;
2153
- if (_isMgrEnabled(cookieMgr)) {
2154
- result = cookieMgr.purge(name, path);
2155
- }
2156
- return result;
2157
- },
2158
- purge: function (name, path) {
2159
- var _a;
2160
- var result = false;
2161
- if (areCookiesSupported(logger)) {
2162
- var values = (_a = {},
2163
- _a["path"] = path ? path : "/",
2164
- _a[strExpires] = "Thu, 01 Jan 1970 00:00:01 GMT",
2165
- _a);
2166
- if (!isIE()) {
2167
- values["max-age"] = "0";
2168
- }
2169
- var delCookie = cookieMgrConfig.delCookie || _setCookieValue;
2170
- delCookie(name, _formatCookieValue(strEmpty, values));
2171
- result = true;
2172
- }
2173
- return result;
2174
- }
2175
- };
2176
- cookieMgr[strConfigCookieMgr] = cookieMgr;
2177
- return cookieMgr;
2178
- }
2179
- function areCookiesSupported(logger) {
2180
- if (_supportsCookies === null) {
2181
- _supportsCookies = false;
2039
+ function eventOn(target, eventName, handlerRef, evtNamespace, useCapture) {
2040
+ if (useCapture === void 0) { useCapture = false; }
2041
+ var result = false;
2042
+ if (target) {
2182
2043
  try {
2183
- var doc = _doc || {};
2184
- _supportsCookies = doc[strCookie] !== undefined;
2044
+ var evtName = _getEvtNamespace(eventName, evtNamespace);
2045
+ result = _doAttach(target, evtName, handlerRef, useCapture);
2046
+ if (result && elmNodeData.accept(target)) {
2047
+ var registeredEvent = {
2048
+ guid: _guid++,
2049
+ evtName: evtName,
2050
+ handler: handlerRef,
2051
+ capture: useCapture
2052
+ };
2053
+ _getRegisteredEvents(target, evtName.type).push(registeredEvent);
2054
+ }
2185
2055
  }
2186
2056
  catch (e) {
2187
- _throwInternal(logger, 2 , 68 , "Cannot access document.cookie - " + getExceptionName(e), { exception: dumpObj(e) });
2188
2057
  }
2189
2058
  }
2190
- return _supportsCookies;
2059
+ return result;
2191
2060
  }
2192
- function _extractParts(theValue) {
2193
- var values = {};
2194
- if (theValue && theValue.length) {
2195
- var parts = strTrim(theValue).split(";");
2196
- arrForEach(parts, function (thePart) {
2197
- thePart = strTrim(thePart || strEmpty);
2198
- if (thePart) {
2199
- var idx = thePart.indexOf("=");
2200
- if (idx === -1) {
2201
- values[thePart] = null;
2202
- }
2203
- else {
2204
- values[strTrim(thePart.substring(0, idx))] = strTrim(thePart.substring(idx + 1));
2061
+ function eventOff(target, eventName, handlerRef, evtNamespace, useCapture) {
2062
+ if (useCapture === void 0) { useCapture = false; }
2063
+ if (target) {
2064
+ try {
2065
+ var evtName_1 = _getEvtNamespace(eventName, evtNamespace);
2066
+ var found_1 = false;
2067
+ _unregisterEvents(target, evtName_1, function (regEvent) {
2068
+ if ((evtName_1.ns && !handlerRef) || regEvent.handler === handlerRef) {
2069
+ found_1 = true;
2070
+ return true;
2205
2071
  }
2072
+ return false;
2073
+ });
2074
+ if (!found_1) {
2075
+ _doDetach(target, evtName_1, handlerRef, useCapture);
2206
2076
  }
2207
- });
2077
+ }
2078
+ catch (e) {
2079
+ }
2208
2080
  }
2209
- return values;
2210
2081
  }
2211
- function _formatDate(theDate, func) {
2212
- if (isFunction(theDate[func])) {
2213
- return theDate[func]();
2214
- }
2215
- return null;
2082
+ function attachEvent(obj, eventNameWithoutOn, handlerRef, useCapture) {
2083
+ if (useCapture === void 0) { useCapture = false; }
2084
+ return eventOn(obj, eventNameWithoutOn, handlerRef, null, useCapture);
2216
2085
  }
2217
- function _formatCookieValue(value, values) {
2218
- var cookieValue = value || strEmpty;
2219
- objForEachKey(values, function (name, theValue) {
2220
- cookieValue += "; " + name + (!isNullOrUndefined(theValue) ? "=" + theValue : strEmpty);
2221
- });
2222
- return cookieValue;
2086
+ function detachEvent(obj, eventNameWithoutOn, handlerRef, useCapture) {
2087
+ if (useCapture === void 0) { useCapture = false; }
2088
+ eventOff(obj, eventNameWithoutOn, handlerRef, null, useCapture);
2223
2089
  }
2224
- function _getCookieValue(name) {
2225
- var cookieValue = strEmpty;
2226
- if (_doc) {
2227
- var theCookie = _doc[strCookie] || strEmpty;
2228
- if (_parsedCookieValue !== theCookie) {
2229
- _cookieCache = _extractParts(theCookie);
2230
- _parsedCookieValue = theCookie;
2231
- }
2232
- cookieValue = strTrim(_cookieCache[name] || strEmpty);
2090
+ function addEventHandler(eventName, callback, evtNamespace) {
2091
+ var result = false;
2092
+ var w = getWindow();
2093
+ if (w) {
2094
+ result = eventOn(w, eventName, callback, evtNamespace);
2095
+ result = eventOn(w["body"], eventName, callback, evtNamespace) || result;
2233
2096
  }
2234
- return cookieValue;
2235
- }
2236
- function _setCookieValue(name, cookieValue) {
2237
- if (_doc) {
2238
- _doc[strCookie] = name + "=" + cookieValue;
2097
+ var doc = getDocument();
2098
+ if (doc) {
2099
+ result = eventOn(doc, eventName, callback, evtNamespace) || result;
2239
2100
  }
2101
+ return result;
2240
2102
  }
2241
- function uaDisallowsSameSiteNone(userAgent) {
2242
- if (!isString(userAgent)) {
2243
- return false;
2244
- }
2245
- if (strContains(userAgent, "CPU iPhone OS 12") || strContains(userAgent, "iPad; CPU OS 12")) {
2246
- return true;
2247
- }
2248
- if (strContains(userAgent, "Macintosh; Intel Mac OS X 10_14") && strContains(userAgent, "Version/") && strContains(userAgent, "Safari")) {
2249
- return true;
2250
- }
2251
- if (strContains(userAgent, "Macintosh; Intel Mac OS X 10_14") && strEndsWith(userAgent, "AppleWebKit/605.1.15 (KHTML, like Gecko)")) {
2252
- return true;
2253
- }
2254
- if (strContains(userAgent, "Chrome/5") || strContains(userAgent, "Chrome/6")) {
2255
- return true;
2256
- }
2257
- if (strContains(userAgent, "UnrealEngine") && !strContains(userAgent, "Chrome")) {
2258
- return true;
2103
+ function removeEventHandler(eventName, callback, evtNamespace) {
2104
+ var w = getWindow();
2105
+ if (w) {
2106
+ eventOff(w, eventName, callback, evtNamespace);
2107
+ eventOff(w["body"], eventName, callback, evtNamespace);
2259
2108
  }
2260
- if (strContains(userAgent, "UCBrowser/12") || strContains(userAgent, "UCBrowser/11")) {
2261
- return true;
2109
+ var doc = getDocument();
2110
+ if (doc) {
2111
+ eventOff(doc, eventName, callback, evtNamespace);
2262
2112
  }
2263
- return false;
2264
2113
  }
2265
-
2266
- var strIKey = "iKey";
2267
- var strExtensionConfig = "extensionConfig";
2268
-
2269
- var ChannelControllerPriority = 500;
2270
- var ChannelValidationMessage = "Channel has invalid priority - ";
2271
- function _addChannelQueue(channelQueue, queue, config, core) {
2272
- if (queue && isArray(queue) && queue.length > 0) {
2273
- queue = queue.sort(function (a, b) {
2274
- return a.priority - b.priority;
2275
- });
2276
- arrForEach(queue, function (queueItem) {
2277
- if (queueItem.priority < ChannelControllerPriority) {
2278
- throwError(ChannelValidationMessage + queueItem.identifier);
2114
+ function _addEventListeners(events, listener, excludeEvents, evtNamespace) {
2115
+ var added = false;
2116
+ if (listener && events && events.length > 0) {
2117
+ arrForEach(events, function (name) {
2118
+ if (name) {
2119
+ if (!excludeEvents || arrIndexOf(excludeEvents, name) === -1) {
2120
+ added = addEventHandler(name, listener, evtNamespace) || added;
2121
+ }
2279
2122
  }
2280
2123
  });
2281
- channelQueue.push({
2282
- queue: objFreeze(queue),
2283
- chain: createTelemetryProxyChain(queue, config, core)
2284
- });
2285
2124
  }
2125
+ return added;
2286
2126
  }
2287
- function createChannelControllerPlugin(channelQueue, core) {
2288
- var _a;
2289
- function _getTelCtx() {
2290
- return createProcessTelemetryContext(null, core.config, core, null);
2127
+ function addEventListeners(events, listener, excludeEvents, evtNamespace) {
2128
+ var added = false;
2129
+ if (listener && events && isArray(events)) {
2130
+ added = _addEventListeners(events, listener, excludeEvents, evtNamespace);
2131
+ if (!added && excludeEvents && excludeEvents.length > 0) {
2132
+ added = _addEventListeners(events, listener, null, evtNamespace);
2133
+ }
2291
2134
  }
2292
- function _processChannelQueue(theChannels, itemCtx, processFn, onComplete) {
2293
- var waiting = theChannels ? (theChannels.length + 1) : 1;
2294
- function _runChainOnComplete() {
2295
- waiting--;
2296
- if (waiting === 0) {
2297
- onComplete && onComplete();
2298
- onComplete = null;
2135
+ return added;
2136
+ }
2137
+ function removeEventListeners(events, listener, evtNamespace) {
2138
+ if (events && isArray(events)) {
2139
+ arrForEach(events, function (name) {
2140
+ if (name) {
2141
+ removeEventHandler(name, listener, evtNamespace);
2299
2142
  }
2300
- }
2301
- if (waiting > 0) {
2302
- arrForEach(theChannels, function (channels) {
2303
- if (channels && channels.queue.length > 0) {
2304
- var channelChain = channels.chain;
2305
- var chainCtx = itemCtx.createNew(channelChain);
2306
- chainCtx.onComplete(_runChainOnComplete);
2307
- processFn(chainCtx);
2308
- }
2309
- else {
2310
- waiting--;
2311
- }
2312
- });
2313
- }
2314
- _runChainOnComplete();
2315
- }
2316
- function _doUpdate(updateCtx, updateState) {
2317
- var theUpdateState = updateState || {
2318
- reason: 0
2319
- };
2320
- _processChannelQueue(channelQueue, updateCtx, function (chainCtx) {
2321
- chainCtx[strProcessNext](theUpdateState);
2322
- }, function () {
2323
- updateCtx[strProcessNext](theUpdateState);
2324
- });
2325
- return true;
2326
- }
2327
- function _doTeardown(unloadCtx, unloadState) {
2328
- var theUnloadState = unloadState || {
2329
- reason: 0 ,
2330
- isAsync: false
2331
- };
2332
- _processChannelQueue(channelQueue, unloadCtx, function (chainCtx) {
2333
- chainCtx[strProcessNext](theUnloadState);
2334
- }, function () {
2335
- unloadCtx[strProcessNext](theUnloadState);
2336
- isInitialized = false;
2337
2143
  });
2338
- return true;
2339
2144
  }
2340
- function _getChannel(pluginIdentifier) {
2341
- var thePlugin = null;
2342
- if (channelQueue && channelQueue.length > 0) {
2343
- arrForEach(channelQueue, function (channels) {
2344
- if (channels && channels.queue.length > 0) {
2345
- arrForEach(channels.queue, function (ext) {
2346
- if (ext.identifier === pluginIdentifier) {
2347
- thePlugin = ext;
2348
- return -1;
2349
- }
2350
- });
2351
- if (thePlugin) {
2352
- return -1;
2353
- }
2354
- }
2355
- });
2145
+ }
2146
+ function addPageUnloadEventListener(listener, excludeEvents, evtNamespace) {
2147
+ return addEventListeners([strBeforeUnload, strUnload, strPageHide], listener, excludeEvents, evtNamespace);
2148
+ }
2149
+ function removePageUnloadEventListener(listener, evtNamespace) {
2150
+ removeEventListeners([strBeforeUnload, strUnload, strPageHide], listener, evtNamespace);
2151
+ }
2152
+ function addPageHideEventListener(listener, excludeEvents, evtNamespace) {
2153
+ function _handlePageVisibility(evt) {
2154
+ var doc = getDocument();
2155
+ if (listener && doc && doc.visibilityState === "hidden") {
2156
+ listener(evt);
2356
2157
  }
2357
- return thePlugin;
2358
2158
  }
2359
- var isInitialized = false;
2360
- var channelController = (_a = {
2361
- identifier: "ChannelControllerPlugin",
2362
- priority: ChannelControllerPriority,
2363
- initialize: function (config, core, extensions, pluginChain) {
2364
- isInitialized = true;
2365
- arrForEach(channelQueue, function (channels) {
2366
- if (channels && channels.queue.length > 0) {
2367
- initializePlugins(createProcessTelemetryContext(channels.chain, config, core), extensions);
2368
- }
2369
- });
2370
- },
2371
- isInitialized: function () {
2372
- return isInitialized;
2373
- },
2374
- processTelemetry: function (item, itemCtx) {
2375
- _processChannelQueue(channelQueue, itemCtx || _getTelCtx(), function (chainCtx) {
2376
- chainCtx[strProcessNext](item);
2377
- }, function () {
2378
- itemCtx[strProcessNext](item);
2379
- });
2380
- },
2381
- update: _doUpdate
2382
- },
2383
- _a[strPause] = function () {
2384
- _processChannelQueue(channelQueue, _getTelCtx(), function (chainCtx) {
2385
- chainCtx.iterate(function (plugin) {
2386
- plugin[strPause] && plugin[strPause]();
2387
- });
2388
- }, null);
2389
- },
2390
- _a[strResume] = function () {
2391
- _processChannelQueue(channelQueue, _getTelCtx(), function (chainCtx) {
2392
- chainCtx.iterate(function (plugin) {
2393
- plugin[strResume] && plugin[strResume]();
2394
- });
2395
- }, null);
2396
- },
2397
- _a[strTeardown] = _doTeardown,
2398
- _a.getChannel = _getChannel,
2399
- _a.flush = function (isAsync, callBack, sendReason, cbTimeout) {
2400
- var waiting = 1;
2401
- var doneIterating = false;
2402
- var cbTimer = null;
2403
- cbTimeout = cbTimeout || 5000;
2404
- function doCallback() {
2405
- waiting--;
2406
- if (doneIterating && waiting === 0) {
2407
- if (cbTimer) {
2408
- clearTimeout(cbTimer);
2409
- cbTimer = null;
2410
- }
2411
- callBack && callBack(doneIterating);
2412
- callBack = null;
2413
- }
2414
- }
2415
- _processChannelQueue(channelQueue, _getTelCtx(), function (chainCtx) {
2416
- chainCtx.iterate(function (plugin) {
2417
- if (plugin.flush) {
2418
- waiting++;
2419
- var handled_1 = false;
2420
- if (!plugin.flush(isAsync, function () {
2421
- handled_1 = true;
2422
- doCallback();
2423
- }, sendReason)) {
2424
- if (!handled_1) {
2425
- if (isAsync && cbTimer == null) {
2426
- cbTimer = setTimeout(function () {
2427
- cbTimer = null;
2428
- doCallback();
2429
- }, cbTimeout);
2430
- }
2431
- else {
2432
- doCallback();
2433
- }
2434
- }
2435
- }
2436
- }
2437
- });
2438
- }, function () {
2439
- doneIterating = true;
2440
- doCallback();
2441
- });
2442
- return true;
2443
- },
2444
- _a._setQueue = function (queue) {
2445
- channelQueue = queue;
2446
- },
2447
- _a);
2448
- return channelController;
2449
- }
2450
- function createChannelQueues(channels, extensions, config, core) {
2451
- var channelQueue = [];
2452
- if (channels) {
2453
- arrForEach(channels, function (queue) { return _addChannelQueue(channelQueue, queue, config, core); });
2159
+ var newNamespaces = mergeEvtNamespace(strPageHideNamespace, evtNamespace);
2160
+ var pageUnloadAdded = _addEventListeners([strPageHide], listener, excludeEvents, newNamespaces);
2161
+ if (!excludeEvents || arrIndexOf(excludeEvents, strVisibilityChangeEvt) === -1) {
2162
+ pageUnloadAdded = _addEventListeners([strVisibilityChangeEvt], _handlePageVisibility, excludeEvents, newNamespaces) || pageUnloadAdded;
2454
2163
  }
2455
- if (extensions) {
2456
- var extensionQueue_1 = [];
2457
- arrForEach(extensions, function (plugin) {
2458
- if (plugin.priority > ChannelControllerPriority) {
2459
- extensionQueue_1.push(plugin);
2460
- }
2461
- });
2462
- _addChannelQueue(channelQueue, extensionQueue_1, config, core);
2164
+ if (!pageUnloadAdded && excludeEvents) {
2165
+ pageUnloadAdded = addPageHideEventListener(listener, null, evtNamespace);
2463
2166
  }
2464
- return channelQueue;
2167
+ return pageUnloadAdded;
2465
2168
  }
2466
-
2467
- function createUnloadHandlerContainer() {
2468
- var handlers = [];
2469
- function _addHandler(handler) {
2470
- if (handler) {
2471
- handlers.push(handler);
2169
+ function removePageHideEventListener(listener, evtNamespace) {
2170
+ var newNamespaces = mergeEvtNamespace(strPageHideNamespace, evtNamespace);
2171
+ removeEventListeners([strPageHide], listener, newNamespaces);
2172
+ removeEventListeners([strVisibilityChangeEvt], null, newNamespaces);
2173
+ }
2174
+ function addPageShowEventListener(listener, excludeEvents, evtNamespace) {
2175
+ function _handlePageVisibility(evt) {
2176
+ var doc = getDocument();
2177
+ if (listener && doc && doc.visibilityState === "visible") {
2178
+ listener(evt);
2472
2179
  }
2473
2180
  }
2474
- function _runHandlers(unloadCtx, unloadState) {
2475
- arrForEach(handlers, function (handler) {
2476
- try {
2477
- handler(unloadCtx, unloadState);
2478
- }
2479
- catch (e) {
2480
- _throwInternal(unloadCtx.diagLog(), 2 , 73 , "Unexpected error calling unload handler - " + dumpObj(e));
2481
- }
2482
- });
2483
- handlers = [];
2181
+ var newNamespaces = mergeEvtNamespace(strPageShowNamespace, evtNamespace);
2182
+ var pageShowAdded = _addEventListeners([strPageShow], listener, excludeEvents, newNamespaces);
2183
+ pageShowAdded = _addEventListeners([strVisibilityChangeEvt], _handlePageVisibility, excludeEvents, newNamespaces) || pageShowAdded;
2184
+ if (!pageShowAdded && excludeEvents) {
2185
+ pageShowAdded = addPageShowEventListener(listener, null, evtNamespace);
2484
2186
  }
2485
- return {
2486
- add: _addHandler,
2487
- run: _runHandlers
2488
- };
2187
+ return pageShowAdded;
2188
+ }
2189
+ function removePageShowEventListener(listener, evtNamespace) {
2190
+ var newNamespaces = mergeEvtNamespace(strPageShowNamespace, evtNamespace);
2191
+ removeEventListeners([strPageShow], listener, newNamespaces);
2192
+ removeEventListeners([strVisibilityChangeEvt], null, newNamespaces);
2489
2193
  }
2490
2194
 
2491
- var strGetPlugin = "getPlugin";
2492
- var BaseTelemetryPlugin = /** @class */ (function () {
2493
- function BaseTelemetryPlugin() {
2494
- var _self = this;
2495
- var _isinitialized;
2496
- var _rootCtx;
2497
- var _nextPlugin;
2498
- var _unloadHandlerContainer;
2499
- var _hooks;
2500
- _initDefaults();
2501
- dynamicProto(BaseTelemetryPlugin, _self, function (_self) {
2502
- _self.initialize = function (config, core, extensions, pluginChain) {
2503
- _setDefaults(config, core, pluginChain);
2504
- _isinitialized = true;
2505
- };
2506
- _self.teardown = function (unloadCtx, unloadState) {
2507
- var core = _self.core;
2508
- if (!core || (unloadCtx && core !== unloadCtx.core())) {
2509
- return;
2510
- }
2511
- var result;
2512
- var unloadDone = false;
2513
- var theUnloadCtx = unloadCtx || createProcessTelemetryUnloadContext(null, core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
2514
- var theUnloadState = unloadState || {
2195
+ function newGuid() {
2196
+ function randomHexDigit() {
2197
+ return randomValue(15);
2198
+ }
2199
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(GuidRegex, function (c) {
2200
+ var r = (randomHexDigit() | 0), v = (c === "x" ? r : r & 0x3 | 0x8);
2201
+ return v.toString(16);
2202
+ });
2203
+ }
2204
+ function perfNow() {
2205
+ var perf = getPerformance();
2206
+ if (perf && perf.now) {
2207
+ return perf.now();
2208
+ }
2209
+ return dateNow();
2210
+ }
2211
+ function generateW3CId() {
2212
+ var hexValues = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"];
2213
+ var oct = strEmpty, tmp;
2214
+ for (var a = 0; a < 4; a++) {
2215
+ tmp = random32();
2216
+ oct +=
2217
+ hexValues[tmp & 0xF] +
2218
+ hexValues[tmp >> 4 & 0xF] +
2219
+ hexValues[tmp >> 8 & 0xF] +
2220
+ hexValues[tmp >> 12 & 0xF] +
2221
+ hexValues[tmp >> 16 & 0xF] +
2222
+ hexValues[tmp >> 20 & 0xF] +
2223
+ hexValues[tmp >> 24 & 0xF] +
2224
+ hexValues[tmp >> 28 & 0xF];
2225
+ }
2226
+ var clockSequenceHi = hexValues[8 + (random32() & 0x03) | 0];
2227
+ return oct.substr(0, 8) + oct.substr(9, 4) + "4" + oct.substr(13, 3) + clockSequenceHi + oct.substr(16, 3) + oct.substr(19, 12);
2228
+ }
2229
+ var GuidRegex = /[xy]/g;
2230
+ var EventHelper = {
2231
+ Attach: attachEvent,
2232
+ AttachEvent: attachEvent,
2233
+ Detach: detachEvent,
2234
+ DetachEvent: detachEvent
2235
+ };
2236
+
2237
+ var TRACE_PARENT_REGEX = /^([\da-f]{2})-([\da-f]{32})-([\da-f]{16})-([\da-f]{2})(-[^\s]*)?$/;
2238
+ var DEFAULT_VERSION = "00";
2239
+ var INVALID_VERSION = "ff";
2240
+ var INVALID_TRACE_ID = "00000000000000000000000000000000";
2241
+ var INVALID_SPAN_ID = "0000000000000000";
2242
+ var SAMPLED_FLAG = 0x01;
2243
+ function _isValid(value, len, invalidValue) {
2244
+ if (value && value.length === len && value !== invalidValue) {
2245
+ return !!value.match(/^[\da-f]*$/);
2246
+ }
2247
+ return false;
2248
+ }
2249
+ function _formatValue(value, len, defValue) {
2250
+ if (_isValid(value, len)) {
2251
+ return value;
2252
+ }
2253
+ return defValue;
2254
+ }
2255
+ function _formatFlags(value) {
2256
+ if (isNaN(value) || value < 0 || value > 255) {
2257
+ value = 0x01;
2258
+ }
2259
+ var result = value.toString(16);
2260
+ while (result.length < 2) {
2261
+ result = "0" + result;
2262
+ }
2263
+ return result;
2264
+ }
2265
+ function createTraceParent(traceId, spanId, flags, version) {
2266
+ return {
2267
+ version: _isValid(version, 2, INVALID_VERSION) ? version : DEFAULT_VERSION,
2268
+ traceId: isValidTraceId(traceId) ? traceId : generateW3CId(),
2269
+ spanId: isValidSpanId(spanId) ? spanId : generateW3CId().substr(0, 16),
2270
+ traceFlags: flags >= 0 && flags <= 0xFF ? flags : 1
2271
+ };
2272
+ }
2273
+ function parseTraceParent(value) {
2274
+ if (!value) {
2275
+ return null;
2276
+ }
2277
+ if (isArray(value)) {
2278
+ value = value[0] || "";
2279
+ }
2280
+ if (!value || !isString(value) || value.length > 8192) {
2281
+ return null;
2282
+ }
2283
+ var match = TRACE_PARENT_REGEX.exec(strTrim(value));
2284
+ if (!match ||
2285
+ match[1] === INVALID_VERSION ||
2286
+ match[2] === INVALID_TRACE_ID ||
2287
+ match[3] === INVALID_SPAN_ID) {
2288
+ return null;
2289
+ }
2290
+ return {
2291
+ version: match[1],
2292
+ traceId: match[2],
2293
+ spanId: match[3],
2294
+ traceFlags: parseInt(match[4], 16)
2295
+ };
2296
+ }
2297
+ function isValidTraceId(value) {
2298
+ return _isValid(value, 32, INVALID_TRACE_ID);
2299
+ }
2300
+ function isValidSpanId(value) {
2301
+ return _isValid(value, 16, INVALID_SPAN_ID);
2302
+ }
2303
+ function isValidTraceParent(value) {
2304
+ if (!value ||
2305
+ !_isValid(value.version, 2, INVALID_VERSION) ||
2306
+ !_isValid(value.traceId, 32, INVALID_TRACE_ID) ||
2307
+ !_isValid(value.spanId, 16, INVALID_SPAN_ID) ||
2308
+ !_isValid(_formatFlags(value.traceFlags), 2)) {
2309
+ return false;
2310
+ }
2311
+ return true;
2312
+ }
2313
+ function isSampledFlag(value) {
2314
+ if (isValidTraceParent(value)) {
2315
+ return (value.traceFlags & SAMPLED_FLAG) === SAMPLED_FLAG;
2316
+ }
2317
+ return false;
2318
+ }
2319
+ function formatTraceParent(value) {
2320
+ if (value) {
2321
+ var flags = _formatFlags(value.traceFlags);
2322
+ if (!_isValid(flags, 2)) {
2323
+ flags = "01";
2324
+ }
2325
+ var version = value.version || DEFAULT_VERSION;
2326
+ if (version !== "00" && version !== "ff") {
2327
+ version = DEFAULT_VERSION;
2328
+ }
2329
+ return "".concat(version, "-").concat(_formatValue(value.traceId, 32, INVALID_TRACE_ID), "-").concat(_formatValue(value.spanId, 16, INVALID_SPAN_ID), "-").concat(flags);
2330
+ }
2331
+ return "";
2332
+ }
2333
+ function findW3cTraceParent() {
2334
+ var name = "traceparent";
2335
+ var traceParent = parseTraceParent(findMetaTag(name));
2336
+ if (!traceParent) {
2337
+ traceParent = parseTraceParent(findNamedServerTiming(name));
2338
+ }
2339
+ return traceParent;
2340
+ }
2341
+
2342
+ var pluginStateData = createElmNodeData("plugin");
2343
+ function _getPluginState(plugin) {
2344
+ return pluginStateData.get(plugin, "state", {}, true);
2345
+ }
2346
+ function initializePlugins(processContext, extensions) {
2347
+ var initPlugins = [];
2348
+ var lastPlugin = null;
2349
+ var proxy = processContext.getNext();
2350
+ var pluginState;
2351
+ while (proxy) {
2352
+ var thePlugin = proxy.getPlugin();
2353
+ if (thePlugin) {
2354
+ if (lastPlugin &&
2355
+ isFunction(lastPlugin[strSetNextPlugin]) &&
2356
+ isFunction(thePlugin[strProcessTelemetry])) {
2357
+ lastPlugin[strSetNextPlugin](thePlugin);
2358
+ }
2359
+ var isInitialized = false;
2360
+ if (isFunction(thePlugin[strIsInitialized])) {
2361
+ isInitialized = thePlugin[strIsInitialized]();
2362
+ }
2363
+ else {
2364
+ pluginState = _getPluginState(thePlugin);
2365
+ isInitialized = pluginState[strIsInitialized];
2366
+ }
2367
+ if (!isInitialized) {
2368
+ initPlugins.push(thePlugin);
2369
+ }
2370
+ lastPlugin = thePlugin;
2371
+ proxy = proxy.getNext();
2372
+ }
2373
+ }
2374
+ arrForEach(initPlugins, function (thePlugin) {
2375
+ var core = processContext.core();
2376
+ thePlugin.initialize(processContext.getCfg(), core, extensions, processContext.getNext());
2377
+ pluginState = _getPluginState(thePlugin);
2378
+ if (!thePlugin[strCore] && !pluginState[strCore]) {
2379
+ pluginState[strCore] = core;
2380
+ }
2381
+ pluginState[strIsInitialized] = true;
2382
+ delete pluginState[strTeardown];
2383
+ });
2384
+ }
2385
+ function sortPlugins(plugins) {
2386
+ return plugins.sort(function (extA, extB) {
2387
+ var result = 0;
2388
+ if (extB) {
2389
+ var bHasProcess = isFunction(extB[strProcessTelemetry]);
2390
+ if (isFunction(extA[strProcessTelemetry])) {
2391
+ result = bHasProcess ? extA[strPriority] - extB[strPriority] : 1;
2392
+ }
2393
+ else if (bHasProcess) {
2394
+ result = -1;
2395
+ }
2396
+ }
2397
+ else {
2398
+ result = extA ? 1 : -1;
2399
+ }
2400
+ return result;
2401
+ });
2402
+ }
2403
+ function createDistributedTraceContext(parentCtx) {
2404
+ var trace = {};
2405
+ return {
2406
+ getName: function () {
2407
+ return trace.name;
2408
+ },
2409
+ setName: function (newValue) {
2410
+ parentCtx && parentCtx.setName(newValue);
2411
+ trace.name = newValue;
2412
+ },
2413
+ getTraceId: function () {
2414
+ return trace.traceId;
2415
+ },
2416
+ setTraceId: function (newValue) {
2417
+ parentCtx && parentCtx.setTraceId(newValue);
2418
+ if (isValidTraceId(newValue)) {
2419
+ trace.traceId = newValue;
2420
+ }
2421
+ },
2422
+ getSpanId: function () {
2423
+ return trace.spanId;
2424
+ },
2425
+ setSpanId: function (newValue) {
2426
+ parentCtx && parentCtx.setSpanId(newValue);
2427
+ if (isValidSpanId(newValue)) {
2428
+ trace.spanId = newValue;
2429
+ }
2430
+ },
2431
+ getTraceFlags: function () {
2432
+ return trace.traceFlags;
2433
+ },
2434
+ setTraceFlags: function (newTraceFlags) {
2435
+ parentCtx && parentCtx.setTraceFlags(newTraceFlags);
2436
+ trace.traceFlags = newTraceFlags;
2437
+ }
2438
+ };
2439
+ }
2440
+
2441
+ var strTelemetryPluginChain = "TelemetryPluginChain";
2442
+ var strHasRunFlags = "_hasRun";
2443
+ var strGetTelCtx = "_getTelCtx";
2444
+ var _chainId = 0;
2445
+ function _getNextProxyStart(proxy, core, startAt) {
2446
+ while (proxy) {
2447
+ if (proxy.getPlugin() === startAt) {
2448
+ return proxy;
2449
+ }
2450
+ proxy = proxy.getNext();
2451
+ }
2452
+ return createTelemetryProxyChain([startAt], core.config || {}, core);
2453
+ }
2454
+ function _createInternalContext(telemetryChain, config, core, startAt) {
2455
+ var _nextProxy = null;
2456
+ var _onComplete = [];
2457
+ if (startAt !== null) {
2458
+ _nextProxy = startAt ? _getNextProxyStart(telemetryChain, core, startAt) : telemetryChain;
2459
+ }
2460
+ var context = {
2461
+ _next: _moveNext,
2462
+ ctx: {
2463
+ core: function () {
2464
+ return core;
2465
+ },
2466
+ diagLog: function () {
2467
+ return safeGetLogger(core, config);
2468
+ },
2469
+ getCfg: function () {
2470
+ return config;
2471
+ },
2472
+ getExtCfg: _getExtCfg,
2473
+ getConfig: _getConfig,
2474
+ hasNext: function () {
2475
+ return !!_nextProxy;
2476
+ },
2477
+ getNext: function () {
2478
+ return _nextProxy;
2479
+ },
2480
+ setNext: function (nextPlugin) {
2481
+ _nextProxy = nextPlugin;
2482
+ },
2483
+ iterate: _iterateChain,
2484
+ onComplete: _addOnComplete
2485
+ }
2486
+ };
2487
+ function _addOnComplete(onComplete, that) {
2488
+ var args = [];
2489
+ for (var _i = 2; _i < arguments.length; _i++) {
2490
+ args[_i - 2] = arguments[_i];
2491
+ }
2492
+ if (onComplete) {
2493
+ _onComplete.push({
2494
+ func: onComplete,
2495
+ self: !isUndefined(that) ? that : context.ctx,
2496
+ args: args
2497
+ });
2498
+ }
2499
+ }
2500
+ function _moveNext() {
2501
+ var nextProxy = _nextProxy;
2502
+ _nextProxy = nextProxy ? nextProxy.getNext() : null;
2503
+ if (!nextProxy) {
2504
+ var onComplete = _onComplete;
2505
+ if (onComplete && onComplete.length > 0) {
2506
+ arrForEach(onComplete, function (completeDetails) {
2507
+ try {
2508
+ completeDetails.func.call(completeDetails.self, completeDetails.args);
2509
+ }
2510
+ catch (e) {
2511
+ _throwInternal(core.logger, 2 , 73 , "Unexpected Exception during onComplete - " + dumpObj(e));
2512
+ }
2513
+ });
2514
+ _onComplete = [];
2515
+ }
2516
+ }
2517
+ return nextProxy;
2518
+ }
2519
+ function _getExtCfg(identifier, defaultValue, mergeDefault) {
2520
+ if (defaultValue === void 0) { defaultValue = {}; }
2521
+ if (mergeDefault === void 0) { mergeDefault = 0 ; }
2522
+ var theConfig;
2523
+ if (config) {
2524
+ var extConfig = config.extensionConfig;
2525
+ if (extConfig && identifier) {
2526
+ theConfig = extConfig[identifier];
2527
+ }
2528
+ }
2529
+ if (!theConfig) {
2530
+ theConfig = defaultValue;
2531
+ }
2532
+ else if (isObject(defaultValue)) {
2533
+ if (mergeDefault !== 0 ) {
2534
+ var newConfig_1 = objExtend(true, defaultValue, theConfig);
2535
+ if (config && mergeDefault === 2 ) {
2536
+ objForEachKey(defaultValue, function (field) {
2537
+ if (isNullOrUndefined(newConfig_1[field])) {
2538
+ var cfgValue = config[field];
2539
+ if (!isNullOrUndefined(cfgValue)) {
2540
+ newConfig_1[field] = cfgValue;
2541
+ }
2542
+ }
2543
+ });
2544
+ }
2545
+ theConfig = newConfig_1;
2546
+ }
2547
+ }
2548
+ return theConfig;
2549
+ }
2550
+ function _getConfig(identifier, field, defaultValue) {
2551
+ if (defaultValue === void 0) { defaultValue = false; }
2552
+ var theValue;
2553
+ var extConfig = _getExtCfg(identifier, null);
2554
+ if (extConfig && !isNullOrUndefined(extConfig[field])) {
2555
+ theValue = extConfig[field];
2556
+ }
2557
+ else if (config && !isNullOrUndefined(config[field])) {
2558
+ theValue = config[field];
2559
+ }
2560
+ return !isNullOrUndefined(theValue) ? theValue : defaultValue;
2561
+ }
2562
+ function _iterateChain(cb) {
2563
+ var nextPlugin;
2564
+ while (!!(nextPlugin = context._next())) {
2565
+ var plugin = nextPlugin.getPlugin();
2566
+ if (plugin) {
2567
+ cb(plugin);
2568
+ }
2569
+ }
2570
+ }
2571
+ return context;
2572
+ }
2573
+ function createProcessTelemetryContext(telemetryChain, config, core, startAt) {
2574
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
2575
+ var context = internalContext.ctx;
2576
+ function _processNext(env) {
2577
+ var nextPlugin = internalContext._next();
2578
+ nextPlugin && nextPlugin.processTelemetry(env, context);
2579
+ return !nextPlugin;
2580
+ }
2581
+ function _createNew(plugins, startAt) {
2582
+ if (plugins === void 0) { plugins = null; }
2583
+ if (isArray(plugins)) {
2584
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
2585
+ }
2586
+ return createProcessTelemetryContext(plugins || context.getNext(), config, core, startAt);
2587
+ }
2588
+ context.processNext = _processNext;
2589
+ context.createNew = _createNew;
2590
+ return context;
2591
+ }
2592
+ function createProcessTelemetryUnloadContext(telemetryChain, core, startAt) {
2593
+ var config = core.config || {};
2594
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
2595
+ var context = internalContext.ctx;
2596
+ function _processNext(unloadState) {
2597
+ var nextPlugin = internalContext._next();
2598
+ nextPlugin && nextPlugin.unload(context, unloadState);
2599
+ return !nextPlugin;
2600
+ }
2601
+ function _createNew(plugins, startAt) {
2602
+ if (plugins === void 0) { plugins = null; }
2603
+ if (isArray(plugins)) {
2604
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
2605
+ }
2606
+ return createProcessTelemetryUnloadContext(plugins || context.getNext(), core, startAt);
2607
+ }
2608
+ context.processNext = _processNext;
2609
+ context.createNew = _createNew;
2610
+ return context;
2611
+ }
2612
+ function createProcessTelemetryUpdateContext(telemetryChain, core, startAt) {
2613
+ var config = core.config || {};
2614
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
2615
+ var context = internalContext.ctx;
2616
+ function _processNext(updateState) {
2617
+ return context.iterate(function (plugin) {
2618
+ if (isFunction(plugin.update)) {
2619
+ plugin.update(context, updateState);
2620
+ }
2621
+ });
2622
+ }
2623
+ function _createNew(plugins, startAt) {
2624
+ if (plugins === void 0) { plugins = null; }
2625
+ if (isArray(plugins)) {
2626
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
2627
+ }
2628
+ return createProcessTelemetryUpdateContext(plugins || context.getNext(), core, startAt);
2629
+ }
2630
+ context.processNext = _processNext;
2631
+ context.createNew = _createNew;
2632
+ return context;
2633
+ }
2634
+ function createTelemetryProxyChain(plugins, config, core, startAt) {
2635
+ var firstProxy = null;
2636
+ var add = startAt ? false : true;
2637
+ if (isArray(plugins) && plugins.length > 0) {
2638
+ var lastProxy_1 = null;
2639
+ arrForEach(plugins, function (thePlugin) {
2640
+ if (!add && startAt === thePlugin) {
2641
+ add = true;
2642
+ }
2643
+ if (add && thePlugin && isFunction(thePlugin.processTelemetry)) {
2644
+ var newProxy = createTelemetryPluginProxy(thePlugin, config, core);
2645
+ if (!firstProxy) {
2646
+ firstProxy = newProxy;
2647
+ }
2648
+ if (lastProxy_1) {
2649
+ lastProxy_1._setNext(newProxy);
2650
+ }
2651
+ lastProxy_1 = newProxy;
2652
+ }
2653
+ });
2654
+ }
2655
+ if (startAt && !firstProxy) {
2656
+ return createTelemetryProxyChain([startAt], config, core);
2657
+ }
2658
+ return firstProxy;
2659
+ }
2660
+ function createTelemetryPluginProxy(plugin, config, core) {
2661
+ var nextProxy = null;
2662
+ var hasProcessTelemetry = isFunction(plugin.processTelemetry);
2663
+ var hasSetNext = isFunction(plugin.setNextPlugin);
2664
+ var chainId;
2665
+ if (plugin) {
2666
+ chainId = plugin.identifier + "-" + plugin.priority + "-" + _chainId++;
2667
+ }
2668
+ else {
2669
+ chainId = "Unknown-0-" + _chainId++;
2670
+ }
2671
+ var proxyChain = {
2672
+ getPlugin: function () {
2673
+ return plugin;
2674
+ },
2675
+ getNext: function () {
2676
+ return nextProxy;
2677
+ },
2678
+ processTelemetry: _processTelemetry,
2679
+ unload: _unloadPlugin,
2680
+ update: _updatePlugin,
2681
+ _id: chainId,
2682
+ _setNext: function (nextPlugin) {
2683
+ nextProxy = nextPlugin;
2684
+ }
2685
+ };
2686
+ function _getTelCtx() {
2687
+ var itemCtx;
2688
+ if (plugin && isFunction(plugin[strGetTelCtx])) {
2689
+ itemCtx = plugin[strGetTelCtx]();
2690
+ }
2691
+ if (!itemCtx) {
2692
+ itemCtx = createProcessTelemetryContext(proxyChain, config, core);
2693
+ }
2694
+ return itemCtx;
2695
+ }
2696
+ function _processChain(itemCtx, processPluginFn, name, details, isAsync) {
2697
+ var hasRun = false;
2698
+ var identifier = plugin ? plugin.identifier : strTelemetryPluginChain;
2699
+ var hasRunContext = itemCtx[strHasRunFlags];
2700
+ if (!hasRunContext) {
2701
+ hasRunContext = itemCtx[strHasRunFlags] = {};
2702
+ }
2703
+ itemCtx.setNext(nextProxy);
2704
+ if (plugin) {
2705
+ doPerf(itemCtx[strCore](), function () { return identifier + ":" + name; }, function () {
2706
+ hasRunContext[chainId] = true;
2707
+ try {
2708
+ var nextId = nextProxy ? nextProxy._id : strEmpty;
2709
+ if (nextId) {
2710
+ hasRunContext[nextId] = false;
2711
+ }
2712
+ hasRun = processPluginFn(itemCtx);
2713
+ }
2714
+ catch (error) {
2715
+ var hasNextRun = nextProxy ? hasRunContext[nextProxy._id] : true;
2716
+ if (hasNextRun) {
2717
+ hasRun = true;
2718
+ }
2719
+ if (!nextProxy || !hasNextRun) {
2720
+ _throwInternal(itemCtx.diagLog(), 1 , 73 , "Plugin [" + identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
2721
+ }
2722
+ }
2723
+ }, details, isAsync);
2724
+ }
2725
+ return hasRun;
2726
+ }
2727
+ function _processTelemetry(env, itemCtx) {
2728
+ itemCtx = itemCtx || _getTelCtx();
2729
+ function _callProcessTelemetry(itemCtx) {
2730
+ if (!plugin || !hasProcessTelemetry) {
2731
+ return false;
2732
+ }
2733
+ var pluginState = _getPluginState(plugin);
2734
+ if (pluginState.teardown || pluginState[strDisabled]) {
2735
+ return false;
2736
+ }
2737
+ if (hasSetNext) {
2738
+ plugin.setNextPlugin(nextProxy);
2739
+ }
2740
+ plugin.processTelemetry(env, itemCtx);
2741
+ return true;
2742
+ }
2743
+ if (!_processChain(itemCtx, _callProcessTelemetry, "processTelemetry", function () { return ({ item: env }); }, !(env.sync))) {
2744
+ itemCtx.processNext(env);
2745
+ }
2746
+ }
2747
+ function _unloadPlugin(unloadCtx, unloadState) {
2748
+ function _callTeardown() {
2749
+ var hasRun = false;
2750
+ if (plugin) {
2751
+ var pluginState = _getPluginState(plugin);
2752
+ var pluginCore = plugin[strCore] || pluginState.core;
2753
+ if (plugin && (!pluginCore || pluginCore === unloadCtx[strCore]()) && !pluginState[strTeardown]) {
2754
+ pluginState[strCore] = null;
2755
+ pluginState[strTeardown] = true;
2756
+ pluginState[strIsInitialized] = false;
2757
+ if (plugin[strTeardown] && plugin[strTeardown](unloadCtx, unloadState) === true) {
2758
+ hasRun = true;
2759
+ }
2760
+ }
2761
+ }
2762
+ return hasRun;
2763
+ }
2764
+ if (!_processChain(unloadCtx, _callTeardown, "unload", function () { }, unloadState.isAsync)) {
2765
+ unloadCtx.processNext(unloadState);
2766
+ }
2767
+ }
2768
+ function _updatePlugin(updateCtx, updateState) {
2769
+ function _callUpdate() {
2770
+ var hasRun = false;
2771
+ if (plugin) {
2772
+ var pluginState = _getPluginState(plugin);
2773
+ var pluginCore = plugin[strCore] || pluginState.core;
2774
+ if (plugin && (!pluginCore || pluginCore === updateCtx[strCore]()) && !pluginState[strTeardown]) {
2775
+ if (plugin[strUpdate] && plugin[strUpdate](updateCtx, updateState) === true) {
2776
+ hasRun = true;
2777
+ }
2778
+ }
2779
+ }
2780
+ return hasRun;
2781
+ }
2782
+ if (!_processChain(updateCtx, _callUpdate, "update", function () { }, false)) {
2783
+ updateCtx.processNext(updateState);
2784
+ }
2785
+ }
2786
+ return objFreeze(proxyChain);
2787
+ }
2788
+ var ProcessTelemetryContext = /** @class */ (function () {
2789
+ function ProcessTelemetryContext(pluginChain, config, core, startAt) {
2790
+ var _self = this;
2791
+ var context = createProcessTelemetryContext(pluginChain, config, core, startAt);
2792
+ proxyFunctions(_self, context, objKeys(context));
2793
+ }
2794
+ return ProcessTelemetryContext;
2795
+ }());
2796
+
2797
+ var strIKey = "iKey";
2798
+ var strExtensionConfig = "extensionConfig";
2799
+
2800
+ var ChannelControllerPriority = 500;
2801
+ var ChannelValidationMessage = "Channel has invalid priority - ";
2802
+ function _addChannelQueue(channelQueue, queue, config, core) {
2803
+ if (queue && isArray(queue) && queue.length > 0) {
2804
+ queue = queue.sort(function (a, b) {
2805
+ return a.priority - b.priority;
2806
+ });
2807
+ arrForEach(queue, function (queueItem) {
2808
+ if (queueItem.priority < ChannelControllerPriority) {
2809
+ throwError(ChannelValidationMessage + queueItem.identifier);
2810
+ }
2811
+ });
2812
+ channelQueue.push({
2813
+ queue: objFreeze(queue),
2814
+ chain: createTelemetryProxyChain(queue, config, core)
2815
+ });
2816
+ }
2817
+ }
2818
+ function createChannelControllerPlugin(channelQueue, core) {
2819
+ var _a;
2820
+ function _getTelCtx() {
2821
+ return createProcessTelemetryContext(null, core.config, core, null);
2822
+ }
2823
+ function _processChannelQueue(theChannels, itemCtx, processFn, onComplete) {
2824
+ var waiting = theChannels ? (theChannels.length + 1) : 1;
2825
+ function _runChainOnComplete() {
2826
+ waiting--;
2827
+ if (waiting === 0) {
2828
+ onComplete && onComplete();
2829
+ onComplete = null;
2830
+ }
2831
+ }
2832
+ if (waiting > 0) {
2833
+ arrForEach(theChannels, function (channels) {
2834
+ if (channels && channels.queue.length > 0) {
2835
+ var channelChain = channels.chain;
2836
+ var chainCtx = itemCtx.createNew(channelChain);
2837
+ chainCtx.onComplete(_runChainOnComplete);
2838
+ processFn(chainCtx);
2839
+ }
2840
+ else {
2841
+ waiting--;
2842
+ }
2843
+ });
2844
+ }
2845
+ _runChainOnComplete();
2846
+ }
2847
+ function _doUpdate(updateCtx, updateState) {
2848
+ var theUpdateState = updateState || {
2849
+ reason: 0
2850
+ };
2851
+ _processChannelQueue(channelQueue, updateCtx, function (chainCtx) {
2852
+ chainCtx[strProcessNext](theUpdateState);
2853
+ }, function () {
2854
+ updateCtx[strProcessNext](theUpdateState);
2855
+ });
2856
+ return true;
2857
+ }
2858
+ function _doTeardown(unloadCtx, unloadState) {
2859
+ var theUnloadState = unloadState || {
2860
+ reason: 0 ,
2861
+ isAsync: false
2862
+ };
2863
+ _processChannelQueue(channelQueue, unloadCtx, function (chainCtx) {
2864
+ chainCtx[strProcessNext](theUnloadState);
2865
+ }, function () {
2866
+ unloadCtx[strProcessNext](theUnloadState);
2867
+ isInitialized = false;
2868
+ });
2869
+ return true;
2870
+ }
2871
+ function _getChannel(pluginIdentifier) {
2872
+ var thePlugin = null;
2873
+ if (channelQueue && channelQueue.length > 0) {
2874
+ arrForEach(channelQueue, function (channels) {
2875
+ if (channels && channels.queue.length > 0) {
2876
+ arrForEach(channels.queue, function (ext) {
2877
+ if (ext.identifier === pluginIdentifier) {
2878
+ thePlugin = ext;
2879
+ return -1;
2880
+ }
2881
+ });
2882
+ if (thePlugin) {
2883
+ return -1;
2884
+ }
2885
+ }
2886
+ });
2887
+ }
2888
+ return thePlugin;
2889
+ }
2890
+ var isInitialized = false;
2891
+ var channelController = (_a = {
2892
+ identifier: "ChannelControllerPlugin",
2893
+ priority: ChannelControllerPriority,
2894
+ initialize: function (config, core, extensions, pluginChain) {
2895
+ isInitialized = true;
2896
+ arrForEach(channelQueue, function (channels) {
2897
+ if (channels && channels.queue.length > 0) {
2898
+ initializePlugins(createProcessTelemetryContext(channels.chain, config, core), extensions);
2899
+ }
2900
+ });
2901
+ },
2902
+ isInitialized: function () {
2903
+ return isInitialized;
2904
+ },
2905
+ processTelemetry: function (item, itemCtx) {
2906
+ _processChannelQueue(channelQueue, itemCtx || _getTelCtx(), function (chainCtx) {
2907
+ chainCtx[strProcessNext](item);
2908
+ }, function () {
2909
+ itemCtx[strProcessNext](item);
2910
+ });
2911
+ },
2912
+ update: _doUpdate
2913
+ },
2914
+ _a[strPause] = function () {
2915
+ _processChannelQueue(channelQueue, _getTelCtx(), function (chainCtx) {
2916
+ chainCtx.iterate(function (plugin) {
2917
+ plugin[strPause] && plugin[strPause]();
2918
+ });
2919
+ }, null);
2920
+ },
2921
+ _a[strResume] = function () {
2922
+ _processChannelQueue(channelQueue, _getTelCtx(), function (chainCtx) {
2923
+ chainCtx.iterate(function (plugin) {
2924
+ plugin[strResume] && plugin[strResume]();
2925
+ });
2926
+ }, null);
2927
+ },
2928
+ _a[strTeardown] = _doTeardown,
2929
+ _a.getChannel = _getChannel,
2930
+ _a.flush = function (isAsync, callBack, sendReason, cbTimeout) {
2931
+ var waiting = 1;
2932
+ var doneIterating = false;
2933
+ var cbTimer = null;
2934
+ cbTimeout = cbTimeout || 5000;
2935
+ function doCallback() {
2936
+ waiting--;
2937
+ if (doneIterating && waiting === 0) {
2938
+ if (cbTimer) {
2939
+ clearTimeout(cbTimer);
2940
+ cbTimer = null;
2941
+ }
2942
+ callBack && callBack(doneIterating);
2943
+ callBack = null;
2944
+ }
2945
+ }
2946
+ _processChannelQueue(channelQueue, _getTelCtx(), function (chainCtx) {
2947
+ chainCtx.iterate(function (plugin) {
2948
+ if (plugin.flush) {
2949
+ waiting++;
2950
+ var handled_1 = false;
2951
+ if (!plugin.flush(isAsync, function () {
2952
+ handled_1 = true;
2953
+ doCallback();
2954
+ }, sendReason)) {
2955
+ if (!handled_1) {
2956
+ if (isAsync && cbTimer == null) {
2957
+ cbTimer = setTimeout(function () {
2958
+ cbTimer = null;
2959
+ doCallback();
2960
+ }, cbTimeout);
2961
+ }
2962
+ else {
2963
+ doCallback();
2964
+ }
2965
+ }
2966
+ }
2967
+ }
2968
+ });
2969
+ }, function () {
2970
+ doneIterating = true;
2971
+ doCallback();
2972
+ });
2973
+ return true;
2974
+ },
2975
+ _a._setQueue = function (queue) {
2976
+ channelQueue = queue;
2977
+ },
2978
+ _a);
2979
+ return channelController;
2980
+ }
2981
+ function createChannelQueues(channels, extensions, config, core) {
2982
+ var channelQueue = [];
2983
+ if (channels) {
2984
+ arrForEach(channels, function (queue) { return _addChannelQueue(channelQueue, queue, config, core); });
2985
+ }
2986
+ if (extensions) {
2987
+ var extensionQueue_1 = [];
2988
+ arrForEach(extensions, function (plugin) {
2989
+ if (plugin.priority > ChannelControllerPriority) {
2990
+ extensionQueue_1.push(plugin);
2991
+ }
2992
+ });
2993
+ _addChannelQueue(channelQueue, extensionQueue_1, config, core);
2994
+ }
2995
+ return channelQueue;
2996
+ }
2997
+
2998
+ function createUnloadHandlerContainer() {
2999
+ var handlers = [];
3000
+ function _addHandler(handler) {
3001
+ if (handler) {
3002
+ handlers.push(handler);
3003
+ }
3004
+ }
3005
+ function _runHandlers(unloadCtx, unloadState) {
3006
+ arrForEach(handlers, function (handler) {
3007
+ try {
3008
+ handler(unloadCtx, unloadState);
3009
+ }
3010
+ catch (e) {
3011
+ _throwInternal(unloadCtx.diagLog(), 2 , 73 , "Unexpected error calling unload handler - " + dumpObj(e));
3012
+ }
3013
+ });
3014
+ handlers = [];
3015
+ }
3016
+ return {
3017
+ add: _addHandler,
3018
+ run: _runHandlers
3019
+ };
3020
+ }
3021
+
3022
+ var strGetPlugin = "getPlugin";
3023
+ var BaseTelemetryPlugin = /** @class */ (function () {
3024
+ function BaseTelemetryPlugin() {
3025
+ var _self = this;
3026
+ var _isinitialized;
3027
+ var _rootCtx;
3028
+ var _nextPlugin;
3029
+ var _unloadHandlerContainer;
3030
+ var _hooks;
3031
+ _initDefaults();
3032
+ dynamicProto(BaseTelemetryPlugin, _self, function (_self) {
3033
+ _self.initialize = function (config, core, extensions, pluginChain) {
3034
+ _setDefaults(config, core, pluginChain);
3035
+ _isinitialized = true;
3036
+ };
3037
+ _self.teardown = function (unloadCtx, unloadState) {
3038
+ var core = _self.core;
3039
+ if (!core || (unloadCtx && core !== unloadCtx.core())) {
3040
+ return;
3041
+ }
3042
+ var result;
3043
+ var unloadDone = false;
3044
+ var theUnloadCtx = unloadCtx || createProcessTelemetryUnloadContext(null, core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
3045
+ var theUnloadState = unloadState || {
2515
3046
  reason: 0 ,
2516
3047
  isAsync: false
2517
3048
  };
@@ -2773,6 +3304,7 @@
2773
3304
  var _evtNamespace;
2774
3305
  var _unloadHandlers;
2775
3306
  var _debugListener;
3307
+ var _traceCtx;
2776
3308
  var _internalLogPoller = 0;
2777
3309
  dynamicProto(BaseCore, this, function (_self) {
2778
3310
  _initDefaults();
@@ -2975,6 +3507,15 @@
2975
3507
  return _evtNamespace;
2976
3508
  };
2977
3509
  _self.flush = _flushChannels;
3510
+ _self.getTraceCtx = function (createNew) {
3511
+ if (!_traceCtx) {
3512
+ _traceCtx = createDistributedTraceContext();
3513
+ }
3514
+ return _traceCtx;
3515
+ };
3516
+ _self.setTraceCtx = function (traceCtx) {
3517
+ _traceCtx = traceCtx || null;
3518
+ };
2978
3519
  proxyFunctionAs(_self, "addUnloadCb", function () { return _unloadHandlers; }, "add");
2979
3520
  function _initDefaults() {
2980
3521
  _isInitialized = false;
@@ -2997,6 +3538,7 @@
2997
3538
  _internalLogsEventName = null;
2998
3539
  _evtNamespace = createUniqueNamespace("AIBaseCore", true);
2999
3540
  _unloadHandlers = createUnloadHandlerContainer();
3541
+ _traceCtx = null;
3000
3542
  }
3001
3543
  function _createTelCtx() {
3002
3544
  return createProcessTelemetryContext(_getPluginChain(), _self.config, _self);
@@ -3008,11 +3550,11 @@
3008
3550
  var allExtensions = theExtensions.all;
3009
3551
  _channelQueue = objFreeze(createChannelQueues(_channelConfig, allExtensions, config, _self));
3010
3552
  if (_channelControl) {
3011
- var idx = allExtensions.indexOf(_channelControl);
3553
+ var idx = arrIndexOf(allExtensions, _channelControl);
3012
3554
  if (idx !== -1) {
3013
3555
  allExtensions.splice(idx, 1);
3014
3556
  }
3015
- idx = _coreExtensions.indexOf(_channelControl);
3557
+ idx = arrIndexOf(_coreExtensions, _channelControl);
3016
3558
  if (idx !== -1) {
3017
3559
  _coreExtensions.splice(idx, 1);
3018
3560
  }
@@ -3077,7 +3619,7 @@
3077
3619
  function _getPluginChain() {
3078
3620
  if (!_pluginChain) {
3079
3621
  var extensions = (_coreExtensions || []).slice();
3080
- if (extensions.indexOf(_telemetryInitializerPlugin) === -1) {
3622
+ if (arrIndexOf(extensions, _telemetryInitializerPlugin) === -1) {
3081
3623
  extensions.push(_telemetryInitializerPlugin);
3082
3624
  }
3083
3625
  _pluginChain = createTelemetryProxyChain(sortPlugins(extensions), _self.config, _self);
@@ -3094,549 +3636,201 @@
3094
3636
  arrForEach(_configExtensions, function (plugin, idx) {
3095
3637
  if (!_isPluginPresent(plugin, thePlugins)) {
3096
3638
  newConfigExtensions.push(plugin);
3097
- }
3098
- else {
3099
- removed = true;
3100
- }
3101
- });
3102
- _configExtensions = newConfigExtensions;
3103
- var newChannelConfig = [];
3104
- if (_channelConfig) {
3105
- arrForEach(_channelConfig, function (queue, idx) {
3106
- var newQueue = [];
3107
- arrForEach(queue, function (channel) {
3108
- if (!_isPluginPresent(channel, thePlugins)) {
3109
- newQueue.push(channel);
3110
- }
3111
- else {
3112
- removed = true;
3113
- }
3114
- });
3115
- newChannelConfig.push(newQueue);
3116
- });
3117
- _channelConfig = newChannelConfig;
3118
- }
3119
- removeComplete && removeComplete(removed);
3120
- });
3121
- unloadCtx.processNext(unloadState);
3122
- }
3123
- else {
3124
- removeComplete(false);
3125
- }
3126
- }
3127
- function _flushInternalLogs() {
3128
- var queue = _self.logger ? _self.logger.queue : [];
3129
- if (queue) {
3130
- arrForEach(queue, function (logMessage) {
3131
- var item = {
3132
- name: _internalLogsEventName ? _internalLogsEventName : "InternalMessageId: " + logMessage.messageId,
3133
- iKey: _self.config.instrumentationKey,
3134
- time: toISOString(new Date()),
3135
- baseType: _InternalLogMessage.dataType,
3136
- baseData: { message: logMessage.message }
3137
- };
3138
- _self.track(item);
3139
- });
3140
- queue.length = 0;
3141
- }
3142
- }
3143
- function _flushChannels(isAsync, callBack, sendReason, cbTimeout) {
3144
- if (_channelControl) {
3145
- return _channelControl.flush(isAsync, callBack, sendReason || 6 , cbTimeout);
3146
- }
3147
- callBack && callBack(false);
3148
- return true;
3149
- }
3150
- function _initDebugListener(config) {
3151
- if (config.disableDbgExt === true && _debugListener) {
3152
- _notificationManager[strRemoveNotificationListener](_debugListener);
3153
- _debugListener = null;
3154
- }
3155
- if (_notificationManager && !_debugListener && config.disableDbgExt !== true) {
3156
- _debugListener = getDebugListener(config);
3157
- _notificationManager[strAddNotificationListener](_debugListener);
3158
- }
3159
- }
3160
- function _initPerfManager(config) {
3161
- if (!config.enablePerfMgr && _cfgPerfManager) {
3162
- _cfgPerfManager = null;
3163
- }
3164
- if (config.enablePerfMgr) {
3165
- setValue(_self.config, "createPerfMgr", _createPerfManager);
3166
- }
3167
- }
3168
- function _initExtConfig(config) {
3169
- var extConfig = getSetValue(config, strExtensionConfig);
3170
- extConfig.NotificationManager = _notificationManager;
3171
- }
3172
- function _doUpdate(updateState) {
3173
- var updateCtx = createProcessTelemetryUpdateContext(_getPluginChain(), _self);
3174
- if (!_self._updateHook || _self._updateHook(updateCtx, updateState) !== true) {
3175
- updateCtx.processNext(updateState);
3176
- }
3177
- }
3178
- function _logOrThrowError(message) {
3179
- var logger = _self.logger;
3180
- if (logger) {
3181
- _throwInternal(logger, 2 , 73 , message);
3182
- }
3183
- else {
3184
- throwError(message);
3185
- }
3186
- }
3187
- });
3188
- }
3189
- return BaseCore;
3190
- }());
3191
-
3192
- function _runListeners(listeners, name, isAsync, callback) {
3193
- arrForEach(listeners, function (listener) {
3194
- if (listener && listener[name]) {
3195
- if (isAsync) {
3196
- setTimeout(function () { return callback(listener); }, 0);
3197
- }
3198
- else {
3199
- try {
3200
- callback(listener);
3201
- }
3202
- catch (e) {
3203
- }
3204
- }
3205
- }
3206
- });
3207
- }
3208
- var NotificationManager = /** @class */ (function () {
3209
- function NotificationManager(config) {
3210
- this.listeners = [];
3211
- var perfEvtsSendAll = !!(config || {}).perfEvtsSendAll;
3212
- dynamicProto(NotificationManager, this, function (_self) {
3213
- _self[strAddNotificationListener] = function (listener) {
3214
- _self.listeners.push(listener);
3215
- };
3216
- _self[strRemoveNotificationListener] = function (listener) {
3217
- var index = arrIndexOf(_self.listeners, listener);
3218
- while (index > -1) {
3219
- _self.listeners.splice(index, 1);
3220
- index = arrIndexOf(_self.listeners, listener);
3221
- }
3222
- };
3223
- _self[strEventsSent] = function (events) {
3224
- _runListeners(_self.listeners, strEventsSent, true, function (listener) {
3225
- listener[strEventsSent](events);
3226
- });
3227
- };
3228
- _self[strEventsDiscarded] = function (events, reason) {
3229
- _runListeners(_self.listeners, strEventsDiscarded, true, function (listener) {
3230
- listener[strEventsDiscarded](events, reason);
3231
- });
3232
- };
3233
- _self[strEventsSendRequest] = function (sendReason, isAsync) {
3234
- _runListeners(_self.listeners, strEventsSendRequest, isAsync, function (listener) {
3235
- listener[strEventsSendRequest](sendReason, isAsync);
3236
- });
3237
- };
3238
- _self[strPerfEvent] = function (perfEvent) {
3239
- if (perfEvent) {
3240
- if (perfEvtsSendAll || !perfEvent.isChildEvt()) {
3241
- _runListeners(_self.listeners, strPerfEvent, false, function (listener) {
3242
- if (perfEvent.isAsync) {
3243
- setTimeout(function () { return listener[strPerfEvent](perfEvent); }, 0);
3244
- }
3245
- else {
3246
- listener[strPerfEvent](perfEvent);
3247
- }
3248
- });
3249
- }
3250
- }
3251
- };
3252
- });
3253
- }
3254
- return NotificationManager;
3255
- }());
3256
-
3257
- var AppInsightsCore$2 = /** @class */ (function (_super) {
3258
- __extendsFn(AppInsightsCore, _super);
3259
- function AppInsightsCore() {
3260
- var _this = _super.call(this) || this;
3261
- dynamicProto(AppInsightsCore, _this, function (_self, _base) {
3262
- _self.initialize = function (config, extensions, logger, notificationManager) {
3263
- _base.initialize(config, extensions, logger || new DiagnosticLogger(config), notificationManager || new NotificationManager(config));
3264
- };
3265
- _self.track = function (telemetryItem) {
3266
- doPerf(_self.getPerfMgr(), function () { return "AppInsightsCore:track"; }, function () {
3267
- if (telemetryItem === null) {
3268
- _notifyInvalidEvent(telemetryItem);
3269
- throwError("Invalid telemetry item");
3270
- }
3271
- _validateTelemetryItem(telemetryItem);
3272
- _base.track(telemetryItem);
3273
- }, function () { return ({ item: telemetryItem }); }, !(telemetryItem.sync));
3274
- };
3275
- function _validateTelemetryItem(telemetryItem) {
3276
- if (isNullOrUndefined(telemetryItem.name)) {
3277
- _notifyInvalidEvent(telemetryItem);
3278
- throwError("telemetry name required");
3639
+ }
3640
+ else {
3641
+ removed = true;
3642
+ }
3643
+ });
3644
+ _configExtensions = newConfigExtensions;
3645
+ var newChannelConfig = [];
3646
+ if (_channelConfig) {
3647
+ arrForEach(_channelConfig, function (queue, idx) {
3648
+ var newQueue = [];
3649
+ arrForEach(queue, function (channel) {
3650
+ if (!_isPluginPresent(channel, thePlugins)) {
3651
+ newQueue.push(channel);
3652
+ }
3653
+ else {
3654
+ removed = true;
3655
+ }
3656
+ });
3657
+ newChannelConfig.push(newQueue);
3658
+ });
3659
+ _channelConfig = newChannelConfig;
3660
+ }
3661
+ removeComplete && removeComplete(removed);
3662
+ });
3663
+ unloadCtx.processNext(unloadState);
3664
+ }
3665
+ else {
3666
+ removeComplete(false);
3279
3667
  }
3280
3668
  }
3281
- function _notifyInvalidEvent(telemetryItem) {
3282
- var manager = _self.getNotifyMgr();
3283
- if (manager) {
3284
- manager.eventsDiscarded([telemetryItem], 2 );
3669
+ function _flushInternalLogs() {
3670
+ var queue = _self.logger ? _self.logger.queue : [];
3671
+ if (queue) {
3672
+ arrForEach(queue, function (logMessage) {
3673
+ var item = {
3674
+ name: _internalLogsEventName ? _internalLogsEventName : "InternalMessageId: " + logMessage.messageId,
3675
+ iKey: _self.config.instrumentationKey,
3676
+ time: toISOString(new Date()),
3677
+ baseType: _InternalLogMessage.dataType,
3678
+ baseData: { message: logMessage.message }
3679
+ };
3680
+ _self.track(item);
3681
+ });
3682
+ queue.length = 0;
3285
3683
  }
3286
3684
  }
3287
- });
3288
- return _this;
3289
- }
3290
- return AppInsightsCore;
3291
- }(BaseCore$2));
3292
-
3293
- var strOnPrefix = "on";
3294
- var strAttachEvent = "attachEvent";
3295
- var strAddEventHelper = "addEventListener";
3296
- var strDetachEvent = "detachEvent";
3297
- var strRemoveEventListener = "removeEventListener";
3298
- var strEvents = "events";
3299
- var strVisibilityChangeEvt = "visibilitychange";
3300
- var strPageHide = "pagehide";
3301
- var strPageShow = "pageshow";
3302
- var strUnload = "unload";
3303
- var strBeforeUnload = "beforeunload";
3304
- var strPageHideNamespace = createUniqueNamespace("aiEvtPageHide");
3305
- var strPageShowNamespace = createUniqueNamespace("aiEvtPageShow");
3306
- var rRemoveEmptyNs = /\.[\.]+/g;
3307
- var rRemoveTrailingEmptyNs = /[\.]+$/;
3308
- var _guid = 1;
3309
- var elmNodeData = createElmNodeData("events");
3310
- var eventNamespace = /^([^.]*)(?:\.(.+)|)/;
3311
- function _normalizeNamespace(name) {
3312
- if (name && name.replace) {
3313
- return name.replace(/^\s*\.*|\.*\s*$/g, "");
3314
- }
3315
- return name;
3316
- }
3317
- function _getEvtNamespace(eventName, evtNamespace) {
3318
- if (evtNamespace) {
3319
- var theNamespace_1 = "";
3320
- if (isArray(evtNamespace)) {
3321
- theNamespace_1 = "";
3322
- arrForEach(evtNamespace, function (name) {
3323
- name = _normalizeNamespace(name);
3324
- if (name) {
3325
- if (name[0] !== ".") {
3326
- name = "." + name;
3327
- }
3328
- theNamespace_1 += name;
3685
+ function _flushChannels(isAsync, callBack, sendReason, cbTimeout) {
3686
+ if (_channelControl) {
3687
+ return _channelControl.flush(isAsync, callBack, sendReason || 6 , cbTimeout);
3329
3688
  }
3330
- });
3331
- }
3332
- else {
3333
- theNamespace_1 = _normalizeNamespace(evtNamespace);
3334
- }
3335
- if (theNamespace_1) {
3336
- if (theNamespace_1[0] !== ".") {
3337
- theNamespace_1 = "." + theNamespace_1;
3689
+ callBack && callBack(false);
3690
+ return true;
3338
3691
  }
3339
- eventName = (eventName || "") + theNamespace_1;
3340
- }
3341
- }
3342
- var parsedEvent = (eventNamespace.exec(eventName || "") || []);
3343
- return {
3344
- type: parsedEvent[1],
3345
- ns: ((parsedEvent[2] || "").replace(rRemoveEmptyNs, ".").replace(rRemoveTrailingEmptyNs, "").split(".").sort()).join(".")
3346
- };
3347
- }
3348
- function __getRegisteredEvents(target, eventName, evtNamespace) {
3349
- var theEvents = [];
3350
- var eventCache = elmNodeData.get(target, strEvents, {}, false);
3351
- var evtName = _getEvtNamespace(eventName, evtNamespace);
3352
- objForEachKey(eventCache, function (evtType, registeredEvents) {
3353
- arrForEach(registeredEvents, function (value) {
3354
- if (!evtName.type || evtName.type === value.evtName.type) {
3355
- if (!evtName.ns || evtName.ns === evtName.ns) {
3356
- theEvents.push({
3357
- name: value.evtName.type + (value.evtName.ns ? "." + value.evtName.ns : ""),
3358
- handler: value.handler
3359
- });
3692
+ function _initDebugListener(config) {
3693
+ if (config.disableDbgExt === true && _debugListener) {
3694
+ _notificationManager[strRemoveNotificationListener](_debugListener);
3695
+ _debugListener = null;
3696
+ }
3697
+ if (_notificationManager && !_debugListener && config.disableDbgExt !== true) {
3698
+ _debugListener = getDebugListener(config);
3699
+ _notificationManager[strAddNotificationListener](_debugListener);
3360
3700
  }
3361
3701
  }
3362
- });
3363
- });
3364
- return theEvents;
3365
- }
3366
- function _getRegisteredEvents(target, evtName, addDefault) {
3367
- if (addDefault === void 0) { addDefault = true; }
3368
- var aiEvts = elmNodeData.get(target, strEvents, {}, addDefault);
3369
- var registeredEvents = aiEvts[evtName];
3370
- if (!registeredEvents) {
3371
- registeredEvents = aiEvts[evtName] = [];
3372
- }
3373
- return registeredEvents;
3374
- }
3375
- function _doDetach(obj, evtName, handlerRef, useCapture) {
3376
- if (obj && evtName && evtName.type) {
3377
- if (obj[strRemoveEventListener]) {
3378
- obj[strRemoveEventListener](evtName.type, handlerRef, useCapture);
3379
- }
3380
- else if (obj[strDetachEvent]) {
3381
- obj[strDetachEvent](strOnPrefix + evtName.type, handlerRef);
3382
- }
3383
- }
3384
- }
3385
- function _doAttach(obj, evtName, handlerRef, useCapture) {
3386
- var result = false;
3387
- if (obj && evtName && evtName.type && handlerRef) {
3388
- if (obj[strAddEventHelper]) {
3389
- obj[strAddEventHelper](evtName.type, handlerRef, useCapture);
3390
- result = true;
3391
- }
3392
- else if (obj[strAttachEvent]) {
3393
- obj[strAttachEvent](strOnPrefix + evtName.type, handlerRef);
3394
- result = true;
3395
- }
3396
- }
3397
- return result;
3398
- }
3399
- function _doUnregister(target, events, evtName, unRegFn) {
3400
- var idx = events.length;
3401
- while (idx--) {
3402
- var theEvent = events[idx];
3403
- if (theEvent) {
3404
- if (!evtName.ns || evtName.ns === theEvent.evtName.ns) {
3405
- if (!unRegFn || unRegFn(theEvent)) {
3406
- _doDetach(target, theEvent.evtName, theEvent.handler, theEvent.capture);
3407
- events.splice(idx, 1);
3702
+ function _initPerfManager(config) {
3703
+ if (!config.enablePerfMgr && _cfgPerfManager) {
3704
+ _cfgPerfManager = null;
3705
+ }
3706
+ if (config.enablePerfMgr) {
3707
+ setValue(_self.config, "createPerfMgr", _createPerfManager);
3408
3708
  }
3409
3709
  }
3410
- }
3411
- }
3412
- }
3413
- function _unregisterEvents(target, evtName, unRegFn) {
3414
- if (evtName.type) {
3415
- _doUnregister(target, _getRegisteredEvents(target, evtName.type), evtName, unRegFn);
3416
- }
3417
- else {
3418
- var eventCache = elmNodeData.get(target, strEvents, {});
3419
- objForEachKey(eventCache, function (evtType, events) {
3420
- _doUnregister(target, events, evtName, unRegFn);
3421
- });
3422
- if (objKeys(eventCache).length === 0) {
3423
- elmNodeData.kill(target, strEvents);
3424
- }
3425
- }
3426
- }
3427
- function mergeEvtNamespace(theNamespace, namespaces) {
3428
- var newNamespaces;
3429
- if (namespaces) {
3430
- if (isArray(namespaces)) {
3431
- newNamespaces = [theNamespace].concat(namespaces);
3432
- }
3433
- else {
3434
- newNamespaces = [theNamespace, namespaces];
3435
- }
3436
- newNamespaces = (_getEvtNamespace("xx", newNamespaces).ns).split(".");
3437
- }
3438
- else {
3439
- newNamespaces = theNamespace;
3440
- }
3441
- return newNamespaces;
3442
- }
3443
- function eventOn(target, eventName, handlerRef, evtNamespace, useCapture) {
3444
- if (useCapture === void 0) { useCapture = false; }
3445
- var result = false;
3446
- if (target) {
3447
- try {
3448
- var evtName = _getEvtNamespace(eventName, evtNamespace);
3449
- result = _doAttach(target, evtName, handlerRef, useCapture);
3450
- if (result && elmNodeData.accept(target)) {
3451
- var registeredEvent = {
3452
- guid: _guid++,
3453
- evtName: evtName,
3454
- handler: handlerRef,
3455
- capture: useCapture
3456
- };
3457
- _getRegisteredEvents(target, evtName.type).push(registeredEvent);
3710
+ function _initExtConfig(config) {
3711
+ var extConfig = getSetValue(config, strExtensionConfig);
3712
+ extConfig.NotificationManager = _notificationManager;
3458
3713
  }
3459
- }
3460
- catch (e) {
3461
- }
3462
- }
3463
- return result;
3464
- }
3465
- function eventOff(target, eventName, handlerRef, evtNamespace, useCapture) {
3466
- if (useCapture === void 0) { useCapture = false; }
3467
- if (target) {
3468
- try {
3469
- var evtName_1 = _getEvtNamespace(eventName, evtNamespace);
3470
- var found_1 = false;
3471
- _unregisterEvents(target, evtName_1, function (regEvent) {
3472
- if ((evtName_1.ns && !handlerRef) || regEvent.handler === handlerRef) {
3473
- found_1 = true;
3474
- return true;
3475
- }
3476
- return false;
3477
- });
3478
- if (!found_1) {
3479
- _doDetach(target, evtName_1, handlerRef, useCapture);
3714
+ function _doUpdate(updateState) {
3715
+ var updateCtx = createProcessTelemetryUpdateContext(_getPluginChain(), _self);
3716
+ if (!_self._updateHook || _self._updateHook(updateCtx, updateState) !== true) {
3717
+ updateCtx.processNext(updateState);
3718
+ }
3480
3719
  }
3481
- }
3482
- catch (e) {
3483
- }
3484
- }
3485
- }
3486
- function attachEvent(obj, eventNameWithoutOn, handlerRef, useCapture) {
3487
- if (useCapture === void 0) { useCapture = false; }
3488
- return eventOn(obj, eventNameWithoutOn, handlerRef, null, useCapture);
3489
- }
3490
- function detachEvent(obj, eventNameWithoutOn, handlerRef, useCapture) {
3491
- if (useCapture === void 0) { useCapture = false; }
3492
- eventOff(obj, eventNameWithoutOn, handlerRef, null, useCapture);
3493
- }
3494
- function addEventHandler(eventName, callback, evtNamespace) {
3495
- var result = false;
3496
- var w = getWindow();
3497
- if (w) {
3498
- result = eventOn(w, eventName, callback, evtNamespace);
3499
- result = eventOn(w["body"], eventName, callback, evtNamespace) || result;
3500
- }
3501
- var doc = getDocument();
3502
- if (doc) {
3503
- result = eventOn(doc, eventName, callback, evtNamespace) || result;
3504
- }
3505
- return result;
3506
- }
3507
- function removeEventHandler(eventName, callback, evtNamespace) {
3508
- var w = getWindow();
3509
- if (w) {
3510
- eventOff(w, eventName, callback, evtNamespace);
3511
- eventOff(w["body"], eventName, callback, evtNamespace);
3512
- }
3513
- var doc = getDocument();
3514
- if (doc) {
3515
- eventOff(doc, eventName, callback, evtNamespace);
3516
- }
3517
- }
3518
- function _addEventListeners(events, listener, excludeEvents, evtNamespace) {
3519
- var added = false;
3520
- if (listener && events && events.length > 0) {
3521
- arrForEach(events, function (name) {
3522
- if (name) {
3523
- if (!excludeEvents || arrIndexOf(excludeEvents, name) === -1) {
3524
- added = addEventHandler(name, listener, evtNamespace) || added;
3720
+ function _logOrThrowError(message) {
3721
+ var logger = _self.logger;
3722
+ if (logger) {
3723
+ _throwInternal(logger, 2 , 73 , message);
3724
+ }
3725
+ else {
3726
+ throwError(message);
3525
3727
  }
3526
3728
  }
3527
3729
  });
3528
3730
  }
3529
- return added;
3530
- }
3531
- function addEventListeners(events, listener, excludeEvents, evtNamespace) {
3532
- var added = false;
3533
- if (listener && events && isArray(events)) {
3534
- added = _addEventListeners(events, listener, excludeEvents, evtNamespace);
3535
- if (!added && excludeEvents && excludeEvents.length > 0) {
3536
- added = _addEventListeners(events, listener, null, evtNamespace);
3537
- }
3538
- }
3539
- return added;
3540
- }
3541
- function removeEventListeners(events, listener, evtNamespace) {
3542
- if (events && isArray(events)) {
3543
- arrForEach(events, function (name) {
3544
- if (name) {
3545
- removeEventHandler(name, listener, evtNamespace);
3731
+ return BaseCore;
3732
+ }());
3733
+
3734
+ function _runListeners(listeners, name, isAsync, callback) {
3735
+ arrForEach(listeners, function (listener) {
3736
+ if (listener && listener[name]) {
3737
+ if (isAsync) {
3738
+ setTimeout(function () { return callback(listener); }, 0);
3739
+ }
3740
+ else {
3741
+ try {
3742
+ callback(listener);
3743
+ }
3744
+ catch (e) {
3745
+ }
3546
3746
  }
3547
- });
3548
- }
3549
- }
3550
- function addPageUnloadEventListener(listener, excludeEvents, evtNamespace) {
3551
- return addEventListeners([strBeforeUnload, strUnload, strPageHide], listener, excludeEvents, evtNamespace);
3552
- }
3553
- function removePageUnloadEventListener(listener, evtNamespace) {
3554
- removeEventListeners([strBeforeUnload, strUnload, strPageHide], listener, evtNamespace);
3555
- }
3556
- function addPageHideEventListener(listener, excludeEvents, evtNamespace) {
3557
- function _handlePageVisibility(evt) {
3558
- var doc = getDocument();
3559
- if (listener && doc && doc.visibilityState === "hidden") {
3560
- listener(evt);
3561
- }
3562
- }
3563
- var newNamespaces = mergeEvtNamespace(strPageHideNamespace, evtNamespace);
3564
- var pageUnloadAdded = _addEventListeners([strPageHide], listener, excludeEvents, newNamespaces);
3565
- if (!excludeEvents || arrIndexOf(excludeEvents, strVisibilityChangeEvt) === -1) {
3566
- pageUnloadAdded = _addEventListeners([strVisibilityChangeEvt], _handlePageVisibility, excludeEvents, newNamespaces) || pageUnloadAdded;
3567
- }
3568
- if (!pageUnloadAdded && excludeEvents) {
3569
- pageUnloadAdded = addPageHideEventListener(listener, null, evtNamespace);
3570
- }
3571
- return pageUnloadAdded;
3572
- }
3573
- function removePageHideEventListener(listener, evtNamespace) {
3574
- var newNamespaces = mergeEvtNamespace(strPageHideNamespace, evtNamespace);
3575
- removeEventListeners([strPageHide], listener, newNamespaces);
3576
- removeEventListeners([strVisibilityChangeEvt], null, newNamespaces);
3577
- }
3578
- function addPageShowEventListener(listener, excludeEvents, evtNamespace) {
3579
- function _handlePageVisibility(evt) {
3580
- var doc = getDocument();
3581
- if (listener && doc && doc.visibilityState === "visible") {
3582
- listener(evt);
3583
3747
  }
3584
- }
3585
- var newNamespaces = mergeEvtNamespace(strPageShowNamespace, evtNamespace);
3586
- var pageShowAdded = _addEventListeners([strPageShow], listener, excludeEvents, newNamespaces);
3587
- pageShowAdded = _addEventListeners([strVisibilityChangeEvt], _handlePageVisibility, excludeEvents, newNamespaces) || pageShowAdded;
3588
- if (!pageShowAdded && excludeEvents) {
3589
- pageShowAdded = addPageShowEventListener(listener, null, evtNamespace);
3590
- }
3591
- return pageShowAdded;
3592
- }
3593
- function removePageShowEventListener(listener, evtNamespace) {
3594
- var newNamespaces = mergeEvtNamespace(strPageShowNamespace, evtNamespace);
3595
- removeEventListeners([strPageShow], listener, newNamespaces);
3596
- removeEventListeners([strVisibilityChangeEvt], null, newNamespaces);
3597
- }
3598
-
3599
- function newGuid() {
3600
- function randomHexDigit() {
3601
- return randomValue(15);
3602
- }
3603
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(GuidRegex, function (c) {
3604
- var r = (randomHexDigit() | 0), v = (c === "x" ? r : r & 0x3 | 0x8);
3605
- return v.toString(16);
3606
3748
  });
3607
3749
  }
3608
- function perfNow() {
3609
- var perf = getPerformance();
3610
- if (perf && perf.now) {
3611
- return perf.now();
3750
+ var NotificationManager = /** @class */ (function () {
3751
+ function NotificationManager(config) {
3752
+ this.listeners = [];
3753
+ var perfEvtsSendAll = !!(config || {}).perfEvtsSendAll;
3754
+ dynamicProto(NotificationManager, this, function (_self) {
3755
+ _self[strAddNotificationListener] = function (listener) {
3756
+ _self.listeners.push(listener);
3757
+ };
3758
+ _self[strRemoveNotificationListener] = function (listener) {
3759
+ var index = arrIndexOf(_self.listeners, listener);
3760
+ while (index > -1) {
3761
+ _self.listeners.splice(index, 1);
3762
+ index = arrIndexOf(_self.listeners, listener);
3763
+ }
3764
+ };
3765
+ _self[strEventsSent] = function (events) {
3766
+ _runListeners(_self.listeners, strEventsSent, true, function (listener) {
3767
+ listener[strEventsSent](events);
3768
+ });
3769
+ };
3770
+ _self[strEventsDiscarded] = function (events, reason) {
3771
+ _runListeners(_self.listeners, strEventsDiscarded, true, function (listener) {
3772
+ listener[strEventsDiscarded](events, reason);
3773
+ });
3774
+ };
3775
+ _self[strEventsSendRequest] = function (sendReason, isAsync) {
3776
+ _runListeners(_self.listeners, strEventsSendRequest, isAsync, function (listener) {
3777
+ listener[strEventsSendRequest](sendReason, isAsync);
3778
+ });
3779
+ };
3780
+ _self[strPerfEvent] = function (perfEvent) {
3781
+ if (perfEvent) {
3782
+ if (perfEvtsSendAll || !perfEvent.isChildEvt()) {
3783
+ _runListeners(_self.listeners, strPerfEvent, false, function (listener) {
3784
+ if (perfEvent.isAsync) {
3785
+ setTimeout(function () { return listener[strPerfEvent](perfEvent); }, 0);
3786
+ }
3787
+ else {
3788
+ listener[strPerfEvent](perfEvent);
3789
+ }
3790
+ });
3791
+ }
3792
+ }
3793
+ };
3794
+ });
3612
3795
  }
3613
- return dateNow();
3614
- }
3615
- function generateW3CId() {
3616
- var hexValues = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"];
3617
- var oct = strEmpty, tmp;
3618
- for (var a = 0; a < 4; a++) {
3619
- tmp = random32();
3620
- oct +=
3621
- hexValues[tmp & 0xF] +
3622
- hexValues[tmp >> 4 & 0xF] +
3623
- hexValues[tmp >> 8 & 0xF] +
3624
- hexValues[tmp >> 12 & 0xF] +
3625
- hexValues[tmp >> 16 & 0xF] +
3626
- hexValues[tmp >> 20 & 0xF] +
3627
- hexValues[tmp >> 24 & 0xF] +
3628
- hexValues[tmp >> 28 & 0xF];
3796
+ return NotificationManager;
3797
+ }());
3798
+
3799
+ var AppInsightsCore$2 = /** @class */ (function (_super) {
3800
+ __extendsFn(AppInsightsCore, _super);
3801
+ function AppInsightsCore() {
3802
+ var _this = _super.call(this) || this;
3803
+ dynamicProto(AppInsightsCore, _this, function (_self, _base) {
3804
+ _self.initialize = function (config, extensions, logger, notificationManager) {
3805
+ _base.initialize(config, extensions, logger || new DiagnosticLogger(config), notificationManager || new NotificationManager(config));
3806
+ };
3807
+ _self.track = function (telemetryItem) {
3808
+ doPerf(_self.getPerfMgr(), function () { return "AppInsightsCore:track"; }, function () {
3809
+ if (telemetryItem === null) {
3810
+ _notifyInvalidEvent(telemetryItem);
3811
+ throwError("Invalid telemetry item");
3812
+ }
3813
+ _validateTelemetryItem(telemetryItem);
3814
+ _base.track(telemetryItem);
3815
+ }, function () { return ({ item: telemetryItem }); }, !(telemetryItem.sync));
3816
+ };
3817
+ function _validateTelemetryItem(telemetryItem) {
3818
+ if (isNullOrUndefined(telemetryItem.name)) {
3819
+ _notifyInvalidEvent(telemetryItem);
3820
+ throwError("telemetry name required");
3821
+ }
3822
+ }
3823
+ function _notifyInvalidEvent(telemetryItem) {
3824
+ var manager = _self.getNotifyMgr();
3825
+ if (manager) {
3826
+ manager.eventsDiscarded([telemetryItem], 2 );
3827
+ }
3828
+ }
3829
+ });
3830
+ return _this;
3629
3831
  }
3630
- var clockSequenceHi = hexValues[8 + (random32() & 0x03) | 0];
3631
- return oct.substr(0, 8) + oct.substr(9, 4) + "4" + oct.substr(13, 3) + clockSequenceHi + oct.substr(16, 3) + oct.substr(19, 12);
3632
- }
3633
- var GuidRegex = /[xy]/g;
3634
- var EventHelper = {
3635
- Attach: attachEvent,
3636
- AttachEvent: attachEvent,
3637
- Detach: detachEvent,
3638
- DetachEvent: detachEvent
3639
- };
3832
+ return AppInsightsCore;
3833
+ }(BaseCore$2));
3640
3834
 
3641
3835
  var LoggingSeverity = createEnumStyle({
3642
3836
  CRITICAL: 1 ,
@@ -3724,7 +3918,8 @@
3724
3918
  InvalidContentBlob: 102 ,
3725
3919
  TrackPageActionEventFailed: 103 ,
3726
3920
  FailedAddingCustomDefinedRequestContext: 104 ,
3727
- InMemoryStorageBufferFull: 105
3921
+ InMemoryStorageBufferFull: 105 ,
3922
+ InstrumentationKeyDeprecation: 106
3728
3923
  });
3729
3924
 
3730
3925
  var ValueKind = createEnumStyle({
@@ -3796,7 +3991,7 @@
3796
3991
  })));
3797
3992
 
3798
3993
  var _a;
3799
- var Version = '3.2.0';
3994
+ var Version = '3.2.3';
3800
3995
  var FullVersionString = "1DS-Web-JS-" + Version;
3801
3996
  var strDisabledPropertyName = "Microsoft_ApplicationInsights_BypassAjaxInstrumentation";
3802
3997
  var strWithCredentials = "withCredentials";
@@ -4899,6 +5094,7 @@
4899
5094
  exports.createEnumStyle = createEnumStyle;
4900
5095
  exports.createGuid = createGuid;
4901
5096
  exports.createProcessTelemetryContext = createProcessTelemetryContext;
5097
+ exports.createTraceParent = createTraceParent;
4902
5098
  exports.createUniqueNamespace = createUniqueNamespace;
4903
5099
  exports.createUnloadHandlerContainer = createUnloadHandlerContainer;
4904
5100
  exports.dateNow = dateNow;
@@ -4911,6 +5107,8 @@
4911
5107
  exports.eventOff = eventOff;
4912
5108
  exports.eventOn = eventOn;
4913
5109
  exports.extend = extend;
5110
+ exports.findW3cTraceParent = findW3cTraceParent;
5111
+ exports.formatTraceParent = formatTraceParent;
4914
5112
  exports.generateW3CId = generateW3CId;
4915
5113
  exports.getCommonSchemaMetaData = getCommonSchemaMetaData;
4916
5114
  exports.getConsole = getConsole;
@@ -4957,11 +5155,15 @@
4957
5155
  exports.isNumber = isNumber;
4958
5156
  exports.isObject = isObject;
4959
5157
  exports.isReactNative = isReactNative;
5158
+ exports.isSampledFlag = isSampledFlag;
4960
5159
  exports.isString = isString;
4961
5160
  exports.isTruthy = isTruthy;
4962
5161
  exports.isTypeof = isTypeof;
4963
5162
  exports.isUint8ArrayAvailable = isUint8ArrayAvailable;
4964
5163
  exports.isUndefined = isUndefined;
5164
+ exports.isValidSpanId = isValidSpanId;
5165
+ exports.isValidTraceId = isValidTraceId;
5166
+ exports.isValidTraceParent = isValidTraceParent;
4965
5167
  exports.isValueAssigned = isValueAssigned;
4966
5168
  exports.isValueKind = isValueKind;
4967
5169
  exports.isWindowObjectAvailable = isWindowObjectAvailable;
@@ -4978,6 +5180,7 @@
4978
5180
  exports.objSeal = objSeal;
4979
5181
  exports.openXhr = openXhr;
4980
5182
  exports.optimizeObject = optimizeObject;
5183
+ exports.parseTraceParent = parseTraceParent;
4981
5184
  exports.perfNow = perfNow;
4982
5185
  exports.proxyAssign = proxyAssign;
4983
5186
  exports.proxyFunctionAs = proxyFunctionAs;