@microsoft/applicationinsights-core-js 2.7.5-nightly.2204-03 → 2.7.5-nightly.2204-23

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 +766 -1967
  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 +9840 -16439
  7. package/dist/applicationinsights-core-js.api.md +48 -425
  8. package/dist/applicationinsights-core-js.d.ts +123 -784
  9. package/dist/applicationinsights-core-js.js +766 -1967
  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 +123 -784
  14. package/dist-esm/JavaScriptSDK/AppInsightsCore.js +69 -3
  15. package/dist-esm/JavaScriptSDK/AppInsightsCore.js.map +1 -1
  16. package/dist-esm/JavaScriptSDK/BaseCore.js +99 -496
  17. package/dist-esm/JavaScriptSDK/BaseCore.js.map +1 -1
  18. package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js +21 -120
  19. package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js.map +1 -1
  20. package/dist-esm/JavaScriptSDK/ChannelController.js +87 -202
  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 +148 -7
  26. package/dist-esm/JavaScriptSDK/CoreUtils.js.map +1 -1
  27. package/dist-esm/JavaScriptSDK/DbgExtensionUtils.js +1 -1
  28. package/dist-esm/JavaScriptSDK/DiagnosticLogger.js +14 -27
  29. package/dist-esm/JavaScriptSDK/DiagnosticLogger.js.map +1 -1
  30. package/dist-esm/JavaScriptSDK/EnvUtils.js +12 -13
  31. package/dist-esm/JavaScriptSDK/EnvUtils.js.map +1 -1
  32. package/dist-esm/JavaScriptSDK/HelperFuncs.js +86 -89
  33. package/dist-esm/JavaScriptSDK/HelperFuncs.js.map +1 -1
  34. package/dist-esm/JavaScriptSDK/InstrumentHooks.js +1 -3
  35. package/dist-esm/JavaScriptSDK/InstrumentHooks.js.map +1 -1
  36. package/dist-esm/JavaScriptSDK/NotificationManager.js +42 -37
  37. package/dist-esm/JavaScriptSDK/NotificationManager.js.map +1 -1
  38. package/dist-esm/JavaScriptSDK/PerfManager.js +1 -1
  39. package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js +119 -430
  40. package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js.map +1 -1
  41. package/dist-esm/JavaScriptSDK/RandomHelper.js +4 -30
  42. package/dist-esm/JavaScriptSDK/RandomHelper.js.map +1 -1
  43. package/dist-esm/JavaScriptSDK/TelemetryHelpers.js +14 -60
  44. package/dist-esm/JavaScriptSDK/TelemetryHelpers.js.map +1 -1
  45. package/dist-esm/JavaScriptSDK/TelemetryPluginChain.js +76 -0
  46. package/dist-esm/JavaScriptSDK/TelemetryPluginChain.js.map +1 -0
  47. package/dist-esm/JavaScriptSDK.Enums/EventsDiscardedReason.js +1 -1
  48. package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js +96 -90
  49. package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js.map +1 -1
  50. package/dist-esm/JavaScriptSDK.Enums/SendRequestReason.js +1 -1
  51. package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js +2 -1
  52. package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js.map +1 -1
  53. package/dist-esm/JavaScriptSDK.Interfaces/IChannelControls.js +1 -1
  54. package/dist-esm/JavaScriptSDK.Interfaces/IConfiguration.js +1 -1
  55. package/dist-esm/JavaScriptSDK.Interfaces/ICookieMgr.js +1 -1
  56. package/dist-esm/JavaScriptSDK.Interfaces/IDbgExtension.js +1 -1
  57. package/dist-esm/JavaScriptSDK.Interfaces/IDiagnosticLogger.js +1 -1
  58. package/dist-esm/JavaScriptSDK.Interfaces/IInstrumentHooks.js +1 -1
  59. package/dist-esm/JavaScriptSDK.Interfaces/INotificationListener.js +1 -1
  60. package/dist-esm/JavaScriptSDK.Interfaces/INotificationManager.js +1 -1
  61. package/dist-esm/JavaScriptSDK.Interfaces/IPerfEvent.js +1 -1
  62. package/dist-esm/JavaScriptSDK.Interfaces/IPerfManager.js +1 -1
  63. package/dist-esm/JavaScriptSDK.Interfaces/IProcessTelemetryContext.js +1 -1
  64. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryItem.js +1 -1
  65. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPlugin.js +1 -1
  66. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js +2 -1
  67. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js.map +1 -1
  68. package/dist-esm/applicationinsights-core-js.js +7 -12
  69. package/dist-esm/applicationinsights-core-js.js.map +1 -1
  70. package/package.json +3 -3
  71. package/src/JavaScriptSDK/AppInsightsCore.ts +101 -2
  72. package/src/JavaScriptSDK/BaseCore.ts +120 -696
  73. package/src/JavaScriptSDK/BaseTelemetryPlugin.ts +31 -205
  74. package/src/JavaScriptSDK/ChannelController.ts +103 -242
  75. package/src/JavaScriptSDK/CookieMgr.ts +5 -7
  76. package/src/JavaScriptSDK/CoreUtils.ts +172 -8
  77. package/src/JavaScriptSDK/DiagnosticLogger.ts +14 -29
  78. package/src/JavaScriptSDK/EnvUtils.ts +12 -13
  79. package/src/JavaScriptSDK/HelperFuncs.ts +97 -123
  80. package/src/JavaScriptSDK/InstrumentHooks.ts +2 -4
  81. package/src/JavaScriptSDK/NotificationManager.ts +37 -34
  82. package/src/JavaScriptSDK/PerfManager.ts +7 -4
  83. package/src/JavaScriptSDK/ProcessTelemetryContext.ts +134 -543
  84. package/src/JavaScriptSDK/RandomHelper.ts +3 -35
  85. package/src/JavaScriptSDK/TelemetryHelpers.ts +21 -83
  86. package/src/JavaScriptSDK/TelemetryPluginChain.ts +120 -0
  87. package/src/JavaScriptSDK.Enums/LoggingEnums.ts +87 -184
  88. package/src/JavaScriptSDK.Enums/SendRequestReason.ts +0 -5
  89. package/src/JavaScriptSDK.Interfaces/IAppInsightsCore.ts +2 -82
  90. package/src/JavaScriptSDK.Interfaces/IChannelControls.ts +5 -16
  91. package/src/JavaScriptSDK.Interfaces/IInstrumentHooks.ts +6 -16
  92. package/src/JavaScriptSDK.Interfaces/IProcessTelemetryContext.ts +14 -94
  93. package/src/JavaScriptSDK.Interfaces/ITelemetryPlugin.ts +10 -28
  94. package/src/JavaScriptSDK.Interfaces/ITelemetryPluginChain.ts +11 -9
  95. package/types/JavaScriptSDK/AppInsightsCore.d.ts +21 -0
  96. package/types/JavaScriptSDK/BaseCore.d.ts +3 -81
  97. package/types/JavaScriptSDK/BaseTelemetryPlugin.d.ts +10 -53
  98. package/types/JavaScriptSDK/ChannelController.d.ts +17 -16
  99. package/types/JavaScriptSDK/CoreUtils.d.ts +48 -1
  100. package/types/JavaScriptSDK/DiagnosticLogger.d.ts +0 -10
  101. package/types/JavaScriptSDK/HelperFuncs.d.ts +32 -33
  102. package/types/JavaScriptSDK/PerfManager.d.ts +1 -1
  103. package/types/JavaScriptSDK/ProcessTelemetryContext.d.ts +6 -69
  104. package/types/JavaScriptSDK/RandomHelper.d.ts +0 -6
  105. package/types/JavaScriptSDK/TelemetryHelpers.d.ts +3 -23
  106. package/types/JavaScriptSDK/TelemetryPluginChain.d.ts +32 -0
  107. package/types/JavaScriptSDK.Enums/LoggingEnums.d.ts +2 -91
  108. package/types/JavaScriptSDK.Enums/SendRequestReason.d.ts +0 -4
  109. package/types/JavaScriptSDK.Interfaces/IAppInsightsCore.d.ts +1 -72
  110. package/types/JavaScriptSDK.Interfaces/IChannelControls.d.ts +5 -16
  111. package/types/JavaScriptSDK.Interfaces/IInstrumentHooks.d.ts +0 -9
  112. package/types/JavaScriptSDK.Interfaces/IProcessTelemetryContext.d.ts +11 -82
  113. package/types/JavaScriptSDK.Interfaces/ITelemetryPlugin.d.ts +8 -25
  114. package/types/JavaScriptSDK.Interfaces/ITelemetryPluginChain.d.ts +10 -9
  115. package/types/applicationinsights-core-js.d.ts +9 -18
  116. package/types/tsdoc-metadata.json +1 -1
  117. package/dist-esm/JavaScriptSDK/DataCacheHelper.js +0 -93
  118. package/dist-esm/JavaScriptSDK/DataCacheHelper.js.map +0 -1
  119. package/dist-esm/JavaScriptSDK/EventHelpers.js +0 -477
  120. package/dist-esm/JavaScriptSDK/EventHelpers.js.map +0 -1
  121. package/dist-esm/JavaScriptSDK/InternalConstants.js +0 -28
  122. package/dist-esm/JavaScriptSDK/InternalConstants.js.map +0 -1
  123. package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js +0 -81
  124. package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js.map +0 -1
  125. package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js +0 -33
  126. package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js.map +0 -1
  127. package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js +0 -8
  128. package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js.map +0 -1
  129. package/dist-esm/JavaScriptSDK.Enums/TelemetryUpdateReason.js +0 -8
  130. package/dist-esm/JavaScriptSDK.Enums/TelemetryUpdateReason.js.map +0 -1
  131. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js +0 -6
  132. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js.map +0 -1
  133. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js +0 -8
  134. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js.map +0 -1
  135. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUpdateState.js +0 -8
  136. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUpdateState.js.map +0 -1
  137. package/dist-esm/JavaScriptSDK.Interfaces/IUnloadableComponent.js +0 -6
  138. package/dist-esm/JavaScriptSDK.Interfaces/IUnloadableComponent.js.map +0 -1
  139. package/src/JavaScriptSDK/DataCacheHelper.ts +0 -106
  140. package/src/JavaScriptSDK/EventHelpers.ts +0 -550
  141. package/src/JavaScriptSDK/InternalConstants.ts +0 -26
  142. package/src/JavaScriptSDK/TelemetryInitializerPlugin.ts +0 -111
  143. package/src/JavaScriptSDK/UnloadHandlerContainer.ts +0 -46
  144. package/src/JavaScriptSDK.Enums/TelemetryUnloadReason.ts +0 -27
  145. package/src/JavaScriptSDK.Enums/TelemetryUpdateReason.ts +0 -27
  146. package/src/JavaScriptSDK.Interfaces/ITelemetryInitializers.ts +0 -16
  147. package/src/JavaScriptSDK.Interfaces/ITelemetryUnloadState.ts +0 -10
  148. package/src/JavaScriptSDK.Interfaces/ITelemetryUpdateState.ts +0 -34
  149. package/src/JavaScriptSDK.Interfaces/IUnloadableComponent.ts +0 -17
  150. package/types/JavaScriptSDK/DataCacheHelper.d.ts +0 -13
  151. package/types/JavaScriptSDK/EventHelpers.d.ts +0 -154
  152. package/types/JavaScriptSDK/InternalConstants.d.ts +0 -20
  153. package/types/JavaScriptSDK/TelemetryInitializerPlugin.d.ts +0 -16
  154. package/types/JavaScriptSDK/UnloadHandlerContainer.d.ts +0 -11
  155. package/types/JavaScriptSDK.Enums/TelemetryUnloadReason.d.ts +0 -21
  156. package/types/JavaScriptSDK.Enums/TelemetryUpdateReason.d.ts +0 -20
  157. package/types/JavaScriptSDK.Interfaces/ITelemetryInitializers.d.ts +0 -13
  158. package/types/JavaScriptSDK.Interfaces/ITelemetryUnloadState.d.ts +0 -6
  159. package/types/JavaScriptSDK.Interfaces/ITelemetryUpdateState.d.ts +0 -22
  160. package/types/JavaScriptSDK.Interfaces/IUnloadableComponent.d.ts +0 -13
