@microsoft/applicationinsights-core-js 2.8.0-beta.2203-10 → 2.8.0-beta.2203-11

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 (88) hide show
  1. package/browser/applicationinsights-core-js.integrity.json +9 -9
  2. package/browser/applicationinsights-core-js.js +35 -10
  3. package/browser/applicationinsights-core-js.js.map +1 -1
  4. package/browser/applicationinsights-core-js.min.js +2 -2
  5. package/browser/applicationinsights-core-js.min.js.map +1 -1
  6. package/dist/applicationinsights-core-js.api.json +493 -58
  7. package/dist/applicationinsights-core-js.api.md +42 -23
  8. package/dist/applicationinsights-core-js.d.ts +47 -22
  9. package/dist/applicationinsights-core-js.js +35 -10
  10. package/dist/applicationinsights-core-js.js.map +1 -1
  11. package/dist/applicationinsights-core-js.min.js +2 -2
  12. package/dist/applicationinsights-core-js.min.js.map +1 -1
  13. package/dist/applicationinsights-core-js.rollup.d.ts +48 -23
  14. package/dist-esm/JavaScriptSDK/AppInsightsCore.js +1 -1
  15. package/dist-esm/JavaScriptSDK/BaseCore.js +11 -9
  16. package/dist-esm/JavaScriptSDK/BaseCore.js.map +1 -1
  17. package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js +1 -1
  18. package/dist-esm/JavaScriptSDK/ChannelController.js +1 -1
  19. package/dist-esm/JavaScriptSDK/Constants.js +1 -1
  20. package/dist-esm/JavaScriptSDK/CookieMgr.js +1 -1
  21. package/dist-esm/JavaScriptSDK/CoreUtils.js +1 -1
  22. package/dist-esm/JavaScriptSDK/DataCacheHelper.js +2 -2
  23. package/dist-esm/JavaScriptSDK/DataCacheHelper.js.map +1 -1
  24. package/dist-esm/JavaScriptSDK/DbgExtensionUtils.js +1 -1
  25. package/dist-esm/JavaScriptSDK/DiagnosticLogger.js +1 -1
  26. package/dist-esm/JavaScriptSDK/EnvUtils.js +1 -1
  27. package/dist-esm/JavaScriptSDK/EventHelpers.js +2 -6
  28. package/dist-esm/JavaScriptSDK/EventHelpers.js.map +1 -1
  29. package/dist-esm/JavaScriptSDK/HelperFuncs.js +1 -1
  30. package/dist-esm/JavaScriptSDK/InstrumentHooks.js +1 -1
  31. package/dist-esm/JavaScriptSDK/InternalConstants.js +1 -1
  32. package/dist-esm/JavaScriptSDK/NotificationManager.js +1 -1
  33. package/dist-esm/JavaScriptSDK/PerfManager.js +1 -1
  34. package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js +1 -1
  35. package/dist-esm/JavaScriptSDK/RandomHelper.js +1 -1
  36. package/dist-esm/JavaScriptSDK/TelemetryHelpers.js +29 -2
  37. package/dist-esm/JavaScriptSDK/TelemetryHelpers.js.map +1 -1
  38. package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js +1 -1
  39. package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js +1 -1
  40. package/dist-esm/JavaScriptSDK.Enums/EventsDiscardedReason.js +1 -1
  41. package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js +1 -1
  42. package/dist-esm/JavaScriptSDK.Enums/SendRequestReason.js +1 -1
  43. package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js +1 -1
  44. package/dist-esm/JavaScriptSDK.Enums/TelemetryUpdateReason.js +1 -1
  45. package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js +1 -1
  46. package/dist-esm/JavaScriptSDK.Interfaces/IChannelControls.js +1 -1
  47. package/dist-esm/JavaScriptSDK.Interfaces/IConfiguration.js +1 -1
  48. package/dist-esm/JavaScriptSDK.Interfaces/ICookieMgr.js +1 -1
  49. package/dist-esm/JavaScriptSDK.Interfaces/IDbgExtension.js +1 -1
  50. package/dist-esm/JavaScriptSDK.Interfaces/IDiagnosticLogger.js +1 -1
  51. package/dist-esm/JavaScriptSDK.Interfaces/IInstrumentHooks.js +1 -1
  52. package/dist-esm/JavaScriptSDK.Interfaces/INotificationListener.js +1 -1
  53. package/dist-esm/JavaScriptSDK.Interfaces/INotificationManager.js +1 -1
  54. package/dist-esm/JavaScriptSDK.Interfaces/IPerfEvent.js +1 -1
  55. package/dist-esm/JavaScriptSDK.Interfaces/IPerfManager.js +1 -1
  56. package/dist-esm/JavaScriptSDK.Interfaces/IProcessTelemetryContext.js +1 -1
  57. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js +1 -1
  58. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryItem.js +1 -1
  59. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPlugin.js +1 -1
  60. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js +1 -1
  61. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js +1 -1
  62. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUpdateState.js +1 -1
  63. package/dist-esm/JavaScriptSDK.Interfaces/IUnloadableComponent.js +6 -0
  64. package/dist-esm/JavaScriptSDK.Interfaces/IUnloadableComponent.js.map +1 -0
  65. package/dist-esm/applicationinsights-core-js.js +3 -3
  66. package/dist-esm/applicationinsights-core-js.js.map +1 -1
  67. package/package.json +2 -2
  68. package/src/JavaScriptSDK/BaseCore.ts +22 -20
  69. package/src/JavaScriptSDK/ChannelController.ts +1 -1
  70. package/src/JavaScriptSDK/DataCacheHelper.ts +1 -1
  71. package/src/JavaScriptSDK/EventHelpers.ts +13 -17
  72. package/src/JavaScriptSDK/HelperFuncs.ts +7 -7
  73. package/src/JavaScriptSDK/InstrumentHooks.ts +1 -1
  74. package/src/JavaScriptSDK/PerfManager.ts +1 -1
  75. package/src/JavaScriptSDK/ProcessTelemetryContext.ts +6 -6
  76. package/src/JavaScriptSDK/TelemetryHelpers.ts +34 -2
  77. package/src/JavaScriptSDK.Interfaces/IProcessTelemetryContext.ts +1 -1
  78. package/src/JavaScriptSDK.Interfaces/ITelemetryUpdateState.ts +1 -1
  79. package/src/JavaScriptSDK.Interfaces/IUnloadableComponent.ts +17 -0
  80. package/types/JavaScriptSDK/EventHelpers.d.ts +10 -10
  81. package/types/JavaScriptSDK/HelperFuncs.d.ts +7 -7
  82. package/types/JavaScriptSDK/PerfManager.d.ts +1 -1
  83. package/types/JavaScriptSDK/ProcessTelemetryContext.d.ts +2 -2
  84. package/types/JavaScriptSDK/TelemetryHelpers.d.ts +13 -1
  85. package/types/JavaScriptSDK.Interfaces/IProcessTelemetryContext.d.ts +1 -1
  86. package/types/JavaScriptSDK.Interfaces/IUnloadableComponent.d.ts +13 -0
  87. package/types/applicationinsights-core-js.d.ts +4 -3
  88. package/types/tsdoc-metadata.json +1 -1
