import { LimenError } from "./errors.mjs"; import { HTTPMethod } from "./types.mjs"; import { FetchOptions } from "./plugin.mjs"; import { RouteContext } from "./context.mjs"; //#region src/route.d.ts declare const INPUT: unique symbol; declare const OUTPUT: unique symbol; /** * Runs the route's default HTTP request and parser without session effects. * Pass an input override when a handler needs to omit client-only fields. */ type HttpRunner = (input?: I) => Promise; /** * Custom route behavior for flows that need more than the default request * pipeline. */ type RouteHandler = (ctx: RouteContext, input: I, http: HttpRunner) => Promise; /** Options accepted as the final argument of every route method. */ type RouteCallOptions = FetchOptions & { /** Invoked with the resolved value after the call succeeds. */onSuccess?: (data: O) => void; /** Invoked with the error just before it is re-thrown. */ onError?: (error: LimenError) => void; }; /** * Declarative client route definition. The public client chain is derived from * `path` unless `as` is provided. */ type RouteDef = { method: HTTPMethod; path: `/${string}`; /** Dotted client chain override, e.g. `"twoFactor.getTotpUri"`. */ as?: string; /** Merged under the caller's input before serialization. */ defaults?: Partial; /** SDK input → wire body/query. Defaults to shallow camelCase → snake_case. */ serialize?: (input: I) => unknown; /** Raw response → typed output. Ignored when `parseSession` is set. */ parse?: (raw: unknown) => O; /** * Parse the response as a session and store it when it contains a `user`. * Set `skipStore` to return the parsed session without writing it. */ parseSession?: boolean; /** Resolve `path` from the client base path instead of the plugin base path. */ absolute?: boolean; /** Input keys used as `:param` path values. */ params?: readonly (keyof I & string)[]; /** For `parseSession` routes, skip the session-store write. */ skipStore?: boolean; /** Clear the session store on success. */ clearSession?: boolean; /** Revalidate the session after success. */ refetchSession?: boolean; /** Set `false` to keep the route out of the public client API. */ expose?: boolean; /** Override the default route call behavior. */ handler?: RouteHandler; }; /** * A route definition carrying its input and output types for inference. */ type RouteDescriptor = RouteDef> = D & { readonly [INPUT]: I; readonly [OUTPUT]: O; }; /** * Loose route-descriptor constraint for route tuples and plugin definitions. */ type AnyRouteDescriptor = RouteDescriptor; type InputOf = R extends { readonly [INPUT]: infer I; } ? I : never; type OutputOf = R extends { readonly [OUTPUT]: infer O; } ? O : never; /** * Define an HTTP-backed client method for a plugin. The input/output types * become the generated method's argument and resolved value. * * @example * route>()({ * method: "POST", * path: "/verify", * parseSession: true, * }) */ declare function route(): >(def: D) => RouteDescriptor; //#endregion export { AnyRouteDescriptor, HttpRunner, InputOf, OutputOf, RouteCallOptions, RouteDescriptor, RouteHandler, route };