@splitsoftware/splitio-commons 1.6.2-rc.5 → 1.6.2-rc.6

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 (178) hide show
  1. package/cjs/consent/sdkUserConsent.js +2 -2
  2. package/cjs/evaluator/index.js +10 -11
  3. package/cjs/integrations/ga/GaToSplit.js +8 -5
  4. package/cjs/listeners/browser.js +1 -2
  5. package/cjs/logger/constants.js +1 -2
  6. package/cjs/sdkFactory/index.js +7 -25
  7. package/cjs/sdkManager/index.js +3 -11
  8. package/cjs/services/splitApi.js +0 -20
  9. package/cjs/storages/AbstractSplitsCacheAsync.js +7 -9
  10. package/cjs/storages/AbstractSplitsCacheSync.js +7 -9
  11. package/cjs/storages/KeyBuilderSS.js +0 -6
  12. package/cjs/storages/dataLoader.js +1 -1
  13. package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +5 -6
  14. package/cjs/storages/inLocalStorage/index.js +0 -4
  15. package/cjs/storages/inMemory/ImpressionCountsCacheInMemory.js +1 -12
  16. package/cjs/storages/inMemory/InMemoryStorage.js +1 -5
  17. package/cjs/storages/inMemory/InMemoryStorageCS.js +1 -5
  18. package/cjs/storages/inMemory/SplitsCacheInMemory.js +7 -10
  19. package/cjs/storages/inRedis/SplitsCacheInRedis.js +15 -9
  20. package/cjs/storages/inRedis/constants.js +1 -4
  21. package/cjs/storages/inRedis/index.js +1 -15
  22. package/cjs/storages/pluggable/SplitsCachePluggable.js +14 -9
  23. package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +2 -3
  24. package/cjs/sync/polling/updaters/splitChangesUpdater.js +1 -1
  25. package/cjs/sync/submitters/submitterManager.js +0 -3
  26. package/cjs/sync/submitters/telemetrySubmitter.js +0 -1
  27. package/cjs/trackers/impressionsTracker.js +41 -22
  28. package/cjs/trackers/telemetryTracker.js +6 -0
  29. package/cjs/utils/constants/index.js +2 -4
  30. package/cjs/utils/settingsValidation/impressionsMode.js +2 -2
  31. package/cjs/utils/settingsValidation/index.js +0 -3
  32. package/esm/consent/sdkUserConsent.js +2 -2
  33. package/esm/evaluator/index.js +10 -11
  34. package/esm/integrations/ga/GaToSplit.js +8 -5
  35. package/esm/listeners/browser.js +2 -3
  36. package/esm/logger/constants.js +0 -1
  37. package/esm/sdkFactory/index.js +7 -25
  38. package/esm/sdkManager/index.js +3 -11
  39. package/esm/services/splitApi.js +0 -20
  40. package/esm/storages/AbstractSplitsCacheAsync.js +7 -9
  41. package/esm/storages/AbstractSplitsCacheSync.js +7 -9
  42. package/esm/storages/KeyBuilderSS.js +0 -6
  43. package/esm/storages/dataLoader.js +1 -1
  44. package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +5 -6
  45. package/esm/storages/inLocalStorage/index.js +1 -5
  46. package/esm/storages/inMemory/ImpressionCountsCacheInMemory.js +1 -12
  47. package/esm/storages/inMemory/InMemoryStorage.js +2 -6
  48. package/esm/storages/inMemory/InMemoryStorageCS.js +2 -6
  49. package/esm/storages/inMemory/SplitsCacheInMemory.js +7 -10
  50. package/esm/storages/inRedis/SplitsCacheInRedis.js +15 -9
  51. package/esm/storages/inRedis/constants.js +0 -3
  52. package/esm/storages/inRedis/index.js +2 -16
  53. package/esm/storages/pluggable/SplitsCachePluggable.js +14 -9
  54. package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +2 -3
  55. package/esm/sync/polling/updaters/splitChangesUpdater.js +1 -1
  56. package/esm/sync/submitters/submitterManager.js +0 -3
  57. package/esm/sync/submitters/telemetrySubmitter.js +1 -2
  58. package/esm/trackers/impressionsTracker.js +41 -22
  59. package/esm/trackers/telemetryTracker.js +6 -0
  60. package/esm/utils/constants/index.js +0 -2
  61. package/esm/utils/settingsValidation/impressionsMode.js +3 -3
  62. package/esm/utils/settingsValidation/index.js +0 -3
  63. package/package.json +1 -1
  64. package/src/consent/sdkUserConsent.ts +2 -2
  65. package/src/evaluator/index.ts +8 -9
  66. package/src/integrations/ga/GaToSplit.ts +9 -5
  67. package/src/integrations/types.ts +2 -1
  68. package/src/listeners/browser.ts +2 -3
  69. package/src/logger/.DS_Store +0 -0
  70. package/src/logger/constants.ts +0 -1
  71. package/src/sdkFactory/index.ts +7 -28
  72. package/src/sdkFactory/types.ts +4 -7
  73. package/src/sdkManager/index.ts +3 -12
  74. package/src/services/splitApi.ts +0 -22
  75. package/src/services/types.ts +0 -6
  76. package/src/storages/AbstractSplitsCacheAsync.ts +13 -14
  77. package/src/storages/AbstractSplitsCacheSync.ts +14 -16
  78. package/src/storages/KeyBuilderSS.ts +0 -8
  79. package/src/storages/dataLoader.ts +1 -1
  80. package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +8 -10
  81. package/src/storages/inLocalStorage/index.ts +1 -4
  82. package/src/storages/inMemory/ImpressionCountsCacheInMemory.ts +1 -16
  83. package/src/storages/inMemory/InMemoryStorage.ts +2 -5
  84. package/src/storages/inMemory/InMemoryStorageCS.ts +2 -6
  85. package/src/storages/inMemory/SplitsCacheInMemory.ts +10 -14
  86. package/src/storages/inRedis/SplitsCacheInRedis.ts +21 -17
  87. package/src/storages/inRedis/constants.ts +0 -3
  88. package/src/storages/inRedis/index.ts +3 -12
  89. package/src/storages/pluggable/SplitsCachePluggable.ts +20 -17
  90. package/src/storages/types.ts +21 -40
  91. package/src/sync/offline/syncTasks/fromObjectSyncTask.ts +5 -6
  92. package/src/sync/polling/updaters/splitChangesUpdater.ts +2 -2
  93. package/src/sync/submitters/submitterManager.ts +0 -2
  94. package/src/sync/submitters/telemetrySubmitter.ts +3 -4
  95. package/src/sync/submitters/types.ts +1 -20
  96. package/src/trackers/impressionsTracker.ts +48 -27
  97. package/src/trackers/telemetryTracker.ts +7 -2
  98. package/src/trackers/types.ts +4 -26
  99. package/src/types.ts +1 -3
  100. package/src/utils/constants/index.ts +0 -2
  101. package/src/utils/settingsValidation/impressionsMode.ts +3 -3
  102. package/src/utils/settingsValidation/index.ts +0 -4
  103. package/types/integrations/types.d.ts +2 -1
  104. package/types/logger/constants.d.ts +0 -1
  105. package/types/sdkFactory/types.d.ts +2 -4
  106. package/types/services/types.d.ts +0 -4
  107. package/types/storages/AbstractSplitsCacheAsync.d.ts +6 -5
  108. package/types/storages/AbstractSplitsCacheSync.d.ts +5 -5
  109. package/types/storages/KeyBuilderSS.d.ts +0 -2
  110. package/types/storages/inLocalStorage/SplitsCacheInLocal.d.ts +3 -3
  111. package/types/storages/inMemory/ImpressionCountsCacheInMemory.d.ts +1 -5
  112. package/types/storages/inMemory/SplitsCacheInMemory.d.ts +3 -2
  113. package/types/storages/inRedis/SplitsCacheInRedis.d.ts +6 -5
  114. package/types/storages/inRedis/constants.d.ts +0 -3
  115. package/types/storages/pluggable/SplitsCachePluggable.d.ts +6 -5
  116. package/types/storages/types.d.ts +18 -28
  117. package/types/sync/polling/updaters/splitChangesUpdater.d.ts +1 -1
  118. package/types/sync/submitters/types.d.ts +1 -18
  119. package/types/trackers/impressionsTracker.d.ts +6 -4
  120. package/types/trackers/types.d.ts +4 -21
  121. package/types/types.d.ts +1 -3
  122. package/types/utils/constants/index.d.ts +0 -2
  123. package/types/utils/settingsValidation/index.d.ts +0 -1
  124. package/cjs/storages/inMemory/uniqueKeysCacheInMemory.js +0 -73
  125. package/cjs/storages/inMemory/uniqueKeysCacheInMemoryCS.js +0 -78
  126. package/cjs/storages/inRedis/ImpressionCountsCacheInRedis.js +0 -46
  127. package/cjs/storages/inRedis/uniqueKeysCacheInRedis.js +0 -55
  128. package/cjs/sync/submitters/uniqueKeysSubmitter.js +0 -26
  129. package/cjs/trackers/strategy/strategyDebug.js +0 -25
  130. package/cjs/trackers/strategy/strategyNone.js +0 -29
  131. package/cjs/trackers/strategy/strategyOptimized.js +0 -34
  132. package/cjs/trackers/uniqueKeysTracker.js +0 -31
  133. package/esm/storages/inMemory/uniqueKeysCacheInMemory.js +0 -70
  134. package/esm/storages/inMemory/uniqueKeysCacheInMemoryCS.js +0 -75
  135. package/esm/storages/inRedis/ImpressionCountsCacheInRedis.js +0 -43
  136. package/esm/storages/inRedis/uniqueKeysCacheInRedis.js +0 -52
  137. package/esm/sync/submitters/uniqueKeysSubmitter.js +0 -22
  138. package/esm/trackers/strategy/strategyDebug.js +0 -21
  139. package/esm/trackers/strategy/strategyNone.js +0 -25
  140. package/esm/trackers/strategy/strategyOptimized.js +0 -30
  141. package/esm/trackers/uniqueKeysTracker.js +0 -27
  142. package/src/storages/inMemory/uniqueKeysCacheInMemory.ts +0 -82
  143. package/src/storages/inMemory/uniqueKeysCacheInMemoryCS.ts +0 -88
  144. package/src/storages/inRedis/ImpressionCountsCacheInRedis.ts +0 -48
  145. package/src/storages/inRedis/uniqueKeysCacheInRedis.ts +0 -61
  146. package/src/sync/submitters/uniqueKeysSubmitter.ts +0 -35
  147. package/src/trackers/strategy/strategyDebug.ts +0 -28
  148. package/src/trackers/strategy/strategyNone.ts +0 -34
  149. package/src/trackers/strategy/strategyOptimized.ts +0 -42
  150. package/src/trackers/uniqueKeysTracker.ts +0 -37
  151. package/types/sdkClient/types.d.ts +0 -18
  152. package/types/storages/inMemory/CountsCacheInMemory.d.ts +0 -20
  153. package/types/storages/inMemory/LatenciesCacheInMemory.d.ts +0 -20
  154. package/types/storages/inMemory/uniqueKeysCacheInMemory.d.ts +0 -35
  155. package/types/storages/inMemory/uniqueKeysCacheInMemoryCS.d.ts +0 -37
  156. package/types/storages/inRedis/CountsCacheInRedis.d.ts +0 -9
  157. package/types/storages/inRedis/ImpressionCountsCacheInRedis.d.ts +0 -13
  158. package/types/storages/inRedis/LatenciesCacheInRedis.d.ts +0 -9
  159. package/types/storages/inRedis/uniqueKeysCacheInRedis.d.ts +0 -14
  160. package/types/sync/offline/LocalhostFromFile.d.ts +0 -2
  161. package/types/sync/offline/splitsParser/splitsParserFromFile.d.ts +0 -2
  162. package/types/sync/submitters/eventsSyncTask.d.ts +0 -8
  163. package/types/sync/submitters/impressionCountsSubmitterInRedis.d.ts +0 -5
  164. package/types/sync/submitters/impressionCountsSyncTask.d.ts +0 -13
  165. package/types/sync/submitters/impressionsSyncTask.d.ts +0 -14
  166. package/types/sync/submitters/metricsSyncTask.d.ts +0 -12
  167. package/types/sync/submitters/submitterSyncTask.d.ts +0 -10
  168. package/types/sync/submitters/uniqueKeysSubmitter.d.ts +0 -5
  169. package/types/sync/submitters/uniqueKeysSubmitterInRedis.d.ts +0 -5
  170. package/types/sync/syncTaskComposite.d.ts +0 -5
  171. package/types/trackers/filter/bloomFilter.d.ts +0 -10
  172. package/types/trackers/filter/dictionaryFilter.d.ts +0 -8
  173. package/types/trackers/filter/types.d.ts +0 -5
  174. package/types/trackers/strategy/strategyDebug.d.ts +0 -9
  175. package/types/trackers/strategy/strategyNone.d.ts +0 -10
  176. package/types/trackers/strategy/strategyOptimized.d.ts +0 -11
  177. package/types/trackers/uniqueKeysTracker.d.ts +0 -13
  178. package/types/utils/timeTracker/index.d.ts +0 -70
