@microsoft/1ds-post-js 4.1.0-nightly3.2402-08 → 4.1.0-nightly3.2402-12

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