@microsoft/applicationinsights-web-basic 3.0.0-beta.2211-01 → 3.0.0-beta.2211-04

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.
package/browser/aib.2.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Application Insights JavaScript Web SDK - Basic, 3.0.0-beta.2211-01
2
+ * Application Insights JavaScript Web SDK - Basic, 3.0.0-beta.2211-04
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
  (function (global, factory) {
@@ -1080,6 +1080,22 @@
1080
1080
  return _scheduleTimeoutWith(this, setTimeout, clearTimeout, _extractArgs(arguments, 0));
1081
1081
  }
1082
1082
 
1083
+ function scheduleInterval(callback, timeout) {
1084
+ var self = this;
1085
+ var theArguments = arguments;
1086
+ var intervalId = setInterval.apply(self, theArguments);
1087
+ return {
1088
+ cancel: function () {
1089
+ clearInterval(intervalId);
1090
+ },
1091
+ refresh: function () {
1092
+ clearInterval(intervalId);
1093
+ intervalId = setInterval.apply(self, theArguments);
1094
+ return this;
1095
+ }
1096
+ };
1097
+ }
1098
+
1083
1099
  var createEnumStyle = createEnum;
1084
1100
  var createValueMap = createTypeMap;
1085
1101
 
@@ -1094,9 +1110,12 @@
1094
1110
  var _DYN_APPLY = "apply";
1095
1111
  var _DYN_PUSH$1 = "push";
1096
1112
  var _DYN_SPLICE = "splice";
1097
- var _DYN_INITIALIZE$1 = "initialize";
1113
+ var _DYN_CANCEL = "cancel";
1114
+ var _DYN_INITIALIZE = "initialize";
1098
1115
  var _DYN_IDENTIFIER = "identifier";
1099
1116
  var _DYN_IS_INITIALIZED = "isInitialized";
1117
+ var _DYN_GET_PLUGIN = "getPlugin";
1118
+ var _DYN_POLL_INTERNAL_LOGS = "pollInternalLogs";
1100
1119
  var _DYN_NAME$2 = "name";
1101
1120
  var _DYN_TIME = "time";
1102
1121
  var _DYN_PROCESS_NEXT = "processNext";
@@ -1107,10 +1126,9 @@
1107
1126
  var _DYN_STOP_POLLING_INTERNA3 = "stopPollingInternalLogs";
1108
1127
  var _DYN_ON_COMPLETE = "onComplete";
1109
1128
  var _DYN_CALL = "call";
1110
- var _DYN_GET_PLUGIN = "getPlugin";
1111
- var _DYN_FLUSH = "flush";
1112
1129
  var _DYN_VERSION = "version";
1113
1130
  var _DYN_LOGGING_LEVEL_CONSOL4 = "loggingLevelConsole";
1131
+ var _DYN_CREATE_NEW = "createNew";
1114
1132
  var _DYN_TEARDOWN = "teardown";
1115
1133
  var _DYN_MESSAGE_ID = "messageId";
1116
1134
  var _DYN_MESSAGE$1 = "message";
@@ -1120,8 +1138,6 @@
1120
1138
  var _DYN_UPDATE = "update";
1121
1139
  var _DYN_GET_NEXT = "getNext";
1122
1140
  var _DYN_SET_NEXT_PLUGIN = "setNextPlugin";
1123
- var _DYN_CREATE_NEW = "createNew";
1124
- var _DYN_CONFIG = "config";
1125
1141
  var _DYN_USER_AGENT = "userAgent";
1126
1142
  var _DYN_SPLIT$1 = "split";
1127
1143
  var _DYN_NODE_TYPE = "nodeType";
@@ -1547,7 +1563,7 @@
1547
1563
  }
1548
1564
 
1549
1565
  var _objDefineProperty = ObjDefineProperty;
1550
- var version = "3.0.0-beta.2211-01";
1566
+ var version = "3.0.0-beta.2211-04";
1551
1567
  var instanceName = "." + newId(6);
1552
1568
  var _dataUid = 0;
