@microsoft/1ds-post-js 4.0.6 → 4.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/bundle/es5/{ms.post-4.0.6.gbl.js → ms.post-4.0.7.gbl.js} +83 -100
  2. package/bundle/es5/ms.post-4.0.7.gbl.js.map +1 -0
  3. package/bundle/es5/ms.post-4.0.7.gbl.min.js +7 -0
  4. package/bundle/es5/ms.post-4.0.7.gbl.min.js.map +1 -0
  5. package/bundle/es5/ms.post-4.0.7.integrity.json +46 -0
  6. package/bundle/es5/{ms.post-4.0.6.js → ms.post-4.0.7.js} +83 -100
  7. package/bundle/es5/ms.post-4.0.7.js.map +1 -0
  8. package/bundle/es5/ms.post-4.0.7.min.js +7 -0
  9. package/bundle/es5/ms.post-4.0.7.min.js.map +1 -0
  10. package/bundle/es5/ms.post.gbl.js +82 -99
  11. package/bundle/es5/ms.post.gbl.js.map +1 -1
  12. package/bundle/es5/ms.post.gbl.min.js +2 -2
  13. package/bundle/es5/ms.post.gbl.min.js.map +1 -1
  14. package/bundle/es5/ms.post.integrity.json +17 -17
  15. package/bundle/es5/ms.post.js +82 -99
  16. package/bundle/es5/ms.post.js.map +1 -1
  17. package/bundle/es5/ms.post.min.js +2 -2
  18. package/bundle/es5/ms.post.min.js.map +1 -1
  19. package/dist/es5/ms.post.js +80 -97
  20. package/dist/es5/ms.post.js.map +1 -1
  21. package/dist/es5/ms.post.min.js +2 -2
  22. package/dist/es5/ms.post.min.js.map +1 -1
  23. package/dist-es5/BatchNotificationActions.js +1 -1
  24. package/dist-es5/ClockSkewManager.js +1 -1
  25. package/dist-es5/DataModels.js +1 -1
  26. package/dist-es5/EventBatch.js +1 -1
  27. package/dist-es5/HttpManager.js +1 -1
  28. package/dist-es5/Index.js +1 -1
  29. package/dist-es5/InternalConstants.js +1 -1
  30. package/dist-es5/KillSwitch.js +1 -1
  31. package/dist-es5/PostChannel.js +2 -2
  32. package/dist-es5/PostChannel.js.map +1 -1
  33. package/dist-es5/RetryPolicy.js +1 -1
  34. package/dist-es5/Serializer.js +1 -1
  35. package/dist-es5/TimeoutOverrideWrapper.js +1 -1
  36. package/dist-es5/__DynamicConstants.js +1 -1
  37. package/dist-es5/typings/XDomainRequest.js +1 -1
  38. package/package.json +66 -63
  39. package/types/1ds-post-js.d.ts +6 -2
  40. package/types/1ds-post-js.namespaced.d.ts +2247 -100
  41. package/bundle/es5/ms.post-4.0.6.gbl.js.map +0 -1
  42. package/bundle/es5/ms.post-4.0.6.gbl.min.js +0 -7
  43. package/bundle/es5/ms.post-4.0.6.gbl.min.js.map +0 -1
  44. package/bundle/es5/ms.post-4.0.6.integrity.json +0 -46
  45. package/bundle/es5/ms.post-4.0.6.js.map +0 -1
  46. package/bundle/es5/ms.post-4.0.6.min.js +0 -7
  47. package/bundle/es5/ms.post-4.0.6.min.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  /*
2
- * 1DS JS SDK Post Channel, 4.0.6
2
+ * 1DS JS SDK Post Channel, 4.0.7
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  *
5
5
  * Microsoft Application Insights Team
@@ -7,23 +7,104 @@
7
7
  */
8
8
 
