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

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 (69) hide show
  1. package/README.md +1 -1
  2. package/bundle/{ms.post-3.2.1.gbl.js → ms.post-3.2.4.gbl.js} +1071 -966
  3. package/bundle/ms.post-3.2.4.gbl.js.map +1 -0
  4. package/bundle/ms.post-3.2.4.gbl.min.js +7 -0
  5. package/bundle/ms.post-3.2.4.gbl.min.js.map +1 -0
  6. package/bundle/ms.post-3.2.4.integrity.json +46 -0
  7. package/bundle/{ms.post-3.2.1.js → ms.post-3.2.4.js} +1071 -966
  8. package/bundle/ms.post-3.2.4.js.map +1 -0
  9. package/bundle/ms.post-3.2.4.min.js +7 -0
  10. package/bundle/ms.post-3.2.4.min.js.map +1 -0
  11. package/bundle/ms.post.gbl.js +1070 -965
  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 +1070 -965
  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 +251 -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 +6 -1
  26. package/dist-esm/src/ClockSkewManager.js.map +1 -1
  27. package/dist-esm/src/DataModels.js +1 -1
  28. package/dist-esm/src/EventBatch.d.ts +0 -5
  29. package/dist-esm/src/EventBatch.js +9 -4
  30. package/dist-esm/src/EventBatch.js.map +1 -1
  31. package/dist-esm/src/HttpManager.d.ts +4 -8
  32. package/dist-esm/src/HttpManager.js +120 -112
  33. package/dist-esm/src/HttpManager.js.map +1 -1
  34. package/dist-esm/src/Index.js +1 -1
  35. package/dist-esm/src/InternalConstants.d.ts +27 -0
  36. package/dist-esm/src/InternalConstants.js +40 -0
  37. package/dist-esm/src/InternalConstants.js.map +1 -0
  38. package/dist-esm/src/KillSwitch.js +7 -2
  39. package/dist-esm/src/KillSwitch.js.map +1 -1
  40. package/dist-esm/src/PostChannel.d.ts +3 -6
  41. package/dist-esm/src/PostChannel.js +97 -73
  42. package/dist-esm/src/PostChannel.js.map +1 -1
  43. package/dist-esm/src/RetryPolicy.js +1 -1
  44. package/dist-esm/src/Serializer.d.ts +1 -1
  45. package/dist-esm/src/Serializer.js +9 -3
  46. package/dist-esm/src/Serializer.js.map +1 -1
  47. package/dist-esm/src/TimeoutOverrideWrapper.d.ts +18 -0
  48. package/dist-esm/src/TimeoutOverrideWrapper.js +28 -0
  49. package/dist-esm/src/TimeoutOverrideWrapper.js.map +1 -0
  50. package/dist-esm/src/typings/XDomainRequest.js +1 -1
  51. package/package.json +5 -3
  52. package/src/EventBatch.ts +4 -4
  53. package/src/HttpManager.ts +74 -71
  54. package/src/InternalConstants.ts +41 -0
  55. package/src/KillSwitch.ts +1 -1
  56. package/src/PostChannel.ts +72 -44
  57. package/src/Serializer.ts +7 -5
  58. package/src/TimeoutOverrideWrapper.ts +29 -0
  59. package/bundle/ms.post-3.2.1.gbl.js.map +0 -1
  60. package/bundle/ms.post-3.2.1.gbl.min.js +0 -7
  61. package/bundle/ms.post-3.2.1.gbl.min.js.map +0 -1
  62. package/bundle/ms.post-3.2.1.integrity.json +0 -46
  63. package/bundle/ms.post-3.2.1.js.map +0 -1
  64. package/bundle/ms.post-3.2.1.min.js +0 -7
  65. package/bundle/ms.post-3.2.1.min.js.map +0 -1
  66. package/dist-esm/src/Constants.d.ts +0 -25
  67. package/dist-esm/src/Constants.js +0 -31
  68. package/dist-esm/src/Constants.js.map +0 -1
  69. package/src/Constants.ts +0 -28
@@ -1,5 +1,5 @@
1
1
  /*
2
- * 1DS JS SDK POST plugin, 3.2.1
2
+ * 1DS JS SDK POST plugin, 3.2.4
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  * (Microsoft Internal Only)
5
5
  */
@@ -9,20 +9,20 @@ import { __extendsFn as __extends } from "@microsoft/applicationinsights-shims";
9
9
  * @author Abhilash Panwar (abpanwar); Hector Hernandez (hectorh); Nev Wylie (newylie)
10
10
  * @copyright Microsoft 2018-2020
11
11
  */
