UNPKG

unleash-server

Version:

Unleash is an enterprise ready feature flag service. It provides different strategies for handling feature flags.

49 lines 2.19 kB
import Client from './client.js'; import Repository from './repository/index.js'; import { Strategy, defaultStrategies } from './strategy/index.js'; import { createFallbackFunction } from './helpers.js'; import { resolveBootstrapProvider, } from './repository/bootstrap-provider.js'; import InMemStorageProvider from './repository/storage-provider-in-mem.js'; export { Strategy }; export class FeatureEvaluator { constructor({ appName, environment = 'default', strategies = [], repository, bootstrap = { data: [] }, storageProvider = new InMemStorageProvider(), }) { this.staticContext = { appName, environment }; const bootstrapProvider = resolveBootstrapProvider(bootstrap); this.repository = repository || new Repository({ appName, bootstrapProvider, storageProvider, }); // setup client const supportedStrategies = strategies.concat(defaultStrategies); this.client = new Client(this.repository, supportedStrategies); } async start() { return this.repository.start(); } destroy() { this.repository.stop(); } isEnabled(name, context = {}, fallback) { const enhancedContext = { ...this.staticContext, ...context }; const fallbackFunc = createFallbackFunction(name, enhancedContext, fallback); return this.client.isEnabled(name, enhancedContext, fallbackFunc); } getVariant(name, context = {}, fallbackVariant) { const enhancedContext = { ...this.staticContext, ...context }; return this.client.getVariant(name, enhancedContext, fallbackVariant); } forceGetVariant(name, forcedResults, context = {}, fallbackVariant) { const enhancedContext = { ...this.staticContext, ...context }; return this.client.forceGetVariant(name, enhancedContext, forcedResults, fallbackVariant); } getFeatureToggleDefinition(toggleName) { return this.repository.getToggle(toggleName); } getFeatureToggleDefinitions() { return this.repository.getToggles(); } } //# sourceMappingURL=feature-evaluator.js.map