@microsoft/1ds-post-js 3.1.10 → 3.2.1

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 (57) hide show
  1. package/README.md +124 -6
  2. package/bundle/{ms.post-3.1.10.gbl.js → ms.post-3.2.1.gbl.js} +1502 -725
  3. package/bundle/ms.post-3.2.1.gbl.js.map +1 -0
  4. package/bundle/ms.post-3.2.1.gbl.min.js +7 -0
  5. package/bundle/ms.post-3.2.1.gbl.min.js.map +1 -0
  6. package/bundle/ms.post-3.2.1.integrity.json +46 -0
  7. package/bundle/{ms.post-3.1.10.js → ms.post-3.2.1.js} +1502 -725
  8. package/bundle/ms.post-3.2.1.js.map +1 -0
  9. package/bundle/ms.post-3.2.1.min.js +7 -0
  10. package/bundle/ms.post-3.2.1.min.js.map +1 -0
  11. package/bundle/ms.post.gbl.js +1501 -724
  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 +1501 -724
  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 +264 -149
  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.d.ts +1 -0
  27. package/dist-esm/src/Constants.js +2 -1
  28. package/dist-esm/src/Constants.js.map +1 -1
  29. package/dist-esm/src/DataModels.d.ts +49 -0
  30. package/dist-esm/src/DataModels.js +1 -1
  31. package/dist-esm/src/EventBatch.js +1 -1
  32. package/dist-esm/src/HttpManager.d.ts +1 -1
  33. package/dist-esm/src/HttpManager.js +102 -58
  34. package/dist-esm/src/HttpManager.js.map +1 -1
  35. package/dist-esm/src/Index.js +1 -1
  36. package/dist-esm/src/KillSwitch.js +1 -1
  37. package/dist-esm/src/PostChannel.d.ts +0 -4
  38. package/dist-esm/src/PostChannel.js +171 -104
  39. package/dist-esm/src/PostChannel.js.map +1 -1
  40. package/dist-esm/src/RetryPolicy.d.ts +20 -25
  41. package/dist-esm/src/RetryPolicy.js +35 -44
  42. package/dist-esm/src/RetryPolicy.js.map +1 -1
  43. package/dist-esm/src/Serializer.js +1 -1
  44. package/dist-esm/src/typings/XDomainRequest.js +1 -1
  45. package/package.json +2 -2
  46. package/src/Constants.ts +1 -0
  47. package/src/DataModels.ts +62 -1
  48. package/src/HttpManager.ts +110 -69
  49. package/src/PostChannel.ts +203 -127
  50. package/src/RetryPolicy.ts +33 -38
  51. package/bundle/ms.post-3.1.10.gbl.js.map +0 -1
  52. package/bundle/ms.post-3.1.10.gbl.min.js +0 -7
  53. package/bundle/ms.post-3.1.10.gbl.min.js.map +0 -1
  54. package/bundle/ms.post-3.1.10.integrity.json +0 -46
  55. package/bundle/ms.post-3.1.10.js.map +0 -1
  56. package/bundle/ms.post-3.1.10.min.js +0 -7
  57. package/bundle/ms.post-3.1.10.min.js.map +0 -1
package/dist/ms.post.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * 1DS JS SDK POST plugin, 3.1.10
2
+ * 1DS JS SDK POST plugin, 3.2.1
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  * (Microsoft Internal Only)
5
5
  */
@@ -38,6 +38,8 @@
38
38
  var strUploadTime = "upload-time";
39
39
  var strApiKey = "apikey";
40
40
  var strMsaDeviceTicket = "AuthMsaDeviceTicket";
41
+ var strAuthXToken = "AuthXToken";
42
+ var strNoResponseBody = "NoResponseBody";
41
43
  var strMsfpc = "msfpc";
42
44
 
43
45
  function _getEventMsfpc(theEvent) {
@@ -349,24 +351,19 @@
349
351
  var RandomizationUpperThreshold = 1.2;
350
352
  var BaseBackoff = 3000;
351
353
  var MaxBackoff = 600000;
352
- var RetryPolicy = /** @class */ (function () {
353
- function RetryPolicy() {
354
- }
355
- RetryPolicy.shouldRetryForStatus = function (httpStatusCode) {
356
- return !((httpStatusCode >= 300 && httpStatusCode < 500 && httpStatusCode != 408 && httpStatusCode != 429)
357
- || (httpStatusCode == 501)
358
- || (httpStatusCode == 505));
359
- };
360
- RetryPolicy.getMillisToBackoffForRetry = function (retriesSoFar) {
361
- var waitDuration = 0;
362
- var minBackoff = BaseBackoff * RandomizationLowerThreshold;
363
- var maxBackoff = BaseBackoff * RandomizationUpperThreshold;
364
- var randomBackoff = Math.floor(Math.random() * (maxBackoff - minBackoff)) + minBackoff;
365
- waitDuration = Math.pow(2, retriesSoFar) * randomBackoff;
366
- return Math.min(waitDuration, MaxBackoff);
367
- };
368
- return RetryPolicy;
369
- }());
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
+ }
370
367
 
371
368
  var SecToMsMultiplier = 1000;
372
369
  var KillSwitch = /** @class */ (function () {
@@ -458,6 +455,8 @@
458
455
  }());
459
456
 
460
457
  var _a;
458
+ var strSendAttempt = "sendAttempt";
459
+ var _noResponseQs = "&" + strNoResponseBody + "=true";
461
460
  var _eventActionMap = (_a = {},
462
461
  _a[1 ] = strRequeue,
463
462
  _a[100 ] = strRequeue,
@@ -467,11 +466,19 @@
467
466
  _a);
468
467
  var _collectorQsHeaders = {};
469
468
  var _collectorHeaderToQs = {};
470
- function _addCollectorHeaderQsMapping(qsName, headerName) {
469
+ function _addCollectorHeaderQsMapping(qsName, headerName, allowQs) {
471
470
  _collectorQsHeaders[qsName] = headerName;
472
- _collectorHeaderToQs[headerName] = qsName;
471
+ if (allowQs !== false) {
472
+ _collectorHeaderToQs[headerName] = qsName;
473
+ }
473
474
  }
474
- _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);
475
482
  function _getResponseText(xhr) {
476
483
  try {
477
484
  return xhr.responseText;
@@ -510,7 +517,7 @@
510
517
  }
511
518
  }