12
- import { BaseTelemetryPlugin, EventsDiscardedReason, isValueAssigned, setProcessTelemetryTimings, isWindowObjectAvailable, arrForEach, doPerf, objForEachKey, optimizeObject, isChromium, getWindow, isNumber, mergeEvtNamespace, createUniqueNamespace, addPageUnloadEventListener, addPageHideEventListener, addPageShowEventListener, removePageUnloadEventListener, removePageHideEventListener, removePageShowEventListener, _throwInternal } from "@microsoft/1ds-core-js";
13
- import { RT_PROFILE, NRT_PROFILE, BE_PROFILE, } from "./DataModels";
12
+ import dynamicProto from "@microsoft/dynamicproto-js";
13
+ import { BaseTelemetryPlugin, EventsDiscardedReason, _throwInternal, addPageHideEventListener, addPageShowEventListener, addPageUnloadEventListener, arrForEach, createUniqueNamespace, doPerf, getWindow, isChromium, isNumber, isValueAssigned, mergeEvtNamespace, objDefineAccessors, objForEachKey, optimizeObject, removePageHideEventListener, removePageShowEventListener, removePageUnloadEventListener, setProcessTelemetryTimings } from "@microsoft/1ds-core-js";
14
+ import { BE_PROFILE, NRT_PROFILE, RT_PROFILE } from "./DataModels";
14
15
  import { EventBatch } from "./EventBatch";
15
16
  import { HttpManager } from "./HttpManager";
17
+ import { STR_MSA_DEVICE_TICKET, STR_TRACE, STR_USER } from "./InternalConstants";
16
18
  import { retryPolicyGetMillisToBackoffForRetry } from "./RetryPolicy";
17
- import dynamicProto from "@microsoft/dynamicproto-js";
18
- import { strMsaDeviceTicket } from "./Constants";
19
+ import { createTimeoutWrapper } from "./TimeoutOverrideWrapper";
19
20
  var FlushCheckTimer = 0.250; // This needs to be in seconds, so this is 250ms
20
21
  var MaxNumberEventPerBatch = 500;
21
22
  var EventsDroppedAtOneTime = 20;
22
23
  var MaxSendAttempts = 6;
23
24
  var MaxSyncUnloadSendAttempts = 2; // Assuming 2 based on beforeunload and unload
24
25
  var MaxBackoffCount = 4;
25
- var globalContext = isWindowObjectAvailable ? window : this;
26
26
  var MaxConnections = 2;
27
27
  var MaxRequestRetriesBeforeBackoff = 1;
28
28
  var strEventsDiscarded = "eventsDiscarded";
