|
1 | 1 | import { |
2 | | - EvaluationResult, |
3 | 2 | CustomFeatureMetadata, |
4 | | - FlagResultWithMetadata |
| 3 | + FlagResultWithMetadata, |
| 4 | + EvaluationResultWithMetadata |
5 | 5 | } from '../flagsmith-engine/evaluation/models.js'; |
6 | 6 | import { FeatureStateModel } from '../flagsmith-engine/features/models.js'; |
7 | 7 | import { AnalyticsProcessor } from './analytics.js'; |
@@ -85,7 +85,7 @@ export class Flag extends BaseFlag { |
85 | 85 | }); |
86 | 86 | } |
87 | 87 |
|
88 | | - static fromFlagResult(flagResult: FlagResultWithMetadata<CustomFeatureMetadata>): Flag { |
| 88 | + static fromFlagResult(flagResult: FlagResultWithMetadata<CustomFeatureMetadata>): Flag | null { |
89 | 89 | return new Flag({ |
90 | 90 | enabled: flagResult.enabled, |
91 | 91 | value: flagResult.value ?? null, |
@@ -122,16 +122,21 @@ export class Flags { |
122 | 122 | } |
123 | 123 |
|
124 | 124 | static fromEvaluationResult( |
125 | | - evaluationResult: EvaluationResult, |
| 125 | + evaluationResult: EvaluationResultWithMetadata, |
126 | 126 | defaultFlagHandler?: (v: string) => DefaultFlag, |
127 | 127 | analyticsProcessor?: AnalyticsProcessor |
128 | 128 | ): Flags { |
129 | 129 | const flags: { [key: string]: Flag } = {}; |
130 | 130 | for (const flag of Object.values(evaluationResult.flags)) { |
| 131 | + const flagsmithId = flag.metadata?.flagsmithId || Number(flag.feature_key); |
| 132 | + if (!flagsmithId) { |
| 133 | + continue; |
| 134 | + } |
| 135 | + |
131 | 136 | flags[flag.name] = new Flag({ |
132 | 137 | enabled: flag.enabled, |
133 | 138 | value: flag.value ?? null, |
134 | | - featureId: Number(flag.feature_key), |
| 139 | + featureId: flag.metadata?.flagsmithId || Number(flag.feature_key), |
135 | 140 | featureName: flag.name, |
136 | 141 | reason: flag.reason |
137 | 142 | }); |
|
0 commit comments