@splitsoftware/splitio-commons 1.11.0 → 1.12.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 (132) hide show
  1. package/CHANGES.txt +15 -9
  2. package/cjs/evaluator/index.js +19 -3
  3. package/cjs/logger/constants.js +6 -4
  4. package/cjs/logger/messages/warn.js +5 -3
  5. package/cjs/sdkClient/client.js +19 -16
  6. package/cjs/sdkClient/clientInputValidation.js +16 -16
  7. package/cjs/sdkFactory/index.js +1 -1
  8. package/cjs/sdkManager/index.js +14 -13
  9. package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +3 -10
  10. package/cjs/storages/inMemory/SplitsCacheInMemory.js +2 -10
  11. package/cjs/storages/inRedis/RedisAdapter.js +32 -13
  12. package/cjs/storages/inRedis/SegmentsCacheInRedis.js +2 -2
  13. package/cjs/storages/inRedis/SplitsCacheInRedis.js +39 -22
  14. package/cjs/storages/inRedis/index.js +1 -1
  15. package/cjs/storages/pluggable/SplitsCachePluggable.js +28 -11
  16. package/cjs/storages/pluggable/index.js +1 -1
  17. package/cjs/utils/constants/index.js +16 -2
  18. package/cjs/utils/inputValidation/index.js +5 -5
  19. package/cjs/utils/inputValidation/{splitExistance.js → splitExistence.js} +3 -3
  20. package/cjs/utils/inputValidation/{trafficTypeExistance.js → trafficTypeExistence.js} +6 -6
  21. package/cjs/utils/lang/sets.js +11 -1
  22. package/cjs/utils/settingsValidation/index.js +1 -1
  23. package/cjs/utils/settingsValidation/splitFilters.js +25 -17
  24. package/esm/evaluator/index.js +20 -4
  25. package/esm/logger/constants.js +4 -2
  26. package/esm/logger/messages/warn.js +5 -3
  27. package/esm/sdkClient/client.js +20 -17
  28. package/esm/sdkClient/clientInputValidation.js +18 -18
  29. package/esm/sdkFactory/index.js +1 -1
  30. package/esm/sdkManager/index.js +11 -10
  31. package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +4 -11
  32. package/esm/storages/inMemory/SplitsCacheInMemory.js +3 -11
  33. package/esm/storages/inRedis/RedisAdapter.js +32 -13
  34. package/esm/storages/inRedis/SegmentsCacheInRedis.js +2 -2
  35. package/esm/storages/inRedis/SplitsCacheInRedis.js +40 -23
  36. package/esm/storages/inRedis/index.js +1 -1
  37. package/esm/storages/pluggable/SplitsCachePluggable.js +29 -12
  38. package/esm/storages/pluggable/index.js +1 -1
  39. package/esm/utils/constants/index.js +14 -0
  40. package/esm/utils/inputValidation/index.js +2 -2
  41. package/esm/utils/inputValidation/{splitExistance.js → splitExistence.js} +1 -1
  42. package/esm/utils/inputValidation/{trafficTypeExistance.js → trafficTypeExistence.js} +4 -4
  43. package/esm/utils/lang/sets.js +9 -0
  44. package/esm/utils/settingsValidation/index.js +1 -1
  45. package/esm/utils/settingsValidation/splitFilters.js +17 -9
  46. package/package.json +1 -1
  47. package/src/evaluator/index.ts +24 -4
  48. package/src/logger/constants.ts +4 -2
  49. package/src/logger/messages/warn.ts +9 -7
  50. package/src/sdkClient/client.ts +18 -18
  51. package/src/sdkClient/clientInputValidation.ts +18 -18
  52. package/src/sdkFactory/index.ts +1 -1
  53. package/src/sdkFactory/types.ts +3 -7
  54. package/src/sdkManager/index.ts +14 -14
  55. package/src/storages/AbstractSplitsCacheAsync.ts +1 -1
  56. package/src/storages/AbstractSplitsCacheSync.ts +1 -1
  57. package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +8 -15
  58. package/src/storages/inMemory/SplitsCacheInMemory.ts +6 -14
  59. package/src/storages/inRedis/EventsCacheInRedis.ts +3 -3
  60. package/src/storages/inRedis/ImpressionCountsCacheInRedis.ts +3 -3
  61. package/src/storages/inRedis/ImpressionsCacheInRedis.ts +3 -3
  62. package/src/storages/inRedis/RedisAdapter.ts +38 -16
  63. package/src/storages/inRedis/SegmentsCacheInRedis.ts +5 -5
  64. package/src/storages/inRedis/SplitsCacheInRedis.ts +49 -28
  65. package/src/storages/inRedis/TelemetryCacheInRedis.ts +2 -2
  66. package/src/storages/inRedis/UniqueKeysCacheInRedis.ts +3 -3
  67. package/src/storages/inRedis/index.ts +1 -1
  68. package/src/storages/pluggable/SplitsCachePluggable.ts +35 -13
  69. package/src/storages/pluggable/index.ts +1 -1
  70. package/src/storages/types.ts +5 -5
  71. package/src/trackers/impressionObserver/utils.ts +1 -1
  72. package/src/types.ts +0 -2
  73. package/src/utils/constants/index.ts +16 -0
  74. package/src/utils/inputValidation/index.ts +2 -2
  75. package/src/utils/inputValidation/{splitExistance.ts → splitExistence.ts} +1 -1
  76. package/src/utils/inputValidation/{trafficTypeExistance.ts → trafficTypeExistence.ts} +4 -4
  77. package/src/utils/lang/sets.ts +9 -1
  78. package/src/utils/redis/RedisMock.ts +1 -3
  79. package/src/utils/settingsValidation/index.ts +1 -1
  80. package/src/utils/settingsValidation/splitFilters.ts +19 -11
  81. package/types/evaluator/index.d.ts +1 -1
  82. package/types/logger/constants.d.ts +4 -2
  83. package/types/sdkClient/identity.d.ts +6 -0
  84. package/types/sdkFactory/types.d.ts +3 -3
  85. package/types/sdkManager/index.d.ts +2 -3
  86. package/types/storages/AbstractSplitsCacheAsync.d.ts +1 -1
  87. package/types/storages/AbstractSplitsCacheSync.d.ts +1 -1
  88. package/types/storages/inLocalStorage/SplitsCacheInLocal.d.ts +1 -1
  89. package/types/storages/inMemory/SplitsCacheInMemory.d.ts +1 -1
  90. package/types/storages/inRedis/EventsCacheInRedis.d.ts +2 -2
  91. package/types/storages/inRedis/ImpressionCountsCacheInRedis.d.ts +3 -2
  92. package/types/storages/inRedis/ImpressionsCacheInRedis.d.ts +2 -2
  93. package/types/storages/inRedis/RedisAdapter.d.ts +1 -1
  94. package/types/storages/inRedis/SegmentsCacheInRedis.d.ts +3 -3
  95. package/types/storages/inRedis/SplitsCacheInRedis.d.ts +10 -14
  96. package/types/storages/inRedis/TelemetryCacheInRedis.d.ts +2 -2
  97. package/types/storages/inRedis/{uniqueKeysCacheInRedis.d.ts → UniqueKeysCacheInRedis.d.ts} +3 -2
  98. package/types/storages/pluggable/SplitsCachePluggable.d.ts +10 -9
  99. package/types/storages/types.d.ts +5 -5
  100. package/types/trackers/impressionObserver/utils.d.ts +1 -1
  101. package/types/types.d.ts +0 -2
  102. package/types/utils/constants/index.d.ts +12 -0
  103. package/types/utils/inputValidation/index.d.ts +2 -2
  104. package/types/utils/inputValidation/sdkKey.d.ts +7 -0
  105. package/types/utils/inputValidation/splitExistence.d.ts +7 -0
  106. package/types/utils/inputValidation/trafficTypeExistence.d.ts +9 -0
  107. package/types/utils/lang/sets.d.ts +1 -0
  108. package/types/utils/settingsValidation/splitFilters.d.ts +3 -2
  109. package/types/myLogger.d.ts +0 -5
  110. package/types/sdkClient/types.d.ts +0 -18
  111. package/types/storages/inMemory/CountsCacheInMemory.d.ts +0 -20
  112. package/types/storages/inMemory/LatenciesCacheInMemory.d.ts +0 -20
  113. package/types/storages/inRedis/CountsCacheInRedis.d.ts +0 -9
  114. package/types/storages/inRedis/LatenciesCacheInRedis.d.ts +0 -9
  115. package/types/storages/metadataBuilder.d.ts +0 -3
  116. package/types/sync/offline/LocalhostFromFile.d.ts +0 -2
  117. package/types/sync/offline/splitsParser/splitsParserFromFile.d.ts +0 -2
  118. package/types/sync/offline/updaters/splitChangesUpdater.d.ts +0 -0
  119. package/types/sync/submitters/eventsSyncTask.d.ts +0 -8
  120. package/types/sync/submitters/impressionCountsSubmitterInRedis.d.ts +0 -5
  121. package/types/sync/submitters/impressionCountsSyncTask.d.ts +0 -13
  122. package/types/sync/submitters/impressionsSyncTask.d.ts +0 -14
  123. package/types/sync/submitters/metricsSyncTask.d.ts +0 -12
  124. package/types/sync/submitters/submitterSyncTask.d.ts +0 -10
  125. package/types/sync/submitters/uniqueKeysSubmitterInRedis.d.ts +0 -5
  126. package/types/sync/syncTaskComposite.d.ts +0 -5
  127. package/types/trackers/filter/bloomFilter.d.ts +0 -10
  128. package/types/trackers/filter/dictionaryFilter.d.ts +0 -8
  129. package/types/trackers/filter/types.d.ts +0 -5
  130. package/types/utils/timeTracker/index.d.ts +0 -70
  131. /package/types/storages/inMemory/{uniqueKeysCacheInMemory.d.ts → UniqueKeysCacheInMemory.d.ts} +0 -0
  132. /package/types/storages/inMemory/{uniqueKeysCacheInMemoryCS.d.ts → UniqueKeysCacheInMemoryCS.d.ts} +0 -0
