@splitsoftware/splitio-commons 1.10.1-rc.4 → 1.12.0-rc.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 (109) hide show
  1. package/CHANGES.txt +16 -10
  2. package/cjs/evaluator/index.js +22 -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/KeyBuilder.js +1 -1
  10. package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +3 -10
  11. package/cjs/storages/inMemory/SplitsCacheInMemory.js +2 -10
  12. package/cjs/storages/inRedis/RedisAdapter.js +32 -13
  13. package/cjs/storages/inRedis/SegmentsCacheInRedis.js +2 -2
  14. package/cjs/storages/inRedis/SplitsCacheInRedis.js +38 -22
  15. package/cjs/storages/inRedis/index.js +1 -1
  16. package/cjs/storages/pluggable/SplitsCachePluggable.js +27 -11
  17. package/cjs/storages/pluggable/index.js +1 -1
  18. package/cjs/utils/constants/index.js +16 -2
  19. package/cjs/utils/inputValidation/index.js +5 -5
  20. package/cjs/utils/inputValidation/{splitExistance.js → splitExistence.js} +3 -3
  21. package/cjs/utils/inputValidation/{trafficTypeExistance.js → trafficTypeExistence.js} +6 -6
  22. package/cjs/utils/lang/sets.js +11 -1
  23. package/cjs/utils/settingsValidation/index.js +1 -1
  24. package/cjs/utils/settingsValidation/splitFilters.js +25 -17
  25. package/esm/evaluator/index.js +23 -4
  26. package/esm/logger/constants.js +4 -2
  27. package/esm/logger/messages/warn.js +5 -3
  28. package/esm/sdkClient/client.js +20 -17
  29. package/esm/sdkClient/clientInputValidation.js +18 -18
  30. package/esm/sdkFactory/index.js +1 -1
  31. package/esm/sdkManager/index.js +11 -10
  32. package/esm/storages/KeyBuilder.js +1 -1
  33. package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +4 -11
  34. package/esm/storages/inMemory/SplitsCacheInMemory.js +3 -11
  35. package/esm/storages/inRedis/RedisAdapter.js +32 -13
  36. package/esm/storages/inRedis/SegmentsCacheInRedis.js +2 -2
  37. package/esm/storages/inRedis/SplitsCacheInRedis.js +40 -24
  38. package/esm/storages/inRedis/index.js +1 -1
  39. package/esm/storages/pluggable/SplitsCachePluggable.js +29 -13
  40. package/esm/storages/pluggable/index.js +1 -1
  41. package/esm/utils/constants/index.js +14 -0
  42. package/esm/utils/inputValidation/index.js +2 -2
  43. package/esm/utils/inputValidation/{splitExistance.js → splitExistence.js} +1 -1
  44. package/esm/utils/inputValidation/{trafficTypeExistance.js → trafficTypeExistence.js} +4 -4
  45. package/esm/utils/lang/sets.js +9 -0
  46. package/esm/utils/settingsValidation/index.js +1 -1
  47. package/esm/utils/settingsValidation/splitFilters.js +17 -9
  48. package/package.json +1 -1
  49. package/src/evaluator/index.ts +28 -5
  50. package/src/logger/constants.ts +4 -2
  51. package/src/logger/messages/warn.ts +9 -7
  52. package/src/sdkClient/client.ts +18 -18
  53. package/src/sdkClient/clientInputValidation.ts +18 -18
  54. package/src/sdkFactory/index.ts +1 -1
  55. package/src/sdkFactory/types.ts +3 -7
  56. package/src/sdkManager/index.ts +14 -14
  57. package/src/storages/AbstractSplitsCacheAsync.ts +1 -1
  58. package/src/storages/AbstractSplitsCacheSync.ts +1 -1
  59. package/src/storages/KeyBuilder.ts +1 -1
  60. package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +8 -15
  61. package/src/storages/inMemory/SplitsCacheInMemory.ts +6 -14
  62. package/src/storages/inRedis/EventsCacheInRedis.ts +3 -3
  63. package/src/storages/inRedis/ImpressionCountsCacheInRedis.ts +3 -3
  64. package/src/storages/inRedis/ImpressionsCacheInRedis.ts +3 -3
  65. package/src/storages/inRedis/RedisAdapter.ts +38 -16
  66. package/src/storages/inRedis/SegmentsCacheInRedis.ts +5 -5
  67. package/src/storages/inRedis/SplitsCacheInRedis.ts +49 -28
  68. package/src/storages/inRedis/TelemetryCacheInRedis.ts +2 -2
  69. package/src/storages/inRedis/UniqueKeysCacheInRedis.ts +3 -3
  70. package/src/storages/inRedis/index.ts +1 -1
  71. package/src/storages/pluggable/SplitsCachePluggable.ts +35 -13
  72. package/src/storages/pluggable/index.ts +1 -1
  73. package/src/storages/types.ts +5 -5
  74. package/src/trackers/impressionObserver/utils.ts +1 -1
  75. package/src/types.ts +0 -2
  76. package/src/utils/constants/index.ts +16 -0
  77. package/src/utils/inputValidation/index.ts +2 -2
  78. package/src/utils/inputValidation/{splitExistance.ts → splitExistence.ts} +1 -1
  79. package/src/utils/inputValidation/{trafficTypeExistance.ts → trafficTypeExistence.ts} +4 -4
  80. package/src/utils/lang/sets.ts +9 -1
  81. package/src/utils/redis/RedisMock.ts +1 -3
  82. package/src/utils/settingsValidation/index.ts +1 -1
  83. package/src/utils/settingsValidation/splitFilters.ts +19 -11
  84. package/types/evaluator/index.d.ts +1 -1
  85. package/types/logger/constants.d.ts +4 -2
  86. package/types/sdkFactory/types.d.ts +3 -3
  87. package/types/sdkManager/index.d.ts +2 -3
  88. package/types/storages/AbstractSplitsCacheAsync.d.ts +1 -1
  89. package/types/storages/AbstractSplitsCacheSync.d.ts +1 -1
  90. package/types/storages/inLocalStorage/SplitsCacheInLocal.d.ts +1 -1
  91. package/types/storages/inMemory/SplitsCacheInMemory.d.ts +1 -1
  92. package/types/storages/inRedis/EventsCacheInRedis.d.ts +2 -2
  93. package/types/storages/inRedis/ImpressionCountsCacheInRedis.d.ts +3 -2
  94. package/types/storages/inRedis/ImpressionsCacheInRedis.d.ts +2 -2
  95. package/types/storages/inRedis/RedisAdapter.d.ts +1 -1
  96. package/types/storages/inRedis/SegmentsCacheInRedis.d.ts +3 -3
  97. package/types/storages/inRedis/SplitsCacheInRedis.d.ts +10 -14
  98. package/types/storages/inRedis/TelemetryCacheInRedis.d.ts +2 -2
  99. package/types/storages/inRedis/UniqueKeysCacheInRedis.d.ts +3 -2
  100. package/types/storages/pluggable/SplitsCachePluggable.d.ts +10 -9
  101. package/types/storages/types.d.ts +5 -5
  102. package/types/trackers/impressionObserver/utils.d.ts +1 -1
  103. package/types/types.d.ts +0 -2
  104. package/types/utils/constants/index.d.ts +12 -0
  105. package/types/utils/inputValidation/index.d.ts +2 -2
  106. package/types/utils/inputValidation/splitExistence.d.ts +7 -0
  107. package/types/utils/inputValidation/trafficTypeExistence.d.ts +9 -0
  108. package/types/utils/lang/sets.d.ts +1 -0
  109. package/types/utils/settingsValidation/splitFilters.d.ts +3 -2
