interface IFeatureFilter { name: string; evaluate(context: IFeatureFilterEvaluationContext, appContext?: unknown): boolean | Promise; } interface IFeatureFilterEvaluationContext { featureName: string; parameters?: unknown; } /** * A feature flag is a named property that can be toggled to enable or disable some feature of an application. */ interface FeatureFlag { /** * An ID used to uniquely identify and reference the feature. */ id: string; /** * A feature is OFF if enabled is false. If enabled is true, then the feature is ON if there are no conditions (null or empty) or if the conditions are satisfied. */ enabled?: boolean; /** * The declaration of conditions used to dynamically enable the feature. */ conditions?: FeatureEnablementConditions; /** * The list of variants defined for this feature. A variant represents a configuration value of a feature flag that can be a string, a number, a boolean, or a JSON object. */ variants?: VariantDefinition[]; /** * Determines how variants should be allocated for the feature to various users. */ allocation?: VariantAllocation; /** * The declaration of options used to configure telemetry for this feature. */ telemetry?: TelemetryOptions; } /** * The declaration of conditions used to dynamically enable the feature */ interface FeatureEnablementConditions { /** * Determines whether any or all registered client filters must be evaluated as true for the feature to be considered enabled. */ requirement_type?: RequirementType; /** * Filters that must run on the client and be evaluated as true for the feature to be considered enabled. */ client_filters?: ClientFilter[]; } type RequirementType = "Any" | "All"; interface ClientFilter { /** * The name used to refer to a client filter. */ name: string; /** * Parameters for a given client filter. A client filter can require any set of parameters of any type. */ parameters?: Record; } interface VariantDefinition { /** * The name used to refer to a feature variant. */ name: string; /** * The configuration value for this feature variant. */ configuration_value?: unknown; /** * Overrides the enabled state of the feature if the given variant is assigned. Does not override the state if value is None. */ status_override?: "None" | "Enabled" | "Disabled"; } /** * Determines how variants should be allocated for the feature to various users. */ interface VariantAllocation { /** * Specifies which variant should be used when the feature is considered disabled. */ default_when_disabled?: string; /** * Specifies which variant should be used when the feature is considered enabled and no other allocation rules are applicable. */ default_when_enabled?: string; /** * A list of objects, each containing a variant name and list of users for whom that variant should be used. */ user?: UserAllocation[]; /** * A list of objects, each containing a variant name and list of groups for which that variant should be used. */ group?: GroupAllocation[]; /** * A list of objects, each containing a variant name and percentage range for which that variant should be used. */ percentile?: PercentileAllocation[]; /** * The value percentile calculations are based on. The calculated percentile is consistent across features for a given user if the same nonempty seed is used. */ seed?: string; } interface UserAllocation { /** * The name of the variant to use if the user allocation matches the current user. */ variant: string; /** * Collection of users where if any match the current user, the variant specified in the user allocation is used. */ users: string[]; } interface GroupAllocation { /** * The name of the variant to use if the group allocation matches a group the current user is in. */ variant: string; /** * Collection of groups where if the current user is in any of these groups, the variant specified in the group allocation is used. */ groups: string[]; } interface PercentileAllocation { /** * The name of the variant to use if the calculated percentile for the current user falls in the provided range. */ variant: string; /** * The lower end of the percentage range for which this variant will be used. */ from: number; /** * The upper end of the percentage range for which this variant will be used. */ to: number; } /** * The declaration of options used to configure telemetry for this feature. */ interface TelemetryOptions { /** * Indicates if telemetry is enabled. */ enabled?: boolean; /** * A container for metadata that should be bundled with flag telemetry. */ metadata?: Record; } /** * Contextual information that is required to perform a targeting evaluation. */ interface ITargetingContext { /** * The user id that should be considered when evaluating if the context is being targeted. */ userId?: string; /** * The groups that should be considered when evaluating if the context is being targeted. */ groups?: string[]; } /** * Provides access to the current targeting context. */ interface ITargetingContextAccessor { /** * Retrieves the current targeting context. */ getTargetingContext: () => ITargetingContext | undefined; } declare class Variant { name: string; configuration: unknown; constructor(name: string, configuration: unknown); } interface IFeatureManager { /** * Get the list of feature names. */ listFeatureNames(): Promise; /** * Check if a feature is enabled. * @param featureName name of the feature. * @param context an object providing information that can be used to evaluate whether a feature should be on or off. */ isEnabled(featureName: string, context?: unknown): Promise; /** * Get the allocated variant of a feature given the targeting context. * @param featureName name of the feature. * @param context a targeting context object used to evaluate which variant the user will be assigned. */ getVariant(featureName: string, context: ITargetingContext): Promise; } interface IFeatureFlagProvider { /** * Get all feature flags. */ getFeatureFlags(): Promise; /** * Get a feature flag by name. * @param featureName The name of the feature flag. */ getFeatureFlag(featureName: string): Promise; } declare class FeatureManager implements IFeatureManager { #private; constructor(provider: IFeatureFlagProvider, options?: FeatureManagerOptions); listFeatureNames(): Promise; isEnabled(featureName: string, context?: unknown): Promise; getVariant(featureName: string, context?: ITargetingContext): Promise; } interface FeatureManagerOptions { /** * The custom filters to be used by the feature manager. */ customFilters?: IFeatureFilter[]; /** * The callback function that is called when a feature flag is evaluated. * The callback function is called only when telemetry is enabled for the feature flag. */ onFeatureEvaluated?: (event: EvaluationResult) => void; /** * The accessor function that provides the @see ITargetingContext for targeting evaluation. */ targetingContextAccessor?: ITargetingContextAccessor; } declare class EvaluationResult { readonly feature: FeatureFlag | undefined; enabled: boolean; targetingId: string | undefined; variant: Variant | undefined; variantAssignmentReason: VariantAssignmentReason; constructor(feature: FeatureFlag | undefined, enabled?: boolean, targetingId?: string | undefined, variant?: Variant | undefined, variantAssignmentReason?: VariantAssignmentReason); } declare enum VariantAssignmentReason { /** * Variant allocation did not happen. No variant is assigned. */ None = "None", /** * The default variant is assigned when a feature flag is disabled. */ DefaultWhenDisabled = "DefaultWhenDisabled", /** * The default variant is assigned because of no applicable user/group/percentile allocation when a feature flag is enabled. */ DefaultWhenEnabled = "DefaultWhenEnabled", /** * The variant is assigned because of the user allocation when a feature flag is enabled. */ User = "User", /** * The variant is assigned because of the group allocation when a feature flag is enabled. */ Group = "Group", /** * The variant is assigned because of the percentile allocation when a feature flag is enabled. */ Percentile = "Percentile" } interface IGettable { get(key: string): T | undefined; } /** * A feature flag provider that uses a map-like configuration to provide feature flags. */ declare class ConfigurationMapFeatureFlagProvider implements IFeatureFlagProvider { #private; constructor(configuration: IGettable); getFeatureFlag(featureName: string): Promise; getFeatureFlags(): Promise; } /** * A feature flag provider that uses an object-like configuration to provide feature flags. */ declare class ConfigurationObjectFeatureFlagProvider implements IFeatureFlagProvider { #private; constructor(configuration: Record); getFeatureFlag(featureName: string): Promise; getFeatureFlags(): Promise; } declare function createFeatureEvaluationEventProperties(result: EvaluationResult): any; declare const VERSION = "2.3.1"; export { ConfigurationMapFeatureFlagProvider, ConfigurationObjectFeatureFlagProvider, EvaluationResult, FeatureManager, VERSION, VariantAssignmentReason, createFeatureEvaluationEventProperties }; export type { FeatureManagerOptions, IFeatureFilter, IFeatureFilterEvaluationContext, IFeatureFlagProvider, IFeatureManager, ITargetingContext, ITargetingContextAccessor };