@microsoft/1ds-post-js 3.2.2 → 3.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +1 -1
  2. package/bundle/{ms.post-3.2.2.gbl.js → ms.post-3.2.3.gbl.js} +732 -726
  3. package/bundle/ms.post-3.2.3.gbl.js.map +1 -0
  4. package/bundle/ms.post-3.2.3.gbl.min.js +7 -0
  5. package/bundle/ms.post-3.2.3.gbl.min.js.map +1 -0
  6. package/bundle/ms.post-3.2.3.integrity.json +46 -0
  7. package/bundle/{ms.post-3.2.2.js → ms.post-3.2.3.js} +732 -726
  8. package/bundle/ms.post-3.2.3.js.map +1 -0
  9. package/bundle/ms.post-3.2.3.min.js +7 -0
  10. package/bundle/ms.post-3.2.3.min.js.map +1 -0
  11. package/bundle/ms.post.gbl.js +731 -725
  12. package/bundle/ms.post.gbl.js.map +1 -1
  13. package/bundle/ms.post.gbl.min.js +2 -2
  14. package/bundle/ms.post.gbl.min.js.map +1 -1
  15. package/bundle/ms.post.integrity.json +17 -17
  16. package/bundle/ms.post.js +731 -725
  17. package/bundle/ms.post.js.map +1 -1
  18. package/bundle/ms.post.min.js +2 -2
  19. package/bundle/ms.post.min.js.map +1 -1
  20. package/dist/ms.post.js +18 -12
  21. package/dist/ms.post.js.map +1 -1
  22. package/dist/ms.post.min.js +2 -2
  23. package/dist/ms.post.min.js.map +1 -1
  24. package/dist-esm/src/BatchNotificationActions.js +1 -1
  25. package/dist-esm/src/ClockSkewManager.js +1 -1
  26. package/dist-esm/src/Constants.js +1 -1
  27. package/dist-esm/src/DataModels.js +1 -1
  28. package/dist-esm/src/EventBatch.js +1 -1
  29. package/dist-esm/src/HttpManager.js +63 -63
  30. package/dist-esm/src/HttpManager.js.map +1 -1
  31. package/dist-esm/src/Index.js +1 -1
  32. package/dist-esm/src/KillSwitch.js +1 -1
  33. package/dist-esm/src/PostChannel.js +65 -57
  34. package/dist-esm/src/PostChannel.js.map +1 -1
  35. package/dist-esm/src/RetryPolicy.js +1 -1
  36. package/dist-esm/src/Serializer.js +1 -1
  37. package/dist-esm/src/TimeoutOverrideWrapper.js +1 -1
  38. package/dist-esm/src/typings/XDomainRequest.js +1 -1
  39. package/package.json +2 -2
  40. package/src/PostChannel.ts +29 -16
  41. package/bundle/ms.post-3.2.2.gbl.js.map +0 -1
  42. package/bundle/ms.post-3.2.2.gbl.min.js +0 -7
  43. package/bundle/ms.post-3.2.2.gbl.min.js.map +0 -1
  44. package/bundle/ms.post-3.2.2.integrity.json +0 -46
  45. package/bundle/ms.post-3.2.2.js.map +0 -1
  46. package/bundle/ms.post-3.2.2.min.js +0 -7
  47. package/bundle/ms.post-3.2.2.min.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * 1DS JS SDK POST plugin, 3.2.2
2
+ * 1DS JS SDK POST plugin, 3.2.3
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  * (Microsoft Internal Only)
5
5
  */
@@ -1217,7 +1217,7 @@
1217
1217
  }
1218
1218
 
1219
1219
  var _objDefineProperty = ObjDefineProperty;
1220
- var version = "2.8.3";
1220
+ var version = "2.8.4";
1221
1221
  var instanceName = "." + newId(6);
1222
1222
  var _dataUid = 0;
1223
1223
  function _createAccessor(target, prop, value) {
@@ -1288,822 +1288,822 @@
1288
1288
  return data;
1289
1289
  }
1290
1290
 
