@microsoft/applicationinsights-common 3.3.12-nightly3.2602-20 → 3.4.0-beta

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 (175) hide show
  1. package/README.md +21 -2
  2. package/browser/es5/applicationinsights-common.cjs.js +1089 -289
  3. package/browser/es5/applicationinsights-common.cjs.js.map +1 -1
  4. package/browser/es5/applicationinsights-common.cjs.min.js +2 -2
  5. package/browser/es5/applicationinsights-common.cjs.min.js.map +1 -1
  6. package/browser/es5/applicationinsights-common.gbl.js +1091 -291
  7. package/browser/es5/applicationinsights-common.gbl.js.map +1 -1
  8. package/browser/es5/applicationinsights-common.gbl.min.js +2 -2
  9. package/browser/es5/applicationinsights-common.gbl.min.js.map +1 -1
  10. package/browser/es5/applicationinsights-common.integrity.json +25 -25
  11. package/browser/es5/applicationinsights-common.js +1091 -291
  12. package/browser/es5/applicationinsights-common.js.map +1 -1
  13. package/browser/es5/applicationinsights-common.min.js +2 -2
  14. package/browser/es5/applicationinsights-common.min.js.map +1 -1
  15. package/dist/es5/applicationinsights-common.js +1089 -289
  16. package/dist/es5/applicationinsights-common.js.map +1 -1
  17. package/dist/es5/applicationinsights-common.min.js +2 -2
  18. package/dist/es5/applicationinsights-common.min.js.map +1 -1
  19. package/dist-es5/applicationinsights-common.js +42 -32
  20. package/dist-es5/applicationinsights-common.js.map +1 -1
  21. package/package.json +65 -66
  22. package/types/applicationinsights-common.d.ts +408 -2574
  23. package/types/applicationinsights-common.namespaced.d.ts +2385 -89
  24. package/dist-es5/ConnectionStringParser.js +0 -44
  25. package/dist-es5/ConnectionStringParser.js.map +0 -1
  26. package/dist-es5/Constants.js +0 -22
  27. package/dist-es5/Constants.js.map +0 -1
  28. package/dist-es5/DomHelperFuncs.js +0 -22
  29. package/dist-es5/DomHelperFuncs.js.map +0 -1
  30. package/dist-es5/Enums.js +0 -30
  31. package/dist-es5/Enums.js.map +0 -1
  32. package/dist-es5/HelperFuncs.js +0 -50
  33. package/dist-es5/HelperFuncs.js.map +0 -1
  34. package/dist-es5/Interfaces/ConnectionString.js +0 -6
  35. package/dist-es5/Interfaces/ConnectionString.js.map +0 -1
  36. package/dist-es5/Interfaces/Context/IApplication.js +0 -8
  37. package/dist-es5/Interfaces/Context/IApplication.js.map +0 -1
  38. package/dist-es5/Interfaces/Context/IDevice.js +0 -8
  39. package/dist-es5/Interfaces/Context/IDevice.js.map +0 -1
  40. package/dist-es5/Interfaces/Context/IInternal.js +0 -8
  41. package/dist-es5/Interfaces/Context/IInternal.js.map +0 -1
  42. package/dist-es5/Interfaces/Context/ILocation.js +0 -8
  43. package/dist-es5/Interfaces/Context/ILocation.js.map +0 -1
  44. package/dist-es5/Interfaces/Context/IOperatingSystem.js +0 -8
  45. package/dist-es5/Interfaces/Context/IOperatingSystem.js.map +0 -1
  46. package/dist-es5/Interfaces/Context/ISample.js +0 -8
  47. package/dist-es5/Interfaces/Context/ISample.js.map +0 -1
  48. package/dist-es5/Interfaces/Context/ISession.js +0 -8
  49. package/dist-es5/Interfaces/Context/ISession.js.map +0 -1
  50. package/dist-es5/Interfaces/Context/ISessionManager.js +0 -8
  51. package/dist-es5/Interfaces/Context/ISessionManager.js.map +0 -1
  52. package/dist-es5/Interfaces/Context/ITelemetryTrace.js +0 -8
  53. package/dist-es5/Interfaces/Context/ITelemetryTrace.js.map +0 -1
  54. package/dist-es5/Interfaces/Context/IUser.js +0 -8
  55. package/dist-es5/Interfaces/Context/IUser.js.map +0 -1
  56. package/dist-es5/Interfaces/Context/IWeb.js +0 -8
  57. package/dist-es5/Interfaces/Context/IWeb.js.map +0 -1
  58. package/dist-es5/Interfaces/Contracts/AvailabilityData.js +0 -52
  59. package/dist-es5/Interfaces/Contracts/AvailabilityData.js.map +0 -1
  60. package/dist-es5/Interfaces/Contracts/ContextTagKeys.js +0 -89
  61. package/dist-es5/Interfaces/Contracts/ContextTagKeys.js.map +0 -1
  62. package/dist-es5/Interfaces/Contracts/DataPointType.js +0 -8
  63. package/dist-es5/Interfaces/Contracts/DataPointType.js.map +0 -1
  64. package/dist-es5/Interfaces/Contracts/DependencyKind.js +0 -8
  65. package/dist-es5/Interfaces/Contracts/DependencyKind.js.map +0 -1
  66. package/dist-es5/Interfaces/Contracts/DependencySourceType.js +0 -8
  67. package/dist-es5/Interfaces/Contracts/DependencySourceType.js.map +0 -1
  68. package/dist-es5/Interfaces/Contracts/IBase.js +0 -8
  69. package/dist-es5/Interfaces/Contracts/IBase.js.map +0 -1
  70. package/dist-es5/Interfaces/Contracts/IData.js +0 -8
  71. package/dist-es5/Interfaces/Contracts/IData.js.map +0 -1
  72. package/dist-es5/Interfaces/Contracts/IDataPoint.js +0 -6
  73. package/dist-es5/Interfaces/Contracts/IDataPoint.js.map +0 -1
  74. package/dist-es5/Interfaces/Contracts/IDomain.js +0 -8
  75. package/dist-es5/Interfaces/Contracts/IDomain.js.map +0 -1
  76. package/dist-es5/Interfaces/Contracts/IEnvelope.js +0 -46
  77. package/dist-es5/Interfaces/Contracts/IEnvelope.js.map +0 -1
  78. package/dist-es5/Interfaces/Contracts/IEventData.js +0 -8
  79. package/dist-es5/Interfaces/Contracts/IEventData.js.map +0 -1
  80. package/dist-es5/Interfaces/Contracts/IExceptionData.js +0 -8
  81. package/dist-es5/Interfaces/Contracts/IExceptionData.js.map +0 -1
  82. package/dist-es5/Interfaces/Contracts/IExceptionDetails.js +0 -8
  83. package/dist-es5/Interfaces/Contracts/IExceptionDetails.js.map +0 -1
  84. package/dist-es5/Interfaces/Contracts/IMessageData.js +0 -8
  85. package/dist-es5/Interfaces/Contracts/IMessageData.js.map +0 -1
  86. package/dist-es5/Interfaces/Contracts/IMetricData.js +0 -8
  87. package/dist-es5/Interfaces/Contracts/IMetricData.js.map +0 -1
  88. package/dist-es5/Interfaces/Contracts/IPageViewData.js +0 -8
  89. package/dist-es5/Interfaces/Contracts/IPageViewData.js.map +0 -1
  90. package/dist-es5/Interfaces/Contracts/IPageViewPerfData.js +0 -8
  91. package/dist-es5/Interfaces/Contracts/IPageViewPerfData.js.map +0 -1
  92. package/dist-es5/Interfaces/Contracts/IRemoteDependencyData.js +0 -8
  93. package/dist-es5/Interfaces/Contracts/IRemoteDependencyData.js.map +0 -1
  94. package/dist-es5/Interfaces/Contracts/IStackFrame.js +0 -8
  95. package/dist-es5/Interfaces/Contracts/IStackFrame.js.map +0 -1
  96. package/dist-es5/Interfaces/Contracts/RequestData.js +0 -46
  97. package/dist-es5/Interfaces/Contracts/RequestData.js.map +0 -1
  98. package/dist-es5/Interfaces/Contracts/SeverityLevel.js +0 -18
  99. package/dist-es5/Interfaces/Contracts/SeverityLevel.js.map +0 -1
  100. package/dist-es5/Interfaces/IAppInsights.js +0 -8
  101. package/dist-es5/Interfaces/IAppInsights.js.map +0 -1
  102. package/dist-es5/Interfaces/IConfig.js +0 -26
  103. package/dist-es5/Interfaces/IConfig.js.map +0 -1
  104. package/dist-es5/Interfaces/ICorrelationConfig.js +0 -8
  105. package/dist-es5/Interfaces/ICorrelationConfig.js.map +0 -1
  106. package/dist-es5/Interfaces/IDependencyTelemetry.js +0 -8
  107. package/dist-es5/Interfaces/IDependencyTelemetry.js.map +0 -1
  108. package/dist-es5/Interfaces/IEventTelemetry.js +0 -6
  109. package/dist-es5/Interfaces/IEventTelemetry.js.map +0 -1
  110. package/dist-es5/Interfaces/IExceptionTelemetry.js +0 -8
  111. package/dist-es5/Interfaces/IExceptionTelemetry.js.map +0 -1
  112. package/dist-es5/Interfaces/IMetricTelemetry.js +0 -6
  113. package/dist-es5/Interfaces/IMetricTelemetry.js.map +0 -1
  114. package/dist-es5/Interfaces/IPageViewPerformanceTelemetry.js +0 -6
  115. package/dist-es5/Interfaces/IPageViewPerformanceTelemetry.js.map +0 -1
  116. package/dist-es5/Interfaces/IPageViewTelemetry.js +0 -6
  117. package/dist-es5/Interfaces/IPageViewTelemetry.js.map +0 -1
  118. package/dist-es5/Interfaces/IPartC.js +0 -8
  119. package/dist-es5/Interfaces/IPartC.js.map +0 -1
  120. package/dist-es5/Interfaces/IPropertiesPlugin.js +0 -8
  121. package/dist-es5/Interfaces/IPropertiesPlugin.js.map +0 -1
  122. package/dist-es5/Interfaces/IRequestContext.js +0 -6
  123. package/dist-es5/Interfaces/IRequestContext.js.map +0 -1
  124. package/dist-es5/Interfaces/IStorageBuffer.js +0 -6
  125. package/dist-es5/Interfaces/IStorageBuffer.js.map +0 -1
  126. package/dist-es5/Interfaces/ITelemetryContext.js +0 -8
  127. package/dist-es5/Interfaces/ITelemetryContext.js.map +0 -1
  128. package/dist-es5/Interfaces/IThrottleMgr.js +0 -6
  129. package/dist-es5/Interfaces/IThrottleMgr.js.map +0 -1
  130. package/dist-es5/Interfaces/ITraceTelemetry.js +0 -8
  131. package/dist-es5/Interfaces/ITraceTelemetry.js.map +0 -1
  132. package/dist-es5/Interfaces/PartAExtensions.js +0 -17
  133. package/dist-es5/Interfaces/PartAExtensions.js.map +0 -1
  134. package/dist-es5/Interfaces/Telemetry/IEnvelope.js +0 -8
  135. package/dist-es5/Interfaces/Telemetry/IEnvelope.js.map +0 -1
  136. package/dist-es5/Interfaces/Telemetry/ISerializable.js +0 -8
  137. package/dist-es5/Interfaces/Telemetry/ISerializable.js.map +0 -1
  138. package/dist-es5/Offline.js +0 -137
  139. package/dist-es5/Offline.js.map +0 -1
  140. package/dist-es5/RequestResponseHeaders.js +0 -19
  141. package/dist-es5/RequestResponseHeaders.js.map +0 -1
  142. package/dist-es5/StorageHelperFuncs.js +0 -184
  143. package/dist-es5/StorageHelperFuncs.js.map +0 -1
  144. package/dist-es5/Telemetry/Common/Data.js +0 -25
  145. package/dist-es5/Telemetry/Common/Data.js.map +0 -1
  146. package/dist-es5/Telemetry/Common/DataPoint.js +0 -29
  147. package/dist-es5/Telemetry/Common/DataPoint.js.map +0 -1
  148. package/dist-es5/Telemetry/Common/DataSanitizer.js +0 -129
  149. package/dist-es5/Telemetry/Common/DataSanitizer.js.map +0 -1
  150. package/dist-es5/Telemetry/Common/Envelope.js +0 -38
  151. package/dist-es5/Telemetry/Common/Envelope.js.map +0 -1
  152. package/dist-es5/Telemetry/Event.js +0 -32
  153. package/dist-es5/Telemetry/Event.js.map +0 -1
  154. package/dist-es5/Telemetry/Exception.js +0 -759
  155. package/dist-es5/Telemetry/Exception.js.map +0 -1
  156. package/dist-es5/Telemetry/Metric.js +0 -39
  157. package/dist-es5/Telemetry/Metric.js.map +0 -1
  158. package/dist-es5/Telemetry/PageView.js +0 -41
  159. package/dist-es5/Telemetry/PageView.js.map +0 -1
  160. package/dist-es5/Telemetry/PageViewPerformance.js +0 -48
  161. package/dist-es5/Telemetry/PageViewPerformance.js.map +0 -1
  162. package/dist-es5/Telemetry/RemoteDependencyData.js +0 -62
  163. package/dist-es5/Telemetry/RemoteDependencyData.js.map +0 -1
  164. package/dist-es5/Telemetry/Trace.js +0 -36
  165. package/dist-es5/Telemetry/Trace.js.map +0 -1
  166. package/dist-es5/TelemetryItemCreator.js +0 -65
  167. package/dist-es5/TelemetryItemCreator.js.map +0 -1
  168. package/dist-es5/ThrottleMgr.js +0 -388
  169. package/dist-es5/ThrottleMgr.js.map +0 -1
  170. package/dist-es5/UrlHelperFuncs.js +0 -90
  171. package/dist-es5/UrlHelperFuncs.js.map +0 -1
  172. package/dist-es5/Util.js +0 -198
  173. package/dist-es5/Util.js.map +0 -1
  174. package/dist-es5/__DynamicConstants.js +0 -44
  175. package/dist-es5/__DynamicConstants.js.map +0 -1
