@microsoft/applicationinsights-core-js 3.0.0-beta.2303-03 → 3.0.0-beta.2303-05

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 (132) hide show
  1. package/browser/applicationinsights-core-js.integrity.json +9 -9
  2. package/browser/applicationinsights-core-js.js +2 -2
  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 +113 -206
  7. package/dist/applicationinsights-core-js.api.md +11 -14
  8. package/dist/applicationinsights-core-js.d.ts +15 -13
  9. package/dist/applicationinsights-core-js.js +2 -2
  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 +15 -13
  14. package/dist-esm/Config/ConfigDefaultHelpers.js +1 -1
  15. package/dist-esm/Config/ConfigDefaults.js +1 -1
  16. package/dist-esm/Config/DynamicConfig.js +1 -1
  17. package/dist-esm/Config/DynamicProperty.js +1 -1
  18. package/dist-esm/Config/DynamicState.js +1 -1
  19. package/dist-esm/Config/DynamicSupport.js +1 -1
  20. package/dist-esm/Config/IConfigDefaults.js +1 -1
  21. package/dist-esm/Config/IDynamicConfigHandler.js +1 -1
  22. package/dist-esm/Config/IDynamicPropertyHandler.js +1 -1
  23. package/dist-esm/Config/IDynamicWatcher.js +1 -1
  24. package/dist-esm/Config/_IDynamicConfigHandlerState.js +1 -1
  25. package/dist-esm/JavaScriptSDK/AggregationError.js +1 -1
  26. package/dist-esm/JavaScriptSDK/AppInsightsCore.js +1 -1
  27. package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js +1 -1
  28. package/dist-esm/JavaScriptSDK/Constants.js +1 -1
  29. package/dist-esm/JavaScriptSDK/CookieMgr.js +1 -1
  30. package/dist-esm/JavaScriptSDK/CoreUtils.js +1 -1
  31. package/dist-esm/JavaScriptSDK/DataCacheHelper.js +2 -2
  32. package/dist-esm/JavaScriptSDK/DataCacheHelper.js.map +1 -1
  33. package/dist-esm/JavaScriptSDK/DbgExtensionUtils.js +1 -1
  34. package/dist-esm/JavaScriptSDK/DiagnosticLogger.js +1 -1
  35. package/dist-esm/JavaScriptSDK/EnvUtils.js +1 -1
  36. package/dist-esm/JavaScriptSDK/EventHelpers.js +1 -1
  37. package/dist-esm/JavaScriptSDK/HelperFuncs.js +1 -1
  38. package/dist-esm/JavaScriptSDK/InstrumentHooks.js +1 -1
  39. package/dist-esm/JavaScriptSDK/InternalConstants.js +1 -1
  40. package/dist-esm/JavaScriptSDK/NotificationManager.js +1 -1
  41. package/dist-esm/JavaScriptSDK/PerfManager.js +1 -1
  42. package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js +1 -1
  43. package/dist-esm/JavaScriptSDK/RandomHelper.js +1 -1
  44. package/dist-esm/JavaScriptSDK/TelemetryHelpers.js +1 -1
  45. package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js +1 -1
  46. package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js +1 -1
  47. package/dist-esm/JavaScriptSDK/UnloadHookContainer.js +1 -1
  48. package/dist-esm/JavaScriptSDK/W3cTraceParent.js +1 -1
  49. package/dist-esm/JavaScriptSDK.Enums/EnumHelperFuncs.js +1 -1
  50. package/dist-esm/JavaScriptSDK.Enums/EventsDiscardedReason.js +1 -1
  51. package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js +1 -1
  52. package/dist-esm/JavaScriptSDK.Enums/SendRequestReason.js +1 -1
  53. package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js +1 -1
  54. package/dist-esm/JavaScriptSDK.Enums/TelemetryUpdateReason.js +1 -1
  55. package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js +1 -1
  56. package/dist-esm/JavaScriptSDK.Interfaces/IChannelControls.js +1 -1
  57. package/dist-esm/JavaScriptSDK.Interfaces/IConfiguration.js +1 -1
  58. package/dist-esm/JavaScriptSDK.Interfaces/ICookieMgr.js +1 -1
  59. package/dist-esm/JavaScriptSDK.Interfaces/IDbgExtension.js +1 -1
  60. package/dist-esm/JavaScriptSDK.Interfaces/IDiagnosticLogger.js +1 -1
  61. package/dist-esm/JavaScriptSDK.Interfaces/IDistributedTraceContext.js +1 -1
  62. package/dist-esm/JavaScriptSDK.Interfaces/IInstrumentHooks.js +1 -1
  63. package/dist-esm/JavaScriptSDK.Interfaces/INotificationListener.js +1 -1
  64. package/dist-esm/JavaScriptSDK.Interfaces/INotificationManager.js +1 -1
  65. package/dist-esm/JavaScriptSDK.Interfaces/IPerfEvent.js +1 -1
  66. package/dist-esm/JavaScriptSDK.Interfaces/IPerfManager.js +1 -1
  67. package/dist-esm/JavaScriptSDK.Interfaces/IProcessTelemetryContext.js +1 -1
  68. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js +1 -1
  69. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryItem.js +1 -1
  70. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPlugin.js +1 -1
  71. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js +1 -1
  72. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js +1 -1
  73. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUpdateState.js +1 -1
  74. package/dist-esm/JavaScriptSDK.Interfaces/ITraceParent.js +1 -1
  75. package/dist-esm/JavaScriptSDK.Interfaces/IUnloadHook.js +1 -1
  76. package/dist-esm/JavaScriptSDK.Interfaces/IUnloadableComponent.js +1 -1
  77. package/dist-esm/__DynamicConstants.js +1 -1
  78. package/dist-esm/applicationinsights-core-js.js +1 -1
  79. package/package.json +1 -1
  80. package/types/JavaScriptSDK/AppInsightsCore.d.ts +5 -6
  81. package/types/JavaScriptSDK.Interfaces/IAppInsightsCore.d.ts +9 -6
  82. package/src/JavaScriptSDK/AggregationError.ts +0 -36
  83. package/src/JavaScriptSDK/AppInsightsCore.ts +0 -1322
  84. package/src/JavaScriptSDK/BaseTelemetryPlugin.ts +0 -343
  85. package/src/JavaScriptSDK/Constants.ts +0 -4
  86. package/src/JavaScriptSDK/CookieMgr.ts +0 -449
  87. package/src/JavaScriptSDK/CoreUtils.ts +0 -58
  88. package/src/JavaScriptSDK/DataCacheHelper.ts +0 -107
  89. package/src/JavaScriptSDK/DbgExtensionUtils.ts +0 -56
  90. package/src/JavaScriptSDK/DiagnosticLogger.ts +0 -380
  91. package/src/JavaScriptSDK/EnvUtils.ts +0 -312
  92. package/src/JavaScriptSDK/EventHelpers.ts +0 -550
  93. package/src/JavaScriptSDK/HelperFuncs.ts +0 -351
  94. package/src/JavaScriptSDK/InstrumentHooks.ts +0 -280
  95. package/src/JavaScriptSDK/InternalConstants.ts +0 -31
  96. package/src/JavaScriptSDK/NotificationManager.ts +0 -165
  97. package/src/JavaScriptSDK/PerfManager.ts +0 -288
  98. package/src/JavaScriptSDK/ProcessTelemetryContext.ts +0 -674
  99. package/src/JavaScriptSDK/RandomHelper.ts +0 -145
  100. package/src/JavaScriptSDK/TelemetryHelpers.ts +0 -184
  101. package/src/JavaScriptSDK/TelemetryInitializerPlugin.ts +0 -112
  102. package/src/JavaScriptSDK/UnloadHandlerContainer.ts +0 -45
  103. package/src/JavaScriptSDK/UnloadHookContainer.ts +0 -52
  104. package/src/JavaScriptSDK/W3cTraceParent.ts +0 -197
  105. package/src/JavaScriptSDK.Enums/EnumHelperFuncs.ts +0 -24
  106. package/src/JavaScriptSDK.Enums/EventsDiscardedReason.ts +0 -71
  107. package/src/JavaScriptSDK.Enums/LoggingEnums.ts +0 -121
  108. package/src/JavaScriptSDK.Enums/SendRequestReason.ts +0 -56
  109. package/src/JavaScriptSDK.Enums/TelemetryUnloadReason.ts +0 -27
  110. package/src/JavaScriptSDK.Enums/TelemetryUpdateReason.ts +0 -27
  111. package/src/JavaScriptSDK.Interfaces/IAppInsightsCore.ts +0 -216
  112. package/src/JavaScriptSDK.Interfaces/IChannelControls.ts +0 -46
  113. package/src/JavaScriptSDK.Interfaces/IConfiguration.ts +0 -176
  114. package/src/JavaScriptSDK.Interfaces/ICookieMgr.ts +0 -116
  115. package/src/JavaScriptSDK.Interfaces/IDbgExtension.ts +0 -14
  116. package/src/JavaScriptSDK.Interfaces/IDiagnosticLogger.ts +0 -75
  117. package/src/JavaScriptSDK.Interfaces/IDistributedTraceContext.ts +0 -54
  118. package/src/JavaScriptSDK.Interfaces/IInstrumentHooks.ts +0 -100
  119. package/src/JavaScriptSDK.Interfaces/INotificationListener.ts +0 -39
  120. package/src/JavaScriptSDK.Interfaces/INotificationManager.ts +0 -52
  121. package/src/JavaScriptSDK.Interfaces/IPerfEvent.ts +0 -69
  122. package/src/JavaScriptSDK.Interfaces/IPerfManager.ts +0 -53
  123. package/src/JavaScriptSDK.Interfaces/IProcessTelemetryContext.ts +0 -157
  124. package/src/JavaScriptSDK.Interfaces/ITelemetryInitializers.ts +0 -17
  125. package/src/JavaScriptSDK.Interfaces/ITelemetryItem.ts +0 -62
  126. package/src/JavaScriptSDK.Interfaces/ITelemetryPlugin.ts +0 -94
  127. package/src/JavaScriptSDK.Interfaces/ITelemetryPluginChain.ts +0 -30
  128. package/src/JavaScriptSDK.Interfaces/ITelemetryUnloadState.ts +0 -10
  129. package/src/JavaScriptSDK.Interfaces/ITelemetryUpdateState.ts +0 -44
  130. package/src/JavaScriptSDK.Interfaces/ITraceParent.ts +0 -38
  131. package/src/JavaScriptSDK.Interfaces/IUnloadHook.ts +0 -22
  132. package/src/JavaScriptSDK.Interfaces/IUnloadableComponent.ts +0 -17
