@openfeature/web-sdk
Advanced tools
Comparing version 0.3.6-experimental to 0.3.7-experimental
@@ -450,2 +450,3 @@ "use strict"; | ||
InvalidContextError: () => InvalidContextError, | ||
LOG_LEVELS: () => LOG_LEVELS, | ||
NOOP_PROVIDER: () => NOOP_PROVIDER, | ||
@@ -465,7 +466,20 @@ NOOP_TRANSACTION_CONTEXT_PROPAGATOR: () => NOOP_TRANSACTION_CONTEXT_PROPAGATOR, | ||
TargetingKeyMissingError: () => TargetingKeyMissingError, | ||
TypeMismatchError: () => TypeMismatchError | ||
TypeMismatchError: () => TypeMismatchError, | ||
isObject: () => isObject, | ||
isString: () => isString, | ||
objectOrUndefined: () => objectOrUndefined, | ||
stringOrUndefined: () => stringOrUndefined | ||
}); | ||
module.exports = __toCommonJS(src_exports); | ||
// ../shared/src/types.ts | ||
// ../shared/src/errors/open-feature-error-abstract.ts | ||
var OpenFeatureError = class extends Error { | ||
constructor(message) { | ||
super(message); | ||
Object.setPrototypeOf(this, OpenFeatureError.prototype); | ||
this.name = "OpenFeatureError"; | ||
} | ||
}; | ||
// ../shared/src/evaluation/evaluation.ts | ||
var StandardResolutionReasons = { | ||
@@ -517,18 +531,3 @@ /** | ||
})(ErrorCode || {}); | ||
var ProviderStatus = /* @__PURE__ */ ((ProviderStatus2) => { | ||
ProviderStatus2["NOT_READY"] = "NOT_READY"; | ||
ProviderStatus2["READY"] = "READY"; | ||
ProviderStatus2["ERROR"] = "ERROR"; | ||
return ProviderStatus2; | ||
})(ProviderStatus || {}); | ||
// ../shared/src/errors/open-feature-error-abstract.ts | ||
var OpenFeatureError = class extends Error { | ||
constructor(message) { | ||
super(message); | ||
Object.setPrototypeOf(this, OpenFeatureError.prototype); | ||
this.name = "OpenFeatureError"; | ||
} | ||
}; | ||
// ../shared/src/errors/general-error.ts | ||
@@ -594,4 +593,12 @@ var GeneralError = class extends OpenFeatureError { | ||
// ../shared/src/logger.ts | ||
var LOG_LEVELS = ["error", "warn", "info", "debug"]; | ||
// ../shared/src/events/events.ts | ||
var ProviderEvents = /* @__PURE__ */ ((ProviderEvents2) => { | ||
ProviderEvents2["Ready"] = "PROVIDER_READY"; | ||
ProviderEvents2["Error"] = "PROVIDER_ERROR"; | ||
ProviderEvents2["ConfigurationChanged"] = "PROVIDER_CONFIGURATION_CHANGED"; | ||
ProviderEvents2["Stale"] = "PROVIDER_STALE"; | ||
return ProviderEvents2; | ||
})(ProviderEvents || {}); | ||
// ../shared/src/logger/default-logger.ts | ||
var DefaultLogger = class { | ||
@@ -609,2 +616,5 @@ error(...args) { | ||
}; | ||
// ../shared/src/logger/safe-logger.ts | ||
var LOG_LEVELS = ["error", "warn", "info", "debug"]; | ||
var SafeLogger = class { | ||
@@ -647,22 +657,4 @@ constructor(logger) { | ||
// ../shared/src/no-op-transaction-context-propagator.ts | ||
var NoopTransactionContextPropagator = class { | ||
getTransactionContext() { | ||
return {}; | ||
} | ||
setTransactionContext(_, callback) { | ||
callback(); | ||
} | ||
}; | ||
var NOOP_TRANSACTION_CONTEXT_PROPAGATOR = new NoopTransactionContextPropagator(); | ||
// ../shared/src/events.ts | ||
// ../shared/src/events/open-feature-event-emitter.ts | ||
var import_events = __toESM(require_events()); | ||
var ProviderEvents = /* @__PURE__ */ ((ProviderEvents2) => { | ||
ProviderEvents2["Ready"] = "PROVIDER_READY"; | ||
ProviderEvents2["Error"] = "PROVIDER_ERROR"; | ||
ProviderEvents2["ConfigurationChanged"] = "PROVIDER_CONFIGURATION_CHANGED"; | ||
ProviderEvents2["Stale"] = "PROVIDER_STALE"; | ||
return ProviderEvents2; | ||
})(ProviderEvents || {}); | ||
var OpenFeatureEventEmitter = class { | ||
@@ -715,2 +707,21 @@ constructor(globalLogger) { | ||
// ../shared/src/provider/provider.ts | ||
var ProviderStatus = /* @__PURE__ */ ((ProviderStatus2) => { | ||
ProviderStatus2["NOT_READY"] = "NOT_READY"; | ||
ProviderStatus2["READY"] = "READY"; | ||
ProviderStatus2["ERROR"] = "ERROR"; | ||
return ProviderStatus2; | ||
})(ProviderStatus || {}); | ||
// ../shared/src/transaction-context/no-op-transaction-context-propagator.ts | ||
var NoopTransactionContextPropagator = class { | ||
getTransactionContext() { | ||
return {}; | ||
} | ||
setTransactionContext(_, callback) { | ||
callback(); | ||
} | ||
}; | ||
var NOOP_TRANSACTION_CONTEXT_PROPAGATOR = new NoopTransactionContextPropagator(); | ||
// ../shared/src/type-guards.ts | ||
@@ -738,2 +749,3 @@ function isString(value) { | ||
constructor() { | ||
this._hooks = []; | ||
this._transactionContextPropagator = NOOP_TRANSACTION_CONTEXT_PROPAGATOR; | ||
@@ -747,2 +759,13 @@ this._context = {}; | ||
} | ||
addHooks(...hooks) { | ||
this._hooks = [...this._hooks, ...hooks]; | ||
return this; | ||
} | ||
getHooks() { | ||
return this._hooks; | ||
} | ||
clearHooks() { | ||
this._hooks = []; | ||
return this; | ||
} | ||
setLogger(logger) { | ||
@@ -759,5 +782,2 @@ this._logger = new SafeLogger(logger); | ||
} | ||
getContext() { | ||
return this._context; | ||
} | ||
/** | ||
@@ -861,3 +881,8 @@ * Adds a handler for the given provider event type. | ||
const unboundEmitterNames = eventEmitterNames.filter((name) => !namedProviders.includes(name)); | ||
return unboundEmitterNames.map((name) => this._clientEvents.get(name)).filter(isDefined); | ||
return [ | ||
// all unbound, named emitters | ||
...unboundEmitterNames.map((name) => this._clientEvents.get(name)), | ||
// the default emitter | ||
this._clientEvents.get(void 0) | ||
].filter(isDefined); | ||
} | ||
@@ -938,3 +963,3 @@ transferListeners(oldProvider, newProvider, clientName, emitters) { | ||
// src/no-op-provider.ts | ||
// src/provider/no-op-provider.ts | ||
var REASON_NO_OP = "No-op"; | ||
@@ -978,3 +1003,2 @@ var NoopFeatureProvider = class { | ||
super(); | ||
this._hooks = []; | ||
this._defaultProvider = NOOP_PROVIDER; | ||
@@ -996,17 +1020,2 @@ } | ||
} | ||
setLogger(logger) { | ||
this._logger = new SafeLogger(logger); | ||
return this; | ||
} | ||
addHooks(...hooks) { | ||
this._hooks = [...this._hooks, ...hooks]; | ||
return this; | ||
} | ||
getHooks() { | ||
return this._hooks; | ||
} | ||
clearHooks() { | ||
this._hooks = []; | ||
return this; | ||
} | ||
setContext(context) { | ||
@@ -1020,2 +1029,5 @@ return __async(this, null, function* () { | ||
} | ||
getContext() { | ||
return this._context; | ||
} | ||
/** | ||
@@ -1045,3 +1057,3 @@ * A factory function for creating new named OpenFeature clients. Clients can contain | ||
// src/client.ts | ||
// src/client/open-feature-client.ts | ||
var OpenFeatureClient = class { | ||
@@ -1048,0 +1060,0 @@ constructor(providerAccessor, emitterAccessor, globalLogger, options) { |
@@ -436,3 +436,12 @@ var __create = Object.create; | ||
// ../shared/src/types.ts | ||
// ../shared/src/errors/open-feature-error-abstract.ts | ||
var OpenFeatureError = class extends Error { | ||
constructor(message) { | ||
super(message); | ||
Object.setPrototypeOf(this, OpenFeatureError.prototype); | ||
this.name = "OpenFeatureError"; | ||
} | ||
}; | ||
// ../shared/src/evaluation/evaluation.ts | ||
var StandardResolutionReasons = { | ||
@@ -484,18 +493,3 @@ /** | ||
})(ErrorCode || {}); | ||
var ProviderStatus = /* @__PURE__ */ ((ProviderStatus2) => { | ||
ProviderStatus2["NOT_READY"] = "NOT_READY"; | ||
ProviderStatus2["READY"] = "READY"; | ||
ProviderStatus2["ERROR"] = "ERROR"; | ||
return ProviderStatus2; | ||
})(ProviderStatus || {}); | ||
// ../shared/src/errors/open-feature-error-abstract.ts | ||
var OpenFeatureError = class extends Error { | ||
constructor(message) { | ||
super(message); | ||
Object.setPrototypeOf(this, OpenFeatureError.prototype); | ||
this.name = "OpenFeatureError"; | ||
} | ||
}; | ||
// ../shared/src/errors/general-error.ts | ||
@@ -561,4 +555,12 @@ var GeneralError = class extends OpenFeatureError { | ||
// ../shared/src/logger.ts | ||
var LOG_LEVELS = ["error", "warn", "info", "debug"]; | ||
// ../shared/src/events/events.ts | ||
var ProviderEvents = /* @__PURE__ */ ((ProviderEvents2) => { | ||
ProviderEvents2["Ready"] = "PROVIDER_READY"; | ||
ProviderEvents2["Error"] = "PROVIDER_ERROR"; | ||
ProviderEvents2["ConfigurationChanged"] = "PROVIDER_CONFIGURATION_CHANGED"; | ||
ProviderEvents2["Stale"] = "PROVIDER_STALE"; | ||
return ProviderEvents2; | ||
})(ProviderEvents || {}); | ||
// ../shared/src/logger/default-logger.ts | ||
var DefaultLogger = class { | ||
@@ -576,2 +578,5 @@ error(...args) { | ||
}; | ||
// ../shared/src/logger/safe-logger.ts | ||
var LOG_LEVELS = ["error", "warn", "info", "debug"]; | ||
var SafeLogger = class { | ||
@@ -614,22 +619,4 @@ constructor(logger) { | ||
// ../shared/src/no-op-transaction-context-propagator.ts | ||
var NoopTransactionContextPropagator = class { | ||
getTransactionContext() { | ||
return {}; | ||
} | ||
setTransactionContext(_, callback) { | ||
callback(); | ||
} | ||
}; | ||
var NOOP_TRANSACTION_CONTEXT_PROPAGATOR = new NoopTransactionContextPropagator(); | ||
// ../shared/src/events.ts | ||
// ../shared/src/events/open-feature-event-emitter.ts | ||
var import_events = __toESM(require_events()); | ||
var ProviderEvents = /* @__PURE__ */ ((ProviderEvents2) => { | ||
ProviderEvents2["Ready"] = "PROVIDER_READY"; | ||
ProviderEvents2["Error"] = "PROVIDER_ERROR"; | ||
ProviderEvents2["ConfigurationChanged"] = "PROVIDER_CONFIGURATION_CHANGED"; | ||
ProviderEvents2["Stale"] = "PROVIDER_STALE"; | ||
return ProviderEvents2; | ||
})(ProviderEvents || {}); | ||
var OpenFeatureEventEmitter = class { | ||
@@ -682,2 +669,21 @@ constructor(globalLogger) { | ||
// ../shared/src/provider/provider.ts | ||
var ProviderStatus = /* @__PURE__ */ ((ProviderStatus2) => { | ||
ProviderStatus2["NOT_READY"] = "NOT_READY"; | ||
ProviderStatus2["READY"] = "READY"; | ||
ProviderStatus2["ERROR"] = "ERROR"; | ||
return ProviderStatus2; | ||
})(ProviderStatus || {}); | ||
// ../shared/src/transaction-context/no-op-transaction-context-propagator.ts | ||
var NoopTransactionContextPropagator = class { | ||
getTransactionContext() { | ||
return {}; | ||
} | ||
setTransactionContext(_, callback) { | ||
callback(); | ||
} | ||
}; | ||
var NOOP_TRANSACTION_CONTEXT_PROPAGATOR = new NoopTransactionContextPropagator(); | ||
// ../shared/src/type-guards.ts | ||
@@ -705,2 +711,3 @@ function isString(value) { | ||
constructor() { | ||
this._hooks = []; | ||
this._transactionContextPropagator = NOOP_TRANSACTION_CONTEXT_PROPAGATOR; | ||
@@ -714,2 +721,13 @@ this._context = {}; | ||
} | ||
addHooks(...hooks) { | ||
this._hooks = [...this._hooks, ...hooks]; | ||
return this; | ||
} | ||
getHooks() { | ||
return this._hooks; | ||
} | ||
clearHooks() { | ||
this._hooks = []; | ||
return this; | ||
} | ||
setLogger(logger) { | ||
@@ -726,5 +744,2 @@ this._logger = new SafeLogger(logger); | ||
} | ||
getContext() { | ||
return this._context; | ||
} | ||
/** | ||
@@ -828,3 +843,8 @@ * Adds a handler for the given provider event type. | ||
const unboundEmitterNames = eventEmitterNames.filter((name) => !namedProviders.includes(name)); | ||
return unboundEmitterNames.map((name) => this._clientEvents.get(name)).filter(isDefined); | ||
return [ | ||
// all unbound, named emitters | ||
...unboundEmitterNames.map((name) => this._clientEvents.get(name)), | ||
// the default emitter | ||
this._clientEvents.get(void 0) | ||
].filter(isDefined); | ||
} | ||
@@ -905,3 +925,3 @@ transferListeners(oldProvider, newProvider, clientName, emitters) { | ||
// src/no-op-provider.ts | ||
// src/provider/no-op-provider.ts | ||
var REASON_NO_OP = "No-op"; | ||
@@ -945,3 +965,2 @@ var NoopFeatureProvider = class { | ||
super(); | ||
this._hooks = []; | ||
this._defaultProvider = NOOP_PROVIDER; | ||
@@ -963,17 +982,2 @@ } | ||
} | ||
setLogger(logger) { | ||
this._logger = new SafeLogger(logger); | ||
return this; | ||
} | ||
addHooks(...hooks) { | ||
this._hooks = [...this._hooks, ...hooks]; | ||
return this; | ||
} | ||
getHooks() { | ||
return this._hooks; | ||
} | ||
clearHooks() { | ||
this._hooks = []; | ||
return this; | ||
} | ||
setContext(context) { | ||
@@ -987,2 +991,5 @@ return __async(this, null, function* () { | ||
} | ||
getContext() { | ||
return this._context; | ||
} | ||
/** | ||
@@ -1012,3 +1019,3 @@ * A factory function for creating new named OpenFeature clients. Clients can contain | ||
// src/client.ts | ||
// src/client/open-feature-client.ts | ||
var OpenFeatureClient = class { | ||
@@ -1199,2 +1206,3 @@ constructor(providerAccessor, emitterAccessor, globalLogger, options) { | ||
InvalidContextError, | ||
LOG_LEVELS, | ||
NOOP_PROVIDER, | ||
@@ -1214,4 +1222,8 @@ NOOP_TRANSACTION_CONTEXT_PROPAGATOR, | ||
TargetingKeyMissingError, | ||
TypeMismatchError | ||
TypeMismatchError, | ||
isObject, | ||
isString, | ||
objectOrUndefined, | ||
stringOrUndefined | ||
}; | ||
//# sourceMappingURL=index.js.map |
@@ -0,1 +1,20 @@ | ||
declare enum ProviderEvents { | ||
/** | ||
* The provider is ready to evaluate flags. | ||
*/ | ||
Ready = "PROVIDER_READY", | ||
/** | ||
* The provider is in an error state. | ||
*/ | ||
Error = "PROVIDER_ERROR", | ||
/** | ||
* The flag configuration in the source-of-truth has changed. | ||
*/ | ||
ConfigurationChanged = "PROVIDER_CONFIGURATION_CHANGED", | ||
/** | ||
* The provider's cached state is no longer valid and may not be up-to-date with the source of truth. | ||
*/ | ||
Stale = "PROVIDER_STALE" | ||
} | ||
type EventMetadata = { | ||
@@ -32,20 +51,41 @@ [key: string]: string | boolean | number; | ||
} | ||
declare enum ProviderEvents { | ||
interface Logger { | ||
error(...args: unknown[]): void; | ||
warn(...args: unknown[]): void; | ||
info(...args: unknown[]): void; | ||
debug(...args: unknown[]): void; | ||
} | ||
interface ManageLogger<T> { | ||
/** | ||
* The provider is ready to evaluate flags. | ||
* Sets a logger on this receiver. This logger supersedes to the global logger | ||
* and is passed to various components in the SDK. | ||
* The logger configured on the global API object will be used for all evaluations, | ||
* unless overridden in a particular client. | ||
* @template T The type of the receiver | ||
* @param {Logger} logger The logger to be used | ||
* @returns {T} The receiver (this object) | ||
*/ | ||
Ready = "PROVIDER_READY", | ||
/** | ||
* The provider is in an error state. | ||
*/ | ||
Error = "PROVIDER_ERROR", | ||
/** | ||
* The flag configuration in the source-of-truth has changed. | ||
*/ | ||
ConfigurationChanged = "PROVIDER_CONFIGURATION_CHANGED", | ||
/** | ||
* The provider's cached state is no longer valid and may not be up-to-date with the source of truth. | ||
*/ | ||
Stale = "PROVIDER_STALE" | ||
setLogger(logger: Logger): T; | ||
} | ||
declare class DefaultLogger implements Logger { | ||
error(...args: unknown[]): void; | ||
warn(...args: unknown[]): void; | ||
info(): void; | ||
debug(): void; | ||
} | ||
declare const LOG_LEVELS: Array<keyof Logger>; | ||
declare class SafeLogger implements Logger { | ||
private readonly logger; | ||
private readonly fallbackLogger; | ||
constructor(logger: Logger); | ||
error(...args: unknown[]): void; | ||
warn(...args: unknown[]): void; | ||
info(...args: unknown[]): void; | ||
debug(...args: unknown[]): void; | ||
private log; | ||
} | ||
declare class OpenFeatureEventEmitter implements ManageLogger<OpenFeatureEventEmitter> { | ||
@@ -66,2 +106,6 @@ private readonly globalLogger?; | ||
interface Metadata { | ||
} | ||
type FlagValueType = 'boolean' | 'string' | 'number' | 'object'; | ||
type PrimitiveValue = null | boolean | string | number; | ||
@@ -79,24 +123,22 @@ type JsonObject = { | ||
*/ | ||
type EvaluationContextValue = PrimitiveValue | Date | { | ||
[key: string]: EvaluationContextValue; | ||
} | EvaluationContextValue[]; | ||
type FlagValue = boolean | string | number | JsonValue; | ||
type ResolutionReason = keyof typeof StandardResolutionReasons | (string & Record<never, never>); | ||
/** | ||
* A container for arbitrary contextual data that can be used as a basis for dynamic evaluation | ||
* A structure which supports definition of arbitrary properties, with keys of type string, and values of type boolean, string, or number. | ||
* | ||
* This structure is populated by a provider for use by an Application Author (via the Evaluation API) or an Application Integrator (via hooks). | ||
*/ | ||
type EvaluationContext = { | ||
/** | ||
* A string uniquely identifying the subject (end-user, or client service) of a flag evaluation. | ||
* Providers may require this field for fractional flag evaluation, rules, or overrides targeting specific users. | ||
* Such providers may behave unpredictably if a targeting key is not specified at flag resolution. | ||
*/ | ||
targetingKey?: string; | ||
} & Record<string, EvaluationContextValue>; | ||
type FlagValue = boolean | string | number | JsonValue; | ||
type FlagValueType = 'boolean' | 'string' | 'number' | 'object'; | ||
interface Logger { | ||
error(...args: unknown[]): void; | ||
warn(...args: unknown[]): void; | ||
info(...args: unknown[]): void; | ||
debug(...args: unknown[]): void; | ||
} | ||
type FlagMetadata = Record<string, string | number | boolean>; | ||
type ResolutionDetails<U> = { | ||
value: U; | ||
variant?: string; | ||
flagMetadata?: FlagMetadata; | ||
reason?: ResolutionReason; | ||
errorCode?: ErrorCode; | ||
errorMessage?: string; | ||
}; | ||
type EvaluationDetails<T extends FlagValue> = { | ||
flagKey: string; | ||
flagMetadata: Readonly<FlagMetadata>; | ||
} & ResolutionDetails<T>; | ||
declare const StandardResolutionReasons: { | ||
@@ -168,21 +210,17 @@ /** | ||
} | ||
type ResolutionReason = keyof typeof StandardResolutionReasons | (string & Record<never, never>); | ||
type EvaluationContextValue = PrimitiveValue | Date | { | ||
[key: string]: EvaluationContextValue; | ||
} | EvaluationContextValue[]; | ||
/** | ||
* A structure which supports definition of arbitrary properties, with keys of type string, and values of type boolean, string, or number. | ||
* | ||
* This structure is populated by a provider for use by an Application Author (via the Evaluation API) or an Application Integrator (via hooks). | ||
* A container for arbitrary contextual data that can be used as a basis for dynamic evaluation | ||
*/ | ||
type FlagMetadata = Record<string, string | number | boolean>; | ||
type ResolutionDetails<U> = { | ||
value: U; | ||
variant?: string; | ||
flagMetadata?: FlagMetadata; | ||
reason?: ResolutionReason; | ||
errorCode?: ErrorCode; | ||
errorMessage?: string; | ||
}; | ||
type EvaluationDetails<T extends FlagValue> = { | ||
flagKey: string; | ||
flagMetadata: Readonly<FlagMetadata>; | ||
} & ResolutionDetails<T>; | ||
type EvaluationContext = { | ||
/** | ||
* A string uniquely identifying the subject (end-user, or client service) of a flag evaluation. | ||
* Providers may require this field for fractional flag evaluation, rules, or overrides targeting specific users. | ||
* Such providers may behave unpredictably if a targeting key is not specified at flag resolution. | ||
*/ | ||
targetingKey?: string; | ||
} & Record<string, EvaluationContextValue>; | ||
interface ManageContext<T> { | ||
@@ -203,17 +241,31 @@ /** | ||
} | ||
interface ManageLogger<T> { | ||
declare enum ProviderStatus { | ||
NOT_READY = "NOT_READY", | ||
READY = "READY", | ||
ERROR = "ERROR" | ||
} | ||
interface ProviderMetadata extends Metadata { | ||
readonly name: string; | ||
} | ||
interface CommonProvider { | ||
readonly metadata: ProviderMetadata; | ||
readonly status?: ProviderStatus; | ||
/** | ||
* Sets a logger on this receiver. This logger supersedes to the global logger | ||
* and is passed to various components in the SDK. | ||
* The logger configured on the global API object will be used for all evaluations, | ||
* unless overridden in a particular client. | ||
* @template T The type of the receiver | ||
* @param {Logger} logger The logger to be used | ||
* @returns {T} The receiver (this object) | ||
* An event emitter for ProviderEvents. | ||
* @see ProviderEvents | ||
*/ | ||
setLogger(logger: Logger): T; | ||
events?: OpenFeatureEventEmitter; | ||
onClose?(): Promise<void>; | ||
/** | ||
* A handler function used to setup the provider. | ||
* Called by the SDK after the provider is set. | ||
* When the returned promise resolves, the SDK fires the ProviderEvents.Ready event. | ||
* If the returned promise rejects, the SDK fires the ProviderEvents.Error event. | ||
* Use this function to perform any context-dependent setup within the provider. | ||
* @param context | ||
*/ | ||
initialize?(context?: EvaluationContext): Promise<void>; | ||
} | ||
type HookHints = Readonly<Record<string, unknown>>; | ||
interface Metadata { | ||
} | ||
interface ClientMetadata extends Metadata { | ||
@@ -224,5 +276,4 @@ readonly version?: string; | ||
} | ||
interface ProviderMetadata extends Metadata { | ||
readonly name: string; | ||
} | ||
type HookHints = Readonly<Record<string, unknown>>; | ||
interface HookContext<T extends FlagValue = FlagValue> { | ||
@@ -240,70 +291,57 @@ readonly flagKey: string; | ||
} | ||
/** | ||
* Transaction context is a mechanism for adding transaction specific context that | ||
* is merged with evaluation context prior to flag evaluation. Examples of potential | ||
* transaction specific context include: a user id, user agent, or request path. | ||
*/ | ||
type TransactionContext = EvaluationContext; | ||
interface ManageTransactionContextPropagator<T> extends TransactionContextPropagator { | ||
interface Hook<T extends FlagValue = FlagValue> { | ||
/** | ||
* EXPERIMENTAL: Transaction context propagation is experimental and subject to change. | ||
* The OpenFeature Enhancement Proposal regarding transaction context can be found [here](https://github.com/open-feature/ofep/pull/32). | ||
* | ||
* Sets a transaction context propagator on this receiver. The transaction context | ||
* propagator is responsible for persisting context for the duration of a single | ||
* transaction. | ||
* @experimental | ||
* @template T The type of the receiver | ||
* @param {TransactionContextPropagator} transactionContextPropagator The context propagator to be used | ||
* @returns {T} The receiver (this object) | ||
* Runs before flag values are resolved from the provider. | ||
* If an EvaluationContext is returned, it will be merged with the pre-existing EvaluationContext. | ||
* @param hookContext | ||
* @param hookHints | ||
*/ | ||
setTransactionContextPropagator(transactionContextPropagator: TransactionContextPropagator): T; | ||
} | ||
interface TransactionContextPropagator { | ||
before?(hookContext: BeforeHookContext, hookHints?: HookHints): Promise<EvaluationContext | void> | EvaluationContext | void; | ||
/** | ||
* EXPERIMENTAL: Transaction context propagation is experimental and subject to change. | ||
* The OpenFeature Enhancement Proposal regarding transaction context can be found [here](https://github.com/open-feature/ofep/pull/32). | ||
* | ||
* Returns the currently defined transaction context using the registered transaction | ||
* context propagator. | ||
* @experimental | ||
* @returns {TransactionContext} The current transaction context | ||
* Runs after flag values are successfully resolved from the provider. | ||
* @param hookContext | ||
* @param evaluationDetails | ||
* @param hookHints | ||
*/ | ||
getTransactionContext(): TransactionContext; | ||
after?(hookContext: Readonly<HookContext<T>>, evaluationDetails: EvaluationDetails<T>, hookHints?: HookHints): Promise<void> | void; | ||
/** | ||
* EXPERIMENTAL: Transaction context propagation is experimental and subject to change. | ||
* The OpenFeature Enhancement Proposal regarding transaction context can be found [here](https://github.com/open-feature/ofep/pull/32). | ||
* | ||
* Sets the transaction context using the registered transaction context propagator. | ||
* @experimental | ||
* @template R The return value of the callback | ||
* @param {TransactionContext} transactionContext The transaction specific context | ||
* @param {(...args: unknown[]) => R} callback Callback function used to set the transaction context on the stack | ||
* @param {...unknown[]} args Optional arguments that are passed to the callback function | ||
* Runs in the event of an unhandled error or promise rejection during flag resolution, or any attached hooks. | ||
* @param hookContext | ||
* @param error | ||
* @param hookHints | ||
*/ | ||
setTransactionContext<R>(transactionContext: TransactionContext, callback: (...args: unknown[]) => R, ...args: unknown[]): void; | ||
error?(hookContext: Readonly<HookContext<T>>, error: unknown, hookHints?: HookHints): Promise<void> | void; | ||
/** | ||
* Runs after all other hook stages, regardless of success or error. | ||
* Errors thrown here are unhandled by the client and will surface in application code. | ||
* @param hookContext | ||
* @param hookHints | ||
*/ | ||
finally?(hookContext: Readonly<HookContext<T>>, hookHints?: HookHints): Promise<void> | void; | ||
} | ||
declare enum ProviderStatus { | ||
NOT_READY = "NOT_READY", | ||
READY = "READY", | ||
ERROR = "ERROR" | ||
} | ||
interface CommonProvider { | ||
readonly metadata: ProviderMetadata; | ||
readonly status?: ProviderStatus; | ||
interface EvaluationLifeCycle<T> { | ||
/** | ||
* An event emitter for ProviderEvents. | ||
* @see ProviderEvents | ||
* Adds hooks that will run during flag evaluations on this receiver. | ||
* Hooks are executed in the order they were registered. Adding additional hooks | ||
* will not remove existing hooks. | ||
* Hooks registered on the global API object run with all evaluations. | ||
* Hooks registered on the client run with all evaluations on that client. | ||
* @template T The type of the receiver | ||
* @param {Hook<FlagValue>[]} hooks A list of hooks that should always run | ||
* @returns {T} The receiver (this object) | ||
*/ | ||
events?: OpenFeatureEventEmitter; | ||
onClose?(): Promise<void>; | ||
addHooks(...hooks: Hook<FlagValue>[]): T; | ||
/** | ||
* A handler function used to setup the provider. | ||
* Called by the SDK after the provider is set. | ||
* When the returned promise resolves, the SDK fires the ProviderEvents.Ready event. | ||
* If the returned promise rejects, the SDK fires the ProviderEvents.Error event. | ||
* Use this function to perform any context-dependent setup within the provider. | ||
* @param context | ||
* Access all the hooks that are registered on this receiver. | ||
* @returns {Hook<FlagValue>[]} A list of the client hooks | ||
*/ | ||
initialize?(context?: EvaluationContext): Promise<void>; | ||
getHooks(): Hook<FlagValue>[]; | ||
/** | ||
* Clears all the hooks that are registered on this receiver. | ||
* @template T The type of the receiver | ||
* @returns {T} The receiver (this object) | ||
*/ | ||
clearHooks(): T; | ||
} | ||
@@ -346,17 +384,46 @@ | ||
declare class DefaultLogger implements Logger { | ||
error(...args: unknown[]): void; | ||
warn(...args: unknown[]): void; | ||
info(): void; | ||
debug(): void; | ||
/** | ||
* Transaction context is a mechanism for adding transaction specific context that | ||
* is merged with evaluation context prior to flag evaluation. Examples of potential | ||
* transaction specific context include: a user id, user agent, or request path. | ||
*/ | ||
type TransactionContext = EvaluationContext; | ||
interface ManageTransactionContextPropagator<T> extends TransactionContextPropagator { | ||
/** | ||
* EXPERIMENTAL: Transaction context propagation is experimental and subject to change. | ||
* The OpenFeature Enhancement Proposal regarding transaction context can be found [here](https://github.com/open-feature/ofep/pull/32). | ||
* | ||
* Sets a transaction context propagator on this receiver. The transaction context | ||
* propagator is responsible for persisting context for the duration of a single | ||
* transaction. | ||
* @experimental | ||
* @template T The type of the receiver | ||
* @param {TransactionContextPropagator} transactionContextPropagator The context propagator to be used | ||
* @returns {T} The receiver (this object) | ||
*/ | ||
setTransactionContextPropagator(transactionContextPropagator: TransactionContextPropagator): T; | ||
} | ||
declare class SafeLogger implements Logger { | ||
private readonly logger; | ||
private readonly fallbackLogger; | ||
constructor(logger: Logger); | ||
error(...args: unknown[]): void; | ||
warn(...args: unknown[]): void; | ||
info(...args: unknown[]): void; | ||
debug(...args: unknown[]): void; | ||
private log; | ||
interface TransactionContextPropagator { | ||
/** | ||
* EXPERIMENTAL: Transaction context propagation is experimental and subject to change. | ||
* The OpenFeature Enhancement Proposal regarding transaction context can be found [here](https://github.com/open-feature/ofep/pull/32). | ||
* | ||
* Returns the currently defined transaction context using the registered transaction | ||
* context propagator. | ||
* @experimental | ||
* @returns {TransactionContext} The current transaction context | ||
*/ | ||
getTransactionContext(): TransactionContext; | ||
/** | ||
* EXPERIMENTAL: Transaction context propagation is experimental and subject to change. | ||
* The OpenFeature Enhancement Proposal regarding transaction context can be found [here](https://github.com/open-feature/ofep/pull/32). | ||
* | ||
* Sets the transaction context using the registered transaction context propagator. | ||
* @experimental | ||
* @template R The return value of the callback | ||
* @param {TransactionContext} transactionContext The transaction specific context | ||
* @param {(...args: unknown[]) => R} callback Callback function used to set the transaction context on the stack | ||
* @param {...unknown[]} args Optional arguments that are passed to the callback function | ||
*/ | ||
setTransactionContext<R>(transactionContext: TransactionContext, callback: (...args: unknown[]) => R, ...args: unknown[]): void; | ||
} | ||
@@ -370,3 +437,29 @@ | ||
declare abstract class OpenFeatureCommonAPI<P extends CommonProvider = CommonProvider> implements Eventing { | ||
/** | ||
* Checks whether the parameter is a string. | ||
* @param {unknown} value The value to check | ||
* @returns {value is string} True if the value is a string | ||
*/ | ||
declare function isString(value: unknown): value is string; | ||
/** | ||
* Returns the parameter if it is a string, otherwise returns undefined. | ||
* @param {unknown} value The value to check | ||
* @returns {string|undefined} The parameter if it is a string, otherwise undefined | ||
*/ | ||
declare function stringOrUndefined(value: unknown): string | undefined; | ||
/** | ||
* Checks whether the parameter is an object. | ||
* @param {unknown} value The value to check | ||
* @returns {value is string} True if the value is an object | ||
*/ | ||
declare function isObject<T extends object>(value: unknown): value is T; | ||
/** | ||
* Returns the parameter if it is an object, otherwise returns undefined. | ||
* @param {unknown} value The value to check | ||
* @returns {object|undefined} The parameter if it is an object, otherwise undefined | ||
*/ | ||
declare function objectOrUndefined<T extends object>(value: unknown): T | undefined; | ||
declare abstract class OpenFeatureCommonAPI<P extends CommonProvider = CommonProvider> implements Eventing, EvaluationLifeCycle<OpenFeatureCommonAPI<P>>, ManageLogger<OpenFeatureCommonAPI<P>>, ManageTransactionContextPropagator<OpenFeatureCommonAPI<P>> { | ||
protected _hooks: Hook[]; | ||
protected _transactionContextPropagator: TransactionContextPropagator; | ||
@@ -380,3 +473,5 @@ protected _context: EvaluationContext; | ||
protected _clientEvents: Map<string | undefined, OpenFeatureEventEmitter>; | ||
abstract clearHooks(): this; | ||
addHooks(...hooks: Hook<FlagValue>[]): this; | ||
getHooks(): Hook<FlagValue>[]; | ||
clearHooks(): this; | ||
setLogger(logger: Logger): this; | ||
@@ -388,3 +483,2 @@ /** | ||
get providerMetadata(): ProviderMetadata; | ||
getContext(): EvaluationContext; | ||
/** | ||
@@ -439,94 +533,2 @@ * Adds a handler for the given provider event type. | ||
/** | ||
* Interface that providers must implement to resolve flag values for their particular | ||
* backend or vendor. | ||
* | ||
* Implementation for resolving all the required flag types must be defined. | ||
*/ | ||
interface Provider extends CommonProvider { | ||
/** | ||
* A provider hook exposes a mechanism for provider authors to register hooks | ||
* to tap into various stages of the flag evaluation lifecycle. These hooks can | ||
* be used to perform side effects and mutate the context for purposes of the | ||
* provider. Provider hooks are not configured or controlled by the application author. | ||
*/ | ||
readonly hooks?: Hook[]; | ||
/** | ||
* A handler function to reconcile changes when the static context. | ||
* Called by the SDK when the context is changed. | ||
* @param oldContext | ||
* @param newContext | ||
*/ | ||
onContextChange?(oldContext: EvaluationContext, newContext: EvaluationContext): Promise<void>; | ||
/** | ||
* Resolve a boolean flag and its evaluation details. | ||
*/ | ||
resolveBooleanEvaluation(flagKey: string, defaultValue: boolean, context: EvaluationContext, logger: Logger): ResolutionDetails<boolean>; | ||
/** | ||
* Resolve a string flag and its evaluation details. | ||
*/ | ||
resolveStringEvaluation(flagKey: string, defaultValue: string, context: EvaluationContext, logger: Logger): ResolutionDetails<string>; | ||
/** | ||
* Resolve a numeric flag and its evaluation details. | ||
*/ | ||
resolveNumberEvaluation(flagKey: string, defaultValue: number, context: EvaluationContext, logger: Logger): ResolutionDetails<number>; | ||
/** | ||
* Resolve and parse an object flag and its evaluation details. | ||
*/ | ||
resolveObjectEvaluation<T extends JsonValue>(flagKey: string, defaultValue: T, context: EvaluationContext, logger: Logger): ResolutionDetails<T>; | ||
} | ||
interface Hook<T extends FlagValue = FlagValue> { | ||
/** | ||
* Runs before flag values are resolved from the provider. | ||
* If an EvaluationContext is returned, it will be merged with the pre-existing EvaluationContext. | ||
* @param hookContext | ||
* @param hookHints | ||
*/ | ||
before?(hookContext: BeforeHookContext, hookHints?: HookHints): EvaluationContext | void; | ||
/** | ||
* Runs after flag values are successfully resolved from the provider. | ||
* @param hookContext | ||
* @param evaluationDetails | ||
* @param hookHints | ||
*/ | ||
after?(hookContext: Readonly<HookContext<T>>, evaluationDetails: EvaluationDetails<T>, hookHints?: HookHints): void; | ||
/** | ||
* Runs in the event of an unhandled error or promise rejection during flag resolution, or any attached hooks. | ||
* @param hookContext | ||
* @param error | ||
* @param hookHints | ||
*/ | ||
error?(hookContext: Readonly<HookContext<T>>, error: unknown, hookHints?: HookHints): void; | ||
/** | ||
* Runs after all other hook stages, regardless of success or error. | ||
* Errors thrown here are unhandled by the client and will surface in application code. | ||
* @param hookContext | ||
* @param hookHints | ||
*/ | ||
finally?(hookContext: Readonly<HookContext<T>>, hookHints?: HookHints): void; | ||
} | ||
interface EvaluationLifeCycle<T> { | ||
/** | ||
* Adds hooks that will run during flag evaluations on this receiver. | ||
* Hooks are executed in the order they were registered. Adding additional hooks | ||
* will not remove existing hooks. | ||
* Hooks registered on the global API object run with all evaluations. | ||
* Hooks registered on the client run with all evaluations on that client. | ||
* @template T The type of the receiver | ||
* @param {Hook<FlagValue>[]} hooks A list of hooks that should always run | ||
* @returns {T} The receiver (this object) | ||
*/ | ||
addHooks(...hooks: Hook[]): T; | ||
/** | ||
* Access all the hooks that are registered on this receiver. | ||
* @returns {Hook<FlagValue>[]} A list of the client hooks | ||
*/ | ||
getHooks(): Hook[]; | ||
/** | ||
* Clears all the hooks that are registered on this receiver. | ||
* @template T The type of the receiver | ||
* @returns {T} The receiver (this object) | ||
*/ | ||
clearHooks(): T; | ||
} | ||
interface FlagEvaluationOptions { | ||
@@ -614,26 +616,62 @@ hooks?: Hook[]; | ||
} | ||
interface Client extends EvaluationLifeCycle<Client>, Features, ManageLogger<Client>, Eventing { | ||
readonly metadata: ClientMetadata; | ||
} | ||
interface GlobalApi extends EvaluationLifeCycle<GlobalApi>, ManageContext<GlobalApi>, ManageLogger<GlobalApi>, ManageTransactionContextPropagator<GlobalApi> { | ||
readonly providerMetadata: ProviderMetadata; | ||
/** | ||
* Interface that providers must implement to resolve flag values for their particular | ||
* backend or vendor. | ||
* | ||
* Implementation for resolving all the required flag types must be defined. | ||
*/ | ||
interface Provider extends CommonProvider { | ||
/** | ||
* A factory function for creating new OpenFeature clients. Clients can contain | ||
* their own state (e.g. logger, hook, context). Multiple clients can be used | ||
* to segment feature flag configuration. | ||
* @param {string} name The name of the client | ||
* @param {string} version The version of the client | ||
* @param {EvaluationContext} context Evaluation context that should be set on the client to used during flag evaluations | ||
* @returns {Client} OpenFeature Client | ||
* A provider hook exposes a mechanism for provider authors to register hooks | ||
* to tap into various stages of the flag evaluation lifecycle. These hooks can | ||
* be used to perform side effects and mutate the context for purposes of the | ||
* provider. Provider hooks are not configured or controlled by the application author. | ||
*/ | ||
getClient(name?: string, version?: string, context?: EvaluationContext): Client; | ||
readonly hooks?: Hook[]; | ||
/** | ||
* Sets the provider that OpenFeature will use for flag evaluations. Setting | ||
* a provider supersedes the current provider used in new and existing clients. | ||
* @param {Provider} provider The provider responsible for flag evaluations. | ||
* @returns {GlobalApi} OpenFeature API | ||
* A handler function to reconcile changes when the static context. | ||
* Called by the SDK when the context is changed. | ||
* @param oldContext | ||
* @param newContext | ||
*/ | ||
setProvider(provider: Provider): GlobalApi; | ||
onContextChange?(oldContext: EvaluationContext, newContext: EvaluationContext): Promise<void>; | ||
/** | ||
* Resolve a boolean flag and its evaluation details. | ||
*/ | ||
resolveBooleanEvaluation(flagKey: string, defaultValue: boolean, context: EvaluationContext, logger: Logger): ResolutionDetails<boolean>; | ||
/** | ||
* Resolve a string flag and its evaluation details. | ||
*/ | ||
resolveStringEvaluation(flagKey: string, defaultValue: string, context: EvaluationContext, logger: Logger): ResolutionDetails<string>; | ||
/** | ||
* Resolve a numeric flag and its evaluation details. | ||
*/ | ||
resolveNumberEvaluation(flagKey: string, defaultValue: number, context: EvaluationContext, logger: Logger): ResolutionDetails<number>; | ||
/** | ||
* Resolve and parse an object flag and its evaluation details. | ||
*/ | ||
resolveObjectEvaluation<T extends JsonValue>(flagKey: string, defaultValue: T, context: EvaluationContext, logger: Logger): ResolutionDetails<T>; | ||
} | ||
/** | ||
* The No-op provider is set by default, and simply always returns the default value. | ||
*/ | ||
declare class NoopFeatureProvider implements Provider { | ||
readonly metadata: { | ||
readonly name: "No-op Provider"; | ||
}; | ||
get status(): ProviderStatus; | ||
resolveBooleanEvaluation(_: string, defaultValue: boolean): ResolutionDetails<boolean>; | ||
resolveStringEvaluation(_: string, defaultValue: string): ResolutionDetails<string>; | ||
resolveNumberEvaluation(_: string, defaultValue: number): ResolutionDetails<number>; | ||
resolveObjectEvaluation<T extends JsonValue>(_: string, defaultValue: T): ResolutionDetails<T>; | ||
private noOp; | ||
} | ||
declare const NOOP_PROVIDER: NoopFeatureProvider; | ||
type OpenFeatureClientOptions = { | ||
@@ -676,20 +714,3 @@ name?: string; | ||
/** | ||
* The No-op provider is set by default, and simply always returns the default value. | ||
*/ | ||
declare class NoopFeatureProvider implements Provider { | ||
readonly metadata: { | ||
readonly name: "No-op Provider"; | ||
}; | ||
get status(): ProviderStatus; | ||
resolveBooleanEvaluation(_: string, defaultValue: boolean): ResolutionDetails<boolean>; | ||
resolveStringEvaluation(_: string, defaultValue: string): ResolutionDetails<string>; | ||
resolveNumberEvaluation(_: string, defaultValue: number): ResolutionDetails<number>; | ||
resolveObjectEvaluation<T extends JsonValue>(_: string, defaultValue: T): ResolutionDetails<T>; | ||
private noOp; | ||
} | ||
declare const NOOP_PROVIDER: NoopFeatureProvider; | ||
declare class OpenFeatureAPI extends OpenFeatureCommonAPI<Provider> { | ||
protected _hooks: Hook[]; | ||
declare class OpenFeatureAPI extends OpenFeatureCommonAPI<Provider> implements ManageContext<Promise<void>> { | ||
protected _defaultProvider: Provider; | ||
@@ -703,7 +724,4 @@ private constructor(); | ||
static getInstance(): OpenFeatureAPI; | ||
setLogger(logger: Logger): this; | ||
addHooks(...hooks: Hook<FlagValue>[]): this; | ||
getHooks(): Hook<FlagValue>[]; | ||
clearHooks(): this; | ||
setContext(context: EvaluationContext): Promise<void>; | ||
getContext(): EvaluationContext; | ||
/** | ||
@@ -728,2 +746,2 @@ * A factory function for creating new named OpenFeature clients. Clients can contain | ||
export { BeforeHookContext, Client, ClientMetadata, CommonProvider, DefaultLogger, ErrorCode, EvaluationContext, EvaluationContextValue, EvaluationDetails, EventDetails, EventHandler, EventMetadata, Eventing, Features, FlagEvaluationOptions, FlagMetadata, FlagNotFoundError, FlagValue, FlagValueType, GeneralError, GlobalApi, Hook, HookContext, HookHints, InvalidContextError, JsonArray, JsonObject, JsonValue, Logger, ManageContext, ManageLogger, ManageTransactionContextPropagator, NOOP_PROVIDER, NOOP_TRANSACTION_CONTEXT_PROPAGATOR, OpenFeature, OpenFeatureAPI, OpenFeatureClient, OpenFeatureCommonAPI, OpenFeatureError, OpenFeatureEventEmitter, ParseError, PrimitiveValue, Provider, ProviderEvents, ProviderMetadata, ProviderStatus, ResolutionDetails, ResolutionReason, SafeLogger, StandardResolutionReasons, TargetingKeyMissingError, TransactionContext, TransactionContextPropagator, TypeMismatchError }; | ||
export { BeforeHookContext, Client, ClientMetadata, CommonProvider, DefaultLogger, ErrorCode, EvaluationContext, EvaluationContextValue, EvaluationDetails, EvaluationLifeCycle, EventDetails, EventHandler, EventMetadata, Eventing, Features, FlagEvaluationOptions, FlagMetadata, FlagNotFoundError, FlagValue, FlagValueType, GeneralError, Hook, HookContext, HookHints, InvalidContextError, JsonArray, JsonObject, JsonValue, LOG_LEVELS, Logger, ManageContext, ManageLogger, ManageTransactionContextPropagator, Metadata, NOOP_PROVIDER, NOOP_TRANSACTION_CONTEXT_PROPAGATOR, OpenFeature, OpenFeatureAPI, OpenFeatureClient, OpenFeatureCommonAPI, OpenFeatureError, OpenFeatureEventEmitter, ParseError, PrimitiveValue, Provider, ProviderEvents, ProviderMetadata, ProviderStatus, ResolutionDetails, ResolutionReason, SafeLogger, StandardResolutionReasons, TargetingKeyMissingError, TransactionContext, TransactionContextPropagator, TypeMismatchError, isObject, isString, objectOrUndefined, stringOrUndefined }; |
{ | ||
"name": "@openfeature/web-sdk", | ||
"version": "0.3.6-experimental", | ||
"version": "0.3.7-experimental", | ||
"description": "OpenFeature SDK for Web", | ||
@@ -5,0 +5,0 @@ "main": "./dist/cjs/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3094
292634