@microsoft/1ds-post-js 4.1.1-nightly3.2403-03 → 4.1.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 (50) hide show
  1. package/bundle/es5/{ms.post-4.1.1-nightly3.2403-03.gbl.js → ms.post-4.1.1.gbl.js} +1145 -711
  2. package/bundle/es5/ms.post-4.1.1.gbl.js.map +1 -0
  3. package/bundle/es5/ms.post-4.1.1.gbl.min.js +7 -0
  4. package/bundle/es5/ms.post-4.1.1.gbl.min.js.map +1 -0
  5. package/bundle/es5/ms.post-4.1.1.integrity.json +46 -0
  6. package/bundle/es5/{ms.post-4.1.1-nightly3.2403-03.js → ms.post-4.1.1.js} +1145 -711
  7. package/bundle/es5/ms.post-4.1.1.js.map +1 -0
  8. package/bundle/es5/ms.post-4.1.1.min.js +7 -0
  9. package/bundle/es5/ms.post-4.1.1.min.js.map +1 -0
  10. package/bundle/es5/ms.post.gbl.js +1144 -710
  11. package/bundle/es5/ms.post.gbl.js.map +1 -1
  12. package/bundle/es5/ms.post.gbl.min.js +2 -2
  13. package/bundle/es5/ms.post.gbl.min.js.map +1 -1
  14. package/bundle/es5/ms.post.integrity.json +17 -17
  15. package/bundle/es5/ms.post.js +1144 -710
  16. package/bundle/es5/ms.post.js.map +1 -1
  17. package/bundle/es5/ms.post.min.js +2 -2
  18. package/bundle/es5/ms.post.min.js.map +1 -1
  19. package/dist/es5/ms.post.js +1142 -708
  20. package/dist/es5/ms.post.js.map +1 -1
  21. package/dist/es5/ms.post.min.js +2 -2
  22. package/dist/es5/ms.post.min.js.map +1 -1
  23. package/dist-es5/BatchNotificationActions.js +1 -1
  24. package/dist-es5/ClockSkewManager.js +1 -1
  25. package/dist-es5/DataModels.js +1 -1
  26. package/dist-es5/EventBatch.js +1 -1
  27. package/dist-es5/HttpManager.js +123 -279
  28. package/dist-es5/HttpManager.js.map +1 -1
  29. package/dist-es5/Index.js +1 -1
  30. package/dist-es5/InternalConstants.js +1 -1
  31. package/dist-es5/KillSwitch.js +3 -3
  32. package/dist-es5/KillSwitch.js.map +1 -1
  33. package/dist-es5/PostChannel.js +34 -26
  34. package/dist-es5/PostChannel.js.map +1 -1
  35. package/dist-es5/RetryPolicy.js +1 -1
  36. package/dist-es5/Serializer.js +1 -1
  37. package/dist-es5/TimeoutOverrideWrapper.js +1 -1
  38. package/dist-es5/__DynamicConstants.js +21 -25
  39. package/dist-es5/__DynamicConstants.js.map +1 -1
  40. package/dist-es5/typings/XDomainRequest.js +1 -1
  41. package/package.json +63 -66
  42. package/types/1ds-post-js.d.ts +1 -1
  43. package/types/1ds-post-js.namespaced.d.ts +1 -1
  44. package/bundle/es5/ms.post-4.1.1-nightly3.2403-03.gbl.js.map +0 -1
  45. package/bundle/es5/ms.post-4.1.1-nightly3.2403-03.gbl.min.js +0 -7
  46. package/bundle/es5/ms.post-4.1.1-nightly3.2403-03.gbl.min.js.map +0 -1
  47. package/bundle/es5/ms.post-4.1.1-nightly3.2403-03.integrity.json +0 -46
  48. package/bundle/es5/ms.post-4.1.1-nightly3.2403-03.js.map +0 -1
  49. package/bundle/es5/ms.post-4.1.1-nightly3.2403-03.min.js +0 -7
  50. package/bundle/es5/ms.post-4.1.1-nightly3.2403-03.min.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  /*
2
- * 1DS JS SDK POST plugin, 4.1.1-nightly3.2403-03
2
+ * 1DS JS SDK POST plugin, 4.1.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, 4.1.1-nightly3.2403-03
2
+ * 1DS JS SDK POST plugin, 4.1.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, 4.1.1-nightly3.2403-03
2
+ * 1DS JS SDK POST plugin, 4.1.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, 4.1.1-nightly3.2403-03
2
+ * 1DS JS SDK POST plugin, 4.1.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, 4.1.1-nightly3.2403-03
2
+ * 1DS JS SDK POST plugin, 4.1.1
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  * (Microsoft Internal Only)
5
5
  */
@@ -10,15 +10,15 @@ var _a;
10
10
  * @copyright Microsoft 2018-2020
11
11
  */
12
12
  import dynamicProto from "@microsoft/dynamicproto-js";
13
- import { FullVersionString, _throwInternal, _warnToConsole, arrForEach, dateNow, doPerf, dumpObj, extend, getCommonSchemaMetaData, getLocation, getNavigator, getTime, hasOwnProperty, isArray, isBeaconsSupported, isFetchSupported, isNullOrUndefined, isNumber, isReactNative, isString, isUndefined, isValueAssigned, isXhrSupported, objForEachKey, objKeys, onConfigChange, openXhr, strTrim, strUndefined, useXDomainRequest } from "@microsoft/1ds-core-js";
13
+ import { FullVersionString, SenderPostManager, _getAllResponseHeaders, _throwInternal, _warnToConsole, arrForEach, dateNow, doPerf, dumpObj, extend, getCommonSchemaMetaData, getNavigator, getResponseText, getTime, hasOwnProperty, isBeaconsSupported, isFetchSupported, isNullOrUndefined, isReactNative, isUndefined, isValueAssigned, objForEachKey, objKeys, onConfigChange, prependTransports, strUndefined } from "@microsoft/1ds-core-js";
14
14
  import { arrAppend } from "@nevware21/ts-utils";
