@openfeature/web-sdk 0.4.11 → 0.4.13

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,641 +1,8 @@
1
+ import { BaseHook, HookHints, EvaluationDetails, JsonValue, EvaluationLifeCycle, ManageLogger, Eventing, ClientMetadata, ProviderStatus, ClientProviderEvents, GenericEventEmitter, CommonEventDetails, FlagValue, CommonProvider, EvaluationContext, Logger, ResolutionDetails, EventHandler, OpenFeatureCommonAPI, ManageContext } from '@openfeature/core';
2
+ export * from '@openfeature/core';
3
+ export { ClientProviderEvents as ProviderEvents } from '@openfeature/core';
1
4
  import EventEmitter from 'events';
2
5
 
3
- type FlagValueType = 'boolean' | 'string' | 'number' | 'object';
4
- type PrimitiveValue = null | boolean | string | number;
5
- type JsonObject = {
6
- [key: string]: JsonValue;
7
- };
8
- type JsonArray = JsonValue[];
9
- /**
10
- * Represents a JSON node value.
11
- */
12
- type JsonValue = PrimitiveValue | JsonObject | JsonArray;
13
- /**
14
- * Represents a JSON node value, or Date.
15
- */
16
- type FlagValue = boolean | string | number | JsonValue;
17
- type ResolutionReason = keyof typeof StandardResolutionReasons | (string & Record<never, never>);
18
- /**
19
- * A structure which supports definition of arbitrary properties, with keys of type string, and values of type boolean, string, or number.
20
- *
21
- * This structure is populated by a provider for use by an Application Author (via the Evaluation API) or an Application Integrator (via hooks).
22
- */
23
- type FlagMetadata = Record<string, string | number | boolean>;
24
- type ResolutionDetails<U> = {
25
- value: U;
26
- variant?: string;
27
- flagMetadata?: FlagMetadata;
28
- reason?: ResolutionReason;
29
- errorCode?: ErrorCode;
30
- errorMessage?: string;
31
- };
32
- type EvaluationDetails<T extends FlagValue> = {
33
- flagKey: string;
34
- flagMetadata: Readonly<FlagMetadata>;
35
- } & ResolutionDetails<T>;
36
- declare const StandardResolutionReasons: {
37
- /**
38
- * The resolved value was the result of a dynamic evaluation, such as a rule or specific user-targeting.
39
- */
40
- readonly TARGETING_MATCH: "TARGETING_MATCH";
41
- /**
42
- * The resolved value was the result of pseudorandom assignment.
43
- */
44
- readonly SPLIT: "SPLIT";
45
- /**
46
- * The resolved value was the result of the flag being disabled in the management system.
47
- */
48
- readonly DISABLED: "DISABLED";
49
- /**
50
- * The resolved value was configured statically, or otherwise fell back to a pre-configured value.
51
- */
52
- readonly DEFAULT: "DEFAULT";
53
- /**
54
- * The reason for the resolved value could not be determined.
55
- */
56
- readonly UNKNOWN: "UNKNOWN";
57
- /**
58
- * The resolved value is static (no dynamic evaluation).
59
- */
60
- readonly STATIC: "STATIC";
61
- /**
62
- * The resolved value was retrieved from cache.
63
- */
64
- readonly CACHED: "CACHED";
65
- /**
66
- * The resolved value was the result of an error.
67
- *
68
- * Note: The `errorCode` and `errorMessage` fields may contain additional details of this error.
69
- */
70
- readonly ERROR: "ERROR";
71
- };
72
- declare enum ErrorCode {
73
- /**
74
- * The value was resolved before the provider was ready.
75
- */
76
- PROVIDER_NOT_READY = "PROVIDER_NOT_READY",
77
- /**
78
- * The flag could not be found.
79
- */
80
- FLAG_NOT_FOUND = "FLAG_NOT_FOUND",
81
- /**
82
- * An error was encountered parsing data, such as a flag configuration.
83
- */
84
- PARSE_ERROR = "PARSE_ERROR",
85
- /**
86
- * The type of the flag value does not match the expected type.
87
- */
88
- TYPE_MISMATCH = "TYPE_MISMATCH",
89
- /**
90
- * The provider requires a targeting key and one was not provided in the evaluation context.
91
- */
92
- TARGETING_KEY_MISSING = "TARGETING_KEY_MISSING",
93
- /**
94
- * The evaluation context does not meet provider requirements.
95
- */
96
- INVALID_CONTEXT = "INVALID_CONTEXT",
97
- /**
98
- * An error with an unspecified code.
99
- */
100
- GENERAL = "GENERAL"
101
- }
102
-
103
- type EvaluationContextValue = PrimitiveValue | Date | {
104
- [key: string]: EvaluationContextValue;
105
- } | EvaluationContextValue[];
106
- /**
107
- * A container for arbitrary contextual data that can be used as a basis for dynamic evaluation
108
- */
109
- type EvaluationContext = {
110
- /**
111
- * A string uniquely identifying the subject (end-user, or client service) of a flag evaluation.
112
- * Providers may require this field for fractional flag evaluation, rules, or overrides targeting specific users.
113
- * Such providers may behave unpredictably if a targeting key is not specified at flag resolution.
114
- */
115
- targetingKey?: string;
116
- } & Record<string, EvaluationContextValue>;
117
- interface ManageContext<T> {
118
- /**
119
- * Access the evaluation context set on the receiver.
120
- * @returns {EvaluationContext} Evaluation context
121
- */
122
- getContext(): EvaluationContext;
123
- /**
124
- * Sets evaluation context that will be used during flag evaluations
125
- * on this receiver.
126
- * @template T The type of the receiver
127
- * @param {EvaluationContext} context Evaluation context
128
- * @returns {T} The receiver (this object)
129
- */
130
- setContext(context: EvaluationContext): T;
131
- }
132
-
133
- /**
134
- * An enumeration of possible events for server-sdk providers.
135
- */
136
- declare enum ServerProviderEvents {
137
- /**
138
- * The provider is ready to evaluate flags.
139
- */
140
- Ready = "PROVIDER_READY",
141
- /**
142
- * The provider is in an error state.
143
- */
144
- Error = "PROVIDER_ERROR",
145
- /**
146
- * The flag configuration in the source-of-truth has changed.
147
- */
148
- ConfigurationChanged = "PROVIDER_CONFIGURATION_CHANGED",
149
- /**
150
- * The provider's cached state is no longer valid and may not be up-to-date with the source of truth.
151
- */
152
- Stale = "PROVIDER_STALE"
153
- }
154
- /**
155
- * An enumeration of possible events for web-sdk providers.
156
- */
157
- declare enum ClientProviderEvents {
158
- /**
159
- * The provider is ready to evaluate flags.
160
- */
161
- Ready = "PROVIDER_READY",
162
- /**
163
- * The provider is in an error state.
164
- */
165
- Error = "PROVIDER_ERROR",
166
- /**
167
- * The flag configuration in the source-of-truth has changed.
168
- */
169
- ConfigurationChanged = "PROVIDER_CONFIGURATION_CHANGED",
170
- /**
171
- * The context associated with the provider has changed, and the provider has reconciled it's associated state.
172
- */
173
- ContextChanged = "PROVIDER_CONTEXT_CHANGED",
174
- /**
175
- * The provider's cached state is no longer valid and may not be up-to-date with the source of truth.
176
- */
177
- Stale = "PROVIDER_STALE"
178
- }
179
-
180
- /**
181
- * A type representing any possible ProviderEvent (server or client side).
182
- * If you are implementing a hook or provider, you probably want to import `ProviderEvents` from the respective SDK.
183
- */
184
- type AnyProviderEvent = ServerProviderEvents | ClientProviderEvents;
185
-
186
- /**
187
- * Returns true if the provider's status corresponds to the event.
188
- * If the provider's status is not defined, it matches READY.
189
- * @param {AnyProviderEvent} event event to match
190
- * @param {ProviderStatus} status status of provider
191
- * @returns {boolean} boolean indicating if the provider status corresponds to the event.
192
- */
193
- declare const statusMatchesEvent: <T extends AnyProviderEvent>(event: T, status?: ProviderStatus) => boolean;
194
-
195
- type EventMetadata = {
196
- [key: string]: string | boolean | number;
197
- };
198
- type CommonEventDetails = {
199
- providerName: string;
200
- clientName?: string;
201
- };
202
- type CommonEventProps = {
203
- message?: string;
204
- metadata?: EventMetadata;
205
- };
206
- type ReadyEvent = CommonEventProps;
207
- type ErrorEvent = CommonEventProps;
208
- type StaleEvent = CommonEventProps;
209
- type ConfigChangeEvent = CommonEventProps & {
210
- flagsChanged?: string[];
211
- };
212
- type EventMap = {
213
- [ClientProviderEvents.Ready]: ReadyEvent;
214
- [ClientProviderEvents.Error]: ErrorEvent;
215
- [ClientProviderEvents.Stale]: StaleEvent;
216
- [ClientProviderEvents.ContextChanged]: CommonEventProps;
217
- [ClientProviderEvents.ConfigurationChanged]: ConfigChangeEvent;
218
- };
219
- type EventContext<U extends Record<string, unknown> = Record<string, unknown>> = EventMap[ClientProviderEvents] & U;
220
- type EventDetails = EventContext & CommonEventDetails;
221
- type EventHandler = (eventDetails?: EventDetails) => Promise<unknown> | unknown;
222
- interface Eventing {
223
- /**
224
- * Adds a handler for the given provider event type.
225
- * The handlers are called in the order they have been added.
226
- * @param {AnyProviderEvent} eventType The provider event type to listen to
227
- * @param {EventHandler} handler The handler to run on occurrence of the event type
228
- */
229
- addHandler(eventType: AnyProviderEvent, handler: EventHandler): void;
230
- /**
231
- * Removes a handler for the given provider event type.
232
- * @param {AnyProviderEvent} eventType The provider event type to remove the listener for
233
- * @param {EventHandler} handler The handler to remove for the provider event type
234
- */
235
- removeHandler(eventType: AnyProviderEvent, handler: EventHandler): void;
236
- /**
237
- * Gets the current handlers for the given provider event type.
238
- * @param {AnyProviderEvent} eventType The provider event type to get the current handlers for
239
- * @returns {EventHandler[]} The handlers currently attached to the given provider event type
240
- */
241
- getHandlers(eventType: AnyProviderEvent): EventHandler[];
242
- }
243
-
244
- interface Logger {
245
- error(...args: unknown[]): void;
246
- warn(...args: unknown[]): void;
247
- info(...args: unknown[]): void;
248
- debug(...args: unknown[]): void;
249
- }
250
- interface ManageLogger<T> {
251
- /**
252
- * Sets a logger on this receiver. This logger supersedes to the global logger
253
- * and is passed to various components in the SDK.
254
- * The logger configured on the global API object will be used for all evaluations,
255
- * unless overridden in a particular client.
256
- * @template T The type of the receiver
257
- * @param {Logger} logger The logger to be used
258
- * @returns {T} The receiver (this object)
259
- */
260
- setLogger(logger: Logger): T;
261
- }
262
-
263
- declare class DefaultLogger implements Logger {
264
- error(...args: unknown[]): void;
265
- warn(...args: unknown[]): void;
266
- info(): void;
267
- debug(): void;
268
- }
269
-
270
- declare const LOG_LEVELS: Array<keyof Logger>;
271
- declare class SafeLogger implements Logger {
272
- private readonly logger;
273
- private readonly fallbackLogger;
274
- constructor(logger: Logger);
275
- error(...args: unknown[]): void;
276
- warn(...args: unknown[]): void;
277
- info(...args: unknown[]): void;
278
- debug(...args: unknown[]): void;
279
- private log;
280
- }
281
-
282
- /**
283
- * The GenericEventEmitter should only be used within the SDK. It supports additional properties that can be included
284
- * in the event details.
285
- */
286
- declare abstract class GenericEventEmitter<E extends AnyProviderEvent, AdditionalContext extends Record<string, unknown> = Record<string, unknown>> implements ManageLogger<GenericEventEmitter<E, AdditionalContext>> {
287
- private readonly globalLogger?;
288
- protected abstract readonly eventEmitter: PlatformEventEmitter;
289
- private readonly _handlers;
290
- private _eventLogger?;
291
- constructor(globalLogger?: (() => Logger) | undefined);
292
- emit(eventType: E, context?: EventContext): void;
293
- addHandler(eventType: AnyProviderEvent, handler: EventHandler): void;
294
- removeHandler(eventType: AnyProviderEvent, handler: EventHandler): void;
295
- removeAllHandlers(eventType?: AnyProviderEvent): void;
296
- getHandlers(eventType: AnyProviderEvent): EventHandler[];
297
- setLogger(logger: Logger): this;
298
- protected get _logger(): Logger | undefined;
299
- }
300
- /**
301
- * This is an un-exported type that corresponds to NodeJS.EventEmitter.
302
- * We can't use that type here, because this module is used in both the browser, and the server.
303
- * In the server, node (or whatever server runtime) provides an implementation for this.
304
- * In the browser, we bundle in the popular 'events' package, which is a polyfill of NodeJS.EventEmitter.
305
- */
306
- interface PlatformEventEmitter {
307
- addListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
308
- on(eventName: string | symbol, listener: (...args: any[]) => void): this;
309
- once(eventName: string | symbol, listener: (...args: any[]) => void): this;
310
- removeListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
311
- off(eventName: string | symbol, listener: (...args: any[]) => void): this;
312
- removeAllListeners(event?: string | symbol): this;
313
- setMaxListeners(n: number): this;
314
- getMaxListeners(): number;
315
- listeners(eventName: string | symbol): Function[];
316
- rawListeners(eventName: string | symbol): Function[];
317
- emit(eventName: string | symbol, ...args: any[]): boolean;
318
- listenerCount(eventName: string | symbol, listener?: Function): number;
319
- prependListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
320
- prependOnceListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
321
- eventNames(): Array<string | symbol>;
322
- }
323
-
324
- interface Metadata {
325
- }
326
-
327
- /**
328
- * Defines where the library is intended to be run.
329
- */
330
- type Paradigm = 'server' | 'client';
331
-
332
- /**
333
- * The state of the provider.
334
- */
335
- declare enum ProviderStatus {
336
- /**
337
- * The provider has not been initialized and cannot yet evaluate flags.
338
- */
339
- NOT_READY = "NOT_READY",
340
- /**
341
- * The provider is ready to resolve flags.
342
- */
343
- READY = "READY",
344
- /**
345
- * The provider is in an error state and unable to evaluate flags.
346
- */
347
- ERROR = "ERROR",
348
- /**
349
- * The provider's cached state is no longer valid and may not be up-to-date with the source of truth.
350
- */
351
- STALE = "STALE"
352
- }
353
- /**
354
- * Static data about the provider.
355
- */
356
- interface ProviderMetadata extends Metadata {
357
- readonly name: string;
358
- }
359
- interface CommonProvider {
360
- readonly metadata: ProviderMetadata;
361
- /**
362
- * Represents where the provider is intended to be run. If defined,
363
- * the SDK will enforce that the defined paradigm at runtime.
364
- */
365
- readonly runsOn?: Paradigm;
366
- /**
367
- * Returns a representation of the current readiness of the provider.
368
- * If the provider needs to be initialized, it should return {@link ProviderStatus.READY}.
369
- * If the provider is in an error state, it should return {@link ProviderStatus.ERROR}.
370
- * If the provider is functioning normally, it should return {@link ProviderStatus.NOT_READY}.
371
- *
372
- * _Providers which do not implement this method are assumed to be ready immediately._
373
- */
374
- readonly status?: ProviderStatus;
375
- /**
376
- * An event emitter for ProviderEvents.
377
- * @see ProviderEvents
378
- */
379
- events?: GenericEventEmitter<AnyProviderEvent>;
380
- /**
381
- * A function used to shut down the provider.
382
- * Called when this provider is replaced with a new one, or when the OpenFeature is shut down.
383
- */
384
- onClose?(): Promise<void>;
385
- /**
386
- * A function used to setup the provider.
387
- * Called by the SDK after the provider is set if the provider's status is {@link ProviderStatus.NOT_READY}.
388
- * When the returned promise resolves, the SDK fires the ProviderEvents.Ready event.
389
- * If the returned promise rejects, the SDK fires the ProviderEvents.Error event.
390
- * Use this function to perform any context-dependent setup within the provider.
391
- * @param context
392
- */
393
- initialize?(context?: EvaluationContext): Promise<void>;
394
- }
395
-
396
- interface ClientMetadata extends Metadata {
397
- readonly version?: string;
398
- readonly name?: string;
399
- readonly providerMetadata: ProviderMetadata;
400
- }
401
-
402
- type HookHints = Readonly<Record<string, unknown>>;
403
- interface HookContext<T extends FlagValue = FlagValue> {
404
- readonly flagKey: string;
405
- readonly defaultValue: T;
406
- readonly flagValueType: FlagValueType;
407
- readonly context: Readonly<EvaluationContext>;
408
- readonly clientMetadata: ClientMetadata;
409
- readonly providerMetadata: ProviderMetadata;
410
- readonly logger: Logger;
411
- }
412
- interface BeforeHookContext extends HookContext {
413
- context: EvaluationContext;
414
- }
415
-
416
- interface BaseHook<T extends FlagValue = FlagValue, BeforeHookReturn = unknown, HooksReturn = unknown> {
417
- /**
418
- * Runs before flag values are resolved from the provider.
419
- * If an EvaluationContext is returned, it will be merged with the pre-existing EvaluationContext.
420
- * @param hookContext
421
- * @param hookHints
422
- */
423
- before?(hookContext: BeforeHookContext, hookHints?: HookHints): BeforeHookReturn;
424
- /**
425
- * Runs after flag values are successfully resolved from the provider.
426
- * @param hookContext
427
- * @param evaluationDetails
428
- * @param hookHints
429
- */
430
- after?(hookContext: Readonly<HookContext<T>>, evaluationDetails: EvaluationDetails<T>, hookHints?: HookHints): HooksReturn;
431
- /**
432
- * Runs in the event of an unhandled error or promise rejection during flag resolution, or any attached hooks.
433
- * @param hookContext
434
- * @param error
435
- * @param hookHints
436
- */
437
- error?(hookContext: Readonly<HookContext<T>>, error: unknown, hookHints?: HookHints): HooksReturn;
438
- /**
439
- * Runs after all other hook stages, regardless of success or error.
440
- * Errors thrown here are unhandled by the client and will surface in application code.
441
- * @param hookContext
442
- * @param hookHints
443
- */
444
- finally?(hookContext: Readonly<HookContext<T>>, hookHints?: HookHints): HooksReturn;
445
- }
446
-
447
- interface EvaluationLifeCycle<T> {
448
- /**
449
- * Adds hooks that will run during flag evaluations on this receiver.
450
- * Hooks are executed in the order they were registered. Adding additional hooks
451
- * will not remove existing hooks.
452
- * Hooks registered on the global API object run with all evaluations.
453
- * Hooks registered on the client run with all evaluations on that client.
454
- * @template T The type of the receiver
455
- * @param {BaseHook[]} hooks A list of hooks that should always run
456
- * @returns {T} The receiver (this object)
457
- */
458
- addHooks(...hooks: BaseHook[]): T;
459
- /**
460
- * Access all the hooks that are registered on this receiver.
461
- * @returns {BaseHook<FlagValue>[]} A list of the client hooks
462
- */
463
- getHooks(): BaseHook[];
464
- /**
465
- * Clears all the hooks that are registered on this receiver.
466
- * @template T The type of the receiver
467
- * @returns {T} The receiver (this object)
468
- */
469
- clearHooks(): T;
470
- }
471
-
472
- declare abstract class OpenFeatureError extends Error {
473
- abstract code: ErrorCode;
474
- constructor(message?: string, options?: ErrorOptions);
475
- }
476
-
477
- declare class GeneralError extends OpenFeatureError {
478
- code: ErrorCode;
479
- constructor(message?: string, options?: ErrorOptions);
480
- }
481
-
482
- declare class FlagNotFoundError extends OpenFeatureError {
483
- code: ErrorCode;
484
- constructor(message?: string, options?: ErrorOptions);
485
- }
486
-
487
- declare class ParseError extends OpenFeatureError {
488
- code: ErrorCode;
489
- constructor(message?: string, options?: ErrorOptions);
490
- }
491
-
492
- declare class TypeMismatchError extends OpenFeatureError {
493
- code: ErrorCode;
494
- constructor(message?: string, options?: ErrorOptions);
495
- }
496
-
497
- declare class TargetingKeyMissingError extends OpenFeatureError {
498
- code: ErrorCode;
499
- constructor(message?: string, options?: ErrorOptions);
500
- }
501
-
502
- declare class InvalidContextError extends OpenFeatureError {
503
- code: ErrorCode;
504
- constructor(message?: string, options?: ErrorOptions);
505
- }
506
-
507
- declare class ProviderNotReadyError extends OpenFeatureError {
508
- code: ErrorCode;
509
- constructor(message?: string, options?: ErrorOptions);
510
- }
511
-
512
- /**
513
- * Checks whether the parameter is a string.
514
- * @param {unknown} value The value to check
515
- * @returns {value is string} True if the value is a string
516
- */
517
- declare function isString(value: unknown): value is string;
518
- /**
519
- * Returns the parameter if it is a string, otherwise returns undefined.
520
- * @param {unknown} value The value to check
521
- * @returns {string|undefined} The parameter if it is a string, otherwise undefined
522
- */
523
- declare function stringOrUndefined(value: unknown): string | undefined;
524
- /**
525
- * Checks whether the parameter is an object.
526
- * @param {unknown} value The value to check
527
- * @returns {value is string} True if the value is an object
528
- */
529
- declare function isObject<T extends object>(value: unknown): value is T;
530
- /**
531
- * Returns the parameter if it is an object, otherwise returns undefined.
532
- * @param {unknown} value The value to check
533
- * @returns {object|undefined} The parameter if it is an object, otherwise undefined
534
- */
535
- declare function objectOrUndefined<T extends object>(value: unknown): T | undefined;
536
-
537
- declare abstract class OpenFeatureCommonAPI<P extends CommonProvider = CommonProvider, H extends BaseHook = BaseHook> implements Eventing, EvaluationLifeCycle<OpenFeatureCommonAPI<P>>, ManageLogger<OpenFeatureCommonAPI<P>> {
538
- protected abstract _createEventEmitter(): GenericEventEmitter<AnyProviderEvent>;
539
- protected abstract _defaultProvider: P;
540
- protected abstract readonly _events: GenericEventEmitter<AnyProviderEvent>;
541
- protected _hooks: H[];
542
- protected _context: EvaluationContext;
543
- protected _logger: Logger;
544
- private readonly _clientEventHandlers;
545
- protected _clientProviders: Map<string, P>;
546
- protected _clientEvents: Map<string | undefined, GenericEventEmitter<AnyProviderEvent>>;
547
- protected _runsOn: Paradigm;
548
- constructor(category: Paradigm);
549
- addHooks(...hooks: H[]): this;
550
- getHooks(): H[];
551
- clearHooks(): this;
552
- setLogger(logger: Logger): this;
553
- /**
554
- * Get metadata about the default provider.
555
- * @returns {ProviderMetadata} Provider Metadata
556
- */
557
- get providerMetadata(): ProviderMetadata;
558
- /**
559
- * Get metadata about a registered provider using the client name.
560
- * An unbound or empty client name will return metadata from the default provider.
561
- * @param {string} [clientName] The name to identify the client
562
- * @returns {ProviderMetadata} Provider Metadata
563
- */
564
- getProviderMetadata(clientName?: string): ProviderMetadata;
565
- /**
566
- * Adds a handler for the given provider event type.
567
- * The handlers are called in the order they have been added.
568
- * API (global) events run for all providers.
569
- * @param {AnyProviderEvent} eventType The provider event type to listen to
570
- * @param {EventHandler} handler The handler to run on occurrence of the event type
571
- */
572
- addHandler<T extends AnyProviderEvent>(eventType: T, handler: EventHandler): void;
573
- /**
574
- * Removes a handler for the given provider event type.
575
- * @param {AnyProviderEvent} eventType The provider event type to remove the listener for
576
- * @param {EventHandler} handler The handler to remove for the provider event type
577
- */
578
- removeHandler<T extends AnyProviderEvent>(eventType: T, handler: EventHandler): void;
579
- /**
580
- * Removes all event handlers.
581
- */
582
- clearHandlers(): void;
583
- /**
584
- * Gets the current handlers for the given provider event type.
585
- * @param {AnyProviderEvent} eventType The provider event type to get the current handlers for
586
- * @returns {EventHandler[]} The handlers currently attached to the given provider event type
587
- */
588
- getHandlers<T extends AnyProviderEvent>(eventType: T): EventHandler[];
589
- /**
590
- * Sets the default provider for flag evaluations and returns a promise that resolves when the provider is ready.
591
- * This provider will be used by unnamed clients and named clients to which no provider is bound.
592
- * Setting a provider supersedes the current provider used in new and existing clients without a name.
593
- * @template P
594
- * @param {P} provider The provider responsible for flag evaluations.
595
- * @returns {Promise<void>}
596
- * @throws Uncaught exceptions thrown by the provider during initialization.
597
- */
598
- setProviderAndWait(provider: P): Promise<void>;
599
- /**
600
- * Sets the provider that OpenFeature will use for flag evaluations of providers with the given name.
601
- * A promise is returned that resolves when the provider is ready.
602
- * Setting a provider supersedes the current provider used in new and existing clients with that name.
603
- * @template P
604
- * @param {string} clientName The name to identify the client
605
- * @param {P} provider The provider responsible for flag evaluations.
606
- * @returns {Promise<void>}
607
- * @throws Uncaught exceptions thrown by the provider during initialization.
608
- */
609
- setProviderAndWait(clientName: string, provider: P): Promise<void>;
610
- /**
611
- * Sets the default provider for flag evaluations.
612
- * This provider will be used by unnamed clients and named clients to which no provider is bound.
613
- * Setting a provider supersedes the current provider used in new and existing clients without a name.
614
- * @template P
615
- * @param {P} provider The provider responsible for flag evaluations.
616
- * @returns {this} OpenFeature API
617
- */
618
- setProvider(provider: P): this;
619
- /**
620
- * Sets the provider that OpenFeature will use for flag evaluations of providers with the given name.
621
- * Setting a provider supersedes the current provider used in new and existing clients with that name.
622
- * @template P
623
- * @param {string} clientName The name to identify the client
624
- * @param {P} provider The provider responsible for flag evaluations.
625
- * @returns {this} OpenFeature API
626
- */
627
- setProvider(clientName: string, provider: P): this;
628
- private setAwaitableProvider;
629
- protected getProviderForClient(name?: string): P;
630
- protected buildAndCacheEventEmitterForClient(name?: string): GenericEventEmitter<AnyProviderEvent>;
631
- private getUnboundEmitters;
632
- protected getAssociatedEventEmitters(clientName: string | undefined): GenericEventEmitter<AnyProviderEvent, Record<string, unknown>>[];
633
- private transferListeners;
634
- close(): Promise<void>;
635
- protected clearProvidersAndSetDefault(defaultProvider: P): Promise<void>;
636
- private handleShutdownError;
637
- }
638
-
639
6
  interface FlagEvaluationOptions {
640
7
  hooks?: BaseHook[];
641
8
  hookHints?: HookHints;
@@ -872,7 +239,11 @@ declare class InMemoryProvider implements Provider {
872
239
  }
873
240
 
874
241
  type OpenFeatureClientOptions = {
242
+ /**
243
+ * @deprecated Use `domain` instead.
244
+ */
875
245
  name?: string;
246
+ domain?: string;
876
247
  version?: string;
877
248
  };
878
249
  declare class OpenFeatureClient implements Client {
@@ -913,7 +284,6 @@ declare class OpenFeatureAPI extends OpenFeatureCommonAPI<Provider, Hook> implem
913
284
  protected _events: GenericEventEmitter<ClientProviderEvents>;
914
285
  protected _defaultProvider: Provider;
915
286
  protected _createEventEmitter: () => OpenFeatureEventEmitter;
916
- protected _namedProviderContext: Map<string, EvaluationContext>;
917
287
  private constructor();
918
288
  /**
919
289
  * Gets a singleton instance of the OpenFeature API.
@@ -923,7 +293,7 @@ declare class OpenFeatureAPI extends OpenFeatureCommonAPI<Provider, Hook> implem
923
293
  static getInstance(): OpenFeatureAPI;
924
294
  /**
925
295
  * Sets the evaluation context globally.
926
- * This will be used by all providers that have not been overridden with a named client.
296
+ * This will be used by all providers that have not bound to a domain.
927
297
  * @param {EvaluationContext} context Evaluation context
928
298
  * @example
929
299
  * await OpenFeature.setContext({ region: "us" });
@@ -931,15 +301,15 @@ declare class OpenFeatureAPI extends OpenFeatureCommonAPI<Provider, Hook> implem
931
301
  setContext(context: EvaluationContext): Promise<void>;
932
302
  /**
933
303
  * Sets the evaluation context for a specific provider.
934
- * This will only affect providers with a matching client name.
935
- * @param {string} clientName The name to identify the client
304
+ * This will only affect providers bound to a domain.
305
+ * @param {string} domain An identifier which logically binds clients with providers
936
306
  * @param {EvaluationContext} context Evaluation context
937
307
  * @example
938
308
  * await OpenFeature.setContext("test", { scope: "provider" });
939
309
  * OpenFeature.setProvider(new MyProvider()) // Uses the default context
940
310
  * OpenFeature.setProvider("test", new MyProvider()) // Uses context: { scope: "provider" }
941
311
  */
942
- setContext(clientName: string, context: EvaluationContext): Promise<void>;
312
+ setContext(domain: string, context: EvaluationContext): Promise<void>;
943
313
  /**
944
314
  * Access the global evaluation context.
945
315
  * @returns {EvaluationContext} Evaluation context
@@ -948,22 +318,22 @@ declare class OpenFeatureAPI extends OpenFeatureCommonAPI<Provider, Hook> implem
948
318
  /**
949
319
  * Access the evaluation context for a specific named client.
950
320
  * The global evaluation context is returned if a matching named client is not found.
951
- * @param {string} clientName The name to identify the client
321
+ * @param {string} domain An identifier which logically binds clients with providers
952
322
  * @returns {EvaluationContext} Evaluation context
953
323
  */
954
- getContext(clientName?: string): EvaluationContext;
324
+ getContext(domain?: string): EvaluationContext;
955
325
  /**
956
326
  * Resets the global evaluation context to an empty object.
957
327
  */
958
328
  clearContext(): Promise<void>;
959
329
  /**
960
330
  * Removes the evaluation context for a specific named client.
961
- * @param {string} clientName The name to identify the client
331
+ * @param {string} domain An identifier which logically binds clients with providers
962
332
  */
963
- clearContext(clientName: string): Promise<void>;
333
+ clearContext(domain: string): Promise<void>;
964
334
  /**
965
335
  * Resets the global evaluation context and removes the evaluation context for
966
- * all named clients.
336
+ * all domains.
967
337
  */
968
338
  clearContexts(): Promise<void>;
969
339
  /**
@@ -973,11 +343,11 @@ declare class OpenFeatureAPI extends OpenFeatureCommonAPI<Provider, Hook> implem
973
343
  *
974
344
  * If there is already a provider bound to this name via {@link this.setProvider setProvider}, this provider will be used.
975
345
  * Otherwise, the default provider is used until a provider is assigned to that name.
976
- * @param {string} name The name of the client
346
+ * @param {string} domain An identifier which logically binds clients with providers
977
347
  * @param {string} version The version of the client (only used for metadata)
978
348
  * @returns {Client} OpenFeature Client
979
349
  */
980
- getClient(name?: string, version?: string): Client;
350
+ getClient(domain?: string, version?: string): Client;
981
351
  /**
982
352
  * Clears all registered providers and resets the default provider.
983
353
  * @returns {Promise<void>}
@@ -991,4 +361,4 @@ declare class OpenFeatureAPI extends OpenFeatureCommonAPI<Provider, Hook> implem
991
361
  */
992
362
  declare const OpenFeature: OpenFeatureAPI;
993
363
 
994
- export { ClientProviderEvents as AllProviderEvents, AnyProviderEvent, BaseHook, BeforeHookContext, Client, ClientMetadata, ClientProviderEvents, CommonEventDetails, CommonProvider, ConfigChangeEvent, DefaultLogger, ErrorCode, ErrorEvent, EvaluationContext, EvaluationContextValue, EvaluationDetails, EvaluationLifeCycle, EventContext, EventDetails, EventHandler, EventMetadata, Eventing, Features, FlagEvaluationOptions, FlagMetadata, FlagNotFoundError, FlagValue, FlagValueType, GeneralError, GenericEventEmitter, Hook, HookContext, HookHints, InMemoryProvider, InvalidContextError, JsonArray, JsonObject, JsonValue, LOG_LEVELS, Logger, ManageContext, ManageLogger, Metadata, NOOP_PROVIDER, OpenFeature, OpenFeatureAPI, OpenFeatureClient, OpenFeatureCommonAPI, OpenFeatureError, OpenFeatureEventEmitter, Paradigm, ParseError, PrimitiveValue, Provider, ProviderEmittableEvents, ClientProviderEvents as ProviderEvents, ProviderMetadata, ProviderNotReadyError, ProviderStatus, ReadyEvent, ResolutionDetails, ResolutionReason, SafeLogger, ServerProviderEvents, StaleEvent, StandardResolutionReasons, TargetingKeyMissingError, TypeMismatchError, isObject, isString, objectOrUndefined, statusMatchesEvent, stringOrUndefined };
364
+ export { Client, Features, FlagEvaluationOptions, Hook, InMemoryProvider, NOOP_PROVIDER, OpenFeature, OpenFeatureAPI, OpenFeatureClient, OpenFeatureEventEmitter, Provider, ProviderEmittableEvents };