512
519
  var HttpManager = /** @class */ (function () {
513
- function HttpManager(maxEventsPerBatch, maxConnections, maxRetries, actions) {
520
+ function HttpManager(maxEventsPerBatch, maxConnections, maxRequestRetriesBeforeBackoff, actions) {
514
521
  this._responseHandlers = [];
515
522
  var _urlString = "?cors=true&" + strContentTypeHeader.toLowerCase() + "=" + defaultContentType;
516
523
  var _killSwitch = new KillSwitch();
@@ -530,6 +537,8 @@
530
537
  var _cookieMgr;
531
538
  var _isUnloading = false;
532
539
  var _useHeaders = false;
540
+ var _xhrTimeout;
541
+ var _disableXhrSync;
533
542
  dynamicProto__default(HttpManager, this, function (_self) {
534
543
  var _sendCredentials = true;
535
544
  _self.initialize = function (endpointUrl, core, postChannel, httpInterface, channelConfig) {
@@ -538,7 +547,7 @@
538
547
  channelConfig = {};
539
548
  }
540
549
  _urlString = endpointUrl + _urlString;
541
- _useHeaders = !_1dsCoreJs.isUndefined(channelConfig.avoidOptions) ? !channelConfig.avoidOptions : false;
550
+ _useHeaders = !_1dsCoreJs.isUndefined(channelConfig.avoidOptions) ? !channelConfig.avoidOptions : true;
542
551
  _core = core;
543
552
  _cookieMgr = core.getCookieMgr();
544
553
  _enableEventTimings = !_core.config.disableEventTimings;
@@ -549,9 +558,13 @@
549
558
  if (!_1dsCoreJs.isUndefined(channelConfig.enableCompoundKey)) {
550
559
  enableCompoundKey = !!channelConfig.enableCompoundKey;
551
560
  }
561
+ _xhrTimeout = channelConfig.xhrTimeout;
562
+ _disableXhrSync = channelConfig.disableXhrSync;
552
563
  _useBeacons = !_1dsCoreJs.isReactNative();
553
564
  _serializer = new Serializer(_core, valueSanitizer, stringifyObjects, enableCompoundKey);
554
565
  var syncHttpInterface = httpInterface;
566
+ var beaconHttpInterface = channelConfig.alwaysUseXhrOverride ? httpInterface : null;
567
+ var fetchSyncHttpInterface = channelConfig.alwaysUseXhrOverride ? httpInterface : null;
555
568
  if (!httpInterface) {
556
569
  _customHttpInterface = false;
557
570
  var location_1 = _1dsCoreJs.getLocation();
@@ -583,8 +596,8 @@
583
596
  _sendInterfaces = (_a = {},
584
597
  _a[0 ] = httpInterface,
585
598
  _a[1 ] = syncHttpInterface || _getSenderInterface([1 , 2 , 3 ], true),
586
- _a[2 ] = _getSenderInterface([3 , 2 , 1 ], true) || syncHttpInterface,
587
- _a[3 ] = _getSenderInterface([2 , 3 , 1 ], true) || syncHttpInterface,
599
+ _a[2 ] = beaconHttpInterface || _getSenderInterface([3 , 2 ], true) || syncHttpInterface || _getSenderInterface([1 ], true),
600
+ _a[3 ] = fetchSyncHttpInterface || _getSenderInterface([2 , 3 ], true) || syncHttpInterface || _getSenderInterface([1 ], true),
588
601
  _a);
589
602
  };
590
603
  function _getSenderInterface(transports, syncSupport) {
@@ -624,6 +637,9 @@
624
637
  function _xdrSendPost(payload, oncomplete, sync) {
625
638
  var xdr = new XDomainRequest();
626
639
  xdr.open(Method, payload.urlString);
640
+ if (payload.timeout) {
641
+ xdr.timeout = payload.timeout;
642
+ }
627
643
  xdr.onload = function () {
628
644
  var response = _getResponseText(xdr);
629
645
  _doOnComplete(oncomplete, 200, {}, response);
@@ -647,6 +663,7 @@
647
663
  }
648
664
  function _fetchSendPost(payload, oncomplete, sync) {
649
665
  var _a;
666
+ var theUrl = payload.urlString;
650
667
  var ignoreResponse = false;
651
668
  var responseHandled = false;
652
669
  var requestInit = (_a = {
@@ -659,6 +676,7 @@
659
676
  requestInit.keepalive = true;
660
677
  if (payload._sendReason === 2 ) {
661
678
  ignoreResponse = true;
679
+ theUrl += _noResponseQs;
662
680
  }
663
681
  }
664
682
  if (_sendCredentials) {
@@ -667,7 +685,7 @@
667
685
  if (payload.headers && _1dsCoreJs.objKeys(payload.headers).length > 0) {
668
686
  requestInit.headers = payload.headers;
669
687
  }
670
- fetch(payload.urlString, requestInit).then(function (response) {
688
+ fetch(theUrl, requestInit).then(function (response) {
671
689
  var headerMap = {};
672
690
  var responseText = "";
673
691
  if (response.headers) {
@@ -695,8 +713,17 @@
695
713
  responseHandled = true;
696
714
  _doOnComplete(oncomplete, 200, {});
697
715
  }
716
+ if (!responseHandled && payload.timeout > 0) {
717
+ _postManager._setTimeoutOverride(function () {
718
+ if (!responseHandled) {
719
+ responseHandled = true;
720
+ _doOnComplete(oncomplete, 500, {});
721
+ }
722
+ }, payload.timeout);
723
+ }
698
724
  }
699
725
  function _xhrSendPost(payload, oncomplete, sync) {
726
+ var theUrl = payload.urlString;
700
727
  function _appendHeader(theHeaders, xhr, name) {
701
728
  if (!theHeaders[name] && xhr && xhr.getResponseHeader) {
702
729
  var value = xhr.getResponseHeader(name);
@@ -721,45 +748,49 @@
721
748
  function xhrComplete(xhr, responseTxt) {
722
749
  _doOnComplete(oncomplete, xhr.status, _getAllResponseHeaders(xhr), responseTxt);
723
750
  }
724
- var xhRequest = _1dsCoreJs.openXhr(Method, payload.urlString, _sendCredentials, true, sync);
751
+ if (sync && payload.disableXhrSync) {
752
+ sync = false;
753
+ }
754
+ var xhrRequest = _1dsCoreJs.openXhr(Method, theUrl, _sendCredentials, true, sync, payload.timeout);
725
755
  _1dsCoreJs.objForEachKey(payload.headers, function (name, value) {
726
- xhRequest.setRequestHeader(name, value);
756
+ xhrRequest.setRequestHeader(name, value);
727
757
  });
728
- xhRequest.onload = function () {
729
- var response = _getResponseText(xhRequest);
730
- xhrComplete(xhRequest, response);
758
+ xhrRequest.onload = function () {
759
+ var response = _getResponseText(xhrRequest);
760
+ xhrComplete(xhrRequest, response);
731
761
  _handleCollectorResponse(response);
732
762
  };
733
- xhRequest.onerror = function () {
734
- xhrComplete(xhRequest);
763
+ xhrRequest.onerror = function () {
764
+ xhrComplete(xhrRequest);
735
765
  };
736
- xhRequest.ontimeout = function () {
737
- xhrComplete(xhRequest);
766
+ xhrRequest.ontimeout = function () {
767
+ xhrComplete(xhrRequest);
738
768
  };
739
- xhRequest.send(payload.data);
769
+ xhrRequest.send(payload.data);
740
770
  }
741
771
  function _doOnComplete(oncomplete, status, headers, response) {
742
772
  try {
743
773
  oncomplete(status, headers, response);
744
774
  }
745
775
  catch (e) {
746
- _postManager.diagLog().throwInternal(_1dsCoreJs.LoggingSeverity.WARNING, _1dsCoreJs._ExtendedInternalMessageId.SendPostOnCompleteFailure, _1dsCoreJs.dumpObj(e));
776
+ _1dsCoreJs._throwInternal(_postManager.diagLog(), 2 , 518 , _1dsCoreJs.dumpObj(e));
747
777
  }
748
778
  }
749
779
  function _beaconSendPost(payload, oncomplete, sync) {
750
780
  var internalPayloadData = payload;
751
781
  var status = 200;
752
782
  var thePayload = internalPayloadData._thePayload;
783
+ var theUrl = payload.urlString + _noResponseQs;
753
784
  try {
754
785
  var nav_1 = _1dsCoreJs.getNavigator();
755
- if (!nav_1.sendBeacon(payload.urlString, payload.data)) {
786
+ if (!nav_1.sendBeacon(theUrl, payload.data)) {
756
787
  if (thePayload) {
757
788
  var droppedBatches_1 = [];
758
789
  _1dsCoreJs.arrForEach(thePayload.batches, function (theBatch) {
759
790
  if (droppedBatches_1 && theBatch && theBatch.count() > 0) {
760
791
  var theEvents = theBatch.events();
761
792
  for (var lp = 0; lp < theEvents.length; lp++) {
762
- if (!nav_1.sendBeacon(payload.urlString, _serializer.getEventBlob(theEvents[lp]))) {
793
+ if (!nav_1.sendBeacon(theUrl, _serializer.getEventBlob(theEvents[lp]))) {
763
794
  droppedBatches_1.push(theBatch.split(lp));
764
795
  break;
765
796
  }
@@ -777,7 +808,7 @@
777
808
  }
778
809
  }
779
810
  catch (ex) {
780
- _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));
781
812
  status = 0;
782
813
  }
783
814
  finally {
@@ -941,7 +972,7 @@
941
972
  }, function () { return ({ batches: _createDebugBatches(orgBatches_1), retryCount: retryCount, isTeardown: isTeardown, isSynchronous: isSynchronous_1, sendReason: sendReason, useSendBeacon: _isBeaconPayload(sendType), sendType: sendType }); }, !isSynchronous_1);
942
973
  }
943
974
  catch (ex) {
944
- _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));
945
976
  }
946
977
  }
947
978
  function _buildRequestDetails(thePayload, useHeaders) {
@@ -950,8 +981,21 @@
950
981
  hdrs: {},
951
982
  useHdrs: false
952
983
  };
953
- requestDetails.hdrs = _1dsCoreJs.extend(requestDetails.hdrs, _headers);
954
- 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
+ }
955
999
  _addRequestDetails(requestDetails, strClientId, "NO_AUTH", useHeaders);
956
1000
  _addRequestDetails(requestDetails, strClientVersion, _1dsCoreJs.FullVersionString, useHeaders);
957
1001
  var apiQsKeys = "";
@@ -1002,7 +1046,6 @@
1002
1046
  var requestDetails_1 = _buildRequestDetails(thePayload, useHeaders_1);
1003
1047
  useHeaders_1 = useHeaders_1 || requestDetails_1.useHdrs;
1004
1048
  var sendEventStart_1 = _1dsCoreJs.getTime();
1005
- var strSendAttempt_1 = "sendAttempt";
1006
1049
  _1dsCoreJs.doPerf(_core, function () { return "HttpManager:_doPayloadSend"; }, function () {
1007
1050
  for (var batchLp = 0; batchLp < thePayload.batches.length; batchLp++) {
1008
1051
  var theBatch = thePayload.batches[batchLp];
@@ -1015,7 +1058,7 @@
1015
1058
  _setTimingValue(timings, "serializationStart", serializationStart);
1016
1059
  _setTimingValue(timings, "serializationCompleted", serializationCompleted);
1017
1060
  }
1018
- telemetryItem[strSendAttempt_1] > 0 ? telemetryItem[strSendAttempt_1]++ : telemetryItem[strSendAttempt_1] = 1;
1061
+ telemetryItem[strSendAttempt] > 0 ? telemetryItem[strSendAttempt]++ : telemetryItem[strSendAttempt] = 1;
1019
1062
  }
1020
1063
  }
1021
1064
  _sendBatchesNotification(thePayload.batches, (1000 + (sendReason || 0 )), thePayload.sendType, true);
@@ -1024,8 +1067,12 @@
1024
1067
  urlString: requestDetails_1.url,
1025
1068
  headers: requestDetails_1.hdrs,
1026
1069
  _thePayload: thePayload,
1027
- _sendReason: sendReason
1070
+ _sendReason: sendReason,
1071
+ timeout: _xhrTimeout
1028
1072
  };
1073
+ if (!_1dsCoreJs.isUndefined(_disableXhrSync)) {
1074
+ orgPayloadData.disableXhrSync = !!_disableXhrSync;
1075
+ }
1029
1076
  if (useHeaders_1) {
1030
1077
  if (!_hasHeader(orgPayloadData.headers, strCacheControl)) {
1031
1078
  orgPayloadData.headers[strCacheControl] = defaultCacheControl;
@@ -1063,7 +1110,9 @@
1063
1110
  var hookData_1 = {
1064
1111
  data: orgPayloadData.data,
1065
1112
  urlString: orgPayloadData.urlString,
1066
- headers: _1dsCoreJs.extend({}, orgPayloadData.headers)
1113
+ headers: _1dsCoreJs.extend({}, orgPayloadData.headers),
1114
+ timeout: orgPayloadData.timeout,
1115
+ disableXhrSync: orgPayloadData.disableXhrSync
1067
1116
  };
1068
1117
  var senderCalled_1 = false;
1069
1118
  _1dsCoreJs.doPerf(_core, function () { return "HttpManager:_doPayloadSend.sendHook"; }, function () {
@@ -1128,11 +1177,11 @@
1128
1177
  });
1129
1178
  });
1130
1179
  }
1131
- if (status == 200) {
1180
+ if (status == 200 || status == 204) {
1132
1181
  reason = 200 ;
1133
1182
  return;
1134
1183
  }
1135
- if (!RetryPolicy.shouldRetryForStatus(status) || thePayload.numEvents <= 0) {
1184
+ if (!retryPolicyShouldRetryForStatus(status) || thePayload.numEvents <= 0) {
1136
1185
  shouldRetry = false;
1137
1186
  }
1138
1187
  reason = 9000 + (status % 1000);
@@ -1141,17 +1190,20 @@
1141
1190
  reason = 100 ;
1142
1191
  var retryCount_1 = thePayload.retryCnt;
1143
1192
  if (thePayload.sendType === 0 ) {
1144
- if (retryCount_1 < maxRetries) {
1193
+ if (retryCount_1 < maxRequestRetriesBeforeBackoff) {
1145
1194
  isRetrying = true;
1146
1195
  _doAction(function () {
1147
1196
  if (thePayload.sendType === 0 ) {
1148
1197
  _outstandingRequests--;
1149
1198
  }
1150
1199
  _sendBatches(thePayload.batches, retryCount_1 + 1, thePayload.isTeardown, _isUnloading ? 2 : thePayload.sendType, 5 );
1151
- }, _isUnloading, RetryPolicy.getMillisToBackoffForRetry(retryCount_1));
1200
+ }, _isUnloading, retryPolicyGetMillisToBackoffForRetry(retryCount_1));
1152
1201
  }
1153
1202
  else {
1154
1203
  backOffTrans = true;
1204
+ if (_isUnloading) {
1205
+ reason = 8001 ;
1206
+ }
1155
1207
  }
1156
1208
  }
1157
1209
  }
@@ -1241,7 +1293,7 @@
1241
1293
  responseHandlers[i](responseText);
1242
1294
  }
1243
1295
  catch (e) {
1244
- _postManager.diagLog().throwInternal(_1dsCoreJs.LoggingSeverity.CRITICAL, _1dsCoreJs._ExtendedInternalMessageId.PostResponseHandler, "Response handler failed: " + e);
1296
+ _1dsCoreJs._throwInternal(_postManager.diagLog(), 1 , 519 , "Response handler failed: " + e);
1245
1297
  }
1246
1298
  }
1247
1299
  if (responseText) {
@@ -1265,7 +1317,7 @@
1265
1317
  theAction_1.call(actions, theBatches, batchReason, isSyncRequest_1, sendType);
1266
1318
  }
1267
1319
  catch (e) {
1268
- _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);
1269
1321
  }
1270
1322
  }, sendSync || isSyncRequest_1, 0);
1271
1323
  }, function () { return ({ batches: _createDebugBatches(theBatches), reason: batchReason, isSync: isSyncRequest_1, sendSync: sendSync, sendType: sendType }); }, !isSyncRequest_1);
@@ -1297,19 +1349,23 @@
1297
1349
  var MaxNumberEventPerBatch = 500;
1298
1350
  var EventsDroppedAtOneTime = 20;
1299
1351
  var MaxSendAttempts = 6;
1352
+ var MaxSyncUnloadSendAttempts = 2;
1300
1353
  var MaxBackoffCount = 4;
1301
1354
  var globalContext = _1dsCoreJs.isWindowObjectAvailable ? window : undefined;
1302
1355
  var MaxConnections = 2;
1303
- var MaxRetries = 1;
1356
+ var MaxRequestRetriesBeforeBackoff = 1;
1304
1357
  var strEventsDiscarded = "eventsDiscarded";
1305
1358
  var strOverrideInstrumentationKey = "overrideInstrumentationKey";
1359
+ var strMaxEventRetryAttempts = "maxEventRetryAttempts";
1360
+ var strMaxUnloadEventRetryAttempts = "maxUnloadEventRetryAttempts";
1361
+ var strAddUnloadCb = "addUnloadCb";
1306
1362
  var PostChannel = /** @class */ (function (_super) {
1307
1363
  applicationinsightsShims.__extendsFn(PostChannel, _super);
1308
1364
  function PostChannel() {
1309
1365
  var _this = _super.call(this) || this;
1310
1366
  _this.identifier = "PostChannel";
1311
1367
  _this.priority = 1011;
1312
- _this.version = '3.1.10';
1368
+ _this.version = '3.2.1';
1313
1369
  var _config;
1314
1370
  var _isTeardownCalled = false;
1315
1371
  var _flushCallbackQueue = [];
@@ -1334,18 +1390,12 @@
1334
1390
  var _delayedBatchReason;
1335
1391
  var _optimizeObject = true;
1336
1392
  var _isPageUnloadTriggered = false;
1393
+ var _disableXhrSync = false;
1394
+ var _maxEventSendAttempts = MaxSendAttempts;
1395
+ var _maxUnloadEventSendAttempts = MaxSyncUnloadSendAttempts;
1396
+ var _evtNamespace;
1337
1397
  dynamicProto__default(PostChannel, _this, function (_self, _base) {
1338
- _initializeProfiles();
1339
- _clearQueues();
1340
- _setAutoLimits();
1341
- _httpManager = new HttpManager(MaxNumberEventPerBatch, MaxConnections, MaxRetries, {
1342
- requeue: _requeueEvents,
1343
- send: _sendingEvent,
1344
- sent: _eventsSentEvent,
1345
- drop: _eventsDropped,
1346
- rspFail: _eventsResponseFail,
1347
- oth: _otherEvent
1348
- });
1398
+ _initDefaults();
1349
1399
  _self["_getDbgPlgTargets"] = function () {
1350
1400
  return [_httpManager];
1351
1401
  };
@@ -1353,58 +1403,53 @@
1353
1403
  _1dsCoreJs.doPerf(core, function () { return "PostChannel:initialize"; }, function () {
1354
1404
  var extendedCore = core;
1355
1405
  _base.initialize(coreConfig, core, extensions);
1356
- _self.setInitialized(false);
1357
- var ctx = _self._getTelCtx();
1358
- coreConfig.extensionConfig[_self.identifier] = coreConfig.extensionConfig[_self.identifier] || {};
1359
- _config = ctx.getExtCfg(_self.identifier);
1360
- _self._setTimeoutOverride = _config.setTimeoutOverride ? _config.setTimeoutOverride : setTimeout.bind(globalContext);
1361
- _self._clearTimeoutOverride = _config.clearTimeoutOverride ? _config.clearTimeoutOverride : clearTimeout.bind(globalContext);
1362
- _optimizeObject = !_config.disableOptimizeObj && _1dsCoreJs.isChromium();
1363
- var existingGetWParamMethod = extendedCore.getWParam;
1364
- extendedCore.getWParam = function () {
1365
- var wparam = 0;
1366
- if (_config.ignoreMc1Ms0CookieProcessing) {
1367
- wparam = wparam | 2;
1406
+ try {
1407
+ var hasAddUnloadCb = !!core[strAddUnloadCb];
1408
+ _evtNamespace = _1dsCoreJs.mergeEvtNamespace(_1dsCoreJs.createUniqueNamespace(_self.identifier), core.evtNamespace && core.evtNamespace());
1409
+ var ctx = _self._getTelCtx();
1410
+ coreConfig.extensionConfig[_self.identifier] = coreConfig.extensionConfig[_self.identifier] || {};
1411
+ _config = ctx.getExtCfg(_self.identifier);
1412
+ _self._setTimeoutOverride = _config.setTimeoutOverride ? _config.setTimeoutOverride : setTimeout.bind(globalContext);
1413
+ _self._clearTimeoutOverride = _config.clearTimeoutOverride ? _config.clearTimeoutOverride : clearTimeout.bind(globalContext);
1414
+ _optimizeObject = !_config.disableOptimizeObj && _1dsCoreJs.isChromium();
1415
+ _hookWParam(extendedCore);
1416
+ if (_config.eventsLimitInMem > 0) {
1417
+ _queueSizeLimit = _config.eventsLimitInMem;
1368
1418
  }
1369
- return wparam | existingGetWParamMethod();
1370
- };
1371
- if (_config.eventsLimitInMem > 0) {
1372
- _queueSizeLimit = _config.eventsLimitInMem;
1373
- }
1374
- if (_config.immediateEventLimit > 0) {
1375
- _immediateQueueSizeLimit = _config.immediateEventLimit;
1376
- }
1377
- if (_config.autoFlushEventsLimit > 0) {
1378
- _autoFlushEventsLimit = _config.autoFlushEventsLimit;
1379
- }
1380
- _setAutoLimits();
1381
- if (_config.httpXHROverride && _config.httpXHROverride.sendPOST) {
1382
- _xhrOverride = _config.httpXHROverride;
1383
- }
1384
- if (_1dsCoreJs.isValueAssigned(coreConfig.anonCookieName)) {
1385
- _httpManager.addQueryStringParameter("anoncknm", coreConfig.anonCookieName);
1386
- }
1387
- _httpManager.sendHook = _config.payloadPreprocessor;
1388
- _httpManager.sendListener = _config.payloadListener;
1389
- var endpointUrl = _config.overrideEndpointUrl ? _config.overrideEndpointUrl : coreConfig.endpointUrl;
1390
- _self._notificationManager = coreConfig.extensionConfig.NotificationManager;
1391
- _httpManager.initialize(endpointUrl, _self.core, _self, _xhrOverride, _config);
1392
- function _handleUnloadEvents(evt) {
1393
- var theEvt = evt || _1dsCoreJs.getWindow().event;
1394
- if (theEvt.type !== "beforeunload") {
1395
- _isPageUnloadTriggered = true;
1396
- _httpManager.setUnloading(_isPageUnloadTriggered);
1419
+ if (_config.immediateEventLimit > 0) {
1420
+ _immediateQueueSizeLimit = _config.immediateEventLimit;
1397
1421
  }
1398
- _releaseAllQueues(2 , 2 );
1422
+ if (_config.autoFlushEventsLimit > 0) {
1423
+ _autoFlushEventsLimit = _config.autoFlushEventsLimit;
1424
+ }
1425
+ _disableXhrSync = _config.disableXhrSync;
1426
+ if (_1dsCoreJs.isNumber(_config[strMaxEventRetryAttempts])) {
1427
+ _maxEventSendAttempts = _config[strMaxEventRetryAttempts];
1428
+ }
1429
+ if (_1dsCoreJs.isNumber(_config[strMaxUnloadEventRetryAttempts])) {
1430
+ _maxUnloadEventSendAttempts = _config[strMaxUnloadEventRetryAttempts];
1431
+ }
1432
+ _setAutoLimits();
1433
+ if (_config.httpXHROverride && _config.httpXHROverride.sendPOST) {
1434
+ _xhrOverride = _config.httpXHROverride;
1435
+ }
1436
+ if (_1dsCoreJs.isValueAssigned(coreConfig.anonCookieName)) {
1437
+ _httpManager.addQueryStringParameter("anoncknm", coreConfig.anonCookieName);
1438
+ }
1439
+ _httpManager.sendHook = _config.payloadPreprocessor;
1440
+ _httpManager.sendListener = _config.payloadListener;
1441
+ var endpointUrl = _config.overrideEndpointUrl ? _config.overrideEndpointUrl : coreConfig.endpointUrl;
1442
+ _self._notificationManager = coreConfig.extensionConfig.NotificationManager;
1443
+ _httpManager.initialize(endpointUrl, _self.core, _self, _xhrOverride, _config);
1444
+ var excludePageUnloadEvents = coreConfig.disablePageUnloadEvents || [];
1445
+ _1dsCoreJs.addPageUnloadEventListener(_handleUnloadEvents, excludePageUnloadEvents, _evtNamespace);
1446
+ _1dsCoreJs.addPageHideEventListener(_handleUnloadEvents, excludePageUnloadEvents, _evtNamespace);
1447
+ _1dsCoreJs.addPageShowEventListener(_handleShowEvents, coreConfig.disablePageShowEvents, _evtNamespace);
1448
+ }
1449
+ catch (e) {
1450
+ _self.setInitialized(false);
1451
+ throw e;
1399
1452
  }
1400
- var excludePageUnloadEvents = coreConfig.disablePageUnloadEvents || [];
1401
- _1dsCoreJs.addPageUnloadEventListener(_handleUnloadEvents, excludePageUnloadEvents);
1402
- _1dsCoreJs.addPageHideEventListener(_handleUnloadEvents, excludePageUnloadEvents);
1403
- _1dsCoreJs.addPageShowEventListener(function (evt) {
1404
- _isPageUnloadTriggered = false;
1405
- _httpManager.setUnloading(_isPageUnloadTriggered);
1406
- }, coreConfig.disablePageShowEvents);
1407
- _self.setInitialized(true);
1408
1453
  }, function () { return ({ coreConfig: coreConfig, core: core, extensions: extensions }); });
1409
1454
  };
1410
1455
  _self.processTelemetry = function (ev, itemCtx) {
@@ -1433,12 +1478,43 @@
1433
1478
  }
1434
1479
  _self.processNext(event, itemCtx);
1435
1480
  };
1481
+ _self._doTeardown = function (unloadCtx, unloadState) {
1482
+ _releaseAllQueues(2 , 2 );
1483
+ _isTeardownCalled = true;
1484
+ _httpManager.teardown();
1485
+ _1dsCoreJs.removePageUnloadEventListener(null, _evtNamespace);
1486
+ _1dsCoreJs.removePageHideEventListener(null, _evtNamespace);
1487
+ _1dsCoreJs.removePageShowEventListener(null, _evtNamespace);
1488
+ _initDefaults();
1489
+ };
1490
+ function _hookWParam(extendedCore) {
1491
+ var existingGetWParamMethod = extendedCore.getWParam;
1492
+ extendedCore.getWParam = function () {
1493
+ var wparam = 0;
1494
+ if (_config.ignoreMc1Ms0CookieProcessing) {
1495
+ wparam = wparam | 2;
1496
+ }
1497
+ return wparam | existingGetWParamMethod();
1498
+ };
1499
+ }
1500
+ function _handleUnloadEvents(evt) {
1501
+ var theEvt = evt || _1dsCoreJs.getWindow().event;
1502
+ if (theEvt.type !== "beforeunload") {
1503
+ _isPageUnloadTriggered = true;
1504
+ _httpManager.setUnloading(_isPageUnloadTriggered);
1505
+ }
1506
+ _releaseAllQueues(2 , 2 );
1507
+ }
1508
+ function _handleShowEvents(evt) {
1509
+ _isPageUnloadTriggered = false;
1510
+ _httpManager.setUnloading(_isPageUnloadTriggered);
1511
+ }
1436
1512
  function _addEventToQueues(event, append) {
1437
1513
  if (!event.sendAttempt) {
1438
1514
  event.sendAttempt = 0;
1439
1515
  }
1440
1516
  if (!event.latency) {
1441
- event.latency = _1dsCoreJs.EventLatency.Normal;
1517
+ event.latency = 1 ;
1442
1518
  }
1443
1519
  if (event.ext && event.ext["trace"]) {
1444
1520
  delete (event.ext["trace"]);
@@ -1457,7 +1533,7 @@
1457
1533
  }
1458
1534
  if (event.sync) {
1459
1535
  if (_currentBackoffCount || _paused) {
1460
- event.latency = _1dsCoreJs.EventLatency.RealTime;
1536
+ event.latency = 3 ;
1461
1537
  event.sync = false;
1462
1538
  }
1463
1539
  else {
@@ -1473,7 +1549,7 @@
1473
1549
  var evtLatency = event.latency;
1474
1550
  var queueSize = _queueSize;
1475
1551
  var queueLimit = _queueSizeLimit;
1476
- if (evtLatency === _1dsCoreJs.EventLatency.Immediate) {
1552
+ if (evtLatency === 4 ) {
1477
1553
  queueSize = _immediateQueueSize;
1478
1554
  queueLimit = _immediateQueueSizeLimit;
1479
1555
  }
@@ -1482,10 +1558,10 @@
1482
1558
  eventDropped = !_addEventToProperQueue(event, append);
1483
1559
  }
1484
1560
  else {
1485
- var dropLatency = _1dsCoreJs.EventLatency.Normal;
1561
+ var dropLatency = 1 ;
1486
1562
  var dropNumber = EventsDroppedAtOneTime;
1487
- if (evtLatency === _1dsCoreJs.EventLatency.Immediate) {
1488
- dropLatency = _1dsCoreJs.EventLatency.Immediate;
1563
+ if (evtLatency === 4 ) {
1564
+ dropLatency = 4 ;
1489
1565
  dropNumber = 1;
1490
1566
  }
1491
1567
  eventDropped = true;
@@ -1503,7 +1579,7 @@
1503
1579
  _setAutoLimits();
1504
1580
  var doFlush = _queueSize > eventLimit;
1505
1581
  if (!doFlush && _autoFlushBatchLimit > 0) {
1506
- for (var latency = _1dsCoreJs.EventLatency.Normal; !doFlush && latency <= _1dsCoreJs.EventLatency.RealTime; latency++) {
1582
+ for (var latency = 1 ; !doFlush && latency <= 3 ; latency++) {
1507
1583
  var batchQueue = _batchQueues[latency];
1508
1584
  if (batchQueue && batchQueue.batches) {
1509
1585
  _1dsCoreJs.arrForEach(batchQueue.batches, function (theBatch) {
@@ -1516,11 +1592,6 @@
1516
1592
  }
1517
1593
  _performAutoFlush(true, doFlush);
1518
1594
  };
1519
- _self.teardown = function () {
1520
- _releaseAllQueues(2 , 2 );
1521
- _isTeardownCalled = true;
1522
- _httpManager.teardown();
1523
- };
1524
1595
  _self.pause = function () {
1525
1596
  _clearScheduledTimer();
1526
1597
  _paused = true;
@@ -1562,7 +1633,7 @@
1562
1633
  _clearScheduledTimer();
1563
1634
  sendReason = sendReason || 1 ;
1564
1635
  if (async) {
1565
- _queueBatches(_1dsCoreJs.EventLatency.Normal, 0 , sendReason);
1636
+ _queueBatches(1 , 0 , sendReason);
1566
1637
  _resetQueueCounts();
1567
1638
  if (_flushCallbackTimerId == null) {
1568
1639
  _flushCallbackTimerId = _createTimer(function () {
@@ -1574,7 +1645,7 @@
1574
1645
  }
1575
1646
  }
1576
1647
  else {
1577
- _sendEventsForLatencyAndAbove(_1dsCoreJs.EventLatency.Normal, 1 , sendReason);
1648
+ _sendEventsForLatencyAndAbove(1 , 1 , sendReason);
1578
1649
  if (callback !== null && callback !== undefined) {
1579
1650
  callback();
1580
1651
  }
@@ -1609,7 +1680,7 @@
1609
1680
  if (immediateTimeOut >= 0) {
1610
1681
  _immediateTimerId = _createTimer(function () {
1611
1682
  _immediateTimerId = null;
1612
- _sendEventsForLatencyAndAbove(_1dsCoreJs.EventLatency.Immediate, 0 , 1 );
1683
+ _sendEventsForLatencyAndAbove(4 , 0 , 1 );
1613
1684
  _scheduleTimer();
1614
1685
  }, immediateTimeOut);
1615
1686
  }
@@ -1619,7 +1690,7 @@
1619
1690
  if (_hasEvents()) {
1620
1691
  _scheduledTimerId = _createTimer(function () {
1621
1692
  _scheduledTimerId = null;
1622
- _sendEventsForLatencyAndAbove(_timerCount === 0 ? _1dsCoreJs.EventLatency.RealTime : _1dsCoreJs.EventLatency.Normal, 0 , 1 );
1693
+ _sendEventsForLatencyAndAbove(_timerCount === 0 ? 3 : 1 , 0 , 1 );
1623
1694
  _timerCount++;
1624
1695
  _timerCount %= 2;
1625
1696
  _scheduleTimer();
@@ -1644,13 +1715,53 @@
1644
1715
  _scheduleTimer();
1645
1716
  }
1646
1717
  };
1718
+ function _initDefaults() {
1719
+ _config = null;
1720
+ _isTeardownCalled = false;
1721
+ _flushCallbackQueue = [];
1722
+ _flushCallbackTimerId = null;
1723
+ _paused = false;
1724
+ _immediateQueueSize = 0;
1725
+ _immediateQueueSizeLimit = 500;
1726
+ _queueSize = 0;
1727
+ _queueSizeLimit = 10000;
1728
+ _profiles = {};
1729
+ _currentProfile = RT_PROFILE;
1730
+ _scheduledTimerId = null;
1731
+ _immediateTimerId = null;
1732
+ _currentBackoffCount = 0;
1733
+ _timerCount = 0;
1734
+ _xhrOverride = null;
1735
+ _batchQueues = {};
1736
+ _autoFlushEventsLimit = undefined;
1737
+ _autoFlushBatchLimit = 0;
1738
+ _delayedBatchSendLatency = -1;
1739
+ _delayedBatchReason = null;
1740
+ _optimizeObject = true;
1741
+ _isPageUnloadTriggered = false;
1742
+ _disableXhrSync = false;
1743
+ _maxEventSendAttempts = MaxSendAttempts;
1744
+ _maxUnloadEventSendAttempts = MaxSyncUnloadSendAttempts;
1745
+ _evtNamespace = null;
1746
+ _httpManager = new HttpManager(MaxNumberEventPerBatch, MaxConnections, MaxRequestRetriesBeforeBackoff, {
1747
+ requeue: _requeueEvents,
1748
+ send: _sendingEvent,
1749
+ sent: _eventsSentEvent,
1750
+ drop: _eventsDropped,
1751
+ rspFail: _eventsResponseFail,
1752
+ oth: _otherEvent
1753
+ });
1754
+ _initializeProfiles();
1755
+ _clearQueues();
1756
+ _setAutoLimits();
1757
+ }
1647
1758
  function _createTimer(theTimerFunc, timeOut) {
1648
1759
  if (timeOut === 0 && _currentBackoffCount) {
1649
1760
  timeOut = 1;
1650
1761
  }
1651
1762
  var timerMultiplier = 1000;
1652
1763
  if (_currentBackoffCount) {
1653
- timerMultiplier = RetryPolicy.getMillisToBackoffForRetry(_currentBackoffCount - 1);
1764
+ timerMultiplier = retryPolicyGetMillisToBackoffForRetry(_currentBackoffCount - 1);
1654
1765
  }
1655
1766
  return _self._setTimeoutOverride(theTimerFunc, timeOut * timerMultiplier);
1656
1767
  }
@@ -1668,23 +1779,23 @@
1668
1779
  _flushCallbackTimerId = null;
1669
1780
  }
1670
1781
  if (!_paused) {
1671
- _sendEventsForLatencyAndAbove(_1dsCoreJs.EventLatency.Normal, sendType, sendReason);
1782
+ _sendEventsForLatencyAndAbove(1 , sendType, sendReason);
1672
1783
  }
1673
1784
  }
1674
1785
  function _clearQueues() {
1675
- _batchQueues[_1dsCoreJs.EventLatency.Immediate] = {
1786
+ _batchQueues[4 ] = {
1676
1787
  batches: [],
1677
1788
  iKeyMap: {}
1678
1789
  };
1679
- _batchQueues[_1dsCoreJs.EventLatency.RealTime] = {
1790
+ _batchQueues[3 ] = {
1680
1791
  batches: [],
1681
1792
  iKeyMap: {}
1682
1793
  };
1683
- _batchQueues[_1dsCoreJs.EventLatency.CostDeferred] = {
1794
+ _batchQueues[2 ] = {
1684
1795
  batches: [],
1685
1796
  iKeyMap: {}
1686
1797
  };
1687
- _batchQueues[_1dsCoreJs.EventLatency.Normal] = {
1798
+ _batchQueues[1 ] = {
1688
1799
  batches: [],
1689
1800
  iKeyMap: {}
1690
1801
  };
@@ -1692,7 +1803,7 @@
1692
1803
  function _getEventBatch(iKey, latency, create) {
1693
1804
  var batchQueue = _batchQueues[latency];
1694
1805
  if (!batchQueue) {
1695
- latency = _1dsCoreJs.EventLatency.Normal;
1806
+ latency = 1 ;
1696
1807
  batchQueue = _batchQueues[latency];
1697
1808
  }
1698
1809
  var eventBatch = batchQueue.iKeyMap[iKey];
@@ -1720,7 +1831,7 @@
1720
1831
  var latency = event.latency;
1721
1832
  var eventBatch = _getEventBatch(event.iKey, latency, true);
1722
1833
  if (eventBatch.addEvent(event)) {
1723
- if (latency !== _1dsCoreJs.EventLatency.Immediate) {
1834
+ if (latency !== 4 ) {
1724
1835
  _queueSize++;
1725
1836
  if (append && event.sendAttempt === 0) {
1726
1837
  _performAutoFlush(!event.sync, _autoFlushBatchLimit > 0 && eventBatch.count() >= _autoFlushBatchLimit);
@@ -1740,7 +1851,7 @@
1740
1851
  var droppedEvents = eventBatch.split(0, dropNumber);
1741
1852
  var droppedCount = droppedEvents.count();
1742
1853
  if (droppedCount > 0) {
1743
- if (currentLatency === _1dsCoreJs.EventLatency.Immediate) {
1854
+ if (currentLatency === 4 ) {
1744
1855
  _immediateQueueSize -= droppedCount;
1745
1856
  }
1746
1857
  else {
@@ -1762,7 +1873,7 @@
1762
1873
  var batchQueue = _batchQueues[latency];
1763
1874
  if (batchQueue && batchQueue.batches) {
1764
1875
  _1dsCoreJs.arrForEach(batchQueue.batches, function (theBatch) {
1765
- if (latency === _1dsCoreJs.EventLatency.Immediate) {
1876
+ if (latency === 4 ) {
1766
1877
  immediateQueue += theBatch.count();
1767
1878
  }
1768
1879
  else {
@@ -1771,7 +1882,7 @@
1771
1882
  });
1772
1883
  }
1773
1884
  };
1774
- for (var latency = _1dsCoreJs.EventLatency.Normal; latency <= _1dsCoreJs.EventLatency.Immediate; latency++) {
1885
+ for (var latency = 1 ; latency <= 4 ; latency++) {
1775
1886
  _loop_1(latency);
1776
1887
  }
1777
1888
  _queueSize = normalQueue;
@@ -1783,7 +1894,7 @@
1783
1894
  if (!isAsync || _httpManager.canSendRequest()) {
1784
1895
  _1dsCoreJs.doPerf(_self.core, function () { return "PostChannel._queueBatches"; }, function () {
1785
1896
  var droppedEvents = [];
1786
- var latencyToProcess = _1dsCoreJs.EventLatency.Immediate;
1897
+ var latencyToProcess = 4 ;
1787
1898
  while (latencyToProcess >= latency) {
1788
1899
  var batchQueue = _batchQueues[latencyToProcess];
1789
1900
  if (batchQueue && batchQueue.batches && batchQueue.batches.length > 0) {
@@ -1794,7 +1905,7 @@
1794
1905
  else {
1795
1906
  eventsQueued = eventsQueued || (theBatch && theBatch.count() > 0);
1796
1907
  }
1797
- if (latencyToProcess === _1dsCoreJs.EventLatency.Immediate) {
1908
+ if (latencyToProcess === 4 ) {
1798
1909
  _immediateQueueSize -= theBatch.count();
1799
1910
  }
1800
1911
  else {
@@ -1822,7 +1933,7 @@
1822
1933
  return eventsQueued;
1823
1934
  }
1824
1935
  function _flushImpl(callback, sendReason) {
1825
- _sendEventsForLatencyAndAbove(_1dsCoreJs.EventLatency.Normal, 0 , sendReason);
1936
+ _sendEventsForLatencyAndAbove(1 , 0 , sendReason);
1826
1937
  _waitForIdleManager(function () {
1827
1938
  if (callback) {
1828
1939
  callback();
@@ -1862,15 +1973,19 @@
1862
1973
  }
1863
1974
  function _requeueEvents(batches, reason) {
1864
1975
  var droppedEvents = [];
1976
+ var maxSendAttempts = _maxEventSendAttempts;
1977
+ if (_isPageUnloadTriggered) {
1978
+ maxSendAttempts = _maxUnloadEventSendAttempts;
1979
+ }
1865
1980
  _1dsCoreJs.arrForEach(batches, function (theBatch) {
1866
1981
  if (theBatch && theBatch.count() > 0) {
1867
1982
  _1dsCoreJs.arrForEach(theBatch.events(), function (theEvent) {
1868
1983
  if (theEvent) {
1869
1984
  if (theEvent.sync) {
1870
- theEvent.latency = _1dsCoreJs.EventLatency.Immediate;
1985
+ theEvent.latency = 4 ;
1871
1986
  theEvent.sync = false;
1872
1987
  }
1873
- if (theEvent.sendAttempt < MaxSendAttempts) {
1988
+ if (theEvent.sendAttempt < maxSendAttempts) {
1874
1989
  _1dsCoreJs.setProcessTelemetryTimings(theEvent, _self.identifier);
1875
1990
  _addEventToQueues(theEvent, false);
1876
1991
  }
@@ -1896,7 +2011,7 @@
1896
2011
  notifyFunc.apply(manager, theArgs);
1897
2012
  }
1898
2013
  catch (e) {
1899
- _self.diagLog().throwInternal(_1dsCoreJs.LoggingSeverity.CRITICAL, _1dsCoreJs._ExtendedInternalMessageId.NotificationException, evtName + " notification failed: " + e);
2014
+ _1dsCoreJs._throwInternal(_self.diagLog(), 1 , 74 , evtName + " notification failed: " + e);
1900
2015
  }
1901
2016
  }
1902
2017
  }