flagsmith-nodejs 8.0.0 → 8.0.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.
@@ -1 +1 @@
1
- {".":"8.0.0"}
1
+ {".":"8.0.1"}
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [8.0.1](https://github.com/Flagsmith/flagsmith-nodejs-client/compare/v8.0.0...v8.0.1) (2026-03-16)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * unwrap TraitConfig values in local evaluation before segment matching ([#252](https://github.com/Flagsmith/flagsmith-nodejs-client/issues/252)) ([4e37994](https://github.com/Flagsmith/flagsmith-nodejs-client/commit/4e37994829bb741665a26aa38d543bebe51231d8))
9
+
3
10
  ## [8.0.0](https://github.com/Flagsmith/flagsmith-nodejs-client/compare/v7.0.3...v8.0.0) (2026-02-25)
4
11
 
5
12
 
@@ -226,7 +226,7 @@ class Flagsmith {
226
226
  const environment = await this.getEnvironment();
227
227
  const identityModel = this.getIdentityModel(environment, identifier, Object.keys(traits || {}).map(key => ({
228
228
  key,
229
- value: traits?.[key]
229
+ value: (0, utils_js_1.isTraitConfig)(traits?.[key]) ? traits[key].value : traits?.[key]
230
230
  })));
231
231
  const context = (0, mappers_js_1.getEvaluationContext)(environment, identityModel);
232
232
  if (!context) {
@@ -379,7 +379,7 @@ class Flagsmith {
379
379
  const environment = await this.getEnvironment();
380
380
  const identityModel = this.getIdentityModel(environment, identifier, Object.keys(traits).map(key => ({
381
381
  key,
382
- value: traits[key]
382
+ value: (0, utils_js_1.isTraitConfig)(traits[key]) ? traits[key].value : traits[key]
383
383
  })));
384
384
  const context = (0, mappers_js_1.getEvaluationContext)(environment, identityModel);
385
385
  if (!context) {
@@ -3,7 +3,7 @@ import { ANALYTICS_ENDPOINT, AnalyticsProcessor } from './analytics.js';
3
3
  import { FlagsmithAPIError, FlagsmithClientError } from './errors.js';
4
4
  import { Flags } from './models.js';
5
5
  import { EnvironmentDataPollingManager } from './polling_manager.js';
6
- import { Deferred, generateIdentitiesData, getUserAgent, retryFetch } from './utils.js';
6
+ import { Deferred, generateIdentitiesData, getUserAgent, isTraitConfig, retryFetch } from './utils.js';
7
7
  import { SegmentModel, IdentityModel, TraitModel, getEvaluationResult } from '../flagsmith-engine/index.js';
8
8
  import { pino } from 'pino';
9
9
  import { getEvaluationContext } from '../flagsmith-engine/evaluation/evaluationContext/mappers.js';
@@ -216,7 +216,7 @@ export class Flagsmith {
216
216
  const environment = await this.getEnvironment();
217
217
  const identityModel = this.getIdentityModel(environment, identifier, Object.keys(traits || {}).map(key => ({
218
218
  key,
219
- value: traits?.[key]
219
+ value: isTraitConfig(traits?.[key]) ? traits[key].value : traits?.[key]
220
220
  })));
221
221
  const context = getEvaluationContext(environment, identityModel);
222
222
  if (!context) {
@@ -369,7 +369,7 @@ export class Flagsmith {
369
369
  const environment = await this.getEnvironment();
370
370
  const identityModel = this.getIdentityModel(environment, identifier, Object.keys(traits).map(key => ({
371
371
  key,
372
- value: traits[key]
372
+ value: isTraitConfig(traits[key]) ? traits[key].value : traits[key]
373
373
  })));
374
374
  const context = getEvaluationContext(environment, identityModel);
375
375
  if (!context) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flagsmith-nodejs",
3
- "version": "8.0.0",
3
+ "version": "8.0.1",
4
4
  "description": "Flagsmith lets you manage features flags and remote config across web, mobile and server side applications. Deliver true Continuous Integration. Get builds out faster. Control who has access to new features.",
5
5
  "main": "./build/cjs/index.js",
6
6
  "type": "module",
package/sdk/index.ts CHANGED
@@ -8,7 +8,13 @@ import { FlagsmithAPIError, FlagsmithClientError } from './errors.js';
8
8
 
9
9
  import { DefaultFlag, Flags } from './models.js';
10
10
  import { EnvironmentDataPollingManager } from './polling_manager.js';
11
- import { Deferred, generateIdentitiesData, getUserAgent, retryFetch } from './utils.js';
11
+ import {
12
+ Deferred,
13
+ generateIdentitiesData,
14
+ getUserAgent,
15
+ isTraitConfig,
16
+ retryFetch
17
+ } from './utils.js';
12
18
  import {
13
19
  SegmentModel,
14
20
  EnvironmentModel,
@@ -275,7 +281,7 @@ export class Flagsmith {
275
281
  identifier,
276
282
  Object.keys(traits || {}).map(key => ({
277
283
  key,
278
- value: traits?.[key]
284
+ value: isTraitConfig(traits?.[key]) ? traits![key].value : traits?.[key]
279
285
  }))
280
286
  );
281
287
 
@@ -474,7 +480,7 @@ export class Flagsmith {
474
480
  identifier,
475
481
  Object.keys(traits).map(key => ({
476
482
  key,
477
- value: traits[key]
483
+ value: isTraitConfig(traits[key]) ? traits[key].value : traits[key]
478
484
  }))
479
485
  );
480
486
 
@@ -209,6 +209,76 @@ test('test_identity_with_transient_traits', async () => {
209
209
  expect(identityFlags[0].featureName).toBe('some_feature');
210
210
  });
211
211
 
212
+ test('getIdentityFlags local evaluation with plain traits matches segment', async () => {
213
+ const identifier = 'identifier';
214
+ // Plain trait format: age=30 should match segment rule "age LESS_THAN 40"
215
+ const traits = { age: 30 };
216
+
217
+ const flg = flagsmith({
218
+ environmentKey: 'ser.key',
219
+ enableLocalEvaluation: true
220
+ });
221
+
222
+ const flags = await flg.getIdentityFlags(identifier, traits);
223
+
224
+ // Should get segment override value, not the default
225
+ expect(flags.getFeatureValue('some_feature')).toBe('segment_override');
226
+ expect(flags.isFeatureEnabled('some_feature')).toBe(false);
227
+ });
228
+
229
+ test('getIdentityFlags local evaluation with TraitConfig format matches segment', async () => {
230
+ const identifier = 'identifier';
231
+ // TraitConfig format: same trait value wrapped with transient metadata
232
+ const traits = { age: { value: 30, transient: true } };
233
+
234
+ const flg = flagsmith({
235
+ environmentKey: 'ser.key',
236
+ enableLocalEvaluation: true
237
+ });
238
+
239
+ const flags = await flg.getIdentityFlags(identifier, traits);
240
+
241
+ // Should get segment override value — same result as plain trait format
242
+ expect(flags.getFeatureValue('some_feature')).toBe('segment_override');
243
+ expect(flags.isFeatureEnabled('some_feature')).toBe(false);
244
+ });
245
+
246
+ test('getIdentityFlags local evaluation with mixed trait formats matches segment', async () => {
247
+ const identifier = 'identifier';
248
+ // Mix of plain and TraitConfig formats
249
+ const traits = {
250
+ age: { value: 30, transient: true },
251
+ some_other_trait: 'plain_value'
252
+ };
253
+
254
+ const flg = flagsmith({
255
+ environmentKey: 'ser.key',
256
+ enableLocalEvaluation: true
257
+ });
258
+
259
+ const flags = await flg.getIdentityFlags(identifier, traits);
260
+
261
+ // Should get segment override value
262
+ expect(flags.getFeatureValue('some_feature')).toBe('segment_override');
263
+ expect(flags.isFeatureEnabled('some_feature')).toBe(false);
264
+ });
265
+
266
+ test('getIdentitySegments with TraitConfig format matches segment', async () => {
267
+ const identifier = 'identifier';
268
+ // TraitConfig format should work for getIdentitySegments too
269
+ const traits = { age: { value: 30, transient: true } };
270
+
271
+ const flg = flagsmith({
272
+ environmentKey: 'ser.key',
273
+ enableLocalEvaluation: true
274
+ });
275
+
276
+ const segments = await flg.getIdentitySegments(identifier, traits);
277
+
278
+ expect(segments).toHaveLength(1);
279
+ expect(segments[0].name).toBe('regular_segment');
280
+ });
281
+
212
282
  test('getIdentityFlags fails if API call failed and no default flag handler was provided', async () => {
213
283
  const flg = flagsmith({
214
284
  fetch: badFetch