From d1e447c0cef0945b06e7ea2b184093b30b41a12b Mon Sep 17 00:00:00 2001 From: wadii Date: Wed, 12 Nov 2025 16:28:26 +0100 Subject: [PATCH 1/2] fix: fix-mv-evaluation --- .github/workflows/publish.yml | 2 +- .gitmodules | 2 +- CHANGELOG.md | 16 ++++++---------- flagsmith-engine/index.ts | 10 +++++----- flagsmith-engine/segments/evaluators.ts | 17 +++++++++++------ tests/engine/engine-tests/engine-test-data | 2 +- 6 files changed, 25 insertions(+), 24 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 0463213..bd6430e 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -6,7 +6,7 @@ on: - '*' permissions: - id-token: write # Required for OIDC + id-token: write # Required for OIDC contents: read jobs: diff --git a/.gitmodules b/.gitmodules index 93de146..b5ddcdf 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ [submodule "tests/engine/engine-tests/engine-test-data"] path = tests/engine/engine-tests/engine-test-data url = git@github.com:Flagsmith/engine-test-data.git - branch = v3.1.0 + branch = v3.4.1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 50a0a54..dff0fd7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,30 +2,26 @@ ## [6.2.0](https://github.com/Flagsmith/flagsmith-nodejs-client/compare/v6.1.0...v6.2.0) (2025-11-04) - ### Features -* add user agent to requests ([#206](https://github.com/Flagsmith/flagsmith-nodejs-client/issues/206)) ([ef2b97a](https://github.com/Flagsmith/flagsmith-nodejs-client/commit/ef2b97a3022a5feeb96c3ccdb8009ae89b582d0b)) +- add user agent to requests ([#206](https://github.com/Flagsmith/flagsmith-nodejs-client/issues/206)) ([ef2b97a](https://github.com/Flagsmith/flagsmith-nodejs-client/commit/ef2b97a3022a5feeb96c3ccdb8009ae89b582d0b)) ### Bug Fixes -* handle environment documentation pagination ([#205](https://github.com/Flagsmith/flagsmith-nodejs-client/issues/205)) ([a83d3a5](https://github.com/Flagsmith/flagsmith-nodejs-client/commit/a83d3a5789abbc47abc2a95d07a19756ab7befbb)) - +- handle environment documentation pagination ([#205](https://github.com/Flagsmith/flagsmith-nodejs-client/issues/205)) ([a83d3a5](https://github.com/Flagsmith/flagsmith-nodejs-client/commit/a83d3a5789abbc47abc2a95d07a19756ab7befbb)) ### CI -* add release please configuration ([#190](https://github.com/Flagsmith/flagsmith-nodejs-client/issues/190)) ([946f911](https://github.com/Flagsmith/flagsmith-nodejs-client/commit/946f911e3c9d7df21bd7e5c6df5f9f92927e5e59)) - +- add release please configuration ([#190](https://github.com/Flagsmith/flagsmith-nodejs-client/issues/190)) ([946f911](https://github.com/Flagsmith/flagsmith-nodejs-client/commit/946f911e3c9d7df21bd7e5c6df5f9f92927e5e59)) ### Docs -* removing hero image from SDK readme ([#194](https://github.com/Flagsmith/flagsmith-nodejs-client/issues/194)) ([bc71d40](https://github.com/Flagsmith/flagsmith-nodejs-client/commit/bc71d40bdfa319b5333c18f4f9eacbe90b6fad0d)) - +- removing hero image from SDK readme ([#194](https://github.com/Flagsmith/flagsmith-nodejs-client/issues/194)) ([bc71d40](https://github.com/Flagsmith/flagsmith-nodejs-client/commit/bc71d40bdfa319b5333c18f4f9eacbe90b6fad0d)) ### Other -* add root CODEOWNERS ([#200](https://github.com/Flagsmith/flagsmith-nodejs-client/issues/200)) ([e81cc00](https://github.com/Flagsmith/flagsmith-nodejs-client/commit/e81cc00f1de35e0884b2cfc70c6cf54a75a3426c)) -* versioned test data ([#197](https://github.com/Flagsmith/flagsmith-nodejs-client/issues/197)) ([9fb5c12](https://github.com/Flagsmith/flagsmith-nodejs-client/commit/9fb5c127a2b56503ba876da2466c24e5ceff1d3f)) +- add root CODEOWNERS ([#200](https://github.com/Flagsmith/flagsmith-nodejs-client/issues/200)) ([e81cc00](https://github.com/Flagsmith/flagsmith-nodejs-client/commit/e81cc00f1de35e0884b2cfc70c6cf54a75a3426c)) +- versioned test data ([#197](https://github.com/Flagsmith/flagsmith-nodejs-client/issues/197)) ([9fb5c12](https://github.com/Flagsmith/flagsmith-nodejs-client/commit/9fb5c127a2b56503ba876da2466c24e5ceff1d3f)) diff --git a/flagsmith-engine/index.ts b/flagsmith-engine/index.ts index e3f20f1..03b8434 100644 --- a/flagsmith-engine/index.ts +++ b/flagsmith-engine/index.ts @@ -70,7 +70,7 @@ export function evaluateSegments(context: EvaluationContextWithMetadata): { } } : {}) - })); + })) as EvaluationResultSegments; const segmentOverrides = processSegmentOverrides(identitySegments); return { segments, segmentOverrides }; @@ -127,11 +127,11 @@ export function evaluateFeatures( for (const feature of Object.values(context.features || {})) { const segmentOverride = segmentOverrides[feature.name]; const finalFeature = segmentOverride ? segmentOverride.feature : feature; - const hasOverride = !!segmentOverride; - const { value: evaluatedValue, reason: evaluatedReason } = hasOverride - ? { value: finalFeature.value, reason: undefined } - : evaluateFeatureValue(finalFeature, getIdentityKey(context)); + const { value: evaluatedValue, reason: evaluatedReason } = evaluateFeatureValue( + finalFeature, + getIdentityKey(context) + ); flags[finalFeature.name] = { name: finalFeature.name, diff --git a/flagsmith-engine/segments/evaluators.ts b/flagsmith-engine/segments/evaluators.ts index aecae7f..1763481 100644 --- a/flagsmith-engine/segments/evaluators.ts +++ b/flagsmith-engine/segments/evaluators.ts @@ -131,22 +131,22 @@ function evaluateRuleConditions(ruleType: string, conditionResults: boolean[]): function getTraitValue(property: string, context?: GenericEvaluationContext): any { if (property.startsWith('$.')) { const contextValue = getContextValue(property, context); - if (contextValue && !isNonPrimitive(contextValue)) { + if (contextValue !== undefined && isPrimitive(contextValue)) { return contextValue; } } - const traits = context?.identity?.traits || {}; + return traits[property]; } -function isNonPrimitive(value: any): boolean { +function isPrimitive(value: any): boolean { if (value === null || value === undefined) { - return false; + return true; } // Objects and arrays are non-primitive - return typeof value === 'object'; + return typeof value !== 'object'; } /** @@ -167,7 +167,8 @@ export function getContextValue(jsonPath: string, context?: GenericEvaluationCon if (!context || !jsonPath?.startsWith('$.')) return undefined; try { - const results = jsonpath.query(context, jsonPath); + const normalizedPath = normalizeJsonPath(jsonPath); + const results = jsonpath.query(context, normalizedPath); return results.length > 0 ? results[0] : undefined; } catch (error) { return undefined; @@ -179,3 +180,7 @@ export function getIdentityKey(context?: GenericEvaluationContext): string | und return context.identity.key || `${context.environment.key}_${context.identity.identifier}`; } + +function normalizeJsonPath(jsonPath: string): string { + return jsonPath.replace(/\.([^.\[\]]+)$/, "['$1']"); +} diff --git a/tests/engine/engine-tests/engine-test-data b/tests/engine/engine-tests/engine-test-data index 6ab57ec..839e8d5 160000 --- a/tests/engine/engine-tests/engine-test-data +++ b/tests/engine/engine-tests/engine-test-data @@ -1 +1 @@ -Subproject commit 6ab57ec67bc84659e8b5aa41534b04fe45cc4cbe +Subproject commit 839e8d5e5f2e9af6392062cf5e575d43c03770d4 From d2062c5768fa54aab24fd1c7b0ffdaccc4b296a9 Mon Sep 17 00:00:00 2001 From: wadii Date: Mon, 17 Nov 2025 13:25:57 +0100 Subject: [PATCH 2/2] fix: changelog --- CHANGELOG.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dff0fd7..50a0a54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,26 +2,30 @@ ## [6.2.0](https://github.com/Flagsmith/flagsmith-nodejs-client/compare/v6.1.0...v6.2.0) (2025-11-04) + ### Features -- add user agent to requests ([#206](https://github.com/Flagsmith/flagsmith-nodejs-client/issues/206)) ([ef2b97a](https://github.com/Flagsmith/flagsmith-nodejs-client/commit/ef2b97a3022a5feeb96c3ccdb8009ae89b582d0b)) +* add user agent to requests ([#206](https://github.com/Flagsmith/flagsmith-nodejs-client/issues/206)) ([ef2b97a](https://github.com/Flagsmith/flagsmith-nodejs-client/commit/ef2b97a3022a5feeb96c3ccdb8009ae89b582d0b)) ### Bug Fixes -- handle environment documentation pagination ([#205](https://github.com/Flagsmith/flagsmith-nodejs-client/issues/205)) ([a83d3a5](https://github.com/Flagsmith/flagsmith-nodejs-client/commit/a83d3a5789abbc47abc2a95d07a19756ab7befbb)) +* handle environment documentation pagination ([#205](https://github.com/Flagsmith/flagsmith-nodejs-client/issues/205)) ([a83d3a5](https://github.com/Flagsmith/flagsmith-nodejs-client/commit/a83d3a5789abbc47abc2a95d07a19756ab7befbb)) + ### CI -- add release please configuration ([#190](https://github.com/Flagsmith/flagsmith-nodejs-client/issues/190)) ([946f911](https://github.com/Flagsmith/flagsmith-nodejs-client/commit/946f911e3c9d7df21bd7e5c6df5f9f92927e5e59)) +* add release please configuration ([#190](https://github.com/Flagsmith/flagsmith-nodejs-client/issues/190)) ([946f911](https://github.com/Flagsmith/flagsmith-nodejs-client/commit/946f911e3c9d7df21bd7e5c6df5f9f92927e5e59)) + ### Docs -- removing hero image from SDK readme ([#194](https://github.com/Flagsmith/flagsmith-nodejs-client/issues/194)) ([bc71d40](https://github.com/Flagsmith/flagsmith-nodejs-client/commit/bc71d40bdfa319b5333c18f4f9eacbe90b6fad0d)) +* removing hero image from SDK readme ([#194](https://github.com/Flagsmith/flagsmith-nodejs-client/issues/194)) ([bc71d40](https://github.com/Flagsmith/flagsmith-nodejs-client/commit/bc71d40bdfa319b5333c18f4f9eacbe90b6fad0d)) + ### Other -- add root CODEOWNERS ([#200](https://github.com/Flagsmith/flagsmith-nodejs-client/issues/200)) ([e81cc00](https://github.com/Flagsmith/flagsmith-nodejs-client/commit/e81cc00f1de35e0884b2cfc70c6cf54a75a3426c)) -- versioned test data ([#197](https://github.com/Flagsmith/flagsmith-nodejs-client/issues/197)) ([9fb5c12](https://github.com/Flagsmith/flagsmith-nodejs-client/commit/9fb5c127a2b56503ba876da2466c24e5ceff1d3f)) +* add root CODEOWNERS ([#200](https://github.com/Flagsmith/flagsmith-nodejs-client/issues/200)) ([e81cc00](https://github.com/Flagsmith/flagsmith-nodejs-client/commit/e81cc00f1de35e0884b2cfc70c6cf54a75a3426c)) +* versioned test data ([#197](https://github.com/Flagsmith/flagsmith-nodejs-client/issues/197)) ([9fb5c12](https://github.com/Flagsmith/flagsmith-nodejs-client/commit/9fb5c127a2b56503ba876da2466c24e5ceff1d3f))