configcat-common
Version:
ConfigCat is a configuration as a service that lets you manage your features and configurations without actually deploying new code.
226 lines • 11.7 kB
TypeScript
import type * as ConfigJson from "./ConfigJson";
import type { PrerequisiteFlagComparator, RedirectMode, SegmentComparator, SettingType, UserComparator } from "./ConfigJson";
export declare class ProjectConfig {
readonly configJson: string | undefined;
readonly config: Config | undefined;
readonly timestamp: number;
readonly httpETag: string | undefined;
static readonly serializationFormatVersion = "v2";
static readonly empty: ProjectConfig;
static equals(projectConfig1: ProjectConfig, projectConfig2: ProjectConfig): boolean;
constructor(configJson: string | undefined, config: Config | undefined, timestamp: number, httpETag: string | undefined);
with(timestamp: number): ProjectConfig;
get isEmpty(): boolean;
isExpired(expirationMs: number): boolean;
static generateTimestamp(): number;
static serialize(config: ProjectConfig): string;
static deserialize(value: string): ProjectConfig;
}
/** Details of a ConfigCat config. */
export interface IConfig {
/** The salt that was used to hash sensitive comparison values. */
readonly salt: string | undefined;
/** The array of segments. */
readonly segments: ReadonlyArray<ISegment>;
/** The key-value map of settings. */
readonly settings: Readonly<{
[]: ISettingUnion;
}>;
}
export declare class Config implements IConfig {
static deserialize(configJson: string): Config;
readonly preferences: Preferences | undefined;
readonly segments: ReadonlyArray<Segment>;
readonly settings: Readonly<{
[]: SettingUnion;
}>;
constructor(json: Partial<ConfigJson.Config>);
get salt(): string | undefined;
}
export declare class Preferences {
readonly baseUrl: string | undefined;
readonly redirectMode: RedirectMode | undefined;
readonly salt: string | undefined;
constructor(json: ConfigJson.Preferences);
}
/** Describes a segment. */
export interface ISegment {
/** The name of the segment. */
readonly name: string;
/** The array of segment rule conditions (where there is a logical AND relation between the items). */
readonly conditions: ReadonlyArray<IUserConditionUnion>;
}
export declare class Segment implements ISegment {
readonly name: string;
readonly conditions: ReadonlyArray<UserConditionUnion>;
constructor(json: ConfigJson.Segment);
}
export declare type SettingTypeMap = {
[]: boolean;
[]: string;
[]: number;
[]: number;
};
export declare type SettingValue = SettingTypeMap[SettingType] | null | undefined;
export declare type VariationIdValue = string | null | undefined;
/** A model object which contains a setting value along with related data. */
export interface ISettingValueContainer<TSetting extends SettingType = SettingType> {
/** Setting value. */
readonly value: SettingTypeMap[TSetting];
/** Variation ID. */
readonly variationId?: NonNullable<VariationIdValue>;
}
export declare class SettingValueContainer<TSetting extends SettingType = SettingType> implements ISettingValueContainer<TSetting> {
readonly value: SettingTypeMap[TSetting];
readonly variationId?: NonNullable<VariationIdValue>;
constructor(json: ConfigJson.ServedValue, hasUnwrappedValue?: boolean);
}
export declare type ISettingUnion = {
[]: ISetting<K>;
}[SettingType];
/** Feature flag or setting. */
export interface ISetting<TSetting extends SettingType = SettingType> extends ISettingValueContainer<TSetting> {
/** Setting type. */
readonly type: TSetting;
/** The User Object attribute which serves as the basis of percentage options evaluation. */
readonly percentageOptionsAttribute: string;
/** The array of targeting rules (where there is a logical OR relation between the items). */
readonly targetingRules: ReadonlyArray<ITargetingRule<TSetting>>;
/** The array of percentage options. */
readonly percentageOptions: ReadonlyArray<IPercentageOption<TSetting>>;
}
export declare type SettingUnion = {
[]: Setting<K>;
}[SettingType];
export declare class Setting<TSetting extends SettingType = SettingType> extends SettingValueContainer<TSetting> implements ISetting<TSetting> {
readonly type: TSetting;
readonly percentageOptionsAttribute: string;
readonly targetingRules: ReadonlyArray<TargetingRule<TSetting>>;
readonly percentageOptions: ReadonlyArray<PercentageOption<TSetting>>;
readonly configJsonSalt: string;
constructor(json: ConfigJson.Setting<TSetting>, config?: Config);
static fromValue(value: NonNullable<SettingValue>): Setting;
}
/** Describes a targeting rule. */
export interface ITargetingRule<TSetting extends SettingType = SettingType> {
/** The array of conditions that are combined with the AND logical operator. (The IF part of the targeting rule.) */
readonly conditions: ReadonlyArray<IConditionUnion>;
/** The simple value or the array of percentage options associated with the targeting rule. (The THEN part of the targeting rule.) */
readonly then: ISettingValueContainer<TSetting> | ReadonlyArray<IPercentageOption<TSetting>>;
}
export declare class TargetingRule<TSetting extends SettingType = SettingType> implements ITargetingRule<TSetting> {
readonly conditions: ReadonlyArray<ConditionUnion>;
readonly then: SettingValueContainer<TSetting> | ReadonlyArray<PercentageOption<TSetting>>;
constructor(json: ConfigJson.TargetingRule<TSetting>, config: Config);
}
/** Represents a percentage option. */
export interface IPercentageOption<TSetting extends SettingType = SettingType> extends ISettingValueContainer<TSetting> {
/** A number between 0 and 100 that represents a randomly allocated fraction of the users. */
readonly percentage: number;
}
export declare class PercentageOption<TSetting extends SettingType = SettingType> extends SettingValueContainer<TSetting> implements IPercentageOption<TSetting> {
readonly percentage: number;
constructor(json: ConfigJson.PercentageOption<TSetting>);
}
export declare type ConditionTypeMap = {
["UserCondition"]: IUserConditionUnion;
["PrerequisiteFlagCondition"]: IPrerequisiteFlagCondition;
["SegmentCondition"]: ISegmentCondition;
};
export declare type IConditionUnion = ConditionTypeMap[keyof ConditionTypeMap];
/** Represents a condition. */
export interface ICondition<TCondition extends keyof ConditionTypeMap = keyof ConditionTypeMap> {
/** The type of the condition. */
readonly type: TCondition;
}
export declare type ConditionUnion = UserConditionUnion | PrerequisiteFlagCondition | SegmentCondition;
export declare type UserConditionComparisonValueTypeMap = {
[]: Readonly<string[]>;
[]: Readonly<string[]>;
[]: Readonly<string[]>;
[]: Readonly<string[]>;
[]: Readonly<string[]>;
[]: Readonly<string[]>;
[]: string;
[]: string;
[]: string;
[]: string;
[]: number;
[]: number;
[]: number;
[]: number;
[]: number;
[]: number;
[]: Readonly<string[]>;
[]: Readonly<string[]>;
[]: number;
[]: number;
[]: string;
[]: string;
[]: Readonly<string[]>;
[]: Readonly<string[]>;
[]: Readonly<string[]>;
[]: Readonly<string[]>;
[]: Readonly<string[]>;
[]: Readonly<string[]>;
[]: string;
[]: string;
[]: Readonly<string[]>;
[]: Readonly<string[]>;
[]: Readonly<string[]>;
[]: Readonly<string[]>;
[]: Readonly<string[]>;
[]: Readonly<string[]>;
};
export declare type IUserConditionUnion = {
[]: IUserCondition<K>;
}[UserComparator];
/** Describes a condition that is based on a User Object attribute. */
export interface IUserCondition<TComparator extends UserComparator = UserComparator> extends ICondition<"UserCondition"> {
/** The User Object attribute that the condition is based on. Can be "Identifier", "Email", "Country" or any custom attribute. */
readonly comparisonAttribute: string;
/** The operator which defines the relation between the comparison attribute and the comparison value. */
readonly comparator: TComparator;
/** The value that the User Object attribute is compared to. */
readonly comparisonValue: UserConditionComparisonValueTypeMap[TComparator];
}
export declare type UserConditionUnion = {
[]: UserCondition<K>;
}[UserComparator];
export declare class UserCondition<TComparator extends UserComparator = UserComparator> implements IUserCondition<TComparator> {
readonly type = "UserCondition";
readonly comparisonAttribute: string;
readonly comparator: TComparator;
readonly comparisonValue: UserConditionComparisonValueTypeMap[TComparator];
constructor(json: ConfigJson.UserCondition<TComparator>);
}
/** Describes a condition that is based on a prerequisite flag. */
export interface IPrerequisiteFlagCondition extends ICondition<"PrerequisiteFlagCondition"> {
/** The key of the prerequisite flag that the condition is based on. */
readonly prerequisiteFlagKey: string;
/** The operator which defines the relation between the evaluated value of the prerequisite flag and the comparison value. */
readonly comparator: PrerequisiteFlagComparator;
/** The value that the evaluated value of the prerequisite flag is compared to. */
readonly comparisonValue: NonNullable<SettingValue>;
}
export declare class PrerequisiteFlagCondition implements IPrerequisiteFlagCondition {
readonly type = "PrerequisiteFlagCondition";
readonly prerequisiteFlagKey: string;
readonly comparator: PrerequisiteFlagComparator;
readonly comparisonValue: NonNullable<SettingValue>;
constructor(json: ConfigJson.PrerequisiteFlagCondition);
}
/** Describes a condition that is based on a segment. */
export interface ISegmentCondition extends ICondition<"SegmentCondition"> {
/** The segment that the condition is based on. */
readonly segment: ISegment;
/** The operator which defines the expected result of the evaluation of the segment. */
readonly comparator: SegmentComparator;
}
export declare class SegmentCondition implements ISegmentCondition {
readonly type = "SegmentCondition";
readonly segment: Segment;
readonly comparator: SegmentComparator;
constructor(json: ConfigJson.SegmentCondition, config: Config);
}
//# sourceMappingURL=ProjectConfig.d.ts.map