@@ -0,0 +1,6 @@
1
+ import { SplitIO } from '../types';
2
+ export declare function buildInstanceId(key: SplitIO.SplitKey, trafficType?: string): string;
3
+ export declare function parseInstanceId(instanceId: string): {
4
+ key: SplitIO.SplitKey;
5
+ trafficType?: string;
6
+ };
@@ -1,9 +1,9 @@
1
1
  import { IIntegrationManager, IIntegrationFactoryParams } from '../integrations/types';
2
2
  import { ISignalListener } from '../listeners/types';
3
- import { ILogger } from '../logger/types';
4
3
  import { IReadinessManager, ISdkReadinessManager } from '../readiness/types';
4
+ import type { sdkManagerFactory } from '../sdkManager';
5
5
  import { IFetch, ISplitApi, IEventSourceConstructor } from '../services/types';
6
- import { IStorageAsync, IStorageSync, ISplitsCacheSync, ISplitsCacheAsync, IStorageFactoryParams } from '../storages/types';
6
+ import { IStorageAsync, IStorageSync, IStorageFactoryParams } from '../storages/types';
7
7
  import { ISyncManager } from '../sync/types';
8
8
  import { IImpressionObserver } from '../trackers/impressionObserver/types';
9
9
  import { IImpressionsTracker, IEventTracker, ITelemetryTracker, IFilterAdapter, IUniqueKeysTracker } from '../trackers/types';
