@openfeature/web-sdk
Advanced tools
Comparing version 0.4.8 to 0.4.9
@@ -453,3 +453,4 @@ "use strict"; | ||
OpenFeatureClient: () => OpenFeatureClient, | ||
OpenFeatureEventEmitter: () => OpenFeatureEventEmitter | ||
OpenFeatureEventEmitter: () => OpenFeatureEventEmitter, | ||
ProviderEvents: () => import_core2.ClientProviderEvents | ||
}); | ||
@@ -459,9 +460,26 @@ module.exports = __toCommonJS(src_exports); | ||
// src/client/open-feature-client.ts | ||
var import_core6 = require("@openfeature/core"); | ||
var import_core7 = require("@openfeature/core"); | ||
// src/open-feature.ts | ||
var import_core5 = require("@openfeature/core"); | ||
var import_core6 = require("@openfeature/core"); | ||
// src/events/open-feature-event-emitter.ts | ||
var import_core = require("@openfeature/core"); | ||
var import_events = __toESM(require_events()); | ||
var OpenFeatureEventEmitter = class extends import_core.GenericEventEmitter { | ||
constructor() { | ||
super(); | ||
this.eventEmitter = new import_events.default({ captureRejections: true }); | ||
this.eventEmitter.on("error", (err) => { | ||
var _a; | ||
(_a = this._logger) == null ? void 0 : _a.error("Error running event handler:", err); | ||
}); | ||
} | ||
}; | ||
// src/events/events.ts | ||
var import_core2 = require("@openfeature/core"); | ||
// src/provider/no-op-provider.ts | ||
var import_core = require("@openfeature/core"); | ||
var import_core3 = require("@openfeature/core"); | ||
var REASON_NO_OP = "No-op"; | ||
@@ -475,3 +493,3 @@ var NoopFeatureProvider = class { | ||
get status() { | ||
return import_core.ProviderStatus.NOT_READY; | ||
return import_core3.ProviderStatus.NOT_READY; | ||
} | ||
@@ -500,21 +518,7 @@ resolveBooleanEvaluation(_, defaultValue) { | ||
// src/provider/in-memory-provider/in-memory-provider.ts | ||
var import_core4 = require("@openfeature/core"); | ||
var import_core5 = require("@openfeature/core"); | ||
// src/events/open-feature-event-emitter.ts | ||
var import_core2 = require("@openfeature/core"); | ||
var import_events = __toESM(require_events()); | ||
var OpenFeatureEventEmitter = class extends import_core2.GenericEventEmitter { | ||
constructor() { | ||
super(); | ||
this.eventEmitter = new import_events.default({ captureRejections: true }); | ||
this.eventEmitter.on("error", (err) => { | ||
var _a; | ||
(_a = this._logger) == null ? void 0 : _a.error("Error running event handler:", err); | ||
}); | ||
} | ||
}; | ||
// src/provider/in-memory-provider/variant-not-found-error.ts | ||
var import_core3 = require("@openfeature/core"); | ||
var VariantNotFoundError = class extends import_core3.OpenFeatureError { | ||
var import_core4 = require("@openfeature/core"); | ||
var VariantNotFoundError = class extends import_core4.OpenFeatureError { | ||
constructor(message) { | ||
@@ -524,3 +528,3 @@ super(message); | ||
this.name = "VariantNotFoundError"; | ||
this.code = import_core3.ErrorCode.GENERAL; | ||
this.code = import_core4.ErrorCode.GENERAL; | ||
} | ||
@@ -534,3 +538,3 @@ }; | ||
this.runsOn = "client"; | ||
this.status = import_core4.ProviderStatus.NOT_READY; | ||
this.status = import_core5.ProviderStatus.NOT_READY; | ||
this.metadata = { | ||
@@ -548,5 +552,5 @@ name: "in-memory" | ||
this._context = context; | ||
this.status = import_core4.ProviderStatus.READY; | ||
this.status = import_core5.ProviderStatus.READY; | ||
} catch (error) { | ||
this.status = import_core4.ProviderStatus.ERROR; | ||
this.status = import_core5.ProviderStatus.ERROR; | ||
throw error; | ||
@@ -563,11 +567,11 @@ } | ||
const flagsChanged = Object.entries(flagConfiguration).filter(([key, value]) => this._flagConfiguration[key] !== value).map(([key]) => key); | ||
this.status = import_core4.ProviderStatus.STALE; | ||
this.events.emit(import_core4.ProviderEvents.Stale); | ||
this.status = import_core5.ProviderStatus.STALE; | ||
this.events.emit(import_core2.ClientProviderEvents.Stale); | ||
this._flagConfiguration = __spreadValues({}, flagConfiguration); | ||
this.events.emit(import_core4.ProviderEvents.ConfigurationChanged, { flagsChanged }); | ||
this.events.emit(import_core2.ClientProviderEvents.ConfigurationChanged, { flagsChanged }); | ||
try { | ||
yield this.initialize(this._context); | ||
this.events.emit(import_core4.ProviderEvents.Ready); | ||
this.events.emit(import_core2.ClientProviderEvents.Ready); | ||
} catch (err) { | ||
this.events.emit(import_core4.ProviderEvents.Error); | ||
this.events.emit(import_core2.ClientProviderEvents.Error); | ||
throw err; | ||
@@ -593,6 +597,6 @@ } | ||
logger == null ? void 0 : logger.debug(message); | ||
throw new import_core4.FlagNotFoundError(message); | ||
throw new import_core5.FlagNotFoundError(message); | ||
} | ||
if (this._flagConfiguration[flagKey].disabled) { | ||
return { value: defaultValue, reason: import_core4.StandardResolutionReasons.DISABLED }; | ||
return { value: defaultValue, reason: import_core5.StandardResolutionReasons.DISABLED }; | ||
} | ||
@@ -606,3 +610,3 @@ const resolvedFlag = this.resolveFlagWithReason(flagKey, context); | ||
if (typeof resolvedFlag.value != typeof defaultValue) { | ||
throw new import_core4.TypeMismatchError(); | ||
throw new import_core5.TypeMismatchError(); | ||
} | ||
@@ -616,4 +620,4 @@ return resolvedFlag; | ||
} catch (error) { | ||
if (!(error instanceof import_core4.OpenFeatureError)) { | ||
throw new import_core4.GeneralError((error == null ? void 0 : error.message) || "unknown error"); | ||
if (!(error instanceof import_core5.OpenFeatureError)) { | ||
throw new import_core5.GeneralError((error == null ? void 0 : error.message) || "unknown error"); | ||
} | ||
@@ -629,4 +633,4 @@ throw error; | ||
const value = variant && (flagSpec == null ? void 0 : flagSpec.variants[variant]); | ||
const evalReason = isContextEval ? import_core4.StandardResolutionReasons.TARGETING_MATCH : import_core4.StandardResolutionReasons.STATIC; | ||
const reason = this.status === import_core4.ProviderStatus.STALE ? import_core4.StandardResolutionReasons.CACHED : evalReason; | ||
const evalReason = isContextEval ? import_core5.StandardResolutionReasons.TARGETING_MATCH : import_core5.StandardResolutionReasons.STATIC; | ||
const reason = this.status === import_core5.ProviderStatus.STALE ? import_core5.StandardResolutionReasons.CACHED : evalReason; | ||
return __spreadProps(__spreadValues({ | ||
@@ -643,3 +647,3 @@ value | ||
var _globalThis = globalThis; | ||
var OpenFeatureAPI = class extends import_core5.OpenFeatureCommonAPI { | ||
var OpenFeatureAPI = class extends import_core6.OpenFeatureCommonAPI { | ||
constructor() { | ||
@@ -669,4 +673,4 @@ super("client"); | ||
var _a, _b; | ||
const clientName = (0, import_core5.stringOrUndefined)(nameOrContext); | ||
const context = (_b = (_a = (0, import_core5.objectOrUndefined)(nameOrContext)) != null ? _a : (0, import_core5.objectOrUndefined)(contextOrUndefined)) != null ? _b : {}; | ||
const clientName = (0, import_core6.stringOrUndefined)(nameOrContext); | ||
const context = (_b = (_a = (0, import_core6.objectOrUndefined)(nameOrContext)) != null ? _a : (0, import_core6.objectOrUndefined)(contextOrUndefined)) != null ? _b : {}; | ||
if (clientName) { | ||
@@ -677,3 +681,3 @@ const provider = this._clientProviders.get(clientName); | ||
this._namedProviderContext.set(clientName, context); | ||
yield this.runProviderContextChangeHandler(provider, oldContext, context); | ||
yield this.runProviderContextChangeHandler(clientName, provider, oldContext, context); | ||
} else { | ||
@@ -691,3 +695,3 @@ this._namedProviderContext.set(clientName, context); | ||
yield Promise.all( | ||
allProviders.map((provider) => this.runProviderContextChangeHandler(provider, oldContext, context)) | ||
allProviders.map((provider) => this.runProviderContextChangeHandler(void 0, provider, oldContext, context)) | ||
); | ||
@@ -698,3 +702,3 @@ } | ||
getContext(nameOrUndefined) { | ||
const clientName = (0, import_core5.stringOrUndefined)(nameOrUndefined); | ||
const clientName = (0, import_core6.stringOrUndefined)(nameOrUndefined); | ||
if (clientName) { | ||
@@ -712,3 +716,3 @@ const context = this._namedProviderContext.get(clientName); | ||
return __async(this, null, function* () { | ||
const clientName = (0, import_core5.stringOrUndefined)(nameOrUndefined); | ||
const clientName = (0, import_core6.stringOrUndefined)(nameOrUndefined); | ||
if (clientName) { | ||
@@ -720,3 +724,3 @@ const provider = this._clientProviders.get(clientName); | ||
const newContext = this.getContext(); | ||
yield this.runProviderContextChangeHandler(provider, oldContext, newContext); | ||
yield this.runProviderContextChangeHandler(clientName, provider, oldContext, newContext); | ||
} else { | ||
@@ -771,10 +775,20 @@ this._namedProviderContext.delete(clientName); | ||
} | ||
runProviderContextChangeHandler(provider, oldContext, newContext) { | ||
runProviderContextChangeHandler(clientName, provider, oldContext, newContext) { | ||
return __async(this, null, function* () { | ||
var _a, _b; | ||
try { | ||
return yield (_a = provider.onContextChange) == null ? void 0 : _a.call(provider, oldContext, newContext); | ||
} catch (err) { | ||
(_b = this._logger) == null ? void 0 : _b.error(`Error running ${provider.metadata.name}'s context change handler:`, err); | ||
} | ||
var _a; | ||
const providerName = provider.metadata.name; | ||
return (_a = provider.onContextChange) == null ? void 0 : _a.call(provider, oldContext, newContext).then(() => { | ||
var _a2; | ||
this.getAssociatedEventEmitters(clientName).forEach((emitter) => { | ||
emitter == null ? void 0 : emitter.emit(import_core2.ClientProviderEvents.ContextChanged, { clientName, providerName }); | ||
}); | ||
(_a2 = this._events) == null ? void 0 : _a2.emit(import_core2.ClientProviderEvents.ContextChanged, { clientName, providerName }); | ||
}).catch((err) => { | ||
var _a2, _b; | ||
(_a2 = this._logger) == null ? void 0 : _a2.error(`Error running ${provider.metadata.name}'s context change handler:`, err); | ||
this.getAssociatedEventEmitters(clientName).forEach((emitter) => { | ||
emitter == null ? void 0 : emitter.emit(import_core2.ClientProviderEvents.Error, { clientName, providerName, message: err == null ? void 0 : err.message }); | ||
}); | ||
(_b = this._events) == null ? void 0 : _b.emit(import_core2.ClientProviderEvents.Error, { clientName, providerName, message: err == null ? void 0 : err.message }); | ||
}); | ||
}); | ||
@@ -803,3 +817,3 @@ } | ||
var _a; | ||
return ((_a = this.providerAccessor()) == null ? void 0 : _a.status) || import_core6.ProviderStatus.READY; | ||
return ((_a = this.providerAccessor()) == null ? void 0 : _a.status) || import_core7.ProviderStatus.READY; | ||
} | ||
@@ -809,3 +823,3 @@ addHandler(eventType, handler) { | ||
this.emitterAccessor().addHandler(eventType, handler); | ||
const shouldRunNow = (0, import_core6.statusMatchesEvent)(eventType, this._provider.status); | ||
const shouldRunNow = (0, import_core7.statusMatchesEvent)(eventType, this._provider.status); | ||
if (shouldRunNow) { | ||
@@ -826,3 +840,3 @@ try { | ||
setLogger(logger) { | ||
this._clientLogger = new import_core6.SafeLogger(logger); | ||
this._clientLogger = new import_core7.SafeLogger(logger); | ||
return this; | ||
@@ -909,3 +923,3 @@ } | ||
const errorMessage = err == null ? void 0 : err.message; | ||
const errorCode = (err == null ? void 0 : err.code) || import_core6.ErrorCode.GENERAL; | ||
const errorCode = (err == null ? void 0 : err.code) || import_core7.ErrorCode.GENERAL; | ||
this.errorHooks(allHooksReversed, hookContext, err, options); | ||
@@ -916,3 +930,3 @@ return { | ||
value: defaultValue, | ||
reason: import_core6.StandardResolutionReasons.ERROR, | ||
reason: import_core7.StandardResolutionReasons.ERROR, | ||
flagMetadata: Object.freeze({}), | ||
@@ -919,0 +933,0 @@ flagKey |
@@ -454,2 +454,19 @@ var __create = Object.create; | ||
// src/events/open-feature-event-emitter.ts | ||
var import_events = __toESM(require_events()); | ||
import { GenericEventEmitter } from "@openfeature/core"; | ||
var OpenFeatureEventEmitter = class extends GenericEventEmitter { | ||
constructor() { | ||
super(); | ||
this.eventEmitter = new import_events.default({ captureRejections: true }); | ||
this.eventEmitter.on("error", (err) => { | ||
var _a; | ||
(_a = this._logger) == null ? void 0 : _a.error("Error running event handler:", err); | ||
}); | ||
} | ||
}; | ||
// src/events/events.ts | ||
import { ClientProviderEvents } from "@openfeature/core"; | ||
// src/provider/no-op-provider.ts | ||
@@ -493,3 +510,2 @@ import { ProviderStatus } from "@openfeature/core"; | ||
OpenFeatureError as OpenFeatureError2, | ||
ProviderEvents, | ||
StandardResolutionReasons, | ||
@@ -500,16 +516,2 @@ TypeMismatchError, | ||
// src/events/open-feature-event-emitter.ts | ||
var import_events = __toESM(require_events()); | ||
import { GenericEventEmitter } from "@openfeature/core"; | ||
var OpenFeatureEventEmitter = class extends GenericEventEmitter { | ||
constructor() { | ||
super(); | ||
this.eventEmitter = new import_events.default({ captureRejections: true }); | ||
this.eventEmitter.on("error", (err) => { | ||
var _a; | ||
(_a = this._logger) == null ? void 0 : _a.error("Error running event handler:", err); | ||
}); | ||
} | ||
}; | ||
// src/provider/in-memory-provider/variant-not-found-error.ts | ||
@@ -559,10 +561,10 @@ import { ErrorCode, OpenFeatureError } from "@openfeature/core"; | ||
this.status = ProviderStatus2.STALE; | ||
this.events.emit(ProviderEvents.Stale); | ||
this.events.emit(ClientProviderEvents.Stale); | ||
this._flagConfiguration = __spreadValues({}, flagConfiguration); | ||
this.events.emit(ProviderEvents.ConfigurationChanged, { flagsChanged }); | ||
this.events.emit(ClientProviderEvents.ConfigurationChanged, { flagsChanged }); | ||
try { | ||
yield this.initialize(this._context); | ||
this.events.emit(ProviderEvents.Ready); | ||
this.events.emit(ClientProviderEvents.Ready); | ||
} catch (err) { | ||
this.events.emit(ProviderEvents.Error); | ||
this.events.emit(ClientProviderEvents.Error); | ||
throw err; | ||
@@ -666,3 +668,3 @@ } | ||
this._namedProviderContext.set(clientName, context); | ||
yield this.runProviderContextChangeHandler(provider, oldContext, context); | ||
yield this.runProviderContextChangeHandler(clientName, provider, oldContext, context); | ||
} else { | ||
@@ -680,3 +682,3 @@ this._namedProviderContext.set(clientName, context); | ||
yield Promise.all( | ||
allProviders.map((provider) => this.runProviderContextChangeHandler(provider, oldContext, context)) | ||
allProviders.map((provider) => this.runProviderContextChangeHandler(void 0, provider, oldContext, context)) | ||
); | ||
@@ -707,3 +709,3 @@ } | ||
const newContext = this.getContext(); | ||
yield this.runProviderContextChangeHandler(provider, oldContext, newContext); | ||
yield this.runProviderContextChangeHandler(clientName, provider, oldContext, newContext); | ||
} else { | ||
@@ -758,10 +760,20 @@ this._namedProviderContext.delete(clientName); | ||
} | ||
runProviderContextChangeHandler(provider, oldContext, newContext) { | ||
runProviderContextChangeHandler(clientName, provider, oldContext, newContext) { | ||
return __async(this, null, function* () { | ||
var _a, _b; | ||
try { | ||
return yield (_a = provider.onContextChange) == null ? void 0 : _a.call(provider, oldContext, newContext); | ||
} catch (err) { | ||
(_b = this._logger) == null ? void 0 : _b.error(`Error running ${provider.metadata.name}'s context change handler:`, err); | ||
} | ||
var _a; | ||
const providerName = provider.metadata.name; | ||
return (_a = provider.onContextChange) == null ? void 0 : _a.call(provider, oldContext, newContext).then(() => { | ||
var _a2; | ||
this.getAssociatedEventEmitters(clientName).forEach((emitter) => { | ||
emitter == null ? void 0 : emitter.emit(ClientProviderEvents.ContextChanged, { clientName, providerName }); | ||
}); | ||
(_a2 = this._events) == null ? void 0 : _a2.emit(ClientProviderEvents.ContextChanged, { clientName, providerName }); | ||
}).catch((err) => { | ||
var _a2, _b; | ||
(_a2 = this._logger) == null ? void 0 : _a2.error(`Error running ${provider.metadata.name}'s context change handler:`, err); | ||
this.getAssociatedEventEmitters(clientName).forEach((emitter) => { | ||
emitter == null ? void 0 : emitter.emit(ClientProviderEvents.Error, { clientName, providerName, message: err == null ? void 0 : err.message }); | ||
}); | ||
(_b = this._events) == null ? void 0 : _b.emit(ClientProviderEvents.Error, { clientName, providerName, message: err == null ? void 0 : err.message }); | ||
}); | ||
}); | ||
@@ -965,4 +977,5 @@ } | ||
OpenFeatureClient, | ||
OpenFeatureEventEmitter | ||
OpenFeatureEventEmitter, | ||
ClientProviderEvents as ProviderEvents | ||
}; | ||
//# sourceMappingURL=index.js.map |
@@ -133,3 +133,6 @@ import EventEmitter from 'events'; | ||
declare enum ProviderEvents { | ||
/** | ||
* An enumeration of possible events for server-sdk providers. | ||
*/ | ||
declare enum ServerProviderEvents { | ||
/** | ||
@@ -152,11 +155,42 @@ * The provider is ready to evaluate flags. | ||
} | ||
/** | ||
* An enumeration of possible events for web-sdk providers. | ||
*/ | ||
declare enum ClientProviderEvents { | ||
/** | ||
* 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 context associated with the provider has changed, and the provider has reconciled it's associated state. | ||
*/ | ||
ContextChanged = "PROVIDER_CONTEXT_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" | ||
} | ||
/** | ||
* A type representing any possible ProviderEvent (server or client side). | ||
* If you are implementing a hook or provider, you probably want to import `ProviderEvents` from the respective SDK. | ||
*/ | ||
type AnyProviderEvent = ServerProviderEvents | ClientProviderEvents; | ||
/** | ||
* Returns true if the provider's status corresponds to the event. | ||
* If the provider's status is not defined, it matches READY. | ||
* @param {ProviderEvents} event event to match | ||
* @param {AnyProviderEvent} event event to match | ||
* @param {ProviderStatus} status status of provider | ||
* @returns {boolean} boolean indicating if the provider status corresponds to the event. | ||
*/ | ||
declare const statusMatchesEvent: (event: ProviderEvents, status?: ProviderStatus) => boolean; | ||
declare const statusMatchesEvent: <T extends AnyProviderEvent>(event: T, status?: ProviderStatus) => boolean; | ||
@@ -181,10 +215,11 @@ type EventMetadata = { | ||
type EventMap = { | ||
[ProviderEvents.Ready]: ReadyEvent; | ||
[ProviderEvents.Error]: ErrorEvent; | ||
[ProviderEvents.Stale]: StaleEvent; | ||
[ProviderEvents.ConfigurationChanged]: ConfigChangeEvent; | ||
[ClientProviderEvents.Ready]: ReadyEvent; | ||
[ClientProviderEvents.Error]: ErrorEvent; | ||
[ClientProviderEvents.Stale]: StaleEvent; | ||
[ClientProviderEvents.ContextChanged]: CommonEventProps; | ||
[ClientProviderEvents.ConfigurationChanged]: ConfigChangeEvent; | ||
}; | ||
type EventContext<T extends ProviderEvents, U extends Record<string, unknown> = Record<string, unknown>> = EventMap[T] & U; | ||
type EventDetails<T extends ProviderEvents> = EventContext<T> & CommonEventDetails; | ||
type EventHandler<T extends ProviderEvents> = (eventDetails?: EventDetails<T>) => Promise<unknown> | unknown; | ||
type EventContext<U extends Record<string, unknown> = Record<string, unknown>> = EventMap[ClientProviderEvents] & U; | ||
type EventDetails = EventContext & CommonEventDetails; | ||
type EventHandler = (eventDetails?: EventDetails) => Promise<unknown> | unknown; | ||
interface Eventing { | ||
@@ -194,18 +229,18 @@ /** | ||
* The handlers are called in the order they have been added. | ||
* @param {ProviderEvents} eventType The provider event type to listen to | ||
* @param {AnyProviderEvent} eventType The provider event type to listen to | ||
* @param {EventHandler} handler The handler to run on occurrence of the event type | ||
*/ | ||
addHandler<T extends ProviderEvents>(eventType: T, handler: EventHandler<T>): void; | ||
addHandler(eventType: AnyProviderEvent, handler: EventHandler): void; | ||
/** | ||
* Removes a handler for the given provider event type. | ||
* @param {ProviderEvents} eventType The provider event type to remove the listener for | ||
* @param {AnyProviderEvent} eventType The provider event type to remove the listener for | ||
* @param {EventHandler} handler The handler to remove for the provider event type | ||
*/ | ||
removeHandler<T extends ProviderEvents>(eventType: T, handler: EventHandler<T>): void; | ||
removeHandler(eventType: AnyProviderEvent, handler: EventHandler): void; | ||
/** | ||
* Gets the current handlers for the given provider event type. | ||
* @param {ProviderEvents} eventType The provider event type to get the current handlers for | ||
* @param {AnyProviderEvent} eventType The provider event type to get the current handlers for | ||
* @returns {EventHandler[]} The handlers currently attached to the given provider event type | ||
*/ | ||
getHandlers<T extends ProviderEvents>(eventType: T): EventHandler<T>[]; | ||
getHandlers(eventType: AnyProviderEvent): EventHandler[]; | ||
} | ||
@@ -255,3 +290,3 @@ | ||
*/ | ||
declare abstract class GenericEventEmitter<AdditionalContext extends Record<string, unknown> = Record<string, unknown>> implements ManageLogger<GenericEventEmitter<AdditionalContext>> { | ||
declare abstract class GenericEventEmitter<E extends AnyProviderEvent, AdditionalContext extends Record<string, unknown> = Record<string, unknown>> implements ManageLogger<GenericEventEmitter<E, AdditionalContext>> { | ||
private readonly globalLogger?; | ||
@@ -262,7 +297,7 @@ protected abstract readonly eventEmitter: PlatformEventEmitter; | ||
constructor(globalLogger?: (() => Logger) | undefined); | ||
emit<T extends ProviderEvents>(eventType: T, context?: EventContext<T, AdditionalContext>): void; | ||
addHandler<T extends ProviderEvents>(eventType: T, handler: EventHandler<T>): void; | ||
removeHandler<T extends ProviderEvents>(eventType: T, handler: EventHandler<T>): void; | ||
removeAllHandlers(eventType?: ProviderEvents): void; | ||
getHandlers<T extends ProviderEvents>(eventType: T): EventHandler<T>[]; | ||
emit(eventType: E, context?: EventContext): void; | ||
addHandler(eventType: AnyProviderEvent, handler: EventHandler): void; | ||
removeHandler(eventType: AnyProviderEvent, handler: EventHandler): void; | ||
removeAllHandlers(eventType?: AnyProviderEvent): void; | ||
getHandlers(eventType: AnyProviderEvent): EventHandler[]; | ||
setLogger(logger: Logger): this; | ||
@@ -350,3 +385,3 @@ protected get _logger(): Logger | undefined; | ||
*/ | ||
events?: GenericEventEmitter; | ||
events?: GenericEventEmitter<AnyProviderEvent>; | ||
/** | ||
@@ -510,5 +545,5 @@ * A function used to shut down the provider. | ||
declare abstract class OpenFeatureCommonAPI<P extends CommonProvider = CommonProvider, H extends BaseHook = BaseHook> implements Eventing, EvaluationLifeCycle<OpenFeatureCommonAPI<P>>, ManageLogger<OpenFeatureCommonAPI<P>> { | ||
protected abstract _createEventEmitter(): GenericEventEmitter; | ||
protected abstract _createEventEmitter(): GenericEventEmitter<AnyProviderEvent>; | ||
protected abstract _defaultProvider: P; | ||
protected abstract readonly _events: GenericEventEmitter; | ||
protected abstract readonly _events: GenericEventEmitter<AnyProviderEvent>; | ||
protected _hooks: H[]; | ||
@@ -519,3 +554,3 @@ protected _context: EvaluationContext; | ||
protected _clientProviders: Map<string, P>; | ||
protected _clientEvents: Map<string | undefined, GenericEventEmitter>; | ||
protected _clientEvents: Map<string | undefined, GenericEventEmitter<AnyProviderEvent>>; | ||
protected _runsOn: Paradigm; | ||
@@ -528,3 +563,3 @@ constructor(category: Paradigm); | ||
/** | ||
* Get metadata about registered provider. | ||
* Get metadata about the default provider. | ||
* @returns {ProviderMetadata} Provider Metadata | ||
@@ -534,21 +569,28 @@ */ | ||
/** | ||
* Get metadata about a registered provider using the client name. | ||
* An unbound or empty client name will return metadata from the default provider. | ||
* @param {string} [clientName] The name to identify the client | ||
* @returns {ProviderMetadata} Provider Metadata | ||
*/ | ||
getProviderMetadata(clientName?: string): ProviderMetadata; | ||
/** | ||
* Adds a handler for the given provider event type. | ||
* The handlers are called in the order they have been added. | ||
* API (global) events run for all providers. | ||
* @param {ProviderEvents} eventType The provider event type to listen to | ||
* @param {AnyProviderEvent} eventType The provider event type to listen to | ||
* @param {EventHandler} handler The handler to run on occurrence of the event type | ||
*/ | ||
addHandler<T extends ProviderEvents>(eventType: T, handler: EventHandler<T>): void; | ||
addHandler<T extends AnyProviderEvent>(eventType: T, handler: EventHandler): void; | ||
/** | ||
* Removes a handler for the given provider event type. | ||
* @param {ProviderEvents} eventType The provider event type to remove the listener for | ||
* @param {AnyProviderEvent} eventType The provider event type to remove the listener for | ||
* @param {EventHandler} handler The handler to remove for the provider event type | ||
*/ | ||
removeHandler<T extends ProviderEvents>(eventType: T, handler: EventHandler<T>): void; | ||
removeHandler<T extends AnyProviderEvent>(eventType: T, handler: EventHandler): void; | ||
/** | ||
* Gets the current handlers for the given provider event type. | ||
* @param {ProviderEvents} eventType The provider event type to get the current handlers for | ||
* @param {AnyProviderEvent} eventType The provider event type to get the current handlers for | ||
* @returns {EventHandler[]} The handlers currently attached to the given provider event type | ||
*/ | ||
getHandlers<T extends ProviderEvents>(eventType: T): EventHandler<T>[]; | ||
getHandlers<T extends AnyProviderEvent>(eventType: T): EventHandler[]; | ||
/** | ||
@@ -595,5 +637,5 @@ * Sets the default provider for flag evaluations and returns a promise that resolves when the provider is ready. | ||
protected getProviderForClient(name?: string): P; | ||
protected buildAndCacheEventEmitterForClient(name?: string): GenericEventEmitter; | ||
protected buildAndCacheEventEmitterForClient(name?: string): GenericEventEmitter<AnyProviderEvent>; | ||
private getUnboundEmitters; | ||
private getAssociatedEventEmitters; | ||
protected getAssociatedEventEmitters(clientName: string | undefined): GenericEventEmitter<AnyProviderEvent, Record<string, unknown>>[]; | ||
private transferListeners; | ||
@@ -697,2 +739,19 @@ close(): Promise<void>; | ||
/** | ||
* A subset of events that can be directly emitted by providers. | ||
*/ | ||
type ProviderEmittableEvents = Exclude<ClientProviderEvents, ClientProviderEvents.ContextChanged>; | ||
/** | ||
* The OpenFeatureEventEmitter can be used by provider developers to emit | ||
* events at various parts of the provider lifecycle. | ||
* | ||
* NOTE: Ready and error events are automatically emitted by the SDK based on | ||
* the result of the initialize method. | ||
*/ | ||
declare class OpenFeatureEventEmitter extends GenericEventEmitter<ProviderEmittableEvents> { | ||
protected readonly eventEmitter: EventEmitter; | ||
constructor(); | ||
} | ||
/** | ||
* The InternalEventEmitter is not exported publicly and should only be used within the SDK. It extends the | ||
@@ -702,3 +761,3 @@ * OpenFeatureEventEmitter to include additional properties that can be included | ||
*/ | ||
declare abstract class InternalEventEmitter extends GenericEventEmitter<CommonEventDetails> { | ||
declare abstract class InternalEventEmitter extends GenericEventEmitter<ClientProviderEvents, CommonEventDetails> { | ||
} | ||
@@ -764,14 +823,2 @@ | ||
/** | ||
* The OpenFeatureEventEmitter can be used by provider developers to emit | ||
* events at various parts of the provider lifecycle. | ||
* | ||
* NOTE: Ready and error events are automatically emitted by the SDK based on | ||
* the result of the initialize method. | ||
*/ | ||
declare class OpenFeatureEventEmitter extends GenericEventEmitter { | ||
protected readonly eventEmitter: EventEmitter; | ||
constructor(); | ||
} | ||
/** | ||
* Don't export types from this file publicly. | ||
@@ -852,5 +899,5 @@ * It might cause confusion since these types are not a part of the general API, | ||
get providerStatus(): ProviderStatus; | ||
addHandler<T extends ProviderEvents>(eventType: T, handler: EventHandler<T>): void; | ||
removeHandler<T extends ProviderEvents>(notificationType: T, handler: EventHandler<T>): void; | ||
getHandlers(eventType: ProviderEvents): EventHandler<ProviderEvents>[]; | ||
addHandler(eventType: ClientProviderEvents, handler: EventHandler): void; | ||
removeHandler(notificationType: ClientProviderEvents, handler: EventHandler): void; | ||
getHandlers(eventType: ClientProviderEvents): EventHandler[]; | ||
setLogger(logger: Logger): this; | ||
@@ -878,3 +925,3 @@ addHooks(...hooks: Hook[]): this; | ||
declare class OpenFeatureAPI extends OpenFeatureCommonAPI<Provider, Hook> implements ManageContext<Promise<void>> { | ||
protected _events: OpenFeatureEventEmitter; | ||
protected _events: GenericEventEmitter<ClientProviderEvents>; | ||
protected _defaultProvider: Provider; | ||
@@ -960,2 +1007,2 @@ protected _createEventEmitter: () => OpenFeatureEventEmitter; | ||
export { BaseHook, 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, InMemoryProvider, InvalidContextError, JsonArray, JsonObject, JsonValue, LOG_LEVELS, Logger, ManageContext, ManageLogger, Metadata, NOOP_PROVIDER, OpenFeature, OpenFeatureAPI, OpenFeatureClient, OpenFeatureCommonAPI, OpenFeatureError, OpenFeatureEventEmitter, Paradigm, ParseError, PrimitiveValue, Provider, ProviderEvents, ProviderMetadata, ProviderNotReadyError, ProviderStatus, ReadyEvent, ResolutionDetails, ResolutionReason, SafeLogger, StaleEvent, StandardResolutionReasons, TargetingKeyMissingError, TypeMismatchError, isObject, isString, objectOrUndefined, statusMatchesEvent, stringOrUndefined }; | ||
export { ClientProviderEvents as AllProviderEvents, AnyProviderEvent, BaseHook, BeforeHookContext, Client, ClientMetadata, ClientProviderEvents, CommonEventDetails, CommonProvider, ConfigChangeEvent, DefaultLogger, ErrorCode, ErrorEvent, EvaluationContext, EvaluationContextValue, EvaluationDetails, EvaluationLifeCycle, EventContext, EventDetails, EventHandler, EventMetadata, Eventing, Features, FlagEvaluationOptions, FlagMetadata, FlagNotFoundError, FlagValue, FlagValueType, GeneralError, GenericEventEmitter, Hook, HookContext, HookHints, InMemoryProvider, InvalidContextError, JsonArray, JsonObject, JsonValue, LOG_LEVELS, Logger, ManageContext, ManageLogger, Metadata, NOOP_PROVIDER, OpenFeature, OpenFeatureAPI, OpenFeatureClient, OpenFeatureCommonAPI, OpenFeatureError, OpenFeatureEventEmitter, Paradigm, ParseError, PrimitiveValue, Provider, ProviderEmittableEvents, ClientProviderEvents as ProviderEvents, ProviderMetadata, ProviderNotReadyError, ProviderStatus, ReadyEvent, ResolutionDetails, ResolutionReason, SafeLogger, ServerProviderEvents, StaleEvent, StandardResolutionReasons, TargetingKeyMissingError, TypeMismatchError, isObject, isString, objectOrUndefined, statusMatchesEvent, stringOrUndefined }; |
{ | ||
"name": "@openfeature/web-sdk", | ||
"version": "0.4.8", | ||
"version": "0.4.9", | ||
"description": "OpenFeature SDK for Web", | ||
@@ -49,7 +49,7 @@ "main": "./dist/cjs/index.js", | ||
"peerDependencies": { | ||
"@openfeature/core": "0.0.20" | ||
"@openfeature/core": "0.0.22" | ||
}, | ||
"devDependencies": { | ||
"@openfeature/core": "0.0.20" | ||
"@openfeature/core": "0.0.22" | ||
} | ||
} |
@@ -19,4 +19,4 @@ <!-- markdownlint-disable MD033 --> | ||
<!-- x-release-please-start-version --> | ||
<a href="https://github.com/open-feature/js-sdk/releases/tag/web-sdk-v0.4.8"> | ||
<img alt="Release" src="https://img.shields.io/static/v1?label=release&message=v0.4.8&color=blue&style=for-the-badge" /> | ||
<a href="https://github.com/open-feature/js-sdk/releases/tag/web-sdk-v0.4.9"> | ||
<img alt="Release" src="https://img.shields.io/static/v1?label=release&message=v0.4.9&color=blue&style=for-the-badge" /> | ||
</a> | ||
@@ -23,0 +23,0 @@ <!-- x-release-please-end --> |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
266242
2866