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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/README.md +124 -6
  2. package/bundle/{ms.post-3.1.10.gbl.js → ms.post-3.2.1.gbl.js} +1502 -725
  3. package/bundle/ms.post-3.2.1.gbl.js.map +1 -0
  4. package/bundle/ms.post-3.2.1.gbl.min.js +7 -0
  5. package/bundle/ms.post-3.2.1.gbl.min.js.map +1 -0
  6. package/bundle/ms.post-3.2.1.integrity.json +46 -0
  7. package/bundle/{ms.post-3.1.10.js → ms.post-3.2.1.js} +1502 -725
  8. package/bundle/ms.post-3.2.1.js.map +1 -0
  9. package/bundle/ms.post-3.2.1.min.js +7 -0
  10. package/bundle/ms.post-3.2.1.min.js.map +1 -0
  11. package/bundle/ms.post.gbl.js +1501 -724
  12. package/bundle/ms.post.gbl.js.map +1 -1
  13. package/bundle/ms.post.gbl.min.js +2 -2
  14. package/bundle/ms.post.gbl.min.js.map +1 -1
  15. package/bundle/ms.post.integrity.json +17 -17
  16. package/bundle/ms.post.js +1501 -724
  17. package/bundle/ms.post.js.map +1 -1
  18. package/bundle/ms.post.min.js +2 -2
  19. package/bundle/ms.post.min.js.map +1 -1
  20. package/dist/ms.post.js +264 -149
  21. package/dist/ms.post.js.map +1 -1
  22. package/dist/ms.post.min.js +2 -2
  23. package/dist/ms.post.min.js.map +1 -1
  24. package/dist-esm/src/BatchNotificationActions.js +1 -1
  25. package/dist-esm/src/ClockSkewManager.js +1 -1
  26. package/dist-esm/src/Constants.d.ts +1 -0
  27. package/dist-esm/src/Constants.js +2 -1
  28. package/dist-esm/src/Constants.js.map +1 -1
  29. package/dist-esm/src/DataModels.d.ts +49 -0
  30. package/dist-esm/src/DataModels.js +1 -1
  31. package/dist-esm/src/EventBatch.js +1 -1
  32. package/dist-esm/src/HttpManager.d.ts +1 -1
  33. package/dist-esm/src/HttpManager.js +102 -58
  34. package/dist-esm/src/HttpManager.js.map +1 -1
  35. package/dist-esm/src/Index.js +1 -1
  36. package/dist-esm/src/KillSwitch.js +1 -1
  37. package/dist-esm/src/PostChannel.d.ts +0 -4
  38. package/dist-esm/src/PostChannel.js +171 -104
  39. package/dist-esm/src/PostChannel.js.map +1 -1
  40. package/dist-esm/src/RetryPolicy.d.ts +20 -25
  41. package/dist-esm/src/RetryPolicy.js +35 -44
  42. package/dist-esm/src/RetryPolicy.js.map +1 -1
  43. package/dist-esm/src/Serializer.js +1 -1
  44. package/dist-esm/src/typings/XDomainRequest.js +1 -1
  45. package/package.json +2 -2
  46. package/src/Constants.ts +1 -0
  47. package/src/DataModels.ts +62 -1
  48. package/src/HttpManager.ts +110 -69
  49. package/src/PostChannel.ts +203 -127
  50. package/src/RetryPolicy.ts +33 -38
  51. package/bundle/ms.post-3.1.10.gbl.js.map +0 -1
  52. package/bundle/ms.post-3.1.10.gbl.min.js +0 -7
  53. package/bundle/ms.post-3.1.10.gbl.min.js.map +0 -1
  54. package/bundle/ms.post-3.1.10.integrity.json +0 -46
  55. package/bundle/ms.post-3.1.10.js.map +0 -1
  56. package/bundle/ms.post-3.1.10.min.js +0 -7
  57. package/bundle/ms.post-3.1.10.min.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  /*
2
- * 1DS JS SDK POST plugin, 3.1.10
2
+ * 1DS JS SDK POST plugin, 3.2.1
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  * (Microsoft Internal Only)
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*
2
- * 1DS JS SDK POST plugin, 3.1.10
2
+ * 1DS JS SDK POST plugin, 3.2.1
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  * (Microsoft Internal Only)
5
5
  */
@@ -21,4 +21,5 @@ export declare const strApiKey = "apikey";
21
21
  export declare const strMsaDeviceTicket = "AuthMsaDeviceTicket";
22
22
  export declare const strAuthXToken = "AuthXToken";
23
23
  export declare const strSdkVersion = "sdk-version";
24
+ export declare const strNoResponseBody = "NoResponseBody";
24
25
  export declare const strMsfpc = "msfpc";
@@ -1,5 +1,5 @@
1
1
  /*
2
- * 1DS JS SDK POST plugin, 3.1.10
2
+ * 1DS JS SDK POST plugin, 3.2.1
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  * (Microsoft Internal Only)
5
5
  */
