Skip to content

Commit 41258f2

Browse files
authored
feat!: implement context values (#203)
This reverts commit c789c23.
1 parent 4c23ff2 commit 41258f2

File tree

26 files changed

+5928
-444
lines changed

26 files changed

+5928
-444
lines changed

.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 = v1.0.0
4+
branch = v2.5.0

.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/sh
22
. "$(dirname "$0")/_/husky.sh"
33

4+
npm run generate-engine-types
45
npm run lint
56
git add ./flagsmith-engine ./sdk ./tests ./index.ts ./.github
67
npm run test
Lines changed: 252 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
1+
/* eslint-disable */
2+
/**
3+
* This file was automatically generated by json-schema-to-typescript.
4+
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
5+
* and run json-schema-to-typescript to regenerate this file.
6+
*/
7+
8+
/**
9+
* An environment's unique identifier.
10+
*/
11+
export type Key = string;
12+
/**
13+
* An environment's human-readable name.
14+
*/
15+
export type Name = string;
16+
/**
17+
* A unique identifier for an identity, used for segment and multivariate feature flag targeting, and displayed in the Flagsmith UI.
18+
*/
19+
export type Identifier = string;
20+
/**
21+
* Key used when selecting a value for a multivariate feature, or for % split segmentation. Set to an internal identifier or a composite value based on the environment key and identifier, depending on Flagsmith implementation.
22+
*/
23+
export type Key1 = string;
24+
/**
25+
* Key used for % split segmentation.
26+
*/
27+
export type Key2 = string;
28+
/**
29+
* The name of the segment.
30+
*/
31+
export type Name1 = string;
32+
/**
33+
* Segment rule type. Represents a logical quantifier for the conditions and sub-rules.
34+
*/
35+
export type Type = 'ALL' | 'ANY' | 'NONE';
36+
export type SegmentCondition = SegmentCondition1 | InSegmentCondition;
37+
/**
38+
* A reference to the identity trait or value in the evaluation context.
39+
*/
40+
export type Property = string;
41+
/**
42+
* The operator to use for evaluating the condition.
43+
*/
44+
export type Operator =
45+
| 'EQUAL'
46+
| 'GREATER_THAN'
47+
| 'LESS_THAN'
48+
| 'LESS_THAN_INCLUSIVE'
49+
| 'CONTAINS'
50+
| 'GREATER_THAN_INCLUSIVE'
51+
| 'NOT_CONTAINS'
52+
| 'NOT_EQUAL'
53+
| 'REGEX'
54+
| 'PERCENTAGE_SPLIT'
55+
| 'MODULO'
56+
| 'IS_SET'
57+
| 'IS_NOT_SET'
58+
| 'IN';
59+
/**
60+
* The value to compare against the trait or context value.
61+
*/
62+
export type Value = string;
63+
/**
64+
* A reference to the identity trait or value in the evaluation context.
65+
*/
66+
export type Property1 = string;
67+
/**
68+
* The operator to use for evaluating the condition.
69+
*/
70+
export type Operator1 = 'IN';
71+
/**
72+
* The values to compare against the trait or context value.
73+
*/
74+
export type Value1 = string[];
75+
/**
76+
* Conditions that must be met for the rule to apply.
77+
*/
78+
export type Conditions = SegmentCondition[];
79+
/**
80+
* Sub-rules nested within the segment rule.
81+
*/
82+
export type SubRules = SegmentRule[];
83+
/**
84+
* Rules that define the segment.
85+
*/
86+
export type Rules = SegmentRule[];
87+
/**
88+
* Key used when selecting a value for a multivariate feature. Set to an internal identifier or a UUID, depending on Flagsmith implementation.
89+
*/
90+
export type Key3 = string;
91+
/**
92+
* Unique feature identifier.
93+
*/
94+
export type FeatureKey = string;
95+
/**
96+
* Feature name.
97+
*/
98+
export type Name2 = string;
99+
/**
100+
* Indicates whether the feature is enabled in the environment.
101+
*/
102+
export type Enabled = boolean;
103+
/**
104+
* A default environment value for the feature. If the feature is multivariate, this will be the control value.
105+
*/
106+
export type Value2 = string | number | boolean | null;
107+
/**
108+
* The value of the feature.
109+
*/
110+
export type Value3 = string | number | boolean | null;
111+
/**
112+
* The weight of the feature value variant, as a percentage number (i.e. 100.0).
113+
*/
114+
export type Weight = number;
115+
/**
116+
* Priority of the feature flag variant. Lower values indicate a higher priority when multiple variants apply to the same context key.
117+
*/
118+
export type VariantPriority = number;
119+
/**
120+
* An array of environment default values associated with the feature. Empty for standard features, or contains multiple values for multivariate features.
121+
*/
122+
export type Variants = FeatureValue[];
123+
/**
124+
* Priority of the feature context. Lower values indicate a higher priority when multiple contexts apply to the same feature.
125+
*/
126+
export type FeaturePriority = number;
127+
/**
128+
* Feature overrides for the segment.
129+
*/
130+
export type Overrides = FeatureContext[];
131+
132+
/**
133+
* A context object containing the necessary information to evaluate Flagsmith feature flags.
134+
*/
135+
export interface EvaluationContext {
136+
environment: EnvironmentContext;
137+
/**
138+
* Identity context used for identity-based evaluation.
139+
*/
140+
identity?: IdentityContext | null;
141+
segments?: Segments;
142+
features?: Features;
143+
[k: string]: unknown;
144+
}
145+
/**
146+
* Environment context required for evaluation.
147+
*/
148+
export interface EnvironmentContext {
149+
key: Key;
150+
name: Name;
151+
[k: string]: unknown;
152+
}
153+
/**
154+
* Represents an identity context for feature flag evaluation.
155+
*/
156+
export interface IdentityContext {
157+
identifier: Identifier;
158+
key: Key1;
159+
traits?: Traits;
160+
[k: string]: unknown;
161+
}
162+
/**
163+
* A map of traits associated with the identity, where the key is the trait name and the value is the trait value.
164+
*/
165+
export interface Traits {
166+
[k: string]: string | number | boolean | null;
167+
}
168+
/**
169+
* Segments applicable to the evaluation context.
170+
*/
171+
export interface Segments {
172+
[k: string]: SegmentContext;
173+
}
174+
/**
175+
* Represents a segment context for feature flag evaluation.
176+
*/
177+
export interface SegmentContext {
178+
key: Key2;
179+
name: Name1;
180+
rules: Rules;
181+
overrides?: Overrides;
182+
metadata?: SegmentMetadata;
183+
[k: string]: unknown;
184+
}
185+
/**
186+
* Represents a rule within a segment for feature flag evaluation.
187+
*/
188+
export interface SegmentRule {
189+
type: Type;
190+
conditions?: Conditions;
191+
rules?: SubRules;
192+
[k: string]: unknown;
193+
}
194+
/**
195+
* Represents a condition within a segment rule for feature flag evaluation.
196+
*/
197+
export interface SegmentCondition1 {
198+
property: Property;
199+
operator: Operator;
200+
value: Value;
201+
[k: string]: unknown;
202+
}
203+
/**
204+
* Represents an IN condition within a segment rule for feature flag evaluation.
205+
*/
206+
export interface InSegmentCondition {
207+
property: Property1;
208+
operator: Operator1;
209+
value: Value1;
210+
[k: string]: unknown;
211+
}
212+
/**
213+
* Represents a feature context for feature flag evaluation.
214+
*/
215+
export interface FeatureContext {
216+
key: Key3;
217+
feature_key: FeatureKey;
218+
name: Name2;
219+
enabled: Enabled;
220+
value: Value2;
221+
variants?: Variants;
222+
priority?: FeaturePriority;
223+
metadata?: FeatureMetadata;
224+
[k: string]: unknown;
225+
}
226+
/**
227+
* Represents a multivariate value for a feature flag.
228+
*/
229+
export interface FeatureValue {
230+
value: Value3;
231+
weight: Weight;
232+
priority: VariantPriority;
233+
[k: string]: unknown;
234+
}
235+
/**
236+
* Additional metadata associated with the feature.
237+
*/
238+
export interface FeatureMetadata {
239+
[k: string]: unknown;
240+
}
241+
/**
242+
* Additional metadata associated with the segment.
243+
*/
244+
export interface SegmentMetadata {
245+
[k: string]: unknown;
246+
}
247+
/**
248+
* Features to be evaluated in the context.
249+
*/
250+
export interface Features {
251+
[k: string]: FeatureContext;
252+
}

0 commit comments

Comments
 (0)