@@ -2,14 +2,13 @@
2
2
  // Licensed under the MIT License.
3
3
  "use strict"
4
4
  import { IConfiguration } from "../JavaScriptSDK.Interfaces/IConfiguration"
5
- import { _InternalMessageId, _eInternalMessageId, LoggingSeverity, eLoggingSeverity } from "../JavaScriptSDK.Enums/LoggingEnums";
5
+ import { _InternalMessageId, LoggingSeverity } from "../JavaScriptSDK.Enums/LoggingEnums";
6
6
  import { IDiagnosticLogger } from "../JavaScriptSDK.Interfaces/IDiagnosticLogger";
7
- import { hasJSON, getJSON, getConsole } from "./EnvUtils";
7
+ import { hasJSON, getJSON, getConsole, dumpObj } from "./EnvUtils";
8
8
  import dynamicProto from "@microsoft/dynamicproto-js";
9
9
  import { isFunction, isNullOrUndefined, isUndefined } from "./HelperFuncs";
10
10
  import { IAppInsightsCore } from "../JavaScriptSDK.Interfaces/IAppInsightsCore";
11
11
  import { getDebugExt } from "./DbgExtensionUtils";
12
- import { strEmpty } from "./InternalConstants";
13
12
 
14
13
  /**
15
14
  * For user non actionable traces use AI Internal prefix.
@@ -31,10 +30,10 @@ const strWarnToConsole = "warnToConsole";
31
30
 
32
31
  function _sanitizeDiagnosticText(text: string) {
33
32
  if (text) {
34
- return "\"" + text.replace(/\"/g, strEmpty) + "\"";
33
+ return "\"" + text.replace(/\"/g, "") + "\"";
35
34
  }
36
35
 
37
- return strEmpty;
36
+ return "";
38
37
  }
39
38
 
40
39
  function _logToConsole(func: string, message: string) {
@@ -65,14 +64,14 @@ export class _InternalLogMessage{
65
64
  (isUserAct ? AiUserActionablePrefix : AiNonUserActionablePrefix) +
66
65
  msgId;
67
66
 
68
- let strProps:string = strEmpty;
67
+ let strProps:string = "";
69
68
  if (hasJSON()) {
70
69
  strProps = getJSON().stringify(properties);
71
70
  }
72
71
 
73
72
  const diagnosticText =
74
- (msg ? " message:" + _sanitizeDiagnosticText(msg) : strEmpty) +
75
- (properties ? " props:" + _sanitizeDiagnosticText(strProps) : strEmpty);
73
+ (msg ? " message:" + _sanitizeDiagnosticText(msg) : "") +
74
+ (properties ? " props:" + _sanitizeDiagnosticText(strProps) : "");
76
75
 
77
76
  _self.message += diagnosticText;
78
77
  }
@@ -123,10 +122,10 @@ export class DiagnosticLogger implements IDiagnosticLogger {
123
122
  const message = new _InternalLogMessage(msgId, msg, isUserAct, properties);
124
123
 
125
124
  if (_self.enableDebugExceptions()) {
126
- throw message;
125
+ throw dumpObj(message);
127
126
  } else {
128
127
  // Get the logging function and fallback to warnToConsole of for some reason errorToConsole doesn't exist
129
- let logFunc = severity === eLoggingSeverity.CRITICAL ? strErrorToConsole : strWarnToConsole;
128
+ let logFunc = severity === LoggingSeverity.CRITICAL ? strErrorToConsole : strWarnToConsole;
130
129
 
131
130
  if (!isUndefined(message.message)) {
132
131
  const logLevel = _self.consoleLoggingLevel();
@@ -147,7 +146,7 @@ export class DiagnosticLogger implements IDiagnosticLogger {
147
146
 
148
147
  _self.logInternalMessage(severity, message);
149
148
  } else {
150
- _debugExtMsg("throw" + (severity === eLoggingSeverity.CRITICAL ? "Critical" : "Warning"), message);
149
+ _debugExtMsg("throw" + (severity === LoggingSeverity.CRITICAL ? "Critical" : "Warning"), message);
151
150
  }
152
151
  }
153
152
  }
@@ -165,7 +164,7 @@ export class DiagnosticLogger implements IDiagnosticLogger {
165
164
  * This will write an error to the console if possible
166
165
  * @param message {string} - The error message
167
166
  */
