@microsoft/applicationinsights-core-js 2.8.0-nightly.2202-06 → 2.8.0-nightly.2204-06

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 (167) hide show
  1. package/browser/applicationinsights-core-js.integrity.json +9 -9
  2. package/browser/applicationinsights-core-js.js +2440 -1199
  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 +16710 -8876
  7. package/dist/applicationinsights-core-js.api.md +465 -140
  8. package/dist/applicationinsights-core-js.d.ts +856 -217
  9. package/dist/applicationinsights-core-js.js +2440 -1199
  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 +856 -217
  14. package/dist-esm/JavaScriptSDK/AppInsightsCore.js +4 -72
  15. package/dist-esm/JavaScriptSDK/AppInsightsCore.js.map +1 -1
  16. package/dist-esm/JavaScriptSDK/BaseCore.js +496 -99
  17. package/dist-esm/JavaScriptSDK/BaseCore.js.map +1 -1
  18. package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js +120 -21
  19. package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js.map +1 -1
  20. package/dist-esm/JavaScriptSDK/ChannelController.js +202 -87
  21. package/dist-esm/JavaScriptSDK/ChannelController.js.map +1 -1
  22. package/dist-esm/JavaScriptSDK/Constants.js +1 -1
  23. package/dist-esm/JavaScriptSDK/CookieMgr.js +4 -4
  24. package/dist-esm/JavaScriptSDK/CookieMgr.js.map +1 -1
  25. package/dist-esm/JavaScriptSDK/CoreUtils.js +7 -148
  26. package/dist-esm/JavaScriptSDK/CoreUtils.js.map +1 -1
  27. package/dist-esm/JavaScriptSDK/DataCacheHelper.js +93 -0
  28. package/dist-esm/JavaScriptSDK/DataCacheHelper.js.map +1 -0
  29. package/dist-esm/JavaScriptSDK/DbgExtensionUtils.js +1 -1
  30. package/dist-esm/JavaScriptSDK/DiagnosticLogger.js +45 -12
  31. package/dist-esm/JavaScriptSDK/DiagnosticLogger.js.map +1 -1
  32. package/dist-esm/JavaScriptSDK/EnvUtils.js +13 -12
  33. package/dist-esm/JavaScriptSDK/EnvUtils.js.map +1 -1
  34. package/dist-esm/JavaScriptSDK/EventHelpers.js +477 -0
  35. package/dist-esm/JavaScriptSDK/EventHelpers.js.map +1 -0
  36. package/dist-esm/JavaScriptSDK/HelperFuncs.js +80 -86
  37. package/dist-esm/JavaScriptSDK/HelperFuncs.js.map +1 -1
  38. package/dist-esm/JavaScriptSDK/InstrumentHooks.js +3 -1
  39. package/dist-esm/JavaScriptSDK/InstrumentHooks.js.map +1 -1
  40. package/dist-esm/JavaScriptSDK/InternalConstants.js +28 -0
  41. package/dist-esm/JavaScriptSDK/InternalConstants.js.map +1 -0
  42. package/dist-esm/JavaScriptSDK/NotificationManager.js +37 -42
  43. package/dist-esm/JavaScriptSDK/NotificationManager.js.map +1 -1
  44. package/dist-esm/JavaScriptSDK/PerfManager.js +1 -1
  45. package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js +430 -119
  46. package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js.map +1 -1
  47. package/dist-esm/JavaScriptSDK/RandomHelper.js +30 -4
  48. package/dist-esm/JavaScriptSDK/RandomHelper.js.map +1 -1
  49. package/dist-esm/JavaScriptSDK/TelemetryHelpers.js +60 -14
  50. package/dist-esm/JavaScriptSDK/TelemetryHelpers.js.map +1 -1
  51. package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js +81 -0
  52. package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js.map +1 -0
  53. package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js +33 -0
  54. package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js.map +1 -0
  55. package/dist-esm/JavaScriptSDK.Enums/EnumHelperFuncs.js +51 -0
  56. package/dist-esm/JavaScriptSDK.Enums/EnumHelperFuncs.js.map +1 -0
  57. package/dist-esm/JavaScriptSDK.Enums/EventsDiscardedReason.js +10 -9
  58. package/dist-esm/JavaScriptSDK.Enums/EventsDiscardedReason.js.map +1 -1
  59. package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js +90 -96
  60. package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js.map +1 -1
  61. package/dist-esm/JavaScriptSDK.Enums/SendRequestReason.js +1 -1
  62. package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js +8 -0
  63. package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js.map +1 -0
  64. package/dist-esm/JavaScriptSDK.Enums/TelemetryUpdateReason.js +8 -0
  65. package/dist-esm/JavaScriptSDK.Enums/TelemetryUpdateReason.js.map +1 -0
  66. package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js +1 -2
  67. package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js.map +1 -1
  68. package/dist-esm/JavaScriptSDK.Interfaces/IChannelControls.js +1 -1
  69. package/dist-esm/JavaScriptSDK.Interfaces/IConfiguration.js +1 -1
  70. package/dist-esm/JavaScriptSDK.Interfaces/ICookieMgr.js +1 -1
  71. package/dist-esm/JavaScriptSDK.Interfaces/IDbgExtension.js +1 -1
  72. package/dist-esm/JavaScriptSDK.Interfaces/IDiagnosticLogger.js +1 -1
  73. package/dist-esm/JavaScriptSDK.Interfaces/IInstrumentHooks.js +1 -1
  74. package/dist-esm/JavaScriptSDK.Interfaces/INotificationListener.js +1 -1
  75. package/dist-esm/JavaScriptSDK.Interfaces/INotificationManager.js +1 -1
  76. package/dist-esm/JavaScriptSDK.Interfaces/IPerfEvent.js +1 -1
  77. package/dist-esm/JavaScriptSDK.Interfaces/IPerfManager.js +1 -1
  78. package/dist-esm/JavaScriptSDK.Interfaces/IProcessTelemetryContext.js +1 -1
  79. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js +6 -0
  80. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js.map +1 -0
  81. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryItem.js +1 -1
  82. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPlugin.js +1 -1
  83. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js +1 -2
  84. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js.map +1 -1
  85. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js +8 -0
  86. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js.map +1 -0
  87. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUpdateState.js +8 -0
  88. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUpdateState.js.map +1 -0
  89. package/dist-esm/JavaScriptSDK.Interfaces/IUnloadableComponent.js +6 -0
  90. package/dist-esm/JavaScriptSDK.Interfaces/IUnloadableComponent.js.map +1 -0
  91. package/dist-esm/applicationinsights-core-js.js +13 -7
  92. package/dist-esm/applicationinsights-core-js.js.map +1 -1
  93. package/package.json +2 -2
  94. package/src/JavaScriptSDK/AppInsightsCore.ts +4 -105
  95. package/src/JavaScriptSDK/BaseCore.ts +696 -120
  96. package/src/JavaScriptSDK/BaseTelemetryPlugin.ts +205 -31
  97. package/src/JavaScriptSDK/ChannelController.ts +242 -103
  98. package/src/JavaScriptSDK/CookieMgr.ts +7 -5
  99. package/src/JavaScriptSDK/CoreUtils.ts +8 -172
  100. package/src/JavaScriptSDK/DataCacheHelper.ts +106 -0
  101. package/src/JavaScriptSDK/DiagnosticLogger.ts +49 -12
  102. package/src/JavaScriptSDK/EnvUtils.ts +13 -12
  103. package/src/JavaScriptSDK/EventHelpers.ts +550 -0
  104. package/src/JavaScriptSDK/HelperFuncs.ts +114 -97
  105. package/src/JavaScriptSDK/InstrumentHooks.ts +4 -2
  106. package/src/JavaScriptSDK/InternalConstants.ts +26 -0
  107. package/src/JavaScriptSDK/NotificationManager.ts +34 -37
  108. package/src/JavaScriptSDK/PerfManager.ts +4 -7
  109. package/src/JavaScriptSDK/ProcessTelemetryContext.ts +543 -134
  110. package/src/JavaScriptSDK/RandomHelper.ts +35 -3
  111. package/src/JavaScriptSDK/TelemetryHelpers.ts +83 -21
  112. package/src/JavaScriptSDK/TelemetryInitializerPlugin.ts +111 -0
  113. package/src/JavaScriptSDK/UnloadHandlerContainer.ts +46 -0
  114. package/src/JavaScriptSDK.Enums/EnumHelperFuncs.ts +56 -0
  115. package/src/JavaScriptSDK.Enums/EventsDiscardedReason.ts +48 -8
  116. package/src/JavaScriptSDK.Enums/LoggingEnums.ts +183 -87
  117. package/src/JavaScriptSDK.Enums/SendRequestReason.ts +5 -0
  118. package/src/JavaScriptSDK.Enums/TelemetryUnloadReason.ts +27 -0
  119. package/src/JavaScriptSDK.Enums/TelemetryUpdateReason.ts +27 -0
  120. package/src/JavaScriptSDK.Interfaces/IAppInsightsCore.ts +82 -2
  121. package/src/JavaScriptSDK.Interfaces/IChannelControls.ts +16 -5
  122. package/src/JavaScriptSDK.Interfaces/IInstrumentHooks.ts +16 -6
  123. package/src/JavaScriptSDK.Interfaces/IProcessTelemetryContext.ts +94 -14
  124. package/src/JavaScriptSDK.Interfaces/ITelemetryInitializers.ts +16 -0
  125. package/src/JavaScriptSDK.Interfaces/ITelemetryPlugin.ts +28 -10
  126. package/src/JavaScriptSDK.Interfaces/ITelemetryPluginChain.ts +9 -11
  127. package/src/JavaScriptSDK.Interfaces/ITelemetryUnloadState.ts +10 -0
  128. package/src/JavaScriptSDK.Interfaces/ITelemetryUpdateState.ts +34 -0
  129. package/src/JavaScriptSDK.Interfaces/IUnloadableComponent.ts +17 -0
  130. package/types/JavaScriptSDK/AppInsightsCore.d.ts +0 -21
  131. package/types/JavaScriptSDK/BaseCore.d.ts +81 -3
  132. package/types/JavaScriptSDK/BaseTelemetryPlugin.d.ts +53 -10
  133. package/types/JavaScriptSDK/ChannelController.d.ts +16 -17
  134. package/types/JavaScriptSDK/CoreUtils.d.ts +1 -48
  135. package/types/JavaScriptSDK/DataCacheHelper.d.ts +13 -0
  136. package/types/JavaScriptSDK/DiagnosticLogger.d.ts +23 -0
  137. package/types/JavaScriptSDK/EventHelpers.d.ts +154 -0
  138. package/types/JavaScriptSDK/HelperFuncs.d.ts +37 -32
  139. package/types/JavaScriptSDK/InternalConstants.d.ts +20 -0
  140. package/types/JavaScriptSDK/PerfManager.d.ts +1 -1
  141. package/types/JavaScriptSDK/ProcessTelemetryContext.d.ts +69 -6
  142. package/types/JavaScriptSDK/RandomHelper.d.ts +6 -0
  143. package/types/JavaScriptSDK/TelemetryHelpers.d.ts +23 -3
  144. package/types/JavaScriptSDK/TelemetryInitializerPlugin.d.ts +16 -0
  145. package/types/JavaScriptSDK/UnloadHandlerContainer.d.ts +11 -0
  146. package/types/JavaScriptSDK.Enums/EnumHelperFuncs.d.ts +34 -0
  147. package/types/JavaScriptSDK.Enums/EventsDiscardedReason.d.ts +14 -9
  148. package/types/JavaScriptSDK.Enums/LoggingEnums.d.ts +89 -86
  149. package/types/JavaScriptSDK.Enums/SendRequestReason.d.ts +4 -0
  150. package/types/JavaScriptSDK.Enums/TelemetryUnloadReason.d.ts +21 -0
  151. package/types/JavaScriptSDK.Enums/TelemetryUpdateReason.d.ts +20 -0
  152. package/types/JavaScriptSDK.Interfaces/IAppInsightsCore.d.ts +72 -1
  153. package/types/JavaScriptSDK.Interfaces/IChannelControls.d.ts +16 -5
  154. package/types/JavaScriptSDK.Interfaces/IInstrumentHooks.d.ts +9 -0
  155. package/types/JavaScriptSDK.Interfaces/IProcessTelemetryContext.d.ts +82 -11
  156. package/types/JavaScriptSDK.Interfaces/ITelemetryInitializers.d.ts +13 -0
  157. package/types/JavaScriptSDK.Interfaces/ITelemetryPlugin.d.ts +25 -8
  158. package/types/JavaScriptSDK.Interfaces/ITelemetryPluginChain.d.ts +9 -10
  159. package/types/JavaScriptSDK.Interfaces/ITelemetryUnloadState.d.ts +6 -0
  160. package/types/JavaScriptSDK.Interfaces/ITelemetryUpdateState.d.ts +22 -0
  161. package/types/JavaScriptSDK.Interfaces/IUnloadableComponent.d.ts +13 -0
  162. package/types/applicationinsights-core-js.d.ts +20 -10
  163. package/types/tsdoc-metadata.json +1 -1
  164. package/dist-esm/JavaScriptSDK/TelemetryPluginChain.js +0 -76
  165. package/dist-esm/JavaScriptSDK/TelemetryPluginChain.js.map +0 -1
  166. package/src/JavaScriptSDK/TelemetryPluginChain.ts +0 -120
  167. package/types/JavaScriptSDK/TelemetryPluginChain.d.ts +0 -32
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Microsoft Application Insights Core Javascript SDK, 2.8.0-nightly.2202-06
2
+ * Microsoft Application Insights Core Javascript SDK, 2.8.0-nightly.2204-06
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  *
5
5
  * Microsoft Application Insights Team
