@microsoft/1ds-post-js 3.1.11 → 3.2.2
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.
- package/README.md +2 -2
- package/bundle/{ms.post-3.1.11.gbl.js → ms.post-3.2.2.gbl.js} +1278 -548
- package/bundle/ms.post-3.2.2.gbl.js.map +1 -0
- package/bundle/ms.post-3.2.2.gbl.min.js +7 -0
- package/bundle/ms.post-3.2.2.gbl.min.js.map +1 -0
- package/bundle/ms.post-3.2.2.integrity.json +46 -0
- package/bundle/{ms.post-3.1.11.js → ms.post-3.2.2.js} +1278 -548
- package/bundle/ms.post-3.2.2.js.map +1 -0
- package/bundle/ms.post-3.2.2.min.js +7 -0
- package/bundle/ms.post-3.2.2.min.js.map +1 -0
- package/bundle/ms.post.gbl.js +1277 -547
- package/bundle/ms.post.gbl.js.map +1 -1
- package/bundle/ms.post.gbl.min.js +2 -2
- package/bundle/ms.post.gbl.min.js.map +1 -1
- package/bundle/ms.post.integrity.json +17 -17
- package/bundle/ms.post.js +1277 -547
- package/bundle/ms.post.js.map +1 -1
- package/bundle/ms.post.min.js +2 -2
- package/bundle/ms.post.min.js.map +1 -1
- package/dist/ms.post.js +212 -128
- package/dist/ms.post.js.map +1 -1
- package/dist/ms.post.min.js +2 -2
- package/dist/ms.post.min.js.map +1 -1
- package/dist-esm/src/BatchNotificationActions.js +1 -1
- package/dist-esm/src/ClockSkewManager.js +1 -1
- package/dist-esm/src/Constants.js +1 -1
- package/dist-esm/src/DataModels.js +1 -1
- package/dist-esm/src/EventBatch.js +1 -1
- package/dist-esm/src/HttpManager.d.ts +2 -1
- package/dist-esm/src/HttpManager.js +45 -40
- package/dist-esm/src/HttpManager.js.map +1 -1
- package/dist-esm/src/Index.js +1 -1
- package/dist-esm/src/KillSwitch.js +1 -1
- package/dist-esm/src/PostChannel.d.ts +2 -9
- package/dist-esm/src/PostChannel.js +151 -97
- package/dist-esm/src/PostChannel.js.map +1 -1
- package/dist-esm/src/RetryPolicy.d.ts +20 -25
- package/dist-esm/src/RetryPolicy.js +35 -44
- package/dist-esm/src/RetryPolicy.js.map +1 -1
- package/dist-esm/src/Serializer.js +1 -1
- package/dist-esm/src/TimeoutOverrideWrapper.d.ts +18 -0
- package/dist-esm/src/TimeoutOverrideWrapper.js +28 -0
- package/dist-esm/src/TimeoutOverrideWrapper.js.map +1 -0
- package/dist-esm/src/typings/XDomainRequest.js +1 -1
- package/package.json +3 -3
- package/src/HttpManager.ts +48 -51
- package/src/PostChannel.ts +186 -119
- package/src/RetryPolicy.ts +33 -38
- package/src/TimeoutOverrideWrapper.ts +29 -0
- package/bundle/ms.post-3.1.11.gbl.js.map +0 -1
- package/bundle/ms.post-3.1.11.gbl.min.js +0 -7
- package/bundle/ms.post-3.1.11.gbl.min.js.map +0 -1
- package/bundle/ms.post-3.1.11.integrity.json +0 -46
- package/bundle/ms.post-3.1.11.js.map +0 -1
- package/bundle/ms.post-3.1.11.min.js +0 -7
- package/bundle/ms.post-3.1.11.min.js.map +0 -1
|
@@ -8,6 +8,7 @@ import { IXHROverride, IPostChannel, PayloadPreprocessorFunction, PayloadListene
|
|
|
8
8
|
import { BatchNotificationActions } from "./BatchNotificationActions";
|
|
9
9
|
import { EventBatch } from "./EventBatch";
|
|
10
10
|
import { IChannelConfiguration } from "./Index";
|
|
11
|
+
import { ITimeoutOverrideWrapper } from "./TimeoutOverrideWrapper";
|
|
11
12
|
/**
|
|
12
13
|
* Class managing the sending of requests.
|
|
13
14
|
*/
|
|
@@ -19,7 +20,7 @@ export declare class HttpManager {
|
|
|
19
20
|
* @constructor
|
|
20
21
|
* @param requestQueue - The queue that contains the requests to be sent.
|
|
21
22
|
*/
|
|
22
|
-
constructor(maxEventsPerBatch: number, maxConnections: number, maxRequestRetriesBeforeBackoff: number, actions: BatchNotificationActions);
|
|
23
|
+
constructor(maxEventsPerBatch: number, maxConnections: number, maxRequestRetriesBeforeBackoff: number, actions: BatchNotificationActions, timeoutOverride: ITimeoutOverrideWrapper);
|
|
23
24
|
/**
|
|
24
25
|
* @constructor
|
|
25
26
|
* @param requestQueue - The queue that contains the requests to be sent.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* 1DS JS SDK POST plugin, 3.
|
|
2
|
+
* 1DS JS SDK POST plugin, 3.2.2
|
|
3
3
|
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
4
|
* (Microsoft Internal Only)
|
|
5
5
|
*/
|
|
@@ -9,13 +9,13 @@ 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,
|
|
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
|
|
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, strNoResponseBody, 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
19
|
var strSendAttempt = "sendAttempt";
|
|
20
20
|
var _noResponseQs = "&" + strNoResponseBody + "=true";
|
|
21
21
|
/**
|
|
@@ -30,11 +30,19 @@ var _eventActionMap = (_a = {},
|
|
|
30
30
|
_a);
|
|
31
31
|
var _collectorQsHeaders = {};
|
|
32
32
|
var _collectorHeaderToQs = {};
|
|
33
|
-
function _addCollectorHeaderQsMapping(qsName, headerName) {
|
|
33
|
+
function _addCollectorHeaderQsMapping(qsName, headerName, allowQs) {
|
|
34
34
|
_collectorQsHeaders[qsName] = headerName;
|
|
35
|
-
|
|
35
|
+
if (allowQs !== false) {
|
|
36
|
+
_collectorHeaderToQs[headerName] = qsName;
|
|
37
|
+
}
|
|
36
38
|
}
|
|
37
|
-
_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);
|
|
38
46
|
function _getResponseText(xhr) {
|
|
39
47
|
try {
|
|
40
48
|
return xhr.responseText;
|
|
@@ -81,7 +89,7 @@ var HttpManager = /** @class */ (function () {
|
|
|
81
89
|
* @constructor
|
|
82
90
|
* @param requestQueue - The queue that contains the requests to be sent.
|
|
83
91
|
*/
|
|
84
|
-
function HttpManager(maxEventsPerBatch, maxConnections, maxRequestRetriesBeforeBackoff, actions) {
|
|
92
|
+
function HttpManager(maxEventsPerBatch, maxConnections, maxRequestRetriesBeforeBackoff, actions, timeoutOverride) {
|
|
85
93
|
this._responseHandlers = [];
|
|
86
94
|
var _urlString = "?cors=true&" + strContentTypeHeader.toLowerCase() + "=" + defaultContentType;
|
|
87
95
|
var _killSwitch = new EVTKillSwitch();
|
|
@@ -111,8 +119,7 @@ var HttpManager = /** @class */ (function () {
|
|
|
111
119
|
channelConfig = {};
|
|
112
120
|
}
|
|
113
121
|
_urlString = endpointUrl + _urlString;
|
|
114
|
-
|
|
115
|
-
_useHeaders = !isUndefined(channelConfig.avoidOptions) ? !channelConfig.avoidOptions : false;
|
|
122
|
+
_useHeaders = !isUndefined(channelConfig.avoidOptions) ? !channelConfig.avoidOptions : true;
|
|
116
123
|
_core = core;
|
|
117
124
|
_cookieMgr = core.getCookieMgr();
|
|
118
125
|
_enableEventTimings = !_core.config.disableEventTimings;
|
|
@@ -233,7 +240,7 @@ var HttpManager = /** @class */ (function () {
|
|
|
233
240
|
xdr.send(payload.data);
|
|
234
241
|
}
|
|
235
242
|
else {
|
|
236
|
-
|
|
243
|
+
timeoutOverride.set(function () {
|
|
237
244
|
xdr.send(payload.data);
|
|
238
245
|
}, 0);
|
|
239
246
|
}
|
|
@@ -299,7 +306,7 @@ var HttpManager = /** @class */ (function () {
|
|
|
299
306
|
}
|
|
300
307
|
if (!responseHandled && payload.timeout > 0) {
|
|
301
308
|
// Simulate timeout
|
|
302
|
-
|
|
309
|
+
timeoutOverride.set(function () {
|
|
303
310
|
if (!responseHandled) {
|
|
304
311
|
// Assume a 500 response (which will cause a retry)
|
|
305
312
|
responseHandled = true;
|
|
@@ -363,7 +370,7 @@ var HttpManager = /** @class */ (function () {
|
|
|
363
370
|
oncomplete(status, headers, response);
|
|
364
371
|
}
|
|
365
372
|
catch (e) {
|
|
366
|
-
_postManager.diagLog()
|
|
373
|
+
_throwInternal(_postManager.diagLog(), 2 /* WARNING */, 518 /* SendPostOnCompleteFailure */, dumpObj(e));
|
|
367
374
|
}
|
|
368
375
|
}
|
|
369
376
|
function _beaconSendPost(payload, oncomplete, sync) {
|
|
@@ -402,7 +409,7 @@ var HttpManager = /** @class */ (function () {
|
|
|
402
409
|
}
|
|
403
410
|
}
|
|
404
411
|
catch (ex) {
|
|
405
|
-
_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));
|
|
406
413
|
status = 0;
|
|
407
414
|
}
|
|
408
415
|
finally {
|
|
@@ -606,7 +613,7 @@ var HttpManager = /** @class */ (function () {
|
|
|
606
613
|
}, function () { return ({ batches: _createDebugBatches(orgBatches_1), retryCount: retryCount, isTeardown: isTeardown, isSynchronous: isSynchronous_1, sendReason: sendReason, useSendBeacon: _isBeaconPayload(sendType), sendType: sendType }); }, !isSynchronous_1);
|
|
607
614
|
}
|
|
608
615
|
catch (ex) {
|
|
609
|
-
_postManager.diagLog()
|
|
616
|
+
_throwInternal(_postManager.diagLog(), 2 /* WARNING */, 48 /* CannotSerializeObject */, "Unexpected Exception sending batch: " + dumpObj(ex));
|
|
610
617
|
}
|
|
611
618
|
}
|
|
612
619
|
function _buildRequestDetails(thePayload, useHeaders) {
|
|
@@ -615,26 +622,24 @@ var HttpManager = /** @class */ (function () {
|
|
|
615
622
|
hdrs: {},
|
|
616
623
|
useHdrs: false // Assume no headers
|
|
617
624
|
};
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
// }
|
|
637
|
-
// ----------------------------------------------------------------------------------------------------------------
|
|
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
|
+
}
|
|
638
643
|
_addRequestDetails(requestDetails, strClientId, "NO_AUTH", useHeaders);
|
|
639
644
|
_addRequestDetails(requestDetails, strClientVersion, FullVersionString, useHeaders);
|
|
640
645
|
var apiQsKeys = "";
|
|
@@ -847,7 +852,7 @@ var HttpManager = /** @class */ (function () {
|
|
|
847
852
|
reason = 200 /* Complete */;
|
|
848
853
|
return;
|
|
849
854
|
}
|
|
850
|
-
if (!
|
|
855
|
+
if (!retryPolicyShouldRetryForStatus(status) || thePayload.numEvents <= 0) {
|
|
851
856
|
// Only retry for specific response codes and if there is still events after kill switch processing
|
|
852
857
|
shouldRetry = false;
|
|
853
858
|
}
|
|
@@ -871,7 +876,7 @@ var HttpManager = /** @class */ (function () {
|
|
|
871
876
|
_outstandingRequests--;
|
|
872
877
|
}
|
|
873
878
|
_sendBatches(thePayload.batches, retryCount_1 + 1, thePayload.isTeardown, _isUnloading ? 2 /* SendBeacon */ : thePayload.sendType, 5 /* Retry */);
|
|
874
|
-
}, _isUnloading,
|
|
879
|
+
}, _isUnloading, retryPolicyGetMillisToBackoffForRetry(retryCount_1));
|
|
875
880
|
}
|
|
876
881
|
else {
|
|
877
882
|
backOffTrans = true;
|
|
@@ -940,7 +945,7 @@ var HttpManager = /** @class */ (function () {
|
|
|
940
945
|
cb();
|
|
941
946
|
}
|
|
942
947
|
else {
|
|
943
|
-
|
|
948
|
+
timeoutOverride.set(cb, interval);
|
|
944
949
|
}
|
|
945
950
|
}
|
|
946
951
|
/**
|
|
@@ -985,7 +990,7 @@ var HttpManager = /** @class */ (function () {
|
|
|
985
990
|
responseHandlers[i](responseText);
|
|
986
991
|
}
|
|
987
992
|
catch (e) {
|
|
988
|
-
_postManager.diagLog()
|
|
993
|
+
_throwInternal(_postManager.diagLog(), 1 /* CRITICAL */, 519 /* PostResponseHandler */, "Response handler failed: " + e);
|
|
989
994
|
}
|
|
990
995
|
}
|
|
991
996
|
if (responseText) {
|
|
@@ -1011,7 +1016,7 @@ var HttpManager = /** @class */ (function () {
|
|
|
1011
1016
|
theAction_1.call(actions, theBatches, batchReason, isSyncRequest_1, sendType);
|
|
1012
1017
|
}
|
|
1013
1018
|
catch (e) {
|
|
1014
|
-
_postManager.diagLog()
|
|
1019
|
+
_throwInternal(_postManager.diagLog(), 1 /* CRITICAL */, 74 /* NotificationException */, "send request notification failed: " + e);
|
|
1015
1020
|
}
|
|
1016
1021
|
}, sendSync || isSyncRequest_1, 0);
|
|
1017
1022
|
}, function () { return ({ batches: _createDebugBatches(theBatches), reason: batchReason, isSync: isSyncRequest_1, sendSync: sendSync, sendType: sendType }); }, !isSyncRequest_1);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpManager.js.map","sources":["HttpManager.js"],"sourcesContent":["var _a;\r\n/**\r\n* HttpManager.ts\r\n* @author Abhilash Panwar (abpanwar); Hector Hernandez (hectorh); Nev Wylie (newylie)\r\n* @copyright Microsoft 2018-2020\r\n*/\r\nimport { 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\";\r\nimport { Serializer } from \"./Serializer\";\r\nimport RetryPolicy from \"./RetryPolicy\";\r\nimport EVTKillSwitch from \"./KillSwitch\";\r\nimport EVTClockSkewManager from \"./ClockSkewManager\";\r\nimport dynamicProto from \"@microsoft/dynamicproto-js\";\r\nimport { defaultCacheControl, defaultContentType, DisabledPropertyName, Method, strApiKey, strCacheControl, strClientId, strClientVersion, strContentTypeHeader, strDropped, strKillDurationHeader, strKillDurationSecondsHeader, strKillTokensHeader, strMsaDeviceTicket, strMsfpc, strNoResponseBody, strOther, strRequeue, strResponseFail, strSending, strTimeDeltaHeader, strTimeDeltaToApply, strUploadTime } from \"./Constants\";\r\nvar strSendAttempt = \"sendAttempt\";\r\nvar _noResponseQs = \"&\" + strNoResponseBody + \"=true\";\r\n/**\r\n * Identifies the default notification reason to the action names\r\n */\r\nvar _eventActionMap = (_a = {},\r\n _a[1 /* Paused */] = strRequeue,\r\n _a[100 /* RequeueEvents */] = strRequeue,\r\n _a[200 /* Complete */] = \"sent\",\r\n _a[8004 /* KillSwitch */] = strDropped,\r\n _a[8003 /* SizeLimitExceeded */] = strDropped,\r\n _a);\r\nvar _collectorQsHeaders = {};\r\nvar _collectorHeaderToQs = {};\r\nfunction _addCollectorHeaderQsMapping(qsName, headerName) {\r\n _collectorQsHeaders[qsName] = headerName;\r\n _collectorHeaderToQs[headerName] = qsName;\r\n}\r\n_addCollectorHeaderQsMapping(strMsaDeviceTicket, strMsaDeviceTicket);\r\nfunction _getResponseText(xhr) {\r\n try {\r\n return xhr.responseText;\r\n }\r\n catch (e) {\r\n // Best effort, as XHR may throw while XDR wont so just ignore\r\n }\r\n return \"\";\r\n}\r\nfunction _hasHeader(headers, header) {\r\n var hasHeader = false;\r\n if (headers && header) {\r\n var keys = objKeys(headers);\r\n if (keys && keys.length > 0) {\r\n var lowerHeader = header.toLowerCase();\r\n for (var lp = 0; lp < keys.length; lp++) {\r\n var value = keys[lp];\r\n if (value && hasOwnProperty(header, value) &&\r\n value.toLowerCase() === lowerHeader) {\r\n hasHeader = true;\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n return hasHeader;\r\n}\r\nfunction _addRequestDetails(details, name, value, useHeaders) {\r\n if (name && value && value.length > 0) {\r\n if (useHeaders && _collectorQsHeaders[name]) {\r\n details.hdrs[_collectorQsHeaders[name]] = value;\r\n details.useHdrs = true;\r\n }\r\n else {\r\n details.url += \"&\" + name + \"=\" + value;\r\n }\r\n }\r\n}\r\n/**\r\n * Class managing the sending of requests.\r\n */\r\nvar HttpManager = /** @class */ (function () {\r\n /**\r\n * @constructor\r\n * @param requestQueue - The queue that contains the requests to be sent.\r\n */\r\n function HttpManager(maxEventsPerBatch, maxConnections, maxRequestRetriesBeforeBackoff, actions) {\r\n this._responseHandlers = [];\r\n var _urlString = \"?cors=true&\" + strContentTypeHeader.toLowerCase() + \"=\" + defaultContentType;\r\n var _killSwitch = new EVTKillSwitch();\r\n var _paused = false;\r\n var _clockSkewManager = new EVTClockSkewManager();\r\n var _useBeacons = false;\r\n var _outstandingRequests = 0; // Holds the number of outstanding async requests that have not returned a response yet\r\n var _postManager;\r\n var _sendInterfaces;\r\n var _core;\r\n var _customHttpInterface = true;\r\n var _queryStringParameters = [];\r\n var _headers = {};\r\n var _batchQueue = [];\r\n var _serializer = null;\r\n var _enableEventTimings = false;\r\n var _cookieMgr;\r\n var _isUnloading = false;\r\n var _useHeaders = false;\r\n var _xhrTimeout;\r\n var _disableXhrSync;\r\n dynamicProto(HttpManager, this, function (_self) {\r\n var _sendCredentials = true;\r\n _self.initialize = function (endpointUrl, core, postChannel, httpInterface, channelConfig) {\r\n var _a;\r\n if (!channelConfig) {\r\n channelConfig = {};\r\n }\r\n _urlString = endpointUrl + _urlString;\r\n // Task 12886642: Defaulting to 'false' until the Collector handles sending upload-time header in the OPTIONS call\r\n _useHeaders = !isUndefined(channelConfig.avoidOptions) ? !channelConfig.avoidOptions : false;\r\n _core = core;\r\n _cookieMgr = core.getCookieMgr();\r\n _enableEventTimings = !_core.config.disableEventTimings;\r\n var enableCompoundKey = !!_core.config.enableCompoundKey;\r\n _postManager = postChannel;\r\n var valueSanitizer = channelConfig.valueSanitizer;\r\n var stringifyObjects = channelConfig.stringifyObjects;\r\n if (!isUndefined(channelConfig.enableCompoundKey)) {\r\n enableCompoundKey = !!channelConfig.enableCompoundKey;\r\n }\r\n _xhrTimeout = channelConfig.xhrTimeout;\r\n _disableXhrSync = channelConfig.disableXhrSync;\r\n _useBeacons = !isReactNative(); // Only use beacons if not running in React Native\r\n _serializer = new Serializer(_core, valueSanitizer, stringifyObjects, enableCompoundKey);\r\n var syncHttpInterface = httpInterface;\r\n var beaconHttpInterface = channelConfig.alwaysUseXhrOverride ? httpInterface : null;\r\n var fetchSyncHttpInterface = channelConfig.alwaysUseXhrOverride ? httpInterface : null;\r\n if (!httpInterface) {\r\n _customHttpInterface = false;\r\n var location_1 = getLocation();\r\n if (location_1 && location_1.protocol && location_1.protocol.toLowerCase() === \"file:\") {\r\n // Special case where a local html file fails with a CORS error on Chromium browsers\r\n _sendCredentials = false;\r\n }\r\n var theTransports = [];\r\n if (isReactNative()) {\r\n // Use Fetch or XDR/XHR\r\n theTransports = [2 /* Fetch */, 1 /* Xhr */];\r\n }\r\n else {\r\n // Use XDR/XHR, Fetch or beacons\r\n theTransports = [1 /* Xhr */, 2 /* Fetch */, 3 /* Beacon */];\r\n }\r\n // Prefix any user requested transport(s) values\r\n var configTransports = channelConfig.transports;\r\n if (configTransports) {\r\n if (isNumber(configTransports)) {\r\n theTransports = [configTransports].concat(theTransports);\r\n }\r\n else if (isArray(configTransports)) {\r\n theTransports = configTransports.concat(theTransports);\r\n }\r\n }\r\n httpInterface = _getSenderInterface(theTransports, false);\r\n syncHttpInterface = _getSenderInterface(theTransports, true);\r\n if (!httpInterface) {\r\n _postManager.diagLog().warnToConsole(\"No available transport to send events\");\r\n }\r\n }\r\n _sendInterfaces = (_a = {},\r\n _a[0 /* Batched */] = httpInterface,\r\n _a[1 /* Synchronous */] = syncHttpInterface || _getSenderInterface([1 /* Xhr */, 2 /* Fetch */, 3 /* Beacon */], true),\r\n _a[2 /* SendBeacon */] = beaconHttpInterface || _getSenderInterface([3 /* Beacon */, 2 /* Fetch */], true) || syncHttpInterface || _getSenderInterface([1 /* Xhr */], true),\r\n _a[3 /* SyncFetch */] = fetchSyncHttpInterface || _getSenderInterface([2 /* Fetch */, 3 /* Beacon */], true) || syncHttpInterface || _getSenderInterface([1 /* Xhr */], true),\r\n _a);\r\n };\r\n // Special internal method to allow the DebugPlugin to hook embedded objects\r\n function _getSenderInterface(transports, syncSupport) {\r\n var transportType = 0 /* NotSet */;\r\n var sendPostFunc = null;\r\n var lp = 0;\r\n while (sendPostFunc == null && lp < transports.length) {\r\n transportType = transports[lp];\r\n if (transportType === 1 /* Xhr */) {\r\n if (useXDomainRequest()) {\r\n sendPostFunc = _xdrSendPost;\r\n }\r\n else if (isXhrSupported()) {\r\n sendPostFunc = _xhrSendPost;\r\n }\r\n }\r\n else if (transportType === 2 /* Fetch */ && isFetchSupported(syncSupport)) {\r\n sendPostFunc = _fetchSendPost;\r\n }\r\n else if (_useBeacons && transportType === 3 /* Beacon */ && isBeaconsSupported()) {\r\n sendPostFunc = _beaconSendPost;\r\n }\r\n lp++;\r\n }\r\n if (sendPostFunc) {\r\n return {\r\n _transport: transportType,\r\n _isSync: syncSupport,\r\n sendPOST: sendPostFunc\r\n };\r\n }\r\n return null;\r\n }\r\n _self[\"_getDbgPlgTargets\"] = function () {\r\n return [_sendInterfaces[0 /* Batched */], _killSwitch, _serializer, _sendInterfaces];\r\n };\r\n function _xdrSendPost(payload, oncomplete, sync) {\r\n // It doesn't support custom headers, so no action is taken with current requestHeaders\r\n var xdr = new XDomainRequest();\r\n xdr.open(Method, payload.urlString);\r\n if (payload.timeout) {\r\n xdr.timeout = payload.timeout;\r\n }\r\n // can't get the status code in xdr.\r\n xdr.onload = function () {\r\n // we will assume onload means the request succeeded.\r\n var response = _getResponseText(xdr);\r\n _doOnComplete(oncomplete, 200, {}, response);\r\n _handleCollectorResponse(response);\r\n };\r\n // we will assume onerror means we need to drop the events.\r\n xdr.onerror = function () {\r\n _doOnComplete(oncomplete, 400, {});\r\n };\r\n // we will assume ontimeout means we need to retry the events.\r\n xdr.ontimeout = function () {\r\n _doOnComplete(oncomplete, 500, {});\r\n };\r\n // https://cypressnorth.com/web-programming-and-development/internet-explorer-aborting-ajax-requests-fixed/\r\n // tslint:disable-next-line:no-empty\r\n xdr.onprogress = function () { };\r\n if (sync) {\r\n xdr.send(payload.data);\r\n }\r\n else {\r\n _postManager._setTimeoutOverride(function () {\r\n xdr.send(payload.data);\r\n }, 0);\r\n }\r\n }\r\n function _fetchSendPost(payload, oncomplete, sync) {\r\n var _a;\r\n var theUrl = payload.urlString;\r\n var ignoreResponse = false;\r\n var responseHandled = false;\r\n var requestInit = (_a = {\r\n body: payload.data,\r\n method: Method\r\n },\r\n _a[DisabledPropertyName] = true,\r\n _a);\r\n if (sync) {\r\n requestInit.keepalive = true;\r\n if (payload._sendReason === 2 /* Unload */) {\r\n // As a sync request (during unload), it is unlikely that we will get a chance to process the response so\r\n // just like beacon send assume that the events have been accepted and processed\r\n ignoreResponse = true;\r\n theUrl += _noResponseQs;\r\n }\r\n }\r\n if (_sendCredentials) {\r\n // Don't send credentials when URL is file://\r\n requestInit.credentials = \"include\";\r\n }\r\n // Only add headers if there are headers to add, due to issue with some polyfills\r\n if (payload.headers && objKeys(payload.headers).length > 0) {\r\n requestInit.headers = payload.headers;\r\n }\r\n fetch(theUrl, requestInit).then(function (response) {\r\n var headerMap = {};\r\n var responseText = \"\";\r\n if (response.headers) {\r\n response.headers.forEach(function (value, name) {\r\n headerMap[name] = value;\r\n });\r\n }\r\n if (response.body) {\r\n response.text().then(function (text) {\r\n responseText = text;\r\n });\r\n }\r\n if (!responseHandled) {\r\n responseHandled = true;\r\n _doOnComplete(oncomplete, response.status, headerMap, responseText);\r\n _handleCollectorResponse(responseText);\r\n }\r\n })[\"catch\"](function (error) {\r\n // In case there is an error in the request. Set the status to 0\r\n // so that the events can be retried later.\r\n if (!responseHandled) {\r\n responseHandled = true;\r\n _doOnComplete(oncomplete, 0, {});\r\n }\r\n });\r\n if (ignoreResponse && !responseHandled) {\r\n // Assume success during unload processing\r\n responseHandled = true;\r\n _doOnComplete(oncomplete, 200, {});\r\n }\r\n if (!responseHandled && payload.timeout > 0) {\r\n // Simulate timeout\r\n _postManager._setTimeoutOverride(function () {\r\n if (!responseHandled) {\r\n // Assume a 500 response (which will cause a retry)\r\n responseHandled = true;\r\n _doOnComplete(oncomplete, 500, {});\r\n }\r\n }, payload.timeout);\r\n }\r\n }\r\n function _xhrSendPost(payload, oncomplete, sync) {\r\n var theUrl = payload.urlString;\r\n function _appendHeader(theHeaders, xhr, name) {\r\n if (!theHeaders[name] && xhr && xhr.getResponseHeader) {\r\n var value = xhr.getResponseHeader(name);\r\n if (value) {\r\n theHeaders[name] = strTrim(value);\r\n }\r\n }\r\n return theHeaders;\r\n }\r\n function _getAllResponseHeaders(xhr) {\r\n var theHeaders = {};\r\n if (!xhr.getAllResponseHeaders) {\r\n // Firefox 2-63 doesn't have getAllResponseHeaders function but it does have getResponseHeader\r\n // Only call these if getAllResponseHeaders doesn't exist, otherwise we can get invalid response errors\r\n // as collector is not currently returning the correct header to allow JS to access these headers\r\n theHeaders = _appendHeader(theHeaders, xhr, strTimeDeltaHeader);\r\n theHeaders = _appendHeader(theHeaders, xhr, strKillDurationHeader);\r\n theHeaders = _appendHeader(theHeaders, xhr, strKillDurationSecondsHeader);\r\n }\r\n else {\r\n theHeaders = _convertAllHeadersToMap(xhr.getAllResponseHeaders());\r\n }\r\n return theHeaders;\r\n }\r\n function xhrComplete(xhr, responseTxt) {\r\n _doOnComplete(oncomplete, xhr.status, _getAllResponseHeaders(xhr), responseTxt);\r\n }\r\n if (sync && payload.disableXhrSync) {\r\n sync = false;\r\n }\r\n var xhrRequest = openXhr(Method, theUrl, _sendCredentials, true, sync, payload.timeout);\r\n // Set custom headers (e.g. gzip) here (after open())\r\n objForEachKey(payload.headers, function (name, value) {\r\n xhrRequest.setRequestHeader(name, value);\r\n });\r\n xhrRequest.onload = function () {\r\n var response = _getResponseText(xhrRequest);\r\n xhrComplete(xhrRequest, response);\r\n _handleCollectorResponse(response);\r\n };\r\n xhrRequest.onerror = function () {\r\n xhrComplete(xhrRequest);\r\n };\r\n xhrRequest.ontimeout = function () {\r\n xhrComplete(xhrRequest);\r\n };\r\n xhrRequest.send(payload.data);\r\n }\r\n function _doOnComplete(oncomplete, status, headers, response) {\r\n try {\r\n oncomplete(status, headers, response);\r\n }\r\n catch (e) {\r\n _postManager.diagLog().throwInternal(LoggingSeverity.WARNING, _ExtendedInternalMessageId.SendPostOnCompleteFailure, dumpObj(e));\r\n }\r\n }\r\n function _beaconSendPost(payload, oncomplete, sync) {\r\n // Custom headers not supported in sendBeacon payload.headers would be ignored\r\n var internalPayloadData = payload;\r\n var status = 200;\r\n var thePayload = internalPayloadData._thePayload;\r\n var theUrl = payload.urlString + _noResponseQs;\r\n try {\r\n var nav_1 = getNavigator();\r\n if (!nav_1.sendBeacon(theUrl, payload.data)) {\r\n if (thePayload) {\r\n // Failed to send entire payload so try and split data and try to send as much events as possible\r\n var droppedBatches_1 = [];\r\n arrForEach(thePayload.batches, function (theBatch) {\r\n if (droppedBatches_1 && theBatch && theBatch.count() > 0) {\r\n var theEvents = theBatch.events();\r\n for (var lp = 0; lp < theEvents.length; lp++) {\r\n if (!nav_1.sendBeacon(theUrl, _serializer.getEventBlob(theEvents[lp]))) {\r\n // Can't send anymore, so split the batch and drop the rest\r\n droppedBatches_1.push(theBatch.split(lp));\r\n break;\r\n }\r\n }\r\n }\r\n else {\r\n // Remove all of the events from the existing batch in the payload as the copy includes the original\r\n droppedBatches_1.push(theBatch.split(0));\r\n }\r\n });\r\n _sendBatchesNotification(droppedBatches_1, 8003 /* SizeLimitExceeded */, thePayload.sendType, true);\r\n }\r\n else {\r\n status = 0;\r\n }\r\n }\r\n }\r\n catch (ex) {\r\n _postManager.diagLog().warnToConsole(\"Failed to send telemetry using sendBeacon API. Ex:\" + ex);\r\n status = 0;\r\n }\r\n finally {\r\n _doOnComplete(oncomplete, status, {}, \"\");\r\n }\r\n }\r\n function _isBeaconPayload(sendType) {\r\n // Sync Fetch has the same payload limitation as sendBeacon -- 64kb limit, so treat both as a beacon send\r\n return sendType === 2 /* SendBeacon */ || sendType === 3 /* SyncFetch */;\r\n }\r\n function _adjustSendType(sendType) {\r\n if (_isUnloading && _isBeaconPayload(sendType)) {\r\n sendType = 2 /* SendBeacon */;\r\n }\r\n return sendType;\r\n }\r\n _self.addQueryStringParameter = function (name, value) {\r\n for (var i = 0; i < _queryStringParameters.length; i++) {\r\n if (_queryStringParameters[i].name === name) {\r\n _queryStringParameters[i].value = value;\r\n return;\r\n }\r\n }\r\n _queryStringParameters.push({ name: name, value: value });\r\n };\r\n _self.addHeader = function (name, value) {\r\n _headers[name] = value;\r\n };\r\n _self.canSendRequest = function () {\r\n return _hasIdleConnection() && _clockSkewManager.allowRequestSending();\r\n };\r\n _self.sendQueuedRequests = function (sendType, sendReason) {\r\n if (isUndefined(sendType)) {\r\n sendType = 0 /* Batched */;\r\n }\r\n if (_isUnloading) {\r\n sendType = _adjustSendType(sendType);\r\n sendReason = 2 /* Unload */;\r\n }\r\n if (_canSendPayload(_batchQueue, sendType, 0)) {\r\n _sendBatches(_clearQueue(), 0, false, sendType, sendReason || 0 /* Undefined */);\r\n }\r\n };\r\n _self.isCompletelyIdle = function () {\r\n return !_paused && _outstandingRequests === 0 && _batchQueue.length === 0;\r\n };\r\n _self.setUnloading = function (value) {\r\n _isUnloading = value;\r\n };\r\n _self.addBatch = function (theBatch) {\r\n if (theBatch && theBatch.count() > 0) {\r\n // Try and kill the event faster\r\n if (_killSwitch.isTenantKilled(theBatch.iKey())) {\r\n return false;\r\n }\r\n _batchQueue.push(theBatch);\r\n }\r\n return true;\r\n };\r\n /**\r\n * Queue all the remaining requests to be sent. The requests will be\r\n * sent using HTML5 Beacons if they are available.\r\n */\r\n _self.teardown = function () {\r\n if (_batchQueue.length > 0) {\r\n _sendBatches(_clearQueue(), 0, true, 2 /* SendBeacon */, 2 /* Unload */);\r\n }\r\n };\r\n /**\r\n * Pause the sending of requests. No new requests will be sent.\r\n */\r\n _self.pause = function () {\r\n _paused = true;\r\n };\r\n /**\r\n * Resume the sending of requests.\r\n */\r\n _self.resume = function () {\r\n _paused = false;\r\n _self.sendQueuedRequests(0 /* Batched */, 4 /* Resumed */);\r\n };\r\n /**\r\n * Sends a request synchronously to the Aria collector. This api is used to send\r\n * a request containing a single immediate event.\r\n *\r\n * @param batch - The request to be sent.\r\n * @param sendReason - The token used to send the request.\r\n */\r\n _self.sendSynchronousBatch = function (batch, sendType, sendReason) {\r\n // This will not take into account the max connections restriction. Since this is sync, we can\r\n // only send one of this request at a time and thus should not worry about multiple connections\r\n // being used to send synchronous events.\r\n // Increment active connection since we are still going to use a connection to send the request.\r\n if (batch && batch.count() > 0) {\r\n if (isNullOrUndefined(sendType)) {\r\n sendType = 1 /* Synchronous */;\r\n }\r\n if (_isUnloading) {\r\n sendType = _adjustSendType(sendType);\r\n sendReason = 2 /* Unload */;\r\n }\r\n // For sync requests we will not wait for the clock skew.\r\n _sendBatches([batch], 0, false, sendType, sendReason || 0 /* Undefined */);\r\n }\r\n };\r\n function _hasIdleConnection() {\r\n return !_paused && _outstandingRequests < maxConnections;\r\n }\r\n function _clearQueue() {\r\n var theQueue = _batchQueue;\r\n _batchQueue = [];\r\n return theQueue;\r\n }\r\n function _canSendPayload(theBatches, sendType, retryCnt) {\r\n var result = false;\r\n if (theBatches && theBatches.length > 0 && !_paused && _sendInterfaces[sendType] && _serializer) {\r\n // Always attempt to send synchronous events don't wait for idle or clockSkew\r\n // and don't block retry requests if clockSkew is not yet set\r\n result = (sendType !== 0 /* Batched */) || (_hasIdleConnection() && (retryCnt > 0 || _clockSkewManager.allowRequestSending()));\r\n }\r\n return result;\r\n }\r\n function _createDebugBatches(theBatches) {\r\n var values = {};\r\n if (theBatches) {\r\n arrForEach(theBatches, function (theBatch, idx) {\r\n values[idx] = {\r\n iKey: theBatch.iKey(),\r\n evts: theBatch.events()\r\n };\r\n });\r\n }\r\n return values;\r\n }\r\n function _sendBatches(theBatches, retryCount, isTeardown, sendType, sendReason) {\r\n if (!theBatches || theBatches.length === 0) {\r\n // Nothing to do\r\n return;\r\n }\r\n if (_paused) {\r\n _sendBatchesNotification(theBatches, 1 /* Paused */, sendType);\r\n return;\r\n }\r\n // Make sure that if we are unloading the sendType is a supported version\r\n sendType = _adjustSendType(sendType);\r\n try {\r\n var orgBatches_1 = theBatches;\r\n var isSynchronous_1 = sendType !== 0 /* Batched */;\r\n doPerf(_core, function () { return \"HttpManager:_sendBatches\"; }, function (perfEvt) {\r\n if (perfEvt) {\r\n // Perf Monitoring is enabled, so create a \"Quick\" copy of the original batches so we still report\r\n // the original values as part of the perfEvent. This is because theBatches uses .shift() to remove each\r\n // batch as they are processed - removing from the original array, so by the time the _createDebugBatches()\r\n // function is called the passed in value has changed and therefore the reported value for the perfEvent is incorrect\r\n theBatches = theBatches.slice(0);\r\n }\r\n var droppedBatches = [];\r\n var thePayload = null;\r\n var serializationStart = getTime();\r\n var sendInterface = _sendInterfaces[sendType] || (isSynchronous_1 ? _sendInterfaces[1 /* Synchronous */] : _sendInterfaces[0 /* Batched */]);\r\n // Sync Fetch has the same payload limitation as sendBeacon -- 64kb limit\r\n var isBeaconTransport = (_isUnloading || _isBeaconPayload(sendType) || (sendInterface && sendInterface._transport === 3 /* Beacon */)) && _canUseSendBeaconApi();\r\n while (_canSendPayload(theBatches, sendType, retryCount)) {\r\n var theBatch = theBatches.shift();\r\n if (theBatch && theBatch.count() > 0) {\r\n if (!_killSwitch.isTenantKilled(theBatch.iKey())) {\r\n // Make sure we have a payload object\r\n thePayload = thePayload || _serializer.createPayload(retryCount, isTeardown, isSynchronous_1, isBeaconTransport, sendReason, sendType);\r\n // Add the batch to the current payload\r\n if (!_serializer.appendPayload(thePayload, theBatch, maxEventsPerBatch)) {\r\n // Entire batch was not added so send the payload and retry adding this batch\r\n _doPayloadSend(thePayload, serializationStart, getTime(), sendReason);\r\n serializationStart = getTime();\r\n theBatches = [theBatch].concat(theBatches);\r\n thePayload = null;\r\n }\r\n else if (thePayload.overflow !== null) {\r\n // Total Payload size was exceeded so send the payload and add the unsent as the next batch to send\r\n theBatches = [thePayload.overflow].concat(theBatches);\r\n thePayload.overflow = null;\r\n _doPayloadSend(thePayload, serializationStart, getTime(), sendReason);\r\n serializationStart = getTime();\r\n thePayload = null;\r\n }\r\n }\r\n else {\r\n droppedBatches.push(theBatch);\r\n }\r\n }\r\n }\r\n // Make sure to flush any remaining payload\r\n if (thePayload) {\r\n _doPayloadSend(thePayload, serializationStart, getTime(), sendReason);\r\n }\r\n if (theBatches.length > 0) {\r\n // Add any unsent batches back to the head of the queue\r\n _batchQueue = theBatches.concat(_batchQueue);\r\n }\r\n // Now send notification about any dropped events\r\n _sendBatchesNotification(droppedBatches, 8004 /* KillSwitch */, sendType);\r\n }, function () { return ({ batches: _createDebugBatches(orgBatches_1), retryCount: retryCount, isTeardown: isTeardown, isSynchronous: isSynchronous_1, sendReason: sendReason, useSendBeacon: _isBeaconPayload(sendType), sendType: sendType }); }, !isSynchronous_1);\r\n }\r\n catch (ex) {\r\n _postManager.diagLog().throwInternal(LoggingSeverity.WARNING, _ExtendedInternalMessageId.CannotSerializeObject, \"Unexpected Exception sending batch: \" + dumpObj(ex));\r\n }\r\n }\r\n function _buildRequestDetails(thePayload, useHeaders) {\r\n var requestDetails = {\r\n url: _urlString,\r\n hdrs: {},\r\n useHdrs: false // Assume no headers\r\n };\r\n // ----------------------------------------------------------------------------------------------------------------\r\n // Task 12886642: Need to wait until an updated version of the collector is released to return these as allowed in the OPTIONS call\r\n // ----------------------------------------------------------------------------------------------------------------\r\n // if (!useHeaders) {\r\n // // Attempt to map headers to a query string if possible\r\n // objForEachKey(_headers, (name, value) => {\r\n // if (_collectorHeaderToQs[name]) {\r\n // _addRequestDetails(requestDetails, _collectorHeaderToQs[name], value, false);\r\n // } else {\r\n // // No mapping, so just include in the headers anyway (may not get sent if using sendBeacon())\r\n // requestDetails.hdrs[name] = value;\r\n // requestDetails.useHdrs = true;\r\n // }\r\n // });\r\n // } else {\r\n // Copy the pre-defined headers into the payload headers\r\n requestDetails.hdrs = extend(requestDetails.hdrs, _headers);\r\n requestDetails.useHdrs = (objKeys(requestDetails.hdrs).length > 0);\r\n // }\r\n // ----------------------------------------------------------------------------------------------------------------\r\n _addRequestDetails(requestDetails, strClientId, \"NO_AUTH\", useHeaders);\r\n _addRequestDetails(requestDetails, strClientVersion, FullVersionString, useHeaders);\r\n var apiQsKeys = \"\";\r\n arrForEach(thePayload.apiKeys, function (apiKey) {\r\n if (apiQsKeys.length > 0) {\r\n apiQsKeys += \",\";\r\n }\r\n apiQsKeys += apiKey;\r\n });\r\n _addRequestDetails(requestDetails, strApiKey, apiQsKeys, useHeaders);\r\n _addRequestDetails(requestDetails, strUploadTime, dateNow().toString(), useHeaders);\r\n var msfpc = _getMsfpc(thePayload);\r\n if (isValueAssigned(msfpc)) {\r\n requestDetails.url += \"&ext.intweb.msfpc=\" + msfpc;\r\n }\r\n if (_clockSkewManager.shouldAddClockSkewHeaders()) {\r\n _addRequestDetails(requestDetails, strTimeDeltaToApply, _clockSkewManager.getClockSkewHeaderValue(), useHeaders);\r\n }\r\n if (_core.getWParam) {\r\n var wParam = _core.getWParam();\r\n if (wParam >= 0) {\r\n requestDetails.url += \"&w=\" + wParam;\r\n }\r\n }\r\n for (var i = 0; i < _queryStringParameters.length; i++) {\r\n requestDetails.url += \"&\" + _queryStringParameters[i].name + \"=\" + _queryStringParameters[i].value;\r\n }\r\n return requestDetails;\r\n }\r\n function _canUseSendBeaconApi() {\r\n return !_customHttpInterface && _useBeacons && isBeaconsSupported();\r\n }\r\n function _setTimingValue(timings, name, value) {\r\n timings[name] = timings[name] || {};\r\n timings[name][_postManager.identifier] = value;\r\n }\r\n function _doPayloadSend(thePayload, serializationStart, serializationCompleted, sendReason) {\r\n if (thePayload && thePayload.payloadBlob && thePayload.payloadBlob.length > 0) {\r\n var useSendHook_1 = !!_self.sendHook;\r\n var sendInterface_1 = _sendInterfaces[thePayload.sendType];\r\n // Send all data using a beacon style transport if closing mode is on or channel was teared down\r\n if (!_isBeaconPayload(thePayload.sendType) && thePayload.isBeacon && thePayload.sendReason === 2 /* Unload */) {\r\n sendInterface_1 = _sendInterfaces[2 /* SendBeacon */] || _sendInterfaces[3 /* SyncFetch */] || sendInterface_1;\r\n }\r\n var useHeaders_1 = _useHeaders;\r\n // Disable header usage if we know we are using sendBeacon as additional headers are not supported\r\n if (thePayload.isBeacon || sendInterface_1._transport === 3 /* Beacon */) {\r\n useHeaders_1 = false;\r\n }\r\n var requestDetails_1 = _buildRequestDetails(thePayload, useHeaders_1);\r\n useHeaders_1 = useHeaders_1 || requestDetails_1.useHdrs;\r\n var sendEventStart_1 = getTime();\r\n doPerf(_core, function () { return \"HttpManager:_doPayloadSend\"; }, function () {\r\n // Increment the send attempt count and add timings after packaging (So it's not serialized in the 1st attempt)\r\n for (var batchLp = 0; batchLp < thePayload.batches.length; batchLp++) {\r\n var theBatch = thePayload.batches[batchLp];\r\n var theEvents = theBatch.events();\r\n for (var evtLp = 0; evtLp < theEvents.length; evtLp++) {\r\n var telemetryItem = theEvents[evtLp];\r\n if (_enableEventTimings) {\r\n var timings = telemetryItem.timings = telemetryItem.timings || {};\r\n _setTimingValue(timings, \"sendEventStart\", sendEventStart_1);\r\n _setTimingValue(timings, \"serializationStart\", serializationStart);\r\n _setTimingValue(timings, \"serializationCompleted\", serializationCompleted);\r\n }\r\n telemetryItem[strSendAttempt] > 0 ? telemetryItem[strSendAttempt]++ : telemetryItem[strSendAttempt] = 1;\r\n }\r\n }\r\n // Note: always sending this notification in a synchronous manner.\r\n _sendBatchesNotification(thePayload.batches, (1000 /* SendingUndefined */ + (sendReason || 0 /* Undefined */)), thePayload.sendType, true);\r\n // Disabling the use of const because of Issue: \r\n // - Task 9227844: [1DS] Some environments and packagers automatically \"freeze\" objects which are defined as const which causes any mutations to throw\r\n // eslint-disable-next-line prefer-const\r\n var orgPayloadData = {\r\n data: thePayload.payloadBlob,\r\n urlString: requestDetails_1.url,\r\n headers: requestDetails_1.hdrs,\r\n _thePayload: thePayload,\r\n _sendReason: sendReason,\r\n timeout: _xhrTimeout\r\n };\r\n if (!isUndefined(_disableXhrSync)) {\r\n orgPayloadData.disableXhrSync = !!_disableXhrSync;\r\n }\r\n // Only automatically add the following headers if already sending headers and we are not attempting to avoid an options call\r\n if (useHeaders_1) {\r\n if (!_hasHeader(orgPayloadData.headers, strCacheControl)) {\r\n orgPayloadData.headers[strCacheControl] = defaultCacheControl;\r\n }\r\n if (!_hasHeader(orgPayloadData.headers, strContentTypeHeader)) {\r\n orgPayloadData.headers[strContentTypeHeader] = defaultContentType;\r\n }\r\n }\r\n var sender = null;\r\n if (sendInterface_1) {\r\n // Send sync requests if the request is immediate or we are tearing down telemetry.\r\n sender = function (payload) {\r\n // Notify the clock skew manager that we are sending the first request (Potentially blocking all further requests)\r\n _clockSkewManager.firstRequestSent();\r\n var onComplete = function (status, headers) {\r\n _retryRequestIfNeeded(status, headers, thePayload, sendReason);\r\n };\r\n var isSync = thePayload.isTeardown || thePayload.isSync;\r\n try {\r\n sendInterface_1.sendPOST(payload, onComplete, isSync);\r\n if (_self.sendListener) {\r\n // Send the original payload to the listener\r\n _self.sendListener(orgPayloadData, payload, isSync, thePayload.isBeacon);\r\n }\r\n }\r\n catch (ex) {\r\n _postManager.diagLog().warnToConsole(\"Unexpected exception sending payload. Ex:\" + dumpObj(ex));\r\n _doOnComplete(onComplete, 0, {});\r\n }\r\n };\r\n }\r\n doPerf(_core, function () { return \"HttpManager:_doPayloadSend.sender\"; }, function () {\r\n if (sender) {\r\n if (thePayload.sendType === 0 /* Batched */) {\r\n _outstandingRequests++;\r\n }\r\n // Only call the hook if it's defined and we are not using sendBeacon as additional headers are not supported\r\n if (useSendHook_1 && !thePayload.isBeacon && sendInterface_1._transport !== 3 /* Beacon */) {\r\n // Create a new IPayloadData that is sent into the hook method, so that the hook method\r\n // can't change the object references to the orgPayloadData (it can still change the content -- mainly the headers)\r\n // Disabling the use of const because of Issue: \r\n // - Task 9227844: [1DS] Some environments and packagers automatically \"freeze\" objects which are defined as const which causes any mutations to throw\r\n // eslint-disable-next-line prefer-const\r\n var hookData_1 = {\r\n data: orgPayloadData.data,\r\n urlString: orgPayloadData.urlString,\r\n headers: extend({}, orgPayloadData.headers),\r\n timeout: orgPayloadData.timeout,\r\n disableXhrSync: orgPayloadData.disableXhrSync\r\n };\r\n var senderCalled_1 = false;\r\n doPerf(_core, function () { return \"HttpManager:_doPayloadSend.sendHook\"; }, function () {\r\n try {\r\n _self.sendHook(hookData_1, function (payload) {\r\n senderCalled_1 = true;\r\n // Add back the internal properties\r\n if (!_customHttpInterface && !payload._thePayload) {\r\n payload._thePayload = payload._thePayload || orgPayloadData._thePayload;\r\n payload._sendReason = payload._sendReason || orgPayloadData._sendReason;\r\n }\r\n sender(payload);\r\n }, thePayload.isSync || thePayload.isTeardown);\r\n }\r\n catch (ex) {\r\n if (!senderCalled_1) {\r\n // The hook never called the sender -- assume that it never will\r\n sender(orgPayloadData);\r\n }\r\n }\r\n });\r\n }\r\n else {\r\n sender(orgPayloadData);\r\n }\r\n }\r\n });\r\n }, function () { return ({ thePayload: thePayload, serializationStart: serializationStart, serializationCompleted: serializationCompleted, sendReason: sendReason }); }, thePayload.isSync);\r\n }\r\n if (thePayload.sizeExceed && thePayload.sizeExceed.length > 0) {\r\n // Ensure that we send any discard events for oversize events even when there was no payload to send\r\n _sendBatchesNotification(thePayload.sizeExceed, 8003 /* SizeLimitExceeded */, thePayload.sendType);\r\n }\r\n if (thePayload.failedEvts && thePayload.failedEvts.length > 0) {\r\n // Ensure that we send any discard events for events that could not be serialized even when there was no payload to send\r\n _sendBatchesNotification(thePayload.failedEvts, 8002 /* InvalidEvent */, thePayload.sendType);\r\n }\r\n }\r\n function _addEventCompletedTimings(theEvents, sendEventCompleted) {\r\n if (_enableEventTimings) {\r\n arrForEach(theEvents, function (theEvent) {\r\n var timings = theEvent.timings = theEvent.timings || {};\r\n _setTimingValue(timings, \"sendEventCompleted\", sendEventCompleted);\r\n });\r\n }\r\n }\r\n function _retryRequestIfNeeded(status, headers, thePayload, sendReason) {\r\n var reason = 9000 /* ResponseFailure */;\r\n var droppedBatches = null;\r\n var isRetrying = false;\r\n var backOffTrans = false;\r\n try {\r\n var shouldRetry = true;\r\n if (typeof status !== strUndefined) {\r\n if (headers) {\r\n _clockSkewManager.setClockSkew(headers[strTimeDeltaHeader]);\r\n var killDuration = headers[strKillDurationHeader] || headers[\"kill-duration-seconds\"];\r\n arrForEach(_killSwitch.setKillSwitchTenants(headers[strKillTokensHeader], killDuration), function (killToken) {\r\n arrForEach(thePayload.batches, function (theBatch) {\r\n if (theBatch.iKey() === killToken) {\r\n // Make sure we have initialized the array\r\n droppedBatches = droppedBatches || [];\r\n // Create a copy of the batch with all of the events (and more importantly the action functions)\r\n var removedEvents = theBatch.split(0);\r\n // And then remove the events for the payload batch and reduce the actual number of processed\r\n thePayload.numEvents -= removedEvents.count();\r\n droppedBatches.push(removedEvents);\r\n }\r\n });\r\n });\r\n }\r\n // Disabling triple-equals rule to avoid httpOverrides from failing because they are returning a string value\r\n // tslint:disable-next-line:triple-equals\r\n if (status == 200 || status == 204) {\r\n // Response was successfully sent\r\n reason = 200 /* Complete */;\r\n return;\r\n }\r\n if (!RetryPolicy.shouldRetryForStatus(status) || thePayload.numEvents <= 0) {\r\n // Only retry for specific response codes and if there is still events after kill switch processing\r\n shouldRetry = false;\r\n }\r\n // Derive the notification response from the HttpStatus Code\r\n reason = 9000 /* ResponseFailure */ + (status % 1000);\r\n }\r\n if (shouldRetry) {\r\n // The events should be retried -- so change notification to requeue them\r\n reason = 100 /* RequeueEvents */;\r\n var retryCount_1 = thePayload.retryCnt;\r\n if (thePayload.sendType === 0 /* Batched */) {\r\n // attempt to resend the entire batch\r\n if (retryCount_1 < maxRequestRetriesBeforeBackoff) {\r\n isRetrying = true;\r\n _doAction(function () {\r\n // try to resend the same batches\r\n if (thePayload.sendType === 0 /* Batched */) {\r\n // Reduce the outstanding request count (if this was an async request) as we didn't reduce the count\r\n // previously and we are about to reschedule our retry attempt and we want an attempt to send\r\n // to occur, it's also required to ensure that a follow up handleRequestFinished() call occurs\r\n _outstandingRequests--;\r\n }\r\n _sendBatches(thePayload.batches, retryCount_1 + 1, thePayload.isTeardown, _isUnloading ? 2 /* SendBeacon */ : thePayload.sendType, 5 /* Retry */);\r\n }, _isUnloading, RetryPolicy.getMillisToBackoffForRetry(retryCount_1));\r\n }\r\n else {\r\n backOffTrans = true;\r\n if (_isUnloading) {\r\n // we are unloading so don't try and requeue the events otherwise let the events get requeued and resent during the backoff sending\r\n // This will also cause the events to be purged based on the priority (if necessary)\r\n reason = 8001 /* NonRetryableStatus */;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n finally {\r\n if (!isRetrying) {\r\n // Make sure the clockSkewManager doesn't blocking further sending of requests once we have a proper response\r\n // This won't override any previously sent clock Skew value\r\n _clockSkewManager.setClockSkew();\r\n _handleRequestFinished(thePayload, reason, sendReason, backOffTrans);\r\n }\r\n _sendBatchesNotification(droppedBatches, 8004 /* KillSwitch */, thePayload.sendType);\r\n }\r\n }\r\n function _handleRequestFinished(thePayload, batchReason, sendReason, backOffTrans) {\r\n try {\r\n if (backOffTrans) {\r\n // Slow down the transmission requests\r\n _postManager._backOffTransmission();\r\n }\r\n if (batchReason === 200 /* Complete */) {\r\n if (!backOffTrans && !thePayload.isSync) {\r\n // We have a successful async response, so the lets open the floodgates\r\n // The reason for checking isSync is to avoid unblocking if beacon send occurred as it\r\n // doesn't wait for a response.\r\n _postManager._clearBackOff();\r\n }\r\n _addCompleteTimings(thePayload.batches);\r\n }\r\n // Send the notifications synchronously\r\n _sendBatchesNotification(thePayload.batches, batchReason, thePayload.sendType, true);\r\n }\r\n finally {\r\n if (thePayload.sendType === 0 /* Batched */) {\r\n // we always need to decrement this value otherwise the httpmanager locks up and won't send any more events\r\n _outstandingRequests--;\r\n // Don't try to send additional queued events if this is a retry operation as the retried\r\n // response will eventually call _handleRequestFinished for the retried event\r\n if (sendReason !== 5 /* Retry */) {\r\n // Try and send any other queued batched events\r\n _self.sendQueuedRequests(thePayload.sendType, sendReason);\r\n }\r\n }\r\n }\r\n }\r\n function _addCompleteTimings(theBatches) {\r\n if (_enableEventTimings) {\r\n var sendEventCompleted_1 = getTime();\r\n arrForEach(theBatches, function (theBatch) {\r\n if (theBatch && theBatch.count() > 0) {\r\n _addEventCompletedTimings(theBatch.events(), sendEventCompleted_1);\r\n }\r\n });\r\n }\r\n }\r\n function _doAction(cb, isSync, interval) {\r\n if (isSync) {\r\n cb();\r\n }\r\n else {\r\n _postManager._setTimeoutOverride(cb, interval);\r\n }\r\n }\r\n /**\r\n * Converts the XHR getAllResponseHeaders to a map containing the header key and value.\r\n */\r\n // tslint:disable-next-line: align\r\n function _convertAllHeadersToMap(headersString) {\r\n var headers = {};\r\n if (isString(headersString)) {\r\n var headersArray = strTrim(headersString).split(/[\\r\\n]+/);\r\n arrForEach(headersArray, function (headerEntry) {\r\n if (headerEntry) {\r\n var idx = headerEntry.indexOf(\": \");\r\n if (idx !== -1) {\r\n // The new spec has the headers returning all as lowercase -- but not all browsers do this yet\r\n var header = strTrim(headerEntry.substring(0, idx)).toLowerCase();\r\n var value = strTrim(headerEntry.substring(idx + 1));\r\n headers[header] = value;\r\n }\r\n else {\r\n headers[strTrim(headerEntry)] = 1;\r\n }\r\n }\r\n });\r\n }\r\n return headers;\r\n }\r\n function _getMsfpc(thePayload) {\r\n for (var lp = 0; lp < thePayload.batches.length; lp++) {\r\n var msfpc = thePayload.batches[lp].Msfpc();\r\n if (msfpc) {\r\n return encodeURIComponent(msfpc);\r\n }\r\n }\r\n return \"\";\r\n }\r\n function _handleCollectorResponse(responseText) {\r\n var responseHandlers = _self._responseHandlers;\r\n try {\r\n for (var i = 0; i < responseHandlers.length; i++) {\r\n try {\r\n responseHandlers[i](responseText);\r\n }\r\n catch (e) {\r\n _postManager.diagLog().throwInternal(LoggingSeverity.CRITICAL, _ExtendedInternalMessageId.PostResponseHandler, \"Response handler failed: \" + e);\r\n }\r\n }\r\n if (responseText) {\r\n var response = JSON.parse(responseText);\r\n if (isValueAssigned(response.webResult) && isValueAssigned(response.webResult[strMsfpc])) {\r\n // Set cookie\r\n _cookieMgr.set(\"MSFPC\", response.webResult[strMsfpc], 365 * 86400);\r\n }\r\n }\r\n }\r\n catch (ex) {\r\n // Doing nothing\r\n }\r\n }\r\n function _sendBatchesNotification(theBatches, batchReason, sendType, sendSync) {\r\n if (theBatches && theBatches.length > 0 && actions) {\r\n var theAction_1 = actions[_getNotificationAction(batchReason)];\r\n if (theAction_1) {\r\n var isSyncRequest_1 = sendType !== 0 /* Batched */;\r\n doPerf(_core, function () { return \"HttpManager:_sendBatchesNotification\"; }, function () {\r\n _doAction(function () {\r\n try {\r\n theAction_1.call(actions, theBatches, batchReason, isSyncRequest_1, sendType);\r\n }\r\n catch (e) {\r\n _postManager.diagLog().throwInternal(LoggingSeverity.CRITICAL, _ExtendedInternalMessageId.NotificationException, \"send request notification failed: \" + e);\r\n }\r\n }, sendSync || isSyncRequest_1, 0);\r\n }, function () { return ({ batches: _createDebugBatches(theBatches), reason: batchReason, isSync: isSyncRequest_1, sendSync: sendSync, sendType: sendType }); }, !isSyncRequest_1);\r\n }\r\n }\r\n }\r\n function _getNotificationAction(reason) {\r\n var action = _eventActionMap[reason];\r\n if (!isValueAssigned(action)) {\r\n action = strOther;\r\n if (reason >= 9000 /* ResponseFailure */ && reason <= 9999 /* ResponseFailureMax */) {\r\n action = strResponseFail;\r\n }\r\n else if (reason >= 8000 /* EventsDropped */ && reason <= 8999 /* EventsDroppedMax */) {\r\n action = strDropped;\r\n }\r\n else if (reason >= 1000 /* SendingUndefined */ && reason <= 1999 /* SendingEventMax */) {\r\n action = strSending;\r\n }\r\n }\r\n return action;\r\n }\r\n });\r\n }\r\n /**\r\n * @constructor\r\n * @param requestQueue - The queue that contains the requests to be sent.\r\n * @param endpointUrl - The collector url to which the requests must be sent.\r\n * @param postManager - The post manager that we should add requests back to if needed.\r\n * @param httpInterface - The http interface that should be used to send HTTP requests.\r\n * @param channelConfig - The IChannelConfiguration the should be used to get additional configuration\r\n */\r\n HttpManager.prototype.initialize = function (endpointUrl, core, postChannel, httpInterface, channelConfig) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Add query string parameter to url\r\n * @param name - Query string name.\r\n * @param value - Query string value.\r\n */\r\n HttpManager.prototype.addQueryStringParameter = function (name, value) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Add header to request\r\n * @param name - Header name.\r\n * @param value - Header value.\r\n */\r\n HttpManager.prototype.addHeader = function (name, value) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Add the batch of events to the queue for sending\r\n * @param batch The batch with the events to send\r\n * @returns True if the http manager has accepted the batch (including if the batch is empty) otherwise false\r\n */\r\n HttpManager.prototype.addBatch = function (batch) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n return false;\r\n };\r\n /**\r\n * Check if there is an idle connection and we can send a request.\r\n * @returns True if there is an idle connection, false otherwise.\r\n */\r\n HttpManager.prototype.canSendRequest = function () {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n return false;\r\n };\r\n /**\r\n * Send requests in the request queue up if there is an idle connection, sending is\r\n * not pause and clock skew manager allows sending request.\r\n * @param sendType - Identifies how the batched events should be send, defaults to Batched\r\n * @param sendReason - The reason the batch is being sent\r\n */\r\n HttpManager.prototype.sendQueuedRequests = function (sendType, sendReason) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Check if there are no active requests being sent.\r\n * @returns True if idle, false otherwise.\r\n */\r\n HttpManager.prototype.isCompletelyIdle = function () {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n return false;\r\n };\r\n /**\r\n * Inform the HttpManager that a page unload event was received\r\n */\r\n HttpManager.prototype.setUnloading = function (value) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Queue all the remaining requests to be sent. The requests will be\r\n * sent using HTML5 Beacons if they are available.\r\n */\r\n HttpManager.prototype.teardown = function () {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Pause the sending of requests. No new requests will be sent.\r\n */\r\n HttpManager.prototype.pause = function () {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Resume the sending of requests.\r\n */\r\n HttpManager.prototype.resume = function () {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Sends the batches synchronously to the collector. This api is used to send a batches immediate event.\r\n *\r\n * @param batch - The batch of events to be sent.\r\n * @param sendReason - The reason the batch is being sent\r\n * @param sendType - Identifies the sending type to use when sending the batch\r\n */\r\n HttpManager.prototype.sendSynchronousBatch = function (batch, sendType, sendReason) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n return HttpManager;\r\n}());\r\nexport { HttpManager };\r\n//# sourceMappingURL=HttpManager.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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;+DA+FM;AACN;AACA;AACA;AACA"}
|
|
1
|
+
{"version":3,"file":"HttpManager.js.map","sources":["HttpManager.js"],"sourcesContent":["var _a;\r\n/**\r\n* HttpManager.ts\r\n* @author Abhilash Panwar (abpanwar); Hector Hernandez (hectorh); Nev Wylie (newylie)\r\n* @copyright Microsoft 2018-2020\r\n*/\r\nimport { 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\";\r\nimport { Serializer } from \"./Serializer\";\r\nimport { retryPolicyGetMillisToBackoffForRetry, retryPolicyShouldRetryForStatus } from \"./RetryPolicy\";\r\nimport EVTKillSwitch from \"./KillSwitch\";\r\nimport EVTClockSkewManager from \"./ClockSkewManager\";\r\nimport dynamicProto from \"@microsoft/dynamicproto-js\";\r\nimport { 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\";\r\nvar strSendAttempt = \"sendAttempt\";\r\nvar _noResponseQs = \"&\" + strNoResponseBody + \"=true\";\r\n/**\r\n * Identifies the default notification reason to the action names\r\n */\r\nvar _eventActionMap = (_a = {},\r\n _a[1 /* Paused */] = strRequeue,\r\n _a[100 /* RequeueEvents */] = strRequeue,\r\n _a[200 /* Complete */] = \"sent\",\r\n _a[8004 /* KillSwitch */] = strDropped,\r\n _a[8003 /* SizeLimitExceeded */] = strDropped,\r\n _a);\r\nvar _collectorQsHeaders = {};\r\nvar _collectorHeaderToQs = {};\r\nfunction _addCollectorHeaderQsMapping(qsName, headerName, allowQs) {\r\n _collectorQsHeaders[qsName] = headerName;\r\n if (allowQs !== false) {\r\n _collectorHeaderToQs[headerName] = qsName;\r\n }\r\n}\r\n_addCollectorHeaderQsMapping(strMsaDeviceTicket, strMsaDeviceTicket, false);\r\n_addCollectorHeaderQsMapping(strClientVersion, strClientVersion);\r\n_addCollectorHeaderQsMapping(strClientId, \"Client-Id\");\r\n_addCollectorHeaderQsMapping(strApiKey, strApiKey);\r\n_addCollectorHeaderQsMapping(strTimeDeltaToApply, strTimeDeltaToApply);\r\n_addCollectorHeaderQsMapping(strUploadTime, strUploadTime);\r\n_addCollectorHeaderQsMapping(strAuthXToken, strAuthXToken);\r\nfunction _getResponseText(xhr) {\r\n try {\r\n return xhr.responseText;\r\n }\r\n catch (e) {\r\n // Best effort, as XHR may throw while XDR wont so just ignore\r\n }\r\n return \"\";\r\n}\r\nfunction _hasHeader(headers, header) {\r\n var hasHeader = false;\r\n if (headers && header) {\r\n var keys = objKeys(headers);\r\n if (keys && keys.length > 0) {\r\n var lowerHeader = header.toLowerCase();\r\n for (var lp = 0; lp < keys.length; lp++) {\r\n var value = keys[lp];\r\n if (value && hasOwnProperty(header, value) &&\r\n value.toLowerCase() === lowerHeader) {\r\n hasHeader = true;\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n return hasHeader;\r\n}\r\nfunction _addRequestDetails(details, name, value, useHeaders) {\r\n if (name && value && value.length > 0) {\r\n if (useHeaders && _collectorQsHeaders[name]) {\r\n details.hdrs[_collectorQsHeaders[name]] = value;\r\n details.useHdrs = true;\r\n }\r\n else {\r\n details.url += \"&\" + name + \"=\" + value;\r\n }\r\n }\r\n}\r\n/**\r\n * Class managing the sending of requests.\r\n */\r\nvar HttpManager = /** @class */ (function () {\r\n /**\r\n * @constructor\r\n * @param requestQueue - The queue that contains the requests to be sent.\r\n */\r\n function HttpManager(maxEventsPerBatch, maxConnections, maxRequestRetriesBeforeBackoff, actions, timeoutOverride) {\r\n this._responseHandlers = [];\r\n var _urlString = \"?cors=true&\" + strContentTypeHeader.toLowerCase() + \"=\" + defaultContentType;\r\n var _killSwitch = new EVTKillSwitch();\r\n var _paused = false;\r\n var _clockSkewManager = new EVTClockSkewManager();\r\n var _useBeacons = false;\r\n var _outstandingRequests = 0; // Holds the number of outstanding async requests that have not returned a response yet\r\n var _postManager;\r\n var _sendInterfaces;\r\n var _core;\r\n var _customHttpInterface = true;\r\n var _queryStringParameters = [];\r\n var _headers = {};\r\n var _batchQueue = [];\r\n var _serializer = null;\r\n var _enableEventTimings = false;\r\n var _cookieMgr;\r\n var _isUnloading = false;\r\n var _useHeaders = false;\r\n var _xhrTimeout;\r\n var _disableXhrSync;\r\n dynamicProto(HttpManager, this, function (_self) {\r\n var _sendCredentials = true;\r\n _self.initialize = function (endpointUrl, core, postChannel, httpInterface, channelConfig) {\r\n var _a;\r\n if (!channelConfig) {\r\n channelConfig = {};\r\n }\r\n _urlString = endpointUrl + _urlString;\r\n _useHeaders = !isUndefined(channelConfig.avoidOptions) ? !channelConfig.avoidOptions : true;\r\n _core = core;\r\n _cookieMgr = core.getCookieMgr();\r\n _enableEventTimings = !_core.config.disableEventTimings;\r\n var enableCompoundKey = !!_core.config.enableCompoundKey;\r\n _postManager = postChannel;\r\n var valueSanitizer = channelConfig.valueSanitizer;\r\n var stringifyObjects = channelConfig.stringifyObjects;\r\n if (!isUndefined(channelConfig.enableCompoundKey)) {\r\n enableCompoundKey = !!channelConfig.enableCompoundKey;\r\n }\r\n _xhrTimeout = channelConfig.xhrTimeout;\r\n _disableXhrSync = channelConfig.disableXhrSync;\r\n _useBeacons = !isReactNative(); // Only use beacons if not running in React Native\r\n _serializer = new Serializer(_core, valueSanitizer, stringifyObjects, enableCompoundKey);\r\n var syncHttpInterface = httpInterface;\r\n var beaconHttpInterface = channelConfig.alwaysUseXhrOverride ? httpInterface : null;\r\n var fetchSyncHttpInterface = channelConfig.alwaysUseXhrOverride ? httpInterface : null;\r\n if (!httpInterface) {\r\n _customHttpInterface = false;\r\n var location_1 = getLocation();\r\n if (location_1 && location_1.protocol && location_1.protocol.toLowerCase() === \"file:\") {\r\n // Special case where a local html file fails with a CORS error on Chromium browsers\r\n _sendCredentials = false;\r\n }\r\n var theTransports = [];\r\n if (isReactNative()) {\r\n // Use Fetch or XDR/XHR\r\n theTransports = [2 /* Fetch */, 1 /* Xhr */];\r\n }\r\n else {\r\n // Use XDR/XHR, Fetch or beacons\r\n theTransports = [1 /* Xhr */, 2 /* Fetch */, 3 /* Beacon */];\r\n }\r\n // Prefix any user requested transport(s) values\r\n var configTransports = channelConfig.transports;\r\n if (configTransports) {\r\n if (isNumber(configTransports)) {\r\n theTransports = [configTransports].concat(theTransports);\r\n }\r\n else if (isArray(configTransports)) {\r\n theTransports = configTransports.concat(theTransports);\r\n }\r\n }\r\n httpInterface = _getSenderInterface(theTransports, false);\r\n syncHttpInterface = _getSenderInterface(theTransports, true);\r\n if (!httpInterface) {\r\n _postManager.diagLog().warnToConsole(\"No available transport to send events\");\r\n }\r\n }\r\n _sendInterfaces = (_a = {},\r\n _a[0 /* Batched */] = httpInterface,\r\n _a[1 /* Synchronous */] = syncHttpInterface || _getSenderInterface([1 /* Xhr */, 2 /* Fetch */, 3 /* Beacon */], true),\r\n _a[2 /* SendBeacon */] = beaconHttpInterface || _getSenderInterface([3 /* Beacon */, 2 /* Fetch */], true) || syncHttpInterface || _getSenderInterface([1 /* Xhr */], true),\r\n _a[3 /* SyncFetch */] = fetchSyncHttpInterface || _getSenderInterface([2 /* Fetch */, 3 /* Beacon */], true) || syncHttpInterface || _getSenderInterface([1 /* Xhr */], true),\r\n _a);\r\n };\r\n // Special internal method to allow the DebugPlugin to hook embedded objects\r\n function _getSenderInterface(transports, syncSupport) {\r\n var transportType = 0 /* NotSet */;\r\n var sendPostFunc = null;\r\n var lp = 0;\r\n while (sendPostFunc == null && lp < transports.length) {\r\n transportType = transports[lp];\r\n if (transportType === 1 /* Xhr */) {\r\n if (useXDomainRequest()) {\r\n sendPostFunc = _xdrSendPost;\r\n }\r\n else if (isXhrSupported()) {\r\n sendPostFunc = _xhrSendPost;\r\n }\r\n }\r\n else if (transportType === 2 /* Fetch */ && isFetchSupported(syncSupport)) {\r\n sendPostFunc = _fetchSendPost;\r\n }\r\n else if (_useBeacons && transportType === 3 /* Beacon */ && isBeaconsSupported()) {\r\n sendPostFunc = _beaconSendPost;\r\n }\r\n lp++;\r\n }\r\n if (sendPostFunc) {\r\n return {\r\n _transport: transportType,\r\n _isSync: syncSupport,\r\n sendPOST: sendPostFunc\r\n };\r\n }\r\n return null;\r\n }\r\n _self[\"_getDbgPlgTargets\"] = function () {\r\n return [_sendInterfaces[0 /* Batched */], _killSwitch, _serializer, _sendInterfaces];\r\n };\r\n function _xdrSendPost(payload, oncomplete, sync) {\r\n // It doesn't support custom headers, so no action is taken with current requestHeaders\r\n var xdr = new XDomainRequest();\r\n xdr.open(Method, payload.urlString);\r\n if (payload.timeout) {\r\n xdr.timeout = payload.timeout;\r\n }\r\n // can't get the status code in xdr.\r\n xdr.onload = function () {\r\n // we will assume onload means the request succeeded.\r\n var response = _getResponseText(xdr);\r\n _doOnComplete(oncomplete, 200, {}, response);\r\n _handleCollectorResponse(response);\r\n };\r\n // we will assume onerror means we need to drop the events.\r\n xdr.onerror = function () {\r\n _doOnComplete(oncomplete, 400, {});\r\n };\r\n // we will assume ontimeout means we need to retry the events.\r\n xdr.ontimeout = function () {\r\n _doOnComplete(oncomplete, 500, {});\r\n };\r\n // https://cypressnorth.com/web-programming-and-development/internet-explorer-aborting-ajax-requests-fixed/\r\n // tslint:disable-next-line:no-empty\r\n xdr.onprogress = function () { };\r\n if (sync) {\r\n xdr.send(payload.data);\r\n }\r\n else {\r\n timeoutOverride.set(function () {\r\n xdr.send(payload.data);\r\n }, 0);\r\n }\r\n }\r\n function _fetchSendPost(payload, oncomplete, sync) {\r\n var _a;\r\n var theUrl = payload.urlString;\r\n var ignoreResponse = false;\r\n var responseHandled = false;\r\n var requestInit = (_a = {\r\n body: payload.data,\r\n method: Method\r\n },\r\n _a[DisabledPropertyName] = true,\r\n _a);\r\n if (sync) {\r\n requestInit.keepalive = true;\r\n if (payload._sendReason === 2 /* Unload */) {\r\n // As a sync request (during unload), it is unlikely that we will get a chance to process the response so\r\n // just like beacon send assume that the events have been accepted and processed\r\n ignoreResponse = true;\r\n theUrl += _noResponseQs;\r\n }\r\n }\r\n if (_sendCredentials) {\r\n // Don't send credentials when URL is file://\r\n requestInit.credentials = \"include\";\r\n }\r\n // Only add headers if there are headers to add, due to issue with some polyfills\r\n if (payload.headers && objKeys(payload.headers).length > 0) {\r\n requestInit.headers = payload.headers;\r\n }\r\n fetch(theUrl, requestInit).then(function (response) {\r\n var headerMap = {};\r\n var responseText = \"\";\r\n if (response.headers) {\r\n response.headers.forEach(function (value, name) {\r\n headerMap[name] = value;\r\n });\r\n }\r\n if (response.body) {\r\n response.text().then(function (text) {\r\n responseText = text;\r\n });\r\n }\r\n if (!responseHandled) {\r\n responseHandled = true;\r\n _doOnComplete(oncomplete, response.status, headerMap, responseText);\r\n _handleCollectorResponse(responseText);\r\n }\r\n })[\"catch\"](function (error) {\r\n // In case there is an error in the request. Set the status to 0\r\n // so that the events can be retried later.\r\n if (!responseHandled) {\r\n responseHandled = true;\r\n _doOnComplete(oncomplete, 0, {});\r\n }\r\n });\r\n if (ignoreResponse && !responseHandled) {\r\n // Assume success during unload processing\r\n responseHandled = true;\r\n _doOnComplete(oncomplete, 200, {});\r\n }\r\n if (!responseHandled && payload.timeout > 0) {\r\n // Simulate timeout\r\n timeoutOverride.set(function () {\r\n if (!responseHandled) {\r\n // Assume a 500 response (which will cause a retry)\r\n responseHandled = true;\r\n _doOnComplete(oncomplete, 500, {});\r\n }\r\n }, payload.timeout);\r\n }\r\n }\r\n function _xhrSendPost(payload, oncomplete, sync) {\r\n var theUrl = payload.urlString;\r\n function _appendHeader(theHeaders, xhr, name) {\r\n if (!theHeaders[name] && xhr && xhr.getResponseHeader) {\r\n var value = xhr.getResponseHeader(name);\r\n if (value) {\r\n theHeaders[name] = strTrim(value);\r\n }\r\n }\r\n return theHeaders;\r\n }\r\n function _getAllResponseHeaders(xhr) {\r\n var theHeaders = {};\r\n if (!xhr.getAllResponseHeaders) {\r\n // Firefox 2-63 doesn't have getAllResponseHeaders function but it does have getResponseHeader\r\n // Only call these if getAllResponseHeaders doesn't exist, otherwise we can get invalid response errors\r\n // as collector is not currently returning the correct header to allow JS to access these headers\r\n theHeaders = _appendHeader(theHeaders, xhr, strTimeDeltaHeader);\r\n theHeaders = _appendHeader(theHeaders, xhr, strKillDurationHeader);\r\n theHeaders = _appendHeader(theHeaders, xhr, strKillDurationSecondsHeader);\r\n }\r\n else {\r\n theHeaders = _convertAllHeadersToMap(xhr.getAllResponseHeaders());\r\n }\r\n return theHeaders;\r\n }\r\n function xhrComplete(xhr, responseTxt) {\r\n _doOnComplete(oncomplete, xhr.status, _getAllResponseHeaders(xhr), responseTxt);\r\n }\r\n if (sync && payload.disableXhrSync) {\r\n sync = false;\r\n }\r\n var xhrRequest = openXhr(Method, theUrl, _sendCredentials, true, sync, payload.timeout);\r\n // Set custom headers (e.g. gzip) here (after open())\r\n objForEachKey(payload.headers, function (name, value) {\r\n xhrRequest.setRequestHeader(name, value);\r\n });\r\n xhrRequest.onload = function () {\r\n var response = _getResponseText(xhrRequest);\r\n xhrComplete(xhrRequest, response);\r\n _handleCollectorResponse(response);\r\n };\r\n xhrRequest.onerror = function () {\r\n xhrComplete(xhrRequest);\r\n };\r\n xhrRequest.ontimeout = function () {\r\n xhrComplete(xhrRequest);\r\n };\r\n xhrRequest.send(payload.data);\r\n }\r\n function _doOnComplete(oncomplete, status, headers, response) {\r\n try {\r\n oncomplete(status, headers, response);\r\n }\r\n catch (e) {\r\n _throwInternal(_postManager.diagLog(), 2 /* WARNING */, 518 /* SendPostOnCompleteFailure */, dumpObj(e));\r\n }\r\n }\r\n function _beaconSendPost(payload, oncomplete, sync) {\r\n // Custom headers not supported in sendBeacon payload.headers would be ignored\r\n var internalPayloadData = payload;\r\n var status = 200;\r\n var thePayload = internalPayloadData._thePayload;\r\n var theUrl = payload.urlString + _noResponseQs;\r\n try {\r\n var nav_1 = getNavigator();\r\n if (!nav_1.sendBeacon(theUrl, payload.data)) {\r\n if (thePayload) {\r\n // Failed to send entire payload so try and split data and try to send as much events as possible\r\n var droppedBatches_1 = [];\r\n arrForEach(thePayload.batches, function (theBatch) {\r\n if (droppedBatches_1 && theBatch && theBatch.count() > 0) {\r\n var theEvents = theBatch.events();\r\n for (var lp = 0; lp < theEvents.length; lp++) {\r\n if (!nav_1.sendBeacon(theUrl, _serializer.getEventBlob(theEvents[lp]))) {\r\n // Can't send anymore, so split the batch and drop the rest\r\n droppedBatches_1.push(theBatch.split(lp));\r\n break;\r\n }\r\n }\r\n }\r\n else {\r\n // Remove all of the events from the existing batch in the payload as the copy includes the original\r\n droppedBatches_1.push(theBatch.split(0));\r\n }\r\n });\r\n _sendBatchesNotification(droppedBatches_1, 8003 /* SizeLimitExceeded */, thePayload.sendType, true);\r\n }\r\n else {\r\n status = 0;\r\n }\r\n }\r\n }\r\n catch (ex) {\r\n _postManager.diagLog().warnToConsole(\"Failed to send telemetry using sendBeacon API. Ex:\" + dumpObj(ex));\r\n status = 0;\r\n }\r\n finally {\r\n _doOnComplete(oncomplete, status, {}, \"\");\r\n }\r\n }\r\n function _isBeaconPayload(sendType) {\r\n // Sync Fetch has the same payload limitation as sendBeacon -- 64kb limit, so treat both as a beacon send\r\n return sendType === 2 /* SendBeacon */ || sendType === 3 /* SyncFetch */;\r\n }\r\n function _adjustSendType(sendType) {\r\n if (_isUnloading && _isBeaconPayload(sendType)) {\r\n sendType = 2 /* SendBeacon */;\r\n }\r\n return sendType;\r\n }\r\n _self.addQueryStringParameter = function (name, value) {\r\n for (var i = 0; i < _queryStringParameters.length; i++) {\r\n if (_queryStringParameters[i].name === name) {\r\n _queryStringParameters[i].value = value;\r\n return;\r\n }\r\n }\r\n _queryStringParameters.push({ name: name, value: value });\r\n };\r\n _self.addHeader = function (name, value) {\r\n _headers[name] = value;\r\n };\r\n _self.canSendRequest = function () {\r\n return _hasIdleConnection() && _clockSkewManager.allowRequestSending();\r\n };\r\n _self.sendQueuedRequests = function (sendType, sendReason) {\r\n if (isUndefined(sendType)) {\r\n sendType = 0 /* Batched */;\r\n }\r\n if (_isUnloading) {\r\n sendType = _adjustSendType(sendType);\r\n sendReason = 2 /* Unload */;\r\n }\r\n if (_canSendPayload(_batchQueue, sendType, 0)) {\r\n _sendBatches(_clearQueue(), 0, false, sendType, sendReason || 0 /* Undefined */);\r\n }\r\n };\r\n _self.isCompletelyIdle = function () {\r\n return !_paused && _outstandingRequests === 0 && _batchQueue.length === 0;\r\n };\r\n _self.setUnloading = function (value) {\r\n _isUnloading = value;\r\n };\r\n _self.addBatch = function (theBatch) {\r\n if (theBatch && theBatch.count() > 0) {\r\n // Try and kill the event faster\r\n if (_killSwitch.isTenantKilled(theBatch.iKey())) {\r\n return false;\r\n }\r\n _batchQueue.push(theBatch);\r\n }\r\n return true;\r\n };\r\n /**\r\n * Queue all the remaining requests to be sent. The requests will be\r\n * sent using HTML5 Beacons if they are available.\r\n */\r\n _self.teardown = function () {\r\n if (_batchQueue.length > 0) {\r\n _sendBatches(_clearQueue(), 0, true, 2 /* SendBeacon */, 2 /* Unload */);\r\n }\r\n };\r\n /**\r\n * Pause the sending of requests. No new requests will be sent.\r\n */\r\n _self.pause = function () {\r\n _paused = true;\r\n };\r\n /**\r\n * Resume the sending of requests.\r\n */\r\n _self.resume = function () {\r\n _paused = false;\r\n _self.sendQueuedRequests(0 /* Batched */, 4 /* Resumed */);\r\n };\r\n /**\r\n * Sends a request synchronously to the Aria collector. This api is used to send\r\n * a request containing a single immediate event.\r\n *\r\n * @param batch - The request to be sent.\r\n * @param sendReason - The token used to send the request.\r\n */\r\n _self.sendSynchronousBatch = function (batch, sendType, sendReason) {\r\n // This will not take into account the max connections restriction. Since this is sync, we can\r\n // only send one of this request at a time and thus should not worry about multiple connections\r\n // being used to send synchronous events.\r\n // Increment active connection since we are still going to use a connection to send the request.\r\n if (batch && batch.count() > 0) {\r\n if (isNullOrUndefined(sendType)) {\r\n sendType = 1 /* Synchronous */;\r\n }\r\n if (_isUnloading) {\r\n sendType = _adjustSendType(sendType);\r\n sendReason = 2 /* Unload */;\r\n }\r\n // For sync requests we will not wait for the clock skew.\r\n _sendBatches([batch], 0, false, sendType, sendReason || 0 /* Undefined */);\r\n }\r\n };\r\n function _hasIdleConnection() {\r\n return !_paused && _outstandingRequests < maxConnections;\r\n }\r\n function _clearQueue() {\r\n var theQueue = _batchQueue;\r\n _batchQueue = [];\r\n return theQueue;\r\n }\r\n function _canSendPayload(theBatches, sendType, retryCnt) {\r\n var result = false;\r\n if (theBatches && theBatches.length > 0 && !_paused && _sendInterfaces[sendType] && _serializer) {\r\n // Always attempt to send synchronous events don't wait for idle or clockSkew\r\n // and don't block retry requests if clockSkew is not yet set\r\n result = (sendType !== 0 /* Batched */) || (_hasIdleConnection() && (retryCnt > 0 || _clockSkewManager.allowRequestSending()));\r\n }\r\n return result;\r\n }\r\n function _createDebugBatches(theBatches) {\r\n var values = {};\r\n if (theBatches) {\r\n arrForEach(theBatches, function (theBatch, idx) {\r\n values[idx] = {\r\n iKey: theBatch.iKey(),\r\n evts: theBatch.events()\r\n };\r\n });\r\n }\r\n return values;\r\n }\r\n function _sendBatches(theBatches, retryCount, isTeardown, sendType, sendReason) {\r\n if (!theBatches || theBatches.length === 0) {\r\n // Nothing to do\r\n return;\r\n }\r\n if (_paused) {\r\n _sendBatchesNotification(theBatches, 1 /* Paused */, sendType);\r\n return;\r\n }\r\n // Make sure that if we are unloading the sendType is a supported version\r\n sendType = _adjustSendType(sendType);\r\n try {\r\n var orgBatches_1 = theBatches;\r\n var isSynchronous_1 = sendType !== 0 /* Batched */;\r\n doPerf(_core, function () { return \"HttpManager:_sendBatches\"; }, function (perfEvt) {\r\n if (perfEvt) {\r\n // Perf Monitoring is enabled, so create a \"Quick\" copy of the original batches so we still report\r\n // the original values as part of the perfEvent. This is because theBatches uses .shift() to remove each\r\n // batch as they are processed - removing from the original array, so by the time the _createDebugBatches()\r\n // function is called the passed in value has changed and therefore the reported value for the perfEvent is incorrect\r\n theBatches = theBatches.slice(0);\r\n }\r\n var droppedBatches = [];\r\n var thePayload = null;\r\n var serializationStart = getTime();\r\n var sendInterface = _sendInterfaces[sendType] || (isSynchronous_1 ? _sendInterfaces[1 /* Synchronous */] : _sendInterfaces[0 /* Batched */]);\r\n // Sync Fetch has the same payload limitation as sendBeacon -- 64kb limit\r\n var isBeaconTransport = (_isUnloading || _isBeaconPayload(sendType) || (sendInterface && sendInterface._transport === 3 /* Beacon */)) && _canUseSendBeaconApi();\r\n while (_canSendPayload(theBatches, sendType, retryCount)) {\r\n var theBatch = theBatches.shift();\r\n if (theBatch && theBatch.count() > 0) {\r\n if (!_killSwitch.isTenantKilled(theBatch.iKey())) {\r\n // Make sure we have a payload object\r\n thePayload = thePayload || _serializer.createPayload(retryCount, isTeardown, isSynchronous_1, isBeaconTransport, sendReason, sendType);\r\n // Add the batch to the current payload\r\n if (!_serializer.appendPayload(thePayload, theBatch, maxEventsPerBatch)) {\r\n // Entire batch was not added so send the payload and retry adding this batch\r\n _doPayloadSend(thePayload, serializationStart, getTime(), sendReason);\r\n serializationStart = getTime();\r\n theBatches = [theBatch].concat(theBatches);\r\n thePayload = null;\r\n }\r\n else if (thePayload.overflow !== null) {\r\n // Total Payload size was exceeded so send the payload and add the unsent as the next batch to send\r\n theBatches = [thePayload.overflow].concat(theBatches);\r\n thePayload.overflow = null;\r\n _doPayloadSend(thePayload, serializationStart, getTime(), sendReason);\r\n serializationStart = getTime();\r\n thePayload = null;\r\n }\r\n }\r\n else {\r\n droppedBatches.push(theBatch);\r\n }\r\n }\r\n }\r\n // Make sure to flush any remaining payload\r\n if (thePayload) {\r\n _doPayloadSend(thePayload, serializationStart, getTime(), sendReason);\r\n }\r\n if (theBatches.length > 0) {\r\n // Add any unsent batches back to the head of the queue\r\n _batchQueue = theBatches.concat(_batchQueue);\r\n }\r\n // Now send notification about any dropped events\r\n _sendBatchesNotification(droppedBatches, 8004 /* KillSwitch */, sendType);\r\n }, function () { return ({ batches: _createDebugBatches(orgBatches_1), retryCount: retryCount, isTeardown: isTeardown, isSynchronous: isSynchronous_1, sendReason: sendReason, useSendBeacon: _isBeaconPayload(sendType), sendType: sendType }); }, !isSynchronous_1);\r\n }\r\n catch (ex) {\r\n _throwInternal(_postManager.diagLog(), 2 /* WARNING */, 48 /* CannotSerializeObject */, \"Unexpected Exception sending batch: \" + dumpObj(ex));\r\n }\r\n }\r\n function _buildRequestDetails(thePayload, useHeaders) {\r\n var requestDetails = {\r\n url: _urlString,\r\n hdrs: {},\r\n useHdrs: false // Assume no headers\r\n };\r\n if (!useHeaders) {\r\n // Attempt to map headers to a query string if possible\r\n objForEachKey(_headers, function (name, value) {\r\n if (_collectorHeaderToQs[name]) {\r\n _addRequestDetails(requestDetails, _collectorHeaderToQs[name], value, false);\r\n }\r\n else {\r\n // No mapping, so just include in the headers anyway (may not get sent if using sendBeacon())\r\n requestDetails.hdrs[name] = value;\r\n requestDetails.useHdrs = true;\r\n }\r\n });\r\n }\r\n else {\r\n // Copy the pre-defined headers into the payload headers\r\n requestDetails.hdrs = extend(requestDetails.hdrs, _headers);\r\n requestDetails.useHdrs = (objKeys(requestDetails.hdrs).length > 0);\r\n }\r\n _addRequestDetails(requestDetails, strClientId, \"NO_AUTH\", useHeaders);\r\n _addRequestDetails(requestDetails, strClientVersion, FullVersionString, useHeaders);\r\n var apiQsKeys = \"\";\r\n arrForEach(thePayload.apiKeys, function (apiKey) {\r\n if (apiQsKeys.length > 0) {\r\n apiQsKeys += \",\";\r\n }\r\n apiQsKeys += apiKey;\r\n });\r\n _addRequestDetails(requestDetails, strApiKey, apiQsKeys, useHeaders);\r\n _addRequestDetails(requestDetails, strUploadTime, dateNow().toString(), useHeaders);\r\n var msfpc = _getMsfpc(thePayload);\r\n if (isValueAssigned(msfpc)) {\r\n requestDetails.url += \"&ext.intweb.msfpc=\" + msfpc;\r\n }\r\n if (_clockSkewManager.shouldAddClockSkewHeaders()) {\r\n _addRequestDetails(requestDetails, strTimeDeltaToApply, _clockSkewManager.getClockSkewHeaderValue(), useHeaders);\r\n }\r\n if (_core.getWParam) {\r\n var wParam = _core.getWParam();\r\n if (wParam >= 0) {\r\n requestDetails.url += \"&w=\" + wParam;\r\n }\r\n }\r\n for (var i = 0; i < _queryStringParameters.length; i++) {\r\n requestDetails.url += \"&\" + _queryStringParameters[i].name + \"=\" + _queryStringParameters[i].value;\r\n }\r\n return requestDetails;\r\n }\r\n function _canUseSendBeaconApi() {\r\n return !_customHttpInterface && _useBeacons && isBeaconsSupported();\r\n }\r\n function _setTimingValue(timings, name, value) {\r\n timings[name] = timings[name] || {};\r\n timings[name][_postManager.identifier] = value;\r\n }\r\n function _doPayloadSend(thePayload, serializationStart, serializationCompleted, sendReason) {\r\n if (thePayload && thePayload.payloadBlob && thePayload.payloadBlob.length > 0) {\r\n var useSendHook_1 = !!_self.sendHook;\r\n var sendInterface_1 = _sendInterfaces[thePayload.sendType];\r\n // Send all data using a beacon style transport if closing mode is on or channel was teared down\r\n if (!_isBeaconPayload(thePayload.sendType) && thePayload.isBeacon && thePayload.sendReason === 2 /* Unload */) {\r\n sendInterface_1 = _sendInterfaces[2 /* SendBeacon */] || _sendInterfaces[3 /* SyncFetch */] || sendInterface_1;\r\n }\r\n var useHeaders_1 = _useHeaders;\r\n // Disable header usage if we know we are using sendBeacon as additional headers are not supported\r\n if (thePayload.isBeacon || sendInterface_1._transport === 3 /* Beacon */) {\r\n useHeaders_1 = false;\r\n }\r\n var requestDetails_1 = _buildRequestDetails(thePayload, useHeaders_1);\r\n useHeaders_1 = useHeaders_1 || requestDetails_1.useHdrs;\r\n var sendEventStart_1 = getTime();\r\n doPerf(_core, function () { return \"HttpManager:_doPayloadSend\"; }, function () {\r\n // Increment the send attempt count and add timings after packaging (So it's not serialized in the 1st attempt)\r\n for (var batchLp = 0; batchLp < thePayload.batches.length; batchLp++) {\r\n var theBatch = thePayload.batches[batchLp];\r\n var theEvents = theBatch.events();\r\n for (var evtLp = 0; evtLp < theEvents.length; evtLp++) {\r\n var telemetryItem = theEvents[evtLp];\r\n if (_enableEventTimings) {\r\n var timings = telemetryItem.timings = telemetryItem.timings || {};\r\n _setTimingValue(timings, \"sendEventStart\", sendEventStart_1);\r\n _setTimingValue(timings, \"serializationStart\", serializationStart);\r\n _setTimingValue(timings, \"serializationCompleted\", serializationCompleted);\r\n }\r\n telemetryItem[strSendAttempt] > 0 ? telemetryItem[strSendAttempt]++ : telemetryItem[strSendAttempt] = 1;\r\n }\r\n }\r\n // Note: always sending this notification in a synchronous manner.\r\n _sendBatchesNotification(thePayload.batches, (1000 /* SendingUndefined */ + (sendReason || 0 /* Undefined */)), thePayload.sendType, true);\r\n // Disabling the use of const because of Issue: \r\n // - Task 9227844: [1DS] Some environments and packagers automatically \"freeze\" objects which are defined as const which causes any mutations to throw\r\n // eslint-disable-next-line prefer-const\r\n var orgPayloadData = {\r\n data: thePayload.payloadBlob,\r\n urlString: requestDetails_1.url,\r\n headers: requestDetails_1.hdrs,\r\n _thePayload: thePayload,\r\n _sendReason: sendReason,\r\n timeout: _xhrTimeout\r\n };\r\n if (!isUndefined(_disableXhrSync)) {\r\n orgPayloadData.disableXhrSync = !!_disableXhrSync;\r\n }\r\n // Only automatically add the following headers if already sending headers and we are not attempting to avoid an options call\r\n if (useHeaders_1) {\r\n if (!_hasHeader(orgPayloadData.headers, strCacheControl)) {\r\n orgPayloadData.headers[strCacheControl] = defaultCacheControl;\r\n }\r\n if (!_hasHeader(orgPayloadData.headers, strContentTypeHeader)) {\r\n orgPayloadData.headers[strContentTypeHeader] = defaultContentType;\r\n }\r\n }\r\n var sender = null;\r\n if (sendInterface_1) {\r\n // Send sync requests if the request is immediate or we are tearing down telemetry.\r\n sender = function (payload) {\r\n // Notify the clock skew manager that we are sending the first request (Potentially blocking all further requests)\r\n _clockSkewManager.firstRequestSent();\r\n var onComplete = function (status, headers) {\r\n _retryRequestIfNeeded(status, headers, thePayload, sendReason);\r\n };\r\n var isSync = thePayload.isTeardown || thePayload.isSync;\r\n try {\r\n sendInterface_1.sendPOST(payload, onComplete, isSync);\r\n if (_self.sendListener) {\r\n // Send the original payload to the listener\r\n _self.sendListener(orgPayloadData, payload, isSync, thePayload.isBeacon);\r\n }\r\n }\r\n catch (ex) {\r\n _postManager.diagLog().warnToConsole(\"Unexpected exception sending payload. Ex:\" + dumpObj(ex));\r\n _doOnComplete(onComplete, 0, {});\r\n }\r\n };\r\n }\r\n doPerf(_core, function () { return \"HttpManager:_doPayloadSend.sender\"; }, function () {\r\n if (sender) {\r\n if (thePayload.sendType === 0 /* Batched */) {\r\n _outstandingRequests++;\r\n }\r\n // Only call the hook if it's defined and we are not using sendBeacon as additional headers are not supported\r\n if (useSendHook_1 && !thePayload.isBeacon && sendInterface_1._transport !== 3 /* Beacon */) {\r\n // Create a new IPayloadData that is sent into the hook method, so that the hook method\r\n // can't change the object references to the orgPayloadData (it can still change the content -- mainly the headers)\r\n // Disabling the use of const because of Issue: \r\n // - Task 9227844: [1DS] Some environments and packagers automatically \"freeze\" objects which are defined as const which causes any mutations to throw\r\n // eslint-disable-next-line prefer-const\r\n var hookData_1 = {\r\n data: orgPayloadData.data,\r\n urlString: orgPayloadData.urlString,\r\n headers: extend({}, orgPayloadData.headers),\r\n timeout: orgPayloadData.timeout,\r\n disableXhrSync: orgPayloadData.disableXhrSync\r\n };\r\n var senderCalled_1 = false;\r\n doPerf(_core, function () { return \"HttpManager:_doPayloadSend.sendHook\"; }, function () {\r\n try {\r\n _self.sendHook(hookData_1, function (payload) {\r\n senderCalled_1 = true;\r\n // Add back the internal properties\r\n if (!_customHttpInterface && !payload._thePayload) {\r\n payload._thePayload = payload._thePayload || orgPayloadData._thePayload;\r\n payload._sendReason = payload._sendReason || orgPayloadData._sendReason;\r\n }\r\n sender(payload);\r\n }, thePayload.isSync || thePayload.isTeardown);\r\n }\r\n catch (ex) {\r\n if (!senderCalled_1) {\r\n // The hook never called the sender -- assume that it never will\r\n sender(orgPayloadData);\r\n }\r\n }\r\n });\r\n }\r\n else {\r\n sender(orgPayloadData);\r\n }\r\n }\r\n });\r\n }, function () { return ({ thePayload: thePayload, serializationStart: serializationStart, serializationCompleted: serializationCompleted, sendReason: sendReason }); }, thePayload.isSync);\r\n }\r\n if (thePayload.sizeExceed && thePayload.sizeExceed.length > 0) {\r\n // Ensure that we send any discard events for oversize events even when there was no payload to send\r\n _sendBatchesNotification(thePayload.sizeExceed, 8003 /* SizeLimitExceeded */, thePayload.sendType);\r\n }\r\n if (thePayload.failedEvts && thePayload.failedEvts.length > 0) {\r\n // Ensure that we send any discard events for events that could not be serialized even when there was no payload to send\r\n _sendBatchesNotification(thePayload.failedEvts, 8002 /* InvalidEvent */, thePayload.sendType);\r\n }\r\n }\r\n function _addEventCompletedTimings(theEvents, sendEventCompleted) {\r\n if (_enableEventTimings) {\r\n arrForEach(theEvents, function (theEvent) {\r\n var timings = theEvent.timings = theEvent.timings || {};\r\n _setTimingValue(timings, \"sendEventCompleted\", sendEventCompleted);\r\n });\r\n }\r\n }\r\n function _retryRequestIfNeeded(status, headers, thePayload, sendReason) {\r\n var reason = 9000 /* ResponseFailure */;\r\n var droppedBatches = null;\r\n var isRetrying = false;\r\n var backOffTrans = false;\r\n try {\r\n var shouldRetry = true;\r\n if (typeof status !== strUndefined) {\r\n if (headers) {\r\n _clockSkewManager.setClockSkew(headers[strTimeDeltaHeader]);\r\n var killDuration = headers[strKillDurationHeader] || headers[\"kill-duration-seconds\"];\r\n arrForEach(_killSwitch.setKillSwitchTenants(headers[strKillTokensHeader], killDuration), function (killToken) {\r\n arrForEach(thePayload.batches, function (theBatch) {\r\n if (theBatch.iKey() === killToken) {\r\n // Make sure we have initialized the array\r\n droppedBatches = droppedBatches || [];\r\n // Create a copy of the batch with all of the events (and more importantly the action functions)\r\n var removedEvents = theBatch.split(0);\r\n // And then remove the events for the payload batch and reduce the actual number of processed\r\n thePayload.numEvents -= removedEvents.count();\r\n droppedBatches.push(removedEvents);\r\n }\r\n });\r\n });\r\n }\r\n // Disabling triple-equals rule to avoid httpOverrides from failing because they are returning a string value\r\n // tslint:disable-next-line:triple-equals\r\n if (status == 200 || status == 204) {\r\n // Response was successfully sent\r\n reason = 200 /* Complete */;\r\n return;\r\n }\r\n if (!retryPolicyShouldRetryForStatus(status) || thePayload.numEvents <= 0) {\r\n // Only retry for specific response codes and if there is still events after kill switch processing\r\n shouldRetry = false;\r\n }\r\n // Derive the notification response from the HttpStatus Code\r\n reason = 9000 /* ResponseFailure */ + (status % 1000);\r\n }\r\n if (shouldRetry) {\r\n // The events should be retried -- so change notification to requeue them\r\n reason = 100 /* RequeueEvents */;\r\n var retryCount_1 = thePayload.retryCnt;\r\n if (thePayload.sendType === 0 /* Batched */) {\r\n // attempt to resend the entire batch\r\n if (retryCount_1 < maxRequestRetriesBeforeBackoff) {\r\n isRetrying = true;\r\n _doAction(function () {\r\n // try to resend the same batches\r\n if (thePayload.sendType === 0 /* Batched */) {\r\n // Reduce the outstanding request count (if this was an async request) as we didn't reduce the count\r\n // previously and we are about to reschedule our retry attempt and we want an attempt to send\r\n // to occur, it's also required to ensure that a follow up handleRequestFinished() call occurs\r\n _outstandingRequests--;\r\n }\r\n _sendBatches(thePayload.batches, retryCount_1 + 1, thePayload.isTeardown, _isUnloading ? 2 /* SendBeacon */ : thePayload.sendType, 5 /* Retry */);\r\n }, _isUnloading, retryPolicyGetMillisToBackoffForRetry(retryCount_1));\r\n }\r\n else {\r\n backOffTrans = true;\r\n if (_isUnloading) {\r\n // we are unloading so don't try and requeue the events otherwise let the events get requeued and resent during the backoff sending\r\n // This will also cause the events to be purged based on the priority (if necessary)\r\n reason = 8001 /* NonRetryableStatus */;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n finally {\r\n if (!isRetrying) {\r\n // Make sure the clockSkewManager doesn't blocking further sending of requests once we have a proper response\r\n // This won't override any previously sent clock Skew value\r\n _clockSkewManager.setClockSkew();\r\n _handleRequestFinished(thePayload, reason, sendReason, backOffTrans);\r\n }\r\n _sendBatchesNotification(droppedBatches, 8004 /* KillSwitch */, thePayload.sendType);\r\n }\r\n }\r\n function _handleRequestFinished(thePayload, batchReason, sendReason, backOffTrans) {\r\n try {\r\n if (backOffTrans) {\r\n // Slow down the transmission requests\r\n _postManager._backOffTransmission();\r\n }\r\n if (batchReason === 200 /* Complete */) {\r\n if (!backOffTrans && !thePayload.isSync) {\r\n // We have a successful async response, so the lets open the floodgates\r\n // The reason for checking isSync is to avoid unblocking if beacon send occurred as it\r\n // doesn't wait for a response.\r\n _postManager._clearBackOff();\r\n }\r\n _addCompleteTimings(thePayload.batches);\r\n }\r\n // Send the notifications synchronously\r\n _sendBatchesNotification(thePayload.batches, batchReason, thePayload.sendType, true);\r\n }\r\n finally {\r\n if (thePayload.sendType === 0 /* Batched */) {\r\n // we always need to decrement this value otherwise the httpmanager locks up and won't send any more events\r\n _outstandingRequests--;\r\n // Don't try to send additional queued events if this is a retry operation as the retried\r\n // response will eventually call _handleRequestFinished for the retried event\r\n if (sendReason !== 5 /* Retry */) {\r\n // Try and send any other queued batched events\r\n _self.sendQueuedRequests(thePayload.sendType, sendReason);\r\n }\r\n }\r\n }\r\n }\r\n function _addCompleteTimings(theBatches) {\r\n if (_enableEventTimings) {\r\n var sendEventCompleted_1 = getTime();\r\n arrForEach(theBatches, function (theBatch) {\r\n if (theBatch && theBatch.count() > 0) {\r\n _addEventCompletedTimings(theBatch.events(), sendEventCompleted_1);\r\n }\r\n });\r\n }\r\n }\r\n function _doAction(cb, isSync, interval) {\r\n if (isSync) {\r\n cb();\r\n }\r\n else {\r\n timeoutOverride.set(cb, interval);\r\n }\r\n }\r\n /**\r\n * Converts the XHR getAllResponseHeaders to a map containing the header key and value.\r\n */\r\n // tslint:disable-next-line: align\r\n function _convertAllHeadersToMap(headersString) {\r\n var headers = {};\r\n if (isString(headersString)) {\r\n var headersArray = strTrim(headersString).split(/[\\r\\n]+/);\r\n arrForEach(headersArray, function (headerEntry) {\r\n if (headerEntry) {\r\n var idx = headerEntry.indexOf(\": \");\r\n if (idx !== -1) {\r\n // The new spec has the headers returning all as lowercase -- but not all browsers do this yet\r\n var header = strTrim(headerEntry.substring(0, idx)).toLowerCase();\r\n var value = strTrim(headerEntry.substring(idx + 1));\r\n headers[header] = value;\r\n }\r\n else {\r\n headers[strTrim(headerEntry)] = 1;\r\n }\r\n }\r\n });\r\n }\r\n return headers;\r\n }\r\n function _getMsfpc(thePayload) {\r\n for (var lp = 0; lp < thePayload.batches.length; lp++) {\r\n var msfpc = thePayload.batches[lp].Msfpc();\r\n if (msfpc) {\r\n return encodeURIComponent(msfpc);\r\n }\r\n }\r\n return \"\";\r\n }\r\n function _handleCollectorResponse(responseText) {\r\n var responseHandlers = _self._responseHandlers;\r\n try {\r\n for (var i = 0; i < responseHandlers.length; i++) {\r\n try {\r\n responseHandlers[i](responseText);\r\n }\r\n catch (e) {\r\n _throwInternal(_postManager.diagLog(), 1 /* CRITICAL */, 519 /* PostResponseHandler */, \"Response handler failed: \" + e);\r\n }\r\n }\r\n if (responseText) {\r\n var response = JSON.parse(responseText);\r\n if (isValueAssigned(response.webResult) && isValueAssigned(response.webResult[strMsfpc])) {\r\n // Set cookie\r\n _cookieMgr.set(\"MSFPC\", response.webResult[strMsfpc], 365 * 86400);\r\n }\r\n }\r\n }\r\n catch (ex) {\r\n // Doing nothing\r\n }\r\n }\r\n function _sendBatchesNotification(theBatches, batchReason, sendType, sendSync) {\r\n if (theBatches && theBatches.length > 0 && actions) {\r\n var theAction_1 = actions[_getNotificationAction(batchReason)];\r\n if (theAction_1) {\r\n var isSyncRequest_1 = sendType !== 0 /* Batched */;\r\n doPerf(_core, function () { return \"HttpManager:_sendBatchesNotification\"; }, function () {\r\n _doAction(function () {\r\n try {\r\n theAction_1.call(actions, theBatches, batchReason, isSyncRequest_1, sendType);\r\n }\r\n catch (e) {\r\n _throwInternal(_postManager.diagLog(), 1 /* CRITICAL */, 74 /* NotificationException */, \"send request notification failed: \" + e);\r\n }\r\n }, sendSync || isSyncRequest_1, 0);\r\n }, function () { return ({ batches: _createDebugBatches(theBatches), reason: batchReason, isSync: isSyncRequest_1, sendSync: sendSync, sendType: sendType }); }, !isSyncRequest_1);\r\n }\r\n }\r\n }\r\n function _getNotificationAction(reason) {\r\n var action = _eventActionMap[reason];\r\n if (!isValueAssigned(action)) {\r\n action = strOther;\r\n if (reason >= 9000 /* ResponseFailure */ && reason <= 9999 /* ResponseFailureMax */) {\r\n action = strResponseFail;\r\n }\r\n else if (reason >= 8000 /* EventsDropped */ && reason <= 8999 /* EventsDroppedMax */) {\r\n action = strDropped;\r\n }\r\n else if (reason >= 1000 /* SendingUndefined */ && reason <= 1999 /* SendingEventMax */) {\r\n action = strSending;\r\n }\r\n }\r\n return action;\r\n }\r\n });\r\n }\r\n /**\r\n * @constructor\r\n * @param requestQueue - The queue that contains the requests to be sent.\r\n * @param endpointUrl - The collector url to which the requests must be sent.\r\n * @param postManager - The post manager that we should add requests back to if needed.\r\n * @param httpInterface - The http interface that should be used to send HTTP requests.\r\n * @param channelConfig - The IChannelConfiguration the should be used to get additional configuration\r\n */\r\n HttpManager.prototype.initialize = function (endpointUrl, core, postChannel, httpInterface, channelConfig) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Add query string parameter to url\r\n * @param name - Query string name.\r\n * @param value - Query string value.\r\n */\r\n HttpManager.prototype.addQueryStringParameter = function (name, value) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Add header to request\r\n * @param name - Header name.\r\n * @param value - Header value.\r\n */\r\n HttpManager.prototype.addHeader = function (name, value) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Add the batch of events to the queue for sending\r\n * @param batch The batch with the events to send\r\n * @returns True if the http manager has accepted the batch (including if the batch is empty) otherwise false\r\n */\r\n HttpManager.prototype.addBatch = function (batch) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n return false;\r\n };\r\n /**\r\n * Check if there is an idle connection and we can send a request.\r\n * @returns True if there is an idle connection, false otherwise.\r\n */\r\n HttpManager.prototype.canSendRequest = function () {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n return false;\r\n };\r\n /**\r\n * Send requests in the request queue up if there is an idle connection, sending is\r\n * not pause and clock skew manager allows sending request.\r\n * @param sendType - Identifies how the batched events should be send, defaults to Batched\r\n * @param sendReason - The reason the batch is being sent\r\n */\r\n HttpManager.prototype.sendQueuedRequests = function (sendType, sendReason) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Check if there are no active requests being sent.\r\n * @returns True if idle, false otherwise.\r\n */\r\n HttpManager.prototype.isCompletelyIdle = function () {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n return false;\r\n };\r\n /**\r\n * Inform the HttpManager that a page unload event was received\r\n */\r\n HttpManager.prototype.setUnloading = function (value) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Queue all the remaining requests to be sent. The requests will be\r\n * sent using HTML5 Beacons if they are available.\r\n */\r\n HttpManager.prototype.teardown = function () {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Pause the sending of requests. No new requests will be sent.\r\n */\r\n HttpManager.prototype.pause = function () {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Resume the sending of requests.\r\n */\r\n HttpManager.prototype.resume = function () {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Sends the batches synchronously to the collector. This api is used to send a batches immediate event.\r\n *\r\n * @param batch - The batch of events to be sent.\r\n * @param sendReason - The reason the batch is being sent\r\n * @param sendType - Identifies the sending type to use when sending the batch\r\n */\r\n HttpManager.prototype.sendSynchronousBatch = function (batch, sendType, sendReason) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n return HttpManager;\r\n}());\r\nexport { HttpManager };\r\n//# sourceMappingURL=HttpManager.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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;+DA+FM;AACN;AACA;AACA;AACA"}
|