@@ -26,5 +26,6 @@ export var strApiKey = "apikey";
26
26
  export var strMsaDeviceTicket = "AuthMsaDeviceTicket";
27
27
  export var strAuthXToken = "AuthXToken";
28
28
  export var strSdkVersion = "sdk-version";
29
+ export var strNoResponseBody = "NoResponseBody";
29
30
  export var strMsfpc = "msfpc";
30
31
  //# sourceMappingURL=Constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Constants.js.map","sources":["Constants.js"],"sourcesContent":["export var Method = \"POST\";\r\nexport var DisabledPropertyName = \"Microsoft_ApplicationInsights_BypassAjaxInstrumentation\";\r\nexport var strDropped = \"drop\";\r\nexport var strSending = \"send\";\r\nexport var strRequeue = \"requeue\";\r\nexport var strResponseFail = \"rspFail\";\r\nexport var strOther = \"oth\";\r\nexport var defaultCacheControl = \"no-cache, no-store\";\r\nexport var defaultContentType = \"application/x-json-stream\";\r\nexport var strCacheControl = \"cache-control\";\r\nexport var strContentTypeHeader = \"content-type\";\r\nexport var strKillTokensHeader = \"kill-tokens\";\r\nexport var strKillDurationHeader = \"kill-duration\";\r\nexport var strKillDurationSecondsHeader = \"kill-duration-seconds\";\r\nexport var strTimeDeltaHeader = \"time-delta-millis\";\r\nexport var strClientVersion = \"client-version\";\r\nexport var strClientId = \"client-id\";\r\nexport var strTimeDeltaToApply = \"time-delta-to-apply-millis\";\r\nexport var strUploadTime = \"upload-time\";\r\nexport var strApiKey = \"apikey\";\r\nexport var strMsaDeviceTicket = \"AuthMsaDeviceTicket\";\r\nexport var strAuthXToken = \"AuthXToken\";\r\nexport var strSdkVersion = \"sdk-version\";\r\nexport var strMsfpc = \"msfpc\";\r\n//# sourceMappingURL=Constants.js.map"],"names":[],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
