@microsoft/applicationinsights-core-js 2.8.0-beta.2203-09 → 2.8.0-beta.2203-12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/browser/applicationinsights-core-js.integrity.json +9 -9
  2. package/browser/applicationinsights-core-js.js +47 -14
  3. package/browser/applicationinsights-core-js.js.map +1 -1
  4. package/browser/applicationinsights-core-js.min.js +2 -2
  5. package/browser/applicationinsights-core-js.min.js.map +1 -1
  6. package/dist/applicationinsights-core-js.api.json +493 -58
  7. package/dist/applicationinsights-core-js.api.md +42 -23
  8. package/dist/applicationinsights-core-js.d.ts +47 -22
  9. package/dist/applicationinsights-core-js.js +47 -14
  10. package/dist/applicationinsights-core-js.js.map +1 -1
  11. package/dist/applicationinsights-core-js.min.js +2 -2
  12. package/dist/applicationinsights-core-js.min.js.map +1 -1
  13. package/dist/applicationinsights-core-js.rollup.d.ts +48 -23
  14. package/dist-esm/JavaScriptSDK/AppInsightsCore.js +1 -1
  15. package/dist-esm/JavaScriptSDK/BaseCore.js +11 -9
  16. package/dist-esm/JavaScriptSDK/BaseCore.js.map +1 -1
  17. package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js +1 -1
  18. package/dist-esm/JavaScriptSDK/ChannelController.js +4 -2
  19. package/dist-esm/JavaScriptSDK/ChannelController.js.map +1 -1
  20. package/dist-esm/JavaScriptSDK/Constants.js +1 -1
  21. package/dist-esm/JavaScriptSDK/CookieMgr.js +1 -1
  22. package/dist-esm/JavaScriptSDK/CoreUtils.js +1 -1
  23. package/dist-esm/JavaScriptSDK/DataCacheHelper.js +2 -2
  24. package/dist-esm/JavaScriptSDK/DataCacheHelper.js.map +1 -1
  25. package/dist-esm/JavaScriptSDK/DbgExtensionUtils.js +1 -1
  26. package/dist-esm/JavaScriptSDK/DiagnosticLogger.js +1 -1
  27. package/dist-esm/JavaScriptSDK/EnvUtils.js +1 -1
  28. package/dist-esm/JavaScriptSDK/EventHelpers.js +2 -6
  29. package/dist-esm/JavaScriptSDK/EventHelpers.js.map +1 -1
  30. package/dist-esm/JavaScriptSDK/HelperFuncs.js +7 -7
  31. package/dist-esm/JavaScriptSDK/HelperFuncs.js.map +1 -1
  32. package/dist-esm/JavaScriptSDK/InstrumentHooks.js +1 -1
  33. package/dist-esm/JavaScriptSDK/InternalConstants.js +1 -1
  34. package/dist-esm/JavaScriptSDK/NotificationManager.js +1 -1
  35. package/dist-esm/JavaScriptSDK/PerfManager.js +1 -1
  36. package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js +4 -2
  37. package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js.map +1 -1
  38. package/dist-esm/JavaScriptSDK/RandomHelper.js +1 -1
  39. package/dist-esm/JavaScriptSDK/TelemetryHelpers.js +29 -2
  40. package/dist-esm/JavaScriptSDK/TelemetryHelpers.js.map +1 -1
  41. package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js +1 -1
  42. package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js +1 -1
  43. package/dist-esm/JavaScriptSDK.Enums/EventsDiscardedReason.js +1 -1
  44. package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js +1 -1
  45. package/dist-esm/JavaScriptSDK.Enums/SendRequestReason.js +1 -1
  46. package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js +1 -1
  47. package/dist-esm/JavaScriptSDK.Enums/TelemetryUpdateReason.js +1 -1
  48. package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js +1 -1
  49. package/dist-esm/JavaScriptSDK.Interfaces/IChannelControls.js +1 -1
  50. package/dist-esm/JavaScriptSDK.Interfaces/IConfiguration.js +1 -1
  51. package/dist-esm/JavaScriptSDK.Interfaces/ICookieMgr.js +1 -1
  52. package/dist-esm/JavaScriptSDK.Interfaces/IDbgExtension.js +1 -1
  53. package/dist-esm/JavaScriptSDK.Interfaces/IDiagnosticLogger.js +1 -1
  54. package/dist-esm/JavaScriptSDK.Interfaces/IInstrumentHooks.js +1 -1
  55. package/dist-esm/JavaScriptSDK.Interfaces/INotificationListener.js +1 -1
  56. package/dist-esm/JavaScriptSDK.Interfaces/INotificationManager.js +1 -1
  57. package/dist-esm/JavaScriptSDK.Interfaces/IPerfEvent.js +1 -1
  58. package/dist-esm/JavaScriptSDK.Interfaces/IPerfManager.js +1 -1
  59. package/dist-esm/JavaScriptSDK.Interfaces/IProcessTelemetryContext.js +1 -1
  60. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js +1 -1
  61. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryItem.js +1 -1
  62. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPlugin.js +1 -1
  63. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js +1 -1
  64. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js +1 -1
  65. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUpdateState.js +1 -1
  66. package/dist-esm/JavaScriptSDK.Interfaces/IUnloadableComponent.js +6 -0
  67. package/dist-esm/JavaScriptSDK.Interfaces/IUnloadableComponent.js.map +1 -0
  68. package/dist-esm/applicationinsights-core-js.js +3 -3
  69. package/dist-esm/applicationinsights-core-js.js.map +1 -1
  70. package/package.json +2 -2
  71. package/src/JavaScriptSDK/BaseCore.ts +27 -25
  72. package/src/JavaScriptSDK/BaseTelemetryPlugin.ts +1 -1
  73. package/src/JavaScriptSDK/ChannelController.ts +4 -2
  74. package/src/JavaScriptSDK/CoreUtils.ts +1 -1
  75. package/src/JavaScriptSDK/DataCacheHelper.ts +1 -1
  76. package/src/JavaScriptSDK/DiagnosticLogger.ts +1 -1
  77. package/src/JavaScriptSDK/EnvUtils.ts +1 -1
  78. package/src/JavaScriptSDK/EventHelpers.ts +14 -18
  79. package/src/JavaScriptSDK/HelperFuncs.ts +30 -30
  80. package/src/JavaScriptSDK/InstrumentHooks.ts +1 -1
  81. package/src/JavaScriptSDK/PerfManager.ts +3 -6
  82. package/src/JavaScriptSDK/ProcessTelemetryContext.ts +16 -14
  83. package/src/JavaScriptSDK/RandomHelper.ts +1 -1
  84. package/src/JavaScriptSDK/TelemetryHelpers.ts +34 -2
  85. package/src/JavaScriptSDK.Enums/TelemetryUnloadReason.ts +1 -1
  86. package/src/JavaScriptSDK.Enums/TelemetryUpdateReason.ts +1 -1
  87. package/src/JavaScriptSDK.Interfaces/IProcessTelemetryContext.ts +1 -1
  88. package/src/JavaScriptSDK.Interfaces/ITelemetryUpdateState.ts +1 -1
  89. package/src/JavaScriptSDK.Interfaces/IUnloadableComponent.ts +17 -0
  90. package/types/JavaScriptSDK/EventHelpers.d.ts +10 -10
  91. package/types/JavaScriptSDK/HelperFuncs.d.ts +10 -10
  92. package/types/JavaScriptSDK/PerfManager.d.ts +1 -1
  93. package/types/JavaScriptSDK/ProcessTelemetryContext.d.ts +2 -2
  94. package/types/JavaScriptSDK/TelemetryHelpers.d.ts +13 -1
  95. package/types/JavaScriptSDK.Interfaces/IProcessTelemetryContext.d.ts +1 -1
  96. package/types/JavaScriptSDK.Interfaces/IUnloadableComponent.d.ts +13 -0
  97. package/types/applicationinsights-core-js.d.ts +4 -3
  98. package/types/tsdoc-metadata.json +1 -1
