@openfeature/web-sdk 1.6.1 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +59 -2
- package/dist/cjs/index.js +542 -24
- package/dist/cjs/index.js.map +4 -4
- package/dist/esm/index.js +524 -6
- package/dist/esm/index.js.map +4 -4
- package/dist/global/index.js +527 -8
- package/dist/global/index.js.map +4 -4
- package/dist/global/index.min.js +1 -1
- package/dist/global/index.min.js.map +4 -4
- package/dist/types.d.ts +145 -3
- package/package.json +1 -1
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseHook, HookHints, EvaluationDetails, JsonValue, FlagValue, CommonProvider, ClientProviderStatus, EvaluationContext, Logger, ResolutionDetails, ClientProviderEvents, GenericEventEmitter, TrackingEventDetails, EvaluationLifeCycle, ManageLogger, Eventing, ClientMetadata, OpenFeatureCommonAPI, ManageContext, ProviderWrapper } from '@openfeature/core';
|
|
1
|
+
import { BaseHook, HookHints, EvaluationDetails, JsonValue, FlagValue, CommonProvider, ClientProviderStatus, EvaluationContext, Logger, ResolutionDetails, ClientProviderEvents, GenericEventEmitter, FlagValueType, TrackingEventDetails, ErrorCode, ProviderMetadata, OpenFeatureError, GeneralError, EvaluationLifeCycle, ManageLogger, Eventing, ClientMetadata, OpenFeatureCommonAPI, ManageContext, ProviderWrapper } from '@openfeature/core';
|
|
2
2
|
export * from '@openfeature/core';
|
|
3
3
|
export { ClientProviderEvents as ProviderEvents, ClientProviderStatus as ProviderStatus } from '@openfeature/core';
|
|
4
4
|
|
|
@@ -357,6 +357,148 @@ declare class InMemoryProvider implements Provider {
|
|
|
357
357
|
private lookupFlagValue;
|
|
358
358
|
}
|
|
359
359
|
|
|
360
|
+
type StrategyEvaluationContext = {
|
|
361
|
+
flagKey: string;
|
|
362
|
+
flagType: FlagValueType;
|
|
363
|
+
};
|
|
364
|
+
type StrategyProviderContext = {
|
|
365
|
+
provider: Provider;
|
|
366
|
+
providerName: string;
|
|
367
|
+
providerStatus: ClientProviderStatus;
|
|
368
|
+
};
|
|
369
|
+
type StrategyPerProviderContext = StrategyEvaluationContext & StrategyProviderContext;
|
|
370
|
+
type ProviderResolutionResultBase = {
|
|
371
|
+
provider: Provider;
|
|
372
|
+
providerName: string;
|
|
373
|
+
};
|
|
374
|
+
type ProviderResolutionSuccessResult<T extends FlagValue> = ProviderResolutionResultBase & {
|
|
375
|
+
details: ResolutionDetails<T>;
|
|
376
|
+
};
|
|
377
|
+
type ProviderResolutionErrorResult = ProviderResolutionResultBase & {
|
|
378
|
+
thrownError: unknown;
|
|
379
|
+
};
|
|
380
|
+
type ProviderResolutionResult<T extends FlagValue> = ProviderResolutionSuccessResult<T> | ProviderResolutionErrorResult;
|
|
381
|
+
type FinalResult<T extends FlagValue> = {
|
|
382
|
+
details?: ResolutionDetails<T>;
|
|
383
|
+
provider?: Provider;
|
|
384
|
+
providerName?: string;
|
|
385
|
+
errors?: {
|
|
386
|
+
providerName: string;
|
|
387
|
+
error: unknown;
|
|
388
|
+
}[];
|
|
389
|
+
};
|
|
390
|
+
/**
|
|
391
|
+
* Base strategy to inherit from. Not directly usable, as strategies must implement the "determineResult" method
|
|
392
|
+
* Contains default implementations for `shouldEvaluateThisProvider` and `shouldEvaluateNextProvider`
|
|
393
|
+
*/
|
|
394
|
+
declare abstract class BaseEvaluationStrategy {
|
|
395
|
+
shouldEvaluateThisProvider(strategyContext: StrategyPerProviderContext, _evalContext: EvaluationContext): boolean;
|
|
396
|
+
shouldEvaluateNextProvider<T extends FlagValue>(_strategyContext: StrategyPerProviderContext, _context: EvaluationContext, _result: ProviderResolutionResult<T>): boolean;
|
|
397
|
+
shouldTrackWithThisProvider(strategyContext: StrategyProviderContext, _context: EvaluationContext, _trackingEventName: string, _trackingEventDetails: TrackingEventDetails): boolean;
|
|
398
|
+
abstract determineFinalResult<T extends FlagValue>(strategyContext: StrategyEvaluationContext, context: EvaluationContext, resolutions: ProviderResolutionResult<T>[]): FinalResult<T>;
|
|
399
|
+
protected hasError(resolution: ProviderResolutionResult<FlagValue>): resolution is ProviderResolutionErrorResult | (ProviderResolutionSuccessResult<FlagValue> & {
|
|
400
|
+
details: ResolutionDetails<FlagValue> & {
|
|
401
|
+
errorCode: ErrorCode;
|
|
402
|
+
};
|
|
403
|
+
});
|
|
404
|
+
protected hasErrorWithCode(resolution: ProviderResolutionResult<FlagValue>, code: ErrorCode): boolean;
|
|
405
|
+
protected collectProviderErrors<T extends FlagValue>(resolutions: ProviderResolutionResult<T>[]): FinalResult<T>;
|
|
406
|
+
protected resolutionToFinalResult<T extends FlagValue>(resolution: ProviderResolutionSuccessResult<T>): {
|
|
407
|
+
details: ResolutionDetails<T>;
|
|
408
|
+
provider: Provider;
|
|
409
|
+
providerName: string;
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Return the first result that did not indicate "flag not found".
|
|
415
|
+
* If any provider in the course of evaluation returns or throws an error, throw that error
|
|
416
|
+
*/
|
|
417
|
+
declare class FirstMatchStrategy extends BaseEvaluationStrategy {
|
|
418
|
+
shouldEvaluateNextProvider<T extends FlagValue>(strategyContext: StrategyPerProviderContext, context: EvaluationContext, result: ProviderResolutionResult<T>): boolean;
|
|
419
|
+
determineFinalResult<T extends FlagValue>(strategyContext: StrategyPerProviderContext, context: EvaluationContext, resolutions: ProviderResolutionResult<T>[]): FinalResult<T>;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Return the first result that did NOT result in an error
|
|
424
|
+
* If any provider in the course of evaluation returns or throws an error, ignore it as long as there is a successful result
|
|
425
|
+
* If there is no successful result, throw all errors
|
|
426
|
+
*/
|
|
427
|
+
declare class FirstSuccessfulStrategy extends BaseEvaluationStrategy {
|
|
428
|
+
shouldEvaluateNextProvider<T extends FlagValue>(strategyContext: StrategyPerProviderContext, context: EvaluationContext, result: ProviderResolutionResult<T>): boolean;
|
|
429
|
+
determineFinalResult<T extends FlagValue>(strategyContext: StrategyPerProviderContext, context: EvaluationContext, resolutions: ProviderResolutionResult<T>[]): FinalResult<T>;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* Evaluate all providers and compare the results.
|
|
434
|
+
* If the values agree, return the value
|
|
435
|
+
* If the values disagree, return the value from the configured "fallback provider" and execute the "onMismatch"
|
|
436
|
+
* callback if defined
|
|
437
|
+
*/
|
|
438
|
+
declare class ComparisonStrategy extends BaseEvaluationStrategy {
|
|
439
|
+
private fallbackProvider;
|
|
440
|
+
private onMismatch?;
|
|
441
|
+
constructor(fallbackProvider: Provider, onMismatch?: ((resolutions: ProviderResolutionResult<FlagValue>[]) => void) | undefined);
|
|
442
|
+
determineFinalResult<T extends FlagValue>(strategyContext: StrategyPerProviderContext, context: EvaluationContext, resolutions: ProviderResolutionResult<T>[]): FinalResult<T>;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
type ProviderEntryInput = {
|
|
446
|
+
provider: Provider;
|
|
447
|
+
name?: string;
|
|
448
|
+
};
|
|
449
|
+
type RegisteredProvider = Required<ProviderEntryInput>;
|
|
450
|
+
|
|
451
|
+
declare class MultiProvider implements Provider {
|
|
452
|
+
readonly constructorProviders: ProviderEntryInput[];
|
|
453
|
+
private readonly evaluationStrategy;
|
|
454
|
+
private readonly logger;
|
|
455
|
+
readonly runsOn = "client";
|
|
456
|
+
readonly events: OpenFeatureEventEmitter;
|
|
457
|
+
private hookContexts;
|
|
458
|
+
private hookHints;
|
|
459
|
+
metadata: ProviderMetadata;
|
|
460
|
+
providerEntries: RegisteredProvider[];
|
|
461
|
+
private providerEntriesByName;
|
|
462
|
+
private hookExecutor;
|
|
463
|
+
private statusTracker;
|
|
464
|
+
constructor(constructorProviders: ProviderEntryInput[], evaluationStrategy?: BaseEvaluationStrategy, logger?: Logger);
|
|
465
|
+
private registerProviders;
|
|
466
|
+
initialize(context?: EvaluationContext): Promise<void>;
|
|
467
|
+
onClose(): Promise<void>;
|
|
468
|
+
onContextChange(oldContext: EvaluationContext, newContext: EvaluationContext): Promise<void>;
|
|
469
|
+
resolveBooleanEvaluation(flagKey: string, defaultValue: boolean, context: EvaluationContext): ResolutionDetails<boolean>;
|
|
470
|
+
resolveStringEvaluation(flagKey: string, defaultValue: string, context: EvaluationContext): ResolutionDetails<string>;
|
|
471
|
+
resolveNumberEvaluation(flagKey: string, defaultValue: number, context: EvaluationContext): ResolutionDetails<number>;
|
|
472
|
+
resolveObjectEvaluation<T extends JsonValue>(flagKey: string, defaultValue: T, context: EvaluationContext): ResolutionDetails<T>;
|
|
473
|
+
track(trackingEventName: string, context: EvaluationContext, trackingEventDetails: TrackingEventDetails): void;
|
|
474
|
+
private flagResolutionProxy;
|
|
475
|
+
private evaluateProviderEntry;
|
|
476
|
+
private evaluateProviderAndHooks;
|
|
477
|
+
private callProviderResolve;
|
|
478
|
+
get hooks(): Hook[];
|
|
479
|
+
private getErrorEvaluationDetails;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
declare class ErrorWithCode extends OpenFeatureError {
|
|
483
|
+
code: ErrorCode;
|
|
484
|
+
constructor(code: ErrorCode, message: string);
|
|
485
|
+
}
|
|
486
|
+
declare class AggregateError extends GeneralError {
|
|
487
|
+
originalErrors: {
|
|
488
|
+
source: string;
|
|
489
|
+
error: unknown;
|
|
490
|
+
}[];
|
|
491
|
+
constructor(message: string, originalErrors: {
|
|
492
|
+
source: string;
|
|
493
|
+
error: unknown;
|
|
494
|
+
}[]);
|
|
495
|
+
}
|
|
496
|
+
declare const constructAggregateError: (providerErrors: {
|
|
497
|
+
error: unknown;
|
|
498
|
+
providerName: string;
|
|
499
|
+
}[]) => AggregateError;
|
|
500
|
+
declare const throwAggregateErrorFromPromiseResults: (result: PromiseSettledResult<unknown>[], providerEntries: RegisteredProvider[]) => void;
|
|
501
|
+
|
|
360
502
|
interface Tracking {
|
|
361
503
|
/**
|
|
362
504
|
* Track a user action or application state, usually representing a business objective or outcome.
|
|
@@ -549,5 +691,5 @@ declare class OpenFeatureAPI extends OpenFeatureCommonAPI<ClientProviderStatus,
|
|
|
549
691
|
*/
|
|
550
692
|
declare const OpenFeature: OpenFeatureAPI;
|
|
551
693
|
|
|
552
|
-
export { InMemoryProvider, NOOP_PROVIDER, OpenFeature, OpenFeatureAPI, OpenFeatureEventEmitter };
|
|
553
|
-
export type { Client, Features, FlagEvaluationOptions, Hook, Provider, ProviderEmittableEvents, Tracking };
|
|
694
|
+
export { AggregateError, BaseEvaluationStrategy, ComparisonStrategy, ErrorWithCode, FirstMatchStrategy, FirstSuccessfulStrategy, InMemoryProvider, MultiProvider, NOOP_PROVIDER, OpenFeature, OpenFeatureAPI, OpenFeatureEventEmitter, constructAggregateError, throwAggregateErrorFromPromiseResults };
|
|
695
|
+
export type { Client, Features, FinalResult, FlagEvaluationOptions, Hook, Provider, ProviderEmittableEvents, ProviderResolutionErrorResult, ProviderResolutionResult, ProviderResolutionSuccessResult, StrategyEvaluationContext, StrategyPerProviderContext, StrategyProviderContext, Tracking };
|