@@ -41,7 +41,7 @@ const strValidationError = "Plugins must provide initialize method";
41
41
  const strNotificationManager = "_notificationManager";
42
42
  const strSdkUnloadingError = "SDK is still unloading...";
43
43
  const strSdkNotInitialized = "SDK is not initialized";
44
- const strPluginUnloadFailed = "Failed to unload plugin";
44
+ // const strPluginUnloadFailed = "Failed to unload plugin";
45
45
 
46
46
  /**
47
47
  * Helper to create the default performance manager
@@ -126,22 +126,22 @@ export class BaseCore implements IAppInsightsCore {
126
126
  // NOTE!: DON'T set default values here, instead set them in the _initDefaults() function as it is also called during teardown()
127
127
  let _isInitialized: boolean;
128
128
  let _eventQueue: ITelemetryItem[];
129
- let _notificationManager: INotificationManager;
130
- let _perfManager: IPerfManager;
131
- let _cfgPerfManager: IPerfManager;
132
- let _cookieManager: ICookieMgr;
133
- let _pluginChain: ITelemetryPluginChain;
129
+ let _notificationManager: INotificationManager | null | undefined;
130
+ let _perfManager: IPerfManager | null;
131
+ let _cfgPerfManager: IPerfManager | null;
132
+ let _cookieManager: ICookieMgr | null;
133
+ let _pluginChain: ITelemetryPluginChain | null;
134
134
  let _configExtensions: IPlugin[];
135
- let _coreExtensions: ITelemetryPlugin[];
136
- let _channelControl: IChannelController;
137
- let _channelConfig: IChannelControls[][];
138
- let _channelQueue: _IInternalChannels[];
135
+ let _coreExtensions: ITelemetryPlugin[] | null;
136
+ let _channelControl: IChannelController | null;
137
+ let _channelConfig: IChannelControls[][] | null | undefined;
138
+ let _channelQueue: _IInternalChannels[] | null;
139
139
  let _isUnloading: boolean;
140
140
  let _telemetryInitializerPlugin: TelemetryInitializerPlugin;
141
- let _internalLogsEventName: string;
141
+ let _internalLogsEventName: string | null;
142
142
  let _evtNamespace: string;
143
143
  let _unloadHandlers: IUnloadHandlerContainer;
144
- let _debugListener: INotificationListener;
144
+ let _debugListener: INotificationListener | null;
145
145
 
146
146
  /**
147
147
  * Internal log poller
@@ -204,9 +204,11 @@ export class BaseCore implements IAppInsightsCore {
204
204
 
205
205
  _self.getTransmissionControls = (): IChannelControls[][] => {
206
206
  let controls: IChannelControls[][] = [];
207
- arrForEach(_channelQueue, (channels) => {
208
- controls.push(channels.queue);
209
- });
207
+ if (_channelQueue) {
208
+ arrForEach(_channelQueue, (channels) => {
209
+ controls.push(channels.queue);
210
+ });
211
+ }
210
212
 
211
213
  return objFreeze(controls);
212
214
  };
@@ -311,7 +313,7 @@ export class BaseCore implements IAppInsightsCore {
311
313
  * Periodically check logger.queue for log messages to be flushed
312
314
  */
