Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@openfeature/js-sdk

Package Overview
Dependencies
Maintainers
2
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@openfeature/js-sdk - npm Package Compare versions

Comparing version 1.0.0 to 1.0.99-experimental-55bf085fbdec8a76753b02b3efee8bec3eac53c0

42

dist/cjs/index.js

@@ -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"] = "PROVIDER_READY";
ProviderEvents2["Error"] = "PROVIDER_ERROR";
ProviderEvents2["ConfigurationChanged"] = "PROVIDER_CONFIGURATION_CHANGED";
ProviderEvents2["Shutdown"] = "PROVIDER_SHUTDOWN";
return ProviderEvents2;
})(ProviderEvents || {});
var ApiEvents = /* @__PURE__ */ ((ApiEvents2) => {
ApiEvents2["ProviderChanged"] = "providerChanged";
return ApiEvents2;
})(ApiEvents || {});
var StandardResolutionReasons = {

@@ -135,2 +151,3 @@ TARGETING_MATCH: "TARGETING_MATCH",

UNKNOWN: "UNKNOWN",
CACHED: "CACHED",
ERROR: "ERROR"

@@ -155,2 +172,3 @@ };

this._hooks = [];
this._handlerWrappers = [];
this.metadata = {

@@ -161,3 +179,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 === "PROVIDER_READY" /* Ready */ && this.providerAccessor().ready) {
handler();
}
}
setLogger(logger) {

@@ -337,2 +363,10 @@ this._clientLogger = new SafeLogger(logger);

}
attachListeners() {
Object.values(ProviderEvents).forEach((e) => {
var _a;
return (_a = this.providerAccessor().events) == null ? void 0 : _a.on(e, () => {
this._handlerWrappers.filter((wrapper) => wrapper.eventType === e).forEach((wrapper) => wrapper.handler());
});
});
}
};

@@ -385,2 +419,3 @@

constructor() {
this.events = new import_events.EventEmitter();
this._provider = NOOP_PROVIDER;

@@ -428,3 +463,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;

@@ -536,2 +574,3 @@ }

0 && (module.exports = {
ApiEvents,
ErrorCode,

@@ -544,2 +583,3 @@ FlagNotFoundError,

ParseError,
ProviderEvents,
StandardResolutionReasons,

@@ -546,0 +586,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"] = "PROVIDER_READY";
ProviderEvents2["Error"] = "PROVIDER_ERROR";
ProviderEvents2["ConfigurationChanged"] = "PROVIDER_CONFIGURATION_CHANGED";
ProviderEvents2["Shutdown"] = "PROVIDER_SHUTDOWN";
return ProviderEvents2;
})(ProviderEvents || {});
var ApiEvents = /* @__PURE__ */ ((ApiEvents2) => {
ApiEvents2["ProviderChanged"] = "providerChanged";
return ApiEvents2;
})(ApiEvents || {});
var StandardResolutionReasons = {

@@ -101,2 +115,3 @@ TARGETING_MATCH: "TARGETING_MATCH",

UNKNOWN: "UNKNOWN",
CACHED: "CACHED",
ERROR: "ERROR"

@@ -121,2 +136,3 @@ };

this._hooks = [];
this._handlerWrappers = [];
this.metadata = {

@@ -127,3 +143,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 === "PROVIDER_READY" /* Ready */ && this.providerAccessor().ready) {
handler();
}
}
setLogger(logger) {

@@ -303,2 +327,10 @@ this._clientLogger = new SafeLogger(logger);

}
attachListeners() {
Object.values(ProviderEvents).forEach((e) => {
var _a;
return (_a = this.providerAccessor().events) == null ? void 0 : _a.on(e, () => {
this._handlerWrappers.filter((wrapper) => wrapper.eventType === e).forEach((wrapper) => wrapper.handler());
});
});
}
};

@@ -351,2 +383,3 @@

constructor() {
this.events = new EventEmitter();
this._provider = NOOP_PROVIDER;

@@ -394,3 +427,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;

@@ -501,2 +537,3 @@ }

export {
ApiEvents,
ErrorCode,

@@ -509,2 +546,3 @@ FlagNotFoundError,

ParseError,
ProviderEvents,
StandardResolutionReasons,

@@ -511,0 +549,0 @@ TargetingKeyMissingError,

7

dist/types/client.d.ts

@@ -1,2 +0,2 @@

import { Client, ClientMetadata, EvaluationContext, EvaluationDetails, FlagEvaluationOptions, FlagValue, Hook, JsonValue, Logger, Provider } from './types';
import { Client, ClientMetadata, EvaluationContext, EvaluationDetails, EventProvider, FlagEvaluationOptions, FlagValue, Handler, Hook, JsonValue, Logger, Provider, ProviderEvents } from './types';
declare type OpenFeatureClientOptions = {

@@ -13,3 +13,5 @@ name?: string;

private _clientLogger?;
constructor(providerAccessor: () => Provider, globalLogger: () => Logger, options: OpenFeatureClientOptions, context?: EvaluationContext);
private _handlerWrappers;
constructor(providerAccessor: () => Provider & Partial<EventProvider>, globalLogger: () => Logger, options: OpenFeatureClientOptions, context?: EvaluationContext);
addHandler(eventType: ProviderEvents, handler: Handler): void;
setLogger(logger: Logger): OpenFeatureClient;

@@ -36,3 +38,4 @@ setContext(context: EvaluationContext): OpenFeatureClient;

private get _logger();
private attachListeners;
}
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 EventProvider {
readonly events: EventEmitter;
readonly ready: boolean;
}
export declare enum ProviderEvents {
Ready = "PROVIDER_READY",
Error = "PROVIDER_ERROR",
ConfigurationChanged = "PROVIDER_CONFIGURATION_CHANGED",
Shutdown = "PROVIDER_SHUTDOWN"
}
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 = {

@@ -187,2 +223,6 @@ [key: string]: JsonValue;

/**
* A cached value was resolved.
*/
readonly CACHED: "CACHED";
/**
* The resolved value was the result of an error.

@@ -235,3 +275,3 @@ *

} & 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 +278,0 @@ }

{
"name": "@openfeature/js-sdk",
"version": "1.0.0",
"version": "1.0.99-experimental-55bf085fbdec8a76753b02b3efee8bec3eac53c0",
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc