@microsoft/1ds-post-js 3.1.9 → 3.2.0

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 (60) hide show
  1. package/README.md +124 -5
  2. package/bundle/{ms.post-3.1.9.gbl.js → ms.post-3.2.0.gbl.js} +1706 -825
  3. package/bundle/ms.post-3.2.0.gbl.js.map +1 -0
  4. package/bundle/ms.post-3.2.0.gbl.min.js +7 -0
  5. package/bundle/ms.post-3.2.0.gbl.min.js.map +1 -0
  6. package/bundle/ms.post-3.2.0.integrity.json +46 -0
  7. package/bundle/{ms.post-3.1.9.js → ms.post-3.2.0.js} +1706 -825
  8. package/bundle/ms.post-3.2.0.js.map +1 -0
  9. package/bundle/ms.post-3.2.0.min.js +7 -0
  10. package/bundle/ms.post-3.2.0.min.js.map +1 -0
  11. package/bundle/ms.post.gbl.js +1705 -824
  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 +1705 -824
  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 +395 -212
  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 +25 -0
  27. package/dist-esm/src/Constants.js +31 -0
  28. package/dist-esm/src/Constants.js.map +1 -0
  29. package/dist-esm/src/DataModels.d.ts +55 -0
  30. package/dist-esm/src/DataModels.js +1 -1
  31. package/dist-esm/src/EventBatch.d.ts +5 -2
  32. package/dist-esm/src/EventBatch.js +35 -15
  33. package/dist-esm/src/EventBatch.js.map +1 -1
  34. package/dist-esm/src/HttpManager.d.ts +2 -2
  35. package/dist-esm/src/HttpManager.js +186 -94
  36. package/dist-esm/src/HttpManager.js.map +1 -1
  37. package/dist-esm/src/Index.js +1 -1
  38. package/dist-esm/src/KillSwitch.js +1 -1
  39. package/dist-esm/src/PostChannel.d.ts +0 -4
  40. package/dist-esm/src/PostChannel.js +175 -107
  41. package/dist-esm/src/PostChannel.js.map +1 -1
  42. package/dist-esm/src/RetryPolicy.d.ts +20 -25
  43. package/dist-esm/src/RetryPolicy.js +35 -44
  44. package/dist-esm/src/RetryPolicy.js.map +1 -1
  45. package/dist-esm/src/Serializer.js +1 -1
  46. package/dist-esm/src/typings/XDomainRequest.js +1 -1
  47. package/package.json +3 -3
  48. package/src/Constants.ts +28 -0
  49. package/src/DataModels.ts +68 -0
  50. package/src/EventBatch.ts +47 -14
  51. package/src/HttpManager.ts +216 -98
  52. package/src/PostChannel.ts +207 -130
  53. package/src/RetryPolicy.ts +33 -38
  54. package/bundle/ms.post-3.1.9.gbl.js.map +0 -1
  55. package/bundle/ms.post-3.1.9.gbl.min.js +0 -7
  56. package/bundle/ms.post-3.1.9.gbl.min.js.map +0 -1
  57. package/bundle/ms.post-3.1.9.integrity.json +0 -46
  58. package/bundle/ms.post-3.1.9.js.map +0 -1
  59. package/bundle/ms.post-3.1.9.min.js +0 -7
  60. package/bundle/ms.post-3.1.9.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.9
2
+ * 1DS JS SDK POST plugin, 3.2.0
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  * (Microsoft Internal Only)
5
5
  */
@@ -17,42 +17,83 @@
17
17
  var NRT_PROFILE = "NEAR_REAL_TIME";
18
18
  var BE_PROFILE = "BEST_EFFORT";
19
19
 
