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

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