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

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 (56) hide show
  1. package/README.md +2 -2
  2. package/bundle/{ms.post-3.1.11.gbl.js → ms.post-3.2.2.gbl.js} +1278 -548
  3. package/bundle/ms.post-3.2.2.gbl.js.map +1 -0
  4. package/bundle/ms.post-3.2.2.gbl.min.js +7 -0
  5. package/bundle/ms.post-3.2.2.gbl.min.js.map +1 -0
  6. package/bundle/ms.post-3.2.2.integrity.json +46 -0
  7. package/bundle/{ms.post-3.1.11.js → ms.post-3.2.2.js} +1278 -548
  8. package/bundle/ms.post-3.2.2.js.map +1 -0
  9. package/bundle/ms.post-3.2.2.min.js +7 -0
  10. package/bundle/ms.post-3.2.2.min.js.map +1 -0
  11. package/bundle/ms.post.gbl.js +1277 -547
  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 +1277 -547
  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 +212 -128
  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.d.ts +2 -1
  30. package/dist-esm/src/HttpManager.js +45 -40
  31. package/dist-esm/src/HttpManager.js.map +1 -1
  32. package/dist-esm/src/Index.js +1 -1
  33. package/dist-esm/src/KillSwitch.js +1 -1
  34. package/dist-esm/src/PostChannel.d.ts +2 -9
  35. package/dist-esm/src/PostChannel.js +151 -97
  36. package/dist-esm/src/PostChannel.js.map +1 -1
  37. package/dist-esm/src/RetryPolicy.d.ts +20 -25
  38. package/dist-esm/src/RetryPolicy.js +35 -44
  39. package/dist-esm/src/RetryPolicy.js.map +1 -1
  40. package/dist-esm/src/Serializer.js +1 -1
  41. package/dist-esm/src/TimeoutOverrideWrapper.d.ts +18 -0
  42. package/dist-esm/src/TimeoutOverrideWrapper.js +28 -0
  43. package/dist-esm/src/TimeoutOverrideWrapper.js.map +1 -0
  44. package/dist-esm/src/typings/XDomainRequest.js +1 -1
  45. package/package.json +3 -3
  46. package/src/HttpManager.ts +48 -51
  47. package/src/PostChannel.ts +186 -119
  48. package/src/RetryPolicy.ts +33 -38
  49. package/src/TimeoutOverrideWrapper.ts +29 -0
  50. package/bundle/ms.post-3.1.11.gbl.js.map +0 -1
  51. package/bundle/ms.post-3.1.11.gbl.min.js +0 -7
  52. package/bundle/ms.post-3.1.11.gbl.min.js.map +0 -1
  53. package/bundle/ms.post-3.1.11.integrity.json +0 -46
  54. package/bundle/ms.post-3.1.11.js.map +0 -1
  55. package/bundle/ms.post-3.1.11.min.js +0 -7
  56. package/bundle/ms.post-3.1.11.min.js.map +0 -1
package/dist/ms.post.js CHANGED
@@ -1,13 +1,13 @@
1
1
  /*!
2
- * 1DS JS SDK POST plugin, 3.1.11
2
+ * 1DS JS SDK POST plugin, 3.2.2
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  * (Microsoft Internal Only)
5
5
  */
