Skip to content

Commit 40355a1

Browse files
committed
feat: merged-evaluation-context-types
1 parent 9a89bf7 commit 40355a1

File tree

14 files changed

+577
-72
lines changed

14 files changed

+577
-72
lines changed
Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
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+
* An array of environment default values associated with the feature. Contains a single value for standard features, or multiple values for multivariate features.
117+
*/
118+
export type Variants = FeatureValue[];
119+
/**
120+
* Priority of the feature context. Lower values indicate a higher priority when multiple contexts apply to the same feature.
121+
*/
122+
export type Priority = number;
123+
/**
124+
* Feature overrides for the segment.
125+
*/
126+
export type Overrides = FeatureContext[];
127+
128+
/**
129+
* A context object containing the necessary information to evaluate Flagsmith feature flags.
130+
*/
131+
export interface EvaluationContext {
132+
environment: EnvironmentContext;
133+
/**
134+
* Identity context used for identity-based evaluation.
135+
*/
136+
identity?: IdentityContext | null;
137+
segments?: Segments;
138+
features?: Features;
139+
[k: string]: unknown;
140+
}
141+
/**
142+
* Environment context required for evaluation.
143+
*/
144+
export interface EnvironmentContext {
145+
key: Key;
146+
name: Name;
147+
[k: string]: unknown;
148+
}
149+
/**
150+
* Represents an identity context for feature flag evaluation.
151+
*/
152+
export interface IdentityContext {
153+
identifier: Identifier;
154+
key: Key1;
155+
traits?: Traits;
156+
[k: string]: unknown;
157+
}
158+
/**
159+
* A map of traits associated with the identity, where the key is the trait name and the value is the trait value.
160+
*/
161+
export interface Traits {
162+
[k: string]: string | number | boolean | null;
163+
}
164+
/**
165+
* Segments applicable to the evaluation context.
166+
*/
167+
export interface Segments {
168+
[k: string]: SegmentContext;
169+
}
170+
/**
171+
* Represents a segment context for feature flag evaluation.
172+
*/
173+
export interface SegmentContext {
174+
key: Key2;
175+
name: Name1;
176+
rules: Rules;
177+
overrides?: Overrides;
178+
[k: string]: unknown;
179+
}
180+
/**
181+
* Represents a rule within a segment for feature flag evaluation.
182+
*/
183+
export interface SegmentRule {
184+
type: Type;
185+
conditions?: Conditions;
186+
rules?: SubRules;
187+
[k: string]: unknown;
188+
}
189+
/**
190+
* Represents a condition within a segment rule for feature flag evaluation.
191+
*/
192+
export interface SegmentCondition1 {
193+
property: Property;
194+
operator: Operator;
195+
value: Value;
196+
[k: string]: unknown;
197+
}
198+
/**
199+
* Represents an IN condition within a segment rule for feature flag evaluation.
200+
*/
201+
export interface InSegmentCondition {
202+
property: Property1;
203+
operator: Operator1;
204+
value: Value1;
205+
[k: string]: unknown;
206+
}
207+
/**
208+
* Represents a feature context for feature flag evaluation.
209+
*/
210+
export interface FeatureContext {
211+
key: Key3;
212+
feature_key: FeatureKey;
213+
name: Name2;
214+
enabled: Enabled;
215+
value: Value2;
216+
variants?: Variants;
217+
priority?: Priority;
218+
[k: string]: unknown;
219+
}
220+
/**
221+
* Represents a multivariate value for a feature flag.
222+
*/
223+
export interface FeatureValue {
224+
value: Value3;
225+
weight: Weight;
226+
[k: string]: unknown;
227+
}
228+
/**
229+
* Features to be evaluated in the context.
230+
*/
231+
export interface Features {
232+
[k: string]: FeatureContext;
233+
}

flagsmith-engine/evaluationContext/mappers.ts renamed to flagsmith-engine/evaluation/evaluationContext/mappers.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import {
55
EvaluationContext,
66
EnvironmentContext,
77
IdentityContext
8-
} from './models.js';
9-
import { EnvironmentModel } from '../environments/models.js';
10-
import { IdentityModel } from '../identities/models.js';
11-
import { TraitModel } from '../identities/traits/models.js';
12-
import { IDENTITY_OVERRIDE_SEGMENT_NAME } from '../segments/constants.js';
8+
} from '../models.js';
9+
import { EnvironmentModel } from '../../environments/models.js';
10+
import { IdentityModel } from '../../identities/models.js';
11+
import { TraitModel } from '../../identities/traits/models.js';
12+
import { IDENTITY_OVERRIDE_SEGMENT_NAME } from '../../segments/constants.js';
1313
import { createHash } from 'node:crypto';
1414

1515
export function getEvaluationContext(

0 commit comments

Comments
 (0)