@microsoft/1ds-post-js 3.2.10 → 4.0.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.
Files changed (105) hide show
  1. package/README.md +1 -1
  2. package/bundle/es5/ms.post-4.0.0.gbl.js +5816 -0
  3. package/bundle/es5/ms.post-4.0.0.gbl.js.map +1 -0
  4. package/bundle/es5/ms.post-4.0.0.gbl.min.js +7 -0
  5. package/bundle/es5/ms.post-4.0.0.gbl.min.js.map +1 -0
  6. package/bundle/es5/ms.post-4.0.0.integrity.json +46 -0
  7. package/bundle/es5/ms.post-4.0.0.js +5820 -0
  8. package/bundle/es5/ms.post-4.0.0.js.map +1 -0
  9. package/bundle/es5/ms.post-4.0.0.min.js +7 -0
  10. package/bundle/es5/ms.post-4.0.0.min.js.map +1 -0
  11. package/bundle/es5/ms.post.gbl.js +5816 -0
  12. package/bundle/es5/ms.post.gbl.js.map +1 -0
  13. package/bundle/es5/ms.post.gbl.min.js +7 -0
  14. package/bundle/es5/ms.post.gbl.min.js.map +1 -0
  15. package/bundle/es5/ms.post.integrity.json +46 -0
  16. package/bundle/es5/ms.post.js +5820 -0
  17. package/bundle/es5/ms.post.js.map +1 -0
  18. package/bundle/es5/ms.post.min.js +7 -0
  19. package/bundle/es5/ms.post.min.js.map +1 -0
  20. package/{bundle → dist/es5}/ms.post.js +2942 -1670
  21. package/dist/es5/ms.post.js.map +1 -0
  22. package/dist/es5/ms.post.min.js +7 -0
  23. package/dist/es5/ms.post.min.js.map +1 -0
  24. package/{dist-esm/src → dist-es5}/BatchNotificationActions.js +1 -1
  25. package/{dist-esm/src → dist-es5}/ClockSkewManager.js +2 -2
  26. package/{dist-esm/src → dist-es5}/ClockSkewManager.js.map +1 -1
  27. package/{dist-esm/src → dist-es5}/DataModels.js +1 -1
  28. package/{dist-esm/src → dist-es5}/EventBatch.js +1 -1
  29. package/{dist-esm/src → dist-es5}/HttpManager.js +175 -94
  30. package/dist-es5/HttpManager.js.map +1 -0
  31. package/{dist-esm/src → dist-es5}/Index.js +2 -2
  32. package/dist-es5/Index.js.map +1 -0
  33. package/{dist-esm/src → dist-es5}/InternalConstants.js +1 -1
  34. package/{dist-esm/src → dist-es5}/KillSwitch.js +2 -2
  35. package/{dist-esm/src → dist-es5}/KillSwitch.js.map +1 -1
  36. package/{dist-esm/src → dist-es5}/PostChannel.js +166 -144
  37. package/dist-es5/PostChannel.js.map +1 -0
  38. package/{dist-esm/src → dist-es5}/RetryPolicy.js +1 -1
  39. package/{dist-esm/src → dist-es5}/Serializer.js +3 -2
  40. package/dist-es5/Serializer.js.map +1 -0
  41. package/dist-es5/TimeoutOverrideWrapper.js +24 -0
  42. package/dist-es5/TimeoutOverrideWrapper.js.map +1 -0
  43. package/{dist-esm/src → dist-es5}/typings/XDomainRequest.js +1 -1
  44. package/package.json +17 -11
  45. package/tsconfig.json +5 -2
  46. package/{src/DataModels.ts → types/1ds-post-js.d.ts} +408 -467
  47. package/types/1ds-post-js.namespaced.d.ts +404 -0
  48. package/bundle/ms.post-3.2.10.gbl.js +0 -4524
  49. package/bundle/ms.post-3.2.10.gbl.js.map +0 -1
  50. package/bundle/ms.post-3.2.10.gbl.min.js +0 -7
  51. package/bundle/ms.post-3.2.10.gbl.min.js.map +0 -1
  52. package/bundle/ms.post-3.2.10.integrity.json +0 -46
  53. package/bundle/ms.post-3.2.10.js +0 -4527
  54. package/bundle/ms.post-3.2.10.js.map +0 -1
  55. package/bundle/ms.post-3.2.10.min.js +0 -7
  56. package/bundle/ms.post-3.2.10.min.js.map +0 -1
  57. package/bundle/ms.post.gbl.js +0 -4524
  58. package/bundle/ms.post.gbl.js.map +0 -1
  59. package/bundle/ms.post.gbl.min.js +0 -7
  60. package/bundle/ms.post.gbl.min.js.map +0 -1
  61. package/bundle/ms.post.integrity.json +0 -46
  62. package/bundle/ms.post.js.map +0 -1
  63. package/bundle/ms.post.min.js +0 -7
  64. package/bundle/ms.post.min.js.map +0 -1
  65. package/dist/ms.post.js +0 -2144
  66. package/dist/ms.post.js.map +0 -1
  67. package/dist/ms.post.min.js +0 -7
  68. package/dist/ms.post.min.js.map +0 -1
  69. package/dist-esm/src/BatchNotificationActions.d.ts +0 -36
  70. package/dist-esm/src/ClockSkewManager.d.ts +0 -38
  71. package/dist-esm/src/DataModels.d.ts +0 -405
  72. package/dist-esm/src/EventBatch.d.ts +0 -47
  73. package/dist-esm/src/HttpManager.d.ts +0 -88
  74. package/dist-esm/src/HttpManager.js.map +0 -1
  75. package/dist-esm/src/Index.d.ts +0 -9
  76. package/dist-esm/src/Index.js.map +0 -1
  77. package/dist-esm/src/InternalConstants.d.ts +0 -28
  78. package/dist-esm/src/KillSwitch.d.ts +0 -26
  79. package/dist-esm/src/PostChannel.d.ts +0 -101
  80. package/dist-esm/src/PostChannel.js.map +0 -1
  81. package/dist-esm/src/RetryPolicy.d.ts +0 -21
  82. package/dist-esm/src/Serializer.d.ts +0 -108
  83. package/dist-esm/src/Serializer.js.map +0 -1
  84. package/dist-esm/src/TimeoutOverrideWrapper.d.ts +0 -18
  85. package/dist-esm/src/TimeoutOverrideWrapper.js +0 -28
  86. package/dist-esm/src/TimeoutOverrideWrapper.js.map +0 -1
  87. package/dist-esm/src/typings/XDomainRequest.d.ts +0 -17
  88. package/src/BatchNotificationActions.ts +0 -44
  89. package/src/ClockSkewManager.ts +0 -127
  90. package/src/EventBatch.ts +0 -137
  91. package/src/HttpManager.ts +0 -1379
  92. package/src/Index.ts +0 -18
  93. package/src/InternalConstants.ts +0 -42
  94. package/src/KillSwitch.ts +0 -84
  95. package/src/PostChannel.ts +0 -1163
  96. package/src/RetryPolicy.ts +0 -46
  97. package/src/Serializer.ts +0 -487
  98. package/src/TimeoutOverrideWrapper.ts +0 -29
  99. package/src/typings/XDomainRequest.ts +0 -23
  100. /package/{dist-esm/src → dist-es5}/BatchNotificationActions.js.map +0 -0
  101. /package/{dist-esm/src → dist-es5}/DataModels.js.map +0 -0
  102. /package/{dist-esm/src → dist-es5}/EventBatch.js.map +0 -0
  103. /package/{dist-esm/src → dist-es5}/InternalConstants.js.map +0 -0
  104. /package/{dist-esm/src → dist-es5}/RetryPolicy.js.map +0 -0
  105. /package/{dist-esm/src → dist-es5}/typings/XDomainRequest.js.map +0 -0
