@splitsoftware/splitio-commons 2.1.0-rc.2 → 2.1.1-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.
- package/CHANGES.txt +2 -7
- package/README.md +1 -0
- package/cjs/evaluator/combiners/and.js +2 -6
- package/cjs/evaluator/combiners/ifelseif.js +6 -6
- package/cjs/evaluator/condition/index.js +6 -5
- package/cjs/evaluator/index.js +7 -7
- package/cjs/evaluator/matchers/index.js +3 -1
- package/cjs/evaluator/matchers/matcherTypes.js +1 -0
- package/cjs/evaluator/matchers/rbsegment.js +43 -0
- package/cjs/evaluator/matchersTransform/index.js +4 -0
- package/cjs/evaluator/parser/index.js +2 -2
- package/cjs/evaluator/value/sanitize.js +1 -0
- package/cjs/logger/constants.js +5 -6
- package/cjs/logger/messages/debug.js +3 -4
- package/cjs/logger/messages/warn.js +1 -1
- package/cjs/readiness/readinessManager.js +0 -6
- package/cjs/services/splitApi.js +2 -2
- package/cjs/storages/AbstractSplitsCacheAsync.js +19 -1
- package/cjs/storages/AbstractSplitsCacheSync.js +17 -9
- package/cjs/storages/KeyBuilder.js +8 -15
- package/cjs/storages/KeyBuilderCS.js +11 -5
- package/cjs/storages/KeyBuilderSS.js +3 -0
- package/cjs/storages/dataLoader.js +3 -5
- package/cjs/storages/inLocalStorage/RBSegmentsCacheInLocal.js +117 -0
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +69 -15
- package/cjs/storages/inLocalStorage/index.js +7 -5
- package/cjs/storages/inMemory/InMemoryStorage.js +3 -0
- package/cjs/storages/inMemory/InMemoryStorageCS.js +4 -0
- package/cjs/storages/inMemory/RBSegmentsCacheInMemory.js +61 -0
- package/cjs/storages/inMemory/SplitsCacheInMemory.js +24 -31
- package/cjs/storages/inRedis/RBSegmentsCacheInRedis.js +64 -0
- package/cjs/storages/inRedis/SplitsCacheInRedis.js +4 -21
- package/cjs/storages/inRedis/constants.js +1 -1
- package/cjs/storages/inRedis/index.js +2 -0
- package/cjs/storages/pluggable/RBSegmentsCachePluggable.js +64 -0
- package/cjs/storages/pluggable/SplitsCachePluggable.js +2 -19
- package/cjs/storages/pluggable/index.js +3 -2
- package/cjs/sync/offline/syncTasks/fromObjectSyncTask.js +14 -16
- package/cjs/sync/polling/fetchers/splitChangesFetcher.js +2 -2
- package/cjs/sync/polling/pollingManagerCS.js +7 -7
- package/cjs/sync/polling/syncTasks/splitsSyncTask.js +1 -1
- package/cjs/sync/polling/updaters/mySegmentsUpdater.js +2 -2
- package/cjs/sync/polling/updaters/segmentChangesUpdater.js +1 -1
- package/cjs/sync/polling/updaters/splitChangesUpdater.js +62 -51
- package/cjs/sync/streaming/SSEHandler/index.js +1 -0
- package/cjs/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +106 -77
- package/cjs/sync/streaming/constants.js +2 -1
- package/cjs/sync/streaming/pushManager.js +3 -16
- package/cjs/sync/syncManagerOnline.js +5 -10
- package/cjs/trackers/uniqueKeysTracker.js +1 -1
- package/cjs/utils/constants/browser.js +5 -0
- package/cjs/utils/constants/index.js +3 -2
- package/cjs/utils/settingsValidation/storage/storageCS.js +1 -1
- package/esm/evaluator/combiners/and.js +2 -6
- package/esm/evaluator/combiners/ifelseif.js +7 -7
- package/esm/evaluator/condition/index.js +6 -5
- package/esm/evaluator/index.js +7 -7
- package/esm/evaluator/matchers/index.js +3 -1
- package/esm/evaluator/matchers/matcherTypes.js +1 -0
- package/esm/evaluator/matchers/rbsegment.js +39 -0
- package/esm/evaluator/matchersTransform/index.js +4 -0
- package/esm/evaluator/parser/index.js +2 -2
- package/esm/evaluator/value/sanitize.js +1 -0
- package/esm/logger/constants.js +2 -3
- package/esm/logger/messages/debug.js +3 -4
- package/esm/logger/messages/warn.js +1 -1
- package/esm/readiness/readinessManager.js +0 -6
- package/esm/services/splitApi.js +2 -2
- package/esm/storages/AbstractSplitsCacheAsync.js +19 -1
- package/esm/storages/AbstractSplitsCacheSync.js +17 -9
- package/esm/storages/KeyBuilder.js +8 -15
- package/esm/storages/KeyBuilderCS.js +11 -5
- package/esm/storages/KeyBuilderSS.js +3 -0
- package/esm/storages/dataLoader.js +2 -4
- package/esm/storages/inLocalStorage/RBSegmentsCacheInLocal.js +114 -0
- package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +69 -15
- package/esm/storages/inLocalStorage/index.js +7 -5
- package/esm/storages/inMemory/InMemoryStorage.js +3 -0
- package/esm/storages/inMemory/InMemoryStorageCS.js +4 -0
- package/esm/storages/inMemory/RBSegmentsCacheInMemory.js +58 -0
- package/esm/storages/inMemory/SplitsCacheInMemory.js +24 -31
- package/esm/storages/inRedis/RBSegmentsCacheInRedis.js +61 -0
- package/esm/storages/inRedis/SplitsCacheInRedis.js +4 -21
- package/esm/storages/inRedis/constants.js +1 -1
- package/esm/storages/inRedis/index.js +2 -0
- package/esm/storages/pluggable/RBSegmentsCachePluggable.js +61 -0
- package/esm/storages/pluggable/SplitsCachePluggable.js +2 -19
- package/esm/storages/pluggable/index.js +3 -2
- package/esm/sync/offline/syncTasks/fromObjectSyncTask.js +14 -16
- package/esm/sync/polling/fetchers/splitChangesFetcher.js +2 -2
- package/esm/sync/polling/pollingManagerCS.js +7 -7
- package/esm/sync/polling/syncTasks/splitsSyncTask.js +1 -1
- package/esm/sync/polling/updaters/mySegmentsUpdater.js +2 -2
- package/esm/sync/polling/updaters/segmentChangesUpdater.js +1 -1
- package/esm/sync/polling/updaters/splitChangesUpdater.js +63 -52
- package/esm/sync/streaming/SSEHandler/index.js +2 -1
- package/esm/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +102 -73
- package/esm/sync/streaming/constants.js +1 -0
- package/esm/sync/streaming/pushManager.js +6 -19
- package/esm/sync/syncManagerOnline.js +5 -10
- package/esm/trackers/uniqueKeysTracker.js +1 -1
- package/esm/utils/constants/browser.js +2 -0
- package/esm/utils/constants/index.js +2 -1
- package/esm/utils/settingsValidation/storage/storageCS.js +1 -1
- package/package.json +1 -1
- package/src/dtos/types.ts +32 -8
- package/src/evaluator/Engine.ts +1 -1
- package/src/evaluator/combiners/and.ts +5 -4
- package/src/evaluator/combiners/ifelseif.ts +7 -9
- package/src/evaluator/condition/engineUtils.ts +1 -1
- package/src/evaluator/condition/index.ts +12 -12
- package/src/evaluator/index.ts +7 -7
- package/src/evaluator/matchers/index.ts +3 -1
- package/src/evaluator/matchers/matcherTypes.ts +1 -0
- package/src/evaluator/matchers/rbsegment.ts +61 -0
- package/src/evaluator/matchersTransform/index.ts +3 -0
- package/src/evaluator/parser/index.ts +3 -3
- package/src/evaluator/types.ts +2 -2
- package/src/evaluator/value/index.ts +2 -2
- package/src/evaluator/value/sanitize.ts +5 -4
- package/src/logger/constants.ts +2 -3
- package/src/logger/messages/debug.ts +3 -4
- package/src/logger/messages/warn.ts +1 -1
- package/src/readiness/readinessManager.ts +0 -5
- package/src/sdkManager/index.ts +1 -1
- package/src/services/splitApi.ts +2 -2
- package/src/services/types.ts +1 -1
- package/src/storages/AbstractSplitsCacheAsync.ts +23 -5
- package/src/storages/AbstractSplitsCacheSync.ts +22 -15
- package/src/storages/KeyBuilder.ts +9 -17
- package/src/storages/KeyBuilderCS.ts +13 -6
- package/src/storages/KeyBuilderSS.ts +4 -0
- package/src/storages/dataLoader.ts +2 -5
- package/src/storages/inLocalStorage/RBSegmentsCacheInLocal.ts +136 -0
- package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +80 -16
- package/src/storages/inLocalStorage/index.ts +12 -8
- package/src/storages/inMemory/InMemoryStorage.ts +3 -0
- package/src/storages/inMemory/InMemoryStorageCS.ts +4 -0
- package/src/storages/inMemory/RBSegmentsCacheInMemory.ts +68 -0
- package/src/storages/inMemory/SplitsCacheInMemory.ts +22 -27
- package/src/storages/inRedis/RBSegmentsCacheInRedis.ts +79 -0
- package/src/storages/inRedis/SplitsCacheInRedis.ts +4 -21
- package/src/storages/inRedis/constants.ts +1 -1
- package/src/storages/inRedis/index.ts +2 -0
- package/src/storages/pluggable/RBSegmentsCachePluggable.ts +76 -0
- package/src/storages/pluggable/SplitsCachePluggable.ts +2 -19
- package/src/storages/pluggable/index.ts +3 -2
- package/src/storages/types.ts +47 -18
- package/src/sync/offline/syncTasks/fromObjectSyncTask.ts +19 -21
- package/src/sync/polling/fetchers/splitChangesFetcher.ts +2 -1
- package/src/sync/polling/fetchers/types.ts +1 -0
- package/src/sync/polling/pollingManagerCS.ts +7 -7
- package/src/sync/polling/syncTasks/splitsSyncTask.ts +1 -2
- package/src/sync/polling/types.ts +2 -2
- package/src/sync/polling/updaters/mySegmentsUpdater.ts +2 -2
- package/src/sync/polling/updaters/segmentChangesUpdater.ts +1 -1
- package/src/sync/polling/updaters/splitChangesUpdater.ts +74 -63
- package/src/sync/streaming/SSEHandler/index.ts +2 -1
- package/src/sync/streaming/SSEHandler/types.ts +2 -2
- package/src/sync/streaming/UpdateWorkers/SplitsUpdateWorker.ts +98 -68
- package/src/sync/streaming/constants.ts +1 -0
- package/src/sync/streaming/parseUtils.ts +2 -2
- package/src/sync/streaming/pushManager.ts +6 -18
- package/src/sync/streaming/types.ts +3 -2
- package/src/sync/syncManagerOnline.ts +5 -11
- package/src/trackers/uniqueKeysTracker.ts +1 -1
- package/src/utils/constants/browser.ts +2 -0
- package/src/utils/constants/index.ts +2 -1
- package/src/utils/lang/index.ts +2 -2
- package/src/utils/settingsValidation/storage/storageCS.ts +1 -1
- package/types/splitio.d.ts +1 -25
- package/cjs/storages/inLocalStorage/validateCache.js +0 -79
- package/esm/storages/inLocalStorage/validateCache.js +0 -75
- package/src/storages/inLocalStorage/validateCache.ts +0 -91
package/src/dtos/types.ts
CHANGED
|
@@ -66,6 +66,11 @@ interface IInSegmentMatcher extends ISplitMatcherBase {
|
|
|
66
66
|
userDefinedSegmentMatcherData: IInSegmentMatcherData
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
interface IInRBSegmentMatcher extends ISplitMatcherBase {
|
|
70
|
+
matcherType: 'IN_RULE_BASED_SEGMENT',
|
|
71
|
+
userDefinedSegmentMatcherData: IInSegmentMatcherData
|
|
72
|
+
}
|
|
73
|
+
|
|
69
74
|
interface IInLargeSegmentMatcher extends ISplitMatcherBase {
|
|
70
75
|
matcherType: 'IN_LARGE_SEGMENT',
|
|
71
76
|
userDefinedLargeSegmentMatcherData: IInLargeSegmentMatcherData
|
|
@@ -176,7 +181,7 @@ export type ISplitMatcher = IAllKeysMatcher | IInSegmentMatcher | IWhitelistMatc
|
|
|
176
181
|
ILessThanOrEqualToMatcher | IBetweenMatcher | IEqualToSetMatcher | IContainsAnyOfSetMatcher | IContainsAllOfSetMatcher | IPartOfSetMatcher |
|
|
177
182
|
IStartsWithMatcher | IEndsWithMatcher | IContainsStringMatcher | IInSplitTreatmentMatcher | IEqualToBooleanMatcher | IMatchesStringMatcher |
|
|
178
183
|
IEqualToSemverMatcher | IGreaterThanOrEqualToSemverMatcher | ILessThanOrEqualToSemverMatcher | IBetweenSemverMatcher | IInListSemverMatcher |
|
|
179
|
-
IInLargeSegmentMatcher
|
|
184
|
+
IInLargeSegmentMatcher | IInRBSegmentMatcher
|
|
180
185
|
|
|
181
186
|
/** Split object */
|
|
182
187
|
export interface ISplitPartition {
|
|
@@ -189,19 +194,30 @@ export interface ISplitCondition {
|
|
|
189
194
|
combiner: 'AND',
|
|
190
195
|
matchers: ISplitMatcher[]
|
|
191
196
|
}
|
|
192
|
-
partitions
|
|
193
|
-
label
|
|
194
|
-
conditionType
|
|
197
|
+
partitions?: ISplitPartition[]
|
|
198
|
+
label?: string
|
|
199
|
+
conditionType?: 'ROLLOUT' | 'WHITELIST'
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export interface IRBSegment {
|
|
203
|
+
name: string,
|
|
204
|
+
changeNumber: number,
|
|
205
|
+
status: 'ACTIVE' | 'ARCHIVED',
|
|
206
|
+
conditions: ISplitCondition[],
|
|
207
|
+
excluded: {
|
|
208
|
+
keys: string[],
|
|
209
|
+
segments: string[]
|
|
210
|
+
}
|
|
195
211
|
}
|
|
196
212
|
|
|
197
213
|
export interface ISplit {
|
|
198
214
|
name: string,
|
|
199
215
|
changeNumber: number,
|
|
216
|
+
status: 'ACTIVE' | 'ARCHIVED',
|
|
217
|
+
conditions: ISplitCondition[],
|
|
200
218
|
killed: boolean,
|
|
201
219
|
defaultTreatment: string,
|
|
202
220
|
trafficTypeName: string,
|
|
203
|
-
conditions: ISplitCondition[],
|
|
204
|
-
status: 'ACTIVE' | 'ARCHIVED',
|
|
205
221
|
seed: number,
|
|
206
222
|
trafficAllocation?: number,
|
|
207
223
|
trafficAllocationSeed?: number
|
|
@@ -217,8 +233,16 @@ export type ISplitPartial = Pick<ISplit, 'conditions' | 'configurations' | 'traf
|
|
|
217
233
|
|
|
218
234
|
/** Interface of the parsed JSON response of `/splitChanges` */
|
|
219
235
|
export interface ISplitChangesResponse {
|
|
220
|
-
|
|
221
|
-
|
|
236
|
+
ff?: {
|
|
237
|
+
t: number,
|
|
238
|
+
s?: number,
|
|
239
|
+
d: ISplit[]
|
|
240
|
+
},
|
|
241
|
+
rbs?: {
|
|
242
|
+
t: number,
|
|
243
|
+
s?: number,
|
|
244
|
+
d: IRBSegment[]
|
|
245
|
+
}
|
|
222
246
|
}
|
|
223
247
|
|
|
224
248
|
/** Interface of the parsed JSON response of `/segmentChanges/{segmentName}` */
|
package/src/evaluator/Engine.ts
CHANGED
|
@@ -2,10 +2,11 @@ import { findIndex } from '../../utils/lang';
|
|
|
2
2
|
import { ILogger } from '../../logger/types';
|
|
3
3
|
import { thenable } from '../../utils/promise/thenable';
|
|
4
4
|
import { MaybeThenable } from '../../dtos/types';
|
|
5
|
-
import {
|
|
5
|
+
import { ISplitEvaluator } from '../types';
|
|
6
6
|
import { ENGINE_COMBINER_AND } from '../../logger/constants';
|
|
7
|
+
import SplitIO from '../../../types/splitio';
|
|
7
8
|
|
|
8
|
-
export function andCombinerContext(log: ILogger, matchers:
|
|
9
|
+
export function andCombinerContext(log: ILogger, matchers: Array<(key: SplitIO.SplitKey, attributes?: SplitIO.Attributes, splitEvaluator?: ISplitEvaluator) => MaybeThenable<boolean>>) {
|
|
9
10
|
|
|
10
11
|
function andResults(results: boolean[]): boolean {
|
|
11
12
|
// Array.prototype.every is supported by target environments
|
|
@@ -15,8 +16,8 @@ export function andCombinerContext(log: ILogger, matchers: IMatcher[]) {
|
|
|
15
16
|
return hasMatchedAll;
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
return function andCombiner(
|
|
19
|
-
const matcherResults = matchers.map(matcher => matcher(
|
|
19
|
+
return function andCombiner(key: SplitIO.SplitKey, attributes?: SplitIO.Attributes, splitEvaluator?: ISplitEvaluator): MaybeThenable<boolean> {
|
|
20
|
+
const matcherResults = matchers.map(matcher => matcher(key, attributes, splitEvaluator));
|
|
20
21
|
|
|
21
22
|
// If any matching result is a thenable we should use Promise.all
|
|
22
23
|
if (findIndex(matcherResults, thenable) !== -1) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { findIndex } from '../../utils/lang';
|
|
1
|
+
import { findIndex, isBoolean } from '../../utils/lang';
|
|
2
2
|
import { ILogger } from '../../logger/types';
|
|
3
3
|
import { thenable } from '../../utils/promise/thenable';
|
|
4
4
|
import { UNSUPPORTED_MATCHER_TYPE } from '../../utils/labels';
|
|
@@ -18,14 +18,12 @@ export function ifElseIfCombinerContext(log: ILogger, predicates: IEvaluator[]):
|
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
function
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
for (let i = 0; i < len; i++) {
|
|
21
|
+
function computeEvaluation(predicateResults: Array<IEvaluation | boolean | undefined>): IEvaluation | boolean | undefined {
|
|
22
|
+
for (let i = 0, len = predicateResults.length; i < len; i++) {
|
|
25
23
|
const evaluation = predicateResults[i];
|
|
26
24
|
|
|
27
25
|
if (evaluation !== undefined) {
|
|
28
|
-
log.debug(ENGINE_COMBINER_IFELSEIF, [evaluation.treatment]);
|
|
26
|
+
if (!isBoolean(evaluation)) log.debug(ENGINE_COMBINER_IFELSEIF, [evaluation.treatment]);
|
|
29
27
|
|
|
30
28
|
return evaluation;
|
|
31
29
|
}
|
|
@@ -35,7 +33,7 @@ export function ifElseIfCombinerContext(log: ILogger, predicates: IEvaluator[]):
|
|
|
35
33
|
return undefined;
|
|
36
34
|
}
|
|
37
35
|
|
|
38
|
-
function ifElseIfCombiner(key: SplitIO.
|
|
36
|
+
function ifElseIfCombiner(key: SplitIO.SplitKeyObject, seed?: number, trafficAllocation?: number, trafficAllocationSeed?: number, attributes?: SplitIO.Attributes, splitEvaluator?: ISplitEvaluator) {
|
|
39
37
|
// In Async environments we are going to have async predicates. There is none way to know
|
|
40
38
|
// before hand so we need to evaluate all the predicates, verify for thenables, and finally,
|
|
41
39
|
// define how to return the treatment (wrap result into a Promise or not).
|
|
@@ -43,10 +41,10 @@ export function ifElseIfCombinerContext(log: ILogger, predicates: IEvaluator[]):
|
|
|
43
41
|
|
|
44
42
|
// if we find a thenable
|
|
45
43
|
if (findIndex(predicateResults, thenable) !== -1) {
|
|
46
|
-
return Promise.all(predicateResults).then(results =>
|
|
44
|
+
return Promise.all(predicateResults).then(results => computeEvaluation(results));
|
|
47
45
|
}
|
|
48
46
|
|
|
49
|
-
return
|
|
47
|
+
return computeEvaluation(predicateResults as IEvaluation[]);
|
|
50
48
|
}
|
|
51
49
|
|
|
52
50
|
// if there is none predicates, then there was an error in parsing phase
|
|
@@ -5,7 +5,7 @@ import { bucket } from '../../utils/murmur3/murmur3';
|
|
|
5
5
|
/**
|
|
6
6
|
* Get the treatment name given a key, a seed, and the percentage of each treatment.
|
|
7
7
|
*/
|
|
8
|
-
export function getTreatment(log: ILogger, key: string, seed: number, treatments: { getTreatmentFor: (x: number) => string }) {
|
|
8
|
+
export function getTreatment(log: ILogger, key: string, seed: number | undefined, treatments: { getTreatmentFor: (x: number) => string }) {
|
|
9
9
|
const _bucket = bucket(key, seed);
|
|
10
10
|
|
|
11
11
|
const treatment = treatments.getTreatmentFor(_bucket);
|
|
@@ -7,14 +7,14 @@ import SplitIO from '../../../types/splitio';
|
|
|
7
7
|
import { ILogger } from '../../logger/types';
|
|
8
8
|
|
|
9
9
|
// Build Evaluation object if and only if matchingResult is true
|
|
10
|
-
function match(log: ILogger, matchingResult: boolean, bucketingKey: string | undefined, seed
|
|
10
|
+
function match(log: ILogger, matchingResult: boolean, bucketingKey: string | undefined, seed?: number, treatments?: { getTreatmentFor: (x: number) => string }, label?: string): IEvaluation | boolean | undefined {
|
|
11
11
|
if (matchingResult) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
return treatments ? // Feature flag
|
|
13
|
+
{
|
|
14
|
+
treatment: getTreatment(log, bucketingKey as string, seed, treatments),
|
|
15
|
+
label: label!
|
|
16
|
+
} : // Rule-based segment
|
|
17
|
+
true;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
// else we should notify the engine to continue evaluating
|
|
@@ -22,12 +22,12 @@ function match(log: ILogger, matchingResult: boolean, bucketingKey: string | und
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
// Condition factory
|
|
25
|
-
export function conditionContext(log: ILogger, matcherEvaluator: (
|
|
25
|
+
export function conditionContext(log: ILogger, matcherEvaluator: (key: SplitIO.SplitKeyObject, attributes?: SplitIO.Attributes, splitEvaluator?: ISplitEvaluator) => MaybeThenable<boolean>, treatments?: { getTreatmentFor: (x: number) => string }, label?: string, conditionType?: 'ROLLOUT' | 'WHITELIST'): IEvaluator {
|
|
26
26
|
|
|
27
|
-
return function conditionEvaluator(key: SplitIO.
|
|
27
|
+
return function conditionEvaluator(key: SplitIO.SplitKeyObject, seed?: number, trafficAllocation?: number, trafficAllocationSeed?: number, attributes?: SplitIO.Attributes, splitEvaluator?: ISplitEvaluator) {
|
|
28
28
|
|
|
29
29
|
// Whitelisting has more priority than traffic allocation, so we don't apply this filtering to those conditions.
|
|
30
|
-
if (conditionType === 'ROLLOUT' && !shouldApplyRollout(trafficAllocation
|
|
30
|
+
if (conditionType === 'ROLLOUT' && !shouldApplyRollout(trafficAllocation!, key.bucketingKey, trafficAllocationSeed!)) {
|
|
31
31
|
return {
|
|
32
32
|
treatment: undefined, // treatment value is assigned later
|
|
33
33
|
label: NOT_IN_SPLIT
|
|
@@ -41,10 +41,10 @@ export function conditionContext(log: ILogger, matcherEvaluator: (...args: any)
|
|
|
41
41
|
const matches = matcherEvaluator(key, attributes, splitEvaluator);
|
|
42
42
|
|
|
43
43
|
if (thenable(matches)) {
|
|
44
|
-
return matches.then(result => match(log, result,
|
|
44
|
+
return matches.then(result => match(log, result, key.bucketingKey, seed, treatments, label));
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
return match(log, matches,
|
|
47
|
+
return match(log, matches, key.bucketingKey, seed, treatments, label);
|
|
48
48
|
};
|
|
49
49
|
|
|
50
50
|
}
|
package/src/evaluator/index.ts
CHANGED
|
@@ -43,8 +43,8 @@ export function evaluateFeature(
|
|
|
43
43
|
if (thenable(parsedSplit)) {
|
|
44
44
|
return parsedSplit.then((split) => getEvaluation(
|
|
45
45
|
log,
|
|
46
|
-
split,
|
|
47
46
|
key,
|
|
47
|
+
split,
|
|
48
48
|
attributes,
|
|
49
49
|
storage,
|
|
50
50
|
)).catch(
|
|
@@ -56,8 +56,8 @@ export function evaluateFeature(
|
|
|
56
56
|
|
|
57
57
|
return getEvaluation(
|
|
58
58
|
log,
|
|
59
|
-
parsedSplit,
|
|
60
59
|
key,
|
|
60
|
+
parsedSplit,
|
|
61
61
|
attributes,
|
|
62
62
|
storage,
|
|
63
63
|
);
|
|
@@ -80,13 +80,13 @@ export function evaluateFeatures(
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
return thenable(parsedSplits) ?
|
|
83
|
-
parsedSplits.then(splits => getEvaluations(log, splitNames, splits,
|
|
83
|
+
parsedSplits.then(splits => getEvaluations(log, key, splitNames, splits, attributes, storage))
|
|
84
84
|
.catch(() => {
|
|
85
85
|
// Exception on async `getSplits` storage. For example, when the storage is redis or
|
|
86
86
|
// pluggable and there is a connection issue and we can't retrieve the split to be evaluated
|
|
87
87
|
return treatmentsException(splitNames);
|
|
88
88
|
}) :
|
|
89
|
-
getEvaluations(log, splitNames, parsedSplits,
|
|
89
|
+
getEvaluations(log, key, splitNames, parsedSplits, attributes, storage);
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
export function evaluateFeaturesByFlagSets(
|
|
@@ -136,8 +136,8 @@ export function evaluateFeaturesByFlagSets(
|
|
|
136
136
|
|
|
137
137
|
function getEvaluation(
|
|
138
138
|
log: ILogger,
|
|
139
|
-
splitJSON: ISplit | null,
|
|
140
139
|
key: SplitIO.SplitKey,
|
|
140
|
+
splitJSON: ISplit | null,
|
|
141
141
|
attributes: SplitIO.Attributes | undefined,
|
|
142
142
|
storage: IStorageSync | IStorageAsync,
|
|
143
143
|
): MaybeThenable<IEvaluationResult> {
|
|
@@ -172,9 +172,9 @@ function getEvaluation(
|
|
|
172
172
|
|
|
173
173
|
function getEvaluations(
|
|
174
174
|
log: ILogger,
|
|
175
|
+
key: SplitIO.SplitKey,
|
|
175
176
|
splitNames: string[],
|
|
176
177
|
splits: Record<string, ISplit | null>,
|
|
177
|
-
key: SplitIO.SplitKey,
|
|
178
178
|
attributes: SplitIO.Attributes | undefined,
|
|
179
179
|
storage: IStorageSync | IStorageAsync,
|
|
180
180
|
): MaybeThenable<Record<string, IEvaluationResult>> {
|
|
@@ -183,8 +183,8 @@ function getEvaluations(
|
|
|
183
183
|
splitNames.forEach(splitName => {
|
|
184
184
|
const evaluation = getEvaluation(
|
|
185
185
|
log,
|
|
186
|
-
splits[splitName],
|
|
187
186
|
key,
|
|
187
|
+
splits[splitName],
|
|
188
188
|
attributes,
|
|
189
189
|
storage
|
|
190
190
|
);
|
|
@@ -24,6 +24,7 @@ import { inListSemverMatcherContext } from './semver_inlist';
|
|
|
24
24
|
import { IStorageAsync, IStorageSync } from '../../storages/types';
|
|
25
25
|
import { IMatcher, IMatcherDto } from '../types';
|
|
26
26
|
import { ILogger } from '../../logger/types';
|
|
27
|
+
import { ruleBasedSegmentMatcherContext } from './rbsegment';
|
|
27
28
|
|
|
28
29
|
const matchers = [
|
|
29
30
|
undefined, // UNDEFINED: 0
|
|
@@ -50,6 +51,7 @@ const matchers = [
|
|
|
50
51
|
betweenSemverMatcherContext, // BETWEEN_SEMVER: 21
|
|
51
52
|
inListSemverMatcherContext, // IN_LIST_SEMVER: 22
|
|
52
53
|
largeSegmentMatcherContext, // IN_LARGE_SEGMENT: 23
|
|
54
|
+
ruleBasedSegmentMatcherContext // IN_RULE_BASED_SEGMENT: 24
|
|
53
55
|
];
|
|
54
56
|
|
|
55
57
|
/**
|
|
@@ -64,5 +66,5 @@ export function matcherFactory(log: ILogger, matcherDto: IMatcherDto, storage?:
|
|
|
64
66
|
let matcherFn;
|
|
65
67
|
// @ts-ignore
|
|
66
68
|
if (matchers[type]) matcherFn = matchers[type](value, storage, log); // There is no index-out-of-bound exception in JavaScript
|
|
67
|
-
return matcherFn;
|
|
69
|
+
return matcherFn as IMatcher;
|
|
68
70
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { IRBSegment, MaybeThenable } from '../../dtos/types';
|
|
2
|
+
import { IStorageAsync, IStorageSync } from '../../storages/types';
|
|
3
|
+
import { ILogger } from '../../logger/types';
|
|
4
|
+
import { IDependencyMatcherValue, ISplitEvaluator } from '../types';
|
|
5
|
+
import { thenable } from '../../utils/promise/thenable';
|
|
6
|
+
import { getMatching, keyParser } from '../../utils/key';
|
|
7
|
+
import { parser } from '../parser';
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
export function ruleBasedSegmentMatcherContext(segmentName: string, storage: IStorageSync | IStorageAsync, log: ILogger) {
|
|
11
|
+
|
|
12
|
+
return function ruleBasedSegmentMatcher({ key, attributes }: IDependencyMatcherValue, splitEvaluator: ISplitEvaluator): MaybeThenable<boolean> {
|
|
13
|
+
|
|
14
|
+
function matchConditions(rbsegment: IRBSegment) {
|
|
15
|
+
const conditions = rbsegment.conditions;
|
|
16
|
+
const evaluator = parser(log, conditions, storage);
|
|
17
|
+
|
|
18
|
+
const evaluation = evaluator(
|
|
19
|
+
keyParser(key),
|
|
20
|
+
undefined,
|
|
21
|
+
undefined,
|
|
22
|
+
undefined,
|
|
23
|
+
attributes,
|
|
24
|
+
splitEvaluator
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
return thenable(evaluation) ?
|
|
28
|
+
evaluation.then(evaluation => evaluation ? true : false) :
|
|
29
|
+
evaluation ? true : false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function isExcluded(rbSegment: IRBSegment) {
|
|
33
|
+
const matchingKey = getMatching(key);
|
|
34
|
+
|
|
35
|
+
if (rbSegment.excluded.keys.indexOf(matchingKey) !== -1) return true;
|
|
36
|
+
|
|
37
|
+
const isInSegment = rbSegment.excluded.segments.map(segmentName => {
|
|
38
|
+
return storage.segments.isInSegment(segmentName, matchingKey);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
return isInSegment.length && thenable(isInSegment[0]) ?
|
|
42
|
+
Promise.all(isInSegment).then(results => results.some(result => result)) :
|
|
43
|
+
isInSegment.some(result => result);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function isInSegment(rbSegment: IRBSegment | null) {
|
|
47
|
+
if (!rbSegment) return false;
|
|
48
|
+
const excluded = isExcluded(rbSegment);
|
|
49
|
+
|
|
50
|
+
return thenable(excluded) ?
|
|
51
|
+
excluded.then(excluded => excluded ? false : matchConditions(rbSegment)) :
|
|
52
|
+
excluded ? false : matchConditions(rbSegment);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const rbSegment = storage.rbSegments.get(segmentName);
|
|
56
|
+
|
|
57
|
+
return thenable(rbSegment) ?
|
|
58
|
+
rbSegment.then(isInSegment) :
|
|
59
|
+
isInSegment(rbSegment);
|
|
60
|
+
};
|
|
61
|
+
}
|
|
@@ -95,6 +95,9 @@ export function matchersTransform(matchers: ISplitMatcher[]): IMatcherDto[] {
|
|
|
95
95
|
type === matcherTypes.LESS_THAN_OR_EQUAL_TO_SEMVER
|
|
96
96
|
) {
|
|
97
97
|
value = stringMatcherData;
|
|
98
|
+
} else if (type === matcherTypes.IN_RULE_BASED_SEGMENT) {
|
|
99
|
+
value = segmentTransform(userDefinedSegmentMatcherData as IInSegmentMatcherData);
|
|
100
|
+
dataType = matcherDataTypes.NOT_SPECIFIED;
|
|
98
101
|
}
|
|
99
102
|
|
|
100
103
|
return {
|
|
@@ -37,7 +37,7 @@ export function parser(log: ILogger, conditions: ISplitCondition[], storage: ISt
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
// Evaluator function.
|
|
40
|
-
return (key:
|
|
40
|
+
return (key: SplitIO.SplitKey, attributes?: SplitIO.Attributes, splitEvaluator?: ISplitEvaluator) => {
|
|
41
41
|
const value = sanitizeValue(log, key, matcherDto, attributes);
|
|
42
42
|
let result: MaybeThenable<boolean> = false;
|
|
43
43
|
|
|
@@ -71,12 +71,12 @@ export function parser(log: ILogger, conditions: ISplitCondition[], storage: ISt
|
|
|
71
71
|
predicates.push(conditionContext(
|
|
72
72
|
log,
|
|
73
73
|
andCombinerContext(log, expressions),
|
|
74
|
-
Treatments.parse(partitions),
|
|
74
|
+
partitions && Treatments.parse(partitions),
|
|
75
75
|
label,
|
|
76
76
|
conditionType
|
|
77
77
|
));
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
//
|
|
80
|
+
// Instantiate evaluator given the set of conditions using if else if logic
|
|
81
81
|
return ifElseIfCombinerContext(log, predicates);
|
|
82
82
|
}
|
package/src/evaluator/types.ts
CHANGED
|
@@ -29,6 +29,6 @@ export type IEvaluationResult = IEvaluation & { treatment: string; impressionsDi
|
|
|
29
29
|
|
|
30
30
|
export type ISplitEvaluator = (log: ILogger, key: SplitIO.SplitKey, splitName: string, attributes: SplitIO.Attributes | undefined, storage: IStorageSync | IStorageAsync) => MaybeThenable<IEvaluation>
|
|
31
31
|
|
|
32
|
-
export type IEvaluator = (key: SplitIO.
|
|
32
|
+
export type IEvaluator = (key: SplitIO.SplitKeyObject, seed?: number, trafficAllocation?: number, trafficAllocationSeed?: number, attributes?: SplitIO.Attributes, splitEvaluator?: ISplitEvaluator) => MaybeThenable<IEvaluation | boolean | undefined>
|
|
33
33
|
|
|
34
|
-
export type IMatcher = (
|
|
34
|
+
export type IMatcher = (value: string | number | boolean | string[] | IDependencyMatcherValue, splitEvaluator?: ISplitEvaluator) => MaybeThenable<boolean>
|
|
@@ -4,7 +4,7 @@ import { ILogger } from '../../logger/types';
|
|
|
4
4
|
import { sanitize } from './sanitize';
|
|
5
5
|
import { ENGINE_VALUE, ENGINE_VALUE_NO_ATTRIBUTES, ENGINE_VALUE_INVALID } from '../../logger/constants';
|
|
6
6
|
|
|
7
|
-
function parseValue(log: ILogger, key:
|
|
7
|
+
function parseValue(log: ILogger, key: SplitIO.SplitKey, attributeName: string | null, attributes?: SplitIO.Attributes) {
|
|
8
8
|
let value = undefined;
|
|
9
9
|
if (attributeName) {
|
|
10
10
|
if (attributes) {
|
|
@@ -23,7 +23,7 @@ function parseValue(log: ILogger, key: string, attributeName: string | null, att
|
|
|
23
23
|
/**
|
|
24
24
|
* Defines value to be matched (key / attribute).
|
|
25
25
|
*/
|
|
26
|
-
export function sanitizeValue(log: ILogger, key:
|
|
26
|
+
export function sanitizeValue(log: ILogger, key: SplitIO.SplitKey, matcherDto: IMatcherDto, attributes?: SplitIO.Attributes) {
|
|
27
27
|
const attributeName = matcherDto.attribute;
|
|
28
28
|
const valueToMatch = parseValue(log, key, attributeName, attributes);
|
|
29
29
|
const sanitizedValue = sanitize(log, matcherDto.type, valueToMatch, matcherDto.dataType, attributes);
|
|
@@ -41,7 +41,7 @@ function sanitizeBoolean(val: any): boolean | undefined {
|
|
|
41
41
|
return undefined;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
function dependencyProcessor(sanitizedValue:
|
|
44
|
+
function dependencyProcessor(sanitizedValue: SplitIO.SplitKey, attributes?: SplitIO.Attributes): IDependencyMatcherValue {
|
|
45
45
|
return {
|
|
46
46
|
key: sanitizedValue,
|
|
47
47
|
attributes
|
|
@@ -60,6 +60,7 @@ function getProcessingFunction(matcherTypeID: number, dataType: string) {
|
|
|
60
60
|
case matcherTypes.BETWEEN:
|
|
61
61
|
return dataType === 'DATETIME' ? zeroSinceSS : undefined;
|
|
62
62
|
case matcherTypes.IN_SPLIT_TREATMENT:
|
|
63
|
+
case matcherTypes.IN_RULE_BASED_SEGMENT:
|
|
63
64
|
return dependencyProcessor;
|
|
64
65
|
default:
|
|
65
66
|
return undefined;
|
|
@@ -69,9 +70,9 @@ function getProcessingFunction(matcherTypeID: number, dataType: string) {
|
|
|
69
70
|
/**
|
|
70
71
|
* Sanitize matcher value
|
|
71
72
|
*/
|
|
72
|
-
export function sanitize(log: ILogger, matcherTypeID: number, value: string | number | boolean | Array<string | number> | undefined, dataType: string, attributes?: SplitIO.Attributes) {
|
|
73
|
+
export function sanitize(log: ILogger, matcherTypeID: number, value: string | number | boolean | Array<string | number> | SplitIO.SplitKey | undefined, dataType: string, attributes?: SplitIO.Attributes) {
|
|
73
74
|
const processor = getProcessingFunction(matcherTypeID, dataType);
|
|
74
|
-
let sanitizedValue: string | number | boolean | Array<string
|
|
75
|
+
let sanitizedValue: string | number | boolean | Array<string> | IDependencyMatcherValue | undefined;
|
|
75
76
|
|
|
76
77
|
switch (dataType) {
|
|
77
78
|
case matcherDataTypes.NUMBER:
|
|
@@ -88,7 +89,7 @@ export function sanitize(log: ILogger, matcherTypeID: number, value: string | nu
|
|
|
88
89
|
sanitizedValue = sanitizeBoolean(value);
|
|
89
90
|
break;
|
|
90
91
|
case matcherDataTypes.NOT_SPECIFIED:
|
|
91
|
-
sanitizedValue = value;
|
|
92
|
+
sanitizedValue = value as any;
|
|
92
93
|
break;
|
|
93
94
|
default:
|
|
94
95
|
sanitizedValue = undefined;
|
package/src/logger/constants.ts
CHANGED
|
@@ -20,9 +20,8 @@ export const RETRIEVE_CLIENT_EXISTING = 28;
|
|
|
20
20
|
export const RETRIEVE_MANAGER = 29;
|
|
21
21
|
export const SYNC_OFFLINE_DATA = 30;
|
|
22
22
|
export const SYNC_SPLITS_FETCH = 31;
|
|
23
|
-
export const
|
|
24
|
-
export const
|
|
25
|
-
export const SYNC_SPLITS_SEGMENTS = 34;
|
|
23
|
+
export const SYNC_SPLITS_UPDATE = 32;
|
|
24
|
+
export const SYNC_RBS_UPDATE = 33;
|
|
26
25
|
export const STREAMING_NEW_MESSAGE = 35;
|
|
27
26
|
export const SYNC_TASK_START = 36;
|
|
28
27
|
export const SYNC_TASK_EXECUTE = 37;
|
|
@@ -20,10 +20,9 @@ export const codesDebug: [number, string][] = codesInfo.concat([
|
|
|
20
20
|
[c.RETRIEVE_MANAGER, 'Retrieving manager instance.'],
|
|
21
21
|
// synchronizer
|
|
22
22
|
[c.SYNC_OFFLINE_DATA, c.LOG_PREFIX_SYNC_OFFLINE + 'Feature flags data: \n%s'],
|
|
23
|
-
[c.SYNC_SPLITS_FETCH, c.LOG_PREFIX_SYNC_SPLITS + 'Spin up feature flags update using since = %s'],
|
|
24
|
-
[c.
|
|
25
|
-
[c.
|
|
26
|
-
[c.SYNC_SPLITS_SEGMENTS, c.LOG_PREFIX_SYNC_SPLITS + 'Segment names collected %s'],
|
|
23
|
+
[c.SYNC_SPLITS_FETCH, c.LOG_PREFIX_SYNC_SPLITS + 'Spin up feature flags update using since = %s and rbSince = %s.'],
|
|
24
|
+
[c.SYNC_SPLITS_UPDATE, c.LOG_PREFIX_SYNC_SPLITS + 'New feature flags %s. Removed feature flags %s.'],
|
|
25
|
+
[c.SYNC_RBS_UPDATE, c.LOG_PREFIX_SYNC_SPLITS + 'New rule-based segments %s. Removed rule-based segments %s.'],
|
|
27
26
|
[c.STREAMING_NEW_MESSAGE, c.LOG_PREFIX_SYNC_STREAMING + 'New SSE message received, with data: %s.'],
|
|
28
27
|
[c.SYNC_TASK_START, c.LOG_PREFIX_SYNC + ': Starting %s. Running each %s millis'],
|
|
29
28
|
[c.SYNC_TASK_EXECUTE, c.LOG_PREFIX_SYNC + ': Running %s'],
|
|
@@ -33,7 +33,7 @@ export const codesWarn: [number, string][] = codesError.concat([
|
|
|
33
33
|
[c.WARN_SDK_KEY, c.LOG_PREFIX_SETTINGS + ': You already have %s. We recommend keeping only one instance of the factory at all times (Singleton pattern) and reusing it throughout your application'],
|
|
34
34
|
|
|
35
35
|
[c.STREAMING_PARSING_MEMBERSHIPS_UPDATE, c.LOG_PREFIX_SYNC_STREAMING + 'Fetching Memberships due to an error processing %s notification: %s'],
|
|
36
|
-
[c.STREAMING_PARSING_SPLIT_UPDATE, c.LOG_PREFIX_SYNC_STREAMING + 'Fetching SplitChanges due to an error processing
|
|
36
|
+
[c.STREAMING_PARSING_SPLIT_UPDATE, c.LOG_PREFIX_SYNC_STREAMING + 'Fetching SplitChanges due to an error processing %s notification: %s'],
|
|
37
37
|
[c.WARN_INVALID_FLAGSET, '%s: you passed %s, flag set must adhere to the regular expressions %s. This means a flag set must start with a letter or number, be in lowercase, alphanumeric and have a max length of 50 characters. %s was discarded.'],
|
|
38
38
|
[c.WARN_LOWERCASE_FLAGSET, '%s: flag set %s should be all lowercase - converting string to lowercase.'],
|
|
39
39
|
[c.WARN_FLAGSET_WITHOUT_FLAGS, '%s: you passed %s flag set that does not contain cached feature flag names. Please double check what flag sets are in use in the Split user interface.'],
|
|
@@ -3,7 +3,6 @@ import { ISettings } from '../types';
|
|
|
3
3
|
import SplitIO from '../../types/splitio';
|
|
4
4
|
import { SDK_SPLITS_ARRIVED, SDK_SPLITS_CACHE_LOADED, SDK_SEGMENTS_ARRIVED, SDK_READY_TIMED_OUT, SDK_READY_FROM_CACHE, SDK_UPDATE, SDK_READY } from './constants';
|
|
5
5
|
import { IReadinessEventEmitter, IReadinessManager, ISegmentsEventEmitter, ISplitsEventEmitter } from './types';
|
|
6
|
-
import { STORAGE_LOCALSTORAGE } from '../utils/constants';
|
|
7
6
|
|
|
8
7
|
function splitsEventEmitterFactory(EventEmitter: new () => SplitIO.IEventEmitter): ISplitsEventEmitter {
|
|
9
8
|
const splitsEventEmitter = objectAssign(new EventEmitter(), {
|
|
@@ -115,10 +114,6 @@ export function readinessManagerFactory(
|
|
|
115
114
|
isReady = true;
|
|
116
115
|
try {
|
|
117
116
|
syncLastUpdate();
|
|
118
|
-
if (!isReadyFromCache && settings.storage?.type === STORAGE_LOCALSTORAGE) {
|
|
119
|
-
isReadyFromCache = true;
|
|
120
|
-
gate.emit(SDK_READY_FROM_CACHE);
|
|
121
|
-
}
|
|
122
117
|
gate.emit(SDK_READY);
|
|
123
118
|
} catch (e) {
|
|
124
119
|
// throws user callback exceptions in next tick
|
package/src/sdkManager/index.ts
CHANGED
|
@@ -17,7 +17,7 @@ function collectTreatments(splitObject: ISplit) {
|
|
|
17
17
|
// Localstorage mode could fall into a no rollout conditions state. Take the first condition in that case.
|
|
18
18
|
if (!allTreatmentsCondition) allTreatmentsCondition = conditions[0];
|
|
19
19
|
// Then extract the treatments from the partitions
|
|
20
|
-
return allTreatmentsCondition ? allTreatmentsCondition.partitions
|
|
20
|
+
return allTreatmentsCondition ? allTreatmentsCondition.partitions!.map(v => v.treatment) : [];
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
function objectToView(splitObject: ISplit | null): SplitIO.SplitView | null {
|
package/src/services/splitApi.ts
CHANGED
|
@@ -53,8 +53,8 @@ export function splitApiFactory(
|
|
|
53
53
|
return splitHttpClient(url, undefined, telemetryTracker.trackHttp(TOKEN));
|
|
54
54
|
},
|
|
55
55
|
|
|
56
|
-
fetchSplitChanges(since: number, noCache?: boolean, till?: number) {
|
|
57
|
-
const url = `${urls.sdk}/splitChanges?s=${flagSpecVersion}&since=${since}${filterQueryString || ''}${till ? '&till=' + till : ''}`;
|
|
56
|
+
fetchSplitChanges(since: number, noCache?: boolean, till?: number, rbSince?: number) {
|
|
57
|
+
const url = `${urls.sdk}/splitChanges?s=${flagSpecVersion}&since=${since}${rbSince ? '&rbSince=' + rbSince : ''}${filterQueryString || ''}${till ? '&till=' + till : ''}`;
|
|
58
58
|
return splitHttpClient(url, noCache ? noCacheHeaderOptions : undefined, telemetryTracker.trackHttp(SPLITS))
|
|
59
59
|
.catch((err) => {
|
|
60
60
|
if (err.statusCode === 414) settings.log.error(ERROR_TOO_MANY_SETS);
|
package/src/services/types.ts
CHANGED
|
@@ -35,7 +35,7 @@ export type ISplitHttpClient = (url: string, options?: IRequestOptions, latencyT
|
|
|
35
35
|
|
|
36
36
|
export type IFetchAuth = (userKeys?: string[]) => Promise<IResponse>
|
|
37
37
|
|
|
38
|
-
export type IFetchSplitChanges = (since: number, noCache?: boolean, till?: number) => Promise<IResponse>
|
|
38
|
+
export type IFetchSplitChanges = (since: number, noCache?: boolean, till?: number, rbSince?: number) => Promise<IResponse>
|
|
39
39
|
|
|
40
40
|
export type IFetchSegmentChanges = (since: number, segmentName: string, noCache?: boolean, till?: number) => Promise<IResponse>
|
|
41
41
|
|
|
@@ -8,12 +8,22 @@ import { objectAssign } from '../utils/lang/objectAssign';
|
|
|
8
8
|
*/
|
|
9
9
|
export abstract class AbstractSplitsCacheAsync implements ISplitsCacheAsync {
|
|
10
10
|
|
|
11
|
-
abstract addSplit(
|
|
12
|
-
abstract
|
|
13
|
-
abstract
|
|
11
|
+
protected abstract addSplit(split: ISplit): Promise<boolean>
|
|
12
|
+
protected abstract removeSplit(name: string): Promise<boolean>
|
|
13
|
+
protected abstract setChangeNumber(changeNumber: number): Promise<boolean | void>
|
|
14
|
+
|
|
15
|
+
update(toAdd: ISplit[], toRemove: ISplit[], changeNumber: number): Promise<boolean> {
|
|
16
|
+
return Promise.all([
|
|
17
|
+
this.setChangeNumber(changeNumber),
|
|
18
|
+
Promise.all(toAdd.map(addedFF => this.addSplit(addedFF))),
|
|
19
|
+
Promise.all(toRemove.map(removedFF => this.removeSplit(removedFF.name)))
|
|
20
|
+
]).then(([, added, removed]) => {
|
|
21
|
+
return added.some(result => result) || removed.some(result => result);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
14
25
|
abstract getSplit(name: string): Promise<ISplit | null>
|
|
15
26
|
abstract getSplits(names: string[]): Promise<Record<string, ISplit | null>>
|
|
16
|
-
abstract setChangeNumber(changeNumber: number): Promise<boolean | void>
|
|
17
27
|
abstract getChangeNumber(): Promise<number>
|
|
18
28
|
abstract getAll(): Promise<ISplit[]>
|
|
19
29
|
abstract getSplitNames(): Promise<string[]>
|
|
@@ -27,6 +37,14 @@ export abstract class AbstractSplitsCacheAsync implements ISplitsCacheAsync {
|
|
|
27
37
|
return Promise.resolve(true);
|
|
28
38
|
}
|
|
29
39
|
|
|
40
|
+
/**
|
|
41
|
+
* Check if the splits information is already stored in cache.
|
|
42
|
+
* Noop, just keeping the interface. This is used by client-side implementations only.
|
|
43
|
+
*/
|
|
44
|
+
checkCache(): Promise<boolean> {
|
|
45
|
+
return Promise.resolve(false);
|
|
46
|
+
}
|
|
47
|
+
|
|
30
48
|
/**
|
|
31
49
|
* Kill `name` split and set `defaultTreatment` and `changeNumber`.
|
|
32
50
|
* Used for SPLIT_KILL push notifications.
|
|
@@ -44,7 +62,7 @@ export abstract class AbstractSplitsCacheAsync implements ISplitsCacheAsync {
|
|
|
44
62
|
newSplit.defaultTreatment = defaultTreatment;
|
|
45
63
|
newSplit.changeNumber = changeNumber;
|
|
46
64
|
|
|
47
|
-
return this.addSplit(
|
|
65
|
+
return this.addSplit(newSplit);
|
|
48
66
|
}
|
|
49
67
|
return false;
|
|
50
68
|
}).catch(() => false);
|