@microsoft/1ds-post-js 3.2.6 → 3.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/README.md +5 -1
  2. package/bundle/{ms.post-3.2.6.gbl.js → ms.post-3.2.8.gbl.js} +132 -85
  3. package/bundle/ms.post-3.2.8.gbl.js.map +1 -0
  4. package/bundle/ms.post-3.2.8.gbl.min.js +7 -0
  5. package/bundle/ms.post-3.2.8.gbl.min.js.map +1 -0
  6. package/bundle/ms.post-3.2.8.integrity.json +46 -0
  7. package/bundle/{ms.post-3.2.6.js → ms.post-3.2.8.js} +132 -85
  8. package/bundle/ms.post-3.2.8.js.map +1 -0
  9. package/bundle/ms.post-3.2.8.min.js +7 -0
  10. package/bundle/ms.post-3.2.8.min.js.map +1 -0
  11. package/bundle/ms.post.gbl.js +131 -84
  12. package/bundle/ms.post.gbl.js.map +1 -1
  13. package/bundle/ms.post.gbl.min.js +2 -2
  14. package/bundle/ms.post.gbl.min.js.map +1 -1
  15. package/bundle/ms.post.integrity.json +17 -17
  16. package/bundle/ms.post.js +131 -84
  17. package/bundle/ms.post.js.map +1 -1
  18. package/bundle/ms.post.min.js +2 -2
  19. package/bundle/ms.post.min.js.map +1 -1
  20. package/dist/ms.post.js +56 -37
  21. package/dist/ms.post.js.map +1 -1
  22. package/dist/ms.post.min.js +2 -2
  23. package/dist/ms.post.min.js.map +1 -1
  24. package/dist-esm/src/BatchNotificationActions.js +1 -1
  25. package/dist-esm/src/ClockSkewManager.js +1 -1
  26. package/dist-esm/src/DataModels.d.ts +24 -3
  27. package/dist-esm/src/DataModels.js +1 -1
  28. package/dist-esm/src/EventBatch.js +3 -3
  29. package/dist-esm/src/EventBatch.js.map +1 -1
  30. package/dist-esm/src/HttpManager.js +51 -32
  31. package/dist-esm/src/HttpManager.js.map +1 -1
  32. package/dist-esm/src/Index.js +1 -1
  33. package/dist-esm/src/InternalConstants.d.ts +1 -0
  34. package/dist-esm/src/InternalConstants.js +2 -1
  35. package/dist-esm/src/InternalConstants.js.map +1 -1
  36. package/dist-esm/src/KillSwitch.js +1 -1
  37. package/dist-esm/src/PostChannel.js +3 -3
  38. package/dist-esm/src/PostChannel.js.map +1 -1
  39. package/dist-esm/src/RetryPolicy.js +1 -1
  40. package/dist-esm/src/Serializer.d.ts +3 -3
  41. package/dist-esm/src/Serializer.js +5 -4
  42. package/dist-esm/src/Serializer.js.map +1 -1
  43. package/dist-esm/src/TimeoutOverrideWrapper.js +1 -1
  44. package/dist-esm/src/typings/XDomainRequest.js +1 -1
  45. package/package.json +4 -4
  46. package/src/DataModels.ts +26 -1
  47. package/src/EventBatch.ts +2 -2
  48. package/src/HttpManager.ts +59 -34
  49. package/src/InternalConstants.ts +1 -0
  50. package/src/PostChannel.ts +1 -1
  51. package/src/Serializer.ts +12 -11
  52. package/bundle/ms.post-3.2.6.gbl.js.map +0 -1
  53. package/bundle/ms.post-3.2.6.gbl.min.js +0 -7
  54. package/bundle/ms.post-3.2.6.gbl.min.js.map +0 -1
  55. package/bundle/ms.post-3.2.6.integrity.json +0 -46
  56. package/bundle/ms.post-3.2.6.js.map +0 -1
  57. package/bundle/ms.post-3.2.6.min.js +0 -7
  58. package/bundle/ms.post-3.2.6.min.js.map +0 -1
@@ -22,7 +22,7 @@ import { EventBatch } from "./EventBatch";
22
22
  import { IChannelConfiguration } from "./Index";
