import { z } from 'zod'; declare const ErrorCodes: Readonly<{ readonly VALIDATION_FAILED: { readonly code: "VALIDATION_FAILED"; readonly status: 400; }; readonly UNAUTHORIZED: { readonly code: "UNAUTHORIZED"; readonly status: 401; }; readonly FORBIDDEN: { readonly code: "FORBIDDEN"; readonly status: 403; }; readonly PERMISSION_DENIED: { readonly code: "PERMISSION_DENIED"; readonly status: 403; }; readonly NOT_FOUND: { readonly code: "NOT_FOUND"; readonly status: 404; }; readonly CONFLICT: { readonly code: "CONFLICT"; readonly status: 409; }; readonly RATE_LIMITED: { readonly code: "RATE_LIMITED"; readonly status: 429; }; readonly INTERNAL_ERROR: { readonly code: "INTERNAL_ERROR"; readonly status: 500; }; }>; type ErrorCode = keyof typeof ErrorCodes; type AuthMode = 'none' | 'api_key'; interface ApiKey { id: string; key_hash: string; key_prefix: string; label: string; description?: string; scopes: string[]; user_id?: string; created_at: string; last_used_at?: string; revoked_at?: string; } interface IssuedApiKey { api_key: ApiKey; raw_key: string; } type ApiKeyValidator = (raw_key: string) => Promise; interface ApiKeyService { issue(input: { label: string; scopes?: string[]; user_id?: string; description?: string; }): Promise; list(filter?: { user_id?: string; include_revoked?: boolean; }): Promise; update(id: string, patch: { label?: string; description?: string; }): Promise; revoke(id: string): Promise; enable(id: string): Promise; validate(raw_key: string): Promise; } interface WithApiKeyOptions { service?: ApiKeyService; verify?: ApiKeyValidator; require_scopes?: string[]; bind_user?: boolean; } interface RateLimitConsumeInput { bucket_key: string; capacity: number; refill_rate: number; cost?: number; } interface RateLimitResult { allowed: boolean; /** * Whole tokens currently available in the bucket. * * On denial (`allowed: false`), this is the leftover token count at the * moment of denial, NOT necessarily 0 — e.g. with `cost > 1`, a bucket * can hold 2 tokens, deny a `cost: 3` request, and report * `remaining: 2`. Do not treat `remaining === 0` as "bucket fully * exhausted"; check `allowed` for that. */ remaining: number; retry_after_sec: number; } interface RateLimitService { consume(input: RateLimitConsumeInput): Promise; } interface WithRateLimitOptions { service: RateLimitService; bucket_key: (req: Request) => string; limit: number; window_sec: number; cost?: number; } interface ResponseMeta { version: string; request_id: string; elapsed_ms: number; env: string; headers?: Record; } interface ErrorBody { code: ErrorCode; message: string; details?: unknown; } interface OkResponse { ok: true; data: T; meta: ResponseMeta; } interface FailResponse { ok: false; error: ErrorBody; meta: ResponseMeta; } type EnvelopeResponse = OkResponse | FailResponse; type HttpMethod = 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE'; interface RouteResponseSpec { description: string; schema?: z.ZodType; } interface RouteDefinition { method: HttpMethod; path: string; summary: string; description?: string; tags?: string[]; request?: { body?: z.ZodType; query?: z.ZodType; params?: z.ZodType; }; responses: Record; auth?: AuthMode; _responseType?: TResp; } type OpenAPIObject = Record; /** * Canonical shape carried in the `error.details` field of a FORBIDDEN (or the * legacy PERMISSION_DENIED alias) response envelope when a permission check fails. * Type-only + client-safe (no runtime, no Node imports). */ interface PermissionFailureDetails { /** The permission keys the caller was missing, e.g. ["env.migrate"]. */ missing_permissions: string[]; /** Optional human descriptions keyed by permission key. */ permission_descriptions?: Record; /** Optional scope the check was evaluated against. */ scope_id?: string; } export { type ApiKey as A, type EnvelopeResponse as E, type FailResponse as F, type HttpMethod as H, type IssuedApiKey as I, type OkResponse as O, type PermissionFailureDetails as P, type ResponseMeta as R, type WithApiKeyOptions as W, type ApiKeyValidator as a, type AuthMode as b, type ErrorBody as c, type ErrorCode as d, type OpenAPIObject as e, type RouteDefinition as f, type RouteResponseSpec as g, type ApiKeyService as h, type RateLimitService as i, type WithRateLimitOptions as j, ErrorCodes as k, type RateLimitConsumeInput as l, type RateLimitResult as m };