import type { GatewayApiEnvelope, GatewayErrorObject } from '@xopcai/gateway-contract'; import type { Context, Env, Hono, MiddlewareHandler } from 'hono'; import type { ContentfulStatusCode } from 'hono/utils/http-status'; import type { z } from 'zod'; export type HttpMethod = 'get' | 'post' | 'put' | 'patch' | 'delete'; export type GatewayRouteErrorFormat = 'envelope' | 'legacy-error-string' | 'legacy-ok-error-string' | 'legacy-error-object'; export type GatewayRouteBodyParseMode = 'required' | 'optional-json' | 'lenient-json'; export type GatewayRouteValidationFailure = { kind: 'invalid_json'; message: string; } | { kind: 'invalid_query'; message: string; error: z.ZodError; } | { kind: 'invalid_body'; message: string; error: z.ZodError; }; export interface DefinedGatewayRouteMetadata { method: HttpMethod; path: string; samplePath: string; bundleId?: string | null; hasBodySchema: boolean; hasQuerySchema: boolean; } type InferOptionalZod = [ TSchema ] extends [z.ZodType] ? z.ZodType extends TSchema ? undefined : z.infer : undefined; export interface GatewayRouteSpec { method: HttpMethod; path: TPath; /** * Owning lazy route bundle id, or `null` when eagerly registered on the core authenticated router. */ bundleId?: string | null; /** * Optional concrete path override for lazy-bundle verification when route params have format constraints. */ samplePath?: string; middleware?: MiddlewareHandler | readonly (MiddlewareHandler | undefined)[]; beforeValidate?: (c: Context) => Promise | Response | void; bodySchema?: TBodySchema; bodyParseMode?: GatewayRouteBodyParseMode; querySchema?: TQuerySchema; errorFormat?: GatewayRouteErrorFormat; onInvalidRequest?: (c: Context, failure: GatewayRouteValidationFailure) => Response | Promise; handler: (ctx: { c: Context; body: InferOptionalZod; query: InferOptionalZod; }) => Promise> | Response | GatewayApiEnvelope; } export declare function materializeGatewayRoutePath(routePath: string, explicitSamplePath?: string): string; export declare function recordDefinedGatewayRoute(app: Hono, metadata: DefinedGatewayRouteMetadata): void; export declare function getDefinedGatewayRoutes(app?: Hono): readonly DefinedGatewayRouteMetadata[]; export declare function clearDefinedGatewayRoutesForTests(): void; export declare function gatewayOk(c: Context, payload: T, status?: ContentfulStatusCode): Response; export declare function gatewayFail(c: Context, error: GatewayErrorObject | string, status?: ContentfulStatusCode): Response; /** * Contract-first route helper that validates JSON bodies and query parameters * with Zod schemas from `@xopcai/gateway-contract` before invoking the handler. */ export declare function defineGatewayRoute(app: Hono, spec: GatewayRouteSpec): void; export {};