6
6
  (function (global, factory) {
7
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@microsoft/applicationinsights-shims'), require('@microsoft/1ds-core-js'), require('@microsoft/dynamicproto-js')) :
8
- typeof define === 'function' && define.amd ? define(['exports', '@microsoft/applicationinsights-shims', '@microsoft/1ds-core-js', '@microsoft/dynamicproto-js'], factory) :
9
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.oneDS = global.oneDS || {}, global.applicationinsightsShims, global._1dsCoreJs, global.dynamicProto));
10
- })(this, (function (exports, applicationinsightsShims, _1dsCoreJs, dynamicProto) { 'use strict';
7
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@microsoft/applicationinsights-shims'), require('@microsoft/dynamicproto-js'), require('@microsoft/1ds-core-js')) :
8
+ typeof define === 'function' && define.amd ? define(['exports', '@microsoft/applicationinsights-shims', '@microsoft/dynamicproto-js', '@microsoft/1ds-core-js'], factory) :
9
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.oneDS = global.oneDS || {}, global.applicationinsightsShims, global.dynamicProto, global._1dsCoreJs));
10
+ })(this, (function (exports, applicationinsightsShims, dynamicProto, _1dsCoreJs) { 'use strict';
11
11
 
12
12
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
13
13
 
@@ -38,6 +38,7 @@
38
38
  var strUploadTime = "upload-time";
39
39
  var strApiKey = "apikey";
40
40
  var strMsaDeviceTicket = "AuthMsaDeviceTicket";
41
+ var strAuthXToken = "AuthXToken";
41
42
  var strNoResponseBody = "NoResponseBody";
42
43
  var strMsfpc = "msfpc";
43
44
 
@@ -350,24 +351,19 @@
350
351
  var RandomizationUpperThreshold = 1.2;
351
352
  var BaseBackoff = 3000;
352
353
  var MaxBackoff = 600000;
353
- var RetryPolicy = /** @class */ (function () {
354
- function RetryPolicy() {
355
- }
356
- RetryPolicy.shouldRetryForStatus = function (httpStatusCode) {
357
- return !((httpStatusCode >= 300 && httpStatusCode < 500 && httpStatusCode != 408 && httpStatusCode != 429)
358
- || (httpStatusCode == 501)
359
- || (httpStatusCode == 505));
360
- };
361
- RetryPolicy.getMillisToBackoffForRetry = function (retriesSoFar) {
362
- var waitDuration = 0;
363
- var minBackoff = BaseBackoff * RandomizationLowerThreshold;
364
- var maxBackoff = BaseBackoff * RandomizationUpperThreshold;
365
- var randomBackoff = Math.floor(Math.random() * (maxBackoff - minBackoff)) + minBackoff;
366
- waitDuration = Math.pow(2, retriesSoFar) * randomBackoff;
367
- return Math.min(waitDuration, MaxBackoff);
368
- };
369
- return RetryPolicy;
370
- }());
354
+ function retryPolicyShouldRetryForStatus(httpStatusCode) {
355
+ return !((httpStatusCode >= 300 && httpStatusCode < 500 && httpStatusCode != 408 && httpStatusCode != 429)
356
+ || (httpStatusCode == 501)
357
+ || (httpStatusCode == 505));
358
+ }
359
+ function retryPolicyGetMillisToBackoffForRetry(retriesSoFar) {
360
+ var waitDuration = 0;
361
+ var minBackoff = BaseBackoff * RandomizationLowerThreshold;
362
+ var maxBackoff = BaseBackoff * RandomizationUpperThreshold;
363
+ var randomBackoff = Math.floor(Math.random() * (maxBackoff - minBackoff)) + minBackoff;
364
+ waitDuration = Math.pow(2, retriesSoFar) * randomBackoff;
365
+ return Math.min(waitDuration, MaxBackoff);
366
+ }
371
367
 
372
368
  var SecToMsMultiplier = 1000;
373
369
  var KillSwitch = /** @class */ (function () {
@@ -470,11 +466,19 @@
470
466
  _a);
471
467
  var _collectorQsHeaders = {};
472
468
  var _collectorHeaderToQs = {};
473
- function _addCollectorHeaderQsMapping(qsName, headerName) {
469
+ function _addCollectorHeaderQsMapping(qsName, headerName, allowQs) {
474
470
  _collectorQsHeaders[qsName] = headerName;
475
- _collectorHeaderToQs[headerName] = qsName;
471
+ if (allowQs !== false) {
472
+ _collectorHeaderToQs[headerName] = qsName;
473
+ }
476
474
  }
477
- _addCollectorHeaderQsMapping(strMsaDeviceTicket, strMsaDeviceTicket);
475
+ _addCollectorHeaderQsMapping(strMsaDeviceTicket, strMsaDeviceTicket, false);
476
+ _addCollectorHeaderQsMapping(strClientVersion, strClientVersion);
477
+ _addCollectorHeaderQsMapping(strClientId, "Client-Id");
478
+ _addCollectorHeaderQsMapping(strApiKey, strApiKey);
479
+ _addCollectorHeaderQsMapping(strTimeDeltaToApply, strTimeDeltaToApply);
480
+ _addCollectorHeaderQsMapping(strUploadTime, strUploadTime);
481
+ _addCollectorHeaderQsMapping(strAuthXToken, strAuthXToken);
478
482
  function _getResponseText(xhr) {
479
483
  try {
480
484
  return xhr.responseText;
@@ -513,7 +517,7 @@
513
517
  }
514
518
  }
515
519
  var HttpManager = /** @class */ (function () {
516
- function HttpManager(maxEventsPerBatch, maxConnections, maxRequestRetriesBeforeBackoff, actions) {
520
+ function HttpManager(maxEventsPerBatch, maxConnections, maxRequestRetriesBeforeBackoff, actions, timeoutOverride) {
517
521
  this._responseHandlers = [];
518
522
  var _urlString = "?cors=true&" + strContentTypeHeader.toLowerCase() + "=" + defaultContentType;
519
523
  var _killSwitch = new KillSwitch();
@@ -543,7 +547,7 @@
543
547
  channelConfig = {};
544
548
  }
545
549
  _urlString = endpointUrl + _urlString;
546
- _useHeaders = !_1dsCoreJs.isUndefined(channelConfig.avoidOptions) ? !channelConfig.avoidOptions : false;
550
+ _useHeaders = !_1dsCoreJs.isUndefined(channelConfig.avoidOptions) ? !channelConfig.avoidOptions : true;
547
551
  _core = core;
548
552
  _cookieMgr = core.getCookieMgr();
549
553
  _enableEventTimings = !_core.config.disableEventTimings;
@@ -652,7 +656,7 @@
652
656
  xdr.send(payload.data);
653
657
  }
654
658
  else {
655
- _postManager._setTimeoutOverride(function () {
659
+ timeoutOverride.set(function () {
656
660
  xdr.send(payload.data);
657
661
  }, 0);
658
662
  }
@@ -710,7 +714,7 @@
710
714
  _doOnComplete(oncomplete, 200, {});
711
715
  }
712
716
  if (!responseHandled && payload.timeout > 0) {
713
- _postManager._setTimeoutOverride(function () {
717
+ timeoutOverride.set(function () {
714
718
  if (!responseHandled) {
715
719
  responseHandled = true;
716
720
  _doOnComplete(oncomplete, 500, {});
@@ -769,7 +773,7 @@
769
773
  oncomplete(status, headers, response);
770
774
  }
771
775
  catch (e) {
772
- _postManager.diagLog().throwInternal(_1dsCoreJs.LoggingSeverity.WARNING, _1dsCoreJs._ExtendedInternalMessageId.SendPostOnCompleteFailure, _1dsCoreJs.dumpObj(e));
776
+ _1dsCoreJs._throwInternal(_postManager.diagLog(), 2 , 518 , _1dsCoreJs.dumpObj(e));
773
777
  }
774
778
  }
775
779
  function _beaconSendPost(payload, oncomplete, sync) {
@@ -804,7 +808,7 @@
804
808
  }
805
809
  }
806
810
  catch (ex) {
807
- _postManager.diagLog().warnToConsole("Failed to send telemetry using sendBeacon API. Ex:" + ex);
811
+ _postManager.diagLog().warnToConsole("Failed to send telemetry using sendBeacon API. Ex:" + _1dsCoreJs.dumpObj(ex));
808
812
  status = 0;
809
813
  }
810
814
  finally {
@@ -968,7 +972,7 @@
968
972
  }, function () { return ({ batches: _createDebugBatches(orgBatches_1), retryCount: retryCount, isTeardown: isTeardown, isSynchronous: isSynchronous_1, sendReason: sendReason, useSendBeacon: _isBeaconPayload(sendType), sendType: sendType }); }, !isSynchronous_1);
969
973
  }
970
974
  catch (ex) {
971
- _postManager.diagLog().throwInternal(_1dsCoreJs.LoggingSeverity.WARNING, _1dsCoreJs._ExtendedInternalMessageId.CannotSerializeObject, "Unexpected Exception sending batch: " + _1dsCoreJs.dumpObj(ex));
975
+ _1dsCoreJs._throwInternal(_postManager.diagLog(), 2 , 48 , "Unexpected Exception sending batch: " + _1dsCoreJs.dumpObj(ex));
972
976
  }
973
977
  }
974
978
  function _buildRequestDetails(thePayload, useHeaders) {
@@ -977,8 +981,21 @@
977
981
  hdrs: {},
978
982
  useHdrs: false
979
983
  };
980
- requestDetails.hdrs = _1dsCoreJs.extend(requestDetails.hdrs, _headers);
981
- requestDetails.useHdrs = (_1dsCoreJs.objKeys(requestDetails.hdrs).length > 0);
984
+ if (!useHeaders) {
985
+ _1dsCoreJs.objForEachKey(_headers, function (name, value) {
986
+ if (_collectorHeaderToQs[name]) {
987
+ _addRequestDetails(requestDetails, _collectorHeaderToQs[name], value, false);
988
+ }
989
+ else {
990
+ requestDetails.hdrs[name] = value;
991
+ requestDetails.useHdrs = true;
992
+ }
993
+ });
994
+ }
995
+ else {
996
+ requestDetails.hdrs = _1dsCoreJs.extend(requestDetails.hdrs, _headers);
997
+ requestDetails.useHdrs = (_1dsCoreJs.objKeys(requestDetails.hdrs).length > 0);
998
+ }
982
999
  _addRequestDetails(requestDetails, strClientId, "NO_AUTH", useHeaders);
983
1000
  _addRequestDetails(requestDetails, strClientVersion, _1dsCoreJs.FullVersionString, useHeaders);
984
1001
  var apiQsKeys = "";
@@ -1164,7 +1181,7 @@
1164
1181
  reason = 200 ;
1165
1182
  return;
1166
1183
  }
1167
- if (!RetryPolicy.shouldRetryForStatus(status) || thePayload.numEvents <= 0) {
1184
+ if (!retryPolicyShouldRetryForStatus(status) || thePayload.numEvents <= 0) {
1168
1185
  shouldRetry = false;
1169
1186
  }
1170
1187
  reason = 9000 + (status % 1000);
@@ -1180,7 +1197,7 @@
1180
1197
  _outstandingRequests--;
1181
1198
  }
1182
1199
  _sendBatches(thePayload.batches, retryCount_1 + 1, thePayload.isTeardown, _isUnloading ? 2 : thePayload.sendType, 5 );
1183
- }, _isUnloading, RetryPolicy.getMillisToBackoffForRetry(retryCount_1));
1200
+ }, _isUnloading, retryPolicyGetMillisToBackoffForRetry(retryCount_1));
1184
1201
  }
1185
1202
  else {
1186
1203
  backOffTrans = true;
@@ -1236,7 +1253,7 @@
1236
1253
  cb();
1237
1254
  }
1238
1255
  else {
1239
- _postManager._setTimeoutOverride(cb, interval);
1256
+ timeoutOverride.set(cb, interval);
1240
1257
  }
1241
1258
  }
1242
1259
  function _convertAllHeadersToMap(headersString) {
@@ -1276,7 +1293,7 @@
1276
1293
  responseHandlers[i](responseText);
1277
1294
  }
1278
1295
  catch (e) {
1279
- _postManager.diagLog().throwInternal(_1dsCoreJs.LoggingSeverity.CRITICAL, _1dsCoreJs._ExtendedInternalMessageId.PostResponseHandler, "Response handler failed: " + e);
1296
+ _1dsCoreJs._throwInternal(_postManager.diagLog(), 1 , 519 , "Response handler failed: " + e);
1280
1297
  }
1281
1298
  }