@@ -40,7 +40,7 @@ var PostChannel = /** @class */ (function (_super) {
40
40
  var _this = _super.call(this) || this;
41
41
  _this.identifier = "PostChannel";
42
42
  _this.priority = 1011;
43
- _this.version = '3.2.1';
43
+ _this.version = '3.2.4';
44
44
  var _config;
45
45
  var _isTeardownCalled = false;
46
46
  var _flushCallbackQueue = [];
@@ -66,10 +66,10 @@ var PostChannel = /** @class */ (function (_super) {
66
66
  var _delayedBatchReason;
67
67
  var _optimizeObject = true;
68
68
  var _isPageUnloadTriggered = false;
69
- var _disableXhrSync = false;
70
69
  var _maxEventSendAttempts = MaxSendAttempts;
71
70
  var _maxUnloadEventSendAttempts = MaxSyncUnloadSendAttempts;
72
71
  var _evtNamespace;
72
+ var _timeoutWrapper;
73
73
  dynamicProto(PostChannel, _this, function (_self, _base) {
74
74
  _initDefaults();
75
75
  // Special internal method to allow the DebugPlugin to hook embedded objects
@@ -86,8 +86,7 @@ var PostChannel = /** @class */ (function (_super) {
86
86
  var ctx = _self._getTelCtx();
87
87
  coreConfig.extensionConfig[_self.identifier] = coreConfig.extensionConfig[_self.identifier] || {};
88
88
  _config = ctx.getExtCfg(_self.identifier);
89
- _self._setTimeoutOverride = _config.setTimeoutOverride ? _config.setTimeoutOverride : setTimeout.bind(globalContext);
90
- _self._clearTimeoutOverride = _config.clearTimeoutOverride ? _config.clearTimeoutOverride : clearTimeout.bind(globalContext);
89
+ _timeoutWrapper = createTimeoutWrapper(_config.setTimeoutOverride, _config.clearTimeoutOverride);
91
90
  // Only try and use the optimizeObject() if this appears to be a chromium based browser and it has not been explicitly disabled
92
91
  _optimizeObject = !_config.disableOptimizeObj && isChromium();
93
92
  _hookWParam(extendedCore);
@@ -100,7 +99,6 @@ var PostChannel = /** @class */ (function (_super) {
100
99
  if (_config.autoFlushEventsLimit > 0) {
101
100
  _autoFlushEventsLimit = _config.autoFlushEventsLimit;
102
101
  }
103
- _disableXhrSync = _config.disableXhrSync;
104
102
  if (isNumber(_config[strMaxEventRetryAttempts])) {
105
103
  _maxEventSendAttempts = _config[strMaxEventRetryAttempts];
106
104
  }
@@ -157,7 +155,7 @@ var PostChannel = /** @class */ (function (_super) {
157
155
  _addEventToQueues(event, true);
158
156
  if (_isPageUnloadTriggered) {
159
157
  // Unload event has been received so we need to try and flush new events
160
- _releaseAllQueues(2 /* SendBeacon */, 2 /* Unload */);
158
+ _releaseAllQueues(2 /* EventSendType.SendBeacon */, 2 /* SendRequestReason.Unload */);
161
159
  }
162
160
  else {
163
161
  _scheduleTimer();
@@ -166,7 +164,7 @@ var PostChannel = /** @class */ (function (_super) {
166
164
  _self.processNext(event, itemCtx);
167
165
  };
168
166
  _self._doTeardown = function (unloadCtx, unloadState) {
169
- _releaseAllQueues(2 /* SendBeacon */, 2 /* Unload */);
167
+ _releaseAllQueues(2 /* EventSendType.SendBeacon */, 2 /* SendRequestReason.Unload */);
170
168
  _isTeardownCalled = true;
171
169
  _httpManager.teardown();
172
170
  removePageUnloadEventListener(null, _evtNamespace);
@@ -193,7 +191,7 @@ var PostChannel = /** @class */ (function (_super) {
193
191
  _isPageUnloadTriggered = true;
194
192
  _httpManager.setUnloading(_isPageUnloadTriggered);
195
193
  }
196
- _releaseAllQueues(2 /* SendBeacon */, 2 /* Unload */);
194
+ _releaseAllQueues(2 /* EventSendType.SendBeacon */, 2 /* SendRequestReason.Unload */);
197
195
  }
198
196
  function _handleShowEvents(evt) {
199
197
  // Handle the page becoming visible again
@@ -207,17 +205,18 @@ var PostChannel = /** @class */ (function (_super) {
207
205
  }
208
206
  // Add default latency
209
207
  if (!event.latency) {
210
- event.latency = 1 /* Normal */;
208
+ event.latency = 1 /* EventLatencyValue.Normal */;
211
209
  }
212
210
  // Remove extra AI properties if present
213
- if (event.ext && event.ext["trace"]) {
214
- delete (event.ext["trace"]);
211
+ if (event.ext && event.ext[STR_TRACE]) {
212
+ delete (event.ext[STR_TRACE]);
215
213
  }
216
- if (event.ext && event.ext["user"] && event.ext["user"]["id"]) {
217
- delete (event.ext["user"]["id"]);
214
+ if (event.ext && event.ext[STR_USER] && event.ext[STR_USER]["id"]) {
215
+ delete (event.ext[STR_USER]["id"]);
218
216
  }
219
217
  // v8 performance optimization for iterating over the keys
220
218
  if (_optimizeObject) {
219
+ setProcessTelemetryTimings;
221
220
  event.ext = optimizeObject(event.ext);
222
221
  if (event.baseData) {
223
222
  event.baseData = optimizeObject(event.baseData);
@@ -230,7 +229,7 @@ var PostChannel = /** @class */ (function (_super) {
230
229
  // If the transmission is backed off then do not send synchronous events.
231
230
  // We will convert these events to Real time latency instead.
232
231
  if (_currentBackoffCount || _paused) {
233
- event.latency = 3 /* RealTime */;
232
+ event.latency = 3 /* EventLatencyValue.RealTime */;
234
233
  event.sync = false;
235
234
  }
236
235
  else {
@@ -240,7 +239,7 @@ var PostChannel = /** @class */ (function (_super) {
240
239
  if (_optimizeObject) {
241
240
  event = optimizeObject(event);
242
241
  }
243
- _httpManager.sendSynchronousBatch(EventBatch.create(event.iKey, [event]), event.sync === true ? 1 /* Synchronous */ : event.sync, 3 /* SyncEvent */);
242
+ _httpManager.sendSynchronousBatch(EventBatch.create(event.iKey, [event]), event.sync === true ? 1 /* EventSendType.Synchronous */ : event.sync, 3 /* SendRequestReason.SyncEvent */);
244
243
  return;
245
244
  }
246
245
  }
@@ -248,7 +247,7 @@ var PostChannel = /** @class */ (function (_super) {
248
247
  var evtLatency = event.latency;
249
248
  var queueSize = _queueSize;
250
249
  var queueLimit = _queueSizeLimit;
251
- if (evtLatency === 4 /* Immediate */) {
250
+ if (evtLatency === 4 /* EventLatencyValue.Immediate */) {
252
251
  queueSize = _immediateQueueSize;
253
252
  queueLimit = _immediateQueueSizeLimit;
254
253
  }
@@ -258,11 +257,11 @@ var PostChannel = /** @class */ (function (_super) {
258
257
  eventDropped = !_addEventToProperQueue(event, append);
259
258
  }
260
259
  else {
261
- var dropLatency = 1 /* Normal */;
260
+ var dropLatency = 1 /* EventLatencyValue.Normal */;
262
261
  var dropNumber = EventsDroppedAtOneTime;
263
- if (evtLatency === 4 /* Immediate */) {
262
+ if (evtLatency === 4 /* EventLatencyValue.Immediate */) {
264
263
  // Only drop other immediate events as they are not technically sharing the general queue
265
- dropLatency = 4 /* Immediate */;
264
+ dropLatency = 4 /* EventLatencyValue.Immediate */;
266
265
  dropNumber = 1;
267
266
  }
268
267
  // Drop old event from lower or equal latency
@@ -284,7 +283,7 @@ var PostChannel = /** @class */ (function (_super) {
284
283
  var doFlush = _queueSize > eventLimit;
285
284
  if (!doFlush && _autoFlushBatchLimit > 0) {
286
285
  // Check the auto flush max batch size
287
- for (var latency = 1 /* Normal */; !doFlush && latency <= 3 /* RealTime */; latency++) {
286
+ for (var latency = 1 /* EventLatencyValue.Normal */; !doFlush && latency <= 3 /* EventLatencyValue.RealTime */; latency++) {
288
287
  var batchQueue = _batchQueues[latency];
289
288
  if (batchQueue && batchQueue.batches) {
290
289
  arrForEach(batchQueue.batches, function (theBatch) {
@@ -341,16 +340,15 @@ var PostChannel = /** @class */ (function (_super) {
341
340
  _self.flush = function (async, callback, sendReason) {
342
341
  if (async === void 0) { async = true; }
343
342
  if (!_paused) {
344
- // Clear the normal schedule timer as we are going to try and flush ASAP
345
- _clearScheduledTimer();
346
- sendReason = sendReason || 1 /* ManualFlush */;
343
+ sendReason = sendReason || 1 /* SendRequestReason.ManualFlush */;
347
344
  if (async) {
348
- // Move all queued events to the HttpManager
349
- _queueBatches(1 /* Normal */, 0 /* Batched */, sendReason);
350
- // All events (should) have been queue -- lets just make sure the queue counts are correct to avoid queue exhaustion (previous bug #9685112)
351
- _resetQueueCounts();
352
345
  if (_flushCallbackTimerId == null) {
346
+ // Clear the normal schedule timer as we are going to try and flush ASAP
347
+ _clearScheduledTimer();
348
+ // Move all queued events to the HttpManager so that we don't discard new events (Auto flush scenario)
349
+ _queueBatches(1 /* EventLatencyValue.Normal */, 0 /* EventSendType.Batched */, sendReason);
353
350
  _flushCallbackTimerId = _createTimer(function () {
351
+ _flushCallbackTimerId = null;
354
352
  _flushImpl(callback, sendReason);
355
353
  }, 0);
356
354
  }
@@ -361,16 +359,22 @@ var PostChannel = /** @class */ (function (_super) {
361
359
  }
362
360
  }
363
361
  else {
362
+ // Clear the normal schedule timer as we are going to try and flush ASAP
363
+ var cleared = _clearScheduledTimer();
364
364
  // Now cause all queued events to be sent synchronously
365
- _sendEventsForLatencyAndAbove(1 /* Normal */, 1 /* Synchronous */, sendReason);
365
+ _sendEventsForLatencyAndAbove(1 /* EventLatencyValue.Normal */, 1 /* EventSendType.Synchronous */, sendReason);
366
366
  if (callback !== null && callback !== undefined) {
367
367
  callback();
368
368
  }
369
+ if (cleared) {
370
+ // restart the normal event timer if it was cleared
371
+ _scheduleTimer();
372
+ }
369
373
  }
370
374
  }
371
375
  };
372
376
  _self.setMsaAuthTicket = function (ticket) {
373
- _httpManager.addHeader(strMsaDeviceTicket, ticket);
377
+ _httpManager.addHeader(STR_MSA_DEVICE_TICKET, ticket);
374
378
  };
375
379
  _self.hasEvents = _hasEvents;
376
380
  _self._setTransmitProfile = function (profileName) {
@@ -401,8 +405,8 @@ var PostChannel = /** @class */ (function (_super) {
401
405
  function _scheduleTimer() {
402
406
  // If we had previously attempted to send requests, but the http manager didn't have any idle connections then the requests where delayed
403
407
  // so try and requeue then again now
404
- if (_delayedBatchSendLatency >= 0 && _queueBatches(_delayedBatchSendLatency, 0 /* Batched */, _delayedBatchReason)) {
405
- _httpManager.sendQueuedRequests(0 /* Batched */, _delayedBatchReason);
408
+ if (_delayedBatchSendLatency >= 0 && _queueBatches(_delayedBatchSendLatency, 0 /* EventSendType.Batched */, _delayedBatchReason)) {
409
+ _httpManager.sendQueuedRequests(0 /* EventSendType.Batched */, _delayedBatchReason);
406
410
  }
407
411
  if (_immediateQueueSize > 0 && !_immediateTimerId && !_paused) {
408
412
  // During initialization _profiles enforce that the direct [2] is less than real time [1] timer value
@@ -412,7 +416,7 @@ var PostChannel = /** @class */ (function (_super) {
412
416
  _immediateTimerId = _createTimer(function () {
413
417
  _immediateTimerId = null;
414
418
  // Only try to send direct events
415
- _sendEventsForLatencyAndAbove(4 /* Immediate */, 0 /* Batched */, 1 /* NormalSchedule */);
419
+ _sendEventsForLatencyAndAbove(4 /* EventLatencyValue.Immediate */, 0 /* EventSendType.Batched */, 1 /* SendRequestReason.NormalSchedule */);
416
420
  _scheduleTimer();
417
421
  }, immediateTimeOut);
418
422
  }
@@ -423,7 +427,7 @@ var PostChannel = /** @class */ (function (_super) {
423
427
  if (_hasEvents()) {
424
428
  _scheduledTimerId = _createTimer(function () {
425
429
  _scheduledTimerId = null;
426
- _sendEventsForLatencyAndAbove(_timerCount === 0 ? 3 /* RealTime */ : 1 /* Normal */, 0 /* Batched */, 1 /* NormalSchedule */);
430
+ _sendEventsForLatencyAndAbove(_timerCount === 0 ? 3 /* EventLatencyValue.RealTime */ : 1 /* EventLatencyValue.Normal */, 0 /* EventSendType.Batched */, 1 /* SendRequestReason.NormalSchedule */);
427
431
  // Increment the count for next cycle
428
432
  _timerCount++;
429
433
  _timerCount %= 2;
@@ -474,10 +478,10 @@ var PostChannel = /** @class */ (function (_super) {
474
478
  _delayedBatchReason = null;
475
479
  _optimizeObject = true;
476
480
  _isPageUnloadTriggered = false;
477
- _disableXhrSync = false;
478
481
  _maxEventSendAttempts = MaxSendAttempts;
479
482
  _maxUnloadEventSendAttempts = MaxSyncUnloadSendAttempts;
480
483
  _evtNamespace = null;
484
+ _timeoutWrapper = createTimeoutWrapper();
481
485
  _httpManager = new HttpManager(MaxNumberEventPerBatch, MaxConnections, MaxRequestRetriesBeforeBackoff, {
482
486
  requeue: _requeueEvents,
483
487
  send: _sendingEvent,
@@ -485,7 +489,7 @@ var PostChannel = /** @class */ (function (_super) {
485
489
  drop: _eventsDropped,
486
490
  rspFail: _eventsResponseFail,
487
491
  oth: _otherEvent
488
- });
492
+ }, _timeoutWrapper);
489
493
  _initializeProfiles();
490
494
  _clearQueues();
491
495
  _setAutoLimits();
@@ -499,26 +503,28 @@ var PostChannel = /** @class */ (function (_super) {
499
503
  if (_currentBackoffCount) {
500
504
  timerMultiplier = retryPolicyGetMillisToBackoffForRetry(_currentBackoffCount - 1);
501
505
  }
502
- return _self._setTimeoutOverride(theTimerFunc, timeOut * timerMultiplier);
506
+ return _timeoutWrapper.set(theTimerFunc, timeOut * timerMultiplier);
503
507
  }
504
508
  function _clearScheduledTimer() {
505
509
  if (_scheduledTimerId !== null) {
506
- _self._clearTimeoutOverride(_scheduledTimerId);
510
+ _timeoutWrapper.clear(_scheduledTimerId);
507
511
  _scheduledTimerId = null;
508
512
  _timerCount = 0;
513
+ return true;
509
514
  }
515
+ return false;
510
516
  }
511
517
  // Try to send all queued events using beacons if available
512
518
  function _releaseAllQueues(sendType, sendReason) {
513
519
  _clearScheduledTimer();
514
520
  // Cancel all flush callbacks
515
521
  if (_flushCallbackTimerId) {
516
- _self._clearTimeoutOverride(_flushCallbackTimerId);
522
+ _timeoutWrapper.clear(_flushCallbackTimerId);
517
523
  _flushCallbackTimerId = null;
518
524
  }
519
525
  if (!_paused) {
520
526
  // Queue all the remaining requests to be sent. The requests will be sent using HTML5 Beacons if they are available.
521
- _sendEventsForLatencyAndAbove(1 /* Normal */, sendType, sendReason);
527
+ _sendEventsForLatencyAndAbove(1 /* EventLatencyValue.Normal */, sendType, sendReason);
522
528
  }
523
529
  }
524
530
  /**
@@ -527,19 +533,19 @@ var PostChannel = /** @class */ (function (_super) {
527
533
  * after flush are stored separately till we flush the current events.
528
534
  */
529
535
  function _clearQueues() {
530
- _batchQueues[4 /* Immediate */] = {
536
+ _batchQueues[4 /* EventLatencyValue.Immediate */] = {
531
537
  batches: [],
532
538
  iKeyMap: {}
533
539
  };
534
- _batchQueues[3 /* RealTime */] = {
540
+ _batchQueues[3 /* EventLatencyValue.RealTime */] = {
535
541
  batches: [],
536
542
  iKeyMap: {}
537
543
  };
538
- _batchQueues[2 /* CostDeferred */] = {
544
+ _batchQueues[2 /* EventLatencyValue.CostDeferred */] = {
539
545
  batches: [],
540
546
  iKeyMap: {}
541
547
  };
542
- _batchQueues[1 /* Normal */] = {
548
+ _batchQueues[1 /* EventLatencyValue.Normal */] = {
543
549
  batches: [],
544
550
  iKeyMap: {}
545
551
  };
@@ -547,7 +553,7 @@ var PostChannel = /** @class */ (function (_super) {
547
553
  function _getEventBatch(iKey, latency, create) {
548
554
  var batchQueue = _batchQueues[latency];
549
555
  if (!batchQueue) {
550
- latency = 1 /* Normal */;
556
+ latency = 1 /* EventLatencyValue.Normal */;
551
557
  batchQueue = _batchQueues[latency];
552
558
  }
553
559
  var eventBatch = batchQueue.iKeyMap[iKey];
@@ -567,7 +573,7 @@ var PostChannel = /** @class */ (function (_super) {
567
573
  }
568
574
  if (doFlush && _flushCallbackTimerId == null) {
569
575
  // Auto flush the queue
570
- _self.flush(isAsync, null, 20 /* MaxQueuedEvents */);
576
+ _self.flush(isAsync, null, 20 /* SendRequestReason.MaxQueuedEvents */);
571
577
  }
572
578
  }
573
579
  }
@@ -579,7 +585,7 @@ var PostChannel = /** @class */ (function (_super) {
579
585
  var latency = event.latency;
580
586
  var eventBatch = _getEventBatch(event.iKey, latency, true);
581
587
  if (eventBatch.addEvent(event)) {
582
- if (latency !== 4 /* Immediate */) {
588
+ if (latency !== 4 /* EventLatencyValue.Immediate */) {
583
589
  _queueSize++;
584
590
  // Check for auto flushing based on total events in the queue, but not for requeued or retry events
585
591
  if (append && event.sendAttempt === 0) {
@@ -603,7 +609,7 @@ var PostChannel = /** @class */ (function (_super) {
603
609
  var droppedEvents = eventBatch.split(0, dropNumber);
604
610
  var droppedCount = droppedEvents.count();
605
611
  if (droppedCount > 0) {
606
- if (currentLatency === 4 /* Immediate */) {
612
+ if (currentLatency === 4 /* EventLatencyValue.Immediate */) {
607
613
  _immediateQueueSize -= droppedCount;
608
614
  }
609
615
  else {
@@ -630,7 +636,7 @@ var PostChannel = /** @class */ (function (_super) {
630
636
  var batchQueue = _batchQueues[latency];
631
637
  if (batchQueue && batchQueue.batches) {
632
638
  arrForEach(batchQueue.batches, function (theBatch) {
633
- if (latency === 4 /* Immediate */) {
639
+ if (latency === 4 /* EventLatencyValue.Immediate */) {
634
640
  immediateQueue += theBatch.count();
635
641
  }
636
642
  else {
@@ -639,7 +645,7 @@ var PostChannel = /** @class */ (function (_super) {
639
645
  });
640
646
  }
641
647
  };
642
- for (var latency = 1 /* Normal */; latency <= 4 /* Immediate */; latency++) {
648
+ for (var latency = 1 /* EventLatencyValue.Normal */; latency <= 4 /* EventLatencyValue.Immediate */; latency++) {
643
649
  _loop_1(latency);
644
650
  }
645
651
  _queueSize = normalQueue;
@@ -647,14 +653,14 @@ var PostChannel = /** @class */ (function (_super) {
647
653
  }
648
654
  function _queueBatches(latency, sendType, sendReason) {
649
655
  var eventsQueued = false;
650
- var isAsync = sendType === 0 /* Batched */;
656
+ var isAsync = sendType === 0 /* EventSendType.Batched */;
651
657
  // Only queue batches (to the HttpManager) if this is a sync request or the httpManager has an idle connection
652
658
  // Thus keeping the events within the PostChannel until the HttpManager has a connection available
653
659
  // This is so we can drop "old" events if the queue is getting full because we can't successfully send events
654
660
  if (!isAsync || _httpManager.canSendRequest()) {
655
661
  doPerf(_self.core, function () { return "PostChannel._queueBatches"; }, function () {
656
662
  var droppedEvents = [];
657
- var latencyToProcess = 4 /* Immediate */;
663
+ var latencyToProcess = 4 /* EventLatencyValue.Immediate */;
658
664
  while (latencyToProcess >= latency) {
659
665
  var batchQueue = _batchQueues[latencyToProcess];
660
666
  if (batchQueue && batchQueue.batches && batchQueue.batches.length > 0) {
@@ -667,7 +673,7 @@ var PostChannel = /** @class */ (function (_super) {
667
673
  else {
668
674
  eventsQueued = eventsQueued || (theBatch && theBatch.count() > 0);
669
675
  }
670
- if (latencyToProcess === 4 /* Immediate */) {
676
+ if (latencyToProcess === 4 /* EventLatencyValue.Immediate */) {
671
677
  _immediateQueueSize -= theBatch.count();
672
678
  }
673
679
  else {
@@ -686,7 +692,7 @@ var PostChannel = /** @class */ (function (_super) {
686
692
  if (eventsQueued && _delayedBatchSendLatency >= latency) {
687
693
  // We have queued events at the same level as the delayed values so clear the setting
688
694
  _delayedBatchSendLatency = -1;
689
- _delayedBatchReason = 0 /* Undefined */;
695
+ _delayedBatchReason = 0 /* SendRequestReason.Undefined */;
690
696
  }
691
697
  }, function () { return ({ latency: latency, sendType: sendType, sendReason: sendReason }); }, !isAsync);
692
698
  }
@@ -704,22 +710,25 @@ var PostChannel = /** @class */ (function (_super) {
704
710
  */
705
711
  function _flushImpl(callback, sendReason) {
706
712
  // Add any additional queued events and cause all queued events to be sent asynchronously
707
- _sendEventsForLatencyAndAbove(1 /* Normal */, 0 /* Batched */, sendReason);
713
+ _sendEventsForLatencyAndAbove(1 /* EventLatencyValue.Normal */, 0 /* EventSendType.Batched */, sendReason);
714
+ // All events (should) have been queue -- lets just make sure the queue counts are correct to avoid queue exhaustion (previous bug #9685112)
715
+ _resetQueueCounts();
708
716
  _waitForIdleManager(function () {
709
717
  // Only called AFTER the httpManager does not have any outstanding requests
710
718
  if (callback) {
711
719
  callback();
712
720
  }
713
721
  if (_flushCallbackQueue.length > 0) {
714
- _flushCallbackTimerId = _createTimer(function () { return _flushImpl(_flushCallbackQueue.shift(), sendReason); }, 0);
722
+ _flushCallbackTimerId = _createTimer(function () {
723
+ _flushCallbackTimerId = null;
724
+ _flushImpl(_flushCallbackQueue.shift(), sendReason);
725
+ }, 0);
715
726
  }
716
727
  else {
717
728
  // No more flush requests
718
729
  _flushCallbackTimerId = null;
719
- if (_hasEvents()) {
720
- // We still have events, so restart the normal timer schedule
721
- _scheduleTimer();
722
- }
730
+ // Restart the normal timer schedule
731
+ _scheduleTimer();
723
732
  }
724
733
  });
725
734
  }
@@ -729,6 +738,7 @@ var PostChannel = /** @class */ (function (_super) {
729
738
  }
730
739
  else {
731
740
  _flushCallbackTimerId = _createTimer(function () {
741
+ _flushCallbackTimerId = null;
732
742
  _waitForIdleManager(callback);
733
743
  }, FlushCheckTimer);
734
744
  }
@@ -766,7 +776,7 @@ var PostChannel = /** @class */ (function (_super) {
766
776
  if (theEvent) {
767
777
  // Check if the request being added back is for a sync event in which case mark it no longer a sync event
768
778
  if (theEvent.sync) {
769
- theEvent.latency = 4 /* Immediate */;
779
+ theEvent.latency = 4 /* EventLatencyValue.Immediate */;
770
780
  theEvent.sync = false;
771
781
  }
772
782
  if (theEvent.sendAttempt < maxSendAttempts) {
@@ -786,7 +796,7 @@ var PostChannel = /** @class */ (function (_super) {
786
796
  }
787
797
  if (_isPageUnloadTriggered) {
788
798
  // Unload event has been received so we need to try and flush new events
789
- _releaseAllQueues(2 /* SendBeacon */, 2 /* Unload */);
799
+ _releaseAllQueues(2 /* EventSendType.SendBeacon */, 2 /* SendRequestReason.Unload */);
790
800
  }
791
801
  }
792
802
  function _callNotification(evtName, theArgs) {
@@ -797,7 +807,7 @@ var PostChannel = /** @class */ (function (_super) {
797
807
  notifyFunc.apply(manager, theArgs);
798
808
  }
799
809
  catch (e) {
800
- _throwInternal(_self.diagLog(), 1 /* CRITICAL */, 74 /* NotificationException */, evtName + " notification failed: " + e);
810
+ _throwInternal(_self.diagLog(), 1 /* eLoggingSeverity.CRITICAL */, 74 /* _eInternalMessageId.NotificationException */, evtName + " notification failed: " + e);
801
811
  }
802
812
  }
803
813
  }
@@ -829,9 +839,9 @@ var PostChannel = /** @class */ (function (_super) {
829
839
  */
830
840
  function _sendingEvent(batches, reason, isSyncRequest) {
831
841
  if (batches && batches.length > 0) {
832
- _callNotification("eventsSendRequest", [(reason >= 1000 /* SendingUndefined */ && reason <= 1999 /* SendingEventMax */ ?
833
- reason - 1000 /* SendingUndefined */ :
834
- 0 /* Undefined */), isSyncRequest !== true]);
842
+ _callNotification("eventsSendRequest", [(reason >= 1000 /* EventBatchNotificationReason.SendingUndefined */ && reason <= 1999 /* EventBatchNotificationReason.SendingEventMax */ ?
843
+ reason - 1000 /* EventBatchNotificationReason.SendingUndefined */ :
844
+ 0 /* SendRequestReason.Undefined */), isSyncRequest !== true]);
835
845
  }
836
846
  }
837
847
  /**
@@ -845,8 +855,8 @@ var PostChannel = /** @class */ (function (_super) {
845
855
  _scheduleTimer();
846
856
  }
847
857
  function _eventsDropped(batches, reason) {
848
- _notifyBatchEvents(strEventsDiscarded, batches, (reason >= 8000 /* EventsDropped */ && reason <= 8999 /* EventsDroppedMax */ ?
849
- reason - 8000 /* EventsDropped */ :
858
+ _notifyBatchEvents(strEventsDiscarded, batches, (reason >= 8000 /* EventBatchNotificationReason.EventsDropped */ && reason <= 8999 /* EventBatchNotificationReason.EventsDroppedMax */ ?
859
+ reason - 8000 /* EventBatchNotificationReason.EventsDropped */ :
850
860
  EventsDiscardedReason.Unknown));
851
861
  }
852
862
  function _eventsResponseFail(batches) {
@@ -867,6 +877,15 @@ var PostChannel = /** @class */ (function (_super) {
867
877
  _autoFlushBatchLimit = 0;
868
878
  }
869
879
  }
880
+ // Provided for backward compatibility they are not "expected" to be in current use but they are public
881
+ objDefineAccessors(_self, "_setTimeoutOverride", function () { return _timeoutWrapper.set; }, function (value) {
882
+ // Recreate the timeout wrapper
883
+ _timeoutWrapper = createTimeoutWrapper(value, _timeoutWrapper.clear);
884
+ });
885
+ objDefineAccessors(_self, "_clearTimeoutOverride", function () { return _timeoutWrapper.clear; }, function (value) {
886
+ // Recreate the timeout wrapper
887
+ _timeoutWrapper = createTimeoutWrapper(_timeoutWrapper.set, value);
888
+ });
870
889
  });
871
890
  return _this;
872
891
  }
@@ -883,6 +902,11 @@ var PostChannel = /** @class */ (function (_super) {
883
902
  // Removed Stub for PostChannel.prototype._setTransmitProfile.
884
903
  // Removed Stub for PostChannel.prototype._backOffTransmission.
885
904
  // Removed Stub for PostChannel.prototype._clearBackOff.
905
+ // This is a workaround for an IE8 bug when using dynamicProto() with classes that don't have any
906
+ // non-dynamic functions or static properties/functions when using uglify-js to minify the resulting code.
907
+ // this will be removed when ES3 support is dropped.
908
+ PostChannel.__ieDyn=1;
909
+
886
910
  return PostChannel;
887
911
  }(BaseTelemetryPlugin));
888
912
  export default PostChannel;