1553
1569
  function _createAccessor(target, prop, value) {
@@ -1881,7 +1897,7 @@
1881
1897
  if (_waitingHandlers) {
1882
1898
  var notifyHandlers = _waitingHandlers;
1883
1899
  _waitingHandlers = null;
1884
- _watcherTimer && _watcherTimer.cancel();
1900
+ _watcherTimer && _watcherTimer[_DYN_CANCEL ]();
1885
1901
  _watcherTimer = null;
1886
1902
  var watcherFailures_1 = [];
1887
1903
  arrForEach(notifyHandlers, function (handler) {
@@ -2041,6 +2057,8 @@
2041
2057
  createDynamicConfig(config, null, logger)[_DYN_WATCH ](configHandler);
2042
2058
  }
2043
2059
 
2060
+ var ChannelControllerPriority = 500;
2061
+
2044
2062
  var listenerFuncs = [STR_EVENTS_SENT, STR_EVENTS_DISCARDED, STR_EVENTS_SEND_REQUEST, STR_PERF_EVENT];
2045
2063
  var _aiNamespace = null;
2046
2064
  var _debugListener;
@@ -2254,1138 +2272,944 @@
2254
2272
  _getLogger(logger)[STR_WARN_TO_CONSOLE ](message);
2255
2273
  }
2256
2274
 
2257
- var strExecutionContextKey = "ctx";
2258
- var strParentContextKey = "ParentContextKey";
2259
- var strChildrenContextKey = "ChildrenContextKey";
2260
- var _defaultPerfManager = null;
2261
- var PerfEvent = /** @class */ (function () {
2262
- function PerfEvent(name, payloadDetails, isAsync) {
2263
- var _self = this;
2264
- _self.start = utcNow();
2265
- _self[_DYN_NAME$2 ] = name;
2266
- _self[_DYN_IS_ASYNC ] = isAsync;
2267
- _self[_DYN_IS_CHILD_EVT ] = function () { return false; };
2268
- if (isFunction(payloadDetails)) {
2269
- var theDetails_1;
2270
- objDefineAccessors(_self, "payload", function () {
2271
- if (!theDetails_1 && isFunction(payloadDetails)) {
2272
- theDetails_1 = payloadDetails();
2273
- payloadDetails = null;
2274
- }
2275
- return theDetails_1;
2276
- });
2275
+ var _a$3, _b$1;
2276
+ var strToGMTString = "toGMTString";
2277
+ var strToUTCString = "toUTCString";
2278
+ var strCookie = "cookie";
2279
+ var strExpires = "expires";
2280
+ var strIsCookieUseDisabled = "isCookieUseDisabled";
2281
+ var strDisableCookiesUsage = "disableCookiesUsage";
2282
+ var strConfigCookieMgr = "_ckMgr";
2283
+ var _supportsCookies = null;
2284
+ var _allowUaSameSite = null;
2285
+ var _parsedCookieValue = null;
2286
+ var _doc = getDocument();
2287
+ var _cookieCache = {};
2288
+ var _globalCookieConfig = {};
2289
+ var defaultConfig$1 = objDeepFreeze((_a$3 = {},
2290
+ _a$3[STR_DOMAIN] = { fb: "cookieDomain", dfVal: isNotNullOrUndefined },
2291
+ _a$3.path = { fb: "cookiePath", dfVal: isNotNullOrUndefined },
2292
+ _a$3.enabled = UNDEFINED_VALUE$1,
2293
+ _a$3));
2294
+ var rootDefaultConfig = (_b$1 = {
2295
+ cookieCfg: {},
2296
+ cookieDomain: UNDEFINED_VALUE$1,
2297
+ cookiePath: UNDEFINED_VALUE$1
2298
+ },
2299
+ _b$1[strDisableCookiesUsage] = UNDEFINED_VALUE$1,
2300
+ _b$1);
2301
+ function _isMgrEnabled(cookieMgr) {
2302
+ if (cookieMgr) {
2303
+ return cookieMgr.isEnabled();
2304
+ }
2305
+ return true;
2306
+ }
2307
+ function _isIgnoredCookie(cookieMgrCfg, name) {
2308
+ if (name && cookieMgrCfg && isArray(cookieMgrCfg.ignoreCookies)) {
2309
+ return arrIndexOf(cookieMgrCfg.ignoreCookies, name) !== -1;
2310
+ }
2311
+ return false;
2312
+ }
2313
+ function _isBlockedCookie(cookieMgrCfg, name) {
2314
+ if (name && cookieMgrCfg && isArray(cookieMgrCfg.blockedCookies)) {
2315
+ if (arrIndexOf(cookieMgrCfg.blockedCookies, name) !== -1) {
2316
+ return true;
2277
2317
  }
2278
- _self[_DYN_GET_CTX ] = function (key) {
2279
- if (key) {
2280
- if (key === PerfEvent[strParentContextKey] || key === PerfEvent[strChildrenContextKey]) {
2281
- return _self[key];
2282
- }
2283
- return (_self[strExecutionContextKey] || {})[key];
2318
+ }
2319
+ return _isIgnoredCookie(cookieMgrCfg, name);
2320
+ }
2321
+ function createCookieMgr(rootConfig, logger) {
2322
+ var cookieMgrConfig;
2323
+ var _path;
2324
+ var _domain;
2325
+ var _enabled;
2326
+ var _getCookieFn;
2327
+ var _setCookieFn;
2328
+ var _delCookieFn;
2329
+ rootConfig = createDynamicConfig(rootConfig || _globalCookieConfig, null, logger).cfg;
2330
+ onConfigChange(rootConfig, function (details) {
2331
+ details[_DYN_SET_DF ](details.cfg, rootDefaultConfig);
2332
+ cookieMgrConfig = details[_DYN_SET_DF ](details.cfg.cookieCfg, defaultConfig$1);
2333
+ var isEnabled = cookieMgrConfig.enabled;
2334
+ if (isNullOrUndefined(isEnabled)) {
2335
+ var cookieEnabled = void 0;
2336
+ if (!isUndefined(rootConfig[strIsCookieUseDisabled])) {
2337
+ cookieEnabled = !rootConfig[strIsCookieUseDisabled];
2284
2338
  }
2285
- return null;
2286
- };
2287
- _self[_DYN_SET_CTX ] = function (key, value) {
2288
- if (key) {
2289
- if (key === PerfEvent[strParentContextKey]) {
2290
- if (!_self[key]) {
2291
- _self[_DYN_IS_CHILD_EVT ] = function () { return true; };
2292
- }
2293
- _self[key] = value;
2294
- }
2295
- else if (key === PerfEvent[strChildrenContextKey]) {
2296
- _self[key] = value;
2297
- }
2298
- else {
2299
- var ctx = _self[strExecutionContextKey] = _self[strExecutionContextKey] || {};
2300
- ctx[key] = value;
2301
- }
2339
+ if (!isUndefined(rootConfig[strDisableCookiesUsage])) {
2340
+ cookieEnabled = !rootConfig[strDisableCookiesUsage];
2302
2341
  }
2303
- };
2304
- _self[_DYN_COMPLETE ] = function () {
2305
- var childTime = 0;
2306
- var childEvts = _self[_DYN_GET_CTX ](PerfEvent[strChildrenContextKey]);
2307
- if (isArray(childEvts)) {
2308
- for (var lp = 0; lp < childEvts[_DYN_LENGTH$2 ]; lp++) {
2309
- var childEvt = childEvts[lp];
2310
- if (childEvt) {
2311
- childTime += childEvt[_DYN_TIME ];
2312
- }
2313
- }
2342
+ isEnabled = cookieEnabled;
2343
+ }
2344
+ _path = cookieMgrConfig[STR_PATH ] || "/";
2345
+ _domain = cookieMgrConfig[STR_DOMAIN ];
2346
+ _enabled = isEnabled !== false;
2347
+ _getCookieFn = cookieMgrConfig.getCookie || _getCookieValue;
2348
+ _setCookieFn = cookieMgrConfig.setCookie || _setCookieValue;
2349
+ _delCookieFn = cookieMgrConfig.delCookie || _setCookieValue;
2350
+ }, logger);
2351
+ var cookieMgr = {
2352
+ isEnabled: function () {
2353
+ var enabled = _enabled && areCookiesSupported(logger);
2354
+ var gblManager = _globalCookieConfig[strConfigCookieMgr];
2355
+ if (enabled && gblManager && cookieMgr !== gblManager) {
2356
+ enabled = _isMgrEnabled(gblManager);
2314
2357
  }
2315
- _self[_DYN_TIME ] = utcNow() - _self.start;
2316
- _self.exTime = _self[_DYN_TIME ] - childTime;
2317
- _self[_DYN_COMPLETE ] = function () { };
2318
- };
2319
- }
2320
- PerfEvent.ParentContextKey = "parent";
2321
- PerfEvent.ChildrenContextKey = "childEvts";
2322
- return PerfEvent;
2323
- }());
2324
- var PerfManager = /** @class */ (function () {
2325
- function PerfManager(manager) {
2326
- this.ctx = {};
2327
- dynamicProto(PerfManager, this, function (_self) {
2328
- _self.create = function (src, payloadDetails, isAsync) {
2329
- return new PerfEvent(src, payloadDetails, isAsync);
2330
- };
2331
- _self.fire = function (perfEvent) {
2332
- if (perfEvent) {
2333
- perfEvent[_DYN_COMPLETE ]();
2334
- if (manager && isFunction(manager[STR_PERF_EVENT ])) {
2335
- manager[STR_PERF_EVENT ](perfEvent);
2336
- }
2337
- }
2338
- };
2339
- _self[_DYN_SET_CTX ] = function (key, value) {
2340
- if (key) {
2341
- var ctx = _self[strExecutionContextKey] = _self[strExecutionContextKey] || {};
2342
- ctx[key] = value;
2358
+ return enabled;
2359
+ },
2360
+ setEnabled: function (value) {
2361
+ _enabled = value !== false;
2362
+ },
2363
+ set: function (name, value, maxAgeSec, domain, path) {
2364
+ var result = false;
2365
+ if (_isMgrEnabled(cookieMgr) && !_isBlockedCookie(cookieMgrConfig, name)) {
2366
+ var values = {};
2367
+ var theValue = strTrim(value || STR_EMPTY);
2368
+ var idx = strIndexOf(theValue, ";");
2369
+ if (idx !== -1) {
2370
+ theValue = strTrim(strLeft(value, idx));
2371
+ values = _extractParts(strSubstring(value, idx + 1));
2343
2372
  }
2344
- };
2345
- _self[_DYN_GET_CTX ] = function (key) {
2346
- return (_self[strExecutionContextKey] || {})[key];
2347
- };
2348
- });
2349
- }
2350
- PerfManager.__ieDyn=1;
2351
- return PerfManager;
2352
- }());
2353
- var doPerfActiveKey = "CoreUtils.doPerf";
2354
- function doPerf(mgrSource, getSource, func, details, isAsync) {
2355
- if (mgrSource) {
2356
- var perfMgr = mgrSource;
2357
- if (perfMgr[STR_GET_PERF_MGR]) {
2358
- perfMgr = perfMgr[STR_GET_PERF_MGR]();
2359
- }
2360
- if (perfMgr) {
2361
- var perfEvt = void 0;
2362
- var currentActive = perfMgr[_DYN_GET_CTX ](doPerfActiveKey);
2363
- try {
2364
- perfEvt = perfMgr.create(getSource(), details, isAsync);
2365
- if (perfEvt) {
2366
- if (currentActive && perfEvt[_DYN_SET_CTX ]) {
2367
- perfEvt[_DYN_SET_CTX ](PerfEvent[strParentContextKey], currentActive);
2368
- if (currentActive[_DYN_GET_CTX ] && currentActive[_DYN_SET_CTX ]) {
2369
- var children = currentActive[_DYN_GET_CTX ](PerfEvent[strChildrenContextKey]);
2370
- if (!children) {
2371
- children = [];
2372
- currentActive[_DYN_SET_CTX ](PerfEvent[strChildrenContextKey], children);
2373
- }
2374
- children[_DYN_PUSH$1 ](perfEvt);
2373
+ setValue(values, STR_DOMAIN, domain || _domain, isTruthy, isUndefined);
2374
+ if (!isNullOrUndefined(maxAgeSec)) {
2375
+ var _isIE = isIE();
2376
+ if (isUndefined(values[strExpires])) {
2377
+ var nowMs = utcNow();
2378
+ var expireMs = nowMs + (maxAgeSec * 1000);
2379
+ if (expireMs > 0) {
2380
+ var expiry = new Date();
2381
+ expiry.setTime(expireMs);
2382
+ setValue(values, strExpires, _formatDate(expiry, !_isIE ? strToUTCString : strToGMTString) || _formatDate(expiry, _isIE ? strToGMTString : strToUTCString) || STR_EMPTY, isTruthy);
2375
2383
  }
2376
2384
  }
2377
- perfMgr[_DYN_SET_CTX ](doPerfActiveKey, perfEvt);
2378
- return func(perfEvt);
2385
+ if (!_isIE) {
2386
+ setValue(values, "max-age", STR_EMPTY + maxAgeSec, null, isUndefined);
2387
+ }
2379
2388
  }
2380
- }
2381
- catch (ex) {
2382
- if (perfEvt && perfEvt[_DYN_SET_CTX ]) {
2383
- perfEvt[_DYN_SET_CTX ]("exception", ex);
2389
+ var location_1 = getLocation();
2390
+ if (location_1 && location_1.protocol === "https:") {
2391
+ setValue(values, "secure", null, null, isUndefined);
2392
+ if (_allowUaSameSite === null) {
2393
+ _allowUaSameSite = !uaDisallowsSameSiteNone((getNavigator() || {})[_DYN_USER_AGENT ]);
2394
+ }
2395
+ if (_allowUaSameSite) {
2396
+ setValue(values, "SameSite", "None", null, isUndefined);
2397
+ }
2384
2398
  }
2399
+ setValue(values, STR_PATH, path || _path, null, isUndefined);
2400
+ _setCookieFn(name, _formatCookieValue(theValue, values));
2401
+ result = true;
2385
2402
  }
2386
- finally {
2387
- if (perfEvt) {
2388
- perfMgr.fire(perfEvt);
2403
+ return result;
2404
+ },
2405
+ get: function (name) {
2406
+ var value = STR_EMPTY;
2407
+ if (_isMgrEnabled(cookieMgr) && !_isIgnoredCookie(cookieMgrConfig, name)) {
2408
+ value = _getCookieFn(name);
2409
+ }
2410
+ return value;
2411
+ },
2412
+ del: function (name, path) {
2413
+ var result = false;
2414
+ if (_isMgrEnabled(cookieMgr)) {
2415
+ result = cookieMgr.purge(name, path);
2416
+ }
2417
+ return result;
2418
+ },
2419
+ purge: function (name, path) {
2420
+ var _a;
2421
+ var result = false;
2422
+ if (areCookiesSupported(logger)) {
2423
+ var values = (_a = {},
2424
+ _a[STR_PATH] = path ? path : "/",
2425
+ _a[strExpires] = "Thu, 01 Jan 1970 00:00:01 GMT",
2426
+ _a);
2427
+ if (!isIE()) {
2428
+ values["max-age"] = "0";
2389
2429
  }
2390
- perfMgr[_DYN_SET_CTX ](doPerfActiveKey, currentActive);
2430
+ _delCookieFn(name, _formatCookieValue(STR_EMPTY, values));
2431
+ result = true;
2391
2432
  }
2433
+ return result;
2392
2434
  }
2393
- }
2394
- return func();
2395
- }
2396
- function getGblPerfMgr() {
2397
- return _defaultPerfManager;
2435
+ };
2436
+ cookieMgr[strConfigCookieMgr] = cookieMgr;
2437
+ return cookieMgr;
2398
2438
  }
2399
-
2400
- var INVALID_TRACE_ID = "00000000000000000000000000000000";
2401
- var INVALID_SPAN_ID = "0000000000000000";
2402
- function _isValid(value, len, invalidValue) {
2403
- if (value && value[_DYN_LENGTH$2 ] === len && value !== invalidValue) {
2404
- return !!value.match(/^[\da-f]*$/i);
2439
+ function areCookiesSupported(logger) {
2440
+ if (_supportsCookies === null) {
2441
+ _supportsCookies = false;
2442
+ try {
2443
+ var doc = _doc || {};
2444
+ _supportsCookies = doc[strCookie] !== undefined;
2445
+ }
2446
+ catch (e) {
2447
+ _throwInternal(logger, 2 , 68 , "Cannot access document.cookie - " + getExceptionName(e), { exception: dumpObj(e) });
2448
+ }
2405
2449
  }
2406
- return false;
2407
- }
2408
- function isValidTraceId(value) {
2409
- return _isValid(value, 32, INVALID_TRACE_ID);
2410
- }
2411
- function isValidSpanId(value) {
2412
- return _isValid(value, 16, INVALID_SPAN_ID);
2413
- }
2414
-
2415
- var pluginStateData = createElmNodeData("plugin");
2416
- function _getPluginState(plugin) {
2417
- return pluginStateData.get(plugin, "state", {}, true);
2450
+ return _supportsCookies;
2418
2451
  }
2419
- function initializePlugins(processContext, extensions) {
2420
- var initPlugins = [];
2421
- var lastPlugin = null;
2422
- var proxy = processContext[_DYN_GET_NEXT ]();
2423
- var pluginState;
2424
- while (proxy) {
2425
- var thePlugin = proxy[_DYN_GET_PLUGIN ]();
2426
- if (thePlugin) {
2427
- if (lastPlugin && lastPlugin[_DYN_SET_NEXT_PLUGIN ] && thePlugin[STR_PROCESS_TELEMETRY ]) {
2428
- lastPlugin[_DYN_SET_NEXT_PLUGIN ](thePlugin);
2429
- }
2430
- var isInitialized = false;
2431
- if (isFunction(thePlugin[_DYN_IS_INITIALIZED ])) {
2432
- isInitialized = thePlugin[_DYN_IS_INITIALIZED ]();
2433
- }
2434
- else {
2435
- pluginState = _getPluginState(thePlugin);
2436
- isInitialized = pluginState[_DYN_IS_INITIALIZED ];
2437
- }
2438
- if (!isInitialized) {
2439
- initPlugins[_DYN_PUSH$1 ](thePlugin);
2452
+ function _extractParts(theValue) {
2453
+ var values = {};
2454
+ if (theValue && theValue[_DYN_LENGTH$2 ]) {
2455
+ var parts = strTrim(theValue)[_DYN_SPLIT$1 ](";");
2456
+ arrForEach(parts, function (thePart) {
2457
+ thePart = strTrim(thePart || STR_EMPTY);
2458
+ if (thePart) {
2459
+ var idx = strIndexOf(thePart, "=");
2460
+ if (idx === -1) {
2461
+ values[thePart] = null;
2462
+ }
2463
+ else {
2464
+ values[strTrim(strLeft(thePart, idx))] = strTrim(strSubstring(thePart, idx + 1));
2465
+ }
2440
2466
  }
2441
- lastPlugin = thePlugin;
2442
- proxy = proxy[_DYN_GET_NEXT ]();
2443
- }
2467
+ });
2444
2468
  }
2445
- arrForEach(initPlugins, function (thePlugin) {
2446
- var core = processContext[STR_CORE ]();
2447
- thePlugin[_DYN_INITIALIZE$1 ](processContext.getCfg(), core, extensions, processContext[_DYN_GET_NEXT ]());
2448
- pluginState = _getPluginState(thePlugin);
2449
- if (!thePlugin[STR_CORE] && !pluginState[STR_CORE]) {
2450
- pluginState[STR_CORE] = core;
2451
- }
2452
- pluginState[_DYN_IS_INITIALIZED ] = true;
2453
- delete pluginState[_DYN_TEARDOWN ];
2454
- });
2469
+ return values;
2455
2470
  }
2456
- function sortPlugins(plugins) {
2457
- return plugins.sort(function (extA, extB) {
2458
- var result = 0;
2459
- if (extB) {
2460
- var bHasProcess = extB[STR_PROCESS_TELEMETRY];
2461
- if (extA[STR_PROCESS_TELEMETRY]) {
2462
- result = bHasProcess ? extA[STR_PRIORITY] - extB[STR_PRIORITY] : 1;
2463
- }
2464
- else if (bHasProcess) {
2465
- result = -1;
2466
- }
2467
- }
2468
- else {
2469
- result = extA ? 1 : -1;
2470
- }
2471
- return result;
2471
+ function _formatDate(theDate, func) {
2472
+ if (isFunction(theDate[func])) {
2473
+ return theDate[func]();
2474
+ }
2475
+ return null;
2476
+ }
2477
+ function _formatCookieValue(value, values) {
2478
+ var cookieValue = value || STR_EMPTY;
2479
+ objForEachKey(values, function (name, theValue) {
2480
+ cookieValue += "; " + name + (!isNullOrUndefined(theValue) ? "=" + theValue : STR_EMPTY);
2472
2481
  });
2482
+ return cookieValue;
2473
2483
  }
2474
- function createDistributedTraceContext(parentCtx) {
2475
- var trace = {};
2476
- return {
2477
- getName: function () {
2478
- return trace[_DYN_NAME$2 ];
2479
- },
2480
- setName: function (newValue) {
2481
- parentCtx && parentCtx.setName(newValue);
2482
- trace[_DYN_NAME$2 ] = newValue;
2483
- },
2484
- getTraceId: function () {
2485
- return trace[_DYN_TRACE_ID$1 ];
2486
- },
2487
- setTraceId: function (newValue) {
2488
- parentCtx && parentCtx.setTraceId(newValue);
2489
- if (isValidTraceId(newValue)) {
2490
- trace[_DYN_TRACE_ID$1 ] = newValue;
2491
- }
2492
- },
2493
- getSpanId: function () {
2494
- return trace[_DYN_SPAN_ID ];
2495
- },
2496
- setSpanId: function (newValue) {
2497
- parentCtx && parentCtx.setSpanId(newValue);
2498
- if (isValidSpanId(newValue)) {
2499
- trace[_DYN_SPAN_ID ] = newValue;
2500
- }
2501
- },
2502
- getTraceFlags: function () {
2503
- return trace[_DYN_TRACE_FLAGS ];
2504
- },
2505
- setTraceFlags: function (newTraceFlags) {
2506
- parentCtx && parentCtx.setTraceFlags(newTraceFlags);
2507
- trace[_DYN_TRACE_FLAGS ] = newTraceFlags;
2484
+ function _getCookieValue(name) {
2485
+ var cookieValue = STR_EMPTY;
2486
+ if (_doc) {
2487
+ var theCookie = _doc[strCookie] || STR_EMPTY;
2488
+ if (_parsedCookieValue !== theCookie) {
2489
+ _cookieCache = _extractParts(theCookie);
2490
+ _parsedCookieValue = theCookie;
2508
2491
  }
2509
- };
2492
+ cookieValue = strTrim(_cookieCache[name] || STR_EMPTY);
2493
+ }
2494
+ return cookieValue;
2510
2495
  }
2511
-
2512
- var strTelemetryPluginChain = "TelemetryPluginChain";
2513
- var strHasRunFlags = "_hasRun";
2514
- var strGetTelCtx = "_getTelCtx";
2515
- var _chainId = 0;
2516
- function _getNextProxyStart(proxy, core, startAt) {
2517
- while (proxy) {
2518
- if (proxy[_DYN_GET_PLUGIN ]() === startAt) {
2519
- return proxy;
2520
- }
2521
- proxy = proxy[_DYN_GET_NEXT ]();
2496
+ function _setCookieValue(name, cookieValue) {
2497
+ if (_doc) {
2498
+ _doc[strCookie] = name + "=" + cookieValue;
2522
2499
  }
2523
- return createTelemetryProxyChain([startAt], core[_DYN_CONFIG ] || {}, core);
2524
2500
  }
2525
- function _createInternalContext(telemetryChain, dynamicHandler, core, startAt) {
2526
- var _nextProxy = null;
2527
- var _onComplete = [];
2528
- if (!dynamicHandler) {
2529
- dynamicHandler = createDynamicConfig({}, null, core[_DYN_LOGGER ]);
2501
+ function uaDisallowsSameSiteNone(userAgent) {
2502
+ if (!isString(userAgent)) {
2503
+ return false;
2530
2504
  }
2531
- if (startAt !== null) {
2532
- _nextProxy = startAt ? _getNextProxyStart(telemetryChain, core, startAt) : telemetryChain;
2505
+ if (strContains(userAgent, "CPU iPhone OS 12") || strContains(userAgent, "iPad; CPU OS 12")) {
2506
+ return true;
2533
2507
  }
2534
- var context = {
2535
- _next: _moveNext,
2536
- ctx: {
2537
- core: function () {
2538
- return core;
2539
- },
2540
- diagLog: function () {
2541
- return safeGetLogger(core, dynamicHandler.cfg);
2542
- },
2543
- getCfg: function () {
2544
- return dynamicHandler.cfg;
2545
- },
2546
- getExtCfg: _resolveExtCfg,
2547
- getConfig: _getConfig,
2548
- hasNext: function () {
2549
- return !!_nextProxy;
2550
- },
2551
- getNext: function () {
2552
- return _nextProxy;
2553
- },
2554
- setNext: function (nextPlugin) {
2555
- _nextProxy = nextPlugin;
2556
- },
2557
- iterate: _iterateChain,
2558
- onComplete: _addOnComplete
2559
- }
2560
- };
2561
- function _addOnComplete(onComplete, that) {
2562
- var args = [];
2563
- for (var _i = 2; _i < arguments.length; _i++) {
2564
- args[_i - 2] = arguments[_i];
2565
- }
2566
- if (onComplete) {
2567
- _onComplete[_DYN_PUSH$1 ]({
2568
- func: onComplete,
2569
- self: !isUndefined(that) ? that : context.ctx,
2570
- args: args
2571
- });
2572
- }
2508
+ if (strContains(userAgent, "Macintosh; Intel Mac OS X 10_14") && strContains(userAgent, "Version/") && strContains(userAgent, "Safari")) {
2509
+ return true;
2573
2510
  }
2574
- function _moveNext() {
2575
- var nextProxy = _nextProxy;
2576
- _nextProxy = nextProxy ? nextProxy[_DYN_GET_NEXT ]() : null;
2577
- if (!nextProxy) {
2578
- var onComplete = _onComplete;
2579
- if (onComplete && onComplete[_DYN_LENGTH$2 ] > 0) {
2580
- arrForEach(onComplete, function (completeDetails) {
2581
- try {
2582
- completeDetails.func[_DYN_CALL ](completeDetails.self, completeDetails.args);
2583
- }
2584
- catch (e) {
2585
- _throwInternal(core[_DYN_LOGGER ], 2 , 73 , "Unexpected Exception during onComplete - " + dumpObj(e));
2586
- }
2587
- });
2588
- _onComplete = [];
2589
- }
2590
- }
2591
- return nextProxy;
2592
- }
2593
- function _getExtCfg(identifier, createIfMissing) {
2594
- var idCfg = null;
2595
- var cfg = dynamicHandler.cfg;
2596
- if (cfg && identifier) {
2597
- var extCfg = cfg[STR_EXTENSION_CONFIG ];
2598
- if (!extCfg && createIfMissing) {
2599
- extCfg = {};
2600
- }
2601
- dynamicHandler.set(cfg, STR_EXTENSION_CONFIG, extCfg);
2602
- extCfg = cfg[STR_EXTENSION_CONFIG ];
2603
- if (extCfg) {
2604
- idCfg = extCfg[identifier];
2605
- if (!idCfg && createIfMissing) {
2606
- idCfg = {};
2607
- }
2608
- dynamicHandler.set(extCfg, identifier, idCfg);
2609
- idCfg = extCfg[identifier];
2610
- }
2611
- }
2612
- return idCfg;
2613
- }
2614
- function _resolveExtCfg(identifier, defaultValues) {
2615
- var newConfig = _getExtCfg(identifier, true);
2616
- if (defaultValues) {
2617
- objForEachKey(defaultValues, function (field, defaultValue) {
2618
- if (isNullOrUndefined(newConfig[field])) {
2619
- var cfgValue = dynamicHandler.cfg[field];
2620
- if (cfgValue || !isNullOrUndefined(cfgValue)) {
2621
- newConfig[field] = cfgValue;
2622
- }
2623
- }
2624
- _applyDefaultValue(dynamicHandler, newConfig, field, defaultValue);
2625
- });
2626
- }
2627
- return dynamicHandler[_DYN_SET_DF ](newConfig, defaultValues);
2628
- }
2629
- function _getConfig(identifier, field, defaultValue) {
2630
- if (defaultValue === void 0) { defaultValue = false; }
2631
- var theValue;
2632
- var extConfig = _getExtCfg(identifier, false);
2633
- var rootConfig = dynamicHandler.cfg;
2634
- if (extConfig && (extConfig[field] || !isNullOrUndefined(extConfig[field]))) {
2635
- theValue = extConfig[field];
2636
- }
2637
- else if (rootConfig[field] || !isNullOrUndefined(rootConfig[field])) {
2638
- theValue = rootConfig[field];
2639
- }
2640
- return (theValue || !isNullOrUndefined(theValue)) ? theValue : defaultValue;
2641
- }
2642
- function _iterateChain(cb) {
2643
- var nextPlugin;
2644
- while (!!(nextPlugin = context._next())) {
2645
- var plugin = nextPlugin[_DYN_GET_PLUGIN ]();
2646
- if (plugin) {
2647
- cb(plugin);
2648
- }
2649
- }
2650
- }
2651
- return context;
2652
- }
2653
- function createProcessTelemetryContext(telemetryChain, cfg, core, startAt) {
2654
- var config = createDynamicConfig(cfg);
2655
- var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
2656
- var context = internalContext.ctx;
2657
- function _processNext(env) {
2658
- var nextPlugin = internalContext._next();
2659
- if (nextPlugin) {
2660
- nextPlugin[STR_PROCESS_TELEMETRY ](env, context);
2661
- }
2662
- return !nextPlugin;
2511
+ if (strContains(userAgent, "Macintosh; Intel Mac OS X 10_14") && strEndsWith(userAgent, "AppleWebKit/605.1.15 (KHTML, like Gecko)")) {
2512
+ return true;
2663
2513
  }
2664
- function _createNew(plugins, startAt) {
2665
- if (plugins === void 0) { plugins = null; }
2666
- if (isArray(plugins)) {
2667
- plugins = createTelemetryProxyChain(plugins, config.cfg, core, startAt);
2668
- }
2669
- return createProcessTelemetryContext(plugins || context[_DYN_GET_NEXT ](), config.cfg, core, startAt);
2514
+ if (strContains(userAgent, "Chrome/5") || strContains(userAgent, "Chrome/6")) {
2515
+ return true;
2670
2516
  }
2671
- context[_DYN_PROCESS_NEXT ] = _processNext;
2672
- context[_DYN_CREATE_NEW ] = _createNew;
2673
- return context;
2674
- }
2675
- function createProcessTelemetryUnloadContext(telemetryChain, core, startAt) {
2676
- var config = createDynamicConfig(core[_DYN_CONFIG ]);
2677
- var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
2678
- var context = internalContext.ctx;
2679
- function _processNext(unloadState) {
2680
- var nextPlugin = internalContext._next();
2681
- nextPlugin && nextPlugin.unload(context, unloadState);
2682
- return !nextPlugin;
2517
+ if (strContains(userAgent, "UnrealEngine") && !strContains(userAgent, "Chrome")) {
2518
+ return true;
2683
2519
  }
2684
- function _createNew(plugins, startAt) {
2685
- if (plugins === void 0) { plugins = null; }
2686
- if (isArray(plugins)) {
2687
- plugins = createTelemetryProxyChain(plugins, config.cfg, core, startAt);
2688
- }
2689
- return createProcessTelemetryUnloadContext(plugins || context[_DYN_GET_NEXT ](), core, startAt);
2520
+ if (strContains(userAgent, "UCBrowser/12") || strContains(userAgent, "UCBrowser/11")) {
2521
+ return true;
2690
2522
  }
2691
- context[_DYN_PROCESS_NEXT ] = _processNext;
2692
- context[_DYN_CREATE_NEW ] = _createNew;
2693
- return context;
2523
+ return false;
2694
2524
  }
2695
- function createProcessTelemetryUpdateContext(telemetryChain, core, startAt) {
2696
- var config = createDynamicConfig(core[_DYN_CONFIG ]);
2697
- var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
2698
- var context = internalContext.ctx;
2699
- function _processNext(updateState) {
2700
- return context.iterate(function (plugin) {
2701
- if (isFunction(plugin[_DYN_UPDATE ])) {
2702
- plugin[_DYN_UPDATE ](context, updateState);
2525
+
2526
+ var defaultValues$1 = {
2527
+ perfEvtsSendAll: false
2528
+ };
2529
+ function _runListeners(listeners, name, isAsync, callback) {
2530
+ arrForEach(listeners, function (listener) {
2531
+ if (listener && listener[name]) {
2532
+ if (isAsync) {
2533
+ scheduleTimeout(function () { return callback(listener); }, 0);
2534
+ }
2535
+ else {
2536
+ try {
2537
+ callback(listener);
2538
+ }
2539
+ catch (e) {
2540
+ }
2703
2541
  }
2704
- });
2705
- }
2706
- function _createNew(plugins, startAt) {
2707
- if (plugins === void 0) { plugins = null; }
2708
- if (isArray(plugins)) {
2709
- plugins = createTelemetryProxyChain(plugins, config.cfg, core, startAt);
2710
2542
  }
2711
- return createProcessTelemetryUpdateContext(plugins || context[_DYN_GET_NEXT ](), core, startAt);
2712
- }
2713
- context[_DYN_PROCESS_NEXT ] = _processNext;
2714
- context[_DYN_CREATE_NEW ] = _createNew;
2715
- return context;
2543
+ });
2716
2544
  }
2717
- function createTelemetryProxyChain(plugins, config, core, startAt) {
2718
- var firstProxy = null;
2719
- var add = startAt ? false : true;
2720
- if (isArray(plugins) && plugins[_DYN_LENGTH$2 ] > 0) {
2721
- var lastProxy_1 = null;
2722
- arrForEach(plugins, function (thePlugin) {
2723
- if (!add && startAt === thePlugin) {
2724
- add = true;
2725
- }
2726
- if (add && thePlugin && isFunction(thePlugin[STR_PROCESS_TELEMETRY ])) {
2727
- var newProxy = createTelemetryPluginProxy(thePlugin, config, core);
2728
- if (!firstProxy) {
2729
- firstProxy = newProxy;
2545
+ var NotificationManager = /** @class */ (function () {
2546
+ function NotificationManager(config) {
2547
+ this.listeners = [];
2548
+ var perfEvtsSendAll;
2549
+ var cfgHandler = createDynamicConfig(config, defaultValues$1);
2550
+ cfgHandler[_DYN_WATCH ](function (details) {
2551
+ perfEvtsSendAll = !!details.cfg.perfEvtsSendAll;
2552
+ });
2553
+ dynamicProto(NotificationManager, this, function (_self) {
2554
+ _self[_DYN_ADD_NOTIFICATION_LIS1 ] = function (listener) {
2555
+ _self.listeners[_DYN_PUSH$1 ](listener);
2556
+ };
2557
+ _self[_DYN_REMOVE_NOTIFICATION_2 ] = function (listener) {
2558
+ var index = arrIndexOf(_self[_DYN_LISTENERS ], listener);
2559
+ while (index > -1) {
2560
+ _self.listeners[_DYN_SPLICE ](index, 1);
2561
+ index = arrIndexOf(_self[_DYN_LISTENERS ], listener);
2730
2562
  }
2731
- if (lastProxy_1) {
2732
- lastProxy_1._setNext(newProxy);
2563
+ };
2564
+ _self[STR_EVENTS_SENT ] = function (events) {
2565
+ _runListeners(_self[_DYN_LISTENERS ], STR_EVENTS_SENT, true, function (listener) {
2566
+ listener[STR_EVENTS_SENT ](events);
2567
+ });
2568
+ };
2569
+ _self[STR_EVENTS_DISCARDED ] = function (events, reason) {
2570
+ _runListeners(_self[_DYN_LISTENERS ], STR_EVENTS_DISCARDED, true, function (listener) {
2571
+ listener[STR_EVENTS_DISCARDED ](events, reason);
2572
+ });
2573
+ };
2574
+ _self[STR_EVENTS_SEND_REQUEST ] = function (sendReason, isAsync) {
2575
+ _runListeners(_self[_DYN_LISTENERS ], STR_EVENTS_SEND_REQUEST, isAsync, function (listener) {
2576
+ listener[STR_EVENTS_SEND_REQUEST ](sendReason, isAsync);
2577
+ });
2578
+ };
2579
+ _self[STR_PERF_EVENT ] = function (perfEvent) {
2580
+ if (perfEvent) {
2581
+ if (perfEvtsSendAll || !perfEvent[_DYN_IS_CHILD_EVT ]()) {
2582
+ _runListeners(_self[_DYN_LISTENERS ], STR_PERF_EVENT, false, function (listener) {
2583
+ if (perfEvent[_DYN_IS_ASYNC ]) {
2584
+ scheduleTimeout(function () { return listener[STR_PERF_EVENT ](perfEvent); }, 0);
2585
+ }
2586
+ else {
2587
+ listener[STR_PERF_EVENT ](perfEvent);
2588
+ }
2589
+ });
2590
+ }
2733
2591
  }
2734
- lastProxy_1 = newProxy;
2735
- }
2592
+ };
2736
2593
  });
2737
2594
  }
2738
- if (startAt && !firstProxy) {
2739
- return createTelemetryProxyChain([startAt], config, core);
2740
- }
2741
- return firstProxy;
2742
- }
2743
- function createTelemetryPluginProxy(plugin, config, core) {
2744
- var nextProxy = null;
2745
- var hasProcessTelemetry = isFunction(plugin[STR_PROCESS_TELEMETRY ]);
2746
- var hasSetNext = isFunction(plugin[_DYN_SET_NEXT_PLUGIN ]);
2747
- var chainId;
2748
- if (plugin) {
2749
- chainId = plugin[_DYN_IDENTIFIER ] + "-" + plugin[STR_PRIORITY ] + "-" + _chainId++;
2750
- }
2751
- else {
2752
- chainId = "Unknown-0-" + _chainId++;
2753
- }
2754
- var proxyChain = {
2755
- getPlugin: function () {
2756
- return plugin;
2757
- },
2758
- getNext: function () {
2759
- return nextProxy;
2760
- },
2761
- processTelemetry: _processTelemetry,
2762
- unload: _unloadPlugin,
2763
- update: _updatePlugin,
2764
- _id: chainId,
2765
- _setNext: function (nextPlugin) {
2766
- nextProxy = nextPlugin;
2767
- }
2768
- };
2769
- function _getTelCtx() {
2770
- var itemCtx;
2771
- if (plugin && isFunction(plugin[strGetTelCtx])) {
2772
- itemCtx = plugin[strGetTelCtx]();
2773
- }
2774
- if (!itemCtx) {
2775
- itemCtx = createProcessTelemetryContext(proxyChain, config, core);
2776
- }
2777
- return itemCtx;
2778
- }
2779
- function _processChain(itemCtx, processPluginFn, name, details, isAsync) {
2780
- var hasRun = false;
2781
- var identifier = plugin ? plugin[_DYN_IDENTIFIER ] : strTelemetryPluginChain;
2782
- var hasRunContext = itemCtx[strHasRunFlags];
2783
- if (!hasRunContext) {
2784
- hasRunContext = itemCtx[strHasRunFlags] = {};
2595
+ NotificationManager.__ieDyn=1;
2596
+ return NotificationManager;
2597
+ }());
2598
+
2599
+ var strExecutionContextKey = "ctx";
2600
+ var strParentContextKey = "ParentContextKey";
2601
+ var strChildrenContextKey = "ChildrenContextKey";
2602
+ var _defaultPerfManager = null;
2603
+ var PerfEvent = /** @class */ (function () {
2604
+ function PerfEvent(name, payloadDetails, isAsync) {
2605
+ var _self = this;
2606
+ _self.start = utcNow();
2607
+ _self[_DYN_NAME$2 ] = name;
2608
+ _self[_DYN_IS_ASYNC ] = isAsync;
2609
+ _self[_DYN_IS_CHILD_EVT ] = function () { return false; };
2610
+ if (isFunction(payloadDetails)) {
2611
+ var theDetails_1;
2612
+ objDefineAccessors(_self, "payload", function () {
2613
+ if (!theDetails_1 && isFunction(payloadDetails)) {
2614
+ theDetails_1 = payloadDetails();
2615
+ payloadDetails = null;
2616
+ }
2617
+ return theDetails_1;
2618
+ });
2785
2619
  }
2786
- itemCtx.setNext(nextProxy);
2787
- if (plugin) {
2788
- doPerf(itemCtx[STR_CORE ](), function () { return identifier + ":" + name; }, function () {
2789
- hasRunContext[chainId] = true;
2790
- try {
2791
- var nextId = nextProxy ? nextProxy._id : STR_EMPTY;
2792
- if (nextId) {
2793
- hasRunContext[nextId] = false;
2620
+ _self[_DYN_GET_CTX ] = function (key) {
2621
+ if (key) {
2622
+ if (key === PerfEvent[strParentContextKey] || key === PerfEvent[strChildrenContextKey]) {
2623
+ return _self[key];
2624
+ }
2625
+ return (_self[strExecutionContextKey] || {})[key];
2626
+ }
2627
+ return null;
2628
+ };
2629
+ _self[_DYN_SET_CTX ] = function (key, value) {
2630
+ if (key) {
2631
+ if (key === PerfEvent[strParentContextKey]) {
2632
+ if (!_self[key]) {
2633
+ _self[_DYN_IS_CHILD_EVT ] = function () { return true; };
2794
2634
  }
2795
- hasRun = processPluginFn(itemCtx);
2635
+ _self[key] = value;
2796
2636
  }
2797
- catch (error) {
2798
- var hasNextRun = nextProxy ? hasRunContext[nextProxy._id] : true;
2799
- if (hasNextRun) {
2800
- hasRun = true;
2637
+ else if (key === PerfEvent[strChildrenContextKey]) {
2638
+ _self[key] = value;
2639
+ }
2640
+ else {
2641
+ var ctx = _self[strExecutionContextKey] = _self[strExecutionContextKey] || {};
2642
+ ctx[key] = value;
2643
+ }
2644
+ }
2645
+ };
2646
+ _self[_DYN_COMPLETE ] = function () {
2647
+ var childTime = 0;
2648
+ var childEvts = _self[_DYN_GET_CTX ](PerfEvent[strChildrenContextKey]);
2649
+ if (isArray(childEvts)) {
2650
+ for (var lp = 0; lp < childEvts[_DYN_LENGTH$2 ]; lp++) {
2651
+ var childEvt = childEvts[lp];
2652
+ if (childEvt) {
2653
+ childTime += childEvt[_DYN_TIME ];
2801
2654
  }
2802
- if (!nextProxy || !hasNextRun) {
2803
- _throwInternal(itemCtx[_DYN_DIAG_LOG$1 ](), 1 , 73 , "Plugin [" + identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
2655
+ }
2656
+ }
2657
+ _self[_DYN_TIME ] = utcNow() - _self.start;
2658
+ _self.exTime = _self[_DYN_TIME ] - childTime;
2659
+ _self[_DYN_COMPLETE ] = function () { };
2660
+ };
2661
+ }
2662
+ PerfEvent.ParentContextKey = "parent";
2663
+ PerfEvent.ChildrenContextKey = "childEvts";
2664
+ return PerfEvent;
2665
+ }());
2666
+ var PerfManager = /** @class */ (function () {
2667
+ function PerfManager(manager) {
2668
+ this.ctx = {};
2669
+ dynamicProto(PerfManager, this, function (_self) {
2670
+ _self.create = function (src, payloadDetails, isAsync) {
2671
+ return new PerfEvent(src, payloadDetails, isAsync);
2672
+ };
2673
+ _self.fire = function (perfEvent) {
2674
+ if (perfEvent) {
2675
+ perfEvent[_DYN_COMPLETE ]();
2676
+ if (manager && isFunction(manager[STR_PERF_EVENT ])) {
2677
+ manager[STR_PERF_EVENT ](perfEvent);
2804
2678
  }
2805
2679
  }
2806
- }, details, isAsync);
2807
- }
2808
- return hasRun;
2680
+ };
2681
+ _self[_DYN_SET_CTX ] = function (key, value) {
2682
+ if (key) {
2683
+ var ctx = _self[strExecutionContextKey] = _self[strExecutionContextKey] || {};
2684
+ ctx[key] = value;
2685
+ }
2686
+ };
2687
+ _self[_DYN_GET_CTX ] = function (key) {
2688
+ return (_self[strExecutionContextKey] || {})[key];
2689
+ };
2690
+ });
2809
2691
  }
2810
- function _processTelemetry(env, itemCtx) {
2811
- itemCtx = itemCtx || _getTelCtx();
2812
- function _callProcessTelemetry(itemCtx) {
2813
- if (!plugin || !hasProcessTelemetry) {
2814
- return false;
2692
+ PerfManager.__ieDyn=1;
2693
+ return PerfManager;
2694
+ }());
2695
+ var doPerfActiveKey = "CoreUtils.doPerf";
2696
+ function doPerf(mgrSource, getSource, func, details, isAsync) {
2697
+ if (mgrSource) {
2698
+ var perfMgr = mgrSource;
2699
+ if (perfMgr[STR_GET_PERF_MGR]) {
2700
+ perfMgr = perfMgr[STR_GET_PERF_MGR]();
2701
+ }
2702
+ if (perfMgr) {
2703
+ var perfEvt = void 0;
2704
+ var currentActive = perfMgr[_DYN_GET_CTX ](doPerfActiveKey);
2705
+ try {
2706
+ perfEvt = perfMgr.create(getSource(), details, isAsync);
2707
+ if (perfEvt) {
2708
+ if (currentActive && perfEvt[_DYN_SET_CTX ]) {
2709
+ perfEvt[_DYN_SET_CTX ](PerfEvent[strParentContextKey], currentActive);
2710
+ if (currentActive[_DYN_GET_CTX ] && currentActive[_DYN_SET_CTX ]) {
2711
+ var children = currentActive[_DYN_GET_CTX ](PerfEvent[strChildrenContextKey]);
2712
+ if (!children) {
2713
+ children = [];
2714
+ currentActive[_DYN_SET_CTX ](PerfEvent[strChildrenContextKey], children);
2715
+ }
2716
+ children[_DYN_PUSH$1 ](perfEvt);
2717
+ }
2718
+ }
2719
+ perfMgr[_DYN_SET_CTX ](doPerfActiveKey, perfEvt);
2720
+ return func(perfEvt);
2721
+ }
2815
2722
  }
2816
- var pluginState = _getPluginState(plugin);
2817
- if (pluginState[_DYN_TEARDOWN ] || pluginState[STR_DISABLED]) {
2818
- return false;
2723
+ catch (ex) {
2724
+ if (perfEvt && perfEvt[_DYN_SET_CTX ]) {
2725
+ perfEvt[_DYN_SET_CTX ]("exception", ex);
2726
+ }
2819
2727
  }
2820
- if (hasSetNext) {
2821
- plugin[_DYN_SET_NEXT_PLUGIN ](nextProxy);
2728
+ finally {
2729
+ if (perfEvt) {
2730
+ perfMgr.fire(perfEvt);
2731
+ }
2732
+ perfMgr[_DYN_SET_CTX ](doPerfActiveKey, currentActive);
2822
2733
  }
2823
- plugin[STR_PROCESS_TELEMETRY ](env, itemCtx);
2824
- return true;
2825
- }
2826
- if (!_processChain(itemCtx, _callProcessTelemetry, "processTelemetry", function () { return ({ item: env }); }, !(env.sync))) {
2827
- itemCtx[_DYN_PROCESS_NEXT ](env);
2828
2734
  }
2829
2735
  }
2830
- function _unloadPlugin(unloadCtx, unloadState) {
2831
- function _callTeardown() {
2832
- var hasRun = false;
2833
- if (plugin) {
2834
- var pluginState = _getPluginState(plugin);
2835
- var pluginCore = plugin[STR_CORE] || pluginState[STR_CORE ];
2836
- if (plugin && (!pluginCore || pluginCore === unloadCtx.core()) && !pluginState[_DYN_TEARDOWN ]) {
2837
- pluginState[STR_CORE ] = null;
2838
- pluginState[_DYN_TEARDOWN ] = true;
2839
- pluginState[_DYN_IS_INITIALIZED ] = false;
2840
- if (plugin[_DYN_TEARDOWN ] && plugin[_DYN_TEARDOWN ](unloadCtx, unloadState) === true) {
2841
- hasRun = true;
2842
- }
2843
- }
2736
+ return func();
2737
+ }
2738
+ function getGblPerfMgr() {
2739
+ return _defaultPerfManager;
2740
+ }
2741
+
2742
+ var INVALID_TRACE_ID = "00000000000000000000000000000000";
2743
+ var INVALID_SPAN_ID = "0000000000000000";
2744
+ function _isValid(value, len, invalidValue) {
2745
+ if (value && value[_DYN_LENGTH$2 ] === len && value !== invalidValue) {
2746
+ return !!value.match(/^[\da-f]*$/i);
2747
+ }
2748
+ return false;
2749
+ }
2750
+ function isValidTraceId(value) {
2751
+ return _isValid(value, 32, INVALID_TRACE_ID);
2752
+ }
2753
+ function isValidSpanId(value) {
2754
+ return _isValid(value, 16, INVALID_SPAN_ID);
2755
+ }
2756
+
2757
+ var pluginStateData = createElmNodeData("plugin");
2758
+ function _getPluginState(plugin) {
2759
+ return pluginStateData.get(plugin, "state", {}, true);
2760
+ }
2761
+ function initializePlugins(processContext, extensions) {
2762
+ var initPlugins = [];
2763
+ var lastPlugin = null;
2764
+ var proxy = processContext[_DYN_GET_NEXT ]();
2765
+ var pluginState;
2766
+ while (proxy) {
2767
+ var thePlugin = proxy[_DYN_GET_PLUGIN ]();
2768
+ if (thePlugin) {
2769
+ if (lastPlugin && lastPlugin[_DYN_SET_NEXT_PLUGIN ] && thePlugin[STR_PROCESS_TELEMETRY ]) {
2770
+ lastPlugin[_DYN_SET_NEXT_PLUGIN ](thePlugin);
2771
+ }
2772
+ var isInitialized = false;
2773
+ if (isFunction(thePlugin[_DYN_IS_INITIALIZED ])) {
2774
+ isInitialized = thePlugin[_DYN_IS_INITIALIZED ]();
2775
+ }
2776
+ else {
2777
+ pluginState = _getPluginState(thePlugin);
2778
+ isInitialized = pluginState[_DYN_IS_INITIALIZED ];
2844
2779
  }
2845
- return hasRun;
2846
- }
2847
- if (!_processChain(unloadCtx, _callTeardown, "unload", function () { }, unloadState[_DYN_IS_ASYNC ])) {
2848
- unloadCtx[_DYN_PROCESS_NEXT ](unloadState);
2849
- }
2850
- }
2851
- function _updatePlugin(updateCtx, updateState) {
2852
- function _callUpdate() {
2853
- var hasRun = false;
2854
- if (plugin) {
2855
- var pluginState = _getPluginState(plugin);
2856
- var pluginCore = plugin[STR_CORE] || pluginState[STR_CORE ];
2857
- if (plugin && (!pluginCore || pluginCore === updateCtx.core()) && !pluginState[_DYN_TEARDOWN ]) {
2858
- if (plugin[_DYN_UPDATE ] && plugin[_DYN_UPDATE ](updateCtx, updateState) === true) {
2859
- hasRun = true;
2860
- }
2861
- }
2780
+ if (!isInitialized) {
2781
+ initPlugins[_DYN_PUSH$1 ](thePlugin);
2862
2782
  }
2863
- return hasRun;
2864
- }
2865
- if (!_processChain(updateCtx, _callUpdate, "update", function () { }, false)) {
2866
- updateCtx[_DYN_PROCESS_NEXT ](updateState);
2783
+ lastPlugin = thePlugin;
2784
+ proxy = proxy[_DYN_GET_NEXT ]();
2867
2785
  }
2868
2786
  }
2869
- return objFreeze(proxyChain);
2787
+ arrForEach(initPlugins, function (thePlugin) {
2788
+ var core = processContext[STR_CORE ]();
2789
+ thePlugin[_DYN_INITIALIZE ](processContext.getCfg(), core, extensions, processContext[_DYN_GET_NEXT ]());
2790
+ pluginState = _getPluginState(thePlugin);
2791
+ if (!thePlugin[STR_CORE] && !pluginState[STR_CORE]) {
2792
+ pluginState[STR_CORE] = core;
2793
+ }
2794
+ pluginState[_DYN_IS_INITIALIZED ] = true;
2795
+ delete pluginState[_DYN_TEARDOWN ];
2796
+ });
2870
2797
  }
2871
-
2872
- var ChannelControllerPriority = 500;
2873
- var ChannelValidationMessage = "Channel has invalid priority - ";
2874
- function _addChannelQueue(channelQueue, queue, core) {
2875
- if (queue && isArray(queue) && queue[_DYN_LENGTH$2 ] > 0) {
2876
- queue = queue.sort(function (a, b) {
2877
- return a[STR_PRIORITY ] - b[STR_PRIORITY ];
2878
- });
2879
- arrForEach(queue, function (queueItem) {
2880
- if (queueItem[STR_PRIORITY ] < ChannelControllerPriority) {
2881
- throwError(ChannelValidationMessage + queueItem[_DYN_IDENTIFIER ]);
2798
+ function sortPlugins(plugins) {
2799
+ return plugins.sort(function (extA, extB) {
2800
+ var result = 0;
2801
+ if (extB) {
2802
+ var bHasProcess = extB[STR_PROCESS_TELEMETRY];
2803
+ if (extA[STR_PROCESS_TELEMETRY]) {
2804
+ result = bHasProcess ? extA[STR_PRIORITY] - extB[STR_PRIORITY] : 1;
2882
2805
  }
2883
- });
2884
- channelQueue[_DYN_PUSH$1 ]({
2885
- queue: objFreeze(queue),
2886
- chain: createTelemetryProxyChain(queue, core[_DYN_CONFIG ], core)
2887
- });
2888
- }
2889
- }
2890
- function createChannelControllerPlugin(channelQueue, core) {
2891
- function _getTelCtx() {
2892
- return createProcessTelemetryContext(null, core[_DYN_CONFIG ], core, null);
2893
- }
2894
- function _processChannelQueue(theChannels, itemCtx, processFn, onComplete) {
2895
- var waiting = theChannels ? (theChannels[_DYN_LENGTH$2 ] + 1) : 1;
2896
- function _runChainOnComplete() {
2897
- waiting--;
2898
- if (waiting === 0) {
2899
- onComplete && onComplete();
2900
- onComplete = null;
2806
+ else if (bHasProcess) {
2807
+ result = -1;
2901
2808
  }
2902
2809
  }
2903
- if (waiting > 0) {
2904
- arrForEach(theChannels, function (channels) {
2905
- if (channels && channels.queue[_DYN_LENGTH$2 ] > 0) {
2906
- var channelChain = channels.chain;
2907
- var chainCtx = itemCtx[_DYN_CREATE_NEW ](channelChain);
2908
- chainCtx[_DYN_ON_COMPLETE ](_runChainOnComplete);
2909
- processFn(chainCtx);
2910
- }
2911
- else {
2912
- waiting--;
2913
- }
2914
- });
2915
- }
2916
- _runChainOnComplete();
2917
- }
2918
- function _doUpdate(updateCtx, updateState) {
2919
- var theUpdateState = updateState || {
2920
- reason: 0
2921
- };
2922
- _processChannelQueue(channelQueue, updateCtx, function (chainCtx) {
2923
- chainCtx[_DYN_PROCESS_NEXT ](theUpdateState);
2924
- }, function () {
2925
- updateCtx[_DYN_PROCESS_NEXT ](theUpdateState);
2926
- });
2927
- return true;
2928
- }
2929
- function _doTeardown(unloadCtx, unloadState) {
2930
- var theUnloadState = unloadState || {
2931
- reason: 0 ,
2932
- isAsync: false
2933
- };
2934
- _processChannelQueue(channelQueue, unloadCtx, function (chainCtx) {
2935
- chainCtx[_DYN_PROCESS_NEXT ](theUnloadState);
2936
- }, function () {
2937
- unloadCtx[_DYN_PROCESS_NEXT ](theUnloadState);
2938
- isInitialized = false;
2939
- });
2940
- return true;
2941
- }
2942
- function _getChannel(pluginIdentifier) {
2943
- var thePlugin = null;
2944
- if (channelQueue && channelQueue[_DYN_LENGTH$2 ] > 0) {
2945
- arrForEach(channelQueue, function (channels) {
2946
- if (channels && channels.queue[_DYN_LENGTH$2 ] > 0) {
2947
- arrForEach(channels.queue, function (ext) {
2948
- if (ext[_DYN_IDENTIFIER ] === pluginIdentifier) {
2949
- thePlugin = ext;
2950
- return -1;
2951
- }
2952
- });
2953
- if (thePlugin) {
2954
- return -1;
2955
- }
2956
- }
2957
- });
2810
+ else {
2811
+ result = extA ? 1 : -1;
2958
2812
  }
2959
- return thePlugin;
2960
- }
2961
- var isInitialized = false;
2962
- var channelController = {
2963
- identifier: "ChannelControllerPlugin",
2964
- priority: ChannelControllerPriority,
2965
- initialize: function (config, core, extensions, pluginChain) {
2966
- isInitialized = true;
2967
- arrForEach(channelQueue, function (channels) {
2968
- if (channels && channels.queue[_DYN_LENGTH$2 ] > 0) {
2969
- initializePlugins(createProcessTelemetryContext(channels.chain, config, core), extensions);
2970
- }
2971
- });
2813
+ return result;
2814
+ });
2815
+ }
2816
+ function createDistributedTraceContext(parentCtx) {
2817
+ var trace = {};
2818
+ return {
2819
+ getName: function () {
2820
+ return trace[_DYN_NAME$2 ];
2972
2821
  },
2973
- isInitialized: function () {
2974
- return isInitialized;
2822
+ setName: function (newValue) {
2823
+ parentCtx && parentCtx.setName(newValue);
2824
+ trace[_DYN_NAME$2 ] = newValue;
2975
2825
  },
2976
- processTelemetry: function (item, itemCtx) {
2977
- _processChannelQueue(channelQueue, itemCtx || _getTelCtx(), function (chainCtx) {
2978
- chainCtx[_DYN_PROCESS_NEXT ](item);
2979
- }, function () {
2980
- itemCtx[_DYN_PROCESS_NEXT ](item);
2981
- });
2826
+ getTraceId: function () {
2827
+ return trace[_DYN_TRACE_ID$1 ];
2982
2828
  },
2983
- update: _doUpdate,
2984
- pause: function () {
2985
- _processChannelQueue(channelQueue, _getTelCtx(), function (chainCtx) {
2986
- chainCtx.iterate(function (plugin) {
2987
- plugin.pause && plugin.pause();
2988
- });
2989
- }, null);
2829
+ setTraceId: function (newValue) {
2830
+ parentCtx && parentCtx.setTraceId(newValue);
2831
+ if (isValidTraceId(newValue)) {
2832
+ trace[_DYN_TRACE_ID$1 ] = newValue;
2833
+ }
2990
2834
  },
2991
- resume: function () {
2992
- _processChannelQueue(channelQueue, _getTelCtx(), function (chainCtx) {
2993
- chainCtx.iterate(function (plugin) {
2994
- plugin.resume && plugin.resume();
2995
- });
2996
- }, null);
2835
+ getSpanId: function () {
2836
+ return trace[_DYN_SPAN_ID ];
2997
2837
  },
2998
- teardown: _doTeardown,
2999
- getChannel: _getChannel,
3000
- flush: function (isAsync, callBack, sendReason, cbTimeout) {
3001
- var waiting = 1;
3002
- var doneIterating = false;
3003
- var cbTimer = null;
3004
- cbTimeout = cbTimeout || 5000;
3005
- function doCallback() {
3006
- waiting--;
3007
- if (doneIterating && waiting === 0) {
3008
- cbTimer && cbTimer.cancel();
3009
- cbTimer = null;
3010
- callBack && callBack(doneIterating);
3011
- callBack = null;
3012
- }
3013
- }
3014
- _processChannelQueue(channelQueue, _getTelCtx(), function (chainCtx) {
3015
- chainCtx.iterate(function (plugin) {
3016
- if (plugin[_DYN_FLUSH ]) {
3017
- waiting++;
3018
- var handled_1 = false;
3019
- if (!plugin[_DYN_FLUSH ](isAsync, function () {
3020
- handled_1 = true;
3021
- doCallback();
3022
- }, sendReason)) {
3023
- if (!handled_1) {
3024
- if (isAsync && cbTimer == null) {
3025
- cbTimer = scheduleTimeout(function () {
3026
- cbTimer = null;
3027
- doCallback();
3028
- }, cbTimeout);
3029
- }
3030
- else {
3031
- doCallback();
3032
- }
3033
- }
3034
- }
3035
- }
3036
- });
3037
- }, function () {
3038
- doneIterating = true;
3039
- doCallback();
3040
- });
3041
- return true;
2838
+ setSpanId: function (newValue) {
2839
+ parentCtx && parentCtx.setSpanId(newValue);
2840
+ if (isValidSpanId(newValue)) {
2841
+ trace[_DYN_SPAN_ID ] = newValue;
2842
+ }
2843
+ },
2844
+ getTraceFlags: function () {
2845
+ return trace[_DYN_TRACE_FLAGS ];
3042
2846
  },
3043
- _setQueue: function (queue) {
3044
- channelQueue = queue;
2847
+ setTraceFlags: function (newTraceFlags) {
2848
+ parentCtx && parentCtx.setTraceFlags(newTraceFlags);
2849
+ trace[_DYN_TRACE_FLAGS ] = newTraceFlags;
3045
2850
  }
3046
2851
  };
3047
- return channelController;
3048
- }
3049
- function createChannelQueues(channels, extensions, core) {
3050
- var channelQueue = [];
3051
- if (channels) {
3052
- arrForEach(channels, function (queue) { return _addChannelQueue(channelQueue, queue, core); });
3053
- }
3054
- if (extensions) {
3055
- var extensionQueue_1 = [];
3056
- arrForEach(extensions, function (plugin) {
3057
- if (plugin[STR_PRIORITY ] > ChannelControllerPriority) {
3058
- extensionQueue_1[_DYN_PUSH$1 ](plugin);
3059
- }
3060
- });
3061
- _addChannelQueue(channelQueue, extensionQueue_1, core);
3062
- }
3063
- return channelQueue;
3064
2852
  }
3065
2853
 
3066
- var _a$3, _b$1;
3067
- var strToGMTString = "toGMTString";
3068
- var strToUTCString = "toUTCString";
3069
- var strCookie = "cookie";
3070
- var strExpires = "expires";
3071
- var strIsCookieUseDisabled = "isCookieUseDisabled";
3072
- var strDisableCookiesUsage = "disableCookiesUsage";
3073
- var strConfigCookieMgr = "_ckMgr";
3074
- var _supportsCookies = null;
3075
- var _allowUaSameSite = null;
3076
- var _parsedCookieValue = null;
3077
- var _doc = getDocument();
3078
- var _cookieCache = {};
3079
- var _globalCookieConfig = {};
3080
- var defaultConfig$1 = objDeepFreeze((_a$3 = {},
3081
- _a$3[STR_DOMAIN] = { fb: "cookieDomain", dfVal: isNotNullOrUndefined },
3082
- _a$3.path = { fb: "cookiePath", dfVal: isNotNullOrUndefined },
3083
- _a$3.enabled = UNDEFINED_VALUE$1,
3084
- _a$3));
3085
- var rootDefaultConfig = (_b$1 = {
3086
- cookieCfg: {},
3087
- cookieDomain: UNDEFINED_VALUE$1,
3088
- cookiePath: UNDEFINED_VALUE$1
3089
- },
3090
- _b$1[strDisableCookiesUsage] = UNDEFINED_VALUE$1,
3091
- _b$1);
3092
- function _isMgrEnabled(cookieMgr) {
3093
- if (cookieMgr) {
3094
- return cookieMgr.isEnabled();
3095
- }
3096
- return true;
3097
- }
3098
- function _isIgnoredCookie(cookieMgrCfg, name) {
3099
- if (name && cookieMgrCfg && isArray(cookieMgrCfg.ignoreCookies)) {
3100
- return arrIndexOf(cookieMgrCfg.ignoreCookies, name) !== -1;
3101
- }
3102
- return false;
3103
- }
3104
- function _isBlockedCookie(cookieMgrCfg, name) {
3105
- if (name && cookieMgrCfg && isArray(cookieMgrCfg.blockedCookies)) {
3106
- if (arrIndexOf(cookieMgrCfg.blockedCookies, name) !== -1) {
3107
- return true;
2854
+ var strTelemetryPluginChain = "TelemetryPluginChain";
2855
+ var strHasRunFlags = "_hasRun";
2856
+ var strGetTelCtx = "_getTelCtx";
2857
+ var _chainId = 0;
2858
+ function _getNextProxyStart(proxy, core, startAt) {
2859
+ while (proxy) {
2860
+ if (proxy[_DYN_GET_PLUGIN ]() === startAt) {
2861
+ return proxy;
3108
2862
  }
2863
+ proxy = proxy[_DYN_GET_NEXT ]();
3109
2864
  }
3110
- return _isIgnoredCookie(cookieMgrCfg, name);
2865
+ return createTelemetryProxyChain([startAt], core.config || {}, core);
3111
2866
  }
3112
- function createCookieMgr(rootConfig, logger) {
3113
- var cookieMgrConfig;
3114
- var _path;
3115
- var _domain;
3116
- var _enabled;
3117
- var _getCookieFn;
3118
- var _setCookieFn;
3119
- var _delCookieFn;
3120
- rootConfig = createDynamicConfig(rootConfig || _globalCookieConfig, null, logger).cfg;
3121
- onConfigChange(rootConfig, function (details) {
3122
- details[_DYN_SET_DF ](details.cfg, rootDefaultConfig);
3123
- cookieMgrConfig = details[_DYN_SET_DF ](details.cfg.cookieCfg, defaultConfig$1);
3124
- var isEnabled = cookieMgrConfig.enabled;
3125
- if (isNullOrUndefined(isEnabled)) {
3126
- var cookieEnabled = void 0;
3127
- if (!isUndefined(rootConfig[strIsCookieUseDisabled])) {
3128
- cookieEnabled = !rootConfig[strIsCookieUseDisabled];
3129
- }
3130
- if (!isUndefined(rootConfig[strDisableCookiesUsage])) {
3131
- cookieEnabled = !rootConfig[strDisableCookiesUsage];
3132
- }
3133
- isEnabled = cookieEnabled;
3134
- }
3135
- _path = cookieMgrConfig[STR_PATH ] || "/";
3136
- _domain = cookieMgrConfig[STR_DOMAIN ];
3137
- _enabled = isEnabled !== false;
3138
- _getCookieFn = cookieMgrConfig.getCookie || _getCookieValue;
3139
- _setCookieFn = cookieMgrConfig.setCookie || _setCookieValue;
3140
- _delCookieFn = cookieMgrConfig.delCookie || _setCookieValue;
3141
- }, logger);
3142
- var cookieMgr = {
3143
- isEnabled: function () {
3144
- var enabled = _enabled && areCookiesSupported(logger);
3145
- var gblManager = _globalCookieConfig[strConfigCookieMgr];
3146
- if (enabled && gblManager && cookieMgr !== gblManager) {
3147
- enabled = _isMgrEnabled(gblManager);
3148
- }
3149
- return enabled;
3150
- },
3151
- setEnabled: function (value) {
3152
- _enabled = value !== false;
3153
- },
3154
- set: function (name, value, maxAgeSec, domain, path) {
3155
- var result = false;
3156
- if (_isMgrEnabled(cookieMgr) && !_isBlockedCookie(cookieMgrConfig, name)) {
3157
- var values = {};
3158
- var theValue = strTrim(value || STR_EMPTY);
3159
- var idx = strIndexOf(theValue, ";");
3160
- if (idx !== -1) {
3161
- theValue = strTrim(strLeft(value, idx));
3162
- values = _extractParts(strSubstring(value, idx + 1));
3163
- }
3164
- setValue(values, STR_DOMAIN, domain || _domain, isTruthy, isUndefined);
3165
- if (!isNullOrUndefined(maxAgeSec)) {
3166
- var _isIE = isIE();
3167
- if (isUndefined(values[strExpires])) {
3168
- var nowMs = utcNow();
3169
- var expireMs = nowMs + (maxAgeSec * 1000);
3170
- if (expireMs > 0) {
3171
- var expiry = new Date();
3172
- expiry.setTime(expireMs);
3173
- setValue(values, strExpires, _formatDate(expiry, !_isIE ? strToUTCString : strToGMTString) || _formatDate(expiry, _isIE ? strToGMTString : strToUTCString) || STR_EMPTY, isTruthy);
3174
- }
3175
- }
3176
- if (!_isIE) {
3177
- setValue(values, "max-age", STR_EMPTY + maxAgeSec, null, isUndefined);
3178
- }
3179
- }
3180
- var location_1 = getLocation();
3181
- if (location_1 && location_1.protocol === "https:") {
3182
- setValue(values, "secure", null, null, isUndefined);
3183
- if (_allowUaSameSite === null) {
3184
- _allowUaSameSite = !uaDisallowsSameSiteNone((getNavigator() || {})[_DYN_USER_AGENT ]);
2867
+ function _createInternalContext(telemetryChain, dynamicHandler, core, startAt) {
2868
+ var _nextProxy = null;
2869
+ var _onComplete = [];
2870
+ if (!dynamicHandler) {
2871
+ dynamicHandler = createDynamicConfig({}, null, core[_DYN_LOGGER ]);
2872
+ }
2873
+ if (startAt !== null) {
2874
+ _nextProxy = startAt ? _getNextProxyStart(telemetryChain, core, startAt) : telemetryChain;
2875
+ }
2876
+ var context = {
2877
+ _next: _moveNext,
2878
+ ctx: {
2879
+ core: function () {
2880
+ return core;
2881
+ },
2882
+ diagLog: function () {
2883
+ return safeGetLogger(core, dynamicHandler.cfg);
2884
+ },
2885
+ getCfg: function () {
2886
+ return dynamicHandler.cfg;
2887
+ },
2888
+ getExtCfg: _resolveExtCfg,
2889
+ getConfig: _getConfig,
2890
+ hasNext: function () {
2891
+ return !!_nextProxy;
2892
+ },
2893
+ getNext: function () {
2894
+ return _nextProxy;
2895
+ },
2896
+ setNext: function (nextPlugin) {
2897
+ _nextProxy = nextPlugin;
2898
+ },
2899
+ iterate: _iterateChain,
2900
+ onComplete: _addOnComplete
2901
+ }
2902
+ };
2903
+ function _addOnComplete(onComplete, that) {
2904
+ var args = [];
2905
+ for (var _i = 2; _i < arguments.length; _i++) {
2906
+ args[_i - 2] = arguments[_i];
2907
+ }
2908
+ if (onComplete) {
2909
+ _onComplete[_DYN_PUSH$1 ]({
2910
+ func: onComplete,
2911
+ self: !isUndefined(that) ? that : context.ctx,
2912
+ args: args
2913
+ });
2914
+ }
2915
+ }
2916
+ function _moveNext() {
2917
+ var nextProxy = _nextProxy;
2918
+ _nextProxy = nextProxy ? nextProxy[_DYN_GET_NEXT ]() : null;
2919
+ if (!nextProxy) {
2920
+ var onComplete = _onComplete;
2921
+ if (onComplete && onComplete[_DYN_LENGTH$2 ] > 0) {
2922
+ arrForEach(onComplete, function (completeDetails) {
2923
+ try {
2924
+ completeDetails.func[_DYN_CALL ](completeDetails.self, completeDetails.args);
3185
2925
  }
3186
- if (_allowUaSameSite) {
3187
- setValue(values, "SameSite", "None", null, isUndefined);
2926
+ catch (e) {
2927
+ _throwInternal(core[_DYN_LOGGER ], 2 , 73 , "Unexpected Exception during onComplete - " + dumpObj(e));
3188
2928
  }
3189
- }
3190
- setValue(values, STR_PATH, path || _path, null, isUndefined);
3191
- _setCookieFn(name, _formatCookieValue(theValue, values));
3192
- result = true;
3193
- }
3194
- return result;
3195
- },
3196
- get: function (name) {
3197
- var value = STR_EMPTY;
3198
- if (_isMgrEnabled(cookieMgr) && !_isIgnoredCookie(cookieMgrConfig, name)) {
3199
- value = _getCookieFn(name);
2929
+ });
2930
+ _onComplete = [];
3200
2931
  }
3201
- return value;
3202
- },
3203
- del: function (name, path) {
3204
- var result = false;
3205
- if (_isMgrEnabled(cookieMgr)) {
3206
- result = cookieMgr.purge(name, path);
2932
+ }
2933
+ return nextProxy;
2934
+ }
2935
+ function _getExtCfg(identifier, createIfMissing) {
2936
+ var idCfg = null;
2937
+ var cfg = dynamicHandler.cfg;
2938
+ if (cfg && identifier) {
2939
+ var extCfg = cfg[STR_EXTENSION_CONFIG ];
2940
+ if (!extCfg && createIfMissing) {
2941
+ extCfg = {};
3207
2942
  }
3208
- return result;
3209
- },
3210
- purge: function (name, path) {
3211
- var _a;
3212
- var result = false;
3213
- if (areCookiesSupported(logger)) {
3214
- var values = (_a = {},
3215
- _a[STR_PATH] = path ? path : "/",
3216
- _a[strExpires] = "Thu, 01 Jan 1970 00:00:01 GMT",
3217
- _a);
3218
- if (!isIE()) {
3219
- values["max-age"] = "0";
2943
+ dynamicHandler.set(cfg, STR_EXTENSION_CONFIG, extCfg);
2944
+ extCfg = cfg[STR_EXTENSION_CONFIG ];
2945
+ if (extCfg) {
2946
+ idCfg = extCfg[identifier];
2947
+ if (!idCfg && createIfMissing) {
2948
+ idCfg = {};
3220
2949
  }
3221
- _delCookieFn(name, _formatCookieValue(STR_EMPTY, values));
3222
- result = true;
2950
+ dynamicHandler.set(extCfg, identifier, idCfg);
2951
+ idCfg = extCfg[identifier];
3223
2952
  }
3224
- return result;
3225
2953
  }
3226
- };
3227
- cookieMgr[strConfigCookieMgr] = cookieMgr;
3228
- return cookieMgr;
3229
- }
3230
- function areCookiesSupported(logger) {
3231
- if (_supportsCookies === null) {
3232
- _supportsCookies = false;
3233
- try {
3234
- var doc = _doc || {};
3235
- _supportsCookies = doc[strCookie] !== undefined;
2954
+ return idCfg;
2955
+ }
2956
+ function _resolveExtCfg(identifier, defaultValues) {
2957
+ var newConfig = _getExtCfg(identifier, true);
2958
+ if (defaultValues) {
2959
+ objForEachKey(defaultValues, function (field, defaultValue) {
2960
+ if (isNullOrUndefined(newConfig[field])) {
2961
+ var cfgValue = dynamicHandler.cfg[field];
2962
+ if (cfgValue || !isNullOrUndefined(cfgValue)) {
2963
+ newConfig[field] = cfgValue;
2964
+ }
2965
+ }
2966
+ _applyDefaultValue(dynamicHandler, newConfig, field, defaultValue);
2967
+ });
3236
2968
  }
3237
- catch (e) {
3238
- _throwInternal(logger, 2 , 68 , "Cannot access document.cookie - " + getExceptionName(e), { exception: dumpObj(e) });
2969
+ return dynamicHandler[_DYN_SET_DF ](newConfig, defaultValues);
2970
+ }
2971
+ function _getConfig(identifier, field, defaultValue) {
2972
+ if (defaultValue === void 0) { defaultValue = false; }
2973
+ var theValue;
2974
+ var extConfig = _getExtCfg(identifier, false);
2975
+ var rootConfig = dynamicHandler.cfg;
2976
+ if (extConfig && (extConfig[field] || !isNullOrUndefined(extConfig[field]))) {
2977
+ theValue = extConfig[field];
3239
2978
  }
2979
+ else if (rootConfig[field] || !isNullOrUndefined(rootConfig[field])) {
2980
+ theValue = rootConfig[field];
2981
+ }
2982
+ return (theValue || !isNullOrUndefined(theValue)) ? theValue : defaultValue;
3240
2983
  }
3241
- return _supportsCookies;
3242
- }
3243
- function _extractParts(theValue) {
3244
- var values = {};
3245
- if (theValue && theValue[_DYN_LENGTH$2 ]) {
3246
- var parts = strTrim(theValue)[_DYN_SPLIT$1 ](";");
3247
- arrForEach(parts, function (thePart) {
3248
- thePart = strTrim(thePart || STR_EMPTY);
3249
- if (thePart) {
3250
- var idx = strIndexOf(thePart, "=");
3251
- if (idx === -1) {
3252
- values[thePart] = null;
3253
- }
3254
- else {
3255
- values[strTrim(strLeft(thePart, idx))] = strTrim(strSubstring(thePart, idx + 1));
3256
- }
2984
+ function _iterateChain(cb) {
2985
+ var nextPlugin;
2986
+ while (!!(nextPlugin = context._next())) {
2987
+ var plugin = nextPlugin[_DYN_GET_PLUGIN ]();
2988
+ if (plugin) {
2989
+ cb(plugin);
3257
2990
  }
3258
- });
2991
+ }
3259
2992
  }
3260
- return values;
2993
+ return context;
3261
2994
  }
3262
- function _formatDate(theDate, func) {
3263
- if (isFunction(theDate[func])) {
3264
- return theDate[func]();
2995
+ function createProcessTelemetryContext(telemetryChain, cfg, core, startAt) {
2996
+ var config = createDynamicConfig(cfg);
2997
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
2998
+ var context = internalContext.ctx;
2999
+ function _processNext(env) {
3000
+ var nextPlugin = internalContext._next();
3001
+ if (nextPlugin) {
3002
+ nextPlugin[STR_PROCESS_TELEMETRY ](env, context);
3003
+ }
3004
+ return !nextPlugin;
3265
3005
  }
3266
- return null;
3267
- }
3268
- function _formatCookieValue(value, values) {
3269
- var cookieValue = value || STR_EMPTY;
3270
- objForEachKey(values, function (name, theValue) {
3271
- cookieValue += "; " + name + (!isNullOrUndefined(theValue) ? "=" + theValue : STR_EMPTY);
3272
- });
3273
- return cookieValue;
3274
- }
3275
- function _getCookieValue(name) {
3276
- var cookieValue = STR_EMPTY;
3277
- if (_doc) {
3278
- var theCookie = _doc[strCookie] || STR_EMPTY;
3279
- if (_parsedCookieValue !== theCookie) {
3280
- _cookieCache = _extractParts(theCookie);
3281
- _parsedCookieValue = theCookie;
3006
+ function _createNew(plugins, startAt) {
3007
+ if (plugins === void 0) { plugins = null; }
3008
+ if (isArray(plugins)) {
3009
+ plugins = createTelemetryProxyChain(plugins, config.cfg, core, startAt);
3282
3010
  }
3283
- cookieValue = strTrim(_cookieCache[name] || STR_EMPTY);
3011
+ return createProcessTelemetryContext(plugins || context[_DYN_GET_NEXT ](), config.cfg, core, startAt);
3284
3012
  }
3285
- return cookieValue;
3013
+ context[_DYN_PROCESS_NEXT ] = _processNext;
3014
+ context[_DYN_CREATE_NEW ] = _createNew;
3015
+ return context;
3286
3016
  }
3287
- function _setCookieValue(name, cookieValue) {
3288
- if (_doc) {
3289
- _doc[strCookie] = name + "=" + cookieValue;
3017
+ function createProcessTelemetryUnloadContext(telemetryChain, core, startAt) {
3018
+ var config = createDynamicConfig(core.config);
3019
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
3020
+ var context = internalContext.ctx;
3021
+ function _processNext(unloadState) {
3022
+ var nextPlugin = internalContext._next();
3023
+ nextPlugin && nextPlugin.unload(context, unloadState);
3024
+ return !nextPlugin;
3025
+ }
3026
+ function _createNew(plugins, startAt) {
3027
+ if (plugins === void 0) { plugins = null; }
3028
+ if (isArray(plugins)) {
3029
+ plugins = createTelemetryProxyChain(plugins, config.cfg, core, startAt);
3030
+ }
3031
+ return createProcessTelemetryUnloadContext(plugins || context[_DYN_GET_NEXT ](), core, startAt);
3290
3032
  }
3033
+ context[_DYN_PROCESS_NEXT ] = _processNext;
3034
+ context[_DYN_CREATE_NEW ] = _createNew;
3035
+ return context;
3291
3036
  }
3292
- function uaDisallowsSameSiteNone(userAgent) {
3293
- if (!isString(userAgent)) {
3294
- return false;
3037
+ function createProcessTelemetryUpdateContext(telemetryChain, core, startAt) {
3038
+ var config = createDynamicConfig(core.config);
3039
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
3040
+ var context = internalContext.ctx;
3041
+ function _processNext(updateState) {
3042
+ return context.iterate(function (plugin) {
3043
+ if (isFunction(plugin[_DYN_UPDATE ])) {
3044
+ plugin[_DYN_UPDATE ](context, updateState);
3045
+ }
3046
+ });
3295
3047
  }
3296
- if (strContains(userAgent, "CPU iPhone OS 12") || strContains(userAgent, "iPad; CPU OS 12")) {
3297
- return true;
3048
+ function _createNew(plugins, startAt) {
3049
+ if (plugins === void 0) { plugins = null; }
3050
+ if (isArray(plugins)) {
3051
+ plugins = createTelemetryProxyChain(plugins, config.cfg, core, startAt);
3052
+ }
3053
+ return createProcessTelemetryUpdateContext(plugins || context[_DYN_GET_NEXT ](), core, startAt);
3298
3054
  }
3299
- if (strContains(userAgent, "Macintosh; Intel Mac OS X 10_14") && strContains(userAgent, "Version/") && strContains(userAgent, "Safari")) {
3300
- return true;
3055
+ context[_DYN_PROCESS_NEXT ] = _processNext;
3056
+ context[_DYN_CREATE_NEW ] = _createNew;
3057
+ return context;
3058
+ }
3059
+ function createTelemetryProxyChain(plugins, config, core, startAt) {
3060
+ var firstProxy = null;
3061
+ var add = startAt ? false : true;
3062
+ if (isArray(plugins) && plugins[_DYN_LENGTH$2 ] > 0) {
3063
+ var lastProxy_1 = null;
3064
+ arrForEach(plugins, function (thePlugin) {
3065
+ if (!add && startAt === thePlugin) {
3066
+ add = true;
3067
+ }
3068
+ if (add && thePlugin && isFunction(thePlugin[STR_PROCESS_TELEMETRY ])) {
3069
+ var newProxy = createTelemetryPluginProxy(thePlugin, config, core);
3070
+ if (!firstProxy) {
3071
+ firstProxy = newProxy;
3072
+ }
3073
+ if (lastProxy_1) {
3074
+ lastProxy_1._setNext(newProxy);
3075
+ }
3076
+ lastProxy_1 = newProxy;
3077
+ }
3078
+ });
3301
3079
  }
3302
- if (strContains(userAgent, "Macintosh; Intel Mac OS X 10_14") && strEndsWith(userAgent, "AppleWebKit/605.1.15 (KHTML, like Gecko)")) {
3303
- return true;
3080
+ if (startAt && !firstProxy) {
3081
+ return createTelemetryProxyChain([startAt], config, core);
3304
3082
  }
3305
- if (strContains(userAgent, "Chrome/5") || strContains(userAgent, "Chrome/6")) {
3306
- return true;
3083
+ return firstProxy;
3084
+ }
3085
+ function createTelemetryPluginProxy(plugin, config, core) {
3086
+ var nextProxy = null;
3087
+ var hasProcessTelemetry = isFunction(plugin[STR_PROCESS_TELEMETRY ]);
3088
+ var hasSetNext = isFunction(plugin[_DYN_SET_NEXT_PLUGIN ]);
3089
+ var chainId;
3090
+ if (plugin) {
3091
+ chainId = plugin[_DYN_IDENTIFIER ] + "-" + plugin[STR_PRIORITY ] + "-" + _chainId++;
3307
3092
  }
3308
- if (strContains(userAgent, "UnrealEngine") && !strContains(userAgent, "Chrome")) {
3309
- return true;
3093
+ else {
3094
+ chainId = "Unknown-0-" + _chainId++;
3310
3095
  }
3311
- if (strContains(userAgent, "UCBrowser/12") || strContains(userAgent, "UCBrowser/11")) {
3312
- return true;
3096
+ var proxyChain = {
3097
+ getPlugin: function () {
3098
+ return plugin;
3099
+ },
3100
+ getNext: function () {
3101
+ return nextProxy;
3102
+ },
3103
+ processTelemetry: _processTelemetry,
3104
+ unload: _unloadPlugin,
3105
+ update: _updatePlugin,
3106
+ _id: chainId,
3107
+ _setNext: function (nextPlugin) {
3108
+ nextProxy = nextPlugin;
3109
+ }
3110
+ };
3111
+ function _getTelCtx() {
3112
+ var itemCtx;
3113
+ if (plugin && isFunction(plugin[strGetTelCtx])) {
3114
+ itemCtx = plugin[strGetTelCtx]();
3115
+ }
3116
+ if (!itemCtx) {
3117
+ itemCtx = createProcessTelemetryContext(proxyChain, config, core);
3118
+ }
3119
+ return itemCtx;
3313
3120
  }
3314
- return false;
3315
- }
3316
-
3317
- var defaultValues$1 = {
3318
- perfEvtsSendAll: false
3319
- };
3320
- function _runListeners(listeners, name, isAsync, callback) {
3321
- arrForEach(listeners, function (listener) {
3322
- if (listener && listener[name]) {
3323
- if (isAsync) {
3324
- scheduleTimeout(function () { return callback(listener); }, 0);
3325
- }
3326
- else {
3121
+ function _processChain(itemCtx, processPluginFn, name, details, isAsync) {
3122
+ var hasRun = false;
3123
+ var identifier = plugin ? plugin[_DYN_IDENTIFIER ] : strTelemetryPluginChain;
3124
+ var hasRunContext = itemCtx[strHasRunFlags];
3125
+ if (!hasRunContext) {
3126
+ hasRunContext = itemCtx[strHasRunFlags] = {};
3127
+ }
3128
+ itemCtx.setNext(nextProxy);
3129
+ if (plugin) {
3130
+ doPerf(itemCtx[STR_CORE ](), function () { return identifier + ":" + name; }, function () {
3131
+ hasRunContext[chainId] = true;
3327
3132
  try {
3328
- callback(listener);
3133
+ var nextId = nextProxy ? nextProxy._id : STR_EMPTY;
3134
+ if (nextId) {
3135
+ hasRunContext[nextId] = false;
3136
+ }
3137
+ hasRun = processPluginFn(itemCtx);
3329
3138
  }
3330
- catch (e) {
3139
+ catch (error) {
3140
+ var hasNextRun = nextProxy ? hasRunContext[nextProxy._id] : true;
3141
+ if (hasNextRun) {
3142
+ hasRun = true;
3143
+ }
3144
+ if (!nextProxy || !hasNextRun) {
3145
+ _throwInternal(itemCtx[_DYN_DIAG_LOG$1 ](), 1 , 73 , "Plugin [" + identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
3146
+ }
3331
3147
  }
3148
+ }, details, isAsync);
3149
+ }
3150
+ return hasRun;
3151
+ }
3152
+ function _processTelemetry(env, itemCtx) {
3153
+ itemCtx = itemCtx || _getTelCtx();
3154
+ function _callProcessTelemetry(itemCtx) {
3155
+ if (!plugin || !hasProcessTelemetry) {
3156
+ return false;
3332
3157
  }
3158
+ var pluginState = _getPluginState(plugin);
3159
+ if (pluginState[_DYN_TEARDOWN ] || pluginState[STR_DISABLED]) {
3160
+ return false;
3161
+ }
3162
+ if (hasSetNext) {
3163
+ plugin[_DYN_SET_NEXT_PLUGIN ](nextProxy);
3164
+ }
3165
+ plugin[STR_PROCESS_TELEMETRY ](env, itemCtx);
3166
+ return true;
3333
3167
  }
3334
- });
3335
- }
3336
- var NotificationManager = /** @class */ (function () {
3337
- function NotificationManager(config) {
3338
- this.listeners = [];
3339
- var perfEvtsSendAll;
3340
- var cfgHandler = createDynamicConfig(config, defaultValues$1);
3341
- cfgHandler[_DYN_WATCH ](function (details) {
3342
- perfEvtsSendAll = !!details.cfg.perfEvtsSendAll;
3343
- });
3344
- dynamicProto(NotificationManager, this, function (_self) {
3345
- _self[_DYN_ADD_NOTIFICATION_LIS1 ] = function (listener) {
3346
- _self.listeners[_DYN_PUSH$1 ](listener);
3347
- };
3348
- _self[_DYN_REMOVE_NOTIFICATION_2 ] = function (listener) {
3349
- var index = arrIndexOf(_self[_DYN_LISTENERS ], listener);
3350
- while (index > -1) {
3351
- _self.listeners[_DYN_SPLICE ](index, 1);
3352
- index = arrIndexOf(_self[_DYN_LISTENERS ], listener);
3168
+ if (!_processChain(itemCtx, _callProcessTelemetry, "processTelemetry", function () { return ({ item: env }); }, !(env.sync))) {
3169
+ itemCtx[_DYN_PROCESS_NEXT ](env);
3170
+ }
3171
+ }
3172
+ function _unloadPlugin(unloadCtx, unloadState) {
3173
+ function _callTeardown() {
3174
+ var hasRun = false;
3175
+ if (plugin) {
3176
+ var pluginState = _getPluginState(plugin);
3177
+ var pluginCore = plugin[STR_CORE] || pluginState[STR_CORE ];
3178
+ if (plugin && (!pluginCore || pluginCore === unloadCtx.core()) && !pluginState[_DYN_TEARDOWN ]) {
3179
+ pluginState[STR_CORE ] = null;
3180
+ pluginState[_DYN_TEARDOWN ] = true;
3181
+ pluginState[_DYN_IS_INITIALIZED ] = false;
3182
+ if (plugin[_DYN_TEARDOWN ] && plugin[_DYN_TEARDOWN ](unloadCtx, unloadState) === true) {
3183
+ hasRun = true;
3184
+ }
3353
3185
  }
3354
- };
3355
- _self[STR_EVENTS_SENT ] = function (events) {
3356
- _runListeners(_self[_DYN_LISTENERS ], STR_EVENTS_SENT, true, function (listener) {
3357
- listener[STR_EVENTS_SENT ](events);
3358
- });
3359
- };
3360
- _self[STR_EVENTS_DISCARDED ] = function (events, reason) {
3361
- _runListeners(_self[_DYN_LISTENERS ], STR_EVENTS_DISCARDED, true, function (listener) {
3362
- listener[STR_EVENTS_DISCARDED ](events, reason);
3363
- });
3364
- };
3365
- _self[STR_EVENTS_SEND_REQUEST ] = function (sendReason, isAsync) {
3366
- _runListeners(_self[_DYN_LISTENERS ], STR_EVENTS_SEND_REQUEST, isAsync, function (listener) {
3367
- listener[STR_EVENTS_SEND_REQUEST ](sendReason, isAsync);
3368
- });
3369
- };
3370
- _self[STR_PERF_EVENT ] = function (perfEvent) {
3371
- if (perfEvent) {
3372
- if (perfEvtsSendAll || !perfEvent[_DYN_IS_CHILD_EVT ]()) {
3373
- _runListeners(_self[_DYN_LISTENERS ], STR_PERF_EVENT, false, function (listener) {
3374
- if (perfEvent[_DYN_IS_ASYNC ]) {
3375
- scheduleTimeout(function () { return listener[STR_PERF_EVENT ](perfEvent); }, 0);
3376
- }
3377
- else {
3378
- listener[STR_PERF_EVENT ](perfEvent);
3379
- }
3380
- });
3186
+ }
3187
+ return hasRun;
3188
+ }
3189
+ if (!_processChain(unloadCtx, _callTeardown, "unload", function () { }, unloadState[_DYN_IS_ASYNC ])) {
3190
+ unloadCtx[_DYN_PROCESS_NEXT ](unloadState);
3191
+ }
3192
+ }
3193
+ function _updatePlugin(updateCtx, updateState) {
3194
+ function _callUpdate() {
3195
+ var hasRun = false;
3196
+ if (plugin) {
3197
+ var pluginState = _getPluginState(plugin);
3198
+ var pluginCore = plugin[STR_CORE] || pluginState[STR_CORE ];
3199
+ if (plugin && (!pluginCore || pluginCore === updateCtx.core()) && !pluginState[_DYN_TEARDOWN ]) {
3200
+ if (plugin[_DYN_UPDATE ] && plugin[_DYN_UPDATE ](updateCtx, updateState) === true) {
3201
+ hasRun = true;
3381
3202
  }
3382
3203
  }
3383
- };
3384
- });
3204
+ }
3205
+ return hasRun;
3206
+ }
3207
+ if (!_processChain(updateCtx, _callUpdate, "update", function () { }, false)) {
3208
+ updateCtx[_DYN_PROCESS_NEXT ](updateState);
3209
+ }
3385
3210
  }
3386
- NotificationManager.__ieDyn=1;
3387
- return NotificationManager;
3388
- }());
3211
+ return objFreeze(proxyChain);
3212
+ }
3389
3213
 
3390
3214
  function createUnloadHandlerContainer() {
3391
3215
  var handlers = [];
@@ -3426,7 +3250,7 @@
3426
3250
  var _hooks;
3427
3251
  _initDefaults();
3428
3252
  dynamicProto(BaseTelemetryPlugin, _self, function (_self) {
3429
- _self[_DYN_INITIALIZE$1 ] = function (config, core, extensions, pluginChain) {
3253
+ _self[_DYN_INITIALIZE ] = function (config, core, extensions, pluginChain) {
3430
3254
  _setDefaults(config, core, pluginChain);
3431
3255
  _isinitialized = true;
3432
3256
  };
@@ -3648,9 +3472,10 @@
3648
3472
  function _validateExtensions(logger, channelPriority, allExtensions) {
3649
3473
  var _a;
3650
3474
  var coreExtensions = [];
3475
+ var channels = [];
3651
3476
  var extPriorities = {};
3652
3477
  arrForEach(allExtensions, function (ext) {
3653
- if (isNullOrUndefined(ext) || isNullOrUndefined(ext[_DYN_INITIALIZE$1 ])) {
3478
+ if (isNullOrUndefined(ext) || isNullOrUndefined(ext[_DYN_INITIALIZE ])) {
3654
3479
  throwError(strValidationError);
3655
3480
  }
3656
3481
  var extPriority = ext[STR_PRIORITY ];
@@ -3666,11 +3491,13 @@
3666
3491
  if (!extPriority || extPriority < channelPriority) {
3667
3492
  coreExtensions[_DYN_PUSH$1 ](ext);
3668
3493
  }
3494
+ else {
3495
+ channels[_DYN_PUSH$1 ](ext);
3496
+ }
3669
3497
  });
3670
- return _a = {
3671
- all: allExtensions
3672
- },
3498
+ return _a = {},
3673
3499
  _a[STR_CORE ] = coreExtensions,
3500
+ _a[STR_CHANNELS ] = channels,
3674
3501
  _a;
3675
3502
  }
3676
3503
  function _isPluginPresent(thePlugin, plugins) {
@@ -3748,10 +3575,8 @@
3748
3575
  var _cookieManager;
3749
3576
  var _pluginChain;
3750
3577
  var _configExtensions;
3751
- var _coreExtensions;
3752
- var _channelControl;
3753
3578
  var _channelConfig;
3754
- var _channelQueue;
3579
+ var _channels;
3755
3580
  var _isUnloading;
3756
3581
  var _telemetryInitializerPlugin;
3757
3582
  var _internalLogsEventName;
@@ -3765,14 +3590,15 @@
3765
3590
  var _extensions;
3766
3591
  var _pluginVersionStringArr;
3767
3592
  var _pluginVersionString;
3768
- var _internalLogPoller = 0;
3593
+ var _internalLogPoller;
3594
+ var _internalLogPollerListening;
3769
3595
  dynamicProto(AppInsightsCore, this, function (_self) {
3770
3596
  _initDefaults();
3771
3597
  _self["_getDbgPlgTargets"] = function () {
3772
3598
  return [_extensions];
3773
3599
  };
3774
3600
  _self[_DYN_IS_INITIALIZED ] = function () { return _isInitialized; };
3775
- _self[_DYN_INITIALIZE$1 ] = function (config, extensions, logger, notificationManager) {
3601
+ _self[_DYN_INITIALIZE ] = function (config, extensions, logger, notificationManager) {
3776
3602
  if (_isUnloading) {
3777
3603
  throwError(strSdkUnloadingError);
3778
3604
  }
@@ -3797,19 +3623,26 @@
3797
3623
  _configExtensions[_DYN_PUSH$1 ].apply(_configExtensions, __spreadArrayFn(__spreadArrayFn([], extensions, false), cfgExtensions));
3798
3624
  _channelConfig = config[STR_CHANNELS ];
3799
3625
  _initPluginChain(null);
3800
- if (!_channelQueue || _channelQueue[_DYN_LENGTH$2 ] === 0) {
3626
+ if (!_channels || _channels[_DYN_LENGTH$2 ] === 0) {
3801
3627
  throwError("No " + STR_CHANNELS + " available");
3802
3628
  }
3629
+ if (_channels[_DYN_LENGTH$2 ] > 1) {
3630
+ var teeController = _self[_DYN_GET_PLUGIN ]("TeeChannelController");
3631
+ if (!teeController || !teeController.plugin) {
3632
+ _throwInternal(_self[_DYN_LOGGER ], 1 , 28 , "TeeChannel required");
3633
+ }
3634
+ }
3803
3635
  _registerDelayedCfgListener(config, _cfgListeners, _self[_DYN_LOGGER ]);
3804
3636
  _cfgListeners = null;
3805
3637
  _isInitialized = true;
3806
3638
  _self.releaseQueue();
3639
+ _self[_DYN_POLL_INTERNAL_LOGS ]();
3807
3640
  };
3808
- _self.getTransmissionControls = function () {
3641
+ _self.getChannels = function () {
3809
3642
  var controls = [];
3810
- if (_channelQueue) {
3811
- arrForEach(_channelQueue, function (channels) {
3812
- controls[_DYN_PUSH$1 ](channels.queue);
3643
+ if (_channels) {
3644
+ arrForEach(_channels, function (channel) {
3645
+ controls[_DYN_PUSH$1 ](channel);
3813
3646
  });
3814
3647
  }
3815
3648
  return objFreeze(controls);
@@ -3892,26 +3725,33 @@
3892
3725
  });
3893
3726
  }
3894
3727
  };
3895
- _self.pollInternalLogs = function (eventName) {
3728
+ _self[_DYN_POLL_INTERNAL_LOGS ] = function (eventName) {
3896
3729
  _internalLogsEventName = eventName || null;
3897
- _addUnloadHook(_configHandler[_DYN_WATCH ](function (details) {
3898
- var interval = details.cfg.diagnosticLogInterval;
3730
+ function _startLogPoller(config) {
3731
+ var interval = config.diagnosticLogInterval;
3899
3732
  if (!interval || !(interval > 0)) {
3900
3733
  interval = 10000;
3901
3734
  }
3902
- if (_internalLogPoller) {
3903
- clearInterval(_internalLogPoller);
3904
- }
3905
- _internalLogPoller = setInterval(function () {
3735
+ _internalLogPoller && _internalLogPoller[_DYN_CANCEL ]();
3736
+ _internalLogPoller = scheduleInterval(function () {
3906
3737
  _flushInternalLogs();
3907
3738
  }, interval);
3908
- }));
3739
+ }
3740
+ if (!_internalLogPollerListening) {
3741
+ _internalLogPollerListening = true;
3742
+ _addUnloadHook(_configHandler[_DYN_WATCH ](function (details) {
3743
+ _startLogPoller(details.cfg);
3744
+ }));
3745
+ }
3746
+ else {
3747
+ _startLogPoller(_configHandler.cfg);
3748
+ }
3909
3749
  return _internalLogPoller;
3910
3750
  };
3911
3751
  _self[_DYN_STOP_POLLING_INTERNA3 ] = function () {
3912
3752
  if (_internalLogPoller) {
3913
- clearInterval(_internalLogPoller);
3914
- _internalLogPoller = 0;
3753
+ _internalLogPoller[_DYN_CANCEL ]();
3754
+ _internalLogPoller = null;
3915
3755
  _flushInternalLogs();
3916
3756
  }
3917
3757
  };
@@ -3953,9 +3793,7 @@
3953
3793
  _self[_DYN_STOP_POLLING_INTERNA3 ]();
3954
3794
  processUnloadCtx[_DYN_PROCESS_NEXT ](unloadState);
3955
3795
  }
3956
- if (!_flushChannels(isAsync, _doUnload, 6 , cbTimeout)) {
3957
- _doUnload(false);
3958
- }
3796
+ if (!_flushChannels(isAsync, _doUnload, 6 , cbTimeout)) ;
3959
3797
  };
3960
3798
  _self[_DYN_GET_PLUGIN ] = _getPlugin;
3961
3799
  _self.addPlugin = function (plugin, replaceExisting, isAsync, addCb) {
@@ -4036,7 +3874,7 @@
4036
3874
  _self.evtNamespace = function () {
4037
3875
  return _evtNamespace;
4038
3876
  };
4039
- _self[_DYN_FLUSH ] = _flushChannels;
3877
+ _self.flush = _flushChannels;
4040
3878
  _self.getTraceCtx = function (createNew) {
4041
3879
  if (!_traceCtx) {
4042
3880
  _traceCtx = createDistributedTraceContext();
@@ -4133,11 +3971,9 @@
4133
3971
  _cfgPerfManager = null;
4134
3972
  _cookieManager = null;
4135
3973
  _pluginChain = null;
4136
- _coreExtensions = null;
4137
3974
  _configExtensions = [];
4138
- _channelControl = null;
4139
3975
  _channelConfig = null;
4140
- _channelQueue = null;
3976
+ _channels = null;
4141
3977
  _isUnloading = false;
4142
3978
  _internalLogsEventName = null;
4143
3979
  _evtNamespace = createUniqueNamespace("AIBaseCore", true);
@@ -4154,32 +3990,19 @@
4154
3990
  }
4155
3991
  function _initPluginChain(updateState) {
4156
3992
  var theExtensions = _validateExtensions(_self[_DYN_LOGGER ], ChannelControllerPriority, _configExtensions);
4157
- _coreExtensions = theExtensions[STR_CORE ];
4158
3993
  _pluginChain = null;
4159
3994
  _pluginVersionString = null;
4160
3995
  _pluginVersionStringArr = null;
4161
- var allExtensions = theExtensions.all;
4162
- _channelQueue = objFreeze(createChannelQueues(_channelConfig, allExtensions, _self));
4163
- if (_channelControl) {
4164
- var idx = arrIndexOf(allExtensions, _channelControl);
4165
- if (idx !== -1) {
4166
- allExtensions[_DYN_SPLICE ](idx, 1);
4167
- }
4168
- idx = arrIndexOf(_coreExtensions, _channelControl);
4169
- if (idx !== -1) {
4170
- _coreExtensions[_DYN_SPLICE ](idx, 1);
4171
- }
4172
- _channelControl._setQueue(_channelQueue);
4173
- }
4174
- else {
4175
- _channelControl = createChannelControllerPlugin(_channelQueue, _self);
4176
- }
4177
- allExtensions[_DYN_PUSH$1 ](_channelControl);
4178
- _coreExtensions[_DYN_PUSH$1 ](_channelControl);
4179
- _extensions = sortPlugins(allExtensions);
4180
- _channelControl[_DYN_INITIALIZE$1 ](_configHandler.cfg, _self, allExtensions);
4181
- initializePlugins(_createTelCtx(), allExtensions);
4182
- _extensions = objFreeze(sortPlugins(_coreExtensions || [])).slice();
3996
+ _channels = (_channelConfig || [])[0] || [];
3997
+ _channels = sortPlugins(arrAppend(_channels, theExtensions[STR_CHANNELS ]));
3998
+ var allExtensions = sortPlugins(theExtensions[STR_CORE ]);
3999
+ arrAppend(allExtensions, _channels);
4000
+ _extensions = objFreeze(allExtensions);
4001
+ var rootCtx = _createTelCtx();
4002
+ if (_channels && _channels[_DYN_LENGTH$2 ] > 0) {
4003
+ initializePlugins(rootCtx[_DYN_CREATE_NEW ](_channels), allExtensions);
4004
+ }
4005
+ initializePlugins(rootCtx, allExtensions);
4183
4006
  if (updateState) {
4184
4007
  _doUpdate(updateState);
4185
4008
  }
@@ -4188,14 +4011,11 @@
4188
4011
  var theExt = null;
4189
4012
  var thePlugin = null;
4190
4013
  arrForEach(_extensions, function (ext) {
4191
- if (ext[_DYN_IDENTIFIER ] === pluginIdentifier && ext !== _channelControl && ext !== _telemetryInitializerPlugin) {
4014
+ if (ext[_DYN_IDENTIFIER ] === pluginIdentifier && ext !== _telemetryInitializerPlugin) {
4192
4015
  thePlugin = ext;
4193
4016
  return -1;
4194
4017
  }
4195
4018
  });
4196
- if (!thePlugin && _channelControl) {
4197
- thePlugin = _channelControl.getChannel(pluginIdentifier);
4198
- }
4199
4019
  if (thePlugin) {
4200
4020
  theExt = {
4201
4021
  plugin: thePlugin,
@@ -4231,7 +4051,7 @@
4231
4051
  }
4232
4052
  function _getPluginChain() {
4233
4053
  if (!_pluginChain) {
4234
- var extensions = (_coreExtensions || []).slice();
4054
+ var extensions = (_extensions || []).slice();
4235
4055
  if (arrIndexOf(extensions, _telemetryInitializerPlugin) === -1) {
4236
4056
  extensions[_DYN_PUSH$1 ](_telemetryInitializerPlugin);
4237
4057
  }
@@ -4299,10 +4119,46 @@
4299
4119
  }
4300
4120
  }
4301
4121
  function _flushChannels(isAsync, callBack, sendReason, cbTimeout) {
4302
- if (_channelControl) {
4303
- return _channelControl[_DYN_FLUSH ](isAsync, callBack, sendReason || 6 , cbTimeout);
4122
+ var waiting = 1;
4123
+ var doneIterating = false;
4124
+ var cbTimer = null;
4125
+ cbTimeout = cbTimeout || 5000;
4126
+ function doCallback() {
4127
+ waiting--;
4128
+ if (doneIterating && waiting === 0) {
4129
+ cbTimer && cbTimer[_DYN_CANCEL ]();
4130
+ cbTimer = null;
4131
+ callBack && callBack(doneIterating);
4132
+ callBack = null;
4133
+ }
4134
+ }
4135
+ if (_channels && _channels[_DYN_LENGTH$2 ] > 0) {
4136
+ var flushCtx = _createTelCtx()[_DYN_CREATE_NEW ](_channels);
4137
+ flushCtx.iterate(function (plugin) {
4138
+ if (plugin.flush) {
4139
+ waiting++;
4140
+ var handled_1 = false;
4141
+ if (!plugin.flush(isAsync, function () {
4142
+ handled_1 = true;
4143
+ doCallback();
4144
+ }, sendReason)) {
4145
+ if (!handled_1) {
4146
+ if (isAsync && cbTimer == null) {
4147
+ cbTimer = scheduleTimeout(function () {
4148
+ cbTimer = null;
4149
+ doCallback();
4150
+ }, cbTimeout);
4151
+ }
4152
+ else {
4153
+ doCallback();
4154
+ }
4155
+ }
4156
+ }
4157
+ }
4158
+ });
4304
4159
  }
4305
- callBack && callBack(false);
4160
+ doneIterating = true;
4161
+ doCallback();
4306
4162
  return true;
4307
4163
  }
4308
4164
  function _initDebugListener() {
@@ -5825,7 +5681,7 @@
5825
5681
  }
5826
5682
  }
5827
5683
  var EnvelopeCreator = {
5828
- Version: "3.0.0-beta.2211-01"
5684
+ Version: "3.0.0-beta.2211-04"
5829
5685
  };
5830
5686
  function DependencyEnvelopeCreator(logger, telemetryItem, customUndefinedValue) {
5831
5687
  EnvelopeCreatorInit(logger, telemetryItem);
@@ -7213,7 +7069,6 @@
7213
7069
  return Sender;
7214
7070
  }(BaseTelemetryPlugin));
7215
7071
 
7216
- var _DYN_INITIALIZE = "initialize";
7217
7072
  var _DYN_DIAGNOSTIC_LOG_INTER0 = "diagnosticLogInterval";
7218
7073
 
7219
7074
  var ApplicationInsights = /** @class */ (function () {
@@ -7230,7 +7085,7 @@
7230
7085
  get: function () { return config; }
7231
7086
  });
7232
7087
  _initialize();
7233
- _self[_DYN_INITIALIZE ] = _initialize;
7088
+ _self.initialize = _initialize;
7234
7089
  _self.getSKUDefaults = function () {
7235
7090
  _self.config[_DYN_DIAGNOSTIC_LOG_INTER0 ] =
7236
7091
  _self.config[_DYN_DIAGNOSTIC_LOG_INTER0 ] && _self.config[_DYN_DIAGNOSTIC_LOG_INTER0 ] > 0 ? _self.config[_DYN_DIAGNOSTIC_LOG_INTER0 ] : 10000;
@@ -7248,12 +7103,7 @@
7248
7103
  "addUnloadCb"
7249
7104
  ]);
7250
7105
  function _initialize() {
7251
- var extensions = [];
7252
- var appInsightsChannel = new Sender();
7253
- extensions.push(appInsightsChannel);
7254
- core[_DYN_INITIALIZE ](_self.config, extensions);
7255
- appInsightsChannel[_DYN_INITIALIZE ](_self.config, core, extensions);
7256
- core.pollInternalLogs();
7106
+ core.initialize(_self.config, [new Sender()]);
7257
7107
  }
7258
7108
  });
7259
7109
  }