@microsoft/1ds-core-js 3.2.2 → 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.2.gbl.js → ms.core-3.2.3.gbl.js} +1522 -1326
  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.2.js → ms.core-3.2.3.js} +1522 -1326
  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 +1521 -1325
  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 +1521 -1325
  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 +2 -3
  44. package/src/Index.ts +2 -2
  45. package/bundle/ms.core-3.2.2.gbl.js.map +0 -1
  46. package/bundle/ms.core-3.2.2.gbl.min.js +0 -7
  47. package/bundle/ms.core-3.2.2.gbl.min.js.map +0 -1
  48. package/bundle/ms.core-3.2.2.integrity.json +0 -46
  49. package/bundle/ms.core-3.2.2.js.map +0 -1
  50. package/bundle/ms.core-3.2.2.min.js +0 -7
  51. package/bundle/ms.core-3.2.2.min.js.map +0 -1
package/bundle/ms.core.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * 1DS JS SDK Core, 3.2.2
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
  */
@@ -1112,6 +1112,35 @@
1112
1112
  }
1113
1113
  return isSupported;
1114
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
+ }
1115
1144
 
1116
1145
  var listenerFuncs = ["eventsSent", "eventsDiscarded", "eventsSendRequest", "perfEvent"];
1117
1146
  var _aiNamespace = null;
@@ -1541,7 +1570,7 @@
1541
1570
  }
1542
1571
 
1543
1572
  var _objDefineProperty = ObjDefineProperty;
1544
- var version = "2.8.3";
1573
+ var version = "2.8.4";
1545
1574
  var instanceName = "." + newId(6);
1546
1575
  var _dataUid = 0;
1547
1576
  function _createAccessor(target, prop, value) {
@@ -1612,903 +1641,1398 @@
1612
1641
  return data;
1613
1642
  }
1614
1643
 
1615
- var pluginStateData = createElmNodeData("plugin");
1616
- function _getPluginState(plugin) {
1617
- 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;
1618
1665
  }
1619
- function initializePlugins(processContext, extensions) {
1620
- var initPlugins = [];
1621
- var lastPlugin = null;
1622
- var proxy = processContext.getNext();
1623
- var pluginState;
1624
- while (proxy) {
1625
- var thePlugin = proxy.getPlugin();
1626
- if (thePlugin) {
1627
- if (lastPlugin &&
1628
- isFunction(lastPlugin[strSetNextPlugin]) &&
1629
- isFunction(thePlugin[strProcessTelemetry])) {
1630
- lastPlugin[strSetNextPlugin](thePlugin);
1631
- }
1632
- var isInitialized = false;
1633
- if (isFunction(thePlugin[strIsInitialized])) {
1634
- isInitialized = thePlugin[strIsInitialized]();
1635
- }
1636
- else {
1637
- pluginState = _getPluginState(thePlugin);
1638
- isInitialized = pluginState[strIsInitialized];
1639
- }
1640
- if (!isInitialized) {
1641
- initPlugins.push(thePlugin);
1642
- }
1643
- lastPlugin = thePlugin;
1644
- proxy = proxy.getNext();
1645
- }
1666
+ function _isMgrEnabled(cookieMgr) {
1667
+ if (cookieMgr) {
1668
+ return cookieMgr.isEnabled();
1646
1669
  }
1647
- arrForEach(initPlugins, function (thePlugin) {
1648
- var core = processContext.core();
1649
- thePlugin.initialize(processContext.getCfg(), core, extensions, processContext.getNext());
1650
- pluginState = _getPluginState(thePlugin);
1651
- if (!thePlugin[strCore] && !pluginState[strCore]) {
1652
- pluginState[strCore] = core;
1653
- }
1654
- pluginState[strIsInitialized] = true;
1655
- delete pluginState[strTeardown];
1656
- });
1670
+ return true;
1657
1671
  }
1658
- function sortPlugins(plugins) {
1659
- return plugins.sort(function (extA, extB) {
1660
- var result = 0;
1661
- var bHasProcess = isFunction(extB[strProcessTelemetry]);
1662
- if (isFunction(extA[strProcessTelemetry])) {
1663
- result = bHasProcess ? extA[strPriority] - extB[strPriority] : 1;
1664
- }
1665
- else if (bHasProcess) {
1666
- 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];
1667
1680
  }
1668
- return result;
1669
- });
1670
- }
1671
-
1672
- var strTelemetryPluginChain = "TelemetryPluginChain";
1673
- var strHasRunFlags = "_hasRun";
1674
- var strGetTelCtx = "_getTelCtx";
1675
- var _chainId = 0;
1676
- function _getNextProxyStart(proxy, core, startAt) {
1677
- while (proxy) {
1678
- if (proxy.getPlugin() === startAt) {
1679
- return proxy;
1681
+ if (!isUndefined(rootConfig[strDisableCookiesUsage])) {
1682
+ cookieEnabled = !rootConfig[strDisableCookiesUsage];
1680
1683
  }
1681
- proxy = proxy.getNext();
1684
+ cookieMgrCfg[strEnabled] = cookieEnabled;
1682
1685
  }
1683
- return createTelemetryProxyChain([startAt], core.config || {}, core);
1686
+ return cookieMgrCfg;
1684
1687
  }
1685
- function _createInternalContext(telemetryChain, config, core, startAt) {
1686
- var _nextProxy = null;
1687
- var _onComplete = [];
1688
- if (startAt !== null) {
1689
- _nextProxy = startAt ? _getNextProxyStart(telemetryChain, core, startAt) : telemetryChain;
1688
+ function safeGetCookieMgr(core, config) {
1689
+ var cookieMgr;
1690
+ if (core) {
1691
+ cookieMgr = core.getCookieMgr();
1690
1692
  }
1691
- var context = {
1692
- _next: _moveNext,
1693
- ctx: {
1694
- core: function () {
1695
- return core;
1696
- },
1697
- diagLog: function () {
1698
- return safeGetLogger(core, config);
1699
- },
1700
- getCfg: function () {
1701
- return config;
1702
- },
1703
- getExtCfg: _getExtCfg,
1704
- getConfig: _getConfig,
1705
- hasNext: function () {
1706
- return !!_nextProxy;
1707
- },
1708
- getNext: function () {
1709
- return _nextProxy;
1710
- },
1711
- setNext: function (nextPlugin) {
1712
- _nextProxy = nextPlugin;
1713
- },
1714
- iterate: _iterateChain,
1715
- onComplete: _addOnComplete
1716
- }
1717
- };
1718
- function _addOnComplete(onComplete, that) {
1719
- var args = [];
1720
- for (var _i = 2; _i < arguments.length; _i++) {
1721
- args[_i - 2] = arguments[_i];
1693
+ else if (config) {
1694
+ var cookieCfg = config.cookieCfg;
1695
+ if (cookieCfg[strConfigCookieMgr]) {
1696
+ cookieMgr = cookieCfg[strConfigCookieMgr];
1722
1697
  }
1723
- if (onComplete) {
1724
- _onComplete.push({
1725
- func: onComplete,
1726
- self: !isUndefined(that) ? that : context.ctx,
1727
- args: args
1728
- });
1698
+ else {
1699
+ cookieMgr = createCookieMgr(config);
1729
1700
  }
1730
1701
  }
1731
- function _moveNext() {
1732
- var nextProxy = _nextProxy;
1733
- _nextProxy = nextProxy ? nextProxy.getNext() : null;
1734
- if (!nextProxy) {
1735
- var onComplete = _onComplete;
1736
- if (onComplete && onComplete.length > 0) {
1737
- arrForEach(onComplete, function (completeDetails) {
1738
- try {
1739
- completeDetails.func.call(completeDetails.self, completeDetails.args);
1740
- }
1741
- catch (e) {
1742
- _throwInternal(core.logger, 2 , 73 , "Unexpected Exception during onComplete - " + dumpObj(e));
1743
- }
1744
- });
1745
- _onComplete = [];
1746
- }
1747
- }
1748
- return nextProxy;
1702
+ if (!cookieMgr) {
1703
+ cookieMgr = _gblCookieMgr(config, (core || {}).logger);
1749
1704
  }
1750
- function _getExtCfg(identifier, defaultValue, mergeDefault) {
1751
- if (defaultValue === void 0) { defaultValue = {}; }
1752
- if (mergeDefault === void 0) { mergeDefault = 0 ; }
1753
- var theConfig;
1754
- if (config) {
1755
- var extConfig = config.extensionConfig;
1756
- if (extConfig && identifier) {
1757
- 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);
1758
1718
  }
1759
- }
1760
- if (!theConfig) {
1761
- theConfig = defaultValue;
1762
- }
1763
- else if (isObject(defaultValue)) {
1764
- if (mergeDefault !== 0 ) {
1765
- var newConfig_1 = objExtend(true, defaultValue, theConfig);
1766
- if (config && mergeDefault === 2 ) {
1767
- objForEachKey(defaultValue, function (field) {
1768
- if (isNullOrUndefined(newConfig_1[field])) {
1769
- var cfgValue = config[field];
1770
- if (!isNullOrUndefined(cfgValue)) {
1771
- newConfig_1[field] = cfgValue;
1772
- }
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);
1773
1744
  }
1774
- });
1745
+ }
1746
+ if (!_isIE) {
1747
+ setValue(values, "max-age", strEmpty + maxAgeSec, null, isUndefined);
1748
+ }
1775
1749
  }
1776
- theConfig = newConfig_1;
1777
- }
1778
- }
1779
- return theConfig;
1780
- }
1781
- function _getConfig(identifier, field, defaultValue) {
1782
- if (defaultValue === void 0) { defaultValue = false; }
1783
- var theValue;
1784
- var extConfig = _getExtCfg(identifier, null);
1785
- if (extConfig && !isNullOrUndefined(extConfig[field])) {
1786
- 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;
1787
1797
  }
1788
- else if (config && !isNullOrUndefined(config[field])) {
1789
- 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) });
1790
1811
  }
1791
- return !isNullOrUndefined(theValue) ? theValue : defaultValue;
1792
1812
  }
1793
- function _iterateChain(cb) {
1794
- var nextPlugin;
1795
- while (!!(nextPlugin = context._next())) {
1796
- var plugin = nextPlugin.getPlugin();
1797
- if (plugin) {
1798
- 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
+ }
1799
1829
  }
1800
- }
1830
+ });
1801
1831
  }