@@ -66,7 +66,7 @@ export interface ISdkFactoryParams {
66
66
  storageFactory: (params: IStorageFactoryParams) => IStorageSync | IStorageAsync;
67
67
  splitApiFactory?: (settings: ISettings, platform: IPlatform, telemetryTracker: ITelemetryTracker) => ISplitApi;
68
68
  syncManagerFactory?: (params: ISdkFactoryContextSync) => ISyncManager;
69
- sdkManagerFactory: (log: ILogger, splits: ISplitsCacheSync | ISplitsCacheAsync, sdkReadinessManager: ISdkReadinessManager) => SplitIO.IManager | SplitIO.IAsyncManager;
69
+ sdkManagerFactory: typeof sdkManagerFactory;
70
70
  sdkClientMethodFactory: (params: ISdkFactoryContext) => ({
71
71
  (): SplitIO.ICsClient;
72
72
  (key: SplitIO.SplitKey, trafficType?: string | undefined): SplitIO.ICsClient;
@@ -1,5 +1,4 @@
1
1
  import { ISplitsCacheAsync, ISplitsCacheSync } from '../storages/types';
2
2
  import { ISdkReadinessManager } from '../readiness/types';
3
- import { SplitIO } from '../types';
4
- import { ILogger } from '../logger/types';
5
- export declare function sdkManagerFactory<TSplitCache extends ISplitsCacheSync | ISplitsCacheAsync>(log: ILogger, splits: TSplitCache, { readinessManager, sdkStatus }: ISdkReadinessManager): TSplitCache extends ISplitsCacheAsync ? SplitIO.IAsyncManager : SplitIO.IManager;
3
+ import { ISettings, SplitIO } from '../types';
4
+ export declare function sdkManagerFactory<TSplitCache extends ISplitsCacheSync | ISplitsCacheAsync>(settings: Pick<ISettings, 'log' | 'mode'>, splits: TSplitCache, { readinessManager, sdkStatus }: ISdkReadinessManager): TSplitCache extends ISplitsCacheAsync ? SplitIO.IAsyncManager : SplitIO.IManager;
@@ -15,7 +15,7 @@ export declare abstract class AbstractSplitsCacheAsync implements ISplitsCacheAs
15
15
  abstract getChangeNumber(): Promise<number>;
16
16
  abstract getAll(): Promise<ISplit[]>;
17
17
  abstract getSplitNames(): Promise<string[]>;
18
- abstract getNamesByFlagSets(flagSets: string[]): Promise<ISet<string>>;
18
+ abstract getNamesByFlagSets(flagSets: string[]): Promise<ISet<string>[]>;
19
19
  abstract trafficTypeExists(trafficType: string): Promise<boolean>;
20
20
  abstract clear(): Promise<boolean | void>;
21
21
  usesSegments(): Promise<boolean>;
@@ -35,7 +35,7 @@ export declare abstract class AbstractSplitsCacheSync implements ISplitsCacheSyn
35
35
  * for instance, if the `changeNumber` is old, or if the split is not found (e.g., `/splitchanges` hasn't been fetched yet), or if the storage fails to apply the update.
36
36
  */
37
37
  killLocally(name: string, defaultTreatment: string, changeNumber: number): boolean;
38
- abstract getNamesByFlagSets(flagSets: string[]): ISet<string>;
38
+ abstract getNamesByFlagSets(flagSets: string[]): ISet<string>[];
39
39
  }
40
40
  /**
41
41
  * Given a parsed split, it returns a boolean flagging if its conditions use segments matchers (rules & whitelists).
@@ -48,7 +48,7 @@ export declare class SplitsCacheInLocal extends AbstractSplitsCacheSync {
48
48
  */
49
49
  private _checkExpiration;
50
50
  private _checkFilterQuery;
51
- getNamesByFlagSets(flagSets: string[]): ISet<string>;
51
+ getNamesByFlagSets(flagSets: string[]): ISet<string>[];
52
52
  private addToFlagSets;
53
53
  private removeFromFlagSets;
54
54
  private removeNames;
@@ -22,7 +22,7 @@ export declare class SplitsCacheInMemory extends AbstractSplitsCacheSync {
22
22
  getSplitNames(): string[];
23
23
  trafficTypeExists(trafficType: string): boolean;
24
24
  usesSegments(): boolean;
25
- getNamesByFlagSets(flagSets: string[]): ISet<string>;
25
+ getNamesByFlagSets(flagSets: string[]): ISet<string>[];
26
26
  private addToFlagSets;
27
27
  private removeFromFlagSets;
28
28
  private removeNames;
@@ -1,15 +1,15 @@
1
1
  import { IEventsCacheAsync } from '../types';
2
2
  import { IMetadata } from '../../dtos/types';
3
- import { Redis } from 'ioredis';
4
3
  import { SplitIO } from '../../types';
5
4
  import { ILogger } from '../../logger/types';
6
5
  import { StoredEventWithMetadata } from '../../sync/submitters/types';
6
+ import type { RedisAdapter } from './RedisAdapter';
7
7
  export declare class EventsCacheInRedis implements IEventsCacheAsync {
8
8
  private readonly log;
9
9
  private readonly key;
10
10
  private readonly redis;
11
11
  private readonly metadata;
12
- constructor(log: ILogger, key: string, redis: Redis, metadata: IMetadata);
12
+ constructor(log: ILogger, key: string, redis: RedisAdapter, metadata: IMetadata);
13
13
  /**
14
14
  * Add a new event object into the queue.
15
15
  * Unlike `impressions::track`, result promise is never rejected.
@@ -1,14 +1,15 @@
1
- import { Redis } from 'ioredis';
1
+ /// <reference types="ioredis" />
2
2
  import { ILogger } from '../../logger/types';
3
3
  import { ImpressionCountsPayload } from '../../sync/submitters/types';
4
4
  import { ImpressionCountsCacheInMemory } from '../inMemory/ImpressionCountsCacheInMemory';
5
+ import type { RedisAdapter } from './RedisAdapter';
5
6
  export declare class ImpressionCountsCacheInRedis extends ImpressionCountsCacheInMemory {
6
7
  private readonly log;
7
8
  private readonly key;
8
9
  private readonly redis;
9
10
  private readonly refreshRate;
10
11
  private intervalId;
11
- constructor(log: ILogger, key: string, redis: Redis, impressionCountsCacheSize?: number, refreshRate?: number);
12
+ constructor(log: ILogger, key: string, redis: RedisAdapter, impressionCountsCacheSize?: number, refreshRate?: number);
12
13
  private postImpressionCountsInRedis;
13
14
  start(): void;
14
15
  stop(): Promise<boolean | import("ioredis").BooleanResponse | undefined>;
@@ -1,15 +1,15 @@
1
1
  import { IImpressionsCacheAsync } from '../types';
2
2
  import { IMetadata } from '../../dtos/types';
3
3
  import { ImpressionDTO } from '../../types';
4
- import { Redis } from 'ioredis';
5
4
  import { StoredImpressionWithMetadata } from '../../sync/submitters/types';
6
5
  import { ILogger } from '../../logger/types';
6
+ import type { RedisAdapter } from './RedisAdapter';
7
7
  export declare class ImpressionsCacheInRedis implements IImpressionsCacheAsync {
8
8
  private readonly log;
9
9
  private readonly key;
10
10
  private readonly redis;
11
11
  private readonly metadata;
12
- constructor(log: ILogger, key: string, redis: Redis, metadata: IMetadata);
12
+ constructor(log: ILogger, key: string, redis: RedisAdapter, metadata: IMetadata);
13
13
  track(impressions: ImpressionDTO[]): Promise<void>;
14
14
  count(): Promise<number>;
15
15
  drop(count?: number): Promise<any>;
@@ -8,7 +8,7 @@ export declare class RedisAdapter extends ioredis {
8
8
  private _options;
9
9
  private _notReadyCommandsQueue?;
10
10
  private _runningCommands;
11
- constructor(log: ILogger, storageSettings: Record<string, any>);
11
+ constructor(log: ILogger, storageSettings?: Record<string, any>);
12
12
  _listenToEvents(): void;
13
13
  _setTimeoutWrappers(): void;
14
14
  _setDisconnectWrapper(): void;
@@ -1,12 +1,12 @@
1
- import { Redis } from 'ioredis';
2
1
  import { ILogger } from '../../logger/types';
3
2
  import { KeyBuilderSS } from '../KeyBuilderSS';
4
3
  import { ISegmentsCacheAsync } from '../types';
4
+ import type { RedisAdapter } from './RedisAdapter';
5
5
  export declare class SegmentsCacheInRedis implements ISegmentsCacheAsync {
6
6
  private readonly log;
7
7
  private readonly redis;
8
8
  private readonly keys;
9
- constructor(log: ILogger, keys: KeyBuilderSS, redis: Redis);
9
+ constructor(log: ILogger, keys: KeyBuilderSS, redis: RedisAdapter);
10
10
  addToSegment(name: string, segmentKeys: string[]): Promise<boolean>;
11
11
  removeFromSegment(name: string, segmentKeys: string[]): Promise<boolean>;
12
12
  isInSegment(name: string, key: string): Promise<boolean>;
@@ -14,5 +14,5 @@ export declare class SegmentsCacheInRedis implements ISegmentsCacheAsync {
14
14
  getChangeNumber(name: string): Promise<number>;
15
15
  registerSegments(segments: string[]): Promise<boolean>;
16
16
  getRegisteredSegments(): Promise<string[]>;
17
- clear(): Promise<boolean>;
17
+ clear(): Promise<void>;
18
18
  }
@@ -1,9 +1,9 @@
1
1
  import { KeyBuilderSS } from '../KeyBuilderSS';
2
- import { Redis } from 'ioredis';
3
2
  import { ILogger } from '../../logger/types';
4
- import { ISplit } from '../../dtos/types';
3
+ import { ISplit, ISplitFiltersValidation } from '../../dtos/types';
5
4
  import { AbstractSplitsCacheAsync } from '../AbstractSplitsCacheAsync';
6
5
  import { ISet } from '../../utils/lang/sets';
6
+ import type { RedisAdapter } from './RedisAdapter';
7
7
  /**
8
8
  * ISplitsCacheAsync implementation that stores split definitions in Redis.
9
9
  * Supported by Node.
@@ -13,9 +13,11 @@ export declare class SplitsCacheInRedis extends AbstractSplitsCacheAsync {
13
13
  private readonly redis;
14
14
  private readonly keys;
15
15
  private redisError?;
16
- constructor(log: ILogger, keys: KeyBuilderSS, redis: Redis);
16
+ private readonly flagSetsFilter;
17
+ constructor(log: ILogger, keys: KeyBuilderSS, redis: RedisAdapter, splitFiltersValidation?: ISplitFiltersValidation);
17
18
  private _decrementCounts;
18
19
  private _incrementCounts;
20
+ private _updateFlagSets;
19
21
  /**
20
22
  * Add a given split.
21
23
  * The returned promise is resolved when the operation success
@@ -73,12 +75,11 @@ export declare class SplitsCacheInRedis extends AbstractSplitsCacheAsync {
73
75
  */
74
76
  getSplitNames(): Promise<string[]>;
75
77
  /**
76
- * Get list of split names related to a given flag set names list.
77
- * The returned promise is resolved with the list of split names,
78
- * or rejected if wrapper operation fails.
79
- * @todo this is a no-op method to be implemented
78
+ * Get list of feature flag names related to a given list of flag set names.
79
+ * The returned promise is resolved with the list of feature flag names per flag set,
80
+ * or rejected if the pipelined redis operation fails (e.g., timeout).
80
81
  */
81
- getNamesByFlagSets(): Promise<ISet<string>>;
82
+ getNamesByFlagSets(flagSets: string[]): Promise<ISet<string>[]>;
82
83
  /**
83
84
  * Check traffic type existence.
84
85
  * The returned promise is resolved with a boolean indicating whether the TT exist or not.
@@ -86,12 +87,7 @@ export declare class SplitsCacheInRedis extends AbstractSplitsCacheAsync {
86
87
  * It will never be rejected.
87
88
  */
88
89
  trafficTypeExists(trafficType: string): Promise<boolean>;
89
- /**
90
- * Delete everything in the current database.
91
- *
92
- * @NOTE documentation says it never fails.
93
- */
94
- clear(): Promise<boolean>;
90
+ clear(): Promise<void>;
95
91
  /**
96
92
  * Fetches multiple splits definitions.
97
93
  * Returned promise is rejected if redis operation fails.
@@ -2,7 +2,7 @@ import { ILogger } from '../../logger/types';
2
2
  import { Method, MultiConfigs, MultiMethodExceptions, MultiMethodLatencies } from '../../sync/submitters/types';
3
3
  import { KeyBuilderSS } from '../KeyBuilderSS';
4
4
  import { ITelemetryCacheAsync } from '../types';
5
- import { Redis } from 'ioredis';
5
+ import type { RedisAdapter } from './RedisAdapter';
6
6
  export declare class TelemetryCacheInRedis implements ITelemetryCacheAsync {
7
7
  private readonly log;
8
8
  private readonly keys;
@@ -13,7 +13,7 @@ export declare class TelemetryCacheInRedis implements ITelemetryCacheAsync {
13
13
  * @param keys Key builder.
14
14
  * @param redis Redis client.
15
15
  */
16
- constructor(log: ILogger, keys: KeyBuilderSS, redis: Redis);
16
+ constructor(log: ILogger, keys: KeyBuilderSS, redis: RedisAdapter);
17
17
  recordLatency(method: Method, latencyMs: number): Promise<number | void>;
18
18
  recordException(method: Method): Promise<number | void>;
19
19
  recordConfig(): Promise<number | void>;
@@ -1,15 +1,16 @@
1
+ /// <reference types="ioredis" />
1
2
  import { IUniqueKeysCacheBase } from '../types';
2
- import { Redis } from 'ioredis';
3
3
  import { UniqueKeysCacheInMemory } from '../inMemory/UniqueKeysCacheInMemory';
4
4
  import { ILogger } from '../../logger/types';
5
5
  import { UniqueKeysItemSs } from '../../sync/submitters/types';
6
+ import type { RedisAdapter } from './RedisAdapter';
6
7
  export declare class UniqueKeysCacheInRedis extends UniqueKeysCacheInMemory implements IUniqueKeysCacheBase {
7
8
  private readonly log;
8
9
  private readonly key;
9
10
  private readonly redis;
10
11
  private readonly refreshRate;
11
12
  private intervalId;
12
- constructor(log: ILogger, key: string, redis: Redis, uniqueKeysQueueSize?: number, refreshRate?: number);
13
+ constructor(log: ILogger, key: string, redis: RedisAdapter, uniqueKeysQueueSize?: number, refreshRate?: number);
13
14
  private postUniqueKeysInRedis;
14
15
  start(): void;
15
16
  stop(): Promise<boolean | import("ioredis").BooleanResponse | undefined>;
@@ -1,7 +1,7 @@
1
1
  import { KeyBuilder } from '../KeyBuilder';
2
2
  import { IPluggableStorageWrapper } from '../types';
3
3
  import { ILogger } from '../../logger/types';
4
- import { ISplit } from '../../dtos/types';
4
+ import { ISplit, ISplitFiltersValidation } from '../../dtos/types';
5
5
  import { AbstractSplitsCacheAsync } from '../AbstractSplitsCacheAsync';
6
6
  import { ISet } from '../../utils/lang/sets';
7
7
  /**
@@ -11,15 +11,17 @@ export declare class SplitsCachePluggable extends AbstractSplitsCacheAsync {
11
11
  private readonly log;
12
12
  private readonly keys;
13
13
  private readonly wrapper;
14
+ private readonly flagSetsFilter;
14
15
  /**
15
16
  * Create a SplitsCache that uses a storage wrapper.
16
17
  * @param log Logger instance.
17
18
  * @param keys Key builder.
18
19
  * @param wrapper Adapted wrapper storage.
19
20
  */
20
- constructor(log: ILogger, keys: KeyBuilder, wrapper: IPluggableStorageWrapper);
21
+ constructor(log: ILogger, keys: KeyBuilder, wrapper: IPluggableStorageWrapper, splitFiltersValidation?: ISplitFiltersValidation);
21
22
  private _decrementCounts;
22
23
  private _incrementCounts;
24
+ private _updateFlagSets;
23
25
  /**
24
26
  * Add a given split.
25
27
  * The returned promise is resolved when the operation success
@@ -37,7 +39,7 @@ export declare class SplitsCachePluggable extends AbstractSplitsCacheAsync {
37
39
  * The returned promise is resolved when the operation success, with a boolean indicating if the split existed or not.
38
40
  * or rejected if it fails (e.g., wrapper operation fails).
39
41
  */
40
- removeSplit(name: string): Promise<boolean | void>;
42
+ removeSplit(name: string): Promise<boolean>;
41
43
  /**
42
44
  * Remove a list of splits.
43
45
  * The returned promise is resolved when the operation success, with a boolean array indicating if the splits existed or not.
@@ -69,12 +71,11 @@ export declare class SplitsCachePluggable extends AbstractSplitsCacheAsync {
69
71
  */
70
72
  getSplitNames(): Promise<string[]>;
71
73
  /**
72
- * Get list of split names related to a given flag set names list.
73
- * The returned promise is resolved with the list of split names,
74
- * or rejected if wrapper operation fails.
75
- * @todo this is a no-op method to be implemented
76
- */
77
- getNamesByFlagSets(): Promise<ISet<string>>;
74
+ * Get list of feature flag names related to a given list of flag set names.
75
+ * The returned promise is resolved with the list of feature flag names per flag set.
76
+ * It never rejects (If there is a wrapper error for some flag set, an empty set is returned for it).
77
+ */
78
+ getNamesByFlagSets(flagSets: string[]): Promise<ISet<string>[]>;
78
79
  /**
79
80
  * Check traffic type existence.
80
81
  * The returned promise is resolved with a boolean indicating whether the TT exist or not.
@@ -41,10 +41,10 @@ export interface IPluggableStorageWrapper {
41
41
  *
42
42
  * @function del
43
43
  * @param {string} key Item to delete
44
- * @returns {Promise<void>} A promise that resolves if the operation success, whether the key existed and was removed or it didn't exist.
44
+ * @returns {Promise<boolean>} A promise that resolves if the operation success, whether the key existed and was removed (resolves with true) or it didn't exist (resolves with false).
45
45
  * The promise rejects if the operation fails, for example, if there is a connection error.
46
46
  */
47
- del: (key: string) => Promise<boolean | void>;
47
+ del: (key: string) => Promise<boolean>;
48
48
  /**
49
49
  * Returns all keys matching the given prefix.
50
50
  *
@@ -193,7 +193,7 @@ export interface ISplitsCacheBase {
193
193
  clear(): MaybeThenable<boolean | void>;
194
194
  checkCache(): MaybeThenable<boolean>;
195
195
  killLocally(name: string, defaultTreatment: string, changeNumber: number): MaybeThenable<boolean>;
196
- getNamesByFlagSets(flagSets: string[]): MaybeThenable<ISet<string>>;
196
+ getNamesByFlagSets(flagSets: string[]): MaybeThenable<ISet<string>[]>;
197
197
  }
198
198
  export interface ISplitsCacheSync extends ISplitsCacheBase {
199
199
  addSplits(entries: [string, ISplit][]): boolean[];
@@ -209,7 +209,7 @@ export interface ISplitsCacheSync extends ISplitsCacheBase {
209
209
  clear(): void;
210
210
  checkCache(): boolean;
211
211
  killLocally(name: string, defaultTreatment: string, changeNumber: number): boolean;
212
- getNamesByFlagSets(flagSets: string[]): ISet<string>;
212
+ getNamesByFlagSets(flagSets: string[]): ISet<string>[];
213
213
  }
214
214
  export interface ISplitsCacheAsync extends ISplitsCacheBase {
215
215
  addSplits(entries: [string, ISplit][]): Promise<boolean[] | void>;
@@ -225,7 +225,7 @@ export interface ISplitsCacheAsync extends ISplitsCacheBase {
225
225
  clear(): Promise<boolean | void>;
226
226
  checkCache(): Promise<boolean>;
227
227
  killLocally(name: string, defaultTreatment: string, changeNumber: number): Promise<boolean>;
228
- getNamesByFlagSets(flagSets: string[]): Promise<ISet<string>>;
228
+ getNamesByFlagSets(flagSets: string[]): Promise<ISet<string>[]>;
229
229
  }
230
230
  /** Segments cache */
231
231
  export interface ISegmentsCacheBase {
@@ -2,4 +2,4 @@ import { ISettings } from '../../types';
2
2
  /**
3
3
  * Storage is async if mode is consumer or partial consumer
4
4
  */
5
- export declare function isStorageSync(settings: ISettings): boolean;
5
+ export declare function isStorageSync(settings: Pick<ISettings, 'mode'>): boolean;
package/types/types.d.ts CHANGED
@@ -191,8 +191,6 @@ interface ISharedSettings {
191
191
  * List of feature flag filters. These filters are used to fetch a subset of the feature flag definitions in your environment, in order to reduce the delay of the SDK to be ready.
192
192
  * This configuration is only meaningful when the SDK is working in "standalone" mode.
193
193
  *
194
- * At the moment, only one type of feature flag filter is supported: by name.
195
- *
196
194
  * Example:
197
195
  * `splitFilter: [
198
196
  * { type: 'byName', values: ['my_feature_flag_1', 'my_feature_flag_2'] }, // will fetch feature flags named 'my_feature_flag_1' and 'my_feature_flag_2'
@@ -24,6 +24,18 @@ export declare const STORAGE_PLUGGABLE: StorageType;
24
24
  export declare const CONSENT_GRANTED = "GRANTED";
25
25
  export declare const CONSENT_DECLINED = "DECLINED";
26
26
  export declare const CONSENT_UNKNOWN = "UNKNOWN";
27
+ export declare const GET_TREATMENT = "getTreatment";
28
+ export declare const GET_TREATMENTS = "getTreatments";
29
+ export declare const GET_TREATMENT_WITH_CONFIG = "getTreatmentWithConfig";
30
+ export declare const GET_TREATMENTS_WITH_CONFIG = "getTreatmentsWithConfig";
31
+ export declare const GET_TREATMENTS_BY_FLAG_SET = "getTreatmentsByFlagSet";
32
+ export declare const GET_TREATMENTS_BY_FLAG_SETS = "getTreatmentsByFlagSets";
33
+ export declare const GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET = "getTreatmentsWithConfigByFlagSet";
34
+ export declare const GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS = "getTreatmentsWithConfigByFlagSets";
35
+ export declare const TRACK_FN_LABEL = "track";
36
+ export declare const SPLIT_FN_LABEL = "split";
37
+ export declare const SPLITS_FN_LABEL = "splits";
38
+ export declare const NAMES_FN_LABEL = "names";
27
39
  export declare const QUEUED = 0;
28
40
  export declare const DROPPED = 1;
29
41
  export declare const DEDUPED = 2;
@@ -8,6 +8,6 @@ export { validateSplit } from './split';
8
8
  export { validateSplits } from './splits';
9
9
  export { validateTrafficType } from './trafficType';
10
10
  export { validateIfNotDestroyed, validateIfOperational } from './isOperational';
11
- export { validateSplitExistance } from './splitExistance';
12
- export { validateTrafficTypeExistance } from './trafficTypeExistance';
11
+ export { validateSplitExistence } from './splitExistence';
12
+ export { validateTrafficTypeExistence } from './trafficTypeExistence';
13
13
  export { validatePreloadedData } from './preloadedData';
@@ -0,0 +1,7 @@
1
+ import { ILogger } from '../../logger/types';
2
+ /** validates the given SDK key */
3
+ export declare function validateApiKey(log: ILogger, maybeSdkKey: any): string | false;
4
+ export declare const usedKeysMap: Record<string, number>;
5
+ /** validates the given SDK key and also warns if it is in use */
6
+ export declare function validateAndTrackApiKey(log: ILogger, maybeSdkKey: any): string | false;
7
+ export declare function releaseApiKey(sdkKey: string): void;
@@ -0,0 +1,7 @@
1
+ import { IReadinessManager } from '../../readiness/types';
2
+ import { ILogger } from '../../logger/types';
3
+ /**
4
+ * This is defined here and in this format mostly because of the logger and the fact that it's considered a validation at product level.
5
+ * But it's not going to run on the input validation layer. In any case, the most compeling reason to use it as we do is to avoid going to Redis and get a split twice.
6
+ */
7
+ export declare function validateSplitExistence(log: ILogger, readinessManager: IReadinessManager, splitName: string, labelOrSplitObj: any, method: string): boolean;
@@ -0,0 +1,9 @@
1
+ import { ISplitsCacheBase } from '../../storages/types';
2
+ import { IReadinessManager } from '../../readiness/types';
3
+ import { SDKMode } from '../../types';
4
+ import { MaybeThenable } from '../../dtos/types';
5
+ import { ILogger } from '../../logger/types';
6
+ /**
7
+ * Separated from the previous method since on some cases it'll be async.
8
+ */
9
+ export declare function validateTrafficTypeExistence(log: ILogger, readinessManager: IReadinessManager, splitsCache: ISplitsCacheBase, mode: SDKMode, maybeTT: string, method: string): MaybeThenable<boolean>;
@@ -58,4 +58,5 @@ interface ISetConstructor {
58
58
  export declare function __getSetConstructor(): ISetConstructor;
59
59
  export declare const _Set: ISetConstructor;
60
60
  export declare function returnSetsUnion<T>(set: ISet<T>, set2: ISet<T>): ISet<T>;
61
+ export declare function returnDifference<T>(list?: T[], list2?: T[]): T[];
61
62
  export {};
@@ -5,6 +5,7 @@ import { ILogger } from '../../logger/types';
5
5
  *
6
6
  * @param {ILogger} log logger
7
7
  * @param {any} maybeSplitFilters split filters configuration param provided by the user
8
+ * @param {string} mode settings mode
8
9
  * @returns it returns an object with the following properties:
9
10
  * - `validFilters`: the validated `splitFilters` configuration object defined by the user.
10
11
  * - `queryString`: the parsed split filter query. it is null if all filters are invalid or all values in filters are invalid.
@@ -12,5 +13,5 @@ import { ILogger } from '../../logger/types';
12
13
  *
13
14
  * @throws Error if the some of the grouped list of values per filter exceeds the max allowed length
14
15
  */
15
- export declare function validateSplitFilters(log: ILogger, maybeSplitFilters: any): ISplitFiltersValidation;
16
- export declare function flagSetsAreValid(log: ILogger, method: string, flagSets: string[], flagSetsInConfig: string[]): string[];
16
+ export declare function validateSplitFilters(log: ILogger, maybeSplitFilters: any, mode: string): ISplitFiltersValidation;
17
+ export declare function validateFlagSets(log: ILogger, method: string, flagSets: string[], flagSetsInConfig: string[]): string[];
@@ -1,5 +0,0 @@
1
- export declare const myLogger: {
2
- log: (msg: any) => void;
3
- logCsv: (msg: any) => void;
4
- logToFile: (file: any, msg: any) => void;
5
- };
@@ -1,18 +0,0 @@
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
- }
@@ -1,20 +0,0 @@
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,20 +0,0 @@
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
- }
@@ -1,9 +0,0 @@
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
- }
@@ -1,9 +0,0 @@
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
- }
@@ -1,3 +0,0 @@
1
- import { IMetadata } from '../dtos/types';
2
- import { ISettings } from '../types';
3
- export declare function metadataBuilder(settings: Pick<ISettings, 'version' | 'runtime'>): IMetadata;
@@ -1,2 +0,0 @@
1
- import { SplitIO } from '../../types';
2
- export declare function LocalhostFromFile(): SplitIO.LocalhostFactory;
@@ -1,2 +0,0 @@
1
- import { ISplitsParser } from './types';
2
- export declare function splitsParserFromFileFactory(): ISplitsParser;
@@ -1,8 +0,0 @@
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;
@@ -1,5 +0,0 @@
1
- import { ISdkFactoryContextSync } from '../../sdkFactory/types';
2
- /**
3
- * Submitter that periodically posts impression counts
4
- */
5
- export declare function impressionCountsSubmitterInRedisFactory(params: ISdkFactoryContextSync): import("../types").ISyncTask<[], void>;
@@ -1,13 +0,0 @@
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;
@@ -1,14 +0,0 @@
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;