@@ -20,39 +20,61 @@ import { strShimObject as strObject } from '@microsoft/applicationinsights-shims
20
20
  import { strShimPrototype as strPrototype } from '@microsoft/applicationinsights-shims';
21
21
  import { strShimUndefined as strUndefined } from '@microsoft/applicationinsights-shims';
22
22
 
23
+ /**
24
+ * Get all of the registered events on the target object, this is primarily used for testing cleanup but may also be used by
25
+ * applications to remove their own events
26
+ * @param target - The EventTarget that has registered events
27
+ * @param eventName - [Optional] The name of the event to return the registered handlers and full name (with namespaces)
28
+ * @param evtNamespace - [Optional] Additional namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace,
29
+ * if the eventName also includes a namespace the namespace(s) are merged into a single namespace
30
+ */
31
+ export declare function __getRegisteredEvents(target: any, eventName?: string, evtNamespace?: string | string[]): _IRegisteredEvents[];
32
+
23
33
  /**
24
34
  * Trys to add an event handler for the specified event to the window, body and document
25
35
  * @param eventName {string} - The name of the event
26
36
  * @param callback {any} - The callback function that needs to be executed for the given event
37
+ * @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.
27
38
  * @return {boolean} - true if the handler was successfully added
28
39
  */
29
- export declare function addEventHandler(eventName: string, callback: any): boolean;
40
+ export declare function addEventHandler(eventName: string, callback: any, evtNamespace?: string | string[] | null): boolean;
30
41
 
31
42
  /**
32
43
  * Bind the listener to the array of events
33
44
  * @param events An string array of event names to bind the listener to
34
45
  * @param listener The event callback to call when the event is triggered
35
46
  * @param excludeEvents - [Optional] An array of events that should not be hooked (if possible), unless no other events can be.
47
+ * @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.
36
48
  * @returns true - when at least one of the events was registered otherwise false
37
49
  */
38
- export declare function addEventListeners(events: string[], listener: any, excludeEvents?: string[]): boolean;
50
+ export declare function addEventListeners(events: string[], listener: any, excludeEvents?: string[], evtNamespace?: string | string[]): boolean;
39
51
 
40
52
  /**
41
- * Listen to the pagehide and visibility changing to 'hidden' events
53
+ * Listen to the pagehide and visibility changing to 'hidden' events, because the 'visibilitychange' uses
54
+ * an internal proxy to detect the visibility state you SHOULD use a unique namespace when if you plan to call
55
+ * removePageShowEventListener as the remove ignores the listener argument for the 'visibilitychange' event.
42
56
  * @param listener - The event callback to call when a page hide event is triggered
43
57
  * @param excludeEvents - [Optional] An array of events that should not be hooked (if possible), unless no other events can be.
58
+ * @param evtNamespace - [Optional] A Namespace to append to the event listeners so they can be uniquely identified and removed
59
+ * based on this namespace. This call also adds an additional unique "pageshow" namespace to the events
60
+ * so that only the matching "removePageHideEventListener" can remove these events.
44
61
  * Suggestion: pass as true if you are also calling addPageUnloadEventListener as that also hooks pagehide
45
62
  * @returns true - when at least one of the events was registered otherwise false
46
63
  */
47
- export declare function addPageHideEventListener(listener: any, excludeEvents?: string[]): boolean;
64
+ export declare function addPageHideEventListener(listener: any, excludeEvents?: string[] | null, evtNamespace?: string | string[] | null): boolean;
48
65
 
49
66
  /**
50
- * Listen to the pageshow and visibility changing to 'visible' events
67
+ * Listen to the pageshow and visibility changing to 'visible' events, because the 'visibilitychange' uses
68
+ * an internal proxy to detect the visibility state you SHOULD use a unique namespace when if you plan to call
69
+ * removePageShowEventListener as the remove ignores the listener argument for the 'visibilitychange' event.
51
70
  * @param listener - The event callback to call when a page is show event is triggered
52
71
  * @param excludeEvents - [Optional] An array of events that should not be hooked (if possible), unless no other events can be.
72
+ * @param evtNamespace - [Optional/Recommended] A Namespace to append to the event listeners so they can be uniquely
73
+ * identified and removed based on this namespace. This call also adds an additional unique "pageshow" namespace to the events
74
+ * so that only the matching "removePageShowEventListener" can remove these events.
53
75
  * @returns true - when at least one of the events was registered otherwise false
54
76
  */
55
- export declare function addPageShowEventListener(listener: any, excludeEvents?: string[]): boolean;
77
+ export declare function addPageShowEventListener(listener: any, excludeEvents?: string[] | null, evtNamespace?: string | string[] | null): boolean;
56
78
 
57
79
  /**
58
80
  * Listen to the 'beforeunload', 'unload' and 'pagehide' events which indicates a page unload is occurring,
@@ -62,34 +84,15 @@ export declare function addPageShowEventListener(listener: any, excludeEvents?:
62
84
  * need to listen to the 'addPageHideEventListener' and 'addPageShowEventListener' events.
63
85
  * @param listener - The event callback to call when a page unload event is triggered
64
86
  * @param excludeEvents - [Optional] An array of events that should not be hooked, unless no other events can be.
87
+ * @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.
65
88
  * @returns true - when at least one of the events was registered otherwise false
66
89
  */
67
- export declare function addPageUnloadEventListener(listener: any, excludeEvents?: string[]): boolean;
90
+ export declare function addPageUnloadEventListener(listener: any, excludeEvents?: string[], evtNamespace?: string | string[]): boolean;
68
91
 
69
92
  export declare class AppInsightsCore extends BaseCore implements IAppInsightsCore {
70
93
  constructor();
71
94
  initialize(config: IConfiguration, extensions: IPlugin[], logger?: IDiagnosticLogger, notificationManager?: INotificationManager): void;
72
95
  track(telemetryItem: ITelemetryItem): void;
73
- /**
74
- * Adds a notification listener. The SDK calls methods on the listener when an appropriate notification is raised.
75
- * The added plugins must raise notifications. If the plugins do not implement the notifications, then no methods will be
76
- * called.
77
- * @param {INotificationListener} listener - An INotificationListener object.
78
- */
79
- addNotificationListener(listener: INotificationListener): void;
80
- /**
81
- * Removes all instances of the listener.
82
- * @param {INotificationListener} listener - INotificationListener to remove.
83
- */
84
- removeNotificationListener(listener: INotificationListener): void;
85
- /**
86
- * Periodically check logger.queue for
87
- */
88
- pollInternalLogs(eventName?: string): number;
89
- /**
90
- * Periodically check logger.queue for
91
- */
92
- stopPollingInternalLogs(): void;
93
96
  }
94
97
 
95
98
  export declare function areCookiesSupported(logger?: IDiagnosticLogger): any;
@@ -102,7 +105,7 @@ export declare function areCookiesSupported(logger?: IDiagnosticLogger): any;
102
105
  * @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
103
106
  * @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.
104
107
  */
105
- export declare function arrForEach<T>(arr: T[], callbackfn: (value: T, index?: number, array?: T[]) => void | number, thisArg?: any): void;
108
+ export declare function arrForEach<T = any>(arr: T[], callbackfn: (value: T, index?: number, array?: T[]) => undefined | void | number, thisArg?: any): void;
106
109
 
107
110
  /**
108
111
  * Returns the index of the first occurrence of a value in an array. This helper exists to avoid adding a polyfil for older browsers
@@ -137,7 +140,7 @@ export declare function arrReduce<T, R>(arr: T[], callbackfn: (previousValue: T
137
140
  /**
138
141
  * Binds the specified function to an event, so that the function gets called whenever the event fires on the object
139
142
  * @param obj Object to add the event too.
140
- * @param eventNameWithoutOn String that specifies any of the standard DHTML Events without "on" prefix
143
+ * @param eventNameWithoutOn String that specifies any of the standard DHTML Events without "on" prefix and optional (dot "." prefixed) namespaces "click" "click.mynamespace".
141
144
  * @param handlerRef Pointer that specifies the function to call when event fires
142
145
  * @param useCapture [Optional] Defaults to false
143
146
  * @returns True if the function was bound successfully to the event, otherwise false
@@ -156,6 +159,18 @@ export declare class BaseCore implements IAppInsightsCore {
156
159
  track(telemetryItem: ITelemetryItem): void;
157
160
  getProcessTelContext(): IProcessTelemetryContext;
158
161
  getNotifyMgr(): INotificationManager;
162
+ /**
163
+ * Adds a notification listener. The SDK calls methods on the listener when an appropriate notification is raised.
164
+ * The added plugins must raise notifications. If the plugins do not implement the notifications, then no methods will be
165
+ * called.
166
+ * @param {INotificationListener} listener - An INotificationListener object.
167
+ */
168
+ addNotificationListener(listener: INotificationListener): void;
169
+ /**
170
+ * Removes all instances of the listener.
171
+ * @param {INotificationListener} listener - INotificationListener to remove.
172
+ */
173
+ removeNotificationListener(listener: INotificationListener): void;
159
174
  /**
160
175
  * Get the current cookie manager for this instance
161
176
  */