1
+ {"version":3,"file":"Constants.js.map","sources":["Constants.js"],"sourcesContent":["export var Method = \"POST\";\r\nexport var DisabledPropertyName = \"Microsoft_ApplicationInsights_BypassAjaxInstrumentation\";\r\nexport var strDropped = \"drop\";\r\nexport var strSending = \"send\";\r\nexport var strRequeue = \"requeue\";\r\nexport var strResponseFail = \"rspFail\";\r\nexport var strOther = \"oth\";\r\nexport var defaultCacheControl = \"no-cache, no-store\";\r\nexport var defaultContentType = \"application/x-json-stream\";\r\nexport var strCacheControl = \"cache-control\";\r\nexport var strContentTypeHeader = \"content-type\";\r\nexport var strKillTokensHeader = \"kill-tokens\";\r\nexport var strKillDurationHeader = \"kill-duration\";\r\nexport var strKillDurationSecondsHeader = \"kill-duration-seconds\";\r\nexport var strTimeDeltaHeader = \"time-delta-millis\";\r\nexport var strClientVersion = \"client-version\";\r\nexport var strClientId = \"client-id\";\r\nexport var strTimeDeltaToApply = \"time-delta-to-apply-millis\";\r\nexport var strUploadTime = \"upload-time\";\r\nexport var strApiKey = \"apikey\";\r\nexport var strMsaDeviceTicket = \"AuthMsaDeviceTicket\";\r\nexport var strAuthXToken = \"AuthXToken\";\r\nexport var strSdkVersion = \"sdk-version\";\r\nexport var strNoResponseBody = \"NoResponseBody\";\r\nexport var strMsfpc = \"msfpc\";\r\n//# sourceMappingURL=Constants.js.map"],"names":[],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
@@ -12,6 +12,8 @@ export interface IPayloadData {
12
12
  headers?: {
13
13
  [name: string]: string;
14
14
  };
15
+ timeout?: number;
16
+ disableXhrSync?: boolean;
15
17
  }
16
18
  /**
17
19
  * Defines the function signature for the Payload Preprocessor.
@@ -60,6 +62,10 @@ export interface IChannelConfiguration {
60
62
  disableAutoBatchFlushLimit?: boolean;
61
63
  /**
62
64
  * [Optional] The HTTP override that should be used to send requests, as an IXHROverride object.
65
+ * By default during the unload of a page or if the event specifies that it wants to use sendBeacon() or sync fetch (with keep-alive),
66
+ * this override will NOT be called. You can now change this behavior by enabling the 'alwaysUseXhrOverride' configuration value.
67
+ * The payload data (first argument) now also includes any configured 'timeout' (defaults to undefined) and whether you should avoid
68
+ * creating any synchronous XHR requests 'disableXhrSync' (defaults to false/undefined)
63
69
  */
64
70
  httpXHROverride?: IXHROverride;
65
71
  /**
@@ -138,6 +144,49 @@ export interface IChannelConfiguration {
138
144
  * previous OPTIONS response, at which point some of the current dynamic values sent on the query string will be moved to a header.
139
145
  */
140
146
  avoidOptions?: boolean;
147
+ /**
148
+ * [Optional] Specify a timeout (in ms) to apply to requests when sending requests using XHR, XDR or fetch requests. Defaults to undefined
149
+ * and therefore the runtime defaults (normally zero for browser environments)
150
+ */
151
+ xhrTimeout?: number;
152
+ /**
153
+ * [Optional] When using Xhr for sending requests disable sending as synchronous during unload or synchronous flush.
154
+ * You should enable this feature for IE (when there is no sendBeacon() or fetch (with keep-alive)) and you have clients
155
+ * that end up blocking the UI during page unloading. This will cause ALL XHR requests to be sent asynchronously which
156
+ * during page unload may result in the lose of telemetry.
157
+ */
158
+ disableXhrSync?: boolean;
159
+ /**
160
+ * [Optional] By default during unload (or when you specify to use sendBeacon() or sync fetch (with keep-alive) for an event) the SDK
161
+ * ignores any provided httpXhrOverride and attempts to use sendBeacon() or fetch(with keep-alive) when they are available.
162
+ * When this configuration option is true any provided httpXhrOverride will always be used, so any provided httpXhrOverride will
163
+ * also need to "handle" the synchronous unload scenario.
164
+ */
165
+ alwaysUseXhrOverride?: boolean;
166
+ /**
167
+ * [Optional] Identifies the number of times any single event will be retried if it receives a failed (retirable) response, this
168
+ * causes the event to be internally "requeued" and resent in the next batch. As each normal batched send request is retried at
169
+ * least once before starting to increase the internal backoff send interval, normally batched events will generally be attempted
170
+ * the next nearest even number of times. This means that the total number of actual send attempts will almost always be even
171
+ * (setting to 5 will cause 6 requests), unless using manual synchronous flushing (calling flush(false)) which is not subject to
172
+ * request level retry attempts.
173
+ * Defaults to 6 times.
174
+ */
175
+ maxEventRetryAttempts?: number;
176
+ /**
177
+ * [Optional] Identifies the number of times any single event will be retried if it receives a failed (retriable) response as part
178
+ * of processing / flushing events once a page unload state has been detected, this causes the event to be internally "requeued"
179
+ * and resent in the next batch, which during page unload. Unlike the normal batching process, send requests are never retried,
180
+ * so the value listed here is always the maximum number of attempts for any single event.
181
+ * Defaults to 2 times.
182
+ * Notes:
183
+ * The SDK by default will use the sendBeacon() API if it exists which is treated as a fire and forget successful response, so for
184
+ * environments that support or supply this API the events won't be retried (because they will be deeded to be successfully sent).
185
+ * When an environment (IE) doesn't support sendBeacon(), this will cause multiple synchronous (by default) XMLHttpRequests to be sent,
186
+ * which will block the UI until a response is received. You can disable ALL synchronous XHR requests by setting the 'disableXhrSync'
187
+ * configuration setting and/or changing this value to 0 or 1.
188
+ */
189
+ maxUnloadEventRetryAttempts?: number;
141
190
  }
142
191
  /**
143
192
  * SendPOSTFunction type defines how an HTTP POST request is sent to an ingestion server
@@ -1,5 +1,5 @@
1
1
  /*
2
- * 1DS JS SDK POST plugin, 3.1.10
2
+ * 1DS JS SDK POST plugin, 3.2.1
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  * (Microsoft Internal Only)
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*
2
- * 1DS JS SDK POST plugin, 3.1.10
2
+ * 1DS JS SDK POST plugin, 3.2.1
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  * (Microsoft Internal Only)
5
5
  */
