@microsoft/applicationinsights-debugplugin-js 3.0.7 → 3.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/browser/es5/{ai.dbg.3.0.7.cjs.js → ai.dbg.3.0.9.cjs.js} +224 -207
  2. package/browser/es5/ai.dbg.3.0.9.cjs.js.map +1 -0
  3. package/browser/es5/ai.dbg.3.0.9.cjs.min.js +6 -0
  4. package/browser/es5/ai.dbg.3.0.9.cjs.min.js.map +1 -0
  5. package/browser/es5/{ai.dbg.3.0.7.gbl.js → ai.dbg.3.0.9.gbl.js} +226 -209
  6. package/browser/es5/ai.dbg.3.0.9.gbl.js.map +1 -0
  7. package/browser/es5/ai.dbg.3.0.9.gbl.min.js +6 -0
  8. package/browser/es5/ai.dbg.3.0.9.gbl.min.js.map +1 -0
  9. package/browser/es5/ai.dbg.3.0.9.integrity.json +66 -0
  10. package/browser/es5/{ai.dbg.3.0.7.js → ai.dbg.3.0.9.js} +226 -209
  11. package/browser/es5/ai.dbg.3.0.9.js.map +1 -0
  12. package/browser/es5/ai.dbg.3.0.9.min.js +6 -0
  13. package/browser/es5/ai.dbg.3.0.9.min.js.map +1 -0
  14. package/browser/es5/ai.dbg.3.cjs.js +223 -206
  15. package/browser/es5/ai.dbg.3.cjs.js.map +1 -1
  16. package/browser/es5/ai.dbg.3.cjs.min.js +2 -2
  17. package/browser/es5/ai.dbg.3.cjs.min.js.map +1 -1
  18. package/browser/es5/ai.dbg.3.gbl.js +225 -208
  19. package/browser/es5/ai.dbg.3.gbl.js.map +1 -1
  20. package/browser/es5/ai.dbg.3.gbl.min.js +2 -2
  21. package/browser/es5/ai.dbg.3.gbl.min.js.map +1 -1
  22. package/browser/es5/ai.dbg.3.integrity.json +25 -25
  23. package/browser/es5/ai.dbg.3.js +225 -208
  24. package/browser/es5/ai.dbg.3.js.map +1 -1
  25. package/browser/es5/ai.dbg.3.min.js +2 -2
  26. package/browser/es5/ai.dbg.3.min.js.map +1 -1
  27. package/dist/es5/applicationinsights-debugplugin-js.js +223 -206
  28. package/dist/es5/applicationinsights-debugplugin-js.js.map +1 -1
  29. package/dist/es5/applicationinsights-debugplugin-js.min.js +2 -2
  30. package/dist/es5/applicationinsights-debugplugin-js.min.js.map +1 -1
  31. package/dist-es5/DebugPlugin.js +1 -1
  32. package/dist-es5/__DynamicConstants.js +1 -1
  33. package/dist-es5/applicationinsights-debugplugin-js.js +1 -1
  34. package/dist-es5/components/Dashboard.js +1 -1
  35. package/dist-es5/components/LogEntry.js +1 -1
  36. package/dist-es5/components/debugBins.js +1 -1
  37. package/dist-es5/components/filterList.js +1 -1
  38. package/dist-es5/components/helpers.js +1 -1
  39. package/dist-es5/components/styleNodeSrc.js +1 -1
  40. package/dist-es5/interfaces/IDebugPluginConfig.js +1 -1
  41. package/package.json +64 -61
  42. package/types/applicationinsights-debugplugin-js.d.ts +2 -2
  43. package/types/applicationinsights-debugplugin-js.namespaced.d.ts +1942 -9
  44. package/browser/es5/ai.dbg.3.0.7.cjs.js.map +0 -1
  45. package/browser/es5/ai.dbg.3.0.7.cjs.min.js +0 -6
  46. package/browser/es5/ai.dbg.3.0.7.cjs.min.js.map +0 -1
  47. package/browser/es5/ai.dbg.3.0.7.gbl.js.map +0 -1
  48. package/browser/es5/ai.dbg.3.0.7.gbl.min.js +0 -6
  49. package/browser/es5/ai.dbg.3.0.7.gbl.min.js.map +0 -1
  50. package/browser/es5/ai.dbg.3.0.7.integrity.json +0 -66
  51. package/browser/es5/ai.dbg.3.0.7.js.map +0 -1
  52. package/browser/es5/ai.dbg.3.0.7.min.js +0 -6
  53. package/browser/es5/ai.dbg.3.0.7.min.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Microsoft.ApplicationInsights, 3.0.7
2
+ * Microsoft.ApplicationInsights, 3.0.9
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  *
5
5
  * Microsoft Application Insights Team
@@ -7,13 +7,104 @@
7
7
  */
8
8
 
9
9
  declare namespace ApplicationInsights {
10
- import { BaseTelemetryPlugin } from '@microsoft/applicationinsights-core-js';
11
- import { IAppInsightsCore } from '@microsoft/applicationinsights-core-js';
12
- import { IConfiguration } from '@microsoft/applicationinsights-core-js';
13
- import { IPlugin } from '@microsoft/applicationinsights-core-js';
14
- import { IProcessTelemetryContext } from '@microsoft/applicationinsights-core-js';
15
- import { ITelemetryItem } from '@microsoft/applicationinsights-core-js';
16
- import { ITelemetryPluginChain } from '@microsoft/applicationinsights-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
+ }
17
108
 
