@microsoft/applicationinsights-web-basic 2.8.0-beta.2203-02 → 2.8.0-beta.2203-03

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.
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "aib",
3
+ "version": "2.8.0-beta.2203-03",
4
+ "ext": {
5
+ "@js": {
6
+ "file": "aib.2.8.0-beta.2203-03.js",
7
+ "type": "text/javascript; charset=utf-8",
8
+ "integrity": "sha256-5eJ6Uud7jJAJbriBe66nr6V/H3zgM9Tal1wMlFvOHCY= sha384-+LFwWG5pMgR4lBhYlqsZrDamjv0b5uZE98RKTIh7p6dOtdnAgzGh1pOSWXqSa7Fn sha512-TKlnXP3LB/fdACqXPGAiAEdqyQL2Ba0JtWgh65+IKK9OsqosH1iZKlLK32P/Z3L9VZ3R9pqZBaZH27MuzTawvw==",
9
+ "hashes": {
10
+ "sha256": "5eJ6Uud7jJAJbriBe66nr6V/H3zgM9Tal1wMlFvOHCY=",
11
+ "sha384": "+LFwWG5pMgR4lBhYlqsZrDamjv0b5uZE98RKTIh7p6dOtdnAgzGh1pOSWXqSa7Fn",
12
+ "sha512": "TKlnXP3LB/fdACqXPGAiAEdqyQL2Ba0JtWgh65+IKK9OsqosH1iZKlLK32P/Z3L9VZ3R9pqZBaZH27MuzTawvw=="
13
+ }
14
+ },
15
+ "@min.js": {
16
+ "file": "aib.2.8.0-beta.2203-03.min.js",
17
+ "type": "text/javascript; charset=utf-8",
18
+ "integrity": "sha256-D5djet7rZdWD6OiPzvQnv784R0AEaHxatsB9OdkT0Rg= sha384-9t4LyR6a9NIEJiPDzf2oinpycvi4R/SvFssF8r/S75LPnq1J3N8e7UTVK3YUB5Fv sha512-pFT+VYqul7QTCymGLciMwsEQT3KsEB8bNmRh63nCzNYy/B7iJoqBersLD1TEqyUqWmGaX9p4mi6/uGXslB+guQ==",
19
+ "hashes": {
20
+ "sha256": "D5djet7rZdWD6OiPzvQnv784R0AEaHxatsB9OdkT0Rg=",
21
+ "sha384": "9t4LyR6a9NIEJiPDzf2oinpycvi4R/SvFssF8r/S75LPnq1J3N8e7UTVK3YUB5Fv",
22
+ "sha512": "pFT+VYqul7QTCymGLciMwsEQT3KsEB8bNmRh63nCzNYy/B7iJoqBersLD1TEqyUqWmGaX9p4mi6/uGXslB+guQ=="
23
+ }
24
+ }
25
+ }
26
+ }
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Application Insights JavaScript Web SDK - Basic, 2.8.0-beta.2203-02
2
+ * Application Insights JavaScript Web SDK - Basic, 2.8.0-beta.2203-03
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
  (function (global, factory) {
@@ -786,7 +786,7 @@
786
786
  objForEachKey(values, function (field, value) {
787
787
  enumClass[field] = value;
788
788
  if (!isUndefined(enumClass[value])) {
789
- throwError("Value: [" + value + "] already exists for " + field);
789
+ throwError("[" + value + "] exists for " + field);
790
790
  }
791
791
  enumClass[value] = field;
792
792
  });
@@ -1597,8 +1597,11 @@
1597
1597
  return createTelemetryProxyChain([startAt], config, core);
1598
1598
  }
1599
1599
  function _createInternalContext(telemetryChain, config, core, startAt) {
1600
- var _nextProxy = startAt ? _getNextProxyStart(telemetryChain, config, core, startAt) : telemetryChain;
1600
+ var _nextProxy = null;
1601
1601
  var _onComplete = [];
1602
+ if (startAt !== null) {
1603
+ _nextProxy = startAt ? _getNextProxyStart(telemetryChain, config, core, startAt) : telemetryChain;
1604
+ }
1602
1605
  var context = {
1603
1606
  _next: _moveNext,
1604
1607
  ctx: {
@@ -2295,6 +2298,30 @@
2295
2298
  return channelQueue;
2296
2299
  }
2297
2300
 
2301
+ function createUnloadHandlerContainer() {
2302
+ var handlers = [];
2303
+ function _addHandler(handler) {
2304
+ if (handler) {
2305
+ handlers.push(handler);
2306
+ }
2307
+ }
2308
+ function _runHandlers(unloadCtx, unloadState) {
2309
+ arrForEach(handlers, function (handler) {
2310
+ try {
2311
+ handler(unloadCtx, unloadState);
2312
+ }
2313
+ catch (e) {
2314
+ unloadCtx.diagLog().throwInternal(2 , 73 , "Unexpected error calling unload handler - " + dumpObj(e));
2315
+ }
2316
+ });
2317
+ handlers = [];
2318
+ }
2319
+ return {
2320
+ add: _addHandler,
2321
+ run: _runHandlers
2322
+ };
2323
+ }
2324
+
2298
2325
  var strGetPlugin = "getPlugin";
2299
2326
  var BaseTelemetryPlugin = /** @class */ (function () {
2300
2327
  function BaseTelemetryPlugin() {
@@ -2302,6 +2329,7 @@
2302
2329
  var _isinitialized;
2303
2330
  var _rootCtx;
2304
2331
  var _nextPlugin;
2332
+ var _unloadHandlerContainer;
2305
2333
  var _hooks;
2306
2334
  _initDefaults();
2307
2335
  dynamicProto(BaseTelemetryPlugin, _self, function (_self) {
@@ -2323,6 +2351,7 @@
2323
2351
  function _unloadCallback() {
2324
2352
  if (!unloadDone) {
2325
2353
  unloadDone = true;
2354
+ _unloadHandlerContainer.run(theUnloadCtx, unloadState);
2326
2355
  arrForEach(_hooks, function (fn) {
2327
2356
  fn.rm();
2328
2357
  });
@@ -2351,6 +2380,7 @@
2351
2380
  }
2352
2381
  }
2353
2382
  };
2383
+ proxyFunctionAs(_self, "_addUnloadCb", function () { return _unloadHandlerContainer; }, "add");
2354
2384
  });
2355
2385
  _self.diagLog = function (itemCtx) {
2356
2386
  return _getTelCtx(itemCtx).diagLog();
@@ -2407,6 +2437,7 @@
2407
2437
  _rootCtx = null;
2408
2438
  _nextPlugin = null;
2409
2439
  _hooks = [];
2440
+ _unloadHandlerContainer = createUnloadHandlerContainer();
2410
2441
  }
2411
2442
  }
2412
2443
  return BaseTelemetryPlugin;
@@ -2476,6 +2507,8 @@
2476
2507
 
2477
2508
  var strValidationError = "Plugins must provide initialize method";
2478
2509
  var strNotificationManager = "_notificationManager";
2510
+ var strSdkUnloadingError = "SDK is still unloading...";
2511
+ var strSdkNotInitialized = "SDK is not initialized";
2479
2512
  function _createPerfManager(core, notificationMgr) {
2480
2513
  return new PerfManager(notificationMgr);
2481
2514
  }
@@ -2505,6 +2538,16 @@
2505
2538
  core: coreExtensions
2506
2539
  };
2507
2540
  }
2541
+ function _isPluginPresent(thePlugin, plugins) {
2542
+ var exists = false;
2543
+ arrForEach(plugins, function (plugin) {
2544
+ if (plugin === thePlugin) {
2545
+ exists = true;
2546
+ return -1;
2547
+ }
2548
+ });
2549
+ return exists;
2550
+ }
2508
2551
  function _createDummyNotificationManager() {
2509
2552
  var _a;
2510
2553
  return objCreateFn((_a = {},
@@ -2529,15 +2572,20 @@
2529
2572
  var _channelControl;
2530
2573
  var _channelConfig;
2531
2574
  var _channelQueue;
2575
+ var _isUnloading;
2532
2576
  var _telemetryInitializerPlugin;
2533
2577
  var _internalLogsEventName;
2534
2578
  var _evtNamespace;
2579
+ var _unloadHandlers;
2535
2580
  var _debugListener;
2536
2581
  var _internalLogPoller = 0;
2537
2582
  dynamicProto(BaseCore, this, function (_self) {
2538
2583
  _initDefaults();
2539
2584
  _self.isInitialized = function () { return _isInitialized; };
2540
2585
  _self.initialize = function (config, extensions, logger, notificationManager) {
2586
+ if (_isUnloading) {
2587
+ throwError(strSdkUnloadingError);
2588
+ }
2541
2589
  if (_self.isInitialized()) {
2542
2590
  throwError("Core should not be initialized more than once");
2543
2591
  }
@@ -2550,8 +2598,7 @@
2550
2598
  _initDebugListener(config);
2551
2599
  _initPerfManager(config);
2552
2600
  config.extensions = isNullOrUndefined(config.extensions) ? [] : config.extensions;
2553
- var extConfig = getSetValue(config, strExtensionConfig);
2554
- extConfig.NotificationManager = notificationManager;
2601
+ _initExtConfig(config);
2555
2602
  if (logger) {
2556
2603
  _self.logger = logger;
2557
2604
  }
@@ -2576,7 +2623,7 @@
2576
2623
  setValue(telemetryItem, strIKey, _self.config.instrumentationKey, null, isNotTruthy);
2577
2624
  setValue(telemetryItem, "time", toISOString(new Date()), null, isNotTruthy);
2578
2625
  setValue(telemetryItem, "ver", "4.0", null, isNullOrUndefined);
2579
- if (_self.isInitialized()) {
2626
+ if (!_isUnloading && _self.isInitialized()) {
2580
2627
  _createTelCtx().processNext(telemetryItem);
2581
2628
  }
2582
2629
  else {
@@ -2591,14 +2638,14 @@
2591
2638
  }
2592
2639
  return _notificationManager;
2593
2640
  };
2594
- _self.addNotificationListener = function (listener) {
2641
+ _self[strAddNotificationListener] = function (listener) {
2595
2642
  if (_notificationManager) {
2596
- _notificationManager.addNotificationListener(listener);
2643
+ _notificationManager[strAddNotificationListener](listener);
2597
2644
  }
2598
2645
  };
2599
- _self.removeNotificationListener = function (listener) {
2646
+ _self[strRemoveNotificationListener] = function (listener) {
2600
2647
  if (_notificationManager) {
2601
- _notificationManager.removeNotificationListener(listener);
2648
+ _notificationManager[strRemoveNotificationListener](listener);
2602
2649
  }
2603
2650
  };
2604
2651
  _self.getCookieMgr = function () {
@@ -2655,10 +2702,80 @@
2655
2702
  }
2656
2703
  };
2657
2704
  proxyFunctions(_self, function () { return _telemetryInitializerPlugin; }, ["addTelemetryInitializer"]);
2705
+ _self.unload = function (isAsync, unloadComplete, cbTimeout) {
2706
+ if (isAsync === void 0) { isAsync = true; }
2707
+ if (!_isInitialized) {
2708
+ throwError(strSdkNotInitialized);
2709
+ }
2710
+ if (_isUnloading) {
2711
+ throwError(strSdkUnloadingError);
2712
+ }
2713
+ var unloadState = {
2714
+ reason: 50 ,
2715
+ isAsync: isAsync,
2716
+ flushComplete: false
2717
+ };
2718
+ var processUnloadCtx = createProcessTelemetryUnloadContext(_getPluginChain(), _self.config, _self);
2719
+ processUnloadCtx.onComplete(function () {
2720
+ _initDefaults();
2721
+ unloadComplete && unloadComplete(unloadState);
2722
+ }, _self);
2723
+ function _doUnload(flushComplete) {
2724
+ unloadState.flushComplete = flushComplete;
2725
+ _isUnloading = true;
2726
+ _unloadHandlers.run(processUnloadCtx, unloadState);
2727
+ _self.stopPollingInternalLogs();
2728
+ processUnloadCtx.processNext(unloadState);
2729
+ }
2730
+ if (_channelControl) {
2731
+ _channelControl.flush(isAsync, _doUnload, 6 , cbTimeout);
2732
+ }
2733
+ else {
2734
+ _doUnload(true);
2735
+ }
2736
+ };
2658
2737
  _self.getPlugin = _getPlugin;
2738
+ _self.addPlugin = function (plugin, replaceExisting, isAsync, addCb) {
2739
+ if (isAsync === void 0) { isAsync = true; }
2740
+ if (!plugin) {
2741
+ addCb && addCb(false);
2742
+ _logOrThrowError(strValidationError);
2743
+ return;
2744
+ }
2745
+ var existingPlugin = _getPlugin(plugin.identifier);
2746
+ if (existingPlugin && !replaceExisting) {
2747
+ addCb && addCb(false);
2748
+ _logOrThrowError("Plugin [" + plugin.identifier + "] is already loaded!");
2749
+ return;
2750
+ }
2751
+ function _addPlugin(removed) {
2752
+ _configExtensions.push(plugin);
2753
+ _initPluginChain(_self.config);
2754
+ addCb && addCb(true);
2755
+ }
2756
+ if (existingPlugin) {
2757
+ var removedPlugins = [existingPlugin.plugin];
2758
+ var unloadState = {
2759
+ reason: 2 ,
2760
+ isAsync: isAsync
2761
+ };
2762
+ _removePlugins(removedPlugins, unloadState, function (removed) {
2763
+ if (!removed) {
2764
+ addCb && addCb(false);
2765
+ }
2766
+ else {
2767
+ _addPlugin();
2768
+ }
2769
+ });
2770
+ }
2771
+ else {
2772
+ _addPlugin();
2773
+ }
2774
+ };
2659
2775
  _self.evtNamespace = function () {
2660
2776
  return _evtNamespace;
2661
2777
  };
2778
+ proxyFunctionAs(_self, "addUnloadCb", function () { return _unloadHandlers; }, "add");
2662
2779
  function _initDefaults() {
2663
2780
  _isInitialized = false;
2664
2781
  _self.logger = new DiagnosticLogger({ loggingLevelConsole: 1 });
@@ -2676,8 +2793,10 @@
2676
2793
  _channelControl = null;
2677
2794
  _channelConfig = null;
2678
2795
  _channelQueue = null;
2796
+ _isUnloading = false;
2679
2797
  _internalLogsEventName = null;
2680
2798
  _evtNamespace = createUniqueNamespace("AIBaseCore", true);
2799
+ _unloadHandlers = createUnloadHandlerContainer();
2681
2800
  }
2682
2801
  function _createTelCtx() {
2683
2802
  return createProcessTelemetryContext(_getPluginChain(), _self.config, _self);
@@ -2730,6 +2849,20 @@
2730
2849
  isEnabled: function () {
2731
2850
  var pluginState = _getPluginState(thePlugin);
2732
2851
  return !pluginState[strTeardown] && !pluginState[strDisabled];
2852
+ },
2853
+ remove: function (isAsync, removeCb) {
2854
+ if (isAsync === void 0) { isAsync = true; }
2855
+ var pluginsToRemove = [thePlugin];
2856
+ var unloadState = {
2857
+ reason: 1 ,
2858
+ isAsync: isAsync
2859
+ };
2860
+ _removePlugins(pluginsToRemove, unloadState, function (removed) {
2861
+ if (removed) {
2862
+ _initPluginChain(_self.config);
2863
+ }
2864
+ removeCb && removeCb(removed);
2865
+ });
2733
2866
  }
2734
2867
  };
2735
2868
  }
@@ -2745,6 +2878,46 @@
2745
2878
  }
2746
2879
  return _pluginChain;
2747
2880
  }
2881
+ function _removePlugins(thePlugins, unloadState, removeComplete) {
2882
+ if (thePlugins && thePlugins.length > 0) {
2883
+ var unloadChain = createTelemetryProxyChain(thePlugins, _self.config, _self);
2884
+ var unloadCtx = createProcessTelemetryUnloadContext(unloadChain, _self.config, _self);
2885
+ unloadCtx.onComplete(function () {
2886
+ var removed = false;
2887
+ var newConfigExtensions = [];
2888
+ arrForEach(_configExtensions, function (plugin, idx) {
2889
+ if (!_isPluginPresent(plugin, thePlugins)) {
2890
+ newConfigExtensions.push(plugin);
2891
+ }
2892
+ else {
2893
+ removed = true;
2894
+ }
2895
+ });
2896
+ _configExtensions = newConfigExtensions;
2897
+ var newChannelConfig = [];
2898
+ if (_channelConfig) {
2899
+ arrForEach(_channelConfig, function (queue, idx) {
2900
+ var newQueue = [];
2901
+ arrForEach(queue, function (channel) {
2902
+ if (!_isPluginPresent(channel, thePlugins)) {
2903
+ newQueue.push(channel);
2904
+ }
2905
+ else {
2906
+ removed = true;
2907
+ }
2908
+ });
2909
+ newChannelConfig.push(newQueue);
2910
+ });
2911
+ _channelConfig = newChannelConfig;
2912
+ }
2913
+ removeComplete && removeComplete(removed);
2914
+ });
2915
+ unloadCtx.processNext(unloadState);
2916
+ }
2917
+ else {
2918
+ removeComplete(false);
2919
+ }
2920
+ }
2748
2921
  function _flushInternalLogs() {
2749
2922
  var queue = _self.logger ? _self.logger.queue : [];
2750
2923
  if (queue) {
@@ -2779,6 +2952,19 @@
2779
2952
  setValue(_self.config, "createPerfMgr", _createPerfManager);
2780
2953
  }
2781
2954
  }
2955
+ function _initExtConfig(config) {
2956
+ var extConfig = getSetValue(config, strExtensionConfig);
2957
+ extConfig.NotificationManager = _notificationManager;
2958
+ }
2959
+ function _logOrThrowError(message) {
2960
+ var logger = _self.logger;
2961
+ if (logger) {
2962
+ logger.throwInternal(2 , 73 , message);
2963
+ }
2964
+ else {
2965
+ throwError(message);
2966
+ }
2967
+ }
2782
2968
  });
2783
2969
  }
2784
2970
  return BaseCore;
@@ -4683,7 +4869,7 @@
4683
4869
  }
4684
4870
  }
4685
4871
  var EnvelopeCreator = {
4686
- Version: "2.8.0-beta.2203-02"
4872
+ Version: "2.8.0-beta.2203-03"
4687
4873
  };
4688
4874
  function DependencyEnvelopeCreator(logger, telemetryItem, customUndefinedValue) {
4689
4875
  EnvelopeCreatorInit(logger, telemetryItem);
@@ -5853,4 +6039,4 @@
5853
6039
  (function(obj, prop, descriptor) { /* ai_es3_polyfil defineProperty */ var func = Object["defineProperty"]; if (func) { try { return func(obj, prop, descriptor); } catch(e) { /* IE8 defines defineProperty, but will throw */ } } if (descriptor && typeof descriptor.value !== undefined) { obj[prop] = descriptor.value; } return obj; })(exports, '__esModule', { value: true });
5854
6040
 
5855
6041
  }));
5856
- //# sourceMappingURL=aib.2.8.0-beta.2203-02.js.map
6042
+ //# sourceMappingURL=aib.2.8.0-beta.2203-03.js.map