@openfeature/web-sdk 0.3.6-experimental → 0.3.7-experimental

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/dist/types.d.ts CHANGED
@@ -1,3 +1,22 @@
1
+ declare enum ProviderEvents {
2
+ /**
3
+ * The provider is ready to evaluate flags.
4
+ */
5
+ Ready = "PROVIDER_READY",
6
+ /**
7
+ * The provider is in an error state.
8
+ */
9
+ Error = "PROVIDER_ERROR",
10
+ /**
11
+ * The flag configuration in the source-of-truth has changed.
12
+ */
13
+ ConfigurationChanged = "PROVIDER_CONFIGURATION_CHANGED",
14
+ /**
15
+ * The provider's cached state is no longer valid and may not be up-to-date with the source of truth.
16
+ */
17
+ Stale = "PROVIDER_STALE"
18
+ }
19
+
1
20
  type EventMetadata = {
2
21
  [key: string]: string | boolean | number;
3
22
  };
@@ -29,24 +48,45 @@ interface Eventing {
29
48
  */
30
49
  getHandlers(eventType: ProviderEvents): EventHandler[];
31
50
  }
32
- declare enum ProviderEvents {
33
- /**
34
- * The provider is ready to evaluate flags.
35
- */
36
- Ready = "PROVIDER_READY",
37
- /**
38
- * The provider is in an error state.
39
- */
40
- Error = "PROVIDER_ERROR",
41
- /**
42
- * The flag configuration in the source-of-truth has changed.
43
- */
44
- ConfigurationChanged = "PROVIDER_CONFIGURATION_CHANGED",
51
+
52
+ interface Logger {
53
+ error(...args: unknown[]): void;
54
+ warn(...args: unknown[]): void;
55
+ info(...args: unknown[]): void;
56
+ debug(...args: unknown[]): void;
57
+ }
58
+ interface ManageLogger<T> {
45
59
  /**
46
- * The provider's cached state is no longer valid and may not be up-to-date with the source of truth.
60
+ * Sets a logger on this receiver. This logger supersedes to the global logger
61
+ * and is passed to various components in the SDK.
62
+ * The logger configured on the global API object will be used for all evaluations,
63
+ * unless overridden in a particular client.
64
+ * @template T The type of the receiver
65
+ * @param {Logger} logger The logger to be used
66
+ * @returns {T} The receiver (this object)
47
67
  */
48
- Stale = "PROVIDER_STALE"
68
+ setLogger(logger: Logger): T;
69
+ }
70
+
71
+ declare class DefaultLogger implements Logger {
72
+ error(...args: unknown[]): void;
73
+ warn(...args: unknown[]): void;
74
+ info(): void;
75
+ debug(): void;
76
+ }
77
+
78
+ declare const LOG_LEVELS: Array<keyof Logger>;
79
+ declare class SafeLogger implements Logger {
80
+ private readonly logger;
81
+ private readonly fallbackLogger;
82
+ constructor(logger: Logger);
83
+ error(...args: unknown[]): void;
84
+ warn(...args: unknown[]): void;
85
+ info(...args: unknown[]): void;
86
+ debug(...args: unknown[]): void;
87
+ private log;
49
88
  }
89
+
50
90
  declare class OpenFeatureEventEmitter implements ManageLogger<OpenFeatureEventEmitter> {
51
91
  private readonly globalLogger?;
52
92
  private readonly _handlers;
@@ -62,6 +102,10 @@ declare class OpenFeatureEventEmitter implements ManageLogger<OpenFeatureEventEm
62
102
  private get _logger();
63
103
  }
64
104
 
105
+ interface Metadata {
106
+ }
107
+
108
+ type FlagValueType = 'boolean' | 'string' | 'number' | 'object';
65
109
  type PrimitiveValue = null | boolean | string | number;
66
110
  type JsonObject = {
67
111
  [key: string]: JsonValue;
@@ -74,28 +118,26 @@ type JsonValue = PrimitiveValue | JsonObject | JsonArray;
74
118
  /**
75
119
  * Represents a JSON node value, or Date.
76
120
  */
77
- type EvaluationContextValue = PrimitiveValue | Date | {
78
- [key: string]: EvaluationContextValue;
79
- } | EvaluationContextValue[];
121
+ type FlagValue = boolean | string | number | JsonValue;
122
+ type ResolutionReason = keyof typeof StandardResolutionReasons | (string & Record<never, never>);
80
123
  /**
81
- * A container for arbitrary contextual data that can be used as a basis for dynamic evaluation
124
+ * A structure which supports definition of arbitrary properties, with keys of type string, and values of type boolean, string, or number.
125
+ *
126
+ * This structure is populated by a provider for use by an Application Author (via the Evaluation API) or an Application Integrator (via hooks).
82
127
  */
83
- type EvaluationContext = {
84
- /**
85
- * A string uniquely identifying the subject (end-user, or client service) of a flag evaluation.
86
- * Providers may require this field for fractional flag evaluation, rules, or overrides targeting specific users.
87
- * Such providers may behave unpredictably if a targeting key is not specified at flag resolution.
88
- */
89
- targetingKey?: string;
90
- } & Record<string, EvaluationContextValue>;
91
- type FlagValue = boolean | string | number | JsonValue;
92
- type FlagValueType = 'boolean' | 'string' | 'number' | 'object';
93
- interface Logger {
94
- error(...args: unknown[]): void;
95
- warn(...args: unknown[]): void;
96
- info(...args: unknown[]): void;
97
- debug(...args: unknown[]): void;
98
- }
128
+ type FlagMetadata = Record<string, string | number | boolean>;
129
+ type ResolutionDetails<U> = {
130
+ value: U;
131
+ variant?: string;
132
+ flagMetadata?: FlagMetadata;
133
+ reason?: ResolutionReason;
134
+ errorCode?: ErrorCode;
135
+ errorMessage?: string;
136
+ };
137
+ type EvaluationDetails<T extends FlagValue> = {
138
+ flagKey: string;
139
+ flagMetadata: Readonly<FlagMetadata>;
140
+ } & ResolutionDetails<T>;
99
141
  declare const StandardResolutionReasons: {
100
142
  /**
101
143
  * The resolved value was the result of a dynamic evaluation, such as a rule or specific user-targeting.
@@ -162,25 +204,21 @@ declare enum ErrorCode {
162
204
  */
163
205
  GENERAL = "GENERAL"
164
206
  }
165
- type ResolutionReason = keyof typeof StandardResolutionReasons | (string & Record<never, never>);
207
+
208
+ type EvaluationContextValue = PrimitiveValue | Date | {
209
+ [key: string]: EvaluationContextValue;
210
+ } | EvaluationContextValue[];
166
211
  /**
167
- * A structure which supports definition of arbitrary properties, with keys of type string, and values of type boolean, string, or number.
168
- *
169
- * This structure is populated by a provider for use by an Application Author (via the Evaluation API) or an Application Integrator (via hooks).
212
+ * A container for arbitrary contextual data that can be used as a basis for dynamic evaluation
170
213
  */
171
- type FlagMetadata = Record<string, string | number | boolean>;
172
- type ResolutionDetails<U> = {
173
- value: U;
174
- variant?: string;
175
- flagMetadata?: FlagMetadata;
176
- reason?: ResolutionReason;
177
- errorCode?: ErrorCode;
178
- errorMessage?: string;
179
- };
180
- type EvaluationDetails<T extends FlagValue> = {
181
- flagKey: string;
182
- flagMetadata: Readonly<FlagMetadata>;
183
- } & ResolutionDetails<T>;
214
+ type EvaluationContext = {
215
+ /**
216
+ * A string uniquely identifying the subject (end-user, or client service) of a flag evaluation.
217
+ * Providers may require this field for fractional flag evaluation, rules, or overrides targeting specific users.
218
+ * Such providers may behave unpredictably if a targeting key is not specified at flag resolution.
219
+ */
220
+ targetingKey?: string;
221
+ } & Record<string, EvaluationContextValue>;
184
222
  interface ManageContext<T> {
185
223
  /**
186
224
  * Access the evaluation context set on the receiver.
@@ -196,29 +234,42 @@ interface ManageContext<T> {
196
234
  */
197
235
  setContext(context: EvaluationContext): T;
198
236
  }
199
- interface ManageLogger<T> {
237
+
238
+ declare enum ProviderStatus {
239
+ NOT_READY = "NOT_READY",
240
+ READY = "READY",
241
+ ERROR = "ERROR"
242
+ }
243
+ interface ProviderMetadata extends Metadata {
244
+ readonly name: string;
245
+ }
246
+ interface CommonProvider {
247
+ readonly metadata: ProviderMetadata;
248
+ readonly status?: ProviderStatus;
200
249
  /**
201
- * Sets a logger on this receiver. This logger supersedes to the global logger
202
- * and is passed to various components in the SDK.
203
- * The logger configured on the global API object will be used for all evaluations,
204
- * unless overridden in a particular client.
205
- * @template T The type of the receiver
206
- * @param {Logger} logger The logger to be used
207
- * @returns {T} The receiver (this object)
250
+ * An event emitter for ProviderEvents.
251
+ * @see ProviderEvents
208
252
  */
209
- setLogger(logger: Logger): T;
210
- }
211
- type HookHints = Readonly<Record<string, unknown>>;
212
- interface Metadata {
253
+ events?: OpenFeatureEventEmitter;
254
+ onClose?(): Promise<void>;
255
+ /**
256
+ * A handler function used to setup the provider.
257
+ * Called by the SDK after the provider is set.
258
+ * When the returned promise resolves, the SDK fires the ProviderEvents.Ready event.
259
+ * If the returned promise rejects, the SDK fires the ProviderEvents.Error event.
260
+ * Use this function to perform any context-dependent setup within the provider.
261
+ * @param context
262
+ */
263
+ initialize?(context?: EvaluationContext): Promise<void>;
213
264
  }
265
+
214
266
  interface ClientMetadata extends Metadata {
215
267
  readonly version?: string;
216
268
  readonly name?: string;
217
269
  readonly providerMetadata: ProviderMetadata;
218
270
  }
219
- interface ProviderMetadata extends Metadata {
220
- readonly name: string;
221
- }
271
+
272
+ type HookHints = Readonly<Record<string, unknown>>;
222
273
  interface HookContext<T extends FlagValue = FlagValue> {
223
274
  readonly flagKey: string;
224
275
  readonly defaultValue: T;
@@ -231,6 +282,98 @@ interface HookContext<T extends FlagValue = FlagValue> {
231
282
  interface BeforeHookContext extends HookContext {
232
283
  context: EvaluationContext;
233
284
  }
285
+
286
+ interface Hook<T extends FlagValue = FlagValue> {
287
+ /**
288
+ * Runs before flag values are resolved from the provider.
289
+ * If an EvaluationContext is returned, it will be merged with the pre-existing EvaluationContext.
290
+ * @param hookContext
291
+ * @param hookHints
292
+ */
293
+ before?(hookContext: BeforeHookContext, hookHints?: HookHints): Promise<EvaluationContext | void> | EvaluationContext | void;
294
+ /**
295
+ * Runs after flag values are successfully resolved from the provider.
296
+ * @param hookContext
297
+ * @param evaluationDetails
298
+ * @param hookHints
299
+ */
300
+ after?(hookContext: Readonly<HookContext<T>>, evaluationDetails: EvaluationDetails<T>, hookHints?: HookHints): Promise<void> | void;
301
+ /**
302
+ * Runs in the event of an unhandled error or promise rejection during flag resolution, or any attached hooks.
303
+ * @param hookContext
304
+ * @param error
305
+ * @param hookHints
306
+ */
307
+ error?(hookContext: Readonly<HookContext<T>>, error: unknown, hookHints?: HookHints): Promise<void> | void;
308
+ /**
309
+ * Runs after all other hook stages, regardless of success or error.
310
+ * Errors thrown here are unhandled by the client and will surface in application code.
311
+ * @param hookContext
312
+ * @param hookHints
313
+ */
314
+ finally?(hookContext: Readonly<HookContext<T>>, hookHints?: HookHints): Promise<void> | void;
315
+ }
316
+
317
+ interface EvaluationLifeCycle<T> {
318
+ /**
319
+ * Adds hooks that will run during flag evaluations on this receiver.
320
+ * Hooks are executed in the order they were registered. Adding additional hooks
321
+ * will not remove existing hooks.
322
+ * Hooks registered on the global API object run with all evaluations.
323
+ * Hooks registered on the client run with all evaluations on that client.
324
+ * @template T The type of the receiver
325
+ * @param {Hook<FlagValue>[]} hooks A list of hooks that should always run
326
+ * @returns {T} The receiver (this object)
327
+ */
328
+ addHooks(...hooks: Hook<FlagValue>[]): T;
329
+ /**
330
+ * Access all the hooks that are registered on this receiver.
331
+ * @returns {Hook<FlagValue>[]} A list of the client hooks
332
+ */
333
+ getHooks(): Hook<FlagValue>[];
334
+ /**
335
+ * Clears all the hooks that are registered on this receiver.
336
+ * @template T The type of the receiver
337
+ * @returns {T} The receiver (this object)
338
+ */
339
+ clearHooks(): T;
340
+ }
341
+
342
+ declare abstract class OpenFeatureError extends Error {
343
+ abstract code: ErrorCode;
344
+ constructor(message?: string);
345
+ }
346
+
347
+ declare class GeneralError extends OpenFeatureError {
348
+ code: ErrorCode;
349
+ constructor(message?: string);
350
+ }
351
+
352
+ declare class FlagNotFoundError extends OpenFeatureError {
353
+ code: ErrorCode;
354
+ constructor(message?: string);
355
+ }
356
+
357
+ declare class ParseError extends OpenFeatureError {
358
+ code: ErrorCode;
359
+ constructor(message?: string);
360
+ }
361
+
362
+ declare class TypeMismatchError extends OpenFeatureError {
363
+ code: ErrorCode;
364
+ constructor(message?: string);
365
+ }
366
+
367
+ declare class TargetingKeyMissingError extends OpenFeatureError {
368
+ code: ErrorCode;
369
+ constructor(message?: string);
370
+ }
371
+
372
+ declare class InvalidContextError extends OpenFeatureError {
373
+ code: ErrorCode;
374
+ constructor(message?: string);
375
+ }
376
+
234
377
  /**
235
378
  * Transaction context is a mechanism for adding transaction specific context that
236
379
  * is merged with evaluation context prior to flag evaluation. Examples of potential
@@ -276,82 +419,6 @@ interface TransactionContextPropagator {
276
419
  */
277
420
  setTransactionContext<R>(transactionContext: TransactionContext, callback: (...args: unknown[]) => R, ...args: unknown[]): void;
278
421
  }
279
- declare enum ProviderStatus {
280
- NOT_READY = "NOT_READY",
281
- READY = "READY",
282
- ERROR = "ERROR"
283
- }
284
- interface CommonProvider {
285
- readonly metadata: ProviderMetadata;
286
- readonly status?: ProviderStatus;
287
- /**
288
- * An event emitter for ProviderEvents.
289
- * @see ProviderEvents
290
- */
291
- events?: OpenFeatureEventEmitter;
292
- onClose?(): Promise<void>;
293
- /**
294
- * A handler function used to setup the provider.
295
- * Called by the SDK after the provider is set.
296
- * When the returned promise resolves, the SDK fires the ProviderEvents.Ready event.
297
- * If the returned promise rejects, the SDK fires the ProviderEvents.Error event.
298
- * Use this function to perform any context-dependent setup within the provider.
299
- * @param context
300
- */
301
- initialize?(context?: EvaluationContext): Promise<void>;
302
- }
303
-
304
- declare abstract class OpenFeatureError extends Error {
305
- abstract code: ErrorCode;
306
- constructor(message?: string);
307
- }
308
-
309
- declare class GeneralError extends OpenFeatureError {
310
- code: ErrorCode;
311
- constructor(message?: string);
312
- }
313
-
314
- declare class FlagNotFoundError extends OpenFeatureError {
315
- code: ErrorCode;
316
- constructor(message?: string);
317
- }
318
-
319
- declare class ParseError extends OpenFeatureError {
320
- code: ErrorCode;
321
- constructor(message?: string);
322
- }
323
-
324
- declare class TypeMismatchError extends OpenFeatureError {
325
- code: ErrorCode;
326
- constructor(message?: string);
327
- }
328
-
329
- declare class TargetingKeyMissingError extends OpenFeatureError {
330
- code: ErrorCode;
331
- constructor(message?: string);
332
- }
333
-
334
- declare class InvalidContextError extends OpenFeatureError {
335
- code: ErrorCode;
336
- constructor(message?: string);
337
- }
338
-
339
- declare class DefaultLogger implements Logger {
340
- error(...args: unknown[]): void;
341
- warn(...args: unknown[]): void;
342
- info(): void;
343
- debug(): void;
344
- }
345
- declare class SafeLogger implements Logger {
346
- private readonly logger;
347
- private readonly fallbackLogger;
348
- constructor(logger: Logger);
349
- error(...args: unknown[]): void;
350
- warn(...args: unknown[]): void;
351
- info(...args: unknown[]): void;
352
- debug(...args: unknown[]): void;
353
- private log;
354
- }
355
422
 
356
423
  declare class NoopTransactionContextPropagator implements TransactionContextPropagator {
357
424
  getTransactionContext(): EvaluationContext;
@@ -359,7 +426,33 @@ declare class NoopTransactionContextPropagator implements TransactionContextProp
359
426
  }
360
427
  declare const NOOP_TRANSACTION_CONTEXT_PROPAGATOR: NoopTransactionContextPropagator;
361
428
 
362
- declare abstract class OpenFeatureCommonAPI<P extends CommonProvider = CommonProvider> implements Eventing {
429
+ /**
430
+ * Checks whether the parameter is a string.
431
+ * @param {unknown} value The value to check
432
+ * @returns {value is string} True if the value is a string
433
+ */
434
+ declare function isString(value: unknown): value is string;
435
+ /**
436
+ * Returns the parameter if it is a string, otherwise returns undefined.
437
+ * @param {unknown} value The value to check
438
+ * @returns {string|undefined} The parameter if it is a string, otherwise undefined
439
+ */
440
+ declare function stringOrUndefined(value: unknown): string | undefined;
441
+ /**
442
+ * Checks whether the parameter is an object.
443
+ * @param {unknown} value The value to check
444
+ * @returns {value is string} True if the value is an object
445
+ */
446
+ declare function isObject<T extends object>(value: unknown): value is T;
447
+ /**
448
+ * Returns the parameter if it is an object, otherwise returns undefined.
449
+ * @param {unknown} value The value to check
450
+ * @returns {object|undefined} The parameter if it is an object, otherwise undefined
451
+ */
452
+ declare function objectOrUndefined<T extends object>(value: unknown): T | undefined;
453
+
454
+ declare abstract class OpenFeatureCommonAPI<P extends CommonProvider = CommonProvider> implements Eventing, EvaluationLifeCycle<OpenFeatureCommonAPI<P>>, ManageLogger<OpenFeatureCommonAPI<P>>, ManageTransactionContextPropagator<OpenFeatureCommonAPI<P>> {
455
+ protected _hooks: Hook[];
363
456
  protected _transactionContextPropagator: TransactionContextPropagator;
364
457
  protected _context: EvaluationContext;
365
458
  protected _logger: Logger;
@@ -368,14 +461,15 @@ declare abstract class OpenFeatureCommonAPI<P extends CommonProvider = CommonPro
368
461
  private readonly _clientEventHandlers;
369
462
  protected _clientProviders: Map<string, P>;
370
463
  protected _clientEvents: Map<string | undefined, OpenFeatureEventEmitter>;
371
- abstract clearHooks(): this;
464
+ addHooks(...hooks: Hook<FlagValue>[]): this;
465
+ getHooks(): Hook<FlagValue>[];
466
+ clearHooks(): this;
372
467
  setLogger(logger: Logger): this;
373
468
  /**
374
469
  * Get metadata about registered provider.
375
470
  * @returns {ProviderMetadata} Provider Metadata
376
471
  */
377
472
  get providerMetadata(): ProviderMetadata;
378
- getContext(): EvaluationContext;
379
473
  /**
380
474
  * Adds a handler for the given provider event type.
381
475
  * The handlers are called in the order they have been added.
@@ -425,98 +519,6 @@ declare abstract class OpenFeatureCommonAPI<P extends CommonProvider = CommonPro
425
519
  getTransactionContext(): TransactionContext;
426
520
  }
427
521
 
428
- /**
429
- * Interface that providers must implement to resolve flag values for their particular
430
- * backend or vendor.
431
- *
432
- * Implementation for resolving all the required flag types must be defined.
433
- */
434
- interface Provider extends CommonProvider {
435
- /**
436
- * A provider hook exposes a mechanism for provider authors to register hooks
437
- * to tap into various stages of the flag evaluation lifecycle. These hooks can
438
- * be used to perform side effects and mutate the context for purposes of the
439
- * provider. Provider hooks are not configured or controlled by the application author.
440
- */
441
- readonly hooks?: Hook[];
442
- /**
443
- * A handler function to reconcile changes when the static context.
444
- * Called by the SDK when the context is changed.
445
- * @param oldContext
446
- * @param newContext
447
- */
448
- onContextChange?(oldContext: EvaluationContext, newContext: EvaluationContext): Promise<void>;
449
- /**
450
- * Resolve a boolean flag and its evaluation details.
451
- */
452
- resolveBooleanEvaluation(flagKey: string, defaultValue: boolean, context: EvaluationContext, logger: Logger): ResolutionDetails<boolean>;
453
- /**
454
- * Resolve a string flag and its evaluation details.
455
- */
456
- resolveStringEvaluation(flagKey: string, defaultValue: string, context: EvaluationContext, logger: Logger): ResolutionDetails<string>;
457
- /**
458
- * Resolve a numeric flag and its evaluation details.
459
- */
460
- resolveNumberEvaluation(flagKey: string, defaultValue: number, context: EvaluationContext, logger: Logger): ResolutionDetails<number>;
461
- /**
462
- * Resolve and parse an object flag and its evaluation details.
463
- */
464
- resolveObjectEvaluation<T extends JsonValue>(flagKey: string, defaultValue: T, context: EvaluationContext, logger: Logger): ResolutionDetails<T>;
465
- }
466
- interface Hook<T extends FlagValue = FlagValue> {
467
- /**
468
- * Runs before flag values are resolved from the provider.
469
- * If an EvaluationContext is returned, it will be merged with the pre-existing EvaluationContext.
470
- * @param hookContext
471
- * @param hookHints
472
- */
473
- before?(hookContext: BeforeHookContext, hookHints?: HookHints): EvaluationContext | void;
474
- /**
475
- * Runs after flag values are successfully resolved from the provider.
476
- * @param hookContext
477
- * @param evaluationDetails
478
- * @param hookHints
479
- */
480
- after?(hookContext: Readonly<HookContext<T>>, evaluationDetails: EvaluationDetails<T>, hookHints?: HookHints): void;
481
- /**
482
- * Runs in the event of an unhandled error or promise rejection during flag resolution, or any attached hooks.
483
- * @param hookContext
484
- * @param error
485
- * @param hookHints
486
- */
487
- error?(hookContext: Readonly<HookContext<T>>, error: unknown, hookHints?: HookHints): void;
488
- /**
489
- * Runs after all other hook stages, regardless of success or error.
490
- * Errors thrown here are unhandled by the client and will surface in application code.
491
- * @param hookContext
492
- * @param hookHints
493
- */
494
- finally?(hookContext: Readonly<HookContext<T>>, hookHints?: HookHints): void;
495
- }
496
- interface EvaluationLifeCycle<T> {
497
- /**
498
- * Adds hooks that will run during flag evaluations on this receiver.
499
- * Hooks are executed in the order they were registered. Adding additional hooks
500
- * will not remove existing hooks.
501
- * Hooks registered on the global API object run with all evaluations.
502
- * Hooks registered on the client run with all evaluations on that client.
503
- * @template T The type of the receiver
504
- * @param {Hook<FlagValue>[]} hooks A list of hooks that should always run
505
- * @returns {T} The receiver (this object)
506
- */
507
- addHooks(...hooks: Hook[]): T;
508
- /**
509
- * Access all the hooks that are registered on this receiver.
510
- * @returns {Hook<FlagValue>[]} A list of the client hooks
511
- */
512
- getHooks(): Hook[];
513
- /**
514
- * Clears all the hooks that are registered on this receiver.
515
- * @template T The type of the receiver
516
- * @returns {T} The receiver (this object)
517
- */
518
- clearHooks(): T;
519
- }
520
522
  interface FlagEvaluationOptions {
521
523
  hooks?: Hook[];
522
524
  hookHints?: HookHints;
@@ -599,29 +601,65 @@ interface Features {
599
601
  getObjectDetails(flagKey: string, defaultValue: JsonValue, options?: FlagEvaluationOptions): EvaluationDetails<JsonValue>;
600
602
  getObjectDetails<T extends JsonValue = JsonValue>(flagKey: string, defaultValue: T, options?: FlagEvaluationOptions): EvaluationDetails<T>;
601
603
  }
604
+
602
605
  interface Client extends EvaluationLifeCycle<Client>, Features, ManageLogger<Client>, Eventing {
603
606
  readonly metadata: ClientMetadata;
604
607
  }
605
- interface GlobalApi extends EvaluationLifeCycle<GlobalApi>, ManageContext<GlobalApi>, ManageLogger<GlobalApi>, ManageTransactionContextPropagator<GlobalApi> {
606
- readonly providerMetadata: ProviderMetadata;
608
+
609
+ /**
610
+ * Interface that providers must implement to resolve flag values for their particular
611
+ * backend or vendor.
612
+ *
613
+ * Implementation for resolving all the required flag types must be defined.
614
+ */
615
+ interface Provider extends CommonProvider {
607
616
  /**
608
- * A factory function for creating new OpenFeature clients. Clients can contain
609
- * their own state (e.g. logger, hook, context). Multiple clients can be used
610
- * to segment feature flag configuration.
611
- * @param {string} name The name of the client
612
- * @param {string} version The version of the client
613
- * @param {EvaluationContext} context Evaluation context that should be set on the client to used during flag evaluations
614
- * @returns {Client} OpenFeature Client
617
+ * A provider hook exposes a mechanism for provider authors to register hooks
618
+ * to tap into various stages of the flag evaluation lifecycle. These hooks can
619
+ * be used to perform side effects and mutate the context for purposes of the
620
+ * provider. Provider hooks are not configured or controlled by the application author.
621
+ */
622
+ readonly hooks?: Hook[];
623
+ /**
624
+ * A handler function to reconcile changes when the static context.
625
+ * Called by the SDK when the context is changed.
626
+ * @param oldContext
627
+ * @param newContext
628
+ */
629
+ onContextChange?(oldContext: EvaluationContext, newContext: EvaluationContext): Promise<void>;
630
+ /**
631
+ * Resolve a boolean flag and its evaluation details.
632
+ */
633
+ resolveBooleanEvaluation(flagKey: string, defaultValue: boolean, context: EvaluationContext, logger: Logger): ResolutionDetails<boolean>;
634
+ /**
635
+ * Resolve a string flag and its evaluation details.
636
+ */
637
+ resolveStringEvaluation(flagKey: string, defaultValue: string, context: EvaluationContext, logger: Logger): ResolutionDetails<string>;
638
+ /**
639
+ * Resolve a numeric flag and its evaluation details.
615
640
  */
616
- getClient(name?: string, version?: string, context?: EvaluationContext): Client;
641
+ resolveNumberEvaluation(flagKey: string, defaultValue: number, context: EvaluationContext, logger: Logger): ResolutionDetails<number>;
617
642
  /**
618
- * Sets the provider that OpenFeature will use for flag evaluations. Setting
619
- * a provider supersedes the current provider used in new and existing clients.
620
- * @param {Provider} provider The provider responsible for flag evaluations.
621
- * @returns {GlobalApi} OpenFeature API
643
+ * Resolve and parse an object flag and its evaluation details.
622
644
  */
623
- setProvider(provider: Provider): GlobalApi;
645
+ resolveObjectEvaluation<T extends JsonValue>(flagKey: string, defaultValue: T, context: EvaluationContext, logger: Logger): ResolutionDetails<T>;
646
+ }
647
+
648
+ /**
649
+ * The No-op provider is set by default, and simply always returns the default value.
650
+ */
651
+ declare class NoopFeatureProvider implements Provider {
652
+ readonly metadata: {
653
+ readonly name: "No-op Provider";
654
+ };
655
+ get status(): ProviderStatus;
656
+ resolveBooleanEvaluation(_: string, defaultValue: boolean): ResolutionDetails<boolean>;
657
+ resolveStringEvaluation(_: string, defaultValue: string): ResolutionDetails<string>;
658
+ resolveNumberEvaluation(_: string, defaultValue: number): ResolutionDetails<number>;
659
+ resolveObjectEvaluation<T extends JsonValue>(_: string, defaultValue: T): ResolutionDetails<T>;
660
+ private noOp;
624
661
  }
662
+ declare const NOOP_PROVIDER: NoopFeatureProvider;
625
663
 
626
664
  type OpenFeatureClientOptions = {
627
665
  name?: string;
@@ -660,24 +698,7 @@ declare class OpenFeatureClient implements Client {
660
698
  private get _logger();
661
699
  }
662
700
 
663
- /**
664
- * The No-op provider is set by default, and simply always returns the default value.
665
- */
666
- declare class NoopFeatureProvider implements Provider {
667
- readonly metadata: {
668
- readonly name: "No-op Provider";
669
- };
670
- get status(): ProviderStatus;
671
- resolveBooleanEvaluation(_: string, defaultValue: boolean): ResolutionDetails<boolean>;
672
- resolveStringEvaluation(_: string, defaultValue: string): ResolutionDetails<string>;
673
- resolveNumberEvaluation(_: string, defaultValue: number): ResolutionDetails<number>;
674
- resolveObjectEvaluation<T extends JsonValue>(_: string, defaultValue: T): ResolutionDetails<T>;
675
- private noOp;
676
- }
677
- declare const NOOP_PROVIDER: NoopFeatureProvider;
678
-
679
- declare class OpenFeatureAPI extends OpenFeatureCommonAPI<Provider> {
680
- protected _hooks: Hook[];
701
+ declare class OpenFeatureAPI extends OpenFeatureCommonAPI<Provider> implements ManageContext<Promise<void>> {
681
702
  protected _defaultProvider: Provider;
682
703
  private constructor();
683
704
  /**
@@ -686,11 +707,8 @@ declare class OpenFeatureAPI extends OpenFeatureCommonAPI<Provider> {
686
707
  * @returns {OpenFeatureAPI} OpenFeature API
687
708
  */
688
709
  static getInstance(): OpenFeatureAPI;
689
- setLogger(logger: Logger): this;
690
- addHooks(...hooks: Hook<FlagValue>[]): this;
691
- getHooks(): Hook<FlagValue>[];
692
- clearHooks(): this;
693
710
  setContext(context: EvaluationContext): Promise<void>;
711
+ getContext(): EvaluationContext;
694
712
  /**
695
713
  * A factory function for creating new named OpenFeature clients. Clients can contain
696
714
  * their own state (e.g. logger, hook, context). Multiple clients can be used
@@ -710,4 +728,4 @@ declare class OpenFeatureAPI extends OpenFeatureCommonAPI<Provider> {
710
728
  */
711
729
  declare const OpenFeature: OpenFeatureAPI;
712
730
 
713
- export { BeforeHookContext, Client, ClientMetadata, CommonProvider, DefaultLogger, ErrorCode, EvaluationContext, EvaluationContextValue, EvaluationDetails, EventDetails, EventHandler, EventMetadata, Eventing, Features, FlagEvaluationOptions, FlagMetadata, FlagNotFoundError, FlagValue, FlagValueType, GeneralError, GlobalApi, Hook, HookContext, HookHints, InvalidContextError, JsonArray, JsonObject, JsonValue, Logger, ManageContext, ManageLogger, ManageTransactionContextPropagator, NOOP_PROVIDER, NOOP_TRANSACTION_CONTEXT_PROPAGATOR, OpenFeature, OpenFeatureAPI, OpenFeatureClient, OpenFeatureCommonAPI, OpenFeatureError, OpenFeatureEventEmitter, ParseError, PrimitiveValue, Provider, ProviderEvents, ProviderMetadata, ProviderStatus, ResolutionDetails, ResolutionReason, SafeLogger, StandardResolutionReasons, TargetingKeyMissingError, TransactionContext, TransactionContextPropagator, TypeMismatchError };
731
+ export { BeforeHookContext, Client, ClientMetadata, CommonProvider, DefaultLogger, ErrorCode, EvaluationContext, EvaluationContextValue, EvaluationDetails, EvaluationLifeCycle, EventDetails, EventHandler, EventMetadata, Eventing, Features, FlagEvaluationOptions, FlagMetadata, FlagNotFoundError, FlagValue, FlagValueType, GeneralError, Hook, HookContext, HookHints, InvalidContextError, JsonArray, JsonObject, JsonValue, LOG_LEVELS, Logger, ManageContext, ManageLogger, ManageTransactionContextPropagator, Metadata, NOOP_PROVIDER, NOOP_TRANSACTION_CONTEXT_PROPAGATOR, OpenFeature, OpenFeatureAPI, OpenFeatureClient, OpenFeatureCommonAPI, OpenFeatureError, OpenFeatureEventEmitter, ParseError, PrimitiveValue, Provider, ProviderEvents, ProviderMetadata, ProviderStatus, ResolutionDetails, ResolutionReason, SafeLogger, StandardResolutionReasons, TargetingKeyMissingError, TransactionContext, TransactionContextPropagator, TypeMismatchError, isObject, isString, objectOrUndefined, stringOrUndefined };