23
23
  import {
24
24
  DEFAULT_CACHE_CONTROL, DEFAULT_CONTENT_TYPE, STR_API_KEY, STR_AUTH_XTOKEN, STR_CACHE_CONTROL, STR_CLIENT_ID, STR_CLIENT_VERSION,
25
- STR_CONTENT_TYPE_HEADER, STR_DISABLED_PROPERTY_NAME, STR_DROPPED, STR_KILL_DURATION_HEADER, STR_KILL_DURATION_SECONDS_HEADER,
25
+ STR_CONTENT_TYPE_HEADER, STR_DISABLED_PROPERTY_NAME, STR_DROPPED, STR_EMPTY, STR_KILL_DURATION_HEADER, STR_KILL_DURATION_SECONDS_HEADER,
26
26
  STR_KILL_TOKENS_HEADER, STR_MSA_DEVICE_TICKET, STR_MSFPC, STR_NO_RESPONSE_BODY, STR_OTHER, STR_POST_METHOD, STR_REQUEUE,
27
27
  STR_RESPONSE_FAIL, STR_SENDING, STR_TIME_DELTA_HEADER, STR_TIME_DELTA_TO_APPLY, STR_UPLOAD_TIME
28
28
  } from "./InternalConstants";
@@ -85,7 +85,7 @@ function _getResponseText(xhr: XMLHttpRequest | IXDomainRequest) {
85
85
  // Best effort, as XHR may throw while XDR wont so just ignore
86
86
  }
87
87
 
88
- return "";
88
+ return STR_EMPTY;
89
89
  }
90
90
 
