@happykit/flags
Version:
Feature Flags for Next.js
145 lines (143 loc) • 4 kB
TypeScript
declare type VariantFlagResolution = {
mode: "variant";
variant: string;
};
declare type Condition = {
id: string;
group: "visitor";
lhs: "key";
operator: "equal-to" | "not-equal-to" | "starts-with" | "ends-with";
rhs: string;
} | {
id: string;
group: "visitor";
lhs: "key" | "language" | "country" | "referrer" | "timeZone";
operator: "set" | "not-set";
} | {
id: string;
group: "user";
lhs: "key" | "email" | "name" | "language" | "country";
operator: "set" | "not-set";
} | {
id: string;
group: "user";
lhs: "key" | "email" | "name" | "language" | "country";
operator: "equal-to" | "not-equal-to" | "starts-with" | "ends-with";
rhs: string;
} | {
id: string;
group: "user";
lhs: "authentication";
operator: "authenticated" | "not-authenticated";
} | {
id: string;
group: "traits";
lhs: string;
operator: "set" | "not-set";
} | {
id: string;
group: "traits";
lhs: string;
operator: "equal-to" | "not-equal-to" | "starts-with" | "ends-with";
rhs: string;
};
declare type FlagRule = {
id: string;
conditions: Condition[];
resolution: FlagResolution;
};
interface BaseRolloutFlagResolution {
/**
* This property does not do anything on rollouts.
* It might still be around due to inconsistent data, which
* can happen due to the form submitting wrong data.
*/
variant?: string;
mode: "rollout";
variants: Record<string, {
weight: number;
}>;
}
interface VisitorRolloutFlagResolution extends BaseRolloutFlagResolution {
bucketByCategory: "visitor";
bucketByUserAttribute?: never;
bucketByTrait?: never;
}
interface UserRolloutFlagResolution extends BaseRolloutFlagResolution {
bucketByCategory: "user";
bucketByUserAttribute: "key" | "email" | "name" | "country";
bucketByTrait?: never;
}
interface TraitRolloutFlagResolution extends BaseRolloutFlagResolution {
bucketByCategory: "trait";
bucketByUserAttribute?: never;
bucketByTrait: string;
}
declare type RolloutFlagResolution = UserRolloutFlagResolution | VisitorRolloutFlagResolution | TraitRolloutFlagResolution;
declare type FlagResolution = VariantFlagResolution | RolloutFlagResolution;
declare type EnvironmentConfiguration = {
active: boolean;
fallthrough: FlagResolution;
offVariation: string;
/**
* Keys are variantIds, values are keys of users targeted by that flag
*/
targets: Record<string, {
values: string[];
}>;
rules: FlagRule[];
};
interface BaseFlag {
kind: "boolean" | "number" | "string";
id: string;
projectId: string;
slug: string;
production: EnvironmentConfiguration;
preview: EnvironmentConfiguration;
development: EnvironmentConfiguration;
variants: BooleanVariant[] | NumberVariant[] | StringVariant[];
}
interface BaseVariant {
id: string;
value: string | number | boolean;
}
interface BooleanVariant extends BaseVariant {
value: boolean;
}
interface NumberVariant extends BaseVariant {
value: number;
}
interface StringVariant extends BaseVariant {
value: string;
}
interface BooleanFlag extends BaseFlag {
kind: "boolean";
variants: BooleanVariant[];
}
interface NumberFlag extends BaseFlag {
kind: "number";
variants: NumberVariant[];
}
interface StringFlag extends BaseFlag {
kind: "string";
variants: StringVariant[];
}
declare type Flag = BooleanFlag | NumberFlag | StringFlag;
declare type FlagUserAttributes = {
key: string;
email?: string;
name?: string;
avatar?: string;
language?: string;
timeZone?: string;
country?: string;
};
declare type FlagVisitor = {
key: string;
};
declare type FlagVariant = {
id: string;
value: string | number | boolean;
};
declare type Environment = "development" | "preview" | "production";
export { Environment as E, Flag as F, FlagUserAttributes as a, FlagVisitor as b, FlagVariant as c };