@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
@@ -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
  */
@@ -9,22 +9,27 @@ 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, EventLatency, EventsDiscardedReason, isValueAssigned, addPageUnloadEventListener, addPageHideEventListener, addPageShowEventListener, setProcessTelemetryTimings, isWindowObjectAvailable, arrForEach, LoggingSeverity, _ExtendedInternalMessageId, doPerf, objForEachKey, optimizeObject, isChromium, getWindow, } from "@microsoft/1ds-core-js";
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
13
  import { RT_PROFILE, NRT_PROFILE, BE_PROFILE, } from "./DataModels";
14
14
  import { EventBatch } from "./EventBatch";
15
- import HttpManager from "./HttpManager";
16
- import RetryPolicy from "./RetryPolicy";
15
+ import { HttpManager } from "./HttpManager";
16
+ import { retryPolicyGetMillisToBackoffForRetry } from "./RetryPolicy";
17
17
  import dynamicProto from "@microsoft/dynamicproto-js";
18
+ import { strMsaDeviceTicket } from "./Constants";
18
19
  var FlushCheckTimer = 0.250; // This needs to be in seconds, so this is 250ms
19
20
  var MaxNumberEventPerBatch = 500;
20
21
  var EventsDroppedAtOneTime = 20;
21
22
  var MaxSendAttempts = 6;
23
+ var MaxSyncUnloadSendAttempts = 2; // Assuming 2 based on beforeunload and unload
22
24
  var MaxBackoffCount = 4;
23
25
  var globalContext = isWindowObjectAvailable ? window : this;
24
26
  var MaxConnections = 2;
25
- var MaxRetries = 1;
27
+ var MaxRequestRetriesBeforeBackoff = 1;
26
28
  var strEventsDiscarded = "eventsDiscarded";
27
29
  var strOverrideInstrumentationKey = "overrideInstrumentationKey";
