@featurevisor/sdk
Version:
Featurevisor SDK for Node.js and the browser
68 lines (67 loc) • 3.46 kB
TypeScript
import type { Context, Feature, FeatureKey, StickyFeatures, EvaluatedFeatures, VariableValue, VariationValue, VariableKey, DatafileContent } from "@featurevisor/types";
import { Logger, LogLevel } from "./logger";
import { Hook } from "./hooks";
import { EventCallback, EventName } from "./emitter";
import { Evaluation } from "./evaluate";
import { FeaturevisorChildInstance } from "./child";
export interface OverrideOptions {
sticky?: StickyFeatures;
defaultVariationValue?: VariationValue;
defaultVariableValue?: VariableValue;
}
export interface InstanceOptions {
datafile?: DatafileContent | string;
context?: Context;
logLevel?: LogLevel;
logger?: Logger;
sticky?: StickyFeatures;
hooks?: Hook[];
}
export declare class FeaturevisorInstance {
private context;
private logger;
private sticky?;
private datafileReader;
private hooksManager;
private emitter;
constructor(options: InstanceOptions);
setLogLevel(level: LogLevel): void;
setDatafile(datafile: DatafileContent | string): void;
setSticky(sticky: StickyFeatures, replace?: boolean): void;
getRevision(): string;
getFeature(featureKey: string): Feature | undefined;
addHook(hook: Hook): () => void;
on(eventName: EventName, callback: EventCallback): () => void;
close(): void;
/**
* Context
*/
setContext(context: Context, replace?: boolean): void;
getContext(context?: Context): Context;
spawn(context?: Context, options?: OverrideOptions): FeaturevisorChildInstance;
/**
* Flag
*/
private getEvaluationDependencies;
evaluateFlag(featureKey: FeatureKey, context?: Context, options?: OverrideOptions): Evaluation;
isEnabled(featureKey: FeatureKey, context?: Context, options?: OverrideOptions): boolean;
/**
* Variation
*/
evaluateVariation(featureKey: FeatureKey, context?: Context, options?: OverrideOptions): Evaluation;
getVariation(featureKey: FeatureKey, context?: Context, options?: OverrideOptions): VariationValue | null;
/**
* Variable
*/
evaluateVariable(featureKey: FeatureKey, variableKey: VariableKey, context?: Context, options?: OverrideOptions): Evaluation;
getVariable(featureKey: FeatureKey, variableKey: string, context?: Context, options?: OverrideOptions): VariableValue | null;
getVariableBoolean(featureKey: FeatureKey, variableKey: string, context?: Context, options?: OverrideOptions): boolean | null;
getVariableString(featureKey: FeatureKey, variableKey: string, context?: Context, options?: OverrideOptions): string | null;
getVariableInteger(featureKey: FeatureKey, variableKey: string, context?: Context, options?: OverrideOptions): number | null;
getVariableDouble(featureKey: FeatureKey, variableKey: string, context?: Context, options?: OverrideOptions): number | null;
getVariableArray(featureKey: FeatureKey, variableKey: string, context?: Context, options?: OverrideOptions): string[] | null;
getVariableObject<T>(featureKey: FeatureKey, variableKey: string, context?: Context, options?: OverrideOptions): T | null;
getVariableJSON<T>(featureKey: FeatureKey, variableKey: string, context?: Context, options?: OverrideOptions): T | null;
getAllEvaluations(context?: Context, featureKeys?: string[], options?: OverrideOptions): EvaluatedFeatures;
}
export declare function createInstance(options?: InstanceOptions): FeaturevisorInstance;