Skip to content

Commit f4df1c9

Browse files
feat: add impressionsDisabled option to feature evaluation
1 parent 3b99e8a commit f4df1c9

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

src/evaluator/index.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export function evaluateFeature(
3030
splitName: string,
3131
attributes: SplitIO.Attributes | undefined,
3232
storage: IStorageSync | IStorageAsync,
33+
options?: SplitIO.EvaluationOptions
3334
): MaybeThenable<IEvaluationResult> {
3435
let parsedSplit;
3536

@@ -47,6 +48,7 @@ export function evaluateFeature(
4748
split,
4849
attributes,
4950
storage,
51+
options,
5052
)).catch(
5153
// Exception on async `getSplit` storage. For example, when the storage is redis or
5254
// pluggable and there is a connection issue and we can't retrieve the split to be evaluated
@@ -60,6 +62,7 @@ export function evaluateFeature(
6062
parsedSplit,
6163
attributes,
6264
storage,
65+
options,
6366
);
6467
}
6568

@@ -69,6 +72,7 @@ export function evaluateFeatures(
6972
splitNames: string[],
7073
attributes: SplitIO.Attributes | undefined,
7174
storage: IStorageSync | IStorageAsync,
75+
options?: SplitIO.EvaluationOptions,
7276
): MaybeThenable<Record<string, IEvaluationResult>> {
7377
let parsedSplits;
7478

@@ -80,13 +84,13 @@ export function evaluateFeatures(
8084
}
8185

8286
return thenable(parsedSplits) ?
83-
parsedSplits.then(splits => getEvaluations(log, key, splitNames, splits, attributes, storage))
87+
parsedSplits.then(splits => getEvaluations(log, key, splitNames, splits, attributes, storage, options))
8488
.catch(() => {
8589
// Exception on async `getSplits` storage. For example, when the storage is redis or
8690
// pluggable and there is a connection issue and we can't retrieve the split to be evaluated
8791
return treatmentsException(splitNames);
8892
}) :
89-
getEvaluations(log, key, splitNames, parsedSplits, attributes, storage);
93+
getEvaluations(log, key, splitNames, parsedSplits, attributes, storage, options);
9094
}
9195

9296
export function evaluateFeaturesByFlagSets(
@@ -96,6 +100,7 @@ export function evaluateFeaturesByFlagSets(
96100
attributes: SplitIO.Attributes | undefined,
97101
storage: IStorageSync | IStorageAsync,
98102
method: string,
103+
options?: SplitIO.EvaluationOptions,
99104
): MaybeThenable<Record<string, IEvaluationResult>> {
100105
let storedFlagNames: MaybeThenable<Set<string>[]>;
101106

@@ -111,7 +116,7 @@ export function evaluateFeaturesByFlagSets(
111116
}
112117

113118
return featureFlags.size ?
114-
evaluateFeatures(log, key, setToArray(featureFlags), attributes, storage) :
119+
evaluateFeatures(log, key, setToArray(featureFlags), attributes, storage, options) :
115120
{};
116121
}
117122

@@ -138,6 +143,7 @@ function getEvaluation(
138143
splitJSON: ISplit | null,
139144
attributes: SplitIO.Attributes | undefined,
140145
storage: IStorageSync | IStorageAsync,
146+
options?: SplitIO.EvaluationOptions,
141147
): MaybeThenable<IEvaluationResult> {
142148
let evaluation: MaybeThenable<IEvaluationResult> = {
143149
treatment: CONTROL,
@@ -154,14 +160,14 @@ function getEvaluation(
154160
return evaluation.then(result => {
155161
result.changeNumber = splitJSON.changeNumber;
156162
result.config = splitJSON.configurations && splitJSON.configurations[result.treatment] || null;
157-
result.impressionsDisabled = splitJSON.impressionsDisabled;
163+
result.impressionsDisabled = options?.impressionsDisabled || splitJSON.impressionsDisabled;
158164

159165
return result;
160166
});
161167
} else {
162168
evaluation.changeNumber = splitJSON.changeNumber;
163169
evaluation.config = splitJSON.configurations && splitJSON.configurations[evaluation.treatment] || null;
164-
evaluation.impressionsDisabled = splitJSON.impressionsDisabled;
170+
evaluation.impressionsDisabled = options?.impressionsDisabled || splitJSON.impressionsDisabled;
165171
}
166172
}
167173

@@ -175,6 +181,7 @@ function getEvaluations(
175181
splits: Record<string, ISplit | null>,
176182
attributes: SplitIO.Attributes | undefined,
177183
storage: IStorageSync | IStorageAsync,
184+
options?: SplitIO.EvaluationOptions,
178185
): MaybeThenable<Record<string, IEvaluationResult>> {
179186
const result: Record<string, IEvaluationResult> = {};
180187
const thenables: Promise<void>[] = [];
@@ -184,7 +191,8 @@ function getEvaluations(
184191
key,
185192
splits[splitName],
186193
attributes,
187-
storage
194+
storage,
195+
options
188196
);
189197
if (thenable(evaluation)) {
190198
thenables.push(evaluation.then(res => {

src/sdkClient/client.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export function clientFactory(params: ISdkFactoryContext): SplitIO.IClient | Spl
5252
};
5353

5454
const evaluation = readinessManager.isReady() || readinessManager.isReadyFromCache() ?
55-
evaluateFeature(log, key, featureFlagName, attributes, storage) :
55+
evaluateFeature(log, key, featureFlagName, attributes, storage, options) :
5656
isAsync ? // If the SDK is not ready, treatment may be incorrect due to having splits but not segments data, or storage is not connected
5757
Promise.resolve(treatmentNotReady) :
5858
treatmentNotReady;
@@ -81,7 +81,7 @@ export function clientFactory(params: ISdkFactoryContext): SplitIO.IClient | Spl
8181
};
8282

8383
const evaluations = readinessManager.isReady() || readinessManager.isReadyFromCache() ?
84-
evaluateFeatures(log, key, featureFlagNames, attributes, storage) :
84+
evaluateFeatures(log, key, featureFlagNames, attributes, storage, options) :
8585
isAsync ? // If the SDK is not ready, treatment may be incorrect due to having splits but not segments data, or storage is not connected
8686
Promise.resolve(treatmentsNotReady(featureFlagNames)) :
8787
treatmentsNotReady(featureFlagNames);
@@ -110,7 +110,7 @@ export function clientFactory(params: ISdkFactoryContext): SplitIO.IClient | Spl
110110
};
111111

112112
const evaluations = readinessManager.isReady() || readinessManager.isReadyFromCache() ?
113-
evaluateFeaturesByFlagSets(log, key, flagSetNames, attributes, storage, methodName) :
113+
evaluateFeaturesByFlagSets(log, key, flagSetNames, attributes, storage, methodName, options) :
114114
isAsync ?
115115
Promise.resolve({}) :
116116
{};

types/splitio.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,8 +838,16 @@ declare namespace SplitIO {
838838
* Evaluation options object for getTreatment methods.
839839
*/
840840
type EvaluationOptions = {
841+
/**
842+
* Whether the evaluation/s will track impressions or not.
843+
*
844+
* @defaultValue `false`
845+
*/
846+
impressionsDisabled?: boolean;
841847
/**
842848
* Optional properties to append to the generated impression object sent to Split backend.
849+
*
850+
* @defaultValue `undefined`
843851
*/
844852
properties?: Properties;
845853
}

0 commit comments

Comments
 (0)