@splitsoftware/splitio-commons 1.6.2-rc.8 → 1.7.0

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 (177) hide show
  1. package/CHANGES.txt +4 -1
  2. package/cjs/evaluator/index.js +5 -5
  3. package/cjs/listeners/browser.js +9 -11
  4. package/cjs/sdkClient/client.js +19 -7
  5. package/cjs/sdkFactory/index.js +7 -25
  6. package/cjs/services/splitApi.js +4 -4
  7. package/cjs/storages/AbstractSplitsCacheAsync.js +1 -1
  8. package/cjs/storages/AbstractSplitsCacheSync.js +1 -1
  9. package/cjs/storages/KeyBuilderSS.js +9 -9
  10. package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +0 -1
  11. package/cjs/storages/inLocalStorage/index.js +15 -11
  12. package/cjs/storages/inMemory/InMemoryStorage.js +11 -8
  13. package/cjs/storages/inMemory/InMemoryStorageCS.js +11 -8
  14. package/cjs/storages/inMemory/TelemetryCacheInMemory.js +65 -37
  15. package/cjs/storages/inMemory/{uniqueKeysCacheInMemory.js → UniqueKeysCacheInMemory.js} +24 -25
  16. package/cjs/storages/inMemory/{uniqueKeysCacheInMemoryCS.js → UniqueKeysCacheInMemoryCS.js} +10 -12
  17. package/cjs/storages/inRedis/EventsCacheInRedis.js +1 -1
  18. package/cjs/storages/inRedis/ImpressionCountsCacheInRedis.js +37 -2
  19. package/cjs/storages/inRedis/ImpressionsCacheInRedis.js +2 -19
  20. package/cjs/storages/inRedis/TelemetryCacheInRedis.js +100 -0
  21. package/cjs/storages/inRedis/{uniqueKeysCacheInRedis.js → UniqueKeysCacheInRedis.js} +16 -4
  22. package/cjs/storages/inRedis/index.js +6 -4
  23. package/cjs/storages/pluggable/ImpressionCountsCachePluggable.js +81 -0
  24. package/cjs/storages/pluggable/ImpressionsCachePluggable.js +2 -19
  25. package/cjs/storages/pluggable/TelemetryCachePluggable.js +126 -0
  26. package/cjs/storages/pluggable/UniqueKeysCachePluggable.js +61 -0
  27. package/cjs/storages/pluggable/inMemoryWrapper.js +8 -6
  28. package/cjs/storages/pluggable/index.js +51 -18
  29. package/cjs/storages/utils.js +73 -0
  30. package/cjs/sync/submitters/submitterManager.js +1 -1
  31. package/cjs/sync/submitters/telemetrySubmitter.js +4 -37
  32. package/cjs/sync/submitters/uniqueKeysSubmitter.js +4 -3
  33. package/cjs/trackers/impressionObserver/utils.js +1 -17
  34. package/cjs/trackers/uniqueKeysTracker.js +1 -1
  35. package/cjs/utils/lang/maps.js +15 -7
  36. package/cjs/utils/redis/RedisMock.js +31 -0
  37. package/cjs/utils/settingsValidation/index.js +7 -4
  38. package/esm/evaluator/index.js +5 -5
  39. package/esm/listeners/browser.js +9 -11
  40. package/esm/sdkClient/client.js +19 -7
  41. package/esm/sdkFactory/index.js +7 -25
  42. package/esm/services/splitApi.js +4 -4
  43. package/esm/storages/AbstractSplitsCacheAsync.js +1 -1
  44. package/esm/storages/AbstractSplitsCacheSync.js +1 -1
  45. package/esm/storages/KeyBuilderSS.js +8 -8
  46. package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +0 -1
  47. package/esm/storages/inLocalStorage/index.js +16 -12
  48. package/esm/storages/inMemory/InMemoryStorage.js +13 -10
  49. package/esm/storages/inMemory/InMemoryStorageCS.js +12 -9
  50. package/esm/storages/inMemory/TelemetryCacheInMemory.js +64 -37
  51. package/esm/storages/inMemory/{uniqueKeysCacheInMemory.js → UniqueKeysCacheInMemory.js} +22 -24
  52. package/esm/storages/inMemory/{uniqueKeysCacheInMemoryCS.js → UniqueKeysCacheInMemoryCS.js} +10 -12
  53. package/esm/storages/inRedis/EventsCacheInRedis.js +1 -1
  54. package/esm/storages/inRedis/ImpressionCountsCacheInRedis.js +37 -2
  55. package/esm/storages/inRedis/ImpressionsCacheInRedis.js +2 -19
  56. package/esm/storages/inRedis/TelemetryCacheInRedis.js +100 -0
  57. package/esm/storages/inRedis/{uniqueKeysCacheInRedis.js → UniqueKeysCacheInRedis.js} +15 -3
  58. package/esm/storages/inRedis/index.js +5 -3
  59. package/esm/storages/pluggable/ImpressionCountsCachePluggable.js +78 -0
  60. package/esm/storages/pluggable/ImpressionsCachePluggable.js +2 -19
  61. package/esm/storages/pluggable/TelemetryCachePluggable.js +126 -0
  62. package/esm/storages/pluggable/UniqueKeysCachePluggable.js +58 -0
  63. package/esm/storages/pluggable/inMemoryWrapper.js +8 -6
  64. package/esm/storages/pluggable/index.js +52 -19
  65. package/esm/storages/utils.js +65 -0
  66. package/esm/sync/submitters/submitterManager.js +1 -1
  67. package/esm/sync/submitters/telemetrySubmitter.js +4 -36
  68. package/esm/sync/submitters/uniqueKeysSubmitter.js +4 -3
  69. package/esm/trackers/impressionObserver/utils.js +1 -15
  70. package/esm/trackers/uniqueKeysTracker.js +1 -1
  71. package/esm/utils/lang/maps.js +15 -7
  72. package/esm/utils/redis/RedisMock.js +28 -0
  73. package/esm/utils/settingsValidation/index.js +7 -4
  74. package/package.json +2 -2
  75. package/src/consent/sdkUserConsent.ts +1 -1
  76. package/src/evaluator/index.ts +6 -6
  77. package/src/listeners/browser.ts +9 -13
  78. package/src/logger/.DS_Store +0 -0
  79. package/src/sdkClient/client.ts +21 -8
  80. package/src/sdkClient/sdkClient.ts +1 -1
  81. package/src/sdkFactory/index.ts +10 -33
  82. package/src/sdkFactory/types.ts +2 -2
  83. package/src/services/splitApi.ts +6 -6
  84. package/src/services/types.ts +2 -2
  85. package/src/storages/AbstractSplitsCacheAsync.ts +1 -1
  86. package/src/storages/AbstractSplitsCacheSync.ts +1 -1
  87. package/src/storages/KeyBuilderSS.ts +13 -11
  88. package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +0 -1
  89. package/src/storages/inLocalStorage/index.ts +17 -12
  90. package/src/storages/inMemory/AttributesCacheInMemory.ts +7 -7
  91. package/src/storages/inMemory/ImpressionCountsCacheInMemory.ts +2 -2
  92. package/src/storages/inMemory/InMemoryStorage.ts +14 -10
  93. package/src/storages/inMemory/InMemoryStorageCS.ts +13 -10
  94. package/src/storages/inMemory/TelemetryCacheInMemory.ts +72 -35
  95. package/src/storages/inMemory/{uniqueKeysCacheInMemory.ts → UniqueKeysCacheInMemory.ts} +26 -28
  96. package/src/storages/inMemory/{uniqueKeysCacheInMemoryCS.ts → UniqueKeysCacheInMemoryCS.ts} +15 -17
  97. package/src/storages/inRedis/EventsCacheInRedis.ts +1 -1
  98. package/src/storages/inRedis/ImpressionCountsCacheInRedis.ts +51 -8
  99. package/src/storages/inRedis/ImpressionsCacheInRedis.ts +2 -22
  100. package/src/storages/inRedis/TelemetryCacheInRedis.ts +122 -1
  101. package/src/storages/inRedis/{uniqueKeysCacheInRedis.ts → UniqueKeysCacheInRedis.ts} +25 -12
  102. package/src/storages/inRedis/index.ts +6 -3
  103. package/src/storages/pluggable/ImpressionCountsCachePluggable.ts +92 -0
  104. package/src/storages/pluggable/ImpressionsCachePluggable.ts +3 -23
  105. package/src/storages/pluggable/TelemetryCachePluggable.ts +147 -1
  106. package/src/storages/pluggable/UniqueKeysCachePluggable.ts +67 -0
  107. package/src/storages/pluggable/inMemoryWrapper.ts +6 -6
  108. package/src/storages/pluggable/index.ts +56 -20
  109. package/src/storages/types.ts +53 -70
  110. package/src/storages/utils.ts +78 -0
  111. package/src/sync/submitters/submitter.ts +2 -2
  112. package/src/sync/submitters/submitterManager.ts +1 -1
  113. package/src/sync/submitters/telemetrySubmitter.ts +9 -39
  114. package/src/sync/submitters/types.ts +33 -17
  115. package/src/sync/submitters/uniqueKeysSubmitter.ts +6 -5
  116. package/src/trackers/impressionObserver/utils.ts +1 -16
  117. package/src/trackers/impressionsTracker.ts +2 -2
  118. package/src/trackers/strategy/strategyDebug.ts +4 -4
  119. package/src/trackers/strategy/strategyNone.ts +9 -9
  120. package/src/trackers/strategy/strategyOptimized.ts +9 -9
  121. package/src/trackers/uniqueKeysTracker.ts +6 -6
  122. package/src/types.ts +0 -2
  123. package/src/utils/lang/maps.ts +20 -8
  124. package/src/utils/redis/RedisMock.ts +33 -0
  125. package/src/utils/settingsValidation/index.ts +5 -5
  126. package/types/services/types.d.ts +2 -2
  127. package/types/storages/AbstractSplitsCacheAsync.d.ts +1 -1
  128. package/types/storages/AbstractSplitsCacheSync.d.ts +1 -1
  129. package/types/storages/KeyBuilderSS.d.ts +5 -2
  130. package/types/storages/inLocalStorage/SplitsCacheInLocal.d.ts +0 -1
  131. package/types/storages/inMemory/TelemetryCacheInMemory.d.ts +23 -9
  132. package/types/storages/inMemory/uniqueKeysCacheInMemory.d.ts +9 -9
  133. package/types/storages/inMemory/uniqueKeysCacheInMemoryCS.d.ts +2 -4
  134. package/types/storages/inRedis/EventsCacheInRedis.d.ts +1 -1
  135. package/types/storages/inRedis/ImpressionCountsCacheInRedis.d.ts +3 -1
  136. package/types/storages/inRedis/ImpressionsCacheInRedis.d.ts +0 -1
  137. package/types/storages/inRedis/TelemetryCacheInRedis.d.ts +16 -1
  138. package/types/storages/inRedis/uniqueKeysCacheInRedis.d.ts +8 -2
  139. package/types/storages/pluggable/ImpressionCountsCachePluggable.d.ts +16 -0
  140. package/types/storages/pluggable/ImpressionsCachePluggable.d.ts +1 -2
  141. package/types/storages/pluggable/TelemetryCachePluggable.d.ts +17 -1
  142. package/types/storages/pluggable/UniqueKeysCachePluggable.d.ts +20 -0
  143. package/types/storages/types.d.ts +42 -49
  144. package/types/storages/utils.d.ts +8 -0
  145. package/types/sync/submitters/submitter.d.ts +2 -2
  146. package/types/sync/submitters/telemetrySubmitter.d.ts +2 -10
  147. package/types/sync/submitters/types.d.ts +27 -18
  148. package/types/trackers/impressionObserver/utils.d.ts +0 -8
  149. package/types/trackers/strategy/strategyNone.d.ts +2 -2
  150. package/types/trackers/strategy/strategyOptimized.d.ts +2 -2
  151. package/types/trackers/uniqueKeysTracker.d.ts +1 -1
  152. package/types/types.d.ts +0 -2
  153. package/types/utils/lang/maps.d.ts +6 -2
  154. package/types/utils/redis/RedisMock.d.ts +4 -0
  155. package/types/utils/settingsValidation/index.d.ts +0 -1
  156. package/cjs/storages/metadataBuilder.js +0 -12
  157. package/esm/storages/metadataBuilder.js +0 -8
  158. package/src/storages/metadataBuilder.ts +0 -11
  159. package/types/sdkClient/types.d.ts +0 -18
  160. package/types/storages/inMemory/CountsCacheInMemory.d.ts +0 -20
  161. package/types/storages/inMemory/LatenciesCacheInMemory.d.ts +0 -20
  162. package/types/storages/inRedis/CountsCacheInRedis.d.ts +0 -9
  163. package/types/storages/inRedis/LatenciesCacheInRedis.d.ts +0 -9
  164. package/types/sync/offline/LocalhostFromFile.d.ts +0 -2
  165. package/types/sync/offline/splitsParser/splitsParserFromFile.d.ts +0 -2
  166. package/types/sync/submitters/eventsSyncTask.d.ts +0 -8
  167. package/types/sync/submitters/impressionCountsSubmitterInRedis.d.ts +0 -5
  168. package/types/sync/submitters/impressionCountsSyncTask.d.ts +0 -13
  169. package/types/sync/submitters/impressionsSyncTask.d.ts +0 -14
  170. package/types/sync/submitters/metricsSyncTask.d.ts +0 -12
  171. package/types/sync/submitters/submitterSyncTask.d.ts +0 -10
  172. package/types/sync/submitters/uniqueKeysSubmitterInRedis.d.ts +0 -5
  173. package/types/sync/syncTaskComposite.d.ts +0 -5
  174. package/types/trackers/filter/bloomFilter.d.ts +0 -10
  175. package/types/trackers/filter/dictionaryFilter.d.ts +0 -8
  176. package/types/trackers/filter/types.d.ts +0 -5
  177. package/types/utils/timeTracker/index.d.ts +0 -70