@@ -26,8 +26,6 @@ export class RedisMock {
26
26
  this.pipelineMethods[method] = this[method];
27
27
  });
28
28
 
29
- this.pipeline = jest.fn(() => {return this.pipelineMethods;});
29
+ this.pipeline = jest.fn(() => { return this.pipelineMethods; });
30
30
  }
31
-
32
-
33
31
  }
@@ -202,7 +202,7 @@ export function settingsValidation(config: unknown, validationParams: ISettingsV
202
202
  }
203
203
 
204
204
  // validate the `splitFilters` settings and parse splits query
205
- const splitFiltersValidation = validateSplitFilters(log, withDefaults.sync.splitFilters);
205
+ const splitFiltersValidation = validateSplitFilters(log, withDefaults.sync.splitFilters, withDefaults.mode);
206
206
  withDefaults.sync.splitFilters = splitFiltersValidation.validFilters;
207
207
  withDefaults.sync.__splitFiltersValidation = splitFiltersValidation;
208
208
 
@@ -1,8 +1,9 @@
1
+ import { CONSUMER_MODE, CONSUMER_PARTIAL_MODE } from '../constants';
1
2
  import { validateSplits } from '../inputValidation/splits';
2
3
  import { ISplitFiltersValidation } from '../../dtos/types';
3
4
  import { SplitIO } from '../../types';
4
5
  import { ILogger } from '../../logger/types';
