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

unleash-client

Package Overview
Dependencies
Maintainers
3
Versions
123
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unleash-client - npm Package Compare versions

Comparing version 4.1.0-beta.3 to 4.1.0-beta.4

6

lib/client.d.ts

@@ -6,5 +6,5 @@ /// <reference types="node" />

import { RepositoryInterface } from './repository';
import { Variant, VariantDefinition } from './variant';
import { Variant } from './variant';
import { Context } from './context';
import { Constraint, Segment } from './strategy/strategy';
import { Constraint, Segment, StrategyResult } from './strategy/strategy';
export default class UnleashClient extends EventEmitter {

@@ -18,3 +18,3 @@ private repository;

isEnabled(name: string, context: Context, fallback: Function): boolean;
isFeatureEnabled(feature: FeatureInterface | undefined, context: Context, fallback: Function): [boolean, VariantDefinition | undefined];
isFeatureEnabled(feature: FeatureInterface | undefined, context: Context, fallback: Function): StrategyResult;
yieldConstraintsFor(strategy: StrategyTransportInterface): IterableIterator<Constraint | undefined>;

@@ -21,0 +21,0 @@ yieldSegmentConstraints(segments: (Segment | undefined)[]): IterableIterator<Constraint | undefined>;

@@ -35,3 +35,3 @@ "use strict";

const feature = this.repository.getToggle(name);
const [enabled] = this.isFeatureEnabled(feature, context, fallback);
const { enabled } = this.isFeatureEnabled(feature, context, fallback);
if (feature === null || feature === void 0 ? void 0 : feature.impressionData) {

@@ -48,7 +48,8 @@ this.emit(events_2.UnleashEvents.Impression, (0, events_2.createImpressionEvent)({

isFeatureEnabled(feature, context, fallback) {
var _a;
if (!feature) {
return [fallback(), undefined];
return { enabled: fallback() };
}
if (!feature || !feature.enabled) {
return [false, undefined];
return { enabled: false };
}

@@ -58,23 +59,23 @@ if (!Array.isArray(feature.strategies)) {

this.emit(events_2.UnleashEvents.Error, new Error(msg));
return [false, undefined];
return { enabled: false };
}
if (feature.strategies.length === 0) {
return [feature.enabled, undefined];
return { enabled: feature.enabled };
}
let featureVariant = undefined;
return [(feature.strategies.length > 0 &&
feature.strategies.some((strategySelector) => {
const strategy = this.getStrategy(strategySelector.name);
if (!strategy) {
this.warnOnce(strategySelector.name, feature.name, feature.strategies);
return false;
}
const constraints = this.yieldConstraintsFor(strategySelector);
const enabled = strategy.isEnabledWithConstraints(strategySelector.parameters, context, constraints);
const variantParam = strategySelector === null || strategySelector === void 0 ? void 0 : strategySelector.variants;
if (enabled && Array.isArray(variantParam) && variantParam.length > 0) {
featureVariant = (0, variant_1.selectVariantDefinition)(feature.name, variantParam, context);
}
return enabled;
})), featureVariant];
let strategyResult = { enabled: false };
(_a = feature.strategies) === null || _a === void 0 ? void 0 : _a.some((strategySelector) => {
const strategy = this.getStrategy(strategySelector.name);
if (!strategy) {
this.warnOnce(strategySelector.name, feature.name, feature.strategies);
return false;
}
const constraints = this.yieldConstraintsFor(strategySelector);
const result = strategy.getResult(strategySelector.parameters, context, constraints, strategySelector.variants);
if (result.enabled) {
strategyResult = result;
return true;
}
return false;
});
return strategyResult;
}

@@ -132,16 +133,12 @@ *yieldConstraintsFor(strategy) {

}
let enabled = true;
let strategyVariant = undefined;
if (checkToggle) {
[enabled, strategyVariant] = this.isFeatureEnabled(feature, context, () => fallbackVariant ? fallbackVariant.enabled : false);
const result = this.isFeatureEnabled(feature, context, () => !!(fallbackVariant === null || fallbackVariant === void 0 ? void 0 : fallbackVariant.enabled));
if (result.enabled && result.variant) {
return result.variant;
}
if (!result.enabled) {
return fallback;
}
}
if (strategyVariant) {
return {
name: strategyVariant.name,
payload: strategyVariant.payload,
enabled: !checkToggle || enabled,
};
}
if (!enabled ||
!feature.variants ||
if (!feature.variants ||
!Array.isArray(feature.variants) ||

@@ -158,3 +155,3 @@ feature.variants.length === 0) {

payload: variant.payload,
enabled: !checkToggle || enabled,
enabled: true,
};

@@ -161,0 +158,0 @@ }

import { Context } from '../context';
import { VariantDefinition } from '../variant';
import { Variant, VariantDefinition } from '../variant';
export interface StrategyTransportInterface {

@@ -40,2 +40,8 @@ name: string;

export type OperatorImpl = (constraint: Constraint, context: Context) => boolean;
export type StrategyResult = {
enabled: true;
variant?: Variant;
} | {
enabled: false;
};
export declare class Strategy {

@@ -49,3 +55,4 @@ name: string;

isEnabledWithConstraints(parameters: any, context: Context, constraints: IterableIterator<Constraint | undefined>): boolean;
getResult(parameters: any, context: Context, constraints: IterableIterator<Constraint | undefined>, variants?: VariantDefinition[]): StrategyResult;
}
//# sourceMappingURL=strategy.d.ts.map

@@ -6,2 +6,3 @@ "use strict";

const helpers_1 = require("../helpers");
const variant_1 = require("../variant");
var Operator;

@@ -166,4 +167,22 @@ (function (Operator) {

}
getResult(parameters, context, constraints, variants) {
const enabled = this.isEnabledWithConstraints(parameters, context, constraints);
if (enabled && Array.isArray(variants) && variants.length > 0) {
const variantDefinition = (0, variant_1.selectVariantDefinition)(parameters.groupId, variants, context);
return variantDefinition ? {
enabled: true,
variant: {
name: variantDefinition.name,
enabled: true,
payload: variantDefinition.payload,
},
} : { enabled: true };
}
if (enabled) {
return { enabled: true };
}
return { enabled: false };
}
}
exports.Strategy = Strategy;
//# sourceMappingURL=strategy.js.map

@@ -29,5 +29,5 @@ import { Context } from './context';

export declare function getDefaultVariant(): Variant;
export declare function selectVariantDefinition(featureName: string, variants: VariantDefinition[], context: Context): VariantDefinition | null;
export declare function selectVariantDefinition(groupId: string, variants: VariantDefinition[], context: Context): VariantDefinition | null;
export declare function selectVariant(feature: FeatureInterface, context: Context): VariantDefinition | null;
export {};
//# sourceMappingURL=variant.d.ts.map

@@ -47,3 +47,3 @@ "use strict";

}
function selectVariantDefinition(featureName, variants, context) {
function selectVariantDefinition(groupId, variants, context) {
const totalWeight = variants.reduce((acc, v) => acc + v.weight, 0);

@@ -58,3 +58,3 @@ if (totalWeight <= 0) {

const { stickiness } = variants[0];
const target = (0, util_1.default)(getSeed(context, stickiness), featureName, totalWeight);
const target = (0, util_1.default)(getSeed(context, stickiness), groupId, totalWeight);
let counter = 0;

@@ -61,0 +61,0 @@ const variant = variants.find((v) => {

{
"name": "unleash-client",
"version": "4.1.0-beta.3",
"version": "4.1.0-beta.4",
"description": "Unleash Client for Node",

@@ -5,0 +5,0 @@ "license": "Apache-2.0",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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