@microsoft/applicationinsights-core-js 2.8.4-nightly.2205-09 → 2.8.5-nightly.2206-02

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 (90) hide show
  1. package/browser/applicationinsights-core-js.integrity.json +9 -9
  2. package/browser/applicationinsights-core-js.js +2008 -1811
  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 +1302 -199
  7. package/dist/applicationinsights-core-js.api.md +54 -0
  8. package/dist/applicationinsights-core-js.d.ts +174 -1
  9. package/dist/applicationinsights-core-js.js +2008 -1811
  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 +174 -1
  14. package/dist-esm/JavaScriptSDK/AppInsightsCore.js +1 -1
  15. package/dist-esm/JavaScriptSDK/BaseCore.js +15 -2
  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 +1 -1
  19. package/dist-esm/JavaScriptSDK/Constants.js +1 -1
  20. package/dist-esm/JavaScriptSDK/CookieMgr.js +1 -1
  21. package/dist-esm/JavaScriptSDK/CoreUtils.js +1 -1
  22. package/dist-esm/JavaScriptSDK/DataCacheHelper.js +2 -2
  23. package/dist-esm/JavaScriptSDK/DataCacheHelper.js.map +1 -1
  24. package/dist-esm/JavaScriptSDK/DbgExtensionUtils.js +1 -1
  25. package/dist-esm/JavaScriptSDK/DiagnosticLogger.js +1 -1
  26. package/dist-esm/JavaScriptSDK/EnvUtils.js +40 -1
  27. package/dist-esm/JavaScriptSDK/EnvUtils.js.map +1 -1
  28. package/dist-esm/JavaScriptSDK/EventHelpers.js +1 -1
  29. package/dist-esm/JavaScriptSDK/HelperFuncs.js +1 -1
  30. package/dist-esm/JavaScriptSDK/InstrumentHooks.js +1 -1
  31. package/dist-esm/JavaScriptSDK/InternalConstants.js +1 -1
  32. package/dist-esm/JavaScriptSDK/NotificationManager.js +1 -1
  33. package/dist-esm/JavaScriptSDK/PerfManager.js +1 -1
  34. package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js +1 -1
  35. package/dist-esm/JavaScriptSDK/RandomHelper.js +1 -1
  36. package/dist-esm/JavaScriptSDK/TelemetryHelpers.js +54 -6
  37. package/dist-esm/JavaScriptSDK/TelemetryHelpers.js.map +1 -1
  38. package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js +1 -1
  39. package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js +1 -1
  40. package/dist-esm/JavaScriptSDK/W3cTraceParent.js +172 -0
  41. package/dist-esm/JavaScriptSDK/W3cTraceParent.js.map +1 -0
  42. package/dist-esm/JavaScriptSDK.Enums/EnumHelperFuncs.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/IDistributedTraceContext.js +8 -0
  55. package/dist-esm/JavaScriptSDK.Interfaces/IDistributedTraceContext.js.map +1 -0
  56. package/dist-esm/JavaScriptSDK.Interfaces/IInstrumentHooks.js +1 -1
  57. package/dist-esm/JavaScriptSDK.Interfaces/INotificationListener.js +1 -1
  58. package/dist-esm/JavaScriptSDK.Interfaces/INotificationManager.js +1 -1
  59. package/dist-esm/JavaScriptSDK.Interfaces/IPerfEvent.js +1 -1
  60. package/dist-esm/JavaScriptSDK.Interfaces/IPerfManager.js +1 -1
  61. package/dist-esm/JavaScriptSDK.Interfaces/IProcessTelemetryContext.js +1 -1
  62. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js +1 -1
  63. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryItem.js +1 -1
  64. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPlugin.js +1 -1
  65. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js +1 -1
  66. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js +1 -1
  67. package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUpdateState.js +1 -1
  68. package/dist-esm/JavaScriptSDK.Interfaces/ITraceParent.js +8 -0
  69. package/dist-esm/JavaScriptSDK.Interfaces/ITraceParent.js.map +1 -0
  70. package/dist-esm/JavaScriptSDK.Interfaces/IUnloadableComponent.js +1 -1
  71. package/dist-esm/applicationinsights-core-js.js +3 -2
  72. package/dist-esm/applicationinsights-core-js.js.map +1 -1
  73. package/package.json +1 -1
  74. package/src/JavaScriptSDK/BaseCore.ts +32 -1
  75. package/src/JavaScriptSDK/DataCacheHelper.ts +1 -1
  76. package/src/JavaScriptSDK/EnvUtils.ts +45 -0
  77. package/src/JavaScriptSDK/TelemetryHelpers.ts +57 -5
  78. package/src/JavaScriptSDK/W3cTraceParent.ts +196 -0
  79. package/src/JavaScriptSDK.Interfaces/IAppInsightsCore.ts +12 -0
  80. package/src/JavaScriptSDK.Interfaces/IDistributedTraceContext.ts +54 -0
  81. package/src/JavaScriptSDK.Interfaces/ITraceParent.ts +38 -0
  82. package/types/JavaScriptSDK/BaseCore.d.ts +10 -0
  83. package/types/JavaScriptSDK/EnvUtils.d.ts +10 -0
  84. package/types/JavaScriptSDK/TelemetryHelpers.d.ts +7 -0
  85. package/types/JavaScriptSDK/W3cTraceParent.d.ts +59 -0
  86. package/types/JavaScriptSDK.Interfaces/IAppInsightsCore.d.ts +10 -0
  87. package/types/JavaScriptSDK.Interfaces/IDistributedTraceContext.d.ts +43 -0
  88. package/types/JavaScriptSDK.Interfaces/ITraceParent.d.ts +32 -0
  89. package/types/applicationinsights-core-js.d.ts +4 -1
  90. package/types/tsdoc-metadata.json +1 -1
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Microsoft Application Insights Core Javascript SDK, 2.8.4-nightly.2205-09
2
+ * Microsoft Application Insights Core Javascript SDK, 2.8.5-nightly.2206-02
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  *
5
5
  * Microsoft Application Insights Team
@@ -236,6 +236,15 @@ export declare class BaseCore implements IAppInsightsCore {
236
236
  * @returns - true if the callback will be return after the flush is complete otherwise the caller should assume that any provided callback will never be called
237
237
  */
238
238
  flush(isAsync?: boolean, callBack?: (flushComplete?: boolean) => void, sendReason?: SendRequestReason): void;
239
+ /**
240
+ * Gets the current distributed trace context for this instance if available
241
+ * @param createNew - Optional flag to create a new instance if one doesn't currently exist, defaults to true
242
+ */
243
+ getTraceCtx(createNew?: boolean): IDistributedTraceContext | null;
244
+ /**
245
+ * Sets the current distributed trace context for this instance if available
246
+ */
247
+ setTraceCtx(newTracectx: IDistributedTraceContext): void;
239
248
  protected releaseQueue(): void;
240
249
  /**
241
250
  * Hook for Core extensions to allow them to update their own configuration before updating all of the plugins.
@@ -389,6 +398,16 @@ export declare function createEnumStyle<E>(values: {
389
398
  */
390
399
  export declare function createProcessTelemetryContext(telemetryChain: ITelemetryPluginChain | null, config: IConfiguration, core: IAppInsightsCore, startAt?: IPlugin): IProcessTelemetryContext;
391
400
 
401
+ /**
402
+ * Create a new ITraceParent instance using the provided values.
403
+ * @param traceId - The traceId to use, when invalid a new random W3C id will be generated.
404
+ * @param spanId - The parent/span id to use, a new random value will be generated if it is invalid.
405
+ * @param flags - The traceFlags to use, defaults to zero (0) if not supplied or invalid
406
+ * @param version - The version to used, defaults to version "01" if not supplied or invalid.
407
+ * @returns
408
+ */
409
+ export declare function createTraceParent(traceId?: string, spanId?: string, flags?: number, version?: string): ITraceParent;
410
+
392
411
  export declare function createUniqueNamespace(name: string, includeVersion?: boolean): string;
393
412
 
394
413
  export declare function createUnloadHandlerContainer(): {
@@ -683,6 +702,34 @@ export declare const EventsDiscardedReason: EnumValue<typeof eEventsDiscardedRea
683
702
 
684
703
  export declare type EventsDiscardedReason = number | eEventsDiscardedReason;
685
704
 
705
+ /**
706
+ * Helper function to fetch the named meta-tag from the page.
707
+ * @param name
708
+ */
709
+ export declare function findMetaTag(name: string): any;
710
+
711
+ /**
712
+ * Helper function to fetch the named server timing value from the page response (first navigation event).
713
+ * @param name
714
+ */
715
+ export declare function findNamedServerTiming(name: string): any;
716
+
717
+ /**
718
+ * Helper function to fetch the passed traceparent from the page, looking for it as a meta-tag or a Server-Timing header.
719
+ * @returns
720
+ */
721
+ export declare function findW3cTraceParent(): ITraceParent;
722
+
723
+ /**
724
+ * Format the ITraceParent value as a string using the supported and know version formats.
725
+ * So even if the passed traceParent is a later version the string value returned from this
726
+ * function will convert it to only the known version formats.
727
+ * This currently only supports version "00" and invalid "ff"
728
+ * @param value - The parsed traceParent value
729
+ * @returns
730
+ */
731
+ export declare function formatTraceParent(value: ITraceParent): string;
732
+
686
733
  /**
687
734
  * generate W3C trace id
688
735
  */
@@ -942,6 +989,15 @@ export declare interface IAppInsightsCore extends IPerfManagerProvider {
942
989
  * @returns - true if the callback will be return after the flush is complete otherwise the caller should assume that any provided callback will never be called
943
990
  */
944
991
  flush(isAsync?: boolean, callBack?: (flushComplete?: boolean) => void, sendReason?: SendRequestReason, cbTimeout?: number): boolean | void;
992
+ /**
993
+ * Gets the current distributed trace context for this instance if available
994
+ * @param createNew - Optional flag to create a new instance if one doesn't currently exist, defaults to true
995
+ */
996
+ getTraceCtx(createNew?: boolean): IDistributedTraceContext | null;
997
+ /**
998
+ * Sets the current distributed trace context for this instance if available
999
+ */
1000
+ setTraceCtx(newTraceCtx: IDistributedTraceContext | null | undefined): void;
945
1001
  }
946
1002
 
947
1003
  export declare interface IBaseProcessingContext {
@@ -1516,6 +1572,50 @@ export declare interface IDiagnosticLogger {
1516
1572
  logInternalMessage?(severity: LoggingSeverity, message: _InternalLogMessage): void;
1517
1573
  }
1518
1574
 
1575
+ export declare interface IDistributedTraceContext {
1576
+ /**
1577
+ * Returns the current name of the page
1578
+ */
1579
+ getName(): string;
1580
+ /**
1581
+ * Sets the current name of the page
1582
+ * @param pageName
1583
+ */
1584
+ setName(pageName: string): void;
1585
+ /**
1586
+ * Returns the unique identifier for a trace. All requests / spans from the same trace share the same traceId.
1587
+ * Must be read from incoming headers or generated according to the W3C TraceContext specification,
1588
+ * in a hex representation of 16-byte array. A.k.a. trace-id, TraceID or Distributed TraceID
1589
+ */
1590
+ getTraceId(): string;
1591
+ /**
1592
+ * Set the unique identifier for a trace. All requests / spans from the same trace share the same traceId.
1593
+ * Must be conform to the W3C TraceContext specification, in a hex representation of 16-byte array.
1594
+ * A.k.a. trace-id, TraceID or Distributed TraceID https://www.w3.org/TR/trace-context/#trace-id
1595
+ */
1596
+ setTraceId(newValue: string): void;
1597
+ /**
1598
+ * Self-generated 8-bytes identifier of the incoming request. Must be a hex representation of 8-byte array.
1599
+ * Also know as the parentId, used to link requests together
1600
+ */
1601
+ getSpanId(): string;
1602
+ /**
1603
+ * Self-generated 8-bytes identifier of the incoming request. Must be a hex representation of 8-byte array.
1604
+ * Also know as the parentId, used to link requests together
1605
+ * https://www.w3.org/TR/trace-context/#parent-id
1606
+ */
1607
+ setSpanId(newValue: string): void;
1608
+ /**
1609
+ * An integer representation of the W3C TraceContext trace-flags.
1610
+ */
1611
+ getTraceFlags(): number | undefined;
1612
+ /**
1613
+ * https://www.w3.org/TR/trace-context/#trace-flags
1614
+ * @param newValue
1615
+ */
1616
+ setTraceFlags(newValue?: number): void;
1617
+ }
1618
+
1519
1619
  export declare interface IEventHelper {
1520
1620
  /**
1521
1621
  * Binds the specified function to an event, so that the function gets called whenever the event fires on the object
@@ -2065,6 +2165,13 @@ export declare function isReactNative(): boolean;
2065
2165
 
2066
2166
  export declare function isSafari(userAgentStr?: string): boolean;
2067
2167
 
2168
+ /**
2169
+ * Is the parsed traceParent indicating that the trace is currently sampled.
2170
+ * @param value - The parsed traceParent value
2171
+ * @returns
2172
+ */
2173
+ export declare function isSampledFlag(value: ITraceParent): boolean;
2174
+
2068
2175
  /**
2069
2176
  * Checks if the type of value is a string.
2070
2177
  * @param {any} value - Value to be checked.
@@ -2086,6 +2193,31 @@ export declare function isTypeof(value: any, theType: string): boolean;
2086
2193
 
2087
2194
  export declare function isUndefined(value: any): value is undefined;
2088
2195
 
2196
+ /**
2197
+ * Is the provided W3c span id (aka. parent id) a valid string representation, it must be a 16-character
2198
+ * string of lowercase hexadecimal characters, for example, 00f067aa0ba902b7.
2199
+ * If all characters are zero (0000000000000000) this is considered an invalid value.
2200
+ * @param value - The W3c span id to be validated
2201
+ * @returns true if valid otherwise false
2202
+ */
2203
+ export declare function isValidSpanId(value: string): boolean;
2204
+
2205
+ /**
2206
+ * Is the provided W3c Trace Id a valid string representation, it must be a 32-character string
2207
+ * of lowercase hexadecimal characters for example, 4bf92f3577b34da6a3ce929d0e0e4736.
2208
+ * If all characters as zero (00000000000000000000000000000000) it will be considered an invalid value.
2209
+ * @param value - The W3c trace Id to be validated
2210
+ * @returns true if valid otherwise false
2211
+ */
2212
+ export declare function isValidTraceId(value: string): boolean;
2213
+
2214
+ /**
2215
+ * Validates that the provided ITraceParent instance conforms to the currently supported specifications
2216
+ * @param value
2217
+ * @returns
2218
+ */
2219
+ export declare function isValidTraceParent(value: ITraceParent): boolean;
2220
+
2089
2221
  /**
2090
2222
  * Checks if XMLHttpRequest is supported
2091
2223
  * @returns True if supported, otherwise false
@@ -2235,6 +2367,39 @@ export declare interface ITelemetryUpdateState {
2235
2367
  removed?: IPlugin[];
2236
2368
  }
2237
2369
 
2370
+ /**
2371
+ * This interface represents the components of a W3C traceparent header
2372
+ */
2373
+ export declare interface ITraceParent {
2374
+ /**
2375
+ * The version of the definition, this MUST be a string with a length of 2 and only contain lowercase
2376
+ * hexadecimal characters. A value of 'ff' is considered to be an invalid version.
2377
+ */
2378
+ version: string;
2379
+ /**
2380
+ * This is the ID of the whole trace forest and is used to uniquely identify a distributed trace
2381
+ * through a system. It is represented as a 32-character string of lowercase hexadecimal characters,
2382
+ * for example, 4bf92f3577b34da6a3ce929d0e0e4736.
2383
+ * All characters as zero (00000000000000000000000000000000) is considered an invalid value.
2384
+ */
2385
+ traceId: string;
2386
+ /**
2387
+ * This is the ID of the current request as known by the caller (in some tracing systems, this is also
2388
+ * known as the parent-id, where a span is the execution of a client request). It is represented as an
2389
+ * 16-character string of lowercase hexadecimal characters, for example, 00f067aa0ba902b7.
2390
+ * All bytes as zero (0000000000000000) is considered an invalid value.
2391
+ */
2392
+ spanId: string;
2393
+ /**
2394
+ * An 8-bit value of flags that controls tracing such as sampling, trace level, etc. These flags are
2395
+ * recommendations given by the caller rather than strict rules to follow.
2396
+ * As this is a bit field, you cannot interpret flags by decoding the hex value and looking at the resulting
2397
+ * number. For example, a flag 00000001 could be encoded as 01 in hex, or 09 in hex if present with the flag
2398
+ * 00001000. A common mistake in bit fields is forgetting to mask when interpreting flags.
2399
+ */
2400
+ traceFlags: number;
2401
+ }
2402
+
2238
2403
  export declare interface IUnloadableComponent {
2239
2404
  /**
2240
2405
  * Teardown / Unload hook to allow implementations to perform some additional unload operations before the BaseTelemetryPlugin
@@ -2413,6 +2578,14 @@ export declare function objToString(obj: any): any;
2413
2578
  */
2414
2579
  export declare function optimizeObject<T>(theObject: T): T;
2415
2580
 
2581
+ /**
2582
+ * Attempt to parse the provided string as a W3C TraceParent header value (https://www.w3.org/TR/trace-context/#traceparent-header)
2583
+ *
2584
+ * @param value
2585
+ * @returns
2586
+ */
2587
+ export declare function parseTraceParent(value: string): ITraceParent;
2588
+
2416
2589
  export declare class PerfEvent implements IPerfEvent {
2417
2590
  static ParentContextKey: string;
2418
2591
  static ChildrenContextKey: string;
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Core, 2.8.4-nightly.2205-09
2
+ * Application Insights JavaScript SDK - Core, 2.8.5-nightly.2206-02
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
  import { __extendsFn as __extends } from "@microsoft/applicationinsights-shims";
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Core, 2.8.4-nightly.2205-09
2
+ * Application Insights JavaScript SDK - Core, 2.8.5-nightly.2206-02
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -9,7 +9,7 @@ import { __spreadArrayFn as __spreadArray } from "@microsoft/applicationinsights
9
9
  import { objCreateFn } from "@microsoft/applicationinsights-shims";
10
10
  import dynamicProto from "@microsoft/dynamicproto-js";
11
11
  import { createProcessTelemetryContext, createProcessTelemetryUnloadContext, createProcessTelemetryUpdateContext, createTelemetryProxyChain } from "./ProcessTelemetryContext";
12
- import { initializePlugins, sortPlugins, _getPluginState } from "./TelemetryHelpers";
12
+ import { createDistributedTraceContext, initializePlugins, sortPlugins, _getPluginState } from "./TelemetryHelpers";
13
13
  import { getGblPerfMgr, PerfManager } from "./PerfManager";
14
14
  import { createCookieMgr } from "./CookieMgr";
15
15
  import { arrForEach, isNullOrUndefined, getSetValue, setValue, isNotTruthy, isFunction, objExtend, objFreeze, proxyFunctionAs, proxyFunctions, throwError, toISOString, arrIndexOf } from "./HelperFuncs";
@@ -112,6 +112,7 @@ var BaseCore = /** @class */ (function () {
112
112
  var _evtNamespace;
113
113
  var _unloadHandlers;
114
114
  var _debugListener;
115
+ var _traceCtx;
115
116
  /**
116
117
  * Internal log poller
117
118
  */
@@ -354,6 +355,15 @@ var BaseCore = /** @class */ (function () {
354
355
  return _evtNamespace;
355
356
  };
356
357
  _self.flush = _flushChannels;
358
+ _self.getTraceCtx = function (createNew) {
359
+ if (!_traceCtx) {
360
+ _traceCtx = createDistributedTraceContext();
361
+ }
362
+ return _traceCtx;
363
+ };
364
+ _self.setTraceCtx = function (traceCtx) {
365
+ _traceCtx = traceCtx || null;
366
+ };
357
367
  // Create the addUnloadCb
358
368
  proxyFunctionAs(_self, "addUnloadCb", function () { return _unloadHandlers; }, "add");
359
369
  function _initDefaults() {
@@ -378,6 +388,7 @@ var BaseCore = /** @class */ (function () {
378
388
  _internalLogsEventName = null;
379
389
  _evtNamespace = createUniqueNamespace("AIBaseCore", true);
380
390
  _unloadHandlers = createUnloadHandlerContainer();
391
+ _traceCtx = null;
381
392
  }
382
393
  function _createTelCtx() {
383
394
  return createProcessTelemetryContext(_getPluginChain(), _self.config, _self);
@@ -610,6 +621,8 @@ var BaseCore = /** @class */ (function () {
610
621
  // Removed Stub for BaseCore.prototype.evtNamespace.
611
622
  // Removed Stub for BaseCore.prototype.addUnloadCb.
612
623
  // Removed Stub for BaseCore.prototype.flush.
624
+ // Removed Stub for BaseCore.prototype.getTraceCtx.
625
+ // Removed Stub for BaseCore.prototype.setTraceCtx.
613
626
  // Removed Stub for BaseCore.prototype.releaseQueue.
614
627
  // Removed Stub for BaseCore.prototype._updateHook.
615
628
  return BaseCore;
@@ -1 +1 @@
1
- {"version":3,"file":"BaseCore.js.map","sources":["BaseCore.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\n\"use strict\";\r\nimport { __spreadArray } from \"tslib\";\r\nimport { objCreateFn } from \"@microsoft/applicationinsights-shims\";\r\nimport dynamicProto from \"@microsoft/dynamicproto-js\";\r\nimport { createProcessTelemetryContext, createProcessTelemetryUnloadContext, createProcessTelemetryUpdateContext, createTelemetryProxyChain } from \"./ProcessTelemetryContext\";\r\nimport { initializePlugins, sortPlugins, _getPluginState } from \"./TelemetryHelpers\";\r\nimport { getGblPerfMgr, PerfManager } from \"./PerfManager\";\r\nimport { createCookieMgr } from \"./CookieMgr\";\r\nimport { arrForEach, isNullOrUndefined, getSetValue, setValue, isNotTruthy, isFunction, objExtend, objFreeze, proxyFunctionAs, proxyFunctions, throwError, toISOString, arrIndexOf } from \"./HelperFuncs\";\r\nimport { strExtensionConfig, strIKey } from \"./Constants\";\r\nimport { DiagnosticLogger, _InternalLogMessage, _throwInternal, _warnToConsole } from \"./DiagnosticLogger\";\r\nimport { getDebugListener } from \"./DbgExtensionUtils\";\r\nimport { ChannelControllerPriority, createChannelControllerPlugin, createChannelQueues } from \"./ChannelController\";\r\nimport { TelemetryInitializerPlugin } from \"./TelemetryInitializerPlugin\";\r\nimport { createUniqueNamespace } from \"./DataCacheHelper\";\r\nimport { createUnloadHandlerContainer } from \"./UnloadHandlerContainer\";\r\nimport { strAddNotificationListener, strDisabled, strEventsDiscarded, strEventsSendRequest, strEventsSent, strRemoveNotificationListener, strTeardown } from \"./InternalConstants\";\r\nvar strValidationError = \"Plugins must provide initialize method\";\r\nvar strNotificationManager = \"_notificationManager\";\r\nvar strSdkUnloadingError = \"SDK is still unloading...\";\r\nvar strSdkNotInitialized = \"SDK is not initialized\";\r\n// const strPluginUnloadFailed = \"Failed to unload plugin\";\r\nvar defaultInitConfig = {\r\n // Have the Diagnostic Logger default to log critical errors to the console\r\n loggingLevelConsole: 1 /* eLoggingSeverity.CRITICAL */\r\n};\r\n/**\r\n * Helper to create the default performance manager\r\n * @param core\r\n * @param notificationMgr\r\n */\r\nfunction _createPerfManager(core, notificationMgr) {\r\n return new PerfManager(notificationMgr);\r\n}\r\nfunction _validateExtensions(logger, channelPriority, allExtensions) {\r\n // Concat all available extensions\r\n var coreExtensions = [];\r\n // Check if any two extensions have the same priority, then warn to console\r\n // And extract the local extensions from the\r\n var extPriorities = {};\r\n // Extension validation\r\n arrForEach(allExtensions, function (ext) {\r\n if (isNullOrUndefined(ext) || isNullOrUndefined(ext.initialize)) {\r\n throwError(strValidationError);\r\n }\r\n var extPriority = ext.priority;\r\n var identifier = ext.identifier;\r\n if (ext && extPriority) {\r\n if (!isNullOrUndefined(extPriorities[extPriority])) {\r\n _warnToConsole(logger, \"Two extensions have same priority #\" + extPriority + \" - \" + extPriorities[extPriority] + \", \" + identifier);\r\n }\r\n else {\r\n // set a value\r\n extPriorities[extPriority] = identifier;\r\n }\r\n }\r\n // Split extensions to core and channelController\r\n if (!extPriority || extPriority < channelPriority) {\r\n // Add to core extension that will be managed by BaseCore\r\n coreExtensions.push(ext);\r\n }\r\n });\r\n return {\r\n all: allExtensions,\r\n core: coreExtensions\r\n };\r\n}\r\nfunction _isPluginPresent(thePlugin, plugins) {\r\n var exists = false;\r\n arrForEach(plugins, function (plugin) {\r\n if (plugin === thePlugin) {\r\n exists = true;\r\n return -1;\r\n }\r\n });\r\n return exists;\r\n}\r\nfunction _createDummyNotificationManager() {\r\n var _a;\r\n return objCreateFn((_a = {},\r\n _a[strAddNotificationListener] = function (listener) { },\r\n _a[strRemoveNotificationListener] = function (listener) { },\r\n _a[strEventsSent] = function (events) { },\r\n _a[strEventsDiscarded] = function (events, reason) { },\r\n _a[strEventsSendRequest] = function (sendReason, isAsync) { },\r\n _a));\r\n}\r\nvar BaseCore = /** @class */ (function () {\r\n function BaseCore() {\r\n // NOTE!: DON'T set default values here, instead set them in the _initDefaults() function as it is also called during teardown()\r\n var _isInitialized;\r\n var _eventQueue;\r\n var _notificationManager;\r\n var _perfManager;\r\n var _cfgPerfManager;\r\n var _cookieManager;\r\n var _pluginChain;\r\n var _configExtensions;\r\n var _coreExtensions;\r\n var _channelControl;\r\n var _channelConfig;\r\n var _channelQueue;\r\n var _isUnloading;\r\n var _telemetryInitializerPlugin;\r\n var _internalLogsEventName;\r\n var _evtNamespace;\r\n var _unloadHandlers;\r\n var _debugListener;\r\n /**\r\n * Internal log poller\r\n */\r\n var _internalLogPoller = 0;\r\n dynamicProto(BaseCore, this, function (_self) {\r\n // Set the default values (also called during teardown)\r\n _initDefaults();\r\n _self.isInitialized = function () { return _isInitialized; };\r\n _self.initialize = function (config, extensions, logger, notificationManager) {\r\n if (_isUnloading) {\r\n throwError(strSdkUnloadingError);\r\n }\r\n // Make sure core is only initialized once\r\n if (_self.isInitialized()) {\r\n throwError(\"Core should not be initialized more than once\");\r\n }\r\n if (!config || isNullOrUndefined(config.instrumentationKey)) {\r\n throwError(\"Please provide instrumentation key\");\r\n }\r\n _notificationManager = notificationManager;\r\n // For backward compatibility only\r\n _self[strNotificationManager] = notificationManager;\r\n _self.config = config || {};\r\n _initDebugListener(config);\r\n _initPerfManager(config);\r\n config.extensions = isNullOrUndefined(config.extensions) ? [] : config.extensions;\r\n // add notification to the extensions in the config so other plugins can access it\r\n _initExtConfig(config);\r\n if (logger) {\r\n _self.logger = logger;\r\n }\r\n // Extension validation\r\n _configExtensions = [];\r\n _configExtensions.push.apply(_configExtensions, __spreadArray(__spreadArray([], extensions, false), config.extensions, false));\r\n _channelConfig = (config || {}).channels;\r\n _initPluginChain(config, null);\r\n if (!_channelQueue || _channelQueue.length === 0) {\r\n throwError(\"No channels available\");\r\n }\r\n _isInitialized = true;\r\n _self.releaseQueue();\r\n };\r\n _self.getTransmissionControls = function () {\r\n var controls = [];\r\n if (_channelQueue) {\r\n arrForEach(_channelQueue, function (channels) {\r\n controls.push(channels.queue);\r\n });\r\n }\r\n return objFreeze(controls);\r\n };\r\n _self.track = function (telemetryItem) {\r\n // setup default iKey if not passed in\r\n setValue(telemetryItem, strIKey, _self.config.instrumentationKey, null, isNotTruthy);\r\n // add default timestamp if not passed in\r\n setValue(telemetryItem, \"time\", toISOString(new Date()), null, isNotTruthy);\r\n // Common Schema 4.0\r\n setValue(telemetryItem, \"ver\", \"4.0\", null, isNullOrUndefined);\r\n if (!_isUnloading && _self.isInitialized()) {\r\n // Process the telemetry plugin chain\r\n _createTelCtx().processNext(telemetryItem);\r\n }\r\n else {\r\n // Queue events until all extensions are initialized\r\n _eventQueue.push(telemetryItem);\r\n }\r\n };\r\n _self.getProcessTelContext = _createTelCtx;\r\n _self.getNotifyMgr = function () {\r\n if (!_notificationManager) {\r\n // Create Dummy notification manager\r\n _notificationManager = _createDummyNotificationManager();\r\n // For backward compatibility only\r\n _self[strNotificationManager] = _notificationManager;\r\n }\r\n return _notificationManager;\r\n };\r\n /**\r\n * Adds a notification listener. The SDK calls methods on the listener when an appropriate notification is raised.\r\n * The added plugins must raise notifications. If the plugins do not implement the notifications, then no methods will be\r\n * called.\r\n * @param {INotificationListener} listener - An INotificationListener object.\r\n */\r\n _self[strAddNotificationListener] = function (listener) {\r\n if (_notificationManager) {\r\n _notificationManager[strAddNotificationListener](listener);\r\n }\r\n };\r\n /**\r\n * Removes all instances of the listener.\r\n * @param {INotificationListener} listener - INotificationListener to remove.\r\n */\r\n _self[strRemoveNotificationListener] = function (listener) {\r\n if (_notificationManager) {\r\n _notificationManager[strRemoveNotificationListener](listener);\r\n }\r\n };\r\n _self.getCookieMgr = function () {\r\n if (!_cookieManager) {\r\n _cookieManager = createCookieMgr(_self.config, _self.logger);\r\n }\r\n return _cookieManager;\r\n };\r\n _self.setCookieMgr = function (cookieMgr) {\r\n _cookieManager = cookieMgr;\r\n };\r\n _self.getPerfMgr = function () {\r\n if (!_perfManager && !_cfgPerfManager) {\r\n if (_self.config && _self.config.enablePerfMgr && isFunction(_self.config.createPerfMgr)) {\r\n _cfgPerfManager = _self.config.createPerfMgr(_self, _self.getNotifyMgr());\r\n }\r\n }\r\n return _perfManager || _cfgPerfManager || getGblPerfMgr();\r\n };\r\n _self.setPerfMgr = function (perfMgr) {\r\n _perfManager = perfMgr;\r\n };\r\n _self.eventCnt = function () {\r\n return _eventQueue.length;\r\n };\r\n _self.releaseQueue = function () {\r\n if (_isInitialized && _eventQueue.length > 0) {\r\n var eventQueue = _eventQueue;\r\n _eventQueue = [];\r\n arrForEach(eventQueue, function (event) {\r\n _createTelCtx().processNext(event);\r\n });\r\n }\r\n };\r\n /**\r\n * Periodically check logger.queue for log messages to be flushed\r\n */\r\n _self.pollInternalLogs = function (eventName) {\r\n _internalLogsEventName = eventName || null;\r\n var interval = _self.config.diagnosticLogInterval;\r\n if (!interval || !(interval > 0)) {\r\n interval = 10000;\r\n }\r\n if (_internalLogPoller) {\r\n clearInterval(_internalLogPoller);\r\n }\r\n _internalLogPoller = setInterval(function () {\r\n _flushInternalLogs();\r\n }, interval);\r\n return _internalLogPoller;\r\n };\r\n /**\r\n * Stop polling log messages from logger.queue\r\n */\r\n _self.stopPollingInternalLogs = function () {\r\n if (_internalLogPoller) {\r\n clearInterval(_internalLogPoller);\r\n _internalLogPoller = 0;\r\n _flushInternalLogs();\r\n }\r\n };\r\n // Add addTelemetryInitializer\r\n proxyFunctions(_self, function () { return _telemetryInitializerPlugin; }, [\"addTelemetryInitializer\"]);\r\n _self.unload = function (isAsync, unloadComplete, cbTimeout) {\r\n if (isAsync === void 0) { isAsync = true; }\r\n if (!_isInitialized) {\r\n // The SDK is not initialized\r\n throwError(strSdkNotInitialized);\r\n }\r\n // Check if the SDK still unloading so throw\r\n if (_isUnloading) {\r\n // The SDK is already unloading\r\n throwError(strSdkUnloadingError);\r\n }\r\n var unloadState = {\r\n reason: 50 /* TelemetryUnloadReason.SdkUnload */,\r\n isAsync: isAsync,\r\n flushComplete: false\r\n };\r\n var processUnloadCtx = createProcessTelemetryUnloadContext(_getPluginChain(), _self);\r\n processUnloadCtx.onComplete(function () {\r\n _initDefaults();\r\n unloadComplete && unloadComplete(unloadState);\r\n }, _self);\r\n function _doUnload(flushComplete) {\r\n unloadState.flushComplete = flushComplete;\r\n _isUnloading = true;\r\n // Run all of the unload handlers first (before unloading the plugins)\r\n _unloadHandlers.run(processUnloadCtx, unloadState);\r\n // Stop polling the internal logs\r\n _self.stopPollingInternalLogs();\r\n // Start unloading the components, from this point onwards the SDK should be considered to be in an unstable state\r\n processUnloadCtx.processNext(unloadState);\r\n }\r\n if (!_flushChannels(isAsync, _doUnload, 6 /* SendRequestReason.SdkUnload */, cbTimeout)) {\r\n _doUnload(false);\r\n }\r\n };\r\n _self.getPlugin = _getPlugin;\r\n _self.addPlugin = function (plugin, replaceExisting, isAsync, addCb) {\r\n if (!plugin) {\r\n addCb && addCb(false);\r\n _logOrThrowError(strValidationError);\r\n return;\r\n }\r\n var existingPlugin = _getPlugin(plugin.identifier);\r\n if (existingPlugin && !replaceExisting) {\r\n addCb && addCb(false);\r\n _logOrThrowError(\"Plugin [\" + plugin.identifier + \"] is already loaded!\");\r\n return;\r\n }\r\n var updateState = {\r\n reason: 16 /* TelemetryUpdateReason.PluginAdded */\r\n };\r\n function _addPlugin(removed) {\r\n _configExtensions.push(plugin);\r\n updateState.added = [plugin];\r\n // Re-Initialize the plugin chain\r\n _initPluginChain(_self.config, updateState);\r\n addCb && addCb(true);\r\n }\r\n if (existingPlugin) {\r\n var removedPlugins_1 = [existingPlugin.plugin];\r\n var unloadState = {\r\n reason: 2 /* TelemetryUnloadReason.PluginReplace */,\r\n isAsync: !!isAsync\r\n };\r\n _removePlugins(removedPlugins_1, unloadState, function (removed) {\r\n if (!removed) {\r\n // Previous plugin was successfully removed or was not installed\r\n addCb && addCb(false);\r\n }\r\n else {\r\n updateState.removed = removedPlugins_1;\r\n updateState.reason |= 32 /* TelemetryUpdateReason.PluginRemoved */;\r\n _addPlugin(true);\r\n }\r\n });\r\n }\r\n else {\r\n _addPlugin(false);\r\n }\r\n };\r\n _self.evtNamespace = function () {\r\n return _evtNamespace;\r\n };\r\n _self.flush = _flushChannels;\r\n // Create the addUnloadCb\r\n proxyFunctionAs(_self, \"addUnloadCb\", function () { return _unloadHandlers; }, \"add\");\r\n function _initDefaults() {\r\n _isInitialized = false;\r\n // Use a default logger so initialization errors are not dropped on the floor with full logging\r\n _self.config = objExtend(true, {}, defaultInitConfig);\r\n _self.logger = new DiagnosticLogger(_self.config);\r\n _self._extensions = [];\r\n _telemetryInitializerPlugin = new TelemetryInitializerPlugin();\r\n _eventQueue = [];\r\n _notificationManager = null;\r\n _perfManager = null;\r\n _cfgPerfManager = null;\r\n _cookieManager = null;\r\n _pluginChain = null;\r\n _coreExtensions = null;\r\n _configExtensions = [];\r\n _channelControl = null;\r\n _channelConfig = null;\r\n _channelQueue = null;\r\n _isUnloading = false;\r\n _internalLogsEventName = null;\r\n _evtNamespace = createUniqueNamespace(\"AIBaseCore\", true);\r\n _unloadHandlers = createUnloadHandlerContainer();\r\n }\r\n function _createTelCtx() {\r\n return createProcessTelemetryContext(_getPluginChain(), _self.config, _self);\r\n }\r\n // Initialize or Re-initialize the plugins\r\n function _initPluginChain(config, updateState) {\r\n // Extension validation\r\n var theExtensions = _validateExtensions(_self.logger, ChannelControllerPriority, _configExtensions);\r\n _coreExtensions = theExtensions.core;\r\n _pluginChain = null;\r\n // Sort the complete set of extensions by priority\r\n var allExtensions = theExtensions.all;\r\n // Initialize the Channel Queues and the channel plugins first\r\n _channelQueue = objFreeze(createChannelQueues(_channelConfig, allExtensions, config, _self));\r\n if (_channelControl) {\r\n // During add / remove of a plugin this may get called again, so don't re-add if already present\r\n // But we also want the controller as the last, so remove if already present\r\n // And reusing the existing instance, just in case an installed plugin has a reference and\r\n // is using it.\r\n var idx = arrIndexOf(allExtensions, _channelControl);\r\n if (idx !== -1) {\r\n allExtensions.splice(idx, 1);\r\n }\r\n idx = arrIndexOf(_coreExtensions, _channelControl);\r\n if (idx !== -1) {\r\n _coreExtensions.splice(idx, 1);\r\n }\r\n _channelControl._setQueue(_channelQueue);\r\n }\r\n else {\r\n _channelControl = createChannelControllerPlugin(_channelQueue, _self);\r\n }\r\n // Add on \"channelController\" as the last \"plugin\"\r\n allExtensions.push(_channelControl);\r\n _coreExtensions.push(_channelControl);\r\n // Required to allow plugins to call core.getPlugin() during their own initialization\r\n _self._extensions = sortPlugins(allExtensions);\r\n // Initialize the controls\r\n _channelControl.initialize(config, _self, allExtensions);\r\n initializePlugins(_createTelCtx(), allExtensions);\r\n // Now reset the extensions to just those being managed by Basecore\r\n _self._extensions = objFreeze(sortPlugins(_coreExtensions || [])).slice();\r\n if (updateState) {\r\n _doUpdate(updateState);\r\n }\r\n }\r\n function _getPlugin(pluginIdentifier) {\r\n var theExt = null;\r\n var thePlugin = null;\r\n arrForEach(_self._extensions, function (ext) {\r\n if (ext.identifier === pluginIdentifier && ext !== _channelControl && ext !== _telemetryInitializerPlugin) {\r\n thePlugin = ext;\r\n return -1;\r\n }\r\n });\r\n if (!thePlugin && _channelControl) {\r\n // Check the channel Controller\r\n thePlugin = _channelControl.getChannel(pluginIdentifier);\r\n }\r\n if (thePlugin) {\r\n theExt = {\r\n plugin: thePlugin,\r\n setEnabled: function (enabled) {\r\n _getPluginState(thePlugin)[strDisabled] = !enabled;\r\n },\r\n isEnabled: function () {\r\n var pluginState = _getPluginState(thePlugin);\r\n return !pluginState[strTeardown] && !pluginState[strDisabled];\r\n },\r\n remove: function (isAsync, removeCb) {\r\n if (isAsync === void 0) { isAsync = true; }\r\n var pluginsToRemove = [thePlugin];\r\n var unloadState = {\r\n reason: 1 /* TelemetryUnloadReason.PluginUnload */,\r\n isAsync: isAsync\r\n };\r\n _removePlugins(pluginsToRemove, unloadState, function (removed) {\r\n if (removed) {\r\n // Re-Initialize the plugin chain\r\n _initPluginChain(_self.config, {\r\n reason: 32 /* TelemetryUpdateReason.PluginRemoved */,\r\n removed: pluginsToRemove\r\n });\r\n }\r\n removeCb && removeCb(removed);\r\n });\r\n }\r\n };\r\n }\r\n return theExt;\r\n }\r\n function _getPluginChain() {\r\n if (!_pluginChain) {\r\n // copy the collection of extensions\r\n var extensions = (_coreExtensions || []).slice();\r\n // During add / remove this may get called again, so don't readd if already present\r\n if (arrIndexOf(extensions, _telemetryInitializerPlugin) === -1) {\r\n extensions.push(_telemetryInitializerPlugin);\r\n }\r\n _pluginChain = createTelemetryProxyChain(sortPlugins(extensions), _self.config, _self);\r\n }\r\n return _pluginChain;\r\n }\r\n function _removePlugins(thePlugins, unloadState, removeComplete) {\r\n if (thePlugins && thePlugins.length > 0) {\r\n var unloadChain = createTelemetryProxyChain(thePlugins, _self.config, _self);\r\n var unloadCtx = createProcessTelemetryUnloadContext(unloadChain, _self);\r\n unloadCtx.onComplete(function () {\r\n var removed = false;\r\n // Remove the listed config extensions\r\n var newConfigExtensions = [];\r\n arrForEach(_configExtensions, function (plugin, idx) {\r\n if (!_isPluginPresent(plugin, thePlugins)) {\r\n newConfigExtensions.push(plugin);\r\n }\r\n else {\r\n removed = true;\r\n }\r\n });\r\n _configExtensions = newConfigExtensions;\r\n // Re-Create the channel config\r\n var newChannelConfig = [];\r\n if (_channelConfig) {\r\n arrForEach(_channelConfig, function (queue, idx) {\r\n var newQueue = [];\r\n arrForEach(queue, function (channel) {\r\n if (!_isPluginPresent(channel, thePlugins)) {\r\n newQueue.push(channel);\r\n }\r\n else {\r\n removed = true;\r\n }\r\n });\r\n newChannelConfig.push(newQueue);\r\n });\r\n _channelConfig = newChannelConfig;\r\n }\r\n removeComplete && removeComplete(removed);\r\n });\r\n unloadCtx.processNext(unloadState);\r\n }\r\n else {\r\n removeComplete(false);\r\n }\r\n }\r\n function _flushInternalLogs() {\r\n var queue = _self.logger ? _self.logger.queue : [];\r\n if (queue) {\r\n arrForEach(queue, function (logMessage) {\r\n var item = {\r\n name: _internalLogsEventName ? _internalLogsEventName : \"InternalMessageId: \" + logMessage.messageId,\r\n iKey: _self.config.instrumentationKey,\r\n time: toISOString(new Date()),\r\n baseType: _InternalLogMessage.dataType,\r\n baseData: { message: logMessage.message }\r\n };\r\n _self.track(item);\r\n });\r\n queue.length = 0;\r\n }\r\n }\r\n function _flushChannels(isAsync, callBack, sendReason, cbTimeout) {\r\n if (_channelControl) {\r\n return _channelControl.flush(isAsync, callBack, sendReason || 6 /* SendRequestReason.SdkUnload */, cbTimeout);\r\n }\r\n callBack && callBack(false);\r\n return true;\r\n }\r\n function _initDebugListener(config) {\r\n if (config.disableDbgExt === true && _debugListener) {\r\n // Remove any previously loaded debug listener\r\n _notificationManager[strRemoveNotificationListener](_debugListener);\r\n _debugListener = null;\r\n }\r\n if (_notificationManager && !_debugListener && config.disableDbgExt !== true) {\r\n _debugListener = getDebugListener(config);\r\n _notificationManager[strAddNotificationListener](_debugListener);\r\n }\r\n }\r\n function _initPerfManager(config) {\r\n if (!config.enablePerfMgr && _cfgPerfManager) {\r\n // Remove any existing config based performance manager\r\n _cfgPerfManager = null;\r\n }\r\n if (config.enablePerfMgr) {\r\n // Set the performance manager creation function if not defined\r\n setValue(_self.config, \"createPerfMgr\", _createPerfManager);\r\n }\r\n }\r\n function _initExtConfig(config) {\r\n var extConfig = getSetValue(config, strExtensionConfig);\r\n extConfig.NotificationManager = _notificationManager;\r\n }\r\n function _doUpdate(updateState) {\r\n var updateCtx = createProcessTelemetryUpdateContext(_getPluginChain(), _self);\r\n if (!_self._updateHook || _self._updateHook(updateCtx, updateState) !== true) {\r\n updateCtx.processNext(updateState);\r\n }\r\n }\r\n function _logOrThrowError(message) {\r\n var logger = _self.logger;\r\n if (logger) {\r\n // there should always be a logger\r\n _throwInternal(logger, 2 /* eLoggingSeverity.WARNING */, 73 /* _eInternalMessageId.PluginException */, message);\r\n }\r\n else {\r\n throwError(message);\r\n }\r\n }\r\n });\r\n }\r\n BaseCore.prototype.initialize = function (config, extensions, logger, notificationManager) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n BaseCore.prototype.getTransmissionControls = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n BaseCore.prototype.track = function (telemetryItem) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n BaseCore.prototype.getProcessTelContext = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n BaseCore.prototype.getNotifyMgr = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n /**\r\n * Adds a notification listener. The SDK calls methods on the listener when an appropriate notification is raised.\r\n * The added plugins must raise notifications. If the plugins do not implement the notifications, then no methods will be\r\n * called.\r\n * @param {INotificationListener} listener - An INotificationListener object.\r\n */\r\n BaseCore.prototype.addNotificationListener = function (listener) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Removes all instances of the listener.\r\n * @param {INotificationListener} listener - INotificationListener to remove.\r\n */\r\n BaseCore.prototype.removeNotificationListener = function (listener) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Get the current cookie manager for this instance\r\n */\r\n BaseCore.prototype.getCookieMgr = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n /**\r\n * Set the current cookie manager for this instance\r\n * @param cookieMgr - The manager, if set to null/undefined will cause the default to be created\r\n */\r\n BaseCore.prototype.setCookieMgr = function (cookieMgr) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n BaseCore.prototype.getPerfMgr = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n BaseCore.prototype.setPerfMgr = function (perfMgr) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n BaseCore.prototype.eventCnt = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return 0;\r\n };\r\n /**\r\n * Periodically check logger.queue for\r\n */\r\n BaseCore.prototype.pollInternalLogs = function (eventName) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return 0;\r\n };\r\n /**\r\n * Periodically check logger.queue for\r\n */\r\n BaseCore.prototype.stopPollingInternalLogs = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Add a telemetry processor to decorate or drop telemetry events.\r\n * @param telemetryInitializer - The Telemetry Initializer function\r\n * @returns - A ITelemetryInitializerHandler to enable the initializer to be removed\r\n */\r\n BaseCore.prototype.addTelemetryInitializer = function (telemetryInitializer) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Unload and Tear down the SDK and any initialized plugins, after calling this the SDK will be considered\r\n * to be un-initialized and non-operational, re-initializing the SDK should only be attempted if the previous\r\n * unload call return `true` stating that all plugins reported that they also unloaded, the recommended\r\n * approach is to create a new instance and initialize that instance.\r\n * This is due to possible unexpected side effects caused by plugins not supporting unload / teardown, unable\r\n * to successfully remove any global references or they may just be completing the unload process asynchronously.\r\n * @param isAsync - Can the unload be performed asynchronously (default)\r\n * @param unloadComplete - An optional callback that will be called once the unload has completed\r\n * @param cbTimeout - An optional timeout to wait for any flush operations to complete before proceeding with the unload. Defaults to 5 seconds.\r\n */\r\n BaseCore.prototype.unload = function (isAsync, unloadComplete, cbTimeout) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n BaseCore.prototype.getPlugin = function (pluginIdentifier) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n /**\r\n * Add a new plugin to the installation\r\n * @param plugin - The new plugin to add\r\n * @param replaceExisting - should any existing plugin be replaced, default is false\r\n * @param doAsync - Should the add be performed asynchronously\r\n * @param addCb - [Optional] callback to call after the plugin has been added\r\n */\r\n BaseCore.prototype.addPlugin = function (plugin, replaceExisting, doAsync, addCb) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Returns the unique event namespace that should be used\r\n */\r\n BaseCore.prototype.evtNamespace = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n /**\r\n * Add an unload handler that will be called when the SDK is being unloaded\r\n * @param handler - the handler\r\n */\r\n BaseCore.prototype.addUnloadCb = function (handler) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Flush and send any batched / cached data immediately\r\n * @param async - send data asynchronously when true (defaults to true)\r\n * @param callBack - if specified, notify caller when send is complete, the channel should return true to indicate to the caller that it will be called.\r\n * If the caller doesn't return true the caller should assume that it may never be called.\r\n * @param sendReason - specify the reason that you are calling \"flush\" defaults to ManualFlush (1) if not specified\r\n * @returns - true if the callback will be return after the flush is complete otherwise the caller should assume that any provided callback will never be called\r\n */\r\n BaseCore.prototype.flush = function (isAsync, callBack, sendReason) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n BaseCore.prototype.releaseQueue = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Hook for Core extensions to allow them to update their own configuration before updating all of the plugins.\r\n * @param updateCtx - The plugin update context\r\n * @param updateState - The Update State\r\n * @returns boolean - True means the extension class will call updateState otherwise the Core will\r\n */\r\n BaseCore.prototype._updateHook = function (updateCtx, updateState) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return false;\r\n };\r\n return BaseCore;\r\n}());\r\nexport { BaseCore };\r\n//# sourceMappingURL=BaseCore.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC;AACA,wFAAsC;AACtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;;;;;mDAiJM;AACN;AACA;AACA;AACA"}
1
+ {"version":3,"file":"BaseCore.js.map","sources":["BaseCore.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\n\"use strict\";\r\nimport { __spreadArray } from \"tslib\";\r\nimport { objCreateFn } from \"@microsoft/applicationinsights-shims\";\r\nimport dynamicProto from \"@microsoft/dynamicproto-js\";\r\nimport { createProcessTelemetryContext, createProcessTelemetryUnloadContext, createProcessTelemetryUpdateContext, createTelemetryProxyChain } from \"./ProcessTelemetryContext\";\r\nimport { createDistributedTraceContext, initializePlugins, sortPlugins, _getPluginState } from \"./TelemetryHelpers\";\r\nimport { getGblPerfMgr, PerfManager } from \"./PerfManager\";\r\nimport { createCookieMgr } from \"./CookieMgr\";\r\nimport { arrForEach, isNullOrUndefined, getSetValue, setValue, isNotTruthy, isFunction, objExtend, objFreeze, proxyFunctionAs, proxyFunctions, throwError, toISOString, arrIndexOf } from \"./HelperFuncs\";\r\nimport { strExtensionConfig, strIKey } from \"./Constants\";\r\nimport { DiagnosticLogger, _InternalLogMessage, _throwInternal, _warnToConsole } from \"./DiagnosticLogger\";\r\nimport { getDebugListener } from \"./DbgExtensionUtils\";\r\nimport { ChannelControllerPriority, createChannelControllerPlugin, createChannelQueues } from \"./ChannelController\";\r\nimport { TelemetryInitializerPlugin } from \"./TelemetryInitializerPlugin\";\r\nimport { createUniqueNamespace } from \"./DataCacheHelper\";\r\nimport { createUnloadHandlerContainer } from \"./UnloadHandlerContainer\";\r\nimport { strAddNotificationListener, strDisabled, strEventsDiscarded, strEventsSendRequest, strEventsSent, strRemoveNotificationListener, strTeardown } from \"./InternalConstants\";\r\nvar strValidationError = \"Plugins must provide initialize method\";\r\nvar strNotificationManager = \"_notificationManager\";\r\nvar strSdkUnloadingError = \"SDK is still unloading...\";\r\nvar strSdkNotInitialized = \"SDK is not initialized\";\r\n// const strPluginUnloadFailed = \"Failed to unload plugin\";\r\nvar defaultInitConfig = {\r\n // Have the Diagnostic Logger default to log critical errors to the console\r\n loggingLevelConsole: 1 /* eLoggingSeverity.CRITICAL */\r\n};\r\n/**\r\n * Helper to create the default performance manager\r\n * @param core\r\n * @param notificationMgr\r\n */\r\nfunction _createPerfManager(core, notificationMgr) {\r\n return new PerfManager(notificationMgr);\r\n}\r\nfunction _validateExtensions(logger, channelPriority, allExtensions) {\r\n // Concat all available extensions\r\n var coreExtensions = [];\r\n // Check if any two extensions have the same priority, then warn to console\r\n // And extract the local extensions from the\r\n var extPriorities = {};\r\n // Extension validation\r\n arrForEach(allExtensions, function (ext) {\r\n if (isNullOrUndefined(ext) || isNullOrUndefined(ext.initialize)) {\r\n throwError(strValidationError);\r\n }\r\n var extPriority = ext.priority;\r\n var identifier = ext.identifier;\r\n if (ext && extPriority) {\r\n if (!isNullOrUndefined(extPriorities[extPriority])) {\r\n _warnToConsole(logger, \"Two extensions have same priority #\" + extPriority + \" - \" + extPriorities[extPriority] + \", \" + identifier);\r\n }\r\n else {\r\n // set a value\r\n extPriorities[extPriority] = identifier;\r\n }\r\n }\r\n // Split extensions to core and channelController\r\n if (!extPriority || extPriority < channelPriority) {\r\n // Add to core extension that will be managed by BaseCore\r\n coreExtensions.push(ext);\r\n }\r\n });\r\n return {\r\n all: allExtensions,\r\n core: coreExtensions\r\n };\r\n}\r\nfunction _isPluginPresent(thePlugin, plugins) {\r\n var exists = false;\r\n arrForEach(plugins, function (plugin) {\r\n if (plugin === thePlugin) {\r\n exists = true;\r\n return -1;\r\n }\r\n });\r\n return exists;\r\n}\r\nfunction _createDummyNotificationManager() {\r\n var _a;\r\n return objCreateFn((_a = {},\r\n _a[strAddNotificationListener] = function (listener) { },\r\n _a[strRemoveNotificationListener] = function (listener) { },\r\n _a[strEventsSent] = function (events) { },\r\n _a[strEventsDiscarded] = function (events, reason) { },\r\n _a[strEventsSendRequest] = function (sendReason, isAsync) { },\r\n _a));\r\n}\r\nvar BaseCore = /** @class */ (function () {\r\n function BaseCore() {\r\n // NOTE!: DON'T set default values here, instead set them in the _initDefaults() function as it is also called during teardown()\r\n var _isInitialized;\r\n var _eventQueue;\r\n var _notificationManager;\r\n var _perfManager;\r\n var _cfgPerfManager;\r\n var _cookieManager;\r\n var _pluginChain;\r\n var _configExtensions;\r\n var _coreExtensions;\r\n var _channelControl;\r\n var _channelConfig;\r\n var _channelQueue;\r\n var _isUnloading;\r\n var _telemetryInitializerPlugin;\r\n var _internalLogsEventName;\r\n var _evtNamespace;\r\n var _unloadHandlers;\r\n var _debugListener;\r\n var _traceCtx;\r\n /**\r\n * Internal log poller\r\n */\r\n var _internalLogPoller = 0;\r\n dynamicProto(BaseCore, this, function (_self) {\r\n // Set the default values (also called during teardown)\r\n _initDefaults();\r\n _self.isInitialized = function () { return _isInitialized; };\r\n _self.initialize = function (config, extensions, logger, notificationManager) {\r\n if (_isUnloading) {\r\n throwError(strSdkUnloadingError);\r\n }\r\n // Make sure core is only initialized once\r\n if (_self.isInitialized()) {\r\n throwError(\"Core should not be initialized more than once\");\r\n }\r\n if (!config || isNullOrUndefined(config.instrumentationKey)) {\r\n throwError(\"Please provide instrumentation key\");\r\n }\r\n _notificationManager = notificationManager;\r\n // For backward compatibility only\r\n _self[strNotificationManager] = notificationManager;\r\n _self.config = config || {};\r\n _initDebugListener(config);\r\n _initPerfManager(config);\r\n config.extensions = isNullOrUndefined(config.extensions) ? [] : config.extensions;\r\n // add notification to the extensions in the config so other plugins can access it\r\n _initExtConfig(config);\r\n if (logger) {\r\n _self.logger = logger;\r\n }\r\n // Extension validation\r\n _configExtensions = [];\r\n _configExtensions.push.apply(_configExtensions, __spreadArray(__spreadArray([], extensions, false), config.extensions, false));\r\n _channelConfig = (config || {}).channels;\r\n _initPluginChain(config, null);\r\n if (!_channelQueue || _channelQueue.length === 0) {\r\n throwError(\"No channels available\");\r\n }\r\n _isInitialized = true;\r\n _self.releaseQueue();\r\n };\r\n _self.getTransmissionControls = function () {\r\n var controls = [];\r\n if (_channelQueue) {\r\n arrForEach(_channelQueue, function (channels) {\r\n controls.push(channels.queue);\r\n });\r\n }\r\n return objFreeze(controls);\r\n };\r\n _self.track = function (telemetryItem) {\r\n // setup default iKey if not passed in\r\n setValue(telemetryItem, strIKey, _self.config.instrumentationKey, null, isNotTruthy);\r\n // add default timestamp if not passed in\r\n setValue(telemetryItem, \"time\", toISOString(new Date()), null, isNotTruthy);\r\n // Common Schema 4.0\r\n setValue(telemetryItem, \"ver\", \"4.0\", null, isNullOrUndefined);\r\n if (!_isUnloading && _self.isInitialized()) {\r\n // Process the telemetry plugin chain\r\n _createTelCtx().processNext(telemetryItem);\r\n }\r\n else {\r\n // Queue events until all extensions are initialized\r\n _eventQueue.push(telemetryItem);\r\n }\r\n };\r\n _self.getProcessTelContext = _createTelCtx;\r\n _self.getNotifyMgr = function () {\r\n if (!_notificationManager) {\r\n // Create Dummy notification manager\r\n _notificationManager = _createDummyNotificationManager();\r\n // For backward compatibility only\r\n _self[strNotificationManager] = _notificationManager;\r\n }\r\n return _notificationManager;\r\n };\r\n /**\r\n * Adds a notification listener. The SDK calls methods on the listener when an appropriate notification is raised.\r\n * The added plugins must raise notifications. If the plugins do not implement the notifications, then no methods will be\r\n * called.\r\n * @param {INotificationListener} listener - An INotificationListener object.\r\n */\r\n _self[strAddNotificationListener] = function (listener) {\r\n if (_notificationManager) {\r\n _notificationManager[strAddNotificationListener](listener);\r\n }\r\n };\r\n /**\r\n * Removes all instances of the listener.\r\n * @param {INotificationListener} listener - INotificationListener to remove.\r\n */\r\n _self[strRemoveNotificationListener] = function (listener) {\r\n if (_notificationManager) {\r\n _notificationManager[strRemoveNotificationListener](listener);\r\n }\r\n };\r\n _self.getCookieMgr = function () {\r\n if (!_cookieManager) {\r\n _cookieManager = createCookieMgr(_self.config, _self.logger);\r\n }\r\n return _cookieManager;\r\n };\r\n _self.setCookieMgr = function (cookieMgr) {\r\n _cookieManager = cookieMgr;\r\n };\r\n _self.getPerfMgr = function () {\r\n if (!_perfManager && !_cfgPerfManager) {\r\n if (_self.config && _self.config.enablePerfMgr && isFunction(_self.config.createPerfMgr)) {\r\n _cfgPerfManager = _self.config.createPerfMgr(_self, _self.getNotifyMgr());\r\n }\r\n }\r\n return _perfManager || _cfgPerfManager || getGblPerfMgr();\r\n };\r\n _self.setPerfMgr = function (perfMgr) {\r\n _perfManager = perfMgr;\r\n };\r\n _self.eventCnt = function () {\r\n return _eventQueue.length;\r\n };\r\n _self.releaseQueue = function () {\r\n if (_isInitialized && _eventQueue.length > 0) {\r\n var eventQueue = _eventQueue;\r\n _eventQueue = [];\r\n arrForEach(eventQueue, function (event) {\r\n _createTelCtx().processNext(event);\r\n });\r\n }\r\n };\r\n /**\r\n * Periodically check logger.queue for log messages to be flushed\r\n */\r\n _self.pollInternalLogs = function (eventName) {\r\n _internalLogsEventName = eventName || null;\r\n var interval = _self.config.diagnosticLogInterval;\r\n if (!interval || !(interval > 0)) {\r\n interval = 10000;\r\n }\r\n if (_internalLogPoller) {\r\n clearInterval(_internalLogPoller);\r\n }\r\n _internalLogPoller = setInterval(function () {\r\n _flushInternalLogs();\r\n }, interval);\r\n return _internalLogPoller;\r\n };\r\n /**\r\n * Stop polling log messages from logger.queue\r\n */\r\n _self.stopPollingInternalLogs = function () {\r\n if (_internalLogPoller) {\r\n clearInterval(_internalLogPoller);\r\n _internalLogPoller = 0;\r\n _flushInternalLogs();\r\n }\r\n };\r\n // Add addTelemetryInitializer\r\n proxyFunctions(_self, function () { return _telemetryInitializerPlugin; }, [\"addTelemetryInitializer\"]);\r\n _self.unload = function (isAsync, unloadComplete, cbTimeout) {\r\n if (isAsync === void 0) { isAsync = true; }\r\n if (!_isInitialized) {\r\n // The SDK is not initialized\r\n throwError(strSdkNotInitialized);\r\n }\r\n // Check if the SDK still unloading so throw\r\n if (_isUnloading) {\r\n // The SDK is already unloading\r\n throwError(strSdkUnloadingError);\r\n }\r\n var unloadState = {\r\n reason: 50 /* TelemetryUnloadReason.SdkUnload */,\r\n isAsync: isAsync,\r\n flushComplete: false\r\n };\r\n var processUnloadCtx = createProcessTelemetryUnloadContext(_getPluginChain(), _self);\r\n processUnloadCtx.onComplete(function () {\r\n _initDefaults();\r\n unloadComplete && unloadComplete(unloadState);\r\n }, _self);\r\n function _doUnload(flushComplete) {\r\n unloadState.flushComplete = flushComplete;\r\n _isUnloading = true;\r\n // Run all of the unload handlers first (before unloading the plugins)\r\n _unloadHandlers.run(processUnloadCtx, unloadState);\r\n // Stop polling the internal logs\r\n _self.stopPollingInternalLogs();\r\n // Start unloading the components, from this point onwards the SDK should be considered to be in an unstable state\r\n processUnloadCtx.processNext(unloadState);\r\n }\r\n if (!_flushChannels(isAsync, _doUnload, 6 /* SendRequestReason.SdkUnload */, cbTimeout)) {\r\n _doUnload(false);\r\n }\r\n };\r\n _self.getPlugin = _getPlugin;\r\n _self.addPlugin = function (plugin, replaceExisting, isAsync, addCb) {\r\n if (!plugin) {\r\n addCb && addCb(false);\r\n _logOrThrowError(strValidationError);\r\n return;\r\n }\r\n var existingPlugin = _getPlugin(plugin.identifier);\r\n if (existingPlugin && !replaceExisting) {\r\n addCb && addCb(false);\r\n _logOrThrowError(\"Plugin [\" + plugin.identifier + \"] is already loaded!\");\r\n return;\r\n }\r\n var updateState = {\r\n reason: 16 /* TelemetryUpdateReason.PluginAdded */\r\n };\r\n function _addPlugin(removed) {\r\n _configExtensions.push(plugin);\r\n updateState.added = [plugin];\r\n // Re-Initialize the plugin chain\r\n _initPluginChain(_self.config, updateState);\r\n addCb && addCb(true);\r\n }\r\n if (existingPlugin) {\r\n var removedPlugins_1 = [existingPlugin.plugin];\r\n var unloadState = {\r\n reason: 2 /* TelemetryUnloadReason.PluginReplace */,\r\n isAsync: !!isAsync\r\n };\r\n _removePlugins(removedPlugins_1, unloadState, function (removed) {\r\n if (!removed) {\r\n // Previous plugin was successfully removed or was not installed\r\n addCb && addCb(false);\r\n }\r\n else {\r\n updateState.removed = removedPlugins_1;\r\n updateState.reason |= 32 /* TelemetryUpdateReason.PluginRemoved */;\r\n _addPlugin(true);\r\n }\r\n });\r\n }\r\n else {\r\n _addPlugin(false);\r\n }\r\n };\r\n _self.evtNamespace = function () {\r\n return _evtNamespace;\r\n };\r\n _self.flush = _flushChannels;\r\n _self.getTraceCtx = function (createNew) {\r\n if (!_traceCtx) {\r\n _traceCtx = createDistributedTraceContext();\r\n }\r\n return _traceCtx;\r\n };\r\n _self.setTraceCtx = function (traceCtx) {\r\n _traceCtx = traceCtx || null;\r\n };\r\n // Create the addUnloadCb\r\n proxyFunctionAs(_self, \"addUnloadCb\", function () { return _unloadHandlers; }, \"add\");\r\n function _initDefaults() {\r\n _isInitialized = false;\r\n // Use a default logger so initialization errors are not dropped on the floor with full logging\r\n _self.config = objExtend(true, {}, defaultInitConfig);\r\n _self.logger = new DiagnosticLogger(_self.config);\r\n _self._extensions = [];\r\n _telemetryInitializerPlugin = new TelemetryInitializerPlugin();\r\n _eventQueue = [];\r\n _notificationManager = null;\r\n _perfManager = null;\r\n _cfgPerfManager = null;\r\n _cookieManager = null;\r\n _pluginChain = null;\r\n _coreExtensions = null;\r\n _configExtensions = [];\r\n _channelControl = null;\r\n _channelConfig = null;\r\n _channelQueue = null;\r\n _isUnloading = false;\r\n _internalLogsEventName = null;\r\n _evtNamespace = createUniqueNamespace(\"AIBaseCore\", true);\r\n _unloadHandlers = createUnloadHandlerContainer();\r\n _traceCtx = null;\r\n }\r\n function _createTelCtx() {\r\n return createProcessTelemetryContext(_getPluginChain(), _self.config, _self);\r\n }\r\n // Initialize or Re-initialize the plugins\r\n function _initPluginChain(config, updateState) {\r\n // Extension validation\r\n var theExtensions = _validateExtensions(_self.logger, ChannelControllerPriority, _configExtensions);\r\n _coreExtensions = theExtensions.core;\r\n _pluginChain = null;\r\n // Sort the complete set of extensions by priority\r\n var allExtensions = theExtensions.all;\r\n // Initialize the Channel Queues and the channel plugins first\r\n _channelQueue = objFreeze(createChannelQueues(_channelConfig, allExtensions, config, _self));\r\n if (_channelControl) {\r\n // During add / remove of a plugin this may get called again, so don't re-add if already present\r\n // But we also want the controller as the last, so remove if already present\r\n // And reusing the existing instance, just in case an installed plugin has a reference and\r\n // is using it.\r\n var idx = arrIndexOf(allExtensions, _channelControl);\r\n if (idx !== -1) {\r\n allExtensions.splice(idx, 1);\r\n }\r\n idx = arrIndexOf(_coreExtensions, _channelControl);\r\n if (idx !== -1) {\r\n _coreExtensions.splice(idx, 1);\r\n }\r\n _channelControl._setQueue(_channelQueue);\r\n }\r\n else {\r\n _channelControl = createChannelControllerPlugin(_channelQueue, _self);\r\n }\r\n // Add on \"channelController\" as the last \"plugin\"\r\n allExtensions.push(_channelControl);\r\n _coreExtensions.push(_channelControl);\r\n // Required to allow plugins to call core.getPlugin() during their own initialization\r\n _self._extensions = sortPlugins(allExtensions);\r\n // Initialize the controls\r\n _channelControl.initialize(config, _self, allExtensions);\r\n initializePlugins(_createTelCtx(), allExtensions);\r\n // Now reset the extensions to just those being managed by Basecore\r\n _self._extensions = objFreeze(sortPlugins(_coreExtensions || [])).slice();\r\n if (updateState) {\r\n _doUpdate(updateState);\r\n }\r\n }\r\n function _getPlugin(pluginIdentifier) {\r\n var theExt = null;\r\n var thePlugin = null;\r\n arrForEach(_self._extensions, function (ext) {\r\n if (ext.identifier === pluginIdentifier && ext !== _channelControl && ext !== _telemetryInitializerPlugin) {\r\n thePlugin = ext;\r\n return -1;\r\n }\r\n });\r\n if (!thePlugin && _channelControl) {\r\n // Check the channel Controller\r\n thePlugin = _channelControl.getChannel(pluginIdentifier);\r\n }\r\n if (thePlugin) {\r\n theExt = {\r\n plugin: thePlugin,\r\n setEnabled: function (enabled) {\r\n _getPluginState(thePlugin)[strDisabled] = !enabled;\r\n },\r\n isEnabled: function () {\r\n var pluginState = _getPluginState(thePlugin);\r\n return !pluginState[strTeardown] && !pluginState[strDisabled];\r\n },\r\n remove: function (isAsync, removeCb) {\r\n if (isAsync === void 0) { isAsync = true; }\r\n var pluginsToRemove = [thePlugin];\r\n var unloadState = {\r\n reason: 1 /* TelemetryUnloadReason.PluginUnload */,\r\n isAsync: isAsync\r\n };\r\n _removePlugins(pluginsToRemove, unloadState, function (removed) {\r\n if (removed) {\r\n // Re-Initialize the plugin chain\r\n _initPluginChain(_self.config, {\r\n reason: 32 /* TelemetryUpdateReason.PluginRemoved */,\r\n removed: pluginsToRemove\r\n });\r\n }\r\n removeCb && removeCb(removed);\r\n });\r\n }\r\n };\r\n }\r\n return theExt;\r\n }\r\n function _getPluginChain() {\r\n if (!_pluginChain) {\r\n // copy the collection of extensions\r\n var extensions = (_coreExtensions || []).slice();\r\n // During add / remove this may get called again, so don't readd if already present\r\n if (arrIndexOf(extensions, _telemetryInitializerPlugin) === -1) {\r\n extensions.push(_telemetryInitializerPlugin);\r\n }\r\n _pluginChain = createTelemetryProxyChain(sortPlugins(extensions), _self.config, _self);\r\n }\r\n return _pluginChain;\r\n }\r\n function _removePlugins(thePlugins, unloadState, removeComplete) {\r\n if (thePlugins && thePlugins.length > 0) {\r\n var unloadChain = createTelemetryProxyChain(thePlugins, _self.config, _self);\r\n var unloadCtx = createProcessTelemetryUnloadContext(unloadChain, _self);\r\n unloadCtx.onComplete(function () {\r\n var removed = false;\r\n // Remove the listed config extensions\r\n var newConfigExtensions = [];\r\n arrForEach(_configExtensions, function (plugin, idx) {\r\n if (!_isPluginPresent(plugin, thePlugins)) {\r\n newConfigExtensions.push(plugin);\r\n }\r\n else {\r\n removed = true;\r\n }\r\n });\r\n _configExtensions = newConfigExtensions;\r\n // Re-Create the channel config\r\n var newChannelConfig = [];\r\n if (_channelConfig) {\r\n arrForEach(_channelConfig, function (queue, idx) {\r\n var newQueue = [];\r\n arrForEach(queue, function (channel) {\r\n if (!_isPluginPresent(channel, thePlugins)) {\r\n newQueue.push(channel);\r\n }\r\n else {\r\n removed = true;\r\n }\r\n });\r\n newChannelConfig.push(newQueue);\r\n });\r\n _channelConfig = newChannelConfig;\r\n }\r\n removeComplete && removeComplete(removed);\r\n });\r\n unloadCtx.processNext(unloadState);\r\n }\r\n else {\r\n removeComplete(false);\r\n }\r\n }\r\n function _flushInternalLogs() {\r\n var queue = _self.logger ? _self.logger.queue : [];\r\n if (queue) {\r\n arrForEach(queue, function (logMessage) {\r\n var item = {\r\n name: _internalLogsEventName ? _internalLogsEventName : \"InternalMessageId: \" + logMessage.messageId,\r\n iKey: _self.config.instrumentationKey,\r\n time: toISOString(new Date()),\r\n baseType: _InternalLogMessage.dataType,\r\n baseData: { message: logMessage.message }\r\n };\r\n _self.track(item);\r\n });\r\n queue.length = 0;\r\n }\r\n }\r\n function _flushChannels(isAsync, callBack, sendReason, cbTimeout) {\r\n if (_channelControl) {\r\n return _channelControl.flush(isAsync, callBack, sendReason || 6 /* SendRequestReason.SdkUnload */, cbTimeout);\r\n }\r\n callBack && callBack(false);\r\n return true;\r\n }\r\n function _initDebugListener(config) {\r\n if (config.disableDbgExt === true && _debugListener) {\r\n // Remove any previously loaded debug listener\r\n _notificationManager[strRemoveNotificationListener](_debugListener);\r\n _debugListener = null;\r\n }\r\n if (_notificationManager && !_debugListener && config.disableDbgExt !== true) {\r\n _debugListener = getDebugListener(config);\r\n _notificationManager[strAddNotificationListener](_debugListener);\r\n }\r\n }\r\n function _initPerfManager(config) {\r\n if (!config.enablePerfMgr && _cfgPerfManager) {\r\n // Remove any existing config based performance manager\r\n _cfgPerfManager = null;\r\n }\r\n if (config.enablePerfMgr) {\r\n // Set the performance manager creation function if not defined\r\n setValue(_self.config, \"createPerfMgr\", _createPerfManager);\r\n }\r\n }\r\n function _initExtConfig(config) {\r\n var extConfig = getSetValue(config, strExtensionConfig);\r\n extConfig.NotificationManager = _notificationManager;\r\n }\r\n function _doUpdate(updateState) {\r\n var updateCtx = createProcessTelemetryUpdateContext(_getPluginChain(), _self);\r\n if (!_self._updateHook || _self._updateHook(updateCtx, updateState) !== true) {\r\n updateCtx.processNext(updateState);\r\n }\r\n }\r\n function _logOrThrowError(message) {\r\n var logger = _self.logger;\r\n if (logger) {\r\n // there should always be a logger\r\n _throwInternal(logger, 2 /* eLoggingSeverity.WARNING */, 73 /* _eInternalMessageId.PluginException */, message);\r\n }\r\n else {\r\n throwError(message);\r\n }\r\n }\r\n });\r\n }\r\n BaseCore.prototype.initialize = function (config, extensions, logger, notificationManager) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n BaseCore.prototype.getTransmissionControls = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n BaseCore.prototype.track = function (telemetryItem) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n BaseCore.prototype.getProcessTelContext = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n BaseCore.prototype.getNotifyMgr = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n /**\r\n * Adds a notification listener. The SDK calls methods on the listener when an appropriate notification is raised.\r\n * The added plugins must raise notifications. If the plugins do not implement the notifications, then no methods will be\r\n * called.\r\n * @param {INotificationListener} listener - An INotificationListener object.\r\n */\r\n BaseCore.prototype.addNotificationListener = function (listener) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Removes all instances of the listener.\r\n * @param {INotificationListener} listener - INotificationListener to remove.\r\n */\r\n BaseCore.prototype.removeNotificationListener = function (listener) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Get the current cookie manager for this instance\r\n */\r\n BaseCore.prototype.getCookieMgr = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n /**\r\n * Set the current cookie manager for this instance\r\n * @param cookieMgr - The manager, if set to null/undefined will cause the default to be created\r\n */\r\n BaseCore.prototype.setCookieMgr = function (cookieMgr) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n BaseCore.prototype.getPerfMgr = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n BaseCore.prototype.setPerfMgr = function (perfMgr) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n BaseCore.prototype.eventCnt = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return 0;\r\n };\r\n /**\r\n * Periodically check logger.queue for\r\n */\r\n BaseCore.prototype.pollInternalLogs = function (eventName) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return 0;\r\n };\r\n /**\r\n * Periodically check logger.queue for\r\n */\r\n BaseCore.prototype.stopPollingInternalLogs = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Add a telemetry processor to decorate or drop telemetry events.\r\n * @param telemetryInitializer - The Telemetry Initializer function\r\n * @returns - A ITelemetryInitializerHandler to enable the initializer to be removed\r\n */\r\n BaseCore.prototype.addTelemetryInitializer = function (telemetryInitializer) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Unload and Tear down the SDK and any initialized plugins, after calling this the SDK will be considered\r\n * to be un-initialized and non-operational, re-initializing the SDK should only be attempted if the previous\r\n * unload call return `true` stating that all plugins reported that they also unloaded, the recommended\r\n * approach is to create a new instance and initialize that instance.\r\n * This is due to possible unexpected side effects caused by plugins not supporting unload / teardown, unable\r\n * to successfully remove any global references or they may just be completing the unload process asynchronously.\r\n * @param isAsync - Can the unload be performed asynchronously (default)\r\n * @param unloadComplete - An optional callback that will be called once the unload has completed\r\n * @param cbTimeout - An optional timeout to wait for any flush operations to complete before proceeding with the unload. Defaults to 5 seconds.\r\n */\r\n BaseCore.prototype.unload = function (isAsync, unloadComplete, cbTimeout) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n BaseCore.prototype.getPlugin = function (pluginIdentifier) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n /**\r\n * Add a new plugin to the installation\r\n * @param plugin - The new plugin to add\r\n * @param replaceExisting - should any existing plugin be replaced, default is false\r\n * @param doAsync - Should the add be performed asynchronously\r\n * @param addCb - [Optional] callback to call after the plugin has been added\r\n */\r\n BaseCore.prototype.addPlugin = function (plugin, replaceExisting, doAsync, addCb) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Returns the unique event namespace that should be used\r\n */\r\n BaseCore.prototype.evtNamespace = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n /**\r\n * Add an unload handler that will be called when the SDK is being unloaded\r\n * @param handler - the handler\r\n */\r\n BaseCore.prototype.addUnloadCb = function (handler) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Flush and send any batched / cached data immediately\r\n * @param async - send data asynchronously when true (defaults to true)\r\n * @param callBack - if specified, notify caller when send is complete, the channel should return true to indicate to the caller that it will be called.\r\n * If the caller doesn't return true the caller should assume that it may never be called.\r\n * @param sendReason - specify the reason that you are calling \"flush\" defaults to ManualFlush (1) if not specified\r\n * @returns - true if the callback will be return after the flush is complete otherwise the caller should assume that any provided callback will never be called\r\n */\r\n BaseCore.prototype.flush = function (isAsync, callBack, sendReason) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Gets the current distributed trace context for this instance if available\r\n * @param createNew - Optional flag to create a new instance if one doesn't currently exist, defaults to true\r\n */\r\n BaseCore.prototype.getTraceCtx = function (createNew) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n /**\r\n * Sets the current distributed trace context for this instance if available\r\n */\r\n BaseCore.prototype.setTraceCtx = function (newTracectx) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n BaseCore.prototype.releaseQueue = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Hook for Core extensions to allow them to update their own configuration before updating all of the plugins.\r\n * @param updateCtx - The plugin update context\r\n * @param updateState - The Update State\r\n * @returns boolean - True means the extension class will call updateState otherwise the Core will\r\n */\r\n BaseCore.prototype._updateHook = function (updateCtx, updateState) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n return false;\r\n };\r\n return BaseCore;\r\n}());\r\nexport { BaseCore };\r\n//# sourceMappingURL=BaseCore.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC;AACA,wFAAsC;AACtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;;;;;;;mDA+JM;AACN;AACA;AACA;AACA"}
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Core, 2.8.4-nightly.2205-09
2
+ * Application Insights JavaScript SDK - Core, 2.8.5-nightly.2206-02
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Core, 2.8.4-nightly.2205-09
2
+ * Application Insights JavaScript SDK - Core, 2.8.5-nightly.2206-02
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Core, 2.8.4-nightly.2205-09
2
+ * Application Insights JavaScript SDK - Core, 2.8.5-nightly.2206-02
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Core, 2.8.4-nightly.2205-09
2
+ * Application Insights JavaScript SDK - Core, 2.8.5-nightly.2206-02
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
  import { dumpObj, getDocument, getLocation, getNavigator, isIE } from "./EnvUtils";
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Core, 2.8.4-nightly.2205-09
2
+ * Application Insights JavaScript SDK - Core, 2.8.5-nightly.2206-02
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Core, 2.8.4-nightly.2205-09
2
+ * Application Insights JavaScript SDK - Core, 2.8.5-nightly.2206-02
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -8,7 +8,7 @@ import { ObjDefineProperty } from "@microsoft/applicationinsights-shims";
8
8
  import { normalizeJsName } from "./HelperFuncs";
9
9
  import { newId } from "./RandomHelper";
10
10
  var _objDefineProperty = ObjDefineProperty;
11
- var version = "2.8.4-nightly.2205-09";
11
+ var version = "2.8.5-nightly.2206-02";
12
12
  var instanceName = "." + newId(6);
13
13
  var _dataUid = 0;
14
14
  function _createAccessor(target, prop, value) {
@@ -1 +1 @@
1
- {"version":3,"file":"DataCacheHelper.js.map","sources":["DataCacheHelper.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport { ObjDefineProperty } from \"@microsoft/applicationinsights-shims\";\r\nimport { normalizeJsName } from \"./HelperFuncs\";\r\nimport { newId } from \"./RandomHelper\";\r\nvar _objDefineProperty = ObjDefineProperty;\r\nvar version = \"2.8.4-nightly.2205-09\";\r\nvar instanceName = \".\" + newId(6);\r\nvar _dataUid = 0;\r\nfunction _createAccessor(target, prop, value) {\r\n if (_objDefineProperty) {\r\n try {\r\n _objDefineProperty(target, prop, {\r\n value: value,\r\n enumerable: false,\r\n configurable: true\r\n });\r\n return true;\r\n }\r\n catch (e) {\r\n // IE8 Defines a defineProperty on Object but it's only supported for DOM elements so it will throw\r\n // We will just ignore this here.\r\n }\r\n }\r\n return false;\r\n}\r\n// Accepts only:\r\n// - Node\r\n// - Node.ELEMENT_NODE\r\n// - Node.DOCUMENT_NODE\r\n// - Object\r\n// - Any\r\nfunction _canAcceptData(target) {\r\n return target.nodeType === 1 || target.nodeType === 9 || !(+target.nodeType);\r\n}\r\nfunction _getCache(data, target) {\r\n var theCache = target[data.id];\r\n if (!theCache) {\r\n theCache = {};\r\n try {\r\n if (_canAcceptData(target)) {\r\n if (!_createAccessor(target, data.id, theCache)) {\r\n // Environment doesn't support accessor, so just use direct assignment\r\n target[data.id] = theCache;\r\n }\r\n }\r\n }\r\n catch (e) {\r\n // Not all environments allow extending all objects, so just ignore the cache in those cases\r\n }\r\n }\r\n return theCache;\r\n}\r\nexport function createUniqueNamespace(name, includeVersion) {\r\n if (includeVersion === void 0) { includeVersion = false; }\r\n return normalizeJsName(name + (_dataUid++) + (includeVersion ? \".\" + version : \"\") + instanceName);\r\n}\r\nexport function createElmNodeData(name) {\r\n var data = {\r\n id: createUniqueNamespace(\"_aiData-\" + (name || \"\") + \".\" + version),\r\n accept: function (target) {\r\n return _canAcceptData(target);\r\n },\r\n get: function (target, name, defValue, addDefault) {\r\n var theCache = target[data.id];\r\n if (!theCache) {\r\n if (addDefault) {\r\n // Side effect is adds the cache\r\n theCache = _getCache(data, target);\r\n theCache[normalizeJsName(name)] = defValue;\r\n }\r\n return defValue;\r\n }\r\n return theCache[normalizeJsName(name)];\r\n },\r\n kill: function (target, name) {\r\n if (target && target[name]) {\r\n try {\r\n delete target[name];\r\n }\r\n catch (e) {\r\n // Just cleaning up, so if this fails -- ignore\r\n }\r\n }\r\n }\r\n };\r\n return data;\r\n}\r\n//# sourceMappingURL=DataCacheHelper.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
1
+ {"version":3,"file":"DataCacheHelper.js.map","sources":["DataCacheHelper.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport { ObjDefineProperty } from \"@microsoft/applicationinsights-shims\";\r\nimport { normalizeJsName } from \"./HelperFuncs\";\r\nimport { newId } from \"./RandomHelper\";\r\nvar _objDefineProperty = ObjDefineProperty;\r\nvar version = \"2.8.5-nightly.2206-02\";\r\nvar instanceName = \".\" + newId(6);\r\nvar _dataUid = 0;\r\nfunction _createAccessor(target, prop, value) {\r\n if (_objDefineProperty) {\r\n try {\r\n _objDefineProperty(target, prop, {\r\n value: value,\r\n enumerable: false,\r\n configurable: true\r\n });\r\n return true;\r\n }\r\n catch (e) {\r\n // IE8 Defines a defineProperty on Object but it's only supported for DOM elements so it will throw\r\n // We will just ignore this here.\r\n }\r\n }\r\n return false;\r\n}\r\n// Accepts only:\r\n// - Node\r\n// - Node.ELEMENT_NODE\r\n// - Node.DOCUMENT_NODE\r\n// - Object\r\n// - Any\r\nfunction _canAcceptData(target) {\r\n return target.nodeType === 1 || target.nodeType === 9 || !(+target.nodeType);\r\n}\r\nfunction _getCache(data, target) {\r\n var theCache = target[data.id];\r\n if (!theCache) {\r\n theCache = {};\r\n try {\r\n if (_canAcceptData(target)) {\r\n if (!_createAccessor(target, data.id, theCache)) {\r\n // Environment doesn't support accessor, so just use direct assignment\r\n target[data.id] = theCache;\r\n }\r\n }\r\n }\r\n catch (e) {\r\n // Not all environments allow extending all objects, so just ignore the cache in those cases\r\n }\r\n }\r\n return theCache;\r\n}\r\nexport function createUniqueNamespace(name, includeVersion) {\r\n if (includeVersion === void 0) { includeVersion = false; }\r\n return normalizeJsName(name + (_dataUid++) + (includeVersion ? \".\" + version : \"\") + instanceName);\r\n}\r\nexport function createElmNodeData(name) {\r\n var data = {\r\n id: createUniqueNamespace(\"_aiData-\" + (name || \"\") + \".\" + version),\r\n accept: function (target) {\r\n return _canAcceptData(target);\r\n },\r\n get: function (target, name, defValue, addDefault) {\r\n var theCache = target[data.id];\r\n if (!theCache) {\r\n if (addDefault) {\r\n // Side effect is adds the cache\r\n theCache = _getCache(data, target);\r\n theCache[normalizeJsName(name)] = defValue;\r\n }\r\n return defValue;\r\n }\r\n return theCache[normalizeJsName(name)];\r\n },\r\n kill: function (target, name) {\r\n if (target && target[name]) {\r\n try {\r\n delete target[name];\r\n }\r\n catch (e) {\r\n // Just cleaning up, so if this fails -- ignore\r\n }\r\n }\r\n }\r\n };\r\n return data;\r\n}\r\n//# sourceMappingURL=DataCacheHelper.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Core, 2.8.4-nightly.2205-09
2
+ * Application Insights JavaScript SDK - Core, 2.8.5-nightly.2206-02
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Core, 2.8.4-nightly.2205-09
2
+ * Application Insights JavaScript SDK - Core, 2.8.5-nightly.2206-02
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5