15
15
  import { ClockSkewManager } from "./ClockSkewManager";
16
- import { DEFAULT_CACHE_CONTROL, DEFAULT_CONTENT_TYPE, STR_API_KEY, STR_AUTH_XTOKEN, STR_CACHE_CONTROL, STR_CLIENT_ID, STR_CLIENT_VERSION, STR_CONTENT_TYPE_HEADER, STR_DISABLED_PROPERTY_NAME, STR_DROPPED, STR_EMPTY, STR_KILL_DURATION_HEADER, STR_KILL_DURATION_SECONDS_HEADER, STR_KILL_TOKENS_HEADER, STR_MSA_DEVICE_TICKET, STR_MSFPC, STR_NO_RESPONSE_BODY, STR_OTHER, STR_POST_METHOD, STR_REQUEUE, STR_RESPONSE_FAIL, STR_SENDING, STR_TIME_DELTA_HEADER, STR_TIME_DELTA_TO_APPLY, STR_UPLOAD_TIME } from "./InternalConstants";
16
+ import { DEFAULT_CACHE_CONTROL, DEFAULT_CONTENT_TYPE, STR_API_KEY, STR_AUTH_XTOKEN, STR_CACHE_CONTROL, STR_CLIENT_ID, STR_CLIENT_VERSION, STR_CONTENT_TYPE_HEADER, STR_DROPPED, STR_EMPTY, STR_KILL_DURATION_HEADER, STR_KILL_TOKENS_HEADER, STR_MSA_DEVICE_TICKET, STR_MSFPC, STR_NO_RESPONSE_BODY, STR_OTHER, STR_REQUEUE, STR_RESPONSE_FAIL, STR_SENDING, STR_TIME_DELTA_HEADER, STR_TIME_DELTA_TO_APPLY, STR_UPLOAD_TIME } from "./InternalConstants";
17
17
  import { KillSwitch } from "./KillSwitch";
18
18
  import { retryPolicyGetMillisToBackoffForRetry, retryPolicyShouldRetryForStatus } from "./RetryPolicy";
19
19
  import { Serializer } from "./Serializer";
20
20
  import { createTimeoutWrapper } from "./TimeoutOverrideWrapper";
21
- import { _DYN_ADD_HEADER, _DYN_ALLOW_REQUEST_SENDIN0, _DYN_ALWAYS_USE_XHR_OVERR7, _DYN_AVOID_OPTIONS, _DYN_BATCHES, _DYN_CAN_SEND_REQUEST, _DYN_CLEAR_TIMEOUT_OVERRI3, _DYN_CONCAT, _DYN_COUNT, _DYN_CREATE_PAYLOAD, _DYN_DATA, _DYN_DISABLE_EVENT_TIMING5, _DYN_DISABLE_FETCH_KEEP_A6, _DYN_DISABLE_XHR_SYNC, _DYN_ENABLE_COMPOUND_KEY, _DYN_EVENTS, _DYN_EXCLUDE_CS_META_DATA, _DYN_FIRST_REQUEST_SENT, _DYN_GET_ALL_RESPONSE_HEA10, _DYN_GET_CLOCK_SKEW_HEADE2, _DYN_GET_OFFLINE_REQUEST_9, _DYN_GET_RESPONSE_HEADER, _DYN_GET_WPARAM, _DYN_HDRS, _DYN_HEADERS, _DYN_INITIALIZE, _DYN_IS_BEACON, _DYN_IS_COMPLETELY_IDLE, _DYN_IS_SYNC, _DYN_IS_TEARDOWN, _DYN_I_KEY, _DYN_LENGTH, _DYN_ONTIMEOUT, _DYN_OVERRIDE_ENDPOINT_UR4, _DYN_PAYLOAD_PREPROCESSOR, _DYN_PUSH, _DYN_SEND_POST, _DYN_SEND_QUEUED_REQUESTS, _DYN_SEND_SYNCHRONOUS_BAT11, _DYN_SEND_TYPE, _DYN_SERIALIZE_OFFLINE_EV8, _DYN_SET_CLOCK_SKEW, _DYN_SET_KILL_SWITCH_TENA12, _DYN_SET_TIMEOUT_OVERRIDE, _DYN_SET_UNLOADING, _DYN_SHOULD_ADD_CLOCK_SKE1, _DYN_SPLICE, _DYN_SPLIT, _DYN_STRINGIFY_OBJECTS, _DYN_TIMEOUT, _DYN_TIMINGS, _DYN_TO_LOWER_CASE, _DYN_UNLOAD_TRANSPORTS, _DYN_URL_STRING, _DYN_USE_HDRS, _DYN_USE_SEND_BEACON, _DYN__BACK_OFF_TRANSMISSI13, _DYN__SEND_REASON, _DYN__THE_PAYLOAD, _DYN__TRANSPORT } from "./__DynamicConstants";
21
+ import { _DYN_ADD_HEADER, _DYN_ADD_NO_RESPONSE, _DYN_ALLOW_REQUEST_SENDIN0, _DYN_ALWAYS_USE_XHR_OVERR7, _DYN_AVOID_OPTIONS, _DYN_BATCHES, _DYN_CAN_SEND_REQUEST, _DYN_CLEAR_TIMEOUT_OVERRI3, _DYN_CONCAT, _DYN_COUNT, _DYN_CREATE_PAYLOAD, _DYN_DATA, _DYN_DISABLE_EVENT_TIMING5, _DYN_DISABLE_FETCH_KEEP_A6, _DYN_DISABLE_XHR_SYNC, _DYN_ENABLE_COMPOUND_KEY, _DYN_EVENTS, _DYN_EXCLUDE_CS_META_DATA, _DYN_FIRST_REQUEST_SENT, _DYN_GET_CLOCK_SKEW_HEADE2, _DYN_GET_OFFLINE_REQUEST_9, _DYN_GET_WPARAM, _DYN_HDRS, _DYN_HEADERS, _DYN_INITIALIZE, _DYN_IS_BEACON, _DYN_IS_COMPLETELY_IDLE, _DYN_IS_SYNC, _DYN_IS_TEARDOWN, _DYN_I_KEY, _DYN_LENGTH, _DYN_OVERRIDE_ENDPOINT_UR4, _DYN_PAYLOAD_PREPROCESSOR, _DYN_PUSH, _DYN_SEND_QUEUED_REQUESTS, _DYN_SEND_SYNCHRONOUS_BAT10, _DYN_SEND_TYPE, _DYN_SERIALIZE_OFFLINE_EV8, _DYN_SET_CLOCK_SKEW, _DYN_SET_KILL_SWITCH_TENA11, _DYN_SET_TIMEOUT_OVERRIDE, _DYN_SET_UNLOADING, _DYN_SHOULD_ADD_CLOCK_SKE1, _DYN_SPLICE, _DYN_SPLIT, _DYN_STRINGIFY_OBJECTS, _DYN_TIMINGS, _DYN_TO_LOWER_CASE, _DYN_UNLOAD_TRANSPORTS, _DYN_URL_STRING, _DYN_USE_HDRS, _DYN_USE_SEND_BEACON, _DYN__BACK_OFF_TRANSMISSI12, _DYN__SEND_REASON, _DYN__THE_PAYLOAD, _DYN__TRANSPORT } from "./__DynamicConstants";
22
22
  var strSendAttempt = "sendAttempt";