@@ -1,388 +0,0 @@
1
- /*
2
- * Application Insights JavaScript SDK - Common, 3.3.12-nightly3.2602-20
3
- * Copyright (c) Microsoft and contributors. All rights reserved.
4
- */
5
- import { _throwInternal, arrIndexOf, isNotNullOrUndefined, isNullOrUndefined, onConfigChange, randomValue, safeGetLogger, strTrim } from "@microsoft/applicationinsights-core-js";
6
- import { arrForEach, mathFloor, mathMin, objForEachKey } from "@nevware21/ts-utils";
7
- import { utlCanUseLocalStorage, utlGetLocalStorage, utlSetLocalStorage } from "./StorageHelperFuncs";
8
- import { _DYN_COUNT, _DYN_GET_UTCDATE, _DYN_LENGTH, _DYN_MESSAGE, _DYN_PRE_TRIGGER_DATE, _DYN_STRINGIFY } from "./__DynamicConstants";
9
- var THROTTLE_STORAGE_PREFIX = "appInsightsThrottle";
10
- var ThrottleMgr = /** @class */ (function () {
11
- function ThrottleMgr(core, namePrefix) {
12
- var _self = this;
13
- var _canUseLocalStorage;
14
- var _logger;
15
- var _config;
16
- var _localStorageObj;
17
- var _isTriggered; //_isTriggered is to make sure that we only trigger throttle once a day
18
- var _namePrefix;
19
- var _queue;
20
- var _isReady = false;
21
- var _isSpecificDaysGiven = false;
22
- _initConfig();
23
- // Special internal method to allow the unit tests and DebugPlugin to hook embedded objects
24
- _self["_getDbgPlgTargets"] = function () {
25
- return [_queue];
26
- };
27
- _self.getConfig = function () {
28
- return _config;
29
- };
30
- /**
31
- * Check if it is the correct day to send message.
32
- * If _isTriggered is true, even if canThrottle returns true, message will not be sent,
33
- * because we only allow triggering sendMessage() once a day.
34
- * @returns if the current date is the valid date to send message
35
- */
36
- _self.canThrottle = function (msgId) {
37
- var localObj = _getLocalStorageObjByKey(msgId);
38
- var cfg = _getCfgByKey(msgId);
39
- return _canThrottle(cfg, _canUseLocalStorage, localObj);
40
- };
41
- /**
42
- * Check if throttle is triggered on current day(UTC)
43
- * if canThrottle returns false, isTriggered will return false
44
- * @returns if throttle is triggered on current day(UTC)
45
- */
46
- _self.isTriggered = function (msgId) {
47
- return _isTrigger(msgId);
48
- };
49
- /**
50
- * Before isReady set to true, all message will be stored in queue.
51
- * Message will only be sent out after isReady set to true.
52
- * Initial and default value: false
53
- * @returns isReady state
54
- */
55
- _self.isReady = function () {
56
- return _isReady;
57
- };
58
- /**
59
- * Flush all message with given message key in queue with isReady state set to true.
60
- * @returns if message queue is flushed
61
- */
62
- _self.flush = function (msgId) {
63
- try {
64
- var queue = _getQueueByKey(msgId);
65
- if (queue && queue[_DYN_LENGTH /* @min:%2elength */] > 0) {
66
- var items = queue.slice(0);
67
- _queue[msgId] = [];
68
- arrForEach(items, function (item) {
69
- _flushMessage(item.msgID, item[_DYN_MESSAGE /* @min:%2emessage */], item.severity, false);
70
- });
71
- return true;
72
- }
73
- }
74
- catch (err) {
75
- // eslint-disable-next-line no-empty
76
- }
77
- return false;
78
- };
79
- /**
80
- * Flush all message in queue with isReady state set to true.
81
- * @returns if message queue is flushed
82
- */
83
- _self.flushAll = function () {
84
- try {
85
- if (_queue) {
86
- var result_1 = true;
87
- objForEachKey(_queue, function (key) {
88
- var isFlushed = _self.flush(parseInt(key));
89
- result_1 = result_1 && isFlushed;
90
- });
91
- return result_1;
92
- }
93
- }
94
- catch (err) {
95
- // eslint-disable-next-line no-empty
96
- }
97
- return false;
98
- };
99
- /**
100
- * Set isReady State
101
- * if isReady set to true, message queue will be flushed automatically.
102
- * @param isReady - isReady State
103
- * @pa
104
- * @returns if message queue is flushed
105
- */
106
- _self.onReadyState = function (isReady, flushAll) {
107
- if (flushAll === void 0) { flushAll = true; }
108
- _isReady = isNullOrUndefined(isReady) ? true : isReady;
109
- if (_isReady && flushAll) {
110
- return _self.flushAll();
111
- }
112
- return null;
113
- };
114
- _self.sendMessage = function (msgID, message, severity) {
115
- return _flushMessage(msgID, message, severity, true);
116
- };
117
- function _flushMessage(msgID, message, severity, saveUnsentMsg) {
118
- if (_isReady) {
119
- var isSampledIn = _canSampledIn(msgID);
120
- if (!isSampledIn) {
121
- return;
122
- }
123
- var cfg = _getCfgByKey(msgID);
124
- var localStorageObj = _getLocalStorageObjByKey(msgID);
125
- var canThrottle = _canThrottle(cfg, _canUseLocalStorage, localStorageObj);
126
- var throttled = false;
127
- var number = 0;
128
- var isTriggered = _isTrigger(msgID);
129
- try {
130
- if (canThrottle && !isTriggered) {
131
- number = mathMin(cfg.limit.maxSendNumber, localStorageObj[_DYN_COUNT /* @min:%2ecount */] + 1);
132
- localStorageObj[_DYN_COUNT /* @min:%2ecount */] = 0;
133
- throttled = true;
134
- _isTriggered[msgID] = true;
135
- localStorageObj[_DYN_PRE_TRIGGER_DATE /* @min:%2epreTriggerDate */] = new Date();
136
- }
137
- else {
138
- _isTriggered[msgID] = canThrottle;
139
- localStorageObj[_DYN_COUNT /* @min:%2ecount */] += 1;
140
- }
141
- var localStorageName = _getLocalStorageName(msgID);
142
- _resetLocalStorage(_logger, localStorageName, localStorageObj);
143
- for (var i = 0; i < number; i++) {
144
- _sendMessage(msgID, _logger, message, severity);
145
- }
146
- }
147
- catch (e) {
148
- // eslint-disable-next-line no-empty
149
- }
150
- return {
151
- isThrottled: throttled,
152
- throttleNum: number
153
- };
154
- }
155
- else {
156
- if (!!saveUnsentMsg) {
157
- var queue = _getQueueByKey(msgID);
158
- queue.push({
159
- msgID: msgID,
160
- message: message,
161
- severity: severity
162
- });
163
- }
164
- }
165
- return null;
166
- }
167
- function _initConfig() {
168
- _logger = safeGetLogger(core);
169
- _isTriggered = {};
170
- _localStorageObj = {};
171
- _queue = {};
172
- _config = {};
173
- _setCfgByKey(109 /* _eInternalMessageId.DefaultThrottleMsgKey */);
174
- _namePrefix = isNotNullOrUndefined(namePrefix) ? namePrefix : "";
175
- core.addUnloadHook(onConfigChange(core.config, function (details) {
176
- var coreConfig = details.cfg;
177
- _canUseLocalStorage = utlCanUseLocalStorage();
178
- var configMgr = coreConfig.throttleMgrCfg || {};
179
- objForEachKey(configMgr, function (key, cfg) {
180
- _setCfgByKey(parseInt(key), cfg);
181
- });
182
- }));
183
- }
184
- function _getCfgByKey(msgID) {
185
- return _config[msgID] || _config[109 /* _eInternalMessageId.DefaultThrottleMsgKey */];
186
- }
187
- function _setCfgByKey(msgID, config) {
188
- var _a, _b;
189
- try {
190
- var cfg = config || {};
191
- var curCfg = {};
192
- curCfg.disabled = !!cfg.disabled;
193
- var configInterval = cfg.interval || {};
194
- _isSpecificDaysGiven = (configInterval === null || configInterval === void 0 ? void 0 : configInterval.daysOfMonth) && (configInterval === null || configInterval === void 0 ? void 0 : configInterval.daysOfMonth[_DYN_LENGTH /* @min:%2elength */]) > 0;
195
- curCfg.interval = _getIntervalConfig(configInterval);
196
- var limit = {
197
- samplingRate: ((_a = cfg.limit) === null || _a === void 0 ? void 0 : _a.samplingRate) || 100,
198
- // dafault: every time sent only 1 event
199
- maxSendNumber: ((_b = cfg.limit) === null || _b === void 0 ? void 0 : _b.maxSendNumber) || 1
200
- };
201
- curCfg.limit = limit;
202
- _config[msgID] = curCfg;
203
- }
204
- catch (e) {
205
- // eslint-disable-next-line no-empty
206
- }
207
- }
208
- function _getIntervalConfig(interval) {
209
- interval = interval || {};
210
- var monthInterval = interval === null || interval === void 0 ? void 0 : interval.monthInterval;
211
- var dayInterval = interval === null || interval === void 0 ? void 0 : interval.dayInterval;
212
- // default: send data every 3 month each year
213
- if (isNullOrUndefined(monthInterval) && isNullOrUndefined(dayInterval)) {
214
- interval.monthInterval = 3;
215
- if (!_isSpecificDaysGiven) {
216
- // default: send data on 28th
217
- interval.daysOfMonth = [28];
218
- _isSpecificDaysGiven = true;
219
- }
220
- }
221
- interval = {
222
- // dafault: sent every three months
223
- monthInterval: interval === null || interval === void 0 ? void 0 : interval.monthInterval,
224
- dayInterval: interval === null || interval === void 0 ? void 0 : interval.dayInterval,
225
- daysOfMonth: interval === null || interval === void 0 ? void 0 : interval.daysOfMonth
226
- };
227
- return interval;
228
- }
229
- function _canThrottle(config, canUseLocalStorage, localStorageObj) {
230
- if (config && !config.disabled && canUseLocalStorage && isNotNullOrUndefined(localStorageObj)) {
231
- var curDate = _getThrottleDate();
232
- var date = localStorageObj.date;
233
- var interval = config.interval;
234
- var monthCheck = 1;
235
- if (interval === null || interval === void 0 ? void 0 : interval.monthInterval) {
236
- var monthExpand = (curDate.getUTCFullYear() - date.getUTCFullYear()) * 12 + curDate.getUTCMonth() - date.getUTCMonth();
237
- monthCheck = _checkInterval(interval.monthInterval, 0, monthExpand);
238
- }
239
- var dayCheck = 1;
240
- if (_isSpecificDaysGiven) {
241
- dayCheck = arrIndexOf(interval.daysOfMonth, curDate[_DYN_GET_UTCDATE /* @min:%2egetUTCDate */]());
242
- }
243
- else if (interval === null || interval === void 0 ? void 0 : interval.dayInterval) {
244
- var daySpan = mathFloor((curDate.getTime() - date.getTime()) / 86400000);
245
- dayCheck = _checkInterval(interval.dayInterval, 0, daySpan);
246
- }
247
- return monthCheck >= 0 && dayCheck >= 0;
248
- }
249
- return false;
250
- }
251
- function _getLocalStorageName(msgKey, prefix) {
252
- var fix = isNotNullOrUndefined(prefix) ? prefix : "";
253
- if (msgKey) {
254
- return THROTTLE_STORAGE_PREFIX + fix + "-" + msgKey;
255
- }
256
- return null;
257
- }
258
- // returns if throttle is triggered on current Date
259
- function _isTriggeredOnCurDate(preTriggerDate) {
260
- try {
261
- if (preTriggerDate) {
262
- var curDate = new Date();
263
- return preTriggerDate.getUTCFullYear() === curDate.getUTCFullYear() &&
264
- preTriggerDate.getUTCMonth() === curDate.getUTCMonth() &&
265
- preTriggerDate[_DYN_GET_UTCDATE /* @min:%2egetUTCDate */]() === curDate[_DYN_GET_UTCDATE /* @min:%2egetUTCDate */]();
266
- }
267
- }
268
- catch (e) {
269
- // eslint-disable-next-line no-empty
270
- }
271
- return false;
272
- }
273
- // transfer local storage string value to object that identifies start date, current count and preTriggerDate
274
- function _getLocalStorageObj(value, logger, storageName) {
275
- try {
276
- var storageObj = {
277
- date: _getThrottleDate(),
278
- count: 0
279
- };
280
- if (value) {
281
- var obj = JSON.parse(value);
282
- var curObj = {
283
- date: _getThrottleDate(obj.date) || storageObj.date,
284
- count: obj[_DYN_COUNT /* @min:%2ecount */] || storageObj[_DYN_COUNT /* @min:%2ecount */],
285
- preTriggerDate: obj.preTriggerDate ? _getThrottleDate(obj[_DYN_PRE_TRIGGER_DATE /* @min:%2epreTriggerDate */]) : undefined
286
- };
287
- return curObj;
288
- }
289
- else {
290
- _resetLocalStorage(logger, storageName, storageObj);
291
- return storageObj;
292
- }
293
- }
294
- catch (e) {
295
- // eslint-disable-next-line no-empty
296
- }
297
- return null;
298
- }
299
- // if datestr is not defined, current date will be returned
300
- function _getThrottleDate(dateStr) {
301
- // if new Date() can't be created through the provided dateStr, null will be returned.
302
- try {
303
- if (dateStr) {
304
- var date = new Date(dateStr);
305
- //make sure it is a valid Date Object
306
- if (!isNaN(date.getDate())) {
307
- return date;
308
- }
309
- }
310
- else {
311
- return new Date();
312
- }
313
- }
314
- catch (e) {
315
- // eslint-disable-next-line no-empty
316
- }
317
- return null;
318
- }
319
- function _resetLocalStorage(logger, storageName, obj) {
320
- try {
321
- return utlSetLocalStorage(logger, storageName, strTrim(JSON[_DYN_STRINGIFY /* @min:%2estringify */](obj)));
322
- }
323
- catch (e) {
324
- // eslint-disable-next-line no-empty
325
- }
326
- return false;
327
- }
328
- function _checkInterval(interval, start, current) {
329
- if (interval <= 0) {
330
- return 1;
331
- }
332
- // count from start year
333
- return (current >= start) && (current - start) % interval == 0 ? mathFloor((current - start) / interval) + 1 : -1;
334
- }
335
- function _sendMessage(msgID, logger, message, severity) {
336
- _throwInternal(logger, severity || 1 /* eLoggingSeverity.CRITICAL */, msgID, message);
337
- }
338
- // NOTE: config.limit.samplingRate is set to 4 decimal places,
339
- // so config.limit.samplingRate = 1 means 0.0001%
340
- function _canSampledIn(msgID) {
341
- try {
342
- var cfg = _getCfgByKey(msgID);
343
- return randomValue(1000000) <= cfg.limit.samplingRate;
344
- }
345
- catch (e) {
346
- // eslint-disable-next-line no-empty
347
- }
348
- return false;
349
- }
350
- function _getLocalStorageObjByKey(key) {
351
- try {
352
- var curObj = _localStorageObj[key];
353
- if (!curObj) {
354
- var localStorageName = _getLocalStorageName(key, _namePrefix);
355
- curObj = _getLocalStorageObj(utlGetLocalStorage(_logger, localStorageName), _logger, localStorageName);
356
- _localStorageObj[key] = curObj;
357
- }
358
- return _localStorageObj[key];
359
- }
360
- catch (e) {
361
- // eslint-disable-next-line no-empty
362
- }
363
- return null;
364
- }
365
- function _isTrigger(key) {
366
- var isTrigger = _isTriggered[key];
367
- if (isNullOrUndefined(isTrigger)) {
368
- isTrigger = false;
369
- var localStorageObj = _getLocalStorageObjByKey(key);
370
- if (localStorageObj) {
371
- isTrigger = _isTriggeredOnCurDate(localStorageObj[_DYN_PRE_TRIGGER_DATE /* @min:%2epreTriggerDate */]);
372
- }
373
- _isTriggered[key] = isTrigger;
374
- }
375
- return _isTriggered[key];
376
- }
377
- function _getQueueByKey(key) {
378
- _queue = _queue || {};
379
- if (isNullOrUndefined(_queue[key])) {
380
- _queue[key] = [];
381
- }
382
- return _queue[key];
383
- }
384
- }
385
- return ThrottleMgr;
386
- }());
387
- export { ThrottleMgr };
388
- //# sourceMappingURL=ThrottleMgr.js.map
@@ -1 +0,0 @@
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, mathFloor, mathMin, objForEachKey } from \"@nevware21/ts-utils\";\r\nimport { utlCanUseLocalStorage, utlGetLocalStorage, utlSetLocalStorage } from \"./StorageHelperFuncs\";\r\nimport { _DYN_COUNT, _DYN_GET_UTCDATE, _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 var cfg = _getCfgByKey(msgId);\r\n return _canThrottle(cfg, _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(msgID);\r\n if (!isSampledIn) {\r\n return;\r\n }\r\n var cfg = _getCfgByKey(msgID);\r\n var localStorageObj = _getLocalStorageObjByKey(msgID);\r\n var canThrottle = _canThrottle(cfg, _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 = mathMin(cfg.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 _config = {};\r\n _setCfgByKey(109 /* _eInternalMessageId.DefaultThrottleMsgKey */);\r\n _namePrefix = isNotNullOrUndefined(namePrefix) ? namePrefix : \"\";\r\n core.addUnloadHook(onConfigChange(core.config, function (details) {\r\n var coreConfig = details.cfg;\r\n _canUseLocalStorage = utlCanUseLocalStorage();\r\n var configMgr = coreConfig.throttleMgrCfg || {};\r\n objForEachKey(configMgr, function (key, cfg) {\r\n _setCfgByKey(parseInt(key), cfg);\r\n });\r\n }));\r\n }\r\n function _getCfgByKey(msgID) {\r\n return _config[msgID] || _config[109 /* _eInternalMessageId.DefaultThrottleMsgKey */];\r\n }\r\n function _setCfgByKey(msgID, config) {\r\n var _a, _b;\r\n try {\r\n var cfg = config || {};\r\n var curCfg = {};\r\n curCfg.disabled = !!cfg.disabled;\r\n var configInterval = cfg.interval || {};\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 curCfg.interval = _getIntervalConfig(configInterval);\r\n var limit = {\r\n samplingRate: ((_a = cfg.limit) === null || _a === void 0 ? void 0 : _a.samplingRate) || 100,\r\n // dafault: every time sent only 1 event\r\n maxSendNumber: ((_b = cfg.limit) === null || _b === void 0 ? void 0 : _b.maxSendNumber) || 1\r\n };\r\n curCfg.limit = limit;\r\n _config[msgID] = curCfg;\r\n }\r\n catch (e) {\r\n // eslint-disable-next-line no-empty\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.daysOfMonth = [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 && !config.disabled && canUseLocalStorage && isNotNullOrUndefined(localStorageObj)) {\r\n var curDate = _getThrottleDate();\r\n var date = localStorageObj.date;\r\n var interval = config.interval;\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.daysOfMonth, 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 = mathFloor((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.date) || storageObj.date,\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 ? mathFloor((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(msgID) {\r\n try {\r\n var cfg = _getCfgByKey(msgID);\r\n return randomValue(1000000) <= cfg.limit.samplingRate;\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 _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;AACA;AACA;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,90 +0,0 @@
1
- /*
2
- * Application Insights JavaScript SDK - Common, 3.3.12-nightly3.2602-20
3
- * Copyright (c) Microsoft and contributors. All rights reserved.
4
- */
5
-
6
-
7
- import { getDocument, isString } from "@microsoft/applicationinsights-core-js";
8
- import { _DYN_LENGTH, _DYN_MATCH, _DYN_PATHNAME, _DYN_TO_LOWER_CASE } from "./__DynamicConstants";
9
- var _document = getDocument() || {};
10
- var _htmlAnchorIdx = 0;
11
- // Use an array of temporary values as it's possible for multiple calls to parseUrl() will be called with different URLs
12
- // Using a cache size of 5 for now as it current depth usage is at least 2, so adding a minor buffer to handle future updates
13
- var _htmlAnchorElement = [null, null, null, null, null];
14
- export function urlParseUrl(url) {
15
- var anchorIdx = _htmlAnchorIdx;
16
- var anchorCache = _htmlAnchorElement;
17
- var tempAnchor = anchorCache[anchorIdx];
18
- if (!_document.createElement) {
19
- // Always create the temp instance if createElement is not available
20
- tempAnchor = { host: urlParseHost(url, true) };
21
- }
22
- else if (!anchorCache[anchorIdx]) {
23
- // Create and cache the unattached anchor instance
24
- tempAnchor = anchorCache[anchorIdx] = _document.createElement("a");
25
- }
26
- tempAnchor.href = url;
27
- // Move the cache index forward
28
- anchorIdx++;
29
- if (anchorIdx >= anchorCache[_DYN_LENGTH /* @min:%2elength */]) {
30
- anchorIdx = 0;
31
- }
32
- _htmlAnchorIdx = anchorIdx;
33
- return tempAnchor;
34
- }
35
- export function urlGetAbsoluteUrl(url) {
36
- var result;
37
- var a = urlParseUrl(url);
38
- if (a) {
39
- result = a.href;
40
- }
41
- return result;
42
- }
43
- export function urlGetPathName(url) {
44
- var result;
45
- var a = urlParseUrl(url);
46
- if (a) {
47
- result = a[_DYN_PATHNAME /* @min:%2epathname */];
48
- }
49
- return result;
50
- }
51
- export function urlGetCompleteUrl(method, absoluteUrl) {
52
- if (method) {
53
- return method.toUpperCase() + " " + absoluteUrl;
54
- }
55
- return absoluteUrl;
56
- }
57
- // Fallback method to grab host from url if document.createElement method is not available
58
- export function urlParseHost(url, inclPort) {
59
- var fullHost = urlParseFullHost(url, inclPort) || "";
60
- if (fullHost) {
61
- var match = fullHost[_DYN_MATCH /* @min:%2ematch */](/(www\d{0,5}\.)?([^\/:]{1,256})(:\d{1,20})?/i);
62
- if (match != null && match[_DYN_LENGTH /* @min:%2elength */] > 3 && isString(match[2]) && match[2][_DYN_LENGTH /* @min:%2elength */] > 0) {
63
- return match[2] + (match[3] || "");
64
- }
65
- }
66
- return fullHost;
67
- }
68
- export function urlParseFullHost(url, inclPort) {
69
- var result = null;
70
- if (url) {
71
- var match = url[_DYN_MATCH /* @min:%2ematch */](/(\w{1,150}):\/\/([^\/:]{1,256})(:\d{1,20})?/i);
72
- if (match != null && match[_DYN_LENGTH /* @min:%2elength */] > 2 && isString(match[2]) && match[2][_DYN_LENGTH /* @min:%2elength */] > 0) {
73
- result = match[2] || "";
74
- if (inclPort && match[_DYN_LENGTH /* @min:%2elength */] > 2) {
75
- var protocol = (match[1] || "")[_DYN_TO_LOWER_CASE /* @min:%2etoLowerCase */]();
76
- var port = match[3] || "";
77
- // IE includes the standard port so pass it off if it's the same as the protocol
78
- if (protocol === "http" && port === ":80") {
79
- port = "";
80
- }
81
- else if (protocol === "https" && port === ":443") {
82
- port = "";
83
- }
84
- result += port;
85
- }
86
- }
87
- }
88
- return result;
89
- }
90
- //# sourceMappingURL=UrlHelperFuncs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"UrlHelperFuncs.js.map","sources":["UrlHelperFuncs.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport { getDocument, isString } from \"@microsoft/applicationinsights-core-js\";\r\nimport { _DYN_LENGTH, _DYN_MATCH, _DYN_PATHNAME, _DYN_TO_LOWER_CASE } from \"./__DynamicConstants\";\r\nvar _document = getDocument() || {};\r\nvar _htmlAnchorIdx = 0;\r\n// Use an array of temporary values as it's possible for multiple calls to parseUrl() will be called with different URLs\r\n// Using a cache size of 5 for now as it current depth usage is at least 2, so adding a minor buffer to handle future updates\r\nvar _htmlAnchorElement = [null, null, null, null, null];\r\nexport function urlParseUrl(url) {\r\n var anchorIdx = _htmlAnchorIdx;\r\n var anchorCache = _htmlAnchorElement;\r\n var tempAnchor = anchorCache[anchorIdx];\r\n if (!_document.createElement) {\r\n // Always create the temp instance if createElement is not available\r\n tempAnchor = { host: urlParseHost(url, true) };\r\n }\r\n else if (!anchorCache[anchorIdx]) {\r\n // Create and cache the unattached anchor instance\r\n tempAnchor = anchorCache[anchorIdx] = _document.createElement(\"a\");\r\n }\r\n tempAnchor.href = url;\r\n // Move the cache index forward\r\n anchorIdx++;\r\n if (anchorIdx >= anchorCache[_DYN_LENGTH /* @min:%2elength */]) {\r\n anchorIdx = 0;\r\n }\r\n _htmlAnchorIdx = anchorIdx;\r\n return tempAnchor;\r\n}\r\nexport function urlGetAbsoluteUrl(url) {\r\n var result;\r\n var a = urlParseUrl(url);\r\n if (a) {\r\n result = a.href;\r\n }\r\n return result;\r\n}\r\nexport function urlGetPathName(url) {\r\n var result;\r\n var a = urlParseUrl(url);\r\n if (a) {\r\n result = a[_DYN_PATHNAME /* @min:%2epathname */];\r\n }\r\n return result;\r\n}\r\nexport function urlGetCompleteUrl(method, absoluteUrl) {\r\n if (method) {\r\n return method.toUpperCase() + \" \" + absoluteUrl;\r\n }\r\n return absoluteUrl;\r\n}\r\n// Fallback method to grab host from url if document.createElement method is not available\r\nexport function urlParseHost(url, inclPort) {\r\n var fullHost = urlParseFullHost(url, inclPort) || \"\";\r\n if (fullHost) {\r\n var match = fullHost[_DYN_MATCH /* @min:%2ematch */](/(www\\d{0,5}\\.)?([^\\/:]{1,256})(:\\d{1,20})?/i);\r\n if (match != null && match[_DYN_LENGTH /* @min:%2elength */] > 3 && isString(match[2]) && match[2][_DYN_LENGTH /* @min:%2elength */] > 0) {\r\n return match[2] + (match[3] || \"\");\r\n }\r\n }\r\n return fullHost;\r\n}\r\nexport function urlParseFullHost(url, inclPort) {\r\n var result = null;\r\n if (url) {\r\n var match = url[_DYN_MATCH /* @min:%2ematch */](/(\\w{1,150}):\\/\\/([^\\/:]{1,256})(:\\d{1,20})?/i);\r\n if (match != null && match[_DYN_LENGTH /* @min:%2elength */] > 2 && isString(match[2]) && match[2][_DYN_LENGTH /* @min:%2elength */] > 0) {\r\n result = match[2] || \"\";\r\n if (inclPort && match[_DYN_LENGTH /* @min:%2elength */] > 2) {\r\n var protocol = (match[1] || \"\")[_DYN_TO_LOWER_CASE /* @min:%2etoLowerCase */]();\r\n var port = match[3] || \"\";\r\n // IE includes the standard port so pass it off if it's the same as the protocol\r\n if (protocol === \"http\" && port === \":80\") {\r\n port = \"\";\r\n }\r\n else if (protocol === \"https\" && port === \":443\") {\r\n port = \"\";\r\n }\r\n result += port;\r\n }\r\n }\r\n }\r\n return result;\r\n}\r\n//# sourceMappingURL=UrlHelperFuncs.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"}