@splitsoftware/splitio-commons 1.6.2-rc.9 → 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 (176) hide show
  1. package/CHANGES.txt +3 -1
  2. package/cjs/consent/sdkUserConsent.js +2 -2
  3. package/cjs/listeners/browser.js +11 -12
  4. package/cjs/logger/constants.js +2 -1
  5. package/cjs/sdkClient/sdkClient.js +3 -1
  6. package/cjs/sdkFactory/index.js +26 -26
  7. package/cjs/services/splitApi.js +20 -0
  8. package/cjs/storages/AbstractSplitsCacheAsync.js +1 -1
  9. package/cjs/storages/AbstractSplitsCacheSync.js +1 -1
  10. package/cjs/storages/KeyBuilderSS.js +10 -43
  11. package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +0 -1
  12. package/cjs/storages/inLocalStorage/index.js +17 -9
  13. package/cjs/storages/inMemory/ImpressionCountsCacheInMemory.js +12 -1
  14. package/cjs/storages/inMemory/InMemoryStorage.js +13 -6
  15. package/cjs/storages/inMemory/InMemoryStorageCS.js +13 -6
  16. package/cjs/storages/inMemory/TelemetryCacheInMemory.js +60 -35
  17. package/cjs/storages/inMemory/UniqueKeysCacheInMemory.js +72 -0
  18. package/cjs/storages/inMemory/UniqueKeysCacheInMemoryCS.js +76 -0
  19. package/cjs/storages/inRedis/ImpressionCountsCacheInRedis.js +85 -0
  20. package/cjs/storages/inRedis/ImpressionsCacheInRedis.js +2 -19
  21. package/cjs/storages/inRedis/TelemetryCacheInRedis.js +4 -4
  22. package/cjs/storages/inRedis/UniqueKeysCacheInRedis.js +71 -0
  23. package/cjs/storages/inRedis/constants.js +4 -1
  24. package/cjs/storages/inRedis/index.js +20 -3
  25. package/cjs/storages/pluggable/ImpressionCountsCachePluggable.js +81 -0
  26. package/cjs/storages/pluggable/ImpressionsCachePluggable.js +2 -19
  27. package/cjs/storages/pluggable/TelemetryCachePluggable.js +4 -4
  28. package/cjs/storages/pluggable/UniqueKeysCachePluggable.js +61 -0
  29. package/cjs/storages/pluggable/inMemoryWrapper.js +8 -6
  30. package/cjs/storages/pluggable/index.js +38 -9
  31. package/cjs/storages/utils.js +73 -0
  32. package/cjs/sync/submitters/submitterManager.js +3 -0
  33. package/cjs/sync/submitters/telemetrySubmitter.js +5 -40
  34. package/cjs/sync/submitters/uniqueKeysSubmitter.js +27 -0
  35. package/cjs/trackers/impressionObserver/utils.js +1 -17
  36. package/cjs/trackers/impressionsTracker.js +22 -41
  37. package/cjs/trackers/strategy/strategyDebug.js +25 -0
  38. package/cjs/trackers/strategy/strategyNone.js +29 -0
  39. package/cjs/trackers/strategy/strategyOptimized.js +35 -0
  40. package/cjs/trackers/uniqueKeysTracker.js +38 -0
  41. package/cjs/utils/constants/index.js +4 -2
  42. package/cjs/utils/redis/RedisMock.js +31 -0
  43. package/cjs/utils/settingsValidation/impressionsMode.js +2 -2
  44. package/cjs/utils/settingsValidation/index.js +7 -1
  45. package/esm/consent/sdkUserConsent.js +2 -2
  46. package/esm/listeners/browser.js +12 -13
  47. package/esm/logger/constants.js +1 -0
  48. package/esm/sdkClient/sdkClient.js +3 -1
  49. package/esm/sdkFactory/index.js +26 -26
  50. package/esm/services/splitApi.js +20 -0
  51. package/esm/storages/AbstractSplitsCacheAsync.js +1 -1
  52. package/esm/storages/AbstractSplitsCacheSync.js +1 -1
  53. package/esm/storages/KeyBuilderSS.js +7 -37
  54. package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +0 -1
  55. package/esm/storages/inLocalStorage/index.js +18 -10
  56. package/esm/storages/inMemory/ImpressionCountsCacheInMemory.js +12 -1
  57. package/esm/storages/inMemory/InMemoryStorage.js +14 -7
  58. package/esm/storages/inMemory/InMemoryStorageCS.js +14 -7
  59. package/esm/storages/inMemory/TelemetryCacheInMemory.js +61 -36
  60. package/esm/storages/inMemory/UniqueKeysCacheInMemory.js +68 -0
  61. package/esm/storages/inMemory/UniqueKeysCacheInMemoryCS.js +73 -0
  62. package/esm/storages/inRedis/ImpressionCountsCacheInRedis.js +82 -0
  63. package/esm/storages/inRedis/ImpressionsCacheInRedis.js +2 -19
  64. package/esm/storages/inRedis/TelemetryCacheInRedis.js +1 -1
  65. package/esm/storages/inRedis/UniqueKeysCacheInRedis.js +68 -0
  66. package/esm/storages/inRedis/constants.js +3 -0
  67. package/esm/storages/inRedis/index.js +21 -4
  68. package/esm/storages/pluggable/ImpressionCountsCachePluggable.js +78 -0
  69. package/esm/storages/pluggable/ImpressionsCachePluggable.js +2 -19
  70. package/esm/storages/pluggable/TelemetryCachePluggable.js +1 -1
  71. package/esm/storages/pluggable/UniqueKeysCachePluggable.js +58 -0
  72. package/esm/storages/pluggable/inMemoryWrapper.js +8 -6
  73. package/esm/storages/pluggable/index.js +39 -10
  74. package/esm/storages/utils.js +65 -0
  75. package/esm/sync/submitters/submitterManager.js +3 -0
  76. package/esm/sync/submitters/telemetrySubmitter.js +5 -39
  77. package/esm/sync/submitters/uniqueKeysSubmitter.js +23 -0
  78. package/esm/trackers/impressionObserver/utils.js +1 -15
  79. package/esm/trackers/impressionsTracker.js +22 -41
  80. package/esm/trackers/strategy/strategyDebug.js +21 -0
  81. package/esm/trackers/strategy/strategyNone.js +25 -0
  82. package/esm/trackers/strategy/strategyOptimized.js +31 -0
  83. package/esm/trackers/uniqueKeysTracker.js +34 -0
  84. package/esm/utils/constants/index.js +2 -0
  85. package/esm/utils/redis/RedisMock.js +28 -0
  86. package/esm/utils/settingsValidation/impressionsMode.js +3 -3
  87. package/esm/utils/settingsValidation/index.js +7 -1
  88. package/package.json +1 -2
  89. package/src/consent/sdkUserConsent.ts +2 -2
  90. package/src/listeners/browser.ts +12 -15
  91. package/src/logger/constants.ts +1 -0
  92. package/src/sdkClient/sdkClient.ts +3 -1
  93. package/src/sdkFactory/index.ts +29 -31
  94. package/src/sdkFactory/types.ts +7 -4
  95. package/src/services/splitApi.ts +22 -0
  96. package/src/services/types.ts +6 -0
  97. package/src/storages/AbstractSplitsCacheAsync.ts +1 -1
  98. package/src/storages/AbstractSplitsCacheSync.ts +1 -1
  99. package/src/storages/KeyBuilderSS.ts +9 -43
  100. package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +0 -1
  101. package/src/storages/inLocalStorage/index.ts +18 -10
  102. package/src/storages/inMemory/AttributesCacheInMemory.ts +7 -7
  103. package/src/storages/inMemory/ImpressionCountsCacheInMemory.ts +16 -1
  104. package/src/storages/inMemory/InMemoryStorage.ts +14 -7
  105. package/src/storages/inMemory/InMemoryStorageCS.ts +14 -7
  106. package/src/storages/inMemory/TelemetryCacheInMemory.ts +69 -34
  107. package/src/storages/inMemory/UniqueKeysCacheInMemory.ts +80 -0
  108. package/src/storages/inMemory/UniqueKeysCacheInMemoryCS.ts +86 -0
  109. package/src/storages/inRedis/ImpressionCountsCacheInRedis.ts +95 -0
  110. package/src/storages/inRedis/ImpressionsCacheInRedis.ts +2 -22
  111. package/src/storages/inRedis/TelemetryCacheInRedis.ts +3 -2
  112. package/src/storages/inRedis/UniqueKeysCacheInRedis.ts +77 -0
  113. package/src/storages/inRedis/constants.ts +3 -0
  114. package/src/storages/inRedis/index.ts +18 -5
  115. package/src/storages/pluggable/ImpressionCountsCachePluggable.ts +92 -0
  116. package/src/storages/pluggable/ImpressionsCachePluggable.ts +3 -23
  117. package/src/storages/pluggable/TelemetryCachePluggable.ts +3 -2
  118. package/src/storages/pluggable/UniqueKeysCachePluggable.ts +67 -0
  119. package/src/storages/pluggable/inMemoryWrapper.ts +6 -6
  120. package/src/storages/pluggable/index.ts +41 -9
  121. package/src/storages/types.ts +56 -55
  122. package/src/storages/utils.ts +78 -0
  123. package/src/sync/submitters/submitter.ts +2 -2
  124. package/src/sync/submitters/submitterManager.ts +2 -0
  125. package/src/sync/submitters/telemetrySubmitter.ts +8 -43
  126. package/src/sync/submitters/types.ts +29 -27
  127. package/src/sync/submitters/uniqueKeysSubmitter.ts +36 -0
  128. package/src/trackers/impressionObserver/utils.ts +1 -16
  129. package/src/trackers/impressionsTracker.ts +25 -46
  130. package/src/trackers/strategy/strategyDebug.ts +28 -0
  131. package/src/trackers/strategy/strategyNone.ts +34 -0
  132. package/src/trackers/strategy/strategyOptimized.ts +42 -0
  133. package/src/trackers/types.ts +28 -0
  134. package/src/trackers/uniqueKeysTracker.ts +48 -0
  135. package/src/types.ts +1 -1
  136. package/src/utils/constants/index.ts +2 -0
  137. package/src/utils/redis/RedisMock.ts +33 -0
  138. package/src/utils/settingsValidation/impressionsMode.ts +3 -3
  139. package/src/utils/settingsValidation/index.ts +5 -1
  140. package/types/logger/constants.d.ts +1 -0
  141. package/types/sdkFactory/types.d.ts +4 -2
  142. package/types/services/types.d.ts +4 -0
  143. package/types/storages/AbstractSplitsCacheAsync.d.ts +1 -1
  144. package/types/storages/AbstractSplitsCacheSync.d.ts +1 -1
  145. package/types/storages/KeyBuilderSS.d.ts +3 -3
  146. package/types/storages/inLocalStorage/SplitsCacheInLocal.d.ts +0 -1
  147. package/types/storages/inMemory/ImpressionCountsCacheInMemory.d.ts +5 -1
  148. package/types/storages/inMemory/TelemetryCacheInMemory.d.ts +20 -9
  149. package/types/storages/inMemory/uniqueKeysCacheInMemory.d.ts +35 -0
  150. package/types/storages/inMemory/uniqueKeysCacheInMemoryCS.d.ts +35 -0
  151. package/types/storages/inRedis/ImpressionCountsCacheInRedis.d.ts +16 -0
  152. package/types/storages/inRedis/ImpressionsCacheInRedis.d.ts +0 -1
  153. package/types/storages/inRedis/constants.d.ts +3 -0
  154. package/types/storages/inRedis/uniqueKeysCacheInRedis.d.ts +21 -0
  155. package/types/storages/pluggable/ImpressionCountsCachePluggable.d.ts +16 -0
  156. package/types/storages/pluggable/ImpressionsCachePluggable.d.ts +1 -2
  157. package/types/storages/pluggable/UniqueKeysCachePluggable.d.ts +20 -0
  158. package/types/storages/types.d.ts +39 -38
  159. package/types/storages/utils.d.ts +8 -0
  160. package/types/sync/submitters/submitter.d.ts +2 -2
  161. package/types/sync/submitters/telemetrySubmitter.d.ts +2 -10
  162. package/types/sync/submitters/types.d.ts +27 -7
  163. package/types/sync/submitters/uniqueKeysSubmitter.d.ts +5 -0
  164. package/types/trackers/impressionObserver/utils.d.ts +0 -8
  165. package/types/trackers/impressionsTracker.d.ts +4 -6
  166. package/types/trackers/strategy/strategyDebug.d.ts +9 -0
  167. package/types/trackers/strategy/strategyNone.d.ts +10 -0
  168. package/types/trackers/strategy/strategyOptimized.d.ts +11 -0
  169. package/types/trackers/types.d.ts +23 -0
  170. package/types/trackers/uniqueKeysTracker.d.ts +13 -0
  171. package/types/types.d.ts +1 -1
  172. package/types/utils/constants/index.d.ts +2 -0
  173. package/types/utils/redis/RedisMock.d.ts +4 -0
  174. package/cjs/storages/metadataBuilder.js +0 -12
  175. package/esm/storages/metadataBuilder.js +0 -8
  176. package/src/storages/metadataBuilder.ts +0 -11