@@ -1,380 +0,0 @@
1
- // Copyright (c) Microsoft Corporation. All rights reserved.
2
- // Licensed under the MIT License.
3
- "use strict"
4
- import dynamicProto from "@microsoft/dynamicproto-js";
5
- import { dumpObj, isFunction, isUndefined } from "@nevware21/ts-utils";
6
- import { createDynamicConfig } from "../Config/DynamicConfig";
7
- import { LoggingSeverity, _InternalMessageId, _eInternalMessageId, eLoggingSeverity } from "../JavaScriptSDK.Enums/LoggingEnums";
8
- import { IAppInsightsCore } from "../JavaScriptSDK.Interfaces/IAppInsightsCore";
9
- import { IConfiguration } from "../JavaScriptSDK.Interfaces/IConfiguration";
10
- import { IDiagnosticLogger } from "../JavaScriptSDK.Interfaces/IDiagnosticLogger";
11
- import { ITelemetryUpdateState } from "../JavaScriptSDK.Interfaces/ITelemetryUpdateState";
12
- import { getDebugExt } from "./DbgExtensionUtils";
13
- import { getConsole, getJSON, hasJSON } from "./EnvUtils";
14
- import { STR_EMPTY, STR_ERROR_TO_CONSOLE, STR_WARN_TO_CONSOLE } from "./InternalConstants";
15
-
16
- /**
17
- * For user non actionable traces use AI Internal prefix.
18
- */
19
- const AiNonUserActionablePrefix = "AI (Internal): ";
20
-
21
- /**
22
- * Prefix of the traces in portal.
23
- */
24
- const AiUserActionablePrefix = "AI: ";
25
-
26
- /**
27
- * Session storage key for the prefix for the key indicating message type already logged
28
- */
29
- const AIInternalMessagePrefix = "AITR_";
30
-
31
- /**
32
- * Holds the current logger which will be used as the default if no logger is available
33
- */
34
- let _currentLogger: IDiagnosticLogger = null;
35
-
36
- const defaultValues = {
37
- loggingLevelConsole: 0,
38
- loggingLevelTelemetry: 1,
39
- maxMessageLimit: 25,
40
- enableDebugExceptions: false
41
- }
42
-
43
- function _sanitizeDiagnosticText(text: string) {
44
- if (text) {
45
- return "\"" + text.replace(/\"/g, STR_EMPTY) + "\"";
46
- }
47
-
48
- return STR_EMPTY;
49
- }
50
-
51
- function _logToConsole(func: string, message: string) {
52
- let theConsole = getConsole();
53
- if (!!theConsole) {
54
- let logFunc = "log";
55
- if (theConsole[func]) {
56
- logFunc = func;
57
- }
58
-
59
- if (isFunction(theConsole[logFunc])) {
60
- theConsole[logFunc](message);
61
- }
62
- }
63
- }
64
-
65
- export class _InternalLogMessage{
66
- public static dataType: string = "MessageData";
67
-
68
- public message: string;
69
- public messageId: _InternalMessageId;
70
-
71
- constructor(msgId: _InternalMessageId, msg: string, isUserAct = false, properties?: Object) {
72
- let _self = this;
73
-
74
- _self.messageId = msgId;
75
- _self.message =
76
- (isUserAct ? AiUserActionablePrefix : AiNonUserActionablePrefix) +
77
- msgId;
78
-
79
- let strProps:string = STR_EMPTY;
80
- if (hasJSON()) {
81
- strProps = getJSON().stringify(properties);
82
- }
83
-
84
- const diagnosticText =
85
- (msg ? " message:" + _sanitizeDiagnosticText(msg) : STR_EMPTY) +
86
- (properties ? " props:" + _sanitizeDiagnosticText(strProps) : STR_EMPTY);
87
-
88
- _self.message += diagnosticText;
89
- }
90
- }
91
-
92
- export function safeGetLogger(core: IAppInsightsCore, config?: IConfiguration): IDiagnosticLogger {
93
- return (core || {} as any).logger || new DiagnosticLogger(config);
94
- }
95
-
96
- export class DiagnosticLogger implements IDiagnosticLogger {
97
- public identifier = "DiagnosticLogger";
98
-
99
- /**
100
- * The internal logging queue
101
- */
102
- public queue: _InternalLogMessage[] = [];
103
-
104
- constructor(config?: IConfiguration) {
105
- /**
106
- * Count of internal messages sent
107
- */
108
- let _messageCount: number = 0;
109
-
110
- /**
111
- * Holds information about what message types were already logged to console or sent to server.
112
- */
113
- let _messageLogged: { [msg: number]: boolean } = {};
114
-
115
- let _loggingLevelConsole: number;
116
- let _loggingLevelTelemetry: number;
117
- let _maxInternalMessageLimit: number;
118
- let _enableDebugExceptions: boolean;
119
-
120
- dynamicProto(DiagnosticLogger, this, (_self) => {
121
- _setDefaultsFromConfig(config || {});
122
-
123
- _self.consoleLoggingLevel = () => _loggingLevelConsole;
124
-
125
- _self.telemetryLoggingLevel = () => _loggingLevelTelemetry;
126
-
127
- _self.maxInternalMessageLimit = () => _maxInternalMessageLimit;
128
-
129
- _self.enableDebugExceptions = () => _enableDebugExceptions;
130
-
131
- /**
132
- * This method will throw exceptions in debug mode or attempt to log the error as a console warning.
133
- * @param severity - {LoggingSeverity} - The severity of the log message
134
- * @param message - {_InternalLogMessage} - The log message.
135
- */
136
- _self.throwInternal = (severity: LoggingSeverity, msgId: _InternalMessageId, msg: string, properties?: Object, isUserAct = false) => {
137
- const message = new _InternalLogMessage(msgId, msg, isUserAct, properties);
138
-
139
- if (_enableDebugExceptions) {
140
- throw dumpObj(message);
141
- } else {
142
- // Get the logging function and fallback to warnToConsole of for some reason errorToConsole doesn't exist
143
- let logFunc = severity === eLoggingSeverity.CRITICAL ? STR_ERROR_TO_CONSOLE : STR_WARN_TO_CONSOLE;
144
-
145
- if (!isUndefined(message.message)) {
146
- if (isUserAct) {
147
- // check if this message type was already logged to console for this page view and if so, don't log it again
148
- const messageKey: number = +message.messageId;
149
-
150
- if (!_messageLogged[messageKey] && _loggingLevelConsole >= severity) {
151
- _self[logFunc](message.message);
152
- _messageLogged[messageKey] = true;
153
- }
154
- } else {
155
- // Only log traces if the console Logging Level is >= the throwInternal severity level
156
- if (_loggingLevelConsole >= severity) {
157
- _self[logFunc](message.message);
158
- }
159
- }
160
-
161
- _logInternalMessage(severity, message);
162
- } else {
163
- _debugExtMsg("throw" + (severity === eLoggingSeverity.CRITICAL ? "Critical" : "Warning"), message);
164
- }
165
- }
166
- }
167
-
168
- /**
169
- * This will write a warning to the console if possible
170
- * @param message - {string} - The warning message
171
- */
172
- _self.warnToConsole = (message: string) => {
173
- _logToConsole("warn", message);
174
- _debugExtMsg("warning", message);
175
- }
176
-
177
- /**
178
- * This will write an error to the console if possible
179
- * @param message - {string} - The error message
180
- */
181
- _self.errorToConsole = (message: string) => {
182
- _logToConsole("error", message);
183
- _debugExtMsg("error", message);
184
- }
185
-
186
- /**
187
- * Resets the internal message count
188
- */
189
- _self.resetInternalMessageCount = (): void => {
190
- _messageCount = 0;
191
- _messageLogged = {};
192
- };
193
-
194
- /**
195
- * Logs a message to the internal queue.
196
- * @param severity - {LoggingSeverity} - The severity of the log message
197
- * @param message - {_InternalLogMessage} - The message to log.
198
- */
199
- _self.logInternalMessage = _logInternalMessage;
200
-
201
- function _logInternalMessage(severity: LoggingSeverity, message: _InternalLogMessage): void {
202
- if (_areInternalMessagesThrottled()) {
203
- return;
204
- }
205
-
206
- // check if this message type was already logged for this session and if so, don't log it again
207
- let logMessage = true;
208
- const messageKey = AIInternalMessagePrefix + message.messageId;
209
-
210
- // if the session storage is not available, limit to only one message type per page view
211
- if (_messageLogged[messageKey]) {
212
- logMessage = false;
213
- } else {
214
- _messageLogged[messageKey] = true;
215
- }
216
-
217
- if (logMessage) {
218
- // Push the event in the internal queue
219
- if (severity <= _loggingLevelTelemetry) {
220
- _self.queue.push(message);
221
- _messageCount++;
222
- _debugExtMsg((severity === eLoggingSeverity.CRITICAL ? "error" : "warn"), message);
223
- }
224
-
225
- // When throttle limit reached, send a special event
226
- if (_messageCount === _maxInternalMessageLimit) {
227
- const throttleLimitMessage = "Internal events throttle limit per PageView reached for this app.";
228
- const throttleMessage = new _InternalLogMessage(_eInternalMessageId.MessageLimitPerPVExceeded, throttleLimitMessage, false);
229
- _self.queue.push(throttleMessage);
230
- if (severity === eLoggingSeverity.CRITICAL) {
231
- _self.errorToConsole(throttleLimitMessage);
232
- } else {
233
- _self.warnToConsole(throttleLimitMessage);
234
- }
235
- }
236
- }
237
- }
238
-
239
- function _setDefaultsFromConfig(config: IConfiguration) {
240
- // make sure the config is dynamic
241
- let handler = createDynamicConfig(config, defaultValues, _self);
242
- handler.watch((details) => {
243
- let config = details.cfg;
244
- _loggingLevelConsole = config.loggingLevelConsole;
245
- _loggingLevelTelemetry = config.loggingLevelTelemetry;
246
- _maxInternalMessageLimit = config.maxMessageLimit;
247
- _enableDebugExceptions = config.enableDebugExceptions;
248
- });
249
- }
250
-
251
- function _areInternalMessagesThrottled(): boolean {
252
- return _messageCount >= _maxInternalMessageLimit;
253
- }
254
-
255
- function _debugExtMsg(name: string, data: any) {
256
- let dbgExt = getDebugExt(config || {});
257
- if (dbgExt && dbgExt.diagLog) {
258
- dbgExt.diagLog(name, data);
259
- }
260
- }
261
- });
262
- }
263
-
264
- /**
265
- * When this is true the SDK will throw exceptions to aid in debugging.
266
- */
267
- public enableDebugExceptions(): boolean {
268
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
269
- return false;
270
- }
271
-
272
- /**
273
- * 0: OFF (default)
274
- * 1: CRITICAL
275
- * 2: >= WARNING
276
- */
277
- public consoleLoggingLevel(): number {
278
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
279
- return 0;
280
- }
281
-
282
- /**
283
- * 0: OFF
284
- * 1: CRITICAL (default)
285
- * 2: >= WARNING
286
- */
287
- public telemetryLoggingLevel(): number {
288
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
289
- return 1;
290
- }
291
-
292
- /**
293
- * The maximum number of internal messages allowed to be sent per page view
294
- */
295
- public maxInternalMessageLimit(): number {
296
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
297
- return 25;
298
- }
299
-
300
- /**
301
- * This method will throw exceptions in debug mode or attempt to log the error as a console warning.
302
- * @param severity - {LoggingSeverity} - The severity of the log message
303
- * @param message - {_InternalLogMessage} - The log message.
304
- */
305
- public throwInternal(severity: LoggingSeverity, msgId: _InternalMessageId, msg: string, properties?: Object, isUserAct = false) {
306
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
307
- }
308
-
309
- /**
310
- * This will write a warning to the console if possible
311
- * @param message - {string} - The warning message
312
- */
313
- public warnToConsole(message: string) {
314
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
315
- }
316
-
317
- /**
318
- * This will write an error to the console if possible
319
- * @param message - {string} - The warning message
320
- */
321
- public errorToConsole(message: string) {
322
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
323
- }
324
-
325
- /**
326
- * Resets the internal message count
327
- */
328
- public resetInternalMessageCount(): void {
329
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
330
- }
331
-
332
- /**
333
- * Logs a message to the internal queue.
334
- * @param severity - {LoggingSeverity} - The severity of the log message
335
- * @param message - {_InternalLogMessage} - The message to log.
336
- */
337
- public logInternalMessage(severity: LoggingSeverity, message: _InternalLogMessage): void {
338
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
339
- }
340
-
341
- public update(updateState: ITelemetryUpdateState): void {
342
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
343
- }
344
- }
345
-
346
- function _getLogger(logger: IDiagnosticLogger) {
347
- return (logger || new DiagnosticLogger());
348
- }
349
-
350
- /**
351
- * This is a helper method which will call throwInternal on the passed logger, will throw exceptions in
352
- * debug mode or attempt to log the error as a console warning. This helper is provided mostly to better
353
- * support minification as logger.throwInternal() will not compress the publish "throwInternal" used throughout
354
- * the code.
355
- * @param logger - The Diagnostic Logger instance to use.
356
- * @param severity - {LoggingSeverity} - The severity of the log message
357
- * @param message - {_InternalLogMessage} - The log message.
358
- */
359
- export function _throwInternal(logger: IDiagnosticLogger, severity: LoggingSeverity, msgId: _InternalMessageId, msg: string, properties?: Object, isUserAct = false) {
360
- _getLogger(logger).throwInternal(severity, msgId, msg, properties, isUserAct);
361
- }
362
-
363
- /**
364
- * This is a helper method which will call warnToConsole on the passed logger with the provided message.
365
- * @param logger - The Diagnostic Logger instance to use.
366
- * @param message - {_InternalLogMessage} - The log message.
367
- */
368
- export function _warnToConsole(logger: IDiagnosticLogger, message: string) {
369
- _getLogger(logger).warnToConsole(message);
370
- }
371
-
372
- /**
373
- * Logs a message to the internal queue.
374
- * @param logger - The Diagnostic Logger instance to use.
375
- * @param severity - {LoggingSeverity} - The severity of the log message
376
- * @param message - {_InternalLogMessage} - The message to log.
377
- */
378
- export function _logInternalMessage(logger: IDiagnosticLogger, severity: LoggingSeverity, message: _InternalLogMessage) {
379
- _getLogger(logger).logInternalMessage(severity, message);
380
- }
@@ -1,312 +0,0 @@
1
- // Copyright (c) Microsoft Corporation. All rights reserved.
2
- // Licensed under the MIT License.
3
- "use strict";
4
-
5
- import { strShimObject, strShimPrototype, strShimUndefined } from "@microsoft/applicationinsights-shims";
6
- import { getDocument, getInst, getNavigator, getPerformance, hasNavigator, isString, isUndefined, strIndexOf } from "@nevware21/ts-utils";
7
- import { strContains } from "./HelperFuncs";
8
- import { STR_EMPTY } from "./InternalConstants";
9
-
10
- // TypeScript removed this interface so we need to declare the global so we can check for it's existence.
11
- declare var XDomainRequest: any;
12
-
13
- /**
14
- * This file exists to hold environment utilities that are required to check and
15
- * validate the current operating environment. Unless otherwise required, please
16
- * only use defined methods (functions) in this class so that users of these
17
- * functions/properties only need to include those that are used within their own modules.
18
- */
19
-
20
- const strDocumentMode = "documentMode";
21
- const strLocation = "location";
22
- const strConsole = "console";
23
- const strPerformance = "performance";
24
- const strJSON = "JSON";
25
- const strCrypto = "crypto";
26
- const strMsCrypto = "msCrypto";
27
- const strReactNative = "ReactNative";
28
- const strMsie = "msie";
29
- const strTrident = "trident/";
30
- const strXMLHttpRequest = "XMLHttpRequest";
31
-
32
- let _isTrident: boolean = null;
33
- let _navUserAgentCheck: string = null;
34
- let _enableMocks = false;
35
- let _useXDomainRequest: boolean | null = null;
36
- let _beaconsSupported: boolean | null = null;
37
-
38
- function _hasProperty(theClass: any, property: string) {
39
- let supported = false;
40
- if (theClass) {
41
- try {
42
- supported = property in theClass;
43
- if (!supported) {
44
- let proto = theClass[strShimPrototype];
45
- if (proto) {
46
- supported = property in proto;
47
- }
48
- }
49
- } catch (e) {
50
- // Do Nothing
51
- }
52
-
53
- if (!supported) {
54
- try {
55
- let tmp = new theClass();
56
- supported = !isUndefined(tmp[property]);
57
- } catch (e) {
58
- // Do Nothing
59
- }
60
- }
61
- }
62
-
63
- return supported;
64
- }
65
-
66
- /**
67
- * Enable the lookup of test mock objects if requested
68
- * @param enabled
69
- */
70
- export function setEnableEnvMocks(enabled: boolean) {
71
- _enableMocks = enabled;
72
- }
73
-
74
- /**
75
- * Returns the global location object if it is present otherwise null.
76
- * This helper is used to access the location object without causing an exception
77
- * "Uncaught ReferenceError: location is not defined"
78
- */
79
- export function getLocation(checkForMock?: boolean): Location | null {
80
- if (checkForMock && _enableMocks) {
81
- let mockLocation = getInst("__mockLocation") as Location;
82
- if (mockLocation) {
83
- return mockLocation;
84
- }
85
- }
86
-
87
- if (typeof location === strShimObject && location) {
88
- return location;
89
- }
90
-
91
- return getInst(strLocation);
92
- }
93
-
94
- /**
95
- * Returns the global console object
96
- */
97
- export function getConsole(): Console | null {
98
- if (typeof console !== strShimUndefined) {
99
- return console;
100
- }
101
-
102
- return getInst(strConsole);
103
- }
104
-
105
- /**
106
- * Checks if JSON object is available, this is required as we support the API running without a
107
- * window /document (eg. Node server, electron webworkers) and if we attempt to assign a history
108
- * object to a local variable or pass as an argument an "Uncaught ReferenceError: JSON is not defined"
109
- * exception will be thrown.
110
- * Defined as a function to support lazy / late binding environments.
111
- */
112
- export function hasJSON(): boolean {
113
- return Boolean((typeof JSON === strShimObject && JSON) || getInst(strJSON) !== null);
114
- }
115
-
116
- /**
117
- * Returns the global JSON object if it is present otherwise null.
118
- * This helper is used to access the JSON object without causing an exception
119
- * "Uncaught ReferenceError: JSON is not defined"
120
- */
121
- export function getJSON(): JSON | null {
122
- if (hasJSON()) {
123
- return JSON || getInst(strJSON);
124
- }
125
-
126
- return null;
127
- }
128
-
129
- /**
130
- * Returns the crypto object if it is present otherwise null.
131
- * This helper is used to access the crypto object from the current
132
- * global instance which could be window or globalThis for a web worker
133
- */
134
- export function getCrypto(): Crypto | null {
135
- return getInst(strCrypto);
136
- }
137
-
138
- /**
139
- * Returns the crypto object if it is present otherwise null.
140
- * This helper is used to access the crypto object from the current
141
- * global instance which could be window or globalThis for a web worker
142
- */
143
- export function getMsCrypto(): Crypto | null {
144
- return getInst(strMsCrypto);
145
- }
146
-
147
- /**
148
- * Returns whether the environment is reporting that we are running in a React Native Environment
149
- */
150
- export function isReactNative(): boolean {
151
- // If running in React Native, navigator.product will be populated
152
- var nav = getNavigator();
153
- if (nav && nav.product) {
154
- return nav.product === strReactNative;
155
- }
156
-
157
- return false;
158
- }
159
-
160
- /**
161
- * Identifies whether the current environment appears to be IE
162
- */
163
- export function isIE() {
164
- let nav = getNavigator();
165
- if (nav && (nav.userAgent !== _navUserAgentCheck || _isTrident === null)) {
166
- // Added to support test mocking of the user agent
167
- _navUserAgentCheck = nav.userAgent;
168
- let userAgent = (_navUserAgentCheck || STR_EMPTY).toLowerCase();
169
- _isTrident = (strContains(userAgent, strMsie) || strContains(userAgent, strTrident));
170
- }
171
-
172
- return _isTrident;
173
- }
174
-
175
- /**
176
- * Gets IE version returning the document emulation mode if we are running on IE, or null otherwise
177
- */
178
- export function getIEVersion(userAgentStr: string = null): number {
179
- if (!userAgentStr) {
180
- let navigator = getNavigator() || ({} as Navigator);
181
- userAgentStr = navigator ? (navigator.userAgent || STR_EMPTY).toLowerCase() : STR_EMPTY;
182
- }
183
-
184
- var ua = (userAgentStr || STR_EMPTY).toLowerCase();
185
- // Also check for documentMode in case X-UA-Compatible meta tag was included in HTML.
186
- if (strContains(ua, strMsie)) {
187
- let doc = getDocument() || {} as Document;
188
- return Math.max(parseInt(ua.split(strMsie)[1]), (doc[strDocumentMode] || 0));
189
- } else if (strContains(ua, strTrident)) {
190
- let tridentVer = parseInt(ua.split(strTrident)[1]);
191
- if (tridentVer) {
192
- return tridentVer + 4;
193
- }
194
- }
195
-
196
- return null;
197
- }
198
-
199
- export function isSafari(userAgentStr ?: string) {
200
- if (!userAgentStr || !isString(userAgentStr)) {
201
- let navigator = getNavigator() || ({} as Navigator);
202
- userAgentStr = navigator ? (navigator.userAgent || STR_EMPTY).toLowerCase() : STR_EMPTY;
203
- }
204
-
205
- var ua = (userAgentStr || STR_EMPTY).toLowerCase();
206
- return (strIndexOf(ua, "safari") >= 0);
207
- }
208
-
209
- /**
210
- * Checks if HTML5 Beacons are supported in the current environment.
211
- * @returns True if supported, false otherwise.
212
- */
213
- export function isBeaconsSupported(): boolean {
214
- if (_beaconsSupported === null) {
215
- _beaconsSupported = hasNavigator() && Boolean(getNavigator().sendBeacon);
216
- }
217
-
218
- return _beaconsSupported;
219
- }
220
-
221
- /**
222
- * Checks if the Fetch API is supported in the current environment.
223
- * @param withKeepAlive - [Optional] If True, check if fetch is available and it supports the keepalive feature, otherwise only check if fetch is supported
224
- * @returns True if supported, otherwise false
225
- */
226
- export function isFetchSupported(withKeepAlive?: boolean): boolean {
227
- let isSupported = false;
228
- try {
229
- isSupported = !!getInst("fetch");
230
- const request = getInst("Request");
231
- if (isSupported && withKeepAlive && request) {
232
- isSupported = _hasProperty(request, "keepalive");
233
- }
234
- } catch (e) {
235
- // Just Swallow any failure during availability checks
236
- }
237
-
238
- return isSupported;
239
- }
240
-
241
- export function useXDomainRequest(): boolean | undefined {
242
- if (_useXDomainRequest === null) {
243
- _useXDomainRequest = (typeof XDomainRequest !== strShimUndefined);
244
- if (_useXDomainRequest && isXhrSupported()) {
245
- _useXDomainRequest = _useXDomainRequest && !_hasProperty(getInst(strXMLHttpRequest), "withCredentials");
246
- }
247
- }
248
-
249
- return _useXDomainRequest;
250
- }
251
-
252
- /**
253
- * Checks if XMLHttpRequest is supported
254
- * @returns True if supported, otherwise false
255
- */
256
- export function isXhrSupported(): boolean {
257
- let isSupported = false;
258
- try {
259
- const xmlHttpRequest = getInst(strXMLHttpRequest);
260
- isSupported = !!xmlHttpRequest;
261
- } catch (e) {
262
- // Just Swallow any failure during availability checks
263
- }
264
-
265
- return isSupported;
266
- }
267
-
268
-
269
- function _getNamedValue(values: any, name: string) {
270
- if (values) {
271
- for (var i = 0; i < values.length; i++) {
272
- var value = values[i] as any;
273
- if (value.name) {
274
- if(value.name === name) {
275
- return value;
276
- }
277
- }
278
- }
279
- }
280
-
281
- return {};
282
- }
283
-
284
- /**
285
- * Helper function to fetch the named meta-tag from the page.
286
- * @param name
287
- */
288
- export function findMetaTag(name: string): any {
289
- let doc = getDocument();
290
- if (doc && name) {
291
- // Look for a meta-tag
292
- return _getNamedValue(doc.querySelectorAll("meta"), name).content;
293
- }
294
-
295
- return null;
296
- }
297
-
298
- /**
299
- * Helper function to fetch the named server timing value from the page response (first navigation event).
300
- * @param name
301
- */
302
- export function findNamedServerTiming(name: string): any {
303
- let value: any;
304
- let perf = getPerformance();
305
- if (perf) {
306
- // Try looking for a server-timing header
307
- let navPerf = perf.getEntriesByType("navigation") || [];
308
- value = _getNamedValue((navPerf.length > 0 ? navPerf[0] : {} as any).serverTiming, name).description;
309
- }
310
-
311
- return value;
312
- }