@microsoft/1ds-post-js 3.1.9 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +124 -5
- package/bundle/{ms.post-3.1.9.gbl.js → ms.post-3.2.0.gbl.js} +1706 -825
- package/bundle/ms.post-3.2.0.gbl.js.map +1 -0
- package/bundle/ms.post-3.2.0.gbl.min.js +7 -0
- package/bundle/ms.post-3.2.0.gbl.min.js.map +1 -0
- package/bundle/ms.post-3.2.0.integrity.json +46 -0
- package/bundle/{ms.post-3.1.9.js → ms.post-3.2.0.js} +1706 -825
- package/bundle/ms.post-3.2.0.js.map +1 -0
- package/bundle/ms.post-3.2.0.min.js +7 -0
- package/bundle/ms.post-3.2.0.min.js.map +1 -0
- package/bundle/ms.post.gbl.js +1705 -824
- 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 +1705 -824
- 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 +395 -212
- 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.d.ts +25 -0
- package/dist-esm/src/Constants.js +31 -0
- package/dist-esm/src/Constants.js.map +1 -0
- package/dist-esm/src/DataModels.d.ts +55 -0
- package/dist-esm/src/DataModels.js +1 -1
- package/dist-esm/src/EventBatch.d.ts +5 -2
- package/dist-esm/src/EventBatch.js +35 -15
- package/dist-esm/src/EventBatch.js.map +1 -1
- package/dist-esm/src/HttpManager.d.ts +2 -2
- package/dist-esm/src/HttpManager.js +186 -94
- 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 +0 -4
- package/dist-esm/src/PostChannel.js +175 -107
- 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/typings/XDomainRequest.js +1 -1
- package/package.json +3 -3
- package/src/Constants.ts +28 -0
- package/src/DataModels.ts +68 -0
- package/src/EventBatch.ts +47 -14
- package/src/HttpManager.ts +216 -98
- package/src/PostChannel.ts +207 -130
- package/src/RetryPolicy.ts +33 -38
- package/bundle/ms.post-3.1.9.gbl.js.map +0 -1
- package/bundle/ms.post-3.1.9.gbl.min.js +0 -7
- package/bundle/ms.post-3.1.9.gbl.min.js.map +0 -1
- package/bundle/ms.post-3.1.9.integrity.json +0 -46
- package/bundle/ms.post-3.1.9.js.map +0 -1
- package/bundle/ms.post-3.1.9.min.js +0 -7
- package/bundle/ms.post-3.1.9.min.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* 1DS JS SDK POST plugin, 3.
|
|
2
|
+
* 1DS JS SDK POST plugin, 3.2.0
|
|
3
3
|
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
4
|
* (Microsoft Internal Only)
|
|
5
5
|
*/
|
|
@@ -9,27 +9,15 @@ var _a;
|
|
|
9
9
|
* @author Abhilash Panwar (abpanwar); Hector Hernandez (hectorh); Nev Wylie (newylie)
|
|
10
10
|
* @copyright Microsoft 2018-2020
|
|
11
11
|
*/
|
|
12
|
-
import { isReactNative, isValueAssigned, isString, getTime, arrForEach, getLocation, strTrim, isFetchSupported, isXhrSupported, isBeaconsSupported, FullVersionString, useXDomainRequest,
|
|
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
|
-
|
|
19
|
-
var
|
|
20
|
-
var
|
|
21
|
-
var strSending = "send";
|
|
22
|
-
var strRequeue = "requeue";
|
|
23
|
-
var strResponseFail = "rspFail";
|
|
24
|
-
var strOther = "oth";
|
|
25
|
-
var defaultCacheControl = "no-cache, no-store";
|
|
26
|
-
var defaultContentType = "application/x-json-stream";
|
|
27
|
-
var strCacheControl = "cache-control";
|
|
28
|
-
var strContentTypeHeader = "content-type";
|
|
29
|
-
var strKillTokensHeader = "kill-tokens";
|
|
30
|
-
var strKillDurationHeader = "kill-duration";
|
|
31
|
-
var strKillDurationSecondsHeader = "kill-duration-seconds";
|
|
32
|
-
var strTimeDeltaHeader = "time-delta-millis";
|
|
18
|
+
import { defaultCacheControl, defaultContentType, DisabledPropertyName, Method, strApiKey, strAuthXToken, strCacheControl, strClientId, strClientVersion, strContentTypeHeader, strDropped, strKillDurationHeader, strKillDurationSecondsHeader, strKillTokensHeader, strMsaDeviceTicket, strMsfpc, strNoResponseBody, strOther, strRequeue, strResponseFail, strSending, strTimeDeltaHeader, strTimeDeltaToApply, strUploadTime } from "./Constants";
|
|
19
|
+
var strSendAttempt = "sendAttempt";
|
|
20
|
+
var _noResponseQs = "&" + strNoResponseBody + "=true";
|
|
33
21
|
/**
|
|
34
22
|
* Identifies the default notification reason to the action names
|
|
35
23
|
*/
|
|
@@ -40,6 +28,21 @@ var _eventActionMap = (_a = {},
|
|
|
40
28
|
_a[8004 /* KillSwitch */] = strDropped,
|
|
41
29
|
_a[8003 /* SizeLimitExceeded */] = strDropped,
|
|
42
30
|
_a);
|
|
31
|
+
var _collectorQsHeaders = {};
|
|
32
|
+
var _collectorHeaderToQs = {};
|
|
33
|
+
function _addCollectorHeaderQsMapping(qsName, headerName, allowQs) {
|
|
34
|
+
_collectorQsHeaders[qsName] = headerName;
|
|
35
|
+
if (allowQs !== false) {
|
|
36
|
+
_collectorHeaderToQs[headerName] = qsName;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
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);
|
|
43
46
|
function _getResponseText(xhr) {
|
|
44
47
|
try {
|
|
45
48
|
return xhr.responseText;
|
|
@@ -67,6 +70,17 @@ function _hasHeader(headers, header) {
|
|
|
67
70
|
}
|
|
68
71
|
return hasHeader;
|
|
69
72
|
}
|
|
73
|
+
function _addRequestDetails(details, name, value, useHeaders) {
|
|
74
|
+
if (name && value && value.length > 0) {
|
|
75
|
+
if (useHeaders && _collectorQsHeaders[name]) {
|
|
76
|
+
details.hdrs[_collectorQsHeaders[name]] = value;
|
|
77
|
+
details.useHdrs = true;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
details.url += "&" + name + "=" + value;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
70
84
|
/**
|
|
71
85
|
* Class managing the sending of requests.
|
|
72
86
|
*/
|
|
@@ -75,10 +89,9 @@ var HttpManager = /** @class */ (function () {
|
|
|
75
89
|
* @constructor
|
|
76
90
|
* @param requestQueue - The queue that contains the requests to be sent.
|
|
77
91
|
*/
|
|
78
|
-
function HttpManager(maxEventsPerBatch, maxConnections,
|
|
92
|
+
function HttpManager(maxEventsPerBatch, maxConnections, maxRequestRetriesBeforeBackoff, actions) {
|
|
79
93
|
this._responseHandlers = [];
|
|
80
|
-
var _urlString = "?cors=true&" + strContentTypeHeader.toLowerCase() + "=" + defaultContentType
|
|
81
|
-
+ FullVersionString;
|
|
94
|
+
var _urlString = "?cors=true&" + strContentTypeHeader.toLowerCase() + "=" + defaultContentType;
|
|
82
95
|
var _killSwitch = new EVTKillSwitch();
|
|
83
96
|
var _paused = false;
|
|
84
97
|
var _clockSkewManager = new EVTClockSkewManager();
|
|
@@ -95,6 +108,9 @@ var HttpManager = /** @class */ (function () {
|
|
|
95
108
|
var _enableEventTimings = false;
|
|
96
109
|
var _cookieMgr;
|
|
97
110
|
var _isUnloading = false;
|
|
111
|
+
var _useHeaders = false;
|
|
112
|
+
var _xhrTimeout;
|
|
113
|
+
var _disableXhrSync;
|
|
98
114
|
dynamicProto(HttpManager, this, function (_self) {
|
|
99
115
|
var _sendCredentials = true;
|
|
100
116
|
_self.initialize = function (endpointUrl, core, postChannel, httpInterface, channelConfig) {
|
|
@@ -103,6 +119,7 @@ var HttpManager = /** @class */ (function () {
|
|
|
103
119
|
channelConfig = {};
|
|
104
120
|
}
|
|
105
121
|
_urlString = endpointUrl + _urlString;
|
|
122
|
+
_useHeaders = !isUndefined(channelConfig.avoidOptions) ? !channelConfig.avoidOptions : true;
|
|
106
123
|
_core = core;
|
|
107
124
|
_cookieMgr = core.getCookieMgr();
|
|
108
125
|
_enableEventTimings = !_core.config.disableEventTimings;
|
|
@@ -113,15 +130,13 @@ var HttpManager = /** @class */ (function () {
|
|
|
113
130
|
if (!isUndefined(channelConfig.enableCompoundKey)) {
|
|
114
131
|
enableCompoundKey = !!channelConfig.enableCompoundKey;
|
|
115
132
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
// if (!!channelConfig.disableCacheHeader) {
|
|
119
|
-
// // Stop Chrome from stalling/throttling requests see task #7178858
|
|
120
|
-
// _self.addHeader("Cache-control", "no-cache, no-store");
|
|
121
|
-
// }
|
|
133
|
+
_xhrTimeout = channelConfig.xhrTimeout;
|
|
134
|
+
_disableXhrSync = channelConfig.disableXhrSync;
|
|
122
135
|
_useBeacons = !isReactNative(); // Only use beacons if not running in React Native
|
|
123
136
|
_serializer = new Serializer(_core, valueSanitizer, stringifyObjects, enableCompoundKey);
|
|
124
137
|
var syncHttpInterface = httpInterface;
|
|
138
|
+
var beaconHttpInterface = channelConfig.alwaysUseXhrOverride ? httpInterface : null;
|
|
139
|
+
var fetchSyncHttpInterface = channelConfig.alwaysUseXhrOverride ? httpInterface : null;
|
|
125
140
|
if (!httpInterface) {
|
|
126
141
|
_customHttpInterface = false;
|
|
127
142
|
var location_1 = getLocation();
|
|
@@ -157,8 +172,8 @@ var HttpManager = /** @class */ (function () {
|
|
|
157
172
|
_sendInterfaces = (_a = {},
|
|
158
173
|
_a[0 /* Batched */] = httpInterface,
|
|
159
174
|
_a[1 /* Synchronous */] = syncHttpInterface || _getSenderInterface([1 /* Xhr */, 2 /* Fetch */, 3 /* Beacon */], true),
|
|
160
|
-
_a[2 /* SendBeacon */] = _getSenderInterface([3 /* Beacon */, 2 /* Fetch
|
|
161
|
-
_a[3 /* SyncFetch */] = _getSenderInterface([2 /* Fetch */, 3 /* Beacon
|
|
175
|
+
_a[2 /* SendBeacon */] = beaconHttpInterface || _getSenderInterface([3 /* Beacon */, 2 /* Fetch */], true) || syncHttpInterface || _getSenderInterface([1 /* Xhr */], true),
|
|
176
|
+
_a[3 /* SyncFetch */] = fetchSyncHttpInterface || _getSenderInterface([2 /* Fetch */, 3 /* Beacon */], true) || syncHttpInterface || _getSenderInterface([1 /* Xhr */], true),
|
|
162
177
|
_a);
|
|
163
178
|
};
|
|
164
179
|
// Special internal method to allow the DebugPlugin to hook embedded objects
|
|
@@ -200,6 +215,9 @@ var HttpManager = /** @class */ (function () {
|
|
|
200
215
|
// It doesn't support custom headers, so no action is taken with current requestHeaders
|
|
201
216
|
var xdr = new XDomainRequest();
|
|
202
217
|
xdr.open(Method, payload.urlString);
|
|
218
|
+
if (payload.timeout) {
|
|
219
|
+
xdr.timeout = payload.timeout;
|
|
220
|
+
}
|
|
203
221
|
// can't get the status code in xdr.
|
|
204
222
|
xdr.onload = function () {
|
|
205
223
|
// we will assume onload means the request succeeded.
|
|
@@ -229,6 +247,9 @@ var HttpManager = /** @class */ (function () {
|
|
|
229
247
|
}
|
|
230
248
|
function _fetchSendPost(payload, oncomplete, sync) {
|
|
231
249
|
var _a;
|
|
250
|
+
var theUrl = payload.urlString;
|
|
251
|
+
var ignoreResponse = false;
|
|
252
|
+
var responseHandled = false;
|
|
232
253
|
var requestInit = (_a = {
|
|
233
254
|
body: payload.data,
|
|
234
255
|
method: Method
|
|
@@ -237,6 +258,12 @@ var HttpManager = /** @class */ (function () {
|
|
|
237
258
|
_a);
|
|
238
259
|
if (sync) {
|
|
239
260
|
requestInit.keepalive = true;
|
|
261
|
+
if (payload._sendReason === 2 /* Unload */) {
|
|
262
|
+
// As a sync request (during unload), it is unlikely that we will get a chance to process the response so
|
|
263
|
+
// just like beacon send assume that the events have been accepted and processed
|
|
264
|
+
ignoreResponse = true;
|
|
265
|
+
theUrl += _noResponseQs;
|
|
266
|
+
}
|
|
240
267
|
}
|
|
241
268
|
if (_sendCredentials) {
|
|
242
269
|
// Don't send credentials when URL is file://
|
|
@@ -246,7 +273,7 @@ var HttpManager = /** @class */ (function () {
|
|
|
246
273
|
if (payload.headers && objKeys(payload.headers).length > 0) {
|
|
247
274
|
requestInit.headers = payload.headers;
|
|
248
275
|
}
|
|
249
|
-
fetch(
|
|
276
|
+
fetch(theUrl, requestInit).then(function (response) {
|
|
250
277
|
var headerMap = {};
|
|
251
278
|
var responseText = "";
|
|
252
279
|
if (response.headers) {
|
|
@@ -259,15 +286,37 @@ var HttpManager = /** @class */ (function () {
|
|
|
259
286
|
responseText = text;
|
|
260
287
|
});
|
|
261
288
|
}
|
|
262
|
-
|
|
263
|
-
|
|
289
|
+
if (!responseHandled) {
|
|
290
|
+
responseHandled = true;
|
|
291
|
+
_doOnComplete(oncomplete, response.status, headerMap, responseText);
|
|
292
|
+
_handleCollectorResponse(responseText);
|
|
293
|
+
}
|
|
264
294
|
})["catch"](function (error) {
|
|
265
295
|
// In case there is an error in the request. Set the status to 0
|
|
266
296
|
// so that the events can be retried later.
|
|
267
|
-
|
|
297
|
+
if (!responseHandled) {
|
|
298
|
+
responseHandled = true;
|
|
299
|
+
_doOnComplete(oncomplete, 0, {});
|
|
300
|
+
}
|
|
268
301
|
});
|
|
302
|
+
if (ignoreResponse && !responseHandled) {
|
|
303
|
+
// Assume success during unload processing
|
|
304
|
+
responseHandled = true;
|
|
305
|
+
_doOnComplete(oncomplete, 200, {});
|
|
306
|
+
}
|
|
307
|
+
if (!responseHandled && payload.timeout > 0) {
|
|
308
|
+
// Simulate timeout
|
|
309
|
+
_postManager._setTimeoutOverride(function () {
|
|
310
|
+
if (!responseHandled) {
|
|
311
|
+
// Assume a 500 response (which will cause a retry)
|
|
312
|
+
responseHandled = true;
|
|
313
|
+
_doOnComplete(oncomplete, 500, {});
|
|
314
|
+
}
|
|
315
|
+
}, payload.timeout);
|
|
316
|
+
}
|
|
269
317
|
}
|
|
270
318
|
function _xhrSendPost(payload, oncomplete, sync) {
|
|
319
|
+
var theUrl = payload.urlString;
|
|
271
320
|
function _appendHeader(theHeaders, xhr, name) {
|
|
272
321
|
if (!theHeaders[name] && xhr && xhr.getResponseHeader) {
|
|
273
322
|
var value = xhr.getResponseHeader(name);
|
|
@@ -295,30 +344,33 @@ var HttpManager = /** @class */ (function () {
|
|
|
295
344
|
function xhrComplete(xhr, responseTxt) {
|
|
296
345
|
_doOnComplete(oncomplete, xhr.status, _getAllResponseHeaders(xhr), responseTxt);
|
|
297
346
|
}
|
|
298
|
-
|
|
347
|
+
if (sync && payload.disableXhrSync) {
|
|
348
|
+
sync = false;
|
|
349
|
+
}
|
|
350
|
+
var xhrRequest = openXhr(Method, theUrl, _sendCredentials, true, sync, payload.timeout);
|
|
299
351
|
// Set custom headers (e.g. gzip) here (after open())
|
|
300
352
|
objForEachKey(payload.headers, function (name, value) {
|
|
301
|
-
|
|
353
|
+
xhrRequest.setRequestHeader(name, value);
|
|
302
354
|
});
|
|
303
|
-
|
|
304
|
-
var response = _getResponseText(
|
|
305
|
-
xhrComplete(
|
|
355
|
+
xhrRequest.onload = function () {
|
|
356
|
+
var response = _getResponseText(xhrRequest);
|
|
357
|
+
xhrComplete(xhrRequest, response);
|
|
306
358
|
_handleCollectorResponse(response);
|
|
307
359
|
};
|
|
308
|
-
|
|
309
|
-
xhrComplete(
|
|
360
|
+
xhrRequest.onerror = function () {
|
|
361
|
+
xhrComplete(xhrRequest);
|
|
310
362
|
};
|
|
311
|
-
|
|
312
|
-
xhrComplete(
|
|
363
|
+
xhrRequest.ontimeout = function () {
|
|
364
|
+
xhrComplete(xhrRequest);
|
|
313
365
|
};
|
|
314
|
-
|
|
366
|
+
xhrRequest.send(payload.data);
|
|
315
367
|
}
|
|
316
368
|
function _doOnComplete(oncomplete, status, headers, response) {
|
|
317
369
|
try {
|
|
318
370
|
oncomplete(status, headers, response);
|
|
319
371
|
}
|
|
320
372
|
catch (e) {
|
|
321
|
-
_postManager.diagLog()
|
|
373
|
+
_throwInternal(_postManager.diagLog(), 2 /* WARNING */, 518 /* SendPostOnCompleteFailure */, dumpObj(e));
|
|
322
374
|
}
|
|
323
375
|
}
|
|
324
376
|
function _beaconSendPost(payload, oncomplete, sync) {
|
|
@@ -326,9 +378,10 @@ var HttpManager = /** @class */ (function () {
|
|
|
326
378
|
var internalPayloadData = payload;
|
|
327
379
|
var status = 200;
|
|
328
380
|
var thePayload = internalPayloadData._thePayload;
|
|
381
|
+
var theUrl = payload.urlString + _noResponseQs;
|
|
329
382
|
try {
|
|
330
383
|
var nav_1 = getNavigator();
|
|
331
|
-
if (!nav_1.sendBeacon(
|
|
384
|
+
if (!nav_1.sendBeacon(theUrl, payload.data)) {
|
|
332
385
|
if (thePayload) {
|
|
333
386
|
// Failed to send entire payload so try and split data and try to send as much events as possible
|
|
334
387
|
var droppedBatches_1 = [];
|
|
@@ -336,7 +389,7 @@ var HttpManager = /** @class */ (function () {
|
|
|
336
389
|
if (droppedBatches_1 && theBatch && theBatch.count() > 0) {
|
|
337
390
|
var theEvents = theBatch.events();
|
|
338
391
|
for (var lp = 0; lp < theEvents.length; lp++) {
|
|
339
|
-
if (!nav_1.sendBeacon(
|
|
392
|
+
if (!nav_1.sendBeacon(theUrl, _serializer.getEventBlob(theEvents[lp]))) {
|
|
340
393
|
// Can't send anymore, so split the batch and drop the rest
|
|
341
394
|
droppedBatches_1.push(theBatch.split(lp));
|
|
342
395
|
break;
|
|
@@ -356,7 +409,7 @@ var HttpManager = /** @class */ (function () {
|
|
|
356
409
|
}
|
|
357
410
|
}
|
|
358
411
|
catch (ex) {
|
|
359
|
-
_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));
|
|
360
413
|
status = 0;
|
|
361
414
|
}
|
|
362
415
|
finally {
|
|
@@ -560,11 +613,35 @@ var HttpManager = /** @class */ (function () {
|
|
|
560
613
|
}, function () { return ({ batches: _createDebugBatches(orgBatches_1), retryCount: retryCount, isTeardown: isTeardown, isSynchronous: isSynchronous_1, sendReason: sendReason, useSendBeacon: _isBeaconPayload(sendType), sendType: sendType }); }, !isSynchronous_1);
|
|
561
614
|
}
|
|
562
615
|
catch (ex) {
|
|
563
|
-
_postManager.diagLog()
|
|
616
|
+
_throwInternal(_postManager.diagLog(), 2 /* WARNING */, 48 /* CannotSerializeObject */, "Unexpected Exception sending batch: " + dumpObj(ex));
|
|
564
617
|
}
|
|
565
618
|
}
|
|
566
|
-
function
|
|
567
|
-
var
|
|
619
|
+
function _buildRequestDetails(thePayload, useHeaders) {
|
|
620
|
+
var requestDetails = {
|
|
621
|
+
url: _urlString,
|
|
622
|
+
hdrs: {},
|
|
623
|
+
useHdrs: false // Assume no headers
|
|
624
|
+
};
|
|
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
|
+
}
|
|
643
|
+
_addRequestDetails(requestDetails, strClientId, "NO_AUTH", useHeaders);
|
|
644
|
+
_addRequestDetails(requestDetails, strClientVersion, FullVersionString, useHeaders);
|
|
568
645
|
var apiQsKeys = "";
|
|
569
646
|
arrForEach(thePayload.apiKeys, function (apiKey) {
|
|
570
647
|
if (apiQsKeys.length > 0) {
|
|
@@ -572,27 +649,25 @@ var HttpManager = /** @class */ (function () {
|
|
|
572
649
|
}
|
|
573
650
|
apiQsKeys += apiKey;
|
|
574
651
|
});
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
}
|
|
578
|
-
urlString += "&upload-time=" + dateNow().toString();
|
|
652
|
+
_addRequestDetails(requestDetails, strApiKey, apiQsKeys, useHeaders);
|
|
653
|
+
_addRequestDetails(requestDetails, strUploadTime, dateNow().toString(), useHeaders);
|
|
579
654
|
var msfpc = _getMsfpc(thePayload);
|
|
580
655
|
if (isValueAssigned(msfpc)) {
|
|
581
|
-
|
|
656
|
+
requestDetails.url += "&ext.intweb.msfpc=" + msfpc;
|
|
582
657
|
}
|
|
583
658
|
if (_clockSkewManager.shouldAddClockSkewHeaders()) {
|
|
584
|
-
|
|
659
|
+
_addRequestDetails(requestDetails, strTimeDeltaToApply, _clockSkewManager.getClockSkewHeaderValue(), useHeaders);
|
|
585
660
|
}
|
|
586
661
|
if (_core.getWParam) {
|
|
587
662
|
var wParam = _core.getWParam();
|
|
588
663
|
if (wParam >= 0) {
|
|
589
|
-
|
|
664
|
+
requestDetails.url += "&w=" + wParam;
|
|
590
665
|
}
|
|
591
666
|
}
|
|
592
667
|
for (var i = 0; i < _queryStringParameters.length; i++) {
|
|
593
|
-
|
|
668
|
+
requestDetails.url += "&" + _queryStringParameters[i].name + "=" + _queryStringParameters[i].value;
|
|
594
669
|
}
|
|
595
|
-
return
|
|
670
|
+
return requestDetails;
|
|
596
671
|
}
|
|
597
672
|
function _canUseSendBeaconApi() {
|
|
598
673
|
return !_customHttpInterface && _useBeacons && isBeaconsSupported();
|
|
@@ -603,9 +678,20 @@ var HttpManager = /** @class */ (function () {
|
|
|
603
678
|
}
|
|
604
679
|
function _doPayloadSend(thePayload, serializationStart, serializationCompleted, sendReason) {
|
|
605
680
|
if (thePayload && thePayload.payloadBlob && thePayload.payloadBlob.length > 0) {
|
|
606
|
-
var
|
|
681
|
+
var useSendHook_1 = !!_self.sendHook;
|
|
682
|
+
var sendInterface_1 = _sendInterfaces[thePayload.sendType];
|
|
683
|
+
// Send all data using a beacon style transport if closing mode is on or channel was teared down
|
|
684
|
+
if (!_isBeaconPayload(thePayload.sendType) && thePayload.isBeacon && thePayload.sendReason === 2 /* Unload */) {
|
|
685
|
+
sendInterface_1 = _sendInterfaces[2 /* SendBeacon */] || _sendInterfaces[3 /* SyncFetch */] || sendInterface_1;
|
|
686
|
+
}
|
|
687
|
+
var useHeaders_1 = _useHeaders;
|
|
688
|
+
// Disable header usage if we know we are using sendBeacon as additional headers are not supported
|
|
689
|
+
if (thePayload.isBeacon || sendInterface_1._transport === 3 /* Beacon */) {
|
|
690
|
+
useHeaders_1 = false;
|
|
691
|
+
}
|
|
692
|
+
var requestDetails_1 = _buildRequestDetails(thePayload, useHeaders_1);
|
|
693
|
+
useHeaders_1 = useHeaders_1 || requestDetails_1.useHdrs;
|
|
607
694
|
var sendEventStart_1 = getTime();
|
|
608
|
-
var strSendAttempt_1 = "sendAttempt";
|
|
609
695
|
doPerf(_core, function () { return "HttpManager:_doPayloadSend"; }, function () {
|
|
610
696
|
// Increment the send attempt count and add timings after packaging (So it's not serialized in the 1st attempt)
|
|
611
697
|
for (var batchLp = 0; batchLp < thePayload.batches.length; batchLp++) {
|
|
@@ -619,7 +705,7 @@ var HttpManager = /** @class */ (function () {
|
|
|
619
705
|
_setTimingValue(timings, "serializationStart", serializationStart);
|
|
620
706
|
_setTimingValue(timings, "serializationCompleted", serializationCompleted);
|
|
621
707
|
}
|
|
622
|
-
telemetryItem[
|
|
708
|
+
telemetryItem[strSendAttempt] > 0 ? telemetryItem[strSendAttempt]++ : telemetryItem[strSendAttempt] = 1;
|
|
623
709
|
}
|
|
624
710
|
}
|
|
625
711
|
// Note: always sending this notification in a synchronous manner.
|
|
@@ -629,25 +715,26 @@ var HttpManager = /** @class */ (function () {
|
|
|
629
715
|
// eslint-disable-next-line prefer-const
|
|
630
716
|
var orgPayloadData = {
|
|
631
717
|
data: thePayload.payloadBlob,
|
|
632
|
-
urlString:
|
|
633
|
-
headers:
|
|
718
|
+
urlString: requestDetails_1.url,
|
|
719
|
+
headers: requestDetails_1.hdrs,
|
|
634
720
|
_thePayload: thePayload,
|
|
635
|
-
_sendReason: sendReason
|
|
721
|
+
_sendReason: sendReason,
|
|
722
|
+
timeout: _xhrTimeout
|
|
636
723
|
};
|
|
637
|
-
if (!
|
|
638
|
-
orgPayloadData.
|
|
724
|
+
if (!isUndefined(_disableXhrSync)) {
|
|
725
|
+
orgPayloadData.disableXhrSync = !!_disableXhrSync;
|
|
639
726
|
}
|
|
640
|
-
if
|
|
641
|
-
|
|
727
|
+
// Only automatically add the following headers if already sending headers and we are not attempting to avoid an options call
|
|
728
|
+
if (useHeaders_1) {
|
|
729
|
+
if (!_hasHeader(orgPayloadData.headers, strCacheControl)) {
|
|
730
|
+
orgPayloadData.headers[strCacheControl] = defaultCacheControl;
|
|
731
|
+
}
|
|
732
|
+
if (!_hasHeader(orgPayloadData.headers, strContentTypeHeader)) {
|
|
733
|
+
orgPayloadData.headers[strContentTypeHeader] = defaultContentType;
|
|
734
|
+
}
|
|
642
735
|
}
|
|
643
736
|
var sender = null;
|
|
644
|
-
|
|
645
|
-
var sendInterface = _sendInterfaces[thePayload.sendType];
|
|
646
|
-
// Send all data using a beacon style transport if closing mode is on or channel was teared down
|
|
647
|
-
if (!_isBeaconPayload(thePayload.sendType) && thePayload.isBeacon && thePayload.sendReason === 2 /* Unload */) {
|
|
648
|
-
sendInterface = _sendInterfaces[2 /* SendBeacon */] || _sendInterfaces[3 /* SyncFetch */] || sendInterface;
|
|
649
|
-
}
|
|
650
|
-
if (sendInterface) {
|
|
737
|
+
if (sendInterface_1) {
|
|
651
738
|
// Send sync requests if the request is immediate or we are tearing down telemetry.
|
|
652
739
|
sender = function (payload) {
|
|
653
740
|
// Notify the clock skew manager that we are sending the first request (Potentially blocking all further requests)
|
|
@@ -657,7 +744,7 @@ var HttpManager = /** @class */ (function () {
|
|
|
657
744
|
};
|
|
658
745
|
var isSync = thePayload.isTeardown || thePayload.isSync;
|
|
659
746
|
try {
|
|
660
|
-
|
|
747
|
+
sendInterface_1.sendPOST(payload, onComplete, isSync);
|
|
661
748
|
if (_self.sendListener) {
|
|
662
749
|
// Send the original payload to the listener
|
|
663
750
|
_self.sendListener(orgPayloadData, payload, isSync, thePayload.isBeacon);
|
|
@@ -675,7 +762,7 @@ var HttpManager = /** @class */ (function () {
|
|
|
675
762
|
_outstandingRequests++;
|
|
676
763
|
}
|
|
677
764
|
// Only call the hook if it's defined and we are not using sendBeacon as additional headers are not supported
|
|
678
|
-
if (
|
|
765
|
+
if (useSendHook_1 && !thePayload.isBeacon && sendInterface_1._transport !== 3 /* Beacon */) {
|
|
679
766
|
// Create a new IPayloadData that is sent into the hook method, so that the hook method
|
|
680
767
|
// can't change the object references to the orgPayloadData (it can still change the content -- mainly the headers)
|
|
681
768
|
// Disabling the use of const because of Issue:
|
|
@@ -684,7 +771,9 @@ var HttpManager = /** @class */ (function () {
|
|
|
684
771
|
var hookData_1 = {
|
|
685
772
|
data: orgPayloadData.data,
|
|
686
773
|
urlString: orgPayloadData.urlString,
|
|
687
|
-
headers: extend({}, orgPayloadData.headers)
|
|
774
|
+
headers: extend({}, orgPayloadData.headers),
|
|
775
|
+
timeout: orgPayloadData.timeout,
|
|
776
|
+
disableXhrSync: orgPayloadData.disableXhrSync
|
|
688
777
|
};
|
|
689
778
|
var senderCalled_1 = false;
|
|
690
779
|
doPerf(_core, function () { return "HttpManager:_doPayloadSend.sendHook"; }, function () {
|
|
@@ -758,12 +847,12 @@ var HttpManager = /** @class */ (function () {
|
|
|
758
847
|
}
|
|
759
848
|
// Disabling triple-equals rule to avoid httpOverrides from failing because they are returning a string value
|
|
760
849
|
// tslint:disable-next-line:triple-equals
|
|
761
|
-
if (status == 200) {
|
|
850
|
+
if (status == 200 || status == 204) {
|
|
762
851
|
// Response was successfully sent
|
|
763
852
|
reason = 200 /* Complete */;
|
|
764
853
|
return;
|
|
765
854
|
}
|
|
766
|
-
if (!
|
|
855
|
+
if (!retryPolicyShouldRetryForStatus(status) || thePayload.numEvents <= 0) {
|
|
767
856
|
// Only retry for specific response codes and if there is still events after kill switch processing
|
|
768
857
|
shouldRetry = false;
|
|
769
858
|
}
|
|
@@ -775,7 +864,8 @@ var HttpManager = /** @class */ (function () {
|
|
|
775
864
|
reason = 100 /* RequeueEvents */;
|
|
776
865
|
var retryCount_1 = thePayload.retryCnt;
|
|
777
866
|
if (thePayload.sendType === 0 /* Batched */) {
|
|
778
|
-
|
|
867
|
+
// attempt to resend the entire batch
|
|
868
|
+
if (retryCount_1 < maxRequestRetriesBeforeBackoff) {
|
|
779
869
|
isRetrying = true;
|
|
780
870
|
_doAction(function () {
|
|
781
871
|
// try to resend the same batches
|
|
@@ -786,10 +876,15 @@ var HttpManager = /** @class */ (function () {
|
|
|
786
876
|
_outstandingRequests--;
|
|
787
877
|
}
|
|
788
878
|
_sendBatches(thePayload.batches, retryCount_1 + 1, thePayload.isTeardown, _isUnloading ? 2 /* SendBeacon */ : thePayload.sendType, 5 /* Retry */);
|
|
789
|
-
}, _isUnloading,
|
|
879
|
+
}, _isUnloading, retryPolicyGetMillisToBackoffForRetry(retryCount_1));
|
|
790
880
|
}
|
|
791
881
|
else {
|
|
792
882
|
backOffTrans = true;
|
|
883
|
+
if (_isUnloading) {
|
|
884
|
+
// we are unloading so don't try and requeue the events otherwise let the events get requeued and resent during the backoff sending
|
|
885
|
+
// This will also cause the events to be purged based on the priority (if necessary)
|
|
886
|
+
reason = 8001 /* NonRetryableStatus */;
|
|
887
|
+
}
|
|
793
888
|
}
|
|
794
889
|
}
|
|
795
890
|
}
|
|
@@ -880,12 +975,9 @@ var HttpManager = /** @class */ (function () {
|
|
|
880
975
|
}
|
|
881
976
|
function _getMsfpc(thePayload) {
|
|
882
977
|
for (var lp = 0; lp < thePayload.batches.length; lp++) {
|
|
883
|
-
var
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
if (isValueAssigned(intWeb["msfpc"])) {
|
|
887
|
-
return encodeURIComponent(intWeb["msfpc"]);
|
|
888
|
-
}
|
|
978
|
+
var msfpc = thePayload.batches[lp].Msfpc();
|
|
979
|
+
if (msfpc) {
|
|
980
|
+
return encodeURIComponent(msfpc);
|
|
889
981
|
}
|
|
890
982
|
}
|
|
891
983
|
return "";
|
|
@@ -898,14 +990,14 @@ var HttpManager = /** @class */ (function () {
|
|
|
898
990
|
responseHandlers[i](responseText);
|
|
899
991
|
}
|
|
900
992
|
catch (e) {
|
|
901
|
-
_postManager.diagLog()
|
|
993
|
+
_throwInternal(_postManager.diagLog(), 1 /* CRITICAL */, 519 /* PostResponseHandler */, "Response handler failed: " + e);
|
|
902
994
|
}
|
|
903
995
|
}
|
|
904
996
|
if (responseText) {
|
|
905
997
|
var response = JSON.parse(responseText);
|
|
906
|
-
if (isValueAssigned(response.webResult) && isValueAssigned(response.webResult
|
|
998
|
+
if (isValueAssigned(response.webResult) && isValueAssigned(response.webResult[strMsfpc])) {
|
|
907
999
|
// Set cookie
|
|
908
|
-
_cookieMgr.set("MSFPC", response.webResult
|
|
1000
|
+
_cookieMgr.set("MSFPC", response.webResult[strMsfpc], 365 * 86400);
|
|
909
1001
|
}
|
|
910
1002
|
}
|
|
911
1003
|
}
|
|
@@ -924,7 +1016,7 @@ var HttpManager = /** @class */ (function () {
|
|
|
924
1016
|
theAction_1.call(actions, theBatches, batchReason, isSyncRequest_1, sendType);
|
|
925
1017
|
}
|
|
926
1018
|
catch (e) {
|
|
927
|
-
_postManager.diagLog()
|
|
1019
|
+
_throwInternal(_postManager.diagLog(), 1 /* CRITICAL */, 74 /* NotificationException */, "send request notification failed: " + e);
|
|
928
1020
|
}
|
|
929
1021
|
}, sendSync || isSyncRequest_1, 0);
|
|
930
1022
|
}, function () { return ({ batches: _createDebugBatches(theBatches), reason: batchReason, isSync: isSyncRequest_1, sendSync: sendSync, sendType: sendType }); }, !isSyncRequest_1);
|
|
@@ -963,5 +1055,5 @@ var HttpManager = /** @class */ (function () {
|
|
|
963
1055
|
// Removed Stub for HttpManager.prototype.sendSynchronousBatch.
|
|
964
1056
|
return HttpManager;
|
|
965
1057
|
}());
|
|
966
|
-
export
|
|
1058
|
+
export { HttpManager };
|
|
967
1059
|
//# sourceMappingURL=HttpManager.js.map
|