@microsoft/applicationinsights-common 3.0.3-nightly3.2308-06 → 3.0.3-nightly3.2308-07

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 (97) hide show
  1. package/browser/es5/applicationinsights-common.cjs.js +90 -169
  2. package/browser/es5/applicationinsights-common.cjs.js.map +1 -1
  3. package/browser/es5/applicationinsights-common.cjs.min.js +2 -2
  4. package/browser/es5/applicationinsights-common.cjs.min.js.map +1 -1
  5. package/browser/es5/applicationinsights-common.gbl.js +92 -171
  6. package/browser/es5/applicationinsights-common.gbl.js.map +1 -1
  7. package/browser/es5/applicationinsights-common.gbl.min.js +2 -2
  8. package/browser/es5/applicationinsights-common.gbl.min.js.map +1 -1
  9. package/browser/es5/applicationinsights-common.integrity.json +25 -25
  10. package/browser/es5/applicationinsights-common.js +92 -171
  11. package/browser/es5/applicationinsights-common.js.map +1 -1
  12. package/browser/es5/applicationinsights-common.min.js +2 -2
  13. package/browser/es5/applicationinsights-common.min.js.map +1 -1
  14. package/dist/es5/applicationinsights-common.js +90 -169
  15. package/dist/es5/applicationinsights-common.js.map +1 -1
  16. package/dist/es5/applicationinsights-common.min.js +2 -2
  17. package/dist/es5/applicationinsights-common.min.js.map +1 -1
  18. package/dist-es5/ConnectionStringParser.js +1 -1
  19. package/dist-es5/Constants.js +1 -1
  20. package/dist-es5/DomHelperFuncs.js +1 -1
  21. package/dist-es5/Enums.js +1 -1
  22. package/dist-es5/HelperFuncs.js +1 -1
  23. package/dist-es5/Interfaces/ConnectionString.js +1 -1
  24. package/dist-es5/Interfaces/Context/IApplication.js +1 -1
  25. package/dist-es5/Interfaces/Context/IDevice.js +1 -1
  26. package/dist-es5/Interfaces/Context/IInternal.js +1 -1
  27. package/dist-es5/Interfaces/Context/ILocation.js +1 -1
  28. package/dist-es5/Interfaces/Context/IOperatingSystem.js +1 -1
  29. package/dist-es5/Interfaces/Context/ISample.js +1 -1
  30. package/dist-es5/Interfaces/Context/ISession.js +1 -1
  31. package/dist-es5/Interfaces/Context/ISessionManager.js +1 -1
  32. package/dist-es5/Interfaces/Context/ITelemetryTrace.js +1 -1
  33. package/dist-es5/Interfaces/Context/IUser.js +1 -1
  34. package/dist-es5/Interfaces/Context/IWeb.js +1 -1
  35. package/dist-es5/Interfaces/Contracts/AvailabilityData.js +1 -1
  36. package/dist-es5/Interfaces/Contracts/ContextTagKeys.js +1 -1
  37. package/dist-es5/Interfaces/Contracts/DataPointType.js +1 -1
  38. package/dist-es5/Interfaces/Contracts/DependencyKind.js +1 -1
  39. package/dist-es5/Interfaces/Contracts/DependencySourceType.js +1 -1
  40. package/dist-es5/Interfaces/Contracts/IBase.js +1 -1
  41. package/dist-es5/Interfaces/Contracts/IData.js +1 -1
  42. package/dist-es5/Interfaces/Contracts/IDataPoint.js +1 -1
  43. package/dist-es5/Interfaces/Contracts/IDomain.js +1 -1
  44. package/dist-es5/Interfaces/Contracts/IEnvelope.js +1 -1
  45. package/dist-es5/Interfaces/Contracts/IEventData.js +1 -1
  46. package/dist-es5/Interfaces/Contracts/IExceptionData.js +1 -1
  47. package/dist-es5/Interfaces/Contracts/IExceptionDetails.js +1 -1
  48. package/dist-es5/Interfaces/Contracts/IMessageData.js +1 -1
  49. package/dist-es5/Interfaces/Contracts/IMetricData.js +1 -1
  50. package/dist-es5/Interfaces/Contracts/IPageViewData.js +1 -1
  51. package/dist-es5/Interfaces/Contracts/IPageViewPerfData.js +1 -1
  52. package/dist-es5/Interfaces/Contracts/IRemoteDependencyData.js +1 -1
  53. package/dist-es5/Interfaces/Contracts/IStackFrame.js +1 -1
  54. package/dist-es5/Interfaces/Contracts/RequestData.js +1 -1
  55. package/dist-es5/Interfaces/Contracts/SeverityLevel.js +1 -1
  56. package/dist-es5/Interfaces/IAppInsights.js +1 -1
  57. package/dist-es5/Interfaces/IConfig.js +1 -1
  58. package/dist-es5/Interfaces/ICorrelationConfig.js +1 -1
  59. package/dist-es5/Interfaces/IDependencyTelemetry.js +1 -1
  60. package/dist-es5/Interfaces/IEventTelemetry.js +1 -1
  61. package/dist-es5/Interfaces/IExceptionTelemetry.js +1 -1
  62. package/dist-es5/Interfaces/IMetricTelemetry.js +1 -1
  63. package/dist-es5/Interfaces/IPageViewPerformanceTelemetry.js +1 -1
  64. package/dist-es5/Interfaces/IPageViewTelemetry.js +1 -1
  65. package/dist-es5/Interfaces/IPartC.js +1 -1
  66. package/dist-es5/Interfaces/IPropertiesPlugin.js +1 -1
  67. package/dist-es5/Interfaces/IRequestContext.js +1 -1
  68. package/dist-es5/Interfaces/IStorageBuffer.js +1 -1
  69. package/dist-es5/Interfaces/ITelemetryContext.js +1 -1
  70. package/dist-es5/Interfaces/IThrottleMgr.js +1 -1
  71. package/dist-es5/Interfaces/ITraceTelemetry.js +1 -1
  72. package/dist-es5/Interfaces/PartAExtensions.js +1 -1
  73. package/dist-es5/Interfaces/Telemetry/IEnvelope.js +1 -1
  74. package/dist-es5/Interfaces/Telemetry/ISerializable.js +1 -1
  75. package/dist-es5/RequestResponseHeaders.js +1 -1
  76. package/dist-es5/StorageHelperFuncs.js +1 -1
  77. package/dist-es5/Telemetry/Common/Data.js +1 -1
  78. package/dist-es5/Telemetry/Common/DataPoint.js +1 -1
  79. package/dist-es5/Telemetry/Common/DataSanitizer.js +1 -1
  80. package/dist-es5/Telemetry/Common/Envelope.js +1 -1
  81. package/dist-es5/Telemetry/Event.js +1 -1
  82. package/dist-es5/Telemetry/Exception.js +1 -1
  83. package/dist-es5/Telemetry/Metric.js +1 -1
  84. package/dist-es5/Telemetry/PageView.js +1 -1
  85. package/dist-es5/Telemetry/PageViewPerformance.js +1 -1
  86. package/dist-es5/Telemetry/RemoteDependencyData.js +1 -1
  87. package/dist-es5/Telemetry/Trace.js +1 -1
  88. package/dist-es5/TelemetryItemCreator.js +1 -1
  89. package/dist-es5/ThrottleMgr.js +99 -43
  90. package/dist-es5/ThrottleMgr.js.map +1 -1
  91. package/dist-es5/UrlHelperFuncs.js +1 -1
  92. package/dist-es5/Util.js +1 -1
  93. package/dist-es5/__DynamicConstants.js +1 -1
  94. package/dist-es5/applicationinsights-common.js +1 -1
  95. package/package.json +2 -2
  96. package/types/applicationinsights-common.d.ts +12 -28
  97. package/types/applicationinsights-common.namespaced.d.ts +12 -28
