featurehub-repository
Version:
Core package of API that exposes FeatureHub feature flags, values and configuration to client applications written in Typescript or Javascript.
86 lines (85 loc) • 4.12 kB
TypeScript
import { StrategyAttributeCountryName, StrategyAttributeDeviceName, StrategyAttributePlatformName } from './models';
import { FeatureStateHolder } from './feature_state';
import { FeatureHubRepository } from './client_feature_repository';
import { FeatureHubConfig, EdgeServiceSupplier } from './feature_hub_config';
import { EdgeService } from './edge_service';
import { InternalFeatureRepository } from './internal_feature_repository';
export interface ConfigChangedListener {
(config: ClientContext): any;
}
export interface ClientContext {
userKey(value: string): ClientContext;
sessionKey(value: string): ClientContext;
country(value: StrategyAttributeCountryName): ClientContext;
device(value: StrategyAttributeDeviceName): ClientContext;
platform(value: StrategyAttributePlatformName): ClientContext;
version(version: string): ClientContext;
attribute_value(key: string, value: string): ClientContext;
attribute_values(key: string, values: Array<string>): ClientContext;
clear(): ClientContext;
build(): Promise<ClientContext>;
getAttr(key: string, defaultValue: string): string;
getNumber(name: string): number | undefined;
getString(name: string): string | undefined;
getJson(name: string): any | undefined;
getRawJson(name: string): string | undefined;
getFlag(name: string): boolean | undefined;
getBoolean(name: string): boolean | undefined;
defaultPercentageKey(): string;
feature(name: string): FeatureStateHolder;
isEnabled(name: string): boolean;
isSet(name: string): boolean;
edgeService(): EdgeService;
repository(): FeatureHubRepository;
logAnalyticsEvent(action: string, other?: Map<string, string>, user?: string): any;
close(): any;
}
export declare abstract class BaseClientContext implements ClientContext {
protected readonly _repository: InternalFeatureRepository;
protected _attributes: Map<string, string[]>;
protected readonly _config: FeatureHubConfig;
protected constructor(repository: InternalFeatureRepository, config: FeatureHubConfig);
userKey(value: string): ClientContext;
sessionKey(value: string): ClientContext;
country(value: StrategyAttributeCountryName): ClientContext;
device(value: StrategyAttributeDeviceName): ClientContext;
platform(value: StrategyAttributePlatformName): ClientContext;
version(version: string): ClientContext;
attribute_value(key: string, value: string): ClientContext;
attribute_values(key: string, values: Array<string>): ClientContext;
clear(): ClientContext;
getAttr(key: string, defaultValue?: string): string;
defaultPercentageKey(): string;
isEnabled(name: string): boolean;
isSet(name: string): boolean;
getNumber(name: string): number | undefined;
getString(name: string): string | undefined;
getJson(name: string): any | undefined;
getRawJson(name: string): string | undefined;
getFlag(name: string): boolean | undefined;
getBoolean(name: string): boolean | undefined;
abstract build(): Promise<ClientContext>;
abstract feature(name: string): FeatureStateHolder;
abstract edgeService(): EdgeService;
abstract close(): any;
repository(): FeatureHubRepository;
logAnalyticsEvent(action: string, other?: Map<string, string>, user?: string): void;
}
export declare class ServerEvalFeatureContext extends BaseClientContext {
private readonly _edgeServiceSupplier;
private _currentEdge;
private _xHeader;
constructor(repository: InternalFeatureRepository, config: FeatureHubConfig, edgeServiceSupplier: EdgeServiceSupplier);
build(): Promise<ClientContext>;
close(): void;
edgeService(): EdgeService;
feature(name: string): FeatureStateHolder;
}
export declare class ClientEvalFeatureContext extends BaseClientContext {
private readonly _edgeService;
constructor(repository: InternalFeatureRepository, config: FeatureHubConfig, edgeService: EdgeService);
build(): Promise<ClientContext>;
close(): void;
edgeService(): EdgeService;
feature(name: string): FeatureStateHolder;
}