1291
- var pluginStateData = createElmNodeData("plugin");
1292
- function _getPluginState(plugin) {
1293
- return pluginStateData.get(plugin, "state", {}, true);
1294
- }
1295
-
1296
- var strTelemetryPluginChain = "TelemetryPluginChain";
1297
- var strHasRunFlags = "_hasRun";
1298
- var strGetTelCtx = "_getTelCtx";
1299
- var _chainId = 0;
1300
- function _getNextProxyStart(proxy, core, startAt) {
1301
- while (proxy) {
1302
- if (proxy.getPlugin() === startAt) {
1303
- return proxy;
1304
- }
1305
- proxy = proxy.getNext();
1291
+ var strOnPrefix = "on";
1292
+ var strAttachEvent = "attachEvent";
1293
+ var strAddEventHelper = "addEventListener";
1294
+ var strDetachEvent = "detachEvent";
1295
+ var strRemoveEventListener = "removeEventListener";
1296
+ var strEvents = "events";
1297
+ var strVisibilityChangeEvt = "visibilitychange";
1298
+ var strPageHide = "pagehide";
1299
+ var strPageShow = "pageshow";
1300
+ var strUnload = "unload";
1301
+ var strBeforeUnload = "beforeunload";
1302
+ var strPageHideNamespace = createUniqueNamespace("aiEvtPageHide");
1303
+ var strPageShowNamespace = createUniqueNamespace("aiEvtPageShow");
1304
+ var rRemoveEmptyNs = /\.[\.]+/g;
1305
+ var rRemoveTrailingEmptyNs = /[\.]+$/;
1306
+ var _guid = 1;
1307
+ var elmNodeData = createElmNodeData("events");
1308
+ var eventNamespace = /^([^.]*)(?:\.(.+)|)/;
1309
+ function _normalizeNamespace(name) {
1310
+ if (name && name.replace) {
1311
+ return name.replace(/^\s*\.*|\.*\s*$/g, "");
1306
1312
  }
1307
- return createTelemetryProxyChain([startAt], core.config || {}, core);
1313
+ return name;
1308
1314
  }
1309
- function _createInternalContext(telemetryChain, config, core, startAt) {
1310
- var _nextProxy = null;
1311
- var _onComplete = [];
1312
- if (startAt !== null) {
1313
- _nextProxy = startAt ? _getNextProxyStart(telemetryChain, core, startAt) : telemetryChain;
1314
- }
1315
- var context = {
1316
- _next: _moveNext,
1317
- ctx: {
1318
- core: function () {
1319
- return core;
1320
- },
1321
- diagLog: function () {
1322
- return safeGetLogger(core, config);
1323
- },
1324
- getCfg: function () {
1325
- return config;
1326
- },
1327
- getExtCfg: _getExtCfg,
1328
- getConfig: _getConfig,
1329
- hasNext: function () {
1330
- return !!_nextProxy;
1331
- },
1332
- getNext: function () {
1333
- return _nextProxy;
1334
- },
1335
- setNext: function (nextPlugin) {
1336
- _nextProxy = nextPlugin;
1337
- },
1338
- iterate: _iterateChain,
1339
- onComplete: _addOnComplete
1340
- }
1341
- };
1342
- function _addOnComplete(onComplete, that) {
1343
- var args = [];
1344
- for (var _i = 2; _i < arguments.length; _i++) {
1345
- args[_i - 2] = arguments[_i];
1346
- }
1347
- if (onComplete) {
1348
- _onComplete.push({
1349
- func: onComplete,
1350
- self: !isUndefined(that) ? that : context.ctx,
1351
- args: args
1315
+ function _getEvtNamespace(eventName, evtNamespace) {
1316
+ if (evtNamespace) {
1317
+ var theNamespace_1 = "";
1318
+ if (isArray(evtNamespace)) {
1319
+ theNamespace_1 = "";
1320
+ arrForEach(evtNamespace, function (name) {
1321
+ name = _normalizeNamespace(name);
1322
+ if (name) {
1323
+ if (name[0] !== ".") {
1324
+ name = "." + name;
1325
+ }
1326
+ theNamespace_1 += name;
1327
+ }
1352
1328
  });
1353
1329
  }
1354
- }
1355
- function _moveNext() {
1356
- var nextProxy = _nextProxy;
1357
- _nextProxy = nextProxy ? nextProxy.getNext() : null;
1358
- if (!nextProxy) {
1359
- var onComplete = _onComplete;
1360
- if (onComplete && onComplete.length > 0) {
1361
- arrForEach(onComplete, function (completeDetails) {
1362
- try {
1363
- completeDetails.func.call(completeDetails.self, completeDetails.args);
1364
- }
1365
- catch (e) {
1366
- _throwInternal(core.logger, 2 , 73 , "Unexpected Exception during onComplete - " + dumpObj(e));
1367
- }
1368
- });
1369
- _onComplete = [];
1370
- }
1330
+ else {
1331
+ theNamespace_1 = _normalizeNamespace(evtNamespace);
1371
1332
  }
1372
- return nextProxy;
1373
- }
1374
- function _getExtCfg(identifier, defaultValue, mergeDefault) {
1375
- if (defaultValue === void 0) { defaultValue = {}; }
1376
- if (mergeDefault === void 0) { mergeDefault = 0 ; }
1377
- var theConfig;
1378
- if (config) {
1379
- var extConfig = config.extensionConfig;
1380
- if (extConfig && identifier) {
1381
- theConfig = extConfig[identifier];
1333
+ if (theNamespace_1) {
1334
+ if (theNamespace_1[0] !== ".") {
1335
+ theNamespace_1 = "." + theNamespace_1;
1382
1336
  }
1337
+ eventName = (eventName || "") + theNamespace_1;
1383
1338
  }
1384
- if (!theConfig) {
1385
- theConfig = defaultValue;
1339
+ }
1340
+ var parsedEvent = (eventNamespace.exec(eventName || "") || []);
1341
+ return {
1342
+ type: parsedEvent[1],
1343
+ ns: ((parsedEvent[2] || "").replace(rRemoveEmptyNs, ".").replace(rRemoveTrailingEmptyNs, "").split(".").sort()).join(".")
1344
+ };
1345
+ }
1346
+ function _getRegisteredEvents(target, evtName, addDefault) {
1347
+ if (addDefault === void 0) { addDefault = true; }
1348
+ var aiEvts = elmNodeData.get(target, strEvents, {}, addDefault);
1349
+ var registeredEvents = aiEvts[evtName];
1350
+ if (!registeredEvents) {
1351
+ registeredEvents = aiEvts[evtName] = [];
1352
+ }
1353
+ return registeredEvents;
1354
+ }
1355
+ function _doDetach(obj, evtName, handlerRef, useCapture) {
1356
+ if (obj && evtName && evtName.type) {
1357
+ if (obj[strRemoveEventListener]) {
1358
+ obj[strRemoveEventListener](evtName.type, handlerRef, useCapture);
1386
1359
  }
1387
- else if (isObject(defaultValue)) {
1388
- if (mergeDefault !== 0 ) {
1389
- var newConfig_1 = objExtend(true, defaultValue, theConfig);
1390
- if (config && mergeDefault === 2 ) {
1391
- objForEachKey(defaultValue, function (field) {
1392
- if (isNullOrUndefined(newConfig_1[field])) {
1393
- var cfgValue = config[field];
1394
- if (!isNullOrUndefined(cfgValue)) {
1395
- newConfig_1[field] = cfgValue;
1396
- }
1397
- }
1398
- });
1399
- }
1400
- theConfig = newConfig_1;
1401
- }
1360
+ else if (obj[strDetachEvent]) {
1361
+ obj[strDetachEvent](strOnPrefix + evtName.type, handlerRef);
1402
1362
  }
1403
- return theConfig;
1404
1363
  }
1405
- function _getConfig(identifier, field, defaultValue) {
1406
- if (defaultValue === void 0) { defaultValue = false; }
1407
- var theValue;
1408
- var extConfig = _getExtCfg(identifier, null);
1409
- if (extConfig && !isNullOrUndefined(extConfig[field])) {
1410
- theValue = extConfig[field];
1364
+ }
1365
+ function _doAttach(obj, evtName, handlerRef, useCapture) {
1366
+ var result = false;
1367
+ if (obj && evtName && evtName.type && handlerRef) {
1368
+ if (obj[strAddEventHelper]) {
1369
+ obj[strAddEventHelper](evtName.type, handlerRef, useCapture);
1370
+ result = true;
1411
1371
  }
1412
- else if (config && !isNullOrUndefined(config[field])) {
1413
- theValue = config[field];
1372
+ else if (obj[strAttachEvent]) {
1373
+ obj[strAttachEvent](strOnPrefix + evtName.type, handlerRef);
1374
+ result = true;
1414
1375
  }
1415
- return !isNullOrUndefined(theValue) ? theValue : defaultValue;
1416
1376
  }
1417
- function _iterateChain(cb) {
1418
- var nextPlugin;
1419
- while (!!(nextPlugin = context._next())) {
1420
- var plugin = nextPlugin.getPlugin();
1421
- if (plugin) {
1422
- cb(plugin);
1377
+ return result;
1378
+ }
1379
+ function _doUnregister(target, events, evtName, unRegFn) {
1380
+ var idx = events.length;
1381
+ while (idx--) {
1382
+ var theEvent = events[idx];
1383
+ if (theEvent) {
1384
+ if (!evtName.ns || evtName.ns === theEvent.evtName.ns) {
1385
+ if (!unRegFn || unRegFn(theEvent)) {
1386
+ _doDetach(target, theEvent.evtName, theEvent.handler, theEvent.capture);
1387
+ events.splice(idx, 1);
1388
+ }
1423
1389
  }
1424
1390
  }
1425
1391
  }
1426
- return context;
1427
1392
  }
1428
- function createProcessTelemetryContext(telemetryChain, config, core, startAt) {
1429
- var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1430
- var context = internalContext.ctx;
1431
- function _processNext(env) {
1432
- var nextPlugin = internalContext._next();
1433
- nextPlugin && nextPlugin.processTelemetry(env, context);
1434
- return !nextPlugin;
1393
+ function _unregisterEvents(target, evtName, unRegFn) {
1394
+ if (evtName.type) {
1395
+ _doUnregister(target, _getRegisteredEvents(target, evtName.type), evtName, unRegFn);
1435
1396
  }
1436
- function _createNew(plugins, startAt) {
1437
- if (plugins === void 0) { plugins = null; }
1438
- if (isArray(plugins)) {
1439
- plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1397
+ else {
1398
+ var eventCache = elmNodeData.get(target, strEvents, {});
1399
+ objForEachKey(eventCache, function (evtType, events) {
1400
+ _doUnregister(target, events, evtName, unRegFn);
1401
+ });
1402
+ if (objKeys(eventCache).length === 0) {
1403
+ elmNodeData.kill(target, strEvents);
1440
1404
  }
1441
- return createProcessTelemetryContext(plugins || context.getNext(), config, core, startAt);
1442
1405
  }
1443
- context.processNext = _processNext;
1444
- context.createNew = _createNew;
1445
- return context;
1446
1406
  }
1447
- function createProcessTelemetryUnloadContext(telemetryChain, core, startAt) {
1448
- var config = core.config || {};
1449
- var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1450
- var context = internalContext.ctx;
1451
- function _processNext(unloadState) {
1452
- var nextPlugin = internalContext._next();
1453
- nextPlugin && nextPlugin.unload(context, unloadState);
1454
- return !nextPlugin;
1455
- }
1456
- function _createNew(plugins, startAt) {
1457
- if (plugins === void 0) { plugins = null; }
1458
- if (isArray(plugins)) {
1459
- plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1407
+ function mergeEvtNamespace(theNamespace, namespaces) {
1408
+ var newNamespaces;
1409
+ if (namespaces) {
1410
+ if (isArray(namespaces)) {
1411
+ newNamespaces = [theNamespace].concat(namespaces);
1460
1412
  }
1461
- return createProcessTelemetryUnloadContext(plugins || context.getNext(), core, startAt);
1413
+ else {
1414
+ newNamespaces = [theNamespace, namespaces];
1415
+ }
1416
+ newNamespaces = (_getEvtNamespace("xx", newNamespaces).ns).split(".");
1462
1417
  }
1463
- context.processNext = _processNext;
1464
- context.createNew = _createNew;
1465
- return context;
1466
- }
1467
- function createProcessTelemetryUpdateContext(telemetryChain, core, startAt) {
1468
- var config = core.config || {};
1469
- var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1470
- var context = internalContext.ctx;
1471
- function _processNext(updateState) {
1472
- return context.iterate(function (plugin) {
1473
- if (isFunction(plugin.update)) {
1474
- plugin.update(context, updateState);
1475
- }
1476
- });
1477
- }
1478
- function _createNew(plugins, startAt) {
1479
- if (plugins === void 0) { plugins = null; }
1480
- if (isArray(plugins)) {
1481
- plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1482
- }
1483
- return createProcessTelemetryUpdateContext(plugins || context.getNext(), core, startAt);
1418
+ else {
1419
+ newNamespaces = theNamespace;
1484
1420
  }
1485
- context.processNext = _processNext;
1486
- context.createNew = _createNew;
1487
- return context;
1421
+ return newNamespaces;
1488
1422
  }
1489
- function createTelemetryProxyChain(plugins, config, core, startAt) {
1490
- var firstProxy = null;
1491
- var add = startAt ? false : true;
1492
- if (isArray(plugins) && plugins.length > 0) {
1493
- var lastProxy_1 = null;
1494
- arrForEach(plugins, function (thePlugin) {
1495
- if (!add && startAt === thePlugin) {
1496
- add = true;
1497
- }
1498
- if (add && thePlugin && isFunction(thePlugin.processTelemetry)) {
1499
- var newProxy = createTelemetryPluginProxy(thePlugin, config, core);
1500
- if (!firstProxy) {
1501
- firstProxy = newProxy;
1502
- }
1503
- if (lastProxy_1) {
1504
- lastProxy_1._setNext(newProxy);
1505
- }
1506
- lastProxy_1 = newProxy;
1423
+ function eventOn(target, eventName, handlerRef, evtNamespace, useCapture) {
1424
+ if (useCapture === void 0) { useCapture = false; }
1425
+ var result = false;
1426
+ if (target) {
1427
+ try {
1428
+ var evtName = _getEvtNamespace(eventName, evtNamespace);
1429
+ result = _doAttach(target, evtName, handlerRef, useCapture);
1430
+ if (result && elmNodeData.accept(target)) {
1431
+ var registeredEvent = {
1432
+ guid: _guid++,
1433
+ evtName: evtName,
1434
+ handler: handlerRef,
1435
+ capture: useCapture
1436
+ };
1437
+ _getRegisteredEvents(target, evtName.type).push(registeredEvent);
1507
1438
  }
1508
- });
1509
- }
1510
- if (startAt && !firstProxy) {
1511
- return createTelemetryProxyChain([startAt], config, core);
1512
- }
1513
- return firstProxy;
1514
- }
1515
- function createTelemetryPluginProxy(plugin, config, core) {
1516
- var nextProxy = null;
1517
- var hasProcessTelemetry = isFunction(plugin.processTelemetry);
1518
- var hasSetNext = isFunction(plugin.setNextPlugin);
1519
- var chainId;
1520
- if (plugin) {
1521
- chainId = plugin.identifier + "-" + plugin.priority + "-" + _chainId++;
1522
- }
1523
- else {
1524
- chainId = "Unknown-0-" + _chainId++;
1525
- }
1526
- var proxyChain = {
1527
- getPlugin: function () {
1528
- return plugin;
1529
- },
1530
- getNext: function () {
1531
- return nextProxy;
1532
- },
1533
- processTelemetry: _processTelemetry,
1534
- unload: _unloadPlugin,
1535
- update: _updatePlugin,
1536
- _id: chainId,
1537
- _setNext: function (nextPlugin) {
1538
- nextProxy = nextPlugin;
1539
1439
  }
1540
- };
1541
- function _getTelCtx() {
1542
- var itemCtx;
1543
- if (plugin && isFunction(plugin[strGetTelCtx])) {
1544
- itemCtx = plugin[strGetTelCtx]();
1545
- }
1546
- if (!itemCtx) {
1547
- itemCtx = createProcessTelemetryContext(proxyChain, config, core);
1440
+ catch (e) {
1548
1441
  }
1549
- return itemCtx;
1550
1442
  }
1551
- function _processChain(itemCtx, processPluginFn, name, details, isAsync) {
1552
- var hasRun = false;
1553
- var identifier = plugin ? plugin.identifier : strTelemetryPluginChain;
1554
- var hasRunContext = itemCtx[strHasRunFlags];
1555
- if (!hasRunContext) {
1556
- hasRunContext = itemCtx[strHasRunFlags] = {};
1557
- }
1558
- itemCtx.setNext(nextProxy);
1559
- if (plugin) {
1560
- doPerf(itemCtx[strCore](), function () { return identifier + ":" + name; }, function () {
1561
- hasRunContext[chainId] = true;
1562
- try {
1563
- var nextId = nextProxy ? nextProxy._id : strEmpty;
1564
- if (nextId) {
1565
- hasRunContext[nextId] = false;
1566
- }
1567
- hasRun = processPluginFn(itemCtx);
1568
- }
1569
- catch (error) {
1570
- var hasNextRun = nextProxy ? hasRunContext[nextProxy._id] : true;
1571
- if (hasNextRun) {
1572
- hasRun = true;
1573
- }
1574
- if (!nextProxy || !hasNextRun) {
1575
- _throwInternal(itemCtx.diagLog(), 1 , 73 , "Plugin [" + identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
1576
- }
1443
+ return result;
1444
+ }
1445
+ function eventOff(target, eventName, handlerRef, evtNamespace, useCapture) {
1446
+ if (useCapture === void 0) { useCapture = false; }
1447
+ if (target) {
1448
+ try {
1449
+ var evtName_1 = _getEvtNamespace(eventName, evtNamespace);
1450
+ var found_1 = false;
1451
+ _unregisterEvents(target, evtName_1, function (regEvent) {
1452
+ if ((evtName_1.ns && !handlerRef) || regEvent.handler === handlerRef) {
1453
+ found_1 = true;
1454
+ return true;
1577
1455
  }
1578
- }, details, isAsync);
1579
- }
1580
- return hasRun;
1581
- }
1582
- function _processTelemetry(env, itemCtx) {
1583
- itemCtx = itemCtx || _getTelCtx();
1584
- function _callProcessTelemetry(itemCtx) {
1585
- if (!plugin || !hasProcessTelemetry) {
1586
1456
  return false;
1457
+ });
1458
+ if (!found_1) {
1459
+ _doDetach(target, evtName_1, handlerRef, useCapture);
1587
1460
  }
1588
- var pluginState = _getPluginState(plugin);
1589
- if (pluginState.teardown || pluginState[strDisabled]) {
1590
- return false;
1591
- }
1592
- if (hasSetNext) {
1593
- plugin.setNextPlugin(nextProxy);
1594
- }
1595
- plugin.processTelemetry(env, itemCtx);
1596
- return true;
1597
1461
  }
1598
- if (!_processChain(itemCtx, _callProcessTelemetry, "processTelemetry", function () { return ({ item: env }); }, !(env.sync))) {
1599
- itemCtx.processNext(env);
1462
+ catch (e) {
1600
1463
  }
1601
1464
  }
1602
- function _unloadPlugin(unloadCtx, unloadState) {
1603
- function _callTeardown() {
1604
- var hasRun = false;
1605
- if (plugin) {
1606
- var pluginState = _getPluginState(plugin);
1607
- var pluginCore = plugin[strCore] || pluginState.core;
1608
- if (plugin && (!pluginCore || pluginCore === unloadCtx[strCore]()) && !pluginState[strTeardown]) {
1609
- pluginState[strCore] = null;
1610
- pluginState[strTeardown] = true;
1611
- pluginState[strIsInitialized] = false;
1612
- if (plugin[strTeardown] && plugin[strTeardown](unloadCtx, unloadState) === true) {
1613
- hasRun = true;
1614
- }
1615
- }
1616
- }
1617
- return hasRun;
1618
- }
1619
- if (!_processChain(unloadCtx, _callTeardown, "unload", function () { }, unloadState.isAsync)) {
1620
- unloadCtx.processNext(unloadState);
1621
- }
1465
+ }
1466
+ function addEventHandler(eventName, callback, evtNamespace) {
1467
+ var result = false;
1468
+ var w = getWindow();
1469
+ if (w) {
1470
+ result = eventOn(w, eventName, callback, evtNamespace);
1471
+ result = eventOn(w["body"], eventName, callback, evtNamespace) || result;
1622
1472
  }
1623
- function _updatePlugin(updateCtx, updateState) {
1624
- function _callUpdate() {
1625
- var hasRun = false;
1626
- if (plugin) {
1627
- var pluginState = _getPluginState(plugin);
1628
- var pluginCore = plugin[strCore] || pluginState.core;
1629
- if (plugin && (!pluginCore || pluginCore === updateCtx[strCore]()) && !pluginState[strTeardown]) {
1630
- if (plugin[strUpdate] && plugin[strUpdate](updateCtx, updateState) === true) {
1631
- hasRun = true;
1632
- }
1473
+ var doc = getDocument();
1474
+ if (doc) {
1475
+ result = eventOn(doc, eventName, callback, evtNamespace) || result;
1476
+ }
1477
+ return result;
1478
+ }
1479
+ function removeEventHandler(eventName, callback, evtNamespace) {
1480
+ var w = getWindow();
1481
+ if (w) {
1482
+ eventOff(w, eventName, callback, evtNamespace);
1483
+ eventOff(w["body"], eventName, callback, evtNamespace);
1484
+ }
1485
+ var doc = getDocument();
1486
+ if (doc) {
1487
+ eventOff(doc, eventName, callback, evtNamespace);
1488
+ }
1489
+ }
1490
+ function _addEventListeners(events, listener, excludeEvents, evtNamespace) {
1491
+ var added = false;
1492
+ if (listener && events && events.length > 0) {
1493
+ arrForEach(events, function (name) {
1494
+ if (name) {
1495
+ if (!excludeEvents || arrIndexOf(excludeEvents, name) === -1) {
1496
+ added = addEventHandler(name, listener, evtNamespace) || added;
1633
1497
  }
1634
1498
  }
1635
- return hasRun;
1636
- }
1637
- if (!_processChain(updateCtx, _callUpdate, "update", function () { }, false)) {
1638
- updateCtx.processNext(updateState);
1639
- }
1499
+ });
1640
1500
  }
1641
- return objFreeze(proxyChain);
1501
+ return added;
1642
1502
  }
1643
-
1644
- var strExtensionConfig = "extensionConfig";
1645
-
1646
- function createUnloadHandlerContainer() {
1647
- var handlers = [];
1648
- function _addHandler(handler) {
1649
- if (handler) {
1650
- handlers.push(handler);
1503
+ function addEventListeners(events, listener, excludeEvents, evtNamespace) {
1504
+ var added = false;
1505
+ if (listener && events && isArray(events)) {
1506
+ added = _addEventListeners(events, listener, excludeEvents, evtNamespace);
1507
+ if (!added && excludeEvents && excludeEvents.length > 0) {
1508
+ added = _addEventListeners(events, listener, null, evtNamespace);
1651
1509
  }
1652
1510
  }
1653
- function _runHandlers(unloadCtx, unloadState) {
1654
- arrForEach(handlers, function (handler) {
1655
- try {
1656
- handler(unloadCtx, unloadState);
1657
- }
1658
- catch (e) {
1659
- _throwInternal(unloadCtx.diagLog(), 2 , 73 , "Unexpected error calling unload handler - " + dumpObj(e));
1511
+ return added;
1512
+ }
1513
+ function removeEventListeners(events, listener, evtNamespace) {
1514
+ if (events && isArray(events)) {
1515
+ arrForEach(events, function (name) {
1516
+ if (name) {
1517
+ removeEventHandler(name, listener, evtNamespace);
1660
1518
  }
1661
1519
  });
1662
- handlers = [];
1663
1520
  }
1664
- return {
1665
- add: _addHandler,
1666
- run: _runHandlers
1667
- };
1521
+ }
1522
+ function addPageUnloadEventListener(listener, excludeEvents, evtNamespace) {
1523
+ return addEventListeners([strBeforeUnload, strUnload, strPageHide], listener, excludeEvents, evtNamespace);
1524
+ }
1525
+ function removePageUnloadEventListener(listener, evtNamespace) {
1526
+ removeEventListeners([strBeforeUnload, strUnload, strPageHide], listener, evtNamespace);
1527
+ }
1528
+ function addPageHideEventListener(listener, excludeEvents, evtNamespace) {
1529
+ function _handlePageVisibility(evt) {
1530
+ var doc = getDocument();
1531
+ if (listener && doc && doc.visibilityState === "hidden") {
1532
+ listener(evt);
1533
+ }
1534
+ }
1535
+ var newNamespaces = mergeEvtNamespace(strPageHideNamespace, evtNamespace);
1536
+ var pageUnloadAdded = _addEventListeners([strPageHide], listener, excludeEvents, newNamespaces);
1537
+ if (!excludeEvents || arrIndexOf(excludeEvents, strVisibilityChangeEvt) === -1) {
1538
+ pageUnloadAdded = _addEventListeners([strVisibilityChangeEvt], _handlePageVisibility, excludeEvents, newNamespaces) || pageUnloadAdded;
1539
+ }
1540
+ if (!pageUnloadAdded && excludeEvents) {
1541
+ pageUnloadAdded = addPageHideEventListener(listener, null, evtNamespace);
1542
+ }
1543
+ return pageUnloadAdded;
1544
+ }
1545
+ function removePageHideEventListener(listener, evtNamespace) {
1546
+ var newNamespaces = mergeEvtNamespace(strPageHideNamespace, evtNamespace);
1547
+ removeEventListeners([strPageHide], listener, newNamespaces);
1548
+ removeEventListeners([strVisibilityChangeEvt], null, newNamespaces);
1549
+ }
1550
+ function addPageShowEventListener(listener, excludeEvents, evtNamespace) {
1551
+ function _handlePageVisibility(evt) {
1552
+ var doc = getDocument();
1553
+ if (listener && doc && doc.visibilityState === "visible") {
1554
+ listener(evt);
1555
+ }
1556
+ }
1557
+ var newNamespaces = mergeEvtNamespace(strPageShowNamespace, evtNamespace);
1558
+ var pageShowAdded = _addEventListeners([strPageShow], listener, excludeEvents, newNamespaces);
1559
+ pageShowAdded = _addEventListeners([strVisibilityChangeEvt], _handlePageVisibility, excludeEvents, newNamespaces) || pageShowAdded;
1560
+ if (!pageShowAdded && excludeEvents) {
1561
+ pageShowAdded = addPageShowEventListener(listener, null, evtNamespace);
1562
+ }
1563
+ return pageShowAdded;
1564
+ }
1565
+ function removePageShowEventListener(listener, evtNamespace) {
1566
+ var newNamespaces = mergeEvtNamespace(strPageShowNamespace, evtNamespace);
1567
+ removeEventListeners([strPageShow], listener, newNamespaces);
1568
+ removeEventListeners([strVisibilityChangeEvt], null, newNamespaces);
1668
1569
  }
1669
1570
 
1670
- var strGetPlugin = "getPlugin";
1671
- var BaseTelemetryPlugin = /** @class */ (function () {
1672
- function BaseTelemetryPlugin() {
1673
- var _self = this;
1674
- var _isinitialized;
1675
- var _rootCtx;
1676
- var _nextPlugin;
1677
- var _unloadHandlerContainer;
1678
- var _hooks;
1679
- _initDefaults();
1680
- dynamicProto(BaseTelemetryPlugin, _self, function (_self) {
1681
- _self.initialize = function (config, core, extensions, pluginChain) {
1682
- _setDefaults(config, core, pluginChain);
1683
- _isinitialized = true;
1684
- };
1685
- _self.teardown = function (unloadCtx, unloadState) {
1686
- var core = _self.core;
1687
- if (!core || (unloadCtx && core !== unloadCtx.core())) {
1688
- return;
1689
- }
1690
- var result;
1691
- var unloadDone = false;
1692
- var theUnloadCtx = unloadCtx || createProcessTelemetryUnloadContext(null, core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
1693
- var theUnloadState = unloadState || {
1694
- reason: 0 ,
1695
- isAsync: false
1696
- };
1697
- function _unloadCallback() {
1698
- if (!unloadDone) {
1699
- unloadDone = true;
1700
- _unloadHandlerContainer.run(theUnloadCtx, unloadState);
1701
- arrForEach(_hooks, function (fn) {
1702
- fn.rm();
1703
- });
1704
- _hooks = [];
1705
- if (result === true) {
1706
- theUnloadCtx.processNext(theUnloadState);
1707
- }
1708
- _initDefaults();
1709
- }
1710
- }
1711
- if (!_self[strDoTeardown] || _self[strDoTeardown](theUnloadCtx, theUnloadState, _unloadCallback) !== true) {
1712
- _unloadCallback();
1713
- }
1714
- else {
1715
- result = true;
1716
- }
1717
- return result;
1718
- };
1719
- _self.update = function (updateCtx, updateState) {
1720
- var core = _self.core;
1721
- if (!core || (updateCtx && core !== updateCtx.core())) {
1722
- return;
1723
- }
1724
- var result;
1725
- var updateDone = false;
1726
- var theUpdateCtx = updateCtx || createProcessTelemetryUpdateContext(null, core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
1727
- var theUpdateState = updateState || {
1728
- reason: 0
1729
- };
1730
- function _updateCallback() {
1731
- if (!updateDone) {
1732
- updateDone = true;
1733
- _setDefaults(theUpdateCtx.getCfg(), theUpdateCtx.core(), theUpdateCtx.getNext());
1734
- }
1735
- }
1736
- if (!_self._doUpdate || _self._doUpdate(theUpdateCtx, theUpdateState, _updateCallback) !== true) {
1737
- _updateCallback();
1738
- }
1739
- else {
1740
- result = true;
1741
- }
1742
- return result;
1743
- };
1744
- _self._addHook = function (hooks) {
1745
- if (hooks) {
1746
- if (isArray(hooks)) {
1747
- _hooks = _hooks.concat(hooks);
1571
+ function perfNow() {
1572
+ var perf = getPerformance();
1573
+ if (perf && perf.now) {
1574
+ return perf.now();
1575
+ }
1576
+ return dateNow();
1577
+ }
1578
+
1579
+ var pluginStateData = createElmNodeData("plugin");
1580
+ function _getPluginState(plugin) {
1581
+ return pluginStateData.get(plugin, "state", {}, true);
1582
+ }
1583
+
1584
+ var strTelemetryPluginChain = "TelemetryPluginChain";
1585
+ var strHasRunFlags = "_hasRun";
1586
+ var strGetTelCtx = "_getTelCtx";
1587
+ var _chainId = 0;
1588
+ function _getNextProxyStart(proxy, core, startAt) {
1589
+ while (proxy) {
1590
+ if (proxy.getPlugin() === startAt) {
1591
+ return proxy;
1592
+ }
1593
+ proxy = proxy.getNext();
1594
+ }
1595
+ return createTelemetryProxyChain([startAt], core.config || {}, core);
1596
+ }
1597
+ function _createInternalContext(telemetryChain, config, core, startAt) {
1598
+ var _nextProxy = null;
1599
+ var _onComplete = [];
1600
+ if (startAt !== null) {
1601
+ _nextProxy = startAt ? _getNextProxyStart(telemetryChain, core, startAt) : telemetryChain;
1602
+ }
1603
+ var context = {
1604
+ _next: _moveNext,
1605
+ ctx: {
1606
+ core: function () {
1607
+ return core;
1608
+ },
1609
+ diagLog: function () {
1610
+ return safeGetLogger(core, config);
1611
+ },
1612
+ getCfg: function () {
1613
+ return config;
1614
+ },
1615
+ getExtCfg: _getExtCfg,
1616
+ getConfig: _getConfig,
1617
+ hasNext: function () {
1618
+ return !!_nextProxy;
1619
+ },
1620
+ getNext: function () {
1621
+ return _nextProxy;
1622
+ },
1623
+ setNext: function (nextPlugin) {
1624
+ _nextProxy = nextPlugin;
1625
+ },
1626
+ iterate: _iterateChain,
1627
+ onComplete: _addOnComplete
1628
+ }
1629
+ };
1630
+ function _addOnComplete(onComplete, that) {
1631
+ var args = [];
1632
+ for (var _i = 2; _i < arguments.length; _i++) {
1633
+ args[_i - 2] = arguments[_i];
1634
+ }
1635
+ if (onComplete) {
1636
+ _onComplete.push({
1637
+ func: onComplete,
1638
+ self: !isUndefined(that) ? that : context.ctx,
1639
+ args: args
1640
+ });
1641
+ }
1642
+ }
1643
+ function _moveNext() {
1644
+ var nextProxy = _nextProxy;
1645
+ _nextProxy = nextProxy ? nextProxy.getNext() : null;
1646
+ if (!nextProxy) {
1647
+ var onComplete = _onComplete;
1648
+ if (onComplete && onComplete.length > 0) {
1649
+ arrForEach(onComplete, function (completeDetails) {
1650
+ try {
1651
+ completeDetails.func.call(completeDetails.self, completeDetails.args);
1748
1652
  }
1749
- else {
1750
- _hooks.push(hooks);
1653
+ catch (e) {
1654
+ _throwInternal(core.logger, 2 , 73 , "Unexpected Exception during onComplete - " + dumpObj(e));
1751
1655
  }
1752
- }
1753
- };
1754
- proxyFunctionAs(_self, "_addUnloadCb", function () { return _unloadHandlerContainer; }, "add");
1755
- });
1756
- _self.diagLog = function (itemCtx) {
1757
- return _getTelCtx(itemCtx).diagLog();
1758
- };
1759
- _self[strIsInitialized] = function () {
1760
- return _isinitialized;
1761
- };
1762
- _self.setInitialized = function (isInitialized) {
1763
- _isinitialized = isInitialized;
1764
- };
1765
- _self[strSetNextPlugin] = function (next) {
1766
- _nextPlugin = next;
1767
- };
1768
- _self.processNext = function (env, itemCtx) {
1769
- if (itemCtx) {
1770
- itemCtx.processNext(env);
1771
- }
1772
- else if (_nextPlugin && isFunction(_nextPlugin.processTelemetry)) {
1773
- _nextPlugin.processTelemetry(env, null);
1774
- }
1775
- };
1776
- _self._getTelCtx = _getTelCtx;
1777
- function _getTelCtx(currentCtx) {
1778
- if (currentCtx === void 0) { currentCtx = null; }
1779
- var itemCtx = currentCtx;
1780
- if (!itemCtx) {
1781
- var rootCtx = _rootCtx || createProcessTelemetryContext(null, {}, _self.core);
1782
- if (_nextPlugin && _nextPlugin[strGetPlugin]) {
1783
- itemCtx = rootCtx.createNew(null, _nextPlugin[strGetPlugin]);
1784
- }
1785
- else {
1786
- itemCtx = rootCtx.createNew(null, _nextPlugin);
1787
- }
1656
+ });
1657
+ _onComplete = [];
1788
1658
  }
1789
- return itemCtx;
1790
1659
  }
1791
- function _setDefaults(config, core, pluginChain) {
1792
- if (config) {
1793
- setValue(config, strExtensionConfig, [], null, isNullOrUndefined);
1794
- }
1795
- if (!pluginChain && core) {
1796
- pluginChain = core.getProcessTelContext().getNext();
1797
- }
1798
- var nextPlugin = _nextPlugin;
1799
- if (_nextPlugin && _nextPlugin[strGetPlugin]) {
1800
- nextPlugin = _nextPlugin[strGetPlugin]();
1660
+ return nextProxy;
1661
+ }
1662
+ function _getExtCfg(identifier, defaultValue, mergeDefault) {
1663
+ if (defaultValue === void 0) { defaultValue = {}; }
1664
+ if (mergeDefault === void 0) { mergeDefault = 0 ; }
1665
+ var theConfig;
1666
+ if (config) {
1667
+ var extConfig = config.extensionConfig;
1668
+ if (extConfig && identifier) {
1669
+ theConfig = extConfig[identifier];
1801
1670
  }
1802
- _self.core = core;
1803
- _rootCtx = createProcessTelemetryContext(pluginChain, config, core, nextPlugin);
1804
1671
  }
1805
- function _initDefaults() {
1806
- _isinitialized = false;
1807
- _self.core = null;
1808
- _rootCtx = null;
1809
- _nextPlugin = null;
1810
- _hooks = [];
1811
- _unloadHandlerContainer = createUnloadHandlerContainer();
1672
+ if (!theConfig) {
1673
+ theConfig = defaultValue;
1812
1674
  }
1813
- }
1814
- return BaseTelemetryPlugin;
1815
- }());
1816
-
1817
- var strOnPrefix = "on";
1818
- var strAttachEvent = "attachEvent";
1819
- var strAddEventHelper = "addEventListener";
1820
- var strDetachEvent = "detachEvent";
1821
- var strRemoveEventListener = "removeEventListener";
1822
- var strEvents = "events";
1823
- var strVisibilityChangeEvt = "visibilitychange";
1824
- var strPageHide = "pagehide";
1825
- var strPageShow = "pageshow";
1826
- var strUnload = "unload";
1827
- var strBeforeUnload = "beforeunload";
1828
- var strPageHideNamespace = createUniqueNamespace("aiEvtPageHide");
1829
- var strPageShowNamespace = createUniqueNamespace("aiEvtPageShow");
1830
- var rRemoveEmptyNs = /\.[\.]+/g;
1831
- var rRemoveTrailingEmptyNs = /[\.]+$/;
1832
- var _guid = 1;
1833
- var elmNodeData = createElmNodeData("events");
1834
- var eventNamespace = /^([^.]*)(?:\.(.+)|)/;
1835
- function _normalizeNamespace(name) {
1836
- if (name && name.replace) {
1837
- return name.replace(/^\s*\.*|\.*\s*$/g, "");
1838
- }
1839
- return name;
1840
- }
1841
- function _getEvtNamespace(eventName, evtNamespace) {
1842
- if (evtNamespace) {
1843
- var theNamespace_1 = "";
1844
- if (isArray(evtNamespace)) {
1845
- theNamespace_1 = "";
1846
- arrForEach(evtNamespace, function (name) {
1847
- name = _normalizeNamespace(name);
1848
- if (name) {
1849
- if (name[0] !== ".") {
1850
- name = "." + name;
1851
- }
1852
- theNamespace_1 += name;
1675
+ else if (isObject(defaultValue)) {
1676
+ if (mergeDefault !== 0 ) {
1677
+ var newConfig_1 = objExtend(true, defaultValue, theConfig);
1678
+ if (config && mergeDefault === 2 ) {
1679
+ objForEachKey(defaultValue, function (field) {
1680
+ if (isNullOrUndefined(newConfig_1[field])) {
1681
+ var cfgValue = config[field];
1682
+ if (!isNullOrUndefined(cfgValue)) {
1683
+ newConfig_1[field] = cfgValue;
1684
+ }
1685
+ }
1686
+ });
1853
1687
  }
1854
- });
1688
+ theConfig = newConfig_1;
1689
+ }
1855
1690
  }
1856
- else {
1857
- theNamespace_1 = _normalizeNamespace(evtNamespace);
1691
+ return theConfig;
1692
+ }
1693
+ function _getConfig(identifier, field, defaultValue) {
1694
+ if (defaultValue === void 0) { defaultValue = false; }
1695
+ var theValue;
1696
+ var extConfig = _getExtCfg(identifier, null);
1697
+ if (extConfig && !isNullOrUndefined(extConfig[field])) {
1698
+ theValue = extConfig[field];
1858
1699
  }
1859
- if (theNamespace_1) {
1860
- if (theNamespace_1[0] !== ".") {
1861
- theNamespace_1 = "." + theNamespace_1;
1700
+ else if (config && !isNullOrUndefined(config[field])) {
1701
+ theValue = config[field];
1702
+ }
1703
+ return !isNullOrUndefined(theValue) ? theValue : defaultValue;
1704
+ }
1705
+ function _iterateChain(cb) {
1706
+ var nextPlugin;
1707
+ while (!!(nextPlugin = context._next())) {
1708
+ var plugin = nextPlugin.getPlugin();
1709
+ if (plugin) {
1710
+ cb(plugin);
1862
1711
  }
1863
- eventName = (eventName || "") + theNamespace_1;
1864
1712
  }
1865
1713
  }
1866
- var parsedEvent = (eventNamespace.exec(eventName || "") || []);
1867
- return {
1868
- type: parsedEvent[1],
1869
- ns: ((parsedEvent[2] || "").replace(rRemoveEmptyNs, ".").replace(rRemoveTrailingEmptyNs, "").split(".").sort()).join(".")
1870
- };
1714
+ return context;
1871
1715
  }
1872
- function _getRegisteredEvents(target, evtName, addDefault) {
1873
- if (addDefault === void 0) { addDefault = true; }
1874
- var aiEvts = elmNodeData.get(target, strEvents, {}, addDefault);
1875
- var registeredEvents = aiEvts[evtName];
1876
- if (!registeredEvents) {
1877
- registeredEvents = aiEvts[evtName] = [];
1716
+ function createProcessTelemetryContext(telemetryChain, config, core, startAt) {
1717
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1718
+ var context = internalContext.ctx;
1719
+ function _processNext(env) {
1720
+ var nextPlugin = internalContext._next();
1721
+ nextPlugin && nextPlugin.processTelemetry(env, context);
1722
+ return !nextPlugin;
1878
1723
  }
1879
- return registeredEvents;
1880
- }
1881
- function _doDetach(obj, evtName, handlerRef, useCapture) {
1882
- if (obj && evtName && evtName.type) {
1883
- if (obj[strRemoveEventListener]) {
1884
- obj[strRemoveEventListener](evtName.type, handlerRef, useCapture);
1724
+ function _createNew(plugins, startAt) {
1725
+ if (plugins === void 0) { plugins = null; }
1726
+ if (isArray(plugins)) {
1727
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1885
1728
  }
1886
- else if (obj[strDetachEvent]) {
1887
- obj[strDetachEvent](strOnPrefix + evtName.type, handlerRef);
1729
+ return createProcessTelemetryContext(plugins || context.getNext(), config, core, startAt);
1730
+ }
1731
+ context.processNext = _processNext;
1732
+ context.createNew = _createNew;
1733
+ return context;
1734
+ }
1735
+ function createProcessTelemetryUnloadContext(telemetryChain, core, startAt) {
1736
+ var config = core.config || {};
1737
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1738
+ var context = internalContext.ctx;
1739
+ function _processNext(unloadState) {
1740
+ var nextPlugin = internalContext._next();
1741
+ nextPlugin && nextPlugin.unload(context, unloadState);
1742
+ return !nextPlugin;
1743
+ }
1744
+ function _createNew(plugins, startAt) {
1745
+ if (plugins === void 0) { plugins = null; }
1746
+ if (isArray(plugins)) {
1747
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1888
1748
  }
1749
+ return createProcessTelemetryUnloadContext(plugins || context.getNext(), core, startAt);
1889
1750
  }
1751
+ context.processNext = _processNext;
1752
+ context.createNew = _createNew;
1753
+ return context;
1890
1754
  }
1891
- function _doAttach(obj, evtName, handlerRef, useCapture) {
1892
- var result = false;
1893
- if (obj && evtName && evtName.type && handlerRef) {
1894
- if (obj[strAddEventHelper]) {
1895
- obj[strAddEventHelper](evtName.type, handlerRef, useCapture);
1896
- result = true;
1897
- }
1898
- else if (obj[strAttachEvent]) {
1899
- obj[strAttachEvent](strOnPrefix + evtName.type, handlerRef);
1900
- result = true;
1755
+ function createProcessTelemetryUpdateContext(telemetryChain, core, startAt) {
1756
+ var config = core.config || {};
1757
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1758
+ var context = internalContext.ctx;
1759
+ function _processNext(updateState) {
1760
+ return context.iterate(function (plugin) {
1761
+ if (isFunction(plugin.update)) {
1762
+ plugin.update(context, updateState);
1763
+ }
1764
+ });
1765
+ }
1766
+ function _createNew(plugins, startAt) {
1767
+ if (plugins === void 0) { plugins = null; }
1768
+ if (isArray(plugins)) {
1769
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1901
1770
  }
1771
+ return createProcessTelemetryUpdateContext(plugins || context.getNext(), core, startAt);
1902
1772
  }
1903
- return result;
1773
+ context.processNext = _processNext;
1774
+ context.createNew = _createNew;
1775
+ return context;
1904
1776
  }
1905
- function _doUnregister(target, events, evtName, unRegFn) {
1906
- var idx = events.length;
1907
- while (idx--) {
1908
- var theEvent = events[idx];
1909
- if (theEvent) {
1910
- if (!evtName.ns || evtName.ns === theEvent.evtName.ns) {
1911
- if (!unRegFn || unRegFn(theEvent)) {
1912
- _doDetach(target, theEvent.evtName, theEvent.handler, theEvent.capture);
1913
- events.splice(idx, 1);
1777
+ function createTelemetryProxyChain(plugins, config, core, startAt) {
1778
+ var firstProxy = null;
1779
+ var add = startAt ? false : true;
1780
+ if (isArray(plugins) && plugins.length > 0) {
1781
+ var lastProxy_1 = null;
1782
+ arrForEach(plugins, function (thePlugin) {
1783
+ if (!add && startAt === thePlugin) {
1784
+ add = true;
1785
+ }
1786
+ if (add && thePlugin && isFunction(thePlugin.processTelemetry)) {
1787
+ var newProxy = createTelemetryPluginProxy(thePlugin, config, core);
1788
+ if (!firstProxy) {
1789
+ firstProxy = newProxy;
1914
1790
  }
1791
+ if (lastProxy_1) {
1792
+ lastProxy_1._setNext(newProxy);
1793
+ }
1794
+ lastProxy_1 = newProxy;
1915
1795
  }
1916
- }
1796
+ });
1797
+ }
1798
+ if (startAt && !firstProxy) {
1799
+ return createTelemetryProxyChain([startAt], config, core);
1917
1800
  }
1801
+ return firstProxy;
1918
1802
  }
1919
- function _unregisterEvents(target, evtName, unRegFn) {
1920
- if (evtName.type) {
1921
- _doUnregister(target, _getRegisteredEvents(target, evtName.type), evtName, unRegFn);
1803
+ function createTelemetryPluginProxy(plugin, config, core) {
1804
+ var nextProxy = null;
1805
+ var hasProcessTelemetry = isFunction(plugin.processTelemetry);
1806
+ var hasSetNext = isFunction(plugin.setNextPlugin);
1807
+ var chainId;
1808
+ if (plugin) {
1809
+ chainId = plugin.identifier + "-" + plugin.priority + "-" + _chainId++;
1922
1810
  }
1923
1811
  else {
1924
- var eventCache = elmNodeData.get(target, strEvents, {});
1925
- objForEachKey(eventCache, function (evtType, events) {
1926
- _doUnregister(target, events, evtName, unRegFn);
1927
- });
1928
- if (objKeys(eventCache).length === 0) {
1929
- elmNodeData.kill(target, strEvents);
1930
- }
1812
+ chainId = "Unknown-0-" + _chainId++;
1931
1813
  }
1932
- }
1933
- function mergeEvtNamespace(theNamespace, namespaces) {
1934
- var newNamespaces;
1935
- if (namespaces) {
1936
- if (isArray(namespaces)) {
1937
- newNamespaces = [theNamespace].concat(namespaces);
1814
+ var proxyChain = {
1815
+ getPlugin: function () {
1816
+ return plugin;
1817
+ },
1818
+ getNext: function () {
1819
+ return nextProxy;
1820
+ },
1821
+ processTelemetry: _processTelemetry,
1822
+ unload: _unloadPlugin,
1823
+ update: _updatePlugin,
1824
+ _id: chainId,
1825
+ _setNext: function (nextPlugin) {
1826
+ nextProxy = nextPlugin;
1938
1827
  }
1939
- else {
1940
- newNamespaces = [theNamespace, namespaces];
1828
+ };
1829
+ function _getTelCtx() {
1830
+ var itemCtx;
1831
+ if (plugin && isFunction(plugin[strGetTelCtx])) {
1832
+ itemCtx = plugin[strGetTelCtx]();
1941
1833
  }
1942
- newNamespaces = (_getEvtNamespace("xx", newNamespaces).ns).split(".");
1834
+ if (!itemCtx) {
1835
+ itemCtx = createProcessTelemetryContext(proxyChain, config, core);
1836
+ }
1837
+ return itemCtx;
1943
1838
  }
1944
- else {
1945
- newNamespaces = theNamespace;
1839
+ function _processChain(itemCtx, processPluginFn, name, details, isAsync) {
1840
+ var hasRun = false;
1841
+ var identifier = plugin ? plugin.identifier : strTelemetryPluginChain;
1842
+ var hasRunContext = itemCtx[strHasRunFlags];
1843
+ if (!hasRunContext) {
1844
+ hasRunContext = itemCtx[strHasRunFlags] = {};
1845
+ }
1846
+ itemCtx.setNext(nextProxy);
1847
+ if (plugin) {
1848
+ doPerf(itemCtx[strCore](), function () { return identifier + ":" + name; }, function () {
1849
+ hasRunContext[chainId] = true;
1850
+ try {
1851
+ var nextId = nextProxy ? nextProxy._id : strEmpty;
1852
+ if (nextId) {
1853
+ hasRunContext[nextId] = false;
1854
+ }
1855
+ hasRun = processPluginFn(itemCtx);
1856
+ }
1857
+ catch (error) {
1858
+ var hasNextRun = nextProxy ? hasRunContext[nextProxy._id] : true;
1859
+ if (hasNextRun) {
1860
+ hasRun = true;
1861
+ }
1862
+ if (!nextProxy || !hasNextRun) {
1863
+ _throwInternal(itemCtx.diagLog(), 1 , 73 , "Plugin [" + identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
1864
+ }
1865
+ }
1866
+ }, details, isAsync);
1867
+ }
1868
+ return hasRun;
1946
1869
  }
1947
- return newNamespaces;
1948
- }
1949
- function eventOn(target, eventName, handlerRef, evtNamespace, useCapture) {
1950
- if (useCapture === void 0) { useCapture = false; }
1951
- var result = false;
1952
- if (target) {
1953
- try {
1954
- var evtName = _getEvtNamespace(eventName, evtNamespace);
1955
- result = _doAttach(target, evtName, handlerRef, useCapture);
1956
- if (result && elmNodeData.accept(target)) {
1957
- var registeredEvent = {
1958
- guid: _guid++,
1959
- evtName: evtName,
1960
- handler: handlerRef,
1961
- capture: useCapture
1962
- };
1963
- _getRegisteredEvents(target, evtName.type).push(registeredEvent);
1870
+ function _processTelemetry(env, itemCtx) {
1871
+ itemCtx = itemCtx || _getTelCtx();
1872
+ function _callProcessTelemetry(itemCtx) {
1873
+ if (!plugin || !hasProcessTelemetry) {
1874
+ return false;
1875
+ }
1876
+ var pluginState = _getPluginState(plugin);
1877
+ if (pluginState.teardown || pluginState[strDisabled]) {
1878
+ return false;
1879
+ }
1880
+ if (hasSetNext) {
1881
+ plugin.setNextPlugin(nextProxy);
1964
1882
  }
1883
+ plugin.processTelemetry(env, itemCtx);
1884
+ return true;
1965
1885
  }
1966
- catch (e) {
1886
+ if (!_processChain(itemCtx, _callProcessTelemetry, "processTelemetry", function () { return ({ item: env }); }, !(env.sync))) {
1887
+ itemCtx.processNext(env);
1967
1888
  }
1968
1889
  }
1969
- return result;
1970
- }
1971
- function eventOff(target, eventName, handlerRef, evtNamespace, useCapture) {
1972
- if (useCapture === void 0) { useCapture = false; }
1973
- if (target) {
1974
- try {
1975
- var evtName_1 = _getEvtNamespace(eventName, evtNamespace);
1976
- var found_1 = false;
1977
- _unregisterEvents(target, evtName_1, function (regEvent) {
1978
- if ((evtName_1.ns && !handlerRef) || regEvent.handler === handlerRef) {
1979
- found_1 = true;
1980
- return true;
1890
+ function _unloadPlugin(unloadCtx, unloadState) {
1891
+ function _callTeardown() {
1892
+ var hasRun = false;
1893
+ if (plugin) {
1894
+ var pluginState = _getPluginState(plugin);
1895
+ var pluginCore = plugin[strCore] || pluginState.core;
1896
+ if (plugin && (!pluginCore || pluginCore === unloadCtx[strCore]()) && !pluginState[strTeardown]) {
1897
+ pluginState[strCore] = null;
1898
+ pluginState[strTeardown] = true;
1899
+ pluginState[strIsInitialized] = false;
1900
+ if (plugin[strTeardown] && plugin[strTeardown](unloadCtx, unloadState) === true) {
1901
+ hasRun = true;
1902
+ }
1981
1903
  }
1982
- return false;
1983
- });
1984
- if (!found_1) {
1985
- _doDetach(target, evtName_1, handlerRef, useCapture);
1986
1904
  }
1905
+ return hasRun;
1987
1906
  }
1988
- catch (e) {
1907
+ if (!_processChain(unloadCtx, _callTeardown, "unload", function () { }, unloadState.isAsync)) {
1908
+ unloadCtx.processNext(unloadState);
1989
1909
  }
1990
1910
  }
1991
- }
1992
- function addEventHandler(eventName, callback, evtNamespace) {
1993
- var result = false;
1994
- var w = getWindow();
1995
- if (w) {
1996
- result = eventOn(w, eventName, callback, evtNamespace);
1997
- result = eventOn(w["body"], eventName, callback, evtNamespace) || result;
1998
- }
1999
- var doc = getDocument();
2000
- if (doc) {
2001
- result = eventOn(doc, eventName, callback, evtNamespace) || result;
2002
- }
2003
- return result;
2004
- }
2005
- function removeEventHandler(eventName, callback, evtNamespace) {
2006
- var w = getWindow();
2007
- if (w) {
2008
- eventOff(w, eventName, callback, evtNamespace);
2009
- eventOff(w["body"], eventName, callback, evtNamespace);
2010
- }
2011
- var doc = getDocument();
2012
- if (doc) {
2013
- eventOff(doc, eventName, callback, evtNamespace);
2014
- }
2015
- }
2016
- function _addEventListeners(events, listener, excludeEvents, evtNamespace) {
2017
- var added = false;
2018
- if (listener && events && events.length > 0) {
2019
- arrForEach(events, function (name) {
2020
- if (name) {
2021
- if (!excludeEvents || arrIndexOf(excludeEvents, name) === -1) {
2022
- added = addEventHandler(name, listener, evtNamespace) || added;
1911
+ function _updatePlugin(updateCtx, updateState) {
1912
+ function _callUpdate() {
1913
+ var hasRun = false;
1914
+ if (plugin) {
1915
+ var pluginState = _getPluginState(plugin);
1916
+ var pluginCore = plugin[strCore] || pluginState.core;
1917
+ if (plugin && (!pluginCore || pluginCore === updateCtx[strCore]()) && !pluginState[strTeardown]) {
1918
+ if (plugin[strUpdate] && plugin[strUpdate](updateCtx, updateState) === true) {
1919
+ hasRun = true;
1920
+ }
2023
1921
  }
2024
1922
  }
2025
- });
1923
+ return hasRun;
1924
+ }
1925
+ if (!_processChain(updateCtx, _callUpdate, "update", function () { }, false)) {
1926
+ updateCtx.processNext(updateState);
1927
+ }
2026
1928
  }
2027
- return added;
1929
+ return objFreeze(proxyChain);
2028
1930
  }
2029
- function addEventListeners(events, listener, excludeEvents, evtNamespace) {
2030
- var added = false;
2031
- if (listener && events && isArray(events)) {
2032
- added = _addEventListeners(events, listener, excludeEvents, evtNamespace);
2033
- if (!added && excludeEvents && excludeEvents.length > 0) {
2034
- added = _addEventListeners(events, listener, null, evtNamespace);
1931
+
1932
+ var strExtensionConfig = "extensionConfig";
1933
+
1934
+ function createUnloadHandlerContainer() {
1935
+ var handlers = [];
1936
+ function _addHandler(handler) {
1937
+ if (handler) {
1938
+ handlers.push(handler);
2035
1939
  }
2036
1940
  }
2037
- return added;
2038
- }
2039
- function removeEventListeners(events, listener, evtNamespace) {
2040
- if (events && isArray(events)) {
2041
- arrForEach(events, function (name) {
2042
- if (name) {
2043
- removeEventHandler(name, listener, evtNamespace);
1941
+ function _runHandlers(unloadCtx, unloadState) {
1942
+ arrForEach(handlers, function (handler) {
1943
+ try {
1944
+ handler(unloadCtx, unloadState);
1945
+ }
1946
+ catch (e) {
1947
+ _throwInternal(unloadCtx.diagLog(), 2 , 73 , "Unexpected error calling unload handler - " + dumpObj(e));
2044
1948
  }
2045
1949
  });
1950
+ handlers = [];
2046
1951
  }
1952
+ return {
1953
+ add: _addHandler,
1954
+ run: _runHandlers
1955
+ };
2047
1956
  }
2048
- function addPageUnloadEventListener(listener, excludeEvents, evtNamespace) {
2049
- return addEventListeners([strBeforeUnload, strUnload, strPageHide], listener, excludeEvents, evtNamespace);
2050
- }
2051
- function removePageUnloadEventListener(listener, evtNamespace) {
2052
- removeEventListeners([strBeforeUnload, strUnload, strPageHide], listener, evtNamespace);
2053
- }
2054
- function addPageHideEventListener(listener, excludeEvents, evtNamespace) {
2055
- function _handlePageVisibility(evt) {
2056
- var doc = getDocument();
2057
- if (listener && doc && doc.visibilityState === "hidden") {
2058
- listener(evt);
1957
+
1958
+ var strGetPlugin = "getPlugin";
1959
+ var BaseTelemetryPlugin = /** @class */ (function () {
1960
+ function BaseTelemetryPlugin() {
1961
+ var _self = this;
1962
+ var _isinitialized;
1963
+ var _rootCtx;
1964
+ var _nextPlugin;
1965
+ var _unloadHandlerContainer;
1966
+ var _hooks;
1967
+ _initDefaults();
1968
+ dynamicProto(BaseTelemetryPlugin, _self, function (_self) {
1969
+ _self.initialize = function (config, core, extensions, pluginChain) {
1970
+ _setDefaults(config, core, pluginChain);
1971
+ _isinitialized = true;
1972
+ };
1973
+ _self.teardown = function (unloadCtx, unloadState) {
1974
+ var core = _self.core;
1975
+ if (!core || (unloadCtx && core !== unloadCtx.core())) {
1976
+ return;
1977
+ }
1978
+ var result;
1979
+ var unloadDone = false;
1980
+ var theUnloadCtx = unloadCtx || createProcessTelemetryUnloadContext(null, core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
1981
+ var theUnloadState = unloadState || {
1982
+ reason: 0 ,
1983
+ isAsync: false
1984
+ };
1985
+ function _unloadCallback() {
1986
+ if (!unloadDone) {
1987
+ unloadDone = true;
1988
+ _unloadHandlerContainer.run(theUnloadCtx, unloadState);
1989
+ arrForEach(_hooks, function (fn) {
1990
+ fn.rm();
1991
+ });
1992
+ _hooks = [];
1993
+ if (result === true) {
1994
+ theUnloadCtx.processNext(theUnloadState);
1995
+ }
1996
+ _initDefaults();
1997
+ }
1998
+ }
1999
+ if (!_self[strDoTeardown] || _self[strDoTeardown](theUnloadCtx, theUnloadState, _unloadCallback) !== true) {
2000
+ _unloadCallback();
2001
+ }
2002
+ else {
2003
+ result = true;
2004
+ }
2005
+ return result;
2006
+ };
2007
+ _self.update = function (updateCtx, updateState) {
2008
+ var core = _self.core;
2009
+ if (!core || (updateCtx && core !== updateCtx.core())) {
2010
+ return;
2011
+ }
2012
+ var result;
2013
+ var updateDone = false;
2014
+ var theUpdateCtx = updateCtx || createProcessTelemetryUpdateContext(null, core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
2015
+ var theUpdateState = updateState || {
2016
+ reason: 0
2017
+ };
2018
+ function _updateCallback() {
2019
+ if (!updateDone) {
2020
+ updateDone = true;
2021
+ _setDefaults(theUpdateCtx.getCfg(), theUpdateCtx.core(), theUpdateCtx.getNext());
2022
+ }
2023
+ }
2024
+ if (!_self._doUpdate || _self._doUpdate(theUpdateCtx, theUpdateState, _updateCallback) !== true) {
2025
+ _updateCallback();
2026
+ }
2027
+ else {
2028
+ result = true;
2029
+ }
2030
+ return result;
2031
+ };
2032
+ _self._addHook = function (hooks) {
2033
+ if (hooks) {
2034
+ if (isArray(hooks)) {
2035
+ _hooks = _hooks.concat(hooks);
2036
+ }
2037
+ else {
2038
+ _hooks.push(hooks);
2039
+ }
2040
+ }
2041
+ };
2042
+ proxyFunctionAs(_self, "_addUnloadCb", function () { return _unloadHandlerContainer; }, "add");
2043
+ });
2044
+ _self.diagLog = function (itemCtx) {
2045
+ return _getTelCtx(itemCtx).diagLog();
2046
+ };
2047
+ _self[strIsInitialized] = function () {
2048
+ return _isinitialized;
2049
+ };
2050
+ _self.setInitialized = function (isInitialized) {
2051
+ _isinitialized = isInitialized;
2052
+ };
2053
+ _self[strSetNextPlugin] = function (next) {
2054
+ _nextPlugin = next;
2055
+ };
2056
+ _self.processNext = function (env, itemCtx) {
2057
+ if (itemCtx) {
2058
+ itemCtx.processNext(env);
2059
+ }
2060
+ else if (_nextPlugin && isFunction(_nextPlugin.processTelemetry)) {
2061
+ _nextPlugin.processTelemetry(env, null);
2062
+ }
2063
+ };
2064
+ _self._getTelCtx = _getTelCtx;
2065
+ function _getTelCtx(currentCtx) {
2066
+ if (currentCtx === void 0) { currentCtx = null; }
2067
+ var itemCtx = currentCtx;
2068
+ if (!itemCtx) {
2069
+ var rootCtx = _rootCtx || createProcessTelemetryContext(null, {}, _self.core);
2070
+ if (_nextPlugin && _nextPlugin[strGetPlugin]) {
2071
+ itemCtx = rootCtx.createNew(null, _nextPlugin[strGetPlugin]);
2072
+ }
2073
+ else {
2074
+ itemCtx = rootCtx.createNew(null, _nextPlugin);
2075
+ }
2076
+ }
2077
+ return itemCtx;
2059
2078
  }
2060
- }
2061
- var newNamespaces = mergeEvtNamespace(strPageHideNamespace, evtNamespace);
2062
- var pageUnloadAdded = _addEventListeners([strPageHide], listener, excludeEvents, newNamespaces);
2063
- if (!excludeEvents || arrIndexOf(excludeEvents, strVisibilityChangeEvt) === -1) {
2064
- pageUnloadAdded = _addEventListeners([strVisibilityChangeEvt], _handlePageVisibility, excludeEvents, newNamespaces) || pageUnloadAdded;
2065
- }
2066
- if (!pageUnloadAdded && excludeEvents) {
2067
- pageUnloadAdded = addPageHideEventListener(listener, null, evtNamespace);
2068
- }
2069
- return pageUnloadAdded;
2070
- }
2071
- function removePageHideEventListener(listener, evtNamespace) {
2072
- var newNamespaces = mergeEvtNamespace(strPageHideNamespace, evtNamespace);
2073
- removeEventListeners([strPageHide], listener, newNamespaces);
2074
- removeEventListeners([strVisibilityChangeEvt], null, newNamespaces);
2075
- }
2076
- function addPageShowEventListener(listener, excludeEvents, evtNamespace) {
2077
- function _handlePageVisibility(evt) {
2078
- var doc = getDocument();
2079
- if (listener && doc && doc.visibilityState === "visible") {
2080
- listener(evt);
2079
+ function _setDefaults(config, core, pluginChain) {
2080
+ if (config) {
2081
+ setValue(config, strExtensionConfig, [], null, isNullOrUndefined);
2082
+ }
2083
+ if (!pluginChain && core) {
2084
+ pluginChain = core.getProcessTelContext().getNext();
2085
+ }
2086
+ var nextPlugin = _nextPlugin;
2087
+ if (_nextPlugin && _nextPlugin[strGetPlugin]) {
2088
+ nextPlugin = _nextPlugin[strGetPlugin]();
2089
+ }
2090
+ _self.core = core;
2091
+ _rootCtx = createProcessTelemetryContext(pluginChain, config, core, nextPlugin);
2092
+ }
2093
+ function _initDefaults() {
2094
+ _isinitialized = false;
2095
+ _self.core = null;
2096
+ _rootCtx = null;
2097
+ _nextPlugin = null;
2098
+ _hooks = [];
2099
+ _unloadHandlerContainer = createUnloadHandlerContainer();
2081
2100
  }
2082
2101
  }
2083
- var newNamespaces = mergeEvtNamespace(strPageShowNamespace, evtNamespace);
2084
- var pageShowAdded = _addEventListeners([strPageShow], listener, excludeEvents, newNamespaces);
2085
- pageShowAdded = _addEventListeners([strVisibilityChangeEvt], _handlePageVisibility, excludeEvents, newNamespaces) || pageShowAdded;
2086
- if (!pageShowAdded && excludeEvents) {
2087
- pageShowAdded = addPageShowEventListener(listener, null, evtNamespace);
2088
- }
2089
- return pageShowAdded;
2090
- }
2091
- function removePageShowEventListener(listener, evtNamespace) {
2092
- var newNamespaces = mergeEvtNamespace(strPageShowNamespace, evtNamespace);
2093
- removeEventListeners([strPageShow], listener, newNamespaces);
2094
- removeEventListeners([strVisibilityChangeEvt], null, newNamespaces);
2095
- }
2096
-
2097
- function perfNow() {
2098
- var perf = getPerformance();
2099
- if (perf && perf.now) {
2100
- return perf.now();
2101
- }
2102
- return dateNow();
2103
- }
2102
+ return BaseTelemetryPlugin;
2103
+ }());
2104
2104
 
2105
2105
  var _a$1;
2106
- var Version = '3.2.2';
2106
+ var Version = '3.2.3';
2107
2107
  var FullVersionString = "1DS-Web-JS-" + Version;
2108
2108
  var strDisabledPropertyName = "Microsoft_ApplicationInsights_BypassAjaxInstrumentation";
2109
2109
  var strWithCredentials = "withCredentials";
@@ -3676,7 +3676,7 @@
3676
3676
  var _this = _super.call(this) || this;
3677
3677
  _this.identifier = "PostChannel";
3678
3678
  _this.priority = 1011;
3679
- _this.version = '3.2.2';
3679
+ _this.version = '3.2.3';
3680
3680
  var _config;
3681
3681
  var _isTeardownCalled = false;
3682
3682
  var _flushCallbackQueue = [];
@@ -3701,7 +3701,6 @@
3701
3701
  var _delayedBatchReason;
3702
3702
  var _optimizeObject = true;
3703
3703
  var _isPageUnloadTriggered = false;
3704
- var _disableXhrSync = false;
3705
3704
  var _maxEventSendAttempts = MaxSendAttempts;
3706
3705
  var _maxUnloadEventSendAttempts = MaxSyncUnloadSendAttempts;
3707
3706
  var _evtNamespace;
@@ -3733,7 +3732,6 @@
3733
3732
  if (_config.autoFlushEventsLimit > 0) {
3734
3733
  _autoFlushEventsLimit = _config.autoFlushEventsLimit;
3735
3734
  }
3736
- _disableXhrSync = _config.disableXhrSync;
3737
3735
  if (isNumber(_config[strMaxEventRetryAttempts])) {
3738
3736
  _maxEventSendAttempts = _config[strMaxEventRetryAttempts];
3739
3737
  }
@@ -3941,13 +3939,13 @@
3941
3939
  _self.flush = function (async, callback, sendReason) {
3942
3940
  if (async === void 0) { async = true; }
3943
3941
  if (!_paused) {
3944
- _clearScheduledTimer();
3945
3942
  sendReason = sendReason || 1 ;
3946
3943
  if (async) {
3947
- _queueBatches(1 , 0 , sendReason);
3948
- _resetQueueCounts();
3949
3944
  if (_flushCallbackTimerId == null) {
3945
+ _clearScheduledTimer();
3946
+ _queueBatches(1 , 0 , sendReason);
3950
3947
  _flushCallbackTimerId = _createTimer(function () {
3948
+ _flushCallbackTimerId = null;
3951
3949
  _flushImpl(callback, sendReason);
3952
3950
  }, 0);
3953
3951
  }
@@ -3956,10 +3954,14 @@
3956
3954
  }
3957
3955
  }
3958
3956
  else {
3957
+ var cleared = _clearScheduledTimer();
3959
3958
  _sendEventsForLatencyAndAbove(1 , 1 , sendReason);
3960
3959
  if (callback !== null && callback !== undefined) {
3961
3960
  callback();
3962
3961
  }
3962
+ if (cleared) {
3963
+ _scheduleTimer();
3964
+ }
3963
3965
  }
3964
3966
  }
3965
3967
  };
@@ -4050,7 +4052,6 @@
4050
4052
  _delayedBatchReason = null;
4051
4053
  _optimizeObject = true;
4052
4054
  _isPageUnloadTriggered = false;
4053
- _disableXhrSync = false;
4054
4055
  _maxEventSendAttempts = MaxSendAttempts;
4055
4056
  _maxUnloadEventSendAttempts = MaxSyncUnloadSendAttempts;
4056
4057
  _evtNamespace = null;
@@ -4082,7 +4083,9 @@
4082
4083
  _timeoutWrapper.clear(_scheduledTimerId);
4083
4084
  _scheduledTimerId = null;
4084
4085
  _timerCount = 0;
4086
+ return true;
4085
4087
  }
4088
+ return false;
4086
4089
  }
4087
4090
  function _releaseAllQueues(sendType, sendReason) {
4088
4091
  _clearScheduledTimer();
@@ -4246,18 +4249,20 @@
4246
4249
  }
4247
4250
  function _flushImpl(callback, sendReason) {
4248
4251
  _sendEventsForLatencyAndAbove(1 , 0 , sendReason);
4252
+ _resetQueueCounts();
4249
4253
  _waitForIdleManager(function () {
4250
4254
  if (callback) {
4251
4255
  callback();
4252
4256
  }
4253
4257
  if (_flushCallbackQueue.length > 0) {
4254
- _flushCallbackTimerId = _createTimer(function () { return _flushImpl(_flushCallbackQueue.shift(), sendReason); }, 0);
4258
+ _flushCallbackTimerId = _createTimer(function () {
4259
+ _flushCallbackTimerId = null;
4260
+ _flushImpl(_flushCallbackQueue.shift(), sendReason);
4261
+ }, 0);
4255
4262
  }
4256
4263
  else {
4257
4264
  _flushCallbackTimerId = null;
4258
- if (_hasEvents()) {
4259
- _scheduleTimer();
4260
- }
4265
+ _scheduleTimer();
4261
4266
  }
4262
4267
  });
4263
4268
  }
@@ -4267,6 +4272,7 @@
4267
4272
  }
4268
4273
  else {
4269
4274
  _flushCallbackTimerId = _createTimer(function () {
4275
+ _flushCallbackTimerId = null;
4270
4276
  _waitForIdleManager(callback);
4271
4277
  }, FlushCheckTimer);
4272
4278
  }
@@ -4402,4 +4408,4 @@
4402
4408
  (function(obj, prop, descriptor) { /* ai_es3_polyfil defineProperty */ var func = Object["defineProperty"]; if (func) { try { return func(obj, prop, descriptor); } catch(e) { /* IE8 defines defineProperty, but will throw */ } } if (descriptor && typeof descriptor.value !== undefined) { obj[prop] = descriptor.value; } return obj; })(exports, '__esModule', { value: true });
4403
4409
 
4404
4410
  }));
4405
- //# sourceMappingURL=ms.post-3.2.2.js.map
4411
+ //# sourceMappingURL=ms.post-3.2.3.js.map