@@ -0,0 +1,35 @@
1
+ import { IUniqueKeysCacheBase } from '../types';
2
+ import { UniqueKeysPayloadCs } from '../../sync/submitters/types';
3
+ export declare class UniqueKeysCacheInMemoryCS implements IUniqueKeysCacheBase {
4
+ private onFullQueue?;
5
+ private readonly maxStorage;
6
+ private uniqueTrackerSize;
7
+ private uniqueKeysTracker;
8
+ /**
9
+ *
10
+ * @param impressionsQueueSize number of queued impressions to call onFullQueueCb.
11
+ * Default value is 0, that means no maximum value, in case we want to avoid this being triggered.
12
+ */
13
+ constructor(uniqueKeysQueueSize?: number);
14
+ setOnFullQueueCb(cb: () => void): void;
15
+ /**
16
+ * Store unique keys per feature.
17
+ */
18
+ track(userKey: string, featureName: string): void;
19
+ /**
20
+ * Clear the data stored on the cache.
21
+ */
22
+ clear(): void;
23
+ /**
24
+ * Pop the collected data, used as payload for posting.
25
+ */
26
+ pop(): UniqueKeysPayloadCs;
27
+ /**
28
+ * Check if the cache is empty.
29
+ */
30
+ isEmpty(): boolean;
31
+ /**
32
+ * Converts `uniqueKeys` data from cache into request payload.
33
+ */
34
+ private fromUniqueKeysCollector;
35
+ }
@@ -0,0 +1,16 @@
1
+ import { Redis } from 'ioredis';
2
+ import { ILogger } from '../../logger/types';
3
+ import { ImpressionCountsPayload } from '../../sync/submitters/types';
4
+ import { ImpressionCountsCacheInMemory } from '../inMemory/ImpressionCountsCacheInMemory';
5
+ export declare class ImpressionCountsCacheInRedis extends ImpressionCountsCacheInMemory {
6
+ private readonly log;
7
+ private readonly key;
8
+ private readonly redis;
9
+ private readonly refreshRate;
10
+ private intervalId;
11
+ constructor(log: ILogger, key: string, redis: Redis, impressionCountsCacheSize?: number, refreshRate?: number);
12
+ private postImpressionCountsInRedis;
13
+ start(): void;
14
+ stop(): Promise<boolean | import("ioredis").BooleanResponse | undefined>;
15
+ getImpressionsCount(): Promise<ImpressionCountsPayload | undefined>;
16
+ }
@@ -11,7 +11,6 @@ export declare class ImpressionsCacheInRedis implements IImpressionsCacheAsync {
11
11
  private readonly metadata;
12
12
  constructor(log: ILogger, key: string, redis: Redis, metadata: IMetadata);
13
13
  track(impressions: ImpressionDTO[]): Promise<void>;
14
- private _toJSON;
15
14
  count(): Promise<number>;
16
15
  drop(count?: number): Promise<any>;
17
16
  popNWithMetadata(count: number): Promise<StoredImpressionWithMetadata[]>;
@@ -1 +1,4 @@
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;
@@ -0,0 +1,21 @@
1
+ import { IUniqueKeysCacheBase } from '../types';
2
+ import { Redis } from 'ioredis';
3
+ import { UniqueKeysCacheInMemory } from '../inMemory/UniqueKeysCacheInMemory';
4
+ import { ILogger } from '../../logger/types';
5
+ import { UniqueKeysItemSs } from '../../sync/submitters/types';
6
+ export declare class UniqueKeysCacheInRedis extends UniqueKeysCacheInMemory implements IUniqueKeysCacheBase {
7
+ private readonly log;
8
+ private readonly key;
9
+ private readonly redis;
10
+ private readonly refreshRate;
11
+ private intervalId;
12
+ constructor(log: ILogger, key: string, redis: Redis, uniqueKeysQueueSize?: number, refreshRate?: number);
13
+ private postUniqueKeysInRedis;
14
+ start(): void;
15
+ stop(): Promise<boolean | import("ioredis").BooleanResponse | undefined>;
16
+ /**
17
+ * Async consumer API, used by synchronizer.
18
+ * @param count number of items to pop from the queue. If not provided or equal 0, all items will be popped.
19
+ */
20
+ popNRaw(count?: number): Promise<UniqueKeysItemSs[]>;
21
+ }
@@ -0,0 +1,16 @@
1
+ import { ILogger } from '../../logger/types';
2
+ import { ImpressionCountsPayload } from '../../sync/submitters/types';
3
+ import { ImpressionCountsCacheInMemory } from '../inMemory/ImpressionCountsCacheInMemory';
4
+ import { IPluggableStorageWrapper } from '../types';
5
+ export declare class ImpressionCountsCachePluggable extends ImpressionCountsCacheInMemory {
6
+ private readonly log;
7
+ private readonly key;
8
+ private readonly wrapper;
9
+ private readonly refreshRate;
10
+ private intervalId;
11
+ constructor(log: ILogger, key: string, wrapper: IPluggableStorageWrapper, impressionCountsCacheSize?: number, refreshRate?: number);
12
+ private storeImpressionCounts;
13
+ start(): void;
14
+ stop(): Promise<any>;
15
+ getImpressionsCount(): Promise<ImpressionCountsPayload | undefined>;
16
+ }
@@ -1,8 +1,8 @@
1
1
  import { IPluggableStorageWrapper, IImpressionsCacheAsync } from '../types';
2
2
  import { IMetadata } from '../../dtos/types';
3
3
  import { ImpressionDTO } from '../../types';
4
- import { ILogger } from '../../logger/types';
5
4
  import { StoredImpressionWithMetadata } from '../../sync/submitters/types';
5
+ import { ILogger } from '../../logger/types';
6
6
  export declare class ImpressionsCachePluggable implements IImpressionsCacheAsync {
7
7
  private readonly log;
8
8
  private readonly key;
@@ -16,7 +16,6 @@ export declare class ImpressionsCachePluggable implements IImpressionsCacheAsync
16
16
  * or rejected if the wrapper operation fails.
17
17
  */
18
18
  track(impressions: ImpressionDTO[]): Promise<void>;
19
- private _toJSON;
20
19
  /**
21
20
  * Returns a promise that resolves with the count of stored impressions, or 0 if there was some error.
22
21
  * The promise will never be rejected.
@@ -0,0 +1,20 @@
1
+ import { IPluggableStorageWrapper, IUniqueKeysCacheBase } from '../types';
2
+ import { UniqueKeysCacheInMemory } from '../inMemory/UniqueKeysCacheInMemory';
3
+ import { ILogger } from '../../logger/types';
4
+ import { UniqueKeysItemSs } from '../../sync/submitters/types';
5
+ export declare class UniqueKeysCachePluggable extends UniqueKeysCacheInMemory implements IUniqueKeysCacheBase {
6
+ private readonly log;
7
+ private readonly key;
8
+ private readonly wrapper;
9
+ private readonly refreshRate;
10
+ private intervalId;
11
+ constructor(log: ILogger, key: string, wrapper: IPluggableStorageWrapper, uniqueKeysQueueSize?: number, refreshRate?: number);
12
+ storeUniqueKeys(): Promise<any>;
13
+ start(): void;
14
+ stop(): Promise<any>;
15
+ /**
16
+ * Async consumer API, used by synchronizer.
17
+ * @param count number of items to pop from the queue. If not provided or equal 0, all items will be popped.
18
+ */
19
+ popNRaw(count?: number): Promise<UniqueKeysItemSs[]>;
20
+ }
@@ -1,7 +1,6 @@
1
- import { MaybeThenable, IMetadata, ISplitFiltersValidation, ISplit } from '../dtos/types';
2
- import { ILogger } from '../logger/types';
3
- import { EventDataType, HttpErrors, HttpLatencies, ImpressionDataType, LastSync, Method, MethodExceptions, MethodLatencies, MultiMethodExceptions, MultiMethodLatencies, MultiConfigs, OperationType, StoredEventWithMetadata, StoredImpressionWithMetadata, StreamingEvent } from '../sync/submitters/types';
4
- import { SplitIO, ImpressionDTO, SDKMode } from '../types';
1
+ import { MaybeThenable, ISplit } from '../dtos/types';
2
+ import { EventDataType, HttpErrors, HttpLatencies, ImpressionDataType, LastSync, Method, MethodExceptions, MethodLatencies, MultiMethodExceptions, MultiMethodLatencies, MultiConfigs, OperationType, StoredEventWithMetadata, StoredImpressionWithMetadata, StreamingEvent, UniqueKeysPayloadCs, UniqueKeysPayloadSs, TelemetryUsageStatsPayload } from '../sync/submitters/types';
3
+ import { SplitIO, ImpressionDTO, ISettings } from '../types';
5
4
  /**
6
5
  * Interface of a pluggable storage wrapper.
7
6
  */
@@ -65,23 +64,25 @@ export interface IPluggableStorageWrapper {
65
64
  getMany: (keys: string[]) => Promise<(string | null)[]>;
66
65
  /** Integer operations */
67
66
  /**
68
- * Increments in 1 the given `key` value or set it to 1 if the value doesn't exist.
67
+ * Increments the number stored at `key` by `increment`, or set it to `increment` if the value doesn't exist.
69
68
  *
70
69
  * @function incr
71
70
  * @param {string} key Key to increment
71
+ * @param {number} increment Value to increment by. Defaults to 1.
72
72
  * @returns {Promise<number>} A promise that resolves with the value of key after the increment. The promise rejects if the operation fails,
73
73
  * for example, if there is a connection error or the key contains a string that can not be represented as integer.
74
74
  */
75
- incr: (key: string) => Promise<number>;
75
+ incr: (key: string, increment?: number) => Promise<number>;
76
76
  /**
77
- * Decrements in 1 the given `key` value or set it to -1 if the value doesn't exist.
77
+ * Decrements the number stored at `key` by `decrement`, or set it to minus `decrement` if the value doesn't exist.
78
78
  *
79
79
  * @function decr
80
80
  * @param {string} key Key to decrement
81
+ * @param {number} decrement Value to decrement by. Defaults to 1.
81
82
  * @returns {Promise<number>} A promise that resolves with the value of key after the decrement. The promise rejects if the operation fails,
82
83
  * for example, if there is a connection error or the key contains a string that can not be represented as integer.
83
84
  */
84
- decr: (key: string) => Promise<number>;
85
+ decr: (key: string, decrement?: number) => Promise<number>;
85
86
  /** Queue operations */
86
87
  /**
87
88
  * Inserts given items at the tail of `key` list. If `key` does not exist, an empty list is created before pushing the items.
@@ -262,41 +263,43 @@ export interface IImpressionsCacheBase {
262
263
  export interface IEventsCacheBase {
263
264
  track(data: SplitIO.EventData, size?: number): MaybeThenable<boolean>;
264
265
  }
265
- /** Impressions and events cache for standalone mode (sync) */
266
- export interface IRecorderCacheProducerSync<T> {
266
+ export interface IImpressionCountsCacheBase {
267
+ track(featureName: string, timeFrame: number, amount: number): void;
268
+ }
269
+ export interface IUniqueKeysCacheBase {
270
+ track(key: string, value: string): void;
271
+ }
272
+ /** Impressions and events cache for standalone and partial consumer modes (sync methods) */
273
+ export interface IRecorderCacheSync<T> {
267
274
  isEmpty(): boolean;
268
275
  clear(): void;
269
276
  pop(toMerge?: T): T;
270
277
  }
271
- export interface IImpressionsCacheSync extends IImpressionsCacheBase, IRecorderCacheProducerSync<ImpressionDTO[]> {
278
+ export interface IImpressionsCacheSync extends IImpressionsCacheBase, IRecorderCacheSync<ImpressionDTO[]> {
272
279
  track(data: ImpressionDTO[]): void;
273
280
  setOnFullQueueCb(cb: () => void): void;
274
281
  }
275
- export interface IEventsCacheSync extends IEventsCacheBase, IRecorderCacheProducerSync<SplitIO.EventData[]> {
282
+ export interface IEventsCacheSync extends IEventsCacheBase, IRecorderCacheSync<SplitIO.EventData[]> {
276
283
  track(data: SplitIO.EventData, size?: number): boolean;
277
284
  setOnFullQueueCb(cb: () => void): void;
278
285
  }
279
- /** Impressions and events cache for consumer and producer mode (async) */
280
- export interface IRecorderCacheProducerAsync<T> {
286
+ export interface IImpressionCountsCacheSync extends IImpressionCountsCacheBase, IRecorderCacheSync<Record<string, number>> {
287
+ }
288
+ export interface IUniqueKeysCacheSync extends IUniqueKeysCacheBase, IRecorderCacheSync<UniqueKeysPayloadSs | UniqueKeysPayloadCs> {
289
+ setOnFullQueueCb(cb: () => void): void;
290
+ }
291
+ /** Impressions and events cache for consumer and producer modes (async methods) */
292
+ export interface IRecorderCacheAsync<T> {
281
293
  count(): Promise<number>;
282
294
  drop(count?: number): Promise<void>;
283
295
  popNWithMetadata(count: number): Promise<T>;
284
296
  }
285
- export interface IImpressionsCacheAsync extends IImpressionsCacheBase, IRecorderCacheProducerAsync<StoredImpressionWithMetadata[]> {
297
+ export interface IImpressionsCacheAsync extends IImpressionsCacheBase, IRecorderCacheAsync<StoredImpressionWithMetadata[]> {
286
298
  track(data: ImpressionDTO[]): Promise<void>;
287
299
  }
288
- export interface IEventsCacheAsync extends IEventsCacheBase, IRecorderCacheProducerAsync<StoredEventWithMetadata[]> {
300
+ export interface IEventsCacheAsync extends IEventsCacheBase, IRecorderCacheAsync<StoredEventWithMetadata[]> {
289
301
  track(data: SplitIO.EventData, size?: number): Promise<boolean>;
290
302
  }
291
- /**
292
- * Impression counts cache for impressions dedup in standalone and producer mode.
293
- * Only in memory. Named `ImpressionsCounter` in spec.
294
- */
295
- export interface IImpressionCountsCacheSync extends IRecorderCacheProducerSync<Record<string, number>> {
296
- track(featureName: string, timeFrame: number, amount: number): void;
297
- isEmpty(): boolean;
298
- pop(toMerge?: Record<string, number>): Record<string, number>;
299
- }
300
303
  /**
301
304
  * Telemetry storage interface for standalone and partial consumer modes.
302
305
  * Methods are sync because data is stored in memory.
@@ -347,7 +350,7 @@ export interface ITelemetryEvaluationProducerSync {
347
350
  }
348
351
  export interface ITelemetryStorageProducerSync extends ITelemetryInitProducerSync, ITelemetryRuntimeProducerSync, ITelemetryEvaluationProducerSync {
349
352
  }
350
- export interface ITelemetryCacheSync extends ITelemetryStorageConsumerSync, ITelemetryStorageProducerSync {
353
+ export interface ITelemetryCacheSync extends ITelemetryStorageConsumerSync, ITelemetryStorageProducerSync, IRecorderCacheSync<TelemetryUsageStatsPayload> {
351
354
  }
352
355
  /**
353
356
  * Telemetry storage interface for consumer mode.
@@ -368,32 +371,30 @@ export interface ITelemetryCacheAsync extends ITelemetryEvaluationProducerAsync,
368
371
  /**
369
372
  * Storages
370
373
  */
371
- export interface IStorageBase<TSplitsCache extends ISplitsCacheBase, TSegmentsCache extends ISegmentsCacheBase, TImpressionsCache extends IImpressionsCacheBase, TEventsCache extends IEventsCacheBase, TTelemetryCache extends ITelemetryCacheSync | ITelemetryCacheAsync> {
374
+ export interface IStorageBase<TSplitsCache extends ISplitsCacheBase, TSegmentsCache extends ISegmentsCacheBase, TImpressionsCache extends IImpressionsCacheBase, TImpressionsCountCache extends IImpressionCountsCacheBase, TEventsCache extends IEventsCacheBase, TTelemetryCache extends ITelemetryCacheSync | ITelemetryCacheAsync, TUniqueKeysCache extends IUniqueKeysCacheBase> {
372
375
  splits: TSplitsCache;
373
376
  segments: TSegmentsCache;
374
377
  impressions: TImpressionsCache;
375
- impressionCounts?: IImpressionCountsCacheSync;
378
+ impressionCounts?: TImpressionsCountCache;
376
379
  events: TEventsCache;
377
380
  telemetry?: TTelemetryCache;
381
+ uniqueKeys?: TUniqueKeysCache;
378
382
  destroy(): void | Promise<void>;
379
383
  shared?: (matchingKey: string, onReadyCb: (error?: any) => void) => this;
380
384
  }
381
- export interface IStorageSync extends IStorageBase<ISplitsCacheSync, ISegmentsCacheSync, IImpressionsCacheSync, IEventsCacheSync, ITelemetryCacheSync> {
385
+ export interface IStorageSync extends IStorageBase<ISplitsCacheSync, ISegmentsCacheSync, IImpressionsCacheSync, IImpressionCountsCacheSync, IEventsCacheSync, ITelemetryCacheSync, IUniqueKeysCacheSync> {
382
386
  }
383
- export interface IStorageAsync extends IStorageBase<ISplitsCacheAsync, ISegmentsCacheAsync, IImpressionsCacheAsync | IImpressionsCacheSync, IEventsCacheAsync | IEventsCacheSync, ITelemetryCacheAsync | ITelemetryCacheSync> {
387
+ export interface IStorageAsync extends IStorageBase<ISplitsCacheAsync, ISegmentsCacheAsync, IImpressionsCacheAsync | IImpressionsCacheSync, IImpressionCountsCacheBase, IEventsCacheAsync | IEventsCacheSync, ITelemetryCacheAsync | ITelemetryCacheSync, IUniqueKeysCacheBase> {
384
388
  }
385
389
  /** StorageFactory */
386
390
  export declare type DataLoader = (storage: IStorageSync, matchingKey: string) => void;
387
391
  export interface IStorageFactoryParams {
388
- log: ILogger;
389
- impressionsQueueSize?: number;
390
- eventsQueueSize?: number;
391
- optimize?: boolean;
392
- mode: SDKMode;
393
- matchingKey?: string;
394
- splitFiltersValidation?: ISplitFiltersValidation;
392
+ settings: ISettings;
393
+ /**
394
+ * Error-first callback invoked when the storage is ready to be used. An error means that the storage failed to connect and shouldn't be used.
395
+ * It is meant for emitting SDK_READY event in consumer mode, and waiting before using the storage in the synchronizer.
396
+ */
395
397
  onReadyCb: (error?: any) => void;
396
- metadata: IMetadata;
397
398
  }
398
399
  export declare type StorageType = 'MEMORY' | 'LOCALSTORAGE' | 'REDIS' | 'PLUGGABLE';
399
400
  export declare type IStorageSyncFactory = {
@@ -0,0 +1,8 @@
1
+ import { IMetadata } from '../dtos/types';
2
+ import { Method } from '../sync/submitters/types';
3
+ import { ImpressionDTO, ISettings } from '../types';
4
+ export declare function metadataBuilder(settings: Pick<ISettings, 'version' | 'runtime'>): IMetadata;
5
+ export declare function impressionsToJSON(impressions: ImpressionDTO[], metadata: IMetadata): string[];
6
+ export declare function parseMetadata(field: string): [metadata: string] | string;
7
+ export declare function parseExceptionField(field: string): [metadata: string, method: Method] | string;
8
+ export declare function parseLatencyField(field: string): [metadata: string, method: Method, bucket: number] | string;
@@ -1,11 +1,11 @@
1
1
  import { ISyncTask } from '../types';
2
- import { IRecorderCacheProducerSync } from '../../storages/types';
2
+ import { IRecorderCacheSync } from '../../storages/types';
3
3
  import { ILogger } from '../../logger/types';
4
4
  import { IResponse } from '../../services/types';
5
5
  /**
6
6
  * Base function to create submitters, such as ImpressionsSubmitter and EventsSubmitter
7
7
  */
8
- export declare function submitterFactory<T>(log: ILogger, postClient: (body: string) => Promise<IResponse>, sourceCache: IRecorderCacheProducerSync<T>, postRate: number, dataName: string, fromCacheToPayload?: (cacheData: T) => any, maxRetries?: number, debugLogs?: boolean): ISyncTask<[], void>;
8
+ export declare function submitterFactory<T>(log: ILogger, postClient: (body: string) => Promise<IResponse>, sourceCache: IRecorderCacheSync<T>, postRate: number, dataName: string, fromCacheToPayload?: (cacheData: T) => any, maxRetries?: number, debugLogs?: boolean): ISyncTask<[], void>;
9
9
  /**
10
10
  * Decorates a provided submitter with a first execution window
11
11
  */
@@ -1,15 +1,7 @@
1
- import { ISegmentsCacheSync, ISplitsCacheSync, ITelemetryCacheSync } from '../../storages/types';
2
- import { TelemetryUsageStatsPayload, TelemetryConfigStatsPayload, TelemetryConfigStats } from './types';
1
+ import { ITelemetryCacheSync } from '../../storages/types';
2
+ import { TelemetryConfigStatsPayload, TelemetryConfigStats } from './types';
3
3
  import { ISettings, SDKMode } from '../../types';
4
4
  import { ISdkFactoryContextSync } from '../../sdkFactory/types';
5
- /**
6
- * Converts data from telemetry cache into /metrics/usage request payload.
7
- */
8
- export declare function telemetryCacheStatsAdapter(telemetry: ITelemetryCacheSync, splits?: ISplitsCacheSync, segments?: ISegmentsCacheSync): {
9
- isEmpty(): boolean;
10
- clear(): void;
11
- pop(): TelemetryUsageStatsPayload;
12
- };
13
5
  export declare function getTelemetryConfigStats(mode: SDKMode, storageType: string): TelemetryConfigStats;
14
6
  /**
15
7
  * Converts data from telemetry cache and settings into /metrics/config request payload.
@@ -33,6 +33,23 @@ export declare type ImpressionCountsPayload = {
33
33
  rc: number;
34
34
  }[];
35
35
  };
36
+ export declare type UniqueKeysItemSs = {
37
+ /** Split name */
38
+ f: string;
39
+ /** keyNames */
40
+ ks: string[];
41
+ };
42
+ export declare type UniqueKeysPayloadSs = {
43
+ keys: UniqueKeysItemSs[];
44
+ };
45
+ export declare type UniqueKeysPayloadCs = {
46
+ keys: {
47
+ /** keyNames */
48
+ k: string;
49
+ /** Split name */
50
+ fs: string[];
51
+ }[];
52
+ };
36
53
  export declare type StoredImpressionWithMetadata = {
37
54
  /** Metadata */
38
55
  m: IMetadata;
@@ -52,6 +69,8 @@ export declare type StoredImpressionWithMetadata = {
52
69
  c: number;
53
70
  /** time */
54
71
  m: number;
72
+ /** previous time */
73
+ pt?: number;
55
74
  };
56
75
  };
57
76
  export declare type StoredEventWithMetadata = {
@@ -80,19 +99,19 @@ export declare type TOKEN = 'to';
80
99
  export declare type SEGMENT = 'se';
81
100
  export declare type MY_SEGMENT = 'ms';
82
101
  export declare type OperationType = SPLITS | IMPRESSIONS | IMPRESSIONS_COUNT | EVENTS | TELEMETRY | TOKEN | SEGMENT | MY_SEGMENT;
83
- export declare type LastSync = Record<OperationType, number | undefined>;
84
- export declare type HttpErrors = Record<OperationType, {
102
+ export declare type LastSync = Partial<Record<OperationType, number | undefined>>;
103
+ export declare type HttpErrors = Partial<Record<OperationType, {
85
104
  [statusCode: string]: number;
86
- }>;
87
- export declare type HttpLatencies = Record<OperationType, Array<number>>;
105
+ }>>;
106
+ export declare type HttpLatencies = Partial<Record<OperationType, Array<number>>>;
88
107
  export declare type TREATMENT = 't';
89
108
  export declare type TREATMENTS = 'ts';
90
109
  export declare type TREATMENT_WITH_CONFIG = 'tc';
91
110
  export declare type TREATMENTS_WITH_CONFIG = 'tcs';
92
111
  export declare type TRACK = 'tr';
93
112
  export declare type Method = TREATMENT | TREATMENTS | TREATMENT_WITH_CONFIG | TREATMENTS_WITH_CONFIG | TRACK;
94
- export declare type MethodLatencies = Record<Method, Array<number>>;
95
- export declare type MethodExceptions = Record<Method, number>;
113
+ export declare type MethodLatencies = Partial<Record<Method, Array<number>>>;
114
+ export declare type MethodExceptions = Partial<Record<Method, number>>;
96
115
  export declare type CONNECTION_ESTABLISHED = 0;
97
116
  export declare type OCCUPANCY_PRI = 10;
98
117
  export declare type OCCUPANCY_SEC = 20;
@@ -138,7 +157,8 @@ export declare type CONSUMER_PARTIAL_ENUM = 2;
138
157
  export declare type OperationMode = STANDALONE_ENUM | CONSUMER_ENUM | CONSUMER_PARTIAL_ENUM;
139
158
  export declare type OPTIMIZED_ENUM = 0;
140
159
  export declare type DEBUG_ENUM = 1;
141
- export declare type ImpressionsMode = OPTIMIZED_ENUM | DEBUG_ENUM;
160
+ export declare type NONE_ENUM = 2;
161
+ export declare type ImpressionsMode = OPTIMIZED_ENUM | DEBUG_ENUM | NONE_ENUM;
142
162
  export declare type RefreshRates = {
143
163
  sp: number;
144
164
  se?: number;
@@ -0,0 +1,5 @@
1
+ import { ISdkFactoryContextSync } from '../../sdkFactory/types';
2
+ /**
3
+ * Submitter that periodically posts impression counts
4
+ */
5
+ export declare function uniqueKeysSubmitterFactory(params: ISdkFactoryContextSync): import("../types").ISyncTask<[], void>;
@@ -1,12 +1,4 @@
1
1
  import { ISettings } from '../../types';
2
- /**
3
- * Checks if impressions previous time should be added or not.
4
- */
5
- export declare function shouldAddPt(settings: ISettings): boolean;
6
- /**
7
- * Checks if it should dedupe impressions or not.
8
- */
9
- export declare function shouldBeOptimized(settings: ISettings): boolean;
10
2
  /**
11
3
  * Storage is async if mode is consumer or partial consumer
12
4
  */
@@ -1,7 +1,6 @@
1
- import { IImpressionCountsCacheSync, IImpressionsCacheBase, ITelemetryCacheSync, ITelemetryCacheAsync } from '../storages/types';
2
- import { IImpressionsHandler, IImpressionsTracker } from './types';
1
+ import { IImpressionsCacheBase, ITelemetryCacheSync, ITelemetryCacheAsync } from '../storages/types';
2
+ import { IImpressionsHandler, IImpressionsTracker, IStrategy } from './types';
3
3
  import { ISettings } from '../types';
4
- import { IImpressionObserver } from './impressionObserver/types';
5
4
  /**
6
5
  * Impressions tracker stores impressions in cache and pass them to the listener and integrations manager if provided.
7
6
  *
@@ -9,7 +8,6 @@ import { IImpressionObserver } from './impressionObserver/types';
9
8
  * @param metadata runtime metadata (ip, hostname and version)
10
9
  * @param impressionListener optional impression listener
11
10
  * @param integrationsManager optional integrations manager
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)
11
+ * @param strategy strategy for impressions tracking.
14
12
  */
15
- export declare function impressionsTrackerFactory(settings: ISettings, impressionsCache: IImpressionsCacheBase, integrationsManager?: IImpressionsHandler, observer?: IImpressionObserver, countsCache?: IImpressionCountsCacheSync, telemetryCache?: ITelemetryCacheSync | ITelemetryCacheAsync): IImpressionsTracker;
13
+ export declare function impressionsTrackerFactory(settings: ISettings, impressionsCache: IImpressionsCacheBase, strategy: IStrategy, integrationsManager?: IImpressionsHandler, telemetryCache?: ITelemetryCacheSync | ITelemetryCacheAsync): IImpressionsTracker;
@@ -0,0 +1,9 @@
1
+ import { IImpressionObserver } from '../impressionObserver/types';
2
+ import { IStrategy } from '../types';
3
+ /**
4
+ * Debug strategy for impressions tracker. Wraps impressions to store and adds previousTime if it corresponds
5
+ *
6
+ * @param impressionsObserver impression observer. Previous time (pt property) is included in impression instances
7
+ * @returns IStrategyResult
8
+ */
9
+ export declare function strategyDebugFactory(impressionsObserver: IImpressionObserver): IStrategy;
@@ -0,0 +1,10 @@
1
+ import { IImpressionCountsCacheBase } from '../../storages/types';
2
+ import { IStrategy, IUniqueKeysTracker } from '../types';
3
+ /**
4
+ * None strategy for impressions tracker.
5
+ *
6
+ * @param impressionsCounter cache to save impressions count. impressions will be deduped (OPTIMIZED mode)
7
+ * @param uniqueKeysTracker unique keys tracker in charge of tracking the unique keys per split.
8
+ * @returns IStrategyResult
9
+ */
10
+ export declare function strategyNoneFactory(impressionsCounter: IImpressionCountsCacheBase, uniqueKeysTracker: IUniqueKeysTracker): IStrategy;
@@ -0,0 +1,11 @@
1
+ import { IImpressionCountsCacheBase } from '../../storages/types';
2
+ import { IImpressionObserver } from '../impressionObserver/types';
3
+ import { IStrategy } from '../types';
4
+ /**
5
+ * Optimized 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
+ * @param impressionsCounter cache to save impressions count. impressions will be deduped (OPTIMIZED mode)
9
+ * @returns IStrategyResult
10
+ */
11
+ export declare function strategyOptimizedFactory(impressionsObserver: IImpressionObserver, impressionsCounter: IImpressionCountsCacheBase): IStrategy;
@@ -38,3 +38,26 @@ export interface ITelemetryTracker {
38
38
  */
39
39
  addTag(tag: string): void;
40
40
  }
41
+ export interface IFilterAdapter {
42
+ add(key: string, featureName: string): boolean;
43
+ contains(key: string, featureName: string): boolean;
44
+ clear(): void;
45
+ refreshRate?: number;
46
+ }
47
+ export interface IImpressionSenderAdapter {
48
+ recordUniqueKeys(data: Object): void;
49
+ recordImpressionCounts(data: Object): void;
50
+ }
51
+ /** Unique keys tracker */
52
+ export interface IUniqueKeysTracker {
53
+ stop(): void;
54
+ track(key: string, featureName: string): void;
55
+ }
56
+ export interface IStrategyResult {
57
+ impressionsToStore: ImpressionDTO[];
58
+ impressionsToListener: ImpressionDTO[];
59
+ deduped: number;
60
+ }
61
+ export interface IStrategy {
62
+ process(impressions: ImpressionDTO[]): IStrategyResult;
63
+ }
@@ -0,0 +1,13 @@
1
+ import { ILogger } from '../logger/types';
2
+ import { IUniqueKeysCacheBase } from '../storages/types';
3
+ import { IFilterAdapter, IUniqueKeysTracker } from './types';
4
+ /**
5
+ * Trackes uniques keys
6
+ * Unique Keys Tracker will be in charge of checking if the MTK was already sent to the BE in the last period
7
+ * or schedule to be sent; if not it will be added in an internal cache and sent in the next post.
8
+ *
9
+ * @param log Logger instance
10
+ * @param uniqueKeysCache cache to save unique keys
11
+ * @param filterAdapter filter adapter
12
+ */
13
+ export declare function uniqueKeysTrackerFactory(log: ILogger, uniqueKeysCache: IUniqueKeysCacheBase, filterAdapter?: IFilterAdapter): IUniqueKeysTracker;
package/types/types.d.ts CHANGED
@@ -715,7 +715,7 @@ export declare namespace SplitIO {
715
715
  * ImpressionsMode type
716
716
  * @typedef {string} ImpressionsMode
717
717
  */
718
- type ImpressionsMode = 'OPTIMIZED' | 'DEBUG';
718
+ type ImpressionsMode = 'OPTIMIZED' | 'DEBUG' | 'NONE';
719
719
  /**
720
720
  * Defines the format of Split data to preload on the factory storage (cache).
721
721
  */
@@ -11,6 +11,7 @@ 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";
14
15
  export declare const LOCALHOST_MODE: SDKMode;
15
16
  export declare const STANDALONE_MODE: SDKMode;
16
17
  export declare const PRODUCER_MODE = "producer";
@@ -31,6 +32,7 @@ export declare const CONSUMER_ENUM = 1;
31
32
  export declare const CONSUMER_PARTIAL_ENUM = 2;
32
33
  export declare const OPTIMIZED_ENUM = 0;
33
34
  export declare const DEBUG_ENUM = 1;
35
+ export declare const NONE_ENUM = 2;
34
36
  export declare const SPLITS = "sp";
35
37
  export declare const IMPRESSIONS = "im";
36
38
  export declare const IMPRESSIONS_COUNT = "ic";
@@ -0,0 +1,4 @@
1
+ export declare class RedisMock {
2
+ private pipelineMethods;
3
+ constructor();
4
+ }
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.metadataBuilder = void 0;
4
- var constants_1 = require("../utils/constants");
5
- function metadataBuilder(settings) {
6
- return {
7
- s: settings.version,
8
- i: settings.runtime.ip || constants_1.UNKNOWN,
9
- n: settings.runtime.hostname || constants_1.UNKNOWN,
10
- };
11
- }
12
- exports.metadataBuilder = metadataBuilder;
@@ -1,8 +0,0 @@
1
- import { UNKNOWN } from '../utils/constants';
2
- export function metadataBuilder(settings) {
3
- return {
4
- s: settings.version,
5
- i: settings.runtime.ip || UNKNOWN,
6
- n: settings.runtime.hostname || UNKNOWN,
7
- };
8
- }
@@ -1,11 +0,0 @@
1
- import { IMetadata } from '../dtos/types';
2
- import { ISettings } from '../types';
3
- import { UNKNOWN } from '../utils/constants';
4
-
5
- export function metadataBuilder(settings: Pick<ISettings, 'version' | 'runtime'>): IMetadata {
6
- return {
7
- s: settings.version,
8
- i: settings.runtime.ip || UNKNOWN,
9
- n: settings.runtime.hostname || UNKNOWN,
10
- };
11
- }