@splitsoftware/splitio-commons 2.1.1-rc.0 → 2.1.1-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGES.txt +3 -0
- package/README.md +0 -1
- package/cjs/evaluator/combiners/and.js +6 -2
- package/cjs/evaluator/combiners/ifelseif.js +6 -6
- package/cjs/evaluator/condition/index.js +5 -6
- package/cjs/evaluator/index.js +7 -7
- package/cjs/evaluator/matchers/index.js +1 -3
- package/cjs/evaluator/matchers/matcherTypes.js +0 -1
- package/cjs/evaluator/matchersTransform/index.js +0 -4
- package/cjs/evaluator/parser/index.js +2 -2
- package/cjs/evaluator/value/sanitize.js +0 -1
- package/cjs/logger/constants.js +3 -4
- package/cjs/logger/messages/debug.js +2 -3
- package/cjs/logger/messages/error.js +1 -1
- package/cjs/logger/messages/warn.js +2 -2
- package/cjs/sdkClient/client.js +29 -19
- package/cjs/sdkClient/clientAttributesDecoration.js +19 -25
- package/cjs/sdkClient/clientInputValidation.js +28 -26
- package/cjs/services/splitApi.js +2 -2
- package/cjs/storages/AbstractSplitsCacheSync.js +2 -5
- package/cjs/storages/KeyBuilder.js +0 -9
- package/cjs/storages/KeyBuilderCS.js +1 -4
- package/cjs/storages/KeyBuilderSS.js +0 -3
- package/cjs/storages/inLocalStorage/SplitsCacheInLocal.js +14 -9
- package/cjs/storages/inLocalStorage/index.js +0 -4
- package/cjs/storages/inMemory/InMemoryStorage.js +0 -3
- package/cjs/storages/inMemory/InMemoryStorageCS.js +0 -4
- package/cjs/storages/inRedis/index.js +0 -2
- package/cjs/storages/pluggable/index.js +0 -2
- package/cjs/storages/utils.js +1 -0
- package/cjs/sync/polling/fetchers/splitChangesFetcher.js +2 -2
- package/cjs/sync/polling/pollingManagerCS.js +7 -7
- 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 +35 -51
- package/cjs/sync/streaming/SSEHandler/index.js +0 -1
- package/cjs/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +77 -106
- package/cjs/sync/streaming/constants.js +1 -2
- package/cjs/sync/streaming/pushManager.js +16 -3
- package/cjs/sync/submitters/impressionsSubmitter.js +3 -2
- package/cjs/sync/syncManagerOnline.js +2 -2
- package/cjs/trackers/strategy/strategyOptimized.js +3 -0
- package/cjs/utils/constants/index.js +2 -3
- package/cjs/utils/inputValidation/eventProperties.js +12 -1
- package/cjs/utils/inputValidation/index.js +3 -1
- package/esm/evaluator/combiners/and.js +6 -2
- package/esm/evaluator/combiners/ifelseif.js +7 -7
- package/esm/evaluator/condition/index.js +5 -6
- package/esm/evaluator/index.js +7 -7
- package/esm/evaluator/matchers/index.js +1 -3
- package/esm/evaluator/matchers/matcherTypes.js +0 -1
- package/esm/evaluator/matchersTransform/index.js +0 -4
- package/esm/evaluator/parser/index.js +2 -2
- package/esm/evaluator/value/sanitize.js +0 -1
- package/esm/logger/constants.js +0 -1
- package/esm/logger/messages/debug.js +2 -3
- package/esm/logger/messages/error.js +1 -1
- package/esm/logger/messages/warn.js +2 -2
- package/esm/sdkClient/client.js +29 -19
- package/esm/sdkClient/clientAttributesDecoration.js +19 -25
- package/esm/sdkClient/clientInputValidation.js +29 -27
- package/esm/services/splitApi.js +2 -2
- package/esm/storages/AbstractSplitsCacheSync.js +2 -5
- package/esm/storages/KeyBuilder.js +0 -9
- package/esm/storages/KeyBuilderCS.js +1 -4
- package/esm/storages/KeyBuilderSS.js +0 -3
- package/esm/storages/inLocalStorage/SplitsCacheInLocal.js +14 -9
- package/esm/storages/inLocalStorage/index.js +0 -4
- package/esm/storages/inMemory/InMemoryStorage.js +0 -3
- package/esm/storages/inMemory/InMemoryStorageCS.js +0 -4
- package/esm/storages/inRedis/index.js +0 -2
- package/esm/storages/pluggable/index.js +0 -2
- package/esm/storages/utils.js +1 -0
- package/esm/sync/polling/fetchers/splitChangesFetcher.js +2 -2
- package/esm/sync/polling/pollingManagerCS.js +7 -7
- 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 +35 -51
- package/esm/sync/streaming/SSEHandler/index.js +1 -2
- package/esm/sync/streaming/UpdateWorkers/SplitsUpdateWorker.js +73 -102
- package/esm/sync/streaming/constants.js +0 -1
- package/esm/sync/streaming/pushManager.js +19 -6
- package/esm/sync/submitters/impressionsSubmitter.js +3 -2
- package/esm/sync/syncManagerOnline.js +2 -2
- package/esm/trackers/strategy/strategyOptimized.js +3 -0
- package/esm/utils/constants/index.js +1 -2
- package/esm/utils/inputValidation/eventProperties.js +10 -0
- package/esm/utils/inputValidation/index.js +1 -0
- package/package.json +1 -1
- package/src/dtos/types.ts +8 -32
- package/src/evaluator/Engine.ts +1 -1
- package/src/evaluator/combiners/and.ts +4 -5
- package/src/evaluator/combiners/ifelseif.ts +9 -7
- 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 +1 -3
- package/src/evaluator/matchers/matcherTypes.ts +0 -1
- package/src/evaluator/matchersTransform/index.ts +0 -3
- 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 +4 -5
- package/src/logger/constants.ts +0 -1
- package/src/logger/messages/debug.ts +2 -3
- package/src/logger/messages/error.ts +1 -1
- package/src/logger/messages/warn.ts +2 -2
- package/src/sdkClient/client.ts +31 -21
- package/src/sdkClient/clientAttributesDecoration.ts +20 -27
- package/src/sdkClient/clientInputValidation.ts +30 -27
- package/src/sdkManager/index.ts +1 -1
- package/src/services/splitApi.ts +2 -2
- package/src/services/types.ts +1 -1
- package/src/storages/AbstractSplitsCacheSync.ts +3 -6
- package/src/storages/KeyBuilder.ts +0 -12
- package/src/storages/KeyBuilderCS.ts +1 -5
- package/src/storages/KeyBuilderSS.ts +0 -4
- package/src/storages/inLocalStorage/SplitsCacheInLocal.ts +14 -10
- package/src/storages/inLocalStorage/index.ts +0 -4
- package/src/storages/inMemory/InMemoryStorage.ts +0 -3
- package/src/storages/inMemory/InMemoryStorageCS.ts +0 -4
- package/src/storages/inRedis/index.ts +0 -2
- package/src/storages/pluggable/index.ts +0 -2
- package/src/storages/types.ts +1 -33
- package/src/storages/utils.ts +1 -0
- package/src/sync/polling/fetchers/splitChangesFetcher.ts +1 -2
- package/src/sync/polling/fetchers/types.ts +0 -1
- package/src/sync/polling/pollingManagerCS.ts +7 -7
- 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 +44 -61
- package/src/sync/streaming/SSEHandler/index.ts +1 -2
- package/src/sync/streaming/SSEHandler/types.ts +2 -2
- package/src/sync/streaming/UpdateWorkers/SplitsUpdateWorker.ts +68 -98
- package/src/sync/streaming/constants.ts +0 -1
- package/src/sync/streaming/parseUtils.ts +2 -2
- package/src/sync/streaming/pushManager.ts +18 -6
- package/src/sync/streaming/types.ts +2 -3
- package/src/sync/submitters/impressionsSubmitter.ts +3 -2
- package/src/sync/submitters/types.ts +23 -33
- package/src/sync/syncManagerOnline.ts +2 -2
- package/src/trackers/strategy/strategyOptimized.ts +3 -0
- package/src/utils/constants/index.ts +1 -2
- package/src/utils/inputValidation/eventProperties.ts +10 -0
- package/src/utils/inputValidation/index.ts +1 -0
- package/src/utils/lang/index.ts +1 -1
- package/types/splitio.d.ts +100 -35
- package/cjs/evaluator/matchers/rbsegment.js +0 -43
- package/cjs/storages/inLocalStorage/RBSegmentsCacheInLocal.js +0 -117
- package/cjs/storages/inMemory/RBSegmentsCacheInMemory.js +0 -61
- package/cjs/storages/inRedis/RBSegmentsCacheInRedis.js +0 -64
- package/cjs/storages/pluggable/RBSegmentsCachePluggable.js +0 -64
- package/esm/evaluator/matchers/rbsegment.js +0 -39
- package/esm/storages/inLocalStorage/RBSegmentsCacheInLocal.js +0 -114
- package/esm/storages/inMemory/RBSegmentsCacheInMemory.js +0 -58
- package/esm/storages/inRedis/RBSegmentsCacheInRedis.js +0 -61
- package/esm/storages/pluggable/RBSegmentsCachePluggable.js +0 -61
- package/src/evaluator/matchers/rbsegment.ts +0 -61
- package/src/storages/inLocalStorage/RBSegmentsCacheInLocal.ts +0 -136
- package/src/storages/inMemory/RBSegmentsCacheInMemory.ts +0 -68
- package/src/storages/inRedis/RBSegmentsCacheInRedis.ts +0 -79
- package/src/storages/pluggable/RBSegmentsCachePluggable.ts +0 -76
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { findIndex
|
|
1
|
+
import { findIndex } 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,12 +18,14 @@ export function ifElseIfCombinerContext(log: ILogger, predicates: IEvaluator[]):
|
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
function
|
|
22
|
-
|
|
21
|
+
function computeTreatment(predicateResults: Array<IEvaluation | undefined>) {
|
|
22
|
+
const len = predicateResults.length;
|
|
23
|
+
|
|
24
|
+
for (let i = 0; i < len; i++) {
|
|
23
25
|
const evaluation = predicateResults[i];
|
|
24
26
|
|
|
25
27
|
if (evaluation !== undefined) {
|
|
26
|
-
|
|
28
|
+
log.debug(ENGINE_COMBINER_IFELSEIF, [evaluation.treatment]);
|
|
27
29
|
|
|
28
30
|
return evaluation;
|
|
29
31
|
}
|
|
@@ -33,7 +35,7 @@ export function ifElseIfCombinerContext(log: ILogger, predicates: IEvaluator[]):
|
|
|
33
35
|
return undefined;
|
|
34
36
|
}
|
|
35
37
|
|
|
36
|
-
function ifElseIfCombiner(key: SplitIO.
|
|
38
|
+
function ifElseIfCombiner(key: SplitIO.SplitKey, seed: number, trafficAllocation?: number, trafficAllocationSeed?: number, attributes?: SplitIO.Attributes, splitEvaluator?: ISplitEvaluator) {
|
|
37
39
|
// In Async environments we are going to have async predicates. There is none way to know
|
|
38
40
|
// before hand so we need to evaluate all the predicates, verify for thenables, and finally,
|
|
39
41
|
// define how to return the treatment (wrap result into a Promise or not).
|
|
@@ -41,10 +43,10 @@ export function ifElseIfCombinerContext(log: ILogger, predicates: IEvaluator[]):
|
|
|
41
43
|
|
|
42
44
|
// if we find a thenable
|
|
43
45
|
if (findIndex(predicateResults, thenable) !== -1) {
|
|
44
|
-
return Promise.all(predicateResults).then(results =>
|
|
46
|
+
return Promise.all(predicateResults).then(results => computeTreatment(results));
|
|
45
47
|
}
|
|
46
48
|
|
|
47
|
-
return
|
|
49
|
+
return computeTreatment(predicateResults as IEvaluation[]);
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
// 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
|
|
8
|
+
export function getTreatment(log: ILogger, key: string, seed: number, 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 | undefined {
|
|
11
11
|
if (matchingResult) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
const treatment = getTreatment(log, bucketingKey as string, seed, treatments);
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
treatment,
|
|
16
|
+
label
|
|
17
|
+
};
|
|
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: (...args: any) => 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.SplitKey, 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 as number, (key as SplitIO.SplitKeyObject).bucketingKey as string, trafficAllocationSeed as number)) {
|
|
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: (key: SplitIO.S
|
|
|
41
41
|
const matches = matcherEvaluator(key, attributes, splitEvaluator);
|
|
42
42
|
|
|
43
43
|
if (thenable(matches)) {
|
|
44
|
-
return matches.then(result => match(log, result, key.bucketingKey, seed, treatments, label));
|
|
44
|
+
return matches.then(result => match(log, result, (key as SplitIO.SplitKeyObject).bucketingKey, seed, treatments, label));
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
return match(log, matches, key.bucketingKey, seed, treatments, label);
|
|
47
|
+
return match(log, matches, (key as SplitIO.SplitKeyObject).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
|
-
key,
|
|
47
46
|
split,
|
|
47
|
+
key,
|
|
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
|
-
key,
|
|
60
59
|
parsedSplit,
|
|
60
|
+
key,
|
|
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,
|
|
83
|
+
parsedSplits.then(splits => getEvaluations(log, splitNames, splits, key, 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,
|
|
89
|
+
getEvaluations(log, splitNames, parsedSplits, key, 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
|
-
key: SplitIO.SplitKey,
|
|
140
139
|
splitJSON: ISplit | null,
|
|
140
|
+
key: SplitIO.SplitKey,
|
|
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,
|
|
176
175
|
splitNames: string[],
|
|
177
176
|
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
|
-
key,
|
|
187
186
|
splits[splitName],
|
|
187
|
+
key,
|
|
188
188
|
attributes,
|
|
189
189
|
storage
|
|
190
190
|
);
|
|
@@ -24,7 +24,6 @@ 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';
|
|
28
27
|
|
|
29
28
|
const matchers = [
|
|
30
29
|
undefined, // UNDEFINED: 0
|
|
@@ -51,7 +50,6 @@ const matchers = [
|
|
|
51
50
|
betweenSemverMatcherContext, // BETWEEN_SEMVER: 21
|
|
52
51
|
inListSemverMatcherContext, // IN_LIST_SEMVER: 22
|
|
53
52
|
largeSegmentMatcherContext, // IN_LARGE_SEGMENT: 23
|
|
54
|
-
ruleBasedSegmentMatcherContext // IN_RULE_BASED_SEGMENT: 24
|
|
55
53
|
];
|
|
56
54
|
|
|
57
55
|
/**
|
|
@@ -66,5 +64,5 @@ export function matcherFactory(log: ILogger, matcherDto: IMatcherDto, storage?:
|
|
|
66
64
|
let matcherFn;
|
|
67
65
|
// @ts-ignore
|
|
68
66
|
if (matchers[type]) matcherFn = matchers[type](value, storage, log); // There is no index-out-of-bound exception in JavaScript
|
|
69
|
-
return matcherFn
|
|
67
|
+
return matcherFn;
|
|
70
68
|
}
|
|
@@ -95,9 +95,6 @@ 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;
|
|
101
98
|
}
|
|
102
99
|
|
|
103
100
|
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: string, attributes: SplitIO.Attributes | undefined, 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
|
-
|
|
74
|
+
Treatments.parse(partitions),
|
|
75
75
|
label,
|
|
76
76
|
conditionType
|
|
77
77
|
));
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
//
|
|
80
|
+
// Instanciate 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.SplitKey, seed: number, trafficAllocation?: number, trafficAllocationSeed?: number, attributes?: SplitIO.Attributes, splitEvaluator?: ISplitEvaluator) => MaybeThenable<IEvaluation | undefined>
|
|
33
33
|
|
|
34
|
-
export type IMatcher = (
|
|
34
|
+
export type IMatcher = (...args: any) => 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: string, 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: SplitIO.SplitKey, attributeName: string |
|
|
|
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: string, 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: string, attributes?: SplitIO.Attributes): IDependencyMatcherValue {
|
|
45
45
|
return {
|
|
46
46
|
key: sanitizedValue,
|
|
47
47
|
attributes
|
|
@@ -60,7 +60,6 @@ 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:
|
|
64
63
|
return dependencyProcessor;
|
|
65
64
|
default:
|
|
66
65
|
return undefined;
|
|
@@ -70,9 +69,9 @@ function getProcessingFunction(matcherTypeID: number, dataType: string) {
|
|
|
70
69
|
/**
|
|
71
70
|
* Sanitize matcher value
|
|
72
71
|
*/
|
|
73
|
-
export function sanitize(log: ILogger, matcherTypeID: number, value: string | number | boolean | Array<string | number> |
|
|
72
|
+
export function sanitize(log: ILogger, matcherTypeID: number, value: string | number | boolean | Array<string | number> | undefined, dataType: string, attributes?: SplitIO.Attributes) {
|
|
74
73
|
const processor = getProcessingFunction(matcherTypeID, dataType);
|
|
75
|
-
let sanitizedValue: string | number | boolean | Array<string> | IDependencyMatcherValue | undefined;
|
|
74
|
+
let sanitizedValue: string | number | boolean | Array<string | number> | IDependencyMatcherValue | undefined;
|
|
76
75
|
|
|
77
76
|
switch (dataType) {
|
|
78
77
|
case matcherDataTypes.NUMBER:
|
|
@@ -89,7 +88,7 @@ export function sanitize(log: ILogger, matcherTypeID: number, value: string | nu
|
|
|
89
88
|
sanitizedValue = sanitizeBoolean(value);
|
|
90
89
|
break;
|
|
91
90
|
case matcherDataTypes.NOT_SPECIFIED:
|
|
92
|
-
sanitizedValue = value
|
|
91
|
+
sanitizedValue = value;
|
|
93
92
|
break;
|
|
94
93
|
default:
|
|
95
94
|
sanitizedValue = undefined;
|
package/src/logger/constants.ts
CHANGED
|
@@ -21,7 +21,6 @@ export const RETRIEVE_MANAGER = 29;
|
|
|
21
21
|
export const SYNC_OFFLINE_DATA = 30;
|
|
22
22
|
export const SYNC_SPLITS_FETCH = 31;
|
|
23
23
|
export const SYNC_SPLITS_UPDATE = 32;
|
|
24
|
-
export const SYNC_RBS_UPDATE = 33;
|
|
25
24
|
export const STREAMING_NEW_MESSAGE = 35;
|
|
26
25
|
export const SYNC_TASK_START = 36;
|
|
27
26
|
export const SYNC_TASK_EXECUTE = 37;
|
|
@@ -20,9 +20,8 @@ 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.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.'],
|
|
23
|
+
[c.SYNC_SPLITS_FETCH, c.LOG_PREFIX_SYNC_SPLITS + 'Spin up feature flags update using since = %s'],
|
|
24
|
+
[c.SYNC_SPLITS_UPDATE, c.LOG_PREFIX_SYNC_SPLITS + 'New feature flags %s. Removed feature flags %s. Segment names collected %s'],
|
|
26
25
|
[c.STREAMING_NEW_MESSAGE, c.LOG_PREFIX_SYNC_STREAMING + 'New SSE message received, with data: %s.'],
|
|
27
26
|
[c.SYNC_TASK_START, c.LOG_PREFIX_SYNC + ': Starting %s. Running each %s millis'],
|
|
28
27
|
[c.SYNC_TASK_EXECUTE, c.LOG_PREFIX_SYNC + ': Running %s'],
|
|
@@ -21,7 +21,7 @@ export const codesError: [number, string][] = [
|
|
|
21
21
|
// input validation
|
|
22
22
|
[c.ERROR_EVENT_TYPE_FORMAT, '%s: you passed "%s", event_type must adhere to the regular expression /^[a-zA-Z0-9][-_.:a-zA-Z0-9]{0,79}$/g. This means an event_type must be alphanumeric, cannot be more than 80 characters long, and can only include a dash, underscore, period, or colon as separators of alphanumeric characters.'],
|
|
23
23
|
[c.ERROR_NOT_PLAIN_OBJECT, '%s: %s must be a plain object.'],
|
|
24
|
-
[c.ERROR_SIZE_EXCEEDED, '%s: the maximum size allowed for the properties is 32768 bytes, which was exceeded.
|
|
24
|
+
[c.ERROR_SIZE_EXCEEDED, '%s: the maximum size allowed for the properties is 32768 bytes, which was exceeded.'],
|
|
25
25
|
[c.ERROR_NOT_FINITE, '%s: value must be a finite number.'],
|
|
26
26
|
[c.ERROR_NULL, '%s: you passed a null or undefined %s. It must be a non-empty string.'],
|
|
27
27
|
[c.ERROR_TOO_LONG, '%s: %s too long. It must have 250 characters or less.'],
|
|
@@ -18,7 +18,7 @@ export const codesWarn: [number, string][] = codesError.concat([
|
|
|
18
18
|
[c.CLIENT_NO_LISTENER, 'No listeners for SDK Readiness detected. Incorrect control treatments could have been logged if you called getTreatment/s while the SDK was not yet ready.'],
|
|
19
19
|
// input validation
|
|
20
20
|
[c.WARN_SETTING_NULL, '%s: Property "%s" is of invalid type. Setting value to null.'],
|
|
21
|
-
[c.WARN_TRIMMING_PROPERTIES, '%s:
|
|
21
|
+
[c.WARN_TRIMMING_PROPERTIES, '%s: more than 300 properties were provided. Some of them will be trimmed when processed.'],
|
|
22
22
|
[c.WARN_CONVERTING, '%s: %s "%s" is not of type string, converting.'],
|
|
23
23
|
[c.WARN_TRIMMING, '%s: %s "%s" has extra whitespace, trimming.'],
|
|
24
24
|
[c.WARN_NOT_EXISTENT_SPLIT, '%s: feature flag "%s" does not exist in this environment. Please double check what feature flags exist in the Split user interface.'],
|
|
@@ -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 SPLIT_UPDATE 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.'],
|
package/src/sdkClient/client.ts
CHANGED
|
@@ -23,6 +23,14 @@ function treatmentsNotReady(featureFlagNames: string[]) {
|
|
|
23
23
|
return evaluations;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
function stringify(options?: SplitIO.EvaluationOptions) {
|
|
27
|
+
if (options && options.properties) {
|
|
28
|
+
try {
|
|
29
|
+
return JSON.stringify(options.properties);
|
|
30
|
+
} catch { /* JSON.stringify should never throw with validated options, but handling just in case */ }
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
26
34
|
/**
|
|
27
35
|
* Creator of base client with getTreatments and track methods.
|
|
28
36
|
*/
|
|
@@ -31,12 +39,12 @@ export function clientFactory(params: ISdkFactoryContext): SplitIO.IClient | Spl
|
|
|
31
39
|
const { log, mode } = settings;
|
|
32
40
|
const isAsync = isConsumerMode(mode);
|
|
33
41
|
|
|
34
|
-
function getTreatment(key: SplitIO.SplitKey, featureFlagName: string, attributes
|
|
42
|
+
function getTreatment(key: SplitIO.SplitKey, featureFlagName: string, attributes?: SplitIO.Attributes, options?: SplitIO.EvaluationOptions, withConfig = false, methodName = GET_TREATMENT) {
|
|
35
43
|
const stopTelemetryTracker = telemetryTracker.trackEval(withConfig ? TREATMENT_WITH_CONFIG : TREATMENT);
|
|
36
44
|
|
|
37
45
|
const wrapUp = (evaluationResult: IEvaluationResult) => {
|
|
38
46
|
const queue: ImpressionDecorated[] = [];
|
|
39
|
-
const treatment = processEvaluation(evaluationResult, featureFlagName, key,
|
|
47
|
+
const treatment = processEvaluation(evaluationResult, featureFlagName, key, stringify(options), withConfig, methodName, queue);
|
|
40
48
|
impressionsTracker.track(queue, attributes);
|
|
41
49
|
|
|
42
50
|
stopTelemetryTracker(queue[0] && queue[0].imp.label);
|
|
@@ -52,18 +60,19 @@ export function clientFactory(params: ISdkFactoryContext): SplitIO.IClient | Spl
|
|
|
52
60
|
return thenable(evaluation) ? evaluation.then((res) => wrapUp(res)) : wrapUp(evaluation);
|
|
53
61
|
}
|
|
54
62
|
|
|
55
|
-
function getTreatmentWithConfig(key: SplitIO.SplitKey, featureFlagName: string, attributes
|
|
56
|
-
return getTreatment(key, featureFlagName, attributes, true, GET_TREATMENT_WITH_CONFIG);
|
|
63
|
+
function getTreatmentWithConfig(key: SplitIO.SplitKey, featureFlagName: string, attributes?: SplitIO.Attributes, options?: SplitIO.EvaluationOptions) {
|
|
64
|
+
return getTreatment(key, featureFlagName, attributes, options, true, GET_TREATMENT_WITH_CONFIG);
|
|
57
65
|
}
|
|
58
66
|
|
|
59
|
-
function getTreatments(key: SplitIO.SplitKey, featureFlagNames: string[], attributes
|
|
67
|
+
function getTreatments(key: SplitIO.SplitKey, featureFlagNames: string[], attributes?: SplitIO.Attributes, options?: SplitIO.EvaluationOptions, withConfig = false, methodName = GET_TREATMENTS) {
|
|
60
68
|
const stopTelemetryTracker = telemetryTracker.trackEval(withConfig ? TREATMENTS_WITH_CONFIG : TREATMENTS);
|
|
61
69
|
|
|
62
70
|
const wrapUp = (evaluationResults: Record<string, IEvaluationResult>) => {
|
|
63
71
|
const queue: ImpressionDecorated[] = [];
|
|
64
|
-
const treatments:
|
|
72
|
+
const treatments: SplitIO.Treatments | SplitIO.TreatmentsWithConfig = {};
|
|
73
|
+
const properties = stringify(options);
|
|
65
74
|
Object.keys(evaluationResults).forEach(featureFlagName => {
|
|
66
|
-
treatments[featureFlagName] = processEvaluation(evaluationResults[featureFlagName], featureFlagName, key,
|
|
75
|
+
treatments[featureFlagName] = processEvaluation(evaluationResults[featureFlagName], featureFlagName, key, properties, withConfig, methodName, queue);
|
|
67
76
|
});
|
|
68
77
|
impressionsTracker.track(queue, attributes);
|
|
69
78
|
|
|
@@ -80,19 +89,19 @@ export function clientFactory(params: ISdkFactoryContext): SplitIO.IClient | Spl
|
|
|
80
89
|
return thenable(evaluations) ? evaluations.then((res) => wrapUp(res)) : wrapUp(evaluations);
|
|
81
90
|
}
|
|
82
91
|
|
|
83
|
-
function getTreatmentsWithConfig(key: SplitIO.SplitKey, featureFlagNames: string[], attributes
|
|
84
|
-
return getTreatments(key, featureFlagNames, attributes, true, GET_TREATMENTS_WITH_CONFIG);
|
|
92
|
+
function getTreatmentsWithConfig(key: SplitIO.SplitKey, featureFlagNames: string[], attributes?: SplitIO.Attributes, options?: SplitIO.EvaluationOptions) {
|
|
93
|
+
return getTreatments(key, featureFlagNames, attributes, options, true, GET_TREATMENTS_WITH_CONFIG);
|
|
85
94
|
}
|
|
86
95
|
|
|
87
|
-
function getTreatmentsByFlagSets(key: SplitIO.SplitKey, flagSetNames: string[], attributes
|
|
96
|
+
function getTreatmentsByFlagSets(key: SplitIO.SplitKey, flagSetNames: string[], attributes?: SplitIO.Attributes, options?: SplitIO.EvaluationOptions, withConfig = false, method: Method = TREATMENTS_BY_FLAGSETS, methodName = GET_TREATMENTS_BY_FLAG_SETS) {
|
|
88
97
|
const stopTelemetryTracker = telemetryTracker.trackEval(method);
|
|
89
98
|
|
|
90
99
|
const wrapUp = (evaluationResults: Record<string, IEvaluationResult>) => {
|
|
91
100
|
const queue: ImpressionDecorated[] = [];
|
|
92
|
-
const treatments:
|
|
93
|
-
const
|
|
94
|
-
Object.keys(
|
|
95
|
-
treatments[featureFlagName] = processEvaluation(
|
|
101
|
+
const treatments: SplitIO.Treatments | SplitIO.TreatmentsWithConfig = {};
|
|
102
|
+
const properties = stringify(options);
|
|
103
|
+
Object.keys(evaluationResults).forEach(featureFlagName => {
|
|
104
|
+
treatments[featureFlagName] = processEvaluation(evaluationResults[featureFlagName], featureFlagName, key, properties, withConfig, methodName, queue);
|
|
96
105
|
});
|
|
97
106
|
impressionsTracker.track(queue, attributes);
|
|
98
107
|
|
|
@@ -109,16 +118,16 @@ export function clientFactory(params: ISdkFactoryContext): SplitIO.IClient | Spl
|
|
|
109
118
|
return thenable(evaluations) ? evaluations.then((res) => wrapUp(res)) : wrapUp(evaluations);
|
|
110
119
|
}
|
|
111
120
|
|
|
112
|
-
function getTreatmentsWithConfigByFlagSets(key: SplitIO.SplitKey, flagSetNames: string[], attributes
|
|
113
|
-
return getTreatmentsByFlagSets(key, flagSetNames, attributes, true, TREATMENTS_WITH_CONFIG_BY_FLAGSETS, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS);
|
|
121
|
+
function getTreatmentsWithConfigByFlagSets(key: SplitIO.SplitKey, flagSetNames: string[], attributes?: SplitIO.Attributes, options?: SplitIO.EvaluationOptions) {
|
|
122
|
+
return getTreatmentsByFlagSets(key, flagSetNames, attributes, options, true, TREATMENTS_WITH_CONFIG_BY_FLAGSETS, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS);
|
|
114
123
|
}
|
|
115
124
|
|
|
116
|
-
function getTreatmentsByFlagSet(key: SplitIO.SplitKey, flagSetName: string, attributes
|
|
117
|
-
return getTreatmentsByFlagSets(key, [flagSetName], attributes, false, TREATMENTS_BY_FLAGSET, GET_TREATMENTS_BY_FLAG_SET);
|
|
125
|
+
function getTreatmentsByFlagSet(key: SplitIO.SplitKey, flagSetName: string, attributes?: SplitIO.Attributes, options?: SplitIO.EvaluationOptions) {
|
|
126
|
+
return getTreatmentsByFlagSets(key, [flagSetName], attributes, options, false, TREATMENTS_BY_FLAGSET, GET_TREATMENTS_BY_FLAG_SET);
|
|
118
127
|
}
|
|
119
128
|
|
|
120
|
-
function getTreatmentsWithConfigByFlagSet(key: SplitIO.SplitKey, flagSetName: string, attributes
|
|
121
|
-
return getTreatmentsByFlagSets(key, [flagSetName], attributes, true, TREATMENTS_WITH_CONFIG_BY_FLAGSET, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET);
|
|
129
|
+
function getTreatmentsWithConfigByFlagSet(key: SplitIO.SplitKey, flagSetName: string, attributes?: SplitIO.Attributes, options?: SplitIO.EvaluationOptions) {
|
|
130
|
+
return getTreatmentsByFlagSets(key, [flagSetName], attributes, options, true, TREATMENTS_WITH_CONFIG_BY_FLAGSET, GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET);
|
|
122
131
|
}
|
|
123
132
|
|
|
124
133
|
// Internal function
|
|
@@ -126,7 +135,7 @@ export function clientFactory(params: ISdkFactoryContext): SplitIO.IClient | Spl
|
|
|
126
135
|
evaluation: IEvaluationResult,
|
|
127
136
|
featureFlagName: string,
|
|
128
137
|
key: SplitIO.SplitKey,
|
|
129
|
-
|
|
138
|
+
properties: string | undefined,
|
|
130
139
|
withConfig: boolean,
|
|
131
140
|
invokingMethodName: string,
|
|
132
141
|
queue: ImpressionDecorated[]
|
|
@@ -148,6 +157,7 @@ export function clientFactory(params: ISdkFactoryContext): SplitIO.IClient | Spl
|
|
|
148
157
|
bucketingKey,
|
|
149
158
|
label,
|
|
150
159
|
changeNumber: changeNumber as number,
|
|
160
|
+
properties
|
|
151
161
|
},
|
|
152
162
|
disabled: impressionsDisabled
|
|
153
163
|
});
|
|
@@ -20,50 +20,44 @@ export function clientAttributesDecoration<TClient extends SplitIO.IClient | Spl
|
|
|
20
20
|
const clientGetTreatmentsWithConfigByFlagSets = client.getTreatmentsWithConfigByFlagSets;
|
|
21
21
|
const clientGetTreatmentsByFlagSet = client.getTreatmentsByFlagSet;
|
|
22
22
|
const clientGetTreatmentsWithConfigByFlagSet = client.getTreatmentsWithConfigByFlagSet;
|
|
23
|
-
const clientTrack = client.track;
|
|
24
23
|
|
|
25
|
-
function getTreatment(maybeKey: SplitIO.SplitKey, maybeFeatureFlagName: string, maybeAttributes?: SplitIO.Attributes) {
|
|
26
|
-
return clientGetTreatment(maybeKey, maybeFeatureFlagName, combineAttributes(maybeAttributes));
|
|
24
|
+
function getTreatment(maybeKey: SplitIO.SplitKey, maybeFeatureFlagName: string, maybeAttributes?: SplitIO.Attributes, maybeOptions?: SplitIO.EvaluationOptions) {
|
|
25
|
+
return clientGetTreatment(maybeKey, maybeFeatureFlagName, combineAttributes(maybeAttributes), maybeOptions);
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
function getTreatmentWithConfig(maybeKey: SplitIO.SplitKey, maybeFeatureFlagName: string, maybeAttributes?: SplitIO.Attributes) {
|
|
30
|
-
return clientGetTreatmentWithConfig(maybeKey, maybeFeatureFlagName, combineAttributes(maybeAttributes));
|
|
28
|
+
function getTreatmentWithConfig(maybeKey: SplitIO.SplitKey, maybeFeatureFlagName: string, maybeAttributes?: SplitIO.Attributes, maybeOptions?: SplitIO.EvaluationOptions) {
|
|
29
|
+
return clientGetTreatmentWithConfig(maybeKey, maybeFeatureFlagName, combineAttributes(maybeAttributes), maybeOptions);
|
|
31
30
|
}
|
|
32
31
|
|
|
33
|
-
function getTreatments(maybeKey: SplitIO.SplitKey, maybeFeatureFlagNames: string[], maybeAttributes?: SplitIO.Attributes) {
|
|
34
|
-
return clientGetTreatments(maybeKey, maybeFeatureFlagNames, combineAttributes(maybeAttributes));
|
|
32
|
+
function getTreatments(maybeKey: SplitIO.SplitKey, maybeFeatureFlagNames: string[], maybeAttributes?: SplitIO.Attributes, maybeOptions?: SplitIO.EvaluationOptions) {
|
|
33
|
+
return clientGetTreatments(maybeKey, maybeFeatureFlagNames, combineAttributes(maybeAttributes), maybeOptions);
|
|
35
34
|
}
|
|
36
35
|
|
|
37
|
-
function getTreatmentsWithConfig(maybeKey: SplitIO.SplitKey, maybeFeatureFlagNames: string[], maybeAttributes?: SplitIO.Attributes) {
|
|
38
|
-
return clientGetTreatmentsWithConfig(maybeKey, maybeFeatureFlagNames, combineAttributes(maybeAttributes));
|
|
36
|
+
function getTreatmentsWithConfig(maybeKey: SplitIO.SplitKey, maybeFeatureFlagNames: string[], maybeAttributes?: SplitIO.Attributes, maybeOptions?: SplitIO.EvaluationOptions) {
|
|
37
|
+
return clientGetTreatmentsWithConfig(maybeKey, maybeFeatureFlagNames, combineAttributes(maybeAttributes), maybeOptions);
|
|
39
38
|
}
|
|
40
39
|
|
|
41
|
-
function getTreatmentsByFlagSets(maybeKey: SplitIO.SplitKey, maybeFlagSets: string[], maybeAttributes?: SplitIO.Attributes) {
|
|
42
|
-
return clientGetTreatmentsByFlagSets(maybeKey, maybeFlagSets, combineAttributes(maybeAttributes));
|
|
40
|
+
function getTreatmentsByFlagSets(maybeKey: SplitIO.SplitKey, maybeFlagSets: string[], maybeAttributes?: SplitIO.Attributes, maybeOptions?: SplitIO.EvaluationOptions) {
|
|
41
|
+
return clientGetTreatmentsByFlagSets(maybeKey, maybeFlagSets, combineAttributes(maybeAttributes), maybeOptions);
|
|
43
42
|
}
|
|
44
43
|
|
|
45
|
-
function getTreatmentsWithConfigByFlagSets(maybeKey: SplitIO.SplitKey, maybeFlagSets: string[], maybeAttributes?: SplitIO.Attributes) {
|
|
46
|
-
return clientGetTreatmentsWithConfigByFlagSets(maybeKey, maybeFlagSets, combineAttributes(maybeAttributes));
|
|
44
|
+
function getTreatmentsWithConfigByFlagSets(maybeKey: SplitIO.SplitKey, maybeFlagSets: string[], maybeAttributes?: SplitIO.Attributes, maybeOptions?: SplitIO.EvaluationOptions) {
|
|
45
|
+
return clientGetTreatmentsWithConfigByFlagSets(maybeKey, maybeFlagSets, combineAttributes(maybeAttributes), maybeOptions);
|
|
47
46
|
}
|
|
48
47
|
|
|
49
|
-
function getTreatmentsByFlagSet(maybeKey: SplitIO.SplitKey, maybeFlagSet: string, maybeAttributes?: SplitIO.Attributes) {
|
|
50
|
-
return clientGetTreatmentsByFlagSet(maybeKey, maybeFlagSet, combineAttributes(maybeAttributes));
|
|
48
|
+
function getTreatmentsByFlagSet(maybeKey: SplitIO.SplitKey, maybeFlagSet: string, maybeAttributes?: SplitIO.Attributes, maybeOptions?: SplitIO.EvaluationOptions) {
|
|
49
|
+
return clientGetTreatmentsByFlagSet(maybeKey, maybeFlagSet, combineAttributes(maybeAttributes), maybeOptions);
|
|
51
50
|
}
|
|
52
51
|
|
|
53
|
-
function getTreatmentsWithConfigByFlagSet(maybeKey: SplitIO.SplitKey, maybeFlagSet: string, maybeAttributes?: SplitIO.Attributes) {
|
|
54
|
-
return clientGetTreatmentsWithConfigByFlagSet(maybeKey, maybeFlagSet, combineAttributes(maybeAttributes));
|
|
52
|
+
function getTreatmentsWithConfigByFlagSet(maybeKey: SplitIO.SplitKey, maybeFlagSet: string, maybeAttributes?: SplitIO.Attributes, maybeOptions?: SplitIO.EvaluationOptions) {
|
|
53
|
+
return clientGetTreatmentsWithConfigByFlagSet(maybeKey, maybeFlagSet, combineAttributes(maybeAttributes), maybeOptions);
|
|
55
54
|
}
|
|
56
55
|
|
|
57
|
-
function
|
|
58
|
-
return clientTrack(maybeKey, maybeTT, maybeEvent, maybeEventValue, maybeProperties);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function combineAttributes(maybeAttributes: SplitIO.Attributes | undefined): SplitIO.Attributes | undefined{
|
|
56
|
+
function combineAttributes(maybeAttributes: SplitIO.Attributes | undefined): SplitIO.Attributes | undefined {
|
|
62
57
|
const storedAttributes = attributeStorage.getAll();
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return maybeAttributes;
|
|
58
|
+
return Object.keys(storedAttributes).length > 0 ?
|
|
59
|
+
objectAssign({}, storedAttributes, maybeAttributes) :
|
|
60
|
+
maybeAttributes;
|
|
67
61
|
}
|
|
68
62
|
|
|
69
63
|
return objectAssign(client, {
|
|
@@ -75,7 +69,6 @@ export function clientAttributesDecoration<TClient extends SplitIO.IClient | Spl
|
|
|
75
69
|
getTreatmentsWithConfigByFlagSets: getTreatmentsWithConfigByFlagSets,
|
|
76
70
|
getTreatmentsByFlagSet: getTreatmentsByFlagSet,
|
|
77
71
|
getTreatmentsWithConfigByFlagSet: getTreatmentsWithConfigByFlagSet,
|
|
78
|
-
track: track,
|
|
79
72
|
|
|
80
73
|
/**
|
|
81
74
|
* Add an attribute to client's in memory attributes storage
|