168
- _self.errorToConsole = (message: string) => {
167
+ _self.errorToConsole = (message: string) => {
169
168
  _logToConsole("error", message);
170
169
  _debugExtMsg("error", message);
171
170
  }
@@ -204,15 +203,15 @@ export class DiagnosticLogger implements IDiagnosticLogger {
204
203
  if (severity <= _self.telemetryLoggingLevel()) {
205
204
  _self.queue.push(message);
206
205
  _messageCount++;
207
- _debugExtMsg((severity === eLoggingSeverity.CRITICAL ? "error" : "warn"), message);
206
+ _debugExtMsg((severity === LoggingSeverity.CRITICAL ? "error" : "warn"), message);
208
207
  }
209
208
 
210
209
  // When throttle limit reached, send a special event
211
210
  if (_messageCount === _self.maxInternalMessageLimit()) {
212
211
  const throttleLimitMessage = "Internal events throttle limit per PageView reached for this app.";
213
- const throttleMessage = new _InternalLogMessage(_eInternalMessageId.MessageLimitPerPVExceeded, throttleLimitMessage, false);
212
+ const throttleMessage = new _InternalLogMessage(_InternalMessageId.MessageLimitPerPVExceeded, throttleLimitMessage, false);
214
213
  _self.queue.push(throttleMessage);
215
- if (severity === eLoggingSeverity.CRITICAL) {
214
+ if (severity === LoggingSeverity.CRITICAL) {
216
215
  _self.errorToConsole(throttleLimitMessage);
217
216
  } else {
218
217
  _self.warnToConsole(throttleLimitMessage);
@@ -320,17 +319,3 @@ export class DiagnosticLogger implements IDiagnosticLogger {
320
319
  // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
321
320
  }
322
321
  }
323
-
324
- /**
325
- * This is a helper method which will call throwInternal on the passed logger, will throw exceptions in
326
- * debug mode or attempt to log the error as a console warning. This helper is provided mostly to better
327
- * support minification as logger.throwInternal() will not compress the publish "throwInternal" used throughout
328
- * the code.
329
- * @param logger - The Diagnostic Logger instance to use.
330
- * @param severity {LoggingSeverity} - The severity of the log message
331
- * @param message {_InternalLogMessage} - The log message.
332
- */
333
- export function _throwInternal(logger: IDiagnosticLogger, severity: LoggingSeverity, msgId: _InternalMessageId, msg: string, properties?: Object, isUserAct = false) {
334
- (logger || new DiagnosticLogger()).throwInternal(severity, msgId, msg, properties, isUserAct);
335
- }
336
-
@@ -5,7 +5,6 @@
5
5
  import {
6
6
  getGlobal, strShimUndefined, strShimObject, strShimPrototype
7
7
  } from "@microsoft/applicationinsights-shims";
8
- import { strEmpty } from "./InternalConstants";
9
8
  import { isString, isUndefined, strContains } from "./HelperFuncs";
10
9
 
11
10
  // TypeScript removed this interface so we need to declare the global so we can check for it's existence.
@@ -32,7 +31,6 @@ const strMsCrypto = "msCrypto";
32
31
  const strReactNative = "ReactNative";
33
32
  const strMsie = "msie";
34
33
  const strTrident = "trident/";
35
- const strXMLHttpRequest = "XMLHttpRequest";
36
34
 
37
35
  let _isTrident: boolean = null;
38
36
  let _navUserAgentCheck: string = null;
@@ -297,7 +295,7 @@ export function isIE() {
297
295
  if (nav && (nav.userAgent !== _navUserAgentCheck || _isTrident === null)) {
298
296
  // Added to support test mocking of the user agent
299
297
  _navUserAgentCheck = nav.userAgent;
300
- let userAgent = (_navUserAgentCheck || strEmpty).toLowerCase();
298
+ let userAgent = (_navUserAgentCheck || "").toLowerCase();
301
299
  _isTrident = (strContains(userAgent, strMsie) || strContains(userAgent, strTrident));
302
300
  }
303
301
 
@@ -310,10 +308,10 @@ export function isIE() {
310
308
  export function getIEVersion(userAgentStr: string = null): number {
311
309
  if (!userAgentStr) {
312
310
  let navigator = getNavigator() || ({} as Navigator);
313
- userAgentStr = navigator ? (navigator.userAgent || strEmpty).toLowerCase() : strEmpty;
311
+ userAgentStr = navigator ? (navigator.userAgent || "").toLowerCase() : "";
314
312
  }
315
313
 
316
- var ua = (userAgentStr || strEmpty).toLowerCase();
314
+ var ua = (userAgentStr || "").toLowerCase();
317
315
  // Also check for documentMode in case X-UA-Compatible meta tag was included in HTML.
318
316
  if (strContains(ua, strMsie)) {
319
317
  let doc = getDocument() || {} as Document;
@@ -333,7 +331,7 @@ export function getIEVersion(userAgentStr: string = null): number {
333
331
  */
334
332
  export function dumpObj(object: any): string {
335
333
  const objectTypeDump: string = Object[strShimPrototype].toString.call(object);
336
- let propertyValueDump: string = strEmpty;
334
+ let propertyValueDump: string = "";
337
335
  if (objectTypeDump === "[object Error]") {
338
336
  propertyValueDump = "{ stack: '" + object.stack + "', message: '" + object.message + "', name: '" + object.name + "'";
339
337
  } else if (hasJSON()) {
@@ -346,10 +344,10 @@ export function dumpObj(object: any): string {
346
344
  export function isSafari(userAgentStr ?: string) {
347
345
  if (!userAgentStr || !isString(userAgentStr)) {
348
346
  let navigator = getNavigator() || ({} as Navigator);
349
- userAgentStr = navigator ? (navigator.userAgent || strEmpty).toLowerCase() : strEmpty;
347
+ userAgentStr = navigator ? (navigator.userAgent || "").toLowerCase() : "";
350
348
  }
351
349
 
352
- var ua = (userAgentStr || strEmpty).toLowerCase();
350
+ var ua = (userAgentStr || "").toLowerCase();
353
351
  return (ua.indexOf("safari") >= 0);
354
352
  }
355
353
 
@@ -357,7 +355,7 @@ export function isSafari(userAgentStr ?: string) {
357
355
  * Checks if HTML5 Beacons are supported in the current environment.
358
356
  * @returns True if supported, false otherwise.
359
357
  */
360
- export function isBeaconsSupported(): boolean {
358
+ export function isBeaconsSupported(): boolean {
361
359
  if (_beaconsSupported === null) {
362
360
  _beaconsSupported = hasNavigator() && Boolean(getNavigator().sendBeacon);
363
361
  }
@@ -373,7 +371,8 @@ export function isBeaconsSupported(): boolean {
373
371
  export function isFetchSupported(withKeepAlive?: boolean): boolean {
374
372
  let isSupported = false;
375
373
  try {
376
- isSupported = !!getGlobalInst("fetch");
374
+ const fetchApi = getGlobalInst("fetch");
375
+ isSupported = !!fetchApi;
377
376
  const request = getGlobalInst("Request");
378
377
  if (isSupported && withKeepAlive && request) {
379
378
  isSupported = _hasProperty(request, "keepalive");
@@ -387,9 +386,9 @@ export function isFetchSupported(withKeepAlive?: boolean): boolean {
387
386
 
388
387
  export function useXDomainRequest(): boolean | undefined {
389
388
  if (_useXDomainRequest === null) {
390
- _useXDomainRequest = (typeof XDomainRequest !== strShimUndefined);
389
+ _useXDomainRequest = (typeof XDomainRequest !== "undefined");
391
390
  if (_useXDomainRequest && isXhrSupported()) {
392
- _useXDomainRequest = _useXDomainRequest && !_hasProperty(getGlobalInst(strXMLHttpRequest), "withCredentials");
391
+ _useXDomainRequest = _useXDomainRequest && !_hasProperty(getGlobalInst("XMLHttpRequest"), "withCredentials");
393
392
  }
394
393
  }
395
394
 
@@ -403,7 +402,7 @@ export function useXDomainRequest(): boolean | undefined {
403
402
  export function isXhrSupported(): boolean {
404
403
  let isSupported = false;
405
404
  try {
406
- const xmlHttpRequest = getGlobalInst(strXMLHttpRequest);
405
+ const xmlHttpRequest = getGlobalInst("XMLHttpRequest");
407
406
  isSupported = !!xmlHttpRequest;
408
407
  } catch (e) {
409
408
  // Just Swallow any failure during availability checks
@@ -4,11 +4,15 @@ import {
4
4
  strShimUndefined, strShimObject, strShimFunction, throwTypeError,
5
5
  ObjClass, ObjProto, ObjAssign, ObjHasOwnProperty, ObjDefineProperty, strShimPrototype
6
6
  } from "@microsoft/applicationinsights-shims";
7
- import { strEmpty } from "./InternalConstants";
8
7
 
9
8
  // RESTRICT and AVOID circular dependencies you should not import other contained modules or export the contents of this file directly
10
9
 
11
10
  // Added to help with minfication
11
+ const strOnPrefix = "on";
12
+ const strAttachEvent = "attachEvent";
13
+ const strAddEventHelper = "addEventListener";
14
+ const strDetachEvent = "detachEvent";
15
+ const strRemoveEventListener = "removeEventListener";
12
16
  const strToISOString = "toISOString";
13
17
  const cStrEndsWith = "endsWith";
14
18
  const cStrStartsWith = "startsWith";
@@ -22,9 +26,9 @@ const strToString = "toString";
22
26
  * Constant string defined to support minimization
23
27
  * @ignore
24
28
  */
25
- const str__Proto = "__proto__";
29
+ const str__Proto = "__proto__";
26
30
 
27
- /**
31
+ /**
28
32
  * Constant string defined to support minimization
29
33
  * @ignore
30
34
  */
@@ -58,27 +62,27 @@ const rLeadingNumeric = /^(\d+[\w\d_$])/;
58
62
  * Pre-lookup to check if we are running on a modern browser (i.e. not IE8)
59
63
  * @ignore
60
64
  */
61
- let _objGetPrototypeOf = Object["getPrototypeOf"];
65
+ let _objGetPrototypeOf = Object["getPrototypeOf"];
62
66
 
63
- /**
67
+ /**
64
68
  * Helper used to get the prototype of the target object as getPrototypeOf is not available in an ES3 environment.
65
69
  * @ignore
66
70
  */
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
- }
71
+ export function _getObjProto(target:any) {
72
+ if (target) {
73
+ // This method doesn't existing in older browsers (e.g. IE8)
74
+ if (_objGetPrototypeOf) {
75
+ return _objGetPrototypeOf(target);
76
+ }
73
77
 
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
- }
78
+ // target[Constructor] May break if the constructor has been changed or removed
79
+ let newProto = target[str__Proto] || target[strShimPrototype] || target[strConstructor];
80
+ if(newProto) {
81
+ return newProto;
82
+ }
83
+ }
80
84
 
81
- return null;
85
+ return null;
82
86
  }
83
87
 
84
88
  export function objToString(obj: any) {
@@ -89,19 +93,19 @@ export function isTypeof(value: any, theType: string): boolean {
89
93
  return typeof value === theType;
90
94
  }
91
95
 
92
- export function isUndefined(value: any): value is undefined {
96
+ export function isUndefined(value: any): boolean {
93
97
  return value === undefined || typeof value === strShimUndefined;
94
98
  }
95
99
 
96
- export function isNotUndefined<T>(value: T): value is T {
100
+ export function isNotUndefined(value: any): boolean {
97
101
  return !isUndefined(value);
98
102
  }
99
103
 
100
- export function isNullOrUndefined(value: any): value is null | undefined {
104
+ export function isNullOrUndefined(value: any): boolean {
101
105
  return (value === null || isUndefined(value));
102
106
  }
103
107
 
104
- export function isNotNullOrUndefined<T>(value: T): value is T {
108
+ export function isNotNullOrUndefined(value: any): boolean {
105
109
  return !isNullOrUndefined(value);
106
110
  }
107
111
 
@@ -109,7 +113,7 @@ export function hasOwnProperty(obj: any, prop: string): boolean {
109
113
  return !!(obj && ObjHasOwnProperty.call(obj, prop));
110
114
  }
111
115
 
112
- export function isObject<T>(value: T): value is T {
116
+ export function isObject(value: any): boolean {
113
117
  // Changing to inline for performance
114
118
  return !!(value && typeof value === strShimObject);
115
119
  }
@@ -119,8 +123,54 @@ export function isFunction(value: any): value is Function {
119
123
  return !!(value && typeof value === strShimFunction);
120
124
  }
121
125
 
122
- export function isPromiseLike<T>(value: any): value is PromiseLike<T> {
123
- return value && isFunction(value.then);
126
+ /**
127
+ * Binds the specified function to an event, so that the function gets called whenever the event fires on the object
128
+ * @param obj Object to add the event too.
129
+ * @param eventNameWithoutOn String that specifies any of the standard DHTML Events without "on" prefix
130
+ * @param handlerRef Pointer that specifies the function to call when event fires
131
+ * @param useCapture [Optional] Defaults to false
132
+ * @returns True if the function was bound successfully to the event, otherwise false
133
+ */
134
+ export function attachEvent(obj: any, eventNameWithoutOn: string, handlerRef: any, useCapture: boolean = false) {
135
+ let result = false;
136
+ if (!isNullOrUndefined(obj)) {
137
+ try {
138
+ if (!isNullOrUndefined(obj[strAddEventHelper])) {
139
+ // all browsers except IE before version 9
140
+ obj[strAddEventHelper](eventNameWithoutOn, handlerRef, useCapture);
141
+ result = true;
142
+ } else if (!isNullOrUndefined(obj[strAttachEvent])) {
143
+ // IE before version 9
144
+ obj[strAttachEvent](strOnPrefix + eventNameWithoutOn, handlerRef);
145
+ result = true;
146
+ }
147
+ } catch (e) {
148
+ // Just Ignore any error so that we don't break any execution path
149
+ }
150
+ }
151
+
152
+ return result;
153
+ }
154
+
155
+ /**
156
+ * Removes an event handler for the specified event
157
+ * @param Object to remove the event from
158
+ * @param eventNameWithoutOn {string} - The name of the event
159
+ * @param handlerRef {any} - The callback function that needs to be executed for the given event
160
+ * @param useCapture [Optional] Defaults to false
161
+ */
162
+ export function detachEvent(obj: any, eventNameWithoutOn: string, handlerRef: any, useCapture: boolean = false) {
163
+ if (!isNullOrUndefined(obj)) {
164
+ try {
165
+ if (!isNullOrUndefined(obj[strRemoveEventListener])) {
166
+ obj[strRemoveEventListener](eventNameWithoutOn, handlerRef, useCapture);
167
+ } else if (!isNullOrUndefined(obj[strDetachEvent])) {
168
+ obj[strDetachEvent](strOnPrefix + eventNameWithoutOn, handlerRef);
169
+ }
170
+ } catch (e) {
171
+ // Just Ignore any error so that we don't break any execution path
172
+ }
173
+ }
124
174
  }
125
175
 
126
176
  /**
@@ -154,7 +204,7 @@ export function normalizeJsName(name: string): string {
154
204
  * @param target The target object to find and process the keys
155
205
  * @param callbackfn The function to call with the details
156
206
  */
157
- export function objForEachKey<T = any>(target: T, callbackfn: (name: string, value: T[keyof T]) => void) {
207
+ export function objForEachKey(target: any, callbackfn: (name: string, value: any) => void) {
158
208
  if (target) {
159
209
  for (let prop in target) {
160
210
  if (ObjHasOwnProperty.call(target, prop)) {
@@ -186,7 +236,7 @@ export function strEndsWith(value: string, search: string) {
186
236
  * @param search - The characters to be searched for at the end of the value.
187
237
  * @returns true if the given search value is found at the end of the string, otherwise false.
188
238
  */
189
- export function _strEndsWithPoly(value: string, search: string) {
239
+ export function _strEndsWithPoly(value: string, search: string) {
190
240
  let result = false;
191
241
  let searchLen = search ? search.length : 0;
192
242
  let valLen = value ? value.length : 0;
@@ -214,7 +264,7 @@ export function _strEndsWithPoly(value: string, search: string) {
214
264
  export function strStartsWith(value: string, checkValue: string) {
215
265
  let result = false;
216
266
  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
267
+ // For Performance try and use the native instance, using string lookup of the function to easily pass the ES3 build checks and minification
218
268
  result = _strStartsWith ? value[cStrStartsWith](checkValue) : _strStartsWithPoly(value, checkValue);
219
269
  }
220
270
 
@@ -227,7 +277,7 @@ export function strStartsWith(value: string, checkValue: string) {
227
277
  * @param checkValue - The characters to be searched for at the start of the value.
228
278
  * @returns true if the given search value is found at the start of the string, otherwise false.
229
279
  */
230
- export function _strStartsWithPoly(value: string, checkValue: string) {
280
+ export function _strStartsWithPoly(value: string, checkValue: string) {
231
281
  // Using helper for performance and because string startsWith() is not available on IE
232
282
  let result = false;
233
283
  let chkLen = checkValue ? checkValue.length : 0;
@@ -265,8 +315,7 @@ export function isDate(obj: any): obj is Date {
265
315
  }
266
316
 
267
317
  /**
268
- * Check if an object is of type Array with optional generic T, the generic type is not validated
269
- * and exists to help with TypeScript validation only.
318
+ * Check if an object is of type Array
270
319
  */
271
320
  export let isArray: <T = any>(obj: any) => obj is Array<T> = _isArray || _isArrayPoly;
272
321
  function _isArrayPoly<T = any>(obj: any): obj is Array<T> {
@@ -328,7 +377,7 @@ export function isPlainObject(value: any): boolean {
328
377
  let result: boolean = false;
329
378
 
330
379
  if (value && typeof value === "object") {
331
- // Inlining _objGetPrototypeOf for performance to avoid an additional function call
380
+ // Inlining _objGetPrototypeOf for performance to avoid an additional function call
332
381
  let proto = _objGetPrototypeOf ? _objGetPrototypeOf(value) : _getObjProto(value);
333
382
  if (!proto) {
334
383
  // No prototype found so this is a plain Object eg. 'Object.create(null)'
@@ -389,7 +438,7 @@ export function _toISOStringPoly(date: Date) {
389
438
  * @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
439
  * @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
440
  */
392
- export function arrForEach<T = any>(arr: T[], callbackfn: (value: T, index?: number, array?: T[]) => undefined | void | number, thisArg?: any): void {
441
+ export function arrForEach<T>(arr: T[], callbackfn: (value: T, index?: number, array?: T[]) => void|number, thisArg?: any): void {
393
442
  let len = arr.length;
394
443
  try {
395
444
  for (let idx = 0; idx < len; idx++) {
@@ -615,18 +664,6 @@ function _doNothing<T>(value: T): T {
615
664
  return value;
616
665
  }
617
666
 
618
- export function deepFreeze<T>(obj: T): T {
619
- if (_objFreeze) {
620
- objForEachKey(obj, (name, value) => {
621
- if (isArray(value) || isObject(value)) {
622
- _objFreeze(value);
623
- }
624
- });
625
- }
626
-
627
- return objFreeze(obj);
628
- }
629
-
630
667
  export const objFreeze: <T>(value: T) => T = _objFreeze || _doNothing;
631
668
  export const objSeal: <T>(value: T) => T = _objSeal || _doNothing;
632
669
 
@@ -648,7 +685,7 @@ export function getExceptionName(object: any): string {
648
685
  return object.name;
649
686
  }
650
687
 
651
- return strEmpty;
688
+ return "";
652
689
  }
653
690
 
654
691
  /**
@@ -661,7 +698,7 @@ export function getExceptionName(object: any): string {
661
698
  * @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
699
  * @returns The existing or new value, depending what was set
663
700
  */
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) {
701
+ 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) {
665
702
  let theValue = value;
666
703
  if (target) {
667
704
  theValue = target[field];
@@ -709,28 +746,6 @@ export function throwError(message: string): never {
709
746
  throw new Error(message);
710
747
  }
711
748
 
712
- function _createProxyFunction<S>(source: S | (() => S), funcName: (keyof S)) {
713
- let srcFunc: () => S = null;
714
- let src: S = null;
715
- if (isFunction (source)) {
716
- srcFunc = source;
717
- } else {
718
- src = source;
719
- }
720
-
721
- return function() {
722
- // Capture the original arguments passed to the method
723
- var originalArguments = arguments;
724
- if (srcFunc) {
725
- src = srcFunc();
726
- }
727
-
728
- if (src) {
729
- return (src[funcName] as any).apply(src, originalArguments);
730
- }
731
- }
732
- }
733
-
734
749
  /**
735
750
  * Effectively assigns all enumerable properties (not just own properties) and functions (including inherited prototype) from
736
751
  * the source object to the target, it attempts to use proxy getters / setters (if possible) and proxy functions to avoid potential
@@ -745,9 +760,10 @@ function _createProxyFunction<S>(source: S | (() => S), funcName: (keyof S)) {
745
760
  * @param target - The target object to be assigned with the source properties and functions
746
761
  * @param source - The source object which will be assigned / called by setting / calling the targets proxies
747
762
  * @param chkSet - An optional callback to determine whether a specific property/function should be proxied
763
+ * @memberof Initialization
748
764
  */
749
- export function proxyAssign<T, S>(target: T, source: S, chkSet?: (name: string, isFunc?: boolean, source?: S, target?: T) => boolean) {
750
- if (target && source && isObject(target) && isObject(source)) {
765
+ export function proxyAssign(target: any, source: any, chkSet?: (name: string, isFunc?: boolean, source?: any, target?: any) => boolean) {
766
+ if (target && source && target !== source && isObject(target) && isObject(source)) {
751
767
  // effectively apply/proxy full source to the target instance
752
768
  for (const field in source) {
753
769
  if (isString(field)) {
@@ -755,12 +771,18 @@ export function proxyAssign<T, S>(target: T, source: S, chkSet?: (name: string,
755
771
  if (isFunction(value)) {
756
772
  if (!chkSet || chkSet(field, true, source, target)) {
757
773
  // Create a proxy function rather than just copying the (possible) prototype to the new object as an instance function
758
- target[field as string] = _createProxyFunction(source, field);
774
+ target[field as string] = (function(funcName: string) {
775
+ return function() {
776
+ // Capture the original arguments passed to the method
777
+ var originalArguments = arguments;
778
+ return source[funcName].apply(source, originalArguments);
779
+ }
780
+ })(field);
759
781
  }
760
782
  } else if (!chkSet || chkSet(field, false, source, target)) {
761
783
  if (hasOwnProperty(target, field)) {
762
784
  // Remove any previous instance property
763
- delete (target as any)[field];
785
+ delete target[field];
764
786
  }
765
787
 
766
788
  if (!objDefineAccessors(target, field, () => {
@@ -781,33 +803,6 @@ export function proxyAssign<T, S>(target: T, source: S, chkSet?: (name: string,
781
803
  return target;
782
804
  }
783
805
 
784
- export function proxyFunctionAs<T, S>(target: T, name: string, source: S | (() => S), theFunc: (keyof S), overwriteTarget: boolean = true) {
785
- if (target && name && source) {
786
- if (overwriteTarget || isUndefined(target[name])) {
787
- (target as any)[name] = _createProxyFunction(source, theFunc);
788
- }
789
- }
790
- }
791
-
792
- /**
793
- * Creates proxy functions on the target which internally will call the source version with all arguments passed to the target method.
794
- *
795
- * @param target - The target object to be assigned with the source properties and functions
796
- * @param source - The source object which will be assigned / called by setting / calling the targets proxies
797
- * @param functionsToProxy - An array of function names that will be proxied on the target
798
- */
799
- export function proxyFunctions<T, S>(target: T, source: S | (() => S), functionsToProxy: (keyof S)[], overwriteTarget: boolean = true) {
800
- if (target && source && isObject(target) && isArray(functionsToProxy)) {
801
- arrForEach(functionsToProxy, (theFuncName) => {
802
- if (isString(theFuncName)) {
803
- proxyFunctionAs(target, theFuncName, source, theFuncName, overwriteTarget);
804
- }
805
- });
806
- }
807
-
808
- return target;
809
- }
810
-
811
806
  /**
812
807
  * Simpler helper to create a dynamic class that implements the interface and populates the values with the defaults.
813
808
  * Only instance properties (hasOwnProperty) values are copied from the defaults to the new instance
@@ -825,25 +820,6 @@ export function createClassFromInterface<T>(defaults?: T) {
825
820
  } as new () => T;
826
821
  }
827
822
 
828
- /**
829
- * Create an enum style object which has both the key => value and value => key mappings
830
- * @param values - The values to populate on the new object
831
- * @returns
832
- */
833
- export function createEnumStyle<T>(values: T) {
834
- let enumClass: any = {};
835
- objForEachKey(values, (field, value) => {
836
- enumClass[field] = value;
837
- // Add Reverse lookup
838
- if (!isUndefined(enumClass[value])) {
839
- throwError("[" + value + "] exists for " + field);
840
- }
841
- enumClass[value] = field;
842
- });
843
-
844
- return objFreeze(enumClass as T);
845
- }
846
-
847
823
  /**
848
824
  * A helper function to assist with JIT performance for objects that have properties added / removed dynamically
849
825
  * this is primarily for chromium based browsers and has limited effects on Firefox and none of IE. Only call this
@@ -871,9 +847,7 @@ export function optimizeObject<T>(theObject: T): T {
871
847
  * @param obj5 - object to merge.
872
848
  * @returns The extended first object.
873
849
  */
874
- export function objExtend<T2, T3, T4, T5, T6>(deepExtend?: boolean, obj2?: T2, obj3?: T3, obj4?: T4, obj5?: T5, obj6?: T6): T2 & T3 & T4 & T5 & T6
875
- export 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
876
- export function objExtend<T1, T2, T3, T4, T5, T6>(obj1?: T1 | any, obj2?: T2, obj3?: T3, obj4?: T4, obj5?: T5, obj6?: T6): T1 & T2 & T3 & T4 & T5 & T6 {
850
+ export function objExtend<T1, T2, T3, T4, T5, T6>(obj?: boolean | T1, obj2?: T2, obj3?: T3, obj4?: T4, obj5?: T5, obj6?: T6): T1 & T2 & T3 & T4 & T5 & T6 {
877
851
  // Variables
878
852
  let theArgs = arguments as any;
879
853
  let extended: T1 & T2 & T3 & T4 & T5 & T6 = theArgs[0] || {};
@@ -888,7 +862,7 @@ export function objExtend<T1, T2, T3, T4, T5, T6>(obj1?: T1 | any, obj2?: T2, ob
888
862
  idx++;
889
863
  }
890
864
 
891
- // Handle case when target is a string or something (possible in deep copy)
865
+ // Handle case when target is a string or something (possible in deep copy)
892
866
  if (!isObject(extended)) {
893
867
  extended = {} as T1 & T2 & T3 & T4 & T5 & T6;
894
868
  }
@@ -6,7 +6,6 @@ import {
6
6
  } from "../JavaScriptSDK.Interfaces/IInstrumentHooks";
7
7
  import { strShimFunction, strShimPrototype } from "@microsoft/applicationinsights-shims";
8
8
  import { hasOwnProperty, _getObjProto } from "./HelperFuncs";
9
- import { getGlobalInst } from "./EnvUtils";
10
9
 
11
10
  const aiInstrumentHooks = "_aiHooks";
12
11
 
@@ -73,13 +72,13 @@ function _doCallbacks(hooks:IInstrumentHook[], callDetails: IInstrumentCallDetai
73
72
  function _createFunctionHook(aiHook:IInstrumentHooks) {
74
73
 
75
74
  // Define a temporary method that queues-up a the real method call
76
- return function (this: any) {
75
+ return function () {
77
76
  let funcThis = this;
78
77
  // Capture the original arguments passed to the method
79
78
  let orgArgs = arguments as any;
80
79
  let hooks = aiHook.h;
81
80
 
82
- let funcArgs: IInstrumentCallDetails = {
81
+ let funcArgs:IInstrumentCallDetails = {
83
82
  name: aiHook.n,
84
83
  inst: funcThis,
85
84
  ctx: null,
@@ -88,7 +87,6 @@ function _createFunctionHook(aiHook:IInstrumentHooks) {
88
87
 
89
88
  let hookCtx: any[] = [];
90
89
  let cbArgs = _createArgs([funcArgs], orgArgs);
91
- funcArgs.evt = getGlobalInst("event");
92
90
 
93
91
  function _createArgs(target:any[], theArgs:any[]): any[] {
94
92
  _arrLoop((theArgs as any), (arg) => {