91
91
  interface IInternalXhrOverride extends IXHROverride {
@@ -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,9 @@ 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;
181
+ let _addNoResponse: boolean;
166
182
 
167
183
  dynamicProto(HttpManager, this, (_self) => {
168
184
  let _sendCredentials = true;
@@ -194,14 +210,21 @@ export class HttpManager {
194
210
  }
195
211
 
196
212
  _xhrTimeout = channelConfig.xhrTimeout;
197
- _disableXhrSync = channelConfig.disableXhrSync;
213
+ _disableXhrSync = !!channelConfig.disableXhrSync;
214
+ _disableFetchKeepAlive = !!channelConfig.disableFetchKeepAlive;
215
+ _addNoResponse = channelConfig.addNoResponse !== false;
198
216
 
199
217
  _useBeacons = !isReactNative(); // Only use beacons if not running in React Native
200
218
  _serializer = new Serializer(_core, valueSanitizer, stringifyObjects, enableCompoundKey);
201
219
 
220
+ if (!isNullOrUndefined(channelConfig.useSendBeacon)) {
221
+ _useBeacons = !!channelConfig.useSendBeacon;
222
+ }
223
+
202
224
  let syncHttpInterface = httpInterface;
203
225
  let beaconHttpInterface: IXHROverride = channelConfig.alwaysUseXhrOverride ? httpInterface : null;
204
226
  let fetchSyncHttpInterface: IXHROverride = channelConfig.alwaysUseXhrOverride ? httpInterface : null;
227
+ let beaconUnloadTransports: TransportType[] = [TransportType.Beacon, TransportType.Fetch];
205
228
 
206
229
  if (!httpInterface) {
207
230
  _customHttpInterface = false;
@@ -212,42 +235,45 @@ export class HttpManager {
212
235
  _sendCredentials = false;
213
236
  }
214
237
 
215
- let theTransports: number[] = [];
238
+ let theTransports: TransportType[] = [];
216
239
  if (isReactNative()) {
217
240
  // Use Fetch or XDR/XHR
218
241
  theTransports = [TransportType.Fetch, TransportType.Xhr];
242
+ beaconUnloadTransports = [TransportType.Fetch, TransportType.Xhr, TransportType.Beacon];
219
243
  } else {
220
244
  // Use XDR/XHR, Fetch or beacons
221
245
  theTransports = [TransportType.Xhr, TransportType.Fetch, TransportType.Beacon];
222
246
  }
223
247
 
224
248
  // Prefix any user requested transport(s) values
225
- let configTransports = channelConfig.transports;
226
- if (configTransports) {
227
- if (isNumber(configTransports)) {
228
- theTransports = [configTransports].concat(theTransports);
229
- } else if (isArray(configTransports)) {
230
- theTransports = configTransports.concat(theTransports);
231
- }
232
- }
249
+ theTransports = _prependTransports(theTransports, channelConfig.transports);
233
250
 
234
251
  httpInterface = _getSenderInterface(theTransports, false);
235
- syncHttpInterface = _getSenderInterface(theTransports, true);
236
252
  if (!httpInterface) {
237
253
  _warnToConsole(_logger, "No available transport to send events");
238
254
  }
255
+
256
+ syncHttpInterface = _getSenderInterface(theTransports, true);
257
+ }
258
+
259
+ if (!beaconHttpInterface) {
260
+ // Allow overriding the usage of sendBeacon
261
+ beaconUnloadTransports = _prependTransports(beaconUnloadTransports, channelConfig.unloadTransports);
262
+ beaconHttpInterface = _getSenderInterface(beaconUnloadTransports, true);
239
263
  }
240
264
 
265
+ _canHaveReducedPayload = !_customHttpInterface && ((_useBeacons && isBeaconsSupported()) || (!_disableFetchKeepAlive && isFetchSupported(true)));
266
+
241
267
  _sendInterfaces = {
242
268
  [EventSendType.Batched]: httpInterface,
243
269
  [EventSendType.Synchronous]: syncHttpInterface || _getSenderInterface([TransportType.Xhr, TransportType.Fetch, TransportType.Beacon], true),
244
- [EventSendType.SendBeacon]: beaconHttpInterface || _getSenderInterface([TransportType.Beacon, TransportType.Fetch], true) || syncHttpInterface || _getSenderInterface([TransportType.Xhr], true),
270
+ [EventSendType.SendBeacon]: beaconHttpInterface || syncHttpInterface || _getSenderInterface([TransportType.Xhr], true),
245
271
  [EventSendType.SyncFetch]: fetchSyncHttpInterface || _getSenderInterface([TransportType.Fetch, TransportType.Beacon], true) || syncHttpInterface || _getSenderInterface([TransportType.Xhr], true)
246
272
  };
247
273
  };
248
274
 
249
275
  // Special internal method to allow the DebugPlugin to hook embedded objects
250
- function _getSenderInterface(transports: number[], syncSupport: boolean): IInternalXhrOverride {
276
+ function _getSenderInterface(transports: TransportType[], syncSupport: boolean): IInternalXhrOverride {
251
277
  let transportType: TransportType = TransportType.NotSet;
252
278
  let sendPostFunc: SendPOSTFunction = null;
253
279
  let lp = 0;
@@ -259,7 +285,7 @@ export class HttpManager {
259
285
  } else if (isXhrSupported()) {
260
286
  sendPostFunc = _xhrSendPost;
261
287
  }
262
- } else if (transportType === TransportType.Fetch && isFetchSupported(syncSupport)) {
288
+ } else if (transportType === TransportType.Fetch && isFetchSupported(syncSupport) && (!syncSupport || (syncSupport && !_disableFetchKeepAlive))) {
263
289
  sendPostFunc = _fetchSendPost;
264
290
  } else if (_useBeacons && transportType === TransportType.Beacon && isBeaconsSupported()) {
265
291
  sendPostFunc = _beaconSendPost;
@@ -337,7 +363,9 @@ export class HttpManager {
337
363
  // As a sync request (during unload), it is unlikely that we will get a chance to process the response so
338
364
  // just like beacon send assume that the events have been accepted and processed
339
365
  ignoreResponse = true;
340
- theUrl += _noResponseQs;
366
+ if (_addNoResponse) {
367
+ theUrl += _noResponseQs;
368
+ }
341
369
  }
342
370
  }
343
371
 
@@ -353,7 +381,7 @@ export class HttpManager {
353
381
 
354
382
  fetch(theUrl, requestInit).then((response) => {
355
383
  let headerMap = {};
356
- let responseText = "";
384
+ let responseText = STR_EMPTY;
357
385
  var headers = response.headers;
358
386
  if (headers) {
359
387
  headers["forEach"]((value: string, name: string) => {
@@ -471,7 +499,7 @@ export class HttpManager {
471
499
  let internalPayloadData = payload as IInternalPayloadData;
472
500
  let status = 200;
473
501
  let thePayload = internalPayloadData._thePayload;
474
- let theUrl = payload.urlString + _noResponseQs;
502
+ let theUrl = payload.urlString + (_addNoResponse ? _noResponseQs : STR_EMPTY);
475
503
 
476
504
  try {
477
505
  let nav = getNavigator();
@@ -505,7 +533,7 @@ export class HttpManager {
505
533
  _warnToConsole(_logger, "Failed to send telemetry using sendBeacon API. Ex:" + dumpObj(ex));
506
534
  status = 0;
507
535
  } finally {
508
- _doOnComplete(oncomplete, status, {}, "");
536
+ _doOnComplete(oncomplete, status, {}, STR_EMPTY);
509
537
  }
510
538
  }
511
539
 
@@ -694,8 +722,10 @@ export class HttpManager {
694
722
  let thePayload: ISerializedPayload = null;
695
723
  let serializationStart = getTime();
696
724
  let sendInterface = _sendInterfaces[sendType] || (isSynchronous ? _sendInterfaces[EventSendType.Synchronous] : _sendInterfaces[EventSendType.Batched]);
725
+ let sendTransport = sendInterface && sendInterface._transport;
726
+
697
727
  // Sync Fetch has the same payload limitation as sendBeacon -- 64kb limit
698
- let isBeaconTransport = (_isUnloading || _isBeaconPayload(sendType) || (sendInterface && sendInterface._transport === TransportType.Beacon)) && _canUseSendBeaconApi();
728
+ let isReducedPayload = _canHaveReducedPayload && (_isUnloading || _isBeaconPayload(sendType) || (sendTransport === TransportType.Beacon || (sendInterface._isSync && sendTransport === TransportType.Fetch)));
699
729
 
700
730
  while (_canSendPayload(theBatches, sendType, retryCount)) {
701
731
  let theBatch = theBatches.shift();
@@ -703,7 +733,7 @@ export class HttpManager {
703
733
  if (!_killSwitch.isTenantKilled(theBatch.iKey())) {
704
734
 
705
735
  // Make sure we have a payload object
706
- thePayload = thePayload || _serializer.createPayload(retryCount, isTeardown, isSynchronous, isBeaconTransport, sendReason, sendType);
736
+ thePayload = thePayload || _serializer.createPayload(retryCount, isTeardown, isSynchronous, isReducedPayload, sendReason, sendType);
707
737
 
708
738
  // Add the batch to the current payload
709
739
  if (!_serializer.appendPayload(thePayload, theBatch, maxEventsPerBatch)) {
@@ -773,7 +803,7 @@ export class HttpManager {
773
803
  _addRequestDetails(requestDetails, STR_CLIENT_ID, "NO_AUTH", useHeaders);
774
804
  _addRequestDetails(requestDetails, STR_CLIENT_VERSION, FullVersionString, useHeaders);
775
805
 
776
- let apiQsKeys = "";
806
+ let apiQsKeys = STR_EMPTY;
777
807
  arrForEach(thePayload.apiKeys, (apiKey) => {
778
808
  if (apiQsKeys.length > 0) {
779
809
  apiQsKeys += ",";
@@ -808,10 +838,6 @@ export class HttpManager {
808
838
  return requestDetails;
809
839
  }
810
840
 
811
- function _canUseSendBeaconApi() {
812
- return !_customHttpInterface && _useBeacons && isBeaconsSupported();
813
- }
814
-
815
841
  function _setTimingValue(timings: any, name: string, value: number) {
816
842
  timings[name] = timings[name] || {};
817
843
  timings[name][_postManager.identifier] = value;
@@ -874,13 +900,11 @@ export class HttpManager {
874
900
  headers: requestDetails.hdrs,
875
901
  _thePayload: thePayload,
876
902
  _sendReason: sendReason,
877
- timeout: _xhrTimeout
903
+ timeout: _xhrTimeout,
904
+ disableXhrSync: _disableXhrSync,
905
+ disableFetchKeepAlive: _disableFetchKeepAlive
878
906
  };
879
907
 
880
- if (!isUndefined(_disableXhrSync)) {
881
- orgPayloadData.disableXhrSync = !!_disableXhrSync;
882
- }
883
-
884
908
  // Only automatically add the following headers if already sending headers and we are not attempting to avoid an options call
885
909
  if (useHeaders) {
886
910
  if (!_hasHeader(orgPayloadData.headers, STR_CACHE_CONTROL)) {
@@ -938,7 +962,8 @@ export class HttpManager {
938
962
  urlString: orgPayloadData.urlString,
939
963
  headers: extend({}, orgPayloadData.headers),
940
964
  timeout: orgPayloadData.timeout,
941
- disableXhrSync: orgPayloadData.disableXhrSync
965
+ disableXhrSync: orgPayloadData.disableXhrSync,
966
+ disableFetchKeepAlive: orgPayloadData.disableFetchKeepAlive
942
967
  };
943
968
 
944
969
  let senderCalled = false;
@@ -1176,7 +1201,7 @@ export class HttpManager {
1176
1201
  }
1177
1202
  }
1178
1203
 
1179
- return "";
1204
+ return STR_EMPTY;
1180
1205
  }
1181
1206
 
1182
1207
  function _handleCollectorResponse(responseText: string): void {
@@ -8,6 +8,7 @@
8
8
  // Generally you should only put values that are used more than 2 times and then only if not already exposed as a constant (such as SdkCoreNames)
9
9
  // as when using "short" named values from here they will be will be minified smaller than the SdkCoreNames[eSdkCoreNames.xxxx] value.
10
10
 
11
+ export const STR_EMPTY = "";
11
12
  export const STR_POST_METHOD = "POST";
12
13
  export const STR_DISABLED_PROPERTY_NAME: string = "Microsoft_ApplicationInsights_BypassAjaxInstrumentation";
13
14
 
@@ -160,7 +160,7 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
160
160
 
161
161
  // Override endpointUrl if provided in Post config
162
162
  let endpointUrl = _config.overrideEndpointUrl ? _config.overrideEndpointUrl : coreConfig.endpointUrl;
163
- _self._notificationManager = coreConfig.extensionConfig.NotificationManager;
163
+ _self._notificationManager = core.getNotifyMgr();
164
164
  _httpManager.initialize(endpointUrl, _self.core as IExtendedAppInsightsCore, _self, _xhrOverride, _config);
165
165
 
166
166
  let excludePageUnloadEvents = coreConfig.disablePageUnloadEvents || [];
package/src/Serializer.ts CHANGED
@@ -13,6 +13,7 @@ import {
13
13
  } from "@microsoft/1ds-core-js";
14
14
  import { IPostTransmissionTelemetryItem } from "./DataModels";
15
15
  import { EventBatch } from "./EventBatch";
16
+ import { STR_EMPTY } from "./InternalConstants";
16
17
 
17
18
  /**
18
19
  * Note: This is an optimization for V8-based browsers. When V8 concatenates a string,
@@ -60,7 +61,7 @@ export interface ISerializedPayload {
60
61
  /**
61
62
  * Events that where dropped because they could not be serialized
62
63
  */
63
- failedEvts: EventBatch[];
64
+ failedEvts: EventBatch[];
64
65
 
65
66
  /**
66
67
  * The batches included in this payload
@@ -85,12 +86,12 @@ export interface ISerializedPayload {
85
86
  /**
86
87
  * Is this payload a synchronous payload
87
88
  */
88
- isSync: boolean;
89
+ isSync: boolean;
89
90
 
90
- /**
91
- * The payload has been constructed for usage via sendBeacon API
92
- */
93
- isBeacon: boolean;
91
+ /**
92
+ * The payload has been constructed using a reduced payload size for usage with sendBeacon or fetch(with keepAlive) API's
93
+ */
94
+ isBeacon: boolean;
94
95
 
95
96
  /**
96
97
  * The request event sync type
@@ -121,10 +122,10 @@ export class Serializer {
121
122
 
122
123
  dynamicProto(Serializer, this, (_self) => {
123
124
 
124
- _self.createPayload = (retryCnt: number, isTeardown: boolean, isSync: boolean, useSendBeacon: boolean, sendReason: SendRequestReason, sendType: EventSendType): ISerializedPayload => {
125
+ _self.createPayload = (retryCnt: number, isTeardown: boolean, isSync: boolean, isReducedPayload: boolean, sendReason: SendRequestReason, sendType: EventSendType): ISerializedPayload => {
125
126
  return {
126
127
  apiKeys: [],
127
- payloadBlob: "",
128
+ payloadBlob: STR_EMPTY,
128
129
  overflow: null,
129
130
  sizeExceed: [],
130
131
  failedEvts: [],
@@ -133,7 +134,7 @@ export class Serializer {
133
134
  retryCnt: retryCnt,
134
135
  isTeardown: isTeardown,
135
136
  isSync: isSync,
136
- isBeacon: useSendBeacon,
137
+ isBeacon: isReducedPayload,
137
138
  sendType: sendType,
138
139
  sendReason: sendReason
139
140
  };
@@ -378,11 +379,11 @@ export class Serializer {
378
379
  * @param retryCnt The retry count for the events in this payload
379
380
  * @param isTeardown Is this payload being created as part of a teardown request
380
381
  * @param isSync Should this payload be sent as a synchronous request
381
- * @param useSendBeacon Is this payload going to be sent via sendBeacon() API
382
+ * @param isReducedPayload Is this payload going to be sent via sendBeacon() API
382
383
  * @param sendReason The reason the payload is being sent
383
384
  * @param sendType Identifies how this payload will be sent
384
385
  */
385
- public createPayload(retryCnt: number, isTeardown: boolean, isSync: boolean, useSendBeacon: boolean, sendReason: SendRequestReason, sendType: EventSendType): ISerializedPayload {
386
+ public createPayload(retryCnt: number, isTeardown: boolean, isSync: boolean, isReducedPayload: boolean, sendReason: SendRequestReason, sendType: EventSendType): ISerializedPayload {
386
387
  // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging
387
388
  return null;
388
389
  }