import { type DbExec } from "../db/client.js"; import { type FeatureFlagDefinition } from "./registry.js"; export type FeatureFlagMode = "off" | "on" | "rules"; export interface FeatureFlagRules { version: 1; mode: FeatureFlagMode; emails: string[]; orgIds: string[]; percentage: number; updatedAt: number | null; updatedBy: string | null; } export interface FeatureFlagScope { transaction?: DbExec; userEmail?: string; userKey?: string; orgId?: string | null; } export declare const FEATURE_FLAG_SETTINGS_PREFIX = "feature-flag:"; export declare function defaultFeatureFlagRules(): FeatureFlagRules; export declare function normalizeFeatureFlagRules(value: unknown): FeatureFlagRules; export declare function getFeatureFlagRules(key: string, scope: Pick): Promise; export declare class FeatureFlagRulesError extends Error { readonly code: "unregistered" | "malformed"; readonly key: string; constructor(code: "unregistered" | "malformed", key: string, detail: string); } /** * Reads a flag's rules for callers that route data on it. Unconfigured reads * as off, like `getFeatureFlagRules`, but an unregistered key or malformed * stored rules throw `FeatureFlagRulesError` instead of normalizing to off: * for a routing flag, "off" and "unreadable" choose different write paths. */ export declare function getFeatureFlagRulesStrict(key: string, scope: Pick): Promise; export declare function getFeatureFlagRulesForKeys(keys: readonly string[], scope: Pick): Promise>; /** * Anonymous discovery hint for a rollout that may be scoped to an org. * * This deliberately answers only whether some active rollout exists. It does * not reveal the target email or organization, and callers must still run * `evaluateFeatureFlag` with the authenticated scope before granting access. * Without this separate hint, an org-only rollout is invisible to Desktop * before the user has authenticated and the org can be resolved. */ export declare function hasActiveFeatureFlagRollout(key: string): Promise; export declare function mutateFeatureFlagRules(key: string, scope: Pick, updater: (current: FeatureFlagRules) => FeatureFlagRules | Promise): Promise; export declare function evaluateFeatureFlagRules(key: string, rules: FeatureFlagRules, scope: FeatureFlagScope): boolean; export declare function evaluateFeatureFlag(key: string, scope?: FeatureFlagScope): Promise; export declare function evaluateFeatureFlagStrict(key: string, scope?: FeatureFlagScope): Promise; export declare function isFeatureFlagEnabled(flag: string | FeatureFlagDefinition, scope?: FeatureFlagScope): Promise;