@microsoft/1ds-post-js 3.1.10 → 3.1.11

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 (53) hide show
  1. package/README.md +123 -5
  2. package/bundle/{ms.post-3.1.10.gbl.js → ms.post-3.1.11.gbl.js} +163 -86
  3. package/bundle/ms.post-3.1.11.gbl.js.map +1 -0
  4. package/bundle/ms.post-3.1.11.gbl.min.js +7 -0
  5. package/bundle/ms.post-3.1.11.gbl.min.js.map +1 -0
  6. package/bundle/ms.post-3.1.11.integrity.json +46 -0
  7. package/bundle/{ms.post-3.1.10.js → ms.post-3.1.11.js} +163 -86
  8. package/bundle/ms.post-3.1.11.js.map +1 -0
  9. package/bundle/ms.post-3.1.11.min.js +7 -0
  10. package/bundle/ms.post-3.1.11.min.js.map +1 -0
  11. package/bundle/ms.post.gbl.js +162 -85
  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 +162 -85
  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 +101 -47
  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/Constants.d.ts +1 -0
  27. package/dist-esm/src/Constants.js +2 -1
  28. package/dist-esm/src/Constants.js.map +1 -1
  29. package/dist-esm/src/DataModels.d.ts +49 -0
  30. package/dist-esm/src/DataModels.js +1 -1
  31. package/dist-esm/src/EventBatch.js +1 -1
  32. package/dist-esm/src/HttpManager.d.ts +1 -1
  33. package/dist-esm/src/HttpManager.js +63 -24
  34. package/dist-esm/src/HttpManager.js.map +1 -1
  35. package/dist-esm/src/Index.js +1 -1
  36. package/dist-esm/src/KillSwitch.js +1 -1
  37. package/dist-esm/src/PostChannel.js +51 -28
  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.js +1 -1
  41. package/dist-esm/src/typings/XDomainRequest.js +1 -1
  42. package/package.json +2 -2
  43. package/src/Constants.ts +1 -0
  44. package/src/DataModels.ts +62 -1
  45. package/src/HttpManager.ts +67 -22
  46. package/src/PostChannel.ts +56 -28
  47. package/bundle/ms.post-3.1.10.gbl.js.map +0 -1
  48. package/bundle/ms.post-3.1.10.gbl.min.js +0 -7
  49. package/bundle/ms.post-3.1.10.gbl.min.js.map +0 -1
  50. package/bundle/ms.post-3.1.10.integrity.json +0 -46
  51. package/bundle/ms.post-3.1.10.js.map +0 -1
  52. package/bundle/ms.post-3.1.10.min.js +0 -7
  53. package/bundle/ms.post-3.1.10.min.js.map +0 -1
package/README.md CHANGED
@@ -15,7 +15,7 @@ ms.reviewedBy: ramthi
15
15
 
16
16
  ## npm
17
17
 