5
- import { WARN_SPLITS_FILTER_EMPTY, WARN_SPLITS_FILTER_INVALID, SETTINGS_SPLITS_FILTER, LOG_PREFIX_SETTINGS, ERROR_SETS_FILTER_EXCLUSIVE, WARN_SPLITS_FILTER_LOWERCASE_SET, WARN_SPLITS_FILTER_INVALID_SET, WARN_FLAGSET_NOT_CONFIGURED } from '../../logger/constants';
6
+ import { WARN_SPLITS_FILTER_IGNORED, WARN_SPLITS_FILTER_EMPTY, WARN_SPLITS_FILTER_INVALID, SETTINGS_SPLITS_FILTER, LOG_PREFIX_SETTINGS, ERROR_SETS_FILTER_EXCLUSIVE, WARN_LOWERCASE_FLAGSET, WARN_INVALID_FLAGSET, WARN_FLAGSET_NOT_CONFIGURED } from '../../logger/constants';
6
7
  import { objectAssign } from '../lang/objectAssign';
7
8
  import { find, uniq } from '../lang';
8
9
 
@@ -53,7 +54,7 @@ function validateSplitFilter(log: ILogger, type: SplitIO.SplitFilterType, values
53
54
  if (result) {
54
55
 
55
56
  if (type === 'bySet') {
56
- result = sanitizeFlagSets(log, result);
57
+ result = sanitizeFlagSets(log, result, LOG_PREFIX_SETTINGS);
57
58
  }
58
59
 
59
60
  // check max length
@@ -87,7 +88,7 @@ function queryStringBuilder(groupedFilters: Record<SplitIO.SplitFilterType, stri
87
88
  }
88
89
 
89
90
  /**
90
- * Sanitizes set names list taking in account:
91
+ * Sanitizes set names list taking into account:
91
92
  * - It should be lowercase
92
93
  * - Must adhere the following regular expression /^[a-z0-9][_a-z0-9]{0,49}$/ that means
93
94
  * - must start with a letter or number
@@ -97,20 +98,21 @@ function queryStringBuilder(groupedFilters: Record<SplitIO.SplitFilterType, stri
97
98
  *
98
99
  * @param {ILogger} log
99
100
  * @param {string[]} flagSets
101
+ * @param {string} method
100
102
  * @returns sanitized list of set names
101
103
  */
102
- function sanitizeFlagSets(log: ILogger, flagSets: string[]) {
104
+ function sanitizeFlagSets(log: ILogger, flagSets: string[], method: string) {
103
105
  let sanitizedSets = flagSets
104
106
  .map(flagSet => {
105
- if (CAPITAL_LETTERS_REGEX.test(flagSet)){
106
- log.warn(WARN_SPLITS_FILTER_LOWERCASE_SET,[flagSet]);
107
+ if (CAPITAL_LETTERS_REGEX.test(flagSet)) {
108
+ log.warn(WARN_LOWERCASE_FLAGSET, [method, flagSet]);
107
109
  flagSet = flagSet.toLowerCase();
108
110
  }
109
111
  return flagSet;
110
112
  })
111
113
  .filter(flagSet => {
112
- if (!VALID_FLAGSET_REGEX.test(flagSet)){
113
- log.warn(WARN_SPLITS_FILTER_INVALID_SET, [flagSet,VALID_FLAGSET_REGEX,flagSet]);
114
+ if (!VALID_FLAGSET_REGEX.test(flagSet)) {
115
+ log.warn(WARN_INVALID_FLAGSET, [method, flagSet, VALID_FLAGSET_REGEX, flagSet]);
114
116
  return false;
115
117
  }
116
118
  if (typeof flagSet !== 'string') return false;
@@ -128,6 +130,7 @@ function configuredFilter(validFilters: SplitIO.SplitFilter[], filterType: Split
128
130
  *
129
131
  * @param {ILogger} log logger
130
132
  * @param {any} maybeSplitFilters split filters configuration param provided by the user
133
+ * @param {string} mode settings mode
131
134
  * @returns it returns an object with the following properties:
132
135
  * - `validFilters`: the validated `splitFilters` configuration object defined by the user.
133
136
  * - `queryString`: the parsed split filter query. it is null if all filters are invalid or all values in filters are invalid.
@@ -135,7 +138,7 @@ function configuredFilter(validFilters: SplitIO.SplitFilter[], filterType: Split
135
138
  *
136
139
  * @throws Error if the some of the grouped list of values per filter exceeds the max allowed length
137
140
  */
138
- export function validateSplitFilters(log: ILogger, maybeSplitFilters: any): ISplitFiltersValidation {
141
+ export function validateSplitFilters(log: ILogger, maybeSplitFilters: any, mode: string): ISplitFiltersValidation {
139
142
  // Validation result schema
140
143
  const res = {
141
144
  validFilters: [],
@@ -145,6 +148,11 @@ export function validateSplitFilters(log: ILogger, maybeSplitFilters: any): ISpl
145
148
 
146
149
  // do nothing if `splitFilters` param is not a non-empty array or mode is not STANDALONE
147
150
  if (!maybeSplitFilters) return res;
151
+ // Warn depending on the mode
152
+ if (mode === CONSUMER_MODE || mode === CONSUMER_PARTIAL_MODE) {
153
+ log.warn(WARN_SPLITS_FILTER_IGNORED);
154
+ return res;
155
+ }
148
156
  // Check collection type
149
157
  if (!Array.isArray(maybeSplitFilters) || maybeSplitFilters.length === 0) {
150
158
  log.warn(WARN_SPLITS_FILTER_EMPTY);
@@ -181,9 +189,9 @@ export function validateSplitFilters(log: ILogger, maybeSplitFilters: any): ISpl
181
189
  return res;
182
190
  }
183
191
 
184
- export function flagSetsAreValid(log: ILogger, method: string, flagSets: string[], flagSetsInConfig: string[]): string[] {
192
+ export function validateFlagSets(log: ILogger, method: string, flagSets: string[], flagSetsInConfig: string[]): string[] {
185
193
  const sets = validateSplits(log, flagSets, method, 'flag sets', 'flag set');
186
- let toReturn = sets ? sanitizeFlagSets(log, sets) : [];
194
+ let toReturn = sets ? sanitizeFlagSets(log, sets, method) : [];
187
195
  if (flagSetsInConfig.length > 0) {
188
196
  toReturn = toReturn.filter(flagSet => {
189
197
  if (flagSetsInConfig.indexOf(flagSet) > -1) {
@@ -5,4 +5,4 @@ import { SplitIO } from '../types';
5
5
  import { ILogger } from '../logger/types';
6
6
  export declare function evaluateFeature(log: ILogger, key: SplitIO.SplitKey, splitName: string, attributes: SplitIO.Attributes | undefined, storage: IStorageSync | IStorageAsync): MaybeThenable<IEvaluationResult>;
7
7
  export declare function evaluateFeatures(log: ILogger, key: SplitIO.SplitKey, splitNames: string[], attributes: SplitIO.Attributes | undefined, storage: IStorageSync | IStorageAsync): MaybeThenable<Record<string, IEvaluationResult>>;
8
- export declare function evaluateFeaturesByFlagSets(log: ILogger, key: SplitIO.SplitKey, flagSets: string[], attributes: SplitIO.Attributes | undefined, storage: IStorageSync | IStorageAsync): MaybeThenable<Record<string, IEvaluationResult>>;
8
+ export declare function evaluateFeaturesByFlagSets(log: ILogger, key: SplitIO.SplitKey, flagSets: string[], attributes: SplitIO.Attributes | undefined, storage: IStorageSync | IStorageAsync, method: string): MaybeThenable<Record<string, IEvaluationResult>>;
@@ -89,14 +89,16 @@ export declare const WARN_NOT_EXISTENT_SPLIT = 215;
89
89
  export declare const WARN_LOWERCASE_TRAFFIC_TYPE = 216;
90
90
  export declare const WARN_NOT_EXISTENT_TT = 217;
91
91
  export declare const WARN_INTEGRATION_INVALID = 218;
92
+ export declare const WARN_SPLITS_FILTER_IGNORED = 219;
92
93
  export declare const WARN_SPLITS_FILTER_INVALID = 220;
93
94
  export declare const WARN_SPLITS_FILTER_EMPTY = 221;
94
95
  export declare const WARN_SDK_KEY = 222;
95
96
  export declare const STREAMING_PARSING_MY_SEGMENTS_UPDATE_V2 = 223;
96
97
  export declare const STREAMING_PARSING_SPLIT_UPDATE = 224;
97
- export declare const WARN_SPLITS_FILTER_INVALID_SET = 225;
98
- export declare const WARN_SPLITS_FILTER_LOWERCASE_SET = 226;
98
+ export declare const WARN_INVALID_FLAGSET = 225;
99
+ export declare const WARN_LOWERCASE_FLAGSET = 226;
99
100
  export declare const WARN_FLAGSET_NOT_CONFIGURED = 227;
101
+ export declare const WARN_FLAGSET_WITHOUT_FLAGS = 228;
100
102
  export declare const ERROR_ENGINE_COMBINER_IFELSEIF = 300;
101
103
  export declare const ERROR_LOGLEVEL_INVALID = 301;
102
104
  export declare const ERROR_CLIENT_LISTENER = 302;
@@ -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 { 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[];