@@ -4,7 +4,6 @@ import { impressionCountsSubmitterFactory } from './impressionCountsSubmitter';
4
4
  import { telemetrySubmitterFactory } from './telemetrySubmitter';
5
5
  import { ISdkFactoryContextSync } from '../../sdkFactory/types';
6
6
  import { ISubmitterManager } from './types';
7
- import { uniqueKeysSubmitterFactory } from './uniqueKeysSubmitter';
8
7
 
9
8
  export function submitterManagerFactory(params: ISdkFactoryContextSync): ISubmitterManager {
10
9
 
@@ -16,7 +15,6 @@ export function submitterManagerFactory(params: ISdkFactoryContextSync): ISubmit
16
15
  const impressionCountsSubmitter = impressionCountsSubmitterFactory(params);
17
16
  if (impressionCountsSubmitter) submitters.push(impressionCountsSubmitter);
18
17
  const telemetrySubmitter = telemetrySubmitterFactory(params);
19
- if (params.uniqueKeysTracker) submitters.push(uniqueKeysSubmitterFactory(params));
20
18
 
21
19
  return {
22
20
  // `onlyTelemetry` true if SDK is created with userConsent not GRANTED
@@ -1,7 +1,7 @@
1
1
  import { ISegmentsCacheSync, ISplitsCacheSync, ITelemetryCacheSync } from '../../storages/types';
2
2
  import { submitterFactory, firstPushWindowDecorator } from './submitter';
3
3
  import { TelemetryUsageStatsPayload, TelemetryConfigStatsPayload, TelemetryConfigStats } from './types';
4
- import { QUEUED, DEDUPED, DROPPED, CONSUMER_MODE, CONSUMER_ENUM, STANDALONE_MODE, CONSUMER_PARTIAL_MODE, STANDALONE_ENUM, CONSUMER_PARTIAL_ENUM, OPTIMIZED, DEBUG, NONE, DEBUG_ENUM, OPTIMIZED_ENUM, NONE_ENUM, CONSENT_GRANTED, CONSENT_DECLINED, CONSENT_UNKNOWN } from '../../utils/constants';
4
+ import { QUEUED, DEDUPED, DROPPED, CONSUMER_MODE, CONSUMER_ENUM, STANDALONE_MODE, CONSUMER_PARTIAL_MODE, STANDALONE_ENUM, CONSUMER_PARTIAL_ENUM, OPTIMIZED, DEBUG, DEBUG_ENUM, OPTIMIZED_ENUM, CONSENT_GRANTED, CONSENT_DECLINED, CONSENT_UNKNOWN } from '../../utils/constants';
5
5
  import { SDK_READY, SDK_READY_FROM_CACHE } from '../../readiness/constants';
6
6
  import { ConsentStatus, ISettings, SDKMode } from '../../types';
7
7
  import { base } from '../../utils/settingsValidation';
@@ -52,9 +52,8 @@ const OPERATION_MODE_MAP = {
52
52
 
53
53
  const IMPRESSIONS_MODE_MAP = {
54
54
  [OPTIMIZED]: OPTIMIZED_ENUM,
55
- [DEBUG]: DEBUG_ENUM,
56
- [NONE]: NONE_ENUM
57
- } as Record<ISettings['sync']['impressionsMode'], (0 | 1 | 2)>;
55
+ [DEBUG]: DEBUG_ENUM
56
+ } as Record<ISettings['sync']['impressionsMode'], (0 | 1)>;
58
57
 
59
58
  const USER_CONSENT_MAP = {
60
59
  [CONSENT_UNKNOWN]: 1,
@@ -35,24 +35,6 @@ export type ImpressionCountsPayload = {
35
35
  }[]
36
36
  }
37
37
 
38
- export type UniqueKeysPayloadSs = {
39
- keys: {
40
- /** Split name */
41
- f: string
42
- /** keyNames */
43
- ks: string[]
44
- }[]
45
- }
46
-
47
- export type UniqueKeysPayloadCs = {
48
- keys: {
49
- /** keyNames */
50
- k: string
51
- /** Split name */
52
- fs: string[]
53
- }[]
54
- }
55
-
56
38
  export type StoredImpressionWithMetadata = {
57
39
  /** Metadata */
58
40
  m: IMetadata,
@@ -166,8 +148,7 @@ export type OperationMode = STANDALONE_ENUM | CONSUMER_ENUM | CONSUMER_PARTIAL_E
166
148
 
167
149
  export type OPTIMIZED_ENUM = 0;
168
150
  export type DEBUG_ENUM = 1;
169
- export type NONE_ENUM = 2;
170
- export type ImpressionsMode = OPTIMIZED_ENUM | DEBUG_ENUM | NONE_ENUM;
151
+ export type ImpressionsMode = OPTIMIZED_ENUM | DEBUG_ENUM;
171
152
 
172
153
  export type RefreshRates = {
173
154
  sp: number, // splits
@@ -1,8 +1,10 @@
1
1
  import { objectAssign } from '../utils/lang/objectAssign';
2
2
  import { thenable } from '../utils/promise/thenable';
3
- import { IImpressionsCacheBase, ITelemetryCacheSync, ITelemetryCacheAsync } from '../storages/types';
4
- import { IImpressionsHandler, IImpressionsTracker, IStrategy } from './types';
3
+ import { truncateTimeFrame } from '../utils/time';
4
+ import { IImpressionCountsCacheSync, IImpressionsCacheBase, ITelemetryCacheSync, ITelemetryCacheAsync } from '../storages/types';
5
+ import { IImpressionsHandler, IImpressionsTracker } from './types';
5
6
  import { SplitIO, ImpressionDTO, ISettings } from '../types';
7
+ import { IImpressionObserver } from './impressionObserver/types';
6
8
  import { IMPRESSIONS_TRACKER_SUCCESS, ERROR_IMPRESSIONS_TRACKER, ERROR_IMPRESSIONS_LISTENER } from '../logger/constants';
7
9
  import { CONSENT_DECLINED, DEDUPED, QUEUED } from '../utils/constants';
8
10
 
@@ -13,14 +15,18 @@ import { CONSENT_DECLINED, DEDUPED, QUEUED } from '../utils/constants';
13
15
  * @param metadata runtime metadata (ip, hostname and version)
14
16
  * @param impressionListener optional impression listener
15
17
  * @param integrationsManager optional integrations manager
16
- * @param strategy strategy for impressions tracking.
18
+ * @param observer optional impression observer. If provided, previous time (pt property) is included in impression instances
19
+ * @param countsCache optional cache to save impressions count. If provided, impressions will be deduped (OPTIMIZED mode)
17
20
  */
18
21
  export function impressionsTrackerFactory(
19
22
  settings: ISettings,
20
23
  impressionsCache: IImpressionsCacheBase,
21
- strategy: IStrategy,
22
24
  integrationsManager?: IImpressionsHandler,
23
- telemetryCache?: ITelemetryCacheSync | ITelemetryCacheAsync,
25
+ // if observer is provided, it implies `shouldAddPreviousTime` flag (i.e., if impressions previous time should be added or not)
26
+ observer?: IImpressionObserver,
27
+ // if countsCache is provided, it implies `isOptimized` flag (i.e., if impressions should be deduped or not)
28
+ countsCache?: IImpressionCountsCacheSync,
29
+ telemetryCache?: ITelemetryCacheSync | ITelemetryCacheAsync
24
30
  ): IImpressionsTracker {
25
31
 
26
32
  const { log, impressionListener, runtime: { ip, hostname }, version } = settings;
@@ -30,36 +36,51 @@ export function impressionsTrackerFactory(
30
36
  if (settings.userConsent === CONSENT_DECLINED) return;
31
37
 
32
38
  const impressionsCount = impressions.length;
33
- const { impressionsToStore, impressionsToListener, deduped } = strategy.process(impressions);
34
-
35
- const impressionsToListenerCount = impressionsToListener.length;
36
-
37
- if ( impressionsToStore.length>0 ){
38
- const res = impressionsCache.track(impressionsToStore);
39
39
 
40
- // If we're on an async storage, handle error and log it.
41
- if (thenable(res)) {
42
- res.then(() => {
43
- log.info(IMPRESSIONS_TRACKER_SUCCESS, [impressionsCount]);
44
- }).catch(err => {
45
- log.error(ERROR_IMPRESSIONS_TRACKER, [impressionsCount, err]);
46
- });
47
- } else {
48
- // Record when impressionsCache is sync only (standalone mode)
49
- // @TODO we are not dropping impressions on full queue yet, so DROPPED stats are not recorded
50
- if (telemetryCache) {
51
- (telemetryCache as ITelemetryCacheSync).recordImpressionStats(QUEUED, impressionsToStore.length);
52
- (telemetryCache as ITelemetryCacheSync).recordImpressionStats(DEDUPED, deduped);
53
- }
40
+ const impressionsToStore: ImpressionDTO[] = []; // Track only the impressions that are going to be stored
41
+ // Wraps impressions to store and adds previousTime if it corresponds
42
+ impressions.forEach((impression) => {
43
+ if (observer) {
44
+ // Adds previous time if it is enabled
45
+ impression.pt = observer.testAndSet(impression);
46
+ }
47
+
48
+ const now = Date.now();
49
+ if (countsCache) {
50
+ // Increments impression counter per featureName
51
+ countsCache.track(impression.feature, now, 1);
52
+ }
53
+
54
+ // Checks if the impression should be added in queue to be sent
55
+ if (!countsCache || !impression.pt || impression.pt < truncateTimeFrame(now)) {
56
+ impressionsToStore.push(impression);
57
+ }
58
+ });
59
+
60
+ const res = impressionsCache.track(impressionsToStore);
61
+
62
+ // If we're on an async storage, handle error and log it.
63
+ if (thenable(res)) {
64
+ res.then(() => {
65
+ log.info(IMPRESSIONS_TRACKER_SUCCESS, [impressionsCount]);
66
+ }).catch(err => {
67
+ log.error(ERROR_IMPRESSIONS_TRACKER, [impressionsCount, err]);
68
+ });
69
+ } else {
70
+ // Record when impressionsCache is sync only (standalone mode)
71
+ // @TODO we are not dropping impressions on full queue yet, so DROPPED stats are not recorded
72
+ if (telemetryCache) {
73
+ (telemetryCache as ITelemetryCacheSync).recordImpressionStats(QUEUED, impressionsToStore.length);
74
+ (telemetryCache as ITelemetryCacheSync).recordImpressionStats(DEDUPED, impressions.length - impressionsToStore.length);
54
75
  }
55
76
  }
56
77
 
57
78
  // @TODO next block might be handled by the integration manager. In that case, the metadata object doesn't need to be passed in the constructor
58
79
  if (impressionListener || integrationsManager) {
59
- for (let i = 0; i < impressionsToListenerCount; i++) {
80
+ for (let i = 0; i < impressionsCount; i++) {
60
81
  const impressionData: SplitIO.ImpressionData = {
61
82
  // copy of impression, to avoid unexpected behaviour if modified by integrations or impressionListener
62
- impression: objectAssign({}, impressionsToListener[i]),
83
+ impression: objectAssign({}, impressions[i]),
63
84
  attributes,
64
85
  ip,
65
86
  hostname,
@@ -48,6 +48,10 @@ export function telemetryTrackerFactory(
48
48
  });
49
49
  if (e === TOKEN_REFRESH) (telemetryCache as ITelemetryCacheSync).recordTokenRefreshes();
50
50
  }
51
+ },
52
+ addTag(tag: string) {
53
+ // @ts-ignore
54
+ if (telemetryCache.addTag) telemetryCache.addTag(tag);
51
55
  }
52
56
  };
53
57
 
@@ -56,8 +60,9 @@ export function telemetryTrackerFactory(
56
60
  return {
57
61
  trackEval: noopTrack,
58
62
  trackHttp: noopTrack,
59
- sessionLength: () => { },
60
- streamingEvent: () => { },
63
+ sessionLength() { },
64
+ streamingEvent() { },
65
+ addTag() { }
61
66
  };
62
67
  }
63
68
  }
@@ -41,30 +41,8 @@ export interface ITelemetryTracker {
41
41
  * Records streaming event
42
42
  */
43
43
  streamingEvent(e: StreamingEventType | AUTH_REJECTION, d?: number): void
44
- }
45
-
46
- export interface IFilterAdapter {
47
- add(key: string, featureName: string): boolean;
48
- contains(key: string, featureName: string): boolean;
49
- clear(): void;
50
- }
51
-
52
- export interface IImpressionSenderAdapter {
53
- recordUniqueKeys(data: Object): void;
54
- recordImpressionCounts(data: Object): void
55
- }
56
-
57
- /** Unique keys tracker */
58
- export interface IUniqueKeysTracker {
59
- track(key: string, featureName: string): void;
60
- }
61
-
62
- export interface IStrategyResult {
63
- impressionsToStore: ImpressionDTO[],
64
- impressionsToListener: ImpressionDTO[],
65
- deduped: number
66
- }
67
-
68
- export interface IStrategy {
69
- process(impressions: ImpressionDTO[]): IStrategyResult
44
+ /**
45
+ * Records tag
46
+ */
47
+ addTag(tag: string): void
70
48
  }
package/src/types.ts CHANGED
@@ -80,8 +80,6 @@ export interface ISettings {
80
80
  featuresRefreshRate: number,
81
81
  impressionsRefreshRate: number,
82
82
  impressionsQueueSize: number,
83
- uniqueKeysRefreshRate: number,
84
- uniqueKeysCacheSize: number,
85
83
  /**
86
84
  * @deprecated
87
85
  */
@@ -720,7 +718,7 @@ export namespace SplitIO {
720
718
  * ImpressionsMode type
721
719
  * @typedef {string} ImpressionsMode
722
720
  */
723
- export type ImpressionsMode = 'OPTIMIZED' | 'DEBUG' | 'NONE'
721
+ export type ImpressionsMode = 'OPTIMIZED' | 'DEBUG'
724
722
  /**
725
723
  * Defines the format of Split data to preload on the factory storage (cache).
726
724
  */
@@ -19,7 +19,6 @@ export const SPLIT_EVENT = 'EVENT';
19
19
  // Impression collection modes
20
20
  export const DEBUG = 'DEBUG';
21
21
  export const OPTIMIZED = 'OPTIMIZED';
22
- export const NONE = 'NONE';
23
22
 
24
23
  // SDK Modes
25
24
  export const LOCALHOST_MODE: SDKMode = 'localhost';
@@ -50,7 +49,6 @@ export const CONSUMER_PARTIAL_ENUM = 2;
50
49
 
51
50
  export const OPTIMIZED_ENUM = 0;
52
51
  export const DEBUG_ENUM = 1;
53
- export const NONE_ENUM = 2;
54
52
 
55
53
  export const SPLITS = 'sp';
56
54
  export const IMPRESSIONS = 'im';
@@ -1,14 +1,14 @@
1
1
  import { ERROR_INVALID_CONFIG_PARAM } from '../../logger/constants';
2
2
  import { ILogger } from '../../logger/types';
3
3
  import { SplitIO } from '../../types';
4
- import { DEBUG, OPTIMIZED, NONE } from '../constants';
4
+ import { DEBUG, OPTIMIZED } from '../constants';
5
5
  import { stringToUpperCase } from '../lang';
6
6
 
7
7
  export function validImpressionsMode(log: ILogger, impressionsMode: any): SplitIO.ImpressionsMode {
8
8
  impressionsMode = stringToUpperCase(impressionsMode);
9
9
 
10
- if ([DEBUG, OPTIMIZED, NONE].indexOf(impressionsMode) > -1) return impressionsMode;
10
+ if ([DEBUG, OPTIMIZED].indexOf(impressionsMode) > -1) return impressionsMode;
11
11
 
12
- log.error(ERROR_INVALID_CONFIG_PARAM, ['impressionsMode', [DEBUG, OPTIMIZED, NONE], OPTIMIZED]);
12
+ log.error(ERROR_INVALID_CONFIG_PARAM, ['impressionsMode', [DEBUG, OPTIMIZED], OPTIMIZED]);
13
13
  return OPTIMIZED;
14
14
  }
@@ -36,8 +36,6 @@ export const base = {
36
36
  telemetryRefreshRate: 3600,
37
37
  // publish evaluations each 300 sec (default value for OPTIMIZED impressions mode)
38
38
  impressionsRefreshRate: 300,
39
- // publish unique Keys each 900 sec (15 min)
40
- uniqueKeysRefreshRate: 900,
41
39
  // fetch offline changes each 15 sec
42
40
  offlineRefreshRate: 15,
43
41
  // publish events every 60 seconds after the first flush
@@ -132,13 +130,11 @@ export function settingsValidation(config: unknown, validationParams: ISettingsV
132
130
  scheduler.segmentsRefreshRate = fromSecondsToMillis(scheduler.segmentsRefreshRate);
133
131
  scheduler.offlineRefreshRate = fromSecondsToMillis(scheduler.offlineRefreshRate);
134
132
  scheduler.eventsPushRate = fromSecondsToMillis(scheduler.eventsPushRate);
135
- scheduler.uniqueKeysRefreshRate = fromSecondsToMillis(scheduler.uniqueKeysRefreshRate);
136
133
  scheduler.telemetryRefreshRate = fromSecondsToMillis(validateMinValue('telemetryRefreshRate', scheduler.telemetryRefreshRate, 60));
137
134
 
138
135
  // Default impressionsRefreshRate for DEBUG mode is 60 secs
139
136
  if (get(config, 'scheduler.impressionsRefreshRate') === undefined && withDefaults.sync.impressionsMode === DEBUG) scheduler.impressionsRefreshRate = 60;
140
137
  scheduler.impressionsRefreshRate = fromSecondsToMillis(scheduler.impressionsRefreshRate);
141
-
142
138
 
143
139
  // Log deprecation for old telemetry param
144
140
  if (scheduler.metricsRefreshRate) log.warn('`metricsRefreshRate` will be deprecated soon. For configuring telemetry rates, update `telemetryRefreshRate` value in configs');
@@ -1,5 +1,5 @@
1
1
  import { IEventsCacheBase } from '../storages/types';
2
- import { IEventsHandler, IImpressionsHandler } from '../trackers/types';
2
+ import { IEventsHandler, IImpressionsHandler, ITelemetryTracker } from '../trackers/types';
3
3
  import { ISettings, SplitIO } from '../types';
4
4
  export interface IIntegration {
5
5
  queue(data: SplitIO.IntegrationData): void;
@@ -10,6 +10,7 @@ export interface IIntegrationFactoryParams {
10
10
  events: IEventsCacheBase;
11
11
  };
12
12
  settings: ISettings;
13
+ telemetryTracker: ITelemetryTracker;
13
14
  }
14
15
  export declare type IntegrationFactory = {
15
16
  readonly type: string;
@@ -138,5 +138,4 @@ export declare const LOG_PREFIX_SYNC_POLLING: string;
138
138
  export declare const LOG_PREFIX_SYNC_SUBMITTERS: string;
139
139
  export declare const LOG_PREFIX_IMPRESSIONS_TRACKER = "impressions-tracker: ";
140
140
  export declare const LOG_PREFIX_EVENTS_TRACKER = "events-tracker: ";
141
- export declare const LOG_PREFIX_UNIQUE_KEYS_TRACKER = "unique-keys-tracker: ";
142
141
  export declare const LOG_PREFIX_CLEANUP = "cleanup: ";
@@ -6,7 +6,7 @@ import { IFetch, ISplitApi, IEventSourceConstructor } from '../services/types';
6
6
  import { IStorageAsync, IStorageSync, ISplitsCacheSync, ISplitsCacheAsync, IStorageFactoryParams } from '../storages/types';
7
7
  import { ISyncManager } from '../sync/types';
8
8
  import { IImpressionObserver } from '../trackers/impressionObserver/types';
9
- import { IImpressionsTracker, IEventTracker, ITelemetryTracker, IFilterAdapter, IUniqueKeysTracker } from '../trackers/types';
9
+ import { IImpressionsTracker, IEventTracker, ITelemetryTracker } from '../trackers/types';
10
10
  import { SplitIO, ISettings, IEventEmitter } from '../types';
11
11
  /**
12
12
  * Environment related dependencies.
@@ -42,7 +42,6 @@ export interface ISdkFactoryContext {
42
42
  eventTracker: IEventTracker;
43
43
  telemetryTracker: ITelemetryTracker;
44
44
  storage: IStorageSync | IStorageAsync;
45
- uniqueKeysTracker?: IUniqueKeysTracker;
46
45
  signalListener?: ISignalListener;
47
46
  splitApi?: ISplitApi;
48
47
  syncManager?: ISyncManager;
@@ -71,12 +70,11 @@ export interface ISdkFactoryParams {
71
70
  (): SplitIO.ICsClient;
72
71
  (key: SplitIO.SplitKey, trafficType?: string | undefined): SplitIO.ICsClient;
73
72
  } | (() => SplitIO.IClient) | (() => SplitIO.IAsyncClient));
74
- impressionsObserverFactory: () => IImpressionObserver;
75
- filterAdapterFactory?: () => IFilterAdapter;
76
73
  SignalListener?: new (syncManager: ISyncManager | undefined, // Used by NodeSignalListener to flush data, and by BrowserSignalListener to close streaming connection.
77
74
  settings: ISettings, // Used by BrowserSignalListener
78
75
  storage: IStorageSync | IStorageAsync, // Used by BrowserSignalListener
79
76
  serviceApi: ISplitApi | undefined) => ISignalListener;
80
77
  integrationsManagerFactory?: (params: IIntegrationFactoryParams) => IIntegrationManager | undefined;
78
+ impressionsObserverFactory?: () => IImpressionObserver;
81
79
  extraProps?: (params: ISdkFactoryContext) => object;
82
80
  }
@@ -20,8 +20,6 @@ export declare type IFetchSplitChanges = (since: number, noCache?: boolean, till
20
20
  export declare type IFetchSegmentChanges = (since: number, segmentName: string, noCache?: boolean, till?: number) => Promise<IResponse>;
21
21
  export declare type IFetchMySegments = (userMatchingKey: string, noCache?: boolean) => Promise<IResponse>;
22
22
  export declare type IPostEventsBulk = (body: string, headers?: Record<string, string>) => Promise<IResponse>;
23
- export declare type IPostUniqueKeysBulkCs = (body: string, headers?: Record<string, string>) => Promise<IResponse>;
24
- export declare type IPostUniqueKeysBulkSs = (body: string, headers?: Record<string, string>) => Promise<IResponse>;
25
23
  export declare type IPostTestImpressionsBulk = (body: string, headers?: Record<string, string>) => Promise<IResponse>;
26
24
  export declare type IPostTestImpressionsCount = (body: string, headers?: Record<string, string>) => Promise<IResponse>;
27
25
  export declare type IPostMetricsConfig = (body: string) => Promise<IResponse>;
@@ -34,8 +32,6 @@ export interface ISplitApi {
34
32
  fetchSegmentChanges: IFetchSegmentChanges;
35
33
  fetchMySegments: IFetchMySegments;
36
34
  postEventsBulk: IPostEventsBulk;
37
- postUniqueKeysBulkCs: IPostUniqueKeysBulkCs;
38
- postUniqueKeysBulkSs: IPostUniqueKeysBulkSs;
39
35
  postTestImpressionsBulk: IPostTestImpressionsBulk;
40
36
  postTestImpressionsCount: IPostTestImpressionsCount;
41
37
  postMetricsConfig: IPostMetricsConfig;
@@ -1,17 +1,18 @@
1
1
  import { ISplitsCacheAsync } from './types';
2
+ import { ISplit } from '../dtos/types';
2
3
  /**
3
4
  * This class provides a skeletal implementation of the ISplitsCacheAsync interface
4
5
  * to minimize the effort required to implement this interface.
5
6
  */
6
7
  export declare abstract class AbstractSplitsCacheAsync implements ISplitsCacheAsync {
7
- abstract addSplit(name: string, split: string): Promise<boolean>;
8
- abstract addSplits(entries: [string, string][]): Promise<boolean[] | void>;
8
+ abstract addSplit(name: string, split: ISplit): Promise<boolean>;
9
+ abstract addSplits(entries: [string, ISplit][]): Promise<boolean[] | void>;
9
10
  abstract removeSplits(names: string[]): Promise<boolean[] | void>;
10
- abstract getSplit(name: string): Promise<string | null>;
11
- abstract getSplits(names: string[]): Promise<Record<string, string | null>>;
11
+ abstract getSplit(name: string): Promise<ISplit | null>;
12
+ abstract getSplits(names: string[]): Promise<Record<string, ISplit | null>>;
12
13
  abstract setChangeNumber(changeNumber: number): Promise<boolean | void>;
13
14
  abstract getChangeNumber(): Promise<number>;
14
- abstract getAll(): Promise<string[]>;
15
+ abstract getAll(): Promise<ISplit[]>;
15
16
  abstract getSplitNames(): Promise<string[]>;
16
17
  abstract trafficTypeExists(trafficType: string): Promise<boolean>;
17
18
  abstract clear(): Promise<boolean | void>;
@@ -5,15 +5,15 @@ import { ISplit } from '../dtos/types';
5
5
  * to minimize the effort required to implement this interface.
6
6
  */
7
7
  export declare abstract class AbstractSplitsCacheSync implements ISplitsCacheSync {
8
- abstract addSplit(name: string, split: string): boolean;
9
- addSplits(entries: [string, string][]): boolean[];
8
+ abstract addSplit(name: string, split: ISplit): boolean;
9
+ addSplits(entries: [string, ISplit][]): boolean[];
10
10
  abstract removeSplit(name: string): boolean;
11
11
  removeSplits(names: string[]): boolean[];
12
- abstract getSplit(name: string): string | null;
13
- getSplits(names: string[]): Record<string, string | null>;
12
+ abstract getSplit(name: string): ISplit | null;
13
+ getSplits(names: string[]): Record<string, ISplit | null>;
14
14
  abstract setChangeNumber(changeNumber: number): boolean;
15
15
  abstract getChangeNumber(): number;
16
- getAll(): string[];
16
+ getAll(): ISplit[];
17
17
  abstract getSplitNames(): string[];
18
18
  abstract trafficTypeExists(trafficType: string): boolean;
19
19
  abstract usesSegments(): boolean;
@@ -6,8 +6,6 @@ export declare class KeyBuilderSS extends KeyBuilder {
6
6
  constructor(prefix: string, metadata: IMetadata);
7
7
  buildRegisteredSegmentsKey(): string;
8
8
  buildImpressionsKey(): string;
9
- buildImpressionsCountKey(): string;
10
- buildUniqueKeysKey(): string;
11
9
  buildEventsKey(): string;
12
10
  searchPatternForSplitKeys(): string;
13
11
  buildLatencyKey(method: Method, bucket: number): string;
@@ -1,4 +1,4 @@
1
- import { ISplitFiltersValidation } from '../../dtos/types';
1
+ import { ISplit, ISplitFiltersValidation } from '../../dtos/types';
2
2
  import { AbstractSplitsCacheSync } from '../AbstractSplitsCacheSync';
3
3
  import { KeyBuilderCS } from '../KeyBuilderCS';
4
4
  import { ILogger } from '../../logger/types';
@@ -26,9 +26,9 @@ export declare class SplitsCacheInLocal extends AbstractSplitsCacheSync {
26
26
  * We cannot simply call `localStorage.clear()` since that implies removing user items from the storage.
27
27
  */
28
28
  clear(): void;
29
- addSplit(name: string, split: string): boolean;
29
+ addSplit(name: string, split: ISplit): boolean;
30
30
  removeSplit(name: string): boolean;
31
- getSplit(name: string): string | null;
31
+ getSplit(name: string): any;
32
32
  setChangeNumber(changeNumber: number): boolean;
33
33
  getChangeNumber(): number;
34
34
  getSplitNames(): string[];
@@ -1,10 +1,6 @@
1
1
  import { IImpressionCountsCacheSync } from '../types';
2
2
  export declare class ImpressionCountsCacheInMemory implements IImpressionCountsCacheSync {
3
- protected cache: Record<string, number>;
4
- private readonly maxStorage;
5
- protected onFullQueue?: () => void;
6
- private cacheSize;
7
- constructor(impressionCountsCacheSize?: number);
3
+ private cache;
8
4
  /**
9
5
  * Builds key to be stored in the cache with the featureName and the timeFrame truncated.
10
6
  */
@@ -1,3 +1,4 @@
1
+ import { ISplit } from '../../dtos/types';
1
2
  import { AbstractSplitsCacheSync } from '../AbstractSplitsCacheSync';
2
3
  /**
3
4
  * Default ISplitsCacheSync implementation that stores split definitions in memory.
@@ -9,9 +10,9 @@ export declare class SplitsCacheInMemory extends AbstractSplitsCacheSync {
9
10
  private changeNumber;
10
11
  private splitsWithSegmentsCount;
11
12
  clear(): void;
12
- addSplit(name: string, split: string): boolean;
13
+ addSplit(name: string, split: ISplit): boolean;
13
14
  removeSplit(name: string): boolean;
14
- getSplit(name: string): string | null;
15
+ getSplit(name: string): ISplit | null;
15
16
  setChangeNumber(changeNumber: number): boolean;
16
17
  getChangeNumber(): number;
17
18
  getSplitNames(): string[];
@@ -1,6 +1,7 @@
1
1
  import { KeyBuilderSS } from '../KeyBuilderSS';
2
2
  import { Redis } from 'ioredis';
3
3
  import { ILogger } from '../../logger/types';
4
+ import { ISplit } from '../../dtos/types';
4
5
  import { AbstractSplitsCacheAsync } from '../AbstractSplitsCacheAsync';
5
6
  /**
6
7
  * ISplitsCacheAsync implementation that stores split definitions in Redis.
@@ -19,13 +20,13 @@ export declare class SplitsCacheInRedis extends AbstractSplitsCacheAsync {
19
20
  * The returned promise is resolved when the operation success
20
21
  * or rejected if it fails (e.g., redis operation fails)
21
22
  */
22
- addSplit(name: string, split: string): Promise<boolean>;
23
+ addSplit(name: string, split: ISplit): Promise<boolean>;
23
24
  /**
24
25
  * Add a list of splits.
25
26
  * The returned promise is resolved when the operation success
26
27
  * or rejected if it fails (e.g., redis operation fails)
27
28
  */
28
- addSplits(entries: [string, string][]): Promise<boolean[]>;
29
+ addSplits(entries: [string, ISplit][]): Promise<boolean[]>;
29
30
  /**
30
31
  * Remove a given split.
31
32
  * The returned promise is resolved when the operation success, with 1 or 0 indicating if the split existed or not.
@@ -42,7 +43,7 @@ export declare class SplitsCacheInRedis extends AbstractSplitsCacheAsync {
42
43
  * Get split definition or null if it's not defined.
43
44
  * Returned promise is rejected if redis operation fails.
44
45
  */
45
- getSplit(name: string): Promise<string | null>;
46
+ getSplit(name: string): Promise<ISplit | null>;
46
47
  /**
47
48
  * Set till number.
48
49
  * The returned promise is resolved when the operation success,
@@ -63,7 +64,7 @@ export declare class SplitsCacheInRedis extends AbstractSplitsCacheAsync {
63
64
  * @TODO we need to benchmark which is the maximun number of commands we could
64
65
  * pipeline without kill redis performance.
65
66
  */
66
- getAll(): Promise<string[]>;
67
+ getAll(): Promise<ISplit[]>;
67
68
  /**
68
69
  * Get list of split names.
69
70
  * The returned promise is resolved with the list of split names,
@@ -87,5 +88,5 @@ export declare class SplitsCacheInRedis extends AbstractSplitsCacheAsync {
87
88
  * Fetches multiple splits definitions.
88
89
  * Returned promise is rejected if redis operation fails.
89
90
  */
90
- getSplits(names: string[]): Promise<Record<string, string | null>>;
91
+ getSplits(names: string[]): Promise<Record<string, ISplit | null>>;
91
92
  }
@@ -1,4 +1 @@
1
1
  export declare const LOG_PREFIX = "storage:redis: ";
2
- export declare const DEFAULT_CACHE_SIZE = 30000;
3
- export declare const REFRESH_RATE = 300000;
4
- export declare const TTL_REFRESH = 3600;
@@ -1,6 +1,7 @@
1
1
  import { KeyBuilder } from '../KeyBuilder';
2
2
  import { IPluggableStorageWrapper } from '../types';
3
3
  import { ILogger } from '../../logger/types';
4
+ import { ISplit } from '../../dtos/types';
4
5
  import { AbstractSplitsCacheAsync } from '../AbstractSplitsCacheAsync';
5
6
  /**
6
7
  * ISplitsCacheAsync implementation for pluggable storages.
@@ -23,13 +24,13 @@ export declare class SplitsCachePluggable extends AbstractSplitsCacheAsync {
23
24
  * The returned promise is resolved when the operation success
24
25
  * or rejected if it fails (e.g., wrapper operation fails)
25
26
  */
26
- addSplit(name: string, split: string): Promise<boolean>;
27
+ addSplit(name: string, split: ISplit): Promise<boolean>;
27
28
  /**
28
29
  * Add a list of splits.
29
30
  * The returned promise is resolved when the operation success
30
31
  * or rejected if it fails (e.g., wrapper operation fails)
31
32
  */
32
- addSplits(entries: [string, string][]): Promise<boolean[]>;
33
+ addSplits(entries: [string, ISplit][]): Promise<boolean[]>;
33
34
  /**
34
35
  * Remove a given split.
35
36
  * The returned promise is resolved when the operation success, with a boolean indicating if the split existed or not.
@@ -47,19 +48,19 @@ export declare class SplitsCachePluggable extends AbstractSplitsCacheAsync {
47
48
  * The returned promise is resolved with the split definition or null if it's not defined,
48
49
  * or rejected if wrapper operation fails.
49
50
  */
50
- getSplit(name: string): Promise<string | null>;
51
+ getSplit(name: string): Promise<ISplit | null>;
51
52
  /**
52
53
  * Get list of splits.
53
54
  * The returned promise is resolved with a map of split names to their split definition or null if it's not defined,
54
55
  * or rejected if wrapper operation fails.
55
56
  */
56
- getSplits(names: string[]): Promise<Record<string, string | null>>;
57
+ getSplits(names: string[]): Promise<Record<string, ISplit | null>>;
57
58
  /**
58
59
  * Get list of all split definitions.
59
60
  * The returned promise is resolved with the list of split definitions,
60
61
  * or rejected if wrapper operation fails.
61
62
  */
62
- getAll(): Promise<string[]>;
63
+ getAll(): Promise<ISplit[]>;
63
64
  /**
64
65
  * Get list of split names.
65
66
  * The returned promise is resolved with the list of split names,