1802
- return context;
1832
+ return values;
1803
1833
  }
1804
- function createProcessTelemetryContext(telemetryChain, config, core, startAt) {
1805
- var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1806
- var context = internalContext.ctx;
1807
- function _processNext(env) {
1808
- var nextPlugin = internalContext._next();
1809
- nextPlugin && nextPlugin.processTelemetry(env, context);
1810
- return !nextPlugin;
1834
+ function _formatDate(theDate, func) {
1835
+ if (isFunction(theDate[func])) {
1836
+ return theDate[func]();
1811
1837
  }
1812
- function _createNew(plugins, startAt) {
1813
- if (plugins === void 0) { plugins = null; }
1814
- if (isArray(plugins)) {
1815
- 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;
1816
1854
  }
1817
- return createProcessTelemetryContext(plugins || context.getNext(), config, core, startAt);
1855
+ cookieValue = strTrim(_cookieCache[name] || strEmpty);
1818
1856
  }
1819
- context.processNext = _processNext;
1820
- context.createNew = _createNew;
1821
- return context;
1857
+ return cookieValue;
1822
1858
  }
1823
- function createProcessTelemetryUnloadContext(telemetryChain, core, startAt) {
1824
- var config = core.config || {};
1825
- var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1826
- var context = internalContext.ctx;
1827
- function _processNext(unloadState) {
1828
- var nextPlugin = internalContext._next();
1829
- nextPlugin && nextPlugin.unload(context, unloadState);
1830
- return !nextPlugin;
1831
- }
1832
- function _createNew(plugins, startAt) {
1833
- if (plugins === void 0) { plugins = null; }
1834
- if (isArray(plugins)) {
1835
- plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1836
- }
1837
- return createProcessTelemetryUnloadContext(plugins || context.getNext(), core, startAt);
1859
+ function _setCookieValue(name, cookieValue) {
1860
+ if (_doc) {
1861
+ _doc[strCookie] = name + "=" + cookieValue;
1838
1862
  }
1839
- context.processNext = _processNext;
1840
- context.createNew = _createNew;
1841
- return context;
1842
1863
  }
1843
- function createProcessTelemetryUpdateContext(telemetryChain, core, startAt) {
1844
- var config = core.config || {};
1845
- var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1846
- var context = internalContext.ctx;
1847
- function _processNext(updateState) {
1848
- return context.iterate(function (plugin) {
1849
- if (isFunction(plugin.update)) {
1850
- plugin.update(context, updateState);
1851
- }
1852
- });
1864
+ function uaDisallowsSameSiteNone(userAgent) {
1865
+ if (!isString(userAgent)) {
1866
+ return false;
1853
1867
  }
1854
- function _createNew(plugins, startAt) {
1855
- if (plugins === void 0) { plugins = null; }
1856
- if (isArray(plugins)) {
1857
- plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1858
- }
1859
- return createProcessTelemetryUpdateContext(plugins || context.getNext(), core, startAt);
1868
+ if (strContains(userAgent, "CPU iPhone OS 12") || strContains(userAgent, "iPad; CPU OS 12")) {
1869
+ return true;
1860
1870
  }
1861
- context.processNext = _processNext;
1862
- context.createNew = _createNew;
1863
- return context;
1864
- }
1865
- function createTelemetryProxyChain(plugins, config, core, startAt) {
1866
- var firstProxy = null;
1867
- var add = startAt ? false : true;
1868
- if (isArray(plugins) && plugins.length > 0) {
1869
- var lastProxy_1 = null;
1870
- arrForEach(plugins, function (thePlugin) {
1871
- if (!add && startAt === thePlugin) {
1872
- add = true;
1873
- }
1874
- if (add && thePlugin && isFunction(thePlugin.processTelemetry)) {
1875
- var newProxy = createTelemetryPluginProxy(thePlugin, config, core);
1876
- if (!firstProxy) {
1877
- firstProxy = newProxy;
1878
- }
1879
- if (lastProxy_1) {
1880
- lastProxy_1._setNext(newProxy);
1881
- }
1882
- lastProxy_1 = newProxy;
1883
- }
1884
- });
1871
+ if (strContains(userAgent, "Macintosh; Intel Mac OS X 10_14") && strContains(userAgent, "Version/") && strContains(userAgent, "Safari")) {
1872
+ return true;
1885
1873
  }
1886
- if (startAt && !firstProxy) {
1887
- 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;
1888
1876
  }
1889
- return firstProxy;
1890
- }
1891
- function createTelemetryPluginProxy(plugin, config, core) {
1892
- var nextProxy = null;
1893
- var hasProcessTelemetry = isFunction(plugin.processTelemetry);
1894
- var hasSetNext = isFunction(plugin.setNextPlugin);
1895
- var chainId;
1896
- if (plugin) {
1897
- chainId = plugin.identifier + "-" + plugin.priority + "-" + _chainId++;
1877
+ if (strContains(userAgent, "Chrome/5") || strContains(userAgent, "Chrome/6")) {
1878
+ return true;
1898
1879
  }
1899
- else {
1900
- chainId = "Unknown-0-" + _chainId++;
1880
+ if (strContains(userAgent, "UnrealEngine") && !strContains(userAgent, "Chrome")) {
1881
+ return true;
1901
1882
  }
1902
- var proxyChain = {
1903
- getPlugin: function () {
1904
- return plugin;
1905
- },
1906
- getNext: function () {
1907
- return nextProxy;
1908
- },
1909
- processTelemetry: _processTelemetry,
1910
- unload: _unloadPlugin,
1911
- update: _updatePlugin,
1912
- _id: chainId,
1913
- _setNext: function (nextPlugin) {
1914
- nextProxy = nextPlugin;
1915
- }
1916
- };
1917
- function _getTelCtx() {
1918
- var itemCtx;
1919
- if (plugin && isFunction(plugin[strGetTelCtx])) {
1920
- itemCtx = plugin[strGetTelCtx]();
1921
- }
1922
- if (!itemCtx) {
1923
- itemCtx = createProcessTelemetryContext(proxyChain, config, core);
1924
- }
1925
- return itemCtx;
1883
+ if (strContains(userAgent, "UCBrowser/12") || strContains(userAgent, "UCBrowser/11")) {
1884
+ return true;
1926
1885
  }
1927
- function _processChain(itemCtx, processPluginFn, name, details, isAsync) {
1928
- var hasRun = false;
1929
- var identifier = plugin ? plugin.identifier : strTelemetryPluginChain;
1930
- var hasRunContext = itemCtx[strHasRunFlags];
1931
- if (!hasRunContext) {
1932
- hasRunContext = itemCtx[strHasRunFlags] = {};
1933
- }
1934
- itemCtx.setNext(nextProxy);
1935
- if (plugin) {
1936
- doPerf(itemCtx[strCore](), function () { return identifier + ":" + name; }, function () {
1937
- hasRunContext[chainId] = true;
1938
- try {
1939
- var nextId = nextProxy ? nextProxy._id : strEmpty;
1940
- if (nextId) {
1941
- hasRunContext[nextId] = false;
1942
- }
1943
- hasRun = processPluginFn(itemCtx);
1944
- }
1945
- catch (error) {
1946
- var hasNextRun = nextProxy ? hasRunContext[nextProxy._id] : true;
1947
- if (hasNextRun) {
1948
- hasRun = true;
1949
- }
1950
- if (!nextProxy || !hasNextRun) {
1951
- _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;
1952
1923
  }
1924
+ theNamespace_1 += name;
1953
1925
  }
1954
- }, details, isAsync);
1926
+ });
1955
1927
  }
1956
- return hasRun;
1957
- }
1958
- function _processTelemetry(env, itemCtx) {
1959
- itemCtx = itemCtx || _getTelCtx();
1960
- function _callProcessTelemetry(itemCtx) {
1961
- if (!plugin || !hasProcessTelemetry) {
1962
- return false;
1963
- }
1964
- var pluginState = _getPluginState(plugin);
1965
- if (pluginState.teardown || pluginState[strDisabled]) {
1966
- return false;
1967
- }
1968
- if (hasSetNext) {
1969
- plugin.setNextPlugin(nextProxy);
1970
- }
1971
- plugin.processTelemetry(env, itemCtx);
1972
- return true;
1928
+ else {
1929
+ theNamespace_1 = _normalizeNamespace(evtNamespace);
1973
1930
  }
1974
- if (!_processChain(itemCtx, _callProcessTelemetry, "processTelemetry", function () { return ({ item: env }); }, !(env.sync))) {
1975
- itemCtx.processNext(env);
1931
+ if (theNamespace_1) {
1932
+ if (theNamespace_1[0] !== ".") {
1933
+ theNamespace_1 = "." + theNamespace_1;
1934
+ }
1935
+ eventName = (eventName || "") + theNamespace_1;
1976
1936
  }
1977
1937
  }
1978
- function _unloadPlugin(unloadCtx, unloadState) {
1979
- function _callTeardown() {
1980
- var hasRun = false;
1981
- if (plugin) {
1982
- var pluginState = _getPluginState(plugin);
1983
- var pluginCore = plugin[strCore] || pluginState.core;
1984
- if (plugin && (!pluginCore || pluginCore === unloadCtx[strCore]()) && !pluginState[strTeardown]) {
1985
- pluginState[strCore] = null;
1986
- pluginState[strTeardown] = true;
1987
- pluginState[strIsInitialized] = false;
1988
- if (plugin[strTeardown] && plugin[strTeardown](unloadCtx, unloadState) === true) {
1989
- hasRun = true;
1990
- }
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
+ });
1991
1956
  }
1992
1957
  }
1993
- 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);
1994
1975
  }
1995
- if (!_processChain(unloadCtx, _callTeardown, "unload", function () { }, unloadState.isAsync)) {
1996
- unloadCtx.processNext(unloadState);
1976
+ else if (obj[strDetachEvent]) {
1977
+ obj[strDetachEvent](strOnPrefix + evtName.type, handlerRef);
1997
1978
  }
1998
1979
  }
1999
- function _updatePlugin(updateCtx, updateState) {
2000
- function _callUpdate() {
2001
- var hasRun = false;
2002
- if (plugin) {
2003
- var pluginState = _getPluginState(plugin);
2004
- var pluginCore = plugin[strCore] || pluginState.core;
2005
- if (plugin && (!pluginCore || pluginCore === updateCtx[strCore]()) && !pluginState[strTeardown]) {
2006
- if (plugin[strUpdate] && plugin[strUpdate](updateCtx, updateState) === true) {
2007
- hasRun = true;
2008
- }
2009
- }
2010
- }
2011
- 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;
2012
1987
  }
2013
- if (!_processChain(updateCtx, _callUpdate, "update", function () { }, false)) {
2014
- updateCtx.processNext(updateState);
1988
+ else if (obj[strAttachEvent]) {
1989
+ obj[strAttachEvent](strOnPrefix + evtName.type, handlerRef);
1990
+ result = true;
2015
1991
  }
2016
1992
  }
2017
- return objFreeze(proxyChain);
1993
+ return result;
2018
1994
  }
2019
- var ProcessTelemetryContext = /** @class */ (function () {
2020
- function ProcessTelemetryContext(pluginChain, config, core, startAt) {
2021
- var _self = this;
2022
- var context = createProcessTelemetryContext(pluginChain, config, core, startAt);
2023
- proxyFunctions(_self, context, objKeys(context));
2024
- }
2025
- return ProcessTelemetryContext;
2026
- }());
2027
-
2028
- var strToGMTString = "toGMTString";
2029
- var strToUTCString = "toUTCString";
2030
- var strCookie = "cookie";
2031
- var strExpires = "expires";
2032
- var strEnabled = "enabled";
2033
- var strIsCookieUseDisabled = "isCookieUseDisabled";
2034
- var strDisableCookiesUsage = "disableCookiesUsage";
2035
- var strConfigCookieMgr = "_ckMgr";
2036
- var _supportsCookies = null;
2037
- var _allowUaSameSite = null;
2038
- var _parsedCookieValue = null;
2039
- var _doc = getDocument();
2040
- var _cookieCache = {};
2041
- var _globalCookieConfig = {};
2042
- function _gblCookieMgr(config, logger) {
2043
- var inst = createCookieMgr[strConfigCookieMgr] || _globalCookieConfig[strConfigCookieMgr];
2044
- if (!inst) {
2045
- inst = createCookieMgr[strConfigCookieMgr] = createCookieMgr(config, logger);
2046
- _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
+ }
2047
2007
  }
2048
- return inst;
2049
2008
  }
2050
- function _isMgrEnabled(cookieMgr) {
2051
- if (cookieMgr) {
2052
- return cookieMgr.isEnabled();
2009
+ function _unregisterEvents(target, evtName, unRegFn) {
2010
+ if (evtName.type) {
2011
+ _doUnregister(target, _getRegisteredEvents(target, evtName.type), evtName, unRegFn);
2053
2012
  }
2054
- return true;
2055
- }
2056
- function _createCookieMgrConfig(rootConfig) {
2057
- var cookieMgrCfg = rootConfig.cookieCfg = rootConfig.cookieCfg || {};
2058
- setValue(cookieMgrCfg, "domain", rootConfig.cookieDomain, isNotNullOrUndefined, isNullOrUndefined);
2059
- setValue(cookieMgrCfg, "path", rootConfig.cookiePath || "/", null, isNullOrUndefined);
2060
- if (isNullOrUndefined(cookieMgrCfg[strEnabled])) {
2061
- var cookieEnabled = void 0;
2062
- if (!isUndefined(rootConfig[strIsCookieUseDisabled])) {
2063
- cookieEnabled = !rootConfig[strIsCookieUseDisabled];
2064
- }
2065
- if (!isUndefined(rootConfig[strDisableCookiesUsage])) {
2066
- 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);
2067
2020
  }
2068
- cookieMgrCfg[strEnabled] = cookieEnabled;
2069
2021
  }
2070
- return cookieMgrCfg;
2071
2022
  }
2072
- function safeGetCookieMgr(core, config) {
2073
- var cookieMgr;
2074
- if (core) {
2075
- cookieMgr = core.getCookieMgr();
2076
- }
2077
- else if (config) {
2078
- var cookieCfg = config.cookieCfg;
2079
- if (cookieCfg[strConfigCookieMgr]) {
2080
- cookieMgr = cookieCfg[strConfigCookieMgr];
2023
+ function mergeEvtNamespace(theNamespace, namespaces) {
2024
+ var newNamespaces;
2025
+ if (namespaces) {
2026
+ if (isArray(namespaces)) {
2027
+ newNamespaces = [theNamespace].concat(namespaces);
2081
2028
  }
2082
2029
  else {
2083
- cookieMgr = createCookieMgr(config);
2030
+ newNamespaces = [theNamespace, namespaces];
2084
2031
  }
2032
+ newNamespaces = (_getEvtNamespace("xx", newNamespaces).ns).split(".");
2085
2033
  }
2086
- if (!cookieMgr) {
2087
- cookieMgr = _gblCookieMgr(config, (core || {}).logger);
2034
+ else {
2035
+ newNamespaces = theNamespace;
2088
2036
  }
2089
- return cookieMgr;
2037
+ return newNamespaces;
2090
2038
  }
2091
- function createCookieMgr(rootConfig, logger) {
2092
- var cookieMgrConfig = _createCookieMgrConfig(rootConfig || _globalCookieConfig);
2093
- var _path = cookieMgrConfig.path || "/";
2094
- var _domain = cookieMgrConfig.domain;
2095
- var _enabled = cookieMgrConfig[strEnabled] !== false;
2096
- var cookieMgr = {
2097
- isEnabled: function () {
2098
- var enabled = _enabled && areCookiesSupported(logger);
2099
- var gblManager = _globalCookieConfig[strConfigCookieMgr];
2100
- if (enabled && gblManager && cookieMgr !== gblManager) {
2101
- enabled = _isMgrEnabled(gblManager);
2102
- }
2103
- return enabled;
2104
- },
2105
- setEnabled: function (value) {
2106
- _enabled = value !== false;
2107
- },
2108
- set: function (name, value, maxAgeSec, domain, path) {
2109
- var result = false;
2110
- if (_isMgrEnabled(cookieMgr)) {
2111
- var values = {};
2112
- var theValue = strTrim(value || strEmpty);
2113
- var idx = theValue.indexOf(";");
2114
- if (idx !== -1) {
2115
- theValue = strTrim(value.substring(0, idx));
2116
- values = _extractParts(value.substring(idx + 1));
2117
- }
2118
- setValue(values, "domain", domain || _domain, isTruthy, isUndefined);
2119
- if (!isNullOrUndefined(maxAgeSec)) {
2120
- var _isIE = isIE();
2121
- if (isUndefined(values[strExpires])) {
2122
- var nowMs = dateNow();
2123
- var expireMs = nowMs + (maxAgeSec * 1000);
2124
- if (expireMs > 0) {
2125
- var expiry = new Date();
2126
- expiry.setTime(expireMs);
2127
- setValue(values, strExpires, _formatDate(expiry, !_isIE ? strToUTCString : strToGMTString) || _formatDate(expiry, _isIE ? strToGMTString : strToUTCString) || strEmpty, isTruthy);
2128
- }
2129
- }
2130
- if (!_isIE) {
2131
- setValue(values, "max-age", strEmpty + maxAgeSec, null, isUndefined);
2132
- }
2133
- }
2134
- var location_1 = getLocation();
2135
- if (location_1 && location_1.protocol === "https:") {
2136
- setValue(values, "secure", null, null, isUndefined);
2137
- if (_allowUaSameSite === null) {
2138
- _allowUaSameSite = !uaDisallowsSameSiteNone((getNavigator() || {}).userAgent);
2139
- }
2140
- if (_allowUaSameSite) {
2141
- setValue(values, "SameSite", "None", null, isUndefined);
2142
- }
2143
- }
2144
- setValue(values, "path", path || _path, null, isUndefined);
2145
- var setCookieFn = cookieMgrConfig.setCookie || _setCookieValue;
2146
- setCookieFn(name, _formatCookieValue(theValue, values));
2147
- result = true;
2148
- }
2149
- return result;
2150
- },
2151
- get: function (name) {
2152
- var value = strEmpty;
2153
- if (_isMgrEnabled(cookieMgr)) {
2154
- value = (cookieMgrConfig.getCookie || _getCookieValue)(name);
2155
- }
2156
- return value;
2157
- },
2158
- del: function (name, path) {
2159
- var result = false;
2160
- if (_isMgrEnabled(cookieMgr)) {
2161
- result = cookieMgr.purge(name, path);
2162
- }
2163
- return result;
2164
- },
2165
- purge: function (name, path) {
2166
- var _a;
2167
- var result = false;
2168
- if (areCookiesSupported(logger)) {
2169
- var values = (_a = {},
2170
- _a["path"] = path ? path : "/",
2171
- _a[strExpires] = "Thu, 01 Jan 1970 00:00:01 GMT",
2172
- _a);
2173
- if (!isIE()) {
2174
- values["max-age"] = "0";
2175
- }
2176
- var delCookie = cookieMgrConfig.delCookie || _setCookieValue;
2177
- delCookie(name, _formatCookieValue(strEmpty, values));
2178
- result = true;
2179
- }
2180
- return result;
2181
- }
2182
- };
2183
- cookieMgr[strConfigCookieMgr] = cookieMgr;
2184
- return cookieMgr;
2185
- }
2186
- function areCookiesSupported(logger) {
2187
- if (_supportsCookies === null) {
2188
- _supportsCookies = false;
2039
+ function eventOn(target, eventName, handlerRef, evtNamespace, useCapture) {
2040
+ if (useCapture === void 0) { useCapture = false; }
2041
+ var result = false;
2042
+ if (target) {
2189
2043
  try {
2190
- var doc = _doc || {};
2191
- _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
+ }
2192
2055
  }
2193
2056
  catch (e) {
2194
- _throwInternal(logger, 2 , 68 , "Cannot access document.cookie - " + getExceptionName(e), { exception: dumpObj(e) });
2195
2057
  }
2196
2058
  }
2197
- return _supportsCookies;
2059
+ return result;
2198
2060
  }
2199
- function _extractParts(theValue) {
2200
- var values = {};
2201
- if (theValue && theValue.length) {
2202
- var parts = strTrim(theValue).split(";");
2203
- arrForEach(parts, function (thePart) {
2204
- thePart = strTrim(thePart || strEmpty);
2205
- if (thePart) {
2206
- var idx = thePart.indexOf("=");
2207
- if (idx === -1) {
2208
- values[thePart] = null;
2209
- }
2210
- else {
2211
- 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;
2212
2071
  }
2072
+ return false;
2073
+ });
2074
+ if (!found_1) {
2075
+ _doDetach(target, evtName_1, handlerRef, useCapture);
2213
2076
  }
2214
- });
2077
+ }
2078
+ catch (e) {
2079
+ }
2215
2080
  }
2216
- return values;
2217
2081
  }
2218
- function _formatDate(theDate, func) {
2219
- if (isFunction(theDate[func])) {
2220
- return theDate[func]();
2221
- }
2222
- return null;
2082
+ function attachEvent(obj, eventNameWithoutOn, handlerRef, useCapture) {
2083
+ if (useCapture === void 0) { useCapture = false; }
2084
+ return eventOn(obj, eventNameWithoutOn, handlerRef, null, useCapture);
2223
2085
  }
2224
- function _formatCookieValue(value, values) {
2225
- var cookieValue = value || strEmpty;
2226
- objForEachKey(values, function (name, theValue) {
2227
- cookieValue += "; " + name + (!isNullOrUndefined(theValue) ? "=" + theValue : strEmpty);
2228
- });
2229
- return cookieValue;
2086
+ function detachEvent(obj, eventNameWithoutOn, handlerRef, useCapture) {
2087
+ if (useCapture === void 0) { useCapture = false; }
2088
+ eventOff(obj, eventNameWithoutOn, handlerRef, null, useCapture);
2230
2089
  }
2231
- function _getCookieValue(name) {
2232
- var cookieValue = strEmpty;
2233
- if (_doc) {
2234
- var theCookie = _doc[strCookie] || strEmpty;
2235
- if (_parsedCookieValue !== theCookie) {
2236
- _cookieCache = _extractParts(theCookie);
2237
- _parsedCookieValue = theCookie;
2238
- }
2239
- 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;
2240
2096
  }
2241
- return cookieValue;
2242
- }
2243
- function _setCookieValue(name, cookieValue) {
2244
- if (_doc) {
2245
- _doc[strCookie] = name + "=" + cookieValue;
2097
+ var doc = getDocument();
2098
+ if (doc) {
2099
+ result = eventOn(doc, eventName, callback, evtNamespace) || result;
2246
2100
  }
2101
+ return result;
2247
2102
  }
2248
- function uaDisallowsSameSiteNone(userAgent) {
2249
- if (!isString(userAgent)) {
2250
- return false;
2251
- }
2252
- if (strContains(userAgent, "CPU iPhone OS 12") || strContains(userAgent, "iPad; CPU OS 12")) {
2253
- return true;
2254
- }
2255
- if (strContains(userAgent, "Macintosh; Intel Mac OS X 10_14") && strContains(userAgent, "Version/") && strContains(userAgent, "Safari")) {
2256
- return true;
2257
- }
2258
- if (strContains(userAgent, "Macintosh; Intel Mac OS X 10_14") && strEndsWith(userAgent, "AppleWebKit/605.1.15 (KHTML, like Gecko)")) {
2259
- 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);
2260
2108
  }
2261
- if (strContains(userAgent, "Chrome/5") || strContains(userAgent, "Chrome/6")) {
2262
- return true;
2109
+ var doc = getDocument();
2110
+ if (doc) {
2111
+ eventOff(doc, eventName, callback, evtNamespace);
2263
2112
  }
2264
- if (strContains(userAgent, "UnrealEngine") && !strContains(userAgent, "Chrome")) {
2265
- return true;
2113
+ }
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
+ }
2122
+ }
2123
+ });
2266
2124
  }
2267
- if (strContains(userAgent, "UCBrowser/12") || strContains(userAgent, "UCBrowser/11")) {
2268
- return true;
2125
+ return added;
2126
+ }
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
+ }
2269
2134
  }
2270
- return false;
2135
+ return added;
2271
2136
  }
2272
-
2273
- var strIKey = "iKey";
2274
- var strExtensionConfig = "extensionConfig";
2275
-
2276
- var ChannelControllerPriority = 500;
2277
- var ChannelValidationMessage = "Channel has invalid priority - ";
2278
- function _addChannelQueue(channelQueue, queue, config, core) {
2279
- if (queue && isArray(queue) && queue.length > 0) {
2280
- queue = queue.sort(function (a, b) {
2281
- return a.priority - b.priority;
2282
- });
2283
- arrForEach(queue, function (queueItem) {
2284
- if (queueItem.priority < ChannelControllerPriority) {
2285
- throwError(ChannelValidationMessage + queueItem.identifier);
2137
+ function removeEventListeners(events, listener, evtNamespace) {
2138
+ if (events && isArray(events)) {
2139
+ arrForEach(events, function (name) {
2140
+ if (name) {
2141
+ removeEventHandler(name, listener, evtNamespace);
2286
2142
  }
2287
2143
  });
2288
- channelQueue.push({
2289
- queue: objFreeze(queue),
2290
- chain: createTelemetryProxyChain(queue, config, core)
2291
- });
2292
2144
  }
2293
2145
  }
2294
- function createChannelControllerPlugin(channelQueue, core) {
2295
- var _a;
2296
- function _getTelCtx() {
2297
- return createProcessTelemetryContext(null, core.config, core, null);
2298
- }
2299
- function _processChannelQueue(theChannels, itemCtx, processFn, onComplete) {
2300
- var waiting = theChannels ? (theChannels.length + 1) : 1;
2301
- function _runChainOnComplete() {
2302
- waiting--;
2303
- if (waiting === 0) {
2304
- onComplete && onComplete();
2305
- onComplete = null;
2306
- }
2307
- }
2308
- if (waiting > 0) {
2309
- arrForEach(theChannels, function (channels) {
2310
- if (channels && channels.queue.length > 0) {
2311
- var channelChain = channels.chain;
2312
- var chainCtx = itemCtx.createNew(channelChain);
2313
- chainCtx.onComplete(_runChainOnComplete);
2314
- processFn(chainCtx);
2315
- }
2316
- else {
2317
- waiting--;
2318
- }
2319
- });
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);
2320
2157
  }
2321
- _runChainOnComplete();
2322
- }
2323
- function _doUpdate(updateCtx, updateState) {
2324
- var theUpdateState = updateState || {
2325
- reason: 0
2326
- };
2327
- _processChannelQueue(channelQueue, updateCtx, function (chainCtx) {
2328
- chainCtx[strProcessNext](theUpdateState);
2329
- }, function () {
2330
- updateCtx[strProcessNext](theUpdateState);
2331
- });
2332
- return true;
2333
2158
  }
2334
- function _doTeardown(unloadCtx, unloadState) {
2335
- var theUnloadState = unloadState || {
2336
- reason: 0 ,
2337
- isAsync: false
2338
- };
2339
- _processChannelQueue(channelQueue, unloadCtx, function (chainCtx) {
2340
- chainCtx[strProcessNext](theUnloadState);
2341
- }, function () {
2342
- unloadCtx[strProcessNext](theUnloadState);
2343
- isInitialized = false;
2344
- });
2345
- return true;
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;
2346
2163
  }
2347
- function _getChannel(pluginIdentifier) {
2348
- var thePlugin = null;
2349
- if (channelQueue && channelQueue.length > 0) {
2350
- arrForEach(channelQueue, function (channels) {
2351
- if (channels && channels.queue.length > 0) {
2352
- arrForEach(channels.queue, function (ext) {
2353
- if (ext.identifier === pluginIdentifier) {
2354
- thePlugin = ext;
2355
- return -1;
2356
- }
2357
- });
2358
- if (thePlugin) {
2359
- return -1;
2360
- }
2361
- }
2362
- });
2363
- }
2364
- return thePlugin;
2164
+ if (!pageUnloadAdded && excludeEvents) {
2165
+ pageUnloadAdded = addPageHideEventListener(listener, null, evtNamespace);
2365
2166
  }
2366
- var isInitialized = false;
2367
- var channelController = (_a = {
2368
- identifier: "ChannelControllerPlugin",
2369
- priority: ChannelControllerPriority,
2370
- initialize: function (config, core, extensions, pluginChain) {
2371
- isInitialized = true;
2372
- arrForEach(channelQueue, function (channels) {
2373
- if (channels && channels.queue.length > 0) {
2374
- initializePlugins(createProcessTelemetryContext(channels.chain, config, core), extensions);
2375
- }
2376
- });
2377
- },
2378
- isInitialized: function () {
2379
- return isInitialized;
2380
- },
2381
- processTelemetry: function (item, itemCtx) {
2382
- _processChannelQueue(channelQueue, itemCtx || _getTelCtx(), function (chainCtx) {
2383
- chainCtx[strProcessNext](item);
2384
- }, function () {
2385
- itemCtx[strProcessNext](item);
2386
- });
2387
- },
2388
- update: _doUpdate
2389
- },
2390
- _a[strPause] = function () {
2391
- _processChannelQueue(channelQueue, _getTelCtx(), function (chainCtx) {
2392
- chainCtx.iterate(function (plugin) {
2393
- plugin[strPause] && plugin[strPause]();
2394
- });
2395
- }, null);
2396
- },
2397
- _a[strResume] = function () {
2398
- _processChannelQueue(channelQueue, _getTelCtx(), function (chainCtx) {
2399
- chainCtx.iterate(function (plugin) {
2400
- plugin[strResume] && plugin[strResume]();
2401
- });
2402
- }, null);
2403
- },
2404
- _a[strTeardown] = _doTeardown,
2405
- _a.getChannel = _getChannel,
2406
- _a.flush = function (isAsync, callBack, sendReason, cbTimeout) {
2407
- var waiting = 1;
2408
- var doneIterating = false;
2409
- var cbTimer = null;
2410
- cbTimeout = cbTimeout || 5000;
2411
- function doCallback() {
2412
- waiting--;
2413
- if (doneIterating && waiting === 0) {
2414
- if (cbTimer) {
2415
- clearTimeout(cbTimer);
2416
- cbTimer = null;
2417
- }
2418
- callBack && callBack(doneIterating);
2419
- callBack = null;
2420
- }
2421
- }
2422
- _processChannelQueue(channelQueue, _getTelCtx(), function (chainCtx) {
2423
- chainCtx.iterate(function (plugin) {
2424
- if (plugin.flush) {
2425
- waiting++;
2426
- var handled_1 = false;
2427
- if (!plugin.flush(isAsync, function () {
2428
- handled_1 = true;
2429
- doCallback();
2430
- }, sendReason)) {
2431
- if (!handled_1) {
2432
- if (isAsync && cbTimer == null) {
2433
- cbTimer = setTimeout(function () {
2434
- cbTimer = null;
2435
- doCallback();
2436
- }, cbTimeout);
2437
- }
2438
- else {
2439
- doCallback();
2440
- }
2441
- }
2442
- }
2443
- }
2444
- });
2445
- }, function () {
2446
- doneIterating = true;
2447
- doCallback();
2448
- });
2449
- return true;
2450
- },
2451
- _a._setQueue = function (queue) {
2452
- channelQueue = queue;
2453
- },
2454
- _a);
2455
- return channelController;
2167
+ return pageUnloadAdded;
2456
2168
  }
2457
- function createChannelQueues(channels, extensions, config, core) {
2458
- var channelQueue = [];
2459
- if (channels) {
2460
- arrForEach(channels, function (queue) { return _addChannelQueue(channelQueue, queue, config, core); });
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);
2179
+ }
2461
2180
  }
2462
- if (extensions) {
2463
- var extensionQueue_1 = [];
2464
- arrForEach(extensions, function (plugin) {
2465
- if (plugin.priority > ChannelControllerPriority) {
2466
- extensionQueue_1.push(plugin);
2467
- }
2468
- });
2469
- _addChannelQueue(channelQueue, extensionQueue_1, config, core);
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);
2470
2186
  }
2471
- return channelQueue;
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);
2472
2193
  }
2473
2194
 
2474
- function createUnloadHandlerContainer() {
2475
- var handlers = [];
2476
- function _addHandler(handler) {
2477
- if (handler) {
2478
- handlers.push(handler);
2479
- }
2195
+ function newGuid() {
2196
+ function randomHexDigit() {
2197
+ return randomValue(15);
2480
2198
  }
2481
- function _runHandlers(unloadCtx, unloadState) {
2482
- arrForEach(handlers, function (handler) {
2483
- try {
2484
- handler(unloadCtx, unloadState);
2485
- }
2486
- catch (e) {
2487
- _throwInternal(unloadCtx.diagLog(), 2 , 73 , "Unexpected error calling unload handler - " + dumpObj(e));
2488
- }
2489
- });
2490
- handlers = [];
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();
2491
2208
  }
2492
- return {
2493
- add: _addHandler,
2494
- run: _runHandlers
2495
- };
2209
+ return dateNow();
2496
2210
  }
2497
-
2498
- var strGetPlugin = "getPlugin";
2499
- var BaseTelemetryPlugin = /** @class */ (function () {
2500
- function BaseTelemetryPlugin() {
2501
- var _self = this;
2502
- var _isinitialized;
2503
- var _rootCtx;
2504
- var _nextPlugin;
2505
- var _unloadHandlerContainer;
2506
- var _hooks;
2507
- _initDefaults();
2508
- dynamicProto(BaseTelemetryPlugin, _self, function (_self) {
2509
- _self.initialize = function (config, core, extensions, pluginChain) {
2510
- _setDefaults(config, core, pluginChain);
2511
- _isinitialized = true;
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;
2512
3036
  };
2513
3037
  _self.teardown = function (unloadCtx, unloadState) {
2514
3038
  var core = _self.core;
@@ -2780,6 +3304,7 @@
2780
3304
  var _evtNamespace;
2781
3305
  var _unloadHandlers;
2782
3306
  var _debugListener;
3307
+ var _traceCtx;
2783
3308
  var _internalLogPoller = 0;
2784
3309
  dynamicProto(BaseCore, this, function (_self) {
2785
3310
  _initDefaults();
@@ -2982,6 +3507,15 @@
2982
3507
  return _evtNamespace;
2983
3508
  };
2984
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
+ };
2985
3519
  proxyFunctionAs(_self, "addUnloadCb", function () { return _unloadHandlers; }, "add");
2986
3520
  function _initDefaults() {
2987
3521
  _isInitialized = false;
@@ -3004,6 +3538,7 @@
3004
3538
  _internalLogsEventName = null;
3005
3539
  _evtNamespace = createUniqueNamespace("AIBaseCore", true);
3006
3540
  _unloadHandlers = createUnloadHandlerContainer();
3541
+ _traceCtx = null;
3007
3542
  }
3008
3543
  function _createTelCtx() {
3009
3544
  return createProcessTelemetryContext(_getPluginChain(), _self.config, _self);
@@ -3101,549 +3636,201 @@
3101
3636
  arrForEach(_configExtensions, function (plugin, idx) {
3102
3637
  if (!_isPluginPresent(plugin, thePlugins)) {
3103
3638
  newConfigExtensions.push(plugin);
3104
- }
3105
- else {
3106
- removed = true;
3107
- }
3108
- });
3109
- _configExtensions = newConfigExtensions;
3110
- var newChannelConfig = [];
3111
- if (_channelConfig) {
3112
- arrForEach(_channelConfig, function (queue, idx) {
3113
- var newQueue = [];
3114
- arrForEach(queue, function (channel) {
3115
- if (!_isPluginPresent(channel, thePlugins)) {
3116
- newQueue.push(channel);
3117
- }
3118
- else {
3119
- removed = true;
3120
- }
3121
- });
3122
- newChannelConfig.push(newQueue);
3123
- });
3124
- _channelConfig = newChannelConfig;
3125
- }
3126
- removeComplete && removeComplete(removed);
3127
- });
3128
- unloadCtx.processNext(unloadState);
3129
- }
3130
- else {
3131
- removeComplete(false);
3132
- }
3133
- }
3134
- function _flushInternalLogs() {
3135
- var queue = _self.logger ? _self.logger.queue : [];
3136
- if (queue) {
3137
- arrForEach(queue, function (logMessage) {
3138
- var item = {
3139
- name: _internalLogsEventName ? _internalLogsEventName : "InternalMessageId: " + logMessage.messageId,
3140
- iKey: _self.config.instrumentationKey,
3141
- time: toISOString(new Date()),
3142
- baseType: _InternalLogMessage.dataType,
3143
- baseData: { message: logMessage.message }
3144
- };
3145
- _self.track(item);
3146
- });
3147
- queue.length = 0;
3148
- }
3149
- }
3150
- function _flushChannels(isAsync, callBack, sendReason, cbTimeout) {
3151
- if (_channelControl) {
3152
- return _channelControl.flush(isAsync, callBack, sendReason || 6 , cbTimeout);
3153
- }
3154
- callBack && callBack(false);
3155
- return true;
3156
- }
3157
- function _initDebugListener(config) {
3158
- if (config.disableDbgExt === true && _debugListener) {
3159
- _notificationManager[strRemoveNotificationListener](_debugListener);
3160
- _debugListener = null;
3161
- }
3162
- if (_notificationManager && !_debugListener && config.disableDbgExt !== true) {
3163
- _debugListener = getDebugListener(config);
3164
- _notificationManager[strAddNotificationListener](_debugListener);
3165
- }
3166
- }
3167
- function _initPerfManager(config) {
3168
- if (!config.enablePerfMgr && _cfgPerfManager) {
3169
- _cfgPerfManager = null;
3170
- }
3171
- if (config.enablePerfMgr) {
3172
- setValue(_self.config, "createPerfMgr", _createPerfManager);
3173
- }
3174
- }
3175
- function _initExtConfig(config) {
3176
- var extConfig = getSetValue(config, strExtensionConfig);
3177
- extConfig.NotificationManager = _notificationManager;
3178
- }
3179
- function _doUpdate(updateState) {
3180
- var updateCtx = createProcessTelemetryUpdateContext(_getPluginChain(), _self);
3181
- if (!_self._updateHook || _self._updateHook(updateCtx, updateState) !== true) {
3182
- updateCtx.processNext(updateState);
3183
- }
3184
- }
3185
- function _logOrThrowError(message) {
3186
- var logger = _self.logger;
3187
- if (logger) {
3188
- _throwInternal(logger, 2 , 73 , message);
3189
- }
3190
- else {
3191
- throwError(message);
3192
- }
3193
- }
3194
- });
3195
- }
3196
- return BaseCore;
3197
- }());
3198
-
3199
- function _runListeners(listeners, name, isAsync, callback) {
3200
- arrForEach(listeners, function (listener) {
3201
- if (listener && listener[name]) {
3202
- if (isAsync) {
3203
- setTimeout(function () { return callback(listener); }, 0);
3204
- }
3205
- else {
3206
- try {
3207
- callback(listener);
3208
- }
3209
- catch (e) {
3210
- }
3211
- }
3212
- }
3213
- });
3214
- }
3215
- var NotificationManager = /** @class */ (function () {
3216
- function NotificationManager(config) {
3217
- this.listeners = [];
3218
- var perfEvtsSendAll = !!(config || {}).perfEvtsSendAll;
3219
- dynamicProto(NotificationManager, this, function (_self) {
3220
- _self[strAddNotificationListener] = function (listener) {
3221
- _self.listeners.push(listener);
3222
- };
3223
- _self[strRemoveNotificationListener] = function (listener) {
3224
- var index = arrIndexOf(_self.listeners, listener);
3225
- while (index > -1) {
3226
- _self.listeners.splice(index, 1);
3227
- index = arrIndexOf(_self.listeners, listener);
3228
- }
3229
- };
3230
- _self[strEventsSent] = function (events) {
3231
- _runListeners(_self.listeners, strEventsSent, true, function (listener) {
3232
- listener[strEventsSent](events);
3233
- });
3234
- };
3235
- _self[strEventsDiscarded] = function (events, reason) {
3236
- _runListeners(_self.listeners, strEventsDiscarded, true, function (listener) {
3237
- listener[strEventsDiscarded](events, reason);
3238
- });
3239
- };
3240
- _self[strEventsSendRequest] = function (sendReason, isAsync) {
3241
- _runListeners(_self.listeners, strEventsSendRequest, isAsync, function (listener) {
3242
- listener[strEventsSendRequest](sendReason, isAsync);
3243
- });
3244
- };
3245
- _self[strPerfEvent] = function (perfEvent) {
3246
- if (perfEvent) {
3247
- if (perfEvtsSendAll || !perfEvent.isChildEvt()) {
3248
- _runListeners(_self.listeners, strPerfEvent, false, function (listener) {
3249
- if (perfEvent.isAsync) {
3250
- setTimeout(function () { return listener[strPerfEvent](perfEvent); }, 0);
3251
- }
3252
- else {
3253
- listener[strPerfEvent](perfEvent);
3254
- }
3255
- });
3256
- }
3257
- }
3258
- };
3259
- });
3260
- }
3261
- return NotificationManager;
3262
- }());
3263
-
3264
- var AppInsightsCore$2 = /** @class */ (function (_super) {
3265
- __extendsFn(AppInsightsCore, _super);
3266
- function AppInsightsCore() {
3267
- var _this = _super.call(this) || this;
3268
- dynamicProto(AppInsightsCore, _this, function (_self, _base) {
3269
- _self.initialize = function (config, extensions, logger, notificationManager) {
3270
- _base.initialize(config, extensions, logger || new DiagnosticLogger(config), notificationManager || new NotificationManager(config));
3271
- };
3272
- _self.track = function (telemetryItem) {
3273
- doPerf(_self.getPerfMgr(), function () { return "AppInsightsCore:track"; }, function () {
3274
- if (telemetryItem === null) {
3275
- _notifyInvalidEvent(telemetryItem);
3276
- throwError("Invalid telemetry item");
3277
- }
3278
- _validateTelemetryItem(telemetryItem);
3279
- _base.track(telemetryItem);
3280
- }, function () { return ({ item: telemetryItem }); }, !(telemetryItem.sync));
3281
- };
3282
- function _validateTelemetryItem(telemetryItem) {
3283
- if (isNullOrUndefined(telemetryItem.name)) {
3284
- _notifyInvalidEvent(telemetryItem);
3285
- 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);
3286
3667
  }
3287
3668
  }
3288
- function _notifyInvalidEvent(telemetryItem) {
3289
- var manager = _self.getNotifyMgr();
3290
- if (manager) {
3291
- 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;
3292
3683
  }
3293
3684
  }
3294
- });
3295
- return _this;
3296
- }
3297
- return AppInsightsCore;
3298
- }(BaseCore$2));
3299
-
3300
- var strOnPrefix = "on";
3301
- var strAttachEvent = "attachEvent";
3302
- var strAddEventHelper = "addEventListener";
3303
- var strDetachEvent = "detachEvent";
3304
- var strRemoveEventListener = "removeEventListener";
3305
- var strEvents = "events";
3306
- var strVisibilityChangeEvt = "visibilitychange";
3307
- var strPageHide = "pagehide";
3308
- var strPageShow = "pageshow";
3309
- var strUnload = "unload";
3310
- var strBeforeUnload = "beforeunload";
3311
- var strPageHideNamespace = createUniqueNamespace("aiEvtPageHide");
3312
- var strPageShowNamespace = createUniqueNamespace("aiEvtPageShow");
3313
- var rRemoveEmptyNs = /\.[\.]+/g;
3314
- var rRemoveTrailingEmptyNs = /[\.]+$/;
3315
- var _guid = 1;
3316
- var elmNodeData = createElmNodeData("events");
3317
- var eventNamespace = /^([^.]*)(?:\.(.+)|)/;
3318
- function _normalizeNamespace(name) {
3319
- if (name && name.replace) {
3320
- return name.replace(/^\s*\.*|\.*\s*$/g, "");
3321
- }
3322
- return name;
3323
- }
3324
- function _getEvtNamespace(eventName, evtNamespace) {
3325
- if (evtNamespace) {
3326
- var theNamespace_1 = "";
3327
- if (isArray(evtNamespace)) {
3328
- theNamespace_1 = "";
3329
- arrForEach(evtNamespace, function (name) {
3330
- name = _normalizeNamespace(name);
3331
- if (name) {
3332
- if (name[0] !== ".") {
3333
- name = "." + name;
3334
- }
3335
- theNamespace_1 += name;
3685
+ function _flushChannels(isAsync, callBack, sendReason, cbTimeout) {
3686
+ if (_channelControl) {
3687
+ return _channelControl.flush(isAsync, callBack, sendReason || 6 , cbTimeout);
3336
3688
  }
3337
- });
3338
- }
3339
- else {
3340
- theNamespace_1 = _normalizeNamespace(evtNamespace);
3341
- }
3342
- if (theNamespace_1) {
3343
- if (theNamespace_1[0] !== ".") {
3344
- theNamespace_1 = "." + theNamespace_1;
3689
+ callBack && callBack(false);
3690
+ return true;
3345
3691
  }
3346
- eventName = (eventName || "") + theNamespace_1;
3347
- }
3348
- }
3349
- var parsedEvent = (eventNamespace.exec(eventName || "") || []);
3350
- return {
3351
- type: parsedEvent[1],
3352
- ns: ((parsedEvent[2] || "").replace(rRemoveEmptyNs, ".").replace(rRemoveTrailingEmptyNs, "").split(".").sort()).join(".")
3353
- };
3354
- }
3355
- function __getRegisteredEvents(target, eventName, evtNamespace) {
3356
- var theEvents = [];
3357
- var eventCache = elmNodeData.get(target, strEvents, {}, false);
3358
- var evtName = _getEvtNamespace(eventName, evtNamespace);
3359
- objForEachKey(eventCache, function (evtType, registeredEvents) {
3360
- arrForEach(registeredEvents, function (value) {
3361
- if (!evtName.type || evtName.type === value.evtName.type) {
3362
- if (!evtName.ns || evtName.ns === evtName.ns) {
3363
- theEvents.push({
3364
- name: value.evtName.type + (value.evtName.ns ? "." + value.evtName.ns : ""),
3365
- handler: value.handler
3366
- });
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);
3367
3700
  }
3368
3701
  }
3369
- });
3370
- });
3371
- return theEvents;
3372
- }
3373
- function _getRegisteredEvents(target, evtName, addDefault) {
3374
- if (addDefault === void 0) { addDefault = true; }
3375
- var aiEvts = elmNodeData.get(target, strEvents, {}, addDefault);
3376
- var registeredEvents = aiEvts[evtName];
3377
- if (!registeredEvents) {
3378
- registeredEvents = aiEvts[evtName] = [];
3379
- }
3380
- return registeredEvents;
3381
- }
3382
- function _doDetach(obj, evtName, handlerRef, useCapture) {
3383
- if (obj && evtName && evtName.type) {
3384
- if (obj[strRemoveEventListener]) {
3385
- obj[strRemoveEventListener](evtName.type, handlerRef, useCapture);
3386
- }
3387
- else if (obj[strDetachEvent]) {
3388
- obj[strDetachEvent](strOnPrefix + evtName.type, handlerRef);
3389
- }
3390
- }
3391
- }
3392
- function _doAttach(obj, evtName, handlerRef, useCapture) {
3393
- var result = false;
3394
- if (obj && evtName && evtName.type && handlerRef) {
3395
- if (obj[strAddEventHelper]) {
3396
- obj[strAddEventHelper](evtName.type, handlerRef, useCapture);
3397
- result = true;
3398
- }
3399
- else if (obj[strAttachEvent]) {
3400
- obj[strAttachEvent](strOnPrefix + evtName.type, handlerRef);
3401
- result = true;
3402
- }
3403
- }
3404
- return result;
3405
- }
3406
- function _doUnregister(target, events, evtName, unRegFn) {
3407
- var idx = events.length;
3408
- while (idx--) {
3409
- var theEvent = events[idx];
3410
- if (theEvent) {
3411
- if (!evtName.ns || evtName.ns === theEvent.evtName.ns) {
3412
- if (!unRegFn || unRegFn(theEvent)) {
3413
- _doDetach(target, theEvent.evtName, theEvent.handler, theEvent.capture);
3414
- 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);
3415
3708
  }
3416
3709
  }
3417
- }
3418
- }
3419
- }
3420
- function _unregisterEvents(target, evtName, unRegFn) {
3421
- if (evtName.type) {
3422
- _doUnregister(target, _getRegisteredEvents(target, evtName.type), evtName, unRegFn);
3423
- }
3424
- else {
3425
- var eventCache = elmNodeData.get(target, strEvents, {});
3426
- objForEachKey(eventCache, function (evtType, events) {
3427
- _doUnregister(target, events, evtName, unRegFn);
3428
- });
3429
- if (objKeys(eventCache).length === 0) {
3430
- elmNodeData.kill(target, strEvents);
3431
- }
3432
- }
3433
- }
3434
- function mergeEvtNamespace(theNamespace, namespaces) {
3435
- var newNamespaces;
3436
- if (namespaces) {
3437
- if (isArray(namespaces)) {
3438
- newNamespaces = [theNamespace].concat(namespaces);
3439
- }
3440
- else {
3441
- newNamespaces = [theNamespace, namespaces];
3442
- }
3443
- newNamespaces = (_getEvtNamespace("xx", newNamespaces).ns).split(".");
3444
- }
3445
- else {
3446
- newNamespaces = theNamespace;
3447
- }
3448
- return newNamespaces;
3449
- }
3450
- function eventOn(target, eventName, handlerRef, evtNamespace, useCapture) {
3451
- if (useCapture === void 0) { useCapture = false; }
3452
- var result = false;
3453
- if (target) {
3454
- try {
3455
- var evtName = _getEvtNamespace(eventName, evtNamespace);
3456
- result = _doAttach(target, evtName, handlerRef, useCapture);
3457
- if (result && elmNodeData.accept(target)) {
3458
- var registeredEvent = {
3459
- guid: _guid++,
3460
- evtName: evtName,
3461
- handler: handlerRef,
3462
- capture: useCapture
3463
- };
3464
- _getRegisteredEvents(target, evtName.type).push(registeredEvent);
3710
+ function _initExtConfig(config) {
3711
+ var extConfig = getSetValue(config, strExtensionConfig);
3712
+ extConfig.NotificationManager = _notificationManager;
3465
3713
  }
3466
- }
3467
- catch (e) {
3468
- }
3469
- }
3470
- return result;
3471
- }
3472
- function eventOff(target, eventName, handlerRef, evtNamespace, useCapture) {
3473
- if (useCapture === void 0) { useCapture = false; }
3474
- if (target) {
3475
- try {
3476
- var evtName_1 = _getEvtNamespace(eventName, evtNamespace);
3477
- var found_1 = false;
3478
- _unregisterEvents(target, evtName_1, function (regEvent) {
3479
- if ((evtName_1.ns && !handlerRef) || regEvent.handler === handlerRef) {
3480
- found_1 = true;
3481
- return true;
3482
- }
3483
- return false;
3484
- });
3485
- if (!found_1) {
3486
- _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
+ }
3487
3719
  }
3488
- }
3489
- catch (e) {
3490
- }
3491
- }
3492
- }
3493
- function attachEvent(obj, eventNameWithoutOn, handlerRef, useCapture) {
3494
- if (useCapture === void 0) { useCapture = false; }
3495
- return eventOn(obj, eventNameWithoutOn, handlerRef, null, useCapture);
3496
- }
3497
- function detachEvent(obj, eventNameWithoutOn, handlerRef, useCapture) {
3498
- if (useCapture === void 0) { useCapture = false; }
3499
- eventOff(obj, eventNameWithoutOn, handlerRef, null, useCapture);
3500
- }
3501
- function addEventHandler(eventName, callback, evtNamespace) {
3502
- var result = false;
3503
- var w = getWindow();
3504
- if (w) {
3505
- result = eventOn(w, eventName, callback, evtNamespace);
3506
- result = eventOn(w["body"], eventName, callback, evtNamespace) || result;
3507
- }
3508
- var doc = getDocument();
3509
- if (doc) {
3510
- result = eventOn(doc, eventName, callback, evtNamespace) || result;
3511
- }
3512
- return result;
3513
- }
3514
- function removeEventHandler(eventName, callback, evtNamespace) {
3515
- var w = getWindow();
3516
- if (w) {
3517
- eventOff(w, eventName, callback, evtNamespace);
3518
- eventOff(w["body"], eventName, callback, evtNamespace);
3519
- }
3520
- var doc = getDocument();
3521
- if (doc) {
3522
- eventOff(doc, eventName, callback, evtNamespace);
3523
- }
3524
- }
3525
- function _addEventListeners(events, listener, excludeEvents, evtNamespace) {
3526
- var added = false;
3527
- if (listener && events && events.length > 0) {
3528
- arrForEach(events, function (name) {
3529
- if (name) {
3530
- if (!excludeEvents || arrIndexOf(excludeEvents, name) === -1) {
3531
- 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);
3532
3727
  }
3533
3728
  }
3534
3729
  });
3535
3730
  }
3536
- return added;
3537
- }
3538
- function addEventListeners(events, listener, excludeEvents, evtNamespace) {
3539
- var added = false;
3540
- if (listener && events && isArray(events)) {
3541
- added = _addEventListeners(events, listener, excludeEvents, evtNamespace);
3542
- if (!added && excludeEvents && excludeEvents.length > 0) {
3543
- added = _addEventListeners(events, listener, null, evtNamespace);
3544
- }
3545
- }
3546
- return added;
3547
- }
3548
- function removeEventListeners(events, listener, evtNamespace) {
3549
- if (events && isArray(events)) {
3550
- arrForEach(events, function (name) {
3551
- if (name) {
3552
- 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
+ }
3553
3746
  }
3554
- });
3555
- }
3556
- }
3557
- function addPageUnloadEventListener(listener, excludeEvents, evtNamespace) {
3558
- return addEventListeners([strBeforeUnload, strUnload, strPageHide], listener, excludeEvents, evtNamespace);
3559
- }
3560
- function removePageUnloadEventListener(listener, evtNamespace) {
3561
- removeEventListeners([strBeforeUnload, strUnload, strPageHide], listener, evtNamespace);
3562
- }
3563
- function addPageHideEventListener(listener, excludeEvents, evtNamespace) {
3564
- function _handlePageVisibility(evt) {
3565
- var doc = getDocument();
3566
- if (listener && doc && doc.visibilityState === "hidden") {
3567
- listener(evt);
3568
- }
3569
- }
3570
- var newNamespaces = mergeEvtNamespace(strPageHideNamespace, evtNamespace);
3571
- var pageUnloadAdded = _addEventListeners([strPageHide], listener, excludeEvents, newNamespaces);
3572
- if (!excludeEvents || arrIndexOf(excludeEvents, strVisibilityChangeEvt) === -1) {
3573
- pageUnloadAdded = _addEventListeners([strVisibilityChangeEvt], _handlePageVisibility, excludeEvents, newNamespaces) || pageUnloadAdded;
3574
- }
3575
- if (!pageUnloadAdded && excludeEvents) {
3576
- pageUnloadAdded = addPageHideEventListener(listener, null, evtNamespace);
3577
- }
3578
- return pageUnloadAdded;
3579
- }
3580
- function removePageHideEventListener(listener, evtNamespace) {
3581
- var newNamespaces = mergeEvtNamespace(strPageHideNamespace, evtNamespace);
3582
- removeEventListeners([strPageHide], listener, newNamespaces);
3583
- removeEventListeners([strVisibilityChangeEvt], null, newNamespaces);
3584
- }
3585
- function addPageShowEventListener(listener, excludeEvents, evtNamespace) {
3586
- function _handlePageVisibility(evt) {
3587
- var doc = getDocument();
3588
- if (listener && doc && doc.visibilityState === "visible") {
3589
- listener(evt);
3590
3747
  }
3591
- }
3592
- var newNamespaces = mergeEvtNamespace(strPageShowNamespace, evtNamespace);
3593
- var pageShowAdded = _addEventListeners([strPageShow], listener, excludeEvents, newNamespaces);
3594
- pageShowAdded = _addEventListeners([strVisibilityChangeEvt], _handlePageVisibility, excludeEvents, newNamespaces) || pageShowAdded;
3595
- if (!pageShowAdded && excludeEvents) {
3596
- pageShowAdded = addPageShowEventListener(listener, null, evtNamespace);
3597
- }
3598
- return pageShowAdded;
3599
- }
3600
- function removePageShowEventListener(listener, evtNamespace) {
3601
- var newNamespaces = mergeEvtNamespace(strPageShowNamespace, evtNamespace);
3602
- removeEventListeners([strPageShow], listener, newNamespaces);
3603
- removeEventListeners([strVisibilityChangeEvt], null, newNamespaces);
3604
- }
3605
-
3606
- function newGuid() {
3607
- function randomHexDigit() {
3608
- return randomValue(15);
3609
- }
3610
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(GuidRegex, function (c) {
3611
- var r = (randomHexDigit() | 0), v = (c === "x" ? r : r & 0x3 | 0x8);
3612
- return v.toString(16);
3613
3748
  });
3614
3749
  }
3615
- function perfNow() {
3616
- var perf = getPerformance();
3617
- if (perf && perf.now) {
3618
- 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
+ });
3619
3795
  }
3620
- return dateNow();
3621
- }
3622
- function generateW3CId() {
3623
- var hexValues = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"];
3624
- var oct = strEmpty, tmp;
3625
- for (var a = 0; a < 4; a++) {
3626
- tmp = random32();
3627
- oct +=
3628
- hexValues[tmp & 0xF] +
3629
- hexValues[tmp >> 4 & 0xF] +
3630
- hexValues[tmp >> 8 & 0xF] +
3631
- hexValues[tmp >> 12 & 0xF] +
3632
- hexValues[tmp >> 16 & 0xF] +
3633
- hexValues[tmp >> 20 & 0xF] +
3634
- hexValues[tmp >> 24 & 0xF] +
3635
- 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;
3636
3831
  }
3637
- var clockSequenceHi = hexValues[8 + (random32() & 0x03) | 0];
3638
- return oct.substr(0, 8) + oct.substr(9, 4) + "4" + oct.substr(13, 3) + clockSequenceHi + oct.substr(16, 3) + oct.substr(19, 12);
3639
- }
3640
- var GuidRegex = /[xy]/g;
3641
- var EventHelper = {
3642
- Attach: attachEvent,
3643
- AttachEvent: attachEvent,
3644
- Detach: detachEvent,
3645
- DetachEvent: detachEvent
3646
- };
3832
+ return AppInsightsCore;
3833
+ }(BaseCore$2));
3647
3834
 
3648
3835
  var LoggingSeverity = createEnumStyle({
3649
3836
  CRITICAL: 1 ,
@@ -3731,7 +3918,8 @@
3731
3918
  InvalidContentBlob: 102 ,
3732
3919
  TrackPageActionEventFailed: 103 ,
3733
3920
  FailedAddingCustomDefinedRequestContext: 104 ,
3734
- InMemoryStorageBufferFull: 105
3921
+ InMemoryStorageBufferFull: 105 ,
3922
+ InstrumentationKeyDeprecation: 106
3735
3923
  });
3736
3924
 
3737
3925
  var ValueKind = createEnumStyle({
@@ -3803,7 +3991,7 @@
3803
3991
  })));
3804
3992
 
3805
3993
  var _a;
3806
- var Version = '3.2.2';
3994
+ var Version = '3.2.3';
3807
3995
  var FullVersionString = "1DS-Web-JS-" + Version;
3808
3996
  var strDisabledPropertyName = "Microsoft_ApplicationInsights_BypassAjaxInstrumentation";
3809
3997
  var strWithCredentials = "withCredentials";
@@ -4906,6 +5094,7 @@
4906
5094
  exports.createEnumStyle = createEnumStyle;
4907
5095
  exports.createGuid = createGuid;
4908
5096
  exports.createProcessTelemetryContext = createProcessTelemetryContext;
5097
+ exports.createTraceParent = createTraceParent;
4909
5098
  exports.createUniqueNamespace = createUniqueNamespace;
4910
5099
  exports.createUnloadHandlerContainer = createUnloadHandlerContainer;
4911
5100
  exports.dateNow = dateNow;
@@ -4918,6 +5107,8 @@
4918
5107
  exports.eventOff = eventOff;
4919
5108
  exports.eventOn = eventOn;
4920
5109
  exports.extend = extend;
5110
+ exports.findW3cTraceParent = findW3cTraceParent;
5111
+ exports.formatTraceParent = formatTraceParent;
4921
5112
  exports.generateW3CId = generateW3CId;
4922
5113
  exports.getCommonSchemaMetaData = getCommonSchemaMetaData;
4923
5114
  exports.getConsole = getConsole;
@@ -4964,11 +5155,15 @@
4964
5155
  exports.isNumber = isNumber;
4965
5156
  exports.isObject = isObject;
4966
5157
  exports.isReactNative = isReactNative;
5158
+ exports.isSampledFlag = isSampledFlag;
4967
5159
  exports.isString = isString;
4968
5160
  exports.isTruthy = isTruthy;
4969
5161
  exports.isTypeof = isTypeof;
4970
5162
  exports.isUint8ArrayAvailable = isUint8ArrayAvailable;
4971
5163
  exports.isUndefined = isUndefined;
5164
+ exports.isValidSpanId = isValidSpanId;
5165
+ exports.isValidTraceId = isValidTraceId;
5166
+ exports.isValidTraceParent = isValidTraceParent;
4972
5167
  exports.isValueAssigned = isValueAssigned;
4973
5168
  exports.isValueKind = isValueKind;
4974
5169
  exports.isWindowObjectAvailable = isWindowObjectAvailable;
@@ -4985,6 +5180,7 @@
4985
5180
  exports.objSeal = objSeal;
4986
5181
  exports.openXhr = openXhr;
4987
5182
  exports.optimizeObject = optimizeObject;
5183
+ exports.parseTraceParent = parseTraceParent;
4988
5184
  exports.perfNow = perfNow;
4989
5185
  exports.proxyAssign = proxyAssign;
4990
5186
  exports.proxyFunctionAs = proxyFunctionAs;