313
315
  _self.pollInternalLogs = (eventName?: string): number => {
314
- _internalLogsEventName = eventName;
316
+ _internalLogsEventName = eventName || null;
315
317
 
316
318
  let interval = _self.config.diagnosticLogInterval;
317
319
  if (!interval || !(interval > 0)) {
@@ -418,7 +420,7 @@ export class BaseCore implements IAppInsightsCore {
418
420
  let removedPlugins: IPlugin[] = [existingPlugin.plugin];
419
421
  let unloadState: ITelemetryUnloadState = {
420
422
  reason: TelemetryUnloadReason.PluginReplace,
421
- isAsync: isAsync
423
+ isAsync: !!isAsync
422
424
  };
423
425
 
424
426
  _removePlugins(removedPlugins, unloadState, (removed) => {
@@ -450,7 +452,7 @@ export class BaseCore implements IAppInsightsCore {
450
452
 
451
453
  // Use a default logger so initialization errors are not dropped on the floor with full logging
452
454
  _self.logger = new DiagnosticLogger({ loggingLevelConsole: eLoggingSeverity.CRITICAL });
453
- _self.config = null;
455
+ _self.config = {};
454
456
  _self._extensions = [];
455
457
 
456
458
  _telemetryInitializerPlugin = new TelemetryInitializerPlugin();
@@ -461,7 +463,7 @@ export class BaseCore implements IAppInsightsCore {
461
463
  _cookieManager = null;
462
464
  _pluginChain = null;
463
465
  _coreExtensions = null;
464
- _configExtensions = null;
466
+ _configExtensions = [];
465
467
  _channelControl = null;
466
468
  _channelConfig = null;
467
469
  _channelQueue = null;
@@ -476,7 +478,7 @@ export class BaseCore implements IAppInsightsCore {
476
478
  }
477
479
 
478
480
  // Initialize or Re-initialize the plugins
479
- function _initPluginChain(config: IConfiguration, updateState: ITelemetryUpdateState) {
481
+ function _initPluginChain(config: IConfiguration, updateState: ITelemetryUpdateState | null) {
480
482
  // Extension validation
481
483
  let theExtensions = _validateExtensions(_self.logger, ChannelControllerPriority, _configExtensions);
482
484
 
@@ -61,7 +61,7 @@ export function createChannelControllerPlugin(channelQueue: _IInternalChannels[]
61
61
  return createProcessTelemetryContext(null, core.config, core, null)
62
62
  }
63
63
 
64
- function _processChannelQueue<T extends IBaseProcessingContext>(theChannels: _IInternalChannels[], itemCtx: T, processFn: (chainCtx: T) => void, onComplete: () => void) {
64
+ function _processChannelQueue<T extends IBaseProcessingContext>(theChannels: _IInternalChannels[], itemCtx: T, processFn: (chainCtx: T) => void, onComplete: (() => void) | null) {
65
65
  let waiting = theChannels ? (theChannels.length + 1) : 1;
66
66
 
67
67
  function _runChainOnComplete() {
@@ -7,7 +7,7 @@ import { newId } from "./RandomHelper";
7
7
 
8
8
  const _objDefineProperty = ObjDefineProperty;
9
9
 
10
- const version = "2.7.3";
10
+ const version = "2.8.0-beta.2203-11";
11
11
  let instanceName = "." + newId(6);
12
12
  let _dataUid = 0;
13
13
 
@@ -52,7 +52,7 @@ function _normalizeNamespace(name: string) {
52
52
  return name;
53
53
  }
54
54
 
55
- function _getEvtNamespace(eventName: string, evtNamespace?: string | string[]): IEventDetails {
55
+ function _getEvtNamespace(eventName: string | undefined, evtNamespace?: string | string[] | null): IEventDetails {
56
56
  if (evtNamespace) {
57
57
  let theNamespace: string = "";
58
58
  if (isArray(evtNamespace)) {
@@ -81,7 +81,7 @@ function _getEvtNamespace(eventName: string, evtNamespace?: string | string[]):
81
81
  }
82
82
  }
83
83
 
84
- let parsedEvent: any[] = (eventNamespace.exec(eventName) || []);
84
+ let parsedEvent: any[] = (eventNamespace.exec(eventName || "") || []);
85
85
 
86
86
  return {
87
87
  type: parsedEvent[1],
@@ -195,7 +195,7 @@ function _unregisterEvents(target: any, evtName: IEventDetails, unRegFn: (regEve
195
195
  }
196
196
  }
197
197
 
198
- export function mergeEvtNamespace(theNamespace: string, namespaces: string | string[]): string | string[] {
198
+ export function mergeEvtNamespace(theNamespace: string, namespaces?: string | string[] | null): string | string[] {
199
199
  let newNamespaces: string | string[];
200
200
 
201
201
  if (namespaces) {
@@ -225,7 +225,7 @@ export function mergeEvtNamespace(theNamespace: string, namespaces: string | str
225
225
  * @param useCapture [Optional] Defaults to false
226
226
  * @returns True if the function was bound successfully to the event, otherwise false
227
227
  */
228
- export function eventOn<T>(target: T, eventName: string, handlerRef: any, evtNamespace?: string | string[], useCapture: boolean = false) {
228
+ export function eventOn<T>(target: T, eventName: string, handlerRef: any, evtNamespace?: string | string[] | null, useCapture: boolean = false) {
229
229
  let result = false;
230
230
 
231
231
  if (target) {
@@ -263,7 +263,7 @@ export function eventOn<T>(target: T, eventName: string, handlerRef: any, evtNam
263
263
  * if the eventName also includes a namespace the namespace(s) are merged into a single namespace
264
264
  * @param useCapture [Optional] Defaults to false
265
265
  */
266
- export function eventOff<T>(target: T, eventName: string, handlerRef: any, evtNamespace?: string | string[], useCapture: boolean = false) {
266
+ export function eventOff<T>(target: T, eventName: string, handlerRef: any, evtNamespace?: string | string[] | null, useCapture: boolean = false) {
267
267
  if (target) {
268
268
  try {
269
269
  let evtName = _getEvtNamespace(eventName, evtNamespace);
@@ -321,7 +321,7 @@ export function detachEvent(obj: any, eventNameWithoutOn: string, handlerRef: an
321
321
  * @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.
322
322
  * @return {boolean} - true if the handler was successfully added
323
323
  */
324
- export function addEventHandler(eventName: string, callback: any, evtNamespace?: string | string[]): boolean {
324
+ export function addEventHandler(eventName: string, callback: any, evtNamespace?: string | string[] | null): boolean {
325
325
  let result = false;
326
326
  let w = getWindow();
327
327
  if (w) {
@@ -346,7 +346,7 @@ export function addEventHandler(eventName: string, callback: any, evtNamespace?:
346
346
  * otherwise this will only remove events with this specific handler.
347
347
  * @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.
348
348
  */
349
- export function removeEventHandler(eventName: string, callback: any, evtNamespace?: string | string[]) {
349
+ export function removeEventHandler(eventName: string, callback: any, evtNamespace?: string | string[] | null) {
350
350
  let w = getWindow();
351
351
  if (w) {
352
352
  eventOff(w, eventName, callback, evtNamespace);
@@ -367,7 +367,7 @@ export function removeEventHandler(eventName: string, callback: any, evtNamespac
367
367
  * @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.
368
368
  * @returns true - when at least one of the events was registered otherwise false
369
369
  */
370
- function _addEventListeners(events: string[], listener: any, excludeEvents: string[], evtNamespace: string | string[]): boolean {
370
+ function _addEventListeners(events: string[], listener: any, excludeEvents?: string[] | null, evtNamespace?: string | string[] | null): boolean {
371
371
  let added = false;
372
372
 
373
373
  if (listener && events && events.length > 0) {
@@ -391,7 +391,6 @@ function _addEventListeners(events: string[], listener: any, excludeEvents: stri
391
391
  * @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.
392
392
  * @returns true - when at least one of the events was registered otherwise false
393
393
  */
394
- // export function addEventListeners(events: string[], listener: any, excludeEvents?: string[], evtNamespace?: string): boolean {
395
394
  export function addEventListeners(events: string[], listener: any, excludeEvents?: string[], evtNamespace?: string | string[]): boolean {
396
395
  let added = false;
397
396
 
@@ -434,8 +433,7 @@ export function removeEventListeners(events: string[], listener: any, evtNamespa
434
433
  * @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.
435
434
  * @returns true - when at least one of the events was registered otherwise false
436
435
  */
437
- //export function addPageUnloadEventListener(listener: any, excludeEvents?: string[], evtNamespace?: string): boolean {
438
- export function addPageUnloadEventListener(listener: any, excludeEvents: string[], evtNamespace?: string | string[]): boolean {
436
+ export function addPageUnloadEventListener(listener: any, excludeEvents?: string[], evtNamespace?: string | string[]): boolean {
439
437
  // Hook the unload event for the document, window and body to ensure that the client events are flushed to the server
440
438
  // As just hooking the window does not always fire (on chrome) for page navigation's.
441
439
  return addEventListeners([strBeforeUnload, strUnload, strPageHide], listener, excludeEvents, evtNamespace);
@@ -464,8 +462,7 @@ export function removePageUnloadEventListener(listener: any, evtNamespace?: stri
464
462
  * Suggestion: pass as true if you are also calling addPageUnloadEventListener as that also hooks pagehide
465
463
  * @returns true - when at least one of the events was registered otherwise false
466
464
  */
467
- //export function addPageHideEventListener(listener: any, excludeEvents?: string[], evtNamespace?: string): boolean {
468
- export function addPageHideEventListener(listener: any, excludeEvents: string[], evtNamespace?: string | string[]): boolean {
465
+ export function addPageHideEventListener(listener: any, excludeEvents?: string[] | null, evtNamespace?: string | string[] | null): boolean {
469
466
 
470
467
  function _handlePageVisibility(evt: any) {
471
468
  let doc = getDocument();
@@ -498,7 +495,7 @@ export function addPageHideEventListener(listener: any, excludeEvents: string[],
498
495
  * @param evtNamespace - The unique namespace used when calling addPageShowEventListener
499
496
  */
500
497
 
501
- export function removePageHideEventListener(listener: any, evtNamespace?: string | string[]) {
498
+ export function removePageHideEventListener(listener: any, evtNamespace?: string | string[] | null) {
502
499
  // add the unique page show namespace to any provided namespace so we only remove the ones added by "pagehide"
503
500
  let newNamespaces = mergeEvtNamespace(strPageHideNamespace, evtNamespace);
504
501
  removeEventListeners([strPageHide], listener, newNamespaces);
@@ -516,8 +513,7 @@ export function removePageHideEventListener(listener: any, evtNamespace?: string
516
513
  * so that only the matching "removePageShowEventListener" can remove these events.
517
514
  * @returns true - when at least one of the events was registered otherwise false
518
515
  */
519
- //export function addPageShowEventListener(listener: any, excludeEvents?: string[], evtNamespace?: string): boolean {
520
- export function addPageShowEventListener(listener: any, excludeEvents: string[], evtNamespace?: string | string[]): boolean {
516
+ export function addPageShowEventListener(listener: any, excludeEvents?: string[] | null, evtNamespace?: string | string[] | null): boolean {
521
517
 
522
518
  function _handlePageVisibility(evt: any) {
523
519
  let doc = getDocument();
@@ -546,7 +542,7 @@ export function addPageShowEventListener(listener: any, excludeEvents: string[],
546
542
  * @param listener - The specific listener to remove for the 'pageshow' event only (ignored for 'visibilitychange')
547
543
  * @param evtNamespace - The unique namespace used when calling addPageShowEventListener
548
544
  */
549
- export function removePageShowEventListener(listener: any, evtNamespace?: string | string[]) {
545
+ export function removePageShowEventListener(listener: any, evtNamespace?: string | string[] | null) {
550
546
  // add the unique page show namespace to any provided namespace so we only remove the ones added by "pageshow"
551
547
  let newNamespaces = mergeEvtNamespace(strPageShowNamespace, evtNamespace);
552
548
  removeEventListeners([strPageShow], listener, newNamespaces);
@@ -89,19 +89,19 @@ export function isTypeof(value: any, theType: string): boolean {
89
89
  return typeof value === theType;
90
90
  }
91
91
 
92
- export function isUndefined(value: any): boolean {
92
+ export function isUndefined(value: any): value is undefined {
93
93
  return value === undefined || typeof value === strShimUndefined;
94
94
  }
95
95
 
96
- export function isNotUndefined(value: any): boolean {
96
+ export function isNotUndefined<T>(value: T): value is T {
97
97
  return !isUndefined(value);
98
98
  }
99
99
 
100
- export function isNullOrUndefined(value: any): boolean {
100
+ export function isNullOrUndefined(value: any): value is null | undefined {
101
101
  return (value === null || isUndefined(value));
102
102
  }
103
103
 
104
- export function isNotNullOrUndefined(value: any): boolean {
104
+ export function isNotNullOrUndefined<T>(value: T): value is T {
105
105
  return !isNullOrUndefined(value);
106
106
  }
107
107
 
@@ -109,7 +109,7 @@ export function hasOwnProperty(obj: any, prop: string): boolean {
109
109
  return !!(obj && ObjHasOwnProperty.call(obj, prop));
110
110
  }
111
111
 
112
- export function isObject(value: any): boolean {
112
+ export function isObject<T>(value: T): value is T {
113
113
  // Changing to inline for performance
114
114
  return !!(value && typeof value === strShimObject);
115
115
  }
@@ -389,7 +389,7 @@ export function _toISOStringPoly(date: Date) {
389
389
  * @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array. It can return -1 to break out of the loop
390
390
  * @param thisArg [Optional] An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
391
391
  */
392
- export function arrForEach<T = any>(arr: T[], callbackfn: (value: T, index?: number, array?: T[]) => void|number, thisArg?: any): void {
392
+ export function arrForEach<T = any>(arr: T[], callbackfn: (value: T, index?: number, array?: T[]) => undefined | void | number, thisArg?: any): void {
393
393
  let len = arr.length;
394
394
  try {
395
395
  for (let idx = 0; idx < len; idx++) {
@@ -661,7 +661,7 @@ export function getExceptionName(object: any): string {
661
661
  * @param srcChk - [Optional] Callback to check to original value that if supplied will be called if the new value should be set (if allowed)
662
662
  * @returns The existing or new value, depending what was set
663
663
  */
664
- export function setValue<T, K extends keyof T>(target: T, field: K, value: T[K], valChk?: (value: T[K]) => boolean, srcChk?: (value: T[K]) => boolean) {
664
+ export function setValue<T, K extends keyof T>(target: T, field: K, value: T[K], valChk?: ((value: T[K]) => boolean) | null, srcChk?: ((value: T[K]) => boolean) | null) {
665
665
  let theValue = value;
666
666
  if (target) {
667
667
  theValue = target[field];
@@ -73,7 +73,7 @@ function _doCallbacks(hooks:IInstrumentHook[], callDetails: IInstrumentCallDetai
73
73
  function _createFunctionHook(aiHook:IInstrumentHooks) {
74
74
 
75
75
  // Define a temporary method that queues-up a the real method call
76
- return function () {
76
+ return function (this: any) {
77
77
  let funcThis = this;
78
78
  // Capture the original arguments passed to the method
79
79
  let orgArgs = arguments as any;
@@ -143,7 +143,7 @@ export class PerfManager implements IPerfManager {
143
143
  */
144
144
  private ctx: { [key: string] : any } = {};
145
145
 
146
- constructor(manager: INotificationManager) {
146
+ constructor(manager?: INotificationManager) {
147
147
 
148
148
  dynamicProto(PerfManager, this, (_self) => {
149
149
 
@@ -26,7 +26,7 @@ const strGetTelCtx = "_getTelCtx";
26
26
  let _chainId = 0;
27
27
 
28
28
  interface OnCompleteCallback {
29
- func: Function;
29
+ func: () => void;
30
30
  self: any; // This for the function
31
31
  args: any[]; // Additional arguments for the function
32
32
  }
@@ -67,7 +67,7 @@ function _getNextProxyStart(proxy: ITelemetryPluginChain, config: IConfiguration
67
67
  function _createInternalContext<T extends IBaseProcessingContext>(telemetryChain: ITelemetryPluginChain, config: IConfiguration, core:IAppInsightsCore, startAt?: IPlugin): IInternalContext<T> {
68
68
  // We have a special case where we want to start execution from this specific plugin
69
69
  // or we simply reuse the existing telemetry plugin chain (normal execution case)
70
- let _nextProxy: ITelemetryPluginChain = null; // By Default set as no next plugin
70
+ let _nextProxy: ITelemetryPluginChain | null = null; // By Default set as no next plugin
71
71
  let _onComplete: OnCompleteCallback[] = [];
72
72
 
73
73
  if (startAt !== null) {
@@ -103,7 +103,7 @@ function _createInternalContext<T extends IBaseProcessingContext>(telemetryChain
103
103
  } as T
104
104
  };
105
105
 
106
- function _addOnComplete(onComplete: Function, that?: any, ...args: any[]) {
106
+ function _addOnComplete(onComplete: () => void, that?: any, ...args: any[]) {
107
107
  if (onComplete) {
108
108
  _onComplete.push({
109
109
  func: onComplete,
@@ -211,7 +211,7 @@ function _createInternalContext<T extends IBaseProcessingContext>(telemetryChain
211
211
  * @param core - The current core instance
212
212
  * @param startAt - Identifies the next plugin to execute, if null there is no "next" plugin and if undefined it should assume the start of the chain
213
213
  */
214
- export function createProcessTelemetryContext(telemetryChain: ITelemetryPluginChain, config: IConfiguration, core:IAppInsightsCore, startAt?: IPlugin): IProcessTelemetryContext {
214
+ export function createProcessTelemetryContext(telemetryChain: ITelemetryPluginChain | null, config: IConfiguration, core:IAppInsightsCore, startAt?: IPlugin): IProcessTelemetryContext {
215
215
  let internalContext: IInternalContext<IProcessTelemetryContext> = _createInternalContext<IProcessTelemetryContext>(telemetryChain, config, core, startAt);
216
216
  let context = internalContext.ctx;
217
217
 
@@ -223,7 +223,7 @@ export function createProcessTelemetryContext(telemetryChain: ITelemetryPluginCh
223
223
  return !nextPlugin;
224
224
  }
225
225
 
226
- function _createNew(plugins: IPlugin[] | ITelemetryPluginChain = null, startAt?: IPlugin) {
226
+ function _createNew(plugins: IPlugin[] | ITelemetryPluginChain | null = null, startAt?: IPlugin) {
227
227
  if (isArray(plugins)) {
228
228
  plugins = createTelemetryProxyChain(plugins, config, core, startAt);
229
229
  }
@@ -562,7 +562,7 @@ export class ProcessTelemetryContext implements IProcessTelemetryContext {
562
562
 
563
563
  public getExtCfg: <T>(identifier:string, defaultValue?:T|any) => T;
564
564
 
565
- public getConfig: (identifier:string, field: string, defaultValue?: number | string | boolean) => number | string | boolean;
565
+ public getConfig: (identifier:string, field: string, defaultValue?: number | string | boolean | string[] | RegExp[] | Function) => number | string | boolean | string[] | RegExp[] | Function;
566
566
 
567
567
  /**
568
568
  * Returns the IAppInsightsCore instance for the current request
@@ -3,13 +3,16 @@
3
3
  "use strict";
4
4
 
5
5
  import { IPlugin, ITelemetryPlugin } from "../JavaScriptSDK.Interfaces/ITelemetryPlugin";
6
- import { IProcessTelemetryContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
6
+ import { IProcessTelemetryContext, IProcessTelemetryUnloadContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
7
7
  import { ITelemetryPluginChain } from "../JavaScriptSDK.Interfaces/ITelemetryPluginChain";
8
8
  import { arrForEach, isFunction } from "./HelperFuncs";
9
- import { strCore, strIsInitialized, strPriority, strProcessTelemetry, strSetNextPlugin, strTeardown } from "./InternalConstants";
9
+ import { strCore, strDoTeardown, strIsInitialized, strPriority, strProcessTelemetry, strSetNextPlugin, strTeardown } from "./InternalConstants";
10
10
  import { createElmNodeData } from "./DataCacheHelper";
11
11
  import { IAppInsightsCore } from "../JavaScriptSDK.Interfaces/IAppInsightsCore";
12
+ import { IUnloadableComponent } from "../JavaScriptSDK.Interfaces/IUnloadableComponent";
13
+ import { ITelemetryUnloadState } from "../JavaScriptSDK.Interfaces/ITelemetryUnloadState";
12
14
 
15
+ const strDoUnload = "_doUnload";
13
16
  export interface IPluginState {
14
17
  core?: IAppInsightsCore;
15
18
  isInitialized?: boolean;
@@ -100,4 +103,33 @@ export function sortPlugins<T = IPlugin>(plugins:T[]) {
100
103
  return result;
101
104
  });
102
105
  // sort complete
106
+ }
107
+
108
+ /**
109
+ * Teardown / Unload helper to perform teardown/unloading operations for the provided components synchronously or asynchronously, this will call any
110
+ * _doTeardown() or _doUnload() functions on the provided components to allow them to finish removal.
111
+ * @param components - The components you want to unload
112
+ * @param unloadCtx - This is the context that should be used during unloading.
113
+ * @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.
114
+ * @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.
115
+ * @returns boolean - true if the plugin has or will call asyncCallback, this allows the plugin to perform any asynchronous operations.
116
+ */
117
+ export function unloadComponents(components: any | IUnloadableComponent[], unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState, asyncCallback?: () => void): void | boolean {
118
+ let idx = 0;
119
+
120
+ function _doUnload(): void | boolean {
121
+ while (idx < components.length) {
122
+ let component = components[idx++];
123
+ if (component) {
124
+ let func = component[strDoUnload] || component[strDoTeardown];
125
+ if (isFunction(func)) {
126
+ if (func.call(component, unloadCtx, unloadState, _doUnload) === true) {
127
+ return true;
128
+ }
129
+ }
130
+ }
131
+ }
132
+ }
133
+
134
+ return _doUnload();
103
135
  }
@@ -76,7 +76,7 @@ export interface IBaseProcessingContext {
76
76
  * @param that - The "this" value to use for the onComplete call, if not provided or undefined defaults to the current context
77
77
  * @param args - Any additional arguments to pass to the onComplete function
78
78
  */
79
- onComplete: (onComplete: Function, that?: any, ...args: any[]) => void;
79
+ onComplete: (onComplete: () => void, that?: any, ...args: any[]) => void;
80
80
 
81
81
  /**
82
82
  * Create a new context using the core and config from the current instance, returns a new instance of the same type
@@ -2,7 +2,7 @@
2
2
  // Licensed under the MIT License.
3
3
 
4
4
  import { TelemetryUpdateReason } from "../JavaScriptSDK.Enums/TelemetryUpdateReason";
5
- import { IConfiguration } from "./IConfiguration";
5
+ //import { IConfiguration } from "./IConfiguration";
6
6
  import { IPlugin } from "./ITelemetryPlugin";
7
7
 
8
8
  export interface ITelemetryUpdateState {
@@ -0,0 +1,17 @@
1
+ import { IProcessTelemetryUnloadContext } from "./IProcessTelemetryContext";
2
+ import { ITelemetryUnloadState } from "./ITelemetryUnloadState";
3
+
4
+ // Copyright (c) Microsoft Corporation. All rights reserved.
5
+ // Licensed under the MIT License.
6
+
7
+ export interface IUnloadableComponent {
8
+ /**
9
+ * Teardown / Unload hook to allow implementations to perform some additional unload operations before the BaseTelemetryPlugin
10
+ * finishes it's removal.
11
+ * @param unloadCtx - This is the context that should be used during unloading.
12
+ * @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.
13
+ * @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.
14
+ * @returns boolean - true if the plugin has or will call asyncCallback, this allows the plugin to perform any asynchronous operations.
15
+ */
16
+ _doUnload?: (unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState, asyncCallback?: () => void) => void | boolean;
17
+ }
@@ -11,7 +11,7 @@ export interface _IRegisteredEvents {
11
11
  * if the eventName also includes a namespace the namespace(s) are merged into a single namespace
12
12
  */
13
13
  export declare function __getRegisteredEvents(target: any, eventName?: string, evtNamespace?: string | string[]): _IRegisteredEvents[];
14
- export declare function mergeEvtNamespace(theNamespace: string, namespaces: string | string[]): string | string[];
14
+ export declare function mergeEvtNamespace(theNamespace: string, namespaces?: string | string[] | null): string | string[];
15
15
  /**
16
16
  * Binds the specified function to an event, so that the function gets called whenever the event fires on the object
17
17
  * @param obj Object to add the event too.
@@ -23,7 +23,7 @@ export declare function mergeEvtNamespace(theNamespace: string, namespaces: stri
23
23
  * @param useCapture [Optional] Defaults to false
24
24
  * @returns True if the function was bound successfully to the event, otherwise false
25
25
  */
26
- export declare function eventOn<T>(target: T, eventName: string, handlerRef: any, evtNamespace?: string | string[], useCapture?: boolean): boolean;
26
+ export declare function eventOn<T>(target: T, eventName: string, handlerRef: any, evtNamespace?: string | string[] | null, useCapture?: boolean): boolean;
27
27
  /**
28
28
  * Removes an event handler for the specified event
29
29
  * @param Object to remove the event from
@@ -36,7 +36,7 @@ export declare function eventOn<T>(target: T, eventName: string, handlerRef: any
36
36
  * if the eventName also includes a namespace the namespace(s) are merged into a single namespace
37
37
  * @param useCapture [Optional] Defaults to false
38
38
  */
39
- export declare function eventOff<T>(target: T, eventName: string, handlerRef: any, evtNamespace?: string | string[], useCapture?: boolean): void;
39
+ export declare function eventOff<T>(target: T, eventName: string, handlerRef: any, evtNamespace?: string | string[] | null, useCapture?: boolean): void;
40
40
  /**
41
41
  * Binds the specified function to an event, so that the function gets called whenever the event fires on the object
42
42
  * @param obj Object to add the event too.
@@ -64,7 +64,7 @@ export declare function detachEvent(obj: any, eventNameWithoutOn: string, handle
64
64
  * @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.
65
65
  * @return {boolean} - true if the handler was successfully added
66
66
  */
67
- export declare function addEventHandler(eventName: string, callback: any, evtNamespace?: string | string[]): boolean;
67
+ export declare function addEventHandler(eventName: string, callback: any, evtNamespace?: string | string[] | null): boolean;
68
68
  /**
69
69
  * Trys to remove event handler(s) for the specified event/namespace to the window, body and document
70
70
  * @param eventName {string} - The name of the event, with optional namespaces or just the namespaces,
@@ -74,7 +74,7 @@ export declare function addEventHandler(eventName: string, callback: any, evtNam
74
74
  * otherwise this will only remove events with this specific handler.
75
75
  * @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.
76
76
  */
77
- export declare function removeEventHandler(eventName: string, callback: any, evtNamespace?: string | string[]): void;
77
+ export declare function removeEventHandler(eventName: string, callback: any, evtNamespace?: string | string[] | null): void;
78
78
  /**
79
79
  * Bind the listener to the array of events
80
80
  * @param events An string array of event names to bind the listener to
@@ -102,7 +102,7 @@ export declare function removeEventListeners(events: string[], listener: any, ev
102
102
  * @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.
103
103
  * @returns true - when at least one of the events was registered otherwise false
104
104
  */
105
- export declare function addPageUnloadEventListener(listener: any, excludeEvents: string[], evtNamespace?: string | string[]): boolean;
105
+ export declare function addPageUnloadEventListener(listener: any, excludeEvents?: string[], evtNamespace?: string | string[]): boolean;
106
106
  /**
107
107
  * Remove any matching 'beforeunload', 'unload' and 'pagehide' events that may have been added via addEventListener,
108
108
  * addEventListeners, addPageUnloadEventListener or addPageHideEventListener.
@@ -123,7 +123,7 @@ export declare function removePageUnloadEventListener(listener: any, evtNamespac
123
123
  * Suggestion: pass as true if you are also calling addPageUnloadEventListener as that also hooks pagehide
124
124
  * @returns true - when at least one of the events was registered otherwise false
125
125
  */
126
- export declare function addPageHideEventListener(listener: any, excludeEvents: string[], evtNamespace?: string | string[]): boolean;
126
+ export declare function addPageHideEventListener(listener: any, excludeEvents?: string[] | null, evtNamespace?: string | string[] | null): boolean;
127
127
  /**
128
128
  * Removes the pageHide event listeners added by addPageHideEventListener, because the 'visibilitychange' uses
129
129
  * an internal proxy to detect the visibility state you SHOULD use a unique namespace when calling addPageHideEventListener
@@ -131,7 +131,7 @@ export declare function addPageHideEventListener(listener: any, excludeEvents: s
131
131
  * @param listener - The specific listener to remove for the 'pageshow' event only (ignored for 'visibilitychange')
132
132
  * @param evtNamespace - The unique namespace used when calling addPageShowEventListener
133
133
  */
134
- export declare function removePageHideEventListener(listener: any, evtNamespace?: string | string[]): void;
134
+ export declare function removePageHideEventListener(listener: any, evtNamespace?: string | string[] | null): void;
135
135
  /**
136
136
  * Listen to the pageshow and visibility changing to 'visible' events, because the 'visibilitychange' uses
137
137
  * an internal proxy to detect the visibility state you SHOULD use a unique namespace when if you plan to call
@@ -143,7 +143,7 @@ export declare function removePageHideEventListener(listener: any, evtNamespace?
143
143
  * so that only the matching "removePageShowEventListener" can remove these events.
144
144
  * @returns true - when at least one of the events was registered otherwise false
145
145
  */
146
- export declare function addPageShowEventListener(listener: any, excludeEvents: string[], evtNamespace?: string | string[]): boolean;
146
+ export declare function addPageShowEventListener(listener: any, excludeEvents?: string[] | null, evtNamespace?: string | string[] | null): boolean;
147
147
  /**
148
148
  * Removes the pageShow event listeners added by addPageShowEventListener, because the 'visibilitychange' uses
149
149
  * an internal proxy to detect the visibility state you SHOULD use a unique namespace when calling addPageShowEventListener
@@ -151,4 +151,4 @@ export declare function addPageShowEventListener(listener: any, excludeEvents: s
151
151
  * @param listener - The specific listener to remove for the 'pageshow' event only (ignored for 'visibilitychange')
152
152
  * @param evtNamespace - The unique namespace used when calling addPageShowEventListener
153
153
  */
154
- export declare function removePageShowEventListener(listener: any, evtNamespace?: string | string[]): void;
154
+ export declare function removePageShowEventListener(listener: any, evtNamespace?: string | string[] | null): void;
@@ -5,12 +5,12 @@
5
5
  export declare function _getObjProto(target: any): any;
6
6
  export declare function objToString(obj: any): any;
7
7
  export declare function isTypeof(value: any, theType: string): boolean;
8
- export declare function isUndefined(value: any): boolean;
9
- export declare function isNotUndefined(value: any): boolean;
10
- export declare function isNullOrUndefined(value: any): boolean;
11
- export declare function isNotNullOrUndefined(value: any): boolean;
8
+ export declare function isUndefined(value: any): value is undefined;
9
+ export declare function isNotUndefined<T>(value: T): value is T;
10
+ export declare function isNullOrUndefined(value: any): value is null | undefined;
11
+ export declare function isNotNullOrUndefined<T>(value: T): value is T;
12
12
  export declare function hasOwnProperty(obj: any, prop: string): boolean;
13
- export declare function isObject(value: any): boolean;
13
+ export declare function isObject<T>(value: T): value is T;
14
14
  export declare function isFunction(value: any): value is Function;
15
15
  export declare function isPromiseLike<T>(value: any): value is PromiseLike<T>;
16
16
  /**
@@ -121,7 +121,7 @@ export declare function _toISOStringPoly(date: Date): string;
121
121
  * @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array. It can return -1 to break out of the loop
122
122
  * @param thisArg [Optional] An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
123
123
  */
124
- export declare function arrForEach<T = any>(arr: T[], callbackfn: (value: T, index?: number, array?: T[]) => void | number, thisArg?: any): void;
124
+ export declare function arrForEach<T = any>(arr: T[], callbackfn: (value: T, index?: number, array?: T[]) => undefined | void | number, thisArg?: any): void;
125
125
  /**
126
126
  * Returns the index of the first occurrence of a value in an array. This helper exists to avoid adding a polyfil for older browsers
127
127
  * that do not define Array.prototype.xxxx (eg. ES3 only, IE8) just in case any page checks for presence/absence of the prototype
@@ -193,7 +193,7 @@ export declare function getExceptionName(object: any): string;
193
193
  * @param srcChk - [Optional] Callback to check to original value that if supplied will be called if the new value should be set (if allowed)
194
194
  * @returns The existing or new value, depending what was set
195
195
  */
196
- export declare function setValue<T, K extends keyof T>(target: T, field: K, value: T[K], valChk?: (value: T[K]) => boolean, srcChk?: (value: T[K]) => boolean): T[K];
196
+ export declare function setValue<T, K extends keyof T>(target: T, field: K, value: T[K], valChk?: ((value: T[K]) => boolean) | null, srcChk?: ((value: T[K]) => boolean) | null): T[K];
197
197
  /**
198
198
  * Returns the current value from the target object if not null or undefined otherwise sets the new value and returns it
199
199
  * @param target - The target object to return or set the default value
@@ -46,7 +46,7 @@ export declare class PerfManager implements IPerfManager {
46
46
  * Defined as private so it can be visualized via the DebugPlugin
47
47
  */
48
48
  private ctx;
49
- constructor(manager: INotificationManager);
49
+ constructor(manager?: INotificationManager);
50
50
  /**
51
51
  * Create a new event and start timing, the manager may return null/undefined to indicate that it does not
52
52
  * want to monitor this source event.
@@ -12,7 +12,7 @@ import { IDiagnosticLogger } from "../JavaScriptSDK.Interfaces/IDiagnosticLogger
12
12
  * @param core - The current core instance
13
13
  * @param startAt - Identifies the next plugin to execute, if null there is no "next" plugin and if undefined it should assume the start of the chain
14
14
  */
15
- export declare function createProcessTelemetryContext(telemetryChain: ITelemetryPluginChain, config: IConfiguration, core: IAppInsightsCore, startAt?: IPlugin): IProcessTelemetryContext;
15
+ export declare function createProcessTelemetryContext(telemetryChain: ITelemetryPluginChain | null, config: IConfiguration, core: IAppInsightsCore, startAt?: IPlugin): IProcessTelemetryContext;
16
16
  /**
17
17
  * Creates a new Telemetry Item context with the current config, core and plugin execution chain for handling the unloading of the chain
18
18
  * @param plugins - The plugin instances that will be executed
@@ -59,7 +59,7 @@ export declare class ProcessTelemetryContext implements IProcessTelemetryContext
59
59
  */
60
60
  getCfg: () => IConfiguration;
61
61
  getExtCfg: <T>(identifier: string, defaultValue?: T | any) => T;
62
- getConfig: (identifier: string, field: string, defaultValue?: number | string | boolean) => number | string | boolean;
62
+ getConfig: (identifier: string, field: string, defaultValue?: number | string | boolean | string[] | RegExp[] | Function) => number | string | boolean | string[] | RegExp[] | Function;
63
63
  /**
64
64
  * Returns the IAppInsightsCore instance for the current request
65
65
  */