@openfeature/server-sdk 1.20.1 → 1.21.0
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.
- package/README.md +74 -52
- package/dist/cjs/index.js +88 -266
- package/dist/cjs/index.js.map +4 -4
- package/dist/esm/index.js +77 -246
- package/dist/esm/index.js.map +4 -4
- package/dist/types.d.ts +190 -145
- package/package.json +5 -4
package/dist/types.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { BaseHook, FlagValue, EvaluationContext, HookHints, EvaluationDetails, JsonValue, CommonProvider, ServerProviderStatus, Logger, ResolutionDetails, GenericEventEmitter, ServerProviderEvents,
|
|
1
|
+
import { BaseHook, FlagValue, EvaluationContext, BooleanFlagKey, HookHints, EvaluationDetails, StringFlagKey, NumberFlagKey, ObjectFlagKey, JsonValue, CommonProvider, ServerProviderStatus, Logger, ResolutionDetails, GenericEventEmitter, ServerProviderEvents, ProviderEntryInput, ProviderMetadata, RegisteredProvider, BaseEvaluationStrategy, TrackingEventDetails, BaseStrategyProviderContext, BaseStrategyPerProviderContext, BaseProviderResolutionResult, BaseProviderResolutionSuccessResult, BaseProviderResolutionErrorResult, BaseFinalResult, BaseFirstMatchStrategy, BaseFirstSuccessfulStrategy, BaseComparisonStrategy, EvaluationLifeCycle, ManageContext, ManageLogger, Eventing, ClientMetadata, OpenFeatureCommonAPI, ProviderWrapper } from '@openfeature/core';
|
|
2
2
|
export * from '@openfeature/core';
|
|
3
|
-
export { ServerProviderEvents as ProviderEvents, ServerProviderStatus as ProviderStatus } from '@openfeature/core';
|
|
3
|
+
export { ServerProviderEvents as ProviderEvents, ServerProviderStatus as ProviderStatus, StrategyEvaluationContext } from '@openfeature/core';
|
|
4
4
|
import { EventEmitter } from 'node:events';
|
|
5
5
|
|
|
6
6
|
type Hook<TData = Record<string, unknown>> = BaseHook<FlagValue, TData, Promise<EvaluationContext | void> | EvaluationContext | void, Promise<void> | void>;
|
|
7
7
|
|
|
8
|
+
type ConstrainedFlagKey<T> = T extends boolean ? BooleanFlagKey : T extends number ? NumberFlagKey : T extends string ? StringFlagKey : T extends JsonValue ? ObjectFlagKey : never;
|
|
8
9
|
interface FlagEvaluationOptions {
|
|
9
10
|
hooks?: Hook[];
|
|
10
11
|
hookHints?: HookHints;
|
|
@@ -12,88 +13,88 @@ interface FlagEvaluationOptions {
|
|
|
12
13
|
interface Features {
|
|
13
14
|
/**
|
|
14
15
|
* Performs a flag evaluation that returns a boolean.
|
|
15
|
-
* @param {
|
|
16
|
+
* @param {BooleanFlagKey} flagKey The flag key uniquely identifies a particular flag
|
|
16
17
|
* @param {boolean} defaultValue The value returned if an error occurs
|
|
17
18
|
* @param {EvaluationContext} context The evaluation context used on an individual flag evaluation
|
|
18
19
|
* @param {FlagEvaluationOptions} options Additional flag evaluation options
|
|
19
20
|
* @returns {Promise<boolean>} Flag evaluation response
|
|
20
21
|
*/
|
|
21
|
-
getBooleanValue(flagKey:
|
|
22
|
+
getBooleanValue(flagKey: BooleanFlagKey, defaultValue: boolean, context?: EvaluationContext, options?: FlagEvaluationOptions): Promise<boolean>;
|
|
22
23
|
/**
|
|
23
24
|
* Performs a flag evaluation that a returns an evaluation details object.
|
|
24
|
-
* @param {
|
|
25
|
+
* @param {BooleanFlagKey} flagKey The flag key uniquely identifies a particular flag
|
|
25
26
|
* @param {boolean} defaultValue The value returned if an error occurs
|
|
26
27
|
* @param {EvaluationContext} context The evaluation context used on an individual flag evaluation
|
|
27
28
|
* @param {FlagEvaluationOptions} options Additional flag evaluation options
|
|
28
29
|
* @returns {Promise<EvaluationDetails<boolean>>} Flag evaluation details response
|
|
29
30
|
*/
|
|
30
|
-
getBooleanDetails(flagKey:
|
|
31
|
+
getBooleanDetails(flagKey: BooleanFlagKey, defaultValue: boolean, context?: EvaluationContext, options?: FlagEvaluationOptions): Promise<EvaluationDetails<boolean>>;
|
|
31
32
|
/**
|
|
32
33
|
* Performs a flag evaluation that returns a string.
|
|
33
|
-
* @param {
|
|
34
|
+
* @param {StringFlagKey} flagKey The flag key uniquely identifies a particular flag
|
|
34
35
|
* @template {string} T A optional generic argument constraining the string
|
|
35
36
|
* @param {T} defaultValue The value returned if an error occurs
|
|
36
37
|
* @param {EvaluationContext} context The evaluation context used on an individual flag evaluation
|
|
37
38
|
* @param {FlagEvaluationOptions} options Additional flag evaluation options
|
|
38
39
|
* @returns {Promise<T>} Flag evaluation response
|
|
39
40
|
*/
|
|
40
|
-
getStringValue(flagKey:
|
|
41
|
-
getStringValue<T extends string = string>(flagKey:
|
|
41
|
+
getStringValue(flagKey: StringFlagKey, defaultValue: string, context?: EvaluationContext, options?: FlagEvaluationOptions): Promise<string>;
|
|
42
|
+
getStringValue<T extends string = string>(flagKey: StringFlagKey, defaultValue: T, context?: EvaluationContext, options?: FlagEvaluationOptions): Promise<T>;
|
|
42
43
|
/**
|
|
43
44
|
* Performs a flag evaluation that a returns an evaluation details object.
|
|
44
|
-
* @param {
|
|
45
|
+
* @param {StringFlagKey} flagKey The flag key uniquely identifies a particular flag
|
|
45
46
|
* @template {string} T A optional generic argument constraining the string
|
|
46
47
|
* @param {T} defaultValue The value returned if an error occurs
|
|
47
48
|
* @param {EvaluationContext} context The evaluation context used on an individual flag evaluation
|
|
48
49
|
* @param {FlagEvaluationOptions} options Additional flag evaluation options
|
|
49
50
|
* @returns {Promise<EvaluationDetails<T>>} Flag evaluation details response
|
|
50
51
|
*/
|
|
51
|
-
getStringDetails(flagKey:
|
|
52
|
-
getStringDetails<T extends string = string>(flagKey:
|
|
52
|
+
getStringDetails(flagKey: StringFlagKey, defaultValue: string, context?: EvaluationContext, options?: FlagEvaluationOptions): Promise<EvaluationDetails<string>>;
|
|
53
|
+
getStringDetails<T extends string = string>(flagKey: StringFlagKey, defaultValue: T, context?: EvaluationContext, options?: FlagEvaluationOptions): Promise<EvaluationDetails<T>>;
|
|
53
54
|
/**
|
|
54
55
|
* Performs a flag evaluation that returns a number.
|
|
55
|
-
* @param {
|
|
56
|
+
* @param {NumberFlagKey} flagKey The flag key uniquely identifies a particular flag
|
|
56
57
|
* @template {number} T A optional generic argument constraining the number
|
|
57
58
|
* @param {T} defaultValue The value returned if an error occurs
|
|
58
59
|
* @param {EvaluationContext} context The evaluation context used on an individual flag evaluation
|
|
59
60
|
* @param {FlagEvaluationOptions} options Additional flag evaluation options
|
|
60
61
|
* @returns {Promise<T>} Flag evaluation response
|
|
61
62
|
*/
|
|
62
|
-
getNumberValue(flagKey:
|
|
63
|
-
getNumberValue<T extends number = number>(flagKey:
|
|
63
|
+
getNumberValue(flagKey: NumberFlagKey, defaultValue: number, context?: EvaluationContext, options?: FlagEvaluationOptions): Promise<number>;
|
|
64
|
+
getNumberValue<T extends number = number>(flagKey: NumberFlagKey, defaultValue: T, context?: EvaluationContext, options?: FlagEvaluationOptions): Promise<T>;
|
|
64
65
|
/**
|
|
65
66
|
* Performs a flag evaluation that a returns an evaluation details object.
|
|
66
|
-
* @param {
|
|
67
|
+
* @param {NumberFlagKey} flagKey The flag key uniquely identifies a particular flag
|
|
67
68
|
* @template {number} T A optional generic argument constraining the number
|
|
68
69
|
* @param {T} defaultValue The value returned if an error occurs
|
|
69
70
|
* @param {EvaluationContext} context The evaluation context used on an individual flag evaluation
|
|
70
71
|
* @param {FlagEvaluationOptions} options Additional flag evaluation options
|
|
71
72
|
* @returns {Promise<EvaluationDetails<T>>} Flag evaluation details response
|
|
72
73
|
*/
|
|
73
|
-
getNumberDetails(flagKey:
|
|
74
|
-
getNumberDetails<T extends number = number>(flagKey:
|
|
74
|
+
getNumberDetails(flagKey: NumberFlagKey, defaultValue: number, context?: EvaluationContext, options?: FlagEvaluationOptions): Promise<EvaluationDetails<number>>;
|
|
75
|
+
getNumberDetails<T extends number = number>(flagKey: NumberFlagKey, defaultValue: T, context?: EvaluationContext, options?: FlagEvaluationOptions): Promise<EvaluationDetails<T>>;
|
|
75
76
|
/**
|
|
76
77
|
* Performs a flag evaluation that returns an object.
|
|
77
|
-
* @param {
|
|
78
|
+
* @param {ObjectFlagKey} flagKey The flag key uniquely identifies a particular flag
|
|
78
79
|
* @template {JsonValue} T A optional generic argument describing the structure
|
|
79
80
|
* @param {T} defaultValue The value returned if an error occurs
|
|
80
81
|
* @param {EvaluationContext} context The evaluation context used on an individual flag evaluation
|
|
81
82
|
* @param {FlagEvaluationOptions} options Additional flag evaluation options
|
|
82
83
|
* @returns {Promise<T>} Flag evaluation response
|
|
83
84
|
*/
|
|
84
|
-
getObjectValue(flagKey:
|
|
85
|
-
getObjectValue<T extends JsonValue = JsonValue>(flagKey:
|
|
85
|
+
getObjectValue(flagKey: ObjectFlagKey, defaultValue: JsonValue, context?: EvaluationContext, options?: FlagEvaluationOptions): Promise<JsonValue>;
|
|
86
|
+
getObjectValue<T extends JsonValue = JsonValue>(flagKey: ObjectFlagKey, defaultValue: T, context?: EvaluationContext, options?: FlagEvaluationOptions): Promise<T>;
|
|
86
87
|
/**
|
|
87
88
|
* Performs a flag evaluation that a returns an evaluation details object.
|
|
88
|
-
* @param {
|
|
89
|
+
* @param {ObjectFlagKey} flagKey The flag key uniquely identifies a particular flag
|
|
89
90
|
* @template {JsonValue} T A optional generic argument describing the structure
|
|
90
91
|
* @param {T} defaultValue The value returned if an error occurs
|
|
91
92
|
* @param {EvaluationContext} context The evaluation context used on an individual flag evaluation
|
|
92
93
|
* @param {FlagEvaluationOptions} options Additional flag evaluation options
|
|
93
94
|
* @returns {Promise<EvaluationDetails<T>>} Flag evaluation details response
|
|
94
95
|
*/
|
|
95
|
-
getObjectDetails(flagKey:
|
|
96
|
-
getObjectDetails<T extends JsonValue = JsonValue>(flagKey:
|
|
96
|
+
getObjectDetails(flagKey: ObjectFlagKey, defaultValue: JsonValue, context?: EvaluationContext, options?: FlagEvaluationOptions): Promise<EvaluationDetails<JsonValue>>;
|
|
97
|
+
getObjectDetails<T extends JsonValue = JsonValue>(flagKey: ObjectFlagKey, defaultValue: T, context?: EvaluationContext, options?: FlagEvaluationOptions): Promise<EvaluationDetails<T>>;
|
|
97
98
|
}
|
|
98
99
|
|
|
99
100
|
/**
|
|
@@ -149,19 +150,23 @@ declare const NOOP_PROVIDER: NoopFeatureProvider;
|
|
|
149
150
|
* but just for the in-memory provider.
|
|
150
151
|
*/
|
|
151
152
|
|
|
152
|
-
type
|
|
153
|
+
type NoInfer<T> = [T][T extends unknown ? 0 : never];
|
|
154
|
+
type Simplify<T> = {
|
|
155
|
+
[K in keyof T]: T[K];
|
|
156
|
+
} & {};
|
|
157
|
+
type FlagVariants<T extends string> = Record<T, boolean> | Record<T, string> | Record<T, number> | Record<T, JsonValue>;
|
|
153
158
|
/**
|
|
154
159
|
* A Feature Flag definition, containing it's specification
|
|
155
160
|
*/
|
|
156
|
-
type Flag = {
|
|
161
|
+
type Flag<T extends string = string> = {
|
|
157
162
|
/**
|
|
158
163
|
* An object containing all possible flags mappings (variant -> flag value)
|
|
159
164
|
*/
|
|
160
|
-
variants:
|
|
165
|
+
variants: FlagVariants<T>;
|
|
161
166
|
/**
|
|
162
167
|
* The variant it will resolve to in STATIC evaluation
|
|
163
168
|
*/
|
|
164
|
-
defaultVariant:
|
|
169
|
+
defaultVariant: NoInfer<T>;
|
|
165
170
|
/**
|
|
166
171
|
* Determines if flag evaluation is enabled or not for this flag.
|
|
167
172
|
* If false, falls back to the default value provided to the client
|
|
@@ -173,12 +178,22 @@ type Flag = {
|
|
|
173
178
|
* If it does not return a valid variant it falls back to the default value provided to the client
|
|
174
179
|
* @param EvaluationContext
|
|
175
180
|
*/
|
|
176
|
-
contextEvaluator?: (ctx: EvaluationContext) =>
|
|
181
|
+
contextEvaluator?: (ctx: EvaluationContext) => NoInfer<T>;
|
|
182
|
+
};
|
|
183
|
+
/**
|
|
184
|
+
* The configuration object for the InMemoryProvider, containing all flags and their specifications.
|
|
185
|
+
*
|
|
186
|
+
* The generic ensures that the keys of the `variants` object in each flag specification are consistent with the `defaultVariant` and the return type of `contextEvaluator`.
|
|
187
|
+
*/
|
|
188
|
+
type FlagConfiguration<T extends Record<string, FlagVariants<string>> = Record<string, FlagVariants<string>>> = {
|
|
189
|
+
[K in keyof T]: Simplify<{
|
|
190
|
+
variants: T[K];
|
|
191
|
+
} & Omit<Flag<keyof T[K] & string>, 'variants'>>;
|
|
177
192
|
};
|
|
178
|
-
type FlagConfiguration = Record<string, Flag>;
|
|
179
193
|
|
|
180
194
|
/**
|
|
181
195
|
* A simple OpenFeature provider intended for demos and as a test stub.
|
|
196
|
+
* @deprecated Use {@link TypedInMemoryProvider} for type-safe flag configuration.
|
|
182
197
|
*/
|
|
183
198
|
declare class InMemoryProvider implements Provider {
|
|
184
199
|
readonly events: OpenFeatureEventEmitter;
|
|
@@ -200,114 +215,124 @@ declare class InMemoryProvider implements Provider {
|
|
|
200
215
|
private resolveFlagWithReason;
|
|
201
216
|
private lookupFlagValue;
|
|
202
217
|
}
|
|
203
|
-
|
|
204
218
|
/**
|
|
205
|
-
*
|
|
206
|
-
*
|
|
219
|
+
* A simple OpenFeature provider intended for demos and as a test stub.
|
|
220
|
+
* @example
|
|
221
|
+
* ```
|
|
222
|
+
* const provider = new TypedInMemoryProvider({
|
|
223
|
+
* 'my-flag': {
|
|
224
|
+
* variants: { on: true, off: false },
|
|
225
|
+
* defaultVariant: 'on',
|
|
226
|
+
* contextEvaluator: (ctx) => ctx?.user?.id === '123' ? 'on' : 'off',
|
|
227
|
+
* disabled: false,
|
|
228
|
+
* },
|
|
229
|
+
* });
|
|
207
230
|
*
|
|
208
|
-
*
|
|
209
|
-
*
|
|
231
|
+
* const flags = {
|
|
232
|
+
* 'my-flag': {
|
|
233
|
+
* variants: { on: true, off: false },
|
|
234
|
+
* defaultVariant: 'on',
|
|
235
|
+
* contextEvaluator: (ctx) => ctx?.user?.id === '123' ? 'on' : 'off',
|
|
236
|
+
* disabled: false,
|
|
237
|
+
* },
|
|
238
|
+
* } as const; // 'as const' needed to preserve the `defaultVariant` narrow literal type rather than `string`
|
|
239
|
+
* const provider = new TypedInMemoryProvider(flags);
|
|
240
|
+
* ```
|
|
210
241
|
*/
|
|
211
|
-
declare class
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
provider?: Provider;
|
|
240
|
-
providerName?: string;
|
|
241
|
-
errors?: {
|
|
242
|
-
providerName: string;
|
|
243
|
-
error: unknown;
|
|
244
|
-
}[];
|
|
245
|
-
};
|
|
246
|
-
/**
|
|
247
|
-
* Base strategy to inherit from. Not directly usable, as strategies must implement the "determineResult" method
|
|
248
|
-
* Contains default implementations for `shouldEvaluateThisProvider` and `shouldEvaluateNextProvider`
|
|
249
|
-
*/
|
|
250
|
-
declare abstract class BaseEvaluationStrategy {
|
|
251
|
-
runMode: 'parallel' | 'sequential';
|
|
252
|
-
shouldEvaluateThisProvider(strategyContext: StrategyPerProviderContext, _evalContext?: EvaluationContext): boolean;
|
|
253
|
-
shouldEvaluateNextProvider<T extends FlagValue>(_strategyContext?: StrategyPerProviderContext, _context?: EvaluationContext, _result?: ProviderResolutionResult<T>): boolean;
|
|
254
|
-
shouldTrackWithThisProvider(strategyContext: StrategyProviderContext, _context?: EvaluationContext, _trackingEventName?: string, _trackingEventDetails?: TrackingEventDetails): boolean;
|
|
255
|
-
abstract determineFinalResult<T extends FlagValue>(strategyContext: StrategyEvaluationContext, context: EvaluationContext, resolutions: ProviderResolutionResult<T>[]): FinalResult<T>;
|
|
256
|
-
protected hasError(resolution: ProviderResolutionResult<FlagValue>): resolution is ProviderResolutionErrorResult | (ProviderResolutionSuccessResult<FlagValue> & {
|
|
257
|
-
details: ResolutionDetails<FlagValue> & {
|
|
258
|
-
errorCode: ErrorCode;
|
|
259
|
-
};
|
|
260
|
-
});
|
|
261
|
-
protected hasErrorWithCode(resolution: ProviderResolutionResult<FlagValue>, code: ErrorCode): boolean;
|
|
262
|
-
protected collectProviderErrors<T extends FlagValue>(resolutions: ProviderResolutionResult<T>[]): FinalResult<T>;
|
|
263
|
-
protected resolutionToFinalResult<T extends FlagValue>(resolution: ProviderResolutionSuccessResult<T>): {
|
|
264
|
-
details: ResolutionDetails<T>;
|
|
265
|
-
provider: Provider;
|
|
266
|
-
providerName: string;
|
|
267
|
-
};
|
|
242
|
+
declare class TypedInMemoryProvider<T extends Record<string, FlagVariants<string>> = Record<string, FlagVariants<string>>> extends InMemoryProvider {
|
|
243
|
+
constructor(flagConfiguration?: FlagConfiguration<T>);
|
|
244
|
+
/**
|
|
245
|
+
* Overwrites the configured flags.
|
|
246
|
+
* @param { FlagConfiguration } flagConfiguration new flag configuration
|
|
247
|
+
* @example
|
|
248
|
+
* ```
|
|
249
|
+
* provider.putConfiguration({
|
|
250
|
+
* 'my-flag': {
|
|
251
|
+
* variants: { on: true, off: false },
|
|
252
|
+
* defaultVariant: 'on',
|
|
253
|
+
* contextEvaluator: (ctx) => ctx?.user?.id === '123' ? 'on' : 'off',
|
|
254
|
+
* disabled: false,
|
|
255
|
+
* },
|
|
256
|
+
* });
|
|
257
|
+
*
|
|
258
|
+
* const flags = {
|
|
259
|
+
* 'my-flag': {
|
|
260
|
+
* variants: { on: true, off: false },
|
|
261
|
+
* defaultVariant: 'on',
|
|
262
|
+
* contextEvaluator: (ctx) => ctx?.user?.id === '123' ? 'on' : 'off',
|
|
263
|
+
* disabled: false,
|
|
264
|
+
* },
|
|
265
|
+
* } as const; // 'as const' needed to preserve the `defaultVariant` narrow literal type rather than `string`
|
|
266
|
+
* provider.putConfiguration(flags);
|
|
267
|
+
* ```
|
|
268
|
+
*/
|
|
269
|
+
putConfiguration<U extends Record<string, FlagVariants<string>> = Record<string, FlagVariants<string>>>(flagConfiguration: FlagConfiguration<U>): void;
|
|
268
270
|
}
|
|
269
|
-
|
|
270
271
|
/**
|
|
271
|
-
*
|
|
272
|
-
*
|
|
272
|
+
* The variants object for a flag in the {@link TypedInMemoryProvider}, containing all possible variants and their associated values.
|
|
273
|
+
*
|
|
274
|
+
* Can be used in combination with {@link InMemoryFlagConfiguration} to preserve type-safety when extending the provider class.
|
|
275
|
+
* @example
|
|
276
|
+
* ```
|
|
277
|
+
* export class CustomInMemoryProvider<
|
|
278
|
+
* T extends Record<string, InMemoryFlagVariants<string>> = Record<string, InMemoryFlagVariants<string>>,
|
|
279
|
+
* > extends TypedInMemoryProvider<T> {
|
|
280
|
+
* constructor(flagConfiguration: InMemoryFlagConfiguration<T>) {
|
|
281
|
+
* super(flagConfiguration);
|
|
282
|
+
* // custom logic ...
|
|
283
|
+
* }
|
|
284
|
+
*
|
|
285
|
+
* override putConfiguration<
|
|
286
|
+
* U extends Record<string, InMemoryFlagVariants<string>> = Record<string, InMemoryFlagVariants<string>>,
|
|
287
|
+
* >(flagConfiguration: InMemoryFlagConfiguration<U>) {
|
|
288
|
+
* super.putConfiguration(flagConfiguration);
|
|
289
|
+
* // custom logic ...
|
|
290
|
+
* }
|
|
291
|
+
* }
|
|
292
|
+
* ```
|
|
273
293
|
*/
|
|
274
|
-
|
|
275
|
-
shouldEvaluateNextProvider<T extends FlagValue>(strategyContext: StrategyPerProviderContext, context: EvaluationContext, result: ProviderResolutionResult<T>): boolean;
|
|
276
|
-
determineFinalResult<T extends FlagValue>(strategyContext: StrategyPerProviderContext, context: EvaluationContext, resolutions: ProviderResolutionResult<T>[]): FinalResult<T>;
|
|
277
|
-
}
|
|
278
|
-
|
|
294
|
+
type InMemoryFlagVariants<T extends string> = FlagVariants<T>;
|
|
279
295
|
/**
|
|
280
|
-
*
|
|
281
|
-
*
|
|
282
|
-
*
|
|
296
|
+
* The configuration object for the {@link TypedInMemoryProvider}, containing all flags and their specifications.
|
|
297
|
+
*
|
|
298
|
+
* Can be used in combination with {@link InMemoryFlagVariants} to preserve type-safety when extending the provider class.
|
|
299
|
+
*
|
|
300
|
+
* The generic ensures that the keys of the `variants` object in each flag specification are consistent with the `defaultVariant` and the return type of `contextEvaluator`.
|
|
301
|
+
* @example
|
|
302
|
+
* ```
|
|
303
|
+
* export class CustomInMemoryProvider<
|
|
304
|
+
* T extends Record<string, InMemoryFlagVariants<string>> = Record<string, InMemoryFlagVariants<string>>,
|
|
305
|
+
* > extends TypedInMemoryProvider<T> {
|
|
306
|
+
* constructor(flagConfiguration: InMemoryFlagConfiguration<T>) {
|
|
307
|
+
* super(flagConfiguration);
|
|
308
|
+
* // custom logic ...
|
|
309
|
+
* }
|
|
310
|
+
*
|
|
311
|
+
* override putConfiguration<
|
|
312
|
+
* U extends Record<string, InMemoryFlagVariants<string>> = Record<string, InMemoryFlagVariants<string>>,
|
|
313
|
+
* >(flagConfiguration: InMemoryFlagConfiguration<U>) {
|
|
314
|
+
* super.putConfiguration(flagConfiguration);
|
|
315
|
+
* // custom logic ...
|
|
316
|
+
* }
|
|
317
|
+
* }
|
|
318
|
+
* ```
|
|
283
319
|
*/
|
|
284
|
-
|
|
285
|
-
shouldEvaluateNextProvider<T extends FlagValue>(strategyContext: StrategyPerProviderContext, context: EvaluationContext, result: ProviderResolutionResult<T>): boolean;
|
|
286
|
-
determineFinalResult<T extends FlagValue>(strategyContext: StrategyPerProviderContext, context: EvaluationContext, resolutions: ProviderResolutionResult<T>[]): FinalResult<T>;
|
|
287
|
-
}
|
|
320
|
+
type InMemoryFlagConfiguration<T extends Record<string, FlagVariants<string>> = Record<string, FlagVariants<string>>> = FlagConfiguration<T>;
|
|
288
321
|
|
|
289
322
|
/**
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
*
|
|
323
|
+
* The OpenFeatureEventEmitter can be used by provider developers to emit
|
|
324
|
+
* events at various parts of the provider lifecycle.
|
|
325
|
+
*
|
|
326
|
+
* NOTE: Ready and error events are automatically emitted by the SDK based on
|
|
327
|
+
* the result of the initialize method.
|
|
294
328
|
*/
|
|
295
|
-
declare class
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
runMode: "parallel";
|
|
299
|
-
constructor(fallbackProvider: Provider, onMismatch?: ((resolutions: ProviderResolutionResult<FlagValue>[]) => void) | undefined);
|
|
300
|
-
determineFinalResult<T extends FlagValue>(strategyContext: StrategyPerProviderContext, context: EvaluationContext, resolutions: ProviderResolutionResult<T>[]): FinalResult<T>;
|
|
329
|
+
declare class OpenFeatureEventEmitter extends GenericEventEmitter<ServerProviderEvents> {
|
|
330
|
+
protected readonly eventEmitter: EventEmitter<[never]>;
|
|
331
|
+
constructor();
|
|
301
332
|
}
|
|
302
333
|
|
|
303
|
-
type ProviderEntryInput = {
|
|
304
|
-
provider: Provider;
|
|
305
|
-
name?: string;
|
|
306
|
-
};
|
|
307
|
-
type RegisteredProvider = Required<ProviderEntryInput>;
|
|
308
|
-
|
|
309
334
|
declare class MultiProvider implements Provider {
|
|
310
|
-
readonly constructorProviders: ProviderEntryInput[];
|
|
335
|
+
readonly constructorProviders: ProviderEntryInput<Provider>[];
|
|
311
336
|
private readonly evaluationStrategy;
|
|
312
337
|
private readonly logger;
|
|
313
338
|
readonly runsOn = "server";
|
|
@@ -315,11 +340,11 @@ declare class MultiProvider implements Provider {
|
|
|
315
340
|
private hookContexts;
|
|
316
341
|
private hookHints;
|
|
317
342
|
metadata: ProviderMetadata;
|
|
318
|
-
providerEntries: RegisteredProvider[];
|
|
343
|
+
providerEntries: RegisteredProvider<Provider>[];
|
|
319
344
|
private providerEntriesByName;
|
|
320
345
|
private hookExecutor;
|
|
321
346
|
private statusTracker;
|
|
322
|
-
constructor(constructorProviders: ProviderEntryInput[], evaluationStrategy?: BaseEvaluationStrategy, logger?: Logger);
|
|
347
|
+
constructor(constructorProviders: ProviderEntryInput<Provider>[], evaluationStrategy?: BaseEvaluationStrategy<ServerProviderStatus, Provider>, logger?: Logger);
|
|
323
348
|
private registerProviders;
|
|
324
349
|
initialize(context?: EvaluationContext): Promise<void>;
|
|
325
350
|
onClose(): Promise<void>;
|
|
@@ -336,25 +361,45 @@ declare class MultiProvider implements Provider {
|
|
|
336
361
|
private getErrorEvaluationDetails;
|
|
337
362
|
}
|
|
338
363
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
364
|
+
/**
|
|
365
|
+
* Pre-configured strategy exports for the server SDK.
|
|
366
|
+
* These classes extend the base strategies from @openfeature/core with the
|
|
367
|
+
* server-specific ProviderStatus enum already bound.
|
|
368
|
+
*/
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Pre-bound type aliases for server SDK.
|
|
372
|
+
* These types have the server-specific ProviderStatus and Provider types already applied,
|
|
373
|
+
* providing backward compatibility for existing consumers.
|
|
374
|
+
*/
|
|
375
|
+
type StrategyProviderContext = BaseStrategyProviderContext<ServerProviderStatus, Provider>;
|
|
376
|
+
type StrategyPerProviderContext = BaseStrategyPerProviderContext<ServerProviderStatus, Provider>;
|
|
377
|
+
type ProviderResolutionResult<T extends FlagValue> = BaseProviderResolutionResult<T, ServerProviderStatus, Provider>;
|
|
378
|
+
type ProviderResolutionSuccessResult<T extends FlagValue> = BaseProviderResolutionSuccessResult<T, ServerProviderStatus, Provider>;
|
|
379
|
+
type ProviderResolutionErrorResult = BaseProviderResolutionErrorResult<ServerProviderStatus, Provider>;
|
|
380
|
+
type FinalResult<T extends FlagValue> = BaseFinalResult<T, ServerProviderStatus, Provider>;
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Evaluates providers in order and returns the first successful result.
|
|
384
|
+
* Providers that return FLAG_NOT_FOUND are skipped. Any other error stops evaluation.
|
|
385
|
+
*/
|
|
386
|
+
declare class FirstMatchStrategy extends BaseFirstMatchStrategy<ServerProviderStatus, Provider> {
|
|
387
|
+
constructor();
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Evaluates providers in order and returns the first successful result.
|
|
391
|
+
* Any error causes that provider to be skipped.
|
|
392
|
+
*/
|
|
393
|
+
declare class FirstSuccessfulStrategy extends BaseFirstSuccessfulStrategy<ServerProviderStatus, Provider> {
|
|
394
|
+
constructor();
|
|
342
395
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
constructor(
|
|
349
|
-
source: string;
|
|
350
|
-
error: unknown;
|
|
351
|
-
}[]);
|
|
396
|
+
/**
|
|
397
|
+
* Evaluates all providers in parallel and compares results.
|
|
398
|
+
* If all providers agree, returns that result. Otherwise, returns the fallback provider's result.
|
|
399
|
+
*/
|
|
400
|
+
declare class ComparisonStrategy extends BaseComparisonStrategy<ServerProviderStatus, Provider> {
|
|
401
|
+
constructor(fallbackProvider: Provider, onMismatch?: (resolutions: ProviderResolutionResult<FlagValue>[]) => void);
|
|
352
402
|
}
|
|
353
|
-
declare const constructAggregateError: (providerErrors: {
|
|
354
|
-
error: unknown;
|
|
355
|
-
providerName: string;
|
|
356
|
-
}[]) => AggregateError;
|
|
357
|
-
declare const throwAggregateErrorFromPromiseResults: (result: PromiseSettledResult<unknown>[], providerEntries: RegisteredProvider[]) => void;
|
|
358
403
|
|
|
359
404
|
interface Tracking {
|
|
360
405
|
/**
|
|
@@ -560,5 +605,5 @@ declare class OpenFeatureAPI extends OpenFeatureCommonAPI<ServerProviderStatus,
|
|
|
560
605
|
*/
|
|
561
606
|
declare const OpenFeature: OpenFeatureAPI;
|
|
562
607
|
|
|
563
|
-
export {
|
|
564
|
-
export type { Client, Features, FinalResult, FlagEvaluationOptions, Hook, ManageTransactionContextPropagator, Provider, ProviderResolutionErrorResult, ProviderResolutionResult, ProviderResolutionSuccessResult,
|
|
608
|
+
export { AsyncLocalStorageTransactionContextPropagator, ComparisonStrategy, FirstMatchStrategy, FirstSuccessfulStrategy, InMemoryProvider, MultiProvider, NOOP_PROVIDER, NOOP_TRANSACTION_CONTEXT_PROPAGATOR, OpenFeature, OpenFeatureAPI, OpenFeatureEventEmitter, TypedInMemoryProvider };
|
|
609
|
+
export type { Client, ConstrainedFlagKey, Features, FinalResult, FlagEvaluationOptions, Hook, InMemoryFlagConfiguration, InMemoryFlagVariants, ManageTransactionContextPropagator, Provider, ProviderResolutionErrorResult, ProviderResolutionResult, ProviderResolutionSuccessResult, StrategyPerProviderContext, StrategyProviderContext, Tracking, TransactionContext, TransactionContextPropagator };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfeature/server-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.21.0",
|
|
4
4
|
"description": "OpenFeature SDK for JavaScript",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"files": [
|
|
@@ -48,9 +48,10 @@
|
|
|
48
48
|
"node": ">=20"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@openfeature/core": "^1.
|
|
51
|
+
"@openfeature/core": "^1.10.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@openfeature/core": "^1.9.
|
|
55
|
-
}
|
|
54
|
+
"@openfeature/core": "^1.9.2"
|
|
55
|
+
},
|
|
56
|
+
"sideEffects": false
|
|
56
57
|
}
|