@splitsoftware/splitio-commons 1.6.2-rc.6 → 1.6.2-rc.7
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.
- package/CHANGES.txt +3 -0
- package/cjs/consent/sdkUserConsent.js +2 -2
- package/cjs/listeners/browser.js +2 -1
- package/cjs/logger/constants.js +2 -1
- package/cjs/sdkClient/sdkClient.js +3 -1
- package/cjs/sdkFactory/index.js +26 -5
- package/cjs/services/splitApi.js +20 -0
- package/cjs/storages/KeyBuilderSS.js +6 -0
- package/cjs/storages/inLocalStorage/index.js +4 -0
- package/cjs/storages/inMemory/ImpressionCountsCacheInMemory.js +12 -1
- package/cjs/storages/inMemory/InMemoryStorage.js +5 -1
- package/cjs/storages/inMemory/InMemoryStorageCS.js +5 -1
- package/cjs/storages/inMemory/uniqueKeysCacheInMemory.js +73 -0
- package/cjs/storages/inMemory/uniqueKeysCacheInMemoryCS.js +78 -0
- package/cjs/storages/inRedis/ImpressionCountsCacheInRedis.js +49 -0
- package/cjs/storages/inRedis/constants.js +4 -1
- package/cjs/storages/inRedis/index.js +15 -1
- package/cjs/storages/inRedis/uniqueKeysCacheInRedis.js +56 -0
- package/cjs/sync/submitters/submitterManager.js +3 -0
- package/cjs/sync/submitters/telemetrySubmitter.js +1 -0
- package/cjs/sync/submitters/uniqueKeysSubmitter.js +26 -0
- package/cjs/trackers/impressionsTracker.js +22 -41
- package/cjs/trackers/strategy/strategyDebug.js +25 -0
- package/cjs/trackers/strategy/strategyNone.js +29 -0
- package/cjs/trackers/strategy/strategyOptimized.js +35 -0
- package/cjs/trackers/uniqueKeysTracker.js +38 -0
- package/cjs/utils/constants/index.js +4 -2
- package/cjs/utils/settingsValidation/impressionsMode.js +2 -2
- package/cjs/utils/settingsValidation/index.js +4 -0
- package/esm/consent/sdkUserConsent.js +2 -2
- package/esm/listeners/browser.js +3 -2
- package/esm/logger/constants.js +1 -0
- package/esm/sdkClient/sdkClient.js +3 -1
- package/esm/sdkFactory/index.js +26 -5
- package/esm/services/splitApi.js +20 -0
- package/esm/storages/KeyBuilderSS.js +6 -0
- package/esm/storages/inLocalStorage/index.js +5 -1
- package/esm/storages/inMemory/ImpressionCountsCacheInMemory.js +12 -1
- package/esm/storages/inMemory/InMemoryStorage.js +6 -2
- package/esm/storages/inMemory/InMemoryStorageCS.js +6 -2
- package/esm/storages/inMemory/uniqueKeysCacheInMemory.js +70 -0
- package/esm/storages/inMemory/uniqueKeysCacheInMemoryCS.js +75 -0
- package/esm/storages/inRedis/ImpressionCountsCacheInRedis.js +46 -0
- package/esm/storages/inRedis/constants.js +3 -0
- package/esm/storages/inRedis/index.js +16 -2
- package/esm/storages/inRedis/uniqueKeysCacheInRedis.js +53 -0
- package/esm/sync/submitters/submitterManager.js +3 -0
- package/esm/sync/submitters/telemetrySubmitter.js +2 -1
- package/esm/sync/submitters/uniqueKeysSubmitter.js +22 -0
- package/esm/trackers/impressionsTracker.js +22 -41
- package/esm/trackers/strategy/strategyDebug.js +21 -0
- package/esm/trackers/strategy/strategyNone.js +25 -0
- package/esm/trackers/strategy/strategyOptimized.js +31 -0
- package/esm/trackers/uniqueKeysTracker.js +34 -0
- package/esm/utils/constants/index.js +2 -0
- package/esm/utils/settingsValidation/impressionsMode.js +3 -3
- package/esm/utils/settingsValidation/index.js +4 -0
- package/package.json +1 -1
- package/src/consent/sdkUserConsent.ts +2 -2
- package/src/listeners/browser.ts +3 -2
- package/src/logger/constants.ts +1 -0
- package/src/sdkClient/sdkClient.ts +3 -1
- package/src/sdkFactory/index.ts +29 -5
- package/src/sdkFactory/types.ts +7 -4
- package/src/services/splitApi.ts +22 -0
- package/src/services/types.ts +6 -0
- package/src/storages/AbstractSplitsCacheAsync.ts +0 -1
- package/src/storages/KeyBuilderSS.ts +8 -0
- package/src/storages/inLocalStorage/index.ts +4 -1
- package/src/storages/inMemory/ImpressionCountsCacheInMemory.ts +16 -1
- package/src/storages/inMemory/InMemoryStorage.ts +5 -2
- package/src/storages/inMemory/InMemoryStorageCS.ts +6 -2
- package/src/storages/inMemory/uniqueKeysCacheInMemory.ts +82 -0
- package/src/storages/inMemory/uniqueKeysCacheInMemoryCS.ts +88 -0
- package/src/storages/inRedis/ImpressionCountsCacheInRedis.ts +51 -0
- package/src/storages/inRedis/constants.ts +3 -0
- package/src/storages/inRedis/index.ts +12 -3
- package/src/storages/inRedis/uniqueKeysCacheInRedis.ts +63 -0
- package/src/storages/types.ts +30 -8
- package/src/sync/submitters/submitterManager.ts +2 -0
- package/src/sync/submitters/telemetrySubmitter.ts +4 -3
- package/src/sync/submitters/types.ts +20 -1
- package/src/sync/submitters/uniqueKeysSubmitter.ts +35 -0
- package/src/trackers/impressionsTracker.ts +27 -48
- package/src/trackers/strategy/strategyDebug.ts +28 -0
- package/src/trackers/strategy/strategyNone.ts +34 -0
- package/src/trackers/strategy/strategyOptimized.ts +42 -0
- package/src/trackers/types.ts +28 -0
- package/src/trackers/uniqueKeysTracker.ts +48 -0
- package/src/types.ts +5 -1
- package/src/utils/constants/index.ts +2 -0
- package/src/utils/settingsValidation/impressionsMode.ts +3 -3
- package/src/utils/settingsValidation/index.ts +5 -0
- package/types/logger/constants.d.ts +1 -0
- package/types/sdkClient/types.d.ts +18 -0
- package/types/sdkFactory/types.d.ts +4 -2
- package/types/services/types.d.ts +4 -0
- package/types/storages/KeyBuilderSS.d.ts +2 -0
- package/types/storages/inMemory/CountsCacheInMemory.d.ts +20 -0
- package/types/storages/inMemory/ImpressionCountsCacheInMemory.d.ts +5 -1
- package/types/storages/inMemory/LatenciesCacheInMemory.d.ts +20 -0
- package/types/storages/inMemory/uniqueKeysCacheInMemory.d.ts +35 -0
- package/types/storages/inMemory/uniqueKeysCacheInMemoryCS.d.ts +37 -0
- package/types/storages/inRedis/CountsCacheInRedis.d.ts +9 -0
- package/types/storages/inRedis/ImpressionCountsCacheInRedis.d.ts +14 -0
- package/types/storages/inRedis/LatenciesCacheInRedis.d.ts +9 -0
- package/types/storages/inRedis/constants.d.ts +3 -0
- package/types/storages/inRedis/uniqueKeysCacheInRedis.d.ts +15 -0
- package/types/storages/types.d.ts +18 -5
- package/types/sync/offline/LocalhostFromFile.d.ts +2 -0
- package/types/sync/offline/splitsParser/splitsParserFromFile.d.ts +2 -0
- package/types/sync/submitters/eventsSyncTask.d.ts +8 -0
- package/types/sync/submitters/impressionCountsSubmitterInRedis.d.ts +5 -0
- package/types/sync/submitters/impressionCountsSyncTask.d.ts +13 -0
- package/types/sync/submitters/impressionsSyncTask.d.ts +14 -0
- package/types/sync/submitters/metricsSyncTask.d.ts +12 -0
- package/types/sync/submitters/submitterSyncTask.d.ts +10 -0
- package/types/sync/submitters/types.d.ts +18 -1
- package/types/sync/submitters/uniqueKeysSubmitter.d.ts +5 -0
- package/types/sync/submitters/uniqueKeysSubmitterInRedis.d.ts +5 -0
- package/types/sync/syncTaskComposite.d.ts +5 -0
- package/types/trackers/filter/bloomFilter.d.ts +10 -0
- package/types/trackers/filter/dictionaryFilter.d.ts +8 -0
- package/types/trackers/filter/types.d.ts +5 -0
- package/types/trackers/impressionsTracker.d.ts +4 -6
- package/types/trackers/strategy/strategyDebug.d.ts +9 -0
- package/types/trackers/strategy/strategyNone.d.ts +10 -0
- package/types/trackers/strategy/strategyOptimized.d.ts +11 -0
- package/types/trackers/types.d.ts +23 -0
- package/types/trackers/uniqueKeysTracker.d.ts +13 -0
- package/types/types.d.ts +5 -1
- package/types/utils/constants/index.d.ts +2 -0
- package/types/utils/settingsValidation/index.d.ts +1 -0
- package/types/utils/timeTracker/index.d.ts +70 -0
- package/src/logger/.DS_Store +0 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ISignalListener } from '../listeners/types';
|
|
2
|
+
import { ISdkReadinessManager } from '../readiness/types';
|
|
3
|
+
import { IStorageAsync, IStorageSync } from '../storages/types';
|
|
4
|
+
import { ISyncManager } from '../sync/types';
|
|
5
|
+
import { IEventTracker, IImpressionsTracker } from '../trackers/types';
|
|
6
|
+
import { ISettings } from '../types';
|
|
7
|
+
export interface IClientFactoryParams {
|
|
8
|
+
storage: IStorageSync | IStorageAsync;
|
|
9
|
+
sdkReadinessManager: ISdkReadinessManager;
|
|
10
|
+
settings: ISettings;
|
|
11
|
+
impressionsTracker: IImpressionsTracker;
|
|
12
|
+
eventTracker: IEventTracker;
|
|
13
|
+
}
|
|
14
|
+
export interface ISdkClientFactoryParams extends IClientFactoryParams {
|
|
15
|
+
signalListener?: ISignalListener;
|
|
16
|
+
syncManager?: ISyncManager;
|
|
17
|
+
sharedClient?: boolean;
|
|
18
|
+
}
|
|
@@ -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 } from '../trackers/types';
|
|
9
|
+
import { IImpressionsTracker, IEventTracker, ITelemetryTracker, IFilterAdapter, IUniqueKeysTracker } from '../trackers/types';
|
|
10
10
|
import { SplitIO, ISettings, IEventEmitter } from '../types';
|
|
11
11
|
/**
|
|
12
12
|
* Environment related dependencies.
|
|
@@ -42,6 +42,7 @@ export interface ISdkFactoryContext {
|
|
|
42
42
|
eventTracker: IEventTracker;
|
|
43
43
|
telemetryTracker: ITelemetryTracker;
|
|
44
44
|
storage: IStorageSync | IStorageAsync;
|
|
45
|
+
uniqueKeysTracker?: IUniqueKeysTracker;
|
|
45
46
|
signalListener?: ISignalListener;
|
|
46
47
|
splitApi?: ISplitApi;
|
|
47
48
|
syncManager?: ISyncManager;
|
|
@@ -70,11 +71,12 @@ export interface ISdkFactoryParams {
|
|
|
70
71
|
(): SplitIO.ICsClient;
|
|
71
72
|
(key: SplitIO.SplitKey, trafficType?: string | undefined): SplitIO.ICsClient;
|
|
72
73
|
} | (() => SplitIO.IClient) | (() => SplitIO.IAsyncClient));
|
|
74
|
+
impressionsObserverFactory: () => IImpressionObserver;
|
|
75
|
+
filterAdapterFactory?: () => IFilterAdapter;
|
|
73
76
|
SignalListener?: new (syncManager: ISyncManager | undefined, // Used by NodeSignalListener to flush data, and by BrowserSignalListener to close streaming connection.
|
|
74
77
|
settings: ISettings, // Used by BrowserSignalListener
|
|
75
78
|
storage: IStorageSync | IStorageAsync, // Used by BrowserSignalListener
|
|
76
79
|
serviceApi: ISplitApi | undefined) => ISignalListener;
|
|
77
80
|
integrationsManagerFactory?: (params: IIntegrationFactoryParams) => IIntegrationManager | undefined;
|
|
78
|
-
impressionsObserverFactory?: () => IImpressionObserver;
|
|
79
81
|
extraProps?: (params: ISdkFactoryContext) => object;
|
|
80
82
|
}
|
|
@@ -20,6 +20,8 @@ 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>;
|
|
23
25
|
export declare type IPostTestImpressionsBulk = (body: string, headers?: Record<string, string>) => Promise<IResponse>;
|
|
24
26
|
export declare type IPostTestImpressionsCount = (body: string, headers?: Record<string, string>) => Promise<IResponse>;
|
|
25
27
|
export declare type IPostMetricsConfig = (body: string) => Promise<IResponse>;
|
|
@@ -32,6 +34,8 @@ export interface ISplitApi {
|
|
|
32
34
|
fetchSegmentChanges: IFetchSegmentChanges;
|
|
33
35
|
fetchMySegments: IFetchMySegments;
|
|
34
36
|
postEventsBulk: IPostEventsBulk;
|
|
37
|
+
postUniqueKeysBulkCs: IPostUniqueKeysBulkCs;
|
|
38
|
+
postUniqueKeysBulkSs: IPostUniqueKeysBulkSs;
|
|
35
39
|
postTestImpressionsBulk: IPostTestImpressionsBulk;
|
|
36
40
|
postTestImpressionsCount: IPostTestImpressionsCount;
|
|
37
41
|
postMetricsConfig: IPostMetricsConfig;
|
|
@@ -6,6 +6,8 @@ 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;
|
|
9
11
|
buildEventsKey(): string;
|
|
10
12
|
searchPatternForSplitKeys(): string;
|
|
11
13
|
buildLatencyKey(method: Method, bucket: number): string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ICountsCacheSync } from '../types';
|
|
2
|
+
export declare class CountsCacheInMemory implements ICountsCacheSync {
|
|
3
|
+
private counters;
|
|
4
|
+
/**
|
|
5
|
+
* Add counts.
|
|
6
|
+
*/
|
|
7
|
+
track(metricName: string): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Clear the collector
|
|
10
|
+
*/
|
|
11
|
+
clear(): void;
|
|
12
|
+
/**
|
|
13
|
+
* Get the collected data, used as payload for posting.
|
|
14
|
+
*/
|
|
15
|
+
state(): Record<string, number>;
|
|
16
|
+
/**
|
|
17
|
+
* Check if the cache is empty.
|
|
18
|
+
*/
|
|
19
|
+
isEmpty(): boolean;
|
|
20
|
+
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { IImpressionCountsCacheSync } from '../types';
|
|
2
2
|
export declare class ImpressionCountsCacheInMemory implements IImpressionCountsCacheSync {
|
|
3
|
-
|
|
3
|
+
protected cache: Record<string, number>;
|
|
4
|
+
private readonly maxStorage;
|
|
5
|
+
protected onFullQueue?: () => void;
|
|
6
|
+
private cacheSize;
|
|
7
|
+
constructor(impressionCountsCacheSize?: number);
|
|
4
8
|
/**
|
|
5
9
|
* Builds key to be stored in the cache with the featureName and the timeFrame truncated.
|
|
6
10
|
*/
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ILatenciesCacheSync } from '../types';
|
|
2
|
+
export declare class LatenciesCacheInMemory implements ILatenciesCacheSync {
|
|
3
|
+
private counters;
|
|
4
|
+
/**
|
|
5
|
+
* Add latencies.
|
|
6
|
+
*/
|
|
7
|
+
track(metricName: string, latency: number): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Clear the collector
|
|
10
|
+
*/
|
|
11
|
+
clear(): void;
|
|
12
|
+
/**
|
|
13
|
+
* Get the collected data, used as payload for posting.
|
|
14
|
+
*/
|
|
15
|
+
state(): Record<string, number[]>;
|
|
16
|
+
/**
|
|
17
|
+
* Check if the cache is empty.
|
|
18
|
+
*/
|
|
19
|
+
isEmpty(): boolean;
|
|
20
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { IUniqueKeysCacheBase } from '../types';
|
|
2
|
+
import { ISet } from '../../utils/lang/sets';
|
|
3
|
+
import { UniqueKeysPayloadSs } from '../../sync/submitters/types';
|
|
4
|
+
export declare class UniqueKeysCacheInMemory implements IUniqueKeysCacheBase {
|
|
5
|
+
protected onFullQueue?: () => void;
|
|
6
|
+
private readonly maxStorage;
|
|
7
|
+
private uniqueTrackerSize;
|
|
8
|
+
protected uniqueKeysTracker: {
|
|
9
|
+
[keys: string]: ISet<string>;
|
|
10
|
+
};
|
|
11
|
+
constructor(uniqueKeysQueueSize?: number);
|
|
12
|
+
setOnFullQueueCb(cb: () => void): void;
|
|
13
|
+
/**
|
|
14
|
+
* Store unique keys in sequential order
|
|
15
|
+
* key: string = feature name.
|
|
16
|
+
* value: Set<string> = set of unique keys.
|
|
17
|
+
*/
|
|
18
|
+
track(key: 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(): UniqueKeysPayloadSs;
|
|
27
|
+
/**
|
|
28
|
+
* Check if the cache is empty.
|
|
29
|
+
*/
|
|
30
|
+
isEmpty(): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Converts `uniqueKeys` data from cache into request payload for SS.
|
|
33
|
+
*/
|
|
34
|
+
private fromUniqueKeysCollector;
|
|
35
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
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 in sequential order
|
|
17
|
+
* key: string = key.
|
|
18
|
+
* value: HashSet<string> = set of split names.
|
|
19
|
+
*/
|
|
20
|
+
track(key: string, featureName: string): void;
|
|
21
|
+
/**
|
|
22
|
+
* Clear the data stored on the cache.
|
|
23
|
+
*/
|
|
24
|
+
clear(): void;
|
|
25
|
+
/**
|
|
26
|
+
* Pop the collected data, used as payload for posting.
|
|
27
|
+
*/
|
|
28
|
+
pop(): UniqueKeysPayloadCs;
|
|
29
|
+
/**
|
|
30
|
+
* Check if the cache is empty.
|
|
31
|
+
*/
|
|
32
|
+
isEmpty(): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Converts `uniqueKeys` data from cache into request payload.
|
|
35
|
+
*/
|
|
36
|
+
private fromUniqueKeysCollector;
|
|
37
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ICountsCacheAsync } from '../types';
|
|
2
|
+
import { KeyBuilderSS } from '../KeyBuilderSS';
|
|
3
|
+
import { Redis } from 'ioredis';
|
|
4
|
+
export declare class CountsCacheInRedis implements ICountsCacheAsync {
|
|
5
|
+
private readonly redis;
|
|
6
|
+
private readonly keys;
|
|
7
|
+
constructor(keys: KeyBuilderSS, redis: Redis);
|
|
8
|
+
track(metricName: string): Promise<boolean>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Redis } from 'ioredis';
|
|
2
|
+
import { ILogger } from '../../logger/types';
|
|
3
|
+
import { ImpressionCountsCacheInMemory } from '../inMemory/ImpressionCountsCacheInMemory';
|
|
4
|
+
export declare class ImpressionCountsCacheInRedis extends ImpressionCountsCacheInMemory {
|
|
5
|
+
private readonly log;
|
|
6
|
+
private readonly key;
|
|
7
|
+
private readonly redis;
|
|
8
|
+
private readonly refreshRate;
|
|
9
|
+
private intervalId;
|
|
10
|
+
constructor(log: ILogger, key: string, redis: Redis, impressionCountsCacheSize?: number, refreshRate?: number);
|
|
11
|
+
postImpressionCountsInRedis(): false | Promise<boolean | import("ioredis").BooleanResponse | undefined>;
|
|
12
|
+
start(): void;
|
|
13
|
+
stop(): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ILatenciesCacheAsync } from '../types';
|
|
2
|
+
import { KeyBuilderSS } from '../KeyBuilderSS';
|
|
3
|
+
import { Redis } from 'ioredis';
|
|
4
|
+
export declare class LatenciesCacheInRedis implements ILatenciesCacheAsync {
|
|
5
|
+
private readonly redis;
|
|
6
|
+
private readonly keys;
|
|
7
|
+
constructor(keys: KeyBuilderSS, redis: Redis);
|
|
8
|
+
track(metricName: string, latency: number): Promise<boolean>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { IUniqueKeysCacheBase } from '../types';
|
|
2
|
+
import { Redis } from 'ioredis';
|
|
3
|
+
import { UniqueKeysCacheInMemory } from '../inMemory/uniqueKeysCacheInMemory';
|
|
4
|
+
import { ILogger } from '../../logger/types';
|
|
5
|
+
export declare class UniqueKeysCacheInRedis extends UniqueKeysCacheInMemory implements IUniqueKeysCacheBase {
|
|
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, uniqueKeysQueueSize?: number, refreshRate?: number);
|
|
12
|
+
postUniqueKeysInRedis(): Promise<boolean | import("ioredis").BooleanResponse | undefined>;
|
|
13
|
+
start(): void;
|
|
14
|
+
stop(): void;
|
|
15
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
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 } from '../sync/submitters/types';
|
|
3
|
+
import { EventDataType, HttpErrors, HttpLatencies, ImpressionDataType, LastSync, Method, MethodExceptions, MethodLatencies, OperationType, StoredEventWithMetadata, StoredImpressionWithMetadata, StreamingEvent, UniqueKeysPayloadCs, UniqueKeysPayloadSs } from '../sync/submitters/types';
|
|
4
4
|
import { SplitIO, ImpressionDTO, SDKMode } from '../types';
|
|
5
5
|
/**
|
|
6
6
|
* Interface of a pluggable storage wrapper.
|
|
@@ -297,6 +297,13 @@ 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
|
+
}
|
|
300
307
|
/**
|
|
301
308
|
* Telemetry storage interface for standalone and partial consumer modes.
|
|
302
309
|
* Methods are sync because data is stored in memory.
|
|
@@ -366,28 +373,34 @@ export interface ITelemetryCacheAsync extends ITelemetryEvaluationProducerAsync
|
|
|
366
373
|
/**
|
|
367
374
|
* Storages
|
|
368
375
|
*/
|
|
369
|
-
export interface IStorageBase<TSplitsCache extends ISplitsCacheBase, TSegmentsCache extends ISegmentsCacheBase, TImpressionsCache extends IImpressionsCacheBase, TEventsCache extends IEventsCacheBase, TTelemetryCache extends ITelemetryCacheSync | ITelemetryCacheAsync> {
|
|
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> {
|
|
370
377
|
splits: TSplitsCache;
|
|
371
378
|
segments: TSegmentsCache;
|
|
372
379
|
impressions: TImpressionsCache;
|
|
373
|
-
impressionCounts?:
|
|
380
|
+
impressionCounts?: TImpressionsCountCache;
|
|
374
381
|
events: TEventsCache;
|
|
375
382
|
telemetry?: TTelemetryCache;
|
|
383
|
+
uniqueKeys?: TUniqueKeysCache;
|
|
376
384
|
destroy(): void | Promise<void>;
|
|
377
385
|
shared?: (matchingKey: string, onReadyCb: (error?: any) => void) => this;
|
|
378
386
|
}
|
|
379
|
-
export interface IStorageSync extends IStorageBase<ISplitsCacheSync, ISegmentsCacheSync, IImpressionsCacheSync, IEventsCacheSync, ITelemetryCacheSync> {
|
|
387
|
+
export interface IStorageSync extends IStorageBase<ISplitsCacheSync, ISegmentsCacheSync, IImpressionsCacheSync, IImpressionCountsCacheSync, IEventsCacheSync, ITelemetryCacheSync, IUniqueKeysCacheBase> {
|
|
380
388
|
}
|
|
381
|
-
export interface IStorageAsync extends IStorageBase<ISplitsCacheAsync, ISegmentsCacheAsync, IImpressionsCacheAsync | IImpressionsCacheSync, IEventsCacheAsync | IEventsCacheSync, ITelemetryCacheAsync> {
|
|
389
|
+
export interface IStorageAsync extends IStorageBase<ISplitsCacheAsync, ISegmentsCacheAsync, IImpressionsCacheAsync | IImpressionsCacheSync, IImpressionCountsCacheSync, IEventsCacheAsync | IEventsCacheSync, ITelemetryCacheAsync, IUniqueKeysCacheBase> {
|
|
382
390
|
}
|
|
383
391
|
/** StorageFactory */
|
|
384
392
|
export declare type DataLoader = (storage: IStorageSync, matchingKey: string) => void;
|
|
385
393
|
export interface IStorageFactoryParams {
|
|
386
394
|
log: ILogger;
|
|
387
395
|
impressionsQueueSize?: number;
|
|
396
|
+
impressionCountsQueueSize?: number;
|
|
397
|
+
impressionCountsRefreshRate?: number;
|
|
398
|
+
uniqueKeysRefreshRate?: number;
|
|
399
|
+
uniqueKeysCacheSize?: number;
|
|
388
400
|
eventsQueueSize?: number;
|
|
389
401
|
optimize?: boolean;
|
|
390
402
|
mode: SDKMode;
|
|
403
|
+
impressionsMode?: string;
|
|
391
404
|
matchingKey?: string;
|
|
392
405
|
splitFiltersValidation?: ISplitFiltersValidation;
|
|
393
406
|
onReadyCb: (error?: any) => void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IEventsCacheSync } from '../../storages/types';
|
|
2
|
+
import { IPostEventsBulk } from '../../services/types';
|
|
3
|
+
import { ISyncTask, ITimeTracker } from '../types';
|
|
4
|
+
import { ILogger } from '../../logger/types';
|
|
5
|
+
/**
|
|
6
|
+
* Sync task that periodically posts tracked events
|
|
7
|
+
*/
|
|
8
|
+
export declare function eventsSyncTaskFactory(log: ILogger, postEventsBulk: IPostEventsBulk, eventsCache: IEventsCacheSync, eventsPushRate: number, eventsFirstPushWindow: number, latencyTracker?: ITimeTracker): ISyncTask;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ISyncTask, ITimeTracker } from '../types';
|
|
2
|
+
import { IPostTestImpressionsCount } from '../../services/types';
|
|
3
|
+
import { IImpressionCountsCacheSync } from '../../storages/types';
|
|
4
|
+
import { ImpressionCountsPayload } from './types';
|
|
5
|
+
import { ILogger } from '../../logger/types';
|
|
6
|
+
/**
|
|
7
|
+
* Converts `impressionCounts` data from cache into request payload.
|
|
8
|
+
*/
|
|
9
|
+
export declare function fromImpressionCountsCollector(impressionsCount: Record<string, number>): ImpressionCountsPayload;
|
|
10
|
+
/**
|
|
11
|
+
* Sync task that periodically posts impression counts
|
|
12
|
+
*/
|
|
13
|
+
export declare function impressionCountsSyncTaskFactory(log: ILogger, postTestImpressionsCount: IPostTestImpressionsCount, impressionCountsCache: IImpressionCountsCacheSync, latencyTracker?: ITimeTracker): ISyncTask;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ISyncTask, ITimeTracker } from '../types';
|
|
2
|
+
import { IPostTestImpressionsBulk } from '../../services/types';
|
|
3
|
+
import { IImpressionsCacheSync } from '../../storages/types';
|
|
4
|
+
import { ImpressionDTO } from '../../types';
|
|
5
|
+
import { ImpressionsPayload } from './types';
|
|
6
|
+
import { ILogger } from '../../logger/types';
|
|
7
|
+
/**
|
|
8
|
+
* Converts `impressions` data from cache into request payload.
|
|
9
|
+
*/
|
|
10
|
+
export declare function fromImpressionsCollector(sendLabels: boolean, data: ImpressionDTO[]): ImpressionsPayload;
|
|
11
|
+
/**
|
|
12
|
+
* Sync task that periodically posts impressions data
|
|
13
|
+
*/
|
|
14
|
+
export declare function impressionsSyncTaskFactory(log: ILogger, postTestImpressionsBulk: IPostTestImpressionsBulk, impressionsCache: IImpressionsCacheSync, impressionsRefreshRate: number, sendLabels?: boolean, latencyTracker?: ITimeTracker): ISyncTask;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ICountsCacheSync, ILatenciesCacheSync } from '../../storages/types';
|
|
2
|
+
import { IPostMetricsCounters, IPostMetricsTimes } from '../../services/types';
|
|
3
|
+
import { ISyncTask, ITimeTracker } from '../types';
|
|
4
|
+
import { ILogger } from '../../logger/types';
|
|
5
|
+
/**
|
|
6
|
+
* Sync task that periodically posts telemetry counts
|
|
7
|
+
*/
|
|
8
|
+
export declare function countsSyncTaskFactory(log: ILogger, postMetricsCounters: IPostMetricsCounters, countsCache: ICountsCacheSync, metricsRefreshRate: number, latencyTracker?: ITimeTracker): ISyncTask;
|
|
9
|
+
/**
|
|
10
|
+
* Sync task that periodically posts telemetry latencies
|
|
11
|
+
*/
|
|
12
|
+
export declare function latenciesSyncTaskFactory(log: ILogger, postMetricsLatencies: IPostMetricsTimes, latenciesCache: ILatenciesCacheSync, metricsRefreshRate: number, latencyTracker?: ITimeTracker): ISyncTask;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ISyncTask, ITimeTracker } from '../types';
|
|
2
|
+
import { IRecorderCacheProducerSync } from '../../storages/types';
|
|
3
|
+
import { ILogger } from '../../logger/types';
|
|
4
|
+
import { IResponse } from '../../services/types';
|
|
5
|
+
/**
|
|
6
|
+
* Base function to create submitter sync tasks, such as ImpressionsSyncTask and EventsSyncTask
|
|
7
|
+
*/
|
|
8
|
+
export declare function submitterSyncTaskFactory<TState extends {
|
|
9
|
+
length?: number;
|
|
10
|
+
}>(log: ILogger, postClient: (body: string) => Promise<IResponse>, sourceCache: IRecorderCacheProducerSync<TState>, postRate: number, dataName: string, latencyTracker?: ITimeTracker, fromCacheToPayload?: (cacheData: TState) => any, maxRetries?: number, debugLogs?: boolean): ISyncTask<[], void>;
|
|
@@ -32,6 +32,22 @@ 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
|
+
};
|
|
35
51
|
export declare type StoredImpressionWithMetadata = {
|
|
36
52
|
/** Metadata */
|
|
37
53
|
m: IMetadata;
|
|
@@ -132,7 +148,8 @@ export declare type CONSUMER_PARTIAL_ENUM = 2;
|
|
|
132
148
|
export declare type OperationMode = STANDALONE_ENUM | CONSUMER_ENUM | CONSUMER_PARTIAL_ENUM;
|
|
133
149
|
export declare type OPTIMIZED_ENUM = 0;
|
|
134
150
|
export declare type DEBUG_ENUM = 1;
|
|
135
|
-
export declare type
|
|
151
|
+
export declare type NONE_ENUM = 2;
|
|
152
|
+
export declare type ImpressionsMode = OPTIMIZED_ENUM | DEBUG_ENUM | NONE_ENUM;
|
|
136
153
|
export declare type RefreshRates = {
|
|
137
154
|
sp: number;
|
|
138
155
|
se?: number;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { IFilter } from './types';
|
|
2
|
+
export declare class BloomFilterImp implements IFilter {
|
|
3
|
+
private spectedInsertions;
|
|
4
|
+
private errorRate;
|
|
5
|
+
private filter;
|
|
6
|
+
constructor(spectedInsertions: number, errorRate: number);
|
|
7
|
+
add(data: string): boolean;
|
|
8
|
+
contains(data: string): boolean;
|
|
9
|
+
clear(): void;
|
|
10
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
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
|
|
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,
|
|
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 { IImpressionCountsCacheSync } 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: IImpressionCountsCacheSync, uniqueKeysTracker: IUniqueKeysTracker): IStrategy;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IImpressionCountsCacheSync } 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: IImpressionCountsCacheSync): 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
|
@@ -74,6 +74,10 @@ export interface ISettings {
|
|
|
74
74
|
featuresRefreshRate: number;
|
|
75
75
|
impressionsRefreshRate: number;
|
|
76
76
|
impressionsQueueSize: number;
|
|
77
|
+
impressionCountsRefreshRate: number;
|
|
78
|
+
impressionCountsQueueSize: number;
|
|
79
|
+
uniqueKeysRefreshRate: number;
|
|
80
|
+
uniqueKeysCacheSize: number;
|
|
77
81
|
/**
|
|
78
82
|
* @deprecated
|
|
79
83
|
*/
|
|
@@ -715,7 +719,7 @@ export declare namespace SplitIO {
|
|
|
715
719
|
* ImpressionsMode type
|
|
716
720
|
* @typedef {string} ImpressionsMode
|
|
717
721
|
*/
|
|
718
|
-
type ImpressionsMode = 'OPTIMIZED' | 'DEBUG';
|
|
722
|
+
type ImpressionsMode = 'OPTIMIZED' | 'DEBUG' | 'NONE';
|
|
719
723
|
/**
|
|
720
724
|
* Defines the format of Split data to preload on the factory storage (cache).
|
|
721
725
|
*/
|
|
@@ -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";
|