23
23
  var _noResponseQs = "&" + STR_NO_RESPONSE_BODY + "=true";
24
24
  var UrlQueryString = "?cors=true&" + STR_CONTENT_TYPE_HEADER[_DYN_TO_LOWER_CASE /* @min:%2etoLowerCase */]() + "=" + DEFAULT_CONTENT_TYPE;
@@ -47,15 +47,6 @@ _addCollectorHeaderQsMapping(STR_API_KEY, STR_API_KEY);
47
47
  _addCollectorHeaderQsMapping(STR_TIME_DELTA_TO_APPLY, STR_TIME_DELTA_TO_APPLY);
48
48
  _addCollectorHeaderQsMapping(STR_UPLOAD_TIME, STR_UPLOAD_TIME);
49
49
  _addCollectorHeaderQsMapping(STR_AUTH_XTOKEN, STR_AUTH_XTOKEN);
50
- function _getResponseText(xhr) {
51
- try {
52
- return xhr.responseText;
53
- }
54
- catch (e) {
55
- // Best effort, as XHR may throw while XDR wont so just ignore
56
- }
57
- return STR_EMPTY;
58
- }
59
50
  function _hasHeader(headers, header) {
60
51
  var hasHeader = false;
61
52
  if (headers && header) {
@@ -85,17 +76,6 @@ function _addRequestDetails(details, name, value, useHeaders) {
85
76
  }
86
77
  }
87
78
  }