18
109
  class DebugPlugin extends BaseTelemetryPlugin {
19
110
  static identifier: string;
@@ -23,6 +114,740 @@ declare namespace ApplicationInsights {
23
114
  processTelemetry(event: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
24
115
  }
25
116
 
117
+ const enum _eInternalMessageId {
118
+ BrowserDoesNotSupportLocalStorage = 0,
119
+ BrowserCannotReadLocalStorage = 1,
120
+ BrowserCannotReadSessionStorage = 2,
121
+ BrowserCannotWriteLocalStorage = 3,
122
+ BrowserCannotWriteSessionStorage = 4,
123
+ BrowserFailedRemovalFromLocalStorage = 5,
124
+ BrowserFailedRemovalFromSessionStorage = 6,
125
+ CannotSendEmptyTelemetry = 7,
126
+ ClientPerformanceMathError = 8,
127
+ ErrorParsingAISessionCookie = 9,
128
+ ErrorPVCalc = 10,
129
+ ExceptionWhileLoggingError = 11,
130
+ FailedAddingTelemetryToBuffer = 12,
131
+ FailedMonitorAjaxAbort = 13,
132
+ FailedMonitorAjaxDur = 14,
133
+ FailedMonitorAjaxOpen = 15,
134
+ FailedMonitorAjaxRSC = 16,
135
+ FailedMonitorAjaxSend = 17,
136
+ FailedMonitorAjaxGetCorrelationHeader = 18,
137
+ FailedToAddHandlerForOnBeforeUnload = 19,
138
+ FailedToSendQueuedTelemetry = 20,
139
+ FailedToReportDataLoss = 21,
140
+ FlushFailed = 22,
141
+ MessageLimitPerPVExceeded = 23,
142
+ MissingRequiredFieldSpecification = 24,
143
+ NavigationTimingNotSupported = 25,
144
+ OnError = 26,
145
+ SessionRenewalDateIsZero = 27,
146
+ SenderNotInitialized = 28,
147
+ StartTrackEventFailed = 29,
148
+ StopTrackEventFailed = 30,
149
+ StartTrackFailed = 31,
150
+ StopTrackFailed = 32,
151
+ TelemetrySampledAndNotSent = 33,
152
+ TrackEventFailed = 34,
153
+ TrackExceptionFailed = 35,
154
+ TrackMetricFailed = 36,
155
+ TrackPVFailed = 37,
156
+ TrackPVFailedCalc = 38,
157
+ TrackTraceFailed = 39,
158
+ TransmissionFailed = 40,
159
+ FailedToSetStorageBuffer = 41,
160
+ FailedToRestoreStorageBuffer = 42,
161
+ InvalidBackendResponse = 43,
162
+ FailedToFixDepricatedValues = 44,
163
+ InvalidDurationValue = 45,
164
+ TelemetryEnvelopeInvalid = 46,
165
+ CreateEnvelopeError = 47,
166
+ MaxUnloadHookExceeded = 48,
167
+ CannotSerializeObject = 48,
168
+ CannotSerializeObjectNonSerializable = 49,
169
+ CircularReferenceDetected = 50,
170
+ ClearAuthContextFailed = 51,
171
+ ExceptionTruncated = 52,
172
+ IllegalCharsInName = 53,
173
+ ItemNotInArray = 54,
174
+ MaxAjaxPerPVExceeded = 55,
175
+ MessageTruncated = 56,
176
+ NameTooLong = 57,
177
+ SampleRateOutOfRange = 58,
178
+ SetAuthContextFailed = 59,
179
+ SetAuthContextFailedAccountName = 60,
180
+ StringValueTooLong = 61,
181
+ StartCalledMoreThanOnce = 62,
182
+ StopCalledWithoutStart = 63,
183
+ TelemetryInitializerFailed = 64,
184
+ TrackArgumentsNotSpecified = 65,
185
+ UrlTooLong = 66,
186
+ SessionStorageBufferFull = 67,
187
+ CannotAccessCookie = 68,
188
+ IdTooLong = 69,
189
+ InvalidEvent = 70,
190
+ FailedMonitorAjaxSetRequestHeader = 71,
191
+ SendBrowserInfoOnUserInit = 72,
192
+ PluginException = 73,
193
+ NotificationException = 74,
194
+ SnippetScriptLoadFailure = 99,
195
+ InvalidInstrumentationKey = 100,
196
+ CannotParseAiBlobValue = 101,
197
+ InvalidContentBlob = 102,
198
+ TrackPageActionEventFailed = 103,
199
+ FailedAddingCustomDefinedRequestContext = 104,
200
+ InMemoryStorageBufferFull = 105,
201
+ InstrumentationKeyDeprecation = 106,
202
+ ConfigWatcherException = 107,
203
+ DynamicConfigException = 108,
204
+ DefaultThrottleMsgKey = 109,
205
+ CdnDeprecation = 110,
206
+ SdkLdrUpdate = 111
207
+ }
208
+
209
+ const enum eLoggingSeverity {
210
+ /**
211
+ * No Logging will be enabled
212
+ */
213
+ DISABLED = 0,
214
+ /**
215
+ * Error will be sent as internal telemetry
216
+ */
217
+ CRITICAL = 1,
218
+ /**
219
+ * Error will NOT be sent as internal telemetry, and will only be shown in browser console
220
+ */
221
+ WARNING = 2,
222
+ /**
223
+ * The Error will NOT be sent as an internal telemetry, and will only be shown in the browser
224
+ * console if the logging level allows it.
225
+ */
226
+ DEBUG = 3
227
+ }
228
+
229
+ /**
230
+ * A type that identifies an enum class generated from a constant enum.
231
+ * @group Enum
232
+ * @typeParam E - The constant enum type
233
+ *
234
+ * Returned from {@link createEnum}
235
+ */
236
+ type EnumCls<E = any> = {
237
+ readonly [key in keyof E extends string | number | symbol ? keyof E : never]: key extends string ? E[key] : key;
238
+ } & {
239
+ readonly [key in keyof E]: E[key];
240
+ };
241
+
242
+ type EnumValue<E = any> = EnumCls<E>;
243
+
244
+ const enum FeatureOptInMode {
245
+ /**
246
+ * not set, completely depends on cdn cfg
247
+ */
248
+ none = 1,
249
+ /**
250
+ * try to not apply config from cdn
251
+ */
252
+ disable = 2,
253
+ /**
254
+ * try to apply config from cdn
255
+ */
256
+ enable = 3
257
+ }
258
+
259
+ /**
260
+ * This defines the handler function that is called via the finally when the promise is resolved or rejected
261
+ */
262
+ type FinallyPromiseHandler = (() => void) | undefined | null;
263
+
264
+ interface IAppInsightsCore<CfgType extends IConfiguration = IConfiguration> extends IPerfManagerProvider {
265
+ readonly config: CfgType;
266
+ /**
267
+ * The current logger instance for this instance.
268
+ */
269
+ readonly logger: IDiagnosticLogger;
270
+ /**
271
+ * An array of the installed plugins that provide a version
272
+ */
273
+ readonly pluginVersionStringArr: string[];
274
+ /**
275
+ * The formatted string of the installed plugins that contain a version number
276
+ */
277
+ readonly pluginVersionString: string;
278
+ /**
279
+ * Returns a value that indicates whether the instance has already been previously initialized.
280
+ */
281
+ isInitialized?: () => boolean;
282
+ initialize(config: CfgType, extensions: IPlugin[], logger?: IDiagnosticLogger, notificationManager?: INotificationManager): void;
283
+ getChannels(): IChannelControls[];
284
+ track(telemetryItem: ITelemetryItem): void;
285
+ /**
286
+ * Get the current notification manager
287
+ */
288
+ getNotifyMgr(): INotificationManager;
289
+ /**
290
+ * Get the current cookie manager for this instance
291
+ */
292
+ getCookieMgr(): ICookieMgr;
293
+ /**
294
+ * Set the current cookie manager for this instance
295
+ * @param cookieMgr - The manager, if set to null/undefined will cause the default to be created
296
+ */
297
+ setCookieMgr(cookieMgr: ICookieMgr): void;
298
+ /**
299
+ * Adds a notification listener. The SDK calls methods on the listener when an appropriate notification is raised.
300
+ * The added plugins must raise notifications. If the plugins do not implement the notifications, then no methods will be
301
+ * called.
302
+ * @param listener - An INotificationListener object.
303
+ */
304
+ addNotificationListener?(listener: INotificationListener): void;
305
+ /**
306
+ * Removes all instances of the listener.
307
+ * @param listener - INotificationListener to remove.
308
+ */
309
+ removeNotificationListener?(listener: INotificationListener): void;
310
+ /**
311
+ * Add a telemetry processor to decorate or drop telemetry events.
312
+ * @param telemetryInitializer - The Telemetry Initializer function
313
+ * @returns - A ITelemetryInitializerHandler to enable the initializer to be removed
314
+ */
315
+ addTelemetryInitializer(telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler;
316
+ pollInternalLogs?(eventName?: string): ITimerHandler;
317
+ stopPollingInternalLogs?(): void;
318
+ /**
319
+ * Return a new instance of the IProcessTelemetryContext for processing events
320
+ */
321
+ getProcessTelContext(): IProcessTelemetryContext;
322
+ /**
323
+ * Unload and Tear down the SDK and any initialized plugins, after calling this the SDK will be considered
324
+ * to be un-initialized and non-operational, re-initializing the SDK should only be attempted if the previous
325
+ * unload call return `true` stating that all plugins reported that they also unloaded, the recommended
326
+ * approach is to create a new instance and initialize that instance.
327
+ * This is due to possible unexpected side effects caused by plugins not supporting unload / teardown, unable
328
+ * to successfully remove any global references or they may just be completing the unload process asynchronously.
329
+ * 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)
330
+ * will be returned which will resolve once the unload is complete. The actual implementation of the `IPromise`
331
+ * will be a native Promise (if supported) or the default as supplied by [ts-async library](https://github.com/nevware21/ts-async)
332
+ * @param isAsync - Can the unload be performed asynchronously (default)
333
+ * @param unloadComplete - An optional callback that will be called once the unload has completed
334
+ * @param cbTimeout - An optional timeout to wait for any flush operations to complete before proceeding with the
335
+ * unload. Defaults to 5 seconds.
336
+ * @return Nothing or if occurring asynchronously a [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html)
337
+ * which will be resolved once the unload is complete, the [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html)
338
+ * will only be returned when no callback is provided and isAsync is true
339
+ */
340
+ unload(isAsync?: boolean, unloadComplete?: (unloadState: ITelemetryUnloadState) => void, cbTimeout?: number): void | IPromise<ITelemetryUnloadState>;
341
+ /**
342
+ * Find and return the (first) plugin with the specified identifier if present
343
+ * @param pluginIdentifier
344
+ */
345
+ getPlugin<T extends IPlugin = IPlugin>(pluginIdentifier: string): ILoadedPlugin<T>;
346
+ /**
347
+ * Add a new plugin to the installation
348
+ * @param plugin - The new plugin to add
349
+ * @param replaceExisting - should any existing plugin be replaced, default is false
350
+ * @param doAsync - Should the add be performed asynchronously
351
+ * @param addCb - [Optional] callback to call after the plugin has been added
352
+ */
353
+ addPlugin<T extends IPlugin = ITelemetryPlugin>(plugin: T, replaceExisting?: boolean, doAsync?: boolean, addCb?: (added?: boolean) => void): void;
354
+ /**
355
+ * Update the configuration used and broadcast the changes to all loaded plugins, this does NOT support updating, adding or removing
356
+ * any the plugins (extensions or channels). It will notify each plugin (if supported) that the configuration has changed but it will
357
+ * not remove or add any new plugins, you need to call addPlugin or getPlugin(identifier).remove();
358
+ * @param newConfig - The new configuration is apply
359
+ * @param mergeExisting - Should the new configuration merge with the existing or just replace it. Default is to merge.
360
+ */
361
+ updateCfg(newConfig: CfgType, mergeExisting?: boolean): void;
362
+ /**
363
+ * Returns the unique event namespace that should be used when registering events
364
+ */
365
+ evtNamespace(): string;
366
+ /**
367
+ * Add a handler that will be called when the SDK is being unloaded
368
+ * @param handler - the handler
369
+ */
370
+ addUnloadCb(handler: UnloadHandler): void;
371
+ /**
372
+ * Add this hook so that it is automatically removed during unloading
373
+ * @param hooks - The single hook or an array of IInstrumentHook objects
374
+ */
375
+ addUnloadHook(hooks: IUnloadHook | IUnloadHook[] | Iterator<IUnloadHook> | ILegacyUnloadHook | ILegacyUnloadHook[] | Iterator<ILegacyUnloadHook>): void;
376
+ /**
377
+ * Flush and send any batched / cached data immediately
378
+ * @param async - send data asynchronously when true (defaults to true)
379
+ * @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.
380
+ * If the caller doesn't return true the caller should assume that it may never be called.
381
+ * @param sendReason - specify the reason that you are calling "flush" defaults to ManualFlush (1) if not specified
382
+ * @param cbTimeout - An optional timeout to wait for any flush operations to complete before proceeding with the unload. Defaults to 5 seconds.
383
+ * @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
384
+ */
385
+ flush(isAsync?: boolean, callBack?: (flushComplete?: boolean) => void, sendReason?: SendRequestReason, cbTimeout?: number): boolean | void;
386
+ /**
387
+ * Gets the current distributed trace context for this instance if available
388
+ * @param createNew - Optional flag to create a new instance if one doesn't currently exist, defaults to true
389
+ */
390
+ getTraceCtx(createNew?: boolean): IDistributedTraceContext | null;
391
+ /**
392
+ * Sets the current distributed trace context for this instance if available
393
+ */
394
+ setTraceCtx(newTraceCtx: IDistributedTraceContext | null | undefined): void;
395
+ /**
396
+ * Watches and tracks changes for accesses to the current config, and if the accessed config changes the
397
+ * handler will be recalled.
398
+ * @param handler
399
+ * @returns A watcher handler instance that can be used to remove itself when being unloaded
400
+ */
401
+ onCfgChange(handler: WatcherFunction<CfgType>): IUnloadHook;
402
+ /**
403
+ * Function used to identify the get w parameter used to identify status bit to some channels
404
+ */
405
+ getWParam: () => number;
406
+ }
407
+
408
+ interface IBaseProcessingContext {
409
+ /**
410
+ * The current core instance for the request
411
+ */
412
+ core: () => IAppInsightsCore;
413
+ /**
414
+ * THe current diagnostic logger for the request
415
+ */
416
+ diagLog: () => IDiagnosticLogger;
417
+ /**
418
+ * Gets the current core config instance
419
+ */
420
+ getCfg: () => IConfiguration;
421
+ /**
422
+ * Gets the named extension config
423
+ */
424
+ getExtCfg: <T>(identifier: string, defaultValue?: IConfigDefaults<T>) => T;
425
+ /**
426
+ * Gets the named config from either the named identifier extension or core config if neither exist then the
427
+ * default value is returned
428
+ * @param identifier - The named extension identifier
429
+ * @param field - The config field name
430
+ * @param defaultValue - The default value to return if no defined config exists
431
+ */
432
+ getConfig: (identifier: string, field: string, defaultValue?: number | string | boolean | string[] | RegExp[] | Function) => number | string | boolean | string[] | RegExp[] | Function;
433
+ /**
434
+ * Helper to allow plugins to check and possibly shortcut executing code only
435
+ * required if there is a nextPlugin
436
+ */
437
+ hasNext: () => boolean;
438
+ /**
439
+ * Returns the next configured plugin proxy
440
+ */
441
+ getNext: () => ITelemetryPluginChain;
442
+ /**
443
+ * Helper to set the next plugin proxy
444
+ */
445
+ setNext: (nextCtx: ITelemetryPluginChain) => void;
446
+ /**
447
+ * Synchronously iterate over the context chain running the callback for each plugin, once
448
+ * every plugin has been executed via the callback, any associated onComplete will be called.
449
+ * @param callback - The function call for each plugin in the context chain
450
+ */
451
+ iterate: <T extends ITelemetryPlugin = ITelemetryPlugin>(callback: (plugin: T) => void) => void;
452
+ /**
453
+ * Set the function to call when the current chain has executed all processNext or unloadNext items.
454
+ * @param onComplete - The onComplete to call
455
+ * @param that - The "this" value to use for the onComplete call, if not provided or undefined defaults to the current context
456
+ * @param args - Any additional arguments to pass to the onComplete function
457
+ */
458
+ onComplete: (onComplete: () => void, that?: any, ...args: any[]) => void;
459
+ /**
460
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
461
+ * @param plugins - The execution order to process the plugins, if null or not supplied
462
+ * then the current execution order will be copied.
463
+ * @param startAt - The plugin to start processing from, if missing from the execution
464
+ * order then the next plugin will be NOT set.
465
+ */
466
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IBaseProcessingContext;
467
+ }
468
+
469
+ /**
470
+ * Provides data transmission capabilities
471
+ */
472
+ interface IChannelControls extends ITelemetryPlugin {
473
+ /**
474
+ * Pause sending data
475
+ */
476
+ pause?(): void;
477
+ /**
478
+ * Resume sending data
479
+ */
480
+ resume?(): void;
481
+ /**
482
+ * Tear down the plugin and remove any hooked value, the plugin should be removed so that it is no longer initialized and
483
+ * therefore could be re-initialized after being torn down. The plugin should ensure that once this has been called any further
484
+ * processTelemetry calls are ignored and it just calls the processNext() with the provided context.
485
+ * @param unloadCtx - This is the context that should be used during unloading.
486
+ * @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.
487
+ * @returns boolean - true if the plugin has or will call processNext(), this for backward compatibility as previously teardown was synchronous and returned nothing.
488
+ */
489
+ teardown?: (unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState) => void | boolean;
490
+ /**
491
+ * Flush to send data immediately; channel should default to sending data asynchronously. If executing asynchronously and
492
+ * you DO NOT pass a callback function then a [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html)
493
+ * will be returned which will resolve once the flush is complete. The actual implementation of the `IPromise`
494
+ * will be a native Promise (if supported) or the default as supplied by [ts-async library](https://github.com/nevware21/ts-async)
495
+ * @param async - send data asynchronously when true
496
+ * @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.
497
+ * If the caller doesn't return true the caller should assume that it may never be called.
498
+ * @param sendReason - specify the reason that you are calling "flush" defaults to ManualFlush (1) if not specified
499
+ * @returns - If a callback is provided `true` to indicate that callback will be called after the flush is complete otherwise the caller
500
+ * should assume that any provided callback will never be called, Nothing or if occurring asynchronously a
501
+ * [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html) which will be resolved once the unload is complete,
502
+ * the [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html) will only be returned when no callback is provided
503
+ * and async is true.
504
+ */
505
+ flush?(async: boolean, callBack?: (flushComplete?: boolean) => void, sendReason?: SendRequestReason): boolean | void | IPromise<boolean>;
506
+ }
507
+
508
+ /**
509
+ * The type to identify whether the default value should be applied in preference to the provided value.
510
+ */
511
+ type IConfigCheckFn<V> = (value: V) => boolean;
512
+
513
+ /**
514
+ * The default values with a check function
515
+ */
516
+ interface IConfigDefaultCheck<T, V, C = IConfiguration> {
517
+ /**
518
+ * Callback function to check if the user-supplied value is valid, if not the default will be applied
519
+ */
520
+ isVal?: IConfigCheckFn<V>;
521
+ /**
522
+ * Optional function to allow converting and setting of the default value
523
+ */
524
+ set?: IConfigSetFn<T, V>;
525
+ /**
526
+ * The default value to apply if the user-supplied value is not valid
527
+ */
528
+ v?: V | IConfigDefaults<V, T>;
529
+ /**
530
+ * The default fallback key if the main key is not present, this is the key value from the config
531
+ */
532
+ fb?: keyof T | keyof C | Array<keyof T | keyof C>;
533
+ /**
534
+ * Use this check to determine the default fallback, default only checked whether the property isDefined,
535
+ * therefore `null`; `""` are considered to be valid values.
536
+ */
537
+ dfVal?: (value: any) => boolean;
538
+ /**
539
+ * Specify that any provided value should have the default value(s) merged into the value rather than
540
+ * just using either the default of user provided values. Mergeed objects will automatically be marked
541
+ * as referenced.
542
+ */
543
+ mrg?: boolean;
544
+ /**
545
+ * Set this field of the target as referenced, which will cause any object or array instance
546
+ * to be updated in-place rather than being entirely replaced. All other values will continue to be replaced.
547
+ * This is required for nested default objects to avoid multiple repetitive updates to listeners
548
+ * @returns The referenced properties current value
549
+ */
550
+ ref?: boolean;
551
+ /**
552
+ * Set this field of the target as read-only, which will block this single named property from
553
+ * ever being changed for the target instance.
554
+ * This does NOT freeze or seal the instance, it just stops the direct re-assignment of the named property,
555
+ * if the value is a non-primitive (ie. an object or array) it's properties will still be mutable.
556
+ * @returns The referenced properties current value
557
+ */
558
+ rdOnly?: boolean;
559
+ /**
560
+ * Block the value associated with this property from having it's properties / values converted into
561
+ * dynamic properties, this is generally used to block objects or arrays provided by external libraries
562
+ * which may be a plain object with readonly (non-configurable) or const properties.
563
+ */
564
+ blkVal?: boolean;
565
+ }
566
+
567
+ /**
568
+ * The Type definition to define default values to be applied to the config
569
+ * The value may be either the direct value or a ConfigDefaultCheck definition
570
+ */
571
+ type IConfigDefaults<T, C = IConfiguration> = {
572
+ [key in keyof T]: T[key] | IConfigDefaultCheck<T, T[key], C>;
573
+ };
574
+
575
+ /**
576
+ * The type which identifies the function use to validate the user supplied value
577
+ */
578
+ type IConfigSetFn<T, V> = (value: any, defValue: V, theConfig: T) => V;
579
+
580
+ /**
581
+ * Configuration provided to SDK core
582
+ */
583
+ interface IConfiguration {
584
+ /**
585
+ * Instrumentation key of resource. Either this or connectionString must be specified.
586
+ */
587
+ instrumentationKey?: string;
588
+ /**
589
+ * Connection string of resource. Either this or instrumentationKey must be specified.
590
+ */
591
+ connectionString?: string;
592
+ /**
593
+ * Set the timer interval (in ms) for internal logging queue, this is the
594
+ * amount of time to wait after logger.queue messages are detected to be sent.
595
+ * Note: since 3.0.1 and 2.8.13 the diagnostic logger timer is a normal timeout timer
596
+ * and not an interval timer. So this now represents the timer "delay" and not
597
+ * the frequency at which the events are sent.
598
+ */
599
+ diagnosticLogInterval?: number;
600
+ /**
601
+ * Maximum number of iKey transmitted logging telemetry per page view
602
+ */
603
+ maxMessageLimit?: number;
604
+ /**
605
+ * Console logging level. All logs with a severity level higher
606
+ * than the configured level will be printed to console. Otherwise
607
+ * they are suppressed. ie Level 2 will print both CRITICAL and
608
+ * WARNING logs to console, level 1 prints only CRITICAL.
609
+ *
610
+ * Note: Logs sent as telemetry to instrumentation key will also
611
+ * be logged to console if their severity meets the configured loggingConsoleLevel
612
+ *
613
+ * 0: ALL console logging off
614
+ * 1: logs to console: severity >= CRITICAL
615
+ * 2: logs to console: severity >= WARNING
616
+ */
617
+ loggingLevelConsole?: number;
618
+ /**
619
+ * Telemtry logging level to instrumentation key. All logs with a severity
620
+ * level higher than the configured level will sent as telemetry data to
621
+ * the configured instrumentation key.
622
+ *
623
+ * 0: ALL iKey logging off
624
+ * 1: logs to iKey: severity >= CRITICAL
625
+ * 2: logs to iKey: severity >= WARNING
626
+ */
627
+ loggingLevelTelemetry?: number;
628
+ /**
629
+ * If enabled, uncaught exceptions will be thrown to help with debugging
630
+ */
631
+ enableDebug?: boolean;
632
+ /**
633
+ * Endpoint where telemetry data is sent
634
+ */
635
+ endpointUrl?: string;
636
+ /**
637
+ * Extension configs loaded in SDK
638
+ */
639
+ extensionConfig?: {
640
+ [key: string]: any;
641
+ };
642
+ /**
643
+ * Additional plugins that should be loaded by core at runtime
644
+ */
645
+ readonly extensions?: ITelemetryPlugin[];
646
+ /**
647
+ * Channel queues that is setup by caller in desired order.
648
+ * If channels are provided here, core will ignore any channels that are already setup, example if there is a SKU with an initialized channel
649
+ */
650
+ readonly channels?: IChannelControls[][];
651
+ /**
652
+ * @type {boolean}
653
+ * Flag that disables the Instrumentation Key validation.
654
+ */
655
+ disableInstrumentationKeyValidation?: boolean;
656
+ /**
657
+ * [Optional] When enabled this will create local perfEvents based on sections of the code that have been instrumented
658
+ * to emit perfEvents (via the doPerf()) when this is enabled. This can be used to identify performance issues within
659
+ * the SDK, the way you are using it or optionally your own instrumented code.
660
+ * The provided IPerfManager implementation does NOT send any additional telemetry events to the server it will only fire
661
+ * the new perfEvent() on the INotificationManager which you can listen to.
662
+ * This also does not use the window.performance API, so it will work in environments where this API is not supported.
663
+ */
664
+ enablePerfMgr?: boolean;
665
+ /**
666
+ * [Optional] Callback function that will be called to create a the IPerfManager instance when required and ```enablePerfMgr```
667
+ * is enabled, this enables you to override the default creation of a PerfManager() without needing to ```setPerfMgr()```
668
+ * after initialization.
669
+ */
670
+ createPerfMgr?: (core: IAppInsightsCore, notificationManager: INotificationManager) => IPerfManager;
671
+ /**
672
+ * [Optional] Fire every single performance event not just the top level root performance event. Defaults to false.
673
+ */
674
+ perfEvtsSendAll?: boolean;
675
+ /**
676
+ * [Optional] Identifies the default length used to generate random session and user id's if non currently exists for the user / session.
677
+ * Defaults to 22, previous default value was 5, if you need to keep the previous maximum length you should set this value to 5.
678
+ */
679
+ idLength?: number;
680
+ /**
681
+ * @description Custom cookie domain. This is helpful if you want to share Application Insights cookies across subdomains. It
682
+ * can be set here or as part of the cookieCfg.domain, the cookieCfg takes precedence if both are specified.
683
+ * @type {string}
684
+ * @defaultValue ""
685
+ */
686
+ cookieDomain?: string;
687
+ /**
688
+ * @description Custom cookie path. This is helpful if you want to share Application Insights cookies behind an application
689
+ * gateway. It can be set here or as part of the cookieCfg.domain, the cookieCfg takes precedence if both are specified.
690
+ * @type {string}
691
+ * @defaultValue ""
692
+ */
693
+ cookiePath?: string;
694
+ /**
695
+ * [Optional] A boolean that indicated whether to disable the use of cookies by the SDK. If true, the SDK will not store or
696
+ * read any data from cookies. Cookie usage can be re-enabled after initialization via the core.getCookieMgr().enable().
697
+ */
698
+ disableCookiesUsage?: boolean;
699
+ /**
700
+ * [Optional] A Cookie Manager configuration which includes hooks to allow interception of the get, set and delete cookie
701
+ * operations. If this configuration is specified any specified enabled and domain properties will take precedence over the
702
+ * cookieDomain and disableCookiesUsage values.
703
+ */
704
+ cookieCfg?: ICookieMgrConfig;
705
+ /**
706
+ * [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
707
+ * 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.
708
+ * Unload events include "beforeunload", "unload", "visibilitychange" (with 'hidden' state) and "pagehide"
709
+ */
710
+ disablePageUnloadEvents?: string[];
711
+ /**
712
+ * [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
713
+ * 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.
714
+ * Page Show events include "pageshow" and "visibilitychange" (with 'visible' state)
715
+ */
716
+ disablePageShowEvents?: string[];
717
+ /**
718
+ * [Optional] A flag for performance optimization to disable attempting to use the Chrome Debug Extension, if disabled and the extension is installed
719
+ * this will not send any notifications.
720
+ */
721
+ disableDbgExt?: boolean;
722
+ /**
723
+ * Add "&w=0" parameter to support UA Parsing when web-workers don't have access to Document.
724
+ * Default is false
725
+ */
726
+ enableWParam?: boolean;
727
+ /**
728
+ * Custom optional value that will be added as a prefix for storage name.
729
+ * @defaultValue undefined
730
+ */
731
+ storagePrefix?: string;
732
+ /**
733
+ * Custom optional value to opt in features
734
+ * @defaultValue undefined
735
+ */
736
+ featureOptIn?: IFeatureOptIn;
737
+ }
738
+
739
+ interface ICookieMgr {
740
+ /**
741
+ * Enable or Disable the usage of cookies
742
+ */
743
+ setEnabled(value: boolean): void;
744
+ /**
745
+ * Can the system use cookies, if this returns false then all cookie setting and access functions will return nothing
746
+ */
747
+ isEnabled(): boolean;
748
+ /**
749
+ * Set the named cookie with the value and optional domain and optional
750
+ * @param name - The name of the cookie
751
+ * @param value - The value of the cookie (Must already be encoded)
752
+ * @param maxAgeSec - [optional] The maximum number of SECONDS that this cookie should survive
753
+ * @param domain - [optional] The domain to set for the cookie
754
+ * @param path - [optional] Path to set for the cookie, if not supplied will default to "/"
755
+ * @returns - True if the cookie was set otherwise false (Because cookie usage is not enabled or available)
756
+ */
757
+ set(name: string, value: string, maxAgeSec?: number, domain?: string, path?: string): boolean;
758
+ /**
759
+ * Get the value of the named cookie
760
+ * @param name - The name of the cookie
761
+ */
762
+ get(name: string): string;
763
+ /**
764
+ * Delete/Remove the named cookie if cookie support is available and enabled.
765
+ * Note: Not using "delete" as the name because it's a reserved word which would cause issues on older browsers
766
+ * @param name - The name of the cookie
767
+ * @param path - [optional] Path to set for the cookie, if not supplied will default to "/"
768
+ * @returns - True if the cookie was marked for deletion otherwise false (Because cookie usage is not enabled or available)
769
+ */
770
+ del(name: string, path?: string): boolean;
771
+ /**
772
+ * Purge the cookie from the system if cookie support is available, this function ignores the enabled setting of the manager
773
+ * so any cookie will be removed.
774
+ * Note: Not using "delete" as the name because it's a reserved word which would cause issues on older browsers
775
+ * @param name - The name of the cookie
776
+ * @param path - [optional] Path to set for the cookie, if not supplied will default to "/"
777
+ * @returns - True if the cookie was marked for deletion otherwise false (Because cookie usage is not available)
778
+ */
779
+ purge(name: string, path?: string): boolean;
780
+ /**
781
+ * Optional Callback hook to allow the cookie manager to update it's configuration, not generally implemented now that
782
+ * dynamic configuration is supported
783
+ * @param updateState
784
+ */
785
+ update?(updateState: ITelemetryUpdateState): void;
786
+ /**
787
+ * Unload and remove any state that this ICookieMgr may be holding, this is generally called when the
788
+ * owning SDK is being unloaded.
789
+ * @param isAsync - Can the unload be performed asynchronously (default)
790
+ * @return If the unload occurs synchronously then nothing should be returned, if happening asynchronously then
791
+ * the function should return an [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html)
792
+ * / Promise to allow any listeners to wait for the operation to complete.
793
+ */
794
+ unload?(isAsync?: boolean): void | IPromise<void>;
795
+ }
796
+
797
+ /**
798
+ * Configuration definition for instance based cookie management configuration
799
+ */
800
+ interface ICookieMgrConfig {
801
+ /**
802
+ * Defaults to true, A boolean that indicates whether the use of cookies by the SDK is enabled by the current instance.
803
+ * If false, the instance of the SDK initialized by this configuration will not store or read any data from cookies
804
+ */
805
+ enabled?: boolean;
806
+ /**
807
+ * Custom cookie domain. This is helpful if you want to share Application Insights cookies across subdomains.
808
+ */
809
+ domain?: string;
810
+ /**
811
+ * Specifies the path to use for the cookie, defaults to '/'
812
+ */
813
+ path?: string;
814
+ /**
815
+ * Specify the cookie name(s) to be ignored, this will cause any matching cookie name to never be read or written.
816
+ * They may still be explicitly purged or deleted. You do not need to repeat the name in the `blockedCookies`
817
+ * configuration.(Since v2.8.8)
818
+ */
819
+ ignoreCookies?: string[];
820
+ /**
821
+ * Specify the cookie name(s) to never be written, this will cause any cookie name to never be created or updated,
822
+ * they will still be read unless also included in the ignoreCookies and may still be explicitly purged or deleted.
823
+ * If not provided defaults to the same list provided in ignoreCookies. (Since v2.8.8)
824
+ */
825
+ blockedCookies?: string[];
826
+ /**
827
+ * Hook function to fetch the named cookie value.
828
+ * @param name - The name of the cookie
829
+ */
830
+ getCookie?: (name: string) => string;
831
+ /**
832
+ * Hook function to set the named cookie with the specified value.
833
+ * @param name - The name of the cookie
834
+ * @param value - The value to set for the cookie
835
+ */
836
+ setCookie?: (name: string, value: string) => void;
837
+ /**
838
+ * Hook function to delete the named cookie with the specified value, separated from
839
+ * setCookie to avoid the need to parse the value to determine whether the cookie is being
840
+ * added or removed.
841
+ * @param name - The name of the cookie
842
+ * @param cookieValue - The value to set to expire the cookie
843
+ */
844
+ delCookie?: (name: string, cookieValue: string) => void;
845
+ }
846
+
847
+ interface ICustomProperties {
848
+ [key: string]: any;
849
+ }
850
+
26
851
  interface IDebugPluginConfig extends IConfiguration {
27
852
  trackers?: string[];
28
853
  /**
@@ -51,5 +876,1113 @@ declare namespace ApplicationInsights {
51
876
  logProcessTelemetry?: boolean;
52
877
  }
53
878
 
54
-
879
+ interface IDiagnosticLogger {
880
+ /**
881
+ * 0: OFF
882
+ * 1: only critical (default)
883
+ * 2: critical + info
884
+ */
885
+ consoleLoggingLevel: () => number;
886
+ /**
887
+ * The internal logging queue
888
+ */
889
+ queue: _InternalLogMessage[];
890
+ /**
891
+ * This method will throw exceptions in debug mode or attempt to log the error as a console warning.
892
+ * @param severity - The severity of the log message
893
+ * @param message - The log message.
894
+ */
895
+ throwInternal(severity: LoggingSeverity, msgId: _InternalMessageId, msg: string, properties?: Object, isUserAct?: boolean): void;
896
+ /**
897
+ * This will write a debug message to the console if possible
898
+ * @param message - {string} - The debug message
899
+ */
900
+ debugToConsole?(message: string): void;
901
+ /**
902
+ * This will write a warning to the console if possible
903
+ * @param message - The warning message
904
+ */
905
+ warnToConsole(message: string): void;
906
+ /**
907
+ * This will write an error to the console if possible.
908
+ * Provided by the default DiagnosticLogger instance, and internally the SDK will fall back to warnToConsole, however,
909
+ * direct callers MUST check for its existence on the logger as you can provide your own IDiagnosticLogger instance.
910
+ * @param message - The error message
911
+ */
912
+ errorToConsole?(message: string): void;
913
+ /**
914
+ * Resets the internal message count
915
+ */
916
+ resetInternalMessageCount(): void;
917
+ /**
918
+ * Logs a message to the internal queue.
919
+ * @param severity - The severity of the log message
920
+ * @param message - The message to log.
921
+ */
922
+ logInternalMessage?(severity: LoggingSeverity, message: _InternalLogMessage): void;
923
+ /**
924
+ * Optional Callback hook to allow the diagnostic logger to update it's configuration
925
+ * @param updateState
926
+ */
927
+ update?(updateState: ITelemetryUpdateState): void;
928
+ /**
929
+ * Unload and remove any state that this IDiagnosticLogger may be holding, this is generally called when the
930
+ * owning SDK is being unloaded.
931
+ * @param isAsync - Can the unload be performed asynchronously (default)
932
+ * @return If the unload occurs synchronously then nothing should be returned, if happening asynchronously then
933
+ * the function should return an [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html)
934
+ * / Promise to allow any listeners to wait for the operation to complete.
935
+ */
936
+ unload?(isAsync?: boolean): void | IPromise<void>;
937
+ }
938
+
939
+ interface IDistributedTraceContext {
940
+ /**
941
+ * Returns the current name of the page
942
+ */
943
+ getName(): string;
944
+ /**
945
+ * Sets the current name of the page
946
+ * @param pageName
947
+ */
948
+ setName(pageName: string): void;
949
+ /**
950
+ * Returns the unique identifier for a trace. All requests / spans from the same trace share the same traceId.
951
+ * Must be read from incoming headers or generated according to the W3C TraceContext specification,
952
+ * in a hex representation of 16-byte array. A.k.a. trace-id, TraceID or Distributed TraceID
953
+ */
954
+ getTraceId(): string;
955
+ /**
956
+ * Set the unique identifier for a trace. All requests / spans from the same trace share the same traceId.
957
+ * Must be conform to the W3C TraceContext specification, in a hex representation of 16-byte array.
958
+ * A.k.a. trace-id, TraceID or Distributed TraceID https://www.w3.org/TR/trace-context/#trace-id
959
+ */
960
+ setTraceId(newValue: string): void;
961
+ /**
962
+ * Self-generated 8-bytes identifier of the incoming request. Must be a hex representation of 8-byte array.
963
+ * Also know as the parentId, used to link requests together
964
+ */
965
+ getSpanId(): string;
966
+ /**
967
+ * Self-generated 8-bytes identifier of the incoming request. Must be a hex representation of 8-byte array.
968
+ * Also know as the parentId, used to link requests together
969
+ * https://www.w3.org/TR/trace-context/#parent-id
970
+ */
971
+ setSpanId(newValue: string): void;
972
+ /**
973
+ * An integer representation of the W3C TraceContext trace-flags.
974
+ */
975
+ getTraceFlags(): number | undefined;
976
+ /**
977
+ * https://www.w3.org/TR/trace-context/#trace-flags
978
+ * @param newValue
979
+ */
980
+ setTraceFlags(newValue?: number): void;
981
+ }
982
+
983
+ interface IFeatureOptIn {
984
+ [feature: string]: IFeatureOptInDetails;
985
+ }
986
+
987
+ interface IFeatureOptInDetails {
988
+ /**
989
+ * sets feature opt-in mode
990
+ * @default undefined
991
+ */
992
+ mode?: FeatureOptInMode;
993
+ /**
994
+ * Identifies configuration override values when given feature is enabled
995
+ * NOTE: should use flat string for fields, for example, if you want to set value for extensionConfig.Ananlytics.disableAjaxTrackig in configurations,
996
+ * you should use "extensionConfig.Ananlytics.disableAjaxTrackig" as field name: {["extensionConfig.Analytics.disableAjaxTrackig"]:1}
997
+ * Default: undefined
998
+ */
999
+ onCfg?: {
1000
+ [field: string]: any;
1001
+ };
1002
+ /**
1003
+ * Identifies configuration override values when given feature is disabled
1004
+ * NOTE: should use flat string for fields, for example, if you want to set value for extensionConfig.Ananlytics.disableAjaxTrackig in configurations,
1005
+ * you should use "extensionConfig.Ananlytics.disableAjaxTrackig" as field name: {["extensionConfig.Analytics.disableAjaxTrackig"]:1}
1006
+ * Default: undefined
1007
+ */
1008
+ offCfg?: {
1009
+ [field: string]: any;
1010
+ };
1011
+ /**
1012
+ * define if should block any changes from cdn cfg, if set to true, cfgValue will be applied under all scenarios
1013
+ * @default false
1014
+ */
1015
+ blockCdnCfg?: boolean;
1016
+ }
1017
+
1018
+ /**
1019
+ * An alternate interface which provides automatic removal during unloading of the component
1020
+ */
1021
+ interface ILegacyUnloadHook {
1022
+ /**
1023
+ * Legacy Self remove the referenced component
1024
+ */
1025
+ remove: () => void;
1026
+ }
1027
+
1028
+ interface ILoadedPlugin<T extends IPlugin> {
1029
+ plugin: T;
1030
+ /**
1031
+ * Identifies whether the plugin is enabled and can process events. This is slightly different from isInitialized as the plugin may be initialized but disabled
1032
+ * via the setEnabled() or it may be a shared plugin which has had it's teardown function called from another instance..
1033
+ * @returns boolean = true if the plugin is in a state where it is operational.
1034
+ */
1035
+ isEnabled: () => boolean;
1036
+ /**
1037
+ * You can optionally enable / disable a plugin from processing events.
1038
+ * Setting enabled to true will not necessarily cause the `isEnabled()` to also return true
1039
+ * as the plugin must also have been successfully initialized and not had it's `teardown` method called
1040
+ * (unless it's also been re-initialized)
1041
+ */
1042
+ setEnabled: (isEnabled: boolean) => void;
1043
+ remove: (isAsync?: boolean, removeCb?: (removed?: boolean) => void) => void;
1044
+ }
1045
+
1046
+ /**
1047
+ * An interface used for the notification listener.
1048
+ * @interface
1049
+ */
1050
+ interface INotificationListener {
1051
+ /**
1052
+ * [Optional] A function called when events are sent.
1053
+ * @param events - The array of events that have been sent.
1054
+ */
1055
+ eventsSent?: (events: ITelemetryItem[]) => void;
1056
+ /**
1057
+ * [Optional] A function called when events are discarded.
1058
+ * @param events - The array of events that have been discarded.
1059
+ * @param reason - The reason for discarding the events. The EventsDiscardedReason
1060
+ * constant should be used to check the different values.
1061
+ */
1062
+ eventsDiscarded?: (events: ITelemetryItem[], reason: number) => void;
1063
+ /**
1064
+ * [Optional] A function called when the events have been requested to be sent to the sever.
1065
+ * @param sendReason - The reason why the event batch is being sent.
1066
+ * @param isAsync - A flag which identifies whether the requests are being sent in an async or sync manner.
1067
+ */
1068
+ eventsSendRequest?: (sendReason: number, isAsync?: boolean) => void;
1069
+ /**
1070
+ * [Optional] This event is sent if you have enabled perf events, they are primarily used to track internal performance testing and debugging
1071
+ * the event can be displayed via the debug plugin extension.
1072
+ * @param perfEvent
1073
+ */
1074
+ perfEvent?: (perfEvent: IPerfEvent) => void;
1075
+ /**
1076
+ * Unload and remove any state that this INotificationListener may be holding, this is generally called when the
1077
+ * owning Manager is being unloaded.
1078
+ * @param isAsync - Can the unload be performed asynchronously (default)
1079
+ * @return If the unload occurs synchronously then nothing should be returned, if happening asynchronously then
1080
+ * the function should return an [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html)
1081
+ * / Promise to allow any listeners to wait for the operation to complete.
1082
+ */
1083
+ unload?(isAsync?: boolean): void | IPromise<void>;
1084
+ }
1085
+
1086
+ /**
1087
+ * Class to manage sending notifications to all the listeners.
1088
+ */
1089
+ interface INotificationManager {
1090
+ listeners: INotificationListener[];
1091
+ /**
1092
+ * Adds a notification listener.
1093
+ * @param listener - The notification listener to be added.
1094
+ */
1095
+ addNotificationListener(listener: INotificationListener): void;
1096
+ /**
1097
+ * Removes all instances of the listener.
1098
+ * @param listener - AWTNotificationListener to remove.
1099
+ */
1100
+ removeNotificationListener(listener: INotificationListener): void;
1101
+ /**
1102
+ * Notification for events sent.
1103
+ * @param events - The array of events that have been sent.
1104
+ */
1105
+ eventsSent(events: ITelemetryItem[]): void;
1106
+ /**
1107
+ * Notification for events being discarded.
1108
+ * @param events - The array of events that have been discarded by the SDK.
1109
+ * @param reason - The reason for which the SDK discarded the events. The EventsDiscardedReason
1110
+ * constant should be used to check the different values.
1111
+ */
1112
+ eventsDiscarded(events: ITelemetryItem[], reason: number): void;
1113
+ /**
1114
+ * [Optional] A function called when the events have been requested to be sent to the sever.
1115
+ * @param sendReason - The reason why the event batch is being sent.
1116
+ * @param isAsync - A flag which identifies whether the requests are being sent in an async or sync manner.
1117
+ */
1118
+ eventsSendRequest?(sendReason: number, isAsync: boolean): void;
1119
+ /**
1120
+ * [Optional] This event is sent if you have enabled perf events, they are primarily used to track internal performance testing and debugging
1121
+ * the event can be displayed via the debug plugin extension.
1122
+ * @param perfEvent - The perf event details
1123
+ */
1124
+ perfEvent?(perfEvent: IPerfEvent): void;
1125
+ /**
1126
+ * Unload and remove any state that this INotificationManager may be holding, this is generally called when the
1127
+ * owning SDK is being unloaded.
1128
+ * @param isAsync - Can the unload be performed asynchronously (default)
1129
+ * @return If the unload occurs synchronously then nothing should be returned, if happening asynchronously then
1130
+ * the function should return an [IPromise](https://nevware21.github.io/ts-async/typedoc/interfaces/IPromise.html)
1131
+ * / Promise to allow any listeners to wait for the operation to complete.
1132
+ */
1133
+ unload?(isAsync?: boolean): void | IPromise<void>;
1134
+ }
1135
+
1136
+ class _InternalLogMessage {
1137
+ static dataType: string;
1138
+ message: string;
1139
+ messageId: _InternalMessageId;
1140
+ constructor(msgId: _InternalMessageId, msg: string, isUserAct?: boolean, properties?: Object);
1141
+ }
1142
+
1143
+ type _InternalMessageId = number | _eInternalMessageId;
1144
+
1145
+ /**
1146
+ * This interface identifies the details of an internal performance event - it does not represent an outgoing reported event
1147
+ */
1148
+ interface IPerfEvent {
1149
+ /**
1150
+ * The name of the performance event
1151
+ */
1152
+ name: string;
1153
+ /**
1154
+ * The start time of the performance event
1155
+ */
1156
+ start: number;
1157
+ /**
1158
+ * The payload (contents) of the perfEvent, may be null or only set after the event has completed depending on
1159
+ * the runtime environment.
1160
+ */
1161
+ payload: any;
1162
+ /**
1163
+ * Is this occurring from an asynchronous event
1164
+ */
1165
+ isAsync: boolean;
1166
+ /**
1167
+ * Identifies the total inclusive time spent for this event, including the time spent for child events,
1168
+ * this will be undefined until the event is completed
1169
+ */
1170
+ time?: number;
1171
+ /**
1172
+ * Identifies the exclusive time spent in for this event (not including child events),
1173
+ * this will be undefined until the event is completed.
1174
+ */
1175
+ exTime?: number;
1176
+ /**
1177
+ * The Parent event that was started before this event was created
1178
+ */
1179
+ parent?: IPerfEvent;
1180
+ /**
1181
+ * The child perf events that are contained within the total time of this event.
1182
+ */
1183
+ childEvts?: IPerfEvent[];
1184
+ /**
1185
+ * Identifies whether this event is a child event of a parent
1186
+ */
1187
+ isChildEvt: () => boolean;
1188
+ /**
1189
+ * Get the names additional context associated with this perf event
1190
+ */
1191
+ getCtx?: (key: string) => any;
1192
+ /**
1193
+ * Set the named additional context to be associated with this perf event, this will replace any existing value
1194
+ */
1195
+ setCtx?: (key: string, value: any) => void;
1196
+ /**
1197
+ * Mark this event as completed, calculating the total execution time.
1198
+ */
1199
+ complete: () => void;
1200
+ }
1201
+
1202
+ /**
1203
+ * This defines an internal performance manager for tracking and reporting the internal performance of the SDK -- It does
1204
+ * not represent or report any event to the server.
1205
+ */
1206
+ interface IPerfManager {
1207
+ /**
1208
+ * Create a new event and start timing, the manager may return null/undefined to indicate that it does not
1209
+ * want to monitor this source event.
1210
+ * @param src - The source name of the event
1211
+ * @param payloadDetails - An optional callback function to fetch the payload details for the event.
1212
+ * @param isAsync - Is the event occurring from a async event
1213
+ */
1214
+ create(src: string, payloadDetails?: () => any, isAsync?: boolean): IPerfEvent | null | undefined;
1215
+ /**
1216
+ * Complete the perfEvent and fire any notifications.
1217
+ * @param perfEvent - Fire the event which will also complete the passed event
1218
+ */
1219
+ fire(perfEvent: IPerfEvent): void;
1220
+ /**
1221
+ * Set an execution context value
1222
+ * @param key - The context key name
1223
+ * @param value - The value
1224
+ */
1225
+ setCtx(key: string, value: any): void;
1226
+ /**
1227
+ * Get the execution context value
1228
+ * @param key - The context key
1229
+ */
1230
+ getCtx(key: string): any;
1231
+ }
1232
+
1233
+ /**
1234
+ * Identifies an interface to a host that can provide an IPerfManager implementation
1235
+ */
1236
+ interface IPerfManagerProvider {
1237
+ /**
1238
+ * Get the current performance manager
1239
+ */
1240
+ getPerfMgr(): IPerfManager;
1241
+ /**
1242
+ * Set the current performance manager
1243
+ * @param perfMgr - The performance manager
1244
+ */
1245
+ setPerfMgr(perfMgr: IPerfManager): void;
1246
+ }
1247
+
1248
+ interface IPlugin {
1249
+ /**
1250
+ * Initialize plugin loaded by SDK
1251
+ * @param config - The config for the plugin to use
1252
+ * @param core - The current App Insights core to use for initializing this plugin instance
1253
+ * @param extensions - The complete set of extensions to be used for initializing the plugin
1254
+ * @param pluginChain - [Optional] specifies the current plugin chain which identifies the
1255
+ * set of plugins and the order they should be executed for the current request.
1256
+ */
1257
+ initialize: (config: IConfiguration, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?: ITelemetryPluginChain) => void;
1258
+ /**
1259
+ * Returns a value that indicates whether the plugin has already been previously initialized.
1260
+ * New plugins should implement this method to avoid being initialized more than once.
1261
+ */
1262
+ isInitialized?: () => boolean;
1263
+ /**
1264
+ * Tear down the plugin and remove any hooked value, the plugin should be removed so that it is no longer initialized and
1265
+ * therefore could be re-initialized after being torn down. The plugin should ensure that once this has been called any further
1266
+ * processTelemetry calls are ignored and it just calls the processNext() with the provided context.
1267
+ * @param unloadCtx - This is the context that should be used during unloading.
1268
+ * @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.
1269
+ * @returns boolean - true if the plugin has or will call processNext(), this for backward compatibility as previously teardown was synchronous and returned nothing.
1270
+ */
1271
+ teardown?: (unloadCtx: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState) => void | boolean;
1272
+ /**
1273
+ * Extension name
1274
+ */
1275
+ readonly identifier: string;
1276
+ /**
1277
+ * Plugin version (available in data.properties.version in common schema)
1278
+ */
1279
+ readonly version?: string;
1280
+ /**
1281
+ * The App Insights core to use for backward compatibility.
1282
+ * Therefore the interface will be able to access the core without needing to cast to "any".
1283
+ * [optional] any 3rd party plugins which are already implementing this interface don't fail to compile.
1284
+ */
1285
+ core?: IAppInsightsCore;
1286
+ }
1287
+
1288
+ /**
1289
+ * The current context for the current call to processTelemetry(), used to support sharing the same plugin instance
1290
+ * between multiple AppInsights instances
1291
+ */
1292
+ interface IProcessTelemetryContext extends IBaseProcessingContext {
1293
+ /**
1294
+ * Call back for telemetry processing before it it is sent
1295
+ * @param env - This is the current event being reported
1296
+ * @returns boolean (true) if there is no more plugins to process otherwise false or undefined (void)
1297
+ */
1298
+ processNext: (env: ITelemetryItem) => boolean | void;
1299
+ /**
1300
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
1301
+ * @param plugins - The execution order to process the plugins, if null or not supplied
1302
+ * then the current execution order will be copied.
1303
+ * @param startAt - The plugin to start processing from, if missing from the execution
1304
+ * order then the next plugin will be NOT set.
1305
+ */
1306
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryContext;
1307
+ }
1308
+
1309
+ /**
1310
+ * The current context for the current call to teardown() implementations, used to support when plugins are being removed
1311
+ * or the SDK is being unloaded.
1312
+ */
1313
+ interface IProcessTelemetryUnloadContext extends IBaseProcessingContext {
1314
+ /**
1315
+ * This Plugin has finished unloading, so unload the next one
1316
+ * @param uploadState - The state of the unload process
1317
+ * @returns boolean (true) if there is no more plugins to process otherwise false or undefined (void)
1318
+ */
1319
+ processNext: (unloadState: ITelemetryUnloadState) => boolean | void;
1320
+ /**
1321
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
1322
+ * @param plugins - The execution order to process the plugins, if null or not supplied
1323
+ * then the current execution order will be copied.
1324
+ * @param startAt - The plugin to start processing from, if missing from the execution
1325
+ * order then the next plugin will be NOT set.
1326
+ */
1327
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryUnloadContext;
1328
+ }
1329
+
1330
+ /**
1331
+ * The current context for the current call to the plugin update() implementations, used to support the notifications
1332
+ * for when plugins are added, removed or the configuration was changed.
1333
+ */
1334
+ interface IProcessTelemetryUpdateContext extends IBaseProcessingContext {
1335
+ /**
1336
+ * This Plugin has finished unloading, so unload the next one
1337
+ * @param updateState - The update State
1338
+ * @returns boolean (true) if there is no more plugins to process otherwise false or undefined (void)
1339
+ */
1340
+ processNext: (updateState: ITelemetryUpdateState) => boolean | void;
1341
+ /**
1342
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
1343
+ * @param plugins - The execution order to process the plugins, if null or not supplied
1344
+ * then the current execution order will be copied.
1345
+ * @param startAt - The plugin to start processing from, if missing from the execution
1346
+ * order then the next plugin will be NOT set.
1347
+ */
1348
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryUpdateContext;
1349
+ }
1350
+
1351
+ /**
1352
+ * Create a Promise object that represents the eventual completion (or failure) of an asynchronous operation and its resulting value.
1353
+ * This interface definition, closely mirrors the typescript / javascript PromiseLike<T> and Promise<T> definitions as well as providing
1354
+ * simular functions as that provided by jQuery deferred objects.
1355
+ *
1356
+ * The returned Promise is a proxy for a value not necessarily known when the promise is created. It allows you to associate handlers
1357
+ * with an asynchronous action's eventual success value or failure reason. This lets asynchronous methods return values like synchronous
1358
+ * methods: instead of immediately returning the final value, the asynchronous method returns a promise to supply the value at some point
1359
+ * in the future.
1360
+ *
1361
+ * A Promise is in one of these states:
1362
+ * <ul>
1363
+ * <li> pending: initial state, neither fulfilled nor rejected.
1364
+ * <li> fulfilled: meaning that the operation was completed successfully.
1365
+ * <li> rejected: meaning that the operation failed.
1366
+ * </ul>
1367
+ *
1368
+ * A pending promise can either be fulfilled with a value or rejected with a reason (error). When either of these options happens, the
1369
+ * associated handlers queued up by a promise's then method are called synchronously. If the promise has already been fulfilled or rejected
1370
+ * when a corresponding handler is attached, the handler will be called synchronously, so there is no race condition between an asynchronous
1371
+ * operation completing and its handlers being attached.
1372
+ *
1373
+ * As the `then()` and `catch()` methods return promises, they can be chained.
1374
+ * @typeParam T - Identifies the expected return type from the promise
1375
+ */
1376
+ interface IPromise<T> extends PromiseLike<T>, Promise<T> {
1377
+ /**
1378
+ * Returns a string representation of the current state of the promise. The promise can be in one of four states.
1379
+ * <ul>
1380
+ * <li> <b>"pending"</b>: The promise is not yet in a completed state (neither "rejected"; or "resolved").</li>
1381
+ * <li> <b>"resolved"</b>: The promise is in the resolved state.</li>
1382
+ * <li> <b>"rejected"</b>: The promise is in the rejected state.</li>
1383
+ * </ul>
1384
+ * @example
1385
+ * ```ts
1386
+ * let doResolve;
1387
+ * let promise: IPromise<any> = createSyncPromise((resolve) => {
1388
+ * doResolve = resolve;
1389
+ * });
1390
+ *
1391
+ * let state: string = promise.state();
1392
+ * console.log("State: " + state); // State: pending
1393
+ * doResolve(true); // Promise will resolve synchronously as it's a synchronous promise
1394
+ * console.log("State: " + state); // State: resolved
1395
+ * ```
1396
+ */
1397
+ state?: string;
1398
+ /**
1399
+ * Attaches callbacks for the resolution and/or rejection of the Promise.
1400
+ * @param onResolved The callback to execute when the Promise is resolved.
1401
+ * @param onRejected The callback to execute when the Promise is rejected.
1402
+ * @returns A Promise for the completion of which ever callback is executed.
1403
+ * @example
1404
+ * ```ts
1405
+ * const promise1 = createPromise((resolve, reject) => {
1406
+ * resolve('Success!');
1407
+ * });
1408
+ *
1409
+ * promise1.then((value) => {
1410
+ * console.log(value);
1411
+ * // expected output: "Success!"
1412
+ * });
1413
+ * ```
1414
+ */
1415
+ then<TResult1 = T, TResult2 = never>(onResolved?: ResolvedPromiseHandler<T, TResult1>, onRejected?: RejectedPromiseHandler<TResult2>): IPromise<TResult1 | TResult2>;
1416
+ /**
1417
+ * Attaches callbacks for the resolution and/or rejection of the Promise.
1418
+ * @param onResolved The callback to execute when the Promise is resolved.
1419
+ * @param onRejected The callback to execute when the Promise is rejected.
1420
+ * @returns A Promise for the completion of which ever callback is executed.
1421
+ * @example
1422
+ * ```ts
1423
+ * const promise1 = createPromise((resolve, reject) => {
1424
+ * resolve('Success!');
1425
+ * });
1426
+ *
1427
+ * promise1.then((value) => {
1428
+ * console.log(value);
1429
+ * // expected output: "Success!"
1430
+ * });
1431
+ * ```
1432
+ */
1433
+ then<TResult1 = T, TResult2 = never>(onResolved?: ResolvedPromiseHandler<T, TResult1>, onRejected?: RejectedPromiseHandler<TResult2>): PromiseLike<TResult1 | TResult2>;
1434
+ /**
1435
+ * Attaches callbacks for the resolution and/or rejection of the Promise.
1436
+ * @param onResolved The callback to execute when the Promise is resolved.
1437
+ * @param onRejected The callback to execute when the Promise is rejected.
1438
+ * @returns A Promise for the completion of which ever callback is executed.
1439
+ * @example
1440
+ * ```ts
1441
+ * const promise1 = createPromise((resolve, reject) => {
1442
+ * resolve('Success!');
1443
+ * });
1444
+ *
1445
+ * promise1.then((value) => {
1446
+ * console.log(value);
1447
+ * // expected output: "Success!"
1448
+ * });
1449
+ * ```
1450
+ */
1451
+ then<TResult1 = T, TResult2 = never>(onResolved?: ResolvedPromiseHandler<T, TResult1>, onRejected?: RejectedPromiseHandler<TResult2>): Promise<TResult1 | TResult2>;
1452
+ /**
1453
+ * Attaches a callback for only the rejection of the Promise.
1454
+ * @param onRejected The callback to execute when the Promise is rejected.
1455
+ * @returns A Promise for the completion of the callback.
1456
+ * @example
1457
+ * ```ts
1458
+ * const promise1 = createPromise((resolve, reject) => {
1459
+ * throw 'Uh-oh!';
1460
+ * });
1461
+ *
1462
+ * promise1.catch((error) => {
1463
+ * console.error(error);
1464
+ * });
1465
+ * // expected output: Uh-oh!
1466
+ * ```
1467
+ */
1468
+ catch<TResult = never>(onRejected?: ((reason: any) => TResult | IPromise<TResult>) | undefined | null): IPromise<T | TResult>;
1469
+ /**
1470
+ * Attaches a callback for only the rejection of the Promise.
1471
+ * @param onRejected The callback to execute when the Promise is rejected.
1472
+ * @returns A Promise for the completion of the callback.
1473
+ * @example
1474
+ * ```ts
1475
+ * const promise1 = createPromise((resolve, reject) => {
1476
+ * throw 'Uh-oh!';
1477
+ * });
1478
+ *
1479
+ * promise1.catch((error) => {
1480
+ * console.error(error);
1481
+ * });
1482
+ * // expected output: Uh-oh!
1483
+ * ```
1484
+ */
1485
+ catch<TResult = never>(onRejected?: ((reason: any) => TResult | IPromise<TResult>) | undefined | null): PromiseLike<T | TResult>;
1486
+ /**
1487
+ * Attaches a callback for only the rejection of the Promise.
1488
+ * @param onRejected The callback to execute when the Promise is rejected.
1489
+ * @returns A Promise for the completion of the callback.
1490
+ * @example
1491
+ * ```ts
1492
+ * const promise1 = createPromise((resolve, reject) => {
1493
+ * throw 'Uh-oh!';
1494
+ * });
1495
+ *
1496
+ * promise1.catch((error) => {
1497
+ * console.error(error);
1498
+ * });
1499
+ * // expected output: Uh-oh!
1500
+ * ```
1501
+ */
1502
+ catch<TResult = never>(onRejected?: ((reason: any) => TResult | IPromise<TResult>) | undefined | null): Promise<T | TResult>;
1503
+ /**
1504
+ * Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The
1505
+ * resolved value cannot be modified from the callback.
1506
+ * @param onfinally The callback to execute when the Promise is settled (fulfilled or rejected).
1507
+ * @returns A Promise for the completion of the callback.
1508
+ * @example
1509
+ * ```ts
1510
+ * function doFunction() {
1511
+ * return createPromise((resolve, reject) => {
1512
+ * if (Math.random() > 0.5) {
1513
+ * resolve('Function has completed');
1514
+ * } else {
1515
+ * reject(new Error('Function failed to process'));
1516
+ * }
1517
+ * });
1518
+ * }
1519
+ *
1520
+ * doFunction().then((data) => {
1521
+ * console.log(data);
1522
+ * }).catch((err) => {
1523
+ * console.error(err);
1524
+ * }).finally(() => {
1525
+ * console.log('Function processing completed');
1526
+ * });
1527
+ * ```
1528
+ */
1529
+ finally(onfinally?: FinallyPromiseHandler): IPromise<T>;
1530
+ /**
1531
+ * Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The
1532
+ * resolved value cannot be modified from the callback.
1533
+ * @param onfinally The callback to execute when the Promise is settled (fulfilled or rejected).
1534
+ * @returns A Promise for the completion of the callback.
1535
+ * @example
1536
+ * ```ts
1537
+ * function doFunction() {
1538
+ * return createPromise((resolve, reject) => {
1539
+ * if (Math.random() > 0.5) {
1540
+ * resolve('Function has completed');
1541
+ * } else {
1542
+ * reject(new Error('Function failed to process'));
1543
+ * }
1544
+ * });
1545
+ * }
1546
+ *
1547
+ * doFunction().then((data) => {
1548
+ * console.log(data);
1549
+ * }).catch((err) => {
1550
+ * console.error(err);
1551
+ * }).finally(() => {
1552
+ * console.log('Function processing completed');
1553
+ * });
1554
+ * ```
1555
+ */
1556
+ finally(onFinally?: FinallyPromiseHandler): Promise<T>;
1557
+ }
1558
+
1559
+ interface ITelemetryInitializerHandler extends ILegacyUnloadHook {
1560
+ remove(): void;
1561
+ }
1562
+
1563
+ /**
1564
+ * Telemety item supported in Core
1565
+ */
1566
+ interface ITelemetryItem {
1567
+ /**
1568
+ * CommonSchema Version of this SDK
1569
+ */
1570
+ ver?: string;
1571
+ /**
1572
+ * Unique name of the telemetry item
1573
+ */
1574
+ name: string;
1575
+ /**
1576
+ * Timestamp when item was sent
1577
+ */
1578
+ time?: string;
1579
+ /**
1580
+ * Identifier of the resource that uniquely identifies which resource data is sent to
1581
+ */
1582
+ iKey?: string;
1583
+ /**
1584
+ * System context properties of the telemetry item, example: ip address, city etc
1585
+ */
1586
+ ext?: {
1587
+ [key: string]: any;
1588
+ };
1589
+ /**
1590
+ * System context property extensions that are not global (not in ctx)
1591
+ */
1592
+ tags?: Tags & Tags[];
1593
+ /**
1594
+ * Custom data
1595
+ */
1596
+ data?: ICustomProperties;
1597
+ /**
1598
+ * Telemetry type used for part B
1599
+ */
1600
+ baseType?: string;
1601
+ /**
1602
+ * Based on schema for part B
1603
+ */
1604
+ baseData?: {
1605
+ [key: string]: any;
1606
+ };
1607
+ }
1608
+
1609
+ /**
1610
+ * Configuration provided to SDK core
1611
+ */
1612
+ interface ITelemetryPlugin extends ITelemetryProcessor, IPlugin {
1613
+ /**
1614
+ * Set next extension for telemetry processing, this is not optional as plugins should use the
1615
+ * processNext() function of the passed IProcessTelemetryContext instead. It is being kept for
1616
+ * now for backward compatibility only.
1617
+ */
1618
+ setNextPlugin?: (next: ITelemetryPlugin | ITelemetryPluginChain) => void;
1619
+ /**
1620
+ * Priority of the extension
1621
+ */
1622
+ readonly priority: number;
1623
+ }
1624
+
1625
+ /**
1626
+ * Configuration provided to SDK core
1627
+ */
1628
+ interface ITelemetryPluginChain extends ITelemetryProcessor {
1629
+ /**
1630
+ * Returns the underlying plugin that is being proxied for the processTelemetry call
1631
+ */
1632
+ getPlugin: () => ITelemetryPlugin;
1633
+ /**
1634
+ * Returns the next plugin
1635
+ */
1636
+ getNext: () => ITelemetryPluginChain;
1637
+ /**
1638
+ * This plugin is being unloaded and should remove any hooked events and cleanup any global/scoped values, after this
1639
+ * call the plugin will be removed from the telemetry processing chain and will no longer receive any events..
1640
+ * @param unloadCtx - The unload context to use for this call.
1641
+ * @param unloadState - The details of the unload operation
1642
+ */
1643
+ unload?: (unloadCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
1644
+ }
1645
+
1646
+ interface ITelemetryProcessor {
1647
+ /**
1648
+ * Call back for telemetry processing before it it is sent
1649
+ * @param env - This is the current event being reported
1650
+ * @param itemCtx - This is the context for the current request, ITelemetryPlugin instances
1651
+ * can optionally use this to access the current core instance or define / pass additional information
1652
+ * to later plugins (vs appending items to the telemetry item)
1653
+ */
1654
+ processTelemetry: (env: ITelemetryItem, itemCtx?: IProcessTelemetryContext) => void;
1655
+ /**
1656
+ * The the plugin should re-evaluate configuration and update any cached configuration settings or
1657
+ * plugins. If implemented this method will be called whenever a plugin is added or removed and if
1658
+ * the configuration has bee updated.
1659
+ * @param updateCtx - This is the context that should be used during updating.
1660
+ * @param updateState - The details / state of the update process, it holds details like the current and previous configuration.
1661
+ * @returns boolean - true if the plugin has or will call updateCtx.processNext(), this allows the plugin to perform any asynchronous operations.
1662
+ */
1663
+ update?: (updateCtx: IProcessTelemetryUpdateContext, updateState: ITelemetryUpdateState) => void | boolean;
1664
+ }
1665
+
1666
+ interface ITelemetryUnloadState {
1667
+ reason: TelemetryUnloadReason;
1668
+ isAsync: boolean;
1669
+ flushComplete?: boolean;
1670
+ }
1671
+
1672
+ interface ITelemetryUpdateState {
1673
+ /**
1674
+ * Identifies the reason for the update notification, this is a bitwise numeric value
1675
+ */
1676
+ reason: TelemetryUpdateReason;
1677
+ /**
1678
+ * This is a new active configuration that should be used
1679
+ */
1680
+ cfg?: IConfiguration;
1681
+ /**
1682
+ * The detected changes
1683
+ */
1684
+ oldCfg?: IConfiguration;
1685
+ /**
1686
+ * If this is a configuration update this was the previous configuration that was used
1687
+ */
1688
+ newConfig?: IConfiguration;
1689
+ /**
1690
+ * Was the new config requested to be merged with the existing config
1691
+ */
1692
+ merge?: boolean;
1693
+ /**
1694
+ * This holds a collection of plugins that have been added (if the reason identifies that one or more plugins have been added)
1695
+ */
1696
+ added?: IPlugin[];
1697
+ /**
1698
+ * This holds a collection of plugins that have been removed (if the reason identifies that one or more plugins have been removed)
1699
+ */
1700
+ removed?: IPlugin[];
1701
+ }
1702
+
1703
+ /**
1704
+ * A Timer handler which is returned from {@link scheduleTimeout} which contains functions to
1705
+ * cancel or restart (refresh) the timeout function.
1706
+ *
1707
+ * @since 0.4.4
1708
+ * @group Timer
1709
+ */
1710
+ interface ITimerHandler {
1711
+ /**
1712
+ * Cancels a timeout that was previously scheduled, after calling this function any previously
1713
+ * scheduled timer will not execute.
1714
+ * @example
1715
+ * ```ts
1716
+ * let theTimer = scheduleTimeout(...);
1717
+ * theTimer.cancel();
1718
+ * ```
1719
+ */
1720
+ cancel(): void;
1721
+ /**
1722
+ * Reschedules the timer to call its callback at the previously specified duration
1723
+ * adjusted to the current time. This is useful for refreshing a timer without allocating
1724
+ * a new JavaScript object.
1725
+ *
1726
+ * Using this on a timer that has already called its callback will reactivate the timer.
1727
+ * Calling on a timer that has not yet executed will just reschedule the current timer.
1728
+ * @example
1729
+ * ```ts
1730
+ * let theTimer = scheduleTimeout(...);
1731
+ * // The timer will be restarted (if already executed) or rescheduled (if it has not yet executed)
1732
+ * theTimer.refresh();
1733
+ * ```
1734
+ */
1735
+ refresh(): ITimerHandler;
1736
+ /**
1737
+ * When called, requests that the event loop not exit so long when the ITimerHandler is active.
1738
+ * Calling timer.ref() multiple times will have no effect. By default, all ITimerHandler objects
1739
+ * will create "ref'ed" instances, making it normally unnecessary to call timer.ref() unless
1740
+ * timer.unref() had been called previously.
1741
+ * @since 0.7.0
1742
+ * @returns the ITimerHandler instance
1743
+ * @example
1744
+ * ```ts
1745
+ * let theTimer = createTimeout(...);
1746
+ *
1747
+ * // Make sure the timer is referenced (the default) so that the runtime (Node) does not terminate
1748
+ * // if there is a waiting referenced timer.
1749
+ * theTimer.ref();
1750
+ * ```
1751
+ */
1752
+ ref(): this;
1753
+ /**
1754
+ * When called, the any active ITimerHandler instance will not require the event loop to remain
1755
+ * active (Node.js). If there is no other activity keeping the event loop running, the process may
1756
+ * exit before the ITimerHandler instance callback is invoked. Calling timer.unref() multiple times
1757
+ * will have no effect.
1758
+ * @since 0.7.0
1759
+ * @returns the ITimerHandler instance
1760
+ * @example
1761
+ * ```ts
1762
+ * let theTimer = createTimeout(...);
1763
+ *
1764
+ * // Unreference the timer so that the runtime (Node) may terminate if nothing else is running.
1765
+ * theTimer.unref();
1766
+ * ```
1767
+ */
1768
+ unref(): this;
1769
+ /**
1770
+ * If true, any running referenced `ITimerHandler` instance will keep the Node.js event loop active.
1771
+ * @since 0.7.0
1772
+ * @example
1773
+ * ```ts
1774
+ * let theTimer = createTimeout(...);
1775
+ *
1776
+ * // Unreference the timer so that the runtime (Node) may terminate if nothing else is running.
1777
+ * theTimer.unref();
1778
+ * let hasRef = theTimer.hasRef(); // false
1779
+ *
1780
+ * theTimer.ref();
1781
+ * hasRef = theTimer.hasRef(); // true
1782
+ * ```
1783
+ */
1784
+ hasRef(): boolean;
1785
+ /**
1786
+ * Gets or Sets a flag indicating if the underlying timer is currently enabled and running.
1787
+ * Setting the enabled flag to the same as it's current value has no effect, setting to `true`
1788
+ * when already `true` will not {@link ITimerHandler.refresh | refresh}() the timer.
1789
+ * And setting to 'false` will {@link ITimerHandler.cancel | cancel}() the timer.
1790
+ * @since 0.8.1
1791
+ * @example
1792
+ * ```ts
1793
+ * let theTimer = createTimeout(...);
1794
+ *
1795
+ * // Check if enabled
1796
+ * theTimer.enabled; // false
1797
+ *
1798
+ * // Start the timer
1799
+ * theTimer.enabled = true; // Same as calling refresh()
1800
+ * theTimer.enabled; //true
1801
+ *
1802
+ * // Has no effect as it's already running
1803
+ * theTimer.enabled = true;
1804
+ *
1805
+ * // Will refresh / restart the time
1806
+ * theTimer.refresh()
1807
+ *
1808
+ * let theTimer = scheduleTimeout(...);
1809
+ *
1810
+ * // Check if enabled
1811
+ * theTimer.enabled; // true
1812
+ * ```
1813
+ */
1814
+ enabled: boolean;
1815
+ }
1816
+
1817
+ /**
1818
+ * An interface which provides automatic removal during unloading of the component
1819
+ */
1820
+ interface IUnloadHook {
1821
+ /**
1822
+ * Self remove the referenced component
1823
+ */
1824
+ rm: () => void;
1825
+ }
1826
+
1827
+ /**
1828
+ * Interface which identifiesAdd this hook so that it is automatically removed during unloading
1829
+ * @param hooks - The single hook or an array of IInstrumentHook objects
1830
+ */
1831
+ interface IUnloadHookContainer {
1832
+ add: (hooks: IUnloadHook | IUnloadHook[] | Iterator<IUnloadHook> | ILegacyUnloadHook | ILegacyUnloadHook[] | Iterator<ILegacyUnloadHook>) => void;
1833
+ run: (logger?: IDiagnosticLogger) => void;
1834
+ }
1835
+
1836
+ interface IWatchDetails<T = IConfiguration> {
1837
+ /**
1838
+ * The current config object
1839
+ */
1840
+ cfg: T;
1841
+ /**
1842
+ * Set the value against the provided config/name with the value, the property
1843
+ * will be converted to be dynamic (if not already) as long as the provided config
1844
+ * is already a tracked dynamic object.
1845
+ * @throws TypeError if the provided config is not a monitored dynamic config
1846
+ */
1847
+ set: <C, V>(theConfig: C, name: string, value: V) => V;
1848
+ /**
1849
+ * Set default values for the config if not present.
1850
+ * @param theConfig - The configuration object to set default on (if missing)
1851
+ * @param defaultValues - The default values to apply to the config
1852
+ */
1853
+ setDf: <C>(theConfig: C, defaultValues: IConfigDefaults<C>) => C;
1854
+ /**
1855
+ * Set this named property of the target as referenced, which will cause any object or array instance
1856
+ * to be updated in-place rather than being entirely replaced. All other values will continue to be replaced.
1857
+ * @returns The referenced properties current value
1858
+ */
1859
+ ref: <C, V = any>(target: C, name: string) => V;
1860
+ /**
1861
+ * Set this named property of the target as read-only, which will block this single named property from
1862
+ * ever being changed for the target instance.
1863
+ * This does NOT freeze or seal the instance, it just stops the direct re-assignment of the named property,
1864
+ * if the value is a non-primitive (ie. an object or array) it's properties will still be mutable.
1865
+ * @returns The referenced properties current value
1866
+ */
1867
+ rdOnly: <C, V = any>(target: C, name: string) => V;
1868
+ }
1869
+
1870
+ const LoggingSeverity: EnumValue<typeof eLoggingSeverity>;
1871
+
1872
+ type LoggingSeverity = number | eLoggingSeverity;
1873
+
1874
+ /**
1875
+ * This defines the handler function for when a promise is rejected.
1876
+ * @param value This is the value passed as part of resolving the Promise
1877
+ * @return This may return a value, another Promise or void. @see {@link IPromise.then} for how the value is handled.
1878
+ */
1879
+ type RejectedPromiseHandler<T = never> = (((reason: any) => T | IPromise<T> | PromiseLike<T>) | undefined | null);
1880
+
1881
+ /**
1882
+ * This defines the handler function for when a promise is resolved.
1883
+ * @param value This is the value passed as part of resolving the Promise
1884
+ * @return This may return a value, another Promise or void. @see {@link IPromise.then} for how the value is handled.
1885
+ */
1886
+ type ResolvedPromiseHandler<T, TResult1 = T> = (((value: T) => TResult1 | IPromise<TResult1> | PromiseLike<TResult1>) | undefined | null);
1887
+
1888
+ /**
1889
+ * The EventsDiscardedReason enumeration contains a set of values that specify the reason for discarding an event.
1890
+ */
1891
+ const enum SendRequestReason {
1892
+ /**
1893
+ * No specific reason was specified
1894
+ */
1895
+ Undefined = 0,
1896
+ /**
1897
+ * Events are being sent based on the normal event schedule / timer.
1898
+ */
1899
+ NormalSchedule = 1,
1900
+ /**
1901
+ * A manual flush request was received
1902
+ */
1903
+ ManualFlush = 1,
1904
+ /**
1905
+ * Unload event is being processed
1906
+ */
1907
+ Unload = 2,
1908
+ /**
1909
+ * The event(s) being sent are sync events
1910
+ */
1911
+ SyncEvent = 3,
1912
+ /**
1913
+ * The Channel was resumed
1914
+ */
1915
+ Resumed = 4,
1916
+ /**
1917
+ * The event(s) being sent as a retry
1918
+ */
1919
+ Retry = 5,
1920
+ /**
1921
+ * The SDK is unloading
1922
+ */
1923
+ SdkUnload = 6,
1924
+ /**
1925
+ * Maximum batch size would be exceeded
1926
+ */
1927
+ MaxBatchSize = 10,
1928
+ /**
1929
+ * The Maximum number of events have already been queued
1930
+ */
1931
+ MaxQueuedEvents = 20
1932
+ }
1933
+
1934
+ interface Tags {
1935
+ [key: string]: any;
1936
+ }
1937
+
1938
+ type TelemetryInitializerFunction = <T extends ITelemetryItem>(item: T) => boolean | void;
1939
+
1940
+ /**
1941
+ * The TelemetryUnloadReason enumeration contains the possible reasons for why a plugin is being unloaded / torndown().
1942
+ */
1943
+ const enum TelemetryUnloadReason {
1944
+ /**
1945
+ * Teardown has been called without any context.
1946
+ */
1947
+ ManualTeardown = 0,
1948
+ /**
1949
+ * Just this plugin is being removed
1950
+ */
1951
+ PluginUnload = 1,
1952
+ /**
1953
+ * This instance of the plugin is being removed and replaced
1954
+ */
1955
+ PluginReplace = 2,
1956
+ /**
1957
+ * The entire SDK is being unloaded
1958
+ */
1959
+ SdkUnload = 50
1960
+ }
1961
+
1962
+ /**
1963
+ * The TelemetryUpdateReason enumeration contains a set of bit-wise values that specify the reason for update request.
1964
+ */
1965
+ const enum TelemetryUpdateReason {
1966
+ /**
1967
+ * Unknown.
1968
+ */
1969
+ Unknown = 0,
1970
+ /**
1971
+ * The configuration has ben updated or changed
1972
+ */
1973
+ ConfigurationChanged = 1,
1974
+ /**
1975
+ * One or more plugins have been added
1976
+ */
1977
+ PluginAdded = 16,
1978
+ /**
1979
+ * One or more plugins have been removed
1980
+ */
1981
+ PluginRemoved = 32
1982
+ }
1983
+
1984
+ type UnloadHandler = (itemCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
1985
+
1986
+ type WatcherFunction<T = IConfiguration> = (details: IWatchDetails<T>) => void;
1987
+
55
1988
  }