@@ -303,7 +303,7 @@ export abstract class BaseTelemetryPlugin implements ITelemetryPlugin {
303
303
  * @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.
304
304
  * @returns boolean - true if the plugin has or will call processNext(), this for backward compatibility as previously teardown was synchronous and returned nothing.
305
305
  */
306
- public teardown(unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState): void | boolean {
306
+ public teardown(unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState): void | boolean {
307
307
  // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
308
308
  return false;
309
309
  }
@@ -61,7 +61,7 @@ export function createChannelControllerPlugin(channelQueue: _IInternalChannels[]
61
61
  return createProcessTelemetryContext(null, core.config, core, null)
62
62
  }
63
63
 
64
- function _processChannelQueue<T extends IBaseProcessingContext>(theChannels: _IInternalChannels[], itemCtx: T, processFn: (chainCtx: T) => void, onComplete: () => void) {
64
+ function _processChannelQueue<T extends IBaseProcessingContext>(theChannels: _IInternalChannels[], itemCtx: T, processFn: (chainCtx: T) => void, onComplete: (() => void) | null) {
65
65
  let waiting = theChannels ? (theChannels.length + 1) : 1;
66
66
 
67
67
  function _runChainOnComplete() {
@@ -160,7 +160,9 @@ export function createChannelControllerPlugin(channelQueue: _IInternalChannels[]
160
160
  }
161
161
  });
162
162
  },
163
- isInitialized: () => { return isInitialized },
163
+ isInitialized: () => {
164
+ return isInitialized
165
+ },
164
166
  processTelemetry: (item: ITelemetryItem, itemCtx: IProcessTelemetryContext) => {
165
167
  _processChannelQueue(channelQueue, itemCtx || _getTelCtx(), (chainCtx: IProcessTelemetryContext) => {
166
168
  chainCtx[strProcessNext](item);
@@ -410,7 +410,7 @@ export const EventHelper: IEventHelper = {
410
410
  * @param logger
411
411
  * @returns
412
412
  */
413
- export function _legacyCookieMgr(config?: IConfiguration, logger?: IDiagnosticLogger): ICookieMgr {
413
+ export function _legacyCookieMgr(config?: IConfiguration, logger?: IDiagnosticLogger): ICookieMgr {
414
414
  let cookieMgr = _gblCookieMgr(config, logger);
415
415
  let legacyCanUseCookies = (CoreUtils as any)._canUseCookies;
416
416
 
@@ -7,7 +7,7 @@ import { newId } from "./RandomHelper";
7
7
 
8
8
  const _objDefineProperty = ObjDefineProperty;
9
9
 
10
- const version = "2.7.3";
10
+ const version = "2.8.0-beta.2203-12";
11
11
  let instanceName = "." + newId(6);
12
12
  let _dataUid = 0;
13
13
 
@@ -165,7 +165,7 @@ export class DiagnosticLogger implements IDiagnosticLogger {
165
165
  * This will write an error to the console if possible
166
166
  * @param message {string} - The error message
167
167
  */
168
- _self.errorToConsole = (message: string) => {
168
+ _self.errorToConsole = (message: string) => {
169
169
  _logToConsole("error", message);
170
170
  _debugExtMsg("error", message);
171
171
  }
@@ -357,7 +357,7 @@ export function isSafari(userAgentStr ?: string) {
357
357
  * Checks if HTML5 Beacons are supported in the current environment.
358
358
  * @returns True if supported, false otherwise.
359
359
  */
360
- export function isBeaconsSupported(): boolean {
360
+ export function isBeaconsSupported(): boolean {
361
361
  if (_beaconsSupported === null) {
362
362
  _beaconsSupported = hasNavigator() && Boolean(getNavigator().sendBeacon);
363
363
  }
@@ -52,7 +52,7 @@ function _normalizeNamespace(name: string) {
52
52
  return name;
53
53
  }
54
54
 
55
- function _getEvtNamespace(eventName: string, evtNamespace?: string | string[]): IEventDetails {
55
+ function _getEvtNamespace(eventName: string | undefined, evtNamespace?: string | string[] | null): IEventDetails {
56
56
  if (evtNamespace) {
57
57
  let theNamespace: string = "";
58
58
  if (isArray(evtNamespace)) {
@@ -81,7 +81,7 @@ function _getEvtNamespace(eventName: string, evtNamespace?: string | string[]):
81
81
  }
82
82
  }
83
83
 
84
- let parsedEvent: any[] = (eventNamespace.exec(eventName) || []);
84
+ let parsedEvent: any[] = (eventNamespace.exec(eventName || "") || []);
85
85
 
86
86
  return {
87
87
  type: parsedEvent[1],
@@ -195,7 +195,7 @@ function _unregisterEvents(target: any, evtName: IEventDetails, unRegFn: (regEve
195
195
  }
196
196
  }
197
197
 
198
- export function mergeEvtNamespace(theNamespace: string, namespaces: string | string[]): string | string[] {
198
+ export function mergeEvtNamespace(theNamespace: string, namespaces?: string | string[] | null): string | string[] {
199
199
  let newNamespaces: string | string[];
200
200
 
201
201
  if (namespaces) {
@@ -225,7 +225,7 @@ export function mergeEvtNamespace(theNamespace: string, namespaces: string | str
225
225
  * @param useCapture [Optional] Defaults to false
226
226
  * @returns True if the function was bound successfully to the event, otherwise false
227
227
  */
228
- export function eventOn<T>(target: T, eventName: string, handlerRef: any, evtNamespace?: string | string[], useCapture: boolean = false) {
228
+ export function eventOn<T>(target: T, eventName: string, handlerRef: any, evtNamespace?: string | string[] | null, useCapture: boolean = false) {
229
229
  let result = false;
230
230
 
231
231
  if (target) {
@@ -263,7 +263,7 @@ export function eventOn<T>(target: T, eventName: string, handlerRef: any, evtNam
263
263
  * if the eventName also includes a namespace the namespace(s) are merged into a single namespace
264
264
  * @param useCapture [Optional] Defaults to false
265
265
  */
266
- export function eventOff<T>(target: T, eventName: string, handlerRef: any, evtNamespace?: string | string[], useCapture: boolean = false) {
266
+ export function eventOff<T>(target: T, eventName: string, handlerRef: any, evtNamespace?: string | string[] | null, useCapture: boolean = false) {
267
267
  if (target) {
268
268
  try {
269
269
  let evtName = _getEvtNamespace(eventName, evtNamespace);
@@ -296,7 +296,7 @@ export function eventOn<T>(target: T, eventName: string, handlerRef: any, evtNam
296
296
  * @param useCapture [Optional] Defaults to false
297
297
  * @returns True if the function was bound successfully to the event, otherwise false
298
298
  */
299
- export function attachEvent(obj: any, eventNameWithoutOn: string, handlerRef: any, useCapture: boolean = false) {
299
+ export function attachEvent(obj: any, eventNameWithoutOn: string, handlerRef: any, useCapture: boolean = false) {
300
300
  return eventOn(obj, eventNameWithoutOn, handlerRef, null, useCapture);
301
301
  }
302
302
 
@@ -321,7 +321,7 @@ export function detachEvent(obj: any, eventNameWithoutOn: string, handlerRef: an
321
321
  * @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.
322
322
  * @return {boolean} - true if the handler was successfully added
323
323
  */
324
- export function addEventHandler(eventName: string, callback: any, evtNamespace?: string | string[]): boolean {
324
+ export function addEventHandler(eventName: string, callback: any, evtNamespace?: string | string[] | null): boolean {
325
325
  let result = false;
326
326
  let w = getWindow();
327
327
  if (w) {
@@ -346,7 +346,7 @@ export function detachEvent(obj: any, eventNameWithoutOn: string, handlerRef: an
346
346
  * otherwise this will only remove events with this specific handler.
347
347
  * @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.
348
348
  */
349
- export function removeEventHandler(eventName: string, callback: any, evtNamespace?: string | string[]) {
349
+ export function removeEventHandler(eventName: string, callback: any, evtNamespace?: string | string[] | null) {
350
350
  let w = getWindow();
351
351
  if (w) {
352
352
  eventOff(w, eventName, callback, evtNamespace);
@@ -367,7 +367,7 @@ export function detachEvent(obj: any, eventNameWithoutOn: string, handlerRef: an
367
367
  * @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.
368
368
  * @returns true - when at least one of the events was registered otherwise false
369
369
  */
370
- function _addEventListeners(events: string[], listener: any, excludeEvents: string[], evtNamespace: string | string[]): boolean {
370
+ function _addEventListeners(events: string[], listener: any, excludeEvents?: string[] | null, evtNamespace?: string | string[] | null): boolean {
371
371
  let added = false;
372
372
 
373
373
  if (listener && events && events.length > 0) {
@@ -391,7 +391,6 @@ function _addEventListeners(events: string[], listener: any, excludeEvents: stri
391
391
  * @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.
392
392
  * @returns true - when at least one of the events was registered otherwise false
393
393
  */
394
- // export function addEventListeners(events: string[], listener: any, excludeEvents?: string[], evtNamespace?: string): boolean {
395
394
  export function addEventListeners(events: string[], listener: any, excludeEvents?: string[], evtNamespace?: string | string[]): boolean {
396
395
  let added = false;
397
396
 
@@ -434,8 +433,7 @@ export function removeEventListeners(events: string[], listener: any, evtNamespa
434
433
  * @param evtNamespace - [Optional] Namespace(s) to append to the event listeners so they can be uniquely identified and removed based on this namespace.
435
434
  * @returns true - when at least one of the events was registered otherwise false
436
435
  */
437
- //export function addPageUnloadEventListener(listener: any, excludeEvents?: string[], evtNamespace?: string): boolean {
438
- export function addPageUnloadEventListener(listener: any, excludeEvents: string[], evtNamespace?: string | string[]): boolean {
436
+ export function addPageUnloadEventListener(listener: any, excludeEvents?: string[], evtNamespace?: string | string[]): boolean {
439
437
  // Hook the unload event for the document, window and body to ensure that the client events are flushed to the server
440
438
  // As just hooking the window does not always fire (on chrome) for page navigation's.
441
439
  return addEventListeners([strBeforeUnload, strUnload, strPageHide], listener, excludeEvents, evtNamespace);
@@ -464,8 +462,7 @@ export function removePageUnloadEventListener(listener: any, evtNamespace?: stri
464
462
  * Suggestion: pass as true if you are also calling addPageUnloadEventListener as that also hooks pagehide
465
463
  * @returns true - when at least one of the events was registered otherwise false
466
464
  */
467
- //export function addPageHideEventListener(listener: any, excludeEvents?: string[], evtNamespace?: string): boolean {
468
- export function addPageHideEventListener(listener: any, excludeEvents: string[], evtNamespace?: string | string[]): boolean {
465
+ export function addPageHideEventListener(listener: any, excludeEvents?: string[] | null, evtNamespace?: string | string[] | null): boolean {
469
466
 
470
467
  function _handlePageVisibility(evt: any) {
471
468
  let doc = getDocument();
@@ -498,7 +495,7 @@ export function addPageHideEventListener(listener: any, excludeEvents: string[],
498
495
  * @param evtNamespace - The unique namespace used when calling addPageShowEventListener
499
496
  */
500
497
 
501
- export function removePageHideEventListener(listener: any, evtNamespace?: string | string[]) {
498
+ export function removePageHideEventListener(listener: any, evtNamespace?: string | string[] | null) {
502
499
  // add the unique page show namespace to any provided namespace so we only remove the ones added by "pagehide"
503
500
  let newNamespaces = mergeEvtNamespace(strPageHideNamespace, evtNamespace);
504
501
  removeEventListeners([strPageHide], listener, newNamespaces);
@@ -516,8 +513,7 @@ export function removePageHideEventListener(listener: any, evtNamespace?: string
516
513
  * so that only the matching "removePageShowEventListener" can remove these events.
517
514
  * @returns true - when at least one of the events was registered otherwise false
518
515
  */
519
- //export function addPageShowEventListener(listener: any, excludeEvents?: string[], evtNamespace?: string): boolean {
520
- export function addPageShowEventListener(listener: any, excludeEvents: string[], evtNamespace?: string | string[]): boolean {
516
+ export function addPageShowEventListener(listener: any, excludeEvents?: string[] | null, evtNamespace?: string | string[] | null): boolean {
521
517
 
522
518
  function _handlePageVisibility(evt: any) {
523
519
  let doc = getDocument();
@@ -546,7 +542,7 @@ export function addPageShowEventListener(listener: any, excludeEvents: string[],
546
542
  * @param listener - The specific listener to remove for the 'pageshow' event only (ignored for 'visibilitychange')
547
543
  * @param evtNamespace - The unique namespace used when calling addPageShowEventListener
548
544
  */
549
- export function removePageShowEventListener(listener: any, evtNamespace?: string | string[]) {
545
+ export function removePageShowEventListener(listener: any, evtNamespace?: string | string[] | null) {
550
546
  // add the unique page show namespace to any provided namespace so we only remove the ones added by "pageshow"
551
547
  let newNamespaces = mergeEvtNamespace(strPageShowNamespace, evtNamespace);
552
548
  removeEventListeners([strPageShow], listener, newNamespaces);
@@ -22,9 +22,9 @@ const strToString = "toString";
22
22
  * Constant string defined to support minimization
23
23
  * @ignore
24
24
  */
25
- const str__Proto = "__proto__";
25
+ const str__Proto = "__proto__";
26
26
 
27
- /**
27
+ /**
28
28
  * Constant string defined to support minimization
29
29
  * @ignore
30
30
  */
@@ -58,27 +58,27 @@ const rLeadingNumeric = /^(\d+[\w\d_$])/;
58
58
  * Pre-lookup to check if we are running on a modern browser (i.e. not IE8)
59
59
  * @ignore
60
60
  */
61
- let _objGetPrototypeOf = Object["getPrototypeOf"];
61
+ let _objGetPrototypeOf = Object["getPrototypeOf"];
62
62
 
63
- /**
63
+ /**
64
64
  * Helper used to get the prototype of the target object as getPrototypeOf is not available in an ES3 environment.
65
65
  * @ignore
66
66
  */
67
- export function _getObjProto(target:any) {
68
- if (target) {
69
- // This method doesn't existing in older browsers (e.g. IE8)
70
- if (_objGetPrototypeOf) {
71
- return _objGetPrototypeOf(target);
72
- }
67
+ export function _getObjProto(target:any) {
68
+ if (target) {
69
+ // This method doesn't existing in older browsers (e.g. IE8)
70
+ if (_objGetPrototypeOf) {
71
+ return _objGetPrototypeOf(target);
72
+ }
73
73
 
74
- // target[Constructor] May break if the constructor has been changed or removed
75
- let newProto = target[str__Proto] || target[strShimPrototype] || target[strConstructor];
76
- if(newProto) {
77
- return newProto;
78
- }
79
- }
74
+ // target[Constructor] May break if the constructor has been changed or removed
75
+ let newProto = target[str__Proto] || target[strShimPrototype] || target[strConstructor];
76
+ if(newProto) {
77
+ return newProto;
78
+ }
79
+ }
80
80
 
81
- return null;
81
+ return null;
82
82
  }
83
83
 
84
84
  export function objToString(obj: any) {
@@ -89,19 +89,19 @@ export function isTypeof(value: any, theType: string): boolean {
89
89
  return typeof value === theType;
90
90
  }
91
91
 
92
- export function isUndefined(value: any): boolean {
92
+ export function isUndefined(value: any): value is undefined {
93
93
  return value === undefined || typeof value === strShimUndefined;
94
94
  }
95
95
 
96
- export function isNotUndefined(value: any): boolean {
96
+ export function isNotUndefined<T>(value: T): value is T {
97
97
  return !isUndefined(value);
98
98
  }
99
99
 
100
- export function isNullOrUndefined(value: any): boolean {
100
+ export function isNullOrUndefined(value: any): value is null | undefined {
101
101
  return (value === null || isUndefined(value));
102
102
  }
103
103
 
104
- export function isNotNullOrUndefined(value: any): boolean {
104
+ export function isNotNullOrUndefined<T>(value: T): value is T {
105
105
  return !isNullOrUndefined(value);
106
106
  }
107
107
 
@@ -109,7 +109,7 @@ export function hasOwnProperty(obj: any, prop: string): boolean {
109
109
  return !!(obj && ObjHasOwnProperty.call(obj, prop));
110
110
  }
111
111
 
112
- export function isObject(value: any): boolean {
112
+ export function isObject<T>(value: T): value is T {
113
113
  // Changing to inline for performance
114
114
  return !!(value && typeof value === strShimObject);
115
115
  }
@@ -186,7 +186,7 @@ export function strEndsWith(value: string, search: string) {
186
186
  * @param search - The characters to be searched for at the end of the value.
187
187
  * @returns true if the given search value is found at the end of the string, otherwise false.
188
188
  */
189
- export function _strEndsWithPoly(value: string, search: string) {
189
+ export function _strEndsWithPoly(value: string, search: string) {
190
190
  let result = false;
191
191
  let searchLen = search ? search.length : 0;
192
192
  let valLen = value ? value.length : 0;
@@ -214,7 +214,7 @@ export function strEndsWith(value: string, search: string) {
214
214
  export function strStartsWith(value: string, checkValue: string) {
215
215
  let result = false;
216
216
  if (value && checkValue && !(result = value === checkValue)) {
217
- // For Performance try and use the native instance, using string lookup of the function to easily pass the ES3 build checks and minification
217
+ // For Performance try and use the native instance, using string lookup of the function to easily pass the ES3 build checks and minification
218
218
  result = _strStartsWith ? value[cStrStartsWith](checkValue) : _strStartsWithPoly(value, checkValue);
219
219
  }
220
220
 
@@ -227,7 +227,7 @@ export function strStartsWith(value: string, checkValue: string) {
227
227
  * @param checkValue - The characters to be searched for at the start of the value.
228
228
  * @returns true if the given search value is found at the start of the string, otherwise false.
229
229
  */
230
- export function _strStartsWithPoly(value: string, checkValue: string) {
230
+ export function _strStartsWithPoly(value: string, checkValue: string) {
231
231
  // Using helper for performance and because string startsWith() is not available on IE
232
232
  let result = false;
233
233
  let chkLen = checkValue ? checkValue.length : 0;
@@ -328,7 +328,7 @@ export function isPlainObject(value: any): boolean {
328
328
  let result: boolean = false;
329
329
 
330
330
  if (value && typeof value === "object") {
331
- // Inlining _objGetPrototypeOf for performance to avoid an additional function call
331
+ // Inlining _objGetPrototypeOf for performance to avoid an additional function call
332
332
  let proto = _objGetPrototypeOf ? _objGetPrototypeOf(value) : _getObjProto(value);
333
333
  if (!proto) {
334
334
  // No prototype found so this is a plain Object eg. 'Object.create(null)'
@@ -389,7 +389,7 @@ export function _toISOStringPoly(date: Date) {
389
389
  * @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array. It can return -1 to break out of the loop
390
390
  * @param thisArg [Optional] An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
391
391
  */
392
- export function arrForEach<T = any>(arr: T[], callbackfn: (value: T, index?: number, array?: T[]) => void|number, thisArg?: any): void {
392
+ export function arrForEach<T = any>(arr: T[], callbackfn: (value: T, index?: number, array?: T[]) => undefined | void | number, thisArg?: any): void {
393
393
  let len = arr.length;
394
394
  try {
395
395
  for (let idx = 0; idx < len; idx++) {
@@ -661,7 +661,7 @@ export function getExceptionName(object: any): string {
661
661
  * @param srcChk - [Optional] Callback to check to original value that if supplied will be called if the new value should be set (if allowed)
662
662
  * @returns The existing or new value, depending what was set
663
663
  */
664
- export function setValue<T, K extends keyof T>(target: T, field: K, value: T[K], valChk?: (value: T[K]) => boolean, srcChk?: (value: T[K]) => boolean) {
664
+ export function setValue<T, K extends keyof T>(target: T, field: K, value: T[K], valChk?: ((value: T[K]) => boolean) | null, srcChk?: ((value: T[K]) => boolean) | null) {
665
665
  let theValue = value;
666
666
  if (target) {
667
667
  theValue = target[field];
@@ -796,7 +796,7 @@ export function proxyFunctionAs<T, S>(target: T, name: string, source: S | (() =
796
796
  * @param source - The source object which will be assigned / called by setting / calling the targets proxies
797
797
  * @param functionsToProxy - An array of function names that will be proxied on the target
798
798
  */
799
- export function proxyFunctions<T, S>(target: T, source: S | (() => S), functionsToProxy: (keyof S)[], overwriteTarget: boolean = true) {
799
+ export function proxyFunctions<T, S>(target: T, source: S | (() => S), functionsToProxy: (keyof S)[], overwriteTarget: boolean = true) {
800
800
  if (target && source && isObject(target) && isArray(functionsToProxy)) {
801
801
  arrForEach(functionsToProxy, (theFuncName) => {
802
802
  if (isString(theFuncName)) {
@@ -888,7 +888,7 @@ export function objExtend<T1, T2, T3, T4, T5, T6>(obj1?: T1 | any, obj2?: T2, ob
888
888
  idx++;
889
889
  }
890
890
 
891
- // Handle case when target is a string or something (possible in deep copy)
891
+ // Handle case when target is a string or something (possible in deep copy)
892
892
  if (!isObject(extended)) {
893
893
  extended = {} as T1 & T2 & T3 & T4 & T5 & T6;
894
894
  }
@@ -73,7 +73,7 @@ function _doCallbacks(hooks:IInstrumentHook[], callDetails: IInstrumentCallDetai
73
73
  function _createFunctionHook(aiHook:IInstrumentHooks) {
74
74
 
75
75
  // Define a temporary method that queues-up a the real method call
76
- return function () {
76
+ return function (this: any) {
77
77
  let funcThis = this;
78
78
  // Capture the original arguments passed to the method
79
79
  let orgArgs = arguments as any;
@@ -104,12 +104,9 @@ export class PerfEvent implements IPerfEvent {
104
104
  _self.isChildEvt = (): boolean => true;
105
105
  }
106
106
  _self[key] = value;
107
- }
108
- else if (key === PerfEvent.ChildrenContextKey) {
107
+ } else if (key === PerfEvent.ChildrenContextKey) {
109
108
  _self[key] = value;
110
- }
111
- else
112
- {
109
+ } else {
113
110
  let ctx = _self[strExecutionContextKey] = _self[strExecutionContextKey] || {};
114
111
  ctx[key] = value;
115
112
  }
@@ -146,7 +143,7 @@ export class PerfManager implements IPerfManager {
146
143
  */
147
144
  private ctx: { [key: string] : any } = {};
148
145
 
149
- constructor(manager: INotificationManager) {
146
+ constructor(manager?: INotificationManager) {
150
147
 
151
148
  dynamicProto(PerfManager, this, (_self) => {
152
149
 
@@ -26,7 +26,7 @@ const strGetTelCtx = "_getTelCtx";
26
26
  let _chainId = 0;
27
27
 
28
28
  interface OnCompleteCallback {
29
- func: Function;
29
+ func: () => void;
30
30
  self: any; // This for the function
31
31
  args: any[]; // Additional arguments for the function
32
32
  }
@@ -67,7 +67,7 @@ function _getNextProxyStart(proxy: ITelemetryPluginChain, config: IConfiguration
67
67
  function _createInternalContext<T extends IBaseProcessingContext>(telemetryChain: ITelemetryPluginChain, config: IConfiguration, core:IAppInsightsCore, startAt?: IPlugin): IInternalContext<T> {
68
68
  // We have a special case where we want to start execution from this specific plugin
69
69
  // or we simply reuse the existing telemetry plugin chain (normal execution case)
70
- let _nextProxy: ITelemetryPluginChain = null; // By Default set as no next plugin
70
+ let _nextProxy: ITelemetryPluginChain | null = null; // By Default set as no next plugin
71
71
  let _onComplete: OnCompleteCallback[] = [];
72
72
 
73
73
  if (startAt !== null) {
@@ -78,7 +78,9 @@ function _createInternalContext<T extends IBaseProcessingContext>(telemetryChain
78
78
  let context: IInternalContext<T> = {
79
79
  _next: _moveNext,
80
80
  ctx: {
81
- core: () => { return core },
81
+ core: () => {
82
+ return core
83
+ },
82
84
  diagLog: () => {
83
85
  return safeGetLogger(core, config);
84
86
  },
@@ -101,7 +103,7 @@ function _createInternalContext<T extends IBaseProcessingContext>(telemetryChain
101
103
  } as T
102
104
  };
103
105
 
104
- function _addOnComplete(onComplete: Function, that?: any, ...args: any[]) {
106
+ function _addOnComplete(onComplete: () => void, that?: any, ...args: any[]) {
105
107
  if (onComplete) {
106
108
  _onComplete.push({
107
109
  func: onComplete,
@@ -209,7 +211,7 @@ function _createInternalContext<T extends IBaseProcessingContext>(telemetryChain
209
211
  * @param core - The current core instance
210
212
  * @param startAt - Identifies the next plugin to execute, if null there is no "next" plugin and if undefined it should assume the start of the chain
211
213
  */
212
- export function createProcessTelemetryContext(telemetryChain: ITelemetryPluginChain, config: IConfiguration, core:IAppInsightsCore, startAt?: IPlugin): IProcessTelemetryContext {
214
+ export function createProcessTelemetryContext(telemetryChain: ITelemetryPluginChain | null, config: IConfiguration, core:IAppInsightsCore, startAt?: IPlugin): IProcessTelemetryContext {
213
215
  let internalContext: IInternalContext<IProcessTelemetryContext> = _createInternalContext<IProcessTelemetryContext>(telemetryChain, config, core, startAt);
214
216
  let context = internalContext.ctx;
215
217
 
@@ -221,7 +223,7 @@ export function createProcessTelemetryContext(telemetryChain: ITelemetryPluginCh
221
223
  return !nextPlugin;
222
224
  }
223
225
 
224
- function _createNew(plugins: IPlugin[] | ITelemetryPluginChain = null, startAt?: IPlugin) {
226
+ function _createNew(plugins: IPlugin[] | ITelemetryPluginChain | null = null, startAt?: IPlugin) {
225
227
  if (isArray(plugins)) {
226
228
  plugins = createTelemetryProxyChain(plugins, config, core, startAt);
227
229
  }
@@ -274,7 +276,7 @@ export function createProcessTelemetryUnloadContext(telemetryChain: ITelemetryPl
274
276
  * @param core - The current core instance
275
277
  * @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
276
278
  */
277
- export function createProcessTelemetryUpdateContext(telemetryChain: ITelemetryPluginChain, config: IConfiguration, core:IAppInsightsCore, startAt?: IPlugin): IProcessTelemetryUpdateContext {
279
+ export function createProcessTelemetryUpdateContext(telemetryChain: ITelemetryPluginChain, config: IConfiguration, core:IAppInsightsCore, startAt?: IPlugin): IProcessTelemetryUpdateContext {
278
280
  let internalContext: IInternalContext<IProcessTelemetryUpdateContext> = _createInternalContext<IProcessTelemetryUpdateContext>(telemetryChain, config, core, startAt);
279
281
  let context = internalContext.ctx;
280
282
 
@@ -307,7 +309,7 @@ export function createProcessTelemetryUnloadContext(telemetryChain: ITelemetryPl
307
309
  * should be for legacy plugins only. Currently, only used for passing the current core instance and to provide better error
308
310
  * reporting (hasRun) when errors occur.
309
311
  */
310
- export function createTelemetryProxyChain(plugins: IPlugin[], config: IConfiguration, core: IAppInsightsCore, startAt?: IPlugin): ITelemetryPluginChain {
312
+ export function createTelemetryProxyChain(plugins: IPlugin[], config: IConfiguration, core: IAppInsightsCore, startAt?: IPlugin): ITelemetryPluginChain {
311
313
  let firstProxy: ITelemetryPluginChain = null;
312
314
  let add = startAt ? false : true;
313
315
 
@@ -399,11 +401,11 @@ export function createTelemetryPluginProxy(plugin: ITelemetryPlugin, config: ICo
399
401
  }
400
402
 
401
403
  function _processChain<T extends IBaseProcessingContext>(
402
- itemCtx: T,
403
- processPluginFn: (itemCtx: T) => boolean,
404
- name: string,
405
- details: () => any,
406
- isAsync: boolean) {
404
+ itemCtx: T,
405
+ processPluginFn: (itemCtx: T) => boolean,
406
+ name: string,
407
+ details: () => any,
408
+ isAsync: boolean) {
407
409
 
408
410
  let hasRun = false;
409
411
  let identifier = plugin ? plugin.identifier : strTelemetryPluginChain;
@@ -560,7 +562,7 @@ export class ProcessTelemetryContext implements IProcessTelemetryContext {
560
562
 
561
563
  public getExtCfg: <T>(identifier:string, defaultValue?:T|any) => T;
562
564
 
563
- public getConfig: (identifier:string, field: string, defaultValue?: number | string | boolean) => number | string | boolean;
565
+ public getConfig: (identifier:string, field: string, defaultValue?: number | string | boolean | string[] | RegExp[] | Function) => number | string | boolean | string[] | RegExp[] | Function;
564
566
 
565
567
  /**
566
568
  * Returns the IAppInsightsCore instance for the current request
@@ -122,7 +122,7 @@ export function mwcRandom32(signed?: boolean) {
122
122
  * The default length is 22 which is 132-bits so almost the same as a GUID but as base64 (the previous default was 5)
123
123
  * @param maxLength - Optional value to specify the length of the id to be generated, defaults to 22
124
124
  */
125
- export function newId(maxLength = 22): string {
125
+ export function newId(maxLength = 22): string {
126
126
  const base64chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
127
127
 
128
128
  // Start with an initial random number, consuming the value in reverse byte order
@@ -3,13 +3,16 @@
3
3
  "use strict";
4
4
 
5
5
  import { IPlugin, ITelemetryPlugin } from "../JavaScriptSDK.Interfaces/ITelemetryPlugin";
6
- import { IProcessTelemetryContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
6
+ import { IProcessTelemetryContext, IProcessTelemetryUnloadContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
7
7
  import { ITelemetryPluginChain } from "../JavaScriptSDK.Interfaces/ITelemetryPluginChain";
8
8
  import { arrForEach, isFunction } from "./HelperFuncs";
9
- import { strCore, strIsInitialized, strPriority, strProcessTelemetry, strSetNextPlugin, strTeardown } from "./InternalConstants";
9
+ import { strCore, strDoTeardown, strIsInitialized, strPriority, strProcessTelemetry, strSetNextPlugin, strTeardown } from "./InternalConstants";
10
10
  import { createElmNodeData } from "./DataCacheHelper";
11
11
  import { IAppInsightsCore } from "../JavaScriptSDK.Interfaces/IAppInsightsCore";
12
+ import { IUnloadableComponent } from "../JavaScriptSDK.Interfaces/IUnloadableComponent";
13
+ import { ITelemetryUnloadState } from "../JavaScriptSDK.Interfaces/ITelemetryUnloadState";
12
14
 
15
+ const strDoUnload = "_doUnload";
13
16
  export interface IPluginState {
14
17
  core?: IAppInsightsCore;
15
18
  isInitialized?: boolean;
@@ -100,4 +103,33 @@ export function sortPlugins<T = IPlugin>(plugins:T[]) {
100
103
  return result;
101
104
  });
102
105
  // sort complete
106
+ }
107
+
108
+ /**
109
+ * Teardown / Unload helper to perform teardown/unloading operations for the provided components synchronously or asynchronously, this will call any
110
+ * _doTeardown() or _doUnload() functions on the provided components to allow them to finish removal.
111
+ * @param components - The components you want to unload
112
+ * @param unloadCtx - This is the context that should be used during unloading.
113
+ * @param unloadState - The details / state of the unload process, it holds details like whether it should be unloaded synchronously or asynchronously and the reason for the unload.
114
+ * @param asyncCallback - An optional callback that the plugin must call if it returns true to inform the caller that it has completed any async unload/teardown operations.
115
+ * @returns boolean - true if the plugin has or will call asyncCallback, this allows the plugin to perform any asynchronous operations.
116
+ */
117
+ export function unloadComponents(components: any | IUnloadableComponent[], unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState, asyncCallback?: () => void): void | boolean {
118
+ let idx = 0;
119
+
120
+ function _doUnload(): void | boolean {
121
+ while (idx < components.length) {
122
+ let component = components[idx++];
123
+ if (component) {
124
+ let func = component[strDoUnload] || component[strDoTeardown];
125
+ if (isFunction(func)) {
126
+ if (func.call(component, unloadCtx, unloadState, _doUnload) === true) {
127
+ return true;
128
+ }
129
+ }
130
+ }
131
+ }
132
+ }
133
+
134
+ return _doUnload();
103
135
  }
@@ -4,7 +4,7 @@
4
4
  /**
5
5
  * The TelemetryUnloadReason enumeration contains the possible reasons for why a plugin is being unloaded / torndown().
6
6
  */
7
- export const enum TelemetryUnloadReason {
7
+ export const enum TelemetryUnloadReason {
8
8
  /**
9
9
  * Teardown has been called without any context.
10
10
  */
@@ -4,7 +4,7 @@
4
4
  /**
5
5
  * The TelemetryUpdateReason enumeration contains a set of bit-wise values that specify the reason for update request.
6
6
  */
7
- export const enum TelemetryUpdateReason {
7
+ export const enum TelemetryUpdateReason {
8
8
  /**
9
9
  * Unknown.
10
10
  */
@@ -76,7 +76,7 @@ export interface IBaseProcessingContext {
76
76
  * @param that - The "this" value to use for the onComplete call, if not provided or undefined defaults to the current context
77
77
  * @param args - Any additional arguments to pass to the onComplete function
78
78
  */
79
- onComplete: (onComplete: Function, that?: any, ...args: any[]) => void;
79
+ onComplete: (onComplete: () => void, that?: any, ...args: any[]) => void;
80
80
 
81
81
  /**
82
82
  * Create a new context using the core and config from the current instance, returns a new instance of the same type
@@ -2,7 +2,7 @@
2
2
  // Licensed under the MIT License.
3
3
 
4
4
  import { TelemetryUpdateReason } from "../JavaScriptSDK.Enums/TelemetryUpdateReason";
5
- import { IConfiguration } from "./IConfiguration";
5
+ //import { IConfiguration } from "./IConfiguration";
6
6
  import { IPlugin } from "./ITelemetryPlugin";
7
7
 
8
8
  export interface ITelemetryUpdateState {
@@ -0,0 +1,17 @@
1
+ import { IProcessTelemetryUnloadContext } from "./IProcessTelemetryContext";
2
+ import { ITelemetryUnloadState } from "./ITelemetryUnloadState";
3
+
4
+ // Copyright (c) Microsoft Corporation. All rights reserved.
5
+ // Licensed under the MIT License.
6
+
7
+ export interface IUnloadableComponent {
8
+ /**
9
+ * Teardown / Unload hook to allow implementations to perform some additional unload operations before the BaseTelemetryPlugin
10
+ * finishes it's removal.
11
+ * @param unloadCtx - This is the context that should be used during unloading.
12
+ * @param unloadState - The details / state of the unload process, it holds details like whether it should be unloaded synchronously or asynchronously and the reason for the unload.
13
+ * @param asyncCallback - An optional callback that the plugin must call if it returns true to inform the caller that it has completed any async unload/teardown operations.
14
+ * @returns boolean - true if the plugin has or will call asyncCallback, this allows the plugin to perform any asynchronous operations.
15
+ */
16
+ _doUnload?: (unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState, asyncCallback?: () => void) => void | boolean;
17
+ }