@microsoft/applicationinsights-core-js 2.8.0-beta.2203-01 → 2.8.0-beta.2203-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 (128) hide show
  1. package/browser/applicationinsights-core-js.integrity.json +9 -9
  2. package/browser/applicationinsights-core-js.js +1137 -484
  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 +6529 -2784
  7. package/dist/applicationinsights-core-js.api.md +290 -30
  8. package/dist/applicationinsights-core-js.d.ts +481 -89
  9. package/dist/applicationinsights-core-js.js +1137 -484
  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 +481 -89
  14. package/dist-esm/JavaScriptSDK/AppInsightsCore.js +1 -1
  15. package/dist-esm/JavaScriptSDK/BaseCore.js +248 -32
  16. package/dist-esm/JavaScriptSDK/BaseCore.js.map +1 -1
  17. package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js +50 -5
  18. package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js.map +1 -1
  19. package/dist-esm/JavaScriptSDK/ChannelController.js +105 -73
  20. package/dist-esm/JavaScriptSDK/ChannelController.js.map +1 -1
  21. package/dist-esm/JavaScriptSDK/Constants.js +1 -1
  22. package/dist-esm/JavaScriptSDK/CookieMgr.js +3 -4
  23. package/dist-esm/JavaScriptSDK/CookieMgr.js.map +1 -1
  24. package/dist-esm/JavaScriptSDK/CoreUtils.js +6 -122
  25. package/dist-esm/JavaScriptSDK/CoreUtils.js.map +1 -1
  26. package/dist-esm/JavaScriptSDK/DataCacheHelper.js +93 -0
  27. package/dist-esm/JavaScriptSDK/DataCacheHelper.js.map +1 -0
  28. package/dist-esm/JavaScriptSDK/DbgExtensionUtils.js +1 -1
  29. package/dist-esm/JavaScriptSDK/DiagnosticLogger.js +12 -12
  30. package/dist-esm/JavaScriptSDK/DiagnosticLogger.js.map +1 -1
  31. package/dist-esm/JavaScriptSDK/EnvUtils.js +8 -7
  32. package/dist-esm/JavaScriptSDK/EnvUtils.js.map +1 -1
  33. package/dist-esm/JavaScriptSDK/EventHelpers.js +472 -0
  34. package/dist-esm/JavaScriptSDK/EventHelpers.js.map +1 -0
  35. package/dist-esm/JavaScriptSDK/HelperFuncs.js +32 -59
  36. package/dist-esm/JavaScriptSDK/HelperFuncs.js.map +1 -1
  37. package/dist-esm/JavaScriptSDK/InstrumentHooks.js +1 -1
  38. package/dist-esm/JavaScriptSDK/InternalConstants.js +28 -0
  39. package/dist-esm/JavaScriptSDK/InternalConstants.js.map +1 -0
  40. package/dist-esm/JavaScriptSDK/NotificationManager.js +8 -11
  41. package/dist-esm/JavaScriptSDK/NotificationManager.js.map +1 -1
  42. package/dist-esm/JavaScriptSDK/PerfManager.js +1 -1
  43. package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js +195 -107
  44. package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js.map +1 -1
  45. package/dist-esm/JavaScriptSDK/RandomHelper.js +3 -2
  46. package/dist-esm/JavaScriptSDK/RandomHelper.js.map +1 -1
  47. package/dist-esm/JavaScriptSDK/TelemetryHelpers.js +32 -13
  48. package/dist-esm/JavaScriptSDK/TelemetryHelpers.js.map +1 -1
  49. package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js +4 -6
  50. package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js.map +1 -1
  51. package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js +32 -0
  52. package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js.map +1 -0
  53. package/dist-esm/JavaScriptSDK.Enums/EventsDiscardedReason.js +1 -1
  54. package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js +90 -96
  55. package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js.map +1 -1
  56. package/dist-esm/JavaScriptSDK.Enums/SendRequestReason.js +1 -1
  57. package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js +8 -0
  58. package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js.map +1 -0
  59. package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js +1 -1
  60. package/dist-esm/JavaScriptSDK.Interfaces/IChannelControls.js +1 -1
  61. package/dist-esm/JavaScriptSDK.Interfaces/IConfiguration.js +1 -1
  62. package/dist-esm/JavaScriptSDK.Interfaces/ICookieMgr.js +1 -1
  63. package/dist-esm/JavaScriptSDK.Interfaces/IDbgExtension.js +1 -1
  64. package/dist-esm/JavaScriptSDK.Interfaces/IDiagnosticLogger.js +1 -1
  65. package/dist-esm/JavaScriptSDK.Interfaces/IInstrumentHooks.js +1 -1
  66. package/dist-esm/JavaScriptSDK.Interfaces/INotificationListener.js +1 -1
  67. package/dist-esm/JavaScriptSDK.Interfaces/INotificationManager.js +1 -1
  68. package/dist-esm/JavaScriptSDK.Interfaces/IPerfEvent.js +1 -1
  69. package/dist-esm/JavaScriptSDK.Interfaces/IPerfManager.js +1 -1
  70. package/dist-esm/JavaScriptSDK.Interfaces/IProcessTelemetryContext.js +1 -1
  71. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js +1 -1
  72. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryItem.js +1 -1
  73. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPlugin.js +1 -1
  74. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js +1 -2
  75. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js.map +1 -1
  76. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js +8 -0
  77. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js.map +1 -0
  78. package/dist-esm/applicationinsights-core-js.js +9 -4
  79. package/dist-esm/applicationinsights-core-js.js.map +1 -1
  80. package/package.json +1 -1
  81. package/src/JavaScriptSDK/BaseCore.ts +312 -33
  82. package/src/JavaScriptSDK/BaseTelemetryPlugin.ts +90 -5
  83. package/src/JavaScriptSDK/ChannelController.ts +107 -61
  84. package/src/JavaScriptSDK/CookieMgr.ts +4 -4
  85. package/src/JavaScriptSDK/CoreUtils.ts +6 -143
  86. package/src/JavaScriptSDK/DataCacheHelper.ts +106 -0
  87. package/src/JavaScriptSDK/DiagnosticLogger.ts +12 -11
  88. package/src/JavaScriptSDK/EnvUtils.ts +7 -6
  89. package/src/JavaScriptSDK/EventHelpers.ts +542 -0
  90. package/src/JavaScriptSDK/HelperFuncs.ts +35 -54
  91. package/src/JavaScriptSDK/InternalConstants.ts +26 -0
  92. package/src/JavaScriptSDK/NotificationManager.ts +7 -11
  93. package/src/JavaScriptSDK/ProcessTelemetryContext.ts +248 -121
  94. package/src/JavaScriptSDK/RandomHelper.ts +2 -1
  95. package/src/JavaScriptSDK/TelemetryHelpers.ts +47 -15
  96. package/src/JavaScriptSDK/TelemetryInitializerPlugin.ts +5 -15
  97. package/src/JavaScriptSDK/UnloadHandlerContainer.ts +44 -0
  98. package/src/JavaScriptSDK.Enums/LoggingEnums.ts +184 -87
  99. package/src/JavaScriptSDK.Enums/SendRequestReason.ts +5 -0
  100. package/src/JavaScriptSDK.Enums/TelemetryUnloadReason.ts +27 -0
  101. package/src/JavaScriptSDK.Interfaces/IAppInsightsCore.ts +49 -2
  102. package/src/JavaScriptSDK.Interfaces/IChannelControls.ts +9 -2
  103. package/src/JavaScriptSDK.Interfaces/IProcessTelemetryContext.ts +55 -16
  104. package/src/JavaScriptSDK.Interfaces/ITelemetryPlugin.ts +16 -9
  105. package/src/JavaScriptSDK.Interfaces/ITelemetryPluginChain.ts +9 -11
  106. package/src/JavaScriptSDK.Interfaces/ITelemetryUnloadState.ts +10 -0
  107. package/types/JavaScriptSDK/BaseCore.d.ts +21 -1
  108. package/types/JavaScriptSDK/BaseTelemetryPlugin.d.ts +26 -1
  109. package/types/JavaScriptSDK/ChannelController.d.ts +4 -0
  110. package/types/JavaScriptSDK/CoreUtils.d.ts +1 -42
  111. package/types/JavaScriptSDK/DataCacheHelper.d.ts +13 -0
  112. package/types/JavaScriptSDK/EventHelpers.d.ts +152 -0
  113. package/types/JavaScriptSDK/HelperFuncs.d.ts +8 -17
  114. package/types/JavaScriptSDK/InternalConstants.d.ts +20 -0
  115. package/types/JavaScriptSDK/ProcessTelemetryContext.d.ts +12 -3
  116. package/types/JavaScriptSDK/TelemetryHelpers.d.ts +8 -0
  117. package/types/JavaScriptSDK/TelemetryInitializerPlugin.d.ts +0 -7
  118. package/types/JavaScriptSDK/UnloadHandlerContainer.d.ts +11 -0
  119. package/types/JavaScriptSDK.Enums/LoggingEnums.d.ts +91 -2
  120. package/types/JavaScriptSDK.Enums/SendRequestReason.d.ts +4 -0
  121. package/types/JavaScriptSDK.Enums/TelemetryUnloadReason.d.ts +21 -0
  122. package/types/JavaScriptSDK.Interfaces/IAppInsightsCore.d.ts +41 -1
  123. package/types/JavaScriptSDK.Interfaces/IChannelControls.d.ts +9 -2
  124. package/types/JavaScriptSDK.Interfaces/IProcessTelemetryContext.d.ts +49 -14
  125. package/types/JavaScriptSDK.Interfaces/ITelemetryPlugin.d.ts +15 -8
  126. package/types/JavaScriptSDK.Interfaces/ITelemetryPluginChain.d.ts +9 -10
  127. package/types/JavaScriptSDK.Interfaces/ITelemetryUnloadState.d.ts +6 -0
  128. package/types/applicationinsights-core-js.d.ts +7 -3