88
- function _prependTransports(theTransports, newTransports) {
89
- if (newTransports) {
90
- if (isNumber(newTransports)) {
91
- theTransports = [newTransports][_DYN_CONCAT /* @min:%2econcat */](theTransports);
92
- }
93
- else if (isArray(newTransports)) {
94
- theTransports = newTransports[_DYN_CONCAT /* @min:%2econcat */](theTransports);
95
- }
96
- }
97
- return theTransports;
98
- }
99
79
  function _addQueryStringParameter(qsParams, name, value) {
100
80
  for (var i = 0; i < qsParams[_DYN_LENGTH /* @min:%2elength */]; i++) {
101
81
  if (qsParams[i].name === name) {
@@ -156,6 +136,7 @@ var HttpManager = /** @class */ (function () {
156
136
  var _isInitialized;
157
137
  var _timeoutWrapper;
158
138
  var _excludeCsMetaData;
139
+ var _sendPostMgr;
159
140
  dynamicProto(HttpManager, this, function (_self) {
160
141
  _initDefaults();
161
142
  var _sendCredentials = true;
@@ -193,7 +174,7 @@ var HttpManager = /** @class */ (function () {
193
174
  _xhrTimeout = channelConfig.xhrTimeout;
194
175
  _disableXhrSync = !!channelConfig[_DYN_DISABLE_XHR_SYNC /* @min:%2edisableXhrSync */];
195
176
  _disableFetchKeepAlive = !!channelConfig[_DYN_DISABLE_FETCH_KEEP_A6 /* @min:%2edisableFetchKeepAlive */];
196
- _addNoResponse = channelConfig.addNoResponse !== false;
177
+ _addNoResponse = channelConfig[_DYN_ADD_NO_RESPONSE /* @min:%2eaddNoResponse */] !== false;
197
178
  _excludeCsMetaData = !!channelConfig[_DYN_EXCLUDE_CS_META_DATA /* @min:%2eexcludeCsMetaData */];
198
179
  if (!!core.getPlugin("LocalStorage")) {
199
180
  // Always disable fetch keep alive when persisten storage is available
@@ -204,17 +185,27 @@ var HttpManager = /** @class */ (function () {
204
185
  if (!isNullOrUndefined(channelConfig[_DYN_USE_SEND_BEACON /* @min:%2euseSendBeacon */])) {
205
186
  _useBeacons = !!channelConfig[_DYN_USE_SEND_BEACON /* @min:%2euseSendBeacon */];
206
187
  }
188
+ var sendPostConfig = _getSendPostMgrConfig();
189
+ // only init it once
190
+ if (!_sendPostMgr) {
191
+ _sendPostMgr = new SenderPostManager();
192
+ _sendPostMgr[_DYN_INITIALIZE /* @min:%2einitialize */](sendPostConfig, _logger);
193
+ }
194
+ else {
195
+ _sendPostMgr.SetConfig(sendPostConfig);
196
+ }
207
197
  var syncHttpInterface = httpInterface;
208
198
  var beaconHttpInterface = channelConfig[_DYN_ALWAYS_USE_XHR_OVERR7 /* @min:%2ealwaysUseXhrOverride */] ? httpInterface : null;
209
199
  var fetchSyncHttpInterface = channelConfig[_DYN_ALWAYS_USE_XHR_OVERR7 /* @min:%2ealwaysUseXhrOverride */] ? httpInterface : null;
210
200
  var beaconUnloadTransports = [3 /* TransportType.Beacon */, 2 /* TransportType.Fetch */];
211
201
  if (!httpInterface) {
212
202
  _customHttpInterface = false;
213
- var location_1 = getLocation();
214
- if (location_1 && location_1.protocol && location_1.protocol[_DYN_TO_LOWER_CASE /* @min:%2etoLowerCase */]() === "file:") {
215
- // Special case where a local html file fails with a CORS error on Chromium browsers
216
- _sendCredentials = false;
217
- }
203
+ // this is handled in SendPostManager now
204
+ // let location = getLocation();
205
+ // if (location && location.protocol && location.protocol.toLowerCase() === "file:") {
206
+ // // Special case where a local html file fails with a CORS error on Chromium browsers
207
+ // _sendCredentials = false;
208
+ // }
218
209
  var theTransports = [];
219
210
  if (isReactNative()) {
220
211
  // Use Fetch or XDR/XHR
@@ -226,7 +217,7 @@ var HttpManager = /** @class */ (function () {
226
217
  theTransports = [1 /* TransportType.Xhr */, 2 /* TransportType.Fetch */, 3 /* TransportType.Beacon */];
227
218
  }
228
219
  // Prefix any user requested transport(s) values
229
- theTransports = _prependTransports(theTransports, channelConfig.transports);
220
+ theTransports = prependTransports(theTransports, channelConfig.transports);
230
221
  httpInterface = _getSenderInterface(theTransports, false);
231
222
  if (!httpInterface) {
232
223
  _warnToConsole(_logger, "No available transport to send events");
@@ -235,7 +226,7 @@ var HttpManager = /** @class */ (function () {
235
226
  }
236
227
  if (!beaconHttpInterface) {
237
228
  // Allow overriding the usage of sendBeacon
238
- beaconUnloadTransports = _prependTransports(beaconUnloadTransports, channelConfig[_DYN_UNLOAD_TRANSPORTS /* @min:%2eunloadTransports */]);
229
+ beaconUnloadTransports = prependTransports(beaconUnloadTransports, channelConfig[_DYN_UNLOAD_TRANSPORTS /* @min:%2eunloadTransports */]);
239
230
  beaconHttpInterface = _getSenderInterface(beaconUnloadTransports, true);
240
231
  }
241
232
  _canHaveReducedPayload = !_customHttpInterface && ((_useBeacons && isBeaconsSupported()) || (!_disableFetchKeepAlive && isFetchSupported(true)));
@@ -261,80 +252,70 @@ var HttpManager = /** @class */ (function () {
261
252
  };
262
253
  };
263
254
  _self[_DYN_SERIALIZE_OFFLINE_EV8 /* @min:%2eserializeOfflineEvt */] = function (evt) {
264
- return _serializer.getEventBlob(evt);
255
+ try {
256
+ if (_serializer) {
257
+ return _serializer.getEventBlob(evt);
258
+ }
259
+ }
260
+ catch (e) {
261
+ // eslint-disable-next-line no-empty
262
+ }
263
+ return STR_EMPTY;
265
264
  };
266
265
  _self[_DYN_GET_OFFLINE_REQUEST_9 /* @min:%2egetOfflineRequestDetails */] = function () {
267
- var payload = _serializer[_DYN_CREATE_PAYLOAD /* @min:%2ecreatePayload */](0, false, false, false, 1 /* SendRequestReason.NormalSchedule */, 0 /* EventSendType.Batched */);
268
- return _buildRequestDetails(payload, _useHeaders);
266
+ try {
267
+ var payload = _serializer && _serializer[_DYN_CREATE_PAYLOAD /* @min:%2ecreatePayload */](0, false, false, false, 1 /* SendRequestReason.NormalSchedule */, 0 /* EventSendType.Batched */);
268
+ return _buildRequestDetails(payload, _useHeaders);
269
+ }
270
+ catch (e) {
271
+ // eslint-disable-next-line no-empty
272
+ }
273
+ return null;
269
274
  };
270
275
  // Special internal method to allow the DebugPlugin to hook embedded objects
271
276
  function _getSenderInterface(transports, syncSupport) {
272
- var transportType = 0 /* TransportType.NotSet */;
273
- var sendPostFunc = null;
274
- var lp = 0;
275
- while (sendPostFunc == null && lp < transports[_DYN_LENGTH /* @min:%2elength */]) {
276
- transportType = transports[lp];
277
- if (transportType === 1 /* TransportType.Xhr */) {
278
- if (useXDomainRequest()) {
279
- sendPostFunc = _xdrSendPost;
280
- }
281
- else if (isXhrSupported()) {
282
- sendPostFunc = _xhrSendPost;
283
- }
284
- }
285
- else if (transportType === 2 /* TransportType.Fetch */ && isFetchSupported(syncSupport) && (!syncSupport || (syncSupport && !_disableFetchKeepAlive))) {
286
- sendPostFunc = _fetchSendPost;
287
- }
288
- else if (_useBeacons && transportType === 3 /* TransportType.Beacon */ && isBeaconsSupported()) {
289
- sendPostFunc = _beaconSendPost;
290
- }
291
- lp++;
277
+ try {
278
+ return _sendPostMgr && _sendPostMgr.getSenderInst(transports, syncSupport);
292
279
  }
293
- if (sendPostFunc) {
294
- return {
295
- _transport: transportType,
296
- _isSync: syncSupport,
297
- sendPOST: sendPostFunc
298
- };
280
+ catch (e) {
281
+ // eslint-disable-next-line no-empty
299
282
  }
300
283
  return null;
301
284
  }
302
285
  _self["_getDbgPlgTargets"] = function () {
303
286
  return [_sendInterfaces[0 /* EventSendType.Batched */], _killSwitch, _serializer, _sendInterfaces];
304
287
  };
305
- function _xdrSendPost(payload, oncomplete, sync) {
306
- // It doesn't support custom headers, so no action is taken with current requestHeaders
307
- var xdr = new XDomainRequest();
308
- xdr.open(STR_POST_METHOD, payload[_DYN_URL_STRING /* @min:%2eurlString */]);
309
- if (payload[_DYN_TIMEOUT /* @min:%2etimeout */]) {
310
- xdr[_DYN_TIMEOUT /* @min:%2etimeout */] = payload[_DYN_TIMEOUT /* @min:%2etimeout */];
311
- }
312
- // can't get the status code in xdr.
313
- xdr.onload = function () {
314
- // we will assume onload means the request succeeded.
315
- var response = _getResponseText(xdr);
316
- _doOnComplete(oncomplete, 200, {}, response);
317
- _handleCollectorResponse(response);
318
- };
319
- // we will assume onerror means we need to drop the events.
320
- xdr.onerror = function () {
321
- _doOnComplete(oncomplete, 400, {});
322
- };
323
- // we will assume ontimeout means we need to retry the events.
324
- xdr[_DYN_ONTIMEOUT /* @min:%2eontimeout */] = function () {
325
- _doOnComplete(oncomplete, 500, {});
326
- };
327
- // https://cypressnorth.com/web-programming-and-development/internet-explorer-aborting-ajax-requests-fixed/
328
- // tslint:disable-next-line:no-empty
329
- xdr.onprogress = function () { };
330
- if (sync) {
331
- xdr.send(payload[_DYN_DATA /* @min:%2edata */]);
288
+ function _getSendPostMgrConfig() {
289
+ try {
290
+ var onCompleteFuncs = {
291
+ xdrOnComplete: _xdrOncomplete,
292
+ fetchOnComplete: _fetchOnComplete,
293
+ xhrOnComplete: _xhrOnComplete,
294
+ beaconOnRetry: _onBeaconRetry
295
+ };
296
+ var config = {
297
+ enableSendPromise: false,
298
+ isOneDs: true,
299
+ disableCredentials: !_sendCredentials,
300
+ disableXhr: false,
301
+ disableBeacon: !_useBeacons,
302
+ disableBeaconSync: !_useBeacons,
303
+ disableFetchKeepAlive: _disableFetchKeepAlive,
304
+ timeWrapper: _timeoutWrapper,
305
+ addNoResponse: _addNoResponse,
306
+ senderOnCompleteCallBack: onCompleteFuncs
307
+ };
308
+ return config;
332
309
  }
333
- else {
334
- _timeoutWrapper.set(function () {
335
- xdr.send(payload[_DYN_DATA /* @min:%2edata */]);
336
- }, 0);
310
+ catch (e) {
311
+ // eslint-disable-next-line no-empty
337
312
  }
313
+ return null;
314
+ }
315
+ function _xdrOncomplete(xdr, oncomplete, payload) {
316
+ var response = getResponseText(xdr);
317
+ _doOnComplete(oncomplete, 200, {}, response);
318
+ _handleCollectorResponse(response);
338
319
  }
339
320
  function _initDefaults() {
340
321
  var undefValue;
@@ -369,136 +350,26 @@ var HttpManager = /** @class */ (function () {
369
350
  _isInitialized = false;
370
351
  _timeoutWrapper = createTimeoutWrapper();
371
352
  _excludeCsMetaData = false;
353
+ _sendPostMgr = null;
372
354
  }
373
- function _fetchSendPost(payload, oncomplete, sync) {
374
- var _a;
375
- var theUrl = payload[_DYN_URL_STRING /* @min:%2eurlString */];
376
- var ignoreResponse = false;
377
- var responseHandled = false;
378
- var requestInit = (_a = {
379
- body: payload[_DYN_DATA /* @min:%2edata */],
380
- method: STR_POST_METHOD
381
- },
382
- _a[STR_DISABLED_PROPERTY_NAME] = true,
383
- _a);
384
- if (sync) {
385
- requestInit.keepalive = true;
386
- if (payload[_DYN__SEND_REASON /* @min:%2e_sendReason */] === 2 /* SendRequestReason.Unload */) {
387
- // As a sync request (during unload), it is unlikely that we will get a chance to process the response so
388
- // just like beacon send assume that the events have been accepted and processed
389
- ignoreResponse = true;
390
- if (_addNoResponse) {
391
- theUrl += _noResponseQs;
392
- }
393
- }
394
- }
395
- if (_sendCredentials) {
396
- // Don't send credentials when URL is file://
397
- requestInit.credentials = "include";
398
- }
399
- // Only add headers if there are headers to add, due to issue with some polyfills
400
- if (payload.headers && objKeys(payload.headers)[_DYN_LENGTH /* @min:%2elength */] > 0) {
401
- requestInit[_DYN_HEADERS /* @min:%2eheaders */] = payload[_DYN_HEADERS /* @min:%2eheaders */];
402
- }
355
+ function _fetchOnComplete(response, onComplete, resValue, payload) {
403
356
  var handleResponse = function (status, headerMap, responseText) {
404
- if (!responseHandled) {
405
- responseHandled = true;
406
- _doOnComplete(oncomplete, status, headerMap, responseText);
407
- _handleCollectorResponse(responseText);
408
- }
409
- };
410
- var handleError = function () {
411
- // In case there is an error in the request. Set the status to 0
412
- // so that the events can be retried later.
413
- if (!responseHandled) {
414
- responseHandled = true;
415
- _doOnComplete(oncomplete, 0, {});
416
- }
357
+ _doOnComplete(onComplete, status, headerMap, responseText);
358
+ _handleCollectorResponse(responseText);
417
359
  };
418
- fetch(theUrl, requestInit).then(function (response) {
419
- var headerMap = {};
420
- var responseText = STR_EMPTY;
421
- var headers = response[_DYN_HEADERS /* @min:%2eheaders */];
422
- if (headers) {
423
- headers["forEach"](function (value, name) {
424
- headerMap[name] = value;
425
- });
426
- }
427
- if (response.body) {
428
- response.text().then(function (text) {
429
- responseText = text;
430
- handleResponse(response.status, headerMap, responseText);
431
- }, handleError);
432
- }
433
- else {
434
- handleResponse(response.status, headerMap, "");
435
- }
436
- }).catch(handleError);
437
- if (ignoreResponse && !responseHandled) {
438
- // Assume success during unload processing
439
- responseHandled = true;
440
- _doOnComplete(oncomplete, 200, {});
441
- }
442
- if (!responseHandled && payload[_DYN_TIMEOUT /* @min:%2etimeout */] > 0) {
443
- // Simulate timeout
444
- _timeoutWrapper.set(function () {
445
- if (!responseHandled) {
446
- // Assume a 500 response (which will cause a retry)
447
- responseHandled = true;
448
- _doOnComplete(oncomplete, 500, {});
449
- }
450
- }, payload[_DYN_TIMEOUT /* @min:%2etimeout */]);
360
+ var headerMap = {};
361
+ var headers = response[_DYN_HEADERS /* @min:%2eheaders */];
362
+ if (headers) {
363
+ headers["forEach"](function (value, name) {
364
+ headerMap[name] = value;
365
+ });
451
366
  }
367
+ handleResponse(response.status, headerMap, resValue || STR_EMPTY);
452
368
  }
453
- function _xhrSendPost(payload, oncomplete, sync) {
454
- var theUrl = payload[_DYN_URL_STRING /* @min:%2eurlString */];
455
- function _appendHeader(theHeaders, xhr, name) {
456
- if (!theHeaders[name] && xhr && xhr[_DYN_GET_RESPONSE_HEADER /* @min:%2egetResponseHeader */]) {
457
- var value = xhr[_DYN_GET_RESPONSE_HEADER /* @min:%2egetResponseHeader */](name);
458
- if (value) {
459
- theHeaders[name] = strTrim(value);
460
- }
461
- }
462
- return theHeaders;
463
- }
464
- function _getAllResponseHeaders(xhr) {
465
- var theHeaders = {};
466
- if (!xhr[_DYN_GET_ALL_RESPONSE_HEA10 /* @min:%2egetAllResponseHeaders */]) {
467
- // Firefox 2-63 doesn't have getAllResponseHeaders function but it does have getResponseHeader
468
- // Only call these if getAllResponseHeaders doesn't exist, otherwise we can get invalid response errors
469
- // as collector is not currently returning the correct header to allow JS to access these headers
470
- theHeaders = _appendHeader(theHeaders, xhr, STR_TIME_DELTA_HEADER);
471
- theHeaders = _appendHeader(theHeaders, xhr, STR_KILL_DURATION_HEADER);
472
- theHeaders = _appendHeader(theHeaders, xhr, STR_KILL_DURATION_SECONDS_HEADER);
473
- }
474
- else {
475
- theHeaders = _convertAllHeadersToMap(xhr[_DYN_GET_ALL_RESPONSE_HEA10 /* @min:%2egetAllResponseHeaders */]());
476
- }
477
- return theHeaders;
478
- }
479
- function xhrComplete(xhr, responseTxt) {
480
- _doOnComplete(oncomplete, xhr.status, _getAllResponseHeaders(xhr), responseTxt);
481
- }
482
- if (sync && payload[_DYN_DISABLE_XHR_SYNC /* @min:%2edisableXhrSync */]) {
483
- sync = false;
484
- }
485
- var xhrRequest = openXhr(STR_POST_METHOD, theUrl, _sendCredentials, true, sync, payload[_DYN_TIMEOUT /* @min:%2etimeout */]);
486
- // Set custom headers (e.g. gzip) here (after open())
487
- objForEachKey(payload[_DYN_HEADERS /* @min:%2eheaders */], function (name, value) {
488
- xhrRequest.setRequestHeader(name, value);
489
- });
490
- xhrRequest.onload = function () {
491
- var response = _getResponseText(xhrRequest);
492
- xhrComplete(xhrRequest, response);
493
- _handleCollectorResponse(response);
494
- };
495
- xhrRequest.onerror = function () {
496
- xhrComplete(xhrRequest);
497
- };
498
- xhrRequest[_DYN_ONTIMEOUT /* @min:%2eontimeout */] = function () {
499
- xhrComplete(xhrRequest);
500
- };
501
- xhrRequest.send(payload[_DYN_DATA /* @min:%2edata */]);
369
+ function _xhrOnComplete(request, oncomplete, payload) {
370
+ var response = getResponseText(request);
371
+ _doOnComplete(oncomplete, request.status, _getAllResponseHeaders(request, true), response);
372
+ _handleCollectorResponse(response);
502
373
  }
503
374
  function _doOnComplete(oncomplete, status, headers, response) {
504
375
  try {
@@ -508,7 +379,7 @@ var HttpManager = /** @class */ (function () {
508
379
  _throwInternal(_logger, 2 /* eLoggingSeverity.WARNING */, 518 /* _eExtendedInternalMessageId.SendPostOnCompleteFailure */, dumpObj(e));
509
380
  }
510
381
  }
511
- function _beaconSendPost(payload, oncomplete, sync) {
382
+ function _onBeaconRetry(payload, onComplete, canSend) {
512
383
  // Custom headers not supported in sendBeacon payload.headers would be ignored
513
384
  var internalPayloadData = payload;
514
385
  var status = 200;
@@ -516,50 +387,48 @@ var HttpManager = /** @class */ (function () {
516
387
  var theUrl = payload[_DYN_URL_STRING /* @min:%2eurlString */] + (_addNoResponse ? _noResponseQs : STR_EMPTY);
517
388
  try {
518
389
  var nav_1 = getNavigator();
519
- if (!nav_1.sendBeacon(theUrl, payload[_DYN_DATA /* @min:%2edata */])) {
520
- if (thePayload) {
521
- var persistStorage = !!_core.getPlugin("LocalStorage");
522
- // Failed to send entire payload so try and split data and try to send as much events as possible
523
- var droppedBatches_1 = [];
524
- var sentBatches_1 = [];
525
- arrForEach(thePayload[_DYN_BATCHES /* @min:%2ebatches */], function (theBatch) {
526
- if (droppedBatches_1 && theBatch && theBatch[_DYN_COUNT /* @min:%2ecount */]() > 0) {
527
- var theEvents = theBatch[_DYN_EVENTS /* @min:%2eevents */]();
528
- for (var lp = 0; lp < theEvents[_DYN_LENGTH /* @min:%2elength */]; lp++) {
529
- if (!nav_1.sendBeacon(theUrl, _serializer.getEventBlob(theEvents[lp]))) {
530
- // Can't send anymore, so split the batch and drop the rest
531
- droppedBatches_1[_DYN_PUSH /* @min:%2epush */](theBatch[_DYN_SPLIT /* @min:%2esplit */](lp));
532
- break;
533
- }
534
- else {
535
- sentBatches_1[_DYN_PUSH /* @min:%2epush */](theBatch[lp]);
536
- }
390
+ if (thePayload) {
391
+ var persistStorage = !!_core.getPlugin("LocalStorage");
392
+ // Failed to send entire payload so try and split data and try to send as much events as possible
393
+ var droppedBatches_1 = [];
394
+ var sentBatches_1 = [];
395
+ arrForEach(thePayload[_DYN_BATCHES /* @min:%2ebatches */], function (theBatch) {
396
+ if (droppedBatches_1 && theBatch && theBatch[_DYN_COUNT /* @min:%2ecount */]() > 0) {
397
+ var theEvents = theBatch[_DYN_EVENTS /* @min:%2eevents */]();
398
+ for (var lp = 0; lp < theEvents[_DYN_LENGTH /* @min:%2elength */]; lp++) {
399
+ if (!nav_1.sendBeacon(theUrl, _serializer.getEventBlob(theEvents[lp]))) {
400
+ // Can't send anymore, so split the batch and drop the rest
401
+ droppedBatches_1[_DYN_PUSH /* @min:%2epush */](theBatch[_DYN_SPLIT /* @min:%2esplit */](lp));
402
+ break;
403
+ }
404
+ else {
405
+ sentBatches_1[_DYN_PUSH /* @min:%2epush */](theBatch[lp]);
537
406
  }
538
407
  }
539
- else {
540
- // Remove all of the events from the existing batch in the payload as the copy includes the original
541
- droppedBatches_1[_DYN_PUSH /* @min:%2epush */](theBatch[_DYN_SPLIT /* @min:%2esplit */](0));
542
- }
543
- });
544
- if (sentBatches_1[_DYN_LENGTH /* @min:%2elength */] > 0) {
545
- // Update the payload with the sent batches
546
- thePayload.sentEvts = sentBatches_1;
547
408
  }
548
- if (!persistStorage) {
549
- _sendBatchesNotification(droppedBatches_1, 8003 /* EventBatchNotificationReason.SizeLimitExceeded */, thePayload[_DYN_SEND_TYPE /* @min:%2esendType */], true);
409
+ else {
410
+ // Remove all of the events from the existing batch in the payload as the copy includes the original
411
+ droppedBatches_1[_DYN_PUSH /* @min:%2epush */](theBatch[_DYN_SPLIT /* @min:%2esplit */](0));
550
412
  }
413
+ });
414
+ if (sentBatches_1[_DYN_LENGTH /* @min:%2elength */] > 0) {
415
+ // Update the payload with the sent batches
416
+ thePayload.sentEvts = sentBatches_1;
551
417
  }
552
- else {
553
- status = 0;
418
+ if (!persistStorage) {
419
+ _sendBatchesNotification(droppedBatches_1, 8003 /* EventBatchNotificationReason.SizeLimitExceeded */, thePayload[_DYN_SEND_TYPE /* @min:%2esendType */], true);
554
420
  }
555
421
  }
422
+ else {
423
+ status = 0;
424
+ }
556
425
  }
557
426
  catch (ex) {
558
427
  _warnToConsole(_logger, "Failed to send telemetry using sendBeacon API. Ex:" + dumpObj(ex));
559
428
  status = 0;
560
429
  }
561
430
  finally {
562
- _doOnComplete(oncomplete, status, {}, STR_EMPTY);
431
+ _doOnComplete(onComplete, status, {}, STR_EMPTY);
563
432
  }
564
433
  }
565
434
  function _isBeaconPayload(sendType) {
@@ -642,7 +511,7 @@ var HttpManager = /** @class */ (function () {
642
511
  * @param batch - The request to be sent.
643
512
  * @param sendReason - The token used to send the request.
644
513
  */
645
- _self[_DYN_SEND_SYNCHRONOUS_BAT11 /* @min:%2esendSynchronousBatch */] = function (batch, sendType, sendReason) {
514
+ _self[_DYN_SEND_SYNCHRONOUS_BAT10 /* @min:%2esendSynchronousBatch */] = function (batch, sendType, sendReason) {
646
515
  // This will not take into account the max connections restriction. Since this is sync, we can
647
516
  // only send one of this request at a time and thus should not worry about multiple connections
648
517
  // being used to send synchronous events.
@@ -885,7 +754,7 @@ var HttpManager = /** @class */ (function () {
885
754
  };
886
755
  var isSync = thePayload[_DYN_IS_TEARDOWN /* @min:%2eisTeardown */] || thePayload[_DYN_IS_SYNC /* @min:%2eisSync */];
887
756
  try {
888
- sendInterface_1[_DYN_SEND_POST /* @min:%2esendPOST */](payload, onComplete, isSync);
757
+ sendInterface_1.sendPOST(payload, onComplete, isSync);
889
758
  if (_sendListener) {
890
759
  // Send the original payload to the listener
891
760
  _sendListener(orgPayloadData, payload, isSync, thePayload[_DYN_IS_BEACON /* @min:%2eisBeacon */]);
@@ -913,7 +782,7 @@ var HttpManager = /** @class */ (function () {
913
782
  data: orgPayloadData[_DYN_DATA /* @min:%2edata */],
914
783
  urlString: orgPayloadData[_DYN_URL_STRING /* @min:%2eurlString */],
915
784
  headers: extend({}, orgPayloadData[_DYN_HEADERS /* @min:%2eheaders */]),
916
- timeout: orgPayloadData[_DYN_TIMEOUT /* @min:%2etimeout */],
785
+ timeout: orgPayloadData.timeout,
917
786
  disableXhrSync: orgPayloadData[_DYN_DISABLE_XHR_SYNC /* @min:%2edisableXhrSync */],
918
787
  disableFetchKeepAlive: orgPayloadData[_DYN_DISABLE_FETCH_KEEP_A6 /* @min:%2edisableFetchKeepAlive */]
919
788
  };
@@ -973,7 +842,7 @@ var HttpManager = /** @class */ (function () {
973
842
  if (headers) {
974
843
  _clockSkewManager[_DYN_SET_CLOCK_SKEW /* @min:%2esetClockSkew */](headers[STR_TIME_DELTA_HEADER]);
975
844
  var killDuration = headers[STR_KILL_DURATION_HEADER] || headers["kill-duration-seconds"];
976
- arrForEach(_killSwitch[_DYN_SET_KILL_SWITCH_TENA12 /* @min:%2esetKillSwitchTenants */](headers[STR_KILL_TOKENS_HEADER], killDuration), function (killToken) {
845
+ arrForEach(_killSwitch[_DYN_SET_KILL_SWITCH_TENA11 /* @min:%2esetKillSwitchTenants */](headers[STR_KILL_TOKENS_HEADER], killDuration), function (killToken) {
977
846
  arrForEach(thePayload[_DYN_BATCHES /* @min:%2ebatches */], function (theBatch) {
978
847
  if (theBatch[_DYN_I_KEY /* @min:%2eiKey */]() === killToken) {
979
848
  // Make sure we have initialized the array
@@ -1045,7 +914,7 @@ var HttpManager = /** @class */ (function () {
1045
914
  try {
1046
915
  if (backOffTrans) {
1047
916
  // Slow down the transmission requests
1048
- _postManager[_DYN__BACK_OFF_TRANSMISSI13 /* @min:%2e_backOffTransmission */]();
917
+ _postManager[_DYN__BACK_OFF_TRANSMISSI12 /* @min:%2e_backOffTransmission */]();
1049
918
  }
1050
919
  var theBatches = thePayload[_DYN_BATCHES /* @min:%2ebatches */];
1051
920
  if (batchReason === 200 /* EventBatchNotificationReason.Complete */) {
@@ -1092,31 +961,6 @@ var HttpManager = /** @class */ (function () {
1092
961
  _timeoutWrapper.set(cb, interval);
1093
962
  }
1094
963
  }
1095
- /**
1096
- * Converts the XHR getAllResponseHeaders to a map containing the header key and value.
1097
- */
1098
- // tslint:disable-next-line: align
1099
- function _convertAllHeadersToMap(headersString) {
1100
- var headers = {};
1101
- if (isString(headersString)) {
1102
- var headersArray = strTrim(headersString)[_DYN_SPLIT /* @min:%2esplit */](/[\r\n]+/);
1103
- arrForEach(headersArray, function (headerEntry) {
1104
- if (headerEntry) {
1105
- var idx = headerEntry.indexOf(": ");
1106
- if (idx !== -1) {
1107
- // The new spec has the headers returning all as lowercase -- but not all browsers do this yet
1108
- var header = strTrim(headerEntry.substring(0, idx))[_DYN_TO_LOWER_CASE /* @min:%2etoLowerCase */]();
1109
- var value = strTrim(headerEntry.substring(idx + 1));
1110
- headers[header] = value;
1111
- }
1112
- else {
1113
- headers[strTrim(headerEntry)] = 1;
1114
- }
1115
- }
1116
- });
1117
- }
1118
- return headers;
1119
- }
1120
964
  function _getMsfpc(thePayload) {
1121
965
  for (var lp = 0; lp < thePayload.batches[_DYN_LENGTH /* @min:%2elength */]; lp++) {
1122
966
  var msfpc = thePayload[_DYN_BATCHES /* @min:%2ebatches */][lp].Msfpc();