import { FlagManager } from './engine/manager.js'; import { u as FlagContext, c as AuditActor } from './types-YdF1AOxp.js'; import './core/logger.js'; import './core/metrics.js'; import './core/flag-types.js'; interface RolleasePublicClientKeyConfig { /** Explicit flag keys this public key can evaluate. */ flags?: string[]; /** Environment names this public key can evaluate. */ environments?: string[]; /** Require flags to be marked `clientVisible`. Defaults to true. */ requireClientVisible?: boolean; /** Server-owned context merged over caller-supplied context. */ context?: FlagContext | ((req: Request) => FlagContext | Promise); } interface RolleaseHandlerOptions { /** * Extract the caller's FlagContext from the incoming Request. * Required for flag evaluation endpoints. When omitted, the handler falls * back to the `X-Rollease-Context` header (base64url-encoded JSON). */ contextFromRequest?: (req: Request) => FlagContext | Promise; /** * Authorize admin (write) routes: flag CRUD, history. * Return true to allow; return false / throw to reject with 401. */ adminAuth?: (req: Request) => boolean | Promise; /** * Extract the actor from the incoming admin request. The actor is passed to * all manager write methods so RBAC hooks receive it for permission checking. * * Example: extract actor from a verified JWT or session: * ```ts * extractActor: async (req) => { * const payload = await verifyJWT(req.headers.get('authorization')) * return { id: payload.sub, type: 'user', name: payload.name } * } * ``` */ extractActor?: (req: Request) => AuditActor | undefined | Promise; /** * The path prefix where this handler is mounted. * Used to strip the base from the URL before route matching. * @default '/api/rollease' */ basePath?: string; /** * CORS origin to include in responses. Use `false` to disable CORS headers. * @default '*' */ cors?: string | false; /** * Public browser/client keys. When provided, public evaluation and event * routes require `X-Rollease-Client-Key` or `?clientKey=...`. */ clientKeys?: Record; /** * Authorize the health endpoint. When not provided, `GET /health` is public. * Return true to allow; false to reject with 401. */ healthAuth?: (req: Request) => boolean | Promise; /** * Restrict admin (write) endpoints to a fixed set of client IPs / CIDR * ranges. When provided, requests from IPs not on the list receive 403 * before `adminAuth` even runs. CIDR notation is supported for IPv4 only * (e.g. `"10.0.0.0/8"`). Single IPs match literally. * * The client IP is read from these headers in order: * `cf-connecting-ip`, `x-real-ip`, `x-forwarded-for` (first entry). * Falls back to allowing the request only when no proxy header is present * AND the allowlist is configured to permit local development (omit this * option in production). */ adminIPAllowlist?: string[]; /** * Override how the client IP is extracted from the request. Useful for * custom proxy header schemes (e.g. AWS ALB's `x-amzn-trace-id`). * Defaults to checking cf-connecting-ip → x-real-ip → x-forwarded-for. */ getClientIP?: (req: Request) => string | undefined; } /** A fetch-compatible Rollease HTTP handler. Pass directly as a Next.js route handler. */ type RolleaseHandler = (req: Request) => Promise; declare function createRolleaseHandler(manager: FlagManager, options?: RolleaseHandlerOptions): RolleaseHandler; export { type RolleaseHandler, type RolleaseHandlerOptions, type RolleasePublicClientKeyConfig, createRolleaseHandler };