@microsoft/1ds-post-js 3.2.6 → 3.2.7
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 +4 -1
- package/bundle/{ms.post-3.2.6.gbl.js → ms.post-3.2.7.gbl.js} +44 -30
- package/bundle/ms.post-3.2.7.gbl.js.map +1 -0
- package/bundle/ms.post-3.2.7.gbl.min.js +7 -0
- package/bundle/{ms.post-3.2.6.gbl.min.js.map → ms.post-3.2.7.gbl.min.js.map} +1 -1
- package/bundle/ms.post-3.2.7.integrity.json +46 -0
- package/bundle/{ms.post-3.2.6.js → ms.post-3.2.7.js} +44 -30
- package/bundle/ms.post-3.2.7.js.map +1 -0
- package/bundle/ms.post-3.2.7.min.js +7 -0
- package/bundle/{ms.post-3.2.6.min.js.map → ms.post-3.2.7.min.js.map} +1 -1
- package/bundle/ms.post.gbl.js +43 -29
- 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 +43 -29
- 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 +41 -27
- 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/DataModels.d.ts +19 -3
- package/dist-esm/src/DataModels.js +1 -1
- package/dist-esm/src/EventBatch.js +1 -1
- package/dist-esm/src/HttpManager.js +39 -24
- package/dist-esm/src/HttpManager.js.map +1 -1
- package/dist-esm/src/Index.js +1 -1
- package/dist-esm/src/InternalConstants.js +1 -1
- package/dist-esm/src/KillSwitch.js +1 -1
- package/dist-esm/src/PostChannel.js +2 -2
- package/dist-esm/src/PostChannel.js.map +1 -1
- package/dist-esm/src/RetryPolicy.js +1 -1
- package/dist-esm/src/Serializer.d.ts +3 -3
- package/dist-esm/src/Serializer.js +3 -3
- package/dist-esm/src/Serializer.js.map +1 -1
- package/dist-esm/src/TimeoutOverrideWrapper.js +1 -1
- package/dist-esm/src/typings/XDomainRequest.js +1 -1
- package/package.json +2 -2
- package/src/DataModels.ts +19 -0
- package/src/HttpManager.ts +47 -26
- package/src/Serializer.ts +10 -10
- package/bundle/ms.post-3.2.6.gbl.js.map +0 -1
- package/bundle/ms.post-3.2.6.gbl.min.js +0 -7
- package/bundle/ms.post-3.2.6.integrity.json +0 -46
- package/bundle/ms.post-3.2.6.js.map +0 -1
- package/bundle/ms.post-3.2.6.min.js +0 -7
package/src/HttpManager.ts
CHANGED
|
@@ -129,6 +129,19 @@ function _addRequestDetails(details: IRequestUrlDetails, name: string, value: st
|
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
+
function _prependTransports(theTransports: TransportType[], newTransports: TransportType | TransportType[]) {
|
|
133
|
+
if (newTransports) {
|
|
134
|
+
if (isNumber(newTransports)) {
|
|
135
|
+
theTransports = [newTransports as TransportType].concat(theTransports);
|
|
136
|
+
} else if (isArray(newTransports)) {
|
|
137
|
+
theTransports = newTransports.concat(theTransports);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return theTransports;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
|
|
132
145
|
/**
|
|
133
146
|
* Class managing the sending of requests.
|
|
134
147
|
*/
|
|
@@ -163,6 +176,8 @@ export class HttpManager {
|
|
|
163
176
|
let _useHeaders = false;
|
|
164
177
|
let _xhrTimeout: number;
|
|
165
178
|
let _disableXhrSync: boolean;
|
|
179
|
+
let _disableFetchKeepAlive: boolean;
|
|
180
|
+
let _canHaveReducedPayload: boolean;
|
|
166
181
|
|
|
167
182
|
dynamicProto(HttpManager, this, (_self) => {
|
|
168
183
|
let _sendCredentials = true;
|
|
@@ -194,14 +209,20 @@ export class HttpManager {
|
|
|
194
209
|
}
|
|
195
210
|
|
|
196
211
|
_xhrTimeout = channelConfig.xhrTimeout;
|
|
197
|
-
_disableXhrSync = channelConfig.disableXhrSync;
|
|
212
|
+
_disableXhrSync = !!channelConfig.disableXhrSync;
|
|
213
|
+
_disableFetchKeepAlive = !!channelConfig.disableFetchKeepAlive;
|
|
198
214
|
|
|
199
215
|
_useBeacons = !isReactNative(); // Only use beacons if not running in React Native
|
|
200
216
|
_serializer = new Serializer(_core, valueSanitizer, stringifyObjects, enableCompoundKey);
|
|
201
217
|
|
|
218
|
+
if (!isNullOrUndefined(channelConfig.useSendBeacon)) {
|
|
219
|
+
_useBeacons = !!channelConfig.useSendBeacon;
|
|
220
|
+
}
|
|
221
|
+
|
|
202
222
|
let syncHttpInterface = httpInterface;
|
|
203
223
|
let beaconHttpInterface: IXHROverride = channelConfig.alwaysUseXhrOverride ? httpInterface : null;
|
|
204
224
|
let fetchSyncHttpInterface: IXHROverride = channelConfig.alwaysUseXhrOverride ? httpInterface : null;
|
|
225
|
+
let beaconUnloadTransports: TransportType[] = [TransportType.Beacon, TransportType.Fetch];
|
|
205
226
|
|
|
206
227
|
if (!httpInterface) {
|
|
207
228
|
_customHttpInterface = false;
|
|
@@ -212,42 +233,45 @@ export class HttpManager {
|
|
|
212
233
|
_sendCredentials = false;
|
|
213
234
|
}
|
|
214
235
|
|
|
215
|
-
let theTransports:
|
|
236
|
+
let theTransports: TransportType[] = [];
|
|
216
237
|
if (isReactNative()) {
|
|
217
238
|
// Use Fetch or XDR/XHR
|
|
218
239
|
theTransports = [TransportType.Fetch, TransportType.Xhr];
|
|
240
|
+
beaconUnloadTransports = [TransportType.Fetch, TransportType.Xhr, TransportType.Beacon];
|
|
219
241
|
} else {
|
|
220
242
|
// Use XDR/XHR, Fetch or beacons
|
|
221
243
|
theTransports = [TransportType.Xhr, TransportType.Fetch, TransportType.Beacon];
|
|
222
244
|
}
|
|
223
245
|
|
|
224
246
|
// Prefix any user requested transport(s) values
|
|
225
|
-
|
|
226
|
-
if (configTransports) {
|
|
227
|
-
if (isNumber(configTransports)) {
|
|
228
|
-
theTransports = [configTransports].concat(theTransports);
|
|
229
|
-
} else if (isArray(configTransports)) {
|
|
230
|
-
theTransports = configTransports.concat(theTransports);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
247
|
+
theTransports = _prependTransports(theTransports, channelConfig.transports);
|
|
233
248
|
|
|
234
249
|
httpInterface = _getSenderInterface(theTransports, false);
|
|
235
|
-
syncHttpInterface = _getSenderInterface(theTransports, true);
|
|
236
250
|
if (!httpInterface) {
|
|
237
251
|
_warnToConsole(_logger, "No available transport to send events");
|
|
238
252
|
}
|
|
253
|
+
|
|
254
|
+
syncHttpInterface = _getSenderInterface(theTransports, true);
|
|
239
255
|
}
|
|
240
256
|
|
|
257
|
+
if (!beaconHttpInterface) {
|
|
258
|
+
// Allow overriding the usage of sendBeacon
|
|
259
|
+
beaconUnloadTransports = _prependTransports(beaconUnloadTransports, channelConfig.unloadTransports);
|
|
260
|
+
beaconHttpInterface = _getSenderInterface(beaconUnloadTransports, true);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
_canHaveReducedPayload = !_customHttpInterface && ((_useBeacons && isBeaconsSupported()) || (!_disableFetchKeepAlive && isFetchSupported(true)));
|
|
264
|
+
|
|
241
265
|
_sendInterfaces = {
|
|
242
266
|
[EventSendType.Batched]: httpInterface,
|
|
243
267
|
[EventSendType.Synchronous]: syncHttpInterface || _getSenderInterface([TransportType.Xhr, TransportType.Fetch, TransportType.Beacon], true),
|
|
244
|
-
[EventSendType.SendBeacon]: beaconHttpInterface ||
|
|
268
|
+
[EventSendType.SendBeacon]: beaconHttpInterface || syncHttpInterface || _getSenderInterface([TransportType.Xhr], true),
|
|
245
269
|
[EventSendType.SyncFetch]: fetchSyncHttpInterface || _getSenderInterface([TransportType.Fetch, TransportType.Beacon], true) || syncHttpInterface || _getSenderInterface([TransportType.Xhr], true)
|
|
246
270
|
};
|
|
247
271
|
};
|
|
248
272
|
|
|
249
273
|
// Special internal method to allow the DebugPlugin to hook embedded objects
|
|
250
|
-
function _getSenderInterface(transports:
|
|
274
|
+
function _getSenderInterface(transports: TransportType[], syncSupport: boolean): IInternalXhrOverride {
|
|
251
275
|
let transportType: TransportType = TransportType.NotSet;
|
|
252
276
|
let sendPostFunc: SendPOSTFunction = null;
|
|
253
277
|
let lp = 0;
|
|
@@ -259,7 +283,7 @@ export class HttpManager {
|
|
|
259
283
|
} else if (isXhrSupported()) {
|
|
260
284
|
sendPostFunc = _xhrSendPost;
|
|
261
285
|
}
|
|
262
|
-
} else if (transportType === TransportType.Fetch && isFetchSupported(syncSupport)) {
|
|
286
|
+
} else if (transportType === TransportType.Fetch && isFetchSupported(syncSupport) && (!syncSupport || (syncSupport && !_disableFetchKeepAlive))) {
|
|
263
287
|
sendPostFunc = _fetchSendPost;
|
|
264
288
|
} else if (_useBeacons && transportType === TransportType.Beacon && isBeaconsSupported()) {
|
|
265
289
|
sendPostFunc = _beaconSendPost;
|
|
@@ -694,8 +718,10 @@ export class HttpManager {
|
|
|
694
718
|
let thePayload: ISerializedPayload = null;
|
|
695
719
|
let serializationStart = getTime();
|
|
696
720
|
let sendInterface = _sendInterfaces[sendType] || (isSynchronous ? _sendInterfaces[EventSendType.Synchronous] : _sendInterfaces[EventSendType.Batched]);
|
|
721
|
+
let sendTransport = sendInterface && sendInterface._transport;
|
|
722
|
+
|
|
697
723
|
// Sync Fetch has the same payload limitation as sendBeacon -- 64kb limit
|
|
698
|
-
let
|
|
724
|
+
let isReducedPayload = _canHaveReducedPayload && (_isUnloading || _isBeaconPayload(sendType) || (sendTransport === TransportType.Beacon || (sendInterface._isSync && sendTransport === TransportType.Fetch)));
|
|
699
725
|
|
|
700
726
|
while (_canSendPayload(theBatches, sendType, retryCount)) {
|
|
701
727
|
let theBatch = theBatches.shift();
|
|
@@ -703,7 +729,7 @@ export class HttpManager {
|
|
|
703
729
|
if (!_killSwitch.isTenantKilled(theBatch.iKey())) {
|
|
704
730
|
|
|
705
731
|
// Make sure we have a payload object
|
|
706
|
-
thePayload = thePayload || _serializer.createPayload(retryCount, isTeardown, isSynchronous,
|
|
732
|
+
thePayload = thePayload || _serializer.createPayload(retryCount, isTeardown, isSynchronous, isReducedPayload, sendReason, sendType);
|
|
707
733
|
|
|
708
734
|
// Add the batch to the current payload
|
|
709
735
|
if (!_serializer.appendPayload(thePayload, theBatch, maxEventsPerBatch)) {
|
|
@@ -808,10 +834,6 @@ export class HttpManager {
|
|
|
808
834
|
return requestDetails;
|
|
809
835
|
}
|
|
810
836
|
|
|
811
|
-
function _canUseSendBeaconApi() {
|
|
812
|
-
return !_customHttpInterface && _useBeacons && isBeaconsSupported();
|
|
813
|
-
}
|
|
814
|
-
|
|
815
837
|
function _setTimingValue(timings: any, name: string, value: number) {
|
|
816
838
|
timings[name] = timings[name] || {};
|
|
817
839
|
timings[name][_postManager.identifier] = value;
|
|
@@ -874,13 +896,11 @@ export class HttpManager {
|
|
|
874
896
|
headers: requestDetails.hdrs,
|
|
875
897
|
_thePayload: thePayload,
|
|
876
898
|
_sendReason: sendReason,
|
|
877
|
-
timeout: _xhrTimeout
|
|
899
|
+
timeout: _xhrTimeout,
|
|
900
|
+
disableXhrSync: _disableXhrSync,
|
|
901
|
+
disableFetchKeepAlive: _disableFetchKeepAlive
|
|
878
902
|
};
|
|
879
903
|
|
|
880
|
-
if (!isUndefined(_disableXhrSync)) {
|
|
881
|
-
orgPayloadData.disableXhrSync = !!_disableXhrSync;
|
|
882
|
-
}
|
|
883
|
-
|
|
884
904
|
// Only automatically add the following headers if already sending headers and we are not attempting to avoid an options call
|
|
885
905
|
if (useHeaders) {
|
|
886
906
|
if (!_hasHeader(orgPayloadData.headers, STR_CACHE_CONTROL)) {
|
|
@@ -938,7 +958,8 @@ export class HttpManager {
|
|
|
938
958
|
urlString: orgPayloadData.urlString,
|
|
939
959
|
headers: extend({}, orgPayloadData.headers),
|
|
940
960
|
timeout: orgPayloadData.timeout,
|
|
941
|
-
disableXhrSync: orgPayloadData.disableXhrSync
|
|
961
|
+
disableXhrSync: orgPayloadData.disableXhrSync,
|
|
962
|
+
disableFetchKeepAlive: orgPayloadData.disableFetchKeepAlive
|
|
942
963
|
};
|
|
943
964
|
|
|
944
965
|
let senderCalled = false;
|
package/src/Serializer.ts
CHANGED
|
@@ -60,7 +60,7 @@ export interface ISerializedPayload {
|
|
|
60
60
|
/**
|
|
61
61
|
* Events that where dropped because they could not be serialized
|
|
62
62
|
*/
|
|
63
|
-
|
|
63
|
+
failedEvts: EventBatch[];
|
|
64
64
|
|
|
65
65
|
/**
|
|
66
66
|
* The batches included in this payload
|
|
@@ -85,12 +85,12 @@ export interface ISerializedPayload {
|
|
|
85
85
|
/**
|
|
86
86
|
* Is this payload a synchronous payload
|
|
87
87
|
*/
|
|
88
|
-
|
|
88
|
+
isSync: boolean;
|
|
89
89
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
90
|
+
/**
|
|
91
|
+
* The payload has been constructed using a reduced payload size for usage with sendBeacon or fetch(with keepAlive) API's
|
|
92
|
+
*/
|
|
93
|
+
isBeacon: boolean;
|
|
94
94
|
|
|
95
95
|
/**
|
|
96
96
|
* The request event sync type
|
|
@@ -121,7 +121,7 @@ export class Serializer {
|
|
|
121
121
|
|
|
122
122
|
dynamicProto(Serializer, this, (_self) => {
|
|
123
123
|
|
|
124
|
-
_self.createPayload = (retryCnt: number, isTeardown: boolean, isSync: boolean,
|
|
124
|
+
_self.createPayload = (retryCnt: number, isTeardown: boolean, isSync: boolean, isReducedPayload: boolean, sendReason: SendRequestReason, sendType: EventSendType): ISerializedPayload => {
|
|
125
125
|
return {
|
|
126
126
|
apiKeys: [],
|
|
127
127
|
payloadBlob: "",
|
|
@@ -133,7 +133,7 @@ export class Serializer {
|
|
|
133
133
|
retryCnt: retryCnt,
|
|
134
134
|
isTeardown: isTeardown,
|
|
135
135
|
isSync: isSync,
|
|
136
|
-
isBeacon:
|
|
136
|
+
isBeacon: isReducedPayload,
|
|
137
137
|
sendType: sendType,
|
|
138
138
|
sendReason: sendReason
|
|
139
139
|
};
|
|
@@ -378,11 +378,11 @@ export class Serializer {
|
|
|
378
378
|
* @param retryCnt The retry count for the events in this payload
|
|
379
379
|
* @param isTeardown Is this payload being created as part of a teardown request
|
|
380
380
|
* @param isSync Should this payload be sent as a synchronous request
|
|
381
|
-
* @param
|
|
381
|
+
* @param isReducedPayload Is this payload going to be sent via sendBeacon() API
|
|
382
382
|
* @param sendReason The reason the payload is being sent
|
|
383
383
|
* @param sendType Identifies how this payload will be sent
|
|
384
384
|
*/
|
|
385
|
-
public createPayload(retryCnt: number, isTeardown: boolean, isSync: boolean,
|
|
385
|
+
public createPayload(retryCnt: number, isTeardown: boolean, isSync: boolean, isReducedPayload: boolean, sendReason: SendRequestReason, sendType: EventSendType): ISerializedPayload {
|
|
386
386
|
// @DynamicProtoStub - DO NOT add any code as this will be removed during packaging
|
|
387
387
|
return null;
|
|
388
388
|
}
|