package/CHANGES.txt CHANGED
@@ -1,5 +1,8 @@
1
- 1.6.2 (September XXX, 2022)
1
+ 1.7.0 (October 4, 2022)
2
+ - Added a new impressions mode for the SDK called NONE, to be used in factory when there is no desire to capture impressions on an SDK factory to feed Split's analytics engine. Running NONE mode, the SDK will only capture unique keys evaluated for a particular feature flag instead of full blown impressions.
3
+ - Updated SDK telemetry to support pluggable storage, partial consumer mode, and synchronizer.
2
4
  - Updated storage implementations to improve the performance of split evaluations (i.e., `getTreatment(s)` method calls) when using the default storage in memory.
5
+ - Updated evaluation flow to avoid unnecessarily storage calls when the SDK is not ready.
3
6
 
4
7
  1.6.1 (July 22, 2022)
5
8
  - Updated GoogleAnalyticsToSplit integration to validate `autoRequire` config parameter and avoid some wrong warning logs when mapping GA hit fields to Split event properties.
@@ -19,21 +19,21 @@ function treatmentsException(splitNames) {
19
19
  return evaluations;
20
20
  }
21
21
  function evaluateFeature(log, key, splitName, attributes, storage) {
22
- var stringifiedSplit;
22
+ var parsedSplit;
23
23
  try {
24
- stringifiedSplit = storage.splits.getSplit(splitName);
24
+ parsedSplit = storage.splits.getSplit(splitName);
25
25
  }
26
26
  catch (e) {
27
27
  // Exception on sync `getSplit` storage. Not possible ATM with InMemory and InLocal storages.
28
28
  return treatmentException;
29
29
  }
30
- if ((0, thenable_1.thenable)(stringifiedSplit)) {
31
- return stringifiedSplit.then(function (result) { return getEvaluation(log, result, key, attributes, storage); }).catch(
30
+ if ((0, thenable_1.thenable)(parsedSplit)) {
31
+ return parsedSplit.then(function (split) { return getEvaluation(log, split, key, attributes, storage); }).catch(
32
32
  // Exception on async `getSplit` storage. For example, when the storage is redis or
33
33
  // pluggable and there is a connection issue and we can't retrieve the split to be evaluated
34
34
  function () { return treatmentException; });
35
35
  }
36
- return getEvaluation(log, stringifiedSplit, key, attributes, storage);
36
+ return getEvaluation(log, parsedSplit, key, attributes, storage);
37
37
  }
38
38
  exports.evaluateFeature = evaluateFeature;
39
39
  function evaluateFeatures(log, key, splitNames, attributes, storage) {
@@ -7,7 +7,6 @@ var constants_1 = require("../utils/constants");
7
7
  var objectAssign_1 = require("../utils/lang/objectAssign");
8
8
  var constants_2 = require("../logger/constants");
9
9
  var consent_1 = require("../consent");
10
- var telemetrySubmitter_1 = require("../sync/submitters/telemetrySubmitter");
11
10
  var VISIBILITYCHANGE_EVENT = 'visibilitychange';
12
11
  var PAGEHIDE_EVENT = 'pagehide';
13
12
  var UNLOAD_EVENT = 'unload';
@@ -71,25 +70,25 @@ var BrowserSignalListener = /** @class */ (function () {
71
70
  BrowserSignalListener.prototype.flushData = function () {
72
71
  if (!this.syncManager)
73
72
  return; // In consumer mode there is not sync manager and data to flush
73
+ var _a = this.settings.urls, events = _a.events, telemetry = _a.telemetry;
74
74
  // Flush impressions & events data if there is user consent
75
75
  if ((0, consent_1.isConsentGranted)(this.settings)) {
76
- var eventsUrl = this.settings.urls.events;
77
76
  var sim = this.settings.sync.impressionsMode;
78
77
  var extraMetadata = {
79
78
  // sim stands for Sync/Split Impressions Mode
80
79
  sim: sim === constants_1.OPTIMIZED ? constants_1.OPTIMIZED : sim === constants_1.DEBUG ? constants_1.DEBUG : constants_1.NONE
81
80
  };
82
- this._flushData(eventsUrl + '/testImpressions/beacon', this.storage.impressions, this.serviceApi.postTestImpressionsBulk, this.fromImpressionsCollector, extraMetadata);
83
- this._flushData(eventsUrl + '/events/beacon', this.storage.events, this.serviceApi.postEventsBulk);
81
+ this._flushData(events + '/testImpressions/beacon', this.storage.impressions, this.serviceApi.postTestImpressionsBulk, this.fromImpressionsCollector, extraMetadata);
82
+ this._flushData(events + '/events/beacon', this.storage.events, this.serviceApi.postEventsBulk);
84
83
  if (this.storage.impressionCounts)
85
- this._flushData(eventsUrl + '/testImpressions/count/beacon', this.storage.impressionCounts, this.serviceApi.postTestImpressionsCount, impressionCountsSubmitter_1.fromImpressionCountsCollector);
84
+ this._flushData(events + '/testImpressions/count/beacon', this.storage.impressionCounts, this.serviceApi.postTestImpressionsCount, impressionCountsSubmitter_1.fromImpressionCountsCollector);
85
+ // @ts-ignore
86
+ if (this.storage.uniqueKeys)
87
+ this._flushData(telemetry + '/v1/keys/cs/beacon', this.storage.uniqueKeys, this.serviceApi.postUniqueKeysBulkCs);
86
88
  }
87
89
  // Flush telemetry data
88
- if (this.storage.telemetry) {
89
- var telemetryUrl = this.settings.urls.telemetry;
90
- var telemetryCacheAdapter = (0, telemetrySubmitter_1.telemetryCacheStatsAdapter)(this.storage.telemetry, this.storage.splits, this.storage.segments);
91
- this._flushData(telemetryUrl + '/v1/metrics/usage/beacon', telemetryCacheAdapter, this.serviceApi.postMetricsUsage);
92
- }
90
+ if (this.storage.telemetry)
91
+ this._flushData(telemetry + '/v1/metrics/usage/beacon', this.storage.telemetry, this.serviceApi.postMetricsUsage);
93
92
  };
94
93
  BrowserSignalListener.prototype.flushDataIfHidden = function () {
95
94
  // Precondition: document defined
@@ -103,7 +102,6 @@ var BrowserSignalListener = /** @class */ (function () {
103
102
  if (!this._sendBeacon(url, dataPayload, extraMetadata)) {
104
103
  postService(JSON.stringify(dataPayload)).catch(function () { }); // no-op just to catch a possible exception
105
104
  }
106
- cache.clear();
107
105
  }
108
106
  };
109
107
  /**
@@ -9,6 +9,15 @@ var trafficTypeExistance_1 = require("../utils/inputValidation/trafficTypeExista
9
9
  var labels_1 = require("../utils/labels");
10
10
  var constants_1 = require("../utils/constants");
11
11
  var constants_2 = require("../logger/constants");
12
+ var utils_1 = require("../trackers/impressionObserver/utils");
13
+ var treatmentNotReady = { treatment: constants_1.CONTROL, label: labels_1.SDK_NOT_READY };
14
+ function treatmentsNotReady(splitNames) {
15
+ var evaluations = {};
16
+ splitNames.forEach(function (splitName) {
17
+ evaluations[splitName] = treatmentNotReady;
18
+ });
19
+ return evaluations;
20
+ }
12
21
  /**
13
22
  * Creator of base client with getTreatments and track methods.
14
23
  */
@@ -25,7 +34,11 @@ function clientFactory(params) {
25
34
  stopTelemetryTracker(queue[0] && queue[0].label);
26
35
  return treatment;
27
36
  };
28
- var evaluation = (0, evaluator_1.evaluateFeature)(log, key, splitName, attributes, storage);
37
+ var evaluation = readinessManager.isReady() || readinessManager.isReadyFromCache() ?
38
+ (0, evaluator_1.evaluateFeature)(log, key, splitName, attributes, storage) :
39
+ (0, utils_1.isStorageSync)(settings) ? // If the SDK is not ready, treatment may be incorrect due to having splits but not segments data, or storage is not connected
40
+ treatmentNotReady :
41
+ Promise.resolve(treatmentNotReady); // Promisify if async
29
42
  return (0, thenable_1.thenable)(evaluation) ? evaluation.then(function (res) { return wrapUp(res); }) : wrapUp(evaluation);
30
43
  }
31
44
  function getTreatmentWithConfig(key, splitName, attributes) {
@@ -44,7 +57,11 @@ function clientFactory(params) {
44
57
  stopTelemetryTracker(queue[0] && queue[0].label);
45
58
  return treatments;
46
59
  };
47
- var evaluations = (0, evaluator_1.evaluateFeatures)(log, key, splitNames, attributes, storage);
60
+ var evaluations = readinessManager.isReady() || readinessManager.isReadyFromCache() ?
61
+ (0, evaluator_1.evaluateFeatures)(log, key, splitNames, attributes, storage) :
62
+ (0, utils_1.isStorageSync)(settings) ? // If the SDK is not ready, treatment may be incorrect due to having splits but not segments data, or storage is not connected
63
+ treatmentsNotReady(splitNames) :
64
+ Promise.resolve(treatmentsNotReady(splitNames)); // Promisify if async
48
65
  return (0, thenable_1.thenable)(evaluations) ? evaluations.then(function (res) { return wrapUp(res); }) : wrapUp(evaluations);
49
66
  }
50
67
  function getTreatmentsWithConfig(key, splitNames, attributes) {
@@ -52,13 +69,8 @@ function clientFactory(params) {
52
69
  }
53
70
  // Internal function
54
71
  function processEvaluation(evaluation, splitName, key, attributes, withConfig, invokingMethodName, queue) {
55
- var isSdkReady = readinessManager.isReady() || readinessManager.isReadyFromCache();
56
72
  var matchingKey = (0, key_1.getMatching)(key);
57
73
  var bucketingKey = (0, key_1.getBucketing)(key);
58
- // If the SDK was not ready, treatment may be incorrect due to having Splits but not segments data.
59
- if (!isSdkReady) {
60
- evaluation = { treatment: constants_1.CONTROL, label: labels_1.SDK_NOT_READY };
61
- }
62
74
  var treatment = evaluation.treatment, label = evaluation.label, changeNumber = evaluation.changeNumber, _a = evaluation.config, config = _a === void 0 ? null : _a;
63
75
  log.info(constants_2.IMPRESSION, [splitName, matchingKey, treatment, label]);
64
76
  if ((0, splitExistance_1.validateSplitExistance)(log, readinessManager, splitName, label, invokingMethodName)) {
@@ -5,12 +5,9 @@ var sdkReadinessManager_1 = require("../readiness/sdkReadinessManager");
5
5
  var impressionsTracker_1 = require("../trackers/impressionsTracker");
6
6
  var eventTracker_1 = require("../trackers/eventTracker");
7
7
  var telemetryTracker_1 = require("../trackers/telemetryTracker");
8
- var key_1 = require("../utils/key");
9
- var utils_1 = require("../trackers/impressionObserver/utils");
10
8
  var apiKey_1 = require("../utils/inputValidation/apiKey");
11
9
  var sdkLogger_1 = require("../logger/sdkLogger");
12
10
  var constants_1 = require("../logger/constants");
13
- var metadataBuilder_1 = require("../storages/metadataBuilder");
14
11
  var constants_2 = require("../readiness/constants");
15
12
  var objectAssign_1 = require("../utils/lang/objectAssign");
16
13
  var strategyDebug_1 = require("../trackers/strategy/strategyDebug");
@@ -23,44 +20,29 @@ var constants_3 = require("../utils/constants");
23
20
  */
24
21
  function sdkFactory(params) {
25
22
  var settings = params.settings, platform = params.platform, storageFactory = params.storageFactory, splitApiFactory = params.splitApiFactory, extraProps = params.extraProps, syncManagerFactory = params.syncManagerFactory, SignalListener = params.SignalListener, impressionsObserverFactory = params.impressionsObserverFactory, integrationsManagerFactory = params.integrationsManagerFactory, sdkManagerFactory = params.sdkManagerFactory, sdkClientMethodFactory = params.sdkClientMethodFactory, filterAdapterFactory = params.filterAdapterFactory;
26
- var log = settings.log;
23
+ var log = settings.log, impressionsMode = settings.sync.impressionsMode;
27
24
  // @TODO handle non-recoverable errors, such as, global `fetch` not available, invalid API Key, etc.
28
25
  // On non-recoverable errors, we should mark the SDK as destroyed and not start synchronization.
29
26
  // We will just log and allow for the SDK to end up throwing an SDK_TIMEOUT event for devs to handle.
30
27
  (0, apiKey_1.validateAndTrackApiKey)(log, settings.core.authorizationKey);
31
28
  var sdkReadinessManager = (0, sdkReadinessManager_1.sdkReadinessManagerFactory)(log, platform.EventEmitter, settings.startup.readyTimeout);
32
29
  var readiness = sdkReadinessManager.readinessManager;
33
- // @TODO consider passing the settings object, so that each storage access only what it needs
34
- var storageFactoryParams = {
35
- impressionsQueueSize: settings.scheduler.impressionsQueueSize,
36
- eventsQueueSize: settings.scheduler.eventsQueueSize,
37
- uniqueKeysCacheSize: settings.scheduler.uniqueKeysCacheSize,
38
- optimize: (0, utils_1.shouldBeOptimized)(settings),
39
- // ATM, only used by InLocalStorage
40
- matchingKey: (0, key_1.getMatching)(settings.core.key),
41
- splitFiltersValidation: settings.sync.__splitFiltersValidation,
42
- // ATM, only used by PluggableStorage
43
- mode: settings.mode,
44
- impressionsMode: settings.sync.impressionsMode,
45
- // Callback used to emit SDK_READY in consumer mode, where `syncManagerFactory` is undefined,
46
- // or partial consumer mode, where it only has submitters, and therefore it doesn't emit readiness events.
30
+ var storage = storageFactory({
31
+ settings: settings,
47
32
  onReadyCb: function (error) {
48
33
  if (error)
49
34
  return; // Don't emit SDK_READY if storage failed to connect. Error message is logged by wrapperAdapter
50
35
  readiness.splits.emit(constants_2.SDK_SPLITS_ARRIVED);
51
36
  readiness.segments.emit(constants_2.SDK_SEGMENTS_ARRIVED);
52
37
  },
53
- metadata: (0, metadataBuilder_1.metadataBuilder)(settings),
54
- log: log
55
- };
56
- var storage = storageFactory(storageFactoryParams);
38
+ });
57
39
  // @TODO add support for dataloader: `if (params.dataLoader) params.dataLoader(storage);`
58
40
  var telemetryTracker = (0, telemetryTracker_1.telemetryTrackerFactory)(storage.telemetry, platform.now);
59
41
  var integrationsManager = integrationsManagerFactory && integrationsManagerFactory({ settings: settings, storage: storage, telemetryTracker: telemetryTracker });
60
42
  var observer = impressionsObserverFactory();
61
- var uniqueKeysTracker = storageFactoryParams.impressionsMode === constants_3.NONE ? (0, uniqueKeysTracker_1.uniqueKeysTrackerFactory)(log, storage.uniqueKeys, filterAdapterFactory && filterAdapterFactory()) : undefined;
43
+ var uniqueKeysTracker = impressionsMode === constants_3.NONE ? (0, uniqueKeysTracker_1.uniqueKeysTrackerFactory)(log, storage.uniqueKeys, filterAdapterFactory && filterAdapterFactory()) : undefined;
62
44
  var strategy;
63
- switch (storageFactoryParams.impressionsMode) {
45
+ switch (impressionsMode) {
64
46
  case constants_3.OPTIMIZED:
65
47
  strategy = (0, strategyOptimized_1.strategyOptimizedFactory)(observer, storage.impressionCounts);
66
48
  break;
@@ -95,7 +77,7 @@ function sdkFactory(params) {
95
77
  return managerInstance;
96
78
  },
97
79
  // Logger wrapper API
98
- Logger: (0, sdkLogger_1.createLoggerAPI)(settings.log),
80
+ Logger: (0, sdkLogger_1.createLoggerAPI)(log),
99
81
  settings: settings,
100
82
  }, extraProps && extraProps(ctx));
101
83
  }
@@ -110,13 +110,13 @@ function splitApiFactory(settings, platform, telemetryTracker) {
110
110
  var url = urls.telemetry + "/v1/keys/ss";
111
111
  return splitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(constants_1.TELEMETRY));
112
112
  },
113
- postMetricsConfig: function (body) {
113
+ postMetricsConfig: function (body, headers) {
114
114
  var url = urls.telemetry + "/v1/metrics/config";
115
- return splitHttpClient(url, { method: 'POST', body: body }, telemetryTracker.trackHttp(constants_1.TELEMETRY), true);
115
+ return splitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(constants_1.TELEMETRY), true);
116
116
  },
117
- postMetricsUsage: function (body) {
117
+ postMetricsUsage: function (body, headers) {
118
118
  var url = urls.telemetry + "/v1/metrics/usage";
119
- return splitHttpClient(url, { method: 'POST', body: body }, telemetryTracker.trackHttp(constants_1.TELEMETRY), true);
119
+ return splitHttpClient(url, { method: 'POST', body: body, headers: headers }, telemetryTracker.trackHttp(constants_1.TELEMETRY), true);
120
120
  }
121
121
  };
122
122
  }
@@ -28,7 +28,7 @@ var AbstractSplitsCacheAsync = /** @class */ (function () {
28
28
  * @param {string} name
29
29
  * @param {string} defaultTreatment
30
30
  * @param {number} changeNumber
31
- * @returns {Promise} a promise that is resolved once the split kill operation is performed. The fulfillment value is a boolean: `true` if the kill success updating the split or `false` if no split is updated,
31
+ * @returns {Promise} a promise that is resolved once the split kill operation is performed. The fulfillment value is a boolean: `true` if the operation successed updating the split or `false` if no split is updated,
32
32
  * for instance, if the `changeNumber` is old, or if the split is not found (e.g., `/splitchanges` hasn't been fetched yet), or if the storage fails to apply the update.
33
33
  * The promise will never be rejected.
34
34
  */
@@ -43,7 +43,7 @@ var AbstractSplitsCacheSync = /** @class */ (function () {
43
43
  * @param {string} name
44
44
  * @param {string} defaultTreatment
45
45
  * @param {number} changeNumber
46
- * @returns {Promise} a promise that is resolved once the split kill is performed. The fulfillment value is a boolean: `true` if the kill success updating the split or `false` if no split is updated,
46
+ * @returns {boolean} `true` if the operation successed updating the split, or `false` if no split is updated,
47
47
  * for instance, if the `changeNumber` is old, or if the split is not found (e.g., `/splitchanges` hasn't been fetched yet), or if the storage fails to apply the update.
48
48
  */
49
49
  AbstractSplitsCacheSync.prototype.killLocally = function (name, defaultTreatment, changeNumber) {
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.KeyBuilderSS = void 0;
3
+ exports.KeyBuilderSS = exports.METHOD_NAMES = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var KeyBuilder_1 = require("./KeyBuilder");
6
- var methodNames = {
6
+ exports.METHOD_NAMES = {
7
7
  t: 'treatment',
8
8
  ts: 'treatments',
9
9
  tc: 'treatmentWithConfig',
@@ -14,7 +14,10 @@ var KeyBuilderSS = /** @class */ (function (_super) {
14
14
  (0, tslib_1.__extends)(KeyBuilderSS, _super);
15
15
  function KeyBuilderSS(prefix, metadata) {
16
16
  var _this = _super.call(this, prefix) || this;
17
- _this.metadata = metadata;
17
+ _this.latencyPrefix = _this.prefix + ".telemetry.latencies";
18
+ _this.exceptionPrefix = _this.prefix + ".telemetry.exceptions";
19
+ _this.initPrefix = _this.prefix + ".telemetry.init";
20
+ _this.versionablePrefix = metadata.s + "/" + metadata.n + "/" + metadata.i;
18
21
  return _this;
19
22
  }
20
23
  KeyBuilderSS.prototype.buildRegisteredSegmentsKey = function () {
@@ -37,16 +40,13 @@ var KeyBuilderSS = /** @class */ (function (_super) {
37
40
  };
38
41
  /* Telemetry keys */
39
42
  KeyBuilderSS.prototype.buildLatencyKey = function (method, bucket) {
40
- return this.prefix + ".telemetry.latencies::" + this.buildVersionablePrefix() + "/" + methodNames[method] + "/" + bucket;
43
+ return this.latencyPrefix + "::" + this.versionablePrefix + "/" + exports.METHOD_NAMES[method] + "/" + bucket;
41
44
  };
42
45
  KeyBuilderSS.prototype.buildExceptionKey = function (method) {
43
- return this.prefix + ".telemetry.exceptions::" + this.buildVersionablePrefix() + "/" + methodNames[method];
46
+ return this.exceptionPrefix + "::" + this.versionablePrefix + "/" + exports.METHOD_NAMES[method];
44
47
  };
45
48
  KeyBuilderSS.prototype.buildInitKey = function () {
46
- return this.prefix + ".telemetry.init::" + this.buildVersionablePrefix();
47
- };
48
- KeyBuilderSS.prototype.buildVersionablePrefix = function () {
49
- return this.metadata.s + "/" + this.metadata.n + "/" + this.metadata.i;
49
+ return this.initPrefix + "::" + this.versionablePrefix;
50
50
  };
51
51
  return KeyBuilderSS;
52
52
  }(KeyBuilder_1.KeyBuilder));
@@ -203,7 +203,6 @@ var SplitsCacheInLocal = /** @class */ (function (_super) {
203
203
  };
204
204
  /**
205
205
  * Clean Splits cache if its `lastUpdated` timestamp is older than the given `expirationTimestamp`,
206
- * Clean operation (clear) also updates `lastUpdated` timestamp with current time.
207
206
  *
208
207
  * @param {number | undefined} expirationTimestamp if the value is not a number, data will not be cleaned
209
208
  */
@@ -16,7 +16,8 @@ var InMemoryStorageCS_1 = require("../inMemory/InMemoryStorageCS");
16
16
  var constants_1 = require("./constants");
17
17
  var constants_2 = require("../../utils/constants");
18
18
  var TelemetryCacheInMemory_1 = require("../inMemory/TelemetryCacheInMemory");
19
- var uniqueKeysCacheInMemoryCS_1 = require("../inMemory/uniqueKeysCacheInMemoryCS");
19
+ var UniqueKeysCacheInMemoryCS_1 = require("../inMemory/UniqueKeysCacheInMemoryCS");
20
+ var key_1 = require("../../utils/key");
20
21
  /**
21
22
  * InLocal storage factory for standalone client-side SplitFactory
22
23
  */
@@ -26,20 +27,23 @@ function InLocalStorage(options) {
26
27
  function InLocalStorageCSFactory(params) {
27
28
  // Fallback to InMemoryStorage if LocalStorage API is not available
28
29
  if (!(0, isLocalStorageAvailable_1.isLocalStorageAvailable)()) {
29
- params.log.warn(constants_1.LOG_PREFIX + 'LocalStorage API is unavailable. Falling back to default MEMORY storage');
30
+ params.settings.log.warn(constants_1.LOG_PREFIX + 'LocalStorage API is unavailable. Falling back to default MEMORY storage');
30
31
  return (0, InMemoryStorageCS_1.InMemoryStorageCSFactory)(params);
31
32
  }
32
- var log = params.log;
33
- var keys = new KeyBuilderCS_1.KeyBuilderCS(prefix, params.matchingKey);
33
+ var settings = params.settings, _a = params.settings, log = _a.log, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize, _c = _a.sync, impressionsMode = _c.impressionsMode, __splitFiltersValidation = _c.__splitFiltersValidation;
34
+ var matchingKey = (0, key_1.getMatching)(settings.core.key);
35
+ var keys = new KeyBuilderCS_1.KeyBuilderCS(prefix, matchingKey);
34
36
  var expirationTimestamp = Date.now() - browser_1.DEFAULT_CACHE_EXPIRATION_IN_MILLIS;
37
+ var splits = new SplitsCacheInLocal_1.SplitsCacheInLocal(log, keys, expirationTimestamp, __splitFiltersValidation);
38
+ var segments = new MySegmentsCacheInLocal_1.MySegmentsCacheInLocal(log, keys);
35
39
  return {
36
- splits: new SplitsCacheInLocal_1.SplitsCacheInLocal(log, keys, expirationTimestamp, params.splitFiltersValidation),
37
- segments: new MySegmentsCacheInLocal_1.MySegmentsCacheInLocal(log, keys),
38
- impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(params.impressionsQueueSize),
39
- impressionCounts: params.optimize ? new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory() : undefined,
40
- events: new EventsCacheInMemory_1.EventsCacheInMemory(params.eventsQueueSize),
41
- telemetry: params.mode !== constants_2.LOCALHOST_MODE && (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)() ? new TelemetryCacheInMemory_1.TelemetryCacheInMemory() : undefined,
42
- uniqueKeys: params.impressionsMode === constants_2.NONE ? new uniqueKeysCacheInMemoryCS_1.UniqueKeysCacheInMemoryCS() : undefined,
40
+ splits: splits,
41
+ segments: segments,
42
+ impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(impressionsQueueSize),
43
+ impressionCounts: impressionsMode !== constants_2.DEBUG ? new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory() : undefined,
44
+ events: new EventsCacheInMemory_1.EventsCacheInMemory(eventsQueueSize),
45
+ telemetry: (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)(params) ? new TelemetryCacheInMemory_1.TelemetryCacheInMemory(splits, segments) : undefined,
46
+ uniqueKeys: impressionsMode === constants_2.NONE ? new UniqueKeysCacheInMemoryCS_1.UniqueKeysCacheInMemoryCS() : undefined,
43
47
  destroy: function () {
44
48
  var _a;
45
49
  this.splits = new SplitsCacheInMemory_1.SplitsCacheInMemory();
@@ -8,21 +8,24 @@ var EventsCacheInMemory_1 = require("./EventsCacheInMemory");
8
8
  var ImpressionCountsCacheInMemory_1 = require("./ImpressionCountsCacheInMemory");
9
9
  var constants_1 = require("../../utils/constants");
10
10
  var TelemetryCacheInMemory_1 = require("./TelemetryCacheInMemory");
11
- var uniqueKeysCacheInMemory_1 = require("./uniqueKeysCacheInMemory");
11
+ var UniqueKeysCacheInMemory_1 = require("./UniqueKeysCacheInMemory");
12
12
  /**
13
13
  * InMemory storage factory for standalone server-side SplitFactory
14
14
  *
15
15
  * @param params parameters required by EventsCacheSync
16
16
  */
17
17
  function InMemoryStorageFactory(params) {
18
+ var _a = params.settings, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize, impressionsMode = _a.sync.impressionsMode;
19
+ var splits = new SplitsCacheInMemory_1.SplitsCacheInMemory();
20
+ var segments = new SegmentsCacheInMemory_1.SegmentsCacheInMemory();
18
21
  return {
19
- splits: new SplitsCacheInMemory_1.SplitsCacheInMemory(),
20
- segments: new SegmentsCacheInMemory_1.SegmentsCacheInMemory(),
21
- impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(params.impressionsQueueSize),
22
- impressionCounts: params.impressionsMode !== constants_1.DEBUG ? new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory() : undefined,
23
- events: new EventsCacheInMemory_1.EventsCacheInMemory(params.eventsQueueSize),
24
- telemetry: params.mode !== constants_1.LOCALHOST_MODE ? new TelemetryCacheInMemory_1.TelemetryCacheInMemory() : undefined,
25
- uniqueKeys: params.impressionsMode === constants_1.NONE ? new uniqueKeysCacheInMemory_1.UniqueKeysCacheInMemory(params.uniqueKeysCacheSize) : undefined,
22
+ splits: splits,
23
+ segments: segments,
24
+ impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(impressionsQueueSize),
25
+ impressionCounts: impressionsMode !== constants_1.DEBUG ? new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory() : undefined,
26
+ events: new EventsCacheInMemory_1.EventsCacheInMemory(eventsQueueSize),
27
+ telemetry: (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)(params) ? new TelemetryCacheInMemory_1.TelemetryCacheInMemory(splits, segments) : undefined,
28
+ uniqueKeys: impressionsMode === constants_1.NONE ? new UniqueKeysCacheInMemory_1.UniqueKeysCacheInMemory() : undefined,
26
29
  // When using MEMORY we should clean all the caches to leave them empty
27
30
  destroy: function () {
28
31
  var _a;
@@ -8,21 +8,24 @@ var EventsCacheInMemory_1 = require("./EventsCacheInMemory");
8
8
  var ImpressionCountsCacheInMemory_1 = require("./ImpressionCountsCacheInMemory");
9
9
  var constants_1 = require("../../utils/constants");
10
10
  var TelemetryCacheInMemory_1 = require("./TelemetryCacheInMemory");
11
- var uniqueKeysCacheInMemoryCS_1 = require("./uniqueKeysCacheInMemoryCS");
11
+ var UniqueKeysCacheInMemoryCS_1 = require("./UniqueKeysCacheInMemoryCS");
12
12
  /**
13
13
  * InMemory storage factory for standalone client-side SplitFactory
14
14
  *
15
15
  * @param params parameters required by EventsCacheSync
16
16
  */
17
17
  function InMemoryStorageCSFactory(params) {
18
+ var _a = params.settings, _b = _a.scheduler, impressionsQueueSize = _b.impressionsQueueSize, eventsQueueSize = _b.eventsQueueSize, impressionsMode = _a.sync.impressionsMode;
19
+ var splits = new SplitsCacheInMemory_1.SplitsCacheInMemory();
20
+ var segments = new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory();
18
21
  return {
19
- splits: new SplitsCacheInMemory_1.SplitsCacheInMemory(),
20
- segments: new MySegmentsCacheInMemory_1.MySegmentsCacheInMemory(),
21
- impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(params.impressionsQueueSize),
22
- impressionCounts: params.impressionsMode !== constants_1.DEBUG ? new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory() : undefined,
23
- events: new EventsCacheInMemory_1.EventsCacheInMemory(params.eventsQueueSize),
24
- telemetry: params.mode !== constants_1.LOCALHOST_MODE && (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)() ? new TelemetryCacheInMemory_1.TelemetryCacheInMemory() : undefined,
25
- uniqueKeys: params.impressionsMode === constants_1.NONE ? new uniqueKeysCacheInMemoryCS_1.UniqueKeysCacheInMemoryCS(params.uniqueKeysCacheSize) : undefined,
22
+ splits: splits,
23
+ segments: segments,
24
+ impressions: new ImpressionsCacheInMemory_1.ImpressionsCacheInMemory(impressionsQueueSize),
25
+ impressionCounts: impressionsMode !== constants_1.DEBUG ? new ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory() : undefined,
26
+ events: new EventsCacheInMemory_1.EventsCacheInMemory(eventsQueueSize),
27
+ telemetry: (0, TelemetryCacheInMemory_1.shouldRecordTelemetry)(params) ? new TelemetryCacheInMemory_1.TelemetryCacheInMemory(splits, segments) : undefined,
28
+ uniqueKeys: impressionsMode === constants_1.NONE ? new UniqueKeysCacheInMemoryCS_1.UniqueKeysCacheInMemoryCS() : undefined,
26
29
  // When using MEMORY we should clean all the caches to leave them empty
27
30
  destroy: function () {
28
31
  var _a;
@@ -1,41 +1,72 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TelemetryCacheInMemory = exports.shouldRecordTelemetry = void 0;
3
+ exports.TelemetryCacheInMemory = exports.shouldRecordTelemetry = exports.newBuckets = exports.MAX_LATENCY_BUCKET_COUNT = void 0;
4
+ var constants_1 = require("../../utils/constants");
4
5
  var findLatencyIndex_1 = require("../findLatencyIndex");
5
6
  var MAX_STREAMING_EVENTS = 20;
6
7
  var MAX_TAGS = 10;
8
+ exports.MAX_LATENCY_BUCKET_COUNT = 23;
7
9
  function newBuckets() {
8
- // MAX_LATENCY_BUCKET_COUNT (length) is 23;
10
+ // MAX_LATENCY_BUCKET_COUNT (length) is 23
11
+ // Not using Array.fill for old browsers compatibility
9
12
  return [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
10
13
  }
14
+ exports.newBuckets = newBuckets;
11
15
  var ACCEPTANCE_RANGE = 0.001;
12
16
  /**
13
- * Used on client-side. 0.1% of instances will track telemetry
17
+ * Record telemetry if mode is not localhost.
18
+ * All factory instances track telemetry on server-side, and 0.1% on client-side.
14
19
  */
15
- function shouldRecordTelemetry() {
16
- return Math.random() <= ACCEPTANCE_RANGE;
20
+ function shouldRecordTelemetry(_a) {
21
+ var settings = _a.settings;
22
+ return settings.mode !== constants_1.LOCALHOST_MODE && (settings.core.key === undefined || Math.random() <= ACCEPTANCE_RANGE);
17
23
  }
18
24
  exports.shouldRecordTelemetry = shouldRecordTelemetry;
19
25
  var TelemetryCacheInMemory = /** @class */ (function () {
20
- function TelemetryCacheInMemory() {
26
+ function TelemetryCacheInMemory(splits, segments) {
27
+ this.splits = splits;
28
+ this.segments = segments;
29
+ // isEmpty flag
30
+ this.e = true;
21
31
  this.notReadyUsage = 0;
32
+ /** Usage stats */
22
33
  this.impressionStats = [0, 0, 0];
23
34
  this.eventStats = [0, 0];
24
- // @ts-expect-error
25
35
  this.lastSync = {};
26
- // @ts-expect-error
27
36
  this.httpErrors = {};
28
- // @ts-expect-error
29
37
  this.httpLatencies = {};
30
38
  this.authRejections = 0;
31
39
  this.tokenRefreshes = 0;
32
40
  this.streamingEvents = [];
33
41
  this.tags = [];
34
- // @ts-expect-error
35
42
  this.exceptions = {};
36
- // @ts-expect-error
37
43
  this.latencies = {};
38
44
  }
45
+ TelemetryCacheInMemory.prototype.isEmpty = function () { return this.e; };
46
+ TelemetryCacheInMemory.prototype.clear = function () { };
47
+ TelemetryCacheInMemory.prototype.pop = function () {
48
+ this.e = true;
49
+ return {
50
+ lS: this.getLastSynchronization(),
51
+ mL: this.popLatencies(),
52
+ mE: this.popExceptions(),
53
+ hE: this.popHttpErrors(),
54
+ hL: this.popHttpLatencies(),
55
+ tR: this.popTokenRefreshes(),
56
+ aR: this.popAuthRejections(),
57
+ iQ: this.getImpressionStats(constants_1.QUEUED),
58
+ iDe: this.getImpressionStats(constants_1.DEDUPED),
59
+ iDr: this.getImpressionStats(constants_1.DROPPED),
60
+ spC: this.splits && this.splits.getSplitNames().length,
61
+ seC: this.segments && this.segments.getRegisteredSegments().length,
62
+ skC: this.segments && this.segments.getKeysCount(),
63
+ sL: this.getSessionLength(),
64
+ eQ: this.getEventStats(constants_1.QUEUED),
65
+ eD: this.getEventStats(constants_1.DROPPED),
66
+ sE: this.popStreamingEvents(),
67
+ t: this.popTags(),
68
+ };
69
+ };
39
70
  TelemetryCacheInMemory.prototype.getTimeUntilReady = function () {
40
71
  return this.timeUntilReady;
41
72
  };
@@ -59,44 +90,41 @@ var TelemetryCacheInMemory = /** @class */ (function () {
59
90
  };
60
91
  TelemetryCacheInMemory.prototype.recordImpressionStats = function (type, count) {
61
92
  this.impressionStats[type] += count;
93
+ this.e = false;
62
94
  };
63
95
  TelemetryCacheInMemory.prototype.getEventStats = function (type) {
64
96
  return this.eventStats[type];
65
97
  };
66
98
  TelemetryCacheInMemory.prototype.recordEventStats = function (type, count) {
67
99
  this.eventStats[type] += count;
100
+ this.e = false;
68
101
  };
69
102
  TelemetryCacheInMemory.prototype.getLastSynchronization = function () {
70
103
  return this.lastSync;
71
104
  };
72
105
  TelemetryCacheInMemory.prototype.recordSuccessfulSync = function (resource, timeMs) {
73
106
  this.lastSync[resource] = timeMs;
107
+ this.e = false;
74
108
  };
75
109
  TelemetryCacheInMemory.prototype.popHttpErrors = function () {
76
- var result = this.httpErrors; // @ts-expect-error
110
+ var result = this.httpErrors;
77
111
  this.httpErrors = {};
78
112
  return result;
79
113
  };
80
114
  TelemetryCacheInMemory.prototype.recordHttpError = function (resource, status) {
81
- if (!this.httpErrors[resource])
82
- this.httpErrors[resource] = {};
83
- if (!this.httpErrors[resource][status]) {
84
- this.httpErrors[resource][status] = 1;
85
- }
86
- else {
87
- this.httpErrors[resource][status]++;
88
- }
115
+ var statusErrors = (this.httpErrors[resource] = this.httpErrors[resource] || {});
116
+ statusErrors[status] = (statusErrors[status] || 0) + 1;
117
+ this.e = false;
89
118
  };
90
119
  TelemetryCacheInMemory.prototype.popHttpLatencies = function () {
91
- var result = this.httpLatencies; // @ts-expect-error
120
+ var result = this.httpLatencies;
92
121
  this.httpLatencies = {};
93
122
  return result;
94
123
  };
95
124
  TelemetryCacheInMemory.prototype.recordHttpLatency = function (resource, latencyMs) {
96
- if (!this.httpLatencies[resource]) {
97
- this.httpLatencies[resource] = newBuckets();
98
- }
99
- this.httpLatencies[resource][(0, findLatencyIndex_1.findLatencyIndex)(latencyMs)]++;
125
+ var latencyBuckets = (this.httpLatencies[resource] = this.httpLatencies[resource] || newBuckets());
126
+ latencyBuckets[(0, findLatencyIndex_1.findLatencyIndex)(latencyMs)]++;
127
+ this.e = false;
100
128
  };
101
129
  TelemetryCacheInMemory.prototype.popAuthRejections = function () {
102
130
  var result = this.authRejections;
@@ -105,6 +133,7 @@ var TelemetryCacheInMemory = /** @class */ (function () {
105
133
  };
106
134
  TelemetryCacheInMemory.prototype.recordAuthRejections = function () {
107
135
  this.authRejections++;
136
+ this.e = false;
108
137
  };
109
138
  TelemetryCacheInMemory.prototype.popTokenRefreshes = function () {
110
139
  var result = this.tokenRefreshes;
@@ -113,6 +142,7 @@ var TelemetryCacheInMemory = /** @class */ (function () {
113
142
  };
114
143
  TelemetryCacheInMemory.prototype.recordTokenRefreshes = function () {
115
144
  this.tokenRefreshes++;
145
+ this.e = false;
116
146
  };
117
147
  TelemetryCacheInMemory.prototype.popStreamingEvents = function () {
118
148
  return this.streamingEvents.splice(0);
@@ -121,6 +151,7 @@ var TelemetryCacheInMemory = /** @class */ (function () {
121
151
  if (this.streamingEvents.length < MAX_STREAMING_EVENTS) {
122
152
  this.streamingEvents.push(streamingEvent);
123
153
  }
154
+ this.e = false;
124
155
  };
125
156
  TelemetryCacheInMemory.prototype.popTags = function () {
126
157
  return this.tags.splice(0);
@@ -129,36 +160,33 @@ var TelemetryCacheInMemory = /** @class */ (function () {
129
160
  if (this.tags.length < MAX_TAGS) {
130
161
  this.tags.push(tag);
131
162
  }
163
+ this.e = false;
132
164
  };
133
165
  TelemetryCacheInMemory.prototype.getSessionLength = function () {
134
166
  return this.sessionLength;
135
167
  };
136
168
  TelemetryCacheInMemory.prototype.recordSessionLength = function (ms) {
137
169
  this.sessionLength = ms;
170
+ this.e = false;
138
171
  };
139
172
  TelemetryCacheInMemory.prototype.popExceptions = function () {
140
- var result = this.exceptions; // @ts-expect-error
173
+ var result = this.exceptions;
141
174
  this.exceptions = {};
142
175
  return result;
143
176
  };
144
177
  TelemetryCacheInMemory.prototype.recordException = function (method) {
145
- if (!this.exceptions[method]) {
146
- this.exceptions[method] = 1;
147
- }
148
- else {
149
- this.exceptions[method]++;
150
- }
178
+ this.exceptions[method] = (this.exceptions[method] || 0) + 1;
179
+ this.e = false;
151
180
  };
152
181
  TelemetryCacheInMemory.prototype.popLatencies = function () {
153
- var result = this.latencies; // @ts-expect-error
182
+ var result = this.latencies;
154
183
  this.latencies = {};
155
184
  return result;
156
185
  };
157
186
  TelemetryCacheInMemory.prototype.recordLatency = function (method, latencyMs) {
158
- if (!this.latencies[method]) {
159
- this.latencies[method] = newBuckets();
160
- }
161
- this.latencies[method][(0, findLatencyIndex_1.findLatencyIndex)(latencyMs)]++;
187
+ var latencyBuckets = (this.latencies[method] = this.latencies[method] || newBuckets());
188
+ latencyBuckets[(0, findLatencyIndex_1.findLatencyIndex)(latencyMs)]++;
189
+ this.e = false;
162
190
  };
163
191
  return TelemetryCacheInMemory;
164
192
  }());