@@ -168,7 +183,67 @@ export declare class BaseCore implements IAppInsightsCore {
168
183
  getPerfMgr(): IPerfManager;
169
184
  setPerfMgr(perfMgr: IPerfManager): void;
170
185
  eventCnt(): number;
186
+ /**
187
+ * Periodically check logger.queue for
188
+ */
189
+ pollInternalLogs(eventName?: string): number;
190
+ /**
191
+ * Periodically check logger.queue for
192
+ */
193
+ stopPollingInternalLogs(): void;
194
+ /**
195
+ * Add a telemetry processor to decorate or drop telemetry events.
196
+ * @param telemetryInitializer - The Telemetry Initializer function
197
+ * @returns - A ITelemetryInitializerHandler to enable the initializer to be removed
198
+ */
199
+ addTelemetryInitializer(telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler | void;
200
+ /**
201
+ * Unload and Tear down the SDK and any initialized plugins, after calling this the SDK will be considered
202
+ * to be un-initialized and non-operational, re-initializing the SDK should only be attempted if the previous
203
+ * unload call return `true` stating that all plugins reported that they also unloaded, the recommended
204
+ * approach is to create a new instance and initialize that instance.
205
+ * This is due to possible unexpected side effects caused by plugins not supporting unload / teardown, unable
206
+ * to successfully remove any global references or they may just be completing the unload process asynchronously.
207
+ * @param isAsync - Can the unload be performed asynchronously (default)
208
+ * @param unloadComplete - An optional callback that will be called once the unload has completed
209
+ * @param cbTimeout - An optional timeout to wait for any flush operations to complete before proceeding with the unload. Defaults to 5 seconds.
210
+ */
211
+ unload(isAsync?: boolean, unloadComplete?: (unloadState: ITelemetryUnloadState) => void, cbTimeout?: number): void;
212
+ getPlugin<T extends IPlugin = IPlugin>(pluginIdentifier: string): ILoadedPlugin<T>;
213
+ /**
214
+ * Add a new plugin to the installation
215
+ * @param plugin - The new plugin to add
216
+ * @param replaceExisting - should any existing plugin be replaced, default is false
217
+ * @param doAsync - Should the add be performed asynchronously
218
+ * @param addCb - [Optional] callback to call after the plugin has been added
219
+ */
220
+ addPlugin<T extends IPlugin = ITelemetryPlugin>(plugin: T, replaceExisting?: boolean, doAsync?: boolean, addCb?: (added?: boolean) => void): void;
221
+ /**
222
+ * Returns the unique event namespace that should be used
223
+ */
224
+ evtNamespace(): string;
225
+ /**
226
+ * Add an unload handler that will be called when the SDK is being unloaded
227
+ * @param handler - the handler
228
+ */
229
+ addUnloadCb(handler: UnloadHandler): void;
230
+ /**
231
+ * Flush and send any batched / cached data immediately
232
+ * @param async - send data asynchronously when true (defaults to true)
233
+ * @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.
234
+ * If the caller doesn't return true the caller should assume that it may never be called.
235
+ * @param sendReason - specify the reason that you are calling "flush" defaults to ManualFlush (1) if not specified
236
+ * @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
237
+ */
238
+ flush(isAsync?: boolean, callBack?: (flushComplete?: boolean) => void, sendReason?: SendRequestReason): void;
171
239
  protected releaseQueue(): void;
240
+ /**
241
+ * Hook for Core extensions to allow them to update their own configuration before updating all of the plugins.
242
+ * @param updateCtx - The plugin update context
243
+ * @param updateState - The Update State
244
+ * @returns boolean - True means the extension class will call updateState otherwise the Core will
245
+ */
246
+ protected _updateHook?(updateCtx: IProcessTelemetryUpdateContext, updateState: ITelemetryUpdateState): void | boolean;
172
247
  }
173
248
 
174
249
  /**
@@ -177,6 +252,13 @@ export declare class BaseCore implements IAppInsightsCore {
177
252
  * implementation so that new default implementations can be added without breaking all plugins.
178
253
  */
179
254
  export declare abstract class BaseTelemetryPlugin implements ITelemetryPlugin {
255
+ identifier: string;
256
+ version?: string;
257
+ /**
258
+ * Holds the core instance that was used during initialization
259
+ */
260
+ core: IAppInsightsCore;
261
+ priority: number;
180
262
  /**
181
263
  * Call back for telemetry processing before it it is sent
182
264
  * @param env - This is the current event being reported
@@ -198,13 +280,6 @@ export declare abstract class BaseTelemetryPlugin implements ITelemetryPlugin {
198
280
  * Returns whether the plugin has been initialized
199
281
  */
200
282
  isInitialized: () => boolean;
201
- identifier: string;
202
- version?: string;
203
- /**
204
- * Holds the core instance that was used during initialization
205
- */
206
- core: IAppInsightsCore;
207
- priority: number;
208
283
  /**
209
284
  * Helper to return the current IProcessTelemetryContext, if the passed argument exists this just
210
285
  * returns that value (helps with minification for callers), otherwise it will return the configured
@@ -217,12 +292,51 @@ export declare abstract class BaseTelemetryPlugin implements ITelemetryPlugin {
217
292
  */
218
293
  protected setInitialized: (isInitialized: boolean) => void;
219
294
  /**
220
- * Internal helper to initialize the instance
295
+ * Teardown / Unload hook to allow implementations to perform some additional unload operations before the BaseTelemetryPlugin
296
+ * finishes it's removal.
297
+ * @param unloadCtx - This is the context that should be used during unloading.
298
+ * @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.
299
+ * @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.
300
+ * @returns boolean - true if the plugin has or will call asyncCallback, this allows the plugin to perform any asynchronous operations.
221
301
  */
222
- private _baseTelInit;
302
+ protected _doTeardown?: (unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState, asyncCallback?: () => void) => void | boolean;
303
+ /**
304
+ * Extension hook to allow implementations to perform some additional update operations before the BaseTelemetryPlugin finishes it's removal
305
+ * @param updateCtx - This is the context that should be used during updating.
306
+ * @param updateState - The details / state of the update process, it holds details like the current and previous configuration.
307
+ * @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.
308
+ * @returns boolean - true if the plugin has or will call asyncCallback, this allows the plugin to perform any asynchronous operations.
309
+ */
310
+ protected _doUpdate?: (updateCtx?: IProcessTelemetryUpdateContext, updateState?: ITelemetryUpdateState, asyncCallback?: () => void) => void | boolean;
223
311
  constructor();
224
312
  initialize(config: IConfiguration, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?: ITelemetryPluginChain): void;
313
+ /**
314
+ * Tear down the plugin and remove any hooked value, the plugin should be removed so that it is no longer initialized and
315
+ * therefore could be re-initialized after being torn down. The plugin should ensure that once this has been called any further
316
+ * processTelemetry calls are ignored and it just calls the processNext() with the provided context.
317
+ * @param unloadCtx - This is the context that should be used during unloading.
318
+ * @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.
319
+ * @returns boolean - true if the plugin has or will call processNext(), this for backward compatibility as previously teardown was synchronous and returned nothing.
320
+ */
321
+ teardown(unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState): void | boolean;
225
322
  abstract processTelemetry(env: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
323
+ /**
324
+ * The the plugin should re-evaluate configuration and update any cached configuration settings.
325
+ * @param updateCtx - This is the context that should be used during updating.
326
+ * @param updateState - The details / state of the update process, it holds details like the current and previous configuration.
327
+ * @returns boolean - true if the plugin has or will call updateCtx.processNext(), this allows the plugin to perform any asynchronous operations.
328
+ */
329
+ update(updateCtx: IProcessTelemetryUpdateContext, updateState: ITelemetryUpdateState): void | boolean;
330
+ /**
331
+ * Add an unload handler that will be called when the SDK is being unloaded
332
+ * @param handler - the handler
333
+ */
334
+ protected _addUnloadCb(handler: UnloadHandler): void;
335
+ /**
336
+ * Add this hook so that it is automatically removed during unloading
337
+ * @param hooks - The single hook or an array of IInstrumentHook objects
338
+ */
339
+ protected _addHook(hooks: IInstrumentHook | IInstrumentHook[]): void;
226
340
  }
227
341
 
228
342
  /**
@@ -248,6 +362,53 @@ export declare function createClassFromInterface<T>(defaults?: T): new () => T;
248
362
 
249
363
  export declare function createCookieMgr(rootConfig?: IConfiguration, logger?: IDiagnosticLogger): ICookieMgr;
250
364
 
365
+ /**
366
+ * Create a 2 index map that maps an enum's key as both the key and value, X["key"] => "key" and X[0] => "keyof 0".
367
+ * @param values - The values to populate on the new object
368
+ * @returns
369
+ */
370
+ export declare function createEnumMap<E, I = keyof E>(values: {
371
+ [key in keyof E]: E[keyof E];
372
+ }): EnumMap<E, I>;
373
+
374
+ /**
375
+ * Create an enum style object which has both the key => value and value => key mappings
376
+ * @param values - The values to populate on the new object
377
+ * @returns
378
+ */
379
+ export declare function createEnumStyle<E>(values: {
380
+ [key in keyof E]: E[keyof E];
381
+ }): EnumValue<E>;
382
+
383
+ /**
384
+ * Creates a new Telemetry Item context with the current config, core and plugin execution chain
385
+ * @param plugins - The plugin instances that will be executed
386
+ * @param config - The current config
387
+ * @param core - The current core instance
388
+ * @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
389
+ */
390
+ export declare function createProcessTelemetryContext(telemetryChain: ITelemetryPluginChain | null, config: IConfiguration, core: IAppInsightsCore, startAt?: IPlugin): IProcessTelemetryContext;
391
+
392
+ export declare function createUniqueNamespace(name: string, includeVersion?: boolean): string;
393
+
394
+ export declare function createUnloadHandlerContainer(): {
395
+ add: (handler: UnloadHandler) => void;
396
+ run: (unloadCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
397
+ };
398
+
399
+ /**
400
+ * Create a 2 index map that maps an enum's key and value to the defined map value, X["key"] => mapValue and X[0] => mapValue.
401
+ * Generic values
402
+ * - E = the const enum type (typeof eRequestHeaders);
403
+ * - V = Identifies the valid values for the keys, this should include both the enum numeric and string key of the type. The
404
+ * resulting "Value" of each entry identifies the valid values withing the assignments.
405
+ * @param values - The values to populate on the new object
406
+ * @returns
407
+ */
408
+ export declare function createValueMap<E, V = E>(values: {
409
+ [key in keyof E]: [eValue: E[keyof E], mapValue: V[keyof V]];
410
+ }): V;
411
+
251
412
  /**
252
413
  * Return the current time via the Date now() function (if available) and falls back to (new Date()).getTime() if now() is unavailable (IE8 or less)
253
414
  * https://caniuse.com/#search=Date.now
@@ -264,8 +425,11 @@ export declare function deleteCookie(logger: IDiagnosticLogger, name: string): b
264
425
  /**
265
426
  * Removes an event handler for the specified event
266
427
  * @param Object to remove the event from
267
- * @param eventNameWithoutOn {string} - The name of the event
268
- * @param handlerRef {any} - The callback function that needs to be executed for the given event
428
+ * @param eventNameWithoutOn {string} - The name of the event, with optional namespaces or just the namespaces,
429
+ * such as "click", "click.mynamespace" or ".mynamespace"
430
+ * @param handlerRef {any} - The callback function that needs to be removed from the given event, when using a
431
+ * namespace (with or without a qualifying event) this may be null to remove all previously attached event handlers
432
+ * otherwise this will only remove events with this specific handler.
269
433
  * @param useCapture [Optional] Defaults to false
270
434
  */
271
435
  export declare function detachEvent(obj: any, eventNameWithoutOn: string, handlerRef: any, useCapture?: boolean): void;
@@ -346,38 +510,176 @@ export declare function doPerf<T>(mgrSource: IPerfManagerProvider | IPerfManager
346
510
  */
347
511
  export declare function dumpObj(object: any): string;
348
512
 
349
- export declare const EventHelper: IEventHelper;
350
-
351
513
  /**
352
- * The EventsDiscardedReason enumeration contains a set of values that specify the reason for discarding an event.
514
+ * The eEventsDiscardedReason enumeration contains a set of values that specify the reason for discarding an event.
353
515
  */
354
- export declare const EventsDiscardedReason: {
516
+ export declare const enum eEventsDiscardedReason {
355
517
  /**
356
518
  * Unknown.
357
519
  */
358
- Unknown: number;
520
+ Unknown = 0,
359
521
  /**
360
522
  * Status set to non-retryable.
361
523
  */
362
- NonRetryableStatus: number;
524
+ NonRetryableStatus = 1,
363
525
  /**
364
526
  * The event is invalid.
365
527
  */
366
- InvalidEvent: number;
528
+ InvalidEvent = 2,
367
529
  /**
368
530
  * The size of the event is too large.
369
531
  */
370
- SizeLimitExceeded: number;
532
+ SizeLimitExceeded = 3,
371
533
  /**
372
534
  * The server is not accepting events from this instrumentation key.
373
535
  */
374
- KillSwitch: number;
536
+ KillSwitch = 4,
375
537
  /**
376
538
  * The event queue is full.
377
539
  */
378
- QueueFull: number;
540
+ QueueFull = 5
541
+ }
542
+
543
+ export declare const enum _eInternalMessageId {
544
+ BrowserDoesNotSupportLocalStorage = 0,
545
+ BrowserCannotReadLocalStorage = 1,
546
+ BrowserCannotReadSessionStorage = 2,
547
+ BrowserCannotWriteLocalStorage = 3,
548
+ BrowserCannotWriteSessionStorage = 4,
549
+ BrowserFailedRemovalFromLocalStorage = 5,
550
+ BrowserFailedRemovalFromSessionStorage = 6,
551
+ CannotSendEmptyTelemetry = 7,
552
+ ClientPerformanceMathError = 8,
553
+ ErrorParsingAISessionCookie = 9,
554
+ ErrorPVCalc = 10,
555
+ ExceptionWhileLoggingError = 11,
556
+ FailedAddingTelemetryToBuffer = 12,
557
+ FailedMonitorAjaxAbort = 13,
558
+ FailedMonitorAjaxDur = 14,
559
+ FailedMonitorAjaxOpen = 15,
560
+ FailedMonitorAjaxRSC = 16,
561
+ FailedMonitorAjaxSend = 17,
562
+ FailedMonitorAjaxGetCorrelationHeader = 18,
563
+ FailedToAddHandlerForOnBeforeUnload = 19,
564
+ FailedToSendQueuedTelemetry = 20,
565
+ FailedToReportDataLoss = 21,
566
+ FlushFailed = 22,
567
+ MessageLimitPerPVExceeded = 23,
568
+ MissingRequiredFieldSpecification = 24,
569
+ NavigationTimingNotSupported = 25,
570
+ OnError = 26,
571
+ SessionRenewalDateIsZero = 27,
572
+ SenderNotInitialized = 28,
573
+ StartTrackEventFailed = 29,
574
+ StopTrackEventFailed = 30,
575
+ StartTrackFailed = 31,
576
+ StopTrackFailed = 32,
577
+ TelemetrySampledAndNotSent = 33,
578
+ TrackEventFailed = 34,
579
+ TrackExceptionFailed = 35,
580
+ TrackMetricFailed = 36,
581
+ TrackPVFailed = 37,
582
+ TrackPVFailedCalc = 38,
583
+ TrackTraceFailed = 39,
584
+ TransmissionFailed = 40,
585
+ FailedToSetStorageBuffer = 41,
586
+ FailedToRestoreStorageBuffer = 42,
587
+ InvalidBackendResponse = 43,
588
+ FailedToFixDepricatedValues = 44,
589
+ InvalidDurationValue = 45,
590
+ TelemetryEnvelopeInvalid = 46,
591
+ CreateEnvelopeError = 47,
592
+ CannotSerializeObject = 48,
593
+ CannotSerializeObjectNonSerializable = 49,
594
+ CircularReferenceDetected = 50,
595
+ ClearAuthContextFailed = 51,
596
+ ExceptionTruncated = 52,
597
+ IllegalCharsInName = 53,
598
+ ItemNotInArray = 54,
599
+ MaxAjaxPerPVExceeded = 55,
600
+ MessageTruncated = 56,
601
+ NameTooLong = 57,
602
+ SampleRateOutOfRange = 58,
603
+ SetAuthContextFailed = 59,
604
+ SetAuthContextFailedAccountName = 60,
605
+ StringValueTooLong = 61,
606
+ StartCalledMoreThanOnce = 62,
607
+ StopCalledWithoutStart = 63,
608
+ TelemetryInitializerFailed = 64,
609
+ TrackArgumentsNotSpecified = 65,
610
+ UrlTooLong = 66,
611
+ SessionStorageBufferFull = 67,
612
+ CannotAccessCookie = 68,
613
+ IdTooLong = 69,
614
+ InvalidEvent = 70,
615
+ FailedMonitorAjaxSetRequestHeader = 71,
616
+ SendBrowserInfoOnUserInit = 72,
617
+ PluginException = 73,
618
+ NotificationException = 74,
619
+ SnippetScriptLoadFailure = 99,
620
+ InvalidInstrumentationKey = 100,
621
+ CannotParseAiBlobValue = 101,
622
+ InvalidContentBlob = 102,
623
+ TrackPageActionEventFailed = 103,
624
+ FailedAddingCustomDefinedRequestContext = 104,
625
+ InMemoryStorageBufferFull = 105
626
+ }
627
+
628
+ export declare const enum eLoggingSeverity {
629
+ /**
630
+ * Error will be sent as internal telemetry
631
+ */
632
+ CRITICAL = 1,
633
+ /**
634
+ * Error will NOT be sent as internal telemetry, and will only be shown in browser console
635
+ */
636
+ WARNING = 2
637
+ }
638
+
639
+ export declare type EnumMap<E = any, I = E> = {
640
+ readonly [key in keyof E extends string ? keyof E : never]: key extends string ? key : keyof E;
641
+ } & I;
642
+
643
+ export declare type EnumValue<E = any> = {
644
+ readonly [key in keyof E]: E[key];
379
645
  };
380
646
 
647
+ export declare const EventHelper: IEventHelper;
648
+
649
+ /**
650
+ * Removes an event handler for the specified event
651
+ * @param Object to remove the event from
652
+ * @param eventName {string} - The name of the event, with optional namespaces or just the namespaces,
653
+ * such as "click", "click.mynamespace" or ".mynamespace"
654
+ * @param handlerRef {any} - The callback function that needs to be removed from the given event, when using a
655
+ * namespace (with or without a qualifying event) this may be null to remove all previously attached event handlers
656
+ * otherwise this will only remove events with this specific handler.
657
+ * @param evtNamespace - [Optional] Additional namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace,
658
+ * if the eventName also includes a namespace the namespace(s) are merged into a single namespace
659
+ * @param useCapture [Optional] Defaults to false
660
+ */
661
+ export declare function eventOff<T>(target: T, eventName: string, handlerRef: any, evtNamespace?: string | string[] | null, useCapture?: boolean): void;
662
+
663
+ /**
664
+ * Binds the specified function to an event, so that the function gets called whenever the event fires on the object
665
+ * @param obj Object to add the event too.
666
+ * @param eventName String that specifies any of the standard DHTML Events without "on" prefix, if may also include an optional (dot "." prefixed)
667
+ * namespaces "click" "click.mynamespace" in addition to specific namespaces.
668
+ * @param handlerRef Pointer that specifies the function to call when event fires
669
+ * @param evtNamespace - [Optional] Additional namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace,
670
+ * if the eventName also includes a namespace the namespace(s) are merged into a single namespace
671
+ * @param useCapture [Optional] Defaults to false
672
+ * @returns True if the function was bound successfully to the event, otherwise false
673
+ */
674
+ export declare function eventOn<T>(target: T, eventName: string, handlerRef: any, evtNamespace?: string | string[] | null, useCapture?: boolean): boolean;
675
+
676
+ /**
677
+ * The EventsDiscardedReason enumeration contains a set of values that specify the reason for discarding an event.
678
+ */
679
+ export declare const EventsDiscardedReason: EnumValue<typeof eEventsDiscardedReason>;
680
+
681
+ export declare type EventsDiscardedReason = number | eEventsDiscardedReason;
682
+
381
683
  /**
382
684
  * generate W3C trace id
383
685
  */
@@ -417,6 +719,12 @@ export declare function getDocument(): Document | null;
417
719
  */
418
720
  export declare function getExceptionName(object: any): string;
419
721
 
722
+ export declare const enum GetExtCfgMergeType {
723
+ None = 0,
724
+ MergeDefaultOnly = 1,
725
+ MergeDefaultFromRootOrDefault = 2
726
+ }
727
+
420
728
  /**
421
729
  * Get the current global performance manager that will be used with no performance manager is supplied.
422
730
  * @returns - The current default manager
@@ -575,12 +883,123 @@ export declare interface IAppInsightsCore extends IPerfManagerProvider {
575
883
  * @param {INotificationListener} listener - INotificationListener to remove.
576
884
  */
577
885
  removeNotificationListener?(listener: INotificationListener): void;
886
+ /**
887
+ * Add a telemetry processor to decorate or drop telemetry events.
888
+ * @param telemetryInitializer - The Telemetry Initializer function
889
+ * @returns - A ITelemetryInitializerHandler to enable the initializer to be removed
890
+ */
891
+ addTelemetryInitializer(telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler | void;
578
892
  pollInternalLogs?(eventName?: string): number;
579
893
  stopPollingInternalLogs?(): void;
580
894
  /**
581
895
  * Return a new instance of the IProcessTelemetryContext for processing events
582
896
  */
583
897
  getProcessTelContext(): IProcessTelemetryContext;
898
+ /**
899
+ * Unload and Tear down the SDK and any initialized plugins, after calling this the SDK will be considered
900
+ * to be un-initialized and non-operational, re-initializing the SDK should only be attempted if the previous
901
+ * unload call return `true` stating that all plugins reported that they also unloaded, the recommended
902
+ * approach is to create a new instance and initialize that instance.
903
+ * This is due to possible unexpected side effects caused by plugins not supporting unload / teardown, unable
904
+ * to successfully remove any global references or they may just be completing the unload process asynchronously.
905
+ * @param isAsync - Can the unload be performed asynchronously (default)
906
+ * @param unloadComplete - An optional callback that will be called once the unload has completed
907
+ * @param cbTimeout - An optional timeout to wait for any flush operations to complete before proceeding with the unload. Defaults to 5 seconds.
908
+ */
909
+ unload(isAsync?: boolean, unloadComplete?: (unloadState: ITelemetryUnloadState) => void, cbTimeout?: number): void;
910
+ /**
911
+ * Find and return the (first) plugin with the specified identifier if present
912
+ * @param pluginIdentifier
913
+ */
914
+ getPlugin<T extends IPlugin = IPlugin>(pluginIdentifier: string): ILoadedPlugin<T>;
915
+ /**
916
+ * Add a new plugin to the installation
917
+ * @param plugin - The new plugin to add
918
+ * @param replaceExisting - should any existing plugin be replaced, default is false
919
+ * @param doAsync - Should the add be performed asynchronously
920
+ * @param addCb - [Optional] callback to call after the plugin has been added
921
+ */
922
+ addPlugin<T extends IPlugin = ITelemetryPlugin>(plugin: T, replaceExisting?: boolean, doAsync?: boolean, addCb?: (added?: boolean) => void): void;
923
+ /**
924
+ * Returns the unique event namespace that should be used when registering events
925
+ */
926
+ evtNamespace(): string;
927
+ /**
928
+ * Add a handler that will be called when the SDK is being unloaded
929
+ * @param handler - the handler
930
+ */
931
+ addUnloadCb(handler: UnloadHandler): void;
932
+ /**
933
+ * Flush and send any batched / cached data immediately
934
+ * @param async - send data asynchronously when true (defaults to true)
935
+ * @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.
936
+ * If the caller doesn't return true the caller should assume that it may never be called.
937
+ * @param sendReason - specify the reason that you are calling "flush" defaults to ManualFlush (1) if not specified
938
+ * @param cbTimeout - An optional timeout to wait for any flush operations to complete before proceeding with the unload. Defaults to 5 seconds.
939
+ * @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
940
+ */
941
+ flush(isAsync?: boolean, callBack?: (flushComplete?: boolean) => void, sendReason?: SendRequestReason, cbTimeout?: number): boolean | void;
942
+ }
943
+
944
+ export declare interface IBaseProcessingContext {
945
+ /**
946
+ * The current core instance for the request
947
+ */
948
+ core: () => IAppInsightsCore;
949
+ /**
950
+ * THe current diagnostic logger for the request
951
+ */
952
+ diagLog: () => IDiagnosticLogger;
953
+ /**
954
+ * Gets the current core config instance
955
+ */
956
+ getCfg: () => IConfiguration;
957
+ /**
958
+ * Gets the named extension config
959
+ */
960
+ getExtCfg: <T>(identifier: string, defaultValue?: T | any, mergeDefault?: GetExtCfgMergeType) => T;
961
+ /**
962
+ * Gets the named config from either the named identifier extension or core config if neither exist then the
963
+ * default value is returned
964
+ * @param identifier The named extension identifier
965
+ * @param field The config field name
966
+ * @param defaultValue The default value to return if no defined config exists
967
+ */
968
+ getConfig: (identifier: string, field: string, defaultValue?: number | string | boolean | string[] | RegExp[] | Function) => number | string | boolean | string[] | RegExp[] | Function;
969
+ /**
970
+ * Helper to allow plugins to check and possibly shortcut executing code only
971
+ * required if there is a nextPlugin
972
+ */
973
+ hasNext: () => boolean;
974
+ /**
975
+ * Returns the next configured plugin proxy
976
+ */
977
+ getNext: () => ITelemetryPluginChain;
978
+ /**
979
+ * Helper to set the next plugin proxy
980
+ */
981
+ setNext: (nextCtx: ITelemetryPluginChain) => void;
982
+ /**
983
+ * Synchronously iterate over the context chain running the callback for each plugin, once
984
+ * every plugin has been executed via the callback, any associated onComplete will be called.
985
+ * @param callback - The function call for each plugin in the context chain
986
+ */
987
+ iterate: <T extends ITelemetryPlugin = ITelemetryPlugin>(callback: (plugin: T) => void) => void;
988
+ /**
989
+ * Set the function to call when the current chain has executed all processNext or unloadNext items.
990
+ * @param onComplete - The onComplete to call
991
+ * @param that - The "this" value to use for the onComplete call, if not provided or undefined defaults to the current context
992
+ * @param args - Any additional arguments to pass to the onComplete function
993
+ */
994
+ onComplete: (onComplete: () => void, that?: any, ...args: any[]) => void;
995
+ /**
996
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
997
+ * @param plugins - The execution order to process the plugins, if null or not supplied
998
+ * then the current execution order will be copied.
999
+ * @param startAt - The plugin to start processing from, if missing from the execution
1000
+ * order then the next plugin will be NOT set.
1001
+ */
1002
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IBaseProcessingContext;
584
1003
  }
585
1004
 
586
1005
  /**
@@ -596,15 +1015,23 @@ export declare interface IChannelControls extends ITelemetryPlugin {
596
1015
  */
597
1016
  resume(): void;
598
1017
  /**
599
- * Tear down transmission pipeline
1018
+ * Tear down the plugin and remove any hooked value, the plugin should be removed so that it is no longer initialized and
1019
+ * therefore could be re-initialized after being torn down. The plugin should ensure that once this has been called any further
1020
+ * processTelemetry calls are ignored and it just calls the processNext() with the provided context.
1021
+ * @param unloadCtx - This is the context that should be used during unloading.
1022
+ * @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.
1023
+ * @returns boolean - true if the plugin has or will call processNext(), this for backward compatibility as previously teardown was synchronous and returned nothing.
600
1024
  */
601
- teardown(): void;
1025
+ teardown: (unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState) => void | boolean;
602
1026
  /**
603
1027
  * Flush to send data immediately; channel should default to sending data asynchronously
604
- * @param async: send data asynchronously when true
605
- * @param callBack: if specified, notify caller when send is complete
1028
+ * @param async - send data asynchronously when true
1029
+ * @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.
1030
+ * If the caller doesn't return true the caller should assume that it may never be called.
1031
+ * @param sendReason - specify the reason that you are calling "flush" defaults to ManualFlush (1) if not specified
1032
+ * @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
606
1033
  */
607
- flush(async: boolean, callBack?: () => void): void;
1034
+ flush(async: boolean, callBack?: (flushComplete?: boolean) => void, sendReason?: SendRequestReason): boolean | void;
608
1035
  }
609
1036
 
610
1037
  /**
@@ -964,7 +1391,7 @@ export declare interface ICoreUtils {
964
1391
  * @param callback {any} - The callback function that needs to be executed for the given event
965
1392
  * @return {boolean} - true if the handler was successfully added
966
1393
  */
967
- addEventHandler: (eventName: string, callback: any) => boolean;
1394
+ addEventHandler: (eventName: string, callback: any, evtNamespace?: string | string[]) => boolean;
968
1395
  /**
969
1396
  * Return the current time via the Date now() function (if available) and falls back to (new Date()).getTime() if now() is unavailable (IE8 or less)
970
1397
  * https://caniuse.com/#search=Date.now
@@ -1149,6 +1576,10 @@ export declare interface IInstrumentCallDetails {
1149
1576
  * The error (exception) which occurred while executing the original method
1150
1577
  */
1151
1578
  err?: Error;
1579
+ /**
1580
+ * The Event object from (window.event) at the start of the original call
1581
+ */
1582
+ evt?: Event;
1152
1583
  }
1153
1584
 
1154
1585
  /**
@@ -1175,6 +1606,11 @@ export declare interface IInstrumentHooks {
1175
1606
  * You must always supply the error callback
1176
1607
  */
1177
1608
  export declare interface IInstrumentHooksCallbacks {
1609
+ /**
1610
+ * [Optional] Namespace details (same as the namespace used for events), useful for debugging and testing to
1611
+ * identify the source of the instrumented hooks
1612
+ */
1613
+ ns?: string | string[];
1178
1614
  /**
1179
1615
  * The hook callback to call before the original function is called
1180
1616
  */
@@ -1194,6 +1630,24 @@ export declare interface IInstrumentHooksCallbacks {
1194
1630
  fnErr?: InstrumentorHooksCallback;
1195
1631
  }
1196
1632
 
1633
+ export declare interface ILoadedPlugin<T extends IPlugin> {
1634
+ plugin: T;
1635
+ /**
1636
+ * Identifies whether the plugin is enabled and can process events. This is slightly different from isInitialized as the plugin may be initialized but disabled
1637
+ * via the setEnabled() or it may be a shared plugin which has had it's teardown function called from another instance..
1638
+ * @returns boolean = true if the plugin is in a state where it is operational.
1639
+ */
1640
+ isEnabled: () => boolean;
1641
+ /**
1642
+ * You can optionally enable / disable a plugin from processing events.
1643
+ * Setting enabled to true will not necessarily cause the `isEnabled()` to also return true
1644
+ * as the plugin must also have been successfully initialized and not had it's `teardown` method called
1645
+ * (unless it's also been re-initialized)
1646
+ */
1647
+ setEnabled: (isEnabled: boolean) => void;
1648
+ remove: (isAsync?: boolean, removeCb?: (removed?: boolean) => void) => void;
1649
+ }
1650
+
1197
1651
  /**
1198
1652
  * Initialize the queue of plugins
1199
1653
  * @param plugins - The array of plugins to initialize and setting of the next plugin
@@ -1201,7 +1655,7 @@ export declare interface IInstrumentHooksCallbacks {
1201
1655
  * @param core THe current core instance
1202
1656
  * @param extensions The extensions
1203
1657
  */
1204
- export declare function initializePlugins(processContext: ProcessTelemetryContext, extensions: IPlugin[]): void;
1658
+ export declare function initializePlugins(processContext: IProcessTelemetryContext, extensions: IPlugin[]): void;
1205
1659
 
1206
1660
  /**
1207
1661
  * An interface used for the notification listener.
@@ -1325,92 +1779,9 @@ export declare class _InternalLogMessage {
1325
1779
  /**
1326
1780
  * Internal message ID. Please create a new one for every conceptually different message. Please keep alphabetically ordered
1327
1781
  */
1328
- export declare const _InternalMessageId: {
1329
- BrowserDoesNotSupportLocalStorage: number;
1330
- BrowserCannotReadLocalStorage: number;
1331
- BrowserCannotReadSessionStorage: number;
1332
- BrowserCannotWriteLocalStorage: number;
1333
- BrowserCannotWriteSessionStorage: number;
1334
- BrowserFailedRemovalFromLocalStorage: number;
1335
- BrowserFailedRemovalFromSessionStorage: number;
1336
- CannotSendEmptyTelemetry: number;
1337
- ClientPerformanceMathError: number;
1338
- ErrorParsingAISessionCookie: number;
1339
- ErrorPVCalc: number;
1340
- ExceptionWhileLoggingError: number;
1341
- FailedAddingTelemetryToBuffer: number;
1342
- FailedMonitorAjaxAbort: number;
1343
- FailedMonitorAjaxDur: number;
1344
- FailedMonitorAjaxOpen: number;
1345
- FailedMonitorAjaxRSC: number;
1346
- FailedMonitorAjaxSend: number;
1347
- FailedMonitorAjaxGetCorrelationHeader: number;
1348
- FailedToAddHandlerForOnBeforeUnload: number;
1349
- FailedToSendQueuedTelemetry: number;
1350
- FailedToReportDataLoss: number;
1351
- FlushFailed: number;
1352
- MessageLimitPerPVExceeded: number;
1353
- MissingRequiredFieldSpecification: number;
1354
- NavigationTimingNotSupported: number;
1355
- OnError: number;
1356
- SessionRenewalDateIsZero: number;
1357
- SenderNotInitialized: number;
1358
- StartTrackEventFailed: number;
1359
- StopTrackEventFailed: number;
1360
- StartTrackFailed: number;
1361
- StopTrackFailed: number;
1362
- TelemetrySampledAndNotSent: number;
1363
- TrackEventFailed: number;
1364
- TrackExceptionFailed: number;
1365
- TrackMetricFailed: number;
1366
- TrackPVFailed: number;
1367
- TrackPVFailedCalc: number;
1368
- TrackTraceFailed: number;
1369
- TransmissionFailed: number;
1370
- FailedToSetStorageBuffer: number;
1371
- FailedToRestoreStorageBuffer: number;
1372
- InvalidBackendResponse: number;
1373
- FailedToFixDepricatedValues: number;
1374
- InvalidDurationValue: number;
1375
- TelemetryEnvelopeInvalid: number;
1376
- CreateEnvelopeError: number;
1377
- CannotSerializeObject: number;
1378
- CannotSerializeObjectNonSerializable: number;
1379
- CircularReferenceDetected: number;
1380
- ClearAuthContextFailed: number;
1381
- ExceptionTruncated: number;
1382
- IllegalCharsInName: number;
1383
- ItemNotInArray: number;
1384
- MaxAjaxPerPVExceeded: number;
1385
- MessageTruncated: number;
1386
- NameTooLong: number;
1387
- SampleRateOutOfRange: number;
1388
- SetAuthContextFailed: number;
1389
- SetAuthContextFailedAccountName: number;
1390
- StringValueTooLong: number;
1391
- StartCalledMoreThanOnce: number;
1392
- StopCalledWithoutStart: number;
1393
- TelemetryInitializerFailed: number;
1394
- TrackArgumentsNotSpecified: number;
1395
- UrlTooLong: number;
1396
- SessionStorageBufferFull: number;
1397
- CannotAccessCookie: number;
1398
- IdTooLong: number;
1399
- InvalidEvent: number;
1400
- FailedMonitorAjaxSetRequestHeader: number;
1401
- SendBrowserInfoOnUserInit: number;
1402
- PluginException: number;
1403
- NotificationException: number;
1404
- SnippetScriptLoadFailure: number;
1405
- InvalidInstrumentationKey: number;
1406
- CannotParseAiBlobValue: number;
1407
- InvalidContentBlob: number;
1408
- TrackPageActionEventFailed: number;
1409
- FailedAddingCustomDefinedRequestContext: number;
1410
- InMemoryStorageBufferFull: number;
1411
- };
1782
+ export declare const _InternalMessageId: EnumValue<typeof _eInternalMessageId>;
1412
1783
 
1413
- export declare type _InternalMessageId = number | typeof _InternalMessageId;
1784
+ export declare type _InternalMessageId = number | _eInternalMessageId;
1414
1785
 
1415
1786
  /**
1416
1787
  * This interface identifies the details of an internal performance event - it does not represent an outgoing reported event
@@ -1531,10 +1902,14 @@ export declare interface IPlugin {
1531
1902
  */
1532
1903
  isInitialized?: () => boolean;
1533
1904
  /**
1534
- * Tear down the plugin and remove any hooked value, the plugin should remove that it is no longer initialized and
1535
- * therefore can be re-initialized after being torn down.
1905
+ * Tear down the plugin and remove any hooked value, the plugin should be removed so that it is no longer initialized and
1906
+ * therefore could be re-initialized after being torn down. The plugin should ensure that once this has been called any further
1907
+ * processTelemetry calls are ignored and it just calls the processNext() with the provided context.
1908
+ * @param unloadCtx - This is the context that should be used during unloading.
1909
+ * @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.
1910
+ * @returns boolean - true if the plugin has or will call processNext(), this for backward compatibility as previously teardown was synchronous and returned nothing.
1536
1911
  */
1537
- teardown?: () => void;
1912
+ teardown?: (unloadCtx: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState) => void | boolean;
1538
1913
  /**
1539
1914
  * Extension name
1540
1915
  */
@@ -1549,61 +1924,73 @@ export declare interface IPlugin {
1549
1924
  * The current context for the current call to processTelemetry(), used to support sharing the same plugin instance
1550
1925
  * between multiple AppInsights instances
1551
1926
  */
1552
- export declare interface IProcessTelemetryContext {
1553
- /**
1554
- * The current core instance for the request
1555
- */
1556
- core: () => IAppInsightsCore;
1557
- /**
1558
- * THe current diagnostic logger for the request
1559
- */
1560
- diagLog: () => IDiagnosticLogger;
1561
- /**
1562
- * Gets the current core config instance
1563
- */
1564
- getCfg: () => IConfiguration;
1565
- /**
1566
- * Gets the named extension config
1567
- */
1568
- getExtCfg: <T>(identifier: string, defaultValue?: T | any) => T;
1927
+ export declare interface IProcessTelemetryContext extends IBaseProcessingContext {
1569
1928
  /**
1570
- * Gets the named config from either the named identifier extension or core config if neither exist then the
1571
- * default value is returned
1572
- * @param identifier The named extension identifier
1573
- * @param field The config field name
1574
- * @param defaultValue The default value to return if no defined config exists
1929
+ * Call back for telemetry processing before it it is sent
1930
+ * @param env - This is the current event being reported
1931
+ * @returns boolean (true) if there is no more plugins to process otherwise false or undefined (void)
1575
1932
  */
1576
- getConfig: (identifier: string, field: string, defaultValue?: number | string | boolean) => number | string | boolean;
1933
+ processNext: (env: ITelemetryItem) => boolean | void;
1577
1934
  /**
1578
- * Helper to allow plugins to check and possibly shortcut executing code only
1579
- * required if there is a nextPlugin
1935
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
1936
+ * @param plugins - The execution order to process the plugins, if null or not supplied
1937
+ * then the current execution order will be copied.
1938
+ * @param startAt - The plugin to start processing from, if missing from the execution
1939
+ * order then the next plugin will be NOT set.
1580
1940
  */
1581
- hasNext: () => boolean;
1941
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryContext;
1942
+ }
1943
+
1944
+ /**
1945
+ * The current context for the current call to teardown() implementations, used to support when plugins are being removed
1946
+ * or the SDK is being unloaded.
1947
+ */
1948
+ export declare interface IProcessTelemetryUnloadContext extends IBaseProcessingContext {
1582
1949
  /**
1583
- * Returns the next configured plugin proxy
1950
+ * This Plugin has finished unloading, so unload the next one
1951
+ * @param uploadState - The state of the unload process
1952
+ * @returns boolean (true) if there is no more plugins to process otherwise false or undefined (void)
1584
1953
  */
1585
- getNext: () => ITelemetryPluginChain;
1954
+ processNext: (unloadState: ITelemetryUnloadState) => boolean | void;
1586
1955
  /**
1587
- * Helper to set the next plugin proxy
1956
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
1957
+ * @param plugins - The execution order to process the plugins, if null or not supplied
1958
+ * then the current execution order will be copied.
1959
+ * @param startAt - The plugin to start processing from, if missing from the execution
1960
+ * order then the next plugin will be NOT set.
1588
1961
  */
1589
- setNext: (nextCtx: ITelemetryPluginChain) => void;
1962
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryUnloadContext;
1963
+ }
1964
+
1965
+ /**
1966
+ * The current context for the current call to the plugin update() implementations, used to support the notifications
1967
+ * for when plugins are added, removed or the configuration was changed.
1968
+ */
1969
+ export declare interface IProcessTelemetryUpdateContext extends IBaseProcessingContext {
1590
1970
  /**
1591
- * Call back for telemetry processing before it it is sent
1592
- * @param env - This is the current event being reported
1971
+ * This Plugin has finished unloading, so unload the next one
1972
+ * @param updateState - The update State
1973
+ * @returns boolean (true) if there is no more plugins to process otherwise false or undefined (void)
1593
1974
  */
1594
- processNext: (env: ITelemetryItem) => void;
1975
+ processNext: (updateState: ITelemetryUpdateState) => boolean | void;
1595
1976
  /**
1596
- * Create a new context using the core and config from the current instance
1977
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
1597
1978
  * @param plugins - The execution order to process the plugins, if null or not supplied
1598
1979
  * then the current execution order will be copied.
1599
1980
  * @param startAt - The plugin to start processing from, if missing from the execution
1600
1981
  * order then the next plugin will be NOT set.
1601
1982
  */
1602
- createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryContext;
1983
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryUpdateContext;
1984
+ }
1985
+
1986
+ export declare interface _IRegisteredEvents {
1987
+ name: string;
1988
+ handler: any;
1603
1989
  }
1604
1990
 
1605
1991
  /**
1606
- * Check if an object is of type Array
1992
+ * Check if an object is of type Array with optional generic T, the generic type is not validated
1993
+ * and exists to help with TypeScript validation only.
1607
1994
  */
1608
1995
  export declare let isArray: <T = any>(obj: any) => obj is Array<T>;
1609
1996
 
@@ -1644,13 +2031,13 @@ export declare function isFunction(value: any): value is Function;
1644
2031
  */
1645
2032
  export declare function isIE(): boolean;
1646
2033
 
1647
- export declare function isNotNullOrUndefined(value: any): boolean;
2034
+ export declare function isNotNullOrUndefined<T>(value: T): value is T;
1648
2035
 
1649
2036
  export declare function isNotTruthy(value: any): boolean;
1650
2037
 
1651
- export declare function isNotUndefined(value: any): boolean;
2038
+ export declare function isNotUndefined<T>(value: T): value is T;
1652
2039
 
1653
- export declare function isNullOrUndefined(value: any): boolean;
2040
+ export declare function isNullOrUndefined(value: any): value is null | undefined;
1654
2041
 
1655
2042
  /**
1656
2043
  * Checks if the type of value is a number.
@@ -1659,7 +2046,7 @@ export declare function isNullOrUndefined(value: any): boolean;
1659
2046
  */
1660
2047
  export declare function isNumber(value: any): value is number;
1661
2048
 
1662
- export declare function isObject(value: any): boolean;
2049
+ export declare function isObject<T>(value: T): value is T;
1663
2050
 
1664
2051
  /**
1665
2052
  * Returns whether the environment is reporting that we are running in a React Native Environment
@@ -1687,7 +2074,7 @@ export declare function isTruthy(value: any): boolean;
1687
2074
 
1688
2075
  export declare function isTypeof(value: any, theType: string): boolean;
1689
2076
 
1690
- export declare function isUndefined(value: any): boolean;
2077
+ export declare function isUndefined(value: any): value is undefined;
1691
2078
 
1692
2079
  /**
1693
2080
  * Checks if XMLHttpRequest is supported
@@ -1695,6 +2082,19 @@ export declare function isUndefined(value: any): boolean;
1695
2082
  */
1696
2083
  export declare function isXhrSupported(): boolean;
1697
2084
 
2085
+ export declare interface ITelemetryInitializerContainer {
2086
+ /**
2087
+ * Add a telemetry processor to decorate or drop telemetry events.
2088
+ * @param telemetryInitializer - The Telemetry Initializer function
2089
+ * @returns - A ITelemetryInitializerHandler to enable the initializer to be removed
2090
+ */
2091
+ addTelemetryInitializer(telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler | void;
2092
+ }
2093
+
2094
+ export declare interface ITelemetryInitializerHandler {
2095
+ remove(): void;
2096
+ }
2097
+
1698
2098
  /**
1699
2099
  * Telemety item supported in Core
1700
2100
  */
@@ -1744,15 +2144,7 @@ export declare interface ITelemetryItem {
1744
2144
  /**
1745
2145
  * Configuration provided to SDK core
1746
2146
  */
1747
- export declare interface ITelemetryPlugin extends IPlugin {
1748
- /**
1749
- * Call back for telemetry processing before it it is sent
1750
- * @param env - This is the current event being reported
1751
- * @param itemCtx - This is the context for the current request, ITelemetryPlugin instances
1752
- * can optionally use this to access the current core instance or define / pass additional information
1753
- * to later plugins (vs appending items to the telemetry item)
1754
- */
1755
- processTelemetry: (env: ITelemetryItem, itemCtx?: IProcessTelemetryContext) => void;
2147
+ export declare interface ITelemetryPlugin extends ITelemetryProcessor, IPlugin {
1756
2148
  /**
1757
2149
  * Set next extension for telemetry processing, this is not optional as plugins should use the
1758
2150
  * processNext() function of the passed IProcessTelemetryContext instead. It is being kept for
@@ -1768,7 +2160,7 @@ export declare interface ITelemetryPlugin extends IPlugin {
1768
2160
  /**
1769
2161
  * Configuration provided to SDK core
1770
2162
  */
1771
- export declare interface ITelemetryPluginChain {
2163
+ export declare interface ITelemetryPluginChain extends ITelemetryProcessor {
1772
2164
  /**
1773
2165
  * Returns the underlying plugin that is being proxied for the processTelemetry call
1774
2166
  */
@@ -1777,6 +2169,16 @@ export declare interface ITelemetryPluginChain {
1777
2169
  * Returns the next plugin
1778
2170
  */
1779
2171
  getNext: () => ITelemetryPluginChain;
2172
+ /**
2173
+ * This plugin is being unloaded and should remove any hooked events and cleanup any global/scoped values, after this
2174
+ * call the plugin will be removed from the telemetry processing chain and will no longer receive any events..
2175
+ * @param unloadCtx - The unload context to use for this call.
2176
+ * @param unloadState - The details of the unload operation
2177
+ */
2178
+ unload?: (unloadCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
2179
+ }
2180
+
2181
+ declare interface ITelemetryProcessor {
1780
2182
  /**
1781
2183
  * Call back for telemetry processing before it it is sent
1782
2184
  * @param env - This is the current event being reported
@@ -1784,7 +2186,60 @@ export declare interface ITelemetryPluginChain {
1784
2186
  * can optionally use this to access the current core instance or define / pass additional information
1785
2187
  * to later plugins (vs appending items to the telemetry item)
1786
2188
  */
1787
- processTelemetry: (env: ITelemetryItem, itemCtx: IProcessTelemetryContext) => void;
2189
+ processTelemetry: (env: ITelemetryItem, itemCtx?: IProcessTelemetryContext) => void;
2190
+ /**
2191
+ * The the plugin should re-evaluate configuration and update any cached configuration settings or
2192
+ * plugins. If implemented this method will be called whenever a plugin is added or removed and if
2193
+ * the configuration has bee updated.
2194
+ * @param updateCtx - This is the context that should be used during updating.
2195
+ * @param updateState - The details / state of the update process, it holds details like the current and previous configuration.
2196
+ * @returns boolean - true if the plugin has or will call updateCtx.processNext(), this allows the plugin to perform any asynchronous operations.
2197
+ */
2198
+ update?: (updateCtx: IProcessTelemetryUpdateContext, updateState: ITelemetryUpdateState) => void | boolean;
2199
+ }
2200
+
2201
+ export declare interface ITelemetryUnloadState {
2202
+ reason: TelemetryUnloadReason;
2203
+ isAsync: boolean;
2204
+ flushComplete?: boolean;
2205
+ }
2206
+
2207
+ export declare interface ITelemetryUpdateState {
2208
+ /**
2209
+ * Identifies the reason for the update notification, this is a bitwise numeric value
2210
+ */
2211
+ reason: TelemetryUpdateReason;
2212
+ /**
2213
+ * If this is a configuration update this was the previous configuration that was used
2214
+ */
2215
+ /**
2216
+ * If this is a configuration update is the new configuration that is being used
2217
+ */
2218
+ /**
2219
+ * This holds a collection of plugins that have been added (if the reason identifies that one or more plugins have been added)
2220
+ */
2221
+ added?: IPlugin[];
2222
+ /**
2223
+ * This holds a collection of plugins that have been removed (if the reason identifies that one or more plugins have been removed)
2224
+ */
2225
+ removed?: IPlugin[];
2226
+ }
2227
+
2228
+ export declare interface IUnloadableComponent {
2229
+ /**
2230
+ * Teardown / Unload hook to allow implementations to perform some additional unload operations before the BaseTelemetryPlugin
2231
+ * finishes it's removal.
2232
+ * @param unloadCtx - This is the context that should be used during unloading.
2233
+ * @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.
2234
+ * @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.
2235
+ * @returns boolean - true if the plugin has or will call asyncCallback, this allows the plugin to perform any asynchronous operations.
2236
+ */
2237
+ _doUnload?: (unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState, asyncCallback?: () => void) => void | boolean;
2238
+ }
2239
+
2240
+ export declare interface IUnloadHandlerContainer {
2241
+ add: (handler: UnloadHandler) => void;
2242
+ run: (itemCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
1788
2243
  }
1789
2244
 
1790
2245
  /**
@@ -1799,16 +2254,19 @@ export declare interface ITelemetryPluginChain {
1799
2254
  */
1800
2255
  export declare function _legacyCookieMgr(config?: IConfiguration, logger?: IDiagnosticLogger): ICookieMgr;
1801
2256
 
1802
- export declare enum LoggingSeverity {
1803
- /**
1804
- * Error will be sent as internal telemetry
1805
- */
1806
- CRITICAL = 1,
1807
- /**
1808
- * Error will NOT be sent as internal telemetry, and will only be shown in browser console
1809
- */
1810
- WARNING = 2
1811
- }
2257
+ export declare const LoggingSeverity: EnumValue<typeof eLoggingSeverity>;
2258
+
2259
+ export declare type LoggingSeverity = number | eLoggingSeverity;
2260
+
2261
+ /**
2262
+ * Logs a message to the internal queue.
2263
+ * @param logger - The Diagnostic Logger instance to use.
2264
+ * @param severity {LoggingSeverity} - The severity of the log message
2265
+ * @param message {_InternalLogMessage} - The message to log.
2266
+ */
2267
+ export declare function _logInternalMessage(logger: IDiagnosticLogger, severity: LoggingSeverity, message: _InternalLogMessage): void;
2268
+
2269
+ export declare function mergeEvtNamespace(theNamespace: string, namespaces?: string | string[] | null): string | string[];
1812
2270
 
1813
2271
  export declare const MinChannelPriorty: number;
1814
2272
 
@@ -1900,13 +2358,27 @@ export { objCreate }
1900
2358
  */
1901
2359
  export declare function objDefineAccessors<T>(target: any, prop: string, getProp?: () => T, setProp?: (v: T) => void): boolean;
1902
2360
 
2361
+ /**
2362
+ * Pass in the objects to merge as arguments, this will only "merge" (extend) properties that are owned by the object.
2363
+ * It will NOT merge inherited or non-enumerable properties.
2364
+ * @param obj1 - object to merge. Set this argument to 'true' for a deep extend.
2365
+ * @param obj2 - object to merge.
2366
+ * @param obj3 - object to merge.
2367
+ * @param obj4 - object to merge.
2368
+ * @param obj5 - object to merge.
2369
+ * @returns The extended first object.
2370
+ */
2371
+ export declare function objExtend<T2, T3, T4, T5, T6>(deepExtend?: boolean, obj2?: T2, obj3?: T3, obj4?: T4, obj5?: T5, obj6?: T6): T2 & T3 & T4 & T5 & T6;
2372
+
2373
+ export declare function objExtend<T1, T2, T3, T4, T5, T6>(obj1?: T1, obj2?: T2, obj3?: T3, obj4?: T4, obj5?: T5, obj6?: T6): T1 & T2 & T3 & T4 & T5 & T6;
2374
+
1903
2375
  /**
1904
2376
  * This is a helper function for the equivalent of arForEach(objKeys(target), callbackFn), this is a
1905
2377
  * performance optimization to avoid the creation of a new array for large objects
1906
2378
  * @param target The target object to find and process the keys
1907
2379
  * @param callbackfn The function to call with the details
1908
2380
  */
1909
- export declare function objForEachKey(target: any, callbackfn: (name: string, value: any) => void): void;
2381
+ export declare function objForEachKey<T = any>(target: T, callbackfn: (name: string, value: T[keyof T]) => void): void;
1910
2382
 
1911
2383
  export declare const objFreeze: <T>(value: T) => T;
1912
2384
 
@@ -1920,6 +2392,8 @@ export declare function objKeys(obj: {}): string[];
1920
2392
 
1921
2393
  export declare const objSeal: <T>(value: T) => T;
1922
2394
 
2395
+ export declare function objToString(obj: any): any;
2396
+
1923
2397
  /**
1924
2398
  * A helper function to assist with JIT performance for objects that have properties added / removed dynamically
1925
2399
  * this is primarily for chromium based browsers and has limited effects on Firefox and none of IE. Only call this
@@ -1975,7 +2449,7 @@ export declare class PerfManager implements IPerfManager {
1975
2449
  * Defined as private so it can be visualized via the DebugPlugin
1976
2450
  */
1977
2451
  private ctx;
1978
- constructor(manager: INotificationManager);
2452
+ constructor(manager?: INotificationManager);
1979
2453
  /**
1980
2454
  * Create a new event and start timing, the manager may return null/undefined to indicate that it does not
1981
2455
  * want to monitor this source event.
@@ -2008,13 +2482,17 @@ export declare class PerfManager implements IPerfManager {
2008
2482
  */
2009
2483
  export declare function perfNow(): number;
2010
2484
 
2485
+ /**
2486
+ * This class will be removed!
2487
+ * @deprecated use createProcessTelemetryContext() instead
2488
+ */
2011
2489
  export declare class ProcessTelemetryContext implements IProcessTelemetryContext {
2012
2490
  /**
2013
2491
  * Gets the current core config instance
2014
2492
  */
2015
2493
  getCfg: () => IConfiguration;
2016
2494
  getExtCfg: <T>(identifier: string, defaultValue?: T | any) => T;
2017
- getConfig: (identifier: string, field: string, defaultValue?: number | string | boolean) => number | string | boolean;
2495
+ getConfig: (identifier: string, field: string, defaultValue?: number | string | boolean | string[] | RegExp[] | Function) => number | string | boolean | string[] | RegExp[] | Function;
2018
2496
  /**
2019
2497
  * Returns the IAppInsightsCore instance for the current request
2020
2498
  */
@@ -2042,19 +2520,34 @@ export declare class ProcessTelemetryContext implements IProcessTelemetryContext
2042
2520
  * @param itemCtx - This is the context for the current request, ITelemetryPlugin instances
2043
2521
  * can optionally use this to access the current core instance or define / pass additional information
2044
2522
  * to later plugins (vs appending items to the telemetry item)
2523
+ * @returns boolean (true) if there is no more plugins to process otherwise false or undefined (void)
2045
2524
  */
2046
- processNext: (env: ITelemetryItem) => void;
2525
+ processNext: (env: ITelemetryItem) => boolean | void;
2526
+ /**
2527
+ * Synchronously iterate over the context chain running the callback for each plugin, once
2528
+ * every plugin has been executed via the callback, any associated onComplete will be called.
2529
+ * @param callback - The function call for each plugin in the context chain
2530
+ */
2531
+ iterate: <T extends ITelemetryPlugin = ITelemetryPlugin>(callback: (plugin: T) => void) => void;
2047
2532
  /**
2048
2533
  * Create a new context using the core and config from the current instance
2534
+ * @param plugins - The execution order to process the plugins, if null or not supplied
2535
+ * then the current execution order will be copied.
2536
+ * @param startAt - The plugin to start processing from, if missing from the execution
2537
+ * order then the next plugin will be NOT set.
2049
2538
  */
2050
2539
  createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryContext;
2540
+ /**
2541
+ * Set the function to call when the current chain has executed all processNext or unloadNext items.
2542
+ */
2543
+ onComplete: (onComplete: () => void) => void;
2051
2544
  /**
2052
2545
  * Creates a new Telemetry Item context with the current config, core and plugin execution chain
2053
2546
  * @param plugins - The plugin instances that will be executed
2054
2547
  * @param config - The current config
2055
2548
  * @param core - The current core instance
2056
2549
  */
2057
- constructor(plugins: IPlugin[] | ITelemetryPluginChain, config: IConfiguration, core: IAppInsightsCore, startAt?: IPlugin);
2550
+ constructor(pluginChain: ITelemetryPluginChain, config: IConfiguration, core: IAppInsightsCore, startAt?: IPlugin);
2058
2551
  }
2059
2552
 
2060
2553
  /**
@@ -2071,9 +2564,29 @@ export declare class ProcessTelemetryContext implements IProcessTelemetryContext
2071
2564
  * @param target - The target object to be assigned with the source properties and functions
2072
2565
  * @param source - The source object which will be assigned / called by setting / calling the targets proxies
2073
2566
  * @param chkSet - An optional callback to determine whether a specific property/function should be proxied
2074
- * @memberof Initialization
2075
2567
  */
2076
- export declare function proxyAssign(target: any, source: any, chkSet?: (name: string, isFunc?: boolean, source?: any, target?: any) => boolean): any;
2568
+ export declare function proxyAssign<T, S>(target: T, source: S, chkSet?: (name: string, isFunc?: boolean, source?: S, target?: T) => boolean): T;
2569
+
2570
+ /**
2571
+ * Creates a proxy function on the target which internally will call the source version with all arguments passed to the target method.
2572
+ *
2573
+ * @param target - The target object to be assigned with the source properties and functions
2574
+ * @param name - The function name that will be added on the target
2575
+ * @param source - The source object which will be assigned / called by setting / calling the targets proxies
2576
+ * @param theFunc - The function name on the source that will be proxied on the target
2577
+ * @param overwriteTarget - If `false` this will not replace any pre-existing name otherwise (the default) it will overwrite any existing name
2578
+ */
2579
+ export declare function proxyFunctionAs<T, S>(target: T, name: string, source: S | (() => S), theFunc: (keyof S), overwriteTarget?: boolean): void;
2580
+
2581
+ /**
2582
+ * Creates proxy functions on the target which internally will call the source version with all arguments passed to the target method.
2583
+ *
2584
+ * @param target - The target object to be assigned with the source properties and functions
2585
+ * @param source - The source object which will be assigned / called by setting / calling the targets proxies
2586
+ * @param functionsToProxy - An array of function names that will be proxied on the target
2587
+ * @param overwriteTarget - If false this will not replace any pre-existing name otherwise (the default) it will overwrite any existing name
2588
+ */
2589
+ export declare function proxyFunctions<T, S>(target: T, source: S | (() => S), functionsToProxy: (keyof S)[], overwriteTarget?: boolean): T;
2077
2590
 
2078
2591
  /**
2079
2592
  * generate a random 32-bit number (0x000000..0xFFFFFFFF) or (-0x80000000..0x7FFFFFFF), defaults un-unsigned.
@@ -2088,6 +2601,52 @@ export declare function random32(signed?: boolean): number;
2088
2601
  */
2089
2602
  export declare function randomValue(maxValue: number): number;
2090
2603
 
2604
+ /**
2605
+ * Trys to remove event handler(s) for the specified event/namespace to the window, body and document
2606
+ * @param eventName {string} - The name of the event, with optional namespaces or just the namespaces,
2607
+ * such as "click", "click.mynamespace" or ".mynamespace"
2608
+ * @param callback {any} - - The callback function that needs to be removed from the given event, when using a
2609
+ * namespace (with or without a qualifying event) this may be null to remove all previously attached event handlers
2610
+ * otherwise this will only remove events with this specific handler.
2611
+ * @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.
2612
+ */
2613
+ export declare function removeEventHandler(eventName: string, callback: any, evtNamespace?: string | string[] | null): void;
2614
+
2615
+ /**
2616
+ * Remove the listener from the array of events
2617
+ * @param events An string array of event names to bind the listener to
2618
+ * @param listener The event callback to call when the event is triggered
2619
+ * @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.
2620
+ */
2621
+ export declare function removeEventListeners(events: string[], listener: any, evtNamespace?: string | string[]): void;
2622
+
2623
+ /**
2624
+ * Removes the pageHide event listeners added by addPageHideEventListener, because the 'visibilitychange' uses
2625
+ * an internal proxy to detect the visibility state you SHOULD use a unique namespace when calling addPageHideEventListener
2626
+ * as the remove ignores the listener argument for the 'visibilitychange' event.
2627
+ * @param listener - The specific listener to remove for the 'pageshow' event only (ignored for 'visibilitychange')
2628
+ * @param evtNamespace - The unique namespace used when calling addPageShowEventListener
2629
+ */
2630
+ export declare function removePageHideEventListener(listener: any, evtNamespace?: string | string[] | null): void;
2631
+
2632
+ /**
2633
+ * Removes the pageShow event listeners added by addPageShowEventListener, because the 'visibilitychange' uses
2634
+ * an internal proxy to detect the visibility state you SHOULD use a unique namespace when calling addPageShowEventListener
2635
+ * as the remove ignores the listener argument for the 'visibilitychange' event.
2636
+ * @param listener - The specific listener to remove for the 'pageshow' event only (ignored for 'visibilitychange')
2637
+ * @param evtNamespace - The unique namespace used when calling addPageShowEventListener
2638
+ */
2639
+ export declare function removePageShowEventListener(listener: any, evtNamespace?: string | string[] | null): void;
2640
+
2641
+ /**
2642
+ * Remove any matching 'beforeunload', 'unload' and 'pagehide' events that may have been added via addEventListener,
2643
+ * addEventListeners, addPageUnloadEventListener or addPageHideEventListener.
2644
+ * @param listener - The specific event callback to to be removed
2645
+ * @param evtNamespace - [Optional] Namespace(s) uniquely identified and removed based on this namespace.
2646
+ * @returns true - when at least one of the events was registered otherwise false
2647
+ */
2648
+ export declare function removePageUnloadEventListener(listener: any, evtNamespace?: string | string[]): void;
2649
+
2091
2650
  /**
2092
2651
  * Helper to return the ICookieMgr from the core (if not null/undefined) or a default implementation
2093
2652
  * associated with the configuration or a legacy default.
@@ -2131,6 +2690,10 @@ export declare const enum SendRequestReason {
2131
2690
  * The event(s) being sent as a retry
2132
2691
  */
2133
2692
  Retry = 5,
2693
+ /**
2694
+ * The SDK is unloading
2695
+ */
2696
+ SdkUnload = 6,
2134
2697
  /**
2135
2698
  * Maximum batch size would be exceeded
2136
2699
  */
@@ -2169,9 +2732,9 @@ export declare function setGblPerfMgr(perfManager: IPerfManager): void;
2169
2732
  * @param srcChk - [Optional] Callback to check to original value that if supplied will be called if the new value should be set (if allowed)
2170
2733
  * @returns The existing or new value, depending what was set
2171
2734
  */
2172
- 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];
2735
+ 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];
2173
2736
 
2174
- export declare function sortPlugins(plugins: IPlugin[]): IPlugin[];
2737
+ export declare function sortPlugins<T = IPlugin>(plugins: T[]): T[];
2175
2738
 
2176
2739
  /**
2177
2740
  * A simple wrapper (for minification support) to check if the value contains the search string.
@@ -2217,8 +2780,64 @@ export declare interface Tags {
2217
2780
  [key: string]: any;
2218
2781
  }
2219
2782
 
2783
+ export declare type TelemetryInitializerFunction = <T extends ITelemetryItem>(item: T) => boolean | void;
2784
+
2785
+ /**
2786
+ * The TelemetryUnloadReason enumeration contains the possible reasons for why a plugin is being unloaded / torndown().
2787
+ */
2788
+ export declare const enum TelemetryUnloadReason {
2789
+ /**
2790
+ * Teardown has been called without any context.
2791
+ */
2792
+ ManualTeardown = 0,
2793
+ /**
2794
+ * Just this plugin is being removed
2795
+ */
2796
+ PluginUnload = 1,
2797
+ /**
2798
+ * This instance of the plugin is being removed and replaced
2799
+ */
2800
+ PluginReplace = 2,
2801
+ /**
2802
+ * The entire SDK is being unloaded
2803
+ */
2804
+ SdkUnload = 50
2805
+ }
2806
+
2807
+ /**
2808
+ * The TelemetryUpdateReason enumeration contains a set of bit-wise values that specify the reason for update request.
2809
+ */
2810
+ export declare const enum TelemetryUpdateReason {
2811
+ /**
2812
+ * Unknown.
2813
+ */
2814
+ Unknown = 0,
2815
+ /**
2816
+ * The configuration has ben updated or changed
2817
+ */
2818
+ /**
2819
+ * One or more plugins have been added
2820
+ */
2821
+ PluginAdded = 16,
2822
+ /**
2823
+ * One or more plugins have been removed
2824
+ */
2825
+ PluginRemoved = 32
2826
+ }
2827
+
2220
2828
  export declare function throwError(message: string): never;
2221
2829
 
2830
+ /**
2831
+ * This is a helper method which will call throwInternal on the passed logger, will throw exceptions in
2832
+ * debug mode or attempt to log the error as a console warning. This helper is provided mostly to better
2833
+ * support minification as logger.throwInternal() will not compress the publish "throwInternal" used throughout
2834
+ * the code.
2835
+ * @param logger - The Diagnostic Logger instance to use.
2836
+ * @param severity {LoggingSeverity} - The severity of the log message
2837
+ * @param message {_InternalLogMessage} - The log message.
2838
+ */
2839
+ export declare function _throwInternal(logger: IDiagnosticLogger, severity: LoggingSeverity, msgId: _InternalMessageId, msg: string, properties?: Object, isUserAct?: boolean): void;
2840
+
2222
2841
  /**
2223
2842
  * Convert a date to I.S.O. format in IE8
2224
2843
  */
@@ -2228,6 +2847,26 @@ export declare function uaDisallowsSameSiteNone(userAgent: string): boolean;
2228
2847
 
2229
2848
  export declare const Undefined = "undefined";
2230
2849
 
2850
+ /**
2851
+ * Teardown / Unload helper to perform teardown/unloading operations for the provided components synchronously or asynchronously, this will call any
2852
+ * _doTeardown() or _doUnload() functions on the provided components to allow them to finish removal.
2853
+ * @param components - The components you want to unload
2854
+ * @param unloadCtx - This is the context that should be used during unloading.
2855
+ * @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.
2856
+ * @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.
2857
+ * @returns boolean - true if the plugin has or will call asyncCallback, this allows the plugin to perform any asynchronous operations.
2858
+ */
2859
+ export declare function unloadComponents(components: any | IUnloadableComponent[], unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState, asyncCallback?: () => void): void | boolean;
2860
+
2861
+ export declare type UnloadHandler = (itemCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
2862
+
2231
2863
  export declare function useXDomainRequest(): boolean | undefined;
2232
2864
 
2865
+ /**
2866
+ * This is a helper method which will call warnToConsole on the passed logger with the provided message.
2867
+ * @param logger - The Diagnostic Logger instance to use.
2868
+ * @param message {_InternalLogMessage} - The log message.
2869
+ */
2870
+ export declare function _warnToConsole(logger: IDiagnosticLogger, message: string): void;
2871
+
2233
2872
  export { }