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