18
- Package available [here](https://msasg.visualstudio.com/Shared%20Data/_packaging?_a=package&feed=1DS-SDK&package=%40microsoft%2F1ds-post-js&protocolType=Npm).
18
+ Packages available [here](https://msasg.visualstudio.com/Shared%20Data/_artifacts/feed/1DS-SDK/Npm/%40microsoft%2F1ds-post-js/3.1.11/versions).
19
19
 
20
20
  ## Basic Usage
21
21
 
@@ -65,7 +65,13 @@ appInsightsCore.initialize(coreConfig, []);
65
65
  | stringifyObjects | [Optional] During serialization, when an object is identified should the object serialized by true => JSON.stringify(theObject); otherwise theObject.toString(). Defaults to false. | boolean
66
66
  | enableCompoundKey | [Optional] Enables support for objects with compound keys which indirectly represent an object eg. event: { "somedata.embeddedvalue": 123 } where the "key" of the object contains a "." as part of it's name. Defaults to false. | boolean
67
67
  | disableOptimizeObj | [Optional] Switch to disable the v8 `optimizeObject()` calls used to provide better serialization performance. Defaults to false. | boolean
68
+ | transports | [Optional] Either an array or single value identifying the requested `TransportType` (const enum) type that should be used. This is used during initialization to identify the requested send transport, it will be ignored if a httpXHROverride is provided. | number or number[]
68
69
  | avoidOptions<br/><sub><i>(Since 3.1.10+ === true*)</i></sub> | [Optional] Avoid adding request headers to the outgoing request that would cause a pre-flight (OPTIONS) request to be sent for each request.<br/> <sub>* This currently defaults to true but will be changed once the collector handles additional settings to allow the browser to better cache any previous OPTIONS response, at which point some of the current dynamic values sent on the query string will be moved to a header.</sub> | boolean
70
+ | xhrTimeout<br/><sub><i>(Since 3.1.11+)</i></sub> | [Optional] Specify a timeout (in ms) to apply to requests when sending requests using XHR or fetch() requests only, does not affect sendBeacon() or XDR (XDomainRequest) usage. Defaults to undefined and therefore the runtime defaults (normally zero for browser environments) | number
71
+ | disableXhrSync<br/><sub><i>(Since 3.1.11+)</i></sub> | [Optional] When using [Xhr](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) for sending requests disable sending as synchronous during unload or synchronous flush. __You should enable this feature for IE (when there is no sendBeacon() or fetch (with keep-alive) support) and you have clients that end up blocking the UI during page unloading__. <span style="color:red">This will cause ALL XHR requests to be sent asynchronously which during page unload may result in the lose of telemetry</span>. This does not affect any other request type (fetch(), sendBeacon() or XDR (XDomainRequest)) | boolean<br/>Default: undefined
72
+ | alwaysUseXhrOverride<br /><sub><i>(Since 3.1.11+)</i></sub> | [Optional] By default during unload (or when you specify to use sendBeacon() or sync fetch (with keep-alive) for an event) the SDK ignores any provided httpXhrOverride and attempts to use sendBeacon() or fetch(with keep-alive) when they are available. When this configuration option is true any provided httpXhrOverride will always be used, so any provided httpXhrOverride will also need to "handle" the synchronous unload scenario. | boolean<br /> Default: false
73
+ | maxEventRetryAttempts<br /><sub><i>(Since 3.1.11+)</i></sub> | [Optional] Identifies the number of times any single event will be retried if it receives a failed (retirable) response, this causes the event to be internally "requeued" and resent in the next batch. As each normal batched send request is retried at least once before starting to increase the internal backoff send interval, normally batched events will generally be attempted the next nearest even number of times. This means that the total number of actual send attempts will almost always be even (setting to 5 will cause 6 requests), unless using manual synchronous flushing (calling flush(false)) which is not subject to request level retry attempts. | number<br/>Default: 6
74
+ | maxUnloadEventRetryAttempts<br /><sub><i>(Since 3.1.11+)</i></sub> | [Optional] Identifies the number of times any single event will be retried if it receives a failed (retriable) response as part of processing / flushing events once a page unload state has been detected, this causes the event to be internally "requeued" and resent in the next batch, which during page unload. Unlike the normal batching process, send requests are never retried, so the value listed here is always the maximum number of attempts for any single event.<br/>Notes: The SDK by default will use the sendBeacon() API if it exists which is treated as a fire and forget successful response, so for environments that support or supply this API the events won't be retried (because they will be deeded to be successfully sent). When an environment (IE) doesn't support sendBeacon(), this will cause multiple synchronous (by default) XMLHttpRequests to be sent, which will block the UI until a response is received. You can disable ALL synchronous XHR requests by setting the 'disableXhrSync' configuration setting and/or changing this value to 0 or 1. | number<br/>Default: 2
69
75
 
70
76
  ### [IXHROverride](https://1dsdocs.azurewebsites.net/api/webSDK/chnl/post/3.0/f/interfaces/ixhroverride.html)
71
77
 
@@ -80,6 +86,8 @@ interface IPayloadData {
80
86
  urlString: string;
81
87
  data: Uint8Array | string;
82
88
  headers?: { [name: string]: string };
89
+ timeout?: number; // Optional value supplied by the xhrTimeout configuration option
90
+ disableXhrSync?: boolean; // Optional value supplied by the disableXhrSync configuration option
83
91
  }
84
92
 
85
93
  type PayloadPreprocessorFunction = (payload: IPayloadData, callback: (modifiedBuffer: IPayloadData) => void) => void;
@@ -102,15 +110,39 @@ const gzipFn: PayloadPreprocessorFunction = (payload: IPayloadData, cb) => {
102
110
  }
103
111
  ```
104
112
 
105
- ### XHR Override sample using node.js Https module
113
+ ### XHR Override
106
114
 
107
- ```js
115
+ ```ts
116
+ /**
117
+ * SendPOSTFunction type defines how an HTTP POST request is sent to an ingestion server
118
+ * @param payload - The payload object that should be sent, contains the url, bytes/string and headers for the request
119
+ * @param oncomplete - The function to call once the request has completed whether a success, failure or timeout
120
+ * @param sync - A boolean flag indicating whether the request should be sent as a synchronous request.
121
+ */
122
+ export type SendPOSTFunction = (payload: IPayloadData, oncomplete: (status: number, headers: { [headerName: string]: string; }, response?: string) => void, sync?: boolean) => void;
123
+
124
+ /**
125
+ * The IXHROverride interface overrides the way HTTP requests are sent.
126
+ */
127
+ export interface IXHROverride {
128
+ /**
129
+ * This method sends data to the specified URI using a POST request. If sync is true,
130
+ * then the request is sent synchronously. The <i>oncomplete</i> function should always be called after the request is
131
+ * completed (either successfully or timed out or failed due to errors).
132
+ */
133
+ sendPOST: SendPOSTFunction;
134
+ }
135
+ ```
136
+
137
+ #### Example using node.js Https module
138
+
139
+ ```ts
108
140
  const oneDs = require('@microsoft/1ds-analytics-js');
109
141
  const https = require('https');
110
142
 
111
143
  // XHR override using node.js https module
112
144
  var customHttpXHROverride= {
113
- sendPOST: (payload, oncomplete) => {
145
+ sendPOST: (payload: IPayloadData, oncomplete) => {
114
146
  var options = {
115
147
  method: 'POST',
116
148
  headers: {
@@ -128,12 +160,98 @@ var customHttpXHROverride= {
128
160
  req.end();
129
161
  }
130
162
  };
131
- var postChannelConfig = {
163
+
164
+ var postChannelConfig: IChannelConfiguration = {
132
165
  httpXHROverride: customHttpXHROverride
133
166
  };
134
167
 
135
168
  ```
136
169
 
170
+ #### Example always using fetch API
171
+
172
+ This example is using the [fetch() API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch) for all requests, include synchronous requests and assumes that the browser environment supports the (currently) experimental keepalive option (for chromium).
173
+
174
+ ```ts
175
+ function fetchHttpXHROverride(payload: IPayloadData, onComplete: OnCompleteCallback, sync?: boolean) {
176
+ let ignoreResponse = false;
177
+ let responseHandled = false;
178
+ let requestInit: RequestInit = {
179
+ body: payload.data,
180
+ method: Method,
181
+ headers: payload.headers,
182
+ [DisabledPropertyName]: true,
183
+ credentials: "include"
184
+ };
185
+
186
+ if (sync) {
187
+ // You should validate whether the runtime environment supports this flag and if not you should use either sendBeacon or a synchronous XHR request
188
+ requestInit.keepalive = true;
189
+ if (sync) {
190
+ // As a sync request (during unload), it is unlikely that we will get a chance to process the response so
191
+ // just like beacon send assume that the events have been accepted and processed
192
+ ignoreResponse = true;
193
+ }
194
+ }
195
+
196
+ fetch(payload.urlString, requestInit).then((response) => {
197
+ let headerMap = {};
198
+ let responseText = "";
199
+ if (response.headers) {
200
+ response.headers.forEach((value: string, name: string) => {
201
+ headerMap[name] = value;
202
+ });
203
+ }
204
+
205
+ if (response.body) {
206
+ response.text().then(function(text) {
207
+ responseText = text;
208
+ });
209
+ }
210
+
211
+ if (!responseHandled) {
212
+ responseHandled = true;
213
+ onComplete(response.status, headerMap, responseText);
214
+ }
215
+ }).catch((error) => {
216
+ // In case there is an error in the request. Set the status to 0
217
+ // so that the events can be retried later.
218
+ if (!responseHandled) {
219
+ responseHandled = true;
220
+ onComplete(0, {});
221
+ }
222
+ });
223
+
224
+ // If we are treating this as a synchronous (keepAlive) we need to assume success during unload processing
225
+ if (ignoreResponse && !responseHandled) {
226
+ responseHandled = true;
227
+ onComplete(200, {});
228
+ }
229
+
230
+ // Simulate timeout if a timeout was supplied
231
+ if (!responseHandled && payload.timeout > 0) {
232
+ setTimeout(() => {
233
+ if (!responseHandled) {
234
+ // Assume a 500 response (which will cause a retry)
235
+ responseHandled = true;
236
+ onComplete(500, {});
237
+ }
238
+ }, payload.timeout);
239
+ }
240
+ }
241
+
242
+ let postChannelConfig: IChannelConfiguration = {
243
+ httpXHROverride: fetchHttpXHROverride,
244
+
245
+ // Enable this flag to cause the SDK to ALWAYS call your override otherwise during page unload the SDK will using it's internal
246
+ // sendPost implementation using sendBeacon() or fetch (with keepalive support) whichever is the first supported
247
+ //alwaysUseXhrOverride: true,
248
+
249
+ // If you want to specify a timeout this value is passed on the payload object as `payload.timeout`
250
+ //xhrTimeout: 20000,
251
+ };
252
+
253
+ ```
254
+
137
255
  ## IValueSanitizer Paths / Fields which are excluded
138
256
 
139
257
  To ensure that the service can continue to accept events that are sent from the SDK, some paths and fields are explicitly blocked and are never processed