flagsmith-nodejs 6.2.0 → 7.0.2

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.
Files changed (100) hide show
  1. package/.github/workflows/publish.yml +8 -5
  2. package/.github/workflows/pull_request.yaml +3 -0
  3. package/.gitmodules +1 -1
  4. package/.husky/pre-commit +1 -0
  5. package/.nvmrc +1 -0
  6. package/.release-please-manifest.json +1 -1
  7. package/CHANGELOG.md +40 -0
  8. package/build/cjs/flagsmith-engine/environments/models.d.ts +2 -1
  9. package/build/cjs/flagsmith-engine/environments/models.js +3 -1
  10. package/build/cjs/flagsmith-engine/environments/util.js +1 -1
  11. package/build/cjs/flagsmith-engine/evaluation/evaluationContext/evaluationContext.types.d.ts +230 -0
  12. package/build/cjs/flagsmith-engine/evaluation/evaluationContext/evaluationContext.types.js +8 -0
  13. package/build/cjs/flagsmith-engine/evaluation/evaluationContext/mappers.d.ts +5 -0
  14. package/build/cjs/flagsmith-engine/evaluation/evaluationContext/mappers.js +156 -0
  15. package/build/cjs/flagsmith-engine/evaluation/evaluationContext/types.d.ts +216 -0
  16. package/build/cjs/flagsmith-engine/evaluation/evaluationContext/types.js +8 -0
  17. package/build/cjs/flagsmith-engine/evaluation/evaluationResult/evaluationResult.types.d.ts +68 -0
  18. package/build/cjs/flagsmith-engine/evaluation/evaluationResult/evaluationResult.types.js +8 -0
  19. package/build/cjs/flagsmith-engine/evaluation/models.d.ts +50 -0
  20. package/build/cjs/flagsmith-engine/evaluation/models.js +26 -0
  21. package/build/cjs/flagsmith-engine/features/models.js +1 -1
  22. package/build/cjs/flagsmith-engine/features/types.d.ts +5 -0
  23. package/build/cjs/flagsmith-engine/features/types.js +9 -0
  24. package/build/cjs/flagsmith-engine/features/util.d.ts +1 -0
  25. package/build/cjs/flagsmith-engine/features/util.js +5 -1
  26. package/build/cjs/flagsmith-engine/index.d.ts +61 -9
  27. package/build/cjs/flagsmith-engine/index.js +176 -56
  28. package/build/cjs/flagsmith-engine/segments/constants.d.ts +1 -0
  29. package/build/cjs/flagsmith-engine/segments/constants.js +2 -1
  30. package/build/cjs/flagsmith-engine/segments/evaluators.d.ts +41 -7
  31. package/build/cjs/flagsmith-engine/segments/evaluators.js +136 -24
  32. package/build/cjs/flagsmith-engine/segments/models.d.ts +9 -4
  33. package/build/cjs/flagsmith-engine/segments/models.js +115 -13
  34. package/build/cjs/flagsmith-engine/utils/hashing/index.d.ts +1 -1
  35. package/build/cjs/flagsmith-engine/utils/hashing/index.js +4 -4
  36. package/build/cjs/sdk/index.d.ts +1 -3
  37. package/build/cjs/sdk/index.js +22 -19
  38. package/build/cjs/sdk/models.d.ts +8 -1
  39. package/build/cjs/sdk/models.js +29 -1
  40. package/build/esm/flagsmith-engine/environments/models.d.ts +2 -1
  41. package/build/esm/flagsmith-engine/environments/models.js +3 -1
  42. package/build/esm/flagsmith-engine/environments/util.js +1 -1
  43. package/build/esm/flagsmith-engine/evaluation/evaluationContext/evaluationContext.types.d.ts +230 -0
  44. package/build/esm/flagsmith-engine/evaluation/evaluationContext/evaluationContext.types.js +7 -0
  45. package/build/esm/flagsmith-engine/evaluation/evaluationContext/mappers.d.ts +5 -0
  46. package/build/esm/flagsmith-engine/evaluation/evaluationContext/mappers.js +152 -0
  47. package/build/esm/flagsmith-engine/evaluation/evaluationContext/types.d.ts +216 -0
  48. package/build/esm/flagsmith-engine/evaluation/evaluationContext/types.js +7 -0
  49. package/build/esm/flagsmith-engine/evaluation/evaluationResult/evaluationResult.types.d.ts +68 -0
  50. package/build/esm/flagsmith-engine/evaluation/evaluationResult/evaluationResult.types.js +7 -0
  51. package/build/esm/flagsmith-engine/evaluation/models.d.ts +50 -0
  52. package/build/esm/flagsmith-engine/evaluation/models.js +9 -0
  53. package/build/esm/flagsmith-engine/features/models.js +2 -2
  54. package/build/esm/flagsmith-engine/features/types.d.ts +5 -0
  55. package/build/esm/flagsmith-engine/features/types.js +6 -0
  56. package/build/esm/flagsmith-engine/features/util.d.ts +1 -0
  57. package/build/esm/flagsmith-engine/features/util.js +3 -0
  58. package/build/esm/flagsmith-engine/index.d.ts +61 -9
  59. package/build/esm/flagsmith-engine/index.js +161 -43
  60. package/build/esm/flagsmith-engine/segments/constants.d.ts +1 -0
  61. package/build/esm/flagsmith-engine/segments/constants.js +1 -0
  62. package/build/esm/flagsmith-engine/segments/evaluators.d.ts +41 -7
  63. package/build/esm/flagsmith-engine/segments/evaluators.js +137 -25
  64. package/build/esm/flagsmith-engine/segments/models.d.ts +9 -4
  65. package/build/esm/flagsmith-engine/segments/models.js +115 -13
  66. package/build/esm/flagsmith-engine/utils/hashing/index.d.ts +1 -1
  67. package/build/esm/flagsmith-engine/utils/hashing/index.js +2 -2
  68. package/build/esm/sdk/index.d.ts +1 -3
  69. package/build/esm/sdk/index.js +21 -18
  70. package/build/esm/sdk/models.d.ts +8 -1
  71. package/build/esm/sdk/models.js +29 -1
  72. package/flagsmith-engine/environments/models.ts +3 -1
  73. package/flagsmith-engine/environments/util.ts +2 -1
  74. package/flagsmith-engine/evaluation/evaluationContext/evaluationContext.types.ts +247 -0
  75. package/flagsmith-engine/evaluation/evaluationContext/mappers.ts +204 -0
  76. package/flagsmith-engine/evaluation/evaluationContext/types.ts +233 -0
  77. package/flagsmith-engine/evaluation/evaluationResult/evaluationResult.types.ts +71 -0
  78. package/flagsmith-engine/evaluation/models.ts +96 -0
  79. package/flagsmith-engine/features/models.ts +3 -2
  80. package/flagsmith-engine/features/types.ts +5 -0
  81. package/flagsmith-engine/features/util.ts +4 -0
  82. package/flagsmith-engine/index.ts +229 -72
  83. package/flagsmith-engine/segments/constants.ts +1 -0
  84. package/flagsmith-engine/segments/evaluators.ts +178 -62
  85. package/flagsmith-engine/segments/models.ts +171 -23
  86. package/flagsmith-engine/utils/hashing/index.ts +2 -2
  87. package/package.json +13 -2
  88. package/sdk/index.ts +36 -23
  89. package/sdk/models.ts +44 -2
  90. package/tests/engine/e2e/engine.test.ts +43 -38
  91. package/tests/engine/unit/engine.test.ts +306 -59
  92. package/tests/engine/unit/mappers.test.ts +353 -0
  93. package/tests/engine/unit/segments/segment_evaluators.test.ts +391 -49
  94. package/tests/engine/unit/segments/segments_model.test.ts +85 -0
  95. package/tests/engine/unit/utils/utils.test.ts +7 -7
  96. package/tests/engine/unit/utils.ts +1 -1
  97. package/tests/sdk/data/environment.json +1 -0
  98. package/tests/sdk/flagsmith.test.ts +29 -3
  99. package/tests/sdk/offline-handlers.test.ts +3 -1
  100. package/vitest.config.esm.ts +34 -0