1282
1299
  if (responseText) {
@@ -1300,7 +1317,7 @@
1300
1317
  theAction_1.call(actions, theBatches, batchReason, isSyncRequest_1, sendType);
1301
1318
  }
1302
1319
  catch (e) {
1303
- _postManager.diagLog().throwInternal(_1dsCoreJs.LoggingSeverity.CRITICAL, _1dsCoreJs._ExtendedInternalMessageId.NotificationException, "send request notification failed: " + e);
1320
+ _1dsCoreJs._throwInternal(_postManager.diagLog(), 1 , 74 , "send request notification failed: " + e);
1304
1321
  }
1305
1322
  }, sendSync || isSyncRequest_1, 0);
1306
1323
  }, function () { return ({ batches: _createDebugBatches(theBatches), reason: batchReason, isSync: isSyncRequest_1, sendSync: sendSync, sendType: sendType }); }, !isSyncRequest_1);
@@ -1328,26 +1345,43 @@
1328
1345
  return HttpManager;
1329
1346
  }());
1330
1347
 
1348
+ function defaultSetTimeout(callback, ms) {
1349
+ var args = [];
1350
+ for (var _i = 2; _i < arguments.length; _i++) {
1351
+ args[_i - 2] = arguments[_i];
1352
+ }
1353
+ return setTimeout(callback, ms, args);
1354
+ }
1355
+ function defaultClearTimeout(timeoutId) {
1356
+ clearTimeout(timeoutId);
1357
+ }
1358
+ function createTimeoutWrapper(argSetTimeout, argClearTimeout) {
1359
+ return {
1360
+ set: argSetTimeout || defaultSetTimeout,
1361
+ clear: argClearTimeout || defaultClearTimeout
1362
+ };
1363
+ }
1364
+
1331
1365
  var FlushCheckTimer = 0.250;
