/** * @module @arcis/node/bun * * Bun + Hono adapter for Arcis. Two entry points. * * **Scope:** rate-limit + bot detection + security headers. Bun's * Web Fetch runtime cannot easily inspect request bodies inside this * adapter (consuming the stream defeats the downstream handler). For * XSS/SQL/SSTI/etc. body-payload blocking, call * `sanitizeObject(await req.json())` from `@arcis/node/sanitizers` * inside your route handler. * * **1. `Bun.serve` fetch wrapper:** * * ```ts * import { arcisBun } from '@arcis/node/bun'; * * Bun.serve({ * fetch: arcisBun({ rateLimit: { max: 100 }, bot: true }, async (req, server) => { * return new Response('Hello'); * }), * }); * ``` * * **2. Hono middleware (works on Bun / Workers / Deno / Node):** * * ```ts * import { Hono } from 'hono'; * import { arcisHono } from '@arcis/node/bun'; * * const app = new Hono(); * app.use(arcisHono({ rateLimit: { max: 100 } })); * app.get('/', (c) => c.text('Hello')); * ``` * * No runtime dependency on `bun-types` or `hono` — both shapes are * duck-typed. */ import type { HeaderOptions, RateLimitOptions } from '../core/types'; import { type BotProtectionOptions } from './bot-detection'; export interface BunServerLike { requestIP(req: Request): { address: string; family?: string; port?: number; } | null; } export type BunFetchHandler = (req: Request, server?: BunServerLike) => Promise | Response; interface HonoRequestLike { raw: Request; url: string; header(name: string): string | undefined; } export interface HonoContextLike { req: HonoRequestLike; res: Response; json(object: unknown, status?: number): Response; } export type HonoNext = () => Promise; export type HonoMiddlewareHandler = (c: HonoContextLike, next: HonoNext) => Promise; export interface ArcisBunOptions { /** Security headers configuration. Default: enabled. Pass `false` to disable. */ headers?: boolean | HeaderOptions; /** Rate limiter configuration. Default: 100 req/60s in-memory. Pass `false` to disable. */ rateLimit?: boolean | RateLimitOptions; /** Bot protection. Default: disabled (opt-in). */ bot?: boolean | BotProtectionOptions; } /** * Wrap a `Bun.serve` fetch handler with Arcis protections. The wrapped handler * returns 429/403 directly when rate-limited or bot-blocked; otherwise it * delegates to the user handler and applies security headers to the result. */ export declare function arcisBun(options: ArcisBunOptions, handler: BunFetchHandler): BunFetchHandler; /** * Hono middleware factory. Apply via `app.use(arcisHono({...}))`. Returns 429 * or 403 directly when rate-limited or bot-blocked; otherwise calls `next()` * and mutates `c.res.headers` with security defaults afterwards. */ export declare function arcisHono(options?: ArcisBunOptions): HonoMiddlewareHandler; export default arcisBun; //# sourceMappingURL=bun.d.ts.map