@@ -1,467 +1,408 @@
1
- /**
2
- * DataModels.ts
3
- * @author Abhilash Panwar (abpanwar) and Hector Hernandez (hectorh)
4
- * @copyright Microsoft 2018
5
- * File containing the interfaces for Post channel module.
6
- */
7
- import {
8
- IExtendedTelemetryItem, NotificationManager, IDiagnosticLogger, ITelemetryPlugin, IProcessTelemetryContext,
9
- IValueSanitizer,
10
- } from "@microsoft/1ds-core-js";
11
-
12
- /** IPayloadData describes interface of payload sent via POST channel */
13
- export interface IPayloadData {
14
- urlString: string;
15
- data: Uint8Array | string;
16
- headers?: { [name: string]: string };
17
- timeout?: number;
18
- disableXhrSync?: boolean;
19
- disableFetchKeepAlive?: boolean;
20
- }
21
-
22
- /**
23
- * Defines the function signature for the Payload Preprocessor.
24
- * @param payload - The Initial constructed payload that if not modified should be passed onto the callback function.
25
- * @param callback - The preprocessor MUST call the callback function to ensure that the events are sent to the server, failing to call WILL result in dropped events.
26
- * The modifiedBuffer argument can be either the original payload or may be modified by performing GZipping of the payload and adding the content header.
27
- * @param isSync - A boolean flag indicating whether this request was initiated as part of a sync response (unload / flush request), this is for informative only.
28
- * e.g the preprocessor may wish to not perform any GZip operations if the request was a sync request which is normally called as part of an unload request.
29
- */
30
- export type PayloadPreprocessorFunction = (payload: IPayloadData, callback: (modifiedBuffer: IPayloadData) => void, isSync?: boolean) => void;
31
-
32
- /**
33
- * Defines the function signature of a payload listener, which is called after the payload has been sent to the server. The listener is passed
34
- * both the initial payload object and any altered (modified) payload from a preprocessor so it can determine what payload it may want to log or send.
35
- * Used by the Remove DDV extension to listen to server send events.
36
- * @param orgPayload - The initially constructed payload object
37
- * @param sendPayload - The alternative (possibly modified by a preprocessor) payload
38
- * @param isSync - A boolean flag indicating whether this request was initiated as part of a sync response (unload / flush request), this is for informative only.
39
- * @param isBeaconSend - A boolean flag indicating whether the payload was sent using the navigator.sendBeacon() API.
40
- */
41
- export type PayloadListenerFunction = (orgPayload: IPayloadData, sendPayload?: IPayloadData, isSync?: boolean, isBeaconSend?: boolean) => void;
42
-
43
- /**
44
- * The IChannelConfiguration interface holds the configuration details passed to Post module.
45
- */
46
- export interface IChannelConfiguration {
47
- /**
48
- * [Optional] The number of events that can be kept in memory before the SDK starts to drop events. By default, this is 10,000.
49
- */
50
- eventsLimitInMem?: number;
51
-
52
- /**
53
- * [Optional] Sets the maximum number of immediate latency events that will be cached in memory before the SDK starts to drop other
54
- * immediate events only, does not drop normal and real time latency events as immediate events have their own internal queue. Under
55
- * normal situations immediate events are scheduled to be sent in the next Javascript execution cycle, so the typically number of
56
- * immediate events is small (~1), the only time more than one event may be present is when the channel is paused or immediate send
57
- * is disabled (via manual transmit profile). By default max number of events is 500 and the default transmit time is 0ms.
58
- */
59
- immediateEventLimit?: number;
60
-
61
- /**
62
- * [Optional] If defined, when the number of queued events reaches or exceeded this limit this will cause the queue to be immediately
63
- * flushed rather than waiting for the normal timers. Defaults to undefined.
64
- */
65
- autoFlushEventsLimit?: number;
66
-
67
- /**
68
- * [Optional] If defined allows you to disable the auto batch (iKey set of requests) flushing logic. This is in addition to the
69
- * default transmission profile timers, autoFlushEventsLimit and eventsLimitInMem config values.
70
- */
71
- disableAutoBatchFlushLimit?: boolean;
72
-
73
- /**
74
- * [Optional] The HTTP override that should be used to send requests, as an IXHROverride object.
75
- * By default during the unload of a page or if the event specifies that it wants to use sendBeacon() or sync fetch (with keep-alive),
76
- * this override will NOT be called. You can now change this behavior by enabling the 'alwaysUseXhrOverride' configuration value.
77
- * The payload data (first argument) now also includes any configured 'timeout' (defaults to undefined) and whether you should avoid
78
- * creating any synchronous XHR requests 'disableXhrSync' (defaults to false/undefined)
79
- */
80
- httpXHROverride?: IXHROverride;
81
-
82
- /**
83
- * Override for Instrumentation key
84
- */
85
- overrideInstrumentationKey?: string;
86
-
87
- /**
88
- * Override for Endpoint where telemetry data is sent
89
- */
90
- overrideEndpointUrl?: string;
91
-
92
- /**
93
- * The master off switch. Do not send any data if set to TRUE
94
- */
95
- disableTelemetry?: boolean;
96
-
97
- /**
98
- * MC1 and MS0 cookies will not be returned from Collector endpoint.
99
- */
100
- ignoreMc1Ms0CookieProcessing?: boolean;
101
-
102
- /**
103
- * Override for setTimeout
104
- */
105
- setTimeoutOverride?: typeof setTimeout;
106
-
107
- /**
108
- * Override for clearTimeout
109
- */
110
- clearTimeoutOverride?: typeof clearTimeout;
111
-
112
- /**
113
- * [Optional] POST channel preprocessing function. Can be used to gzip the payload before transmission and to set the appropriate
114
- * Content-Encoding header. The preprocessor is explicitly not called during teardown when using the sendBeacon() API.
115
- */
116
- payloadPreprocessor?: PayloadPreprocessorFunction;
117
-
118
- /**
119
- * [Optional] POST channel listener function, used for enabling logging or reporting (RemoteDDVChannel) of the payload that is being sent.
120
- */
121
- payloadListener?: PayloadListenerFunction;
122
-
123
- /**
124
- * [Optional] By default additional timing metrics details are added to each event after they are sent to allow you to review how long it took
125
- * to create serialized request. As not all implementations require this level of detail and it's now possible to get the same metrics via
126
- * the IPerfManager and IPerfEvent we are enabling these details to be disabled. Default value is false to retain the previous behavior,
127
- * if you are not using these metrics and performance is a concern then it is recommended to set this value to true.
128
- */
129
- disableEventTimings?: boolean;
130
-
131
- /**
132
- * [Optional] The value sanitizer to use while constructing the envelope.
133
- */
134
- valueSanitizer?: IValueSanitizer;
135
-
136
- /**
137
- * [Optional] During serialization, when an object is identified, should the object be serialized by JSON.stringify(theObject); (when true) otherwise by theObject.toString().
138
- * Defaults to false
139
- */
140
- stringifyObjects?: boolean;
141
-
142
- /**
143
- * [Optional] Enables support for objects with compound keys which indirectly represent an object where the "key" of the object contains a "." as part of it's name.
144
- * @example
145
- * ```typescript
146
- * event: { "somedata.embeddedvalue": 123 }
147
- * ```
148
- */
149
- enableCompoundKey?: boolean;
150
-
151
- /**
152
- * [Optional] Switch to disable the v8 optimizeObject() calls used to provide better serialization performance. Defaults to false.
153
- */
154
- disableOptimizeObj?: boolean;
155
-
156
- /**
157
- * [Optional] By default a "Cache-Control" header will be added to the outbound payloads with the value "no-cache, no-store", this is to
158
- * avoid instances where Chrome can "Stall" requests which use the same outbound URL.
159
- */
160
- // See Task #7178858 - Collector requires a change to support this
161
- // disableCacheHeader?: boolean;
162
-
163
- /**
164
- * [Optional] Either an array or single value identifying the requested TransportType type that should be used.
165
- * This is used during initialization to identify the requested send transport, it will be ignored if a httpXHROverride is provided.
166
- */
167
- transports?: number | number[];
168
-
169
- /**
170
- * [Optional] Either an array or single value identifying the requested TransportType type(s) that should be used during unload or events
171
- * marked as sendBeacon. This is used during initialization to identify the requested send transport, it will be ignored if a httpXHROverride
172
- * is provided and alwaysUseXhrOverride is true.
173
- */
174
- unloadTransports?: number | number[];
175
-
176
- /**
177
- * [Optional] A flag to enable or disable the usage of the sendBeacon() API (if available). If running on ReactNative this defaults
178
- * to `false` for all other cases it defaults to `true`.
179
- */
180
- useSendBeacon?: boolean;
181
-
182
- /**
183
- * [Optional] A flag to disable the usage of the [fetch with keep-alive](https://javascript.info/fetch-api#keepalive) support.
184
- */
185
- disableFetchKeepAlive?: boolean;
186
-
187
- /**
188
- * [Optional] Avoid adding request headers to the outgoing request that would cause a pre-flight (OPTIONS) request to be sent for each request.
189
- * This currently defaults to true but will be changed once the collector handles additional settings to allow the browser to better cache any
190
- * previous OPTIONS response, at which point some of the current dynamic values sent on the query string will be moved to a header.
191
- */
192
- avoidOptions?: boolean;
193
-
194
- /**
195
- * [Optional] Specify a timeout (in ms) to apply to requests when sending requests using XHR, XDR or fetch requests. Defaults to undefined
196
- * and therefore the runtime defaults (normally zero for browser environments)
197
- */
198
- xhrTimeout?: number;
199
-
200
- /**
201
- * [Optional] When using Xhr for sending requests disable sending as synchronous during unload or synchronous flush.
202
- * You should enable this feature for IE (when there is no sendBeacon() or fetch (with keep-alive)) and you have clients
203
- * that end up blocking the UI during page unloading. This will cause ALL XHR requests to be sent asynchronously which
204
- * during page unload may result in the lose of telemetry.
205
- */
206
- disableXhrSync?: boolean;
207
-
208
- /**
209
- * [Optional] By default during unload (or when you specify to use sendBeacon() or sync fetch (with keep-alive) for an event) the SDK
210
- * ignores any provided httpXhrOverride and attempts to use sendBeacon() or fetch(with keep-alive) when they are available.
211
- * When this configuration option is true any provided httpXhrOverride will always be used, so any provided httpXhrOverride will
212
- * also need to "handle" the synchronous unload scenario.
213
- */
214
- alwaysUseXhrOverride?: boolean;
215
-
216
- /**
217
- * [Optional] Identifies the number of times any single event will be retried if it receives a failed (retirable) response, this
218
- * causes the event to be internally "requeued" and resent in the next batch. As each normal batched send request is retried at
219
- * least once before starting to increase the internal backoff send interval, normally batched events will generally be attempted
220
- * the next nearest even number of times. This means that the total number of actual send attempts will almost always be even
221
- * (setting to 5 will cause 6 requests), unless using manual synchronous flushing (calling flush(false)) which is not subject to
222
- * request level retry attempts.
223
- * Defaults to 6 times.
224
- */
225
- maxEventRetryAttempts?: number;
226
-
227
- /**
228
- * [Optional] Identifies the number of times any single event will be retried if it receives a failed (retriable) response as part
229
- * of processing / flushing events once a page unload state has been detected, this causes the event to be internally "requeued"
230
- * and resent in the next batch, which during page unload. Unlike the normal batching process, send requests are never retried,
231
- * so the value listed here is always the maximum number of attempts for any single event.
232
- * Defaults to 2 times.
233
- * Notes:
234
- * The SDK by default will use the sendBeacon() API if it exists which is treated as a fire and forget successful response, so for
235
- * environments that support or supply this API the events won't be retried (because they will be deeded to be successfully sent).
236
- * When an environment (IE) doesn't support sendBeacon(), this will cause multiple synchronous (by default) XMLHttpRequests to be sent,
237
- * which will block the UI until a response is received. You can disable ALL synchronous XHR requests by setting the 'disableXhrSync'
238
- * configuration setting and/or changing this value to 0 or 1.
239
- */
240
- maxUnloadEventRetryAttempts?: number;
241
-
242
- /**
243
- * [Optional] flag to indicate whether the sendBeacon and fetch (with keep-alive flag) should add the "NoResponseBody" query string
244
- * value to indicate that the server should return a 204 for successful requests. Defaults to true
245
- */
246
- addNoResponse?: boolean;
247
- }
248
-
249
- /**
250
- * SendPOSTFunction type defines how an HTTP POST request is sent to an ingestion server
251
- * @param payload - The payload object that should be sent, contains the url, bytes/string and headers for the request
252
- * @param oncomplete - The function to call once the request has completed whether a success, failure or timeout
253
- * @param sync - A boolean flag indicating whether the request should be sent as a synchronous request.
254
- */
255
- export type SendPOSTFunction = (payload: IPayloadData, oncomplete: (status: number, headers: { [headerName: string]: string; }, response?: string) => void, sync?: boolean) => void;
256
-
257
- /**
258
- * The IXHROverride interface overrides the way HTTP requests are sent.
259
- */
260
- export interface IXHROverride {
261
- /**
262
- * This method sends data to the specified URI using a POST request. If sync is true,
263
- * then the request is sent synchronously. The <i>oncomplete</i> function should always be called after the request is
264
- * completed (either successfully or timed out or failed due to errors).
265
- */
266
- sendPOST: SendPOSTFunction;
267
- }
268
-
269
- /**
270
- * An interface which extends the telemetry event to track send attempts.
271
- */
272
- export interface IPostTransmissionTelemetryItem extends IExtendedTelemetryItem {
273
- /**
274
- * The number of times the telemtry item has been attempted to be sent.
275
- */
276
- sendAttempt?: number;
277
- }
278
-
279
- /**
280
- * Real Time profile (default profile). RealTime Latency events are sent every 1 sec and
281
- * Normal Latency events are sent every 2 sec.
282
- */
283
- export const RT_PROFILE = "REAL_TIME";
284
- /**
285
- * Near Real Time profile. RealTime Latency events are sent every 3 sec and
286
- * Normal Latency events are sent every 6 sec.
287
- */
288
- export const NRT_PROFILE = "NEAR_REAL_TIME";
289
- /**
290
- * Best Effort. RealTime Latency events are sent every 9 sec and
291
- * Normal Latency events are sent every 18 sec.
292
- */
293
- export const BE_PROFILE = "BEST_EFFORT";
294
-
295
- /**
296
- * An interface representing Collector Web responses.
297
- */
298
- export interface ICollectorResult {
299
- /**
300
- * Number of events accepted.
301
- */
302
- acc?: number;
303
- /**
304
- * Number of events rejected.
305
- */
306
- rej?: number;
307
- /**
308
- * Web Result.
309
- */
310
- webResult?: ICollectorWebResult;
311
- }
312
-
313
- /**
314
- * An interface representing Collector Web responses.
315
- */
316
- export interface ICollectorWebResult {
317
- /**
318
- * MSFPC cookie.
319
- */
320
- msfpc?: string;
321
- /**
322
- * Authentication error.
323
- */
324
- authError?: string;
325
- /**
326
- * Auth Login URL.
327
- */
328
- authLoginUrl?: string;
329
- }
330
-
331
- /**
332
- * Post channel interface
333
- */
334
- export interface IPostChannel extends ITelemetryPlugin {
335
- /**
336
- * Diagnostic logger
337
- */
338
- diagLog: (itemCtx?: IProcessTelemetryContext) => IDiagnosticLogger;
339
-
340
- /**
341
- * Notification manager
342
- */
343
- _notificationManager: NotificationManager | undefined;
344
-
345
- /**
346
- * Override for setTimeout
347
- */
348
- _setTimeoutOverride?: (callback: (...args: any[]) => void, ms: number, ...args: any[]) => any;
349
-
350
- /**
351
- * Backs off transmission. This exponentially increases all the timers.
352
- */
353
- _backOffTransmission(): void;
354
-
355
- /**
356
- * Clears back off for transmission.
357
- */
358
- _clearBackOff(): void;
359
-
360
- /**
361
- * Add handler to be executed with request response text.
362
- */
363
- addResponseHandler(responseHandler: (responseText: string) => void): void;
364
- }
365
-
366
- /**
367
- * This is an internal notification reason used by the HttpManager to report the reason for notification events
368
- * it contains general events as well as specific sections which encompass other enum values such as
369
- * SendRequestReason, EventsDiscardedReason and general HttpStatus values.
370
- */
371
- export declare const enum EventBatchNotificationReason {
372
- /**
373
- * Unable to send the batch as the outbound connection channel is paused
374
- */
375
- Paused = 1,
376
-
377
- /**
378
- * The events failed to send or retry, so requeue them
379
- */
380
- RequeueEvents = 100,
381
-
382
- /**
383
- * The Batch was successfully sent and a response received, equivalent to the HttpStatusCode of 200
384
- */
385
- Complete = 200,
386
-
387
- // Event Send Notifications (Mostly matched with SendRequestReason)
388
- /**
389
- * No specific reason was specified or normal event schedule / timer
390
- */
391
- SendingUndefined = 1000,
392
-
393
- /**
394
- * Events are being sent based on the normal event schedule / timer.
395
- */
396
- SendingNormalSchedule = 1001,
397
- /**
398
- * A manual flush request was received
399
- */
400
- SendingManualFlush = 1001,
401
-
402
- /**
403
- * Unload event is being processed
404
- */
405
- SendingUnload = 1002,
406
- /**
407
- * The event(s) being sent are sync events
408
- */
409
- SendingSyncEvent = 1003,
410
- /**
411
- * The Channel was resumed
412
- */
413
- SendingResumed = 1004,
414
- /**
415
- * The event(s) being sent as a retry
416
- */
417
- SendingRetry = 1005,
418
- /**
419
- * Maximum batch size would be exceeded
420
- */
421
- SendingMaxBatchSize = 1010,
422
- /**
423
- * The Maximum number of events have already been queued
424
- */
425
- SendingMaxQueuedEvents = 1020,
426
-
427
- /**
428
- * The final value for a Sending notification
429
- */
430
- SendingEventMax = 1999,
431
-
432
- // Events Dropped - Failures
433
- EventsDropped = 8000, // EventsDiscardedReason.Unknown
434
- NonRetryableStatus = 8001, // EventsDiscardedReason.NonRetryableStatus
435
- InvalidEvent = 8002, // EventsDiscardedReason.InvalidEvent
436
- SizeLimitExceeded = 8003, // EventsDiscardedReason.SizeLimitExceeded
437
- KillSwitch = 8004, // EventsDiscardedReason.KillSwitch,
438
- QueueFull = 8005, // EventsDiscardedReason.QueueFull
439
- EventsDroppedMax = 8999,
440
-
441
- /**
442
- * Represents the range Http Status codes 000-999 as 9000-9999
443
- */
444
- ResponseFailure = 9000,
445
-
446
- /**
447
- * Represents the range Http Status codes 200-299
448
- */
449
- PartialSuccess = 9200,
450
-
451
- /**
452
- * Represents the range Http Status codes 300-399
453
- */
454
- ClientConfigFailure = 9300,
455
-
456
- /**
457
- * Represents the range Http Status codes 400-499
458
- */
459
- ClientFailure = 9400,
460
-
461
- /**
462
- * Represents the range Http Status codes 500-599
463
- */
464
- ServerFailure = 9500,
465
-
466
- ResponseFailureMax = 9999
467
- }
1
+ /*
2
+ * 1DS JS SDK Post Channel, 4.0.0
3
+ * Copyright (c) Microsoft and contributors. All rights reserved.
4
+ *
5
+ * Javascript Telemetry SDKs <TelReachSDK@microsoft.com>
6
+ * https://1dsdocs.azurewebsites.net/sdk.html
7
+ *
8
+ * ---------------------------------------------------------------------------
9
+ * This is a single combined (rollup) declaration file for the package,
10
+ * if you require a namespace wrapped version it is also available.
11
+ * - Namespaced version: types/1ds-post-js.namespaced.d.ts
12
+ * ---------------------------------------------------------------------------
13
+ */
14
+
15
+ import { BaseTelemetryPlugin } from '@microsoft/1ds-core-js';
16
+ import { IAppInsightsCore } from '@microsoft/1ds-core-js';
17
+ import { IChannelControls } from '@microsoft/1ds-core-js';
18
+ import { IDiagnosticLogger } from '@microsoft/1ds-core-js';
19
+ import { IExtendedConfiguration } from '@microsoft/1ds-core-js';
20
+ import { IPlugin } from '@microsoft/1ds-core-js';
21
+ import { IProcessTelemetryContext } from '@microsoft/1ds-core-js';
22
+ import { IPromise } from '@nevware21/ts-async';
23
+ import { ITelemetryItem } from '@microsoft/1ds-core-js';
24
+ import { ITelemetryPlugin } from '@microsoft/1ds-core-js';
25
+ import { IUnloadHook } from '@microsoft/1ds-core-js';
26
+ import { IValueSanitizer } from '@microsoft/1ds-core-js';
27
+ import { SendRequestReason } from '@microsoft/1ds-core-js';
28
+
29
+ /**
30
+ * Best Effort. RealTime Latency events are sent every 9 sec and
31
+ * Normal Latency events are sent every 18 sec.
32
+ */
33
+ export declare const BE_PROFILE = "BEST_EFFORT";
34
+
35
+ /**
36
+ * The IChannelConfiguration interface holds the configuration details passed to Post module.
37
+ */
38
+ export declare interface IChannelConfiguration {
39
+ /**
40
+ * [Optional] The number of events that can be kept in memory before the SDK starts to drop events. By default, this is 10,000.
41
+ */
42
+ eventsLimitInMem?: number;
43
+ /**
44
+ * [Optional] Sets the maximum number of immediate latency events that will be cached in memory before the SDK starts to drop other
45
+ * immediate events only, does not drop normal and real time latency events as immediate events have their own internal queue. Under
46
+ * normal situations immediate events are scheduled to be sent in the next Javascript execution cycle, so the typically number of
47
+ * immediate events is small (~1), the only time more than one event may be present is when the channel is paused or immediate send
48
+ * is disabled (via manual transmit profile). By default max number of events is 500 and the default transmit time is 0ms.
49
+ */
50
+ immediateEventLimit?: number;
51
+ /**
52
+ * [Optional] If defined, when the number of queued events reaches or exceeded this limit this will cause the queue to be immediately
53
+ * flushed rather than waiting for the normal timers. Defaults to undefined.
54
+ */
55
+ autoFlushEventsLimit?: number;
56
+ /**
57
+ * [Optional] If defined allows you to disable the auto batch (iKey set of requests) flushing logic. This is in addition to the
58
+ * default transmission profile timers, autoFlushEventsLimit and eventsLimitInMem config values.
59
+ */
60
+ disableAutoBatchFlushLimit?: boolean;
61
+ /**
62
+ * [Optional] The HTTP override that should be used to send requests, as an IXHROverride object.
63
+ * By default during the unload of a page or if the event specifies that it wants to use sendBeacon() or sync fetch (with keep-alive),
64
+ * this override will NOT be called. You can now change this behavior by enabling the 'alwaysUseXhrOverride' configuration value.
65
+ * The payload data (first argument) now also includes any configured 'timeout' (defaults to undefined) and whether you should avoid
66
+ * creating any synchronous XHR requests 'disableXhrSync' (defaults to false/undefined)
67
+ */
68
+ httpXHROverride?: IXHROverride;
69
+ /**
70
+ * Override for Instrumentation key
71
+ */
72
+ overrideInstrumentationKey?: string;
73
+ /**
74
+ * Override for Endpoint where telemetry data is sent
75
+ */
76
+ overrideEndpointUrl?: string;
77
+ /**
78
+ * The master off switch. Do not send any data if set to TRUE
79
+ */
80
+ disableTelemetry?: boolean;
81
+ /**
82
+ * MC1 and MS0 cookies will not be returned from Collector endpoint.
83
+ */
84
+ ignoreMc1Ms0CookieProcessing?: boolean;
85
+ /**
86
+ * Override for setTimeout
87
+ */
88
+ setTimeoutOverride?: typeof setTimeout;
89
+ /**
90
+ * Override for clearTimeout
91
+ */
92
+ clearTimeoutOverride?: typeof clearTimeout;
93
+ /**
94
+ * [Optional] POST channel preprocessing function. Can be used to gzip the payload before transmission and to set the appropriate
95
+ * Content-Encoding header. The preprocessor is explicitly not called during teardown when using the sendBeacon() API.
96
+ */
97
+ payloadPreprocessor?: PayloadPreprocessorFunction;
98
+ /**
99
+ * [Optional] POST channel listener function, used for enabling logging or reporting (RemoteDDVChannel) of the payload that is being sent.
100
+ */
101
+ payloadListener?: PayloadListenerFunction;
102
+ /**
103
+ * [Optional] By default additional timing metrics details are added to each event after they are sent to allow you to review how long it took
104
+ * to create serialized request. As not all implementations require this level of detail and it's now possible to get the same metrics via
105
+ * the IPerfManager and IPerfEvent we are enabling these details to be disabled. Default value is false to retain the previous behavior,
106
+ * if you are not using these metrics and performance is a concern then it is recommended to set this value to true.
107
+ */
108
+ disableEventTimings?: boolean;
109
+ /**
110
+ * [Optional] The value sanitizer to use while constructing the envelope.
111
+ */
112
+ valueSanitizer?: IValueSanitizer;
113
+ /**
114
+ * [Optional] During serialization, when an object is identified, should the object be serialized by JSON.stringify(theObject); (when true) otherwise by theObject.toString().
115
+ * Defaults to false
116
+ */
117
+ stringifyObjects?: boolean;
118
+ /**
119
+ * [Optional] Enables support for objects with compound keys which indirectly represent an object where the "key" of the object contains a "." as part of it's name.
120
+ * @example
121
+ * ```typescript
122
+ * event: { "somedata.embeddedvalue": 123 }
123
+ * ```
124
+ */
125
+ enableCompoundKey?: boolean;
126
+ /**
127
+ * [Optional] Switch to disable the v8 optimizeObject() calls used to provide better serialization performance. Defaults to false.
128
+ */
129
+ disableOptimizeObj?: boolean;
130
+ /**
131
+ * [Optional] By default a "Cache-Control" header will be added to the outbound payloads with the value "no-cache, no-store", this is to
132
+ * avoid instances where Chrome can "Stall" requests which use the same outbound URL.
133
+ */
134
+ /**
135
+ * [Optional] Either an array or single value identifying the requested TransportType type that should be used.
136
+ * This is used during initialization to identify the requested send transport, it will be ignored if a httpXHROverride is provided.
137
+ */
138
+ transports?: number | number[];
139
+ /**
140
+ * [Optional] Either an array or single value identifying the requested TransportType type(s) that should be used during unload or events
141
+ * marked as sendBeacon. This is used during initialization to identify the requested send transport, it will be ignored if a httpXHROverride
142
+ * is provided and alwaysUseXhrOverride is true.
143
+ */
144
+ unloadTransports?: number | number[];
145
+ /**
146
+ * [Optional] A flag to enable or disable the usage of the sendBeacon() API (if available). If running on ReactNative this defaults
147
+ * to `false` for all other cases it defaults to `true`.
148
+ */
149
+ useSendBeacon?: boolean;
150
+ /**
151
+ * [Optional] A flag to disable the usage of the [fetch with keep-alive](https://javascript.info/fetch-api#keepalive) support.
152
+ */
153
+ disableFetchKeepAlive?: boolean;
154
+ /**
155
+ * [Optional] Avoid adding request headers to the outgoing request that would cause a pre-flight (OPTIONS) request to be sent for each request.
156
+ * This currently defaults to true but will be changed once the collector handles additional settings to allow the browser to better cache any
157
+ * previous OPTIONS response, at which point some of the current dynamic values sent on the query string will be moved to a header.
158
+ */
159
+ avoidOptions?: boolean;
160
+ /**
161
+ * [Optional] Specify a timeout (in ms) to apply to requests when sending requests using XHR, XDR or fetch requests. Defaults to undefined
162
+ * and therefore the runtime defaults (normally zero for browser environments)
163
+ */
164
+ xhrTimeout?: number;
165
+ /**
166
+ * [Optional] When using Xhr for sending requests disable sending as synchronous during unload or synchronous flush.
167
+ * You should enable this feature for IE (when there is no sendBeacon() or fetch (with keep-alive)) and you have clients
168
+ * that end up blocking the UI during page unloading. This will cause ALL XHR requests to be sent asynchronously which
169
+ * during page unload may result in the lose of telemetry.
170
+ */
171
+ disableXhrSync?: boolean;
172
+ /**
173
+ * [Optional] By default during unload (or when you specify to use sendBeacon() or sync fetch (with keep-alive) for an event) the SDK
174
+ * ignores any provided httpXhrOverride and attempts to use sendBeacon() or fetch(with keep-alive) when they are available.
175
+ * When this configuration option is true any provided httpXhrOverride will always be used, so any provided httpXhrOverride will
176
+ * also need to "handle" the synchronous unload scenario.
177
+ */
178
+ alwaysUseXhrOverride?: boolean;
179
+ /**
180
+ * [Optional] Identifies the number of times any single event will be retried if it receives a failed (retirable) response, this
181
+ * causes the event to be internally "requeued" and resent in the next batch. As each normal batched send request is retried at
182
+ * least once before starting to increase the internal backoff send interval, normally batched events will generally be attempted
183
+ * the next nearest even number of times. This means that the total number of actual send attempts will almost always be even
184
+ * (setting to 5 will cause 6 requests), unless using manual synchronous flushing (calling flush(false)) which is not subject to
185
+ * request level retry attempts.
186
+ * Defaults to 6 times.
187
+ */
188
+ maxEventRetryAttempts?: number;
189
+ /**
190
+ * [Optional] Identifies the number of times any single event will be retried if it receives a failed (retriable) response as part
191
+ * of processing / flushing events once a page unload state has been detected, this causes the event to be internally "requeued"
192
+ * and resent in the next batch, which during page unload. Unlike the normal batching process, send requests are never retried,
193
+ * so the value listed here is always the maximum number of attempts for any single event.
194
+ * Defaults to 2 times.
195
+ * Notes:
196
+ * The SDK by default will use the sendBeacon() API if it exists which is treated as a fire and forget successful response, so for
197
+ * environments that support or supply this API the events won't be retried (because they will be deeded to be successfully sent).
198
+ * When an environment (IE) doesn't support sendBeacon(), this will cause multiple synchronous (by default) XMLHttpRequests to be sent,
199
+ * which will block the UI until a response is received. You can disable ALL synchronous XHR requests by setting the 'disableXhrSync'
200
+ * configuration setting and/or changing this value to 0 or 1.
201
+ */
202
+ maxUnloadEventRetryAttempts?: number;
203
+ /**
204
+ * [Optional] flag to indicate whether the sendBeacon and fetch (with keep-alive flag) should add the "NoResponseBody" query string
205
+ * value to indicate that the server should return a 204 for successful requests. Defaults to true
206
+ */
207
+ addNoResponse?: boolean;
208
+ }
209
+
210
+ /** IPayloadData describes interface of payload sent via POST channel */
211
+ export declare interface IPayloadData {
212
+ urlString: string;
213
+ data: Uint8Array | string;
214
+ headers?: {
215
+ [name: string]: string;
216
+ };
217
+ timeout?: number;
218
+ disableXhrSync?: boolean;
219
+ disableFetchKeepAlive?: boolean;
220
+ }
221
+
222
+ /**
223
+ * Post channel interface
224
+ */
225
+ export declare interface IPostChannel extends ITelemetryPlugin {
226
+ /**
227
+ * Diagnostic logger
228
+ */
229
+ diagLog: (itemCtx?: IProcessTelemetryContext) => IDiagnosticLogger;
230
+ /**
231
+ * Override for setTimeout
232
+ */
233
+ _setTimeoutOverride?: (callback: (...args: any[]) => void, ms: number, ...args: any[]) => any;
234
+ /**
235
+ * Backs off transmission. This exponentially increases all the timers.
236
+ */
237
+ _backOffTransmission(): void;
238
+ /**
239
+ * Clears back off for transmission.
240
+ */
241
+ _clearBackOff(): void;
242
+ /**
243
+ * Add handler to be executed with request response text.
244
+ */
245
+ addResponseHandler(responseHandler: (responseText: string) => void): IUnloadHook;
246
+ }
247
+
248
+ /**
249
+ * The IXHROverride interface overrides the way HTTP requests are sent.
250
+ */
251
+ export declare interface IXHROverride {
252
+ /**
253
+ * This method sends data to the specified URI using a POST request. If sync is true,
254
+ * then the request is sent synchronously. The <i>oncomplete</i> function should always be called after the request is
255
+ * completed (either successfully or timed out or failed due to errors).
256
+ */
257
+ sendPOST: SendPOSTFunction;
258
+ }
259
+
260
+ /**
261
+ * Near Real Time profile. RealTime Latency events are sent every 3 sec and
262
+ * Normal Latency events are sent every 6 sec.
263
+ */
264
+ export declare const NRT_PROFILE = "NEAR_REAL_TIME";
265
+
266
+ /**
267
+ * Defines the function signature of a payload listener, which is called after the payload has been sent to the server. The listener is passed
268
+ * both the initial payload object and any altered (modified) payload from a preprocessor so it can determine what payload it may want to log or send.
269
+ * Used by the Remove DDV extension to listen to server send events.
270
+ * @param orgPayload - The initially constructed payload object
271
+ * @param sendPayload - The alternative (possibly modified by a preprocessor) payload
272
+ * @param isSync - A boolean flag indicating whether this request was initiated as part of a sync response (unload / flush request), this is for informative only.
273
+ * @param isBeaconSend - A boolean flag indicating whether the payload was sent using the navigator.sendBeacon() API.
274
+ */
275
+ export declare type PayloadListenerFunction = (orgPayload: IPayloadData, sendPayload?: IPayloadData, isSync?: boolean, isBeaconSend?: boolean) => void;
276
+
277
+ /**
278
+ * Defines the function signature for the Payload Preprocessor.
279
+ * @param payload - The Initial constructed payload that if not modified should be passed onto the callback function.
280
+ * @param callback - The preprocessor MUST call the callback function to ensure that the events are sent to the server, failing to call WILL result in dropped events.
281
+ * The modifiedBuffer argument can be either the original payload or may be modified by performing GZipping of the payload and adding the content header.
282
+ * @param isSync - A boolean flag indicating whether this request was initiated as part of a sync response (unload / flush request), this is for informative only.
283
+ * e.g the preprocessor may wish to not perform any GZip operations if the request was a sync request which is normally called as part of an unload request.
284
+ */
285
+ export declare type PayloadPreprocessorFunction = (payload: IPayloadData, callback: (modifiedBuffer: IPayloadData) => void, isSync?: boolean) => void;
286
+
287
+ /**
288
+ * Class that manages adding events to inbound queues and batching of events
289
+ * into requests.
290
+ */
291
+ export declare class PostChannel extends BaseTelemetryPlugin implements IChannelControls, IPostChannel {
292
+ identifier: string;
293
+ priority: number;
294
+ version: string;
295
+ constructor();
296
+ /**
297
+ * Start the queue manager to batch and send events via post.
298
+ * @param config - The core configuration.
299
+ */
300
+ initialize(coreConfig: IExtendedConfiguration, core: IAppInsightsCore, extensions: IPlugin[]): void;
301
+ /**
302
+ * Add an event to the appropriate inbound queue based on its latency.
303
+ * @param ev - The event to be added to the queue.
304
+ * @param itemCtx - This is the context for the current request, ITelemetryPlugin instances
305
+ * can optionally use this to access the current core instance or define / pass additional information
306
+ * to later plugins (vs appending items to the telemetry item)
307
+ */
308
+ processTelemetry(ev: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
309
+ /**
310
+ * Sets the event queue limits at runtime (after initialization), if the number of queued events is greater than the
311
+ * eventLimit or autoFlushLimit then a flush() operation will be scheduled.
312
+ * @param eventLimit The number of events that can be kept in memory before the SDK starts to drop events. If the value passed is less than or
313
+ * equal to zero the value will be reset to the default (10,000).
314
+ * @param autoFlushLimit When defined, once this number of events has been queued the system perform a flush() to send the queued events
315
+ * without waiting for the normal schedule timers. Passing undefined, null or a value less than or equal to zero will disable the auto flush.
316
+ */
317
+ setEventQueueLimits(eventLimit: number, autoFlushLimit?: number): void;
318
+ /**
319
+ * Pause the transmission of any requests
320
+ */
321
+ pause(): void;
322
+ /**
323
+ * Resumes transmission of events.
324
+ */
325
+ resume(): void;
326
+ /**
327
+ * Add handler to be executed with request response text.
328
+ */
329
+ addResponseHandler(responseHanlder: (responseText: string) => void): IUnloadHook;
330
+ /**
331
+ * Flush to send data immediately; channel should default to sending data asynchronously. If executing asynchronously (the default) and
332
+ * you DO NOT pass a callback function then a [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html)
333
+ * will be returned which will resolve once the flush is complete. The actual implementation of the `IPromise`
334
+ * will be a native Promise (if supported) or the default as supplied by [ts-async library](https://github.com/nevware21/ts-async)
335
+ * @param async - send data asynchronously when true
336
+ * @param callBack - if specified, notify caller when send is complete, the channel should return true to indicate to the caller that it will be called.
337
+ * If the caller doesn't return true the caller should assume that it may never be called.
338
+ * @param sendReason - specify the reason that you are calling "flush" defaults to ManualFlush (1) if not specified
339
+ * @returns - If a callback is provided `true` to indicate that callback will be called after the flush is complete otherwise the caller
340
+ * should assume that any provided callback will never be called, Nothing or if occurring asynchronously a
341
+ * [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html) which will be resolved once the unload is complete,
342
+ * the [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html) will only be returned when no callback is provided
343
+ * and async is true.
344
+ */
345
+ flush(async?: boolean, callBack?: (flushComplete?: boolean) => void, sendReason?: SendRequestReason): boolean | void | IPromise<boolean>;
346
+ /**
347
+ * Set AuthMsaDeviceTicket header
348
+ * @param ticket - Ticket value.
349
+ */
350
+ setMsaAuthTicket(ticket: string): void;
351
+ /**
352
+ * Check if there are any events waiting to be scheduled for sending.
353
+ * @returns True if there are events, false otherwise.
354
+ */
355
+ hasEvents(): boolean;
356
+ /**
357
+ * Load custom transmission profiles. Each profile should have timers for real time, and normal and can
358
+ * optionally specify the immediate latency time in ms (defaults to 0 when not defined). Each profile should
359
+ * make sure that a each normal latency timer is a multiple of the real-time latency and the immediate
360
+ * is smaller than the real-time.
361
+ * Setting the timer value to -1 means that the events for that latency will not be scheduled to be sent.
362
+ * Note that once a latency has been set to not send, all latencies below it will also not be sent. The
363
+ * timers should be in the form of [normal, high, [immediate]].
364
+ * e.g Custom:
365
+ * [10,5] - Sets the normal latency time to 10 seconds and real-time to 5 seconds; Immediate will default to 0ms
366
+ * [10,5,1] - Sets the normal latency time to 10 seconds and real-time to 5 seconds; Immediate will default to 1ms
367
+ * [10,5,0] - Sets the normal latency time to 10 seconds and real-time to 5 seconds; Immediate will default to 0ms
368
+ * [10,5,-1] - Sets the normal latency time to 10 seconds and real-time to 5 seconds; Immediate events will not be
369
+ * scheduled on their own and but they will be included with real-time or normal events as the first events in a batch.
370
+ * This also removes any previously loaded custom profiles.
371
+ * @param profiles - A dictionary containing the transmit profiles.
372
+ */
373
+ _loadTransmitProfiles(profiles: {
374
+ [profileName: string]: number[];
375
+ }): void;
376
+ /**
377
+ * Set the transmit profile to be used. This will change the transmission timers
378
+ * based on the transmit profile.
379
+ * @param profileName - The name of the transmit profile to be used.
380
+ */
381
+ _setTransmitProfile(profileName: string): void;
382
+ /**
383
+ * Backs off transmission. This exponentially increases all the timers.
384
+ */
385
+ _backOffTransmission(): void;
386
+ /**
387
+ * Clears backoff for transmission.
388
+ */
389
+ _clearBackOff(): void;
390
+ }
391
+
392
+ /**
393
+ * Real Time profile (default profile). RealTime Latency events are sent every 1 sec and
394
+ * Normal Latency events are sent every 2 sec.
395
+ */
396
+ export declare const RT_PROFILE = "REAL_TIME";
397
+
398
+ /**
399
+ * SendPOSTFunction type defines how an HTTP POST request is sent to an ingestion server
400
+ * @param payload - The payload object that should be sent, contains the url, bytes/string and headers for the request
401
+ * @param oncomplete - The function to call once the request has completed whether a success, failure or timeout
402
+ * @param sync - A boolean flag indicating whether the request should be sent as a synchronous request.
403
+ */
404
+ export declare type SendPOSTFunction = (payload: IPayloadData, oncomplete: (status: number, headers: {
405
+ [headerName: string]: string;
406
+ }, response?: string) => void, sync?: boolean) => void;
407
+
408
+ export { }