@openfeature/web-sdk 0.4.3 → 0.4.5
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 +27 -25
- package/dist/cjs/index.js +52 -36
- package/dist/cjs/index.js.map +4 -4
- package/dist/esm/index.js +44 -30
- package/dist/esm/index.js.map +4 -4
- package/dist/types.d.ts +587 -4
- package/package.json +3 -3
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,566 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import EventEmitter from 'events';
|
|
2
|
+
|
|
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
|
+
declare enum ProviderEvents {
|
|
134
|
+
/**
|
|
135
|
+
* The provider is ready to evaluate flags.
|
|
136
|
+
*/
|
|
137
|
+
Ready = "PROVIDER_READY",
|
|
138
|
+
/**
|
|
139
|
+
* The provider is in an error state.
|
|
140
|
+
*/
|
|
141
|
+
Error = "PROVIDER_ERROR",
|
|
142
|
+
/**
|
|
143
|
+
* The flag configuration in the source-of-truth has changed.
|
|
144
|
+
*/
|
|
145
|
+
ConfigurationChanged = "PROVIDER_CONFIGURATION_CHANGED",
|
|
146
|
+
/**
|
|
147
|
+
* The provider's cached state is no longer valid and may not be up-to-date with the source of truth.
|
|
148
|
+
*/
|
|
149
|
+
Stale = "PROVIDER_STALE"
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Returns true if the provider's status corresponds to the event.
|
|
154
|
+
* If the provider's status is not defined, it matches READY.
|
|
155
|
+
* @param {ProviderEvents} event event to match
|
|
156
|
+
* @param {ProviderStatus} status status of provider
|
|
157
|
+
* @returns {boolean} boolean indicating if the provider status corresponds to the event.
|
|
158
|
+
*/
|
|
159
|
+
declare const statusMatchesEvent: (event: ProviderEvents, status?: ProviderStatus) => boolean;
|
|
160
|
+
|
|
161
|
+
type EventMetadata = {
|
|
162
|
+
[key: string]: string | boolean | number;
|
|
163
|
+
};
|
|
164
|
+
type CommonEventDetails = {
|
|
165
|
+
providerName: string;
|
|
166
|
+
clientName?: string;
|
|
167
|
+
};
|
|
168
|
+
type CommonEventProps = {
|
|
169
|
+
message?: string;
|
|
170
|
+
metadata?: EventMetadata;
|
|
171
|
+
};
|
|
172
|
+
type ReadyEvent = CommonEventProps;
|
|
173
|
+
type ErrorEvent = CommonEventProps;
|
|
174
|
+
type StaleEvent = CommonEventProps;
|
|
175
|
+
type ConfigChangeEvent = CommonEventProps & {
|
|
176
|
+
flagsChanged?: string[];
|
|
177
|
+
};
|
|
178
|
+
type EventMap = {
|
|
179
|
+
[ProviderEvents.Ready]: ReadyEvent;
|
|
180
|
+
[ProviderEvents.Error]: ErrorEvent;
|
|
181
|
+
[ProviderEvents.Stale]: StaleEvent;
|
|
182
|
+
[ProviderEvents.ConfigurationChanged]: ConfigChangeEvent;
|
|
183
|
+
};
|
|
184
|
+
type EventContext<T extends ProviderEvents, U extends Record<string, unknown> = Record<string, unknown>> = EventMap[T] & U;
|
|
185
|
+
type EventDetails<T extends ProviderEvents> = EventContext<T> & CommonEventDetails;
|
|
186
|
+
type EventHandler<T extends ProviderEvents> = (eventDetails?: EventDetails<T>) => Promise<unknown> | unknown;
|
|
187
|
+
interface Eventing {
|
|
188
|
+
/**
|
|
189
|
+
* Adds a handler for the given provider event type.
|
|
190
|
+
* The handlers are called in the order they have been added.
|
|
191
|
+
* @param {ProviderEvents} eventType The provider event type to listen to
|
|
192
|
+
* @param {EventHandler} handler The handler to run on occurrence of the event type
|
|
193
|
+
*/
|
|
194
|
+
addHandler<T extends ProviderEvents>(eventType: T, handler: EventHandler<T>): void;
|
|
195
|
+
/**
|
|
196
|
+
* Removes a handler for the given provider event type.
|
|
197
|
+
* @param {ProviderEvents} eventType The provider event type to remove the listener for
|
|
198
|
+
* @param {EventHandler} handler The handler to remove for the provider event type
|
|
199
|
+
*/
|
|
200
|
+
removeHandler<T extends ProviderEvents>(eventType: T, handler: EventHandler<T>): void;
|
|
201
|
+
/**
|
|
202
|
+
* Gets the current handlers for the given provider event type.
|
|
203
|
+
* @param {ProviderEvents} eventType The provider event type to get the current handlers for
|
|
204
|
+
* @returns {EventHandler[]} The handlers currently attached to the given provider event type
|
|
205
|
+
*/
|
|
206
|
+
getHandlers<T extends ProviderEvents>(eventType: T): EventHandler<T>[];
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
interface Logger {
|
|
210
|
+
error(...args: unknown[]): void;
|
|
211
|
+
warn(...args: unknown[]): void;
|
|
212
|
+
info(...args: unknown[]): void;
|
|
213
|
+
debug(...args: unknown[]): void;
|
|
214
|
+
}
|
|
215
|
+
interface ManageLogger<T> {
|
|
216
|
+
/**
|
|
217
|
+
* Sets a logger on this receiver. This logger supersedes to the global logger
|
|
218
|
+
* and is passed to various components in the SDK.
|
|
219
|
+
* The logger configured on the global API object will be used for all evaluations,
|
|
220
|
+
* unless overridden in a particular client.
|
|
221
|
+
* @template T The type of the receiver
|
|
222
|
+
* @param {Logger} logger The logger to be used
|
|
223
|
+
* @returns {T} The receiver (this object)
|
|
224
|
+
*/
|
|
225
|
+
setLogger(logger: Logger): T;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
declare class DefaultLogger implements Logger {
|
|
229
|
+
error(...args: unknown[]): void;
|
|
230
|
+
warn(...args: unknown[]): void;
|
|
231
|
+
info(): void;
|
|
232
|
+
debug(): void;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
declare const LOG_LEVELS: Array<keyof Logger>;
|
|
236
|
+
declare class SafeLogger implements Logger {
|
|
237
|
+
private readonly logger;
|
|
238
|
+
private readonly fallbackLogger;
|
|
239
|
+
constructor(logger: Logger);
|
|
240
|
+
error(...args: unknown[]): void;
|
|
241
|
+
warn(...args: unknown[]): void;
|
|
242
|
+
info(...args: unknown[]): void;
|
|
243
|
+
debug(...args: unknown[]): void;
|
|
244
|
+
private log;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* The GenericEventEmitter should only be used within the SDK. It supports additional properties that can be included
|
|
249
|
+
* in the event details.
|
|
250
|
+
*/
|
|
251
|
+
declare abstract class GenericEventEmitter<AdditionalContext extends Record<string, unknown> = Record<string, unknown>> implements ManageLogger<GenericEventEmitter<AdditionalContext>> {
|
|
252
|
+
private readonly globalLogger?;
|
|
253
|
+
protected abstract readonly eventEmitter: NodeJS.EventEmitter;
|
|
254
|
+
private readonly _handlers;
|
|
255
|
+
private _eventLogger?;
|
|
256
|
+
constructor(globalLogger?: (() => Logger) | undefined);
|
|
257
|
+
emit<T extends ProviderEvents>(eventType: T, context?: EventContext<T, AdditionalContext>): void;
|
|
258
|
+
addHandler<T extends ProviderEvents>(eventType: T, handler: EventHandler<T>): void;
|
|
259
|
+
removeHandler<T extends ProviderEvents>(eventType: T, handler: EventHandler<T>): void;
|
|
260
|
+
removeAllHandlers(eventType?: ProviderEvents): void;
|
|
261
|
+
getHandlers<T extends ProviderEvents>(eventType: T): EventHandler<T>[];
|
|
262
|
+
setLogger(logger: Logger): this;
|
|
263
|
+
protected get _logger(): Logger | undefined;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
interface Metadata {
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Defines where the library is intended to be run.
|
|
271
|
+
*/
|
|
272
|
+
type Paradigm = 'server' | 'client';
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* The state of the provider.
|
|
276
|
+
*/
|
|
277
|
+
declare enum ProviderStatus {
|
|
278
|
+
/**
|
|
279
|
+
* The provider has not been initialized and cannot yet evaluate flags.
|
|
280
|
+
*/
|
|
281
|
+
NOT_READY = "NOT_READY",
|
|
282
|
+
/**
|
|
283
|
+
* The provider is ready to resolve flags.
|
|
284
|
+
*/
|
|
285
|
+
READY = "READY",
|
|
286
|
+
/**
|
|
287
|
+
* The provider is in an error state and unable to evaluate flags.
|
|
288
|
+
*/
|
|
289
|
+
ERROR = "ERROR",
|
|
290
|
+
/**
|
|
291
|
+
* The provider's cached state is no longer valid and may not be up-to-date with the source of truth.
|
|
292
|
+
*/
|
|
293
|
+
STALE = "STALE"
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Static data about the provider.
|
|
297
|
+
*/
|
|
298
|
+
interface ProviderMetadata extends Metadata {
|
|
299
|
+
readonly name: string;
|
|
300
|
+
}
|
|
301
|
+
interface CommonProvider {
|
|
302
|
+
readonly metadata: ProviderMetadata;
|
|
303
|
+
/**
|
|
304
|
+
* Represents where the provider is intended to be run. If defined,
|
|
305
|
+
* the SDK will enforce that the defined paradigm at runtime.
|
|
306
|
+
*/
|
|
307
|
+
readonly runsOn?: Paradigm;
|
|
308
|
+
/**
|
|
309
|
+
* Returns a representation of the current readiness of the provider.
|
|
310
|
+
* If the provider needs to be initialized, it should return {@link ProviderStatus.READY}.
|
|
311
|
+
* If the provider is in an error state, it should return {@link ProviderStatus.ERROR}.
|
|
312
|
+
* If the provider is functioning normally, it should return {@link ProviderStatus.NOT_READY}.
|
|
313
|
+
*
|
|
314
|
+
* _Providers which do not implement this method are assumed to be ready immediately._
|
|
315
|
+
*/
|
|
316
|
+
readonly status?: ProviderStatus;
|
|
317
|
+
/**
|
|
318
|
+
* An event emitter for ProviderEvents.
|
|
319
|
+
* @see ProviderEvents
|
|
320
|
+
*/
|
|
321
|
+
events?: GenericEventEmitter;
|
|
322
|
+
/**
|
|
323
|
+
* A function used to shut down the provider.
|
|
324
|
+
* Called when this provider is replaced with a new one, or when the OpenFeature is shut down.
|
|
325
|
+
*/
|
|
326
|
+
onClose?(): Promise<void>;
|
|
327
|
+
/**
|
|
328
|
+
* A function used to setup the provider.
|
|
329
|
+
* Called by the SDK after the provider is set if the provider's status is {@link ProviderStatus.NOT_READY}.
|
|
330
|
+
* When the returned promise resolves, the SDK fires the ProviderEvents.Ready event.
|
|
331
|
+
* If the returned promise rejects, the SDK fires the ProviderEvents.Error event.
|
|
332
|
+
* Use this function to perform any context-dependent setup within the provider.
|
|
333
|
+
* @param context
|
|
334
|
+
*/
|
|
335
|
+
initialize?(context?: EvaluationContext): Promise<void>;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
interface ClientMetadata extends Metadata {
|
|
339
|
+
readonly version?: string;
|
|
340
|
+
readonly name?: string;
|
|
341
|
+
readonly providerMetadata: ProviderMetadata;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
type HookHints = Readonly<Record<string, unknown>>;
|
|
345
|
+
interface HookContext<T extends FlagValue = FlagValue> {
|
|
346
|
+
readonly flagKey: string;
|
|
347
|
+
readonly defaultValue: T;
|
|
348
|
+
readonly flagValueType: FlagValueType;
|
|
349
|
+
readonly context: Readonly<EvaluationContext>;
|
|
350
|
+
readonly clientMetadata: ClientMetadata;
|
|
351
|
+
readonly providerMetadata: ProviderMetadata;
|
|
352
|
+
readonly logger: Logger;
|
|
353
|
+
}
|
|
354
|
+
interface BeforeHookContext extends HookContext {
|
|
355
|
+
context: EvaluationContext;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
interface Hook<T extends FlagValue = FlagValue> {
|
|
359
|
+
/**
|
|
360
|
+
* Runs before flag values are resolved from the provider.
|
|
361
|
+
* If an EvaluationContext is returned, it will be merged with the pre-existing EvaluationContext.
|
|
362
|
+
* @param hookContext
|
|
363
|
+
* @param hookHints
|
|
364
|
+
*/
|
|
365
|
+
before?(hookContext: BeforeHookContext, hookHints?: HookHints): Promise<EvaluationContext | void> | EvaluationContext | void;
|
|
366
|
+
/**
|
|
367
|
+
* Runs after flag values are successfully resolved from the provider.
|
|
368
|
+
* @param hookContext
|
|
369
|
+
* @param evaluationDetails
|
|
370
|
+
* @param hookHints
|
|
371
|
+
*/
|
|
372
|
+
after?(hookContext: Readonly<HookContext<T>>, evaluationDetails: EvaluationDetails<T>, hookHints?: HookHints): Promise<void> | void;
|
|
373
|
+
/**
|
|
374
|
+
* Runs in the event of an unhandled error or promise rejection during flag resolution, or any attached hooks.
|
|
375
|
+
* @param hookContext
|
|
376
|
+
* @param error
|
|
377
|
+
* @param hookHints
|
|
378
|
+
*/
|
|
379
|
+
error?(hookContext: Readonly<HookContext<T>>, error: unknown, hookHints?: HookHints): Promise<void> | void;
|
|
380
|
+
/**
|
|
381
|
+
* Runs after all other hook stages, regardless of success or error.
|
|
382
|
+
* Errors thrown here are unhandled by the client and will surface in application code.
|
|
383
|
+
* @param hookContext
|
|
384
|
+
* @param hookHints
|
|
385
|
+
*/
|
|
386
|
+
finally?(hookContext: Readonly<HookContext<T>>, hookHints?: HookHints): Promise<void> | void;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
interface EvaluationLifeCycle<T> {
|
|
390
|
+
/**
|
|
391
|
+
* Adds hooks that will run during flag evaluations on this receiver.
|
|
392
|
+
* Hooks are executed in the order they were registered. Adding additional hooks
|
|
393
|
+
* will not remove existing hooks.
|
|
394
|
+
* Hooks registered on the global API object run with all evaluations.
|
|
395
|
+
* Hooks registered on the client run with all evaluations on that client.
|
|
396
|
+
* @template T The type of the receiver
|
|
397
|
+
* @param {Hook<FlagValue>[]} hooks A list of hooks that should always run
|
|
398
|
+
* @returns {T} The receiver (this object)
|
|
399
|
+
*/
|
|
400
|
+
addHooks(...hooks: Hook<FlagValue>[]): T;
|
|
401
|
+
/**
|
|
402
|
+
* Access all the hooks that are registered on this receiver.
|
|
403
|
+
* @returns {Hook<FlagValue>[]} A list of the client hooks
|
|
404
|
+
*/
|
|
405
|
+
getHooks(): Hook<FlagValue>[];
|
|
406
|
+
/**
|
|
407
|
+
* Clears all the hooks that are registered on this receiver.
|
|
408
|
+
* @template T The type of the receiver
|
|
409
|
+
* @returns {T} The receiver (this object)
|
|
410
|
+
*/
|
|
411
|
+
clearHooks(): T;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
declare abstract class OpenFeatureError extends Error {
|
|
415
|
+
abstract code: ErrorCode;
|
|
416
|
+
constructor(message?: string);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
declare class GeneralError extends OpenFeatureError {
|
|
420
|
+
code: ErrorCode;
|
|
421
|
+
constructor(message?: string);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
declare class FlagNotFoundError extends OpenFeatureError {
|
|
425
|
+
code: ErrorCode;
|
|
426
|
+
constructor(message?: string);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
declare class ParseError extends OpenFeatureError {
|
|
430
|
+
code: ErrorCode;
|
|
431
|
+
constructor(message?: string);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
declare class TypeMismatchError extends OpenFeatureError {
|
|
435
|
+
code: ErrorCode;
|
|
436
|
+
constructor(message?: string);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
declare class TargetingKeyMissingError extends OpenFeatureError {
|
|
440
|
+
code: ErrorCode;
|
|
441
|
+
constructor(message?: string);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
declare class InvalidContextError extends OpenFeatureError {
|
|
445
|
+
code: ErrorCode;
|
|
446
|
+
constructor(message?: string);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* Checks whether the parameter is a string.
|
|
451
|
+
* @param {unknown} value The value to check
|
|
452
|
+
* @returns {value is string} True if the value is a string
|
|
453
|
+
*/
|
|
454
|
+
declare function isString(value: unknown): value is string;
|
|
455
|
+
/**
|
|
456
|
+
* Returns the parameter if it is a string, otherwise returns undefined.
|
|
457
|
+
* @param {unknown} value The value to check
|
|
458
|
+
* @returns {string|undefined} The parameter if it is a string, otherwise undefined
|
|
459
|
+
*/
|
|
460
|
+
declare function stringOrUndefined(value: unknown): string | undefined;
|
|
461
|
+
/**
|
|
462
|
+
* Checks whether the parameter is an object.
|
|
463
|
+
* @param {unknown} value The value to check
|
|
464
|
+
* @returns {value is string} True if the value is an object
|
|
465
|
+
*/
|
|
466
|
+
declare function isObject<T extends object>(value: unknown): value is T;
|
|
467
|
+
/**
|
|
468
|
+
* Returns the parameter if it is an object, otherwise returns undefined.
|
|
469
|
+
* @param {unknown} value The value to check
|
|
470
|
+
* @returns {object|undefined} The parameter if it is an object, otherwise undefined
|
|
471
|
+
*/
|
|
472
|
+
declare function objectOrUndefined<T extends object>(value: unknown): T | undefined;
|
|
473
|
+
|
|
474
|
+
declare abstract class OpenFeatureCommonAPI<P extends CommonProvider = CommonProvider> implements Eventing, EvaluationLifeCycle<OpenFeatureCommonAPI<P>>, ManageLogger<OpenFeatureCommonAPI<P>> {
|
|
475
|
+
protected abstract _createEventEmitter(): GenericEventEmitter;
|
|
476
|
+
protected abstract _defaultProvider: P;
|
|
477
|
+
protected abstract readonly _events: GenericEventEmitter;
|
|
478
|
+
protected _hooks: Hook[];
|
|
479
|
+
protected _context: EvaluationContext;
|
|
480
|
+
protected _logger: Logger;
|
|
481
|
+
private readonly _clientEventHandlers;
|
|
482
|
+
protected _clientProviders: Map<string, P>;
|
|
483
|
+
protected _clientEvents: Map<string | undefined, GenericEventEmitter>;
|
|
484
|
+
protected _runsOn: Paradigm;
|
|
485
|
+
constructor(category: Paradigm);
|
|
486
|
+
addHooks(...hooks: Hook<FlagValue>[]): this;
|
|
487
|
+
getHooks(): Hook<FlagValue>[];
|
|
488
|
+
clearHooks(): this;
|
|
489
|
+
setLogger(logger: Logger): this;
|
|
490
|
+
/**
|
|
491
|
+
* Get metadata about registered provider.
|
|
492
|
+
* @returns {ProviderMetadata} Provider Metadata
|
|
493
|
+
*/
|
|
494
|
+
get providerMetadata(): ProviderMetadata;
|
|
495
|
+
/**
|
|
496
|
+
* Adds a handler for the given provider event type.
|
|
497
|
+
* The handlers are called in the order they have been added.
|
|
498
|
+
* API (global) events run for all providers.
|
|
499
|
+
* @param {ProviderEvents} eventType The provider event type to listen to
|
|
500
|
+
* @param {EventHandler} handler The handler to run on occurrence of the event type
|
|
501
|
+
*/
|
|
502
|
+
addHandler<T extends ProviderEvents>(eventType: T, handler: EventHandler<T>): void;
|
|
503
|
+
/**
|
|
504
|
+
* Removes a handler for the given provider event type.
|
|
505
|
+
* @param {ProviderEvents} eventType The provider event type to remove the listener for
|
|
506
|
+
* @param {EventHandler} handler The handler to remove for the provider event type
|
|
507
|
+
*/
|
|
508
|
+
removeHandler<T extends ProviderEvents>(eventType: T, handler: EventHandler<T>): void;
|
|
509
|
+
/**
|
|
510
|
+
* Gets the current handlers for the given provider event type.
|
|
511
|
+
* @param {ProviderEvents} eventType The provider event type to get the current handlers for
|
|
512
|
+
* @returns {EventHandler[]} The handlers currently attached to the given provider event type
|
|
513
|
+
*/
|
|
514
|
+
getHandlers<T extends ProviderEvents>(eventType: T): EventHandler<T>[];
|
|
515
|
+
/**
|
|
516
|
+
* Sets the default provider for flag evaluations and returns a promise that resolves when the provider is ready.
|
|
517
|
+
* This provider will be used by unnamed clients and named clients to which no provider is bound.
|
|
518
|
+
* Setting a provider supersedes the current provider used in new and existing clients without a name.
|
|
519
|
+
* @template P
|
|
520
|
+
* @param {P} provider The provider responsible for flag evaluations.
|
|
521
|
+
* @returns {Promise<void>}
|
|
522
|
+
* @throws Uncaught exceptions thrown by the provider during initialization.
|
|
523
|
+
*/
|
|
524
|
+
setProviderAndWait(provider: P): Promise<void>;
|
|
525
|
+
/**
|
|
526
|
+
* Sets the provider that OpenFeature will use for flag evaluations of providers with the given name.
|
|
527
|
+
* A promise is returned that resolves when the provider is ready.
|
|
528
|
+
* Setting a provider supersedes the current provider used in new and existing clients with that name.
|
|
529
|
+
* @template P
|
|
530
|
+
* @param {string} clientName The name to identify the client
|
|
531
|
+
* @param {P} provider The provider responsible for flag evaluations.
|
|
532
|
+
* @returns {Promise<void>}
|
|
533
|
+
* @throws Uncaught exceptions thrown by the provider during initialization.
|
|
534
|
+
*/
|
|
535
|
+
setProviderAndWait(clientName: string, provider: P): Promise<void>;
|
|
536
|
+
/**
|
|
537
|
+
* Sets the default provider for flag evaluations.
|
|
538
|
+
* This provider will be used by unnamed clients and named clients to which no provider is bound.
|
|
539
|
+
* Setting a provider supersedes the current provider used in new and existing clients without a name.
|
|
540
|
+
* @template P
|
|
541
|
+
* @param {P} provider The provider responsible for flag evaluations.
|
|
542
|
+
* @returns {this} OpenFeature API
|
|
543
|
+
*/
|
|
544
|
+
setProvider(provider: P): this;
|
|
545
|
+
/**
|
|
546
|
+
* Sets the provider that OpenFeature will use for flag evaluations of providers with the given name.
|
|
547
|
+
* Setting a provider supersedes the current provider used in new and existing clients with that name.
|
|
548
|
+
* @template P
|
|
549
|
+
* @param {string} clientName The name to identify the client
|
|
550
|
+
* @param {P} provider The provider responsible for flag evaluations.
|
|
551
|
+
* @returns {this} OpenFeature API
|
|
552
|
+
*/
|
|
553
|
+
setProvider(clientName: string, provider: P): this;
|
|
554
|
+
private setAwaitableProvider;
|
|
555
|
+
protected getProviderForClient(name?: string): P;
|
|
556
|
+
protected buildAndCacheEventEmitterForClient(name?: string): GenericEventEmitter;
|
|
557
|
+
private getUnboundEmitters;
|
|
558
|
+
private getAssociatedEventEmitters;
|
|
559
|
+
private transferListeners;
|
|
560
|
+
close(): Promise<void>;
|
|
561
|
+
protected clearProvidersAndSetDefault(defaultProvider: P): Promise<void>;
|
|
562
|
+
private handleShutdownError;
|
|
563
|
+
}
|
|
3
564
|
|
|
4
565
|
interface FlagEvaluationOptions {
|
|
5
566
|
hooks?: Hook[];
|
|
@@ -143,6 +704,14 @@ declare class NoopFeatureProvider implements Provider {
|
|
|
143
704
|
}
|
|
144
705
|
declare const NOOP_PROVIDER: NoopFeatureProvider;
|
|
145
706
|
|
|
707
|
+
/**
|
|
708
|
+
* The InternalEventEmitter is not exported publicly and should only be used within the SDK. It extends the
|
|
709
|
+
* OpenFeatureEventEmitter to include additional properties that can be included
|
|
710
|
+
* in the event details.
|
|
711
|
+
*/
|
|
712
|
+
declare abstract class InternalEventEmitter extends GenericEventEmitter<CommonEventDetails> {
|
|
713
|
+
}
|
|
714
|
+
|
|
146
715
|
type OpenFeatureClientOptions = {
|
|
147
716
|
name?: string;
|
|
148
717
|
version?: string;
|
|
@@ -154,7 +723,7 @@ declare class OpenFeatureClient implements Client {
|
|
|
154
723
|
private readonly options;
|
|
155
724
|
private _hooks;
|
|
156
725
|
private _clientLogger?;
|
|
157
|
-
constructor(providerAccessor: () => Provider, emitterAccessor: () =>
|
|
726
|
+
constructor(providerAccessor: () => Provider, emitterAccessor: () => InternalEventEmitter, globalLogger: () => Logger, options: OpenFeatureClientOptions);
|
|
158
727
|
get metadata(): ClientMetadata;
|
|
159
728
|
addHandler<T extends ProviderEvents>(eventType: T, handler: EventHandler<T>): void;
|
|
160
729
|
removeHandler<T extends ProviderEvents>(notificationType: T, handler: EventHandler<T>): void;
|
|
@@ -180,8 +749,22 @@ declare class OpenFeatureClient implements Client {
|
|
|
180
749
|
private get _logger();
|
|
181
750
|
}
|
|
182
751
|
|
|
752
|
+
/**
|
|
753
|
+
* The OpenFeatureEventEmitter can be used by provider developers to emit
|
|
754
|
+
* events at various parts of the provider lifecycle.
|
|
755
|
+
*
|
|
756
|
+
* NOTE: Ready and error events are automatically emitted by the SDK based on
|
|
757
|
+
* the result of the initialize method.
|
|
758
|
+
*/
|
|
759
|
+
declare class OpenFeatureEventEmitter extends GenericEventEmitter {
|
|
760
|
+
protected readonly eventEmitter: EventEmitter;
|
|
761
|
+
constructor();
|
|
762
|
+
}
|
|
763
|
+
|
|
183
764
|
declare class OpenFeatureAPI extends OpenFeatureCommonAPI<Provider> implements ManageContext<Promise<void>> {
|
|
765
|
+
protected _events: OpenFeatureEventEmitter;
|
|
184
766
|
protected _defaultProvider: Provider;
|
|
767
|
+
protected _createEventEmitter: () => OpenFeatureEventEmitter;
|
|
185
768
|
private constructor();
|
|
186
769
|
/**
|
|
187
770
|
* Gets a singleton instance of the OpenFeature API.
|
|
@@ -215,4 +798,4 @@ declare class OpenFeatureAPI extends OpenFeatureCommonAPI<Provider> implements M
|
|
|
215
798
|
*/
|
|
216
799
|
declare const OpenFeature: OpenFeatureAPI;
|
|
217
800
|
|
|
218
|
-
export { Client, Features, FlagEvaluationOptions, NOOP_PROVIDER, OpenFeature, OpenFeatureAPI, OpenFeatureClient, Provider };
|
|
801
|
+
export { BeforeHookContext, Client, ClientMetadata, 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, InvalidContextError, JsonArray, JsonObject, JsonValue, LOG_LEVELS, Logger, ManageContext, ManageLogger, Metadata, NOOP_PROVIDER, OpenFeature, OpenFeatureAPI, OpenFeatureClient, OpenFeatureCommonAPI, OpenFeatureError, OpenFeatureEventEmitter, Paradigm, ParseError, PrimitiveValue, Provider, ProviderEvents, ProviderMetadata, ProviderStatus, ReadyEvent, ResolutionDetails, ResolutionReason, SafeLogger, StaleEvent, StandardResolutionReasons, TargetingKeyMissingError, TypeMismatchError, isObject, isString, objectOrUndefined, statusMatchesEvent, stringOrUndefined };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfeature/web-sdk",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.5",
|
|
4
4
|
"description": "OpenFeature SDK for Web",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"files": [
|
|
@@ -46,9 +46,9 @@
|
|
|
46
46
|
},
|
|
47
47
|
"homepage": "https://github.com/open-feature/js-sdk#readme",
|
|
48
48
|
"peerDependencies": {
|
|
49
|
-
"@openfeature/core": "0.0.
|
|
49
|
+
"@openfeature/core": "0.0.18"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@openfeature/core": "0.0.
|
|
52
|
+
"@openfeature/core": "0.0.18"
|
|
53
53
|
}
|
|
54
54
|
}
|