import { O as OnErrorHook } from '../_dts-chunks/on-error.d-DGMUFaZB.d.ts'; import '../_dts-chunks/nextly-error.d-WlStqaV9.d.ts'; import '../_dts-chunks/error-codes.d-CbwkO1ux.d.ts'; type WithErrorHandlerOptions = { /** Per-call observability hook. Fired before the global hook. */ onError?: OnErrorHook; /** Public message used when wrapping unknown errors. Default: generic. */ internalErrorMessage?: string; }; /** * HTTP boundary wrapper for Next.js App Router Route Handlers. * * Responsibilities (in order, per spec §11.2): * 1. Read or generate a Stripe-style `requestId` for this request. * 2. Run the handler. * 3. On thrown values: pass Next.js sentinel errors (`redirect`, `notFound`, * dynamic-API bailouts) through `unstable_rethrow` first. * 4. Otherwise classify: `NextlyError` directly, `DbError` via the safety * net, anything else wrapped as `NextlyError.internal`. * 5. Log the classified error. * 6. Fire the per-call `onError` hook, then the global one. Hook failures * are logged but never poison the response. * 7. Serialize via `toResponseJSON(requestId)` with `application/problem+json` * content type, the response status, and `X-Request-Id`. `Retry-After` * is set for `RATE_LIMITED`. * * Generic over `TArgs` so it transparently supports both static handlers * (`(req)`) and dynamic-segment handlers (`(req, { params })`). */ declare function withErrorHandler(handler: (...args: TArgs) => Promise, options?: WithErrorHandlerOptions): (...args: TArgs) => Promise; /** * Stripe-style request IDs (`req_<16 base32 chars>`) for the unified error * system. Generated at the boundary by withErrorHandler / withAction unless * an upstream proxy already set `x-request-id` (or one of the cloud-provider * variants Vercel and Cloudflare emit), in which case we honor it so a * single user request shares one id across all hops. * * Format: `req_` prefix + 16 chars of RFC 4648 base32-lowercase. 10 random * bytes provide 80 bits of entropy — uniquely identifying every request at * any reasonable scale. * * Works in both Node and Edge runtimes (uses Web Crypto's * `crypto.getRandomValues`). */ declare function generateRequestId(): string; /** * Read an upstream-set request id, falling back to a freshly generated one. * Header precedence (most-specific first): `x-request-id` (our convention) > * `x-vercel-id` (Vercel) > `cf-ray` (Cloudflare). */ declare function readOrGenerateRequestId(req: Request): string; export { generateRequestId, readOrGenerateRequestId, withErrorHandler };