Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2.9.0
- Added property `impressionsDisabled` in getTreatment(s) `evaluationOptions` parameter, to disable impressions per evaluations.

2.8.0 (October 30, 2025)
- Added new configuration for Fallback Treatments, which allows setting a treatment value and optional config to be returned in place of "control", either globally or by flag. Read more in our docs.
- Added `client.getStatus()` method to retrieve the client readiness status properties (`isReady`, `isReadyFromCache`, etc).
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@splitsoftware/splitio-commons",
"version": "2.8.0",
"version": "2.8.1-rc.1",
"description": "Split JavaScript SDK common components",
"main": "cjs/index.js",
"module": "esm/index.js",
Expand Down
20 changes: 14 additions & 6 deletions src/evaluator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export function evaluateFeature(
splitName: string,
attributes: SplitIO.Attributes | undefined,
storage: IStorageSync | IStorageAsync,
options?: SplitIO.EvaluationOptions
): MaybeThenable<IEvaluationResult> {
let parsedSplit;

Expand All @@ -47,6 +48,7 @@ export function evaluateFeature(
split,
attributes,
storage,
options,
)).catch(
// Exception on async `getSplit` storage. For example, when the storage is redis or
// pluggable and there is a connection issue and we can't retrieve the split to be evaluated
Expand All @@ -60,6 +62,7 @@ export function evaluateFeature(
parsedSplit,
attributes,
storage,
options,
);
}

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

Expand All @@ -80,13 +84,13 @@ export function evaluateFeatures(
}

return thenable(parsedSplits) ?
parsedSplits.then(splits => getEvaluations(log, key, splitNames, splits, attributes, storage))
parsedSplits.then(splits => getEvaluations(log, key, splitNames, splits, attributes, storage, options))
.catch(() => {
// Exception on async `getSplits` storage. For example, when the storage is redis or
// pluggable and there is a connection issue and we can't retrieve the split to be evaluated
return treatmentsException(splitNames);
}) :
getEvaluations(log, key, splitNames, parsedSplits, attributes, storage);
getEvaluations(log, key, splitNames, parsedSplits, attributes, storage, options);
}

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

Expand All @@ -111,7 +116,7 @@ export function evaluateFeaturesByFlagSets(
}

return featureFlags.size ?
evaluateFeatures(log, key, setToArray(featureFlags), attributes, storage) :
evaluateFeatures(log, key, setToArray(featureFlags), attributes, storage, options) :
{};
}

