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

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 (160) hide show
  1. package/browser/applicationinsights-core-js.integrity.json +9 -9
  2. package/browser/applicationinsights-core-js.js +1999 -793
  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 +16363 -9167
  7. package/dist/applicationinsights-core-js.api.md +425 -48
  8. package/dist/applicationinsights-core-js.d.ts +784 -123
  9. package/dist/applicationinsights-core-js.js +1999 -793
  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 +784 -123
  14. package/dist-esm/JavaScriptSDK/AppInsightsCore.js +3 -69
  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 +25 -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 +89 -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/EventsDiscardedReason.js +1 -1
  56. package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js +90 -96
  57. package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js.map +1 -1
  58. package/dist-esm/JavaScriptSDK.Enums/SendRequestReason.js +1 -1
  59. package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js +8 -0
  60. package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js.map +1 -0
  61. package/dist-esm/JavaScriptSDK.Enums/TelemetryUpdateReason.js +8 -0
  62. package/dist-esm/JavaScriptSDK.Enums/TelemetryUpdateReason.js.map +1 -0
  63. package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js +1 -2
  64. package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js.map +1 -1
  65. package/dist-esm/JavaScriptSDK.Interfaces/IChannelControls.js +1 -1
  66. package/dist-esm/JavaScriptSDK.Interfaces/IConfiguration.js +1 -1
  67. package/dist-esm/JavaScriptSDK.Interfaces/ICookieMgr.js +1 -1
  68. package/dist-esm/JavaScriptSDK.Interfaces/IDbgExtension.js +1 -1
  69. package/dist-esm/JavaScriptSDK.Interfaces/IDiagnosticLogger.js +1 -1
  70. package/dist-esm/JavaScriptSDK.Interfaces/IInstrumentHooks.js +1 -1
  71. package/dist-esm/JavaScriptSDK.Interfaces/INotificationListener.js +1 -1
  72. package/dist-esm/JavaScriptSDK.Interfaces/INotificationManager.js +1 -1
  73. package/dist-esm/JavaScriptSDK.Interfaces/IPerfEvent.js +1 -1
  74. package/dist-esm/JavaScriptSDK.Interfaces/IPerfManager.js +1 -1
  75. package/dist-esm/JavaScriptSDK.Interfaces/IProcessTelemetryContext.js +1 -1
  76. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js +6 -0
  77. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js.map +1 -0
  78. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryItem.js +1 -1
  79. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPlugin.js +1 -1
  80. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js +1 -2
  81. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js.map +1 -1
  82. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js +8 -0
  83. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js.map +1 -0
  84. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUpdateState.js +8 -0
  85. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUpdateState.js.map +1 -0
  86. package/dist-esm/JavaScriptSDK.Interfaces/IUnloadableComponent.js +6 -0
  87. package/dist-esm/JavaScriptSDK.Interfaces/IUnloadableComponent.js.map +1 -0
  88. package/dist-esm/applicationinsights-core-js.js +12 -7
  89. package/dist-esm/applicationinsights-core-js.js.map +1 -1
  90. package/package.json +2 -2
  91. package/src/JavaScriptSDK/AppInsightsCore.ts +2 -101
  92. package/src/JavaScriptSDK/BaseCore.ts +696 -120
  93. package/src/JavaScriptSDK/BaseTelemetryPlugin.ts +205 -31
  94. package/src/JavaScriptSDK/ChannelController.ts +242 -103
  95. package/src/JavaScriptSDK/CookieMgr.ts +7 -5
  96. package/src/JavaScriptSDK/CoreUtils.ts +8 -172
  97. package/src/JavaScriptSDK/DataCacheHelper.ts +106 -0
  98. package/src/JavaScriptSDK/DiagnosticLogger.ts +27 -12
  99. package/src/JavaScriptSDK/EnvUtils.ts +13 -12
  100. package/src/JavaScriptSDK/EventHelpers.ts +550 -0
  101. package/src/JavaScriptSDK/HelperFuncs.ts +123 -97
  102. package/src/JavaScriptSDK/InstrumentHooks.ts +4 -2
  103. package/src/JavaScriptSDK/InternalConstants.ts +26 -0
  104. package/src/JavaScriptSDK/NotificationManager.ts +34 -37
  105. package/src/JavaScriptSDK/PerfManager.ts +4 -7
  106. package/src/JavaScriptSDK/ProcessTelemetryContext.ts +543 -134
  107. package/src/JavaScriptSDK/RandomHelper.ts +35 -3
  108. package/src/JavaScriptSDK/TelemetryHelpers.ts +83 -21
  109. package/src/JavaScriptSDK/TelemetryInitializerPlugin.ts +111 -0
  110. package/src/JavaScriptSDK/UnloadHandlerContainer.ts +46 -0
  111. package/src/JavaScriptSDK.Enums/LoggingEnums.ts +184 -87
  112. package/src/JavaScriptSDK.Enums/SendRequestReason.ts +5 -0
  113. package/src/JavaScriptSDK.Enums/TelemetryUnloadReason.ts +27 -0
  114. package/src/JavaScriptSDK.Enums/TelemetryUpdateReason.ts +27 -0
  115. package/src/JavaScriptSDK.Interfaces/IAppInsightsCore.ts +82 -2
  116. package/src/JavaScriptSDK.Interfaces/IChannelControls.ts +16 -5
  117. package/src/JavaScriptSDK.Interfaces/IInstrumentHooks.ts +16 -6
  118. package/src/JavaScriptSDK.Interfaces/IProcessTelemetryContext.ts +94 -14
  119. package/src/JavaScriptSDK.Interfaces/ITelemetryInitializers.ts +16 -0
  120. package/src/JavaScriptSDK.Interfaces/ITelemetryPlugin.ts +28 -10
  121. package/src/JavaScriptSDK.Interfaces/ITelemetryPluginChain.ts +9 -11
  122. package/src/JavaScriptSDK.Interfaces/ITelemetryUnloadState.ts +10 -0
  123. package/src/JavaScriptSDK.Interfaces/ITelemetryUpdateState.ts +34 -0
  124. package/src/JavaScriptSDK.Interfaces/IUnloadableComponent.ts +17 -0
  125. package/types/JavaScriptSDK/AppInsightsCore.d.ts +0 -21
  126. package/types/JavaScriptSDK/BaseCore.d.ts +81 -3
  127. package/types/JavaScriptSDK/BaseTelemetryPlugin.d.ts +53 -10
  128. package/types/JavaScriptSDK/ChannelController.d.ts +16 -17
  129. package/types/JavaScriptSDK/CoreUtils.d.ts +1 -48
  130. package/types/JavaScriptSDK/DataCacheHelper.d.ts +13 -0
  131. package/types/JavaScriptSDK/DiagnosticLogger.d.ts +10 -0
  132. package/types/JavaScriptSDK/EventHelpers.d.ts +154 -0
  133. package/types/JavaScriptSDK/HelperFuncs.d.ts +33 -32
  134. package/types/JavaScriptSDK/InternalConstants.d.ts +20 -0
  135. package/types/JavaScriptSDK/PerfManager.d.ts +1 -1
  136. package/types/JavaScriptSDK/ProcessTelemetryContext.d.ts +69 -6
  137. package/types/JavaScriptSDK/RandomHelper.d.ts +6 -0
  138. package/types/JavaScriptSDK/TelemetryHelpers.d.ts +23 -3
  139. package/types/JavaScriptSDK/TelemetryInitializerPlugin.d.ts +16 -0
  140. package/types/JavaScriptSDK/UnloadHandlerContainer.d.ts +11 -0
  141. package/types/JavaScriptSDK.Enums/LoggingEnums.d.ts +91 -2
  142. package/types/JavaScriptSDK.Enums/SendRequestReason.d.ts +4 -0
  143. package/types/JavaScriptSDK.Enums/TelemetryUnloadReason.d.ts +21 -0
  144. package/types/JavaScriptSDK.Enums/TelemetryUpdateReason.d.ts +20 -0
  145. package/types/JavaScriptSDK.Interfaces/IAppInsightsCore.d.ts +72 -1
  146. package/types/JavaScriptSDK.Interfaces/IChannelControls.d.ts +16 -5
  147. package/types/JavaScriptSDK.Interfaces/IInstrumentHooks.d.ts +9 -0
  148. package/types/JavaScriptSDK.Interfaces/IProcessTelemetryContext.d.ts +82 -11
  149. package/types/JavaScriptSDK.Interfaces/ITelemetryInitializers.d.ts +13 -0
  150. package/types/JavaScriptSDK.Interfaces/ITelemetryPlugin.d.ts +25 -8
  151. package/types/JavaScriptSDK.Interfaces/ITelemetryPluginChain.d.ts +9 -10
  152. package/types/JavaScriptSDK.Interfaces/ITelemetryUnloadState.d.ts +6 -0
  153. package/types/JavaScriptSDK.Interfaces/ITelemetryUpdateState.d.ts +22 -0
  154. package/types/JavaScriptSDK.Interfaces/IUnloadableComponent.d.ts +13 -0
  155. package/types/applicationinsights-core-js.d.ts +18 -9
  156. package/types/tsdoc-metadata.json +1 -1
  157. package/dist-esm/JavaScriptSDK/TelemetryPluginChain.js +0 -76
  158. package/dist-esm/JavaScriptSDK/TelemetryPluginChain.js.map +0 -1
  159. package/src/JavaScriptSDK/TelemetryPluginChain.ts +0 -120
  160. 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-04
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  *
5
5
  * Microsoft Application Insights Team
