@openfeature/web-sdk 0.0.2-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/LICENSE +201 -0
- package/README.md +18 -0
- package/dist/cjs/index.js +598 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/esm/index.js +578 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/package.json +3 -0
- package/dist/types.d.ts +627 -0
- package/package.json +51 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,627 @@
|
|
|
1
|
+
type PrimitiveValue = null | boolean | string | number;
|
|
2
|
+
declare enum ProviderEvents {
|
|
3
|
+
/**
|
|
4
|
+
* The provider is ready to evaluate flags.
|
|
5
|
+
*/
|
|
6
|
+
Ready = "PROVIDER_READY",
|
|
7
|
+
/**
|
|
8
|
+
* The provider is in an error state.
|
|
9
|
+
*/
|
|
10
|
+
Error = "PROVIDER_ERROR",
|
|
11
|
+
/**
|
|
12
|
+
* The flag configuration in the source-of-truth has changed.
|
|
13
|
+
*/
|
|
14
|
+
ConfigurationChanged = "PROVIDER_CONFIGURATION_CHANGED",
|
|
15
|
+
/**
|
|
16
|
+
* The provider is transitioning to a state of unavailability.
|
|
17
|
+
*/
|
|
18
|
+
Shutdown = "PROVIDER_SHUTDOWN"
|
|
19
|
+
}
|
|
20
|
+
interface EventData {
|
|
21
|
+
flagKeysChanged?: string[];
|
|
22
|
+
changeMetadata?: {
|
|
23
|
+
[key: string]: boolean | string;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
declare enum ApiEvents {
|
|
27
|
+
ProviderChanged = "providerChanged"
|
|
28
|
+
}
|
|
29
|
+
interface Eventing {
|
|
30
|
+
addHandler(notificationType: string, handler: Handler): void;
|
|
31
|
+
}
|
|
32
|
+
type EventContext = {
|
|
33
|
+
notificationType: string;
|
|
34
|
+
[key: string]: unknown;
|
|
35
|
+
};
|
|
36
|
+
type Handler = (eventContext?: EventContext) => void;
|
|
37
|
+
type EventCallbackMessage = (eventContext: EventContext) => void;
|
|
38
|
+
type JsonObject = {
|
|
39
|
+
[key: string]: JsonValue;
|
|
40
|
+
};
|
|
41
|
+
type JsonArray = JsonValue[];
|
|
42
|
+
/**
|
|
43
|
+
* Represents a JSON node value.
|
|
44
|
+
*/
|
|
45
|
+
type JsonValue = PrimitiveValue | JsonObject | JsonArray;
|
|
46
|
+
/**
|
|
47
|
+
* Represents a JSON node value, or Date.
|
|
48
|
+
*/
|
|
49
|
+
type EvaluationContextValue = PrimitiveValue | Date | {
|
|
50
|
+
[key: string]: EvaluationContextValue;
|
|
51
|
+
} | EvaluationContextValue[];
|
|
52
|
+
/**
|
|
53
|
+
* A container for arbitrary contextual data that can be used as a basis for dynamic evaluation
|
|
54
|
+
*/
|
|
55
|
+
type EvaluationContext = {
|
|
56
|
+
/**
|
|
57
|
+
* A string uniquely identifying the subject (end-user, or client service) of a flag evaluation.
|
|
58
|
+
* Providers may require this field for fractional flag evaluation, rules, or overrides targeting specific users.
|
|
59
|
+
* Such providers may behave unpredictably if a targeting key is not specified at flag resolution.
|
|
60
|
+
*/
|
|
61
|
+
targetingKey?: string;
|
|
62
|
+
} & Record<string, EvaluationContextValue>;
|
|
63
|
+
type FlagValue = boolean | string | number | JsonValue;
|
|
64
|
+
type FlagValueType = 'boolean' | 'string' | 'number' | 'object';
|
|
65
|
+
interface Logger {
|
|
66
|
+
error(...args: unknown[]): void;
|
|
67
|
+
warn(...args: unknown[]): void;
|
|
68
|
+
info(...args: unknown[]): void;
|
|
69
|
+
debug(...args: unknown[]): void;
|
|
70
|
+
}
|
|
71
|
+
declare const StandardResolutionReasons: {
|
|
72
|
+
/**
|
|
73
|
+
* The resolved value was the result of a dynamic evaluation, such as a rule or specific user-targeting.
|
|
74
|
+
*/
|
|
75
|
+
readonly TARGETING_MATCH: "TARGETING_MATCH";
|
|
76
|
+
/**
|
|
77
|
+
* The resolved value was the result of pseudorandom assignment.
|
|
78
|
+
*/
|
|
79
|
+
readonly SPLIT: "SPLIT";
|
|
80
|
+
/**
|
|
81
|
+
* The resolved value was the result of the flag being disabled in the management system.
|
|
82
|
+
*/
|
|
83
|
+
readonly DISABLED: "DISABLED";
|
|
84
|
+
/**
|
|
85
|
+
* The resolved value was configured statically, or otherwise fell back to a pre-configured value.
|
|
86
|
+
*/
|
|
87
|
+
readonly DEFAULT: "DEFAULT";
|
|
88
|
+
/**
|
|
89
|
+
* The reason for the resolved value could not be determined.
|
|
90
|
+
*/
|
|
91
|
+
readonly UNKNOWN: "UNKNOWN";
|
|
92
|
+
/**
|
|
93
|
+
* The resolved value is static (no dynamic evaluation).
|
|
94
|
+
*/
|
|
95
|
+
readonly STATIC: "STATIC";
|
|
96
|
+
/**
|
|
97
|
+
* The resolved value was retrieved from cache.
|
|
98
|
+
*/
|
|
99
|
+
readonly CACHED: "CACHED";
|
|
100
|
+
/**
|
|
101
|
+
* The resolved value was the result of an error.
|
|
102
|
+
*
|
|
103
|
+
* Note: The `errorCode` and `errorMessage` fields may contain additional details of this error.
|
|
104
|
+
*/
|
|
105
|
+
readonly ERROR: "ERROR";
|
|
106
|
+
};
|
|
107
|
+
declare enum ErrorCode {
|
|
108
|
+
/**
|
|
109
|
+
* The value was resolved before the provider was ready.
|
|
110
|
+
*/
|
|
111
|
+
PROVIDER_NOT_READY = "PROVIDER_NOT_READY",
|
|
112
|
+
/**
|
|
113
|
+
* The flag could not be found.
|
|
114
|
+
*/
|
|
115
|
+
FLAG_NOT_FOUND = "FLAG_NOT_FOUND",
|
|
116
|
+
/**
|
|
117
|
+
* An error was encountered parsing data, such as a flag configuration.
|
|
118
|
+
*/
|
|
119
|
+
PARSE_ERROR = "PARSE_ERROR",
|
|
120
|
+
/**
|
|
121
|
+
* The type of the flag value does not match the expected type.
|
|
122
|
+
*/
|
|
123
|
+
TYPE_MISMATCH = "TYPE_MISMATCH",
|
|
124
|
+
/**
|
|
125
|
+
* The provider requires a targeting key and one was not provided in the evaluation context.
|
|
126
|
+
*/
|
|
127
|
+
TARGETING_KEY_MISSING = "TARGETING_KEY_MISSING",
|
|
128
|
+
/**
|
|
129
|
+
* The evaluation context does not meet provider requirements.
|
|
130
|
+
*/
|
|
131
|
+
INVALID_CONTEXT = "INVALID_CONTEXT",
|
|
132
|
+
/**
|
|
133
|
+
* An error with an unspecified code.
|
|
134
|
+
*/
|
|
135
|
+
GENERAL = "GENERAL"
|
|
136
|
+
}
|
|
137
|
+
type ResolutionReason = keyof typeof StandardResolutionReasons | (string & Record<never, never>);
|
|
138
|
+
type ResolutionDetails<U> = {
|
|
139
|
+
value: U;
|
|
140
|
+
variant?: string;
|
|
141
|
+
reason?: ResolutionReason;
|
|
142
|
+
errorCode?: ErrorCode;
|
|
143
|
+
errorMessage?: string;
|
|
144
|
+
};
|
|
145
|
+
type EvaluationDetails<T extends FlagValue> = {
|
|
146
|
+
flagKey: string;
|
|
147
|
+
} & ResolutionDetails<T>;
|
|
148
|
+
interface ManageContext<T> {
|
|
149
|
+
/**
|
|
150
|
+
* Access the evaluation context set on the receiver.
|
|
151
|
+
*
|
|
152
|
+
* @returns {EvaluationContext} Evaluation context
|
|
153
|
+
*/
|
|
154
|
+
getContext(): EvaluationContext;
|
|
155
|
+
/**
|
|
156
|
+
* Sets evaluation context that will be used during flag evaluations
|
|
157
|
+
* on this receiver.
|
|
158
|
+
*
|
|
159
|
+
* @template T The type of the receiver
|
|
160
|
+
* @param {EvaluationContext} context Evaluation context
|
|
161
|
+
* @returns {T} The receiver (this object)
|
|
162
|
+
*/
|
|
163
|
+
setContext(context: EvaluationContext): T;
|
|
164
|
+
}
|
|
165
|
+
interface ManageLogger<T> {
|
|
166
|
+
/**
|
|
167
|
+
* Sets a logger on this receiver. This logger supersedes to the global logger
|
|
168
|
+
* and is passed to various components in the SDK.
|
|
169
|
+
* The logger configured on the global API object will be used for all evaluations,
|
|
170
|
+
* unless overridden in a particular client.
|
|
171
|
+
*
|
|
172
|
+
* @template T The type of the receiver
|
|
173
|
+
* @param {Logger} logger The logger to be used
|
|
174
|
+
* @returns {T} The receiver (this object)
|
|
175
|
+
*/
|
|
176
|
+
setLogger(logger: Logger): T;
|
|
177
|
+
}
|
|
178
|
+
type HookHints = Readonly<Record<string, unknown>>;
|
|
179
|
+
interface Metadata {
|
|
180
|
+
}
|
|
181
|
+
interface ClientMetadata extends Metadata {
|
|
182
|
+
readonly version?: string;
|
|
183
|
+
readonly name?: string;
|
|
184
|
+
}
|
|
185
|
+
interface ProviderMetadata extends Metadata {
|
|
186
|
+
readonly name: string;
|
|
187
|
+
}
|
|
188
|
+
interface HookContext<T extends FlagValue = FlagValue> {
|
|
189
|
+
readonly flagKey: string;
|
|
190
|
+
readonly defaultValue: T;
|
|
191
|
+
readonly flagValueType: FlagValueType;
|
|
192
|
+
readonly context: Readonly<EvaluationContext>;
|
|
193
|
+
readonly clientMetadata: ClientMetadata;
|
|
194
|
+
readonly providerMetadata: ProviderMetadata;
|
|
195
|
+
readonly logger: Logger;
|
|
196
|
+
}
|
|
197
|
+
interface BeforeHookContext extends HookContext {
|
|
198
|
+
context: EvaluationContext;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Transaction context is a mechanism for adding transaction specific context that
|
|
202
|
+
* is merged with evaluation context prior to flag evaluation. Examples of potential
|
|
203
|
+
* transaction specific context include: a user id, user agent, or request path.
|
|
204
|
+
*/
|
|
205
|
+
type TransactionContext = EvaluationContext;
|
|
206
|
+
interface ManageTransactionContextPropagator<T> extends TransactionContextPropagator {
|
|
207
|
+
/**
|
|
208
|
+
* EXPERIMENTAL: Transaction context propagation is experimental and subject to change.
|
|
209
|
+
* The OpenFeature Enhancement Proposal regarding transaction context can be found [here](https://github.com/open-feature/ofep/pull/32).
|
|
210
|
+
*
|
|
211
|
+
* Sets a transaction context propagator on this receiver. The transaction context
|
|
212
|
+
* propagator is responsible for persisting context for the duration of a single
|
|
213
|
+
* transaction.
|
|
214
|
+
*
|
|
215
|
+
* @experimental
|
|
216
|
+
* @template T The type of the receiver
|
|
217
|
+
* @param {TransactionContextPropagator} transactionContextPropagator The context propagator to be used
|
|
218
|
+
* @returns {T} The receiver (this object)
|
|
219
|
+
*/
|
|
220
|
+
setTransactionContextPropagator(transactionContextPropagator: TransactionContextPropagator): T;
|
|
221
|
+
}
|
|
222
|
+
interface TransactionContextPropagator {
|
|
223
|
+
/**
|
|
224
|
+
* EXPERIMENTAL: Transaction context propagation is experimental and subject to change.
|
|
225
|
+
* The OpenFeature Enhancement Proposal regarding transaction context can be found [here](https://github.com/open-feature/ofep/pull/32).
|
|
226
|
+
*
|
|
227
|
+
* Returns the currently defined transaction context using the registered transaction
|
|
228
|
+
* context propagator.
|
|
229
|
+
*
|
|
230
|
+
* @experimental
|
|
231
|
+
* @returns {TransactionContext} The current transaction context
|
|
232
|
+
*/
|
|
233
|
+
getTransactionContext(): TransactionContext;
|
|
234
|
+
/**
|
|
235
|
+
* EXPERIMENTAL: Transaction context propagation is experimental and subject to change.
|
|
236
|
+
* The OpenFeature Enhancement Proposal regarding transaction context can be found [here](https://github.com/open-feature/ofep/pull/32).
|
|
237
|
+
*
|
|
238
|
+
* Sets the transaction context using the registered transaction context propagator.
|
|
239
|
+
*
|
|
240
|
+
* @experimental
|
|
241
|
+
* @template R The return value of the callback
|
|
242
|
+
* @param {TransactionContext} transactionContext The transaction specific context
|
|
243
|
+
* @param {(...args: unknown[]) => R} callback Callback function used to set the transaction context on the stack
|
|
244
|
+
* @param {...unknown[]} args Optional arguments that are passed to the callback function
|
|
245
|
+
*/
|
|
246
|
+
setTransactionContext<R>(transactionContext: TransactionContext, callback: (...args: unknown[]) => R, ...args: unknown[]): void;
|
|
247
|
+
}
|
|
248
|
+
interface CommonProvider {
|
|
249
|
+
readonly metadata: ProviderMetadata;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
declare abstract class OpenFeatureError extends Error {
|
|
253
|
+
abstract code: ErrorCode;
|
|
254
|
+
constructor(message?: string);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
declare class GeneralError extends OpenFeatureError {
|
|
258
|
+
code: ErrorCode;
|
|
259
|
+
constructor(message?: string);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
declare class FlagNotFoundError extends OpenFeatureError {
|
|
263
|
+
code: ErrorCode;
|
|
264
|
+
constructor(message?: string);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
declare class ParseError extends OpenFeatureError {
|
|
268
|
+
code: ErrorCode;
|
|
269
|
+
constructor(message?: string);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
declare class TypeMismatchError extends OpenFeatureError {
|
|
273
|
+
code: ErrorCode;
|
|
274
|
+
constructor(message?: string);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
declare class TargetingKeyMissingError extends OpenFeatureError {
|
|
278
|
+
code: ErrorCode;
|
|
279
|
+
constructor(message?: string);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
declare class InvalidContextError extends OpenFeatureError {
|
|
283
|
+
code: ErrorCode;
|
|
284
|
+
constructor(message?: string);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
declare class DefaultLogger implements Logger {
|
|
288
|
+
error(...args: unknown[]): void;
|
|
289
|
+
warn(...args: unknown[]): void;
|
|
290
|
+
info(): void;
|
|
291
|
+
debug(): void;
|
|
292
|
+
}
|
|
293
|
+
declare class SafeLogger implements Logger {
|
|
294
|
+
private readonly logger;
|
|
295
|
+
private readonly fallbackLogger;
|
|
296
|
+
constructor(logger: Logger);
|
|
297
|
+
error(...args: unknown[]): void;
|
|
298
|
+
warn(...args: unknown[]): void;
|
|
299
|
+
info(...args: unknown[]): void;
|
|
300
|
+
debug(...args: unknown[]): void;
|
|
301
|
+
private log;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
declare class NoopTransactionContextPropagator implements TransactionContextPropagator {
|
|
305
|
+
getTransactionContext(): EvaluationContext;
|
|
306
|
+
setTransactionContext(_: EvaluationContext, callback: () => void): void;
|
|
307
|
+
}
|
|
308
|
+
declare const NOOP_TRANSACTION_CONTEXT_PROPAGATOR: NoopTransactionContextPropagator;
|
|
309
|
+
|
|
310
|
+
declare abstract class OpenFeatureCommonAPI {
|
|
311
|
+
protected _transactionContextPropagator: TransactionContextPropagator;
|
|
312
|
+
protected _context: EvaluationContext;
|
|
313
|
+
protected _logger: Logger;
|
|
314
|
+
abstract clearHooks(): this;
|
|
315
|
+
abstract setLogger(logger: Logger): this;
|
|
316
|
+
getContext(): EvaluationContext;
|
|
317
|
+
setTransactionContextPropagator(transactionContextPropagator: TransactionContextPropagator): OpenFeatureCommonAPI;
|
|
318
|
+
setTransactionContext<R>(transactionContext: TransactionContext, callback: (...args: unknown[]) => R, ...args: unknown[]): void;
|
|
319
|
+
getTransactionContext(): TransactionContext;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Interface that providers must implement to resolve flag values for their particular
|
|
324
|
+
* backend or vendor.
|
|
325
|
+
*
|
|
326
|
+
* Implementation for resolving all the required flag types must be defined.
|
|
327
|
+
*/
|
|
328
|
+
interface Provider extends CommonProvider {
|
|
329
|
+
/**
|
|
330
|
+
* A provider hook exposes a mechanism for provider authors to register hooks
|
|
331
|
+
* to tap into various stages of the flag evaluation lifecycle. These hooks can
|
|
332
|
+
* be used to perform side effects and mutate the context for purposes of the
|
|
333
|
+
* provider. Provider hooks are not configured or controlled by the application author.
|
|
334
|
+
*/
|
|
335
|
+
readonly hooks?: Hook[];
|
|
336
|
+
onContextChange?(oldContext: EvaluationContext, newContext: EvaluationContext): Promise<void>;
|
|
337
|
+
onClose?(): Promise<void>;
|
|
338
|
+
/**
|
|
339
|
+
* Resolve a boolean flag and its evaluation details.
|
|
340
|
+
*/
|
|
341
|
+
resolveBooleanEvaluation(flagKey: string, defaultValue: boolean, context: EvaluationContext, logger: Logger): ResolutionDetails<boolean>;
|
|
342
|
+
/**
|
|
343
|
+
* Resolve a string flag and its evaluation details.
|
|
344
|
+
*/
|
|
345
|
+
resolveStringEvaluation(flagKey: string, defaultValue: string, context: EvaluationContext, logger: Logger): ResolutionDetails<string>;
|
|
346
|
+
/**
|
|
347
|
+
* Resolve a numeric flag and its evaluation details.
|
|
348
|
+
*/
|
|
349
|
+
resolveNumberEvaluation(flagKey: string, defaultValue: number, context: EvaluationContext, logger: Logger): ResolutionDetails<number>;
|
|
350
|
+
/**
|
|
351
|
+
* Resolve and parse an object flag and its evaluation details.
|
|
352
|
+
*/
|
|
353
|
+
resolveObjectEvaluation<T extends JsonValue>(flagKey: string, defaultValue: T, context: EvaluationContext, logger: Logger): ResolutionDetails<T>;
|
|
354
|
+
}
|
|
355
|
+
interface Hook<T extends FlagValue = FlagValue> {
|
|
356
|
+
/**
|
|
357
|
+
* Runs before flag values are resolved from the provider.
|
|
358
|
+
* If an EvaluationContext is returned, it will be merged with the pre-existing EvaluationContext.
|
|
359
|
+
*
|
|
360
|
+
* @param hookContext
|
|
361
|
+
* @param hookHints
|
|
362
|
+
*/
|
|
363
|
+
before?(hookContext: BeforeHookContext, hookHints?: HookHints): EvaluationContext | void;
|
|
364
|
+
/**
|
|
365
|
+
* Runs after flag values are successfully resolved from the provider.
|
|
366
|
+
*
|
|
367
|
+
* @param hookContext
|
|
368
|
+
* @param evaluationDetails
|
|
369
|
+
* @param hookHints
|
|
370
|
+
*/
|
|
371
|
+
after?(hookContext: Readonly<HookContext<T>>, evaluationDetails: EvaluationDetails<T>, hookHints?: HookHints): void;
|
|
372
|
+
/**
|
|
373
|
+
* Runs in the event of an unhandled error or promise rejection during flag resolution, or any attached hooks.
|
|
374
|
+
*
|
|
375
|
+
* @param hookContext
|
|
376
|
+
* @param error
|
|
377
|
+
* @param hookHints
|
|
378
|
+
*/
|
|
379
|
+
error?(hookContext: Readonly<HookContext<T>>, error: unknown, hookHints?: HookHints): 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
|
+
*
|
|
384
|
+
* @param hookContext
|
|
385
|
+
* @param hookHints
|
|
386
|
+
*/
|
|
387
|
+
finally?(hookContext: Readonly<HookContext<T>>, hookHints?: HookHints): void;
|
|
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
|
+
*
|
|
397
|
+
* @template T The type of the receiver
|
|
398
|
+
* @param {Hook<FlagValue>[]} hooks A list of hooks that should always run
|
|
399
|
+
* @returns {T} The receiver (this object)
|
|
400
|
+
*/
|
|
401
|
+
addHooks(...hooks: Hook[]): T;
|
|
402
|
+
/**
|
|
403
|
+
* Access all the hooks that are registered on this receiver.
|
|
404
|
+
*
|
|
405
|
+
* @returns {Hook<FlagValue>[]} A list of the client hooks
|
|
406
|
+
*/
|
|
407
|
+
getHooks(): Hook[];
|
|
408
|
+
/**
|
|
409
|
+
* Clears all the hooks that are registered on this receiver.
|
|
410
|
+
*
|
|
411
|
+
* @template T The type of the receiver
|
|
412
|
+
* @returns {T} The receiver (this object)
|
|
413
|
+
*/
|
|
414
|
+
clearHooks(): T;
|
|
415
|
+
}
|
|
416
|
+
interface FlagEvaluationOptions {
|
|
417
|
+
hooks?: Hook[];
|
|
418
|
+
hookHints?: HookHints;
|
|
419
|
+
}
|
|
420
|
+
interface Features {
|
|
421
|
+
/**
|
|
422
|
+
* Performs a flag evaluation that returns a boolean.
|
|
423
|
+
*
|
|
424
|
+
* @param {string} flagKey The flag key uniquely identifies a particular flag
|
|
425
|
+
* @param {boolean} defaultValue The value returned if an error occurs
|
|
426
|
+
* @param {EvaluationContext} context The evaluation context used on an individual flag evaluation
|
|
427
|
+
* @param {FlagEvaluationOptions} options Additional flag evaluation options
|
|
428
|
+
* @returns {boolean} Flag evaluation response
|
|
429
|
+
*/
|
|
430
|
+
getBooleanValue(flagKey: string, defaultValue: boolean, context?: EvaluationContext, options?: FlagEvaluationOptions): boolean;
|
|
431
|
+
/**
|
|
432
|
+
* Performs a flag evaluation that a returns an evaluation details object.
|
|
433
|
+
*
|
|
434
|
+
* @param {string} flagKey The flag key uniquely identifies a particular flag
|
|
435
|
+
* @param {boolean} defaultValue The value returned if an error occurs
|
|
436
|
+
* @param {EvaluationContext} context The evaluation context used on an individual flag evaluation
|
|
437
|
+
* @param {FlagEvaluationOptions} options Additional flag evaluation options
|
|
438
|
+
* @returns {EvaluationDetails<boolean>} Flag evaluation details response
|
|
439
|
+
*/
|
|
440
|
+
getBooleanDetails(flagKey: string, defaultValue: boolean, context?: EvaluationContext, options?: FlagEvaluationOptions): EvaluationDetails<boolean>;
|
|
441
|
+
/**
|
|
442
|
+
* Performs a flag evaluation that returns a string.
|
|
443
|
+
*
|
|
444
|
+
* @param {string} flagKey The flag key uniquely identifies a particular flag
|
|
445
|
+
* @template {string} T A optional generic argument constraining the string
|
|
446
|
+
* @param {T} defaultValue The value returned if an error occurs
|
|
447
|
+
* @param {EvaluationContext} context The evaluation context used on an individual flag evaluation
|
|
448
|
+
* @param {FlagEvaluationOptions} options Additional flag evaluation options
|
|
449
|
+
* @returns {T} Flag evaluation response
|
|
450
|
+
*/
|
|
451
|
+
getStringValue(flagKey: string, defaultValue: string, context?: EvaluationContext, options?: FlagEvaluationOptions): string;
|
|
452
|
+
getStringValue<T extends string = string>(flagKey: string, defaultValue: T, context?: EvaluationContext, options?: FlagEvaluationOptions): T;
|
|
453
|
+
/**
|
|
454
|
+
* Performs a flag evaluation that a returns an evaluation details object.
|
|
455
|
+
*
|
|
456
|
+
* @param {string} flagKey The flag key uniquely identifies a particular flag
|
|
457
|
+
* @template {string} T A optional generic argument constraining the string
|
|
458
|
+
* @param {T} defaultValue The value returned if an error occurs
|
|
459
|
+
* @param {EvaluationContext} context The evaluation context used on an individual flag evaluation
|
|
460
|
+
* @param {FlagEvaluationOptions} options Additional flag evaluation options
|
|
461
|
+
* @returns {EvaluationDetails<T>} Flag evaluation details response
|
|
462
|
+
*/
|
|
463
|
+
getStringDetails(flagKey: string, defaultValue: string, context?: EvaluationContext, options?: FlagEvaluationOptions): EvaluationDetails<string>;
|
|
464
|
+
getStringDetails<T extends string = string>(flagKey: string, defaultValue: T, context?: EvaluationContext, options?: FlagEvaluationOptions): EvaluationDetails<T>;
|
|
465
|
+
/**
|
|
466
|
+
* Performs a flag evaluation that returns a number.
|
|
467
|
+
*
|
|
468
|
+
* @param {string} flagKey The flag key uniquely identifies a particular flag
|
|
469
|
+
* @template {number} T A optional generic argument constraining the number
|
|
470
|
+
* @param {T} defaultValue The value returned if an error occurs
|
|
471
|
+
* @param {EvaluationContext} context The evaluation context used on an individual flag evaluation
|
|
472
|
+
* @param {FlagEvaluationOptions} options Additional flag evaluation options
|
|
473
|
+
* @returns {T} Flag evaluation response
|
|
474
|
+
*/
|
|
475
|
+
getNumberValue(flagKey: string, defaultValue: number, context?: EvaluationContext, options?: FlagEvaluationOptions): number;
|
|
476
|
+
getNumberValue<T extends number = number>(flagKey: string, defaultValue: T, context?: EvaluationContext, options?: FlagEvaluationOptions): T;
|
|
477
|
+
/**
|
|
478
|
+
* Performs a flag evaluation that a returns an evaluation details object.
|
|
479
|
+
*
|
|
480
|
+
* @param {string} flagKey The flag key uniquely identifies a particular flag
|
|
481
|
+
* @template {number} T A optional generic argument constraining the number
|
|
482
|
+
* @param {T} defaultValue The value returned if an error occurs
|
|
483
|
+
* @param {EvaluationContext} context The evaluation context used on an individual flag evaluation
|
|
484
|
+
* @param {FlagEvaluationOptions} options Additional flag evaluation options
|
|
485
|
+
* @returns {Promise<EvaluationDetails<T>>} Flag evaluation details response
|
|
486
|
+
*/
|
|
487
|
+
getNumberDetails(flagKey: string, defaultValue: number, context?: EvaluationContext, options?: FlagEvaluationOptions): EvaluationDetails<number>;
|
|
488
|
+
getNumberDetails<T extends number = number>(flagKey: string, defaultValue: T, context?: EvaluationContext, options?: FlagEvaluationOptions): EvaluationDetails<T>;
|
|
489
|
+
/**
|
|
490
|
+
* Performs a flag evaluation that returns an object.
|
|
491
|
+
*
|
|
492
|
+
* @param {string} flagKey The flag key uniquely identifies a particular flag
|
|
493
|
+
* @template {JsonValue} T A optional generic argument describing the structure
|
|
494
|
+
* @param {T} defaultValue The value returned if an error occurs
|
|
495
|
+
* @param {EvaluationContext} context The evaluation context used on an individual flag evaluation
|
|
496
|
+
* @param {FlagEvaluationOptions} options Additional flag evaluation options
|
|
497
|
+
* @returns {Promise<T>} Flag evaluation response
|
|
498
|
+
*/
|
|
499
|
+
getObjectValue(flagKey: string, defaultValue: JsonValue, context?: EvaluationContext, options?: FlagEvaluationOptions): JsonValue;
|
|
500
|
+
getObjectValue<T extends JsonValue = JsonValue>(flagKey: string, defaultValue: T, context?: EvaluationContext, options?: FlagEvaluationOptions): T;
|
|
501
|
+
/**
|
|
502
|
+
* Performs a flag evaluation that a returns an evaluation details object.
|
|
503
|
+
*
|
|
504
|
+
* @param {string} flagKey The flag key uniquely identifies a particular flag
|
|
505
|
+
* @template {JsonValue} T A optional generic argument describing the structure
|
|
506
|
+
* @param {T} defaultValue The value returned if an error occurs
|
|
507
|
+
* @param {EvaluationContext} context The evaluation context used on an individual flag evaluation
|
|
508
|
+
* @param {FlagEvaluationOptions} options Additional flag evaluation options
|
|
509
|
+
* @returns {Promise<EvaluationDetails<T>>} Flag evaluation details response
|
|
510
|
+
*/
|
|
511
|
+
getObjectDetails(flagKey: string, defaultValue: JsonValue, context?: EvaluationContext, options?: FlagEvaluationOptions): EvaluationDetails<JsonValue>;
|
|
512
|
+
getObjectDetails<T extends JsonValue = JsonValue>(flagKey: string, defaultValue: T, context?: EvaluationContext, options?: FlagEvaluationOptions): EvaluationDetails<T>;
|
|
513
|
+
}
|
|
514
|
+
interface Client extends EvaluationLifeCycle<Client>, Features, ManageLogger<Client>, Eventing {
|
|
515
|
+
readonly metadata: ClientMetadata;
|
|
516
|
+
}
|
|
517
|
+
interface GlobalApi extends EvaluationLifeCycle<GlobalApi>, ManageContext<GlobalApi>, ManageLogger<GlobalApi>, ManageTransactionContextPropagator<GlobalApi> {
|
|
518
|
+
readonly providerMetadata: ProviderMetadata;
|
|
519
|
+
/**
|
|
520
|
+
* A factory function for creating new OpenFeature clients. Clients can contain
|
|
521
|
+
* their own state (e.g. logger, hook, context). Multiple clients can be used
|
|
522
|
+
* to segment feature flag configuration.
|
|
523
|
+
*
|
|
524
|
+
* @param {string} name The name of the client
|
|
525
|
+
* @param {string} version The version of the client
|
|
526
|
+
* @param {EvaluationContext} context Evaluation context that should be set on the client to used during flag evaluations
|
|
527
|
+
* @returns {Client} OpenFeature Client
|
|
528
|
+
*/
|
|
529
|
+
getClient(name?: string, version?: string, context?: EvaluationContext): Client;
|
|
530
|
+
/**
|
|
531
|
+
* Sets the provider that OpenFeature will use for flag evaluations. Setting
|
|
532
|
+
* a provider supersedes the current provider used in new and existing clients.
|
|
533
|
+
*
|
|
534
|
+
* @param {Provider} provider The provider responsible for flag evaluations.
|
|
535
|
+
* @returns {GlobalApi} OpenFeature API
|
|
536
|
+
*/
|
|
537
|
+
setProvider(provider: Provider): GlobalApi;
|
|
538
|
+
}
|
|
539
|
+
interface EventProvider {
|
|
540
|
+
readonly ready: boolean;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
type OpenFeatureClientOptions = {
|
|
544
|
+
name?: string;
|
|
545
|
+
version?: string;
|
|
546
|
+
};
|
|
547
|
+
declare class OpenFeatureClient implements Client {
|
|
548
|
+
private readonly providerAccessor;
|
|
549
|
+
private readonly globalLogger;
|
|
550
|
+
readonly metadata: ClientMetadata;
|
|
551
|
+
private _context;
|
|
552
|
+
private _hooks;
|
|
553
|
+
private _clientLogger?;
|
|
554
|
+
private _handlerWrappers;
|
|
555
|
+
constructor(providerAccessor: () => Provider & Partial<EventProvider>, globalLogger: () => Logger, options: OpenFeatureClientOptions, context?: EvaluationContext);
|
|
556
|
+
addHandler(eventType: ProviderEvents, handler: Handler): void;
|
|
557
|
+
setLogger(logger: Logger): OpenFeatureClient;
|
|
558
|
+
addHooks(...hooks: Hook<FlagValue>[]): OpenFeatureClient;
|
|
559
|
+
getHooks(): Hook<FlagValue>[];
|
|
560
|
+
clearHooks(): OpenFeatureClient;
|
|
561
|
+
getBooleanValue(flagKey: string, defaultValue: boolean, context?: EvaluationContext, options?: FlagEvaluationOptions): boolean;
|
|
562
|
+
getBooleanDetails(flagKey: string, defaultValue: boolean, context?: EvaluationContext, options?: FlagEvaluationOptions): EvaluationDetails<boolean>;
|
|
563
|
+
getStringValue<T extends string = string>(flagKey: string, defaultValue: T, context?: EvaluationContext, options?: FlagEvaluationOptions): T;
|
|
564
|
+
getStringDetails<T extends string = string>(flagKey: string, defaultValue: T, context?: EvaluationContext, options?: FlagEvaluationOptions): EvaluationDetails<T>;
|
|
565
|
+
getNumberValue<T extends number = number>(flagKey: string, defaultValue: T, context?: EvaluationContext, options?: FlagEvaluationOptions): T;
|
|
566
|
+
getNumberDetails<T extends number = number>(flagKey: string, defaultValue: T, context?: EvaluationContext, options?: FlagEvaluationOptions): EvaluationDetails<T>;
|
|
567
|
+
getObjectValue<T extends JsonValue = JsonValue>(flagKey: string, defaultValue: T, context?: EvaluationContext, options?: FlagEvaluationOptions): T;
|
|
568
|
+
getObjectDetails<T extends JsonValue = JsonValue>(flagKey: string, defaultValue: T, context?: EvaluationContext, options?: FlagEvaluationOptions): EvaluationDetails<T>;
|
|
569
|
+
private evaluate;
|
|
570
|
+
private beforeHooks;
|
|
571
|
+
private afterHooks;
|
|
572
|
+
private errorHooks;
|
|
573
|
+
private finallyHooks;
|
|
574
|
+
private get _provider();
|
|
575
|
+
private get _logger();
|
|
576
|
+
private attachListeners;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
/**
|
|
580
|
+
* The No-op provider is set by default, and simply always returns the default value.
|
|
581
|
+
*/
|
|
582
|
+
declare class NoopFeatureProvider implements Provider {
|
|
583
|
+
readonly metadata: {
|
|
584
|
+
readonly name: "No-op Provider";
|
|
585
|
+
};
|
|
586
|
+
resolveBooleanEvaluation(_: string, defaultValue: boolean): ResolutionDetails<boolean>;
|
|
587
|
+
resolveStringEvaluation(_: string, defaultValue: string): ResolutionDetails<string>;
|
|
588
|
+
resolveNumberEvaluation(_: string, defaultValue: number): ResolutionDetails<number>;
|
|
589
|
+
resolveObjectEvaluation<T extends JsonValue>(_: string, defaultValue: T): ResolutionDetails<T>;
|
|
590
|
+
private noOp;
|
|
591
|
+
}
|
|
592
|
+
declare const NOOP_PROVIDER: NoopFeatureProvider;
|
|
593
|
+
|
|
594
|
+
declare class OpenFeatureAPI extends OpenFeatureCommonAPI {
|
|
595
|
+
protected _hooks: Hook[];
|
|
596
|
+
protected _provider: Provider;
|
|
597
|
+
private constructor();
|
|
598
|
+
/**
|
|
599
|
+
* Gets a singleton instance of the OpenFeature API.
|
|
600
|
+
*
|
|
601
|
+
* @ignore
|
|
602
|
+
* @returns {OpenFeatureAPI} OpenFeature API
|
|
603
|
+
*/
|
|
604
|
+
static getInstance(): OpenFeatureAPI;
|
|
605
|
+
/**
|
|
606
|
+
* Get metadata about registered provider.
|
|
607
|
+
*
|
|
608
|
+
* @returns {ProviderMetadata} Provider Metadata
|
|
609
|
+
*/
|
|
610
|
+
get providerMetadata(): ProviderMetadata;
|
|
611
|
+
setLogger(logger: Logger): this;
|
|
612
|
+
addHooks(...hooks: Hook<FlagValue>[]): this;
|
|
613
|
+
getHooks(): Hook<FlagValue>[];
|
|
614
|
+
clearHooks(): this;
|
|
615
|
+
setContext(context: EvaluationContext): Promise<void>;
|
|
616
|
+
setProvider(provider: Provider): OpenFeatureCommonAPI;
|
|
617
|
+
close(): Promise<void>;
|
|
618
|
+
getClient(name?: string, version?: string, context?: EvaluationContext): Client;
|
|
619
|
+
}
|
|
620
|
+
/**
|
|
621
|
+
* A singleton instance of the OpenFeature API.
|
|
622
|
+
*
|
|
623
|
+
* @returns {OpenFeatureAPI} OpenFeature API
|
|
624
|
+
*/
|
|
625
|
+
declare const OpenFeature: OpenFeatureAPI;
|
|
626
|
+
|
|
627
|
+
export { ApiEvents, BeforeHookContext, Client, ClientMetadata, CommonProvider, DefaultLogger, ErrorCode, EvaluationContext, EvaluationContextValue, EvaluationDetails, EventCallbackMessage, EventContext, EventData, EventProvider, Eventing, Features, FlagEvaluationOptions, FlagNotFoundError, FlagValue, FlagValueType, GeneralError, GlobalApi, Handler, Hook, HookContext, HookHints, InvalidContextError, JsonArray, JsonObject, JsonValue, Logger, ManageContext, ManageLogger, ManageTransactionContextPropagator, NOOP_PROVIDER, NOOP_TRANSACTION_CONTEXT_PROPAGATOR, OpenFeature, OpenFeatureAPI, OpenFeatureClient, OpenFeatureCommonAPI, OpenFeatureError, ParseError, PrimitiveValue, Provider, ProviderEvents, ProviderMetadata, ResolutionDetails, ResolutionReason, SafeLogger, StandardResolutionReasons, TargetingKeyMissingError, TransactionContext, TransactionContextPropagator, TypeMismatchError };
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@openfeature/web-sdk",
|
|
3
|
+
"version": "0.0.2-experimental",
|
|
4
|
+
"description": "OpenFeature SDK for Web",
|
|
5
|
+
"main": "./dist/cjs/index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist/"
|
|
8
|
+
],
|
|
9
|
+
"exports": {
|
|
10
|
+
"types": "./dist/types.d.ts",
|
|
11
|
+
"import": "./dist/esm/index.js",
|
|
12
|
+
"require": "./dist/cjs/index.js",
|
|
13
|
+
"default": "./dist/cjs/index.js"
|
|
14
|
+
},
|
|
15
|
+
"types": "./dist/types.d.ts",
|
|
16
|
+
"scripts": {
|
|
17
|
+
"test": "jest --verbose",
|
|
18
|
+
"lint": "eslint ./",
|
|
19
|
+
"clean": "shx rm -rf ./dist",
|
|
20
|
+
"build:web-esm": "esbuild src/index.ts --bundle --sourcemap --target=es2016 --platform=browser --format=esm --outfile=./dist/esm/index.js --analyze",
|
|
21
|
+
"build:web-cjs": "esbuild src/index.ts --bundle --sourcemap --target=es2016 --platform=browser --format=cjs --outfile=./dist/cjs/index.js --analyze",
|
|
22
|
+
"build:rollup-types": "rollup -c ../../rollup.config.mjs",
|
|
23
|
+
"build": "npm run clean && npm run build:web-esm && npm run build:web-cjs && npm run build:rollup-types",
|
|
24
|
+
"postbuild": "shx cp ./../../package.esm.json ./dist/esm/package.json",
|
|
25
|
+
"current-version": "echo $npm_package_version",
|
|
26
|
+
"prepack": "shx cp ./../../LICENSE ./LICENSE",
|
|
27
|
+
"publish-if-not-exists": "cp $NPM_CONFIG_USERCONFIG .npmrc && if [ \"$(npm show $npm_package_name@$npm_package_version version)\" = \"$(npm run current-version -s)\" ]; then echo 'already published, skipping'; else npm publish --access public --tag experimental; fi",
|
|
28
|
+
"docs": "typedoc"
|
|
29
|
+
},
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/open-feature/js-sdk.git"
|
|
33
|
+
},
|
|
34
|
+
"keywords": [
|
|
35
|
+
"openfeature",
|
|
36
|
+
"feature",
|
|
37
|
+
"flags",
|
|
38
|
+
"toggles",
|
|
39
|
+
"browser",
|
|
40
|
+
"web"
|
|
41
|
+
],
|
|
42
|
+
"author": "",
|
|
43
|
+
"license": "Apache-2.0",
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/open-feature/js-sdk/issues"
|
|
46
|
+
},
|
|
47
|
+
"homepage": "https://github.com/open-feature/js-sdk#readme",
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@openfeature/shared": "0.0.2"
|
|
50
|
+
}
|
|
51
|
+
}
|