@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
@@ -1,6 +1,6 @@
1
- import { MaybeThenable, IMetadata, ISplitFiltersValidation } from '../dtos/types';
1
+ import { MaybeThenable, IMetadata, ISplitFiltersValidation, ISplit } from '../dtos/types';
2
2
  import { ILogger } from '../logger/types';
3
- import { EventDataType, HttpErrors, HttpLatencies, ImpressionDataType, LastSync, Method, MethodExceptions, MethodLatencies, OperationType, StoredEventWithMetadata, StoredImpressionWithMetadata, StreamingEvent, UniqueKeysPayloadCs, UniqueKeysPayloadSs } from '../sync/submitters/types';
3
+ import { EventDataType, HttpErrors, HttpLatencies, ImpressionDataType, LastSync, Method, MethodExceptions, MethodLatencies, OperationType, StoredEventWithMetadata, StoredImpressionWithMetadata, StreamingEvent } from '../sync/submitters/types';
4
4
  import { SplitIO, ImpressionDTO, SDKMode } from '../types';
5
5
  /**
6
6
  * Interface of a pluggable storage wrapper.
@@ -178,13 +178,13 @@ export interface IPluggableStorageWrapper {
178
178
  }
179
179
  /** Splits cache */
180
180
  export interface ISplitsCacheBase {
181
- addSplits(entries: [string, string][]): MaybeThenable<boolean[] | void>;
181
+ addSplits(entries: [string, ISplit][]): MaybeThenable<boolean[] | void>;
182
182
  removeSplits(names: string[]): MaybeThenable<boolean[] | void>;
183
- getSplit(name: string): MaybeThenable<string | null>;
184
- getSplits(names: string[]): MaybeThenable<Record<string, string | null>>;
183
+ getSplit(name: string): MaybeThenable<ISplit | null>;
184
+ getSplits(names: string[]): MaybeThenable<Record<string, ISplit | null>>;
185
185
  setChangeNumber(changeNumber: number): MaybeThenable<boolean | void>;
186
186
  getChangeNumber(): MaybeThenable<number>;
187
- getAll(): MaybeThenable<string[]>;
187
+ getAll(): MaybeThenable<ISplit[]>;
188
188
  getSplitNames(): MaybeThenable<string[]>;
189
189
  trafficTypeExists(trafficType: string): MaybeThenable<boolean>;
190
190
  usesSegments(): MaybeThenable<boolean>;
@@ -193,13 +193,13 @@ export interface ISplitsCacheBase {
193
193
  killLocally(name: string, defaultTreatment: string, changeNumber: number): MaybeThenable<boolean>;
194
194
  }
195
195
  export interface ISplitsCacheSync extends ISplitsCacheBase {
196
- addSplits(entries: [string, string][]): boolean[];
196
+ addSplits(entries: [string, ISplit][]): boolean[];
197
197
  removeSplits(names: string[]): boolean[];
198
- getSplit(name: string): string | null;
199
- getSplits(names: string[]): Record<string, string | null>;
198
+ getSplit(name: string): ISplit | null;
199
+ getSplits(names: string[]): Record<string, ISplit | null>;
200
200
  setChangeNumber(changeNumber: number): boolean;
201
201
  getChangeNumber(): number;
202
- getAll(): string[];
202
+ getAll(): ISplit[];
203
203
  getSplitNames(): string[];
204
204
  trafficTypeExists(trafficType: string): boolean;
205
205
  usesSegments(): boolean;
@@ -208,13 +208,13 @@ export interface ISplitsCacheSync extends ISplitsCacheBase {
208
208
  killLocally(name: string, defaultTreatment: string, changeNumber: number): boolean;
209
209
  }
210
210
  export interface ISplitsCacheAsync extends ISplitsCacheBase {
211
- addSplits(entries: [string, string][]): Promise<boolean[] | void>;
211
+ addSplits(entries: [string, ISplit][]): Promise<boolean[] | void>;
212
212
  removeSplits(names: string[]): Promise<boolean[] | void>;
213
- getSplit(name: string): Promise<string | null>;
214
- getSplits(names: string[]): Promise<Record<string, string | null>>;
213
+ getSplit(name: string): Promise<ISplit | null>;
214
+ getSplits(names: string[]): Promise<Record<string, ISplit | null>>;
215
215
  setChangeNumber(changeNumber: number): Promise<boolean | void>;
216
216
  getChangeNumber(): Promise<number>;
217
- getAll(): Promise<string[]>;
217
+ getAll(): Promise<ISplit[]>;
218
218
  getSplitNames(): Promise<string[]>;
219
219
  trafficTypeExists(trafficType: string): Promise<boolean>;
220
220
  usesSegments(): Promise<boolean>;
@@ -297,13 +297,6 @@ export interface IImpressionCountsCacheSync extends IRecorderCacheProducerSync<R
297
297
  isEmpty(): boolean;
298
298
  pop(toMerge?: Record<string, number>): Record<string, number>;
299
299
  }
300
- export interface IUniqueKeysCacheBase {
301
- track(key: string, value: string): void;
302
- isEmpty(): boolean;
303
- pop(): UniqueKeysPayloadSs | UniqueKeysPayloadCs;
304
- setOnFullQueueCb(cb: () => void): void;
305
- clear(): void;
306
- }
307
300
  /**
308
301
  * Telemetry storage interface for standalone and partial consumer modes.
309
302
  * Methods are sync because data is stored in memory.
@@ -373,31 +366,28 @@ export interface ITelemetryCacheAsync extends ITelemetryEvaluationProducerAsync
373
366
  /**
374
367
  * Storages
375
368
  */
376
- export interface IStorageBase<TSplitsCache extends ISplitsCacheBase, TSegmentsCache extends ISegmentsCacheBase, TImpressionsCache extends IImpressionsCacheBase, TImpressionsCountCache extends IImpressionCountsCacheSync, TEventsCache extends IEventsCacheBase, TTelemetryCache extends ITelemetryCacheSync | ITelemetryCacheAsync, TUniqueKeysCache extends IUniqueKeysCacheBase> {
369
+ export interface IStorageBase<TSplitsCache extends ISplitsCacheBase, TSegmentsCache extends ISegmentsCacheBase, TImpressionsCache extends IImpressionsCacheBase, TEventsCache extends IEventsCacheBase, TTelemetryCache extends ITelemetryCacheSync | ITelemetryCacheAsync> {
377
370
  splits: TSplitsCache;
378
371
  segments: TSegmentsCache;
379
372
  impressions: TImpressionsCache;
380
- impressionCounts?: TImpressionsCountCache;
373
+ impressionCounts?: IImpressionCountsCacheSync;
381
374
  events: TEventsCache;
382
375
  telemetry?: TTelemetryCache;
383
- uniqueKeys?: TUniqueKeysCache;
384
376
  destroy(): void | Promise<void>;
385
377
  shared?: (matchingKey: string, onReadyCb: (error?: any) => void) => this;
386
378
  }
387
- export interface IStorageSync extends IStorageBase<ISplitsCacheSync, ISegmentsCacheSync, IImpressionsCacheSync, IImpressionCountsCacheSync, IEventsCacheSync, ITelemetryCacheSync, IUniqueKeysCacheBase> {
379
+ export interface IStorageSync extends IStorageBase<ISplitsCacheSync, ISegmentsCacheSync, IImpressionsCacheSync, IEventsCacheSync, ITelemetryCacheSync> {
388
380
  }
389
- export interface IStorageAsync extends IStorageBase<ISplitsCacheAsync, ISegmentsCacheAsync, IImpressionsCacheAsync | IImpressionsCacheSync, IImpressionCountsCacheSync, IEventsCacheAsync | IEventsCacheSync, ITelemetryCacheAsync, IUniqueKeysCacheBase> {
381
+ export interface IStorageAsync extends IStorageBase<ISplitsCacheAsync, ISegmentsCacheAsync, IImpressionsCacheAsync | IImpressionsCacheSync, IEventsCacheAsync | IEventsCacheSync, ITelemetryCacheAsync> {
390
382
  }
391
383
  /** StorageFactory */
392
384
  export declare type DataLoader = (storage: IStorageSync, matchingKey: string) => void;
393
385
  export interface IStorageFactoryParams {
394
386
  log: ILogger;
395
387
  impressionsQueueSize?: number;
396
- uniqueKeysCacheSize?: number;
397
388
  eventsQueueSize?: number;
398
389
  optimize?: boolean;
399
390
  mode: SDKMode;
400
- impressionsMode?: string;
401
391
  matchingKey?: string;
402
392
  splitFiltersValidation?: ISplitFiltersValidation;
403
393
  onReadyCb: (error?: any) => void;
@@ -11,7 +11,7 @@ declare type ISplitChangesUpdater = (noCache?: boolean, till?: number) => Promis
11
11
  */
12
12
  export declare function parseSegments({ conditions }: ISplit): ISet<string>;
13
13
  interface ISplitMutations {
14
- added: [string, string][];
14
+ added: [string, ISplit][];
15
15
  removed: string[];
16
16
  segments: string[];
17
17
  }
@@ -32,22 +32,6 @@ export declare type ImpressionCountsPayload = {
32
32
  rc: number;
33
33
  }[];
34
34
  };
35
- export declare type UniqueKeysPayloadSs = {
36
- keys: {
37
- /** Split name */
38
- f: string;
39
- /** keyNames */
40
- ks: string[];
41
- }[];
42
- };
43
- export declare type UniqueKeysPayloadCs = {
44
- keys: {
45
- /** keyNames */
46
- k: string;
47
- /** Split name */
48
- fs: string[];
49
- }[];
50
- };
51
35
  export declare type StoredImpressionWithMetadata = {
52
36
  /** Metadata */
53
37
  m: IMetadata;
@@ -148,8 +132,7 @@ export declare type CONSUMER_PARTIAL_ENUM = 2;
148
132
  export declare type OperationMode = STANDALONE_ENUM | CONSUMER_ENUM | CONSUMER_PARTIAL_ENUM;
149
133
  export declare type OPTIMIZED_ENUM = 0;
150
134
  export declare type DEBUG_ENUM = 1;
151
- export declare type NONE_ENUM = 2;
152
- export declare type ImpressionsMode = OPTIMIZED_ENUM | DEBUG_ENUM | NONE_ENUM;
135
+ export declare type ImpressionsMode = OPTIMIZED_ENUM | DEBUG_ENUM;
153
136
  export declare type RefreshRates = {
154
137
  sp: number;
155
138
  se?: number;
@@ -1,6 +1,7 @@
1
- import { IImpressionsCacheBase, ITelemetryCacheSync, ITelemetryCacheAsync } from '../storages/types';
2
- import { IImpressionsHandler, IImpressionsTracker, IStrategy } from './types';
1
+ import { IImpressionCountsCacheSync, IImpressionsCacheBase, ITelemetryCacheSync, ITelemetryCacheAsync } from '../storages/types';
2
+ import { IImpressionsHandler, IImpressionsTracker } from './types';
3
3
  import { ISettings } from '../types';
4
+ import { IImpressionObserver } from './impressionObserver/types';
4
5
  /**
5
6
  * Impressions tracker stores impressions in cache and pass them to the listener and integrations manager if provided.
6
7
  *
@@ -8,6 +9,7 @@ import { ISettings } from '../types';
8
9
  * @param metadata runtime metadata (ip, hostname and version)
9
10
  * @param impressionListener optional impression listener
10
11
  * @param integrationsManager optional integrations manager
11
- * @param strategy strategy for impressions tracking.
12
+ * @param observer optional impression observer. If provided, previous time (pt property) is included in impression instances
13
+ * @param countsCache optional cache to save impressions count. If provided, impressions will be deduped (OPTIMIZED mode)
12
14
  */
13
- export declare function impressionsTrackerFactory(settings: ISettings, impressionsCache: IImpressionsCacheBase, strategy: IStrategy, integrationsManager?: IImpressionsHandler, telemetryCache?: ITelemetryCacheSync | ITelemetryCacheAsync): IImpressionsTracker;
15
+ export declare function impressionsTrackerFactory(settings: ISettings, impressionsCache: IImpressionsCacheBase, integrationsManager?: IImpressionsHandler, observer?: IImpressionObserver, countsCache?: IImpressionCountsCacheSync, telemetryCache?: ITelemetryCacheSync | ITelemetryCacheAsync): IImpressionsTracker;
@@ -33,25 +33,8 @@ export interface ITelemetryTracker {
33
33
  * Records streaming event
34
34
  */
35
35
  streamingEvent(e: StreamingEventType | AUTH_REJECTION, d?: number): void;
36
- }
37
- export interface IFilterAdapter {
38
- add(key: string, featureName: string): boolean;
39
- contains(key: string, featureName: string): boolean;
40
- clear(): void;
41
- }
42
- export interface IImpressionSenderAdapter {
43
- recordUniqueKeys(data: Object): void;
44
- recordImpressionCounts(data: Object): void;
45
- }
46
- /** Unique keys tracker */
47
- export interface IUniqueKeysTracker {
48
- track(key: string, featureName: string): void;
49
- }
50
- export interface IStrategyResult {
51
- impressionsToStore: ImpressionDTO[];
52
- impressionsToListener: ImpressionDTO[];
53
- deduped: number;
54
- }
55
- export interface IStrategy {
56
- process(impressions: ImpressionDTO[]): IStrategyResult;
36
+ /**
37
+ * Records tag
38
+ */
39
+ addTag(tag: string): void;
57
40
  }
package/types/types.d.ts CHANGED
@@ -74,8 +74,6 @@ export interface ISettings {
74
74
  featuresRefreshRate: number;
75
75
  impressionsRefreshRate: number;
76
76
  impressionsQueueSize: number;
77
- uniqueKeysRefreshRate: number;
78
- uniqueKeysCacheSize: number;
79
77
  /**
80
78
  * @deprecated
81
79
  */
@@ -717,7 +715,7 @@ export declare namespace SplitIO {
717
715
  * ImpressionsMode type
718
716
  * @typedef {string} ImpressionsMode
719
717
  */
720
- type ImpressionsMode = 'OPTIMIZED' | 'DEBUG' | 'NONE';
718
+ type ImpressionsMode = 'OPTIMIZED' | 'DEBUG';
721
719
  /**
722
720
  * Defines the format of Split data to preload on the factory storage (cache).
723
721
  */
@@ -11,7 +11,6 @@ export declare const SPLIT_IMPRESSION = "IMPRESSION";
11
11
  export declare const SPLIT_EVENT = "EVENT";
12
12
  export declare const DEBUG = "DEBUG";
13
13
  export declare const OPTIMIZED = "OPTIMIZED";
14
- export declare const NONE = "NONE";
15
14
  export declare const LOCALHOST_MODE: SDKMode;
16
15
  export declare const STANDALONE_MODE: SDKMode;
17
16
  export declare const PRODUCER_MODE = "producer";
@@ -32,7 +31,6 @@ export declare const CONSUMER_ENUM = 1;
32
31
  export declare const CONSUMER_PARTIAL_ENUM = 2;
33
32
  export declare const OPTIMIZED_ENUM = 0;
34
33
  export declare const DEBUG_ENUM = 1;
35
- export declare const NONE_ENUM = 2;
36
34
  export declare const SPLITS = "sp";
37
35
  export declare const IMPRESSIONS = "im";
38
36
  export declare const IMPRESSIONS_COUNT = "ic";
@@ -14,7 +14,6 @@ export declare const base: {
14
14
  segmentsRefreshRate: number;
15
15
  telemetryRefreshRate: number;
16
16
  impressionsRefreshRate: number;
17
- uniqueKeysRefreshRate: number;
18
17
  offlineRefreshRate: number;
19
18
  eventsPushRate: number;
20
19
  eventsQueueSize: number;
@@ -1,73 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UniqueKeysCacheInMemory = void 0;
4
- var sets_1 = require("../../utils/lang/sets");
5
- var constants_1 = require("../inRedis/constants");
6
- var UniqueKeysCacheInMemory = /** @class */ (function () {
7
- function UniqueKeysCacheInMemory(uniqueKeysQueueSize) {
8
- if (uniqueKeysQueueSize === void 0) { uniqueKeysQueueSize = constants_1.DEFAULT_CACHE_SIZE; }
9
- this.uniqueTrackerSize = 0;
10
- this.maxStorage = uniqueKeysQueueSize;
11
- this.uniqueKeysTracker = {};
12
- }
13
- UniqueKeysCacheInMemory.prototype.setOnFullQueueCb = function (cb) {
14
- this.onFullQueue = cb;
15
- };
16
- /**
17
- * Store unique keys in sequential order
18
- * key: string = feature name.
19
- * value: Set<string> = set of unique keys.
20
- */
21
- UniqueKeysCacheInMemory.prototype.track = function (key, featureName) {
22
- if (!this.uniqueKeysTracker[featureName])
23
- this.uniqueKeysTracker[featureName] = new sets_1._Set();
24
- var tracker = this.uniqueKeysTracker[featureName];
25
- if (!tracker.has(key)) {
26
- tracker.add(key);
27
- this.uniqueTrackerSize++;
28
- }
29
- if (this.uniqueTrackerSize >= this.maxStorage && this.onFullQueue) {
30
- this.uniqueTrackerSize = 0;
31
- this.onFullQueue();
32
- }
33
- };
34
- /**
35
- * Clear the data stored on the cache.
36
- */
37
- UniqueKeysCacheInMemory.prototype.clear = function () {
38
- this.uniqueKeysTracker = {};
39
- };
40
- /**
41
- * Pop the collected data, used as payload for posting.
42
- */
43
- UniqueKeysCacheInMemory.prototype.pop = function () {
44
- var data = this.uniqueKeysTracker;
45
- this.uniqueKeysTracker = {};
46
- return this.fromUniqueKeysCollector(data);
47
- };
48
- /**
49
- * Check if the cache is empty.
50
- */
51
- UniqueKeysCacheInMemory.prototype.isEmpty = function () {
52
- return Object.keys(this.uniqueKeysTracker).length === 0;
53
- };
54
- /**
55
- * Converts `uniqueKeys` data from cache into request payload for SS.
56
- */
57
- UniqueKeysCacheInMemory.prototype.fromUniqueKeysCollector = function (uniqueKeys) {
58
- var payload = [];
59
- var featureNames = Object.keys(uniqueKeys);
60
- for (var i = 0; i < featureNames.length; i++) {
61
- var featureName = featureNames[i];
62
- var featureKeys = (0, sets_1.setToArray)(uniqueKeys[featureName]);
63
- var uniqueKeysPayload = {
64
- f: featureName,
65
- ks: featureKeys
66
- };
67
- payload.push(uniqueKeysPayload);
68
- }
69
- return { keys: payload };
70
- };
71
- return UniqueKeysCacheInMemory;
72
- }());
73
- exports.UniqueKeysCacheInMemory = UniqueKeysCacheInMemory;
@@ -1,78 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UniqueKeysCacheInMemoryCS = void 0;
4
- var sets_1 = require("../../utils/lang/sets");
5
- var constants_1 = require("../inRedis/constants");
6
- var UniqueKeysCacheInMemoryCS = /** @class */ (function () {
7
- /**
8
- *
9
- * @param impressionsQueueSize number of queued impressions to call onFullQueueCb.
10
- * Default value is 0, that means no maximum value, in case we want to avoid this being triggered.
11
- */
12
- function UniqueKeysCacheInMemoryCS(uniqueKeysQueueSize) {
13
- if (uniqueKeysQueueSize === void 0) { uniqueKeysQueueSize = constants_1.DEFAULT_CACHE_SIZE; }
14
- this.uniqueTrackerSize = 0;
15
- this.maxStorage = uniqueKeysQueueSize;
16
- this.uniqueKeysTracker = {};
17
- }
18
- UniqueKeysCacheInMemoryCS.prototype.setOnFullQueueCb = function (cb) {
19
- this.onFullQueue = cb;
20
- };
21
- /**
22
- * Store unique keys in sequential order
23
- * key: string = key.
24
- * value: HashSet<string> = set of split names.
25
- */
26
- UniqueKeysCacheInMemoryCS.prototype.track = function (key, featureName) {
27
- if (!this.uniqueKeysTracker[key])
28
- this.uniqueKeysTracker[key] = new sets_1._Set();
29
- var tracker = this.uniqueKeysTracker[key];
30
- if (!tracker.has(featureName)) {
31
- tracker.add(featureName);
32
- this.uniqueTrackerSize++;
33
- }
34
- if (this.uniqueTrackerSize >= this.maxStorage && this.onFullQueue) {
35
- this.uniqueTrackerSize = 0;
36
- this.onFullQueue();
37
- }
38
- };
39
- /**
40
- * Clear the data stored on the cache.
41
- */
42
- UniqueKeysCacheInMemoryCS.prototype.clear = function () {
43
- this.uniqueKeysTracker = {};
44
- };
45
- /**
46
- * Pop the collected data, used as payload for posting.
47
- */
48
- UniqueKeysCacheInMemoryCS.prototype.pop = function () {
49
- var data = this.uniqueKeysTracker;
50
- this.uniqueKeysTracker = {};
51
- return this.fromUniqueKeysCollector(data);
52
- };
53
- /**
54
- * Check if the cache is empty.
55
- */
56
- UniqueKeysCacheInMemoryCS.prototype.isEmpty = function () {
57
- return Object.keys(this.uniqueKeysTracker).length === 0;
58
- };
59
- /**
60
- * Converts `uniqueKeys` data from cache into request payload.
61
- */
62
- UniqueKeysCacheInMemoryCS.prototype.fromUniqueKeysCollector = function (uniqueKeys) {
63
- var payload = [];
64
- var featureKeys = Object.keys(uniqueKeys);
65
- for (var k = 0; k < featureKeys.length; k++) {
66
- var featureKey = featureKeys[k];
67
- var featureNames = (0, sets_1.setToArray)(uniqueKeys[featureKey]);
68
- var uniqueKeysPayload = {
69
- k: featureKey,
70
- fs: featureNames
71
- };
72
- payload.push(uniqueKeysPayload);
73
- }
74
- return { keys: payload };
75
- };
76
- return UniqueKeysCacheInMemoryCS;
77
- }());
78
- exports.UniqueKeysCacheInMemoryCS = UniqueKeysCacheInMemoryCS;
@@ -1,46 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ImpressionCountsCacheInRedis = void 0;
4
- var tslib_1 = require("tslib");
5
- var ImpressionCountsCacheInMemory_1 = require("../inMemory/ImpressionCountsCacheInMemory");
6
- var constants_1 = require("./constants");
7
- var ImpressionCountsCacheInRedis = /** @class */ (function (_super) {
8
- (0, tslib_1.__extends)(ImpressionCountsCacheInRedis, _super);
9
- function ImpressionCountsCacheInRedis(log, key, redis, impressionCountsCacheSize) {
10
- var _this = _super.call(this, impressionCountsCacheSize) || this;
11
- _this.log = log;
12
- _this.key = key;
13
- _this.redis = redis;
14
- _this.onFullQueue = function () { _this.postImpressionCountsInRedis(); };
15
- return _this;
16
- }
17
- ImpressionCountsCacheInRedis.prototype.postImpressionCountsInRedis = function () {
18
- var _this = this;
19
- var counts = this.pop();
20
- var keys = Object.keys(counts);
21
- var pipeline = this.redis.pipeline();
22
- keys.forEach(function (key) {
23
- pipeline.hincrby(_this.key, key, counts[key]);
24
- });
25
- return pipeline.exec()
26
- .then(function (data) {
27
- // If this is the creation of the key on Redis, set the expiration for it in 3600 seconds.
28
- if (data.length && data.length === keys.length) {
29
- return _this.redis.expire(_this.key, constants_1.TTL_REFRESH);
30
- }
31
- })
32
- .catch(function (err) {
33
- _this.log.error(constants_1.LOG_PREFIX + "Error in impression counts pipeline: " + err + ".");
34
- return false;
35
- });
36
- };
37
- ImpressionCountsCacheInRedis.prototype.start = function (refreshRate) {
38
- if (refreshRate === void 0) { refreshRate = constants_1.REFRESH_RATE; }
39
- this.handle = setInterval(this.postImpressionCountsInRedis.bind(this), refreshRate);
40
- };
41
- ImpressionCountsCacheInRedis.prototype.stop = function () {
42
- clearInterval(this.handle);
43
- };
44
- return ImpressionCountsCacheInRedis;
45
- }(ImpressionCountsCacheInMemory_1.ImpressionCountsCacheInMemory));
46
- exports.ImpressionCountsCacheInRedis = ImpressionCountsCacheInRedis;
@@ -1,55 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UniqueKeysCacheInRedis = void 0;
4
- var tslib_1 = require("tslib");
5
- var uniqueKeysCacheInMemory_1 = require("../inMemory/uniqueKeysCacheInMemory");
6
- var sets_1 = require("../../utils/lang/sets");
7
- var constants_1 = require("./constants");
8
- var constants_2 = require("./constants");
9
- var UniqueKeysCacheInRedis = /** @class */ (function (_super) {
10
- (0, tslib_1.__extends)(UniqueKeysCacheInRedis, _super);
11
- function UniqueKeysCacheInRedis(log, key, redis, uniqueKeysQueueSize) {
12
- if (uniqueKeysQueueSize === void 0) { uniqueKeysQueueSize = constants_1.DEFAULT_CACHE_SIZE; }
13
- var _this = _super.call(this, uniqueKeysQueueSize) || this;
14
- _this.log = log;
15
- _this.key = key;
16
- _this.redis = redis;
17
- _this.onFullQueue = function () { _this.postUniqueKeysInRedis(); };
18
- return _this;
19
- }
20
- UniqueKeysCacheInRedis.prototype.postUniqueKeysInRedis = function () {
21
- var _this = this;
22
- var pipeline = this.redis.pipeline();
23
- var featureNames = Object.keys(this.uniqueKeysTracker);
24
- for (var i = 0; i < featureNames.length; i++) {
25
- var featureName = featureNames[i];
26
- var featureKeys = (0, sets_1.setToArray)(this.uniqueKeysTracker[featureName]);
27
- var uniqueKeysPayload = {
28
- f: featureName,
29
- ks: featureKeys
30
- };
31
- pipeline.rpush(this.key, JSON.stringify(uniqueKeysPayload));
32
- }
33
- this.clear();
34
- return pipeline.exec()
35
- .then(function (data) {
36
- // If this is the creation of the key on Redis, set the expiration for it in 3600 seconds.
37
- if (data.length && data.length === featureNames.length) {
38
- return _this.redis.expire(_this.key, constants_1.TTL_REFRESH);
39
- }
40
- })
41
- .catch(function (err) {
42
- _this.log.error(constants_2.LOG_PREFIX + "Error in uniqueKeys pipeline: " + err + ".");
43
- return false;
44
- });
45
- };
46
- UniqueKeysCacheInRedis.prototype.start = function (refreshRate) {
47
- if (refreshRate === void 0) { refreshRate = constants_1.REFRESH_RATE; }
48
- this.handle = setInterval(this.postUniqueKeysInRedis.bind(this), refreshRate);
49
- };
50
- UniqueKeysCacheInRedis.prototype.stop = function () {
51
- clearInterval(this.handle);
52
- };
53
- return UniqueKeysCacheInRedis;
54
- }(uniqueKeysCacheInMemory_1.UniqueKeysCacheInMemory));
55
- exports.UniqueKeysCacheInRedis = UniqueKeysCacheInRedis;
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.uniqueKeysSubmitterFactory = void 0;
4
- var constants_1 = require("../../logger/constants");
5
- var submitter_1 = require("./submitter");
6
- var DATA_NAME = 'uniqueKeys';
7
- /**
8
- * Submitter that periodically posts impression counts
9
- */
10
- function uniqueKeysSubmitterFactory(params) {
11
- var _a = params.settings, log = _a.log, uniqueKeysRefreshRate = _a.scheduler.uniqueKeysRefreshRate, key = _a.core.key, _b = params.splitApi, postUniqueKeysBulkCs = _b.postUniqueKeysBulkCs, postUniqueKeysBulkSs = _b.postUniqueKeysBulkSs, uniqueKeys = params.storage.uniqueKeys;
12
- var isClientSide = key !== undefined;
13
- var postUniqueKeysBulk = isClientSide ? postUniqueKeysBulkCs : postUniqueKeysBulkSs;
14
- var syncTask = (0, submitter_1.submitterFactory)(log, postUniqueKeysBulk, uniqueKeys, uniqueKeysRefreshRate, 'unique keys');
15
- // register unique keys submitter to be executed when uniqueKeys cache is full
16
- uniqueKeys.setOnFullQueueCb(function () {
17
- if (syncTask.isRunning()) {
18
- log.info(constants_1.SUBMITTERS_PUSH_FULL_QUEUE, [DATA_NAME]);
19
- syncTask.execute();
20
- }
21
- // If submitter is stopped (e.g., user consent declined or unknown, or app state offline), we don't send the data.
22
- // Data will be sent when submitter is resumed.
23
- });
24
- return syncTask;
25
- }
26
- exports.uniqueKeysSubmitterFactory = uniqueKeysSubmitterFactory;
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.strategyDebugFactory = void 0;
4
- /**
5
- * Debug strategy for impressions tracker. Wraps impressions to store and adds previousTime if it corresponds
6
- *
7
- * @param impressionsObserver impression observer. Previous time (pt property) is included in impression instances
8
- * @returns IStrategyResult
9
- */
10
- function strategyDebugFactory(impressionsObserver) {
11
- return {
12
- process: function (impressions) {
13
- impressions.forEach(function (impression) {
14
- // Adds previous time if it is enabled
15
- impression.pt = impressionsObserver.testAndSet(impression);
16
- });
17
- return {
18
- impressionsToStore: impressions,
19
- impressionsToListener: impressions,
20
- deduped: 0
21
- };
22
- }
23
- };
24
- }
25
- exports.strategyDebugFactory = strategyDebugFactory;
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.strategyNoneFactory = void 0;
4
- /**
5
- * None strategy for impressions tracker.
6
- *
7
- * @param impressionsCounter cache to save impressions count. impressions will be deduped (OPTIMIZED mode)
8
- * @param uniqueKeysTracker unique keys tracker in charge of tracking the unique keys per split.
9
- * @returns IStrategyResult
10
- */
11
- function strategyNoneFactory(impressionsCounter, uniqueKeysTracker) {
12
- return {
13
- process: function (impressions) {
14
- impressions.forEach(function (impression) {
15
- var now = Date.now();
16
- // Increments impression counter per featureName
17
- impressionsCounter.track(impression.feature, now, 1);
18
- // Keep track by unique key
19
- uniqueKeysTracker.track(impression.keyName, impression.feature);
20
- });
21
- return {
22
- impressionsToStore: [],
23
- impressionsToListener: impressions,
24
- deduped: 0
25
- };
26
- }
27
- };
28
- }
29
- exports.strategyNoneFactory = strategyNoneFactory;
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.strategyOptimizedFactory = void 0;
4
- var time_1 = require("../../utils/time");
5
- /**
6
- * Optimized strategy for impressions tracker. Wraps impressions to store and adds previousTime if it corresponds
7
- *
8
- * @param impressionsObserver impression observer. previous time (pt property) is included in impression instances
9
- * @param impressionsCounter cache to save impressions count. impressions will be deduped (OPTIMIZED mode)
10
- * @returns IStrategyResult
11
- */
12
- function strategyOptimizedFactory(impressionsObserver, impressionsCounter) {
13
- return {
14
- process: function (impressions) {
15
- var impressionsToStore = [];
16
- impressions.forEach(function (impression) {
17
- impression.pt = impressionsObserver.testAndSet(impression);
18
- var now = Date.now();
19
- // Increments impression counter per featureName
20
- impressionsCounter.track(impression.feature, now, 1);
21
- // Checks if the impression should be added in queue to be sent
22
- if (!impression.pt || impression.pt < (0, time_1.truncateTimeFrame)(now)) {
23
- impressionsToStore.push(impression);
24
- }
25
- });
26
- return {
27
- impressionsToStore: impressionsToStore,
28
- impressionsToListener: impressions,
29
- deduped: impressions.length - impressionsToStore.length
30
- };
31
- }
32
- };
33
- }
34
- exports.strategyOptimizedFactory = strategyOptimizedFactory;
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.uniqueKeysTrackerFactory = void 0;
4
- var constants_1 = require("../logger/constants");
5
- var noopFilterAdapter = {
6
- add: function () { return true; },
7
- contains: function () { return true; },
8
- clear: function () { }
9
- };
10
- /**
11
- * Trackes uniques keys
12
- * Unique Keys Tracker will be in charge of checking if the MTK was already sent to the BE in the last period
13
- * or schedule to be sent; if not it will be added in an internal cache and sent in the next post.
14
- *
15
- * @param log Logger instance
16
- * @param filterAdapter filter adapter
17
- * @param uniqueKeysCache cache to save unique keys
18
- */
19
- function uniqueKeysTrackerFactory(log, uniqueKeysCache, filterAdapter) {
20
- if (filterAdapter === void 0) { filterAdapter = noopFilterAdapter; }
21
- return {
22
- track: function (key, featureName) {
23
- if (!filterAdapter.add(key, featureName)) {
24
- log.debug(constants_1.LOG_PREFIX_UNIQUE_KEYS_TRACKER + "The feature " + featureName + " and key " + key + " exist in the filter");
25
- return;
26
- }
27
- uniqueKeysCache.track(key, featureName);
28
- }
29
- };
30
- }
31
- exports.uniqueKeysTrackerFactory = uniqueKeysTrackerFactory;