1332
1366
  var MaxNumberEventPerBatch = 500;
1333
1367
  var EventsDroppedAtOneTime = 20;
1334
1368
  var MaxSendAttempts = 6;
1335
1369
  var MaxSyncUnloadSendAttempts = 2;
1336
1370
  var MaxBackoffCount = 4;
1337
- var globalContext = _1dsCoreJs.isWindowObjectAvailable ? window : undefined;
1338
1371
  var MaxConnections = 2;
1339
1372
  var MaxRequestRetriesBeforeBackoff = 1;
1340
1373
  var strEventsDiscarded = "eventsDiscarded";
1341
1374
  var strOverrideInstrumentationKey = "overrideInstrumentationKey";
1342
1375
  var strMaxEventRetryAttempts = "maxEventRetryAttempts";
1343
1376
  var strMaxUnloadEventRetryAttempts = "maxUnloadEventRetryAttempts";
1377
+ var strAddUnloadCb = "addUnloadCb";
1344
1378
  var PostChannel = /** @class */ (function (_super) {
1345
1379
  applicationinsightsShims.__extendsFn(PostChannel, _super);
1346
1380
  function PostChannel() {
1347
1381
  var _this = _super.call(this) || this;
1348
1382
  _this.identifier = "PostChannel";
1349
1383
  _this.priority = 1011;
1350
- _this.version = '3.1.11';
1384
+ _this.version = '3.2.2';
1351
1385
  var _config;
1352
1386
  var _isTeardownCalled = false;
1353
1387
  var _flushCallbackQueue = [];
@@ -1372,20 +1406,13 @@
1372
1406
  var _delayedBatchReason;
1373
1407
  var _optimizeObject = true;
1374
1408
  var _isPageUnloadTriggered = false;
1409
+ var _disableXhrSync = false;
1375
1410
  var _maxEventSendAttempts = MaxSendAttempts;
1376
1411
  var _maxUnloadEventSendAttempts = MaxSyncUnloadSendAttempts;
1412
+ var _evtNamespace;
1413
+ var _timeoutWrapper;
1377
1414
  dynamicProto__default(PostChannel, _this, function (_self, _base) {
1378
- _initializeProfiles();
1379
- _clearQueues();
1380
- _setAutoLimits();
1381
- _httpManager = new HttpManager(MaxNumberEventPerBatch, MaxConnections, MaxRequestRetriesBeforeBackoff, {
1382
- requeue: _requeueEvents,
1383
- send: _sendingEvent,
1384
- sent: _eventsSentEvent,
1385
- drop: _eventsDropped,
1386
- rspFail: _eventsResponseFail,
1387
- oth: _otherEvent
1388
- });
1415
+ _initDefaults();
1389
1416
  _self["_getDbgPlgTargets"] = function () {
1390
1417
  return [_httpManager];
1391
1418
  };
@@ -1393,46 +1420,52 @@
1393
1420
  _1dsCoreJs.doPerf(core, function () { return "PostChannel:initialize"; }, function () {
1394
1421
  var extendedCore = core;
1395
1422
  _base.initialize(coreConfig, core, extensions);
1396
- _self.setInitialized(false);
1397
- var ctx = _self._getTelCtx();
1398
- coreConfig.extensionConfig[_self.identifier] = coreConfig.extensionConfig[_self.identifier] || {};
1399
- _config = ctx.getExtCfg(_self.identifier);
1400
- _self._setTimeoutOverride = _config.setTimeoutOverride ? _config.setTimeoutOverride : setTimeout.bind(globalContext);
1401
- _self._clearTimeoutOverride = _config.clearTimeoutOverride ? _config.clearTimeoutOverride : clearTimeout.bind(globalContext);
1402
- _optimizeObject = !_config.disableOptimizeObj && _1dsCoreJs.isChromium();
1403
- _hookWParam(extendedCore);
1404
- if (_config.eventsLimitInMem > 0) {
1405
- _queueSizeLimit = _config.eventsLimitInMem;
1406
- }
1407
- if (_config.immediateEventLimit > 0) {
1408
- _immediateQueueSizeLimit = _config.immediateEventLimit;
1409
- }
1410
- if (_config.autoFlushEventsLimit > 0) {
1411
- _autoFlushEventsLimit = _config.autoFlushEventsLimit;
1412
- }
1413
- if (_1dsCoreJs.isNumber(_config[strMaxEventRetryAttempts])) {
1414
- _maxEventSendAttempts = _config[strMaxEventRetryAttempts];
1415
- }
1416
- if (_1dsCoreJs.isNumber(_config[strMaxUnloadEventRetryAttempts])) {
1417
- _maxUnloadEventSendAttempts = _config[strMaxUnloadEventRetryAttempts];
1418
- }
1419
- _setAutoLimits();
1420
- if (_config.httpXHROverride && _config.httpXHROverride.sendPOST) {
1421
- _xhrOverride = _config.httpXHROverride;
1422
- }
1423
- if (_1dsCoreJs.isValueAssigned(coreConfig.anonCookieName)) {
1424
- _httpManager.addQueryStringParameter("anoncknm", coreConfig.anonCookieName);
1425
- }
1426
- _httpManager.sendHook = _config.payloadPreprocessor;
1427
- _httpManager.sendListener = _config.payloadListener;
1428
- var endpointUrl = _config.overrideEndpointUrl ? _config.overrideEndpointUrl : coreConfig.endpointUrl;
1429
- _self._notificationManager = coreConfig.extensionConfig.NotificationManager;
1430
- _httpManager.initialize(endpointUrl, _self.core, _self, _xhrOverride, _config);
1431
- var excludePageUnloadEvents = coreConfig.disablePageUnloadEvents || [];
1432
- _1dsCoreJs.addPageUnloadEventListener(_handleUnloadEvents, excludePageUnloadEvents);
1433
- _1dsCoreJs.addPageHideEventListener(_handleUnloadEvents, excludePageUnloadEvents);
1434
- _1dsCoreJs.addPageShowEventListener(_handleShowEvents, coreConfig.disablePageShowEvents);
1435
- _self.setInitialized(true);
1423
+ try {
1424
+ var hasAddUnloadCb = !!core[strAddUnloadCb];
1425
+ _evtNamespace = _1dsCoreJs.mergeEvtNamespace(_1dsCoreJs.createUniqueNamespace(_self.identifier), core.evtNamespace && core.evtNamespace());
1426
+ var ctx = _self._getTelCtx();
1427
+ coreConfig.extensionConfig[_self.identifier] = coreConfig.extensionConfig[_self.identifier] || {};
1428
+ _config = ctx.getExtCfg(_self.identifier);
1429
+ _timeoutWrapper = createTimeoutWrapper(_config.setTimeoutOverride, _config.clearTimeoutOverride);
1430
+ _optimizeObject = !_config.disableOptimizeObj && _1dsCoreJs.isChromium();
1431
+ _hookWParam(extendedCore);
1432
+ if (_config.eventsLimitInMem > 0) {
1433
+ _queueSizeLimit = _config.eventsLimitInMem;
1434
+ }
1435
+ if (_config.immediateEventLimit > 0) {
1436
+ _immediateQueueSizeLimit = _config.immediateEventLimit;
1437
+ }
1438
+ if (_config.autoFlushEventsLimit > 0) {
1439
+ _autoFlushEventsLimit = _config.autoFlushEventsLimit;
1440
+ }
1441
+ _disableXhrSync = _config.disableXhrSync;
1442
+ if (_1dsCoreJs.isNumber(_config[strMaxEventRetryAttempts])) {
1443
+ _maxEventSendAttempts = _config[strMaxEventRetryAttempts];
1444
+ }
1445
+ if (_1dsCoreJs.isNumber(_config[strMaxUnloadEventRetryAttempts])) {
1446
+ _maxUnloadEventSendAttempts = _config[strMaxUnloadEventRetryAttempts];
1447
+ }
1448
+ _setAutoLimits();
1449
+ if (_config.httpXHROverride && _config.httpXHROverride.sendPOST) {
1450
+ _xhrOverride = _config.httpXHROverride;
1451
+ }
1452
+ if (_1dsCoreJs.isValueAssigned(coreConfig.anonCookieName)) {
1453
+ _httpManager.addQueryStringParameter("anoncknm", coreConfig.anonCookieName);
1454
+ }
1455
+ _httpManager.sendHook = _config.payloadPreprocessor;
1456
+ _httpManager.sendListener = _config.payloadListener;
1457
+ var endpointUrl = _config.overrideEndpointUrl ? _config.overrideEndpointUrl : coreConfig.endpointUrl;
1458
+ _self._notificationManager = coreConfig.extensionConfig.NotificationManager;
1459
+ _httpManager.initialize(endpointUrl, _self.core, _self, _xhrOverride, _config);
1460
+ var excludePageUnloadEvents = coreConfig.disablePageUnloadEvents || [];
1461
+ _1dsCoreJs.addPageUnloadEventListener(_handleUnloadEvents, excludePageUnloadEvents, _evtNamespace);
1462
+ _1dsCoreJs.addPageHideEventListener(_handleUnloadEvents, excludePageUnloadEvents, _evtNamespace);
1463
+ _1dsCoreJs.addPageShowEventListener(_handleShowEvents, coreConfig.disablePageShowEvents, _evtNamespace);
1464
+ }
1465
+ catch (e) {
1466
+ _self.setInitialized(false);
1467
+ throw e;
1468
+ }
1436
1469
  }, function () { return ({ coreConfig: coreConfig, core: core, extensions: extensions }); });
1437
1470
  };
1438
1471
  _self.processTelemetry = function (ev, itemCtx) {
@@ -1461,6 +1494,15 @@
1461
1494
  }
1462
1495
  _self.processNext(event, itemCtx);
1463
1496
  };
1497
+ _self._doTeardown = function (unloadCtx, unloadState) {
1498
+ _releaseAllQueues(2 , 2 );
1499
+ _isTeardownCalled = true;
1500
+ _httpManager.teardown();
1501
+ _1dsCoreJs.removePageUnloadEventListener(null, _evtNamespace);
1502
+ _1dsCoreJs.removePageHideEventListener(null, _evtNamespace);
1503
+ _1dsCoreJs.removePageShowEventListener(null, _evtNamespace);
1504
+ _initDefaults();
1505
+ };
1464
1506
  function _hookWParam(extendedCore) {
1465
1507
  var existingGetWParamMethod = extendedCore.getWParam;
1466
1508
  extendedCore.getWParam = function () {
@@ -1488,7 +1530,7 @@
1488
1530
  event.sendAttempt = 0;
1489
1531
  }
1490
1532
  if (!event.latency) {
1491
- event.latency = _1dsCoreJs.EventLatency.Normal;
1533
+ event.latency = 1 ;
1492
1534
  }
1493
1535
  if (event.ext && event.ext["trace"]) {
1494
1536
  delete (event.ext["trace"]);
@@ -1507,7 +1549,7 @@
1507
1549
  }
1508
1550
  if (event.sync) {
1509
1551
  if (_currentBackoffCount || _paused) {
1510
- event.latency = _1dsCoreJs.EventLatency.RealTime;
1552
+ event.latency = 3 ;
1511
1553
  event.sync = false;
1512
1554
  }
1513
1555
  else {
@@ -1523,7 +1565,7 @@
1523
1565
  var evtLatency = event.latency;
1524
1566
  var queueSize = _queueSize;
1525
1567
  var queueLimit = _queueSizeLimit;
1526
- if (evtLatency === _1dsCoreJs.EventLatency.Immediate) {
1568
+ if (evtLatency === 4 ) {
1527
1569
  queueSize = _immediateQueueSize;
1528
1570
  queueLimit = _immediateQueueSizeLimit;
1529
1571
  }
@@ -1532,10 +1574,10 @@
1532
1574
  eventDropped = !_addEventToProperQueue(event, append);
1533
1575
  }
1534
1576
  else {
1535
- var dropLatency = _1dsCoreJs.EventLatency.Normal;
1577
+ var dropLatency = 1 ;
1536
1578
  var dropNumber = EventsDroppedAtOneTime;
1537
- if (evtLatency === _1dsCoreJs.EventLatency.Immediate) {
1538
- dropLatency = _1dsCoreJs.EventLatency.Immediate;
1579
+ if (evtLatency === 4 ) {
1580
+ dropLatency = 4 ;
1539
1581
  dropNumber = 1;
1540
1582
  }
1541
1583
  eventDropped = true;
@@ -1553,7 +1595,7 @@
1553
1595
  _setAutoLimits();
1554
1596
  var doFlush = _queueSize > eventLimit;
1555
1597
  if (!doFlush && _autoFlushBatchLimit > 0) {
1556
- for (var latency = _1dsCoreJs.EventLatency.Normal; !doFlush && latency <= _1dsCoreJs.EventLatency.RealTime; latency++) {
1598
+ for (var latency = 1 ; !doFlush && latency <= 3 ; latency++) {
1557
1599
  var batchQueue = _batchQueues[latency];
1558
1600
  if (batchQueue && batchQueue.batches) {
1559
1601
  _1dsCoreJs.arrForEach(batchQueue.batches, function (theBatch) {
@@ -1566,11 +1608,6 @@
1566
1608
  }
1567
1609
  _performAutoFlush(true, doFlush);
1568
1610
  };
1569
- _self.teardown = function () {
1570
- _releaseAllQueues(2 , 2 );
1571
- _isTeardownCalled = true;
1572
- _httpManager.teardown();
1573
- };
1574
1611
  _self.pause = function () {
1575
1612
  _clearScheduledTimer();
1576
1613
  _paused = true;
@@ -1612,7 +1649,7 @@
1612
1649
  _clearScheduledTimer();
1613
1650
  sendReason = sendReason || 1 ;
1614
1651
  if (async) {
1615
- _queueBatches(_1dsCoreJs.EventLatency.Normal, 0 , sendReason);
1652
+ _queueBatches(1 , 0 , sendReason);
1616
1653
  _resetQueueCounts();
1617
1654
  if (_flushCallbackTimerId == null) {
1618
1655
  _flushCallbackTimerId = _createTimer(function () {
@@ -1624,7 +1661,7 @@
1624
1661
  }
1625
1662
  }
1626
1663
  else {
1627
- _sendEventsForLatencyAndAbove(_1dsCoreJs.EventLatency.Normal, 1 , sendReason);
1664
+ _sendEventsForLatencyAndAbove(1 , 1 , sendReason);
1628
1665
  if (callback !== null && callback !== undefined) {
1629
1666
  callback();
1630
1667
  }
@@ -1659,7 +1696,7 @@
1659
1696
  if (immediateTimeOut >= 0) {
1660
1697
  _immediateTimerId = _createTimer(function () {
1661
1698
  _immediateTimerId = null;
1662
- _sendEventsForLatencyAndAbove(_1dsCoreJs.EventLatency.Immediate, 0 , 1 );
1699
+ _sendEventsForLatencyAndAbove(4 , 0 , 1 );
1663
1700
  _scheduleTimer();
1664
1701
  }, immediateTimeOut);
1665
1702
  }
@@ -1669,7 +1706,7 @@
1669
1706
  if (_hasEvents()) {
1670
1707
  _scheduledTimerId = _createTimer(function () {
1671
1708
  _scheduledTimerId = null;
1672
- _sendEventsForLatencyAndAbove(_timerCount === 0 ? _1dsCoreJs.EventLatency.RealTime : _1dsCoreJs.EventLatency.Normal, 0 , 1 );
1709
+ _sendEventsForLatencyAndAbove(_timerCount === 0 ? 3 : 1 , 0 , 1 );
1673
1710
  _timerCount++;
1674
1711
  _timerCount %= 2;
1675
1712
  _scheduleTimer();
@@ -1694,19 +1731,60 @@
1694
1731
  _scheduleTimer();
1695
1732
  }
1696
1733
  };
1734
+ function _initDefaults() {
1735
+ _config = null;
1736
+ _isTeardownCalled = false;
1737
+ _flushCallbackQueue = [];
1738
+ _flushCallbackTimerId = null;
1739
+ _paused = false;
1740
+ _immediateQueueSize = 0;
1741
+ _immediateQueueSizeLimit = 500;
1742
+ _queueSize = 0;
1743
+ _queueSizeLimit = 10000;
1744
+ _profiles = {};
1745
+ _currentProfile = RT_PROFILE;
1746
+ _scheduledTimerId = null;
1747
+ _immediateTimerId = null;
1748
+ _currentBackoffCount = 0;
1749
+ _timerCount = 0;
1750
+ _xhrOverride = null;
1751
+ _batchQueues = {};
1752
+ _autoFlushEventsLimit = undefined;
1753
+ _autoFlushBatchLimit = 0;
1754
+ _delayedBatchSendLatency = -1;
1755
+ _delayedBatchReason = null;
1756
+ _optimizeObject = true;
1757
+ _isPageUnloadTriggered = false;
1758
+ _disableXhrSync = false;
1759
+ _maxEventSendAttempts = MaxSendAttempts;
1760
+ _maxUnloadEventSendAttempts = MaxSyncUnloadSendAttempts;
1761
+ _evtNamespace = null;
1762
+ _timeoutWrapper = createTimeoutWrapper();
1763
+ _httpManager = new HttpManager(MaxNumberEventPerBatch, MaxConnections, MaxRequestRetriesBeforeBackoff, {
1764
+ requeue: _requeueEvents,
1765
+ send: _sendingEvent,
1766
+ sent: _eventsSentEvent,
1767
+ drop: _eventsDropped,
1768
+ rspFail: _eventsResponseFail,
1769
+ oth: _otherEvent
1770
+ }, _timeoutWrapper);
1771
+ _initializeProfiles();
1772
+ _clearQueues();
1773
+ _setAutoLimits();
1774
+ }
1697
1775
  function _createTimer(theTimerFunc, timeOut) {
1698
1776
  if (timeOut === 0 && _currentBackoffCount) {
1699
1777
  timeOut = 1;
1700
1778
  }
1701
1779
  var timerMultiplier = 1000;
1702
1780
  if (_currentBackoffCount) {
1703
- timerMultiplier = RetryPolicy.getMillisToBackoffForRetry(_currentBackoffCount - 1);
1781
+ timerMultiplier = retryPolicyGetMillisToBackoffForRetry(_currentBackoffCount - 1);
1704
1782
  }
1705
- return _self._setTimeoutOverride(theTimerFunc, timeOut * timerMultiplier);
1783
+ return _timeoutWrapper.set(theTimerFunc, timeOut * timerMultiplier);
1706
1784
  }
1707
1785
  function _clearScheduledTimer() {
1708
1786
  if (_scheduledTimerId !== null) {
1709
- _self._clearTimeoutOverride(_scheduledTimerId);
1787
+ _timeoutWrapper.clear(_scheduledTimerId);
1710
1788
  _scheduledTimerId = null;
1711
1789
  _timerCount = 0;
1712
1790
  }
@@ -1714,27 +1792,27 @@
1714
1792
  function _releaseAllQueues(sendType, sendReason) {
1715
1793
  _clearScheduledTimer();
1716
1794
  if (_flushCallbackTimerId) {
1717
- _self._clearTimeoutOverride(_flushCallbackTimerId);
1795
+ _timeoutWrapper.clear(_flushCallbackTimerId);
1718
1796
  _flushCallbackTimerId = null;
1719
1797
  }
1720
1798
  if (!_paused) {
1721
- _sendEventsForLatencyAndAbove(_1dsCoreJs.EventLatency.Normal, sendType, sendReason);
1799
+ _sendEventsForLatencyAndAbove(1 , sendType, sendReason);
1722
1800
  }
1723
1801
  }
1724
1802
  function _clearQueues() {
1725
- _batchQueues[_1dsCoreJs.EventLatency.Immediate] = {
1803
+ _batchQueues[4 ] = {
1726
1804
  batches: [],
1727
1805
  iKeyMap: {}
1728
1806
  };
1729
- _batchQueues[_1dsCoreJs.EventLatency.RealTime] = {
1807
+ _batchQueues[3 ] = {
1730
1808
  batches: [],
1731
1809
  iKeyMap: {}
1732
1810
  };
1733
- _batchQueues[_1dsCoreJs.EventLatency.CostDeferred] = {
1811
+ _batchQueues[2 ] = {
1734
1812
  batches: [],
1735
1813
  iKeyMap: {}
1736
1814
  };
1737
- _batchQueues[_1dsCoreJs.EventLatency.Normal] = {
1815
+ _batchQueues[1 ] = {
1738
1816
  batches: [],
1739
1817
  iKeyMap: {}
1740
1818
  };
@@ -1742,7 +1820,7 @@
1742
1820
  function _getEventBatch(iKey, latency, create) {
1743
1821
  var batchQueue = _batchQueues[latency];
1744
1822
  if (!batchQueue) {
1745
- latency = _1dsCoreJs.EventLatency.Normal;
1823
+ latency = 1 ;
1746
1824
  batchQueue = _batchQueues[latency];
1747
1825
  }
1748
1826
  var eventBatch = batchQueue.iKeyMap[iKey];
@@ -1770,7 +1848,7 @@
1770
1848
  var latency = event.latency;
1771
1849
  var eventBatch = _getEventBatch(event.iKey, latency, true);
1772
1850
  if (eventBatch.addEvent(event)) {
1773
- if (latency !== _1dsCoreJs.EventLatency.Immediate) {
1851
+ if (latency !== 4 ) {
1774
1852
  _queueSize++;
1775
1853
  if (append && event.sendAttempt === 0) {
1776
1854
  _performAutoFlush(!event.sync, _autoFlushBatchLimit > 0 && eventBatch.count() >= _autoFlushBatchLimit);
@@ -1790,7 +1868,7 @@
1790
1868
  var droppedEvents = eventBatch.split(0, dropNumber);
1791
1869
  var droppedCount = droppedEvents.count();
1792
1870
  if (droppedCount > 0) {
1793
- if (currentLatency === _1dsCoreJs.EventLatency.Immediate) {
1871
+ if (currentLatency === 4 ) {
1794
1872
  _immediateQueueSize -= droppedCount;
1795
1873
  }
1796
1874
  else {
@@ -1812,7 +1890,7 @@
1812
1890
  var batchQueue = _batchQueues[latency];
1813
1891
  if (batchQueue && batchQueue.batches) {
1814
1892
  _1dsCoreJs.arrForEach(batchQueue.batches, function (theBatch) {
1815
- if (latency === _1dsCoreJs.EventLatency.Immediate) {
1893
+ if (latency === 4 ) {
1816
1894
  immediateQueue += theBatch.count();
1817
1895
  }
1818
1896
  else {
@@ -1821,7 +1899,7 @@
1821
1899
  });
1822
1900
  }
1823
1901
  };
1824
- for (var latency = _1dsCoreJs.EventLatency.Normal; latency <= _1dsCoreJs.EventLatency.Immediate; latency++) {
1902
+ for (var latency = 1 ; latency <= 4 ; latency++) {
1825
1903
  _loop_1(latency);
1826
1904
  }
1827
1905
  _queueSize = normalQueue;
@@ -1833,7 +1911,7 @@
1833
1911
  if (!isAsync || _httpManager.canSendRequest()) {
1834
1912
  _1dsCoreJs.doPerf(_self.core, function () { return "PostChannel._queueBatches"; }, function () {
1835
1913
  var droppedEvents = [];
1836
- var latencyToProcess = _1dsCoreJs.EventLatency.Immediate;
1914
+ var latencyToProcess = 4 ;
1837
1915
  while (latencyToProcess >= latency) {
1838
1916
  var batchQueue = _batchQueues[latencyToProcess];
1839
1917
  if (batchQueue && batchQueue.batches && batchQueue.batches.length > 0) {
@@ -1844,7 +1922,7 @@
1844
1922
  else {
1845
1923
  eventsQueued = eventsQueued || (theBatch && theBatch.count() > 0);
1846
1924
  }
1847
- if (latencyToProcess === _1dsCoreJs.EventLatency.Immediate) {
1925
+ if (latencyToProcess === 4 ) {
1848
1926
  _immediateQueueSize -= theBatch.count();
1849
1927
  }
1850
1928
  else {
@@ -1872,7 +1950,7 @@
1872
1950
  return eventsQueued;
1873
1951
  }
1874
1952
  function _flushImpl(callback, sendReason) {
1875
- _sendEventsForLatencyAndAbove(_1dsCoreJs.EventLatency.Normal, 0 , sendReason);
1953
+ _sendEventsForLatencyAndAbove(1 , 0 , sendReason);
1876
1954
  _waitForIdleManager(function () {
1877
1955
  if (callback) {
1878
1956
  callback();
@@ -1921,7 +1999,7 @@
1921
1999
  _1dsCoreJs.arrForEach(theBatch.events(), function (theEvent) {
1922
2000
  if (theEvent) {
1923
2001
  if (theEvent.sync) {
1924
- theEvent.latency = _1dsCoreJs.EventLatency.Immediate;
2002
+ theEvent.latency = 4 ;
1925
2003
  theEvent.sync = false;
1926
2004
  }
1927
2005
  if (theEvent.sendAttempt < maxSendAttempts) {
@@ -1950,7 +2028,7 @@
1950
2028
  notifyFunc.apply(manager, theArgs);
1951
2029
  }
1952
2030
  catch (e) {
1953
- _self.diagLog().throwInternal(_1dsCoreJs.LoggingSeverity.CRITICAL, _1dsCoreJs._ExtendedInternalMessageId.NotificationException, evtName + " notification failed: " + e);
2031
+ _1dsCoreJs._throwInternal(_self.diagLog(), 1 , 74 , evtName + " notification failed: " + e);
1954
2032
  }
1955
2033
  }
1956
2034
  }
@@ -2008,6 +2086,12 @@
2008
2086
  _autoFlushBatchLimit = 0;
2009
2087
  }
2010
2088
  }
2089
+ _1dsCoreJs.objDefineAccessors(_self, "_setTimeoutOverride", function () { return _timeoutWrapper.set; }, function (value) {
2090
+ _timeoutWrapper = createTimeoutWrapper(value, _timeoutWrapper.clear);
2091
+ });
2092
+ _1dsCoreJs.objDefineAccessors(_self, "_clearTimeoutOverride", function () { return _timeoutWrapper.clear; }, function (value) {
2093
+ _timeoutWrapper = createTimeoutWrapper(_timeoutWrapper.set, value);
2094
+ });
2011
2095
  });
2012
2096
  return _this;
2013
2097
  }