Skip to content

Commit ae1fb7e

Browse files
authored
fix: fix-mv-evaluation (#222)
* fix: fix-mv-evaluation * fix: changelog
1 parent 014f38b commit ae1fb7e

File tree

5 files changed

+19
-14
lines changed

5 files changed

+19
-14
lines changed

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
- '*'
77

88
permissions:
9-
id-token: write # Required for OIDC
9+
id-token: write # Required for OIDC
1010
contents: read
1111

1212
jobs:

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[submodule "tests/engine/engine-tests/engine-test-data"]
22
path = tests/engine/engine-tests/engine-test-data
33
url = [email protected]:Flagsmith/engine-test-data.git
4-
branch = v3.1.0
4+
branch = v3.4.1

flagsmith-engine/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export function evaluateSegments(context: EvaluationContextWithMetadata): {
7070
}
7171
}
7272
: {})
73-
}));
73+
})) as EvaluationResultSegments;
7474
const segmentOverrides = processSegmentOverrides(identitySegments);
7575

7676
return { segments, segmentOverrides };
@@ -127,11 +127,11 @@ export function evaluateFeatures(
127127
for (const feature of Object.values(context.features || {})) {
128128
const segmentOverride = segmentOverrides[feature.name];
129129
const finalFeature = segmentOverride ? segmentOverride.feature : feature;
130-
const hasOverride = !!segmentOverride;
131130

132-
const { value: evaluatedValue, reason: evaluatedReason } = hasOverride
133-
? { value: finalFeature.value, reason: undefined }
134-
: evaluateFeatureValue(finalFeature, getIdentityKey(context));
131+
const { value: evaluatedValue, reason: evaluatedReason } = evaluateFeatureValue(
132+
finalFeature,
133+
getIdentityKey(context)
134+
);
135135

136136
flags[finalFeature.name] = {
137137
name: finalFeature.name,

flagsmith-engine/segments/evaluators.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,22 +131,22 @@ function evaluateRuleConditions(ruleType: string, conditionResults: boolean[]):
131131
function getTraitValue(property: string, context?: GenericEvaluationContext): any {
132132
if (property.startsWith('$.')) {
133133
const contextValue = getContextValue(property, context);
134-
if (contextValue && !isNonPrimitive(contextValue)) {
134+
if (contextValue !== undefined && isPrimitive(contextValue)) {
135135
return contextValue;
136136
}
137137
}
138-
139138
const traits = context?.identity?.traits || {};
139+
140140
return traits[property];
141141
}
142142

143-
function isNonPrimitive(value: any): boolean {
143+
function isPrimitive(value: any): boolean {
144144
if (value === null || value === undefined) {
145-
return false;
145+
return true;
146146
}
147147

148148
// Objects and arrays are non-primitive
149-
return typeof value === 'object';
149+
return typeof value !== 'object';
150150
}
151151

152152
/**
@@ -167,7 +167,8 @@ export function getContextValue(jsonPath: string, context?: GenericEvaluationCon
167167
if (!context || !jsonPath?.startsWith('$.')) return undefined;
168168

169169
try {
170-
const results = jsonpath.query(context, jsonPath);
170+
const normalizedPath = normalizeJsonPath(jsonPath);
171+
const results = jsonpath.query(context, normalizedPath);
171172
return results.length > 0 ? results[0] : undefined;
172173
} catch (error) {
173174
return undefined;
@@ -179,3 +180,7 @@ export function getIdentityKey(context?: GenericEvaluationContext): string | und
179180

180181
return context.identity.key || `${context.environment.key}_${context.identity.identifier}`;
181182
}
183+
184+
function normalizeJsonPath(jsonPath: string): string {
185+
return jsonPath.replace(/\.([^.\[\]]+)$/, "['$1']");
186+
}
Submodule engine-test-data updated 106 files

0 commit comments

Comments
 (0)