@openfeature/server-sdk
Advanced tools
Comparing version 1.7.1 to 1.7.2
"use strict"; | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
@@ -8,2 +9,3 @@ var __defProps = Object.defineProperties; | ||
var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
@@ -37,2 +39,10 @@ var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default")); | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
// If the importer is in node compatibility mode or this is not an ESM | ||
// file that has been converted to a CommonJS file using a Babel- | ||
// compatible transform (i.e. "__esModule" has not been set), then set | ||
// "default" to the CommonJS "module.exports" for node compatibility. | ||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
mod | ||
)); | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
@@ -68,3 +78,4 @@ var __async = (__this, __arguments, generator) => { | ||
OpenFeatureAPI: () => OpenFeatureAPI, | ||
OpenFeatureClient: () => OpenFeatureClient | ||
OpenFeatureClient: () => OpenFeatureClient, | ||
OpenFeatureEventEmitter: () => OpenFeatureEventEmitter | ||
}); | ||
@@ -74,3 +85,3 @@ module.exports = __toCommonJS(src_exports); | ||
// src/client/open-feature-client.ts | ||
var import_core5 = require("@openfeature/core"); | ||
var import_core6 = require("@openfeature/core"); | ||
@@ -127,3 +138,3 @@ // src/provider/no-op-provider.ts | ||
constructor(flagConfiguration = {}) { | ||
this.events = new import_core3.OpenFeatureEventEmitter(); | ||
this.events = new OpenFeatureEventEmitter(); | ||
this.runsOn = "server"; | ||
@@ -204,3 +215,3 @@ this.metadata = { | ||
// src/open-feature.ts | ||
var import_core4 = require("@openfeature/core"); | ||
var import_core5 = require("@openfeature/core"); | ||
@@ -218,10 +229,26 @@ // src/transaction-context/no-op-transaction-context-propagator.ts | ||
// src/events/open-feature-event-emitter.ts | ||
var import_core4 = require("@openfeature/core"); | ||
var import_events = __toESM(require("events")); | ||
var OpenFeatureEventEmitter = class extends import_core4.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/open-feature.ts | ||
var GLOBAL_OPENFEATURE_API_KEY = Symbol.for("@openfeature/js-sdk/api"); | ||
var _globalThis = globalThis; | ||
var OpenFeatureAPI = class extends import_core4.OpenFeatureCommonAPI { | ||
var OpenFeatureAPI = class extends import_core5.OpenFeatureCommonAPI { | ||
constructor() { | ||
super("server"); | ||
this._events = new OpenFeatureEventEmitter(); | ||
this._defaultProvider = NOOP_PROVIDER; | ||
this._createEventEmitter = () => new OpenFeatureEventEmitter(); | ||
this._transactionContextPropagator = NOOP_TRANSACTION_CONTEXT_PROPAGATOR; | ||
this._defaultProvider = NOOP_PROVIDER; | ||
} | ||
@@ -251,5 +278,5 @@ /** | ||
var _a, _b; | ||
const name = (0, import_core4.stringOrUndefined)(nameOrContext); | ||
const version = (0, import_core4.stringOrUndefined)(versionOrContext); | ||
const context = (_b = (_a = (0, import_core4.objectOrUndefined)(nameOrContext)) != null ? _a : (0, import_core4.objectOrUndefined)(versionOrContext)) != null ? _b : (0, import_core4.objectOrUndefined)(contextOrUndefined); | ||
const name = (0, import_core5.stringOrUndefined)(nameOrContext); | ||
const version = (0, import_core5.stringOrUndefined)(versionOrContext); | ||
const context = (_b = (_a = (0, import_core5.objectOrUndefined)(nameOrContext)) != null ? _a : (0, import_core5.objectOrUndefined)(versionOrContext)) != null ? _b : (0, import_core5.objectOrUndefined)(contextOrUndefined); | ||
return new OpenFeatureClient( | ||
@@ -317,3 +344,3 @@ () => this.getProviderForClient(name), | ||
this.emitterAccessor().addHandler(eventType, handler); | ||
const shouldRunNow = (0, import_core5.statusMatchesEvent)(eventType, this._provider.status); | ||
const shouldRunNow = (0, import_core6.statusMatchesEvent)(eventType, this._provider.status); | ||
if (shouldRunNow) { | ||
@@ -334,3 +361,3 @@ try { | ||
setLogger(logger) { | ||
this._clientLogger = new import_core5.SafeLogger(logger); | ||
this._clientLogger = new import_core6.SafeLogger(logger); | ||
return this; | ||
@@ -442,3 +469,3 @@ } | ||
const errorMessage = err == null ? void 0 : err.message; | ||
const errorCode = (err == null ? void 0 : err.code) || import_core5.ErrorCode.GENERAL; | ||
const errorCode = (err == null ? void 0 : err.code) || import_core6.ErrorCode.GENERAL; | ||
yield this.errorHooks(allHooksReversed, hookContext, err, options); | ||
@@ -449,3 +476,3 @@ return { | ||
value: defaultValue, | ||
reason: import_core5.StandardResolutionReasons.ERROR, | ||
reason: import_core6.StandardResolutionReasons.ERROR, | ||
flagMetadata: Object.freeze({}), | ||
@@ -526,4 +553,5 @@ flagKey | ||
OpenFeatureAPI, | ||
OpenFeatureClient | ||
OpenFeatureClient, | ||
OpenFeatureEventEmitter | ||
}); | ||
//# sourceMappingURL=index.js.map |
@@ -87,3 +87,2 @@ var __defProp = Object.defineProperty; | ||
OpenFeatureError as OpenFeatureError2, | ||
OpenFeatureEventEmitter, | ||
ProviderEvents, | ||
@@ -201,2 +200,16 @@ StandardResolutionReasons, | ||
// src/events/open-feature-event-emitter.ts | ||
import { GenericEventEmitter } from "@openfeature/core"; | ||
import EventEmitter from "events"; | ||
var OpenFeatureEventEmitter = class extends GenericEventEmitter { | ||
constructor() { | ||
super(); | ||
this.eventEmitter = new EventEmitter({ captureRejections: true }); | ||
this.eventEmitter.on("error", (err) => { | ||
var _a; | ||
(_a = this._logger) == null ? void 0 : _a.error("Error running event handler:", err); | ||
}); | ||
} | ||
}; | ||
// src/open-feature.ts | ||
@@ -208,4 +221,6 @@ var GLOBAL_OPENFEATURE_API_KEY = Symbol.for("@openfeature/js-sdk/api"); | ||
super("server"); | ||
this._events = new OpenFeatureEventEmitter(); | ||
this._defaultProvider = NOOP_PROVIDER; | ||
this._createEventEmitter = () => new OpenFeatureEventEmitter(); | ||
this._transactionContextPropagator = NOOP_TRANSACTION_CONTEXT_PROPAGATOR; | ||
this._defaultProvider = NOOP_PROVIDER; | ||
} | ||
@@ -504,4 +519,5 @@ /** | ||
OpenFeatureAPI, | ||
OpenFeatureClient | ||
OpenFeatureClient, | ||
OpenFeatureEventEmitter | ||
}; | ||
//# sourceMappingURL=index.js.map |
@@ -1,4 +0,565 @@ | ||
import { Hook, HookHints, EvaluationContext, EvaluationDetails, JsonValue, EvaluationLifeCycle, ManageContext, ManageLogger, Eventing, ClientMetadata, CommonProvider, Logger, ResolutionDetails, ProviderStatus, OpenFeatureEventEmitter, InternalEventEmitter, ProviderEvents, EventHandler, FlagValue, OpenFeatureCommonAPI } from '@openfeature/core'; | ||
export * from '@openfeature/core'; | ||
import EventEmitter from 'events'; | ||
type FlagValueType = 'boolean' | 'string' | 'number' | 'object'; | ||
type PrimitiveValue = null | boolean | string | number; | ||
type JsonObject = { | ||
[key: string]: JsonValue; | ||
}; | ||
type JsonArray = JsonValue[]; | ||
/** | ||
* Represents a JSON node value. | ||
*/ | ||
type JsonValue = PrimitiveValue | JsonObject | JsonArray; | ||
/** | ||
* Represents a JSON node value, or Date. | ||
*/ | ||
type FlagValue = boolean | string | number | JsonValue; | ||
type ResolutionReason = keyof typeof StandardResolutionReasons | (string & Record<never, never>); | ||
/** | ||
* 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 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: { | ||
/** | ||
* The resolved value was the result of a dynamic evaluation, such as a rule or specific user-targeting. | ||
*/ | ||
readonly TARGETING_MATCH: "TARGETING_MATCH"; | ||
/** | ||
* The resolved value was the result of pseudorandom assignment. | ||
*/ | ||
readonly SPLIT: "SPLIT"; | ||
/** | ||
* The resolved value was the result of the flag being disabled in the management system. | ||
*/ | ||
readonly DISABLED: "DISABLED"; | ||
/** | ||
* The resolved value was configured statically, or otherwise fell back to a pre-configured value. | ||
*/ | ||
readonly DEFAULT: "DEFAULT"; | ||
/** | ||
* The reason for the resolved value could not be determined. | ||
*/ | ||
readonly UNKNOWN: "UNKNOWN"; | ||
/** | ||
* The resolved value is static (no dynamic evaluation). | ||
*/ | ||
readonly STATIC: "STATIC"; | ||
/** | ||
* The resolved value was retrieved from cache. | ||
*/ | ||
readonly CACHED: "CACHED"; | ||
/** | ||
* The resolved value was the result of an error. | ||
* | ||
* Note: The `errorCode` and `errorMessage` fields may contain additional details of this error. | ||
*/ | ||
readonly ERROR: "ERROR"; | ||
}; | ||
declare enum ErrorCode { | ||
/** | ||
* The value was resolved before the provider was ready. | ||
*/ | ||
PROVIDER_NOT_READY = "PROVIDER_NOT_READY", | ||
/** | ||
* The flag could not be found. | ||
*/ | ||
FLAG_NOT_FOUND = "FLAG_NOT_FOUND", | ||
/** | ||
* An error was encountered parsing data, such as a flag configuration. | ||
*/ | ||
PARSE_ERROR = "PARSE_ERROR", | ||
/** | ||
* The type of the flag value does not match the expected type. | ||
*/ | ||
TYPE_MISMATCH = "TYPE_MISMATCH", | ||
/** | ||
* The provider requires a targeting key and one was not provided in the evaluation context. | ||
*/ | ||
TARGETING_KEY_MISSING = "TARGETING_KEY_MISSING", | ||
/** | ||
* The evaluation context does not meet provider requirements. | ||
*/ | ||
INVALID_CONTEXT = "INVALID_CONTEXT", | ||
/** | ||
* An error with an unspecified code. | ||
*/ | ||
GENERAL = "GENERAL" | ||
} | ||
type EvaluationContextValue = PrimitiveValue | Date | { | ||
[key: string]: EvaluationContextValue; | ||
} | EvaluationContextValue[]; | ||
/** | ||
* A container for arbitrary contextual data that can be used as a basis for dynamic evaluation | ||
*/ | ||
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> { | ||
/** | ||
* Access the evaluation context set on the receiver. | ||
* @returns {EvaluationContext} Evaluation context | ||
*/ | ||
getContext(): EvaluationContext; | ||
/** | ||
* Sets evaluation context that will be used during flag evaluations | ||
* on this receiver. | ||
* @template T The type of the receiver | ||
* @param {EvaluationContext} context Evaluation context | ||
* @returns {T} The receiver (this object) | ||
*/ | ||
setContext(context: EvaluationContext): T; | ||
} | ||
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" | ||
} | ||
/** | ||
* 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 {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; | ||
type EventMetadata = { | ||
[key: string]: string | boolean | number; | ||
}; | ||
type CommonEventDetails = { | ||
providerName: string; | ||
clientName?: string; | ||
}; | ||
type CommonEventProps = { | ||
message?: string; | ||
metadata?: EventMetadata; | ||
}; | ||
type ReadyEvent = CommonEventProps; | ||
type ErrorEvent = CommonEventProps; | ||
type StaleEvent = CommonEventProps; | ||
type ConfigChangeEvent = CommonEventProps & { | ||
flagsChanged?: string[]; | ||
}; | ||
type EventMap = { | ||
[ProviderEvents.Ready]: ReadyEvent; | ||
[ProviderEvents.Error]: ErrorEvent; | ||
[ProviderEvents.Stale]: StaleEvent; | ||
[ProviderEvents.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; | ||
interface Eventing { | ||
/** | ||
* Adds a handler for the given provider event type. | ||
* The handlers are called in the order they have been added. | ||
* @param {ProviderEvents} 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; | ||
/** | ||
* Removes a handler for the given provider event type. | ||
* @param {ProviderEvents} 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; | ||
/** | ||
* Gets the current handlers for the given provider event type. | ||
* @param {ProviderEvents} 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>[]; | ||
} | ||
interface Logger { | ||
error(...args: unknown[]): void; | ||
warn(...args: unknown[]): void; | ||
info(...args: unknown[]): void; | ||
debug(...args: unknown[]): void; | ||
} | ||
interface ManageLogger<T> { | ||
/** | ||
* 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) | ||
*/ | ||
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; | ||
} | ||
/** | ||
* The GenericEventEmitter should only be used within the SDK. It supports additional properties that can be included | ||
* in the event details. | ||
*/ | ||
declare abstract class GenericEventEmitter<AdditionalContext extends Record<string, unknown> = Record<string, unknown>> implements ManageLogger<GenericEventEmitter<AdditionalContext>> { | ||
private readonly globalLogger?; | ||
protected abstract readonly eventEmitter: NodeJS.EventEmitter; | ||
private readonly _handlers; | ||
private _eventLogger?; | ||
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>[]; | ||
setLogger(logger: Logger): this; | ||
protected get _logger(): Logger | undefined; | ||
} | ||
interface Metadata { | ||
} | ||
/** | ||
* Defines where the library is intended to be run. | ||
*/ | ||
type Paradigm = 'server' | 'client'; | ||
/** | ||
* The state of the provider. | ||
*/ | ||
declare enum ProviderStatus { | ||
/** | ||
* The provider has not been initialized and cannot yet evaluate flags. | ||
*/ | ||
NOT_READY = "NOT_READY", | ||
/** | ||
* The provider is ready to resolve flags. | ||
*/ | ||
READY = "READY", | ||
/** | ||
* The provider is in an error state and unable to evaluate flags. | ||
*/ | ||
ERROR = "ERROR", | ||
/** | ||
* The provider's cached state is no longer valid and may not be up-to-date with the source of truth. | ||
*/ | ||
STALE = "STALE" | ||
} | ||
/** | ||
* Static data about the provider. | ||
*/ | ||
interface ProviderMetadata extends Metadata { | ||
readonly name: string; | ||
} | ||
interface CommonProvider { | ||
readonly metadata: ProviderMetadata; | ||
/** | ||
* Represents where the provider is intended to be run. If defined, | ||
* the SDK will enforce that the defined paradigm at runtime. | ||
*/ | ||
readonly runsOn?: Paradigm; | ||
/** | ||
* Returns a representation of the current readiness of the provider. | ||
* If the provider needs to be initialized, it should return {@link ProviderStatus.READY}. | ||
* If the provider is in an error state, it should return {@link ProviderStatus.ERROR}. | ||
* If the provider is functioning normally, it should return {@link ProviderStatus.NOT_READY}. | ||
* | ||
* _Providers which do not implement this method are assumed to be ready immediately._ | ||
*/ | ||
readonly status?: ProviderStatus; | ||
/** | ||
* An event emitter for ProviderEvents. | ||
* @see ProviderEvents | ||
*/ | ||
events?: GenericEventEmitter; | ||
/** | ||
* A function used to shut down the provider. | ||
* Called when this provider is replaced with a new one, or when the OpenFeature is shut down. | ||
*/ | ||
onClose?(): Promise<void>; | ||
/** | ||
* A function used to setup the provider. | ||
* Called by the SDK after the provider is set if the provider's status is {@link ProviderStatus.NOT_READY}. | ||
* 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>; | ||
} | ||
interface ClientMetadata extends Metadata { | ||
readonly version?: string; | ||
readonly name?: string; | ||
readonly providerMetadata: ProviderMetadata; | ||
} | ||
type HookHints = Readonly<Record<string, unknown>>; | ||
interface HookContext<T extends FlagValue = FlagValue> { | ||
readonly flagKey: string; | ||
readonly defaultValue: T; | ||
readonly flagValueType: FlagValueType; | ||
readonly context: Readonly<EvaluationContext>; | ||
readonly clientMetadata: ClientMetadata; | ||
readonly providerMetadata: ProviderMetadata; | ||
readonly logger: Logger; | ||
} | ||
interface BeforeHookContext extends HookContext { | ||
context: EvaluationContext; | ||
} | ||
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): Promise<EvaluationContext | void> | 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): Promise<void> | 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): 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; | ||
} | ||
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<FlagValue>[]): T; | ||
/** | ||
* Access all the hooks that are registered on this receiver. | ||
* @returns {Hook<FlagValue>[]} A list of the client hooks | ||
*/ | ||
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; | ||
} | ||
declare abstract class OpenFeatureError extends Error { | ||
abstract code: ErrorCode; | ||
constructor(message?: string); | ||
} | ||
declare class GeneralError extends OpenFeatureError { | ||
code: ErrorCode; | ||
constructor(message?: string); | ||
} | ||
declare class FlagNotFoundError extends OpenFeatureError { | ||
code: ErrorCode; | ||
constructor(message?: string); | ||
} | ||
declare class ParseError extends OpenFeatureError { | ||
code: ErrorCode; | ||
constructor(message?: string); | ||
} | ||
declare class TypeMismatchError extends OpenFeatureError { | ||
code: ErrorCode; | ||
constructor(message?: string); | ||
} | ||
declare class TargetingKeyMissingError extends OpenFeatureError { | ||
code: ErrorCode; | ||
constructor(message?: string); | ||
} | ||
declare class InvalidContextError extends OpenFeatureError { | ||
code: ErrorCode; | ||
constructor(message?: string); | ||
} | ||
/** | ||
* 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>> { | ||
protected abstract _createEventEmitter(): GenericEventEmitter; | ||
protected abstract _defaultProvider: P; | ||
protected abstract readonly _events: GenericEventEmitter; | ||
protected _hooks: Hook[]; | ||
protected _context: EvaluationContext; | ||
protected _logger: Logger; | ||
private readonly _clientEventHandlers; | ||
protected _clientProviders: Map<string, P>; | ||
protected _clientEvents: Map<string | undefined, GenericEventEmitter>; | ||
protected _runsOn: Paradigm; | ||
constructor(category: Paradigm); | ||
addHooks(...hooks: Hook<FlagValue>[]): this; | ||
getHooks(): Hook<FlagValue>[]; | ||
clearHooks(): this; | ||
setLogger(logger: Logger): this; | ||
/** | ||
* Get metadata about registered provider. | ||
* @returns {ProviderMetadata} Provider Metadata | ||
*/ | ||
get providerMetadata(): 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 {EventHandler} handler The handler to run on occurrence of the event type | ||
*/ | ||
addHandler<T extends ProviderEvents>(eventType: T, handler: EventHandler<T>): void; | ||
/** | ||
* Removes a handler for the given provider event type. | ||
* @param {ProviderEvents} 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; | ||
/** | ||
* Gets the current handlers for the given provider event type. | ||
* @param {ProviderEvents} 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>[]; | ||
/** | ||
* Sets the default provider for flag evaluations and returns a promise that resolves when the provider is ready. | ||
* This provider will be used by unnamed clients and named clients to which no provider is bound. | ||
* Setting a provider supersedes the current provider used in new and existing clients without a name. | ||
* @template P | ||
* @param {P} provider The provider responsible for flag evaluations. | ||
* @returns {Promise<void>} | ||
* @throws Uncaught exceptions thrown by the provider during initialization. | ||
*/ | ||
setProviderAndWait(provider: P): Promise<void>; | ||
/** | ||
* Sets the provider that OpenFeature will use for flag evaluations of providers with the given name. | ||
* A promise is returned that resolves when the provider is ready. | ||
* Setting a provider supersedes the current provider used in new and existing clients with that name. | ||
* @template P | ||
* @param {string} clientName The name to identify the client | ||
* @param {P} provider The provider responsible for flag evaluations. | ||
* @returns {Promise<void>} | ||
* @throws Uncaught exceptions thrown by the provider during initialization. | ||
*/ | ||
setProviderAndWait(clientName: string, provider: P): Promise<void>; | ||
/** | ||
* Sets the default provider for flag evaluations. | ||
* This provider will be used by unnamed clients and named clients to which no provider is bound. | ||
* Setting a provider supersedes the current provider used in new and existing clients without a name. | ||
* @template P | ||
* @param {P} provider The provider responsible for flag evaluations. | ||
* @returns {this} OpenFeature API | ||
*/ | ||
setProvider(provider: P): this; | ||
/** | ||
* Sets the provider that OpenFeature will use for flag evaluations of providers with the given name. | ||
* Setting a provider supersedes the current provider used in new and existing clients with that name. | ||
* @template P | ||
* @param {string} clientName The name to identify the client | ||
* @param {P} provider The provider responsible for flag evaluations. | ||
* @returns {this} OpenFeature API | ||
*/ | ||
setProvider(clientName: string, provider: P): this; | ||
private setAwaitableProvider; | ||
protected getProviderForClient(name?: string): P; | ||
protected buildAndCacheEventEmitterForClient(name?: string): GenericEventEmitter; | ||
private getUnboundEmitters; | ||
private getAssociatedEventEmitters; | ||
private transferListeners; | ||
close(): Promise<void>; | ||
protected clearProvidersAndSetDefault(defaultProvider: P): Promise<void>; | ||
private handleShutdownError; | ||
} | ||
interface FlagEvaluationOptions { | ||
@@ -205,2 +766,10 @@ hooks?: Hook[]; | ||
/** | ||
* The InternalEventEmitter is not exported publicly and should only be used within the SDK. It extends the | ||
* OpenFeatureEventEmitter to include additional properties that can be included | ||
* in the event details. | ||
*/ | ||
declare abstract class InternalEventEmitter extends GenericEventEmitter<CommonEventDetails> { | ||
} | ||
type OpenFeatureClientOptions = { | ||
@@ -298,5 +867,19 @@ name?: string; | ||
/** | ||
* 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(); | ||
} | ||
declare class OpenFeatureAPI extends OpenFeatureCommonAPI<Provider> implements ManageContext<OpenFeatureAPI>, ManageTransactionContextPropagator<OpenFeatureCommonAPI<Provider>> { | ||
protected _events: OpenFeatureEventEmitter; | ||
protected _defaultProvider: Provider; | ||
protected _createEventEmitter: () => OpenFeatureEventEmitter; | ||
private _transactionContextPropagator; | ||
protected _defaultProvider: Provider; | ||
private constructor(); | ||
@@ -361,2 +944,2 @@ /** | ||
export { Client, Features, FlagEvaluationOptions, InMemoryProvider, ManageTransactionContextPropagator, NOOP_PROVIDER, NOOP_TRANSACTION_CONTEXT_PROPAGATOR, OpenFeature, OpenFeatureAPI, OpenFeatureClient, Provider, TransactionContext, TransactionContextPropagator }; | ||
export { BeforeHookContext, Client, ClientMetadata, CommonEventDetails, CommonProvider, ConfigChangeEvent, DefaultLogger, ErrorCode, ErrorEvent, EvaluationContext, EvaluationContextValue, EvaluationDetails, EvaluationLifeCycle, EventContext, EventDetails, EventHandler, EventMetadata, Eventing, Features, FlagEvaluationOptions, FlagMetadata, FlagNotFoundError, FlagValue, FlagValueType, GeneralError, GenericEventEmitter, Hook, HookContext, HookHints, InMemoryProvider, InvalidContextError, JsonArray, JsonObject, JsonValue, LOG_LEVELS, Logger, ManageContext, ManageLogger, ManageTransactionContextPropagator, Metadata, NOOP_PROVIDER, NOOP_TRANSACTION_CONTEXT_PROPAGATOR, OpenFeature, OpenFeatureAPI, OpenFeatureClient, OpenFeatureCommonAPI, OpenFeatureError, OpenFeatureEventEmitter, Paradigm, ParseError, PrimitiveValue, Provider, ProviderEvents, ProviderMetadata, ProviderStatus, ReadyEvent, ResolutionDetails, ResolutionReason, SafeLogger, StaleEvent, StandardResolutionReasons, TargetingKeyMissingError, TransactionContext, TransactionContextPropagator, TypeMismatchError, isObject, isString, objectOrUndefined, statusMatchesEvent, stringOrUndefined }; |
{ | ||
"name": "@openfeature/server-sdk", | ||
"version": "1.7.1", | ||
"version": "1.7.2", | ||
"description": "OpenFeature SDK for JavaScript", | ||
@@ -51,7 +51,7 @@ "main": "./dist/cjs/index.js", | ||
"peerDependencies": { | ||
"@openfeature/core": "0.0.17" | ||
"@openfeature/core": "0.0.18" | ||
}, | ||
"devDependencies": { | ||
"@openfeature/core": "0.0.17" | ||
"@openfeature/core": "0.0.18" | ||
} | ||
} |
@@ -19,4 +19,4 @@ <!-- markdownlint-disable MD033 --> | ||
<!-- x-release-please-start-version --> | ||
<a href="https://github.com/open-feature/js-sdk/releases/tag/server-sdk-v1.7.1"> | ||
<img alt="Release" src="https://img.shields.io/static/v1?label=release&message=v1.7.1&color=blue&style=for-the-badge" /> | ||
<a href="https://github.com/open-feature/js-sdk/releases/tag/server-sdk-v1.7.2"> | ||
<img alt="Release" src="https://img.shields.io/static/v1?label=release&message=v1.7.2&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
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
178250
1947