9
9
  declare namespace oneDS {
10
- import { BaseTelemetryPlugin } from '@microsoft/1ds-core-js';
11
- import { IAppInsightsCore } from '@microsoft/1ds-core-js';
12
- import { IChannelControls } from '@microsoft/1ds-core-js';
13
- import { IDiagnosticLogger } from '@microsoft/1ds-core-js';
14
- import { IExtendedConfiguration } from '@microsoft/1ds-core-js';
15
- import { IPayloadData } from '@microsoft/1ds-core-js';
16
- import { IPlugin } from '@microsoft/1ds-core-js';
17
- import { IProcessTelemetryContext } from '@microsoft/1ds-core-js';
18
- import { IPromise } from '@nevware21/ts-async';
19
- import { ITelemetryItem } from '@microsoft/1ds-core-js';
20
- import { ITelemetryPlugin } from '@microsoft/1ds-core-js';
21
- import { IUnloadHook } from '@microsoft/1ds-core-js';
22
- import { IValueSanitizer } from '@microsoft/1ds-core-js';
23
- import { IXHROverride } from '@microsoft/1ds-core-js';
24
- import { OnCompleteCallback } from '@microsoft/1ds-core-js';
25
- import { SendPOSTFunction } from '@microsoft/1ds-core-js';
26
- import { SendRequestReason } from '@microsoft/1ds-core-js';
10
+ /**
11
+ * BaseTelemetryPlugin provides a basic implementation of the ITelemetryPlugin interface so that plugins
12
+ * can avoid implementation the same set of boiler plate code as well as provide a base
13
+ * implementation so that new default implementations can be added without breaking all plugins.
14
+ */
15
+ abstract class BaseTelemetryPlugin implements ITelemetryPlugin {
16
+ identifier: string;
17
+ version?: string;
18
+ /**
19
+ * Holds the core instance that was used during initialization
20
+ */
21
+ core: IAppInsightsCore;
22
+ priority: number;
23
+ /**
24
+ * Call back for telemetry processing before it it is sent
25
+ * @param env - This is the current event being reported
26
+ * @param itemCtx - This is the context for the current request, ITelemetryPlugin instances
27
+ * can optionally use this to access the current core instance or define / pass additional information
28
+ * to later plugins (vs appending items to the telemetry item)
29
+ */
30
+ processNext: (env: ITelemetryItem, itemCtx: IProcessTelemetryContext) => void;
31
+ /**
32
+ * Set next extension for telemetry processing
33
+ */
34
+ setNextPlugin: (next: ITelemetryPlugin | ITelemetryPluginChain) => void;
35
+ /**
36
+ * Returns the current diagnostic logger that can be used to log issues, if no logger is currently
37
+ * assigned a new default one will be created and returned.
38
+ */
39
+ diagLog: (itemCtx?: IProcessTelemetryContext) => IDiagnosticLogger;
40
+ /**
41
+ * Returns whether the plugin has been initialized
42
+ */
43
+ isInitialized: () => boolean;
44
+ /**
45
+ * Helper to return the current IProcessTelemetryContext, if the passed argument exists this just
46
+ * returns that value (helps with minification for callers), otherwise it will return the configured
47
+ * context or a temporary one.
48
+ * @param currentCtx - [Optional] The current execution context
49
+ */
50
+ protected _getTelCtx: (currentCtx?: IProcessTelemetryContext) => IProcessTelemetryContext;
51
+ /**
52
+ * Internal helper to allow setting of the internal initialized setting for inherited instances and unit testing
53
+ */
54
+ protected setInitialized: (isInitialized: boolean) => void;
55
+ /**
56
+ * Teardown / Unload hook to allow implementations to perform some additional unload operations before the BaseTelemetryPlugin
57
+ * finishes it's removal.
58
+ * @param unloadCtx - This is the context that should be used during unloading.
59
+ * @param unloadState - The details / state of the unload process, it holds details like whether it should be unloaded synchronously or asynchronously and the reason for the unload.
60
+ * @param asyncCallback - An optional callback that the plugin must call if it returns true to inform the caller that it has completed any async unload/teardown operations.
61
+ * @returns boolean - true if the plugin has or will call asyncCallback, this allows the plugin to perform any asynchronous operations.
62
+ */
63
+ protected _doTeardown?: (unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState, asyncCallback?: () => void) => void | boolean;
64
+ /**
65
+ * Extension hook to allow implementations to perform some additional update operations before the BaseTelemetryPlugin finishes it's removal
66
+ * @param updateCtx - This is the context that should be used during updating.
67
+ * @param updateState - The details / state of the update process, it holds details like the current and previous configuration.
68
+ * @param asyncCallback - An optional callback that the plugin must call if it returns true to inform the caller that it has completed any async update operations.
69
+ * @returns boolean - true if the plugin has or will call asyncCallback, this allows the plugin to perform any asynchronous operations.
70
+ */
71
+ protected _doUpdate?: (updateCtx?: IProcessTelemetryUpdateContext, updateState?: ITelemetryUpdateState, asyncCallback?: () => void) => void | boolean;
72
+ /**
73
+ * Exposes the underlying unload hook container instance for this extension to allow it to be passed down to any sub components of the class.
74
+ * This should NEVER be exposed or called publically as it's scope is for internal use by BaseTelemetryPlugin and any derived class (which is why
75
+ * it's scoped as protected)
76
+ */
77
+ protected readonly _unloadHooks: IUnloadHookContainer;
78
+ constructor();
79
+ initialize(config: IConfiguration, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?: ITelemetryPluginChain): void;
80
+ /**
81
+ * Tear down the plugin and remove any hooked value, the plugin should be removed so that it is no longer initialized and
82
+ * therefore could be re-initialized after being torn down. The plugin should ensure that once this has been called any further
83
+ * processTelemetry calls are ignored and it just calls the processNext() with the provided context.
84
+ * @param unloadCtx - This is the context that should be used during unloading.
85
+ * @param unloadState - The details / state of the unload process, it holds details like whether it should be unloaded synchronously or asynchronously and the reason for the unload.
86
+ * @returns boolean - true if the plugin has or will call processNext(), this for backward compatibility as previously teardown was synchronous and returned nothing.
87
+ */
88
+ teardown(unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState): void | boolean;
89
+ abstract processTelemetry(env: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
90
+ /**
91
+ * The the plugin should re-evaluate configuration and update any cached configuration settings.
92
+ * @param updateCtx - This is the context that should be used during updating.
93
+ * @param updateState - The details / state of the update process, it holds details like the current and previous configuration.
94
+ * @returns boolean - true if the plugin has or will call updateCtx.processNext(), this allows the plugin to perform any asynchronous operations.
95
+ */
96
+ update(updateCtx: IProcessTelemetryUpdateContext, updateState: ITelemetryUpdateState): void | boolean;
97
+ /**
98
+ * Add an unload handler that will be called when the SDK is being unloaded
99
+ * @param handler - the handler
100
+ */
101
+ protected _addUnloadCb(handler: UnloadHandler): void;
102
+ /**
103
+ * Add this hook so that it is automatically removed during unloading
104
+ * @param hooks - The single hook or an array of IInstrumentHook objects
105
+ */
106
+ protected _addHook(hooks: IUnloadHook | IUnloadHook[] | Iterator<IUnloadHook> | ILegacyUnloadHook | ILegacyUnloadHook[] | Iterator<ILegacyUnloadHook>): void;
107
+ }
27
108
 
28
109
  /**
29
110
  * Best Effort. RealTime Latency events are sent every 9 sec and
@@ -31,6 +112,372 @@ declare namespace oneDS {
31
112
  */
32
113
  const BE_PROFILE = "BEST_EFFORT";
33
114
 
115
+ const enum _eInternalMessageId {
116
+ BrowserDoesNotSupportLocalStorage = 0,
117
+ BrowserCannotReadLocalStorage = 1,
118
+ BrowserCannotReadSessionStorage = 2,
119
+ BrowserCannotWriteLocalStorage = 3,
120
+ BrowserCannotWriteSessionStorage = 4,
121
+ BrowserFailedRemovalFromLocalStorage = 5,
122
+ BrowserFailedRemovalFromSessionStorage = 6,
123
+ CannotSendEmptyTelemetry = 7,
124
+ ClientPerformanceMathError = 8,
125
+ ErrorParsingAISessionCookie = 9,
126
+ ErrorPVCalc = 10,
127
+ ExceptionWhileLoggingError = 11,
128
+ FailedAddingTelemetryToBuffer = 12,
129
+ FailedMonitorAjaxAbort = 13,
130
+ FailedMonitorAjaxDur = 14,
131
+ FailedMonitorAjaxOpen = 15,
132
+ FailedMonitorAjaxRSC = 16,
133
+ FailedMonitorAjaxSend = 17,
134
+ FailedMonitorAjaxGetCorrelationHeader = 18,
135
+ FailedToAddHandlerForOnBeforeUnload = 19,
136
+ FailedToSendQueuedTelemetry = 20,
137
+ FailedToReportDataLoss = 21,
138
+ FlushFailed = 22,
139
+ MessageLimitPerPVExceeded = 23,
140
+ MissingRequiredFieldSpecification = 24,
141
+ NavigationTimingNotSupported = 25,
142
+ OnError = 26,
143
+ SessionRenewalDateIsZero = 27,
144
+ SenderNotInitialized = 28,
145
+ StartTrackEventFailed = 29,
146
+ StopTrackEventFailed = 30,
147
+ StartTrackFailed = 31,
148
+ StopTrackFailed = 32,
149
+ TelemetrySampledAndNotSent = 33,
150
+ TrackEventFailed = 34,
151
+ TrackExceptionFailed = 35,
152
+ TrackMetricFailed = 36,
153
+ TrackPVFailed = 37,
154
+ TrackPVFailedCalc = 38,
155
+ TrackTraceFailed = 39,
156
+ TransmissionFailed = 40,
157
+ FailedToSetStorageBuffer = 41,
158
+ FailedToRestoreStorageBuffer = 42,
159
+ InvalidBackendResponse = 43,
160
+ FailedToFixDepricatedValues = 44,
161
+ InvalidDurationValue = 45,
162
+ TelemetryEnvelopeInvalid = 46,
163
+ CreateEnvelopeError = 47,
164
+ MaxUnloadHookExceeded = 48,
165
+ CannotSerializeObject = 48,
166
+ CannotSerializeObjectNonSerializable = 49,
167
+ CircularReferenceDetected = 50,
168
+ ClearAuthContextFailed = 51,
169
+ ExceptionTruncated = 52,
170
+ IllegalCharsInName = 53,
171
+ ItemNotInArray = 54,
172
+ MaxAjaxPerPVExceeded = 55,
173
+ MessageTruncated = 56,
174
+ NameTooLong = 57,
175
+ SampleRateOutOfRange = 58,
176
+ SetAuthContextFailed = 59,
177
+ SetAuthContextFailedAccountName = 60,
178
+ StringValueTooLong = 61,
179
+ StartCalledMoreThanOnce = 62,
180
+ StopCalledWithoutStart = 63,
181
+ TelemetryInitializerFailed = 64,
182
+ TrackArgumentsNotSpecified = 65,
183
+ UrlTooLong = 66,
184
+ SessionStorageBufferFull = 67,
185
+ CannotAccessCookie = 68,
186
+ IdTooLong = 69,
187
+ InvalidEvent = 70,
188
+ FailedMonitorAjaxSetRequestHeader = 71,
189
+ SendBrowserInfoOnUserInit = 72,
190
+ PluginException = 73,
191
+ NotificationException = 74,
192
+ SnippetScriptLoadFailure = 99,
193
+ InvalidInstrumentationKey = 100,
194
+ CannotParseAiBlobValue = 101,
195
+ InvalidContentBlob = 102,
196
+ TrackPageActionEventFailed = 103,
197
+ FailedAddingCustomDefinedRequestContext = 104,
198
+ InMemoryStorageBufferFull = 105,
199
+ InstrumentationKeyDeprecation = 106,
200
+ ConfigWatcherException = 107,
201
+ DynamicConfigException = 108,
202
+ DefaultThrottleMsgKey = 109,
203
+ CdnDeprecation = 110,
204
+ SdkLdrUpdate = 111
205
+ }
206
+
207
+ const enum eLoggingSeverity {
208
+ /**
209
+ * No Logging will be enabled
210
+ */
211
+ DISABLED = 0,
212
+ /**
213
+ * Error will be sent as internal telemetry
214
+ */
215
+ CRITICAL = 1,
216
+ /**
217
+ * Error will NOT be sent as internal telemetry, and will only be shown in browser console
218
+ */
219
+ WARNING = 2,
220
+ /**
221
+ * The Error will NOT be sent as an internal telemetry, and will only be shown in the browser
222
+ * console if the logging level allows it.
223
+ */
224
+ DEBUG = 3
225
+ }
226
+
227
+ /**
228
+ * A type that identifies an enum class generated from a constant enum.
229
+ * @group Enum
230
+ * @typeParam E - The constant enum type
231
+ *
232
+ * Returned from {@link createEnum}
233
+ */
234
+ type EnumCls<E = any> = {
235
+ readonly [key in keyof E extends string | number | symbol ? keyof E : never]: key extends string ? E[key] : key;
236
+ } & {
237
+ readonly [key in keyof E]: E[key];
238
+ };
239
+
240
+ type EnumValue<E = any> = EnumCls<E>;
241
+
242
+ const enum FeatureOptInMode {
243
+ /**
244
+ * not set, completely depends on cdn cfg
245
+ */
246
+ none = 1,
247
+ /**
248
+ * try to not apply config from cdn
249
+ */
250
+ disable = 2,
251
+ /**
252
+ * try to apply config from cdn
253
+ */
254
+ enable = 3
255
+ }
256
+
257
+ type FieldValueSanitizerFunc = (details: IFieldSanitizerDetails) => IEventProperty | null;
258
+
259
+ const enum FieldValueSanitizerType {
260
+ NotSet = 0,
261
+ String = 1,
262
+ Number = 2,
263
+ Boolean = 3,
264
+ Object = 4,
265
+ Array = 4096,
266
+ EventProperty = 8192
267
+ }
268
+
269
+ type FieldValueSanitizerTypes = string | number | boolean | object | string[] | number[] | boolean[] | IEventProperty;
270
+
271
+ /**
272
+ * This defines the handler function that is called via the finally when the promise is resolved or rejected
273
+ */
274
+ type FinallyPromiseHandler = (() => void) | undefined | null;
275
+
276
+ interface IAppInsightsCore<CfgType extends IConfiguration = IConfiguration> extends IPerfManagerProvider {
277
+ readonly config: CfgType;
278
+ /**
279
+ * The current logger instance for this instance.
280
+ */
281
+ readonly logger: IDiagnosticLogger;
282
+ /**
283
+ * An array of the installed plugins that provide a version
284
+ */
285
+ readonly pluginVersionStringArr: string[];
286
+ /**
287
+ * The formatted string of the installed plugins that contain a version number
288
+ */
289
+ readonly pluginVersionString: string;
290
+ /**
291
+ * Returns a value that indicates whether the instance has already been previously initialized.
292
+ */
293
+ isInitialized?: () => boolean;
294
+ initialize(config: CfgType, extensions: IPlugin[], logger?: IDiagnosticLogger, notificationManager?: INotificationManager): void;
295
+ getChannels(): IChannelControls[];
296
+ track(telemetryItem: ITelemetryItem): void;
297
+ /**
298
+ * Get the current notification manager
299
+ */
300
+ getNotifyMgr(): INotificationManager;
301
+ /**
302
+ * Get the current cookie manager for this instance
303
+ */
304
+ getCookieMgr(): ICookieMgr;
305
+ /**
306
+ * Set the current cookie manager for this instance
307
+ * @param cookieMgr - The manager, if set to null/undefined will cause the default to be created
308
+ */
309
+ setCookieMgr(cookieMgr: ICookieMgr): void;
310
+ /**
311
+ * Adds a notification listener. The SDK calls methods on the listener when an appropriate notification is raised.
312
+ * The added plugins must raise notifications. If the plugins do not implement the notifications, then no methods will be
313
+ * called.
314
+ * @param listener - An INotificationListener object.
315
+ */
316
+ addNotificationListener?(listener: INotificationListener): void;
317
+ /**
318
+ * Removes all instances of the listener.
319
+ * @param listener - INotificationListener to remove.
320
+ */
321
+ removeNotificationListener?(listener: INotificationListener): void;
322
+ /**
323
+ * Add a telemetry processor to decorate or drop telemetry events.
324
+ * @param telemetryInitializer - The Telemetry Initializer function
325
+ * @returns - A ITelemetryInitializerHandler to enable the initializer to be removed
326
+ */
327
+ addTelemetryInitializer(telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler;
328
+ pollInternalLogs?(eventName?: string): ITimerHandler;
329
+ stopPollingInternalLogs?(): void;
330
+ /**
331
+ * Return a new instance of the IProcessTelemetryContext for processing events
332
+ */
333
+ getProcessTelContext(): IProcessTelemetryContext;
334
+ /**
335
+ * Unload and Tear down the SDK and any initialized plugins, after calling this the SDK will be considered
336
+ * to be un-initialized and non-operational, re-initializing the SDK should only be attempted if the previous
337
+ * unload call return `true` stating that all plugins reported that they also unloaded, the recommended
338
+ * approach is to create a new instance and initialize that instance.
339
+ * This is due to possible unexpected side effects caused by plugins not supporting unload / teardown, unable
340
+ * to successfully remove any global references or they may just be completing the unload process asynchronously.
341
+ * If you pass isAsync as `true` (also the default) and DO NOT pass a callback function then an [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html)
342
+ * will be returned which will resolve once the unload is complete. The actual implementation of the `IPromise`
343
+ * will be a native Promise (if supported) or the default as supplied by [ts-async library](https://github.com/nevware21/ts-async)
344
+ * @param isAsync - Can the unload be performed asynchronously (default)
345
+ * @param unloadComplete - An optional callback that will be called once the unload has completed
346
+ * @param cbTimeout - An optional timeout to wait for any flush operations to complete before proceeding with the
347
+ * unload. Defaults to 5 seconds.
348
+ * @return Nothing or if occurring asynchronously a [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html)
349
+ * which will be resolved once the unload is complete, the [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html)
350
+ * will only be returned when no callback is provided and isAsync is true
351
+ */
352
+ unload(isAsync?: boolean, unloadComplete?: (unloadState: ITelemetryUnloadState) => void, cbTimeout?: number): void | IPromise<ITelemetryUnloadState>;
353
+ /**
354
+ * Find and return the (first) plugin with the specified identifier if present
355
+ * @param pluginIdentifier
356
+ */
357
+ getPlugin<T extends IPlugin = IPlugin>(pluginIdentifier: string): ILoadedPlugin<T>;
358
+ /**
359
+ * Add a new plugin to the installation
360
+ * @param plugin - The new plugin to add
361
+ * @param replaceExisting - should any existing plugin be replaced, default is false
362
+ * @param doAsync - Should the add be performed asynchronously
363
+ * @param addCb - [Optional] callback to call after the plugin has been added
364
+ */
365
+ addPlugin<T extends IPlugin = ITelemetryPlugin>(plugin: T, replaceExisting?: boolean, doAsync?: boolean, addCb?: (added?: boolean) => void): void;
366
+ /**
367
+ * Update the configuration used and broadcast the changes to all loaded plugins, this does NOT support updating, adding or removing
368
+ * any the plugins (extensions or channels). It will notify each plugin (if supported) that the configuration has changed but it will
369
+ * not remove or add any new plugins, you need to call addPlugin or getPlugin(identifier).remove();
370
+ * @param newConfig - The new configuration is apply
371
+ * @param mergeExisting - Should the new configuration merge with the existing or just replace it. Default is to merge.
372
+ */
373
+ updateCfg(newConfig: CfgType, mergeExisting?: boolean): void;
374
+ /**
375
+ * Returns the unique event namespace that should be used when registering events
376
+ */
377
+ evtNamespace(): string;
378
+ /**
379
+ * Add a handler that will be called when the SDK is being unloaded
380
+ * @param handler - the handler
381
+ */
382
+ addUnloadCb(handler: UnloadHandler): void;
383
+ /**
384
+ * Add this hook so that it is automatically removed during unloading
385
+ * @param hooks - The single hook or an array of IInstrumentHook objects
386
+ */
387
+ addUnloadHook(hooks: IUnloadHook | IUnloadHook[] | Iterator<IUnloadHook> | ILegacyUnloadHook | ILegacyUnloadHook[] | Iterator<ILegacyUnloadHook>): void;
388
+ /**
389
+ * Flush and send any batched / cached data immediately
390
+ * @param async - send data asynchronously when true (defaults to true)
391
+ * @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.
392
+ * If the caller doesn't return true the caller should assume that it may never be called.
393
+ * @param sendReason - specify the reason that you are calling "flush" defaults to ManualFlush (1) if not specified
394
+ * @param cbTimeout - An optional timeout to wait for any flush operations to complete before proceeding with the unload. Defaults to 5 seconds.
395
+ * @returns - true if the callback will be return after the flush is complete otherwise the caller should assume that any provided callback will never be called
396
+ */
397
+ flush(isAsync?: boolean, callBack?: (flushComplete?: boolean) => void, sendReason?: SendRequestReason, cbTimeout?: number): boolean | void;
398
+ /**
399
+ * Gets the current distributed trace context for this instance if available
400
+ * @param createNew - Optional flag to create a new instance if one doesn't currently exist, defaults to true
401
+ */
402
+ getTraceCtx(createNew?: boolean): IDistributedTraceContext | null;
403
+ /**
404
+ * Sets the current distributed trace context for this instance if available
405
+ */
406
+ setTraceCtx(newTraceCtx: IDistributedTraceContext | null | undefined): void;
407
+ /**
408
+ * Watches and tracks changes for accesses to the current config, and if the accessed config changes the
409
+ * handler will be recalled.
410
+ * @param handler
411
+ * @returns A watcher handler instance that can be used to remove itself when being unloaded
412
+ */
413
+ onCfgChange(handler: WatcherFunction<CfgType>): IUnloadHook;
414
+ /**
415
+ * Function used to identify the get w parameter used to identify status bit to some channels
416
+ */
417
+ getWParam: () => number;
418
+ }
419
+
420
+ interface IBaseProcessingContext {
421
+ /**
422
+ * The current core instance for the request
423
+ */
424
+ core: () => IAppInsightsCore;
425
+ /**
426
+ * THe current diagnostic logger for the request
427
+ */
428
+ diagLog: () => IDiagnosticLogger;
429
+ /**
430
+ * Gets the current core config instance
431
+ */
432
+ getCfg: () => IConfiguration;
433
+ /**
434
+ * Gets the named extension config
435
+ */
436
+ getExtCfg: <T>(identifier: string, defaultValue?: IConfigDefaults<T>) => T;
437
+ /**
438
+ * Gets the named config from either the named identifier extension or core config if neither exist then the
439
+ * default value is returned
440
+ * @param identifier - The named extension identifier
441
+ * @param field - The config field name
442
+ * @param defaultValue - The default value to return if no defined config exists
443
+ */
444
+ getConfig: (identifier: string, field: string, defaultValue?: number | string | boolean | string[] | RegExp[] | Function) => number | string | boolean | string[] | RegExp[] | Function;
445
+ /**
446
+ * Helper to allow plugins to check and possibly shortcut executing code only
447
+ * required if there is a nextPlugin
448
+ */
449
+ hasNext: () => boolean;
450
+ /**
451
+ * Returns the next configured plugin proxy
452
+ */
453
+ getNext: () => ITelemetryPluginChain;
454
+ /**
455
+ * Helper to set the next plugin proxy
456
+ */
457
+ setNext: (nextCtx: ITelemetryPluginChain) => void;
458
+ /**
459
+ * Synchronously iterate over the context chain running the callback for each plugin, once
460
+ * every plugin has been executed via the callback, any associated onComplete will be called.
461
+ * @param callback - The function call for each plugin in the context chain
462
+ */
463
+ iterate: <T extends ITelemetryPlugin = ITelemetryPlugin>(callback: (plugin: T) => void) => void;
464
+ /**
465
+ * Set the function to call when the current chain has executed all processNext or unloadNext items.
466
+ * @param onComplete - The onComplete to call
467
+ * @param that - The "this" value to use for the onComplete call, if not provided or undefined defaults to the current context
468
+ * @param args - Any additional arguments to pass to the onComplete function
469
+ */
470
+ onComplete: (onComplete: () => void, that?: any, ...args: any[]) => void;
471
+ /**
472
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
473
+ * @param plugins - The execution order to process the plugins, if null or not supplied
474
+ * then the current execution order will be copied.
475
+ * @param startAt - The plugin to start processing from, if missing from the execution
476
+ * order then the next plugin will be NOT set.
477
+ */
478
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IBaseProcessingContext;
479
+ }
480
+
34
481
  /**
35
482
  * The IChannelConfiguration interface holds the configuration details passed to Post module.
36
483
  */
@@ -206,123 +653,1703 @@ declare namespace oneDS {
206
653
  addNoResponse?: boolean;
207
654
  }
208
655
 
209
-
210
656
  /**
211
- * Post channel interface
657
+ * Provides data transmission capabilities
212
658
  */
213
- interface IPostChannel extends ITelemetryPlugin {
214
- /**
215
- * Diagnostic logger
216
- */
217
- diagLog: (itemCtx?: IProcessTelemetryContext) => IDiagnosticLogger;
659
+ interface IChannelControls extends ITelemetryPlugin {
218
660
  /**
219
- * Override for setTimeout
661
+ * Pause sending data
220
662
  */
221
- _setTimeoutOverride?: (callback: (...args: any[]) => void, ms: number, ...args: any[]) => any;
663
+ pause?(): void;
222
664
  /**
223
- * Backs off transmission. This exponentially increases all the timers.
665
+ * Resume sending data
224
666
  */
225
- _backOffTransmission(): void;
667
+ resume?(): void;
226
668
  /**
227
- * Clears back off for transmission.
669
+ * Tear down the plugin and remove any hooked value, the plugin should be removed so that it is no longer initialized and
670
+ * therefore could be re-initialized after being torn down. The plugin should ensure that once this has been called any further
671
+ * processTelemetry calls are ignored and it just calls the processNext() with the provided context.
672
+ * @param unloadCtx - This is the context that should be used during unloading.
673
+ * @param unloadState - The details / state of the unload process, it holds details like whether it should be unloaded synchronously or asynchronously and the reason for the unload.
674
+ * @returns boolean - true if the plugin has or will call processNext(), this for backward compatibility as previously teardown was synchronous and returned nothing.
228
675
  */
229
- _clearBackOff(): void;
676
+ teardown?: (unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState) => void | boolean;
230
677
  /**
231
- * Add handler to be executed with request response text.
678
+ * Flush to send data immediately; channel should default to sending data asynchronously. If executing asynchronously and
679
+ * you DO NOT pass a callback function then a [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html)
680
+ * will be returned which will resolve once the flush is complete. The actual implementation of the `IPromise`
681
+ * will be a native Promise (if supported) or the default as supplied by [ts-async library](https://github.com/nevware21/ts-async)
682
+ * @param async - send data asynchronously when true
683
+ * @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.
684
+ * If the caller doesn't return true the caller should assume that it may never be called.
685
+ * @param sendReason - specify the reason that you are calling "flush" defaults to ManualFlush (1) if not specified
686
+ * @returns - If a callback is provided `true` to indicate that callback will be called after the flush is complete otherwise the caller
687
+ * should assume that any provided callback will never be called, Nothing or if occurring asynchronously a
688
+ * [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html) which will be resolved once the unload is complete,
689
+ * the [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html) will only be returned when no callback is provided
690
+ * and async is true.
232
691
  */
233
- addResponseHandler(responseHandler: (responseText: string) => void): IUnloadHook;
692
+ flush?(async: boolean, callBack?: (flushComplete?: boolean) => void, sendReason?: SendRequestReason): boolean | void | IPromise<boolean>;
234
693
  }
235
694
 
236
-
237
695
  /**
238
- * Near Real Time profile. RealTime Latency events are sent every 3 sec and
239
- * Normal Latency events are sent every 6 sec.
696
+ * The type to identify whether the default value should be applied in preference to the provided value.
240
697
  */
241
- const NRT_PROFILE = "NEAR_REAL_TIME";
698
+ type IConfigCheckFn<V> = (value: V) => boolean;
242
699
 
243
-
244
700
  /**
245
- * Defines the function signature of a payload listener, which is called after the payload has been sent to the server. The listener is passed
246
- * 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.
247
- * Used by the Remove DDV extension to listen to server send events.
248
- * @param orgPayload - The initially constructed payload object
249
- * @param sendPayload - The alternative (possibly modified by a preprocessor) payload
250
- * @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.
251
- * @param isBeaconSend - A boolean flag indicating whether the payload was sent using the navigator.sendBeacon() API.
701
+ * The default values with a check function
252
702
  */
253
- type PayloadListenerFunction = (orgPayload: IPayloadData, sendPayload?: IPayloadData, isSync?: boolean, isBeaconSend?: boolean) => void;
703
+ interface IConfigDefaultCheck<T, V, C = IConfiguration> {
704
+ /**
705
+ * Callback function to check if the user-supplied value is valid, if not the default will be applied
706
+ */
707
+ isVal?: IConfigCheckFn<V>;
708
+ /**
709
+ * Optional function to allow converting and setting of the default value
710
+ */
711
+ set?: IConfigSetFn<T, V>;
712
+ /**
713
+ * The default value to apply if the user-supplied value is not valid
714
+ */
715
+ v?: V | IConfigDefaults<V, T>;
716
+ /**
717
+ * The default fallback key if the main key is not present, this is the key value from the config
718
+ */
719
+ fb?: keyof T | keyof C | Array<keyof T | keyof C>;
720
+ /**
721
+ * Use this check to determine the default fallback, default only checked whether the property isDefined,
722
+ * therefore `null`; `""` are considered to be valid values.
723
+ */
724
+ dfVal?: (value: any) => boolean;
725
+ /**
726
+ * Specify that any provided value should have the default value(s) merged into the value rather than
727
+ * just using either the default of user provided values. Mergeed objects will automatically be marked
728
+ * as referenced.
729
+ */
730
+ mrg?: boolean;
731
+ /**
732
+ * Set this field of the target as referenced, which will cause any object or array instance
733
+ * to be updated in-place rather than being entirely replaced. All other values will continue to be replaced.
734
+ * This is required for nested default objects to avoid multiple repetitive updates to listeners
735
+ * @returns The referenced properties current value
736
+ */
737
+ ref?: boolean;
738
+ /**
739
+ * Set this field of the target as read-only, which will block this single named property from
740
+ * ever being changed for the target instance.
741
+ * This does NOT freeze or seal the instance, it just stops the direct re-assignment of the named property,
742
+ * if the value is a non-primitive (ie. an object or array) it's properties will still be mutable.
743
+ * @returns The referenced properties current value
744
+ */
745
+ rdOnly?: boolean;
746
+ /**
747
+ * Block the value associated with this property from having it's properties / values converted into
748
+ * dynamic properties, this is generally used to block objects or arrays provided by external libraries
749
+ * which may be a plain object with readonly (non-configurable) or const properties.
750
+ */
751
+ blkVal?: boolean;
752
+ }
254
753
 
255
754
  /**
256
- * Defines the function signature for the Payload Preprocessor.
257
- * @param payload - The Initial constructed payload that if not modified should be passed onto the callback function.
258
- * @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.
259
- * The modifiedBuffer argument can be either the original payload or may be modified by performing GZipping of the payload and adding the content header.
260
- * @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.
261
- * 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.
755
+ * The Type definition to define default values to be applied to the config
756
+ * The value may be either the direct value or a ConfigDefaultCheck definition
262
757
  */
263
- type PayloadPreprocessorFunction = (payload: IPayloadData, callback: (modifiedBuffer: IPayloadData) => void, isSync?: boolean) => void;
758
+ type IConfigDefaults<T, C = IConfiguration> = {
759
+ [key in keyof T]: T[key] | IConfigDefaultCheck<T, T[key], C>;
760
+ };
264
761
 
265
762
  /**
266
- * Class that manages adding events to inbound queues and batching of events
267
- * into requests.
268
- * @group Classes
269
- * @group Entrypoint
763
+ * The type which identifies the function use to validate the user supplied value
270
764
  */
271
- class PostChannel extends BaseTelemetryPlugin implements IChannelControls, IPostChannel {
272
- identifier: string;
273
- priority: number;
274
- version: string;
275
- constructor();
765
+ type IConfigSetFn<T, V> = (value: any, defValue: V, theConfig: T) => V;
766
+
767
+ /**
768
+ * Configuration provided to SDK core
769
+ */
770
+ interface IConfiguration {
276
771
  /**
277
- * Start the queue manager to batch and send events via post.
278
- * @param config - The core configuration.
772
+ * Instrumentation key of resource. Either this or connectionString must be specified.
279
773
  */
280
- initialize(coreConfig: IExtendedConfiguration, core: IAppInsightsCore, extensions: IPlugin[]): void;
774
+ instrumentationKey?: string;
281
775
  /**
282
- * Add an event to the appropriate inbound queue based on its latency.
283
- * @param ev - The event to be added to the queue.
284
- * @param itemCtx - This is the context for the current request, ITelemetryPlugin instances
285
- * can optionally use this to access the current core instance or define / pass additional information
286
- * to later plugins (vs appending items to the telemetry item)
776
+ * Connection string of resource. Either this or instrumentationKey must be specified.
287
777
  */
288
- processTelemetry(ev: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
778
+ connectionString?: string;
289
779
  /**
290
- * Sets the event queue limits at runtime (after initialization), if the number of queued events is greater than the
291
- * eventLimit or autoFlushLimit then a flush() operation will be scheduled.
292
- * @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
293
- * equal to zero the value will be reset to the default (10,000).
294
- * @param autoFlushLimit When defined, once this number of events has been queued the system perform a flush() to send the queued events
295
- * without waiting for the normal schedule timers. Passing undefined, null or a value less than or equal to zero will disable the auto flush.
780
+ * Set the timer interval (in ms) for internal logging queue, this is the
781
+ * amount of time to wait after logger.queue messages are detected to be sent.
782
+ * Note: since 3.0.1 and 2.8.13 the diagnostic logger timer is a normal timeout timer
783
+ * and not an interval timer. So this now represents the timer "delay" and not
784
+ * the frequency at which the events are sent.
296
785
  */
297
- setEventQueueLimits(eventLimit: number, autoFlushLimit?: number): void;
786
+ diagnosticLogInterval?: number;
298
787
  /**
299
- * Pause the transmission of any requests
788
+ * Maximum number of iKey transmitted logging telemetry per page view
300
789
  */
301
- pause(): void;
790
+ maxMessageLimit?: number;
302
791
  /**
303
- * Resumes transmission of events.
792
+ * Console logging level. All logs with a severity level higher
793
+ * than the configured level will be printed to console. Otherwise
794
+ * they are suppressed. ie Level 2 will print both CRITICAL and
795
+ * WARNING logs to console, level 1 prints only CRITICAL.
796
+ *
797
+ * Note: Logs sent as telemetry to instrumentation key will also
798
+ * be logged to console if their severity meets the configured loggingConsoleLevel
799
+ *
800
+ * 0: ALL console logging off
801
+ * 1: logs to console: severity >= CRITICAL
802
+ * 2: logs to console: severity >= WARNING
304
803
  */
305
- resume(): void;
804
+ loggingLevelConsole?: number;
306
805
  /**
307
- * Add handler to be executed with request response text.
806
+ * Telemtry logging level to instrumentation key. All logs with a severity
807
+ * level higher than the configured level will sent as telemetry data to
808
+ * the configured instrumentation key.
809
+ *
810
+ * 0: ALL iKey logging off
811
+ * 1: logs to iKey: severity >= CRITICAL
812
+ * 2: logs to iKey: severity >= WARNING
308
813
  */
309
- addResponseHandler(responseHanlder: (responseText: string) => void): IUnloadHook;
814
+ loggingLevelTelemetry?: number;
310
815
  /**
311
- * Flush to send data immediately; channel should default to sending data asynchronously. If executing asynchronously (the default) and
312
- * you DO NOT pass a callback function then a [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html)
313
- * will be returned which will resolve once the flush is complete. The actual implementation of the `IPromise`
314
- * will be a native Promise (if supported) or the default as supplied by [ts-async library](https://github.com/nevware21/ts-async)
315
- * @param async - send data asynchronously when true
316
- * @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.
317
- * If the caller doesn't return true the caller should assume that it may never be called.
318
- * @param sendReason - specify the reason that you are calling "flush" defaults to ManualFlush (1) if not specified
319
- * @returns - If a callback is provided `true` to indicate that callback will be called after the flush is complete otherwise the caller
320
- * should assume that any provided callback will never be called, Nothing or if occurring asynchronously a
321
- * [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html) which will be resolved once the unload is complete,
322
- * the [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html) will only be returned when no callback is provided
323
- * and async is true.
816
+ * If enabled, uncaught exceptions will be thrown to help with debugging
324
817
  */
325
- flush(async?: boolean, callBack?: (flushComplete?: boolean) => void, sendReason?: SendRequestReason): boolean | void | IPromise<boolean>;
818
+ enableDebug?: boolean;
819
+ /**
820
+ * Endpoint where telemetry data is sent
821
+ */
822
+ endpointUrl?: string;
823
+ /**
824
+ * Extension configs loaded in SDK
825
+ */
826
+ extensionConfig?: {
827
+ [key: string]: any;
828
+ };
829
+ /**
830
+ * Additional plugins that should be loaded by core at runtime
831
+ */
832
+ readonly extensions?: ITelemetryPlugin[];
833
+ /**
834
+ * Channel queues that is setup by caller in desired order.
835
+ * If channels are provided here, core will ignore any channels that are already setup, example if there is a SKU with an initialized channel
836
+ */
837
+ readonly channels?: IChannelControls[][];
838
+ /**
839
+ * @type {boolean}
840
+ * Flag that disables the Instrumentation Key validation.
841
+ */
842
+ disableInstrumentationKeyValidation?: boolean;
843
+ /**
844
+ * [Optional] When enabled this will create local perfEvents based on sections of the code that have been instrumented
845
+ * to emit perfEvents (via the doPerf()) when this is enabled. This can be used to identify performance issues within
846
+ * the SDK, the way you are using it or optionally your own instrumented code.
847
+ * The provided IPerfManager implementation does NOT send any additional telemetry events to the server it will only fire
848
+ * the new perfEvent() on the INotificationManager which you can listen to.
849
+ * This also does not use the window.performance API, so it will work in environments where this API is not supported.
850
+ */
851
+ enablePerfMgr?: boolean;
852
+ /**
853
+ * [Optional] Callback function that will be called to create a the IPerfManager instance when required and ```enablePerfMgr```
854
+ * is enabled, this enables you to override the default creation of a PerfManager() without needing to ```setPerfMgr()```
855
+ * after initialization.
856
+ */
857
+ createPerfMgr?: (core: IAppInsightsCore, notificationManager: INotificationManager) => IPerfManager;
858
+ /**
859
+ * [Optional] Fire every single performance event not just the top level root performance event. Defaults to false.
860
+ */
861
+ perfEvtsSendAll?: boolean;
862
+ /**
863
+ * [Optional] Identifies the default length used to generate random session and user id's if non currently exists for the user / session.
864
+ * Defaults to 22, previous default value was 5, if you need to keep the previous maximum length you should set this value to 5.
865
+ */
866
+ idLength?: number;
867
+ /**
868
+ * @description Custom cookie domain. This is helpful if you want to share Application Insights cookies across subdomains. It
869
+ * can be set here or as part of the cookieCfg.domain, the cookieCfg takes precedence if both are specified.
870
+ * @type {string}
871
+ * @defaultValue ""
872
+ */
873
+ cookieDomain?: string;
874
+ /**
875
+ * @description Custom cookie path. This is helpful if you want to share Application Insights cookies behind an application
876
+ * gateway. It can be set here or as part of the cookieCfg.domain, the cookieCfg takes precedence if both are specified.
877
+ * @type {string}
878
+ * @defaultValue ""
879
+ */
880
+ cookiePath?: string;
881
+ /**
882
+ * [Optional] A boolean that indicated whether to disable the use of cookies by the SDK. If true, the SDK will not store or
883
+ * read any data from cookies. Cookie usage can be re-enabled after initialization via the core.getCookieMgr().enable().
884
+ */
885
+ disableCookiesUsage?: boolean;
886
+ /**
887
+ * [Optional] A Cookie Manager configuration which includes hooks to allow interception of the get, set and delete cookie
888
+ * operations. If this configuration is specified any specified enabled and domain properties will take precedence over the
889
+ * cookieDomain and disableCookiesUsage values.
890
+ */
891
+ cookieCfg?: ICookieMgrConfig;
892
+ /**
893
+ * [Optional] An array of the page unload events that you would like to be ignored, special note there must be at least one valid unload
894
+ * event hooked, if you list all or the runtime environment only supports a listed "disabled" event it will still be hooked, if required by the SDK.
895
+ * Unload events include "beforeunload", "unload", "visibilitychange" (with 'hidden' state) and "pagehide"
896
+ */
897
+ disablePageUnloadEvents?: string[];
898
+ /**
899
+ * [Optional] An array of page show events that you would like to be ignored, special note there must be at lease one valid show event
900
+ * hooked, if you list all or the runtime environment only supports a listed (disabled) event it will STILL be hooked, if required by the SDK.
901
+ * Page Show events include "pageshow" and "visibilitychange" (with 'visible' state)
902
+ */
903
+ disablePageShowEvents?: string[];
904
+ /**
905
+ * [Optional] A flag for performance optimization to disable attempting to use the Chrome Debug Extension, if disabled and the extension is installed
906
+ * this will not send any notifications.
907
+ */
908
+ disableDbgExt?: boolean;
909
+ /**
910
+ * Add "&w=0" parameter to support UA Parsing when web-workers don't have access to Document.
911
+ * Default is false
912
+ */
913
+ enableWParam?: boolean;
914
+ /**
915
+ * Custom optional value that will be added as a prefix for storage name.
916
+ * @defaultValue undefined
917
+ */
918
+ storagePrefix?: string;
919
+ /**
920
+ * Custom optional value to opt in features
921
+ * @defaultValue undefined
922
+ */
923
+ featureOptIn?: IFeatureOptIn;
924
+ }
925
+
926
+ interface ICookieMgr {
927
+ /**
928
+ * Enable or Disable the usage of cookies
929
+ */
930
+ setEnabled(value: boolean): void;
931
+ /**
932
+ * Can the system use cookies, if this returns false then all cookie setting and access functions will return nothing
933
+ */
934
+ isEnabled(): boolean;
935
+ /**
936
+ * Set the named cookie with the value and optional domain and optional
937
+ * @param name - The name of the cookie
938
+ * @param value - The value of the cookie (Must already be encoded)
939
+ * @param maxAgeSec - [optional] The maximum number of SECONDS that this cookie should survive
940
+ * @param domain - [optional] The domain to set for the cookie
941
+ * @param path - [optional] Path to set for the cookie, if not supplied will default to "/"
942
+ * @returns - True if the cookie was set otherwise false (Because cookie usage is not enabled or available)
943
+ */
944
+ set(name: string, value: string, maxAgeSec?: number, domain?: string, path?: string): boolean;
945
+ /**
946
+ * Get the value of the named cookie
947
+ * @param name - The name of the cookie
948
+ */
949
+ get(name: string): string;
950
+ /**
951
+ * Delete/Remove the named cookie if cookie support is available and enabled.
952
+ * Note: Not using "delete" as the name because it's a reserved word which would cause issues on older browsers
953
+ * @param name - The name of the cookie
954
+ * @param path - [optional] Path to set for the cookie, if not supplied will default to "/"
955
+ * @returns - True if the cookie was marked for deletion otherwise false (Because cookie usage is not enabled or available)
956
+ */
957
+ del(name: string, path?: string): boolean;
958
+ /**
959
+ * Purge the cookie from the system if cookie support is available, this function ignores the enabled setting of the manager
960
+ * so any cookie will be removed.
961
+ * Note: Not using "delete" as the name because it's a reserved word which would cause issues on older browsers
962
+ * @param name - The name of the cookie
963
+ * @param path - [optional] Path to set for the cookie, if not supplied will default to "/"
964
+ * @returns - True if the cookie was marked for deletion otherwise false (Because cookie usage is not available)
965
+ */
966
+ purge(name: string, path?: string): boolean;
967
+ /**
968
+ * Optional Callback hook to allow the cookie manager to update it's configuration, not generally implemented now that
969
+ * dynamic configuration is supported
970
+ * @param updateState
971
+ */
972
+ update?(updateState: ITelemetryUpdateState): void;
973
+ /**
974
+ * Unload and remove any state that this ICookieMgr may be holding, this is generally called when the
975
+ * owning SDK is being unloaded.
976
+ * @param isAsync - Can the unload be performed asynchronously (default)
977
+ * @return If the unload occurs synchronously then nothing should be returned, if happening asynchronously then
978
+ * the function should return an [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html)
979
+ * / Promise to allow any listeners to wait for the operation to complete.
980
+ */
981
+ unload?(isAsync?: boolean): void | IPromise<void>;
982
+ }
983
+
984
+ /**
985
+ * Configuration definition for instance based cookie management configuration
986
+ */
987
+ interface ICookieMgrConfig {
988
+ /**
989
+ * Defaults to true, A boolean that indicates whether the use of cookies by the SDK is enabled by the current instance.
990
+ * If false, the instance of the SDK initialized by this configuration will not store or read any data from cookies
991
+ */
992
+ enabled?: boolean;
993
+ /**
994
+ * Custom cookie domain. This is helpful if you want to share Application Insights cookies across subdomains.
995
+ */
996
+ domain?: string;
997
+ /**
998
+ * Specifies the path to use for the cookie, defaults to '/'
999
+ */
1000
+ path?: string;
1001
+ /**
1002
+ * Specify the cookie name(s) to be ignored, this will cause any matching cookie name to never be read or written.
1003
+ * They may still be explicitly purged or deleted. You do not need to repeat the name in the `blockedCookies`
1004
+ * configuration.(Since v2.8.8)
1005
+ */
1006
+ ignoreCookies?: string[];
1007
+ /**
1008
+ * Specify the cookie name(s) to never be written, this will cause any cookie name to never be created or updated,
1009
+ * they will still be read unless also included in the ignoreCookies and may still be explicitly purged or deleted.
1010
+ * If not provided defaults to the same list provided in ignoreCookies. (Since v2.8.8)
1011
+ */
1012
+ blockedCookies?: string[];
1013
+ /**
1014
+ * Hook function to fetch the named cookie value.
1015
+ * @param name - The name of the cookie
1016
+ */
1017
+ getCookie?: (name: string) => string;
1018
+ /**
1019
+ * Hook function to set the named cookie with the specified value.
1020
+ * @param name - The name of the cookie
1021
+ * @param value - The value to set for the cookie
1022
+ */
1023
+ setCookie?: (name: string, value: string) => void;
1024
+ /**
1025
+ * Hook function to delete the named cookie with the specified value, separated from
1026
+ * setCookie to avoid the need to parse the value to determine whether the cookie is being
1027
+ * added or removed.
1028
+ * @param name - The name of the cookie
1029
+ * @param cookieValue - The value to set to expire the cookie
1030
+ */
1031
+ delCookie?: (name: string, cookieValue: string) => void;
1032
+ }
1033
+
1034
+ interface ICustomProperties {
1035
+ [key: string]: any;
1036
+ }
1037
+
1038
+ interface IDiagnosticLogger {
1039
+ /**
1040
+ * 0: OFF
1041
+ * 1: only critical (default)
1042
+ * 2: critical + info
1043
+ */
1044
+ consoleLoggingLevel: () => number;
1045
+ /**
1046
+ * The internal logging queue
1047
+ */
1048
+ queue: _InternalLogMessage[];
1049
+ /**
1050
+ * This method will throw exceptions in debug mode or attempt to log the error as a console warning.
1051
+ * @param severity - The severity of the log message
1052
+ * @param message - The log message.
1053
+ */
1054
+ throwInternal(severity: LoggingSeverity, msgId: _InternalMessageId, msg: string, properties?: Object, isUserAct?: boolean): void;
1055
+ /**
1056
+ * This will write a debug message to the console if possible
1057
+ * @param message - {string} - The debug message
1058
+ */
1059
+ debugToConsole?(message: string): void;
1060
+ /**
1061
+ * This will write a warning to the console if possible
1062
+ * @param message - The warning message
1063
+ */
1064
+ warnToConsole(message: string): void;
1065
+ /**
1066
+ * This will write an error to the console if possible.
1067
+ * Provided by the default DiagnosticLogger instance, and internally the SDK will fall back to warnToConsole, however,
1068
+ * direct callers MUST check for its existence on the logger as you can provide your own IDiagnosticLogger instance.
1069
+ * @param message - The error message
1070
+ */
1071
+ errorToConsole?(message: string): void;
1072
+ /**
1073
+ * Resets the internal message count
1074
+ */
1075
+ resetInternalMessageCount(): void;
1076
+ /**
1077
+ * Logs a message to the internal queue.
1078
+ * @param severity - The severity of the log message
1079
+ * @param message - The message to log.
1080
+ */
1081
+ logInternalMessage?(severity: LoggingSeverity, message: _InternalLogMessage): void;
1082
+ /**
1083
+ * Optional Callback hook to allow the diagnostic logger to update it's configuration
1084
+ * @param updateState
1085
+ */
1086
+ update?(updateState: ITelemetryUpdateState): void;
1087
+ /**
1088
+ * Unload and remove any state that this IDiagnosticLogger may be holding, this is generally called when the
1089
+ * owning SDK is being unloaded.
1090
+ * @param isAsync - Can the unload be performed asynchronously (default)
1091
+ * @return If the unload occurs synchronously then nothing should be returned, if happening asynchronously then
1092
+ * the function should return an [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html)
1093
+ * / Promise to allow any listeners to wait for the operation to complete.
1094
+ */
1095
+ unload?(isAsync?: boolean): void | IPromise<void>;
1096
+ }
1097
+
1098
+ interface IDistributedTraceContext {
1099
+ /**
1100
+ * Returns the current name of the page
1101
+ */
1102
+ getName(): string;
1103
+ /**
1104
+ * Sets the current name of the page
1105
+ * @param pageName
1106
+ */
1107
+ setName(pageName: string): void;
1108
+ /**
1109
+ * Returns the unique identifier for a trace. All requests / spans from the same trace share the same traceId.
1110
+ * Must be read from incoming headers or generated according to the W3C TraceContext specification,
1111
+ * in a hex representation of 16-byte array. A.k.a. trace-id, TraceID or Distributed TraceID
1112
+ */
1113
+ getTraceId(): string;
1114
+ /**
1115
+ * Set the unique identifier for a trace. All requests / spans from the same trace share the same traceId.
1116
+ * Must be conform to the W3C TraceContext specification, in a hex representation of 16-byte array.
1117
+ * A.k.a. trace-id, TraceID or Distributed TraceID https://www.w3.org/TR/trace-context/#trace-id
1118
+ */
1119
+ setTraceId(newValue: string): void;
1120
+ /**
1121
+ * Self-generated 8-bytes identifier of the incoming request. Must be a hex representation of 8-byte array.
1122
+ * Also know as the parentId, used to link requests together
1123
+ */
1124
+ getSpanId(): string;
1125
+ /**
1126
+ * Self-generated 8-bytes identifier of the incoming request. Must be a hex representation of 8-byte array.
1127
+ * Also know as the parentId, used to link requests together
1128
+ * https://www.w3.org/TR/trace-context/#parent-id
1129
+ */
1130
+ setSpanId(newValue: string): void;
1131
+ /**
1132
+ * An integer representation of the W3C TraceContext trace-flags.
1133
+ */
1134
+ getTraceFlags(): number | undefined;
1135
+ /**
1136
+ * https://www.w3.org/TR/trace-context/#trace-flags
1137
+ * @param newValue
1138
+ */
1139
+ setTraceFlags(newValue?: number): void;
1140
+ }
1141
+
1142
+ /**
1143
+ * An interface used to create an event property value along with tagging it as PII, or customer content.
1144
+ * <b>Caution:</b> Customer content and PII are mutually exclusive. You can use only one of them at a time.
1145
+ * If you use both, then the property will be considered invalid, and therefore won't be sent.
1146
+ */
1147
+ interface IEventProperty {
1148
+ /**
1149
+ * The value for the property.
1150
+ */
1151
+ value: string | number | boolean | string[] | number[] | boolean[];
1152
+ /**
1153
+ * [Optional] The value kind associated with property value. The constant enum ValueKind should be used to specify the
1154
+ * different kinds.
1155
+ */
1156
+ kind?: number;
1157
+ /**
1158
+ * [Optional] The data type for the property. Valid values accepted by onecollector are
1159
+ * "string", "bool", "double", "int64", "datetime", "guid".
1160
+ * The EventPropertyType constant enum should be used to specify the different property type values.
1161
+ */
1162
+ propertyType?: number;
1163
+ }
1164
+
1165
+ /**
1166
+ * The IExtendedConfiguration interface holds the configuration details passed to core during initialize.
1167
+ */
1168
+ interface IExtendedConfiguration extends IConfiguration {
1169
+ /**
1170
+ * [Optional] The property storage override that should be used to store
1171
+ * internal SDK properties, otherwise stored as cookies. It is needed where cookies are not available.
1172
+ */
1173
+ propertyStorageOverride?: IPropertyStorageOverride;
1174
+ /**
1175
+ * [Optional] A boolean that indicated whether to disable the use of cookies by the 1DS Web SDK. The cookies added by the SDK are
1176
+ * MicrosoftApplicationsTelemetryDeviceId. If cookies are disabled, then session events are not sent unless propertyStorageOverride
1177
+ * is provided to store the values elsewhere.
1178
+ */
1179
+ disableCookiesUsage?: boolean;
1180
+ /**
1181
+ * [Optional] Name of the Anon cookie. The value will be set in the qsp header to collector requests. Collector will use this value to look for specific cookie to use for anid property.
1182
+ */
1183
+ anonCookieName?: string;
1184
+ /**
1185
+ * [Optional] Disables additional internal event timings that are added during processing of events, the timings are not sent as part telemetry items to the server
1186
+ */
1187
+ disableEventTimings?: boolean;
1188
+ /**
1189
+ * [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.
1190
+ * @example
1191
+ * ```typescript
1192
+ * event: { "somedata.embeddedvalue": 123 }
1193
+ * ```
1194
+ */
1195
+ enableCompoundKey?: boolean;
1196
+ /**
1197
+ * Add "&w=0" parameter to support UA Parsing when web-workers don't have access to Document.
1198
+ * Default is false
1199
+ */
1200
+ enableWParam?: boolean;
1201
+ }
1202
+
1203
+ interface IFeatureOptIn {
1204
+ [feature: string]: IFeatureOptInDetails;
1205
+ }
1206
+
1207
+ interface IFeatureOptInDetails {
1208
+ /**
1209
+ * sets feature opt-in mode
1210
+ * @default undefined
1211
+ */
1212
+ mode?: FeatureOptInMode;
1213
+ /**
1214
+ * Identifies configuration override values when given feature is enabled
1215
+ * NOTE: should use flat string for fields, for example, if you want to set value for extensionConfig.Ananlytics.disableAjaxTrackig in configurations,
1216
+ * you should use "extensionConfig.Ananlytics.disableAjaxTrackig" as field name: {["extensionConfig.Analytics.disableAjaxTrackig"]:1}
1217
+ * Default: undefined
1218
+ */
1219
+ onCfg?: {
1220
+ [field: string]: any;
1221
+ };
1222
+ /**
1223
+ * Identifies configuration override values when given feature is disabled
1224
+ * NOTE: should use flat string for fields, for example, if you want to set value for extensionConfig.Ananlytics.disableAjaxTrackig in configurations,
1225
+ * you should use "extensionConfig.Ananlytics.disableAjaxTrackig" as field name: {["extensionConfig.Analytics.disableAjaxTrackig"]:1}
1226
+ * Default: undefined
1227
+ */
1228
+ offCfg?: {
1229
+ [field: string]: any;
1230
+ };
1231
+ /**
1232
+ * define if should block any changes from cdn cfg, if set to true, cfgValue will be applied under all scenarios
1233
+ * @default false
1234
+ */
1235
+ blockCdnCfg?: boolean;
1236
+ }
1237
+
1238
+ /**
1239
+ * This interface defines the object that is passed to any provided FieldValueSanitizerFunc, it provides not only the value to be sanitized but also
1240
+ * some context about the value like it's location within the envelope (serialized object), the format is defined via the
1241
+ * [Common Schema 4.0](https://aka.ms/CommonSchema) specification.
1242
+ */
1243
+ interface IFieldSanitizerDetails {
1244
+ /**
1245
+ * The path within the event where the value is stored
1246
+ */
1247
+ path: string;
1248
+ /**
1249
+ * The name of the field with the event path that will store the value
1250
+ */
1251
+ name: string;
1252
+ /**
1253
+ * Identifies the type of the property value
1254
+ */
1255
+ type: FieldValueSanitizerType;
1256
+ /**
1257
+ * The value for the property.
1258
+ */
1259
+ prop: IEventProperty;
1260
+ /**
1261
+ * A reference to the value sanitizer that created the details
1262
+ */
1263
+ sanitizer: IValueSanitizer;
1264
+ }
1265
+
1266
+ /**
1267
+ * This interface is used during the serialization of individual fields when converting the events into envelope (serialized object) which is sent to the services,
1268
+ * the format is defined via the [Common Schema 4.0](https://aka.ms/CommonSchema) specification. The path and field names used are based
1269
+ * on how the data is serialized to the service (CS 4.0 location) and not specifically the location on the event object you pass into the track methods (unless they are the same).
1270
+ */
1271
+ interface IFieldValueSanitizerProvider {
1272
+ /**
1273
+ * Does this field value sanitizer handle this path / field combination
1274
+ * @param path - The field path
1275
+ * @param name - The name of the field
1276
+ */
1277
+ handleField(path: string, name: string): boolean;
1278
+ /**
1279
+ * Get the field sanitizer for this type of field based on the field type, value kind and/or event property type
1280
+ * @param path - The field path
1281
+ * @param name - The name of the field
1282
+ * @param theType - The type of field
1283
+ * @param theKind - The value kind of the field
1284
+ * @param propType - The property type of the field
1285
+ */
1286
+ getSanitizer(path: string, name: string, theType: FieldValueSanitizerType, theKind?: number, propType?: number): FieldValueSanitizerFunc | null | undefined;
1287
+ }
1288
+
1289
+ /**
1290
+ * An alternate interface which provides automatic removal during unloading of the component
1291
+ */
1292
+ interface ILegacyUnloadHook {
1293
+ /**
1294
+ * Legacy Self remove the referenced component
1295
+ */
1296
+ remove: () => void;
1297
+ }
1298
+
1299
+ interface ILoadedPlugin<T extends IPlugin> {
1300
+ plugin: T;
1301
+ /**
1302
+ * Identifies whether the plugin is enabled and can process events. This is slightly different from isInitialized as the plugin may be initialized but disabled
1303
+ * via the setEnabled() or it may be a shared plugin which has had it's teardown function called from another instance..
1304
+ * @returns boolean = true if the plugin is in a state where it is operational.
1305
+ */
1306
+ isEnabled: () => boolean;
1307
+ /**
1308
+ * You can optionally enable / disable a plugin from processing events.
1309
+ * Setting enabled to true will not necessarily cause the `isEnabled()` to also return true
1310
+ * as the plugin must also have been successfully initialized and not had it's `teardown` method called
1311
+ * (unless it's also been re-initialized)
1312
+ */
1313
+ setEnabled: (isEnabled: boolean) => void;
1314
+ remove: (isAsync?: boolean, removeCb?: (removed?: boolean) => void) => void;
1315
+ }
1316
+
1317
+ /**
1318
+ * An interface used for the notification listener.
1319
+ * @interface
1320
+ */
1321
+ interface INotificationListener {
1322
+ /**
1323
+ * [Optional] A function called when events are sent.
1324
+ * @param events - The array of events that have been sent.
1325
+ */
1326
+ eventsSent?: (events: ITelemetryItem[]) => void;
1327
+ /**
1328
+ * [Optional] A function called when events are discarded.
1329
+ * @param events - The array of events that have been discarded.
1330
+ * @param reason - The reason for discarding the events. The EventsDiscardedReason
1331
+ * constant should be used to check the different values.
1332
+ */
1333
+ eventsDiscarded?: (events: ITelemetryItem[], reason: number) => void;
1334
+ /**
1335
+ * [Optional] A function called when the events have been requested to be sent to the sever.
1336
+ * @param sendReason - The reason why the event batch is being sent.
1337
+ * @param isAsync - A flag which identifies whether the requests are being sent in an async or sync manner.
1338
+ */
1339
+ eventsSendRequest?: (sendReason: number, isAsync?: boolean) => void;
1340
+ /**
1341
+ * [Optional] This event is sent if you have enabled perf events, they are primarily used to track internal performance testing and debugging
1342
+ * the event can be displayed via the debug plugin extension.
1343
+ * @param perfEvent
1344
+ */
1345
+ perfEvent?: (perfEvent: IPerfEvent) => void;
1346
+ /**
1347
+ * Unload and remove any state that this INotificationListener may be holding, this is generally called when the
1348
+ * owning Manager is being unloaded.
1349
+ * @param isAsync - Can the unload be performed asynchronously (default)
1350
+ * @return If the unload occurs synchronously then nothing should be returned, if happening asynchronously then
1351
+ * the function should return an [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html)
1352
+ * / Promise to allow any listeners to wait for the operation to complete.
1353
+ */
1354
+ unload?(isAsync?: boolean): void | IPromise<void>;
1355
+ }
1356
+
1357
+ /**
1358
+ * Class to manage sending notifications to all the listeners.
1359
+ */
1360
+ interface INotificationManager {
1361
+ listeners: INotificationListener[];
1362
+ /**
1363
+ * Adds a notification listener.
1364
+ * @param listener - The notification listener to be added.
1365
+ */
1366
+ addNotificationListener(listener: INotificationListener): void;
1367
+ /**
1368
+ * Removes all instances of the listener.
1369
+ * @param listener - AWTNotificationListener to remove.
1370
+ */
1371
+ removeNotificationListener(listener: INotificationListener): void;
1372
+ /**
1373
+ * Notification for events sent.
1374
+ * @param events - The array of events that have been sent.
1375
+ */
1376
+ eventsSent(events: ITelemetryItem[]): void;
1377
+ /**
1378
+ * Notification for events being discarded.
1379
+ * @param events - The array of events that have been discarded by the SDK.
1380
+ * @param reason - The reason for which the SDK discarded the events. The EventsDiscardedReason
1381
+ * constant should be used to check the different values.
1382
+ */
1383
+ eventsDiscarded(events: ITelemetryItem[], reason: number): void;
1384
+ /**
1385
+ * [Optional] A function called when the events have been requested to be sent to the sever.
1386
+ * @param sendReason - The reason why the event batch is being sent.
1387
+ * @param isAsync - A flag which identifies whether the requests are being sent in an async or sync manner.
1388
+ */
1389
+ eventsSendRequest?(sendReason: number, isAsync: boolean): void;
1390
+ /**
1391
+ * [Optional] This event is sent if you have enabled perf events, they are primarily used to track internal performance testing and debugging
1392
+ * the event can be displayed via the debug plugin extension.
1393
+ * @param perfEvent - The perf event details
1394
+ */
1395
+ perfEvent?(perfEvent: IPerfEvent): void;
1396
+ /**
1397
+ * Unload and remove any state that this INotificationManager may be holding, this is generally called when the
1398
+ * owning SDK is being unloaded.
1399
+ * @param isAsync - Can the unload be performed asynchronously (default)
1400
+ * @return If the unload occurs synchronously then nothing should be returned, if happening asynchronously then
1401
+ * the function should return an [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html)
1402
+ * / Promise to allow any listeners to wait for the operation to complete.
1403
+ */
1404
+ unload?(isAsync?: boolean): void | IPromise<void>;
1405
+ }
1406
+
1407
+ class _InternalLogMessage {
1408
+ static dataType: string;
1409
+ message: string;
1410
+ messageId: _InternalMessageId;
1411
+ constructor(msgId: _InternalMessageId, msg: string, isUserAct?: boolean, properties?: Object);
1412
+ }
1413
+
1414
+ type _InternalMessageId = number | _eInternalMessageId;
1415
+
1416
+ /** IPayloadData describes interface of payload sent via POST channel */
1417
+ interface IPayloadData {
1418
+ urlString: string;
1419
+ data: Uint8Array | string;
1420
+ headers?: {
1421
+ [name: string]: string;
1422
+ };
1423
+ timeout?: number;
1424
+ disableXhrSync?: boolean;
1425
+ disableFetchKeepAlive?: boolean;
1426
+ sendReason?: SendRequestReason;
1427
+ }
1428
+
1429
+ /**
1430
+ * This interface identifies the details of an internal performance event - it does not represent an outgoing reported event
1431
+ */
1432
+ interface IPerfEvent {
1433
+ /**
1434
+ * The name of the performance event
1435
+ */
1436
+ name: string;
1437
+ /**
1438
+ * The start time of the performance event
1439
+ */
1440
+ start: number;
1441
+ /**
1442
+ * The payload (contents) of the perfEvent, may be null or only set after the event has completed depending on
1443
+ * the runtime environment.
1444
+ */
1445
+ payload: any;
1446
+ /**
1447
+ * Is this occurring from an asynchronous event
1448
+ */
1449
+ isAsync: boolean;
1450
+ /**
1451
+ * Identifies the total inclusive time spent for this event, including the time spent for child events,
1452
+ * this will be undefined until the event is completed
1453
+ */
1454
+ time?: number;
1455
+ /**
1456
+ * Identifies the exclusive time spent in for this event (not including child events),
1457
+ * this will be undefined until the event is completed.
1458
+ */
1459
+ exTime?: number;
1460
+ /**
1461
+ * The Parent event that was started before this event was created
1462
+ */
1463
+ parent?: IPerfEvent;
1464
+ /**
1465
+ * The child perf events that are contained within the total time of this event.
1466
+ */
1467
+ childEvts?: IPerfEvent[];
1468
+ /**
1469
+ * Identifies whether this event is a child event of a parent
1470
+ */
1471
+ isChildEvt: () => boolean;
1472
+ /**
1473
+ * Get the names additional context associated with this perf event
1474
+ */
1475
+ getCtx?: (key: string) => any;
1476
+ /**
1477
+ * Set the named additional context to be associated with this perf event, this will replace any existing value
1478
+ */
1479
+ setCtx?: (key: string, value: any) => void;
1480
+ /**
1481
+ * Mark this event as completed, calculating the total execution time.
1482
+ */
1483
+ complete: () => void;
1484
+ }
1485
+
1486
+ /**
1487
+ * This defines an internal performance manager for tracking and reporting the internal performance of the SDK -- It does
1488
+ * not represent or report any event to the server.
1489
+ */
1490
+ interface IPerfManager {
1491
+ /**
1492
+ * Create a new event and start timing, the manager may return null/undefined to indicate that it does not
1493
+ * want to monitor this source event.
1494
+ * @param src - The source name of the event
1495
+ * @param payloadDetails - An optional callback function to fetch the payload details for the event.
1496
+ * @param isAsync - Is the event occurring from a async event
1497
+ */
1498
+ create(src: string, payloadDetails?: () => any, isAsync?: boolean): IPerfEvent | null | undefined;
1499
+ /**
1500
+ * Complete the perfEvent and fire any notifications.
1501
+ * @param perfEvent - Fire the event which will also complete the passed event
1502
+ */
1503
+ fire(perfEvent: IPerfEvent): void;
1504
+ /**
1505
+ * Set an execution context value
1506
+ * @param key - The context key name
1507
+ * @param value - The value
1508
+ */
1509
+ setCtx(key: string, value: any): void;
1510
+ /**
1511
+ * Get the execution context value
1512
+ * @param key - The context key
1513
+ */
1514
+ getCtx(key: string): any;
1515
+ }
1516
+
1517
+ /**
1518
+ * Identifies an interface to a host that can provide an IPerfManager implementation
1519
+ */
1520
+ interface IPerfManagerProvider {
1521
+ /**
1522
+ * Get the current performance manager
1523
+ */
1524
+ getPerfMgr(): IPerfManager;
1525
+ /**
1526
+ * Set the current performance manager
1527
+ * @param perfMgr - The performance manager
1528
+ */
1529
+ setPerfMgr(perfMgr: IPerfManager): void;
1530
+ }
1531
+
1532
+ interface IPlugin {
1533
+ /**
1534
+ * Initialize plugin loaded by SDK
1535
+ * @param config - The config for the plugin to use
1536
+ * @param core - The current App Insights core to use for initializing this plugin instance
1537
+ * @param extensions - The complete set of extensions to be used for initializing the plugin
1538
+ * @param pluginChain - [Optional] specifies the current plugin chain which identifies the
1539
+ * set of plugins and the order they should be executed for the current request.
1540
+ */
1541
+ initialize: (config: IConfiguration, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?: ITelemetryPluginChain) => void;
1542
+ /**
1543
+ * Returns a value that indicates whether the plugin has already been previously initialized.
1544
+ * New plugins should implement this method to avoid being initialized more than once.
1545
+ */
1546
+ isInitialized?: () => boolean;
1547
+ /**
1548
+ * Tear down the plugin and remove any hooked value, the plugin should be removed so that it is no longer initialized and
1549
+ * therefore could be re-initialized after being torn down. The plugin should ensure that once this has been called any further
1550
+ * processTelemetry calls are ignored and it just calls the processNext() with the provided context.
1551
+ * @param unloadCtx - This is the context that should be used during unloading.
1552
+ * @param unloadState - The details / state of the unload process, it holds details like whether it should be unloaded synchronously or asynchronously and the reason for the unload.
1553
+ * @returns boolean - true if the plugin has or will call processNext(), this for backward compatibility as previously teardown was synchronous and returned nothing.
1554
+ */
1555
+ teardown?: (unloadCtx: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState) => void | boolean;
1556
+ /**
1557
+ * Extension name
1558
+ */
1559
+ readonly identifier: string;
1560
+ /**
1561
+ * Plugin version (available in data.properties.version in common schema)
1562
+ */
1563
+ readonly version?: string;
1564
+ /**
1565
+ * The App Insights core to use for backward compatibility.
1566
+ * Therefore the interface will be able to access the core without needing to cast to "any".
1567
+ * [optional] any 3rd party plugins which are already implementing this interface don't fail to compile.
1568
+ */
1569
+ core?: IAppInsightsCore;
1570
+ }
1571
+
1572
+ /**
1573
+ * Post channel interface
1574
+ */
1575
+ interface IPostChannel extends ITelemetryPlugin {
1576
+ /**
1577
+ * Diagnostic logger
1578
+ */
1579
+ diagLog: (itemCtx?: IProcessTelemetryContext) => IDiagnosticLogger;
1580
+ /**
1581
+ * Override for setTimeout
1582
+ */
1583
+ _setTimeoutOverride?: (callback: (...args: any[]) => void, ms: number, ...args: any[]) => any;
1584
+ /**
1585
+ * Backs off transmission. This exponentially increases all the timers.
1586
+ */
1587
+ _backOffTransmission(): void;
1588
+ /**
1589
+ * Clears back off for transmission.
1590
+ */
1591
+ _clearBackOff(): void;
1592
+ /**
1593
+ * Add handler to be executed with request response text.
1594
+ */
1595
+ addResponseHandler(responseHandler: (responseText: string) => void): IUnloadHook;
1596
+ }
1597
+
1598
+ /**
1599
+ * The current context for the current call to processTelemetry(), used to support sharing the same plugin instance
1600
+ * between multiple AppInsights instances
1601
+ */
1602
+ interface IProcessTelemetryContext extends IBaseProcessingContext {
1603
+ /**
1604
+ * Call back for telemetry processing before it it is sent
1605
+ * @param env - This is the current event being reported
1606
+ * @returns boolean (true) if there is no more plugins to process otherwise false or undefined (void)
1607
+ */
1608
+ processNext: (env: ITelemetryItem) => boolean | void;
1609
+ /**
1610
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
1611
+ * @param plugins - The execution order to process the plugins, if null or not supplied
1612
+ * then the current execution order will be copied.
1613
+ * @param startAt - The plugin to start processing from, if missing from the execution
1614
+ * order then the next plugin will be NOT set.
1615
+ */
1616
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryContext;
1617
+ }
1618
+
1619
+ /**
1620
+ * The current context for the current call to teardown() implementations, used to support when plugins are being removed
1621
+ * or the SDK is being unloaded.
1622
+ */
1623
+ interface IProcessTelemetryUnloadContext extends IBaseProcessingContext {
1624
+ /**
1625
+ * This Plugin has finished unloading, so unload the next one
1626
+ * @param uploadState - The state of the unload process
1627
+ * @returns boolean (true) if there is no more plugins to process otherwise false or undefined (void)
1628
+ */
1629
+ processNext: (unloadState: ITelemetryUnloadState) => boolean | void;
1630
+ /**
1631
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
1632
+ * @param plugins - The execution order to process the plugins, if null or not supplied
1633
+ * then the current execution order will be copied.
1634
+ * @param startAt - The plugin to start processing from, if missing from the execution
1635
+ * order then the next plugin will be NOT set.
1636
+ */
1637
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryUnloadContext;
1638
+ }
1639
+
1640
+ /**
1641
+ * The current context for the current call to the plugin update() implementations, used to support the notifications
1642
+ * for when plugins are added, removed or the configuration was changed.
1643
+ */
1644
+ interface IProcessTelemetryUpdateContext extends IBaseProcessingContext {
1645
+ /**
1646
+ * This Plugin has finished unloading, so unload the next one
1647
+ * @param updateState - The update State
1648
+ * @returns boolean (true) if there is no more plugins to process otherwise false or undefined (void)
1649
+ */
1650
+ processNext: (updateState: ITelemetryUpdateState) => boolean | void;
1651
+ /**
1652
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
1653
+ * @param plugins - The execution order to process the plugins, if null or not supplied
1654
+ * then the current execution order will be copied.
1655
+ * @param startAt - The plugin to start processing from, if missing from the execution
1656
+ * order then the next plugin will be NOT set.
1657
+ */
1658
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryUpdateContext;
1659
+ }
1660
+
1661
+ /**
1662
+ * Create a Promise object that represents the eventual completion (or failure) of an asynchronous operation and its resulting value.
1663
+ * This interface definition, closely mirrors the typescript / javascript PromiseLike<T> and Promise<T> definitions as well as providing
1664
+ * simular functions as that provided by jQuery deferred objects.
1665
+ *
1666
+ * The returned Promise is a proxy for a value not necessarily known when the promise is created. It allows you to associate handlers
1667
+ * with an asynchronous action's eventual success value or failure reason. This lets asynchronous methods return values like synchronous
1668
+ * methods: instead of immediately returning the final value, the asynchronous method returns a promise to supply the value at some point
1669
+ * in the future.
1670
+ *
1671
+ * A Promise is in one of these states:
1672
+ * <ul>
1673
+ * <li> pending: initial state, neither fulfilled nor rejected.
1674
+ * <li> fulfilled: meaning that the operation was completed successfully.
1675
+ * <li> rejected: meaning that the operation failed.
1676
+ * </ul>
1677
+ *
1678
+ * A pending promise can either be fulfilled with a value or rejected with a reason (error). When either of these options happens, the
1679
+ * associated handlers queued up by a promise's then method are called synchronously. If the promise has already been fulfilled or rejected
1680
+ * when a corresponding handler is attached, the handler will be called synchronously, so there is no race condition between an asynchronous
1681
+ * operation completing and its handlers being attached.
1682
+ *
1683
+ * As the `then()` and `catch()` methods return promises, they can be chained.
1684
+ * @typeParam T - Identifies the expected return type from the promise
1685
+ */
1686
+ interface IPromise<T> extends PromiseLike<T>, Promise<T> {
1687
+ /**
1688
+ * Returns a string representation of the current state of the promise. The promise can be in one of four states.
1689
+ * <ul>
1690
+ * <li> <b>"pending"</b>: The promise is not yet in a completed state (neither "rejected"; or "resolved").</li>
1691
+ * <li> <b>"resolved"</b>: The promise is in the resolved state.</li>
1692
+ * <li> <b>"rejected"</b>: The promise is in the rejected state.</li>
1693
+ * </ul>
1694
+ * @example
1695
+ * ```ts
1696
+ * let doResolve;
1697
+ * let promise: IPromise<any> = createSyncPromise((resolve) => {
1698
+ * doResolve = resolve;
1699
+ * });
1700
+ *
1701
+ * let state: string = promise.state();
1702
+ * console.log("State: " + state); // State: pending
1703
+ * doResolve(true); // Promise will resolve synchronously as it's a synchronous promise
1704
+ * console.log("State: " + state); // State: resolved
1705
+ * ```
1706
+ */
1707
+ state?: string;
1708
+ /**
1709
+ * Attaches callbacks for the resolution and/or rejection of the Promise.
1710
+ * @param onResolved The callback to execute when the Promise is resolved.
1711
+ * @param onRejected The callback to execute when the Promise is rejected.
1712
+ * @returns A Promise for the completion of which ever callback is executed.
1713
+ * @example
1714
+ * ```ts
1715
+ * const promise1 = createPromise((resolve, reject) => {
1716
+ * resolve('Success!');
1717
+ * });
1718
+ *
1719
+ * promise1.then((value) => {
1720
+ * console.log(value);
1721
+ * // expected output: "Success!"
1722
+ * });
1723
+ * ```
1724
+ */
1725
+ then<TResult1 = T, TResult2 = never>(onResolved?: ResolvedPromiseHandler<T, TResult1>, onRejected?: RejectedPromiseHandler<TResult2>): IPromise<TResult1 | TResult2>;
1726
+ /**
1727
+ * Attaches callbacks for the resolution and/or rejection of the Promise.
1728
+ * @param onResolved The callback to execute when the Promise is resolved.
1729
+ * @param onRejected The callback to execute when the Promise is rejected.
1730
+ * @returns A Promise for the completion of which ever callback is executed.
1731
+ * @example
1732
+ * ```ts
1733
+ * const promise1 = createPromise((resolve, reject) => {
1734
+ * resolve('Success!');
1735
+ * });
1736
+ *
1737
+ * promise1.then((value) => {
1738
+ * console.log(value);
1739
+ * // expected output: "Success!"
1740
+ * });
1741
+ * ```
1742
+ */
1743
+ then<TResult1 = T, TResult2 = never>(onResolved?: ResolvedPromiseHandler<T, TResult1>, onRejected?: RejectedPromiseHandler<TResult2>): PromiseLike<TResult1 | TResult2>;
1744
+ /**
1745
+ * Attaches callbacks for the resolution and/or rejection of the Promise.
1746
+ * @param onResolved The callback to execute when the Promise is resolved.
1747
+ * @param onRejected The callback to execute when the Promise is rejected.
1748
+ * @returns A Promise for the completion of which ever callback is executed.
1749
+ * @example
1750
+ * ```ts
1751
+ * const promise1 = createPromise((resolve, reject) => {
1752
+ * resolve('Success!');
1753
+ * });
1754
+ *
1755
+ * promise1.then((value) => {
1756
+ * console.log(value);
1757
+ * // expected output: "Success!"
1758
+ * });
1759
+ * ```
1760
+ */
1761
+ then<TResult1 = T, TResult2 = never>(onResolved?: ResolvedPromiseHandler<T, TResult1>, onRejected?: RejectedPromiseHandler<TResult2>): Promise<TResult1 | TResult2>;
1762
+ /**
1763
+ * Attaches a callback for only the rejection of the Promise.
1764
+ * @param onRejected The callback to execute when the Promise is rejected.
1765
+ * @returns A Promise for the completion of the callback.
1766
+ * @example
1767
+ * ```ts
1768
+ * const promise1 = createPromise((resolve, reject) => {
1769
+ * throw 'Uh-oh!';
1770
+ * });
1771
+ *
1772
+ * promise1.catch((error) => {
1773
+ * console.error(error);
1774
+ * });
1775
+ * // expected output: Uh-oh!
1776
+ * ```
1777
+ */
1778
+ catch<TResult = never>(onRejected?: ((reason: any) => TResult | IPromise<TResult>) | undefined | null): IPromise<T | TResult>;
1779
+ /**
1780
+ * Attaches a callback for only the rejection of the Promise.
1781
+ * @param onRejected The callback to execute when the Promise is rejected.
1782
+ * @returns A Promise for the completion of the callback.
1783
+ * @example
1784
+ * ```ts
1785
+ * const promise1 = createPromise((resolve, reject) => {
1786
+ * throw 'Uh-oh!';
1787
+ * });
1788
+ *
1789
+ * promise1.catch((error) => {
1790
+ * console.error(error);
1791
+ * });
1792
+ * // expected output: Uh-oh!
1793
+ * ```
1794
+ */
1795
+ catch<TResult = never>(onRejected?: ((reason: any) => TResult | IPromise<TResult>) | undefined | null): PromiseLike<T | TResult>;
1796
+ /**
1797
+ * Attaches a callback for only the rejection of the Promise.
1798
+ * @param onRejected The callback to execute when the Promise is rejected.
1799
+ * @returns A Promise for the completion of the callback.
1800
+ * @example
1801
+ * ```ts
1802
+ * const promise1 = createPromise((resolve, reject) => {
1803
+ * throw 'Uh-oh!';
1804
+ * });
1805
+ *
1806
+ * promise1.catch((error) => {
1807
+ * console.error(error);
1808
+ * });
1809
+ * // expected output: Uh-oh!
1810
+ * ```
1811
+ */
1812
+ catch<TResult = never>(onRejected?: ((reason: any) => TResult | IPromise<TResult>) | undefined | null): Promise<T | TResult>;
1813
+ /**
1814
+ * Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The
1815
+ * resolved value cannot be modified from the callback.
1816
+ * @param onfinally The callback to execute when the Promise is settled (fulfilled or rejected).
1817
+ * @returns A Promise for the completion of the callback.
1818
+ * @example
1819
+ * ```ts
1820
+ * function doFunction() {
1821
+ * return createPromise((resolve, reject) => {
1822
+ * if (Math.random() > 0.5) {
1823
+ * resolve('Function has completed');
1824
+ * } else {
1825
+ * reject(new Error('Function failed to process'));
1826
+ * }
1827
+ * });
1828
+ * }
1829
+ *
1830
+ * doFunction().then((data) => {
1831
+ * console.log(data);
1832
+ * }).catch((err) => {
1833
+ * console.error(err);
1834
+ * }).finally(() => {
1835
+ * console.log('Function processing completed');
1836
+ * });
1837
+ * ```
1838
+ */
1839
+ finally(onfinally?: FinallyPromiseHandler): IPromise<T>;
1840
+ /**
1841
+ * Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The
1842
+ * resolved value cannot be modified from the callback.
1843
+ * @param onfinally The callback to execute when the Promise is settled (fulfilled or rejected).
1844
+ * @returns A Promise for the completion of the callback.
1845
+ * @example
1846
+ * ```ts
1847
+ * function doFunction() {
1848
+ * return createPromise((resolve, reject) => {
1849
+ * if (Math.random() > 0.5) {
1850
+ * resolve('Function has completed');
1851
+ * } else {
1852
+ * reject(new Error('Function failed to process'));
1853
+ * }
1854
+ * });
1855
+ * }
1856
+ *
1857
+ * doFunction().then((data) => {
1858
+ * console.log(data);
1859
+ * }).catch((err) => {
1860
+ * console.error(err);
1861
+ * }).finally(() => {
1862
+ * console.log('Function processing completed');
1863
+ * });
1864
+ * ```
1865
+ */
1866
+ finally(onFinally?: FinallyPromiseHandler): Promise<T>;
1867
+ }
1868
+
1869
+ /**
1870
+ * The IPropertyStorageOverride interface provides a custom interface for storing internal SDK properties - otherwise they are
1871
+ * stored as cookies.
1872
+ * You need this interface when you intend to run auto collection for common properties, or when you log a session in
1873
+ * a non browser environment.
1874
+ */
1875
+ interface IPropertyStorageOverride {
1876
+ /**
1877
+ * A function for passing key value pairs to be stored.
1878
+ * @param key - The key for the key value pair.
1879
+ * @param value - The value for the key value pair.
1880
+ */
1881
+ setProperty: (key: string, value: string) => void;
1882
+ /**
1883
+ * A function that gets a value for a given key.
1884
+ * @param key - The key for which the value must be fetched.
1885
+ */
1886
+ getProperty: (key: string) => string;
1887
+ }
1888
+
1889
+ interface ITelemetryInitializerHandler extends ILegacyUnloadHook {
1890
+ remove(): void;
1891
+ }
1892
+
1893
+ /**
1894
+ * Telemety item supported in Core
1895
+ */
1896
+ interface ITelemetryItem {
1897
+ /**
1898
+ * CommonSchema Version of this SDK
1899
+ */
1900
+ ver?: string;
1901
+ /**
1902
+ * Unique name of the telemetry item
1903
+ */
1904
+ name: string;
1905
+ /**
1906
+ * Timestamp when item was sent
1907
+ */
1908
+ time?: string;
1909
+ /**
1910
+ * Identifier of the resource that uniquely identifies which resource data is sent to
1911
+ */
1912
+ iKey?: string;
1913
+ /**
1914
+ * System context properties of the telemetry item, example: ip address, city etc
1915
+ */
1916
+ ext?: {
1917
+ [key: string]: any;
1918
+ };
1919
+ /**
1920
+ * System context property extensions that are not global (not in ctx)
1921
+ */
1922
+ tags?: Tags & Tags[];
1923
+ /**
1924
+ * Custom data
1925
+ */
1926
+ data?: ICustomProperties;
1927
+ /**
1928
+ * Telemetry type used for part B
1929
+ */
1930
+ baseType?: string;
1931
+ /**
1932
+ * Based on schema for part B
1933
+ */
1934
+ baseData?: {
1935
+ [key: string]: any;
1936
+ };
1937
+ }
1938
+
1939
+ /**
1940
+ * Configuration provided to SDK core
1941
+ */
1942
+ interface ITelemetryPlugin extends ITelemetryProcessor, IPlugin {
1943
+ /**
1944
+ * Set next extension for telemetry processing, this is not optional as plugins should use the
1945
+ * processNext() function of the passed IProcessTelemetryContext instead. It is being kept for
1946
+ * now for backward compatibility only.
1947
+ */
1948
+ setNextPlugin?: (next: ITelemetryPlugin | ITelemetryPluginChain) => void;
1949
+ /**
1950
+ * Priority of the extension
1951
+ */
1952
+ readonly priority: number;
1953
+ }
1954
+
1955
+ /**
1956
+ * Configuration provided to SDK core
1957
+ */
1958
+ interface ITelemetryPluginChain extends ITelemetryProcessor {
1959
+ /**
1960
+ * Returns the underlying plugin that is being proxied for the processTelemetry call
1961
+ */
1962
+ getPlugin: () => ITelemetryPlugin;
1963
+ /**
1964
+ * Returns the next plugin
1965
+ */
1966
+ getNext: () => ITelemetryPluginChain;
1967
+ /**
1968
+ * This plugin is being unloaded and should remove any hooked events and cleanup any global/scoped values, after this
1969
+ * call the plugin will be removed from the telemetry processing chain and will no longer receive any events..
1970
+ * @param unloadCtx - The unload context to use for this call.
1971
+ * @param unloadState - The details of the unload operation
1972
+ */
1973
+ unload?: (unloadCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
1974
+ }
1975
+
1976
+ interface ITelemetryProcessor {
1977
+ /**
1978
+ * Call back for telemetry processing before it it is sent
1979
+ * @param env - This is the current event being reported
1980
+ * @param itemCtx - This is the context for the current request, ITelemetryPlugin instances
1981
+ * can optionally use this to access the current core instance or define / pass additional information
1982
+ * to later plugins (vs appending items to the telemetry item)
1983
+ */
1984
+ processTelemetry: (env: ITelemetryItem, itemCtx?: IProcessTelemetryContext) => void;
1985
+ /**
1986
+ * The the plugin should re-evaluate configuration and update any cached configuration settings or
1987
+ * plugins. If implemented this method will be called whenever a plugin is added or removed and if
1988
+ * the configuration has bee updated.
1989
+ * @param updateCtx - This is the context that should be used during updating.
1990
+ * @param updateState - The details / state of the update process, it holds details like the current and previous configuration.
1991
+ * @returns boolean - true if the plugin has or will call updateCtx.processNext(), this allows the plugin to perform any asynchronous operations.
1992
+ */
1993
+ update?: (updateCtx: IProcessTelemetryUpdateContext, updateState: ITelemetryUpdateState) => void | boolean;
1994
+ }
1995
+
1996
+ interface ITelemetryUnloadState {
1997
+ reason: TelemetryUnloadReason;
1998
+ isAsync: boolean;
1999
+ flushComplete?: boolean;
2000
+ }
2001
+
2002
+ interface ITelemetryUpdateState {
2003
+ /**
2004
+ * Identifies the reason for the update notification, this is a bitwise numeric value
2005
+ */
2006
+ reason: TelemetryUpdateReason;
2007
+ /**
2008
+ * This is a new active configuration that should be used
2009
+ */
2010
+ cfg?: IConfiguration;
2011
+ /**
2012
+ * The detected changes
2013
+ */
2014
+ oldCfg?: IConfiguration;
2015
+ /**
2016
+ * If this is a configuration update this was the previous configuration that was used
2017
+ */
2018
+ newConfig?: IConfiguration;
2019
+ /**
2020
+ * Was the new config requested to be merged with the existing config
2021
+ */
2022
+ merge?: boolean;
2023
+ /**
2024
+ * This holds a collection of plugins that have been added (if the reason identifies that one or more plugins have been added)
2025
+ */
2026
+ added?: IPlugin[];
2027
+ /**
2028
+ * This holds a collection of plugins that have been removed (if the reason identifies that one or more plugins have been removed)
2029
+ */
2030
+ removed?: IPlugin[];
2031
+ }
2032
+
2033
+ /**
2034
+ * A Timer handler which is returned from {@link scheduleTimeout} which contains functions to
2035
+ * cancel or restart (refresh) the timeout function.
2036
+ *
2037
+ * @since 0.4.4
2038
+ * @group Timer
2039
+ */
2040
+ interface ITimerHandler {
2041
+ /**
2042
+ * Cancels a timeout that was previously scheduled, after calling this function any previously
2043
+ * scheduled timer will not execute.
2044
+ * @example
2045
+ * ```ts
2046
+ * let theTimer = scheduleTimeout(...);
2047
+ * theTimer.cancel();
2048
+ * ```
2049
+ */
2050
+ cancel(): void;
2051
+ /**
2052
+ * Reschedules the timer to call its callback at the previously specified duration
2053
+ * adjusted to the current time. This is useful for refreshing a timer without allocating
2054
+ * a new JavaScript object.
2055
+ *
2056
+ * Using this on a timer that has already called its callback will reactivate the timer.
2057
+ * Calling on a timer that has not yet executed will just reschedule the current timer.
2058
+ * @example
2059
+ * ```ts
2060
+ * let theTimer = scheduleTimeout(...);
2061
+ * // The timer will be restarted (if already executed) or rescheduled (if it has not yet executed)
2062
+ * theTimer.refresh();
2063
+ * ```
2064
+ */
2065
+ refresh(): ITimerHandler;
2066
+ /**
2067
+ * When called, requests that the event loop not exit so long when the ITimerHandler is active.
2068
+ * Calling timer.ref() multiple times will have no effect. By default, all ITimerHandler objects
2069
+ * will create "ref'ed" instances, making it normally unnecessary to call timer.ref() unless
2070
+ * timer.unref() had been called previously.
2071
+ * @since 0.7.0
2072
+ * @returns the ITimerHandler instance
2073
+ * @example
2074
+ * ```ts
2075
+ * let theTimer = createTimeout(...);
2076
+ *
2077
+ * // Make sure the timer is referenced (the default) so that the runtime (Node) does not terminate
2078
+ * // if there is a waiting referenced timer.
2079
+ * theTimer.ref();
2080
+ * ```
2081
+ */
2082
+ ref(): this;
2083
+ /**
2084
+ * When called, the any active ITimerHandler instance will not require the event loop to remain
2085
+ * active (Node.js). If there is no other activity keeping the event loop running, the process may
2086
+ * exit before the ITimerHandler instance callback is invoked. Calling timer.unref() multiple times
2087
+ * will have no effect.
2088
+ * @since 0.7.0
2089
+ * @returns the ITimerHandler instance
2090
+ * @example
2091
+ * ```ts
2092
+ * let theTimer = createTimeout(...);
2093
+ *
2094
+ * // Unreference the timer so that the runtime (Node) may terminate if nothing else is running.
2095
+ * theTimer.unref();
2096
+ * ```
2097
+ */
2098
+ unref(): this;
2099
+ /**
2100
+ * If true, any running referenced `ITimerHandler` instance will keep the Node.js event loop active.
2101
+ * @since 0.7.0
2102
+ * @example
2103
+ * ```ts
2104
+ * let theTimer = createTimeout(...);
2105
+ *
2106
+ * // Unreference the timer so that the runtime (Node) may terminate if nothing else is running.
2107
+ * theTimer.unref();
2108
+ * let hasRef = theTimer.hasRef(); // false
2109
+ *
2110
+ * theTimer.ref();
2111
+ * hasRef = theTimer.hasRef(); // true
2112
+ * ```
2113
+ */
2114
+ hasRef(): boolean;
2115
+ /**
2116
+ * Gets or Sets a flag indicating if the underlying timer is currently enabled and running.
2117
+ * Setting the enabled flag to the same as it's current value has no effect, setting to `true`
2118
+ * when already `true` will not {@link ITimerHandler.refresh | refresh}() the timer.
2119
+ * And setting to 'false` will {@link ITimerHandler.cancel | cancel}() the timer.
2120
+ * @since 0.8.1
2121
+ * @example
2122
+ * ```ts
2123
+ * let theTimer = createTimeout(...);
2124
+ *
2125
+ * // Check if enabled
2126
+ * theTimer.enabled; // false
2127
+ *
2128
+ * // Start the timer
2129
+ * theTimer.enabled = true; // Same as calling refresh()
2130
+ * theTimer.enabled; //true
2131
+ *
2132
+ * // Has no effect as it's already running
2133
+ * theTimer.enabled = true;
2134
+ *
2135
+ * // Will refresh / restart the time
2136
+ * theTimer.refresh()
2137
+ *
2138
+ * let theTimer = scheduleTimeout(...);
2139
+ *
2140
+ * // Check if enabled
2141
+ * theTimer.enabled; // true
2142
+ * ```
2143
+ */
2144
+ enabled: boolean;
2145
+ }
2146
+
2147
+ /**
2148
+ * An interface which provides automatic removal during unloading of the component
2149
+ */
2150
+ interface IUnloadHook {
2151
+ /**
2152
+ * Self remove the referenced component
2153
+ */
2154
+ rm: () => void;
2155
+ }
2156
+
2157
+ /**
2158
+ * Interface which identifiesAdd this hook so that it is automatically removed during unloading
2159
+ * @param hooks - The single hook or an array of IInstrumentHook objects
2160
+ */
2161
+ interface IUnloadHookContainer {
2162
+ add: (hooks: IUnloadHook | IUnloadHook[] | Iterator<IUnloadHook> | ILegacyUnloadHook | ILegacyUnloadHook[] | Iterator<ILegacyUnloadHook>) => void;
2163
+ run: (logger?: IDiagnosticLogger) => void;
2164
+ }
2165
+
2166
+ /**
2167
+ * This interface is used during the serialization of events into envelope (serialized object) which is sent to the services, the format is defined via the
2168
+ * [Common Schema 4.0](https://aka.ms/CommonSchema) specification. The path and field names used are based on how the data is serialized
2169
+ * to the service (CS 4.0 location) and not specifically the location on the event object you pass into the track methods (unless they are the same).
2170
+ */
2171
+ interface IValueSanitizer {
2172
+ /**
2173
+ * Add a value sanitizer as a fallback sanitizer if this sanitizer can't handle the path/name.
2174
+ */
2175
+ addSanitizer: (sanitizer: IValueSanitizer) => void;
2176
+ /**
2177
+ * Adds a field sanitizer to the evaluation list
2178
+ */
2179
+ addFieldSanitizer: (fieldSanitizer: IFieldValueSanitizerProvider) => void;
2180
+ /**
2181
+ * Removes the value sanitizer as a fallback sanitizer if this sanitizer can't handle the path/name if present.
2182
+ */
2183
+ rmSanitizer: (theSanitizer: IValueSanitizer) => void;
2184
+ /**
2185
+ * Removes the field sanitizer to the evaluation list if present
2186
+ */
2187
+ rmFieldSanitizer: (theFieldSanitizer: IFieldValueSanitizerProvider) => void;
2188
+ /**
2189
+ * Does this field value sanitizer handle this path / field combination
2190
+ * @param path - The field path
2191
+ * @param name - The name of the field
2192
+ */
2193
+ handleField: (path: string, name: string) => boolean;
2194
+ /**
2195
+ * Sanitizes the value. It checks the that the property name and value are valid. It also
2196
+ * checks/populates the correct type and pii of the property value.
2197
+ * @param path - The root path of the property
2198
+ * @param name - The property name.
2199
+ * @param value - The property value or an IEventProperty containing value, type ,pii and customer content.
2200
+ * @param stringifyObjects - If supplied tells the sanitizer that it should JSON stringify() objects
2201
+ * @returns IEventProperty containing valid name, value, pii and type or null if invalid.
2202
+ */
2203
+ value: (path: string, name: string, value: FieldValueSanitizerTypes, stringifyObjects?: boolean) => IEventProperty | null;
2204
+ /**
2205
+ * Sanitizes the Property. It checks the that the property name and value are valid. It also
2206
+ * checks/populates the correct type and pii of the property value.
2207
+ * @param path - The root path of the property
2208
+ * @param name - The property name.
2209
+ * @param property - The property value or an IEventProperty containing value, type ,pii and customer content.
2210
+ * @param stringifyObjects - If supplied tells the sanitizer that it should JSON stringify() objects
2211
+ * @returns IEventProperty containing valid name, value, pii and type or null if invalid.
2212
+ */
2213
+ property: (path: string, name: string, property: IEventProperty, stringifyObjects?: boolean) => IEventProperty | null;
2214
+ }
2215
+
2216
+ interface IWatchDetails<T = IConfiguration> {
2217
+ /**
2218
+ * The current config object
2219
+ */
2220
+ cfg: T;
2221
+ /**
2222
+ * Set the value against the provided config/name with the value, the property
2223
+ * will be converted to be dynamic (if not already) as long as the provided config
2224
+ * is already a tracked dynamic object.
2225
+ * @throws TypeError if the provided config is not a monitored dynamic config
2226
+ */
2227
+ set: <C, V>(theConfig: C, name: string, value: V) => V;
2228
+ /**
2229
+ * Set default values for the config if not present.
2230
+ * @param theConfig - The configuration object to set default on (if missing)
2231
+ * @param defaultValues - The default values to apply to the config
2232
+ */
2233
+ setDf: <C>(theConfig: C, defaultValues: IConfigDefaults<C>) => C;
2234
+ /**
2235
+ * Set this named property of the target as referenced, which will cause any object or array instance
2236
+ * to be updated in-place rather than being entirely replaced. All other values will continue to be replaced.
2237
+ * @returns The referenced properties current value
2238
+ */
2239
+ ref: <C, V = any>(target: C, name: string) => V;
2240
+ /**
2241
+ * Set this named property of the target as read-only, which will block this single named property from
2242
+ * ever being changed for the target instance.
2243
+ * This does NOT freeze or seal the instance, it just stops the direct re-assignment of the named property,
2244
+ * if the value is a non-primitive (ie. an object or array) it's properties will still be mutable.
2245
+ * @returns The referenced properties current value
2246
+ */
2247
+ rdOnly: <C, V = any>(target: C, name: string) => V;
2248
+ }
2249
+
2250
+ /**
2251
+ * The IXHROverride interface overrides the way HTTP requests are sent.
2252
+ */
2253
+ interface IXHROverride {
2254
+ sendPOST: SendPOSTFunction;
2255
+ }
2256
+
2257
+ const LoggingSeverity: EnumValue<typeof eLoggingSeverity>;
2258
+
2259
+ type LoggingSeverity = number | eLoggingSeverity;
2260
+
2261
+ /**
2262
+ * Near Real Time profile. RealTime Latency events are sent every 3 sec and
2263
+ * Normal Latency events are sent every 6 sec.
2264
+ */
2265
+ const NRT_PROFILE = "NEAR_REAL_TIME";
2266
+
2267
+ type OnCompleteCallback = (status: number, headers: {
2268
+ [headerName: string]: string;
2269
+ }, response?: string) => void;
2270
+
2271
+ /**
2272
+ * Defines the function signature of a payload listener, which is called after the payload has been sent to the server. The listener is passed
2273
+ * 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.
2274
+ * Used by the Remove DDV extension to listen to server send events.
2275
+ * @param orgPayload - The initially constructed payload object
2276
+ * @param sendPayload - The alternative (possibly modified by a preprocessor) payload
2277
+ * @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.
2278
+ * @param isBeaconSend - A boolean flag indicating whether the payload was sent using the navigator.sendBeacon() API.
2279
+ */
2280
+ type PayloadListenerFunction = (orgPayload: IPayloadData, sendPayload?: IPayloadData, isSync?: boolean, isBeaconSend?: boolean) => void;
2281
+
2282
+ /**
2283
+ * Defines the function signature for the Payload Preprocessor.
2284
+ * @param payload - The Initial constructed payload that if not modified should be passed onto the callback function.
2285
+ * @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.
2286
+ * The modifiedBuffer argument can be either the original payload or may be modified by performing GZipping of the payload and adding the content header.
2287
+ * @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.
2288
+ * 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.
2289
+ */
2290
+ type PayloadPreprocessorFunction = (payload: IPayloadData, callback: (modifiedBuffer: IPayloadData) => void, isSync?: boolean) => void;
2291
+
2292
+ /**
2293
+ * Class that manages adding events to inbound queues and batching of events
2294
+ * into requests.
2295
+ * @group Classes
2296
+ * @group Entrypoint
2297
+ */
2298
+ class PostChannel extends BaseTelemetryPlugin implements IChannelControls, IPostChannel {
2299
+ identifier: string;
2300
+ priority: number;
2301
+ version: string;
2302
+ constructor();
2303
+ /**
2304
+ * Start the queue manager to batch and send events via post.
2305
+ * @param config - The core configuration.
2306
+ */
2307
+ initialize(coreConfig: IExtendedConfiguration, core: IAppInsightsCore, extensions: IPlugin[]): void;
2308
+ /**
2309
+ * Add an event to the appropriate inbound queue based on its latency.
2310
+ * @param ev - The event to be added to the queue.
2311
+ * @param itemCtx - This is the context for the current request, ITelemetryPlugin instances
2312
+ * can optionally use this to access the current core instance or define / pass additional information
2313
+ * to later plugins (vs appending items to the telemetry item)
2314
+ */
2315
+ processTelemetry(ev: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
2316
+ /**
2317
+ * Sets the event queue limits at runtime (after initialization), if the number of queued events is greater than the
2318
+ * eventLimit or autoFlushLimit then a flush() operation will be scheduled.
2319
+ * @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
2320
+ * equal to zero the value will be reset to the default (10,000).
2321
+ * @param autoFlushLimit When defined, once this number of events has been queued the system perform a flush() to send the queued events
2322
+ * without waiting for the normal schedule timers. Passing undefined, null or a value less than or equal to zero will disable the auto flush.
2323
+ */
2324
+ setEventQueueLimits(eventLimit: number, autoFlushLimit?: number): void;
2325
+ /**
2326
+ * Pause the transmission of any requests
2327
+ */
2328
+ pause(): void;
2329
+ /**
2330
+ * Resumes transmission of events.
2331
+ */
2332
+ resume(): void;
2333
+ /**
2334
+ * Add handler to be executed with request response text.
2335
+ */
2336
+ addResponseHandler(responseHanlder: (responseText: string) => void): IUnloadHook;
2337
+ /**
2338
+ * Flush to send data immediately; channel should default to sending data asynchronously. If executing asynchronously (the default) and
2339
+ * you DO NOT pass a callback function then a [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html)
2340
+ * will be returned which will resolve once the flush is complete. The actual implementation of the `IPromise`
2341
+ * will be a native Promise (if supported) or the default as supplied by [ts-async library](https://github.com/nevware21/ts-async)
2342
+ * @param async - send data asynchronously when true
2343
+ * @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.
2344
+ * If the caller doesn't return true the caller should assume that it may never be called.
2345
+ * @param sendReason - specify the reason that you are calling "flush" defaults to ManualFlush (1) if not specified
2346
+ * @returns - If a callback is provided `true` to indicate that callback will be called after the flush is complete otherwise the caller
2347
+ * should assume that any provided callback will never be called, Nothing or if occurring asynchronously a
2348
+ * [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html) which will be resolved once the unload is complete,
2349
+ * the [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html) will only be returned when no callback is provided
2350
+ * and async is true.
2351
+ */
2352
+ flush(async?: boolean, callBack?: (flushComplete?: boolean) => void, sendReason?: SendRequestReason): boolean | void | IPromise<boolean>;
326
2353
  /**
327
2354
  * Set AuthMsaDeviceTicket header
328
2355
  * @param ticket - Ticket value.
@@ -369,12 +2396,132 @@ declare namespace oneDS {
369
2396
  _clearBackOff(): void;
370
2397
  }
371
2398
 
2399
+ /**
2400
+ * This defines the handler function for when a promise is rejected.
2401
+ * @param value This is the value passed as part of resolving the Promise
2402
+ * @return This may return a value, another Promise or void. @see {@link IPromise.then} for how the value is handled.
2403
+ */
2404
+ type RejectedPromiseHandler<T = never> = (((reason: any) => T | IPromise<T> | PromiseLike<T>) | undefined | null);
2405
+
2406
+ /**
2407
+ * This defines the handler function for when a promise is resolved.
2408
+ * @param value This is the value passed as part of resolving the Promise
2409
+ * @return This may return a value, another Promise or void. @see {@link IPromise.then} for how the value is handled.
2410
+ */
2411
+ type ResolvedPromiseHandler<T, TResult1 = T> = (((value: T) => TResult1 | IPromise<TResult1> | PromiseLike<TResult1>) | undefined | null);
2412
+
372
2413
  /**
373
2414
  * Real Time profile (default profile). RealTime Latency events are sent every 1 sec and
374
2415
  * Normal Latency events are sent every 2 sec.
375
2416
  */
376
2417
  const RT_PROFILE = "REAL_TIME";
377
2418
 
378
-
379
-
2419
+ /**
2420
+ * SendPOSTFunction type defines how an HTTP POST request is sent to an ingestion server
2421
+ * @param payload - The payload object that should be sent, contains the url, bytes/string and headers for the request
2422
+ * @param oncomplete - The function to call once the request has completed whether a success, failure or timeout
2423
+ * @param sync - A boolean flag indicating whether the request should be sent as a synchronous request.
2424
+ */
2425
+ type SendPOSTFunction = (payload: IPayloadData, oncomplete: OnCompleteCallback, sync?: boolean) => void | IPromise<boolean>;
2426
+
2427
+ /**
2428
+ * The EventsDiscardedReason enumeration contains a set of values that specify the reason for discarding an event.
2429
+ */
2430
+ const enum SendRequestReason {
2431
+ /**
2432
+ * No specific reason was specified
2433
+ */
2434
+ Undefined = 0,
2435
+ /**
2436
+ * Events are being sent based on the normal event schedule / timer.
2437
+ */
2438
+ NormalSchedule = 1,
2439
+ /**
2440
+ * A manual flush request was received
2441
+ */
2442
+ ManualFlush = 1,
2443
+ /**
2444
+ * Unload event is being processed
2445
+ */
2446
+ Unload = 2,
2447
+ /**
2448
+ * The event(s) being sent are sync events
2449
+ */
2450
+ SyncEvent = 3,
2451
+ /**
2452
+ * The Channel was resumed
2453
+ */
2454
+ Resumed = 4,
2455
+ /**
2456
+ * The event(s) being sent as a retry
2457
+ */
2458
+ Retry = 5,
2459
+ /**
2460
+ * The SDK is unloading
2461
+ */
2462
+ SdkUnload = 6,
2463
+ /**
2464
+ * Maximum batch size would be exceeded
2465
+ */
2466
+ MaxBatchSize = 10,
2467
+ /**
2468
+ * The Maximum number of events have already been queued
2469
+ */
2470
+ MaxQueuedEvents = 20
2471
+ }
2472
+
2473
+ interface Tags {
2474
+ [key: string]: any;
2475
+ }
2476
+
2477
+ type TelemetryInitializerFunction = <T extends ITelemetryItem>(item: T) => boolean | void;
2478
+
2479
+ /**
2480
+ * The TelemetryUnloadReason enumeration contains the possible reasons for why a plugin is being unloaded / torndown().
2481
+ */
2482
+ const enum TelemetryUnloadReason {
2483
+ /**
2484
+ * Teardown has been called without any context.
2485
+ */
2486
+ ManualTeardown = 0,
2487
+ /**
2488
+ * Just this plugin is being removed
2489
+ */
2490
+ PluginUnload = 1,
2491
+ /**
2492
+ * This instance of the plugin is being removed and replaced
2493
+ */
2494
+ PluginReplace = 2,
2495
+ /**
2496
+ * The entire SDK is being unloaded
2497
+ */
2498
+ SdkUnload = 50
2499
+ }
2500
+
2501
+ /**
2502
+ * The TelemetryUpdateReason enumeration contains a set of bit-wise values that specify the reason for update request.
2503
+ */
2504
+ const enum TelemetryUpdateReason {
2505
+ /**
2506
+ * Unknown.
2507
+ */
2508
+ Unknown = 0,
2509
+ /**
2510
+ * The configuration has ben updated or changed
2511
+ */
2512
+ ConfigurationChanged = 1,
2513
+ /**
2514
+ * One or more plugins have been added
2515
+ */
2516
+ PluginAdded = 16,
2517
+ /**
2518
+ * One or more plugins have been removed
2519
+ */
2520
+ PluginRemoved = 32
2521
+ }
2522
+
2523
+ type UnloadHandler = (itemCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
2524
+
2525
+ type WatcherFunction<T = IConfiguration> = (details: IWatchDetails<T>) => void;
2526
+
380
2527
  }