@@ -1,18 +1,18 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Common, 3.0.3-nightly3.2308-06
2
+ * Application Insights JavaScript SDK - Common, 3.0.3-nightly3.2308-07
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
- import { _throwInternal, arrForEach, arrIndexOf, createDynamicConfig, createUnloadHookContainer, isNotNullOrUndefined, isNullOrUndefined, onConfigChange, randomValue, safeGetLogger, strTrim } from "@microsoft/applicationinsights-core-js";
5
+ import { _throwInternal, arrIndexOf, isNotNullOrUndefined, isNullOrUndefined, onConfigChange, randomValue, safeGetLogger, strTrim } from "@microsoft/applicationinsights-core-js";
6
+ import { arrForEach, objForEachKey } from "@nevware21/ts-utils";
6
7
  import { utlCanUseLocalStorage, utlGetLocalStorage, utlSetLocalStorage } from "./StorageHelperFuncs";
7
8
  import { _DYN_COUNT, _DYN_DATE, _DYN_DAYS_OF_MONTH, _DYN_DISABLED, _DYN_GET_UTCDATE, _DYN_INTERVAL, _DYN_LENGTH, _DYN_MESSAGE, _DYN_PRE_TRIGGER_DATE, _DYN_STRINGIFY } from "./__DynamicConstants";
8
9
  var THROTTLE_STORAGE_PREFIX = "appInsightsThrottle";
