import type { Context, Env, MiddlewareHandler, ValidationTargets } from 'hono'; import type { HasRequiredKeys } from 'hono/utils/types'; import { type DescribeRouteOptions, type ResponsesWithResolver } from 'hono-openapi'; import * as z from 'zod/mini'; import * as Response from './Response.js'; export { type HandlerUniqueProperty, resolver, type ResponsesWithResolver, uniqueSymbol, validator, } from 'hono-openapi'; /** Describes a route without allowing spec generation to mutate reusable response definitions. */ export declare function describeRoute(spec: DescribeRouteOptions): MiddlewareHandler; /** Emits a named OpenAPI component and uses its `$ref` wherever the schema appears. */ export declare function component(schema: schema, name: string): schema; /** * Standard machine-readable `error.code` values per status, shared API-wide. * The reference enumerates `error.code` to these so generated clients narrow it * to a literal union instead of an open `string`. The values here are shared * defaults; operation-specific codes are supplied through {@link responses.Options}. */ export declare const errorCodes: { readonly 400: readonly ["query_invalid", "param_invalid", "body_invalid", "address_invalid", "token_invalid", "symbol_invalid", "swap_continuation_invalid", "swap_provider_invalid", "quote_amount_out_of_range", "pair_invalid", "pair_id_invalid", "transaction_invalid", "order_invalid", "block_invalid", "chain_id_invalid", "chain_id_unsupported", "destination_transition_invalid", "sender_tag_invalid", "url_invalid", "api_key_malformed"]; readonly 401: readonly ["api_key_missing", "api_key_invalid", "unauthorized"]; readonly 403: readonly ["api_key_forbidden", "api_key_ip_forbidden", "forbidden"]; readonly 404: readonly ["not_found", "token_not_found", "token_logo_not_found", "block_not_found", "transaction_not_found", "receipt_not_found", "order_not_found", "pair_not_found", "quote_not_available", "verified_token_not_found", "webhook_not_found", "delivery_not_found", "webhooks_not_enabled", "billing_not_found"]; readonly 429: readonly ["rate_limit_exceeded", "payment_required"]; readonly 500: readonly ["internal_error"]; readonly 501: readonly ["billing_unconfigured"]; readonly 502: readonly ["upstream_error"]; readonly 504: readonly ["request_timeout"]; }; /** * Reusable response-header definitions, registered under `components.headers` * (see `App.ts`) and `$ref`-erenced from 200/429 responses. The rate-limit * headers reflect the quota the request consumed; they are absent on edge-cache * hits (served before metering) and on `402` payment challenges (owned by mppx, * which sets `WWW-Authenticate`/`Payment-Receipt` instead). */ export declare const headerComponents: { readonly RateLimitLimit: { readonly description: 'How many requests you may make in the current time window. Not sent on cached responses or `402` payment challenges.'; readonly schema: { readonly type: 'integer'; }; }; readonly RateLimitRemaining: { readonly description: 'How many requests you have left in the current window before you are rate-limited. Not sent on cached responses or `402` payment challenges.'; readonly schema: { readonly type: 'integer'; }; }; readonly RateLimitReset: { readonly description: 'When the current window resets, as a Unix timestamp in seconds. Not sent on cached responses or `402` payment challenges.'; readonly schema: { readonly type: 'integer'; }; }; readonly RateLimitScope: { readonly description: 'Which quota this request counted against (e.g. `data:read`). Not sent on cached responses or `402` payment challenges.'; readonly schema: { readonly type: 'string'; }; }; readonly RetryAfter: { readonly description: 'How many seconds to wait before trying again. Sent with `429` (rate-limited) responses.'; readonly schema: { readonly type: 'integer'; }; }; readonly TempoRequestId: { readonly description: 'A unique id for this request, returned on every response (and as `requestId` in error bodies). Include it when contacting support so we can find your request.'; readonly schema: { readonly type: 'string'; }; }; readonly WwwAuthenticate: { readonly description: 'On a `402` response, the payment challenge to satisfy. Use it to build the `Authorization: Payment` credential and retry the request.'; readonly schema: { readonly type: 'string'; }; }; }; /** Response headers attached to metered success (2xx) responses. */ export declare const successHeaders: { 'RateLimit-Limit': { $ref: string; }; 'RateLimit-Remaining': { $ref: string; }; 'RateLimit-Reset': { $ref: string; }; 'RateLimit-Scope': { $ref: string; }; 'tempo-request-id': { $ref: string; }; }; /** Response headers attached to `429` rate-limit responses. */ export declare const rateLimitHeaders: { 'RateLimit-Limit': { $ref: string; }; 'RateLimit-Remaining': { $ref: string; }; 'RateLimit-Reset': { $ref: string; }; 'RateLimit-Scope': { $ref: string; }; 'tempo-request-id': { $ref: string; }; 'Retry-After': { $ref: string; }; }; /** * `402` payment-challenge response, injected per operation for MPP-enabled * routes during spec generation (see `App.create`). The challenge is * protocol-native (owned by mppx) rather than the JSON error envelope, so it * declares no JSON body — only the `WWW-Authenticate` header. */ export declare const paymentChallenge: { readonly description: 'Payment required. This endpoint accepts MPP payment, and the request either exceeded free quota or needs a paid request credential. The challenge is protocol-native (handled by mppx), not the JSON error envelope: read the `WWW-Authenticate` header and retry with `Authorization: Payment `. A successful paid response carries `Payment-Receipt`.'; readonly headers: { readonly 'WWW-Authenticate': { $ref: string; }; }; }; /** * Reusable responses registered under `components.responses` (see `App.create`) * and `$ref`-erenced from operations, so the uniform `402`/`429`/`500`/`504` * responses are defined once instead of inlined on every operation. */ export declare function responseComponents(): ResponsesWithResolver; /** `$ref` to the shared `402` payment-challenge response. */ export declare const paymentChallengeRef: { $ref: string; }; /** * Builds a single standard JSON error response with `error.code` enumerated for * the status. For routes whose custom `responses` map can't go through * {@link responses} — non-JSON success bodies (e.g. image, SSE) or proxy routes * with upstream-shaped error bodies. `429`/`500` resolve to the shared * `components.responses` entries. */ export declare function standardError(status: keyof typeof errorCodes, description: string, codes?: readonly [string, ...string[]]): ResponsesWithResolver[string]; /** * Builds an OpenAPI `responses` map with the API's standard error responses * pre-filled, plus the success response (with rate-limit headers): * * - `400` invalid request, `401` missing/invalid key, `403` forbidden, `429` * rate limited, `500` internal error, `502` upstream failure, and `504` * request timeout on every operation; * - `404`/`409`/`412`/`413`/`415` only when an `errors` entry is set. * * `error.code` is enumerated per status from {@link errorCodes}. Operation-level * 400/403 codes merge with shared auth codes; other overrides replace defaults. * The default `429` and `500` `$ref` shared {@link responseComponents}; an exact * operation-level `429` override is emitted inline with the standard headers. * `402` is injected per operation from the route's MPP policy in `App.ts`. */ export declare function responses(options: responses.Options): ResponsesWithResolver; export declare namespace responses { /** * Override for a standard error response: a description string, or an object * adding operation codes. Codes replace defaults except shared 400/403 auth codes. */ type ErrorOverride = string | { /** Human-readable description of the error response. */ description?: string | undefined; /** Operation-specific `error.code` values for this status. */ codes?: readonly string[] | undefined; }; /** Options for building a standard OpenAPI responses map. */ type Options = { /** * Optional overrides for standard error responses. Setting * `404`/`409`/`412`/`413`/`415` includes that status in the map. */ errors?: { /** Override for the 400 response. */ 400?: ErrorOverride | undefined; /** Override for the 401 response. */ 401?: ErrorOverride | undefined; /** Add operation-specific 403 codes or override its description. */ 403?: ErrorOverride | undefined; /** Override for the 404 response. Setting this includes 404 in the map. */ 404?: ErrorOverride | undefined; /** Override for the 409 response. Setting this includes 409 in the map. */ 409?: ErrorOverride | undefined; /** Override for the 412 response. Setting this includes 412 in the map. */ 412?: ErrorOverride | undefined; /** Override for the 413 response. Setting this includes 413 in the map. */ 413?: ErrorOverride | undefined; /** Override for the 415 response. Setting this includes 415 in the map. */ 415?: ErrorOverride | undefined; /** Override the shared 429 response with operation-specific rate-limit codes. */ 429?: ErrorOverride | undefined; /** Override for the 501 response. Setting this includes 501 in the map. */ 501?: ErrorOverride | undefined; /** Override for the 502 response. */ 502?: ErrorOverride | undefined; } | undefined; /** 200 response schema and description. */ success: { /** Human-readable description of the success body. */ description: string; /** Optional full example body rendered for the 200 response. */ example?: unknown; /** Optional named example bodies rendered for the 200 response. */ examples?: Record; /** Zod schema describing the 200 response body. */ schema: schema; }; }; } /** * Always false at runtime, but typed as `boolean` so route handlers can include * a never-reached validation-error branch in Hono's inferred response union. */ export declare const narrowValidation: boolean; /** Typed validation error response for Hono client inference. Never reached at runtime. */ export declare function validationError(c: Context, options: validationError.Options): Response & import("hono").TypedResponse<{ error: string | code | readonly Response.error.Detail[] | undefined extends bigint | readonly bigint[] ? never : { [K in keyof { code: code; details?: readonly Response.error.Detail[] | undefined; message: string; } as ({ code: code; details?: readonly Response.error.Detail[] | undefined; message: string; }[K] extends infer T ? T extends { code: code; details?: readonly Response.error.Detail[] | undefined; message: string; }[K] ? T extends import("hono/utils/types").InvalidJSONValue ? true : false : never : never) extends true ? never : K]: boolean extends ({ code: code; details?: readonly Response.error.Detail[] | undefined; message: string; }[K] extends infer T ? T extends { code: code; details?: readonly Response.error.Detail[] | undefined; message: string; }[K] ? T extends import("hono/utils/types").InvalidJSONValue ? true : false : never : never) ? import("hono/utils/types").JSONParsed<{ code: code; details?: readonly Response.error.Detail[] | undefined; message: string; }[K], bigint | readonly bigint[]> | undefined : import("hono/utils/types").JSONParsed<{ code: code; details?: readonly Response.error.Detail[] | undefined; message: string; }[K], bigint | readonly bigint[]>; }; requestId: string; }, 400, "json">; export declare namespace validationError { /** Options for building a typed validation error response. */ type Options = { /** Stable machine-readable validation error code. */ code: code; /** Human-readable validation error message. */ message: string; }; } /** * Wrapper around `hono-openapi`'s `validator` that returns the API's standard * 400 error envelope (with structured validation details) when parsing fails. * * Use this for every route validator instead of repeating the `result.success` * ceremony per route. */ export declare function validate(target: target, schema: schema, options: validate.Options): MiddlewareHandler>; export declare namespace validate { /** Hono input attached by the standard OpenAPI validator wrapper. */ type Input = { in: RequestInput>; out: { [key in target]: z.output; }; }; /** Options for the standard validator helper. */ type Options = { /** Stable machine-readable error code (e.g. `query_invalid`). */ code: string; /** Human-readable error message. */ message: string; }; /** Request input accepted by `hono/client` for a validation target. */ type RequestInput = target extends 'query' ? input extends object ? HasRequiredKeys extends true ? { query: TargetInput<'query', input>; } : { query?: TargetInput<'query', input> | undefined; } : { query: input; } : { [key in target]: TargetInput; }; /** Converts schema input into the fetch-client input shape for a target. */ type TargetInput = input extends ValidationTargets[target] ? input : { [key in keyof input]: key extends keyof ValidationTargets[target] ? ValidationTargets[target][key] : never; }; } //# sourceMappingURL=OpenApi.d.ts.map