30
+ var strMaxEventRetryAttempts = "maxEventRetryAttempts";
31
+ var strMaxUnloadEventRetryAttempts = "maxUnloadEventRetryAttempts";
32
+ var strAddUnloadCb = "addUnloadCb";
28
33
  /**
29
34
  * Class that manages adding events to inbound queues and batching of events
30
35
  * into requests.
@@ -35,7 +40,7 @@ var PostChannel = /** @class */ (function (_super) {
35
40
  var _this = _super.call(this) || this;
36
41
  _this.identifier = "PostChannel";
37
42
  _this.priority = 1011;
38
- _this.version = '3.1.9';
43
+ _this.version = '3.2.0';
39
44
  var _config;
40
45
  var _isTeardownCalled = false;
41
46
  var _flushCallbackQueue = [];
@@ -61,18 +66,12 @@ var PostChannel = /** @class */ (function (_super) {
61
66
  var _delayedBatchReason;
62
67
  var _optimizeObject = true;
63
68
  var _isPageUnloadTriggered = false;
69
+ var _disableXhrSync = false;
70
+ var _maxEventSendAttempts = MaxSendAttempts;
71
+ var _maxUnloadEventSendAttempts = MaxSyncUnloadSendAttempts;
72
+ var _evtNamespace;
64
73
  dynamicProto(PostChannel, _this, function (_self, _base) {
65
- _initializeProfiles();
66
- _clearQueues();
67
- _setAutoLimits();
68
- _httpManager = new HttpManager(MaxNumberEventPerBatch, MaxConnections, MaxRetries, {
69
- requeue: _requeueEvents,
70
- send: _sendingEvent,
71
- sent: _eventsSentEvent,
72
- drop: _eventsDropped,
73
- rspFail: _eventsResponseFail,
74
- oth: _otherEvent
75
- });
74
+ _initDefaults();
76
75
  // Special internal method to allow the DebugPlugin to hook embedded objects
77
76
  _self["_getDbgPlgTargets"] = function () {
78
77
  return [_httpManager];
@@ -81,63 +80,57 @@ var PostChannel = /** @class */ (function (_super) {
81
80
  doPerf(core, function () { return "PostChannel:initialize"; }, function () {
82
81
  var extendedCore = core;
83
82
  _base.initialize(coreConfig, core, extensions);
84
- _self.setInitialized(false);
85
- var ctx = _self._getTelCtx();
86
- coreConfig.extensionConfig[_self.identifier] = coreConfig.extensionConfig[_self.identifier] || {};
87
- _config = ctx.getExtCfg(_self.identifier);
88
- _self._setTimeoutOverride = _config.setTimeoutOverride ? _config.setTimeoutOverride : setTimeout.bind(globalContext);
89
- _self._clearTimeoutOverride = _config.clearTimeoutOverride ? _config.clearTimeoutOverride : clearTimeout.bind(globalContext);
90
- // Only try and use the optimizeObject() if this appears to be a chromium based browser and it has not been explicitly disabled
91
- _optimizeObject = !_config.disableOptimizeObj && isChromium();
92
- var existingGetWParamMethod = extendedCore.getWParam;
93
- extendedCore.getWParam = function () {
94
- var wparam = 0;
95
- if (_config.ignoreMc1Ms0CookieProcessing) {
96
- wparam = wparam | 2;
83
+ try {
84
+ var hasAddUnloadCb = !!core[strAddUnloadCb];
85
+ _evtNamespace = mergeEvtNamespace(createUniqueNamespace(_self.identifier), core.evtNamespace && core.evtNamespace());
86
+ var ctx = _self._getTelCtx();
87
+ coreConfig.extensionConfig[_self.identifier] = coreConfig.extensionConfig[_self.identifier] || {};
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);
91
+ // Only try and use the optimizeObject() if this appears to be a chromium based browser and it has not been explicitly disabled
92
+ _optimizeObject = !_config.disableOptimizeObj && isChromium();
93
+ _hookWParam(extendedCore);
94
+ if (_config.eventsLimitInMem > 0) {
95
+ _queueSizeLimit = _config.eventsLimitInMem;
97
96
  }
98
- return wparam | existingGetWParamMethod();
99
- };
100
- if (_config.eventsLimitInMem > 0) {
101
- _queueSizeLimit = _config.eventsLimitInMem;
102
- }
103
- if (_config.immediateEventLimit > 0) {
104
- _immediateQueueSizeLimit = _config.immediateEventLimit;
105
- }
106
- if (_config.autoFlushEventsLimit > 0) {
107
- _autoFlushEventsLimit = _config.autoFlushEventsLimit;
108
- }
109
- _setAutoLimits();
110
- if (_config.httpXHROverride && _config.httpXHROverride.sendPOST) {
111
- _xhrOverride = _config.httpXHROverride;
112
- }
113
- if (isValueAssigned(coreConfig.anonCookieName)) {
114
- _httpManager.addQueryStringParameter("anoncknm", coreConfig.anonCookieName);
115
- }
116
- _httpManager.sendHook = _config.payloadPreprocessor;
117
- _httpManager.sendListener = _config.payloadListener;
118
- // Override endpointUrl if provided in Post config
119
- var endpointUrl = _config.overrideEndpointUrl ? _config.overrideEndpointUrl : coreConfig.endpointUrl;
120
- _self._notificationManager = coreConfig.extensionConfig.NotificationManager;
121
- _httpManager.initialize(endpointUrl, _self.core, _self, _xhrOverride, _config);
122
- function _handleUnloadEvents(evt) {
123
- var theEvt = evt || getWindow().event; // IE 8 does not pass the event
124
- if (theEvt.type !== "beforeunload") {
125
- // Only set the unload trigger if not beforeunload event as beforeunload can be cancelled while the other events can't
126
- _isPageUnloadTriggered = true;
127
- _httpManager.setUnloading(_isPageUnloadTriggered);
97
+ if (_config.immediateEventLimit > 0) {
98
+ _immediateQueueSizeLimit = _config.immediateEventLimit;
128
99
  }
129
- _releaseAllQueues(2 /* SendBeacon */, 2 /* Unload */);
100
+ if (_config.autoFlushEventsLimit > 0) {
101
+ _autoFlushEventsLimit = _config.autoFlushEventsLimit;
102
+ }
103
+ _disableXhrSync = _config.disableXhrSync;
104
+ if (isNumber(_config[strMaxEventRetryAttempts])) {
105
+ _maxEventSendAttempts = _config[strMaxEventRetryAttempts];
106
+ }
107
+ if (isNumber(_config[strMaxUnloadEventRetryAttempts])) {
108
+ _maxUnloadEventSendAttempts = _config[strMaxUnloadEventRetryAttempts];
109
+ }
110
+ _setAutoLimits();
111
+ if (_config.httpXHROverride && _config.httpXHROverride.sendPOST) {
112
+ _xhrOverride = _config.httpXHROverride;
113
+ }
114
+ if (isValueAssigned(coreConfig.anonCookieName)) {
115
+ _httpManager.addQueryStringParameter("anoncknm", coreConfig.anonCookieName);
116
+ }
117
+ _httpManager.sendHook = _config.payloadPreprocessor;
118
+ _httpManager.sendListener = _config.payloadListener;
119
+ // Override endpointUrl if provided in Post config
120
+ var endpointUrl = _config.overrideEndpointUrl ? _config.overrideEndpointUrl : coreConfig.endpointUrl;
121
+ _self._notificationManager = coreConfig.extensionConfig.NotificationManager;
122
+ _httpManager.initialize(endpointUrl, _self.core, _self, _xhrOverride, _config);
123
+ var excludePageUnloadEvents = coreConfig.disablePageUnloadEvents || [];
124
+ // When running in Web browsers try to send all telemetry if page is unloaded
125
+ addPageUnloadEventListener(_handleUnloadEvents, excludePageUnloadEvents, _evtNamespace);
126
+ addPageHideEventListener(_handleUnloadEvents, excludePageUnloadEvents, _evtNamespace);
127
+ addPageShowEventListener(_handleShowEvents, coreConfig.disablePageShowEvents, _evtNamespace);
128
+ }
129
+ catch (e) {
130
+ // resetting the initialized state because of failure
131
+ _self.setInitialized(false);
132
+ throw e;
130
133
  }
131
- var excludePageUnloadEvents = coreConfig.disablePageUnloadEvents || [];
132
- // When running in Web browsers try to send all telemetry if page is unloaded
133
- addPageUnloadEventListener(_handleUnloadEvents, excludePageUnloadEvents);
134
- addPageHideEventListener(_handleUnloadEvents, excludePageUnloadEvents);
135
- addPageShowEventListener(function (evt) {
136
- // Handle the page becoming visible again
137
- _isPageUnloadTriggered = false;
138
- _httpManager.setUnloading(_isPageUnloadTriggered);
139
- }, coreConfig.disablePageShowEvents);
140
- _self.setInitialized(true);
141
134
  }, function () { return ({ coreConfig: coreConfig, core: core, extensions: extensions }); });
142
135
  };
143
136
  _self.processTelemetry = function (ev, itemCtx) {
@@ -172,6 +165,41 @@ var PostChannel = /** @class */ (function (_super) {
172
165
  }
173
166
  _self.processNext(event, itemCtx);
174
167
  };
168
+ _self._doTeardown = function (unloadCtx, unloadState) {
169
+ _releaseAllQueues(2 /* SendBeacon */, 2 /* Unload */);
170
+ _isTeardownCalled = true;
171
+ _httpManager.teardown();
172
+ removePageUnloadEventListener(null, _evtNamespace);
173
+ removePageHideEventListener(null, _evtNamespace);
174
+ removePageShowEventListener(null, _evtNamespace);
175
+ // Just register to remove all events associated with this namespace
176
+ _initDefaults();
177
+ };
178
+ function _hookWParam(extendedCore) {
179
+ var existingGetWParamMethod = extendedCore.getWParam;
180
+ extendedCore.getWParam = function () {
181
+ var wparam = 0;
182
+ if (_config.ignoreMc1Ms0CookieProcessing) {
183
+ wparam = wparam | 2;
184
+ }
185
+ return wparam | existingGetWParamMethod();
186
+ };
187
+ }
188
+ // Moving event handlers out from the initialize closure so that any local variables can be garbage collected
189
+ function _handleUnloadEvents(evt) {
190
+ var theEvt = evt || getWindow().event; // IE 8 does not pass the event
191
+ if (theEvt.type !== "beforeunload") {
192
+ // Only set the unload trigger if not beforeunload event as beforeunload can be cancelled while the other events can't
193
+ _isPageUnloadTriggered = true;
194
+ _httpManager.setUnloading(_isPageUnloadTriggered);
195
+ }
196
+ _releaseAllQueues(2 /* SendBeacon */, 2 /* Unload */);
197
+ }
198
+ function _handleShowEvents(evt) {
199
+ // Handle the page becoming visible again
200
+ _isPageUnloadTriggered = false;
201
+ _httpManager.setUnloading(_isPageUnloadTriggered);
202
+ }
175
203
  function _addEventToQueues(event, append) {
176
204
  // If send attempt field is undefined we should set it to 0.
177
205
  if (!event.sendAttempt) {
@@ -179,7 +207,7 @@ var PostChannel = /** @class */ (function (_super) {
179
207
  }
180
208
  // Add default latency
181
209
  if (!event.latency) {
182
- event.latency = EventLatency.Normal;
210
+ event.latency = 1 /* Normal */;
183
211
  }
184
212
  // Remove extra AI properties if present
185
213
  if (event.ext && event.ext["trace"]) {
@@ -202,7 +230,7 @@ var PostChannel = /** @class */ (function (_super) {
202
230
  // If the transmission is backed off then do not send synchronous events.
203
231
  // We will convert these events to Real time latency instead.
204
232
  if (_currentBackoffCount || _paused) {
205
- event.latency = EventLatency.RealTime;
233
+ event.latency = 3 /* RealTime */;
206
234
  event.sync = false;
207
235
  }
208
236
  else {
@@ -220,7 +248,7 @@ var PostChannel = /** @class */ (function (_super) {
220
248
  var evtLatency = event.latency;
221
249
  var queueSize = _queueSize;
222
250
  var queueLimit = _queueSizeLimit;
223
- if (evtLatency === EventLatency.Immediate) {
251
+ if (evtLatency === 4 /* Immediate */) {
224
252
  queueSize = _immediateQueueSize;
225
253
  queueLimit = _immediateQueueSizeLimit;
226
254
  }
@@ -230,11 +258,11 @@ var PostChannel = /** @class */ (function (_super) {
230
258
  eventDropped = !_addEventToProperQueue(event, append);
231
259
  }
232
260
  else {
233
- var dropLatency = EventLatency.Normal;
261
+ var dropLatency = 1 /* Normal */;
234
262
  var dropNumber = EventsDroppedAtOneTime;
235
- if (evtLatency === EventLatency.Immediate) {
263
+ if (evtLatency === 4 /* Immediate */) {
236
264
  // Only drop other immediate events as they are not technically sharing the general queue
237
- dropLatency = EventLatency.Immediate;
265
+ dropLatency = 4 /* Immediate */;
238
266
  dropNumber = 1;
239
267
  }
240
268
  // Drop old event from lower or equal latency
@@ -256,7 +284,7 @@ var PostChannel = /** @class */ (function (_super) {
256
284
  var doFlush = _queueSize > eventLimit;
257
285
  if (!doFlush && _autoFlushBatchLimit > 0) {
258
286
  // Check the auto flush max batch size
259
- for (var latency = EventLatency.Normal; !doFlush && latency <= EventLatency.RealTime; latency++) {
287
+ for (var latency = 1 /* Normal */; !doFlush && latency <= 3 /* RealTime */; latency++) {
260
288
  var batchQueue = _batchQueues[latency];
261
289
  if (batchQueue && batchQueue.batches) {
262
290
  arrForEach(batchQueue.batches, function (theBatch) {
@@ -270,11 +298,6 @@ var PostChannel = /** @class */ (function (_super) {
270
298
  }
271
299
  _performAutoFlush(true, doFlush);
272
300
  };
273
- _self.teardown = function () {
274
- _releaseAllQueues(2 /* SendBeacon */, 2 /* Unload */);
275
- _isTeardownCalled = true;
276
- _httpManager.teardown();
277
- };
278
301
  _self.pause = function () {
279
302
  _clearScheduledTimer();
280
303
  _paused = true;
@@ -323,7 +346,7 @@ var PostChannel = /** @class */ (function (_super) {
323
346
  sendReason = sendReason || 1 /* ManualFlush */;
324
347
  if (async) {
325
348
  // Move all queued events to the HttpManager
326
- _queueBatches(EventLatency.Normal, 0 /* Batched */, sendReason);
349
+ _queueBatches(1 /* Normal */, 0 /* Batched */, sendReason);
327
350
  // All events (should) have been queue -- lets just make sure the queue counts are correct to avoid queue exhaustion (previous bug #9685112)
328
351
  _resetQueueCounts();
329
352
  if (_flushCallbackTimerId == null) {
@@ -339,7 +362,7 @@ var PostChannel = /** @class */ (function (_super) {
339
362
  }
340
363
  else {
341
364
  // Now cause all queued events to be sent synchronously
342
- _sendEventsForLatencyAndAbove(EventLatency.Normal, 1 /* Synchronous */, sendReason);
365
+ _sendEventsForLatencyAndAbove(1 /* Normal */, 1 /* Synchronous */, sendReason);
343
366
  if (callback !== null && callback !== undefined) {
344
367
  callback();
345
368
  }
@@ -347,7 +370,7 @@ var PostChannel = /** @class */ (function (_super) {
347
370
  }
348
371
  };
349
372
  _self.setMsaAuthTicket = function (ticket) {
350
- _httpManager.addHeader("AuthMsaDeviceTicket", ticket);
373
+ _httpManager.addHeader(strMsaDeviceTicket, ticket);
351
374
  };
352
375
  _self.hasEvents = _hasEvents;
353
376
  _self._setTransmitProfile = function (profileName) {
@@ -389,7 +412,7 @@ var PostChannel = /** @class */ (function (_super) {
389
412
  _immediateTimerId = _createTimer(function () {
390
413
  _immediateTimerId = null;
391
414
  // Only try to send direct events
392
- _sendEventsForLatencyAndAbove(EventLatency.Immediate, 0 /* Batched */, 1 /* NormalSchedule */);
415
+ _sendEventsForLatencyAndAbove(4 /* Immediate */, 0 /* Batched */, 1 /* NormalSchedule */);
393
416
  _scheduleTimer();
394
417
  }, immediateTimeOut);
395
418
  }
@@ -400,7 +423,7 @@ var PostChannel = /** @class */ (function (_super) {
400
423
  if (_hasEvents()) {
401
424
  _scheduledTimerId = _createTimer(function () {
402
425
  _scheduledTimerId = null;
403
- _sendEventsForLatencyAndAbove(_timerCount === 0 ? EventLatency.RealTime : EventLatency.Normal, 0 /* Batched */, 1 /* NormalSchedule */);
426
+ _sendEventsForLatencyAndAbove(_timerCount === 0 ? 3 /* RealTime */ : 1 /* Normal */, 0 /* Batched */, 1 /* NormalSchedule */);
404
427
  // Increment the count for next cycle
405
428
  _timerCount++;
406
429
  _timerCount %= 2;
@@ -426,6 +449,47 @@ var PostChannel = /** @class */ (function (_super) {
426
449
  _scheduleTimer();
427
450
  }
428
451
  };
452
+ function _initDefaults() {
453
+ _config = null;
454
+ _isTeardownCalled = false;
455
+ _flushCallbackQueue = [];
456
+ _flushCallbackTimerId = null;
457
+ _paused = false;
458
+ _immediateQueueSize = 0;
459
+ _immediateQueueSizeLimit = 500;
460
+ _queueSize = 0;
461
+ _queueSizeLimit = 10000;
462
+ _profiles = {};
463
+ _currentProfile = RT_PROFILE;
464
+ _scheduledTimerId = null;
465
+ _immediateTimerId = null;
466
+ _currentBackoffCount = 0;
467
+ _timerCount = 0;
468
+ _xhrOverride = null;
469
+ _batchQueues = {};
470
+ _autoFlushEventsLimit = undefined;
471
+ // either MaxBatchSize * (1+ Max Connections) or _queueLimit / 6 (where 3 latency Queues [normal, realtime, cost deferred] * 2 [allow half full -- allow for retry])
472
+ _autoFlushBatchLimit = 0;
473
+ _delayedBatchSendLatency = -1;
474
+ _delayedBatchReason = null;
475
+ _optimizeObject = true;
476
+ _isPageUnloadTriggered = false;
477
+ _disableXhrSync = false;
478
+ _maxEventSendAttempts = MaxSendAttempts;
479
+ _maxUnloadEventSendAttempts = MaxSyncUnloadSendAttempts;
480
+ _evtNamespace = null;
481
+ _httpManager = new HttpManager(MaxNumberEventPerBatch, MaxConnections, MaxRequestRetriesBeforeBackoff, {
482
+ requeue: _requeueEvents,
483
+ send: _sendingEvent,
484
+ sent: _eventsSentEvent,
485
+ drop: _eventsDropped,
486
+ rspFail: _eventsResponseFail,
487
+ oth: _otherEvent
488
+ });
489
+ _initializeProfiles();
490
+ _clearQueues();
491
+ _setAutoLimits();
492
+ }
429
493
  function _createTimer(theTimerFunc, timeOut) {
430
494
  // If the transmission is backed off make the timer at least 1 sec to allow for back off.
431
495
  if (timeOut === 0 && _currentBackoffCount) {
@@ -433,7 +497,7 @@ var PostChannel = /** @class */ (function (_super) {
433
497
  }
434
498
  var timerMultiplier = 1000;
435
499
  if (_currentBackoffCount) {
436
- timerMultiplier = RetryPolicy.getMillisToBackoffForRetry(_currentBackoffCount - 1);
500
+ timerMultiplier = retryPolicyGetMillisToBackoffForRetry(_currentBackoffCount - 1);
437
501
  }
438
502
  return _self._setTimeoutOverride(theTimerFunc, timeOut * timerMultiplier);
439
503
  }
@@ -454,7 +518,7 @@ var PostChannel = /** @class */ (function (_super) {
454
518
  }
455
519
  if (!_paused) {
456
520
  // Queue all the remaining requests to be sent. The requests will be sent using HTML5 Beacons if they are available.
457
- _sendEventsForLatencyAndAbove(EventLatency.Normal, sendType, sendReason);
521
+ _sendEventsForLatencyAndAbove(1 /* Normal */, sendType, sendReason);
458
522
  }
459
523
  }
460
524
  /**
@@ -463,19 +527,19 @@ var PostChannel = /** @class */ (function (_super) {
463
527
  * after flush are stored separately till we flush the current events.
464
528
  */
465
529
  function _clearQueues() {
466
- _batchQueues[EventLatency.Immediate] = {
530
+ _batchQueues[4 /* Immediate */] = {
467
531
  batches: [],
468
532
  iKeyMap: {}
469
533
  };
470
- _batchQueues[EventLatency.RealTime] = {
534
+ _batchQueues[3 /* RealTime */] = {
471
535
  batches: [],
472
536
  iKeyMap: {}
473
537
  };
474
- _batchQueues[EventLatency.CostDeferred] = {
538
+ _batchQueues[2 /* CostDeferred */] = {
475
539
  batches: [],
476
540
  iKeyMap: {}
477
541
  };
478
- _batchQueues[EventLatency.Normal] = {
542
+ _batchQueues[1 /* Normal */] = {
479
543
  batches: [],
480
544
  iKeyMap: {}
481
545
  };
@@ -483,7 +547,7 @@ var PostChannel = /** @class */ (function (_super) {
483
547
  function _getEventBatch(iKey, latency, create) {
484
548
  var batchQueue = _batchQueues[latency];
485
549
  if (!batchQueue) {
486
- latency = EventLatency.Normal;
550
+ latency = 1 /* Normal */;
487
551
  batchQueue = _batchQueues[latency];
488
552
  }
489
553
  var eventBatch = batchQueue.iKeyMap[iKey];
@@ -514,8 +578,8 @@ var PostChannel = /** @class */ (function (_super) {
514
578
  }
515
579
  var latency = event.latency;
516
580
  var eventBatch = _getEventBatch(event.iKey, latency, true);
517
- if (eventBatch.addEvents([event], append)) {
518
- if (latency !== EventLatency.Immediate) {
581
+ if (eventBatch.addEvent(event)) {
582
+ if (latency !== 4 /* Immediate */) {
519
583
  _queueSize++;
520
584
  // Check for auto flushing based on total events in the queue, but not for requeued or retry events
521
585
  if (append && event.sendAttempt === 0) {
@@ -539,7 +603,7 @@ var PostChannel = /** @class */ (function (_super) {
539
603
  var droppedEvents = eventBatch.split(0, dropNumber);
540
604
  var droppedCount = droppedEvents.count();
541
605
  if (droppedCount > 0) {
542
- if (currentLatency === EventLatency.Immediate) {
606
+ if (currentLatency === 4 /* Immediate */) {
543
607
  _immediateQueueSize -= droppedCount;
544
608
  }
545
609
  else {
@@ -566,7 +630,7 @@ var PostChannel = /** @class */ (function (_super) {
566
630
  var batchQueue = _batchQueues[latency];
567
631
  if (batchQueue && batchQueue.batches) {
568
632
  arrForEach(batchQueue.batches, function (theBatch) {
569
- if (latency === EventLatency.Immediate) {
633
+ if (latency === 4 /* Immediate */) {
570
634
  immediateQueue += theBatch.count();
571
635
  }
572
636
  else {
@@ -575,7 +639,7 @@ var PostChannel = /** @class */ (function (_super) {
575
639
  });
576
640
  }
577
641
  };
578
- for (var latency = EventLatency.Normal; latency <= EventLatency.Immediate; latency++) {
642
+ for (var latency = 1 /* Normal */; latency <= 4 /* Immediate */; latency++) {
579
643
  _loop_1(latency);
580
644
  }
581
645
  _queueSize = normalQueue;
@@ -590,7 +654,7 @@ var PostChannel = /** @class */ (function (_super) {
590
654
  if (!isAsync || _httpManager.canSendRequest()) {
591
655
  doPerf(_self.core, function () { return "PostChannel._queueBatches"; }, function () {
592
656
  var droppedEvents = [];
593
- var latencyToProcess = EventLatency.Immediate;
657
+ var latencyToProcess = 4 /* Immediate */;
594
658
  while (latencyToProcess >= latency) {
595
659
  var batchQueue = _batchQueues[latencyToProcess];
596
660
  if (batchQueue && batchQueue.batches && batchQueue.batches.length > 0) {
@@ -603,7 +667,7 @@ var PostChannel = /** @class */ (function (_super) {
603
667
  else {
604
668
  eventsQueued = eventsQueued || (theBatch && theBatch.count() > 0);
605
669
  }
606
- if (latencyToProcess === EventLatency.Immediate) {
670
+ if (latencyToProcess === 4 /* Immediate */) {
607
671
  _immediateQueueSize -= theBatch.count();
608
672
  }
609
673
  else {
@@ -640,7 +704,7 @@ var PostChannel = /** @class */ (function (_super) {
640
704
  */
641
705
  function _flushImpl(callback, sendReason) {
642
706
  // Add any additional queued events and cause all queued events to be sent asynchronously
643
- _sendEventsForLatencyAndAbove(EventLatency.Normal, 0 /* Batched */, sendReason);
707
+ _sendEventsForLatencyAndAbove(1 /* Normal */, 0 /* Batched */, sendReason);
644
708
  _waitForIdleManager(function () {
645
709
  // Only called AFTER the httpManager does not have any outstanding requests
646
710
  if (callback) {
@@ -691,16 +755,21 @@ var PostChannel = /** @class */ (function (_super) {
691
755
  */
692
756
  function _requeueEvents(batches, reason) {
693
757
  var droppedEvents = [];
758
+ var maxSendAttempts = _maxEventSendAttempts;
759
+ if (_isPageUnloadTriggered) {
760
+ // If a page unlaod has been triggered reduce the number of times we try to "retry"
761
+ maxSendAttempts = _maxUnloadEventSendAttempts;
762
+ }
694
763
  arrForEach(batches, function (theBatch) {
695
764
  if (theBatch && theBatch.count() > 0) {
696
765
  arrForEach(theBatch.events(), function (theEvent) {
697
766
  if (theEvent) {
698
767
  // Check if the request being added back is for a sync event in which case mark it no longer a sync event
699
768
  if (theEvent.sync) {
700
- theEvent.latency = EventLatency.Immediate;
769
+ theEvent.latency = 4 /* Immediate */;
701
770
  theEvent.sync = false;
702
771
  }
703
- if (theEvent.sendAttempt < MaxSendAttempts) {
772
+ if (theEvent.sendAttempt < maxSendAttempts) {
704
773
  // Reset the event timings
705
774
  setProcessTelemetryTimings(theEvent, _self.identifier);
706
775
  _addEventToQueues(theEvent, false);
@@ -728,7 +797,7 @@ var PostChannel = /** @class */ (function (_super) {
728
797
  notifyFunc.apply(manager, theArgs);
729
798
  }
730
799
  catch (e) {
731
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _ExtendedInternalMessageId.NotificationException, evtName + " notification failed: " + e);
800
+ _throwInternal(_self.diagLog(), 1 /* CRITICAL */, 74 /* NotificationException */, evtName + " notification failed: " + e);
732
801
  }
733
802
  }
734
803
  }
@@ -804,7 +873,6 @@ var PostChannel = /** @class */ (function (_super) {
804
873
  // Removed Stub for PostChannel.prototype.initialize.
805
874
  // Removed Stub for PostChannel.prototype.processTelemetry.
806
875
  // Removed Stub for PostChannel.prototype.setEventQueueLimits.
807
- // Removed Stub for PostChannel.prototype.teardown.
808
876
  // Removed Stub for PostChannel.prototype.pause.
809
877
  // Removed Stub for PostChannel.prototype.resume.
810
878
  // Removed Stub for PostChannel.prototype.addResponseHandler.