9
10
  var ThrottleMgr = /** @class */ (function () {
10
- function ThrottleMgr(config, core, namePrefix, unloadHookContainer) {
11
+ function ThrottleMgr(core, namePrefix) {
11
12
  var _self = this;
12
13
  var _canUseLocalStorage;
13
14
  var _logger;
14
15
  var _config;
15
- var _localStorageName;
16
16
  var _localStorageObj;
17
17
  var _isTriggered; //_isTriggered is to make sure that we only trigger throttle once a day
18
18
  var _namePrefix;
@@ -33,16 +33,17 @@ var ThrottleMgr = /** @class */ (function () {
33
33
  * because we only allow triggering sendMessage() once a day.
34
34
  * @returns if the current date is the valid date to send message
35
35
  */
36
- _self.canThrottle = function () {
37
- return _canThrottle(_config, _canUseLocalStorage, _localStorageObj);
36
+ _self.canThrottle = function (msgId) {
37
+ var localObj = _getLocalStorageObjByKey(msgId);
38
+ return _canThrottle(_config, _canUseLocalStorage, localObj);
38
39
  };
39
40
  /**
40
41
  * Check if throttle is triggered on current day(UTC)
41
42
  * if canThrottle returns false, isTriggered will return false
42
43
  * @returns if throttle is triggered on current day(UTC)
43
44
  */
44
- _self.isTriggered = function () {
45
- return _isTriggered;
45
+ _self.isTriggered = function (msgId) {
46
+ return _isTrigger(msgId);
46
47
  };
47
48
  /**
48
49
  * Before isReady set to true, all message will be stored in queue.
@@ -54,14 +55,15 @@ var ThrottleMgr = /** @class */ (function () {
54
55
  return _isReady;
55
56
  };
56
57
  /**
57
- * Flush all message in queue with isReady state set to true.
58
+ * Flush all message with given message key in queue with isReady state set to true.
58
59
  * @returns if message queue is flushed
59
60
  */
60
- _self.flush = function () {
61
+ _self.flush = function (msgId) {
61
62
  try {
62
- if (_isReady && _queue[_DYN_LENGTH /* @min:%2elength */] > 0) {
63
- var items = _queue.slice(0);
64
- _queue = [];
63
+ var queue = _getQueueByKey(msgId);
64
+ if (queue && queue[_DYN_LENGTH /* @min:%2elength */] > 0) {
65
+ var items = queue.slice(0);
66
+ _queue[msgId] = [];
65
67
  arrForEach(items, function (item) {
66
68
  _flushMessage(item.msgID, item[_DYN_MESSAGE /* @min:%2emessage */], item.severity, false);
67
69
  });
@@ -73,15 +75,40 @@ var ThrottleMgr = /** @class */ (function () {
73
75
  }
74
76
  return false;
75
77
  };
78
+ /**
79
+ * Flush all message in queue with isReady state set to true.
80
+ * @returns if message queue is flushed
81
+ */
82
+ _self.flushAll = function () {
83
+ try {
84
+ if (_queue) {
85
+ var result_1 = true;
86
+ objForEachKey(_queue, function (key) {
87
+ var isFlushed = _self.flush(parseInt(key));
88
+ result_1 = result_1 && isFlushed;
89
+ });
90
+ return result_1;
91
+ }
92
+ }
93
+ catch (err) {
94
+ // eslint-disable-next-line no-empty
95
+ }
96
+ return false;
97
+ };
76
98
  /**
77
99
  * Set isReady State
78
100
  * if isReady set to true, message queue will be flushed automatically.
79
101
  * @param isReady isReady State
102
+ * @pa
80
103
  * @returns if message queue is flushed
81
104
  */
82
- _self.onReadyState = function (isReady) {
105
+ _self.onReadyState = function (isReady, flushAll) {
106
+ if (flushAll === void 0) { flushAll = true; }
83
107
  _isReady = isNullOrUndefined(isReady) ? true : isReady;
84
- return _self.flush();
108
+ if (_isReady && flushAll) {
109
+ return _self.flushAll();
110
+ }
111
+ return null;
85
112
  };
86
113
  _self.sendMessage = function (msgID, message, severity) {
87
114
  return _flushMessage(msgID, message, severity, true);
@@ -92,22 +119,25 @@ var ThrottleMgr = /** @class */ (function () {
92
119
  if (!isSampledIn) {
93
120
  return;
94
121
  }
95
- var canThrottle = _canThrottle(_config, _canUseLocalStorage, _localStorageObj);
122
+ var localStorageObj = _getLocalStorageObjByKey(msgID);
123
+ var canThrottle = _canThrottle(_config, _canUseLocalStorage, localStorageObj);
96
124
  var throttled = false;
97
125
  var number = 0;
126
+ var isTriggered = _isTrigger(msgID);
98
127
  try {
99
- if (canThrottle && !_isTriggered) {
100
- number = Math.min(_config.limit.maxSendNumber, _localStorageObj[_DYN_COUNT /* @min:%2ecount */] + 1);
101
- _localStorageObj[_DYN_COUNT /* @min:%2ecount */] = 0;
128
+ if (canThrottle && !isTriggered) {
129
+ number = Math.min(_config.limit.maxSendNumber, localStorageObj[_DYN_COUNT /* @min:%2ecount */] + 1);
130
+ localStorageObj[_DYN_COUNT /* @min:%2ecount */] = 0;
102
131
  throttled = true;
103
- _isTriggered = true;
104
- _localStorageObj[_DYN_PRE_TRIGGER_DATE /* @min:%2epreTriggerDate */] = new Date();
132
+ _isTriggered[msgID] = true;
133
+ localStorageObj[_DYN_PRE_TRIGGER_DATE /* @min:%2epreTriggerDate */] = new Date();
105
134
  }
106
135
  else {
107
- _isTriggered = canThrottle;
108
- _localStorageObj[_DYN_COUNT /* @min:%2ecount */] += 1;
136
+ _isTriggered[msgID] = canThrottle;
137
+ localStorageObj[_DYN_COUNT /* @min:%2ecount */] += 1;
109
138
  }
110
- _resetLocalStorage(_logger, _localStorageName, _localStorageObj);
139
+ var localStorageName = _getLocalStorageName(msgID);
140
+ _resetLocalStorage(_logger, localStorageName, localStorageObj);
111
141
  for (var i = 0; i < number; i++) {
112
142
  _sendMessage(msgID, _logger, message, severity);
113
143
  }
@@ -122,7 +152,8 @@ var ThrottleMgr = /** @class */ (function () {
122
152
  }
123
153
  else {
124
154
  if (!!saveUnsentMsg) {
125
- _queue.push({
155
+ var queue = _getQueueByKey(msgID);
156
+ queue.push({
126
157
  msgID: msgID,
127
158
  message: message,
128
159
  severity: severity
@@ -133,19 +164,17 @@ var ThrottleMgr = /** @class */ (function () {
133
164
  }
134
165
  function _initConfig() {
135
166
  _logger = safeGetLogger(core);
136
- _isTriggered = false;
137
- _queue = [];
167
+ _isTriggered = {};
168
+ _localStorageObj = {};
169
+ _queue = {};
138
170
  _namePrefix = isNotNullOrUndefined(namePrefix) ? namePrefix : "";
139
- unloadHookContainer = unloadHookContainer || createUnloadHookContainer();
140
- // Make sure the root config is dynamic as it may be the global config
141
- config = createDynamicConfig(config || {}, null, _logger).cfg;
142
- var unloadHook = onConfigChange(config, function () {
171
+ core.addUnloadHook(onConfigChange(core.config, function (details) {
143
172
  var _a, _b;
173
+ var coreConfig = details.cfg;
144
174
  _canUseLocalStorage = utlCanUseLocalStorage();
145
- var configMgr = config || {};
175
+ var configMgr = coreConfig.throttleMgrCfg || {};
146
176
  _config = {};
147
177
  _config[_DYN_DISABLED /* @min:%2edisabled */] = !!configMgr[_DYN_DISABLED /* @min:%2edisabled */];
148
- _config.msgKey = configMgr.msgKey || 0 /* IThrottleMsgKey.default */;
149
178
  var configInterval = configMgr[_DYN_INTERVAL /* @min:%2einterval */] || {};
150
179
  _isSpecificDaysGiven = (configInterval === null || configInterval === void 0 ? void 0 : configInterval.daysOfMonth) && (configInterval === null || configInterval === void 0 ? void 0 : configInterval.daysOfMonth[_DYN_LENGTH /* @min:%2elength */]) > 0;
151
180
  _config[_DYN_INTERVAL /* @min:%2einterval */] = _getIntervalConfig(configInterval);
@@ -155,15 +184,7 @@ var ThrottleMgr = /** @class */ (function () {
155
184
  maxSendNumber: ((_b = configMgr.limit) === null || _b === void 0 ? void 0 : _b.maxSendNumber) || 1
156
185
  };
157
186
  _config.limit = limit;
158
- _localStorageName = _getLocalStorageName(_config.msgKey, _namePrefix);
159
- if (_canUseLocalStorage && _localStorageName) {
160
- _localStorageObj = _getLocalStorageObj(utlGetLocalStorage(_logger, _localStorageName), _logger, _localStorageName);
161
- }
162
- if (_localStorageObj) {
163
- _isTriggered = _isTriggeredOnCurDate(_localStorageObj[_DYN_PRE_TRIGGER_DATE /* @min:%2epreTriggerDate */]);
164
- }
165
- });
166
- unloadHookContainer && unloadHookContainer.add(unloadHook);
187
+ }));
167
188
  }
168
189
  function _getIntervalConfig(interval) {
169
190
  interval = interval || {};
@@ -239,11 +260,12 @@ var ThrottleMgr = /** @class */ (function () {
239
260
  };
240
261
  if (value) {
241
262
  var obj = JSON.parse(value);
242
- return {
263
+ var curObj = {
243
264
  date: _getThrottleDate(obj[_DYN_DATE /* @min:%2edate */]) || storageObj[_DYN_DATE /* @min:%2edate */],
244
265
  count: obj[_DYN_COUNT /* @min:%2ecount */] || storageObj[_DYN_COUNT /* @min:%2ecount */],
245
266
  preTriggerDate: obj.preTriggerDate ? _getThrottleDate(obj[_DYN_PRE_TRIGGER_DATE /* @min:%2epreTriggerDate */]) : undefined
246
267
  };
268
+ return curObj;
247
269
  }
248
270
  else {
249
271
  _resetLocalStorage(logger, storageName, storageObj);
@@ -299,6 +321,40 @@ var ThrottleMgr = /** @class */ (function () {
299
321
  function _canSampledIn() {
300
322
  return randomValue(1000000) <= _config.limit.samplingRate;
301
323
  }
324
+ function _getLocalStorageObjByKey(key) {
325
+ try {
326
+ var curObj = _localStorageObj[key];
327
+ if (!curObj) {
328
+ var localStorageName = _getLocalStorageName(key, _namePrefix);
329
+ curObj = _getLocalStorageObj(utlGetLocalStorage(_logger, localStorageName), _logger, localStorageName);
330
+ _localStorageObj[key] = curObj;
331
+ }
332
+ return _localStorageObj[key];
333
+ }
334
+ catch (e) {
335
+ // eslint-disable-next-line no-empty
336
+ }
337
+ return null;
338
+ }
339
+ function _isTrigger(key) {
340
+ var isTrigger = _isTriggered[key];
341
+ if (isNullOrUndefined(isTrigger)) {
342
+ isTrigger = false;
343
+ var localStorageObj = _getLocalStorageObjByKey(key);
344
+ if (localStorageObj) {
345
+ isTrigger = _isTriggeredOnCurDate(localStorageObj[_DYN_PRE_TRIGGER_DATE /* @min:%2epreTriggerDate */]);
346
+ }
347
+ _isTriggered[key] = isTrigger;
348
+ }
349
+ return _isTriggered[key];
350
+ }
351
+ function _getQueueByKey(key) {
352
+ _queue = _queue || {};
353
+ if (isNullOrUndefined(_queue[key])) {
354
+ _queue[key] = [];
355
+ }
356
+ return _queue[key];
357
+ }
302
358
  }
303
359
  return ThrottleMgr;
304
360
  }());
@@ -1 +1 @@
1
- {"version":3,"file":"ThrottleMgr.js.map","sources":["ThrottleMgr.js"],"sourcesContent":["import { _throwInternal, arrForEach, arrIndexOf, createDynamicConfig, createUnloadHookContainer, isNotNullOrUndefined, isNullOrUndefined, onConfigChange, randomValue, safeGetLogger, strTrim } from \"@microsoft/applicationinsights-core-js\";\r\nimport { utlCanUseLocalStorage, utlGetLocalStorage, utlSetLocalStorage } from \"./StorageHelperFuncs\";\r\nimport { _DYN_COUNT, _DYN_DATE, _DYN_DAYS_OF_MONTH, _DYN_DISABLED, _DYN_GET_UTCDATE, _DYN_INTERVAL, _DYN_LENGTH, _DYN_MESSAGE, _DYN_PRE_TRIGGER_DATE, _DYN_STRINGIFY } from \"./__DynamicConstants\";\r\nvar THROTTLE_STORAGE_PREFIX = \"appInsightsThrottle\";\r\nvar ThrottleMgr = /** @class */ (function () {\r\n function ThrottleMgr(config, core, namePrefix, unloadHookContainer) {\r\n var _self = this;\r\n var _canUseLocalStorage;\r\n var _logger;\r\n var _config;\r\n var _localStorageName;\r\n var _localStorageObj;\r\n var _isTriggered; //_isTriggered is to make sure that we only trigger throttle once a day\r\n var _namePrefix;\r\n var _queue;\r\n var _isReady = false;\r\n var _isSpecificDaysGiven = false;\r\n _initConfig();\r\n // Special internal method to allow the unit tests and DebugPlugin to hook embedded objects\r\n _self[\"_getDbgPlgTargets\"] = function () {\r\n return [_queue];\r\n };\r\n _self.getConfig = function () {\r\n return _config;\r\n };\r\n /**\r\n * Check if it is the correct day to send message.\r\n * If _isTriggered is true, even if canThrottle returns true, message will not be sent,\r\n * because we only allow triggering sendMessage() once a day.\r\n * @returns if the current date is the valid date to send message\r\n */\r\n _self.canThrottle = function () {\r\n return _canThrottle(_config, _canUseLocalStorage, _localStorageObj);\r\n };\r\n /**\r\n * Check if throttle is triggered on current day(UTC)\r\n * if canThrottle returns false, isTriggered will return false\r\n * @returns if throttle is triggered on current day(UTC)\r\n */\r\n _self.isTriggered = function () {\r\n return _isTriggered;\r\n };\r\n /**\r\n * Before isReady set to true, all message will be stored in queue.\r\n * Message will only be sent out after isReady set to true.\r\n * Initial and default value: false\r\n * @returns isReady state\r\n */\r\n _self.isReady = function () {\r\n return _isReady;\r\n };\r\n /**\r\n * Flush all message in queue with isReady state set to true.\r\n * @returns if message queue is flushed\r\n */\r\n _self.flush = function () {\r\n try {\r\n if (_isReady && _queue[_DYN_LENGTH /* @min:%2elength */] > 0) {\r\n var items = _queue.slice(0);\r\n _queue = [];\r\n arrForEach(items, function (item) {\r\n _flushMessage(item.msgID, item[_DYN_MESSAGE /* @min:%2emessage */], item.severity, false);\r\n });\r\n return true;\r\n }\r\n }\r\n catch (err) {\r\n // eslint-disable-next-line no-empty\r\n }\r\n return false;\r\n };\r\n /**\r\n * Set isReady State\r\n * if isReady set to true, message queue will be flushed automatically.\r\n * @param isReady isReady State\r\n * @returns if message queue is flushed\r\n */\r\n _self.onReadyState = function (isReady) {\r\n _isReady = isNullOrUndefined(isReady) ? true : isReady;\r\n return _self.flush();\r\n };\r\n _self.sendMessage = function (msgID, message, severity) {\r\n return _flushMessage(msgID, message, severity, true);\r\n };\r\n function _flushMessage(msgID, message, severity, saveUnsentMsg) {\r\n if (_isReady) {\r\n var isSampledIn = _canSampledIn();\r\n if (!isSampledIn) {\r\n return;\r\n }\r\n var canThrottle = _canThrottle(_config, _canUseLocalStorage, _localStorageObj);\r\n var throttled = false;\r\n var number = 0;\r\n try {\r\n if (canThrottle && !_isTriggered) {\r\n number = Math.min(_config.limit.maxSendNumber, _localStorageObj[_DYN_COUNT /* @min:%2ecount */] + 1);\r\n _localStorageObj[_DYN_COUNT /* @min:%2ecount */] = 0;\r\n throttled = true;\r\n _isTriggered = true;\r\n _localStorageObj[_DYN_PRE_TRIGGER_DATE /* @min:%2epreTriggerDate */] = new Date();\r\n }\r\n else {\r\n _isTriggered = canThrottle;\r\n _localStorageObj[_DYN_COUNT /* @min:%2ecount */] += 1;\r\n }\r\n _resetLocalStorage(_logger, _localStorageName, _localStorageObj);\r\n for (var i = 0; i < number; i++) {\r\n _sendMessage(msgID, _logger, message, severity);\r\n }\r\n }\r\n catch (e) {\r\n // eslint-disable-next-line no-empty\r\n }\r\n return {\r\n isThrottled: throttled,\r\n throttleNum: number\r\n };\r\n }\r\n else {\r\n if (!!saveUnsentMsg) {\r\n _queue.push({\r\n msgID: msgID,\r\n message: message,\r\n severity: severity\r\n });\r\n }\r\n }\r\n return null;\r\n }\r\n function _initConfig() {\r\n _logger = safeGetLogger(core);\r\n _isTriggered = false;\r\n _queue = [];\r\n _namePrefix = isNotNullOrUndefined(namePrefix) ? namePrefix : \"\";\r\n unloadHookContainer = unloadHookContainer || createUnloadHookContainer();\r\n // Make sure the root config is dynamic as it may be the global config\r\n config = createDynamicConfig(config || {}, null, _logger).cfg;\r\n var unloadHook = onConfigChange(config, function () {\r\n var _a, _b;\r\n _canUseLocalStorage = utlCanUseLocalStorage();\r\n var configMgr = config || {};\r\n _config = {};\r\n _config[_DYN_DISABLED /* @min:%2edisabled */] = !!configMgr[_DYN_DISABLED /* @min:%2edisabled */];\r\n _config.msgKey = configMgr.msgKey || 0 /* IThrottleMsgKey.default */;\r\n var configInterval = configMgr[_DYN_INTERVAL /* @min:%2einterval */] || {};\r\n _isSpecificDaysGiven = (configInterval === null || configInterval === void 0 ? void 0 : configInterval.daysOfMonth) && (configInterval === null || configInterval === void 0 ? void 0 : configInterval.daysOfMonth[_DYN_LENGTH /* @min:%2elength */]) > 0;\r\n _config[_DYN_INTERVAL /* @min:%2einterval */] = _getIntervalConfig(configInterval);\r\n var limit = {\r\n samplingRate: ((_a = configMgr.limit) === null || _a === void 0 ? void 0 : _a.samplingRate) || 100,\r\n // dafault: every time sent only 1 event\r\n maxSendNumber: ((_b = configMgr.limit) === null || _b === void 0 ? void 0 : _b.maxSendNumber) || 1\r\n };\r\n _config.limit = limit;\r\n _localStorageName = _getLocalStorageName(_config.msgKey, _namePrefix);\r\n if (_canUseLocalStorage && _localStorageName) {\r\n _localStorageObj = _getLocalStorageObj(utlGetLocalStorage(_logger, _localStorageName), _logger, _localStorageName);\r\n }\r\n if (_localStorageObj) {\r\n _isTriggered = _isTriggeredOnCurDate(_localStorageObj[_DYN_PRE_TRIGGER_DATE /* @min:%2epreTriggerDate */]);\r\n }\r\n });\r\n unloadHookContainer && unloadHookContainer.add(unloadHook);\r\n }\r\n function _getIntervalConfig(interval) {\r\n interval = interval || {};\r\n var monthInterval = interval === null || interval === void 0 ? void 0 : interval.monthInterval;\r\n var dayInterval = interval === null || interval === void 0 ? void 0 : interval.dayInterval;\r\n // default: send data every 3 month each year\r\n if (isNullOrUndefined(monthInterval) && isNullOrUndefined(dayInterval)) {\r\n interval.monthInterval = 3;\r\n if (!_isSpecificDaysGiven) {\r\n // default: send data on 28th\r\n interval[_DYN_DAYS_OF_MONTH /* @min:%2edaysOfMonth */] = [28];\r\n _isSpecificDaysGiven = true;\r\n }\r\n }\r\n interval = {\r\n // dafault: sent every three months\r\n monthInterval: interval === null || interval === void 0 ? void 0 : interval.monthInterval,\r\n dayInterval: interval === null || interval === void 0 ? void 0 : interval.dayInterval,\r\n daysOfMonth: interval === null || interval === void 0 ? void 0 : interval.daysOfMonth\r\n };\r\n return interval;\r\n }\r\n function _canThrottle(config, canUseLocalStorage, localStorageObj) {\r\n if (!config[_DYN_DISABLED /* @min:%2edisabled */] && canUseLocalStorage && isNotNullOrUndefined(localStorageObj)) {\r\n var curDate = _getThrottleDate();\r\n var date = localStorageObj[_DYN_DATE /* @min:%2edate */];\r\n var interval = config[_DYN_INTERVAL /* @min:%2einterval */];\r\n var monthCheck = 1;\r\n if (interval === null || interval === void 0 ? void 0 : interval.monthInterval) {\r\n var monthExpand = (curDate.getUTCFullYear() - date.getUTCFullYear()) * 12 + curDate.getUTCMonth() - date.getUTCMonth();\r\n monthCheck = _checkInterval(interval.monthInterval, 0, monthExpand);\r\n }\r\n var dayCheck = 1;\r\n if (_isSpecificDaysGiven) {\r\n dayCheck = arrIndexOf(interval[_DYN_DAYS_OF_MONTH /* @min:%2edaysOfMonth */], curDate[_DYN_GET_UTCDATE /* @min:%2egetUTCDate */]());\r\n }\r\n else if (interval === null || interval === void 0 ? void 0 : interval.dayInterval) {\r\n var daySpan = Math.floor((curDate.getTime() - date.getTime()) / 86400000);\r\n dayCheck = _checkInterval(interval.dayInterval, 0, daySpan);\r\n }\r\n return monthCheck >= 0 && dayCheck >= 0;\r\n }\r\n return false;\r\n }\r\n function _getLocalStorageName(msgKey, prefix) {\r\n var fix = isNotNullOrUndefined(prefix) ? prefix : \"\";\r\n if (msgKey) {\r\n return THROTTLE_STORAGE_PREFIX + fix + \"-\" + msgKey;\r\n }\r\n return null;\r\n }\r\n // returns if throttle is triggered on current Date\r\n function _isTriggeredOnCurDate(preTriggerDate) {\r\n try {\r\n if (preTriggerDate) {\r\n var curDate = new Date();\r\n return preTriggerDate.getUTCFullYear() === curDate.getUTCFullYear() &&\r\n preTriggerDate.getUTCMonth() === curDate.getUTCMonth() &&\r\n preTriggerDate[_DYN_GET_UTCDATE /* @min:%2egetUTCDate */]() === curDate[_DYN_GET_UTCDATE /* @min:%2egetUTCDate */]();\r\n }\r\n }\r\n catch (e) {\r\n // eslint-disable-next-line no-empty\r\n }\r\n return false;\r\n }\r\n // transfer local storage string value to object that identifies start date, current count and preTriggerDate\r\n function _getLocalStorageObj(value, logger, storageName) {\r\n try {\r\n var storageObj = {\r\n date: _getThrottleDate(),\r\n count: 0\r\n };\r\n if (value) {\r\n var obj = JSON.parse(value);\r\n return {\r\n date: _getThrottleDate(obj[_DYN_DATE /* @min:%2edate */]) || storageObj[_DYN_DATE /* @min:%2edate */],\r\n count: obj[_DYN_COUNT /* @min:%2ecount */] || storageObj[_DYN_COUNT /* @min:%2ecount */],\r\n preTriggerDate: obj.preTriggerDate ? _getThrottleDate(obj[_DYN_PRE_TRIGGER_DATE /* @min:%2epreTriggerDate */]) : undefined\r\n };\r\n }\r\n else {\r\n _resetLocalStorage(logger, storageName, storageObj);\r\n return storageObj;\r\n }\r\n }\r\n catch (e) {\r\n // eslint-disable-next-line no-empty\r\n }\r\n return null;\r\n }\r\n // if datestr is not defined, current date will be returned\r\n function _getThrottleDate(dateStr) {\r\n // if new Date() can't be created through the provided dateStr, null will be returned.\r\n try {\r\n if (dateStr) {\r\n var date = new Date(dateStr);\r\n //make sure it is a valid Date Object\r\n if (!isNaN(date.getDate())) {\r\n return date;\r\n }\r\n }\r\n else {\r\n return new Date();\r\n }\r\n }\r\n catch (e) {\r\n // eslint-disable-next-line no-empty\r\n }\r\n return null;\r\n }\r\n function _resetLocalStorage(logger, storageName, obj) {\r\n try {\r\n return utlSetLocalStorage(logger, storageName, strTrim(JSON[_DYN_STRINGIFY /* @min:%2estringify */](obj)));\r\n }\r\n catch (e) {\r\n // // eslint-disable-next-line no-empty\r\n }\r\n return false;\r\n }\r\n function _checkInterval(interval, start, current) {\r\n if (interval <= 0) {\r\n return 1;\r\n }\r\n // count from start year\r\n return (current >= start) && (current - start) % interval == 0 ? Math.floor((current - start) / interval) + 1 : -1;\r\n }\r\n function _sendMessage(msgID, logger, message, severity) {\r\n _throwInternal(logger, severity || 1 /* eLoggingSeverity.CRITICAL */, msgID, message);\r\n }\r\n // NOTE: config.limit.samplingRate is set to 4 decimal places,\r\n // so config.limit.samplingRate = 1 means 0.0001%\r\n function _canSampledIn() {\r\n return randomValue(1000000) <= _config.limit.samplingRate;\r\n }\r\n }\r\n return ThrottleMgr;\r\n}());\r\nexport { ThrottleMgr };\r\n//# sourceMappingURL=ThrottleMgr.js.map"],"names":[],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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":"ThrottleMgr.js.map","sources":["ThrottleMgr.js"],"sourcesContent":["import { _throwInternal, arrIndexOf, isNotNullOrUndefined, isNullOrUndefined, onConfigChange, randomValue, safeGetLogger, strTrim } from \"@microsoft/applicationinsights-core-js\";\r\nimport { arrForEach, objForEachKey } from \"@nevware21/ts-utils\";\r\nimport { utlCanUseLocalStorage, utlGetLocalStorage, utlSetLocalStorage } from \"./StorageHelperFuncs\";\r\nimport { _DYN_COUNT, _DYN_DATE, _DYN_DAYS_OF_MONTH, _DYN_DISABLED, _DYN_GET_UTCDATE, _DYN_INTERVAL, _DYN_LENGTH, _DYN_MESSAGE, _DYN_PRE_TRIGGER_DATE, _DYN_STRINGIFY } from \"./__DynamicConstants\";\r\nvar THROTTLE_STORAGE_PREFIX = \"appInsightsThrottle\";\r\nvar ThrottleMgr = /** @class */ (function () {\r\n function ThrottleMgr(core, namePrefix) {\r\n var _self = this;\r\n var _canUseLocalStorage;\r\n var _logger;\r\n var _config;\r\n var _localStorageObj;\r\n var _isTriggered; //_isTriggered is to make sure that we only trigger throttle once a day\r\n var _namePrefix;\r\n var _queue;\r\n var _isReady = false;\r\n var _isSpecificDaysGiven = false;\r\n _initConfig();\r\n // Special internal method to allow the unit tests and DebugPlugin to hook embedded objects\r\n _self[\"_getDbgPlgTargets\"] = function () {\r\n return [_queue];\r\n };\r\n _self.getConfig = function () {\r\n return _config;\r\n };\r\n /**\r\n * Check if it is the correct day to send message.\r\n * If _isTriggered is true, even if canThrottle returns true, message will not be sent,\r\n * because we only allow triggering sendMessage() once a day.\r\n * @returns if the current date is the valid date to send message\r\n */\r\n _self.canThrottle = function (msgId) {\r\n var localObj = _getLocalStorageObjByKey(msgId);\r\n return _canThrottle(_config, _canUseLocalStorage, localObj);\r\n };\r\n /**\r\n * Check if throttle is triggered on current day(UTC)\r\n * if canThrottle returns false, isTriggered will return false\r\n * @returns if throttle is triggered on current day(UTC)\r\n */\r\n _self.isTriggered = function (msgId) {\r\n return _isTrigger(msgId);\r\n };\r\n /**\r\n * Before isReady set to true, all message will be stored in queue.\r\n * Message will only be sent out after isReady set to true.\r\n * Initial and default value: false\r\n * @returns isReady state\r\n */\r\n _self.isReady = function () {\r\n return _isReady;\r\n };\r\n /**\r\n * Flush all message with given message key in queue with isReady state set to true.\r\n * @returns if message queue is flushed\r\n */\r\n _self.flush = function (msgId) {\r\n try {\r\n var queue = _getQueueByKey(msgId);\r\n if (queue && queue[_DYN_LENGTH /* @min:%2elength */] > 0) {\r\n var items = queue.slice(0);\r\n _queue[msgId] = [];\r\n arrForEach(items, function (item) {\r\n _flushMessage(item.msgID, item[_DYN_MESSAGE /* @min:%2emessage */], item.severity, false);\r\n });\r\n return true;\r\n }\r\n }\r\n catch (err) {\r\n // eslint-disable-next-line no-empty\r\n }\r\n return false;\r\n };\r\n /**\r\n * Flush all message in queue with isReady state set to true.\r\n * @returns if message queue is flushed\r\n */\r\n _self.flushAll = function () {\r\n try {\r\n if (_queue) {\r\n var result_1 = true;\r\n objForEachKey(_queue, function (key) {\r\n var isFlushed = _self.flush(parseInt(key));\r\n result_1 = result_1 && isFlushed;\r\n });\r\n return result_1;\r\n }\r\n }\r\n catch (err) {\r\n // eslint-disable-next-line no-empty\r\n }\r\n return false;\r\n };\r\n /**\r\n * Set isReady State\r\n * if isReady set to true, message queue will be flushed automatically.\r\n * @param isReady isReady State\r\n * @pa\r\n * @returns if message queue is flushed\r\n */\r\n _self.onReadyState = function (isReady, flushAll) {\r\n if (flushAll === void 0) { flushAll = true; }\r\n _isReady = isNullOrUndefined(isReady) ? true : isReady;\r\n if (_isReady && flushAll) {\r\n return _self.flushAll();\r\n }\r\n return null;\r\n };\r\n _self.sendMessage = function (msgID, message, severity) {\r\n return _flushMessage(msgID, message, severity, true);\r\n };\r\n function _flushMessage(msgID, message, severity, saveUnsentMsg) {\r\n if (_isReady) {\r\n var isSampledIn = _canSampledIn();\r\n if (!isSampledIn) {\r\n return;\r\n }\r\n var localStorageObj = _getLocalStorageObjByKey(msgID);\r\n var canThrottle = _canThrottle(_config, _canUseLocalStorage, localStorageObj);\r\n var throttled = false;\r\n var number = 0;\r\n var isTriggered = _isTrigger(msgID);\r\n try {\r\n if (canThrottle && !isTriggered) {\r\n number = Math.min(_config.limit.maxSendNumber, localStorageObj[_DYN_COUNT /* @min:%2ecount */] + 1);\r\n localStorageObj[_DYN_COUNT /* @min:%2ecount */] = 0;\r\n throttled = true;\r\n _isTriggered[msgID] = true;\r\n localStorageObj[_DYN_PRE_TRIGGER_DATE /* @min:%2epreTriggerDate */] = new Date();\r\n }\r\n else {\r\n _isTriggered[msgID] = canThrottle;\r\n localStorageObj[_DYN_COUNT /* @min:%2ecount */] += 1;\r\n }\r\n var localStorageName = _getLocalStorageName(msgID);\r\n _resetLocalStorage(_logger, localStorageName, localStorageObj);\r\n for (var i = 0; i < number; i++) {\r\n _sendMessage(msgID, _logger, message, severity);\r\n }\r\n }\r\n catch (e) {\r\n // eslint-disable-next-line no-empty\r\n }\r\n return {\r\n isThrottled: throttled,\r\n throttleNum: number\r\n };\r\n }\r\n else {\r\n if (!!saveUnsentMsg) {\r\n var queue = _getQueueByKey(msgID);\r\n queue.push({\r\n msgID: msgID,\r\n message: message,\r\n severity: severity\r\n });\r\n }\r\n }\r\n return null;\r\n }\r\n function _initConfig() {\r\n _logger = safeGetLogger(core);\r\n _isTriggered = {};\r\n _localStorageObj = {};\r\n _queue = {};\r\n _namePrefix = isNotNullOrUndefined(namePrefix) ? namePrefix : \"\";\r\n core.addUnloadHook(onConfigChange(core.config, function (details) {\r\n var _a, _b;\r\n var coreConfig = details.cfg;\r\n _canUseLocalStorage = utlCanUseLocalStorage();\r\n var configMgr = coreConfig.throttleMgrCfg || {};\r\n _config = {};\r\n _config[_DYN_DISABLED /* @min:%2edisabled */] = !!configMgr[_DYN_DISABLED /* @min:%2edisabled */];\r\n var configInterval = configMgr[_DYN_INTERVAL /* @min:%2einterval */] || {};\r\n _isSpecificDaysGiven = (configInterval === null || configInterval === void 0 ? void 0 : configInterval.daysOfMonth) && (configInterval === null || configInterval === void 0 ? void 0 : configInterval.daysOfMonth[_DYN_LENGTH /* @min:%2elength */]) > 0;\r\n _config[_DYN_INTERVAL /* @min:%2einterval */] = _getIntervalConfig(configInterval);\r\n var limit = {\r\n samplingRate: ((_a = configMgr.limit) === null || _a === void 0 ? void 0 : _a.samplingRate) || 100,\r\n // dafault: every time sent only 1 event\r\n maxSendNumber: ((_b = configMgr.limit) === null || _b === void 0 ? void 0 : _b.maxSendNumber) || 1\r\n };\r\n _config.limit = limit;\r\n }));\r\n }\r\n function _getIntervalConfig(interval) {\r\n interval = interval || {};\r\n var monthInterval = interval === null || interval === void 0 ? void 0 : interval.monthInterval;\r\n var dayInterval = interval === null || interval === void 0 ? void 0 : interval.dayInterval;\r\n // default: send data every 3 month each year\r\n if (isNullOrUndefined(monthInterval) && isNullOrUndefined(dayInterval)) {\r\n interval.monthInterval = 3;\r\n if (!_isSpecificDaysGiven) {\r\n // default: send data on 28th\r\n interval[_DYN_DAYS_OF_MONTH /* @min:%2edaysOfMonth */] = [28];\r\n _isSpecificDaysGiven = true;\r\n }\r\n }\r\n interval = {\r\n // dafault: sent every three months\r\n monthInterval: interval === null || interval === void 0 ? void 0 : interval.monthInterval,\r\n dayInterval: interval === null || interval === void 0 ? void 0 : interval.dayInterval,\r\n daysOfMonth: interval === null || interval === void 0 ? void 0 : interval.daysOfMonth\r\n };\r\n return interval;\r\n }\r\n function _canThrottle(config, canUseLocalStorage, localStorageObj) {\r\n if (!config[_DYN_DISABLED /* @min:%2edisabled */] && canUseLocalStorage && isNotNullOrUndefined(localStorageObj)) {\r\n var curDate = _getThrottleDate();\r\n var date = localStorageObj[_DYN_DATE /* @min:%2edate */];\r\n var interval = config[_DYN_INTERVAL /* @min:%2einterval */];\r\n var monthCheck = 1;\r\n if (interval === null || interval === void 0 ? void 0 : interval.monthInterval) {\r\n var monthExpand = (curDate.getUTCFullYear() - date.getUTCFullYear()) * 12 + curDate.getUTCMonth() - date.getUTCMonth();\r\n monthCheck = _checkInterval(interval.monthInterval, 0, monthExpand);\r\n }\r\n var dayCheck = 1;\r\n if (_isSpecificDaysGiven) {\r\n dayCheck = arrIndexOf(interval[_DYN_DAYS_OF_MONTH /* @min:%2edaysOfMonth */], curDate[_DYN_GET_UTCDATE /* @min:%2egetUTCDate */]());\r\n }\r\n else if (interval === null || interval === void 0 ? void 0 : interval.dayInterval) {\r\n var daySpan = Math.floor((curDate.getTime() - date.getTime()) / 86400000);\r\n dayCheck = _checkInterval(interval.dayInterval, 0, daySpan);\r\n }\r\n return monthCheck >= 0 && dayCheck >= 0;\r\n }\r\n return false;\r\n }\r\n function _getLocalStorageName(msgKey, prefix) {\r\n var fix = isNotNullOrUndefined(prefix) ? prefix : \"\";\r\n if (msgKey) {\r\n return THROTTLE_STORAGE_PREFIX + fix + \"-\" + msgKey;\r\n }\r\n return null;\r\n }\r\n // returns if throttle is triggered on current Date\r\n function _isTriggeredOnCurDate(preTriggerDate) {\r\n try {\r\n if (preTriggerDate) {\r\n var curDate = new Date();\r\n return preTriggerDate.getUTCFullYear() === curDate.getUTCFullYear() &&\r\n preTriggerDate.getUTCMonth() === curDate.getUTCMonth() &&\r\n preTriggerDate[_DYN_GET_UTCDATE /* @min:%2egetUTCDate */]() === curDate[_DYN_GET_UTCDATE /* @min:%2egetUTCDate */]();\r\n }\r\n }\r\n catch (e) {\r\n // eslint-disable-next-line no-empty\r\n }\r\n return false;\r\n }\r\n // transfer local storage string value to object that identifies start date, current count and preTriggerDate\r\n function _getLocalStorageObj(value, logger, storageName) {\r\n try {\r\n var storageObj = {\r\n date: _getThrottleDate(),\r\n count: 0\r\n };\r\n if (value) {\r\n var obj = JSON.parse(value);\r\n var curObj = {\r\n date: _getThrottleDate(obj[_DYN_DATE /* @min:%2edate */]) || storageObj[_DYN_DATE /* @min:%2edate */],\r\n count: obj[_DYN_COUNT /* @min:%2ecount */] || storageObj[_DYN_COUNT /* @min:%2ecount */],\r\n preTriggerDate: obj.preTriggerDate ? _getThrottleDate(obj[_DYN_PRE_TRIGGER_DATE /* @min:%2epreTriggerDate */]) : undefined\r\n };\r\n return curObj;\r\n }\r\n else {\r\n _resetLocalStorage(logger, storageName, storageObj);\r\n return storageObj;\r\n }\r\n }\r\n catch (e) {\r\n // eslint-disable-next-line no-empty\r\n }\r\n return null;\r\n }\r\n // if datestr is not defined, current date will be returned\r\n function _getThrottleDate(dateStr) {\r\n // if new Date() can't be created through the provided dateStr, null will be returned.\r\n try {\r\n if (dateStr) {\r\n var date = new Date(dateStr);\r\n //make sure it is a valid Date Object\r\n if (!isNaN(date.getDate())) {\r\n return date;\r\n }\r\n }\r\n else {\r\n return new Date();\r\n }\r\n }\r\n catch (e) {\r\n // eslint-disable-next-line no-empty\r\n }\r\n return null;\r\n }\r\n function _resetLocalStorage(logger, storageName, obj) {\r\n try {\r\n return utlSetLocalStorage(logger, storageName, strTrim(JSON[_DYN_STRINGIFY /* @min:%2estringify */](obj)));\r\n }\r\n catch (e) {\r\n // // eslint-disable-next-line no-empty\r\n }\r\n return false;\r\n }\r\n function _checkInterval(interval, start, current) {\r\n if (interval <= 0) {\r\n return 1;\r\n }\r\n // count from start year\r\n return (current >= start) && (current - start) % interval == 0 ? Math.floor((current - start) / interval) + 1 : -1;\r\n }\r\n function _sendMessage(msgID, logger, message, severity) {\r\n _throwInternal(logger, severity || 1 /* eLoggingSeverity.CRITICAL */, msgID, message);\r\n }\r\n // NOTE: config.limit.samplingRate is set to 4 decimal places,\r\n // so config.limit.samplingRate = 1 means 0.0001%\r\n function _canSampledIn() {\r\n return randomValue(1000000) <= _config.limit.samplingRate;\r\n }\r\n function _getLocalStorageObjByKey(key) {\r\n try {\r\n var curObj = _localStorageObj[key];\r\n if (!curObj) {\r\n var localStorageName = _getLocalStorageName(key, _namePrefix);\r\n curObj = _getLocalStorageObj(utlGetLocalStorage(_logger, localStorageName), _logger, localStorageName);\r\n _localStorageObj[key] = curObj;\r\n }\r\n return _localStorageObj[key];\r\n }\r\n catch (e) {\r\n // eslint-disable-next-line no-empty\r\n }\r\n return null;\r\n }\r\n function _isTrigger(key) {\r\n var isTrigger = _isTriggered[key];\r\n if (isNullOrUndefined(isTrigger)) {\r\n isTrigger = false;\r\n var localStorageObj = _getLocalStorageObjByKey(key);\r\n if (localStorageObj) {\r\n isTrigger = _isTriggeredOnCurDate(localStorageObj[_DYN_PRE_TRIGGER_DATE /* @min:%2epreTriggerDate */]);\r\n }\r\n _isTriggered[key] = isTrigger;\r\n }\r\n return _isTriggered[key];\r\n }\r\n function _getQueueByKey(key) {\r\n _queue = _queue || {};\r\n if (isNullOrUndefined(_queue[key])) {\r\n _queue[key] = [];\r\n }\r\n return _queue[key];\r\n }\r\n }\r\n return ThrottleMgr;\r\n}());\r\nexport { ThrottleMgr };\r\n//# sourceMappingURL=ThrottleMgr.js.map"],"names":[],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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 - Common, 3.0.3-nightly3.2308-06
2
+ * Application Insights JavaScript SDK - Common, 3.0.3-nightly3.2308-07
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
package/dist-es5/Util.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Common, 3.0.3-nightly3.2308-06
2
+ * Application Insights JavaScript SDK - Common, 3.0.3-nightly3.2308-07
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 - Common, 3.0.3-nightly3.2308-06
2
+ * Application Insights JavaScript SDK - Common, 3.0.3-nightly3.2308-07
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 - Common, 3.0.3-nightly3.2308-06
2
+ * Application Insights JavaScript SDK - Common, 3.0.3-nightly3.2308-07
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microsoft/applicationinsights-common",
3
- "version": "3.0.3-nightly3.2308-06",
3
+ "version": "3.0.3-nightly3.2308-07",
4
4
  "description": "Microsoft Application Insights Common JavaScript Library",
5
5
  "homepage": "https://github.com/microsoft/ApplicationInsights-JS#readme",
6
6
  "author": "Microsoft Application Insights Team",
@@ -53,7 +53,7 @@
53
53
  },
54
54
  "dependencies": {
55
55
  "@microsoft/applicationinsights-shims": "3.0.1",
56
- "@microsoft/applicationinsights-core-js": "3.0.3-nightly3.2308-06",
56
+ "@microsoft/applicationinsights-core-js": "3.0.3-nightly3.2308-07",
57
57
  "@microsoft/dynamicproto-js": "^2.0.2",
58
58
  "@nevware21/ts-utils": ">= 0.9.6 < 2.x"
59
59
  },
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Microsoft Application Insights Common JavaScript Library, 3.0.3-nightly3.2308-06
2
+ * Microsoft Application Insights Common JavaScript Library, 3.0.3-nightly3.2308-07
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  *
5
5
  * Microsoft Application Insights Team
@@ -32,7 +32,6 @@ import { isValidTraceId } from '@microsoft/applicationinsights-core-js';
32
32
  import { isValidTraceParent } from '@microsoft/applicationinsights-core-js';
33
33
  import { ITelemetryItem } from '@microsoft/applicationinsights-core-js';
34
34
  import { ITraceParent } from '@microsoft/applicationinsights-core-js';
35
- import { IUnloadHookContainer } from '@microsoft/applicationinsights-core-js';
36
35
  import { parseTraceParent } from '@microsoft/applicationinsights-core-js';
37
36
 
38
37
  /**
@@ -892,6 +891,10 @@ export declare interface IConfig {
892
891
  * should not be excluded.
893
892
  */
894
893
  addIntEndpoints?: boolean;
894
+ /**
895
+ * [Optional] set throttle mgr configuration
896
+ */
897
+ throttleMgrCfg?: IThrottleMgrConfig;
895
898
  }
896
899
 
897
900
  export declare interface IContextTagKeys {
@@ -2049,11 +2052,6 @@ export declare interface IThrottleLocalStorageObj {
2049
2052
  * Identifies basic config
2050
2053
  */
2051
2054
  export declare interface IThrottleMgrConfig {
2052
- /**
2053
- * Identifies message key to be used for local storage key
2054
- * Default: IThrottleMsgKey.default
2055
- */
2056
- msgKey?: IThrottleMsgKey;
2057
2055
  /**
2058
2056
  * Identifies if throttle is disabled
2059
2057
  * Default: false
@@ -2071,21 +2069,6 @@ export declare interface IThrottleMgrConfig {
2071
2069
  interval?: IThrottleInterval;
2072
2070
  }
2073
2071
 
2074
- export declare const enum IThrottleMsgKey {
2075
- /**
2076
- * Default Message key for non pre-defined message
2077
- */
2078
- default = 0,
2079
- /**
2080
- * Message key for ikey Deprecation
2081
- */
2082
- ikeyDeprecate = 1,
2083
- /**
2084
- * Message key for cdn Deprecation
2085
- */
2086
- cdnDeprecate = 2
2087
- }
2088
-
2089
2072
  /**
2090
2073
  * Identifies throttle result
2091
2074
  */
@@ -2490,15 +2473,16 @@ export declare class TelemetryItemCreator {
2490
2473
  }
2491
2474
 
2492
2475
  export declare class ThrottleMgr {
2493
- canThrottle: () => boolean;
2494
- sendMessage: (msgID: _eInternalMessageId, message: string, severity?: eLoggingSeverity) => IThrottleResult | null;
2476
+ canThrottle: (msgId: _eInternalMessageId | number) => boolean;
2477
+ sendMessage: (msgId: _eInternalMessageId, message: string, severity?: eLoggingSeverity) => IThrottleResult | null;
2495
2478
  getConfig: () => IThrottleMgrConfig;
2496
- isTriggered: () => boolean;
2479
+ isTriggered: (msgId: _eInternalMessageId | number) => boolean;
2497
2480
  isReady: () => boolean;
2498
- onReadyState: (isReady?: boolean) => boolean;
2499
- flush: () => boolean;
2481
+ onReadyState: (isReady?: boolean, flushAll?: boolean) => boolean;
2482
+ flush: (msgId: _eInternalMessageId | number) => boolean;
2483
+ flushAll: () => boolean;
2500
2484
  config: IThrottleMgrConfig;
2501
- constructor(config?: IThrottleMgrConfig, core?: IAppInsightsCore, namePrefix?: string, unloadHookContainer?: IUnloadHookContainer);
2485
+ constructor(core: IAppInsightsCore, namePrefix?: string);
2502
2486
  }
2503
2487
 
2504
2488
  export declare class Trace implements IMessageData, ISerializable {
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Microsoft Application Insights Common JavaScript Library, 3.0.3-nightly3.2308-06
2
+ * Microsoft Application Insights Common JavaScript Library, 3.0.3-nightly3.2308-07
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  *
5
5
  * Microsoft Application Insights Team
@@ -27,7 +27,6 @@ declare namespace ApplicationInsights {
27
27
  import { isValidTraceParent } from '@microsoft/applicationinsights-core-js';
28
28
  import { ITelemetryItem } from '@microsoft/applicationinsights-core-js';
29
29
  import { ITraceParent } from '@microsoft/applicationinsights-core-js';
30
- import { IUnloadHookContainer } from '@microsoft/applicationinsights-core-js';
31
30
  import { parseTraceParent } from '@microsoft/applicationinsights-core-js';
32
31
 
33
32
  /**
@@ -887,6 +886,10 @@ declare namespace ApplicationInsights {
887
886
  * should not be excluded.
888
887
  */
889
888
  addIntEndpoints?: boolean;
889
+ /**
890
+ * [Optional] set throttle mgr configuration
891
+ */
892
+ throttleMgrCfg?: IThrottleMgrConfig;
890
893
  }
891
894
 
892
895
  interface IContextTagKeys {
@@ -2044,11 +2047,6 @@ declare namespace ApplicationInsights {
2044
2047
  * Identifies basic config
2045
2048
  */
2046
2049
  interface IThrottleMgrConfig {
2047
- /**
2048
- * Identifies message key to be used for local storage key
2049
- * Default: IThrottleMsgKey.default
2050
- */
2051
- msgKey?: IThrottleMsgKey;
2052
2050
  /**
2053
2051
  * Identifies if throttle is disabled
2054
2052
  * Default: false
@@ -2066,21 +2064,6 @@ declare namespace ApplicationInsights {
2066
2064
  interval?: IThrottleInterval;
2067
2065
  }
2068
2066
 
2069
- const enum IThrottleMsgKey {
2070
- /**
2071
- * Default Message key for non pre-defined message
2072
- */
2073
- default = 0,
2074
- /**
2075
- * Message key for ikey Deprecation
2076
- */
2077
- ikeyDeprecate = 1,
2078
- /**
2079
- * Message key for cdn Deprecation
2080
- */
2081
- cdnDeprecate = 2
2082
- }
2083
-
2084
2067
  /**
2085
2068
  * Identifies throttle result
2086
2069
  */
@@ -2485,15 +2468,16 @@ declare namespace ApplicationInsights {
2485
2468
  }
2486
2469
 
2487
2470
  class ThrottleMgr {
2488
- canThrottle: () => boolean;
2489
- sendMessage: (msgID: _eInternalMessageId, message: string, severity?: eLoggingSeverity) => IThrottleResult | null;
2471
+ canThrottle: (msgId: _eInternalMessageId | number) => boolean;
2472
+ sendMessage: (msgId: _eInternalMessageId, message: string, severity?: eLoggingSeverity) => IThrottleResult | null;
2490
2473
  getConfig: () => IThrottleMgrConfig;
2491
- isTriggered: () => boolean;
2474
+ isTriggered: (msgId: _eInternalMessageId | number) => boolean;
2492
2475
  isReady: () => boolean;
2493
- onReadyState: (isReady?: boolean) => boolean;
2494
- flush: () => boolean;
2476
+ onReadyState: (isReady?: boolean, flushAll?: boolean) => boolean;
2477
+ flush: (msgId: _eInternalMessageId | number) => boolean;
2478
+ flushAll: () => boolean;
2495
2479
  config: IThrottleMgrConfig;
2496
- constructor(config?: IThrottleMgrConfig, core?: IAppInsightsCore, namePrefix?: string, unloadHookContainer?: IUnloadHookContainer);
2480
+ constructor(core: IAppInsightsCore, namePrefix?: string);
2497
2481
  }
2498
2482
 
2499
2483
  class Trace implements IMessageData, ISerializable {