20
+ var Method = "POST";
21
+ var DisabledPropertyName = "Microsoft_ApplicationInsights_BypassAjaxInstrumentation";
22
+ var strDropped = "drop";
23
+ var strSending = "send";
24
+ var strRequeue = "requeue";
25
+ var strResponseFail = "rspFail";
26
+ var strOther = "oth";
27
+ var defaultCacheControl = "no-cache, no-store";
28
+ var defaultContentType = "application/x-json-stream";
29
+ var strCacheControl = "cache-control";
30
+ var strContentTypeHeader = "content-type";
31
+ var strKillTokensHeader = "kill-tokens";
32
+ var strKillDurationHeader = "kill-duration";
33
+ var strKillDurationSecondsHeader = "kill-duration-seconds";
34
+ var strTimeDeltaHeader = "time-delta-millis";
35
+ var strClientVersion = "client-version";
36
+ var strClientId = "client-id";
37
+ var strTimeDeltaToApply = "time-delta-to-apply-millis";
38
+ var strUploadTime = "upload-time";
39
+ var strApiKey = "apikey";
40
+ var strMsaDeviceTicket = "AuthMsaDeviceTicket";
41
+ var strAuthXToken = "AuthXToken";
42
+ var strNoResponseBody = "NoResponseBody";
43
+ var strMsfpc = "msfpc";
44
+
45
+ function _getEventMsfpc(theEvent) {
46
+ var intWeb = ((theEvent.ext || {})["intweb"]);
47
+ if (intWeb && _1dsCoreJs.isValueAssigned(intWeb[strMsfpc])) {
48
+ return intWeb[strMsfpc];
49
+ }
50
+ return null;
51
+ }
52
+ function _getMsfpc(theEvents) {
53
+ var msfpc = null;
54
+ for (var lp = 0; msfpc === null && lp < theEvents.length; lp++) {
55
+ msfpc = _getEventMsfpc(theEvents[lp]);
56
+ }
57
+ return msfpc;
58
+ }
20
59
  var EventBatch = /** @class */ (function () {
21
60
  function EventBatch(iKey, addEvents) {
22
61
  var events = addEvents ? [].concat(addEvents) : [];
23
62
  var _self = this;
63
+ var _msfpc = _getMsfpc(events);
24
64
  _self.iKey = function () {
25
65
  return iKey;
26
66
  };
67
+ _self.Msfpc = function () {
68
+ return _msfpc || "";
69
+ };
27
70
  _self.count = function () {
28
71
  return events.length;
29
72
  };
30
73
  _self.events = function () {
31
74
  return events;
32
75
  };
33
- _self.addEvents = function (theEvents, append) {
34
- if (append === void 0) { append = true; }
35
- if (theEvents && theEvents.length > 0) {
36
- if (append) {
37
- events = events.concat(theEvents);
76
+ _self.addEvent = function (theEvent) {
77
+ if (theEvent) {
78
+ events.push(theEvent);
79
+ if (!_msfpc) {
80
+ _msfpc = _getEventMsfpc(theEvent);
38
81
  }
39
- else {
40
- events = theEvents.concat(events);
41
- }
42
- return theEvents.length;
82
+ return true;
43
83
  }
44
- return 0;
84
+ return false;
45
85
  };
46
86
  _self.split = function (fromEvent, numEvents) {
47
- var newBatch = new EventBatch(iKey);
87
+ var theEvents;
48
88
  if (fromEvent < events.length) {
49
89
  var cnt = events.length - fromEvent;
50
90
  if (!_1dsCoreJs.isNullOrUndefined(numEvents)) {
51
91
  cnt = numEvents < cnt ? numEvents : cnt;
52
92
  }
53
- newBatch.addEvents(events.splice(fromEvent, cnt), true);
93
+ theEvents = events.splice(fromEvent, cnt);
94
+ _msfpc = _getMsfpc(events);
54
95
  }
55
- return newBatch;
96
+ return new EventBatch(iKey, theEvents);
56
97
  };
57
98
  }
58
99
  EventBatch.create = function (iKey, theEvents) {
@@ -310,24 +351,19 @@
310
351
  var RandomizationUpperThreshold = 1.2;
311
352
  var BaseBackoff = 3000;
312
353
  var MaxBackoff = 600000;
313
- var RetryPolicy = /** @class */ (function () {
314
- function RetryPolicy() {
315
- }
316
- RetryPolicy.shouldRetryForStatus = function (httpStatusCode) {
317
- return !((httpStatusCode >= 300 && httpStatusCode < 500 && httpStatusCode != 408 && httpStatusCode != 429)
318
- || (httpStatusCode == 501)
319
- || (httpStatusCode == 505));
320
- };
321
- RetryPolicy.getMillisToBackoffForRetry = function (retriesSoFar) {
322
- var waitDuration = 0;
323
- var minBackoff = BaseBackoff * RandomizationLowerThreshold;
324
- var maxBackoff = BaseBackoff * RandomizationUpperThreshold;
325
- var randomBackoff = Math.floor(Math.random() * (maxBackoff - minBackoff)) + minBackoff;
326
- waitDuration = Math.pow(2, retriesSoFar) * randomBackoff;
327
- return Math.min(waitDuration, MaxBackoff);
328
- };
329
- return RetryPolicy;
330
- }());
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
+ }
331
367
 
332
368
  var SecToMsMultiplier = 1000;
333
369
  var KillSwitch = /** @class */ (function () {
@@ -419,21 +455,8 @@
419
455
  }());
420
456
 
421
457
  var _a;
422
- var Method = "POST";
423
- var DisabledPropertyName = "Microsoft_ApplicationInsights_BypassAjaxInstrumentation";
424
- var strDropped = "drop";
425
- var strSending = "send";
426
- var strRequeue = "requeue";
427
- var strResponseFail = "rspFail";
428
- var strOther = "oth";
429
- var defaultCacheControl = "no-cache, no-store";
430
- var defaultContentType = "application/x-json-stream";
431
- var strCacheControl = "cache-control";
432
- var strContentTypeHeader = "content-type";
433
- var strKillTokensHeader = "kill-tokens";
434
- var strKillDurationHeader = "kill-duration";
435
- var strKillDurationSecondsHeader = "kill-duration-seconds";
436
- var strTimeDeltaHeader = "time-delta-millis";
458
+ var strSendAttempt = "sendAttempt";
459
+ var _noResponseQs = "&" + strNoResponseBody + "=true";
437
460
  var _eventActionMap = (_a = {},
438
461
  _a[1 ] = strRequeue,
439
462
  _a[100 ] = strRequeue,
@@ -441,6 +464,21 @@
441
464
  _a[8004 ] = strDropped,
442
465
  _a[8003 ] = strDropped,
443
466
  _a);
467
+ var _collectorQsHeaders = {};
468
+ var _collectorHeaderToQs = {};
469
+ function _addCollectorHeaderQsMapping(qsName, headerName, allowQs) {
470
+ _collectorQsHeaders[qsName] = headerName;
471
+ if (allowQs !== false) {
472
+ _collectorHeaderToQs[headerName] = qsName;
473
+ }
474
+ }
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);
444
482
  function _getResponseText(xhr) {
445
483
  try {
446
484
  return xhr.responseText;
@@ -467,11 +505,21 @@
467
505
  }
468
506
  return hasHeader;
469
507
  }
508
+ function _addRequestDetails(details, name, value, useHeaders) {
509
+ if (name && value && value.length > 0) {
510
+ if (useHeaders && _collectorQsHeaders[name]) {
511
+ details.hdrs[_collectorQsHeaders[name]] = value;
512
+ details.useHdrs = true;
513
+ }
514
+ else {
515
+ details.url += "&" + name + "=" + value;
516
+ }
517
+ }
518
+ }
470
519
  var HttpManager = /** @class */ (function () {
471
- function HttpManager(maxEventsPerBatch, maxConnections, maxRetries, actions) {
520
+ function HttpManager(maxEventsPerBatch, maxConnections, maxRequestRetriesBeforeBackoff, actions) {
472
521
  this._responseHandlers = [];
473
- var _urlString = "?cors=true&" + strContentTypeHeader.toLowerCase() + "=" + defaultContentType + "&client-id=NO_AUTH&client-version="
474
- + _1dsCoreJs.FullVersionString;
522
+ var _urlString = "?cors=true&" + strContentTypeHeader.toLowerCase() + "=" + defaultContentType;
475
523
  var _killSwitch = new KillSwitch();
476
524
  var _paused = false;
477
525
  var _clockSkewManager = new ClockSkewManager();
@@ -488,6 +536,9 @@
488
536
  var _enableEventTimings = false;
489
537
  var _cookieMgr;
490
538
  var _isUnloading = false;
539
+ var _useHeaders = false;
540
+ var _xhrTimeout;
541
+ var _disableXhrSync;
491
542
  dynamicProto__default(HttpManager, this, function (_self) {
492
543
  var _sendCredentials = true;
493
544
  _self.initialize = function (endpointUrl, core, postChannel, httpInterface, channelConfig) {
@@ -496,6 +547,7 @@
496
547
  channelConfig = {};
497
548
  }
498
549
  _urlString = endpointUrl + _urlString;
550
+ _useHeaders = !_1dsCoreJs.isUndefined(channelConfig.avoidOptions) ? !channelConfig.avoidOptions : true;
499
551
  _core = core;
500
552
  _cookieMgr = core.getCookieMgr();
501
553
  _enableEventTimings = !_core.config.disableEventTimings;
@@ -506,9 +558,13 @@
506
558
  if (!_1dsCoreJs.isUndefined(channelConfig.enableCompoundKey)) {
507
559
  enableCompoundKey = !!channelConfig.enableCompoundKey;
508
560
  }
561
+ _xhrTimeout = channelConfig.xhrTimeout;
562
+ _disableXhrSync = channelConfig.disableXhrSync;
509
563
  _useBeacons = !_1dsCoreJs.isReactNative();
510
564
  _serializer = new Serializer(_core, valueSanitizer, stringifyObjects, enableCompoundKey);
511
565
  var syncHttpInterface = httpInterface;
566
+ var beaconHttpInterface = channelConfig.alwaysUseXhrOverride ? httpInterface : null;
567
+ var fetchSyncHttpInterface = channelConfig.alwaysUseXhrOverride ? httpInterface : null;
512
568
  if (!httpInterface) {
513
569
  _customHttpInterface = false;
514
570
  var location_1 = _1dsCoreJs.getLocation();
@@ -540,8 +596,8 @@
540
596
  _sendInterfaces = (_a = {},
541
597
  _a[0 ] = httpInterface,
542
598
  _a[1 ] = syncHttpInterface || _getSenderInterface([1 , 2 , 3 ], true),
543
- _a[2 ] = _getSenderInterface([3 , 2 , 1 ], true) || syncHttpInterface,
544
- _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),
545
601
  _a);
546
602
  };
547
603
  function _getSenderInterface(transports, syncSupport) {
@@ -581,6 +637,9 @@
581
637
  function _xdrSendPost(payload, oncomplete, sync) {
582
638
  var xdr = new XDomainRequest();
583
639
  xdr.open(Method, payload.urlString);
640
+ if (payload.timeout) {
641
+ xdr.timeout = payload.timeout;
642
+ }
584
643
  xdr.onload = function () {
585
644
  var response = _getResponseText(xdr);
586
645
  _doOnComplete(oncomplete, 200, {}, response);
@@ -604,6 +663,9 @@
604
663
  }
605
664
  function _fetchSendPost(payload, oncomplete, sync) {
606
665
  var _a;
666
+ var theUrl = payload.urlString;
667
+ var ignoreResponse = false;
668
+ var responseHandled = false;
607
669
  var requestInit = (_a = {
608
670
  body: payload.data,
609
671
  method: Method
@@ -612,6 +674,10 @@
612
674
  _a);
613
675
  if (sync) {
614
676
  requestInit.keepalive = true;
677
+ if (payload._sendReason === 2 ) {
678
+ ignoreResponse = true;
679
+ theUrl += _noResponseQs;
680
+ }
615
681
  }
616
682
  if (_sendCredentials) {
617
683
  requestInit.credentials = "include";
@@ -619,7 +685,7 @@
619
685
  if (payload.headers && _1dsCoreJs.objKeys(payload.headers).length > 0) {
620
686
  requestInit.headers = payload.headers;
621
687
  }
622
- fetch(payload.urlString, requestInit).then(function (response) {
688
+ fetch(theUrl, requestInit).then(function (response) {
623
689
  var headerMap = {};
624
690
  var responseText = "";
625
691
  if (response.headers) {
@@ -632,13 +698,32 @@
632
698
  responseText = text;
633
699
  });
634
700
  }
635
- _doOnComplete(oncomplete, response.status, headerMap, responseText);
636
- _handleCollectorResponse(responseText);
701
+ if (!responseHandled) {
702
+ responseHandled = true;
703
+ _doOnComplete(oncomplete, response.status, headerMap, responseText);
704
+ _handleCollectorResponse(responseText);
705
+ }
637
706
  })["catch"](function (error) {
638
- _doOnComplete(oncomplete, 0, {});
707
+ if (!responseHandled) {
708
+ responseHandled = true;
709
+ _doOnComplete(oncomplete, 0, {});
710
+ }
639
711
  });
712
+ if (ignoreResponse && !responseHandled) {
713
+ responseHandled = true;
714
+ _doOnComplete(oncomplete, 200, {});
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
+ }
640
724
  }
641
725
  function _xhrSendPost(payload, oncomplete, sync) {
726
+ var theUrl = payload.urlString;
642
727
  function _appendHeader(theHeaders, xhr, name) {
643
728
  if (!theHeaders[name] && xhr && xhr.getResponseHeader) {
644
729
  var value = xhr.getResponseHeader(name);
@@ -663,45 +748,49 @@
663
748
  function xhrComplete(xhr, responseTxt) {
664
749
  _doOnComplete(oncomplete, xhr.status, _getAllResponseHeaders(xhr), responseTxt);
665
750
  }
666
- 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);
667
755
  _1dsCoreJs.objForEachKey(payload.headers, function (name, value) {
668
- xhRequest.setRequestHeader(name, value);
756
+ xhrRequest.setRequestHeader(name, value);
669
757
  });
670
- xhRequest.onload = function () {
671
- var response = _getResponseText(xhRequest);
672
- xhrComplete(xhRequest, response);
758
+ xhrRequest.onload = function () {
759
+ var response = _getResponseText(xhrRequest);
760
+ xhrComplete(xhrRequest, response);
673
761
  _handleCollectorResponse(response);
674
762
  };
675
- xhRequest.onerror = function () {
676
- xhrComplete(xhRequest);
763
+ xhrRequest.onerror = function () {
764
+ xhrComplete(xhrRequest);
677
765
  };
678
- xhRequest.ontimeout = function () {
679
- xhrComplete(xhRequest);
766
+ xhrRequest.ontimeout = function () {
767
+ xhrComplete(xhrRequest);
680
768
  };
681
- xhRequest.send(payload.data);
769
+ xhrRequest.send(payload.data);
682
770
  }
683
771
  function _doOnComplete(oncomplete, status, headers, response) {
684
772
  try {
685
773
  oncomplete(status, headers, response);
686
774
  }
687
775
  catch (e) {
688
- _postManager.diagLog().throwInternal(_1dsCoreJs.LoggingSeverity.WARNING, _1dsCoreJs._ExtendedInternalMessageId.SendPostOnCompleteFailure, _1dsCoreJs.dumpObj(e));
776
+ _1dsCoreJs._throwInternal(_postManager.diagLog(), 2 , 518 , _1dsCoreJs.dumpObj(e));
689
777
  }
690
778
  }
691
779
  function _beaconSendPost(payload, oncomplete, sync) {
692
780
  var internalPayloadData = payload;
693
781
  var status = 200;
694
782
  var thePayload = internalPayloadData._thePayload;
783
+ var theUrl = payload.urlString + _noResponseQs;
695
784
  try {
696
785
  var nav_1 = _1dsCoreJs.getNavigator();
697
- if (!nav_1.sendBeacon(payload.urlString, payload.data)) {
786
+ if (!nav_1.sendBeacon(theUrl, payload.data)) {
698
787
  if (thePayload) {
699
788
  var droppedBatches_1 = [];
700
789
  _1dsCoreJs.arrForEach(thePayload.batches, function (theBatch) {
701
790
  if (droppedBatches_1 && theBatch && theBatch.count() > 0) {
702
791
  var theEvents = theBatch.events();
703
792
  for (var lp = 0; lp < theEvents.length; lp++) {
704
- if (!nav_1.sendBeacon(payload.urlString, _serializer.getEventBlob(theEvents[lp]))) {
793
+ if (!nav_1.sendBeacon(theUrl, _serializer.getEventBlob(theEvents[lp]))) {
705
794
  droppedBatches_1.push(theBatch.split(lp));
706
795
  break;
707
796
  }
@@ -719,7 +808,7 @@
719
808
  }
720
809
  }
721
810
  catch (ex) {
722
- _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));
723
812
  status = 0;
724
813
  }
725
814
  finally {
@@ -883,11 +972,32 @@
883
972
  }, function () { return ({ batches: _createDebugBatches(orgBatches_1), retryCount: retryCount, isTeardown: isTeardown, isSynchronous: isSynchronous_1, sendReason: sendReason, useSendBeacon: _isBeaconPayload(sendType), sendType: sendType }); }, !isSynchronous_1);
884
973
  }
885
974
  catch (ex) {
886
- _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));
887
976
  }
888
977
  }
889
- function _buildQueryString(thePayload) {
890
- var urlString = _urlString;
978
+ function _buildRequestDetails(thePayload, useHeaders) {
979
+ var requestDetails = {
980
+ url: _urlString,
981
+ hdrs: {},
982
+ useHdrs: false
983
+ };
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
+ }
999
+ _addRequestDetails(requestDetails, strClientId, "NO_AUTH", useHeaders);
1000
+ _addRequestDetails(requestDetails, strClientVersion, _1dsCoreJs.FullVersionString, useHeaders);
891
1001
  var apiQsKeys = "";
892
1002
  _1dsCoreJs.arrForEach(thePayload.apiKeys, function (apiKey) {
893
1003
  if (apiQsKeys.length > 0) {
@@ -895,27 +1005,25 @@
895
1005
  }
896
1006
  apiQsKeys += apiKey;
897
1007
  });
898
- if (apiQsKeys.length > 0) {
899
- urlString += "&apikey=" + apiQsKeys;
900
- }
901
- urlString += "&upload-time=" + _1dsCoreJs.dateNow().toString();
1008
+ _addRequestDetails(requestDetails, strApiKey, apiQsKeys, useHeaders);
1009
+ _addRequestDetails(requestDetails, strUploadTime, _1dsCoreJs.dateNow().toString(), useHeaders);
902
1010
  var msfpc = _getMsfpc(thePayload);
903
1011
  if (_1dsCoreJs.isValueAssigned(msfpc)) {
904
- urlString = urlString + "&ext.intweb.msfpc=" + msfpc;
1012
+ requestDetails.url += "&ext.intweb.msfpc=" + msfpc;
905
1013
  }
906
1014
  if (_clockSkewManager.shouldAddClockSkewHeaders()) {
907
- urlString += "&time-delta-to-apply-millis=" + _clockSkewManager.getClockSkewHeaderValue();
1015
+ _addRequestDetails(requestDetails, strTimeDeltaToApply, _clockSkewManager.getClockSkewHeaderValue(), useHeaders);
908
1016
  }
909
1017
  if (_core.getWParam) {
910
1018
  var wParam = _core.getWParam();
911
1019
  if (wParam >= 0) {
912
- urlString += "&w=" + wParam;
1020
+ requestDetails.url += "&w=" + wParam;
913
1021
  }
914
1022
  }
915
1023
  for (var i = 0; i < _queryStringParameters.length; i++) {
916
- urlString += "&" + _queryStringParameters[i].name + "=" + _queryStringParameters[i].value;
1024
+ requestDetails.url += "&" + _queryStringParameters[i].name + "=" + _queryStringParameters[i].value;
917
1025
  }
918
- return urlString;
1026
+ return requestDetails;
919
1027
  }
920
1028
  function _canUseSendBeaconApi() {
921
1029
  return !_customHttpInterface && _useBeacons && _1dsCoreJs.isBeaconsSupported();
@@ -926,9 +1034,18 @@
926
1034
  }
927
1035
  function _doPayloadSend(thePayload, serializationStart, serializationCompleted, sendReason) {
928
1036
  if (thePayload && thePayload.payloadBlob && thePayload.payloadBlob.length > 0) {
929
- var urlString_1 = _buildQueryString(thePayload);
1037
+ var useSendHook_1 = !!_self.sendHook;
1038
+ var sendInterface_1 = _sendInterfaces[thePayload.sendType];
1039
+ if (!_isBeaconPayload(thePayload.sendType) && thePayload.isBeacon && thePayload.sendReason === 2 ) {
1040
+ sendInterface_1 = _sendInterfaces[2 ] || _sendInterfaces[3 ] || sendInterface_1;
1041
+ }
1042
+ var useHeaders_1 = _useHeaders;
1043
+ if (thePayload.isBeacon || sendInterface_1._transport === 3 ) {
1044
+ useHeaders_1 = false;
1045
+ }
1046
+ var requestDetails_1 = _buildRequestDetails(thePayload, useHeaders_1);
1047
+ useHeaders_1 = useHeaders_1 || requestDetails_1.useHdrs;
930
1048
  var sendEventStart_1 = _1dsCoreJs.getTime();
931
- var strSendAttempt_1 = "sendAttempt";
932
1049
  _1dsCoreJs.doPerf(_core, function () { return "HttpManager:_doPayloadSend"; }, function () {
933
1050
  for (var batchLp = 0; batchLp < thePayload.batches.length; batchLp++) {
934
1051
  var theBatch = thePayload.batches[batchLp];
@@ -941,30 +1058,31 @@
941
1058
  _setTimingValue(timings, "serializationStart", serializationStart);
942
1059
  _setTimingValue(timings, "serializationCompleted", serializationCompleted);
943
1060
  }
944
- telemetryItem[strSendAttempt_1] > 0 ? telemetryItem[strSendAttempt_1]++ : telemetryItem[strSendAttempt_1] = 1;
1061
+ telemetryItem[strSendAttempt] > 0 ? telemetryItem[strSendAttempt]++ : telemetryItem[strSendAttempt] = 1;
945
1062
  }
946
1063
  }
947
1064
  _sendBatchesNotification(thePayload.batches, (1000 + (sendReason || 0 )), thePayload.sendType, true);
948
1065
  var orgPayloadData = {
949
1066
  data: thePayload.payloadBlob,
950
- urlString: urlString_1,
951
- headers: _1dsCoreJs.extend({}, _headers),
1067
+ urlString: requestDetails_1.url,
1068
+ headers: requestDetails_1.hdrs,
952
1069
  _thePayload: thePayload,
953
- _sendReason: sendReason
1070
+ _sendReason: sendReason,
1071
+ timeout: _xhrTimeout
954
1072
  };
955
- if (!_hasHeader(orgPayloadData.headers, strCacheControl)) {
956
- orgPayloadData.headers[strCacheControl] = defaultCacheControl;
1073
+ if (!_1dsCoreJs.isUndefined(_disableXhrSync)) {
1074
+ orgPayloadData.disableXhrSync = !!_disableXhrSync;
957
1075
  }
958
- if (!_hasHeader(orgPayloadData.headers, strContentTypeHeader)) {
959
- orgPayloadData.headers[strContentTypeHeader] = defaultContentType;
1076
+ if (useHeaders_1) {
1077
+ if (!_hasHeader(orgPayloadData.headers, strCacheControl)) {
1078
+ orgPayloadData.headers[strCacheControl] = defaultCacheControl;
1079
+ }
1080
+ if (!_hasHeader(orgPayloadData.headers, strContentTypeHeader)) {
1081
+ orgPayloadData.headers[strContentTypeHeader] = defaultContentType;
1082
+ }
960
1083
  }
961
1084
  var sender = null;
962
- var useSendHook = !!_self.sendHook;
963
- var sendInterface = _sendInterfaces[thePayload.sendType];
964
- if (!_isBeaconPayload(thePayload.sendType) && thePayload.isBeacon && thePayload.sendReason === 2 ) {
965
- sendInterface = _sendInterfaces[2 ] || _sendInterfaces[3 ] || sendInterface;
966
- }
967
- if (sendInterface) {
1085
+ if (sendInterface_1) {
968
1086
  sender = function (payload) {
969
1087
  _clockSkewManager.firstRequestSent();
970
1088
  var onComplete = function (status, headers) {
@@ -972,7 +1090,7 @@
972
1090
  };
973
1091
  var isSync = thePayload.isTeardown || thePayload.isSync;
974
1092
  try {
975
- sendInterface.sendPOST(payload, onComplete, isSync);
1093
+ sendInterface_1.sendPOST(payload, onComplete, isSync);
976
1094
  if (_self.sendListener) {
977
1095
  _self.sendListener(orgPayloadData, payload, isSync, thePayload.isBeacon);
978
1096
  }
@@ -988,11 +1106,13 @@
988
1106
  if (thePayload.sendType === 0 ) {
989
1107
  _outstandingRequests++;
990
1108
  }
991
- if (useSendHook && !thePayload.isBeacon && sendInterface._transport !== 3 ) {
1109
+ if (useSendHook_1 && !thePayload.isBeacon && sendInterface_1._transport !== 3 ) {
992
1110
  var hookData_1 = {
993
1111
  data: orgPayloadData.data,
994
1112
  urlString: orgPayloadData.urlString,
995
- headers: _1dsCoreJs.extend({}, orgPayloadData.headers)
1113
+ headers: _1dsCoreJs.extend({}, orgPayloadData.headers),
1114
+ timeout: orgPayloadData.timeout,
1115
+ disableXhrSync: orgPayloadData.disableXhrSync
996
1116
  };
997
1117
  var senderCalled_1 = false;
998
1118
  _1dsCoreJs.doPerf(_core, function () { return "HttpManager:_doPayloadSend.sendHook"; }, function () {
@@ -1057,11 +1177,11 @@
1057
1177
  });
1058
1178
  });
1059
1179
  }
1060
- if (status == 200) {
1180
+ if (status == 200 || status == 204) {
1061
1181
  reason = 200 ;
1062
1182
  return;
1063
1183
  }
1064
- if (!RetryPolicy.shouldRetryForStatus(status) || thePayload.numEvents <= 0) {
1184
+ if (!retryPolicyShouldRetryForStatus(status) || thePayload.numEvents <= 0) {
1065
1185
  shouldRetry = false;
1066
1186
  }
1067
1187
  reason = 9000 + (status % 1000);
@@ -1070,17 +1190,20 @@
1070
1190
  reason = 100 ;
1071
1191
  var retryCount_1 = thePayload.retryCnt;
1072
1192
  if (thePayload.sendType === 0 ) {
1073
- if (retryCount_1 < maxRetries) {
1193
+ if (retryCount_1 < maxRequestRetriesBeforeBackoff) {
1074
1194
  isRetrying = true;
1075
1195
  _doAction(function () {
1076
1196
  if (thePayload.sendType === 0 ) {
1077
1197
  _outstandingRequests--;
1078
1198
  }
1079
1199
  _sendBatches(thePayload.batches, retryCount_1 + 1, thePayload.isTeardown, _isUnloading ? 2 : thePayload.sendType, 5 );
1080
- }, _isUnloading, RetryPolicy.getMillisToBackoffForRetry(retryCount_1));
1200
+ }, _isUnloading, retryPolicyGetMillisToBackoffForRetry(retryCount_1));
1081
1201
  }
1082
1202
  else {
1083
1203
  backOffTrans = true;
1204
+ if (_isUnloading) {
1205
+ reason = 8001 ;
1206
+ }
1084
1207
  }
1085
1208
  }
1086
1209
  }
@@ -1155,12 +1278,9 @@
1155
1278
  }
1156
1279
  function _getMsfpc(thePayload) {
1157
1280
  for (var lp = 0; lp < thePayload.batches.length; lp++) {
1158
- var batchEvents = thePayload.batches[lp].events();
1159
- for (var evtLp = 0; evtLp < batchEvents.length; evtLp++) {
1160
- var intWeb = ((batchEvents[evtLp].ext || {})["intweb"] || {});
1161
- if (_1dsCoreJs.isValueAssigned(intWeb["msfpc"])) {
1162
- return encodeURIComponent(intWeb["msfpc"]);
1163
- }
1281
+ var msfpc = thePayload.batches[lp].Msfpc();
1282
+ if (msfpc) {
1283
+ return encodeURIComponent(msfpc);
1164
1284
  }
1165
1285
  }
1166
1286
  return "";
@@ -1173,13 +1293,13 @@
1173
1293
  responseHandlers[i](responseText);
1174
1294
  }
1175
1295
  catch (e) {
1176
- _postManager.diagLog().throwInternal(_1dsCoreJs.LoggingSeverity.CRITICAL, _1dsCoreJs._ExtendedInternalMessageId.PostResponseHandler, "Response handler failed: " + e);
1296
+ _1dsCoreJs._throwInternal(_postManager.diagLog(), 1 , 519 , "Response handler failed: " + e);
1177
1297
  }
1178
1298
  }
1179
1299
  if (responseText) {
1180
1300
  var response = JSON.parse(responseText);
1181
- if (_1dsCoreJs.isValueAssigned(response.webResult) && _1dsCoreJs.isValueAssigned(response.webResult.msfpc)) {
1182
- _cookieMgr.set("MSFPC", response.webResult.msfpc, 365 * 86400);
1301
+ if (_1dsCoreJs.isValueAssigned(response.webResult) && _1dsCoreJs.isValueAssigned(response.webResult[strMsfpc])) {
1302
+ _cookieMgr.set("MSFPC", response.webResult[strMsfpc], 365 * 86400);
1183
1303
  }
1184
1304
  }
1185
1305
  }
@@ -1197,7 +1317,7 @@
1197
1317
  theAction_1.call(actions, theBatches, batchReason, isSyncRequest_1, sendType);
1198
1318
  }
1199
1319
  catch (e) {
1200
- _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);
1201
1321
  }
1202
1322
  }, sendSync || isSyncRequest_1, 0);
1203
1323
  }, function () { return ({ batches: _createDebugBatches(theBatches), reason: batchReason, isSync: isSyncRequest_1, sendSync: sendSync, sendType: sendType }); }, !isSyncRequest_1);
@@ -1229,19 +1349,23 @@
1229
1349
  var MaxNumberEventPerBatch = 500;
1230
1350
  var EventsDroppedAtOneTime = 20;
1231
1351
  var MaxSendAttempts = 6;
1352
+ var MaxSyncUnloadSendAttempts = 2;
1232
1353
  var MaxBackoffCount = 4;
1233
1354
  var globalContext = _1dsCoreJs.isWindowObjectAvailable ? window : undefined;
1234
1355
  var MaxConnections = 2;
1235
- var MaxRetries = 1;
1356
+ var MaxRequestRetriesBeforeBackoff = 1;
1236
1357
  var strEventsDiscarded = "eventsDiscarded";
1237
1358
  var strOverrideInstrumentationKey = "overrideInstrumentationKey";
1359
+ var strMaxEventRetryAttempts = "maxEventRetryAttempts";
1360
+ var strMaxUnloadEventRetryAttempts = "maxUnloadEventRetryAttempts";
1361
+ var strAddUnloadCb = "addUnloadCb";
1238
1362
  var PostChannel = /** @class */ (function (_super) {
1239
1363
  applicationinsightsShims.__extendsFn(PostChannel, _super);
1240
1364
  function PostChannel() {
1241
1365
  var _this = _super.call(this) || this;
1242
1366
  _this.identifier = "PostChannel";
1243
1367
  _this.priority = 1011;
1244
- _this.version = '3.1.9';
1368
+ _this.version = '3.2.0';
1245
1369
  var _config;
1246
1370
  var _isTeardownCalled = false;
1247
1371
  var _flushCallbackQueue = [];
@@ -1266,18 +1390,12 @@
1266
1390
  var _delayedBatchReason;
1267
1391
  var _optimizeObject = true;
1268
1392
  var _isPageUnloadTriggered = false;
1393
+ var _disableXhrSync = false;
1394
+ var _maxEventSendAttempts = MaxSendAttempts;
1395
+ var _maxUnloadEventSendAttempts = MaxSyncUnloadSendAttempts;
1396
+ var _evtNamespace;
1269
1397
  dynamicProto__default(PostChannel, _this, function (_self, _base) {
1270
- _initializeProfiles();
1271
- _clearQueues();
1272
- _setAutoLimits();
1273
- _httpManager = new HttpManager(MaxNumberEventPerBatch, MaxConnections, MaxRetries, {
1274
- requeue: _requeueEvents,
1275
- send: _sendingEvent,
1276
- sent: _eventsSentEvent,
1277
- drop: _eventsDropped,
1278
- rspFail: _eventsResponseFail,
1279
- oth: _otherEvent
1280
- });
1398
+ _initDefaults();
1281
1399
  _self["_getDbgPlgTargets"] = function () {
1282
1400
  return [_httpManager];
1283
1401
  };
@@ -1285,58 +1403,53 @@
1285
1403
  _1dsCoreJs.doPerf(core, function () { return "PostChannel:initialize"; }, function () {
1286
1404
  var extendedCore = core;
1287
1405
  _base.initialize(coreConfig, core, extensions);
1288
- _self.setInitialized(false);
1289
- var ctx = _self._getTelCtx();
1290
- coreConfig.extensionConfig[_self.identifier] = coreConfig.extensionConfig[_self.identifier] || {};
1291
- _config = ctx.getExtCfg(_self.identifier);
1292
- _self._setTimeoutOverride = _config.setTimeoutOverride ? _config.setTimeoutOverride : setTimeout.bind(globalContext);
1293
- _self._clearTimeoutOverride = _config.clearTimeoutOverride ? _config.clearTimeoutOverride : clearTimeout.bind(globalContext);
1294
- _optimizeObject = !_config.disableOptimizeObj && _1dsCoreJs.isChromium();
1295
- var existingGetWParamMethod = extendedCore.getWParam;
1296
- extendedCore.getWParam = function () {
1297
- var wparam = 0;
1298
- if (_config.ignoreMc1Ms0CookieProcessing) {
1299
- 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;
1300
1418
  }
1301
- return wparam | existingGetWParamMethod();
1302
- };
1303
- if (_config.eventsLimitInMem > 0) {
1304
- _queueSizeLimit = _config.eventsLimitInMem;
1305
- }
1306
- if (_config.immediateEventLimit > 0) {
1307
- _immediateQueueSizeLimit = _config.immediateEventLimit;
1308
- }
1309
- if (_config.autoFlushEventsLimit > 0) {
1310
- _autoFlushEventsLimit = _config.autoFlushEventsLimit;
1311
- }
1312
- _setAutoLimits();
1313
- if (_config.httpXHROverride && _config.httpXHROverride.sendPOST) {
1314
- _xhrOverride = _config.httpXHROverride;
1315
- }
1316
- if (_1dsCoreJs.isValueAssigned(coreConfig.anonCookieName)) {
1317
- _httpManager.addQueryStringParameter("anoncknm", coreConfig.anonCookieName);
1318
- }
1319
- _httpManager.sendHook = _config.payloadPreprocessor;
1320
- _httpManager.sendListener = _config.payloadListener;
1321
- var endpointUrl = _config.overrideEndpointUrl ? _config.overrideEndpointUrl : coreConfig.endpointUrl;
1322
- _self._notificationManager = coreConfig.extensionConfig.NotificationManager;
1323
- _httpManager.initialize(endpointUrl, _self.core, _self, _xhrOverride, _config);
1324
- function _handleUnloadEvents(evt) {
1325
- var theEvt = evt || _1dsCoreJs.getWindow().event;
1326
- if (theEvt.type !== "beforeunload") {
1327
- _isPageUnloadTriggered = true;
1328
- _httpManager.setUnloading(_isPageUnloadTriggered);
1419
+ if (_config.immediateEventLimit > 0) {
1420
+ _immediateQueueSizeLimit = _config.immediateEventLimit;
1329
1421
  }
1330
- _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;
1331
1452
  }
1332
- var excludePageUnloadEvents = coreConfig.disablePageUnloadEvents || [];
1333
- _1dsCoreJs.addPageUnloadEventListener(_handleUnloadEvents, excludePageUnloadEvents);
1334
- _1dsCoreJs.addPageHideEventListener(_handleUnloadEvents, excludePageUnloadEvents);
1335
- _1dsCoreJs.addPageShowEventListener(function (evt) {
1336
- _isPageUnloadTriggered = false;
1337
- _httpManager.setUnloading(_isPageUnloadTriggered);
1338
- }, coreConfig.disablePageShowEvents);
1339
- _self.setInitialized(true);
1340
1453
  }, function () { return ({ coreConfig: coreConfig, core: core, extensions: extensions }); });
1341
1454
  };
1342
1455
  _self.processTelemetry = function (ev, itemCtx) {
@@ -1365,12 +1478,43 @@
1365
1478
  }
1366
1479
  _self.processNext(event, itemCtx);
1367
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
+ }
1368
1512
  function _addEventToQueues(event, append) {
1369
1513
  if (!event.sendAttempt) {
1370
1514
  event.sendAttempt = 0;
1371
1515
  }
1372
1516
  if (!event.latency) {
1373
- event.latency = _1dsCoreJs.EventLatency.Normal;
1517
+ event.latency = 1 ;
1374
1518
  }
1375
1519
  if (event.ext && event.ext["trace"]) {
1376
1520
  delete (event.ext["trace"]);
@@ -1389,7 +1533,7 @@
1389
1533
  }
1390
1534
  if (event.sync) {
1391
1535
  if (_currentBackoffCount || _paused) {
1392
- event.latency = _1dsCoreJs.EventLatency.RealTime;
1536
+ event.latency = 3 ;
1393
1537
  event.sync = false;
1394
1538
  }
1395
1539
  else {
@@ -1405,7 +1549,7 @@
1405
1549
  var evtLatency = event.latency;
1406
1550
  var queueSize = _queueSize;
1407
1551
  var queueLimit = _queueSizeLimit;
1408
- if (evtLatency === _1dsCoreJs.EventLatency.Immediate) {
1552
+ if (evtLatency === 4 ) {
1409
1553
  queueSize = _immediateQueueSize;
1410
1554
  queueLimit = _immediateQueueSizeLimit;
1411
1555
  }
@@ -1414,10 +1558,10 @@
1414
1558
  eventDropped = !_addEventToProperQueue(event, append);
1415
1559
  }
1416
1560
  else {
1417
- var dropLatency = _1dsCoreJs.EventLatency.Normal;
1561
+ var dropLatency = 1 ;
1418
1562
  var dropNumber = EventsDroppedAtOneTime;
1419
- if (evtLatency === _1dsCoreJs.EventLatency.Immediate) {
1420
- dropLatency = _1dsCoreJs.EventLatency.Immediate;
1563
+ if (evtLatency === 4 ) {
1564
+ dropLatency = 4 ;
1421
1565
  dropNumber = 1;
1422
1566
  }
1423
1567
  eventDropped = true;
@@ -1435,7 +1579,7 @@
1435
1579
  _setAutoLimits();
1436
1580
  var doFlush = _queueSize > eventLimit;
1437
1581
  if (!doFlush && _autoFlushBatchLimit > 0) {
1438
- for (var latency = _1dsCoreJs.EventLatency.Normal; !doFlush && latency <= _1dsCoreJs.EventLatency.RealTime; latency++) {
1582
+ for (var latency = 1 ; !doFlush && latency <= 3 ; latency++) {
1439
1583
  var batchQueue = _batchQueues[latency];
1440
1584
  if (batchQueue && batchQueue.batches) {
1441
1585
  _1dsCoreJs.arrForEach(batchQueue.batches, function (theBatch) {
@@ -1448,11 +1592,6 @@
1448
1592
  }
1449
1593
  _performAutoFlush(true, doFlush);
1450
1594
  };
1451
- _self.teardown = function () {
1452
- _releaseAllQueues(2 , 2 );
1453
- _isTeardownCalled = true;
1454
- _httpManager.teardown();
1455
- };
1456
1595
  _self.pause = function () {
1457
1596
  _clearScheduledTimer();
1458
1597
  _paused = true;
@@ -1494,7 +1633,7 @@
1494
1633
  _clearScheduledTimer();
1495
1634
  sendReason = sendReason || 1 ;
1496
1635
  if (async) {
1497
- _queueBatches(_1dsCoreJs.EventLatency.Normal, 0 , sendReason);
1636
+ _queueBatches(1 , 0 , sendReason);
1498
1637
  _resetQueueCounts();
1499
1638
  if (_flushCallbackTimerId == null) {
1500
1639
  _flushCallbackTimerId = _createTimer(function () {
@@ -1506,7 +1645,7 @@
1506
1645
  }
1507
1646
  }
1508
1647
  else {
1509
- _sendEventsForLatencyAndAbove(_1dsCoreJs.EventLatency.Normal, 1 , sendReason);
1648
+ _sendEventsForLatencyAndAbove(1 , 1 , sendReason);
1510
1649
  if (callback !== null && callback !== undefined) {
1511
1650
  callback();
1512
1651
  }
@@ -1514,7 +1653,7 @@
1514
1653
  }
1515
1654
  };
1516
1655
  _self.setMsaAuthTicket = function (ticket) {
1517
- _httpManager.addHeader("AuthMsaDeviceTicket", ticket);
1656
+ _httpManager.addHeader(strMsaDeviceTicket, ticket);
1518
1657
  };
1519
1658
  _self.hasEvents = _hasEvents;
1520
1659
  _self._setTransmitProfile = function (profileName) {
@@ -1541,7 +1680,7 @@
1541
1680
  if (immediateTimeOut >= 0) {
1542
1681
  _immediateTimerId = _createTimer(function () {
1543
1682
  _immediateTimerId = null;
1544
- _sendEventsForLatencyAndAbove(_1dsCoreJs.EventLatency.Immediate, 0 , 1 );
1683
+ _sendEventsForLatencyAndAbove(4 , 0 , 1 );
1545
1684
  _scheduleTimer();
1546
1685
  }, immediateTimeOut);
1547
1686
  }
@@ -1551,7 +1690,7 @@
1551
1690
  if (_hasEvents()) {
1552
1691
  _scheduledTimerId = _createTimer(function () {
1553
1692
  _scheduledTimerId = null;
1554
- _sendEventsForLatencyAndAbove(_timerCount === 0 ? _1dsCoreJs.EventLatency.RealTime : _1dsCoreJs.EventLatency.Normal, 0 , 1 );
1693
+ _sendEventsForLatencyAndAbove(_timerCount === 0 ? 3 : 1 , 0 , 1 );
1555
1694
  _timerCount++;
1556
1695
  _timerCount %= 2;
1557
1696
  _scheduleTimer();
@@ -1576,13 +1715,53 @@
1576
1715
  _scheduleTimer();
1577
1716
  }
1578
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
+ }
1579
1758
  function _createTimer(theTimerFunc, timeOut) {
1580
1759
  if (timeOut === 0 && _currentBackoffCount) {
1581
1760
  timeOut = 1;
1582
1761
  }
1583
1762
  var timerMultiplier = 1000;
1584
1763
  if (_currentBackoffCount) {
1585
- timerMultiplier = RetryPolicy.getMillisToBackoffForRetry(_currentBackoffCount - 1);
1764
+ timerMultiplier = retryPolicyGetMillisToBackoffForRetry(_currentBackoffCount - 1);
1586
1765
  }
1587
1766
  return _self._setTimeoutOverride(theTimerFunc, timeOut * timerMultiplier);
1588
1767
  }
@@ -1600,23 +1779,23 @@
1600
1779
  _flushCallbackTimerId = null;
1601
1780
  }
1602
1781
  if (!_paused) {
1603
- _sendEventsForLatencyAndAbove(_1dsCoreJs.EventLatency.Normal, sendType, sendReason);
1782
+ _sendEventsForLatencyAndAbove(1 , sendType, sendReason);
1604
1783
  }
1605
1784
  }
1606
1785
  function _clearQueues() {
1607
- _batchQueues[_1dsCoreJs.EventLatency.Immediate] = {
1786
+ _batchQueues[4 ] = {
1608
1787
  batches: [],
1609
1788
  iKeyMap: {}
1610
1789
  };
1611
- _batchQueues[_1dsCoreJs.EventLatency.RealTime] = {
1790
+ _batchQueues[3 ] = {
1612
1791
  batches: [],
1613
1792
  iKeyMap: {}
1614
1793
  };
1615
- _batchQueues[_1dsCoreJs.EventLatency.CostDeferred] = {
1794
+ _batchQueues[2 ] = {
1616
1795
  batches: [],
1617
1796
  iKeyMap: {}
1618
1797
  };
1619
- _batchQueues[_1dsCoreJs.EventLatency.Normal] = {
1798
+ _batchQueues[1 ] = {
1620
1799
  batches: [],
1621
1800
  iKeyMap: {}
1622
1801
  };
@@ -1624,7 +1803,7 @@
1624
1803
  function _getEventBatch(iKey, latency, create) {
1625
1804
  var batchQueue = _batchQueues[latency];
1626
1805
  if (!batchQueue) {
1627
- latency = _1dsCoreJs.EventLatency.Normal;
1806
+ latency = 1 ;
1628
1807
  batchQueue = _batchQueues[latency];
1629
1808
  }
1630
1809
  var eventBatch = batchQueue.iKeyMap[iKey];
@@ -1651,8 +1830,8 @@
1651
1830
  }
1652
1831
  var latency = event.latency;
1653
1832
  var eventBatch = _getEventBatch(event.iKey, latency, true);
1654
- if (eventBatch.addEvents([event], append)) {
1655
- if (latency !== _1dsCoreJs.EventLatency.Immediate) {
1833
+ if (eventBatch.addEvent(event)) {
1834
+ if (latency !== 4 ) {
1656
1835
  _queueSize++;
1657
1836
  if (append && event.sendAttempt === 0) {
1658
1837
  _performAutoFlush(!event.sync, _autoFlushBatchLimit > 0 && eventBatch.count() >= _autoFlushBatchLimit);
@@ -1672,7 +1851,7 @@
1672
1851
  var droppedEvents = eventBatch.split(0, dropNumber);
1673
1852
  var droppedCount = droppedEvents.count();
1674
1853
  if (droppedCount > 0) {
1675
- if (currentLatency === _1dsCoreJs.EventLatency.Immediate) {
1854
+ if (currentLatency === 4 ) {
1676
1855
  _immediateQueueSize -= droppedCount;
1677
1856
  }
1678
1857
  else {
@@ -1694,7 +1873,7 @@
1694
1873
  var batchQueue = _batchQueues[latency];
1695
1874
  if (batchQueue && batchQueue.batches) {
1696
1875
  _1dsCoreJs.arrForEach(batchQueue.batches, function (theBatch) {
1697
- if (latency === _1dsCoreJs.EventLatency.Immediate) {
1876
+ if (latency === 4 ) {
1698
1877
  immediateQueue += theBatch.count();
1699
1878
  }
1700
1879
  else {
@@ -1703,7 +1882,7 @@
1703
1882
  });
1704
1883
  }
1705
1884
  };
1706
- for (var latency = _1dsCoreJs.EventLatency.Normal; latency <= _1dsCoreJs.EventLatency.Immediate; latency++) {
1885
+ for (var latency = 1 ; latency <= 4 ; latency++) {
1707
1886
  _loop_1(latency);
1708
1887
  }
1709
1888
  _queueSize = normalQueue;
@@ -1715,7 +1894,7 @@
1715
1894
  if (!isAsync || _httpManager.canSendRequest()) {
1716
1895
  _1dsCoreJs.doPerf(_self.core, function () { return "PostChannel._queueBatches"; }, function () {
1717
1896
  var droppedEvents = [];
1718
- var latencyToProcess = _1dsCoreJs.EventLatency.Immediate;
1897
+ var latencyToProcess = 4 ;
1719
1898
  while (latencyToProcess >= latency) {
1720
1899
  var batchQueue = _batchQueues[latencyToProcess];
1721
1900
  if (batchQueue && batchQueue.batches && batchQueue.batches.length > 0) {
@@ -1726,7 +1905,7 @@
1726
1905
  else {
1727
1906
  eventsQueued = eventsQueued || (theBatch && theBatch.count() > 0);
1728
1907
  }
1729
- if (latencyToProcess === _1dsCoreJs.EventLatency.Immediate) {
1908
+ if (latencyToProcess === 4 ) {
1730
1909
  _immediateQueueSize -= theBatch.count();
1731
1910
  }
1732
1911
  else {
@@ -1754,7 +1933,7 @@
1754
1933
  return eventsQueued;
1755
1934
  }
1756
1935
  function _flushImpl(callback, sendReason) {
1757
- _sendEventsForLatencyAndAbove(_1dsCoreJs.EventLatency.Normal, 0 , sendReason);
1936
+ _sendEventsForLatencyAndAbove(1 , 0 , sendReason);
1758
1937
  _waitForIdleManager(function () {
1759
1938
  if (callback) {
1760
1939
  callback();
@@ -1794,15 +1973,19 @@
1794
1973
  }
1795
1974
  function _requeueEvents(batches, reason) {
1796
1975
  var droppedEvents = [];
1976
+ var maxSendAttempts = _maxEventSendAttempts;
1977
+ if (_isPageUnloadTriggered) {
1978
+ maxSendAttempts = _maxUnloadEventSendAttempts;
1979
+ }
1797
1980
  _1dsCoreJs.arrForEach(batches, function (theBatch) {
1798
1981
  if (theBatch && theBatch.count() > 0) {
1799
1982
  _1dsCoreJs.arrForEach(theBatch.events(), function (theEvent) {
1800
1983
  if (theEvent) {
1801
1984
  if (theEvent.sync) {
1802
- theEvent.latency = _1dsCoreJs.EventLatency.Immediate;
1985
+ theEvent.latency = 4 ;
1803
1986
  theEvent.sync = false;
1804
1987
  }
1805
- if (theEvent.sendAttempt < MaxSendAttempts) {
1988
+ if (theEvent.sendAttempt < maxSendAttempts) {
1806
1989
  _1dsCoreJs.setProcessTelemetryTimings(theEvent, _self.identifier);
1807
1990
  _addEventToQueues(theEvent, false);
1808
1991
  }
@@ -1828,7 +2011,7 @@
1828
2011
  notifyFunc.apply(manager, theArgs);
1829
2012
  }
1830
2013
  catch (e) {
1831
- _self.diagLog().throwInternal(_1dsCoreJs.LoggingSeverity.CRITICAL, _1dsCoreJs._ExtendedInternalMessageId.NotificationException, evtName + " notification failed: " + e);
2014
+ _1dsCoreJs._throwInternal(_self.diagLog(), 1 , 74 , evtName + " notification failed: " + e);
1832
2015
  }
1833
2016
  }
1834
2017
  }