@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
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ ms.reviewedBy: ramthi
|
|
|
15
15
|
|
|
16
16
|
## npm
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
Packages available [here](https://msasg.visualstudio.com/Shared%20Data/_artifacts/feed/1DS-SDK/Npm/%40microsoft%2F1ds-post-js/3.2.0/versions).
|
|
19
19
|
|
|
20
20
|
## Basic Usage
|
|
21
21
|
|
|
@@ -65,6 +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[]
|
|
69
|
+
| avoidOptions<br/><sub><i>(Since 3.1.10+)</i></sub><br /><sub>Default: false (Since 3.2.0)<br />Previously true</sub> | [Optional] Avoid adding request headers to the outgoing request that would cause a pre-flight (OPTIONS) request to be sent for each request. | 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
|
|
68
75
|
|
|
69
76
|
### [IXHROverride](https://1dsdocs.azurewebsites.net/api/webSDK/chnl/post/3.0/f/interfaces/ixhroverride.html)
|
|
70
77
|
|
|
@@ -79,6 +86,8 @@ interface IPayloadData {
|
|
|
79
86
|
urlString: string;
|
|
80
87
|
data: Uint8Array | string;
|
|
81
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
|
|
82
91
|
}
|
|
83
92
|
|
|
84
93
|
type PayloadPreprocessorFunction = (payload: IPayloadData, callback: (modifiedBuffer: IPayloadData) => void) => void;
|
|
@@ -101,15 +110,39 @@ const gzipFn: PayloadPreprocessorFunction = (payload: IPayloadData, cb) => {
|
|
|
101
110
|
}
|
|
102
111
|
```
|
|
103
112
|
|
|
104
|
-
### XHR Override
|
|
113
|
+
### XHR Override
|
|
105
114
|
|
|
106
|
-
```
|
|
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
|
|
107
140
|
const oneDs = require('@microsoft/1ds-analytics-js');
|
|
108
141
|
const https = require('https');
|
|
109
142
|
|
|
110
143
|
// XHR override using node.js https module
|
|
111
144
|
var customHttpXHROverride= {
|
|
112
|
-
sendPOST: (payload, oncomplete) => {
|
|
145
|
+
sendPOST: (payload: IPayloadData, oncomplete) => {
|
|
113
146
|
var options = {
|
|
114
147
|
method: 'POST',
|
|
115
148
|
headers: {
|
|
@@ -127,12 +160,98 @@ var customHttpXHROverride= {
|
|
|
127
160
|
req.end();
|
|
128
161
|
}
|
|
129
162
|
};
|
|
130
|
-
|
|
163
|
+
|
|
164
|
+
var postChannelConfig: IChannelConfiguration = {
|
|
131
165
|
httpXHROverride: customHttpXHROverride
|
|
132
166
|
};
|
|
133
167
|
|
|
134
168
|
```
|
|
135
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
|
+
|
|
136
255
|
## IValueSanitizer Paths / Fields which are excluded
|
|
137
256
|
|
|
138
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
|