@@ -0,0 +1,216 @@
1
+ /**
2
+ * This file was automatically generated by json-schema-to-typescript.
3
+ * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
4
+ * and run json-schema-to-typescript to regenerate this file.
5
+ */
6
+ /**
7
+ * An environment's unique identifier.
8
+ */
9
+ export type Key = string;
10
+ /**
11
+ * An environment's human-readable name.
12
+ */
13
+ export type Name = string;
14
+ /**
15
+ * A unique identifier for an identity, used for segment and multivariate feature flag targeting, and displayed in the Flagsmith UI.
16
+ */
17
+ export type Identifier = string;
18
+ /**
19
+ * 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.
20
+ */
21
+ export type Key1 = string;
22
+ /**
23
+ * Key used for % split segmentation.
24
+ */
25
+ export type Key2 = string;
26
+ /**
27
+ * The name of the segment.
28
+ */
29
+ export type Name1 = string;
30
+ /**
31
+ * Segment rule type. Represents a logical quantifier for the conditions and sub-rules.
32
+ */
33
+ export type Type = 'ALL' | 'ANY' | 'NONE';
34
+ export type SegmentCondition = SegmentCondition1 | InSegmentCondition;
35
+ /**
36
+ * A reference to the identity trait or value in the evaluation context.
37
+ */
38
+ export type Property = string;
39
+ /**
40
+ * The operator to use for evaluating the condition.
41
+ */
42
+ export type Operator = 'EQUAL' | 'GREATER_THAN' | 'LESS_THAN' | 'LESS_THAN_INCLUSIVE' | 'CONTAINS' | 'GREATER_THAN_INCLUSIVE' | 'NOT_CONTAINS' | 'NOT_EQUAL' | 'REGEX' | 'PERCENTAGE_SPLIT' | 'MODULO' | 'IS_SET' | 'IS_NOT_SET' | 'IN';
43
+ /**
44
+ * The value to compare against the trait or context value.
45
+ */
46
+ export type Value = string;
47
+ /**
48
+ * A reference to the identity trait or value in the evaluation context.
49
+ */
50
+ export type Property1 = string;
51
+ /**
52
+ * The operator to use for evaluating the condition.
53
+ */
54
+ export type Operator1 = 'IN';
55
+ /**
56
+ * The values to compare against the trait or context value.
57
+ */
58
+ export type Value1 = string[];
59
+ /**
60
+ * Conditions that must be met for the rule to apply.
61
+ */
62
+ export type Conditions = SegmentCondition[];
63
+ /**
64
+ * Sub-rules nested within the segment rule.
65
+ */
66
+ export type SubRules = SegmentRule[];
67
+ /**
68
+ * Rules that define the segment.
69
+ */
70
+ export type Rules = SegmentRule[];
71
+ /**
72
+ * Key used when selecting a value for a multivariate feature. Set to an internal identifier or a UUID, depending on Flagsmith implementation.
73
+ */
74
+ export type Key3 = string;
75
+ /**
76
+ * Unique feature identifier.
77
+ */
78
+ export type FeatureKey = string;
79
+ /**
80
+ * Feature name.
81
+ */
82
+ export type Name2 = string;
83
+ /**
84
+ * Indicates whether the feature is enabled in the environment.
85
+ */
86
+ export type Enabled = boolean;
87
+ /**
88
+ * A default environment value for the feature. If the feature is multivariate, this will be the control value.
89
+ */
90
+ export type Value2 = string;
91
+ /**
92
+ * The value of the feature.
93
+ */
94
+ export type Value3 = string;
95
+ /**
96
+ * The weight of the feature value variant, as a percentage number (i.e. 100.0).
97
+ */
98
+ export type Weight = number;
99
+ /**
100
+ * An array of environment default values associated with the feature. Contains a single value for standard features, or multiple values for multivariate features.
101
+ */
102
+ export type Variants = FeatureValue[];
103
+ /**
104
+ * Priority of the feature context. Lower values indicate a higher priority when multiple contexts apply to the same feature.
105
+ */
106
+ export type Priority = number;
107
+ /**
108
+ * Feature overrides for the segment.
109
+ */
110
+ export type Overrides = FeatureContext[];
111
+ /**
112
+ * A context object containing the necessary information to evaluate Flagsmith feature flags.
113
+ */
114
+ export interface EvaluationContext {
115
+ environment: EnvironmentContext;
116
+ /**
117
+ * Identity context used for identity-based evaluation.
118
+ */
119
+ identity?: IdentityContext | null;
120
+ segments?: Segments;
121
+ features?: Features;
122
+ [k: string]: unknown;
123
+ }
124
+ /**
125
+ * Environment context required for evaluation.
126
+ */
127
+ export interface EnvironmentContext {
128
+ key: Key;
129
+ name: Name;
130
+ [k: string]: unknown;
131
+ }
132
+ /**
133
+ * Represents an identity context for feature flag evaluation.
134
+ */
135
+ export interface IdentityContext {
136
+ identifier: Identifier;
137
+ key: Key1;
138
+ traits?: Traits;
139
+ [k: string]: unknown;
140
+ }
141
+ /**
142
+ * A map of traits associated with the identity, where the key is the trait name and the value is the trait value.
143
+ */
144
+ export interface Traits {
145
+ [k: string]: string | number | boolean | null;
146
+ }
147
+ /**
148
+ * Segments applicable to the evaluation context.
149
+ */
150
+ export interface Segments {
151
+ [k: string]: SegmentContext;
152
+ }
153
+ /**
154
+ * Represents a segment context for feature flag evaluation.
155
+ */
156
+ export interface SegmentContext {
157
+ key: Key2;
158
+ name: Name1;
159
+ rules: Rules;
160
+ overrides?: Overrides;
161
+ [k: string]: unknown;
162
+ }
163
+ /**
164
+ * Represents a rule within a segment for feature flag evaluation.
165
+ */
166
+ export interface SegmentRule {
167
+ type: Type;
168
+ conditions?: Conditions;
169
+ rules?: SubRules;
170
+ [k: string]: unknown;
171
+ }
172
+ /**
173
+ * Represents a condition within a segment rule for feature flag evaluation.
174
+ */
175
+ export interface SegmentCondition1 {
176
+ property: Property;
177
+ operator: Operator;
178
+ value: Value;
179
+ [k: string]: unknown;
180
+ }
181
+ /**
182
+ * Represents an IN condition within a segment rule for feature flag evaluation.
183
+ */
184
+ export interface InSegmentCondition {
185
+ property: Property1;
186
+ operator: Operator1;
187
+ value: Value1;
188
+ [k: string]: unknown;
189
+ }
190
+ /**
191
+ * Represents a feature context for feature flag evaluation.
192
+ */
193
+ export interface FeatureContext {
194
+ key: Key3;
195
+ feature_key: FeatureKey;
196
+ name: Name2;
197
+ enabled: Enabled;
198
+ value: Value2;
199
+ variants?: Variants;
200
+ priority?: Priority;
201
+ [k: string]: unknown;
202
+ }
203
+ /**
204
+ * Represents a multivariate value for a feature flag.
205
+ */
206
+ export interface FeatureValue {
207
+ value: Value3;
208
+ weight: Weight;
209
+ [k: string]: unknown;
210
+ }
211
+ /**
212
+ * Features to be evaluated in the context.
213
+ */
214
+ export interface Features {
215
+ [k: string]: FeatureContext;
216
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ /* eslint-disable */
3
+ /**
4
+ * This file was automatically generated by json-schema-to-typescript.
5
+ * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
6
+ * and run json-schema-to-typescript to regenerate this file.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,68 @@
1
+ /**
2
+ * This file was automatically generated by json-schema-to-typescript.
3
+ * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
4
+ * and run json-schema-to-typescript to regenerate this file.
5
+ */
6
+ /**
7
+ * Feature name.
8
+ */
9
+ export type Name = string;
10
+ /**
11
+ * Indicates if the feature flag is enabled.
12
+ */
13
+ export type Enabled = boolean;
14
+ /**
15
+ * Feature flag value.
16
+ */
17
+ export type Value = string | number | boolean | null;
18
+ /**
19
+ * Reason for the feature flag evaluation.
20
+ */
21
+ export type Reason = string;
22
+ /**
23
+ * Segment name.
24
+ */
25
+ export type Name1 = string;
26
+ /**
27
+ * List of segments which the provided context belongs to.
28
+ */
29
+ export type Segments = SegmentResult[];
30
+ /**
31
+ * Evaluation result object containing the used context, flag evaluation results, and segments used in the evaluation.
32
+ */
33
+ export interface EvaluationResult {
34
+ flags: Flags;
35
+ segments: Segments;
36
+ [k: string]: unknown;
37
+ }
38
+ /**
39
+ * Feature flags evaluated for the context, mapped by feature names.
40
+ */
41
+ export interface Flags {
42
+ [k: string]: FlagResult;
43
+ }
44
+ export interface FlagResult {
45
+ name: Name;
46
+ enabled: Enabled;
47
+ value: Value;
48
+ reason: Reason;
49
+ metadata?: FeatureMetadata;
50
+ [k: string]: unknown;
51
+ }
52
+ /**
53
+ * Additional metadata associated with the feature.
54
+ */
55
+ export interface FeatureMetadata {
56
+ [k: string]: unknown;
57
+ }
58
+ export interface SegmentResult {
59
+ name: Name1;
60
+ metadata?: SegmentMetadata;
61
+ [k: string]: unknown;
62
+ }
63
+ /**
64
+ * Additional metadata associated with the segment.
65
+ */
66
+ export interface SegmentMetadata {
67
+ [k: string]: unknown;
68
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ /* eslint-disable */
3
+ /**
4
+ * This file was automatically generated by json-schema-to-typescript.
5
+ * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
6
+ * and run json-schema-to-typescript to regenerate this file.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,50 @@
1
+ import type { FlagResult, FeatureMetadata, SegmentMetadata } from './evaluationResult/evaluationResult.types.js';
2
+ import type { FeatureContext, EnvironmentContext, IdentityContext, SegmentContext } from './evaluationContext/evaluationContext.types.js';
3
+ export * from './evaluationContext/evaluationContext.types.js';
4
+ export declare enum SegmentSource {
5
+ API = "api",
6
+ IDENTITY_OVERRIDE = "identity_override"
7
+ }
8
+ export interface SDKFeatureMetadata extends FeatureMetadata {
9
+ id: number;
10
+ }
11
+ export interface FeatureContextWithMetadata<T extends FeatureMetadata = FeatureMetadata> extends FeatureContext {
12
+ metadata: T;
13
+ [k: string]: unknown;
14
+ }
15
+ export type FeaturesWithMetadata<T extends FeatureMetadata = FeatureMetadata> = {
16
+ [k: string]: FeatureContextWithMetadata<T>;
17
+ };
18
+ export type FlagResultWithMetadata<T extends FeatureMetadata = FeatureMetadata> = FlagResult & {
19
+ metadata: T;
20
+ };
21
+ export type EvaluationResultFlags<T extends FeatureMetadata = FeatureMetadata> = Record<string, FlagResultWithMetadata<T>>;
22
+ export interface SDKSegmentMetadata extends SegmentMetadata {
23
+ id?: number;
24
+ source?: SegmentSource;
25
+ }
26
+ export interface SegmentContextWithMetadata<T extends SegmentMetadata = SegmentMetadata> extends SegmentContext {
27
+ metadata: T;
28
+ overrides?: FeatureContextWithMetadata<FeatureMetadata>[];
29
+ }
30
+ export type SegmentsWithMetadata<T extends SegmentMetadata = SegmentMetadata> = {
31
+ [k: string]: SegmentContextWithMetadata<T>;
32
+ };
33
+ export interface SegmentResultWithMetadata {
34
+ name: string;
35
+ metadata: SDKSegmentMetadata;
36
+ }
37
+ export type EvaluationResultSegments = SegmentResultWithMetadata[];
38
+ export interface GenericEvaluationContext<T extends FeatureMetadata = FeatureMetadata, S extends SegmentMetadata = SegmentMetadata> {
39
+ environment: EnvironmentContext;
40
+ identity?: IdentityContext | null;
41
+ segments?: SegmentsWithMetadata<S>;
42
+ features?: FeaturesWithMetadata<T>;
43
+ [k: string]: unknown;
44
+ }
45
+ export type EvaluationContextWithMetadata = GenericEvaluationContext<SDKFeatureMetadata, SDKSegmentMetadata>;
46
+ export type EvaluationResult<T extends FeatureMetadata = FeatureMetadata> = {
47
+ flags: EvaluationResultFlags<T>;
48
+ segments: EvaluationResultSegments;
49
+ };
50
+ export type EvaluationResultWithMetadata = EvaluationResult<SDKFeatureMetadata>;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ // This file is the entry point for the evaluation module types
3
+ // All types from evaluations should be at least imported here and re-exported
4
+ // Do not use types directly from generated files
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
17
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.SegmentSource = void 0;
21
+ __exportStar(require("./evaluationContext/evaluationContext.types.js"), exports);
22
+ var SegmentSource;
23
+ (function (SegmentSource) {
24
+ SegmentSource["API"] = "api";
25
+ SegmentSource["IDENTITY_OVERRIDE"] = "identity_override";
26
+ })(SegmentSource = exports.SegmentSource || (exports.SegmentSource = {}));
@@ -93,7 +93,7 @@ class FeatureStateModel {
93
93
  return myValue.multivariateFeatureOption.value;
94
94
  default:
95
95
  if (percentageValue === undefined) {
96
- percentageValue = (0, index_js_1.getHashedPercentateForObjIds)([
96
+ percentageValue = (0, index_js_1.getHashedPercentageForObjIds)([
97
97
  this.djangoID || this.featurestateUUID,
98
98
  identityID
99
99
  ]);
@@ -0,0 +1,5 @@
1
+ export declare enum TARGETING_REASONS {
2
+ DEFAULT = "DEFAULT",
3
+ TARGETING_MATCH = "TARGETING_MATCH",
4
+ SPLIT = "SPLIT"
5
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TARGETING_REASONS = void 0;
4
+ var TARGETING_REASONS;
5
+ (function (TARGETING_REASONS) {
6
+ TARGETING_REASONS["DEFAULT"] = "DEFAULT";
7
+ TARGETING_REASONS["TARGETING_MATCH"] = "TARGETING_MATCH";
8
+ TARGETING_REASONS["SPLIT"] = "SPLIT";
9
+ })(TARGETING_REASONS = exports.TARGETING_REASONS || (exports.TARGETING_REASONS = {}));
@@ -2,3 +2,4 @@ import { FeatureModel, FeatureSegment, FeatureStateModel } from './models.js';
2
2
  export declare function buildFeatureModel(featuresModelJSON: any): FeatureModel;
3
3
  export declare function buildFeatureStateModel(featuresStateModelJSON: any): FeatureStateModel;
4
4
  export declare function buildFeatureSegment(featureSegmentJSON: any): FeatureSegment;
5
+ export declare function uuidToBigInt(uuid: string): BigInt;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildFeatureSegment = exports.buildFeatureStateModel = exports.buildFeatureModel = void 0;
3
+ exports.uuidToBigInt = exports.buildFeatureSegment = exports.buildFeatureStateModel = exports.buildFeatureModel = void 0;
4
4
  const models_js_1 = require("./models.js");
5
5
  function buildFeatureModel(featuresModelJSON) {
6
6
  return new models_js_1.FeatureModel(featuresModelJSON.id, featuresModelJSON.name, featuresModelJSON.type);
@@ -25,3 +25,7 @@ function buildFeatureSegment(featureSegmentJSON) {
25
25
  return new models_js_1.FeatureSegment(featureSegmentJSON.priority);
26
26
  }
27
27
  exports.buildFeatureSegment = buildFeatureSegment;
28
+ function uuidToBigInt(uuid) {
29
+ return BigInt('0x' + uuid.replace(/-/g, ''));
30
+ }
31
+ exports.uuidToBigInt = uuidToBigInt;
@@ -1,14 +1,66 @@
1
- import { EnvironmentModel } from './environments/models.js';
2
- import { FeatureStateModel } from './features/models.js';
3
- import { IdentityModel } from './identities/models.js';
4
- import { TraitModel } from './identities/traits/models.js';
1
+ import { EvaluationContextWithMetadata, EvaluationResultSegments, EvaluationResultWithMetadata, FeatureContextWithMetadata, SDKFeatureMetadata } from './evaluation/models.js';
2
+ import { EvaluationResultFlags } from './evaluation/models.js';
5
3
  export { EnvironmentModel } from './environments/models.js';
6
- export { FeatureModel, FeatureStateModel } from './features/models.js';
7
4
  export { IdentityModel } from './identities/models.js';
8
5
  export { TraitModel } from './identities/traits/models.js';
9
6
  export { SegmentModel } from './segments/models.js';
7
+ export { FeatureModel, FeatureStateModel } from './features/models.js';
10
8
  export { OrganisationModel } from './organisations/models.js';
11
- export declare function getIdentityFeatureState(environment: EnvironmentModel, identity: IdentityModel, featureName: string, overrideTraits?: TraitModel[]): FeatureStateModel;
12
- export declare function getIdentityFeatureStates(environment: EnvironmentModel, identity: IdentityModel, overrideTraits?: TraitModel[]): FeatureStateModel[];
13
- export declare function getEnvironmentFeatureState(environment: EnvironmentModel, featureName: string): FeatureStateModel;
14
- export declare function getEnvironmentFeatureStates(environment: EnvironmentModel): FeatureStateModel[];
9
+ type SegmentOverride = {
10
+ feature: FeatureContextWithMetadata<SDKFeatureMetadata>;
11
+ segmentName: string;
12
+ };
13
+ export type SegmentOverrides = Record<string, SegmentOverride>;
14
+ /**
15
+ * Evaluates flags and segments for the given context.
16
+ *
17
+ * This is the main entry point for the evaluation engine. It processes segments,
18
+ * applies feature overrides based on segment priority, and returns the final flag states with
19
+ * evaluation reasons.
20
+ *
21
+ * @param context - EvaluationContext containing environment, identity, and segment data
22
+ * @returns EvaluationResult with flags, segments, and original context
23
+ */
24
+ export declare function getEvaluationResult(context: EvaluationContextWithMetadata): EvaluationResultWithMetadata;
25
+ /**
26
+ * Evaluates which segments the identity belongs to and collects feature overrides.
27
+ *
28
+ * @param context - EvaluationContext containing identity and segment definitions
29
+ * @returns Object containing segments the identity belongs to and any feature overrides
30
+ */
31
+ export declare function evaluateSegments(context: EvaluationContextWithMetadata): {
32
+ segments: EvaluationResultSegments;
33
+ segmentOverrides: Record<string, SegmentOverride>;
34
+ };
35
+ /**
36
+ * Processes feature overrides from segments, applying priority rules.
37
+ *
38
+ * When multiple segments override the same feature, the segment with
39
+ * higher priority (lower numeric value) takes precedence.
40
+ *
41
+ * @param identitySegments - Segments that the identity belongs to
42
+ * @returns Map of feature keys to their highest-priority segment overrides
43
+ */
44
+ export declare function processSegmentOverrides(identitySegments: any[]): Record<string, SegmentOverride>;
45
+ /**
46
+ * Evaluates all features in the context, applying segment overrides where applicable.
47
+ * For each feature:
48
+ * - Checks if a segment override exists
49
+ * - Uses override values if present, otherwise evaluates the base feature
50
+ * - Determines appropriate evaluation reason
51
+ * - Handles multivariate evaluation for features without overrides
52
+ *
53
+ * @param context - EvaluationContext containing features and identity
54
+ * @param segmentOverrides - Map of feature keys to their segment overrides
55
+ * @returns EvaluationResultFlags containing evaluated flag results
56
+ */
57
+ export declare function evaluateFeatures(context: EvaluationContextWithMetadata, segmentOverrides: Record<string, SegmentOverride>): EvaluationResultFlags<SDKFeatureMetadata>;
58
+ export declare function shouldApplyOverride(override: any, existingOverrides: Record<string, SegmentOverride>): boolean;
59
+ export declare function isHigherPriority(priorityA: number | undefined, priorityB: number | undefined): boolean;
60
+ export type TargetingMatchReason = {
61
+ type: 'SEGMENT';
62
+ override: SegmentOverride;
63
+ } | {
64
+ type: 'SPLIT';
65
+ weight: number;
66
+ };