@@ -3,11 +3,12 @@
3
3
  "use strict";
4
4
 
5
5
  import { IAppInsightsCore } from "./IAppInsightsCore";
6
- import { IDiagnosticLogger } from "./IDiagnosticLogger";
7
6
  import { IConfiguration } from "./IConfiguration";
7
+ import { IDiagnosticLogger } from "./IDiagnosticLogger";
8
8
  import { ITelemetryItem } from "./ITelemetryItem";
9
9
  import { IPlugin, ITelemetryPlugin } from "./ITelemetryPlugin";
10
10
  import { ITelemetryPluginChain } from "./ITelemetryPluginChain";
11
+ import { ITelemetryUnloadState } from "./ITelemetryUnloadState";
11
12
 
12
13
  export const enum GetExtCfgMergeType {
13
14
  None = 0,
@@ -15,11 +16,7 @@ export const enum GetExtCfgMergeType {
15
16
  MergeDefaultFromRootOrDefault = 2,
16
17
  }
17
18
 
18
- /**
19
- * The current context for the current call to processTelemetry(), used to support sharing the same plugin instance
20
- * between multiple AppInsights instances
21
- */
22
- export interface IProcessTelemetryContext {
19
+ export interface IBaseProcessingContext {
23
20
  /**
24
21
  * The current core instance for the request
25
22
  */
@@ -65,12 +62,6 @@ export interface IProcessTelemetryContext {
65
62
  */
66
63
  setNext: (nextCtx: ITelemetryPluginChain) => void;
67
64
 
68
- /**
69
- * Call back for telemetry processing before it it is sent
70
- * @param env - This is the current event being reported
71
- */
72
- processNext: (env: ITelemetryItem) => void;
73
-
74
65
  /**
75
66
  * Synchronously iterate over the context chain running the callback for each plugin, once
76
67
  * every plugin has been executed via the callback, any associated onComplete will be called.
@@ -79,16 +70,64 @@ export interface IProcessTelemetryContext {
79
70
  iterate: <T extends ITelemetryPlugin = ITelemetryPlugin>(callback: (plugin: T) => void) => void;
80
71
 
81
72
  /**
82
- * Create a new context using the core and config from the current instance
73
+ * Set the function to call when the current chain has executed all processNext or unloadNext items.
74
+ * @param onComplete - The onComplete to call
75
+ * @param that - The "this" value to use for the onComplete call, if not provided or undefined defaults to the current context
76
+ * @param args - Any additional arguments to pass to the onComplete function
77
+ */
78
+ onComplete: (onComplete: Function, that?: any, ...args: any[]) => void;
79
+
80
+ /**
81
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
83
82
  * @param plugins - The execution order to process the plugins, if null or not supplied
84
83
  * then the current execution order will be copied.
85
84
  * @param startAt - The plugin to start processing from, if missing from the execution
86
85
  * order then the next plugin will be NOT set.
87
86
  */
88
- createNew: (plugins?:IPlugin[]|ITelemetryPluginChain, startAt?:IPlugin) => IProcessTelemetryContext;
87
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IBaseProcessingContext;
88
+ }
89
89
 
90
+ /**
91
+ * The current context for the current call to processTelemetry(), used to support sharing the same plugin instance
92
+ * between multiple AppInsights instances
93
+ */
94
+ export interface IProcessTelemetryContext extends IBaseProcessingContext {
90
95
  /**
91
- * Set the function to call when the current chain has executed all processNext or unloadNext items.
96
+ * Call back for telemetry processing before it it is sent
97
+ * @param env - This is the current event being reported
98
+ * @returns boolean (true) if there is no more plugins to process otherwise false or undefined (void)
99
+ */
100
+ processNext: (env: ITelemetryItem) => boolean | void;
101
+
102
+ /**
103
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
104
+ * @param plugins - The execution order to process the plugins, if null or not supplied
105
+ * then the current execution order will be copied.
106
+ * @param startAt - The plugin to start processing from, if missing from the execution
107
+ * order then the next plugin will be NOT set.
108
+ */
109
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryContext;
110
+ }
111
+
112
+ /**
113
+ * The current context for the current call to processTelemetry(), used to support sharing the same plugin instance
114
+ * between multiple AppInsights instances
115
+ */
116
+ export interface IProcessTelemetryUnloadContext extends IBaseProcessingContext {
117
+
118
+ /**
119
+ * This Plugin has finished unloading, so unload the next one
120
+ * @param uploadState - The state of the unload process
121
+ * @returns boolean (true) if there is no more plugins to process otherwise false or undefined (void)
122
+ */
123
+ processNext: (unloadState: ITelemetryUnloadState) => boolean | void;
124
+
125
+ /**
126
+ * Create a new context using the core and config from the current instance, returns a new instance of the same type
127
+ * @param plugins - The execution order to process the plugins, if null or not supplied
128
+ * then the current execution order will be copied.
129
+ * @param startAt - The plugin to start processing from, if missing from the execution
130
+ * order then the next plugin will be NOT set.
92
131
  */
93
- onComplete: (onComplete: () => void) => void;
132
+ createNew: (plugins?: IPlugin[] | ITelemetryPluginChain, startAt?: IPlugin) => IProcessTelemetryUnloadContext;
94
133
  }
@@ -5,13 +5,11 @@
5
5
  import { ITelemetryItem } from "./ITelemetryItem";
6
6
  import { IConfiguration } from "./IConfiguration";
7
7
  import { IAppInsightsCore } from "./IAppInsightsCore";
8
- import { IProcessTelemetryContext } from "./IProcessTelemetryContext";
8
+ import { IProcessTelemetryContext, IProcessTelemetryUnloadContext } from "./IProcessTelemetryContext";
9
9
  import { ITelemetryPluginChain } from "./ITelemetryPluginChain";
10
+ import { ITelemetryUnloadState } from "./ITelemetryUnloadState";
10
11
 
11
- /**
12
- * Configuration provided to SDK core
13
- */
14
- export interface ITelemetryPlugin extends IPlugin {
12
+ export interface ITelemetryProcessor {
15
13
  /**
16
14
  * Call back for telemetry processing before it it is sent
17
15
  * @param env - This is the current event being reported
@@ -20,7 +18,12 @@ export interface ITelemetryPlugin extends IPlugin {
20
18
  * to later plugins (vs appending items to the telemetry item)
21
19
  */
22
20
  processTelemetry: (env: ITelemetryItem, itemCtx?: IProcessTelemetryContext) => void;
23
-
21
+ }
22
+
23
+ /**
24
+ * Configuration provided to SDK core
25
+ */
26
+ export interface ITelemetryPlugin extends ITelemetryProcessor, IPlugin {
24
27
  /**
25
28
  * Set next extension for telemetry processing, this is not optional as plugins should use the
26
29
  * processNext() function of the passed IProcessTelemetryContext instead. It is being kept for
@@ -52,10 +55,14 @@ export interface IPlugin {
52
55
  isInitialized?: () => boolean;
53
56
 
54
57
  /**
55
- * Tear down the plugin and remove any hooked value, the plugin should remove that it is no longer initialized and
56
- * therefore can be re-initialized after being torn down.
58
+ * Tear down the plugin and remove any hooked value, the plugin should be removed so that it is no longer initialized and
59
+ * therefore could be re-initialized after being torn down. The plugin should ensure that once this has been called any further
60
+ * processTelemetry calls are ignored and it just calls the processNext() with the provided context.
61
+ * @param unloadCtx - This is the context that should be used during unloading.
62
+ * @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.
63
+ * @returns boolean - true if the plugin has or will call processNext(), this for backward compatibility as previously teardown was synchronous and returned nothing.
57
64
  */
58
- teardown?: () => void;
65
+ teardown?: (unloadCtx: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState) => void | boolean;
59
66
 
60
67
  /**
61
68
  * Extension name
@@ -1,15 +1,14 @@
1
1
  // Copyright (c) Microsoft Corporation. All rights reserved.
2
2
  // Licensed under the MIT License.
3
- "use strict";
4
3
 
5
- import { ITelemetryItem } from "./ITelemetryItem";
6
- import { IProcessTelemetryContext } from "./IProcessTelemetryContext";
7
- import { ITelemetryPlugin } from "./ITelemetryPlugin";
4
+ import { IProcessTelemetryUnloadContext } from "./IProcessTelemetryContext";
5
+ import { ITelemetryPlugin, ITelemetryProcessor } from "./ITelemetryPlugin";
6
+ import { ITelemetryUnloadState } from "./ITelemetryUnloadState";
8
7
 
9
8
  /**
10
9
  * Configuration provided to SDK core
11
10
  */
12
- export interface ITelemetryPluginChain {
11
+ export interface ITelemetryPluginChain extends ITelemetryProcessor {
13
12
 
14
13
  /**
15
14
  * Returns the underlying plugin that is being proxied for the processTelemetry call
@@ -22,11 +21,10 @@ export interface ITelemetryPluginChain {
22
21
  getNext: () => ITelemetryPluginChain;
23
22
 
24
23
  /**
25
- * Call back for telemetry processing before it it is sent
26
- * @param env - This is the current event being reported
27
- * @param itemCtx - This is the context for the current request, ITelemetryPlugin instances
28
- * can optionally use this to access the current core instance or define / pass additional information
29
- * to later plugins (vs appending items to the telemetry item)
24
+ * This plugin is being unloaded and should remove any hooked events and cleanup any global/scoped values, after this
25
+ * call the plugin will be removed from the telemetry processing chain and will no longer receive any events..
26
+ * @param unloadCtx - The unload context to use for this call.
27
+ * @param unloadState - The details of the unload operation
30
28
  */
31
- processTelemetry: (env: ITelemetryItem, itemCtx:IProcessTelemetryContext) => void;
29
+ unload?: (unloadCtx: IProcessTelemetryUnloadContext, unloadState: ITelemetryUnloadState) => void;
32
30
  }
@@ -0,0 +1,10 @@
1
+ // Copyright (c) Microsoft Corporation. All rights reserved.
2
+ // Licensed under the MIT License.
3
+
4
+ import { TelemetryUnloadReason } from "../JavaScriptSDK.Enums/TelemetryUnloadReason";
5
+
6
+ export interface ITelemetryUnloadState {
7
+ reason: TelemetryUnloadReason;
8
+ isAsync: boolean;
9
+ flushComplete?: boolean;
10
+ }
@@ -1,6 +1,6 @@
1
1
  import { IAppInsightsCore, ILoadedPlugin } from "../JavaScriptSDK.Interfaces/IAppInsightsCore";
2
2
  import { IConfiguration } from "../JavaScriptSDK.Interfaces/IConfiguration";
3
- import { IPlugin } from "../JavaScriptSDK.Interfaces/ITelemetryPlugin";
3
+ import { IPlugin, ITelemetryPlugin } from "../JavaScriptSDK.Interfaces/ITelemetryPlugin";
4
4
  import { IChannelControls } from "../JavaScriptSDK.Interfaces/IChannelControls";
5
5
  import { ITelemetryItem } from "../JavaScriptSDK.Interfaces/ITelemetryItem";
6
6
  import { INotificationManager } from "../JavaScriptSDK.Interfaces/INotificationManager";
@@ -10,6 +10,7 @@ import { IProcessTelemetryContext } from "../JavaScriptSDK.Interfaces/IProcessTe
10
10
  import { IPerfManager } from "../JavaScriptSDK.Interfaces/IPerfManager";
11
11
  import { ICookieMgr } from "../JavaScriptSDK.Interfaces/ICookieMgr";
12
12
  import { ITelemetryInitializerHandler, TelemetryInitializerFunction } from "../JavaScriptSDK.Interfaces/ITelemetryInitializers";
13
+ import { UnloadHandler } from "./UnloadHandlerContainer";
13
14
  export declare class BaseCore implements IAppInsightsCore {
14
15
  static defaultConfig: IConfiguration;
15
16
  config: IConfiguration;
@@ -60,6 +61,25 @@ export declare class BaseCore implements IAppInsightsCore {
60
61
  * @returns - A ITelemetryInitializerHandler to enable the initializer to be removed
61
62
  */
62
63
  addTelemetryInitializer(telemetryInitializer: TelemetryInitializerFunction): ITelemetryInitializerHandler | void;
64
+ /**
65
+ * Unload and Tear down the SDK and any initialized plugins, after calling this the SDK will be considered
66
+ * to be un-initialized and non-operational, re-initializing the SDK should only be attempted if the previous
67
+ * unload call return `true` stating that all plugins reported that they also unloaded, the recommended
68
+ * approach is to create a new instance and initialize that instance.
69
+ * This is due to possible unexpected side effects caused by plugins not supporting unload / teardown, unable
70
+ * to successfully remove any global references or they may just be completing the unload process asynchronously.
71
+ */
72
+ unload(isAsync?: boolean, unloadComplete?: () => void): void;
63
73
  getPlugin<T extends IPlugin = IPlugin>(pluginIdentifier: string): ILoadedPlugin<T>;
74
+ addPlugin<T extends IPlugin = ITelemetryPlugin>(plugin: T, replaceExisting: boolean, doAsync: boolean, addCb?: (added?: boolean) => void): void;
75
+ /**
76
+ * Returns the unique event namespace that should be used
77
+ */
78
+ evtNamespace(): string;
79
+ /**
80
+ * Add an unload handler that will be called when the SDK is being unloaded
81
+ * @param handler - the handler
82
+ */
83
+ addUnloadCb(handler: UnloadHandler): void;
64
84
  protected releaseQueue(): void;
65
85
  }
@@ -3,9 +3,11 @@ import { IConfiguration } from "../JavaScriptSDK.Interfaces/IConfiguration";
3
3
  import { IDiagnosticLogger } from "../JavaScriptSDK.Interfaces/IDiagnosticLogger";
4
4
  import { IPlugin, ITelemetryPlugin } from "../JavaScriptSDK.Interfaces/ITelemetryPlugin";
5
5
  import { ITelemetryItem } from "../JavaScriptSDK.Interfaces/ITelemetryItem";
6
- import { IProcessTelemetryContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
6
+ import { IProcessTelemetryContext, IProcessTelemetryUnloadContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
7
7
  import { ITelemetryPluginChain } from "../JavaScriptSDK.Interfaces/ITelemetryPluginChain";
8
+ import { UnloadHandler } from "./UnloadHandlerContainer";
8
9
  import { IInstrumentHook } from "../JavaScriptSDK.Interfaces/IInstrumentHooks";
10
+ import { ITelemetryUnloadState } from "../JavaScriptSDK.Interfaces/ITelemetryUnloadState";
9
11
  /**
10
12
  * BaseTelemetryPlugin provides a basic implementation of the ITelemetryPlugin interface so that plugins
11
13
  * can avoid implementation the same set of boiler plate code as well as provide a base
@@ -51,9 +53,32 @@ export declare abstract class BaseTelemetryPlugin implements ITelemetryPlugin {
51
53
  * Internal helper to allow setting of the internal initialized setting for inherited instances and unit testing
52
54
  */
53
55
  protected setInitialized: (isInitialized: boolean) => void;
56
+ /**
57
+ * Teardown / Unload hook to allow implementations to perform some additional unload operations before the BaseTelemetryPlugin
58
+ * finishes it's removal.
59
+ * @param unloadCtx - This is the context that should be used during unloading.
60
+ * @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.
61
+ * @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.
62
+ * @returns boolean - true if the plugin has or will call asyncCallback, this allows the plugin to perform any asynchronous operations.
63
+ */
64
+ protected _doTeardown?: (unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState, asyncCallback?: () => void) => void | boolean;
54
65
  constructor();
55
66
  initialize(config: IConfiguration, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?: ITelemetryPluginChain): void;
67
+ /**
68
+ * Tear down the plugin and remove any hooked value, the plugin should be removed so that it is no longer initialized and
69
+ * therefore could be re-initialized after being torn down. The plugin should ensure that once this has been called any further
70
+ * processTelemetry calls are ignored and it just calls the processNext() with the provided context.
71
+ * @param unloadCtx - This is the context that should be used during unloading.
72
+ * @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.
73
+ * @returns boolean - true if the plugin has or will call processNext(), this for backward compatibility as previously teardown was synchronous and returned nothing.
74
+ */
75
+ teardown(unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState): void | boolean;
56
76
  abstract processTelemetry(env: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
77
+ /**
78
+ * Add an unload handler that will be called when the SDK is being unloaded
79
+ * @param handler - the handler
80
+ */
81
+ protected _addUnloadCb(handler: UnloadHandler): void;
57
82
  /**
58
83
  * Add this hook so that it is automatically removed during unloading
59
84
  * @param hooks - The single hook or an array of IInstrumentHook objects
@@ -7,6 +7,10 @@ import { ITelemetryPluginChain } from "../JavaScriptSDK.Interfaces/ITelemetryPlu
7
7
  export declare const ChannelControllerPriority = 500;
8
8
  export interface IChannelController extends IChannelControls {
9
9
  flush(isAsync: boolean, callBack: (flushComplete?: boolean) => void, sendReason: SendRequestReason, cbTimeout?: number): void;
10
+ getChannel<T extends IPlugin = IPlugin>(pluginIdentifier: string): T;
11
+ }
12
+ export interface IInternalChannelController extends IChannelController {
13
+ _setQueue: (channels: _IInternalChannels[]) => void;
10
14
  }
11
15
  export interface _IInternalChannels {
12
16
  queue: IChannelControls[];
@@ -2,47 +2,6 @@ import { IConfiguration } from "../JavaScriptSDK.Interfaces/IConfiguration";
2
2
  import { ICookieMgr } from "../JavaScriptSDK.Interfaces/ICookieMgr";
3
3
  import { IDiagnosticLogger } from "../JavaScriptSDK.Interfaces/IDiagnosticLogger";
4
4
  export declare const Undefined = "undefined";
5
- /**
6
- * Trys to add an event handler for the specified event to the window, body and document
7
- * @param eventName {string} - The name of the event
8
- * @param callback {any} - The callback function that needs to be executed for the given event
9
- * @return {boolean} - true if the handler was successfully added
10
- */
11
- export declare function addEventHandler(eventName: string, callback: any): boolean;
12
- /**
13
- * Bind the listener to the array of events
14
- * @param events An string array of event names to bind the listener to
15
- * @param listener The event callback to call when the event is triggered
16
- * @param excludeEvents - [Optional] An array of events that should not be hooked (if possible), unless no other events can be.
17
- * @returns true - when at least one of the events was registered otherwise false
18
- */
19
- export declare function addEventListeners(events: string[], listener: any, excludeEvents?: string[]): boolean;
20
- /**
21
- * Listen to the 'beforeunload', 'unload' and 'pagehide' events which indicates a page unload is occurring,
22
- * this does NOT listen to the 'visibilitychange' event as while it does indicate that the page is being hidden
23
- * it does not *necessarily* mean that the page is being completely unloaded, it can mean that the user is
24
- * just navigating to a different Tab and may come back (without unloading the page). As such you may also
25
- * need to listen to the 'addPageHideEventListener' and 'addPageShowEventListener' events.
26
- * @param listener - The event callback to call when a page unload event is triggered
27
- * @param excludeEvents - [Optional] An array of events that should not be hooked, unless no other events can be.
28
- * @returns true - when at least one of the events was registered otherwise false
29
- */
30
- export declare function addPageUnloadEventListener(listener: any, excludeEvents?: string[]): boolean;
31
- /**
32
- * Listen to the pagehide and visibility changing to 'hidden' events
33
- * @param listener - The event callback to call when a page hide event is triggered
34
- * @param excludeEvents - [Optional] An array of events that should not be hooked (if possible), unless no other events can be.
35
- * Suggestion: pass as true if you are also calling addPageUnloadEventListener as that also hooks pagehide
36
- * @returns true - when at least one of the events was registered otherwise false
37
- */
38
- export declare function addPageHideEventListener(listener: any, excludeEvents?: string[]): boolean;
39
- /**
40
- * Listen to the pageshow and visibility changing to 'visible' events
41
- * @param listener - The event callback to call when a page is show event is triggered
42
- * @param excludeEvents - [Optional] An array of events that should not be hooked (if possible), unless no other events can be.
43
- * @returns true - when at least one of the events was registered otherwise false
44
- */
45
- export declare function addPageShowEventListener(listener: any, excludeEvents?: string[]): boolean;
46
5
  export declare function newGuid(): string;
47
6
  /**
48
7
  * Return the current value of the Performance Api now() function (if available) and fallback to dateNow() if it is unavailable (IE9 or less)
@@ -193,7 +152,7 @@ export interface ICoreUtils {
193
152
  * @param callback {any} - The callback function that needs to be executed for the given event
194
153
  * @return {boolean} - true if the handler was successfully added
195
154
  */
196
- addEventHandler: (eventName: string, callback: any) => boolean;
155
+ addEventHandler: (eventName: string, callback: any, evtNamespace?: string | string[]) => boolean;
197
156
  /**
198
157
  * 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)
199
158
  * https://caniuse.com/#search=Date.now
@@ -0,0 +1,13 @@
1
+ export interface IDataCache {
2
+ id: string;
3
+ accept: (target: any) => boolean;
4
+ get: <T>(target: any, name: string, defValue?: T, addDefault?: boolean) => T;
5
+ kill: (target: any, name: string) => void;
6
+ }
7
+ export declare function createUniqueNamespace(name: string, includeVersion?: boolean): string;
8
+ export declare function createElmNodeData(name?: string): {
9
+ id: string;
10
+ accept: (target: any) => boolean;
11
+ get: <T>(target: any, name: string, defValue?: T, addDefault?: boolean) => T;
12
+ kill: (target: any, name: string) => void;
13
+ };
@@ -0,0 +1,152 @@
1
+ export interface _IRegisteredEvents {
2
+ name: string;
3
+ handler: any;
4
+ }
5
+ /**
6
+ * Get all of the registered events on the target object, this is primarily used for testing cleanup but may also be used by
7
+ * applications to remove their own events
8
+ * @param target - The EventTarget that has registered events
9
+ * @param evtName - [Optional] The name of the event to return the registered handlers and full name (with namespaces)
10
+ */
11
+ export declare function __getRegisteredEvents(target: any, evtName?: string): _IRegisteredEvents[];
12
+ export declare function mergeEvtNamespace(theNamespace: string, namespaces: string | string[]): string | string[];
13
+ /**
14
+ * Binds the specified function to an event, so that the function gets called whenever the event fires on the object
15
+ * @param obj Object to add the event too.
16
+ * @param eventName String that specifies any of the standard DHTML Events without "on" prefix, if may also include an optional (dot "." prefixed)
17
+ * namespaces "click" "click.mynamespace" in addition to specific namespaces.
18
+ * @param handlerRef Pointer that specifies the function to call when event fires
19
+ * @param evtNamespace - [Optional] Additional namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace,
20
+ * if the eventName also includes a namespace the namespace(s) are merged into a single namespace
21
+ * @param useCapture [Optional] Defaults to false
22
+ * @returns True if the function was bound successfully to the event, otherwise false
23
+ */
24
+ export declare function eventOn<T>(target: T, eventName: string, handlerRef: any, evtNamespace?: string | string[], useCapture?: boolean): boolean;
25
+ /**
26
+ * Removes an event handler for the specified event
27
+ * @param Object to remove the event from
28
+ * @param eventName {string} - The name of the event, with optional namespaces or just the namespaces,
29
+ * such as "click", "click.mynamespace" or ".mynamespace"
30
+ * @param handlerRef {any} - The callback function that needs to be removed from the given event, when using a
31
+ * namespace (with or without a qualifying event) this may be null to remove all previously attached event handlers
32
+ * otherwise this will only remove events with this specific handler.
33
+ * @param evtNamespace - [Optional] Additional namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace,
34
+ * if the eventName also includes a namespace the namespace(s) are merged into a single namespace
35
+ * @param useCapture [Optional] Defaults to false
36
+ */
37
+ export declare function eventOff<T>(target: T, eventName: string, handlerRef: any, evtNamespace?: string | string[], useCapture?: boolean): void;
38
+ /**
39
+ * Binds the specified function to an event, so that the function gets called whenever the event fires on the object
40
+ * @param obj Object to add the event too.
41
+ * @param eventNameWithoutOn String that specifies any of the standard DHTML Events without "on" prefix and optional (dot "." prefixed) namespaces "click" "click.mynamespace".
42
+ * @param handlerRef Pointer that specifies the function to call when event fires
43
+ * @param useCapture [Optional] Defaults to false
44
+ * @returns True if the function was bound successfully to the event, otherwise false
45
+ */
46
+ export declare function attachEvent(obj: any, eventNameWithoutOn: string, handlerRef: any, useCapture?: boolean): boolean;
47
+ /**
48
+ * Removes an event handler for the specified event
49
+ * @param Object to remove the event from
50
+ * @param eventNameWithoutOn {string} - The name of the event, with optional namespaces or just the namespaces,
51
+ * such as "click", "click.mynamespace" or ".mynamespace"
52
+ * @param handlerRef {any} - The callback function that needs to be removed from the given event, when using a
53
+ * namespace (with or without a qualifying event) this may be null to remove all previously attached event handlers
54
+ * otherwise this will only remove events with this specific handler.
55
+ * @param useCapture [Optional] Defaults to false
56
+ */
57
+ export declare function detachEvent(obj: any, eventNameWithoutOn: string, handlerRef: any, useCapture?: boolean): void;
58
+ /**
59
+ * Trys to add an event handler for the specified event to the window, body and document
60
+ * @param eventName {string} - The name of the event
61
+ * @param callback {any} - The callback function that needs to be executed for the given event
62
+ * @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.
63
+ * @return {boolean} - true if the handler was successfully added
64
+ */
65
+ export declare function addEventHandler(eventName: string, callback: any, evtNamespace?: string | string[]): boolean;
66
+ /**
67
+ * Trys to remove event handler(s) for the specified event/namespace to the window, body and document
68
+ * @param eventName {string} - The name of the event, with optional namespaces or just the namespaces,
69
+ * such as "click", "click.mynamespace" or ".mynamespace"
70
+ * @param callback {any} - - The callback function that needs to be removed from the given event, when using a
71
+ * namespace (with or without a qualifying event) this may be null to remove all previously attached event handlers
72
+ * otherwise this will only remove events with this specific handler.
73
+ * @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.
74
+ */
75
+ export declare function removeEventHandler(eventName: string, callback: any, evtNamespace?: string | string[]): void;
76
+ /**
77
+ * Bind the listener to the array of events
78
+ * @param events An string array of event names to bind the listener to
79
+ * @param listener The event callback to call when the event is triggered
80
+ * @param excludeEvents - [Optional] An array of events that should not be hooked (if possible), 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.
82
+ * @returns true - when at least one of the events was registered otherwise false
83
+ */
84
+ export declare function addEventListeners(events: string[], listener: any, excludeEvents?: string[], evtNamespace?: string | string[]): boolean;
85
+ /**
86
+ * Remove the listener from the array of events
87
+ * @param events An string array of event names to bind the listener to
88
+ * @param listener The event callback to call when the event is triggered
89
+ * @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.
90
+ */
91
+ export declare function removeEventListeners(events: string[], listener: any, evtNamespace?: string | string[]): void;
92
+ /**
93
+ * Listen to the 'beforeunload', 'unload' and 'pagehide' events which indicates a page unload is occurring,
94
+ * this does NOT listen to the 'visibilitychange' event as while it does indicate that the page is being hidden
95
+ * it does not *necessarily* mean that the page is being completely unloaded, it can mean that the user is
96
+ * just navigating to a different Tab and may come back (without unloading the page). As such you may also
97
+ * need to listen to the 'addPageHideEventListener' and 'addPageShowEventListener' events.
98
+ * @param listener - The event callback to call when a page unload event is triggered
99
+ * @param excludeEvents - [Optional] An array of events that should not be hooked, unless no other events can be.
100
+ * @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.
101
+ * @returns true - when at least one of the events was registered otherwise false
102
+ */
103
+ export declare function addPageUnloadEventListener(listener: any, excludeEvents: string[], evtNamespace?: string | string[]): boolean;
104
+ /**
105
+ * Remove any matching 'beforeunload', 'unload' and 'pagehide' events that may have been added via addEventListener,
106
+ * addEventListeners, addPageUnloadEventListener or addPageHideEventListener.
107
+ * @param listener - The specific event callback to to be removed
108
+ * @param evtNamespace - [Optional] Namespace(s) uniquely identified and removed based on this namespace.
109
+ * @returns true - when at least one of the events was registered otherwise false
110
+ */
111
+ export declare function removePageUnloadEventListener(listener: any, evtNamespace?: string | string[]): void;
112
+ /**
113
+ * Listen to the pagehide and visibility changing to 'hidden' events, because the 'visibilitychange' uses
114
+ * an internal proxy to detect the visibility state you SHOULD use a unique namespace when if you plan to call
115
+ * removePageShowEventListener as the remove ignores the listener argument for the 'visibilitychange' event.
116
+ * @param listener - The event callback to call when a page hide event is triggered
117
+ * @param excludeEvents - [Optional] An array of events that should not be hooked (if possible), unless no other events can be.
118
+ * @param evtNamespace - [Optional] A Namespace to append to the event listeners so they can be uniquely identified and removed
119
+ * based on this namespace. This call also adds an additional unique "pageshow" namespace to the events
120
+ * so that only the matching "removePageHideEventListener" can remove these events.
121
+ * Suggestion: pass as true if you are also calling addPageUnloadEventListener as that also hooks pagehide
122
+ * @returns true - when at least one of the events was registered otherwise false
123
+ */
124
+ export declare function addPageHideEventListener(listener: any, excludeEvents: string[], evtNamespace?: string | string[]): boolean;
125
+ /**
126
+ * Removes the pageHide event listeners added by addPageHideEventListener, because the 'visibilitychange' uses
127
+ * an internal proxy to detect the visibility state you SHOULD use a unique namespace when calling addPageHideEventListener
128
+ * as the remove ignores the listener argument for the 'visibilitychange' event.
129
+ * @param listener - The specific listener to remove for the 'pageshow' event only (ignored for 'visibilitychange')
130
+ * @param evtNamespace - The unique namespace used when calling addPageShowEventListener
131
+ */
132
+ export declare function removePageHideEventListener(listener: any, evtNamespace?: string | string[]): void;
133
+ /**
134
+ * Listen to the pageshow and visibility changing to 'visible' events, because the 'visibilitychange' uses
135
+ * an internal proxy to detect the visibility state you SHOULD use a unique namespace when if you plan to call
136
+ * removePageShowEventListener as the remove ignores the listener argument for the 'visibilitychange' event.
137
+ * @param listener - The event callback to call when a page is show event is triggered
138
+ * @param excludeEvents - [Optional] An array of events that should not be hooked (if possible), unless no other events can be.
139
+ * @param evtNamespace - [Optional/Recommended] A Namespace to append to the event listeners so they can be uniquely
140
+ * identified and removed based on this namespace. This call also adds an additional unique "pageshow" namespace to the events
141
+ * so that only the matching "removePageShowEventListener" can remove these events.
142
+ * @returns true - when at least one of the events was registered otherwise false
143
+ */
144
+ export declare function addPageShowEventListener(listener: any, excludeEvents: string[], evtNamespace?: string | string[]): boolean;
145
+ /**
146
+ * Removes the pageShow event listeners added by addPageShowEventListener, because the 'visibilitychange' uses
147
+ * an internal proxy to detect the visibility state you SHOULD use a unique namespace when calling addPageShowEventListener
148
+ * as the remove ignores the listener argument for the 'visibilitychange' event.
149
+ * @param listener - The specific listener to remove for the 'pageshow' event only (ignored for 'visibilitychange')
150
+ * @param evtNamespace - The unique namespace used when calling addPageShowEventListener
151
+ */
152
+ export declare function removePageShowEventListener(listener: any, evtNamespace?: string | string[]): void;
@@ -12,23 +12,7 @@ export declare function isNotNullOrUndefined(value: any): boolean;
12
12
  export declare function hasOwnProperty(obj: any, prop: string): boolean;
13
13
  export declare function isObject(value: any): boolean;
14
14
  export declare function isFunction(value: any): value is Function;
15
- /**
16
- * Binds the specified function to an event, so that the function gets called whenever the event fires on the object
17
- * @param obj Object to add the event too.
18
- * @param eventNameWithoutOn String that specifies any of the standard DHTML Events without "on" prefix
19
- * @param handlerRef Pointer that specifies the function to call when event fires
20
- * @param useCapture [Optional] Defaults to false
21
- * @returns True if the function was bound successfully to the event, otherwise false
22
- */
23
- export declare function attachEvent(obj: any, eventNameWithoutOn: string, handlerRef: any, useCapture?: boolean): boolean;
24
- /**
25
- * Removes an event handler for the specified event
26
- * @param Object to remove the event from
27
- * @param eventNameWithoutOn {string} - The name of the event
28
- * @param handlerRef {any} - The callback function that needs to be executed for the given event
29
- * @param useCapture [Optional] Defaults to false
30
- */
31
- export declare function detachEvent(obj: any, eventNameWithoutOn: string, handlerRef: any, useCapture?: boolean): void;
15
+ export declare function isPromiseLike<T>(value: any): value is PromiseLike<T>;
32
16
  /**
33
17
  * Validates that the string name conforms to the JS IdentifierName specification and if not
34
18
  * normalizes the name so that it would. This method does not identify or change any keywords
@@ -187,6 +171,7 @@ export declare function objKeys(obj: {}): string[];
187
171
  * @returns True if it was able to create the accessors otherwise false
188
172
  */
189
173
  export declare function objDefineAccessors<T>(target: any, prop: string, getProp?: () => T, setProp?: (v: T) => void): boolean;
174
+ export declare function deepFreeze<T>(obj: T): T;
190
175
  export declare const objFreeze: <T>(value: T) => T;
191
176
  export declare const objSeal: <T>(value: T) => T;
192
177
  /**
@@ -250,6 +235,12 @@ export declare function proxyFunctions<T, S>(target: T, source: S | (() => S), f
250
235
  * @param defaults Simple helper
251
236
  */
252
237
  export declare function createClassFromInterface<T>(defaults?: T): new () => T;
238
+ /**
239
+ * Create an enum style object which has both the key => value and value => key mappings
240
+ * @param values - The values to populate on the new object
241
+ * @returns
242
+ */
243
+ export declare function createEnumStyle<T>(values: T): T;
253
244
  /**
254
245
  * A helper function to assist with JIT performance for objects that have properties added / removed dynamically
255
246
  * this is primarily for chromium based browsers and has limited effects on Firefox and none of IE. Only call this
@@ -0,0 +1,20 @@
1
+ export declare const strEmpty = "";
2
+ export declare const strProcessTelemetry = "processTelemetry";
3
+ export declare const strPriority = "priority";
4
+ export declare const strSetNextPlugin = "setNextPlugin";
5
+ export declare const strIsInitialized = "isInitialized";
6
+ export declare const strTeardown = "teardown";
7
+ export declare const strCore = "core";
8
+ export declare const strUpdate = "update";
9
+ export declare const strDisabled = "disabled";
10
+ export declare const strDoTeardown = "_doTeardown";
11
+ export declare const strProcessNext = "processNext";
12
+ export declare const strResume = "resume";
13
+ export declare const strPause = "pause";
14
+ export declare const strNotificationListener = "NotificationListener";
15
+ export declare const strAddNotificationListener: string;
16
+ export declare const strRemoveNotificationListener: string;
17
+ export declare const strEventsSent = "eventsSent";
18
+ export declare const strEventsDiscarded = "eventsDiscarded";
19
+ export declare const strEventsSendRequest = "eventsSendRequest";
20
+ export declare const strPerfEvent = "perfEvent";