@@ -19,7 +19,7 @@ export declare class HttpManager {
19
19
  * @constructor
20
20
  * @param requestQueue - The queue that contains the requests to be sent.
21
21
  */
22
- constructor(maxEventsPerBatch: number, maxConnections: number, maxRetries: number, actions: BatchNotificationActions);
22
+ constructor(maxEventsPerBatch: number, maxConnections: number, maxRequestRetriesBeforeBackoff: number, actions: BatchNotificationActions);
23
23
  /**
24
24
  * @constructor
25
25
  * @param requestQueue - The queue that contains the requests to be sent.
@@ -1,5 +1,5 @@
1
1
  /*
2
- * 1DS JS SDK POST plugin, 3.1.10
2
+ * 1DS JS SDK POST plugin, 3.2.1
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  * (Microsoft Internal Only)
5
5
  */
@@ -9,13 +9,15 @@ var _a;
9
9
  * @author Abhilash Panwar (abpanwar); Hector Hernandez (hectorh); Nev Wylie (newylie)
10
10
  * @copyright Microsoft 2018-2020
11
11
  */
12
- import { isReactNative, isValueAssigned, isString, getTime, arrForEach, getLocation, strTrim, isFetchSupported, isXhrSupported, isBeaconsSupported, FullVersionString, useXDomainRequest, LoggingSeverity, _ExtendedInternalMessageId, strUndefined, getNavigator, doPerf, dateNow, isUndefined, isNullOrUndefined, objForEachKey, isNumber, isArray, dumpObj, objKeys, extend, hasOwnProperty, openXhr } from "@microsoft/1ds-core-js";
12
+ import { isReactNative, isValueAssigned, isString, getTime, arrForEach, getLocation, strTrim, isFetchSupported, isXhrSupported, isBeaconsSupported, FullVersionString, useXDomainRequest, strUndefined, getNavigator, doPerf, dateNow, isUndefined, isNullOrUndefined, objForEachKey, isNumber, isArray, dumpObj, objKeys, extend, hasOwnProperty, openXhr, _throwInternal } from "@microsoft/1ds-core-js";
13
13
  import { Serializer } from "./Serializer";
14
- import RetryPolicy from "./RetryPolicy";
14
+ import { retryPolicyGetMillisToBackoffForRetry, retryPolicyShouldRetryForStatus } from "./RetryPolicy";
15
15
  import EVTKillSwitch from "./KillSwitch";
16
16
  import EVTClockSkewManager from "./ClockSkewManager";
17
17
  import dynamicProto from "@microsoft/dynamicproto-js";
18
- import { defaultCacheControl, defaultContentType, DisabledPropertyName, Method, strApiKey, strCacheControl, strClientId, strClientVersion, strContentTypeHeader, strDropped, strKillDurationHeader, strKillDurationSecondsHeader, strKillTokensHeader, strMsaDeviceTicket, strMsfpc, strOther, strRequeue, strResponseFail, strSending, strTimeDeltaHeader, strTimeDeltaToApply, strUploadTime } from "./Constants";
18
+ import { defaultCacheControl, defaultContentType, DisabledPropertyName, Method, strApiKey, strAuthXToken, strCacheControl, strClientId, strClientVersion, strContentTypeHeader, strDropped, strKillDurationHeader, strKillDurationSecondsHeader, strKillTokensHeader, strMsaDeviceTicket, strMsfpc, strNoResponseBody, strOther, strRequeue, strResponseFail, strSending, strTimeDeltaHeader, strTimeDeltaToApply, strUploadTime } from "./Constants";
19
+ var strSendAttempt = "sendAttempt";
20
+ var _noResponseQs = "&" + strNoResponseBody + "=true";
19
21
  /**
20
22
  * Identifies the default notification reason to the action names
21
23
  */
@@ -28,11 +30,19 @@ var _eventActionMap = (_a = {},
28
30
  _a);
29
31
  var _collectorQsHeaders = {};
30
32
  var _collectorHeaderToQs = {};
31
- function _addCollectorHeaderQsMapping(qsName, headerName) {
33
+ function _addCollectorHeaderQsMapping(qsName, headerName, allowQs) {
32
34
  _collectorQsHeaders[qsName] = headerName;
33
- _collectorHeaderToQs[headerName] = qsName;
35
+ if (allowQs !== false) {
36
+ _collectorHeaderToQs[headerName] = qsName;
37
+ }
34
38
  }
35
- _addCollectorHeaderQsMapping(strMsaDeviceTicket, strMsaDeviceTicket);
39
+ _addCollectorHeaderQsMapping(strMsaDeviceTicket, strMsaDeviceTicket, false);
40
+ _addCollectorHeaderQsMapping(strClientVersion, strClientVersion);
41
+ _addCollectorHeaderQsMapping(strClientId, "Client-Id");
42
+ _addCollectorHeaderQsMapping(strApiKey, strApiKey);
43
+ _addCollectorHeaderQsMapping(strTimeDeltaToApply, strTimeDeltaToApply);
44
+ _addCollectorHeaderQsMapping(strUploadTime, strUploadTime);
45
+ _addCollectorHeaderQsMapping(strAuthXToken, strAuthXToken);
36
46
  function _getResponseText(xhr) {
37
47
  try {
38
48
  return xhr.responseText;
@@ -79,7 +89,7 @@ var HttpManager = /** @class */ (function () {
79
89
  * @constructor
80
90
  * @param requestQueue - The queue that contains the requests to be sent.
81
91
  */
82
- function HttpManager(maxEventsPerBatch, maxConnections, maxRetries, actions) {
92
+ function HttpManager(maxEventsPerBatch, maxConnections, maxRequestRetriesBeforeBackoff, actions) {
83
93
  this._responseHandlers = [];
84
94
  var _urlString = "?cors=true&" + strContentTypeHeader.toLowerCase() + "=" + defaultContentType;
85
95
  var _killSwitch = new EVTKillSwitch();
@@ -99,6 +109,8 @@ var HttpManager = /** @class */ (function () {
99
109
  var _cookieMgr;
100
110
  var _isUnloading = false;
101
111
  var _useHeaders = false;
112
+ var _xhrTimeout;
113
+ var _disableXhrSync;
102
114
  dynamicProto(HttpManager, this, function (_self) {
103
115
  var _sendCredentials = true;
104
116
  _self.initialize = function (endpointUrl, core, postChannel, httpInterface, channelConfig) {
@@ -107,8 +119,7 @@ var HttpManager = /** @class */ (function () {
107
119
  channelConfig = {};
108
120
  }
109
121
  _urlString = endpointUrl + _urlString;
110
- // Task 12886642: Defaulting to 'false' until the Collector handles sending upload-time header in the OPTIONS call
111
- _useHeaders = !isUndefined(channelConfig.avoidOptions) ? !channelConfig.avoidOptions : false;
122
+ _useHeaders = !isUndefined(channelConfig.avoidOptions) ? !channelConfig.avoidOptions : true;
112
123
  _core = core;
113
124
  _cookieMgr = core.getCookieMgr();
114
125
  _enableEventTimings = !_core.config.disableEventTimings;
@@ -119,9 +130,13 @@ var HttpManager = /** @class */ (function () {
119
130
  if (!isUndefined(channelConfig.enableCompoundKey)) {
120
131
  enableCompoundKey = !!channelConfig.enableCompoundKey;
121
132
  }
133
+ _xhrTimeout = channelConfig.xhrTimeout;
134
+ _disableXhrSync = channelConfig.disableXhrSync;
122
135
  _useBeacons = !isReactNative(); // Only use beacons if not running in React Native
123
136
  _serializer = new Serializer(_core, valueSanitizer, stringifyObjects, enableCompoundKey);
124
137
  var syncHttpInterface = httpInterface;
138
+ var beaconHttpInterface = channelConfig.alwaysUseXhrOverride ? httpInterface : null;
139
+ var fetchSyncHttpInterface = channelConfig.alwaysUseXhrOverride ? httpInterface : null;
125
140
  if (!httpInterface) {
126
141
  _customHttpInterface = false;
127
142
  var location_1 = getLocation();
@@ -157,8 +172,8 @@ var HttpManager = /** @class */ (function () {
157
172
  _sendInterfaces = (_a = {},
158
173
  _a[0 /* Batched */] = httpInterface,
159
174
  _a[1 /* Synchronous */] = syncHttpInterface || _getSenderInterface([1 /* Xhr */, 2 /* Fetch */, 3 /* Beacon */], true),
160
- _a[2 /* SendBeacon */] = _getSenderInterface([3 /* Beacon */, 2 /* Fetch */, 1 /* Xhr */], true) || syncHttpInterface,
161
- _a[3 /* SyncFetch */] = _getSenderInterface([2 /* Fetch */, 3 /* Beacon */, 1 /* Xhr */], true) || syncHttpInterface,
175
+ _a[2 /* SendBeacon */] = beaconHttpInterface || _getSenderInterface([3 /* Beacon */, 2 /* Fetch */], true) || syncHttpInterface || _getSenderInterface([1 /* Xhr */], true),
176
+ _a[3 /* SyncFetch */] = fetchSyncHttpInterface || _getSenderInterface([2 /* Fetch */, 3 /* Beacon */], true) || syncHttpInterface || _getSenderInterface([1 /* Xhr */], true),
162
177
  _a);
163
178
  };
164
179
  // Special internal method to allow the DebugPlugin to hook embedded objects
@@ -200,6 +215,9 @@ var HttpManager = /** @class */ (function () {
200
215
  // It doesn't support custom headers, so no action is taken with current requestHeaders
201
216
  var xdr = new XDomainRequest();
202
217
  xdr.open(Method, payload.urlString);
218
+ if (payload.timeout) {
219
+ xdr.timeout = payload.timeout;
220
+ }
203
221
  // can't get the status code in xdr.
204
222
  xdr.onload = function () {
205
223
  // we will assume onload means the request succeeded.
@@ -229,6 +247,7 @@ var HttpManager = /** @class */ (function () {
229
247
  }
230
248
  function _fetchSendPost(payload, oncomplete, sync) {
231
249
  var _a;
250
+ var theUrl = payload.urlString;
232
251
  var ignoreResponse = false;
233
252
  var responseHandled = false;
234
253
  var requestInit = (_a = {
@@ -243,6 +262,7 @@ var HttpManager = /** @class */ (function () {
243
262
  // As a sync request (during unload), it is unlikely that we will get a chance to process the response so
244
263
  // just like beacon send assume that the events have been accepted and processed
245
264
  ignoreResponse = true;
265
+ theUrl += _noResponseQs;
246
266
  }
247
267
  }
248
268
  if (_sendCredentials) {
@@ -253,7 +273,7 @@ var HttpManager = /** @class */ (function () {
253
273
  if (payload.headers && objKeys(payload.headers).length > 0) {
254
274
  requestInit.headers = payload.headers;
255
275
  }
256
- fetch(payload.urlString, requestInit).then(function (response) {
276
+ fetch(theUrl, requestInit).then(function (response) {
257
277
  var headerMap = {};
258
278
  var responseText = "";
259
279
  if (response.headers) {
@@ -284,8 +304,19 @@ var HttpManager = /** @class */ (function () {
284
304
  responseHandled = true;
285
305
  _doOnComplete(oncomplete, 200, {});
286
306
  }
307
+ if (!responseHandled && payload.timeout > 0) {
308
+ // Simulate timeout
309
+ _postManager._setTimeoutOverride(function () {
310
+ if (!responseHandled) {
311
+ // Assume a 500 response (which will cause a retry)
312
+ responseHandled = true;
313
+ _doOnComplete(oncomplete, 500, {});
314
+ }
315
+ }, payload.timeout);
316
+ }
287
317
  }
288
318
  function _xhrSendPost(payload, oncomplete, sync) {
319
+ var theUrl = payload.urlString;
289
320
  function _appendHeader(theHeaders, xhr, name) {
290
321
  if (!theHeaders[name] && xhr && xhr.getResponseHeader) {
291
322
  var value = xhr.getResponseHeader(name);
@@ -313,30 +344,33 @@ var HttpManager = /** @class */ (function () {
313
344
  function xhrComplete(xhr, responseTxt) {
314
345
  _doOnComplete(oncomplete, xhr.status, _getAllResponseHeaders(xhr), responseTxt);
315
346
  }
316
- var xhRequest = openXhr(Method, payload.urlString, _sendCredentials, true, sync);
347
+ if (sync && payload.disableXhrSync) {
348
+ sync = false;
349
+ }
350
+ var xhrRequest = openXhr(Method, theUrl, _sendCredentials, true, sync, payload.timeout);
317
351
  // Set custom headers (e.g. gzip) here (after open())
318
352
  objForEachKey(payload.headers, function (name, value) {
319
- xhRequest.setRequestHeader(name, value);
353
+ xhrRequest.setRequestHeader(name, value);
320
354
  });
321
- xhRequest.onload = function () {
322
- var response = _getResponseText(xhRequest);
323
- xhrComplete(xhRequest, response);
355
+ xhrRequest.onload = function () {
356
+ var response = _getResponseText(xhrRequest);
357
+ xhrComplete(xhrRequest, response);
324
358
  _handleCollectorResponse(response);
325
359
  };
326
- xhRequest.onerror = function () {
327
- xhrComplete(xhRequest);
360
+ xhrRequest.onerror = function () {
361
+ xhrComplete(xhrRequest);
328
362
  };
329
- xhRequest.ontimeout = function () {
330
- xhrComplete(xhRequest);
363
+ xhrRequest.ontimeout = function () {
364
+ xhrComplete(xhrRequest);
331
365
  };
332
- xhRequest.send(payload.data);
366
+ xhrRequest.send(payload.data);
333
367
  }
334
368
  function _doOnComplete(oncomplete, status, headers, response) {
335
369
  try {
336
370
  oncomplete(status, headers, response);
337
371
  }
338
372
  catch (e) {
339
- _postManager.diagLog().throwInternal(LoggingSeverity.WARNING, _ExtendedInternalMessageId.SendPostOnCompleteFailure, dumpObj(e));
373
+ _throwInternal(_postManager.diagLog(), 2 /* WARNING */, 518 /* SendPostOnCompleteFailure */, dumpObj(e));
340
374
  }
341
375
  }
342
376
  function _beaconSendPost(payload, oncomplete, sync) {
@@ -344,9 +378,10 @@ var HttpManager = /** @class */ (function () {
344
378
  var internalPayloadData = payload;
345
379
  var status = 200;
346
380
  var thePayload = internalPayloadData._thePayload;
381
+ var theUrl = payload.urlString + _noResponseQs;
347
382
  try {
348
383
  var nav_1 = getNavigator();
349
- if (!nav_1.sendBeacon(payload.urlString, payload.data)) {
384
+ if (!nav_1.sendBeacon(theUrl, payload.data)) {
350
385
  if (thePayload) {
351
386
  // Failed to send entire payload so try and split data and try to send as much events as possible
352
387
  var droppedBatches_1 = [];
@@ -354,7 +389,7 @@ var HttpManager = /** @class */ (function () {
354
389
  if (droppedBatches_1 && theBatch && theBatch.count() > 0) {
355
390
  var theEvents = theBatch.events();
356
391
  for (var lp = 0; lp < theEvents.length; lp++) {
357
- if (!nav_1.sendBeacon(payload.urlString, _serializer.getEventBlob(theEvents[lp]))) {
392
+ if (!nav_1.sendBeacon(theUrl, _serializer.getEventBlob(theEvents[lp]))) {
358
393
  // Can't send anymore, so split the batch and drop the rest
359
394
  droppedBatches_1.push(theBatch.split(lp));
360
395
  break;
@@ -374,7 +409,7 @@ var HttpManager = /** @class */ (function () {
374
409
  }
375
410
  }
376
411
  catch (ex) {
377
- _postManager.diagLog().warnToConsole("Failed to send telemetry using sendBeacon API. Ex:" + ex);
412
+ _postManager.diagLog().warnToConsole("Failed to send telemetry using sendBeacon API. Ex:" + dumpObj(ex));
378
413
  status = 0;
379
414
  }
380
415
  finally {
@@ -578,7 +613,7 @@ var HttpManager = /** @class */ (function () {
578
613
  }, function () { return ({ batches: _createDebugBatches(orgBatches_1), retryCount: retryCount, isTeardown: isTeardown, isSynchronous: isSynchronous_1, sendReason: sendReason, useSendBeacon: _isBeaconPayload(sendType), sendType: sendType }); }, !isSynchronous_1);
579
614
  }
580
615
  catch (ex) {
581
- _postManager.diagLog().throwInternal(LoggingSeverity.WARNING, _ExtendedInternalMessageId.CannotSerializeObject, "Unexpected Exception sending batch: " + dumpObj(ex));
616
+ _throwInternal(_postManager.diagLog(), 2 /* WARNING */, 48 /* CannotSerializeObject */, "Unexpected Exception sending batch: " + dumpObj(ex));
582
617
  }
583
618
  }
584
619
  function _buildRequestDetails(thePayload, useHeaders) {
@@ -587,26 +622,24 @@ var HttpManager = /** @class */ (function () {
587
622
  hdrs: {},
588
623
  useHdrs: false // Assume no headers
589
624
  };
590
- // ----------------------------------------------------------------------------------------------------------------
591
- // Task 12886642: Need to wait until an updated version of the collector is released to return these as allowed in the OPTIONS call
592
- // ----------------------------------------------------------------------------------------------------------------
593
- // if (!useHeaders) {
594
- // // Attempt to map headers to a query string if possible
595
- // objForEachKey(_headers, (name, value) => {
596
- // if (_collectorHeaderToQs[name]) {
597
- // _addRequestDetails(requestDetails, _collectorHeaderToQs[name], value, false);
598
- // } else {
599
- // // No mapping, so just include in the headers anyway (may not get sent if using sendBeacon())
600
- // requestDetails.hdrs[name] = value;
601
- // requestDetails.useHdrs = true;
602
- // }
603
- // });
604
- // } else {
605
- // Copy the pre-defined headers into the payload headers
606
- requestDetails.hdrs = extend(requestDetails.hdrs, _headers);
607
- requestDetails.useHdrs = (objKeys(requestDetails.hdrs).length > 0);
608
- // }
609
- // ----------------------------------------------------------------------------------------------------------------
625
+ if (!useHeaders) {
626
+ // Attempt to map headers to a query string if possible
627
+ objForEachKey(_headers, function (name, value) {
628
+ if (_collectorHeaderToQs[name]) {
629
+ _addRequestDetails(requestDetails, _collectorHeaderToQs[name], value, false);
630
+ }
631
+ else {
632
+ // No mapping, so just include in the headers anyway (may not get sent if using sendBeacon())
633
+ requestDetails.hdrs[name] = value;
634
+ requestDetails.useHdrs = true;
635
+ }
636
+ });
637
+ }
638
+ else {
639
+ // Copy the pre-defined headers into the payload headers
640
+ requestDetails.hdrs = extend(requestDetails.hdrs, _headers);
641
+ requestDetails.useHdrs = (objKeys(requestDetails.hdrs).length > 0);
642
+ }
610
643
  _addRequestDetails(requestDetails, strClientId, "NO_AUTH", useHeaders);
611
644
  _addRequestDetails(requestDetails, strClientVersion, FullVersionString, useHeaders);
612
645
  var apiQsKeys = "";
@@ -659,7 +692,6 @@ var HttpManager = /** @class */ (function () {
659
692
  var requestDetails_1 = _buildRequestDetails(thePayload, useHeaders_1);
660
693
  useHeaders_1 = useHeaders_1 || requestDetails_1.useHdrs;
661
694
  var sendEventStart_1 = getTime();
662
- var strSendAttempt_1 = "sendAttempt";
663
695
  doPerf(_core, function () { return "HttpManager:_doPayloadSend"; }, function () {
664
696
  // Increment the send attempt count and add timings after packaging (So it's not serialized in the 1st attempt)
665
697
  for (var batchLp = 0; batchLp < thePayload.batches.length; batchLp++) {
@@ -673,7 +705,7 @@ var HttpManager = /** @class */ (function () {
673
705
  _setTimingValue(timings, "serializationStart", serializationStart);
674
706
  _setTimingValue(timings, "serializationCompleted", serializationCompleted);
675
707
  }
676
- telemetryItem[strSendAttempt_1] > 0 ? telemetryItem[strSendAttempt_1]++ : telemetryItem[strSendAttempt_1] = 1;
708
+ telemetryItem[strSendAttempt] > 0 ? telemetryItem[strSendAttempt]++ : telemetryItem[strSendAttempt] = 1;
677
709
  }
678
710
  }
679
711
  // Note: always sending this notification in a synchronous manner.
@@ -686,8 +718,12 @@ var HttpManager = /** @class */ (function () {
686
718
  urlString: requestDetails_1.url,
687
719
  headers: requestDetails_1.hdrs,
688
720
  _thePayload: thePayload,
689
- _sendReason: sendReason
721
+ _sendReason: sendReason,
722
+ timeout: _xhrTimeout
690
723
  };
724
+ if (!isUndefined(_disableXhrSync)) {
725
+ orgPayloadData.disableXhrSync = !!_disableXhrSync;
726
+ }
691
727
  // Only automatically add the following headers if already sending headers and we are not attempting to avoid an options call
692
728
  if (useHeaders_1) {
693
729
  if (!_hasHeader(orgPayloadData.headers, strCacheControl)) {
@@ -735,7 +771,9 @@ var HttpManager = /** @class */ (function () {
735
771
  var hookData_1 = {
736
772
  data: orgPayloadData.data,
737
773
  urlString: orgPayloadData.urlString,
738
- headers: extend({}, orgPayloadData.headers)
774
+ headers: extend({}, orgPayloadData.headers),
775
+ timeout: orgPayloadData.timeout,
776
+ disableXhrSync: orgPayloadData.disableXhrSync
739
777
  };
740
778
  var senderCalled_1 = false;
741
779
  doPerf(_core, function () { return "HttpManager:_doPayloadSend.sendHook"; }, function () {
@@ -809,12 +847,12 @@ var HttpManager = /** @class */ (function () {
809
847
  }
810
848
  // Disabling triple-equals rule to avoid httpOverrides from failing because they are returning a string value
811
849
  // tslint:disable-next-line:triple-equals
812
- if (status == 200) {
850
+ if (status == 200 || status == 204) {
813
851
  // Response was successfully sent
814
852
  reason = 200 /* Complete */;
815
853
  return;
816
854
  }
817
- if (!RetryPolicy.shouldRetryForStatus(status) || thePayload.numEvents <= 0) {
855
+ if (!retryPolicyShouldRetryForStatus(status) || thePayload.numEvents <= 0) {
818
856
  // Only retry for specific response codes and if there is still events after kill switch processing
819
857
  shouldRetry = false;
820
858
  }
@@ -826,7 +864,8 @@ var HttpManager = /** @class */ (function () {
826
864
  reason = 100 /* RequeueEvents */;
827
865
  var retryCount_1 = thePayload.retryCnt;
828
866
  if (thePayload.sendType === 0 /* Batched */) {
829
- if (retryCount_1 < maxRetries) {
867
+ // attempt to resend the entire batch
868
+ if (retryCount_1 < maxRequestRetriesBeforeBackoff) {
830
869
  isRetrying = true;
831
870
  _doAction(function () {
832
871
  // try to resend the same batches
@@ -837,10 +876,15 @@ var HttpManager = /** @class */ (function () {
837
876
  _outstandingRequests--;
838
877
  }
839
878
  _sendBatches(thePayload.batches, retryCount_1 + 1, thePayload.isTeardown, _isUnloading ? 2 /* SendBeacon */ : thePayload.sendType, 5 /* Retry */);
840
- }, _isUnloading, RetryPolicy.getMillisToBackoffForRetry(retryCount_1));
879
+ }, _isUnloading, retryPolicyGetMillisToBackoffForRetry(retryCount_1));
841
880
  }
842
881
  else {
843
882
  backOffTrans = true;
883
+ if (_isUnloading) {
884
+ // we are unloading so don't try and requeue the events otherwise let the events get requeued and resent during the backoff sending
885
+ // This will also cause the events to be purged based on the priority (if necessary)
886
+ reason = 8001 /* NonRetryableStatus */;
887
+ }
844
888
  }
845
889
  }
846
890
  }
@@ -946,7 +990,7 @@ var HttpManager = /** @class */ (function () {
946
990
  responseHandlers[i](responseText);
947
991
  }
948
992
  catch (e) {
949
- _postManager.diagLog().throwInternal(LoggingSeverity.CRITICAL, _ExtendedInternalMessageId.PostResponseHandler, "Response handler failed: " + e);
993
+ _throwInternal(_postManager.diagLog(), 1 /* CRITICAL */, 519 /* PostResponseHandler */, "Response handler failed: " + e);
950
994
  }
951
995
  }
952
996
  if (responseText) {
@@ -972,7 +1016,7 @@ var HttpManager = /** @class */ (function () {
972
1016
  theAction_1.call(actions, theBatches, batchReason, isSyncRequest_1, sendType);
973
1017
  }
974
1018
  catch (e) {
975
- _postManager.diagLog().throwInternal(LoggingSeverity.CRITICAL, _ExtendedInternalMessageId.NotificationException, "send request notification failed: " + e);
1019
+ _throwInternal(_postManager.diagLog(), 1 /* CRITICAL */, 74 /* NotificationException */, "send request notification failed: " + e);
976
1020
  }
977
1021
  }, sendSync || isSyncRequest_1, 0);
978
1022
  }, function () { return ({ batches: _createDebugBatches(theBatches), reason: batchReason, isSync: isSyncRequest_1, sendSync: sendSync, sendType: sendType }); }, !isSyncRequest_1);