@openfeature/js-sdk
Advanced tools
Comparing version 1.0.0 to 1.0.99-experimental-b56a9f3eb51dbaa642a70d837db141dd22f100da
@@ -60,2 +60,3 @@ "use strict"; | ||
__export(src_exports, { | ||
ApiEvents: () => ApiEvents, | ||
ErrorCode: () => ErrorCode, | ||
@@ -68,2 +69,3 @@ FlagNotFoundError: () => FlagNotFoundError, | ||
ParseError: () => ParseError, | ||
ProviderEvents: () => ProviderEvents, | ||
StandardResolutionReasons: () => StandardResolutionReasons, | ||
@@ -75,2 +77,5 @@ TargetingKeyMissingError: () => TargetingKeyMissingError, | ||
// src/open-feature.ts | ||
var import_events = require("events"); | ||
// src/logger.ts | ||
@@ -128,2 +133,13 @@ var LOG_LEVELS = ["error", "warn", "info", "debug"]; | ||
// src/types.ts | ||
var ProviderEvents = /* @__PURE__ */ ((ProviderEvents2) => { | ||
ProviderEvents2["Ready"] = "ready"; | ||
ProviderEvents2["Error"] = "error"; | ||
ProviderEvents2["ConfigurationChanged"] = "configurationChanged"; | ||
ProviderEvents2["Disposed"] = "disposed"; | ||
return ProviderEvents2; | ||
})(ProviderEvents || {}); | ||
var ApiEvents = /* @__PURE__ */ ((ApiEvents2) => { | ||
ApiEvents2["ProviderChanged"] = "providerChanged"; | ||
return ApiEvents2; | ||
})(ApiEvents || {}); | ||
var StandardResolutionReasons = { | ||
@@ -154,2 +170,3 @@ TARGETING_MATCH: "TARGETING_MATCH", | ||
this._hooks = []; | ||
this._handlerWrappers = []; | ||
this.metadata = { | ||
@@ -160,3 +177,11 @@ name: options.name, | ||
this._context = context; | ||
this.attachListeners(); | ||
OpenFeatureAPI.getInstance().events.on("providerChanged" /* ProviderChanged */, () => this.attachListeners()); | ||
} | ||
addHandler(eventType, handler) { | ||
this._handlerWrappers.push({ eventType, handler }); | ||
if (eventType === "ready" /* Ready */ && this.providerAccessor().ready) { | ||
handler(); | ||
} | ||
} | ||
setLogger(logger) { | ||
@@ -336,2 +361,11 @@ this._clientLogger = new SafeLogger(logger); | ||
} | ||
attachListeners() { | ||
var _a, _b, _c; | ||
(_a = this.providerAccessor().events) == null ? void 0 : _a.on("ready" /* Ready */, () => this.runAllHandlers("ready" /* Ready */)); | ||
(_b = this.providerAccessor().events) == null ? void 0 : _b.on("configurationChanged" /* ConfigurationChanged */, () => this.runAllHandlers("configurationChanged" /* ConfigurationChanged */)); | ||
(_c = this.providerAccessor().events) == null ? void 0 : _c.on("error" /* Error */, () => this.runAllHandlers("error" /* Error */)); | ||
} | ||
runAllHandlers(eventType) { | ||
this._handlerWrappers.filter((wrapper) => wrapper.eventType === eventType).forEach((wrapper) => wrapper.handler()); | ||
} | ||
}; | ||
@@ -384,2 +418,3 @@ | ||
constructor() { | ||
this.events = new import_events.EventEmitter(); | ||
this._provider = NOOP_PROVIDER; | ||
@@ -427,3 +462,6 @@ this._transactionContextPropagator = NOOP_TRANSACTION_CONTEXT_PROPAGATOR; | ||
setProvider(provider) { | ||
this._provider = provider; | ||
if (this._provider !== provider) { | ||
this.events.emit("providerChanged" /* ProviderChanged */); | ||
this._provider = provider; | ||
} | ||
return this; | ||
@@ -535,2 +573,3 @@ } | ||
0 && (module.exports = { | ||
ApiEvents, | ||
ErrorCode, | ||
@@ -543,2 +582,3 @@ FlagNotFoundError, | ||
ParseError, | ||
ProviderEvents, | ||
StandardResolutionReasons, | ||
@@ -545,0 +585,0 @@ TargetingKeyMissingError, |
@@ -41,2 +41,5 @@ var __defProp = Object.defineProperty; | ||
// src/open-feature.ts | ||
import { EventEmitter } from "events"; | ||
// src/logger.ts | ||
@@ -94,2 +97,13 @@ var LOG_LEVELS = ["error", "warn", "info", "debug"]; | ||
// src/types.ts | ||
var ProviderEvents = /* @__PURE__ */ ((ProviderEvents2) => { | ||
ProviderEvents2["Ready"] = "ready"; | ||
ProviderEvents2["Error"] = "error"; | ||
ProviderEvents2["ConfigurationChanged"] = "configurationChanged"; | ||
ProviderEvents2["Disposed"] = "disposed"; | ||
return ProviderEvents2; | ||
})(ProviderEvents || {}); | ||
var ApiEvents = /* @__PURE__ */ ((ApiEvents2) => { | ||
ApiEvents2["ProviderChanged"] = "providerChanged"; | ||
return ApiEvents2; | ||
})(ApiEvents || {}); | ||
var StandardResolutionReasons = { | ||
@@ -120,2 +134,3 @@ TARGETING_MATCH: "TARGETING_MATCH", | ||
this._hooks = []; | ||
this._handlerWrappers = []; | ||
this.metadata = { | ||
@@ -126,3 +141,11 @@ name: options.name, | ||
this._context = context; | ||
this.attachListeners(); | ||
OpenFeatureAPI.getInstance().events.on("providerChanged" /* ProviderChanged */, () => this.attachListeners()); | ||
} | ||
addHandler(eventType, handler) { | ||
this._handlerWrappers.push({ eventType, handler }); | ||
if (eventType === "ready" /* Ready */ && this.providerAccessor().ready) { | ||
handler(); | ||
} | ||
} | ||
setLogger(logger) { | ||
@@ -302,2 +325,11 @@ this._clientLogger = new SafeLogger(logger); | ||
} | ||
attachListeners() { | ||
var _a, _b, _c; | ||
(_a = this.providerAccessor().events) == null ? void 0 : _a.on("ready" /* Ready */, () => this.runAllHandlers("ready" /* Ready */)); | ||
(_b = this.providerAccessor().events) == null ? void 0 : _b.on("configurationChanged" /* ConfigurationChanged */, () => this.runAllHandlers("configurationChanged" /* ConfigurationChanged */)); | ||
(_c = this.providerAccessor().events) == null ? void 0 : _c.on("error" /* Error */, () => this.runAllHandlers("error" /* Error */)); | ||
} | ||
runAllHandlers(eventType) { | ||
this._handlerWrappers.filter((wrapper) => wrapper.eventType === eventType).forEach((wrapper) => wrapper.handler()); | ||
} | ||
}; | ||
@@ -350,2 +382,3 @@ | ||
constructor() { | ||
this.events = new EventEmitter(); | ||
this._provider = NOOP_PROVIDER; | ||
@@ -393,3 +426,6 @@ this._transactionContextPropagator = NOOP_TRANSACTION_CONTEXT_PROPAGATOR; | ||
setProvider(provider) { | ||
this._provider = provider; | ||
if (this._provider !== provider) { | ||
this.events.emit("providerChanged" /* ProviderChanged */); | ||
this._provider = provider; | ||
} | ||
return this; | ||
@@ -500,2 +536,3 @@ } | ||
export { | ||
ApiEvents, | ||
ErrorCode, | ||
@@ -508,2 +545,3 @@ FlagNotFoundError, | ||
ParseError, | ||
ProviderEvents, | ||
StandardResolutionReasons, | ||
@@ -510,0 +548,0 @@ TargetingKeyMissingError, |
@@ -1,2 +0,2 @@ | ||
import { Client, ClientMetadata, EvaluationContext, EvaluationDetails, FlagEvaluationOptions, FlagValue, Hook, JsonValue, Logger, Provider } from './types'; | ||
import { Client, ClientMetadata, EvaluationContext, EvaluationDetails, FlagEvaluationOptions, FlagValue, Handler, Hook, JsonValue, Logger, Provider, ProviderEvents } from './types'; | ||
declare type OpenFeatureClientOptions = { | ||
@@ -13,3 +13,5 @@ name?: string; | ||
private _clientLogger?; | ||
private _handlerWrappers; | ||
constructor(providerAccessor: () => Provider, globalLogger: () => Logger, options: OpenFeatureClientOptions, context?: EvaluationContext); | ||
addHandler(eventType: ProviderEvents, handler: Handler): void; | ||
setLogger(logger: Logger): OpenFeatureClient; | ||
@@ -36,3 +38,5 @@ setContext(context: EvaluationContext): OpenFeatureClient; | ||
private get _logger(); | ||
private attachListeners; | ||
private runAllHandlers; | ||
} | ||
export {}; |
@@ -0,3 +1,6 @@ | ||
/// <reference types="node" /> | ||
import { EventEmitter } from 'events'; | ||
import { Client, EvaluationContext, FlagValue, GlobalApi, Hook, Logger, Provider, ProviderMetadata, TransactionContext, TransactionContextPropagator } from './types'; | ||
export declare class OpenFeatureAPI implements GlobalApi { | ||
events: EventEmitter; | ||
private _provider; | ||
@@ -4,0 +7,0 @@ private _transactionContextPropagator; |
@@ -0,2 +1,38 @@ | ||
/// <reference types="node" /> | ||
import EventEmitter from 'events'; | ||
export declare type PrimitiveValue = null | boolean | string | number; | ||
export interface ProviderEventing { | ||
events?: EventEmitter; | ||
ready?: boolean; | ||
} | ||
export declare enum ProviderEvents { | ||
Ready = "ready", | ||
Error = "error", | ||
ConfigurationChanged = "configurationChanged", | ||
Disposed = "disposed" | ||
} | ||
export declare enum ApiEvents { | ||
ProviderChanged = "providerChanged" | ||
} | ||
export interface Eventing { | ||
addHandler(notificationType: string, handler: Handler): void; | ||
} | ||
export declare type EventContext = { | ||
notificationType: string; | ||
[key: string]: unknown; | ||
}; | ||
export declare type Handler = (eventContext?: EventContext) => void; | ||
export declare type ErrorHandler = (err: unknown) => void; | ||
export declare type HandlerWrapper = { | ||
eventType: string; | ||
handler: Handler; | ||
}; | ||
export declare type EventCallbackMessage = (eventContext: EventContext) => void; | ||
export declare type EventCallbackError = (err: Error) => void; | ||
/** | ||
* Represents a JSON value of a JSON object | ||
*/ | ||
export declare type JSONValue = null | string | number | boolean | Date | { | ||
[x: string]: JSONValue; | ||
} | Array<JSONValue>; | ||
export declare type JsonObject = { | ||
@@ -139,4 +175,6 @@ [key: string]: JsonValue; | ||
*/ | ||
export interface Provider { | ||
export interface Provider extends ProviderEventing { | ||
readonly metadata: ProviderMetadata; | ||
ready?: boolean; | ||
events?: EventEmitter; | ||
/** | ||
@@ -235,3 +273,3 @@ * A provider hook exposes a mechanism for provider authors to register hooks | ||
} & ResolutionDetails<T>; | ||
export interface Client extends EvaluationLifeCycle<Client>, Features, ManageContext<Client>, ManageLogger<Client> { | ||
export interface Client extends EvaluationLifeCycle<Client>, Features, ManageContext<Client>, ManageLogger<Client>, Eventing { | ||
readonly metadata: ClientMetadata; | ||
@@ -238,0 +276,0 @@ } |
{ | ||
"name": "@openfeature/js-sdk", | ||
"version": "1.0.0", | ||
"version": "1.0.99-experimental-b56a9f3eb51dbaa642a70d837db141dd22f100da", | ||
"description": "OpenFeature SDK for JavaScript", | ||
@@ -46,3 +46,3 @@ "main": "./dist/cjs/index.js", | ||
"devDependencies": { | ||
"@openfeature/flagd-provider": "~0.6.0", | ||
"@openfeature/flagd-provider": "~0.7.0", | ||
"@types/jest": "^28.1.4", | ||
@@ -69,2 +69,2 @@ "@types/node": "^18.0.3", | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
184788
1722
1