Expand All @@ -138,6 +143,7 @@ function getEvaluation(
splitJSON: ISplit | null,
attributes: SplitIO.Attributes | undefined,
storage: IStorageSync | IStorageAsync,
options?: SplitIO.EvaluationOptions,
): MaybeThenable<IEvaluationResult> {
let evaluation: MaybeThenable<IEvaluationResult> = {
treatment: CONTROL,
Expand All @@ -154,14 +160,14 @@ function getEvaluation(
return evaluation.then(result => {
result.changeNumber = splitJSON.changeNumber;
result.config = splitJSON.configurations && splitJSON.configurations[result.treatment] || null;
result.impressionsDisabled = splitJSON.impressionsDisabled;
result.impressionsDisabled = options?.impressionsDisabled || splitJSON.impressionsDisabled;

return result;
});
} else {
evaluation.changeNumber = splitJSON.changeNumber;
evaluation.config = splitJSON.configurations && splitJSON.configurations[evaluation.treatment] || null;
evaluation.impressionsDisabled = splitJSON.impressionsDisabled;
evaluation.impressionsDisabled = options?.impressionsDisabled || splitJSON.impressionsDisabled;
}
}

Expand All @@ -175,6 +181,7 @@ function getEvaluations(
splits: Record<string, ISplit | null>,
attributes: SplitIO.Attributes | undefined,
storage: IStorageSync | IStorageAsync,
options?: SplitIO.EvaluationOptions,
): MaybeThenable<Record<string, IEvaluationResult>> {
const result: Record<string, IEvaluationResult> = {};
const thenables: Promise<void>[] = [];
Expand All @@ -184,7 +191,8 @@ function getEvaluations(
key,
splits[splitName],
attributes,
storage
storage,
options
);
if (thenable(evaluation)) {
thenables.push(evaluation.then(res => {
Expand Down
20 changes: 20 additions & 0 deletions src/sdkClient/__tests__/clientInputValidation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,24 @@ describe('clientInputValidationDecorator', () => {

expect(logSpy).not.toBeCalled();
});

test('should ignore the properties in the 4th argument if an empty object is passed', () => {
expect(clientWithValidation.getTreatment('key', 'ff', undefined, { impressionsDisabled: true })).toBe(EVALUATION_RESULT);
expect(client.getTreatment).toHaveBeenLastCalledWith('key', 'ff', undefined, { impressionsDisabled: true });

expect(clientWithValidation.getTreatment('key', 'ff', undefined, { impressionsDisabled: false })).toBe(EVALUATION_RESULT);
expect(client.getTreatment).toHaveBeenLastCalledWith('key', 'ff', undefined, undefined);

expect(clientWithValidation.getTreatment('key', 'ff', undefined, { impressionsDisabled: true })).toBe(EVALUATION_RESULT);
expect(client.getTreatment).toHaveBeenLastCalledWith('key', 'ff', undefined, { impressionsDisabled: true });

expect(clientWithValidation.getTreatment('key', 'ff', undefined, { impressionsDisabled: null })).toBe(EVALUATION_RESULT);
expect(client.getTreatment).toHaveBeenLastCalledWith('key', 'ff', undefined, undefined);

expect(clientWithValidation.getTreatment('key', 'ff', undefined, { impressionsDisabled: false })).toBe(EVALUATION_RESULT);
expect(client.getTreatment).toHaveBeenLastCalledWith('key', 'ff', undefined, undefined); // impressionsDisabled false is the default behavior, so we don't pass it along

expect(clientWithValidation.getTreatment('key', 'ff', undefined, { properties: undefined })).toBe(EVALUATION_RESULT);
expect(client.getTreatment).toHaveBeenLastCalledWith('key', 'ff', undefined, undefined);
});
});
6 changes: 3 additions & 3 deletions src/sdkClient/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function clientFactory(params: ISdkFactoryContext): SplitIO.IClient | Spl
};

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

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

const evaluations = readinessManager.isReadyFromCache() ?
evaluateFeaturesByFlagSets(log, key, flagSetNames, attributes, storage, methodName) :
evaluateFeaturesByFlagSets(log, key, flagSetNames, attributes, storage, methodName, options) :
isAsync ?
Promise.resolve({}) :
{};
Expand Down
7 changes: 6 additions & 1 deletion src/utils/inputValidation/eventProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ export function validateEventProperties(log: ILogger, maybeProperties: any, meth
export function validateEvaluationOptions(log: ILogger, maybeOptions: any, method: string): SplitIO.EvaluationOptions | undefined {
if (isObject(maybeOptions)) {
const properties = validateEventProperties(log, maybeOptions.properties, method).properties;
return properties && Object.keys(properties).length > 0 ? { properties } : undefined;
let options = properties && Object.keys(properties).length > 0 ? { properties } : undefined;

const impressionsDisabled = maybeOptions.impressionsDisabled;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would need to refactor the validateEvaluationOptions so that the impressionsDisabled option is only validated and used for the Evaluator, and for other SDKs it should be sanitized to false (or any other falsy value) to ignore the feature.

Eventually, if the feature is included in SDKs, the change can be rolled back.

if (!impressionsDisabled) return options;

return options ? { ...options, impressionsDisabled } : { impressionsDisabled };
} else if (maybeOptions) {
log.error(ERROR_NOT_PLAIN_OBJECT, [method, 'evaluation options']);
}
Expand Down
8 changes: 8 additions & 0 deletions types/splitio.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -918,8 +918,16 @@ declare namespace SplitIO {
* Evaluation options object for getTreatment methods.
*/
type EvaluationOptions = {
/**
* Whether the evaluation/s will track impressions or not.
*
* @defaultValue `false`
*/
impressionsDisabled?: boolean;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should delete this TypeScript definition, if the feature is not supported yet for SDKs.

/**
* Optional properties to append to the generated impression object sent to Split backend.
*
* @defaultValue `undefined`
*/
properties?: Properties;
}
Expand Down