@featurevisor/sdk
Version:
Featurevisor SDK for Node.js and the browser
100 lines (99 loc) • 4.42 kB
TypeScript
import { Context, DatafileContent, Feature, FeatureKey, InitialFeatures, StickyFeatures, VariableType, VariableValue, VariationValue, VariableKey } from "@featurevisor/types";
import { Logger, LogLevel } from "./logger";
import { Emitter } from "./emitter";
import { ConfigureBucketKey, ConfigureBucketValue } from "./bucket";
import { Evaluation } from "./evaluate";
export type ReadyCallback = () => void;
export type ActivationCallback = (featureName: string, variation: VariationValue, context: Context, captureContext: Context) => void;
export interface Statuses {
ready: boolean;
refreshInProgress: boolean;
}
export type InterceptContext = (context: Context) => Context;
export interface InstanceOptions {
bucketKeySeparator?: string;
configureBucketKey?: ConfigureBucketKey;
configureBucketValue?: ConfigureBucketValue;
datafile?: DatafileContent | string;
datafileUrl?: string;
handleDatafileFetch?: (datafileUrl: string) => Promise<DatafileContent>;
initialFeatures?: InitialFeatures;
interceptContext?: InterceptContext;
logger?: Logger;
onActivation?: ActivationCallback;
onReady?: ReadyCallback;
onRefresh?: () => void;
onUpdate?: () => void;
refreshInterval?: number;
stickyFeatures?: StickyFeatures;
}
export type DatafileFetchHandler = (datafileUrl: string) => Promise<DatafileContent>;
type FieldType = string | VariableType;
type ValueType = VariableValue;
export declare function getValueByType(value: ValueType, fieldType: FieldType): ValueType;
export declare class FeaturevisorInstance {
private bucketKeySeparator;
private configureBucketKey?;
private configureBucketValue?;
private datafileUrl?;
private handleDatafileFetch?;
private initialFeatures?;
private interceptContext?;
private logger;
private refreshInterval?;
private stickyFeatures?;
private datafileReader;
private emitter;
private statuses;
private intervalId?;
on: Emitter["addListener"];
addListener: Emitter["addListener"];
off: Emitter["removeListener"];
removeListener: Emitter["removeListener"];
removeAllListeners: Emitter["removeAllListeners"];
constructor(options: InstanceOptions);
setLogLevels(levels: LogLevel[]): void;
onReady(): Promise<FeaturevisorInstance>;
setDatafile(datafile: DatafileContent | string): void;
setStickyFeatures(stickyFeatures: StickyFeatures | undefined): void;
getRevision(): string;
getFeature(featureKey: string | Feature): Feature | undefined;
/**
* Statuses
*/
isReady(): boolean;
/**
* Refresh
*/
refresh(): void;
startRefreshing(): void;
stopRefreshing(): void;
/**
* Flag
*/
evaluateFlag(featureKey: FeatureKey | Feature, context?: Context): Evaluation;
isEnabled(featureKey: FeatureKey | Feature, context?: Context): boolean;
/**
* Variation
*/
evaluateVariation(featureKey: FeatureKey | Feature, context?: Context): Evaluation;
getVariation(featureKey: FeatureKey | Feature, context?: Context): VariationValue | undefined;
/**
* Activate
*/
activate(featureKey: FeatureKey, context?: Context): VariationValue | undefined;
/**
* Variable
*/
evaluateVariable(featureKey: FeatureKey | Feature, variableKey: VariableKey, context?: Context): Evaluation;
getVariable(featureKey: FeatureKey | Feature, variableKey: string, context?: Context): VariableValue | undefined;
getVariableBoolean(featureKey: FeatureKey | Feature, variableKey: string, context?: Context): boolean | undefined;
getVariableString(featureKey: FeatureKey | Feature, variableKey: string, context?: Context): string | undefined;
getVariableInteger(featureKey: FeatureKey | Feature, variableKey: string, context?: Context): number | undefined;
getVariableDouble(featureKey: FeatureKey | Feature, variableKey: string, context?: Context): number | undefined;
getVariableArray(featureKey: FeatureKey | Feature, variableKey: string, context?: Context): string[] | undefined;
getVariableObject<T>(featureKey: FeatureKey | Feature, variableKey: string, context?: Context): T | undefined;
getVariableJSON<T>(featureKey: FeatureKey | Feature, variableKey: string, context?: Context): T | undefined;
}
export declare function createInstance(options: InstanceOptions): FeaturevisorInstance;
export {};