@@ -14,39 +14,61 @@ declare namespace ApplicationInsights {
14
14
  import { strShimPrototype as strPrototype } from '@microsoft/applicationinsights-shims';
15
15
  import { strShimUndefined as strUndefined } from '@microsoft/applicationinsights-shims';
16
16
 
17
+ /**
18
+ * Get all of the registered events on the target object, this is primarily used for testing cleanup but may also be used by
19
+ * applications to remove their own events
20
+ * @param target - The EventTarget that has registered events
21
+ * @param eventName - [Optional] The name of the event to return the registered handlers and full name (with namespaces)
22
+ * @param evtNamespace - [Optional] Additional namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace,
23
+ * if the eventName also includes a namespace the namespace(s) are merged into a single namespace
24
+ */
25
+ function __getRegisteredEvents(target: any, eventName?: string, evtNamespace?: string | string[]): _IRegisteredEvents[];
26
+
17
27
  /**
18
28
  * Trys to add an event handler for the specified event to the window, body and document
19
29
  * @param eventName {string} - The name of the event
20
30
  * @param callback {any} - The callback function that needs to be executed for the given event
31
+ * @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.
21
32
  * @return {boolean} - true if the handler was successfully added
22
33
  */
23
- function addEventHandler(eventName: string, callback: any): boolean;
34
+ function addEventHandler(eventName: string, callback: any, evtNamespace?: string | string[] | null): boolean;
24
35
 
25
36
  /**
26
37
  * Bind the listener to the array of events
27
38
  * @param events An string array of event names to bind the listener to
28
39
  * @param listener The event callback to call when the event is triggered
29
40
  * @param excludeEvents - [Optional] An array of events that should not be hooked (if possible), unless no other events can be.
41
+ * @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.
30
42
  * @returns true - when at least one of the events was registered otherwise false
31
43
  */
32
- function addEventListeners(events: string[], listener: any, excludeEvents?: string[]): boolean;
44
+ function addEventListeners(events: string[], listener: any, excludeEvents?: string[], evtNamespace?: string | string[]): boolean;
33
45
 
34
46
  /**
35
- * Listen to the pagehide and visibility changing to 'hidden' events
47
+ * Listen to the pagehide and visibility changing to 'hidden' events, because the 'visibilitychange' uses
48
+ * an internal proxy to detect the visibility state you SHOULD use a unique namespace when if you plan to call
49
+ * removePageShowEventListener as the remove ignores the listener argument for the 'visibilitychange' event.
36
50
  * @param listener - The event callback to call when a page hide event is triggered
37
51
  * @param excludeEvents - [Optional] An array of events that should not be hooked (if possible), unless no other events can be.
52
+ * @param evtNamespace - [Optional] A Namespace to append to the event listeners so they can be uniquely identified and removed
53
+ * based on this namespace. This call also adds an additional unique "pageshow" namespace to the events
54
+ * so that only the matching "removePageHideEventListener" can remove these events.
38
55
  * Suggestion: pass as true if you are also calling addPageUnloadEventListener as that also hooks pagehide
39
56
  * @returns true - when at least one of the events was registered otherwise false
40
57
  */
41
- function addPageHideEventListener(listener: any, excludeEvents?: string[]): boolean;
58
+ function addPageHideEventListener(listener: any, excludeEvents?: string[] | null, evtNamespace?: string | string[] | null): boolean;
42
59
 
43
60
  /**
44
- * Listen to the pageshow and visibility changing to 'visible' events
61
+ * Listen to the pageshow and visibility changing to 'visible' events, because the 'visibilitychange' uses
62
+ * an internal proxy to detect the visibility state you SHOULD use a unique namespace when if you plan to call
63
+ * removePageShowEventListener as the remove ignores the listener argument for the 'visibilitychange' event.
45
64
  * @param listener - The event callback to call when a page is show event is triggered
46
65
  * @param excludeEvents - [Optional] An array of events that should not be hooked (if possible), unless no other events can be.
66
+ * @param evtNamespace - [Optional/Recommended] A Namespace to append to the event listeners so they can be uniquely
67
+ * identified and removed based on this namespace. This call also adds an additional unique "pageshow" namespace to the events
68
+ * so that only the matching "removePageShowEventListener" can remove these events.
47
69
  * @returns true - when at least one of the events was registered otherwise false
48
70
  */
49
- function addPageShowEventListener(listener: any, excludeEvents?: string[]): boolean;
71
+ function addPageShowEventListener(listener: any, excludeEvents?: string[] | null, evtNamespace?: string | string[] | null): boolean;
50
72
 
51
73
  /**
52
74
  * Listen to the 'beforeunload', 'unload' and 'pagehide' events which indicates a page unload is occurring,
@@ -56,34 +78,15 @@ declare namespace ApplicationInsights {
56
78
  * need to listen to the 'addPageHideEventListener' and 'addPageShowEventListener' events.
57
79
  * @param listener - The event callback to call when a page unload event is triggered
58
80
  * @param excludeEvents - [Optional] An array of events that should not be hooked, unless no other events can be.
81
+ * @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.
59
82
  * @returns true - when at least one of the events was registered otherwise false
60
83
  */
61
- function addPageUnloadEventListener(listener: any, excludeEvents?: string[]): boolean;
84
+ function addPageUnloadEventListener(listener: any, excludeEvents?: string[], evtNamespace?: string | string[]): boolean;
62
85
 
63
86
  class AppInsightsCore extends BaseCore implements IAppInsightsCore {
64
87
  constructor();
65
88
  initialize(config: IConfiguration, extensions: IPlugin[], logger?: IDiagnosticLogger, notificationManager?: INotificationManager): void;
66
89
  track(telemetryItem: ITelemetryItem): void;
67
- /**
68
- * Adds a notification listener. The SDK calls methods on the listener when an appropriate notification is raised.
69
- * The added plugins must raise notifications. If the plugins do not implement the notifications, then no methods will be
70
- * called.
71
- * @param {INotificationListener} listener - An INotificationListener object.
72
- */
73
- addNotificationListener(listener: INotificationListener): void;
74
- /**
75
- * Removes all instances of the listener.
76
- * @param {INotificationListener} listener - INotificationListener to remove.
77
- */
78
- removeNotificationListener(listener: INotificationListener): void;
79
- /**
80
- * Periodically check logger.queue for
81
- */
82
- pollInternalLogs(eventName?: string): number;
83
- /**
84
- * Periodically check logger.queue for
85
- */
86
- stopPollingInternalLogs(): void;
87
90
  }
88
91
 
89
92
  function areCookiesSupported(logger?: IDiagnosticLogger): any;
@@ -96,7 +99,7 @@ declare namespace ApplicationInsights {
96
99
  * @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
97
100
  * @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.
98
101
  */
99
- function arrForEach<T>(arr: T[], callbackfn: (value: T, index?: number, array?: T[]) => void | number, thisArg?: any): void;
102
+ function arrForEach<T = any>(arr: T[], callbackfn: (value: T, index?: number, array?: T[]) => undefined | void | number, thisArg?: any): void;
100
103
 
101
104
  /**
102
105
  * Returns the index of the first occurrence of a value in an array. This helper exists to avoid adding a polyfil for older browsers
@@ -131,7 +134,7 @@ declare namespace ApplicationInsights {
131
134
  /**
132
135
  * Binds the specified function to an event, so that the function gets called whenever the event fires on the object
133
136
  * @param obj Object to add the event too.
134
- * @param eventNameWithoutOn String that specifies any of the standard DHTML Events without "on" prefix
137
+ * @param eventNameWithoutOn String that specifies any of the standard DHTML Events without "on" prefix and optional (dot "." prefixed) namespaces "click" "click.mynamespace".
135
138
  * @param handlerRef Pointer that specifies the function to call when event fires
136
139
  * @param useCapture [Optional] Defaults to false
137
140
  * @returns True if the function was bound successfully to the event, otherwise false
@@ -150,6 +153,18 @@ declare namespace ApplicationInsights {
150
153
  track(telemetryItem: ITelemetryItem): void;
151
154
  getProcessTelContext(): IProcessTelemetryContext;
152
155
  getNotifyMgr(): INotificationManager;
156
+ /**
157
+ * Adds a notification listener. The SDK calls methods on the listener when an appropriate notification is raised.
158
+ * The added plugins must raise notifications. If the plugins do not implement the notifications, then no methods will be
159
+ * called.
160
+ * @param {INotificationListener} listener - An INotificationListener object.
161
+ */
162
+ addNotificationListener(listener: INotificationListener): void;
163
+ /**
164
+ * Removes all instances of the listener.
165
+ * @param {INotificationListener} listener - INotificationListener to remove.
166
+ */
167
+ removeNotificationListener(listener: INotificationListener): void;
153
168
  /**
154
169
  * Get the current cookie manager for this instance
155
170
  */
@@ -162,7 +177,67 @@ declare namespace ApplicationInsights {
162
177
  getPerfMgr(): IPerfManager;
163
178
  setPerfMgr(perfMgr: IPerfManager): void;
164
179
  eventCnt(): number;
180
+ /**
181
+ * Periodically check logger.queue for
182
+ */
183
+ pollInternalLogs(eventName?: string): number;
184
+ /**
185
+ * Periodically check logger.queue for
186
+ */
187
+ stopPollingInternalLogs(): void;
188
+ /**
189
+ * Add a telemetry processor to decorate or drop telemetry events.
190
+ * @param telemetryInitializer - The Telemetry Initializer function
191
+ * @returns - A ITelemetryInitializerHandler to enable the initializer to be removed
192
+ */
193
+ addTelemetryInitializer(telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler | void;
194
+ /**
195
+ * Unload and Tear down the SDK and any initialized plugins, after calling this the SDK will be considered
196
+ * to be un-initialized and non-operational, re-initializing the SDK should only be attempted if the previous
197
+ * unload call return `true` stating that all plugins reported that they also unloaded, the recommended
198
+ * approach is to create a new instance and initialize that instance.
199
+ * This is due to possible unexpected side effects caused by plugins not supporting unload / teardown, unable
200
+ * to successfully remove any global references or they may just be completing the unload process asynchronously.
201
+ * @param isAsync - Can the unload be performed asynchronously (default)
202
+ * @param unloadComplete - An optional callback that will be called once the unload has completed
203
+ * @param cbTimeout - An optional timeout to wait for any flush operations to complete before proceeding with the unload. Defaults to 5 seconds.
204
+ */
205
+ unload(isAsync?: boolean, unloadComplete?: (unloadState: ITelemetryUnloadState) => void, cbTimeout?: number): void;
206
+ getPlugin<T extends IPlugin = IPlugin>(pluginIdentifier: string): ILoadedPlugin<T>;
207
+ /**
208
+ * Add a new plugin to the installation
209
+ * @param plugin - The new plugin to add
210
+ * @param replaceExisting - should any existing plugin be replaced, default is false
211
+ * @param doAsync - Should the add be performed asynchronously
212
+ * @param addCb - [Optional] callback to call after the plugin has been added
213
+ */
214
+ addPlugin<T extends IPlugin = ITelemetryPlugin>(plugin: T, replaceExisting?: boolean, doAsync?: boolean, addCb?: (added?: boolean) => void): void;
215
+ /**
216
+ * Returns the unique event namespace that should be used
217
+ */
218
+ evtNamespace(): string;
219
+ /**
220
+ * Add an unload handler that will be called when the SDK is being unloaded
221
+ * @param handler - the handler
222
+ */
223
+ addUnloadCb(handler: UnloadHandler): void;
224
+ /**
225
+ * Flush and send any batched / cached data immediately
226
+ * @param async - send data asynchronously when true (defaults to true)
227
+ * @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.
228
+ * If the caller doesn't return true the caller should assume that it may never be called.
229
+ * @param sendReason - specify the reason that you are calling "flush" defaults to ManualFlush (1) if not specified
230
+ * @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
231
+ */
232
+ flush(isAsync?: boolean, callBack?: (flushComplete?: boolean) => void, sendReason?: SendRequestReason): void;
165
233
  protected releaseQueue(): void;
234
+ /**
235
+ * Hook for Core extensions to allow them to update their own configuration before updating all of the plugins.
236
+ * @param updateCtx - The plugin update context
237
+ * @param updateState - The Update State
238
+ * @returns boolean - True means the extension class will call updateState otherwise the Core will
239
+ */
240
+ protected _updateHook?(updateCtx: IProcessTelemetryUpdateContext, updateState: ITelemetryUpdateState): void | boolean;
166
241
  }
167
242
 
168
243
  /**
@@ -171,6 +246,13 @@ declare namespace ApplicationInsights {
171
246
  * implementation so that new default implementations can be added without breaking all plugins.
172
247
  */
173
248
  abstract class BaseTelemetryPlugin implements ITelemetryPlugin {
249
+ identifier: string;
250
+ version?: string;
251
+ /**
252
+ * Holds the core instance that was used during initialization
253
+ */
254
+ core: IAppInsightsCore;
255
+ priority: number;
174
256
  /**
175
257
  * Call back for telemetry processing before it it is sent
176
258
  * @param env - This is the current event being reported
@@ -192,13 +274,6 @@ declare namespace ApplicationInsights {
192
274
  * Returns whether the plugin has been initialized
193
275
  */
194
276
  isInitialized: () => boolean;
195
- identifier: string;
196
- version?: string;
197
- /**
198
- * Holds the core instance that was used during initialization
199
- */
200
- core: IAppInsightsCore;
201
- priority: number;
202
277
  /**
203
278
  * Helper to return the current IProcessTelemetryContext, if the passed argument exists this just
204
279
  * returns that value (helps with minification for callers), otherwise it will return the configured
@@ -211,12 +286,51 @@ declare namespace ApplicationInsights {
211
286
  */
212
287
  protected setInitialized: (isInitialized: boolean) => void;
213
288
  /**
214
- * Internal helper to initialize the instance
289
+ * Teardown / Unload hook to allow implementations to perform some additional unload operations before the BaseTelemetryPlugin
290
+ * finishes it's removal.
291
+ * @param unloadCtx - This is the context that should be used during unloading.
292
+ * @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.
293
+ * @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.
294
+ * @returns boolean - true if the plugin has or will call asyncCallback, this allows the plugin to perform any asynchronous operations.
215
295
  */
216
- private _baseTelInit;
296
+ protected _doTeardown?: (unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState, asyncCallback?: () => void) => void | boolean;
297
+ /**
298
+ * Extension hook to allow implementations to perform some additional update operations before the BaseTelemetryPlugin finishes it's removal
299
+ * @param updateCtx - This is the context that should be used during updating.
300
+ * @param updateState - The details / state of the update process, it holds details like the current and previous configuration.
301
+ * @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.
302
+ * @returns boolean - true if the plugin has or will call asyncCallback, this allows the plugin to perform any asynchronous operations.
303
+ */
304
+ protected _doUpdate?: (updateCtx?: IProcessTelemetryUpdateContext, updateState?: ITelemetryUpdateState, asyncCallback?: () => void) => void | boolean;
217
305
  constructor();
218
306
  initialize(config: IConfiguration, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?: ITelemetryPluginChain): void;
307
+ /**
308
+ * Tear down the plugin and remove any hooked value, the plugin should be removed so that it is no longer initialized and
309
+ * therefore could be re-initialized after being torn down. The plugin should ensure that once this has been called any further
310
+ * processTelemetry calls are ignored and it just calls the processNext() with the provided context.
311
+ * @param unloadCtx - This is the context that should be used during unloading.
312
+ * @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.
313
+ * @returns boolean - true if the plugin has or will call processNext(), this for backward compatibility as previously teardown was synchronous and returned nothing.
314
+ */
315
+ teardown(unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState): void | boolean;
219
316
  abstract processTelemetry(env: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
317
+ /**
318
+ * The the plugin should re-evaluate configuration and update any cached configuration settings.
319
+ * @param updateCtx - This is the context that should be used during updating.
320
+ * @param updateState - The details / state of the update process, it holds details like the current and previous configuration.
321
+ * @returns boolean - true if the plugin has or will call updateCtx.processNext(), this allows the plugin to perform any asynchronous operations.
322
+ */
323
+ update(updateCtx: IProcessTelemetryUpdateContext, updateState: ITelemetryUpdateState): void | boolean;
324
+ /**
325
+ * Add an unload handler that will be called when the SDK is being unloaded
326
+ * @param handler - the handler
327
+ */
328
+ protected _addUnloadCb(handler: UnloadHandler): void;
329
+ /**
330
+ * Add this hook so that it is automatically removed during unloading
331
+ * @param hooks - The single hook or an array of IInstrumentHook objects
332
+ */
333
+ protected _addHook(hooks: IInstrumentHook | IInstrumentHook[]): void;
220
334
  }
221
335
 
222
336
  /**
@@ -242,6 +356,29 @@ declare namespace ApplicationInsights {
242
356
 
243
357
  function createCookieMgr(rootConfig?: IConfiguration, logger?: IDiagnosticLogger): ICookieMgr;
244
358
 
359
+ /**
360
+ * Create an enum style object which has both the key => value and value => key mappings
361
+ * @param values - The values to populate on the new object
362
+ * @returns
363
+ */
364
+ function createEnumStyle<T>(values: T): T;
365
+
366
+ /**
367
+ * Creates a new Telemetry Item context with the current config, core and plugin execution chain
368
+ * @param plugins - The plugin instances that will be executed
369
+ * @param config - The current config
370
+ * @param core - The current core instance
371
+ * @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
372
+ */
373
+ function createProcessTelemetryContext(telemetryChain: ITelemetryPluginChain | null, config: IConfiguration, core: IAppInsightsCore, startAt?: IPlugin): IProcessTelemetryContext;
374
+
375
+ function createUniqueNamespace(name: string, includeVersion?: boolean): string;
376
+
377
+ function createUnloadHandlerContainer(): {
378
+ add: (handler: UnloadHandler) => void;
379
+ run: (unloadCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
380
+ };
381
+
245
382
  /**
246
383
  * 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)
247
384
  * https://caniuse.com/#search=Date.now
@@ -258,8 +395,11 @@ declare namespace ApplicationInsights {
258
395
  /**
259
396
  * Removes an event handler for the specified event
260
397
  * @param Object to remove the event from
261
- * @param eventNameWithoutOn {string} - The name of the event
262
- * @param handlerRef {any} - The callback function that needs to be executed for the given event
398
+ * @param eventNameWithoutOn {string} - The name of the event, with optional namespaces or just the namespaces,
399
+ * such as "click", "click.mynamespace" or ".mynamespace"
400
+ * @param handlerRef {any} - The callback function that needs to be removed from the given event, when using a
401
+ * namespace (with or without a qualifying event) this may be null to remove all previously attached event handlers
402
+ * otherwise this will only remove events with this specific handler.
263
403
  * @param useCapture [Optional] Defaults to false
264
404
  */
265
405
  function detachEvent(obj: any, eventNameWithoutOn: string, handlerRef: any, useCapture?: boolean): void;
@@ -340,8 +480,131 @@ declare namespace ApplicationInsights {
340
480
  */
341
481
  function dumpObj(object: any): string;
342
482
 
483
+ const enum _eInternalMessageId {
484
+ BrowserDoesNotSupportLocalStorage = 0,
485
+ BrowserCannotReadLocalStorage = 1,
486
+ BrowserCannotReadSessionStorage = 2,
487
+ BrowserCannotWriteLocalStorage = 3,
488
+ BrowserCannotWriteSessionStorage = 4,
489
+ BrowserFailedRemovalFromLocalStorage = 5,
490
+ BrowserFailedRemovalFromSessionStorage = 6,
491
+ CannotSendEmptyTelemetry = 7,
492
+ ClientPerformanceMathError = 8,
493
+ ErrorParsingAISessionCookie = 9,
494
+ ErrorPVCalc = 10,
495
+ ExceptionWhileLoggingError = 11,
496
+ FailedAddingTelemetryToBuffer = 12,
497
+ FailedMonitorAjaxAbort = 13,
498
+ FailedMonitorAjaxDur = 14,
499
+ FailedMonitorAjaxOpen = 15,
500
+ FailedMonitorAjaxRSC = 16,
501
+ FailedMonitorAjaxSend = 17,
502
+ FailedMonitorAjaxGetCorrelationHeader = 18,
503
+ FailedToAddHandlerForOnBeforeUnload = 19,
504
+ FailedToSendQueuedTelemetry = 20,
505
+ FailedToReportDataLoss = 21,
506
+ FlushFailed = 22,
507
+ MessageLimitPerPVExceeded = 23,
508
+ MissingRequiredFieldSpecification = 24,
509
+ NavigationTimingNotSupported = 25,
510
+ OnError = 26,
511
+ SessionRenewalDateIsZero = 27,
512
+ SenderNotInitialized = 28,
513
+ StartTrackEventFailed = 29,
514
+ StopTrackEventFailed = 30,
515
+ StartTrackFailed = 31,
516
+ StopTrackFailed = 32,
517
+ TelemetrySampledAndNotSent = 33,
518
+ TrackEventFailed = 34,
519
+ TrackExceptionFailed = 35,
520
+ TrackMetricFailed = 36,
521
+ TrackPVFailed = 37,
522
+ TrackPVFailedCalc = 38,
523
+ TrackTraceFailed = 39,
524
+ TransmissionFailed = 40,
525
+ FailedToSetStorageBuffer = 41,
526
+ FailedToRestoreStorageBuffer = 42,
527
+ InvalidBackendResponse = 43,
528
+ FailedToFixDepricatedValues = 44,
529
+ InvalidDurationValue = 45,
530
+ TelemetryEnvelopeInvalid = 46,
531
+ CreateEnvelopeError = 47,
532
+ CannotSerializeObject = 48,
533
+ CannotSerializeObjectNonSerializable = 49,
534
+ CircularReferenceDetected = 50,
535
+ ClearAuthContextFailed = 51,
536
+ ExceptionTruncated = 52,
537
+ IllegalCharsInName = 53,
538
+ ItemNotInArray = 54,
539
+ MaxAjaxPerPVExceeded = 55,
540
+ MessageTruncated = 56,
541
+ NameTooLong = 57,
542
+ SampleRateOutOfRange = 58,
543
+ SetAuthContextFailed = 59,
544
+ SetAuthContextFailedAccountName = 60,
545
+ StringValueTooLong = 61,
546
+ StartCalledMoreThanOnce = 62,
547
+ StopCalledWithoutStart = 63,
548
+ TelemetryInitializerFailed = 64,
549
+ TrackArgumentsNotSpecified = 65,
550
+ UrlTooLong = 66,
551
+ SessionStorageBufferFull = 67,
552
+ CannotAccessCookie = 68,
553
+ IdTooLong = 69,
554
+ InvalidEvent = 70,
555
+ FailedMonitorAjaxSetRequestHeader = 71,
556
+ SendBrowserInfoOnUserInit = 72,
557
+ PluginException = 73,
558
+ NotificationException = 74,
559
+ SnippetScriptLoadFailure = 99,
560
+ InvalidInstrumentationKey = 100,
561
+ CannotParseAiBlobValue = 101,
562
+ InvalidContentBlob = 102,
563
+ TrackPageActionEventFailed = 103,
564
+ FailedAddingCustomDefinedRequestContext = 104,
565
+ InMemoryStorageBufferFull = 105
566
+ }
567
+
568
+ const enum eLoggingSeverity {
569
+ /**
570
+ * Error will be sent as internal telemetry
571
+ */
572
+ CRITICAL = 1,
573
+ /**
574
+ * Error will NOT be sent as internal telemetry, and will only be shown in browser console
575
+ */
576
+ WARNING = 2
577
+ }
578
+
343
579
  const EventHelper: IEventHelper;
344
580
 
581
+ /**
582
+ * Removes an event handler for the specified event
583
+ * @param Object to remove the event from
584
+ * @param eventName {string} - The name of the event, with optional namespaces or just the namespaces,
585
+ * such as "click", "click.mynamespace" or ".mynamespace"
586
+ * @param handlerRef {any} - The callback function that needs to be removed from the given event, when using a
587
+ * namespace (with or without a qualifying event) this may be null to remove all previously attached event handlers
588
+ * otherwise this will only remove events with this specific handler.
589
+ * @param evtNamespace - [Optional] Additional namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace,
590
+ * if the eventName also includes a namespace the namespace(s) are merged into a single namespace
591
+ * @param useCapture [Optional] Defaults to false
592
+ */
593
+ function eventOff<T>(target: T, eventName: string, handlerRef: any, evtNamespace?: string | string[] | null, useCapture?: boolean): void;
594
+
595
+ /**
596
+ * Binds the specified function to an event, so that the function gets called whenever the event fires on the object
597
+ * @param obj Object to add the event too.
598
+ * @param eventName String that specifies any of the standard DHTML Events without "on" prefix, if may also include an optional (dot "." prefixed)
599
+ * namespaces "click" "click.mynamespace" in addition to specific namespaces.
600
+ * @param handlerRef Pointer that specifies the function to call when event fires
601
+ * @param evtNamespace - [Optional] Additional namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace,
602
+ * if the eventName also includes a namespace the namespace(s) are merged into a single namespace
603
+ * @param useCapture [Optional] Defaults to false
604
+ * @returns True if the function was bound successfully to the event, otherwise false
605
+ */
606
+ function eventOn<T>(target: T, eventName: string, handlerRef: any, evtNamespace?: string | string[] | null, useCapture?: boolean): boolean;
607
+
345
608
  /**
346
609
  * The EventsDiscardedReason enumeration contains a set of values that specify the reason for discarding an event.
347
610
  */
@@ -411,6 +674,12 @@ declare namespace ApplicationInsights {
411
674
  */
412
675
  function getExceptionName(object: any): string;
413
676
 
677
+ const enum GetExtCfgMergeType {
678
+ None = 0,
679
+ MergeDefaultOnly = 1,
680
+ MergeDefaultFromRootOrDefault = 2
681
+ }
682
+
414
683
  /**
415
684
  * Get the current global performance manager that will be used with no performance manager is supplied.
416
685
  * @returns - The current default manager
@@ -569,12 +838,123 @@ declare namespace ApplicationInsights {
569
838
  * @param {INotificationListener} listener - INotificationListener to remove.
570
839
  */
571
840
  removeNotificationListener?(listener: INotificationListener): void;
841
+ /**
842
+ * Add a telemetry processor to decorate or drop telemetry events.
843
+ * @param telemetryInitializer - The Telemetry Initializer function
844
+ * @returns - A ITelemetryInitializerHandler to enable the initializer to be removed
845
+ */
846
+ addTelemetryInitializer(telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler | void;
572
847
  pollInternalLogs?(eventName?: string): number;
573
848
  stopPollingInternalLogs?(): void;
574
849
  /**
575
850
  * Return a new instance of the IProcessTelemetryContext for processing events
576
851
  */
577
852
  getProcessTelContext(): IProcessTelemetryContext;
853
+ /**
854
+ * Unload and Tear down the SDK and any initialized plugins, after calling this the SDK will be considered
855
+ * to be un-initialized and non-operational, re-initializing the SDK should only be attempted if the previous
856
+ * unload call return `true` stating that all plugins reported that they also unloaded, the recommended
857
+ * approach is to create a new instance and initialize that instance.
858
+ * This is due to possible unexpected side effects caused by plugins not supporting unload / teardown, unable
859
+ * to successfully remove any global references or they may just be completing the unload process asynchronously.
860
+ * @param isAsync - Can the unload be performed asynchronously (default)
861
+ * @param unloadComplete - An optional callback that will be called once the unload has completed
862
+ * @param cbTimeout - An optional timeout to wait for any flush operations to complete before proceeding with the unload. Defaults to 5 seconds.
863
+ */
864
+ unload(isAsync?: boolean, unloadComplete?: (unloadState: ITelemetryUnloadState) => void, cbTimeout?: number): void;
865
+ /**
866
+ * Find and return the (first) plugin with the specified identifier if present
867
+ * @param pluginIdentifier
868
+ */
869
+ getPlugin<T extends IPlugin = IPlugin>(pluginIdentifier: string): ILoadedPlugin<T>;
870
+ /**
871
+ * Add a new plugin to the installation
872
+ * @param plugin - The new plugin to add
873
+ * @param replaceExisting - should any existing plugin be replaced, default is false
874
+ * @param doAsync - Should the add be performed asynchronously
875
+ * @param addCb - [Optional] callback to call after the plugin has been added
876
+ */
877
+ addPlugin<T extends IPlugin = ITelemetryPlugin>(plugin: T, replaceExisting?: boolean, doAsync?: boolean, addCb?: (added?: boolean) => void): void;
878
+ /**
879
+ * Returns the unique event namespace that should be used when registering events
880
+ */
881
+ evtNamespace(): string;
882
+ /**
883
+ * Add a handler that will be called when the SDK is being unloaded
884
+ * @param handler - the handler
885
+ */
886
+ addUnloadCb(handler: UnloadHandler): void;
887
+ /**
888
+ * Flush and send any batched / cached data immediately
889
+ * @param async - send data asynchronously when true (defaults to true)
890
+ * @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.
891
+ * If the caller doesn't return true the caller should assume that it may never be called.
892
+ * @param sendReason - specify the reason that you are calling "flush" defaults to ManualFlush (1) if not specified
893
+ * @param cbTimeout - An optional timeout to wait for any flush operations to complete before proceeding with the unload. Defaults to 5 seconds.
894
+ * @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
895
+ */
896
+ flush(isAsync?: boolean, callBack?: (flushComplete?: boolean) => void, sendReason?: SendRequestReason, cbTimeout?: number): boolean | void;
897
+ }
898
+
899
+ interface IBaseProcessingContext {
900
+ /**
901
+ * The current core instance for the request
902
+ */
903
+ core: () => IAppInsightsCore;
904
+ /**
905
+ * THe current diagnostic logger for the request
906
+ */
907
+ diagLog: () => IDiagnosticLogger;
908
+ /**
909
+ * Gets the current core config instance
910
+ */
911
+ getCfg: () => IConfiguration;
912
+ /**
913
+ * Gets the named extension config
914
+ */
915
+ getExtCfg: <T>(identifier: string, defaultValue?: T | any, mergeDefault?: GetExtCfgMergeType) => T;
916
+ /**
917
+ * Gets the named config from either the named identifier extension or core config if neither exist then the
918
+ * default value is returned
919
+ * @param identifier The named extension identifier
920
+ * @param field The config field name
921
+ * @param defaultValue The default value to return if no defined config exists
922
+ */
923
+ getConfig: (identifier: string, field: string, defaultValue?: number | string | boolean | string[] | RegExp[] | Function) => number | string | boolean | string[] | RegExp[] | Function;
924
+ /**
925
+ * Helper to allow plugins to check and possibly shortcut executing code only
926
+ * required if there is a nextPlugin
927
+ */
928
+ hasNext: () => boolean;
929
+ /**
930
+ * Returns the next configured plugin proxy
931
+ */
932
+ getNext: () => ITelemetryPluginChain;
933
+ /**
934
+ * Helper to set the next plugin proxy
935
+ */
936
+ setNext: (nextCtx: ITelemetryPluginChain) => void;
937
+ /**
938
+ * Synchronously iterate over the context chain running the callback for each plugin, once
939
+ * every plugin has been executed via the callback, any associated onComplete will be called.
940
+ * @param callback - The function call for each plugin in the context chain
941
+ */
942
+ iterate: <T extends ITelemetryPlugin = ITelemetryPlugin>(callback: (plugin: T) => void) => void;
943
+ /**
944
+ * Set the function to call when the current chain has executed all processNext or unloadNext items.
945
+ * @param onComplete - The onComplete to call
946
+ * @param that - The "this" value to use for the onComplete call, if not provided or undefined defaults to the current context
947
+ * @param args - Any additional arguments to pass to the onComplete function
948
+ */
949
+ onComplete: (onComplete: () => void, that?: any, ...args: any[]) => void;
950
+ /**
951
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
952
+ * @param plugins - The execution order to process the plugins, if null or not supplied
953
+ * then the current execution order will be copied.
954
+ * @param startAt - The plugin to start processing from, if missing from the execution
955
+ * order then the next plugin will be NOT set.
956
+ */
957
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IBaseProcessingContext;
578
958
  }
579
959
 
580
960
  /**
@@ -590,15 +970,23 @@ declare namespace ApplicationInsights {
590
970
  */
591
971
  resume(): void;
592
972
  /**
593
- * Tear down transmission pipeline
973
+ * Tear down the plugin and remove any hooked value, the plugin should be removed so that it is no longer initialized and
974
+ * therefore could be re-initialized after being torn down. The plugin should ensure that once this has been called any further
975
+ * processTelemetry calls are ignored and it just calls the processNext() with the provided context.
976
+ * @param unloadCtx - This is the context that should be used during unloading.
977
+ * @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.
978
+ * @returns boolean - true if the plugin has or will call processNext(), this for backward compatibility as previously teardown was synchronous and returned nothing.
594
979
  */
595
- teardown(): void;
980
+ teardown: (unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState) => void | boolean;
596
981
  /**
597
982
  * Flush to send data immediately; channel should default to sending data asynchronously
598
- * @param async: send data asynchronously when true
599
- * @param callBack: if specified, notify caller when send is complete
983
+ * @param async - send data asynchronously when true
984
+ * @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.
985
+ * If the caller doesn't return true the caller should assume that it may never be called.
986
+ * @param sendReason - specify the reason that you are calling "flush" defaults to ManualFlush (1) if not specified
987
+ * @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
600
988
  */
601
- flush(async: boolean, callBack?: () => void): void;
989
+ flush(async: boolean, callBack?: (flushComplete?: boolean) => void, sendReason?: SendRequestReason): boolean | void;
602
990
  }
603
991
 
604
992
  /**
@@ -958,7 +1346,7 @@ declare namespace ApplicationInsights {
958
1346
  * @param callback {any} - The callback function that needs to be executed for the given event
959
1347
  * @return {boolean} - true if the handler was successfully added
960
1348
  */
961
- addEventHandler: (eventName: string, callback: any) => boolean;
1349
+ addEventHandler: (eventName: string, callback: any, evtNamespace?: string | string[]) => boolean;
962
1350
  /**
963
1351
  * 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)
964
1352
  * https://caniuse.com/#search=Date.now
@@ -1143,6 +1531,10 @@ declare namespace ApplicationInsights {
1143
1531
  * The error (exception) which occurred while executing the original method
1144
1532
  */
1145
1533
  err?: Error;
1534
+ /**
1535
+ * The Event object from (window.event) at the start of the original call
1536
+ */
1537
+ evt?: Event;
1146
1538
  }
1147
1539
 
1148
1540
  /**
@@ -1169,6 +1561,11 @@ declare namespace ApplicationInsights {
1169
1561
  * You must always supply the error callback
1170
1562
  */
1171
1563
  interface IInstrumentHooksCallbacks {
1564
+ /**
1565
+ * [Optional] Namespace details (same as the namespace used for events), useful for debugging and testing to
1566
+ * identify the source of the instrumented hooks
1567
+ */
1568
+ ns?: string | string[];
1172
1569
  /**
1173
1570
  * The hook callback to call before the original function is called
1174
1571
  */
@@ -1188,6 +1585,24 @@ declare namespace ApplicationInsights {
1188
1585
  fnErr?: InstrumentorHooksCallback;
1189
1586
  }
1190
1587
 
1588
+ interface ILoadedPlugin<T extends IPlugin> {
1589
+ plugin: T;
1590
+ /**
1591
+ * Identifies whether the plugin is enabled and can process events. This is slightly different from isInitialized as the plugin may be initialized but disabled
1592
+ * via the setEnabled() or it may be a shared plugin which has had it's teardown function called from another instance..
1593
+ * @returns boolean = true if the plugin is in a state where it is operational.
1594
+ */
1595
+ isEnabled: () => boolean;
1596
+ /**
1597
+ * You can optionally enable / disable a plugin from processing events.
1598
+ * Setting enabled to true will not necessarily cause the `isEnabled()` to also return true
1599
+ * as the plugin must also have been successfully initialized and not had it's `teardown` method called
1600
+ * (unless it's also been re-initialized)
1601
+ */
1602
+ setEnabled: (isEnabled: boolean) => void;
1603
+ remove: (isAsync?: boolean, removeCb?: (removed?: boolean) => void) => void;
1604
+ }
1605
+
1191
1606
  /**
1192
1607
  * Initialize the queue of plugins
1193
1608
  * @param plugins - The array of plugins to initialize and setting of the next plugin
@@ -1195,7 +1610,7 @@ declare namespace ApplicationInsights {
1195
1610
  * @param core THe current core instance
1196
1611
  * @param extensions The extensions
1197
1612
  */
1198
- function initializePlugins(processContext: ProcessTelemetryContext, extensions: IPlugin[]): void;
1613
+ function initializePlugins(processContext: IProcessTelemetryContext, extensions: IPlugin[]): void;
1199
1614
 
1200
1615
  /**
1201
1616
  * An interface used for the notification listener.
@@ -1404,7 +1819,7 @@ declare namespace ApplicationInsights {
1404
1819
  InMemoryStorageBufferFull: number;
1405
1820
  };
1406
1821
 
1407
- type _InternalMessageId = number | typeof _InternalMessageId;
1822
+ type _InternalMessageId = number | _eInternalMessageId;
1408
1823
 
1409
1824
  /**
1410
1825
  * This interface identifies the details of an internal performance event - it does not represent an outgoing reported event
@@ -1525,10 +1940,14 @@ declare namespace ApplicationInsights {
1525
1940
  */
1526
1941
  isInitialized?: () => boolean;
1527
1942
  /**
1528
- * Tear down the plugin and remove any hooked value, the plugin should remove that it is no longer initialized and
1529
- * therefore can be re-initialized after being torn down.
1943
+ * Tear down the plugin and remove any hooked value, the plugin should be removed so that it is no longer initialized and
1944
+ * therefore could be re-initialized after being torn down. The plugin should ensure that once this has been called any further
1945
+ * processTelemetry calls are ignored and it just calls the processNext() with the provided context.
1946
+ * @param unloadCtx - This is the context that should be used during unloading.
1947
+ * @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.
1948
+ * @returns boolean - true if the plugin has or will call processNext(), this for backward compatibility as previously teardown was synchronous and returned nothing.
1530
1949
  */
1531
- teardown?: () => void;
1950
+ teardown?: (unloadCtx: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState) => void | boolean;
1532
1951
  /**
1533
1952
  * Extension name
1534
1953
  */
@@ -1543,61 +1962,73 @@ declare namespace ApplicationInsights {
1543
1962
  * The current context for the current call to processTelemetry(), used to support sharing the same plugin instance
1544
1963
  * between multiple AppInsights instances
1545
1964
  */
1546
- interface IProcessTelemetryContext {
1547
- /**
1548
- * The current core instance for the request
1549
- */
1550
- core: () => IAppInsightsCore;
1551
- /**
1552
- * THe current diagnostic logger for the request
1553
- */
1554
- diagLog: () => IDiagnosticLogger;
1965
+ interface IProcessTelemetryContext extends IBaseProcessingContext {
1555
1966
  /**
1556
- * Gets the current core config instance
1557
- */
1558
- getCfg: () => IConfiguration;
1559
- /**
1560
- * Gets the named extension config
1561
- */
1562
- getExtCfg: <T>(identifier: string, defaultValue?: T | any) => T;
1563
- /**
1564
- * Gets the named config from either the named identifier extension or core config if neither exist then the
1565
- * default value is returned
1566
- * @param identifier The named extension identifier
1567
- * @param field The config field name
1568
- * @param defaultValue The default value to return if no defined config exists
1967
+ * Call back for telemetry processing before it it is sent
1968
+ * @param env - This is the current event being reported
1969
+ * @returns boolean (true) if there is no more plugins to process otherwise false or undefined (void)
1569
1970
  */
1570
- getConfig: (identifier: string, field: string, defaultValue?: number | string | boolean) => number | string | boolean;
1971
+ processNext: (env: ITelemetryItem) => boolean | void;
1571
1972
  /**
1572
- * Helper to allow plugins to check and possibly shortcut executing code only
1573
- * required if there is a nextPlugin
1973
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
1974
+ * @param plugins - The execution order to process the plugins, if null or not supplied
1975
+ * then the current execution order will be copied.
1976
+ * @param startAt - The plugin to start processing from, if missing from the execution
1977
+ * order then the next plugin will be NOT set.
1574
1978
  */
1575
- hasNext: () => boolean;
1979
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryContext;
1980
+ }
1981
+
1982
+ /**
1983
+ * The current context for the current call to teardown() implementations, used to support when plugins are being removed
1984
+ * or the SDK is being unloaded.
1985
+ */
1986
+ interface IProcessTelemetryUnloadContext extends IBaseProcessingContext {
1576
1987
  /**
1577
- * Returns the next configured plugin proxy
1988
+ * This Plugin has finished unloading, so unload the next one
1989
+ * @param uploadState - The state of the unload process
1990
+ * @returns boolean (true) if there is no more plugins to process otherwise false or undefined (void)
1578
1991
  */
1579
- getNext: () => ITelemetryPluginChain;
1992
+ processNext: (unloadState: ITelemetryUnloadState) => boolean | void;
1580
1993
  /**
1581
- * Helper to set the next plugin proxy
1994
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
1995
+ * @param plugins - The execution order to process the plugins, if null or not supplied
1996
+ * then the current execution order will be copied.
1997
+ * @param startAt - The plugin to start processing from, if missing from the execution
1998
+ * order then the next plugin will be NOT set.
1582
1999
  */
1583
- setNext: (nextCtx: ITelemetryPluginChain) => void;
2000
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryUnloadContext;
2001
+ }
2002
+
2003
+ /**
2004
+ * The current context for the current call to the plugin update() implementations, used to support the notifications
2005
+ * for when plugins are added, removed or the configuration was changed.
2006
+ */
2007
+ interface IProcessTelemetryUpdateContext extends IBaseProcessingContext {
1584
2008
  /**
1585
- * Call back for telemetry processing before it it is sent
1586
- * @param env - This is the current event being reported
2009
+ * This Plugin has finished unloading, so unload the next one
2010
+ * @param updateState - The update State
2011
+ * @returns boolean (true) if there is no more plugins to process otherwise false or undefined (void)
1587
2012
  */
1588
- processNext: (env: ITelemetryItem) => void;
2013
+ processNext: (updateState: ITelemetryUpdateState) => boolean | void;
1589
2014
  /**
1590
- * Create a new context using the core and config from the current instance
2015
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
1591
2016
  * @param plugins - The execution order to process the plugins, if null or not supplied
1592
2017
  * then the current execution order will be copied.
1593
2018
  * @param startAt - The plugin to start processing from, if missing from the execution
1594
2019
  * order then the next plugin will be NOT set.
1595
2020
  */
1596
- createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryContext;
2021
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryUpdateContext;
2022
+ }
2023
+
2024
+ interface _IRegisteredEvents {
2025
+ name: string;
2026
+ handler: any;
1597
2027
  }
1598
2028
 
1599
2029
  /**
1600
- * Check if an object is of type Array
2030
+ * Check if an object is of type Array with optional generic T, the generic type is not validated
2031
+ * and exists to help with TypeScript validation only.
1601
2032
  */
1602
2033
  let isArray: <T = any>(obj: any) => obj is Array<T>;
1603
2034
 
@@ -1638,13 +2069,13 @@ declare namespace ApplicationInsights {
1638
2069
  */
1639
2070
  function isIE(): boolean;
1640
2071
 
1641
- function isNotNullOrUndefined(value: any): boolean;
2072
+ function isNotNullOrUndefined<T>(value: T): value is T;
1642
2073
 
1643
2074
  function isNotTruthy(value: any): boolean;
1644
2075
 
1645
- function isNotUndefined(value: any): boolean;
2076
+ function isNotUndefined<T>(value: T): value is T;
1646
2077
 
1647
- function isNullOrUndefined(value: any): boolean;
2078
+ function isNullOrUndefined(value: any): value is null | undefined;
1648
2079
 
1649
2080
  /**
1650
2081
  * Checks if the type of value is a number.
@@ -1653,7 +2084,7 @@ declare namespace ApplicationInsights {
1653
2084
  */
1654
2085
  function isNumber(value: any): value is number;
1655
2086
 
1656
- function isObject(value: any): boolean;
2087
+ function isObject<T>(value: T): value is T;
1657
2088
 
1658
2089
  /**
1659
2090
  * Returns whether the environment is reporting that we are running in a React Native Environment
@@ -1681,7 +2112,7 @@ declare namespace ApplicationInsights {
1681
2112
 
1682
2113
  function isTypeof(value: any, theType: string): boolean;
1683
2114
 
1684
- function isUndefined(value: any): boolean;
2115
+ function isUndefined(value: any): value is undefined;
1685
2116
 
1686
2117
  /**
1687
2118
  * Checks if XMLHttpRequest is supported
@@ -1689,6 +2120,19 @@ declare namespace ApplicationInsights {
1689
2120
  */
1690
2121
  function isXhrSupported(): boolean;
1691
2122
 
2123
+ interface ITelemetryInitializerContainer {
2124
+ /**
2125
+ * Add a telemetry processor to decorate or drop telemetry events.
2126
+ * @param telemetryInitializer - The Telemetry Initializer function
2127
+ * @returns - A ITelemetryInitializerHandler to enable the initializer to be removed
2128
+ */
2129
+ addTelemetryInitializer(telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler | void;
2130
+ }
2131
+
2132
+ interface ITelemetryInitializerHandler {
2133
+ remove(): void;
2134
+ }
2135
+
1692
2136
  /**
1693
2137
  * Telemety item supported in Core
1694
2138
  */
@@ -1738,15 +2182,7 @@ declare namespace ApplicationInsights {
1738
2182
  /**
1739
2183
  * Configuration provided to SDK core
1740
2184
  */
1741
- interface ITelemetryPlugin extends IPlugin {
1742
- /**
1743
- * Call back for telemetry processing before it it is sent
1744
- * @param env - This is the current event being reported
1745
- * @param itemCtx - This is the context for the current request, ITelemetryPlugin instances
1746
- * can optionally use this to access the current core instance or define / pass additional information
1747
- * to later plugins (vs appending items to the telemetry item)
1748
- */
1749
- processTelemetry: (env: ITelemetryItem, itemCtx?: IProcessTelemetryContext) => void;
2185
+ interface ITelemetryPlugin extends ITelemetryProcessor, IPlugin {
1750
2186
  /**
1751
2187
  * Set next extension for telemetry processing, this is not optional as plugins should use the
1752
2188
  * processNext() function of the passed IProcessTelemetryContext instead. It is being kept for
@@ -1762,7 +2198,7 @@ declare namespace ApplicationInsights {
1762
2198
  /**
1763
2199
  * Configuration provided to SDK core
1764
2200
  */
1765
- interface ITelemetryPluginChain {
2201
+ interface ITelemetryPluginChain extends ITelemetryProcessor {
1766
2202
  /**
1767
2203
  * Returns the underlying plugin that is being proxied for the processTelemetry call
1768
2204
  */
@@ -1771,6 +2207,16 @@ declare namespace ApplicationInsights {
1771
2207
  * Returns the next plugin
1772
2208
  */
1773
2209
  getNext: () => ITelemetryPluginChain;
2210
+ /**
2211
+ * This plugin is being unloaded and should remove any hooked events and cleanup any global/scoped values, after this
2212
+ * call the plugin will be removed from the telemetry processing chain and will no longer receive any events..
2213
+ * @param unloadCtx - The unload context to use for this call.
2214
+ * @param unloadState - The details of the unload operation
2215
+ */
2216
+ unload?: (unloadCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
2217
+ }
2218
+
2219
+ interface ITelemetryProcessor {
1774
2220
  /**
1775
2221
  * Call back for telemetry processing before it it is sent
1776
2222
  * @param env - This is the current event being reported
@@ -1778,7 +2224,60 @@ declare namespace ApplicationInsights {
1778
2224
  * can optionally use this to access the current core instance or define / pass additional information
1779
2225
  * to later plugins (vs appending items to the telemetry item)
1780
2226
  */
1781
- processTelemetry: (env: ITelemetryItem, itemCtx: IProcessTelemetryContext) => void;
2227
+ processTelemetry: (env: ITelemetryItem, itemCtx?: IProcessTelemetryContext) => void;
2228
+ /**
2229
+ * The the plugin should re-evaluate configuration and update any cached configuration settings or
2230
+ * plugins. If implemented this method will be called whenever a plugin is added or removed and if
2231
+ * the configuration has bee updated.
2232
+ * @param updateCtx - This is the context that should be used during updating.
2233
+ * @param updateState - The details / state of the update process, it holds details like the current and previous configuration.
2234
+ * @returns boolean - true if the plugin has or will call updateCtx.processNext(), this allows the plugin to perform any asynchronous operations.
2235
+ */
2236
+ update?: (updateCtx: IProcessTelemetryUpdateContext, updateState: ITelemetryUpdateState) => void | boolean;
2237
+ }
2238
+
2239
+ interface ITelemetryUnloadState {
2240
+ reason: TelemetryUnloadReason;
2241
+ isAsync: boolean;
2242
+ flushComplete?: boolean;
2243
+ }
2244
+
2245
+ interface ITelemetryUpdateState {
2246
+ /**
2247
+ * Identifies the reason for the update notification, this is a bitwise numeric value
2248
+ */
2249
+ reason: TelemetryUpdateReason;
2250
+ /**
2251
+ * If this is a configuration update this was the previous configuration that was used
2252
+ */
2253
+ /**
2254
+ * If this is a configuration update is the new configuration that is being used
2255
+ */
2256
+ /**
2257
+ * This holds a collection of plugins that have been added (if the reason identifies that one or more plugins have been added)
2258
+ */
2259
+ added?: IPlugin[];
2260
+ /**
2261
+ * This holds a collection of plugins that have been removed (if the reason identifies that one or more plugins have been removed)
2262
+ */
2263
+ removed?: IPlugin[];
2264
+ }
2265
+
2266
+ interface IUnloadableComponent {
2267
+ /**
2268
+ * Teardown / Unload hook to allow implementations to perform some additional unload operations before the BaseTelemetryPlugin
2269
+ * finishes it's removal.
2270
+ * @param unloadCtx - This is the context that should be used during unloading.
2271
+ * @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.
2272
+ * @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.
2273
+ * @returns boolean - true if the plugin has or will call asyncCallback, this allows the plugin to perform any asynchronous operations.
2274
+ */
2275
+ _doUnload?: (unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState, asyncCallback?: () => void) => void | boolean;
2276
+ }
2277
+
2278
+ interface IUnloadHandlerContainer {
2279
+ add: (handler: UnloadHandler) => void;
2280
+ run: (itemCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
1782
2281
  }
1783
2282
 
1784
2283
  /**
@@ -1793,16 +2292,14 @@ declare namespace ApplicationInsights {
1793
2292
  */
1794
2293
  function _legacyCookieMgr(config?: IConfiguration, logger?: IDiagnosticLogger): ICookieMgr;
1795
2294
 
1796
- enum LoggingSeverity {
1797
- /**
1798
- * Error will be sent as internal telemetry
1799
- */
1800
- CRITICAL = 1,
1801
- /**
1802
- * Error will NOT be sent as internal telemetry, and will only be shown in browser console
1803
- */
1804
- WARNING = 2
1805
- }
2295
+ const LoggingSeverity: {
2296
+ CRITICAL: number;
2297
+ WARNING: number;
2298
+ };
2299
+
2300
+ type LoggingSeverity = number | eLoggingSeverity;
2301
+
2302
+ function mergeEvtNamespace(theNamespace: string, namespaces?: string | string[] | null): string | string[];
1806
2303
 
1807
2304
  const MinChannelPriorty: number;
1808
2305
 
@@ -1894,13 +2391,27 @@ declare namespace ApplicationInsights {
1894
2391
  */
1895
2392
  function objDefineAccessors<T>(target: any, prop: string, getProp?: () => T, setProp?: (v: T) => void): boolean;
1896
2393
 
2394
+ /**
2395
+ * Pass in the objects to merge as arguments, this will only "merge" (extend) properties that are owned by the object.
2396
+ * It will NOT merge inherited or non-enumerable properties.
2397
+ * @param obj1 - object to merge. Set this argument to 'true' for a deep extend.
2398
+ * @param obj2 - object to merge.
2399
+ * @param obj3 - object to merge.
2400
+ * @param obj4 - object to merge.
2401
+ * @param obj5 - object to merge.
2402
+ * @returns The extended first object.
2403
+ */
2404
+ function objExtend<T2, T3, T4, T5, T6>(deepExtend?: boolean, obj2?: T2, obj3?: T3, obj4?: T4, obj5?: T5, obj6?: T6): T2 & T3 & T4 & T5 & T6;
2405
+
2406
+ 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;
2407
+
1897
2408
  /**
1898
2409
  * This is a helper function for the equivalent of arForEach(objKeys(target), callbackFn), this is a
1899
2410
  * performance optimization to avoid the creation of a new array for large objects
1900
2411
  * @param target The target object to find and process the keys
1901
2412
  * @param callbackfn The function to call with the details
1902
2413
  */
1903
- function objForEachKey(target: any, callbackfn: (name: string, value: any) => void): void;
2414
+ function objForEachKey<T = any>(target: T, callbackfn: (name: string, value: T[keyof T]) => void): void;
1904
2415
 
1905
2416
  const objFreeze: <T>(value: T) => T;
1906
2417
 
@@ -1914,6 +2425,8 @@ declare namespace ApplicationInsights {
1914
2425
 
1915
2426
  const objSeal: <T>(value: T) => T;
1916
2427
 
2428
+ function objToString(obj: any): any;
2429
+
1917
2430
  /**
1918
2431
  * A helper function to assist with JIT performance for objects that have properties added / removed dynamically
1919
2432
  * this is primarily for chromium based browsers and has limited effects on Firefox and none of IE. Only call this
@@ -1969,7 +2482,7 @@ declare namespace ApplicationInsights {
1969
2482
  * Defined as private so it can be visualized via the DebugPlugin
1970
2483
  */
1971
2484
  private ctx;
1972
- constructor(manager: INotificationManager);
2485
+ constructor(manager?: INotificationManager);
1973
2486
  /**
1974
2487
  * Create a new event and start timing, the manager may return null/undefined to indicate that it does not
1975
2488
  * want to monitor this source event.
@@ -2002,13 +2515,17 @@ declare namespace ApplicationInsights {
2002
2515
  */
2003
2516
  function perfNow(): number;
2004
2517
 
2518
+ /**
2519
+ * This class will be removed!
2520
+ * @deprecated use createProcessTelemetryContext() instead
2521
+ */
2005
2522
  class ProcessTelemetryContext implements IProcessTelemetryContext {
2006
2523
  /**
2007
2524
  * Gets the current core config instance
2008
2525
  */
2009
2526
  getCfg: () => IConfiguration;
2010
2527
  getExtCfg: <T>(identifier: string, defaultValue?: T | any) => T;
2011
- getConfig: (identifier: string, field: string, defaultValue?: number | string | boolean) => number | string | boolean;
2528
+ getConfig: (identifier: string, field: string, defaultValue?: number | string | boolean | string[] | RegExp[] | Function) => number | string | boolean | string[] | RegExp[] | Function;
2012
2529
  /**
2013
2530
  * Returns the IAppInsightsCore instance for the current request
2014
2531
  */
@@ -2036,19 +2553,34 @@ declare namespace ApplicationInsights {
2036
2553
  * @param itemCtx - This is the context for the current request, ITelemetryPlugin instances
2037
2554
  * can optionally use this to access the current core instance or define / pass additional information
2038
2555
  * to later plugins (vs appending items to the telemetry item)
2556
+ * @returns boolean (true) if there is no more plugins to process otherwise false or undefined (void)
2557
+ */
2558
+ processNext: (env: ITelemetryItem) => boolean | void;
2559
+ /**
2560
+ * Synchronously iterate over the context chain running the callback for each plugin, once
2561
+ * every plugin has been executed via the callback, any associated onComplete will be called.
2562
+ * @param callback - The function call for each plugin in the context chain
2039
2563
  */
2040
- processNext: (env: ITelemetryItem) => void;
2564
+ iterate: <T extends ITelemetryPlugin = ITelemetryPlugin>(callback: (plugin: T) => void) => void;
2041
2565
  /**
2042
2566
  * Create a new context using the core and config from the current instance
2567
+ * @param plugins - The execution order to process the plugins, if null or not supplied
2568
+ * then the current execution order will be copied.
2569
+ * @param startAt - The plugin to start processing from, if missing from the execution
2570
+ * order then the next plugin will be NOT set.
2043
2571
  */
2044
2572
  createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryContext;
2573
+ /**
2574
+ * Set the function to call when the current chain has executed all processNext or unloadNext items.
2575
+ */
2576
+ onComplete: (onComplete: () => void) => void;
2045
2577
  /**
2046
2578
  * Creates a new Telemetry Item context with the current config, core and plugin execution chain
2047
2579
  * @param plugins - The plugin instances that will be executed
2048
2580
  * @param config - The current config
2049
2581
  * @param core - The current core instance
2050
2582
  */
2051
- constructor(plugins: IPlugin[] | ITelemetryPluginChain, config: IConfiguration, core: IAppInsightsCore, startAt?: IPlugin);
2583
+ constructor(pluginChain: ITelemetryPluginChain, config: IConfiguration, core: IAppInsightsCore, startAt?: IPlugin);
2052
2584
  }
2053
2585
 
2054
2586
  /**
@@ -2065,9 +2597,19 @@ declare namespace ApplicationInsights {
2065
2597
  * @param target - The target object to be assigned with the source properties and functions
2066
2598
  * @param source - The source object which will be assigned / called by setting / calling the targets proxies
2067
2599
  * @param chkSet - An optional callback to determine whether a specific property/function should be proxied
2068
- * @memberof Initialization
2069
2600
  */
2070
- function proxyAssign(target: any, source: any, chkSet?: (name: string, isFunc?: boolean, source?: any, target?: any) => boolean): any;
2601
+ function proxyAssign<T, S>(target: T, source: S, chkSet?: (name: string, isFunc?: boolean, source?: S, target?: T) => boolean): T;
2602
+
2603
+ function proxyFunctionAs<T, S>(target: T, name: string, source: S | (() => S), theFunc: (keyof S), overwriteTarget?: boolean): void;
2604
+
2605
+ /**
2606
+ * Creates proxy functions on the target which internally will call the source version with all arguments passed to the target method.
2607
+ *
2608
+ * @param target - The target object to be assigned with the source properties and functions
2609
+ * @param source - The source object which will be assigned / called by setting / calling the targets proxies
2610
+ * @param functionsToProxy - An array of function names that will be proxied on the target
2611
+ */
2612
+ function proxyFunctions<T, S>(target: T, source: S | (() => S), functionsToProxy: (keyof S)[], overwriteTarget?: boolean): T;
2071
2613
 
2072
2614
  /**
2073
2615
  * generate a random 32-bit number (0x000000..0xFFFFFFFF) or (-0x80000000..0x7FFFFFFF), defaults un-unsigned.
@@ -2082,6 +2624,52 @@ declare namespace ApplicationInsights {
2082
2624
  */
2083
2625
  function randomValue(maxValue: number): number;
2084
2626
 
2627
+ /**
2628
+ * Trys to remove event handler(s) for the specified event/namespace to the window, body and document
2629
+ * @param eventName {string} - The name of the event, with optional namespaces or just the namespaces,
2630
+ * such as "click", "click.mynamespace" or ".mynamespace"
2631
+ * @param callback {any} - - The callback function that needs to be removed from the given event, when using a
2632
+ * namespace (with or without a qualifying event) this may be null to remove all previously attached event handlers
2633
+ * otherwise this will only remove events with this specific handler.
2634
+ * @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.
2635
+ */
2636
+ function removeEventHandler(eventName: string, callback: any, evtNamespace?: string | string[] | null): void;
2637
+
2638
+ /**
2639
+ * Remove the listener from the array of events
2640
+ * @param events An string array of event names to bind the listener to
2641
+ * @param listener The event callback to call when the event is triggered
2642
+ * @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.
2643
+ */
2644
+ function removeEventListeners(events: string[], listener: any, evtNamespace?: string | string[]): void;
2645
+
2646
+ /**
2647
+ * Removes the pageHide event listeners added by addPageHideEventListener, because the 'visibilitychange' uses
2648
+ * an internal proxy to detect the visibility state you SHOULD use a unique namespace when calling addPageHideEventListener
2649
+ * as the remove ignores the listener argument for the 'visibilitychange' event.
2650
+ * @param listener - The specific listener to remove for the 'pageshow' event only (ignored for 'visibilitychange')
2651
+ * @param evtNamespace - The unique namespace used when calling addPageShowEventListener
2652
+ */
2653
+ function removePageHideEventListener(listener: any, evtNamespace?: string | string[] | null): void;
2654
+
2655
+ /**
2656
+ * Removes the pageShow event listeners added by addPageShowEventListener, because the 'visibilitychange' uses
2657
+ * an internal proxy to detect the visibility state you SHOULD use a unique namespace when calling addPageShowEventListener
2658
+ * as the remove ignores the listener argument for the 'visibilitychange' event.
2659
+ * @param listener - The specific listener to remove for the 'pageshow' event only (ignored for 'visibilitychange')
2660
+ * @param evtNamespace - The unique namespace used when calling addPageShowEventListener
2661
+ */
2662
+ function removePageShowEventListener(listener: any, evtNamespace?: string | string[] | null): void;
2663
+
2664
+ /**
2665
+ * Remove any matching 'beforeunload', 'unload' and 'pagehide' events that may have been added via addEventListener,
2666
+ * addEventListeners, addPageUnloadEventListener or addPageHideEventListener.
2667
+ * @param listener - The specific event callback to to be removed
2668
+ * @param evtNamespace - [Optional] Namespace(s) uniquely identified and removed based on this namespace.
2669
+ * @returns true - when at least one of the events was registered otherwise false
2670
+ */
2671
+ function removePageUnloadEventListener(listener: any, evtNamespace?: string | string[]): void;
2672
+
2085
2673
  /**
2086
2674
  * Helper to return the ICookieMgr from the core (if not null/undefined) or a default implementation
2087
2675
  * associated with the configuration or a legacy default.
@@ -2125,6 +2713,10 @@ declare namespace ApplicationInsights {
2125
2713
  * The event(s) being sent as a retry
2126
2714
  */
2127
2715
  Retry = 5,
2716
+ /**
2717
+ * The SDK is unloading
2718
+ */
2719
+ SdkUnload = 6,
2128
2720
  /**
2129
2721
  * Maximum batch size would be exceeded
2130
2722
  */
@@ -2163,9 +2755,9 @@ declare namespace ApplicationInsights {
2163
2755
  * @param srcChk - [Optional] Callback to check to original value that if supplied will be called if the new value should be set (if allowed)
2164
2756
  * @returns The existing or new value, depending what was set
2165
2757
  */
2166
- 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];
2758
+ 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];
2167
2759
 
2168
- function sortPlugins(plugins: IPlugin[]): IPlugin[];
2760
+ function sortPlugins<T = IPlugin>(plugins: T[]): T[];
2169
2761
 
2170
2762
  /**
2171
2763
  * A simple wrapper (for minification support) to check if the value contains the search string.
@@ -2211,8 +2803,64 @@ declare namespace ApplicationInsights {
2211
2803
  [key: string]: any;
2212
2804
  }
2213
2805
 
2806
+ type TelemetryInitializerFunction = <T extends ITelemetryItem>(item: T) => boolean | void;
2807
+
2808
+ /**
2809
+ * The TelemetryUnloadReason enumeration contains the possible reasons for why a plugin is being unloaded / torndown().
2810
+ */
2811
+ const enum TelemetryUnloadReason {
2812
+ /**
2813
+ * Teardown has been called without any context.
2814
+ */
2815
+ ManualTeardown = 0,
2816
+ /**
2817
+ * Just this plugin is being removed
2818
+ */
2819
+ PluginUnload = 1,
2820
+ /**
2821
+ * This instance of the plugin is being removed and replaced
2822
+ */
2823
+ PluginReplace = 2,
2824
+ /**
2825
+ * The entire SDK is being unloaded
2826
+ */
2827
+ SdkUnload = 50
2828
+ }
2829
+
2830
+ /**
2831
+ * The TelemetryUpdateReason enumeration contains a set of bit-wise values that specify the reason for update request.
2832
+ */
2833
+ const enum TelemetryUpdateReason {
2834
+ /**
2835
+ * Unknown.
2836
+ */
2837
+ Unknown = 0,
2838
+ /**
2839
+ * The configuration has ben updated or changed
2840
+ */
2841
+ /**
2842
+ * One or more plugins have been added
2843
+ */
2844
+ PluginAdded = 16,
2845
+ /**
2846
+ * One or more plugins have been removed
2847
+ */
2848
+ PluginRemoved = 32
2849
+ }
2850
+
2214
2851
  function throwError(message: string): never;
2215
2852
 
2853
+ /**
2854
+ * This is a helper method which will call throwInternal on the passed logger, will throw exceptions in
2855
+ * debug mode or attempt to log the error as a console warning. This helper is provided mostly to better
2856
+ * support minification as logger.throwInternal() will not compress the publish "throwInternal" used throughout
2857
+ * the code.
2858
+ * @param logger - The Diagnostic Logger instance to use.
2859
+ * @param severity {LoggingSeverity} - The severity of the log message
2860
+ * @param message {_InternalLogMessage} - The log message.
2861
+ */
2862
+ function _throwInternal(logger: IDiagnosticLogger, severity: LoggingSeverity, msgId: _InternalMessageId, msg: string, properties?: Object, isUserAct?: boolean): void;
2863
+
2216
2864
  /**
2217
2865
  * Convert a date to I.S.O. format in IE8
2218
2866
  */
@@ -2222,6 +2870,19 @@ declare namespace ApplicationInsights {
2222
2870
 
2223
2871
  const Undefined = "undefined";
2224
2872
 
2873
+ /**
2874
+ * Teardown / Unload helper to perform teardown/unloading operations for the provided components synchronously or asynchronously, this will call any
2875
+ * _doTeardown() or _doUnload() functions on the provided components to allow them to finish removal.
2876
+ * @param components - The components you want to unload
2877
+ * @param unloadCtx - This is the context that should be used during unloading.
2878
+ * @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.
2879
+ * @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.
2880
+ * @returns boolean - true if the plugin has or will call asyncCallback, this allows the plugin to perform any asynchronous operations.
2881
+ */
2882
+ function unloadComponents(components: any | IUnloadableComponent[], unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState, asyncCallback?: () => void): void | boolean;
2883
+
2884
+ type UnloadHandler = (itemCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
2885
+
2225
2886
  function useXDomainRequest(): boolean | undefined;
2226
2887
 
2227
2888