/** * Fastify Framework Adapter * * Adapts NAuth to work with Fastify with proper AsyncLocalStorage support. * * **Context Management:** * - First hook (clientInfo) initializes AsyncLocalStorage context * - Context is stored on request object for subsequent hooks * - Each hook restores context using ContextStorage.enterStore() * - Route handlers MUST use wrapRouteHandler() for context access * * **Why Context Restoration is Needed:** * Unlike Express where middleware runs in a continuous call stack, * Fastify hooks run independently. Each hook invocation loses the * AsyncLocalStorage context, so we store it on the request and restore it. */ import { NAuthAdapter, NAuthMiddlewareHandler, NAuthResponseInterceptorHandler, NAuthRouteHandler, MiddlewareOptions } from '../platform/interfaces'; /** * Fastify Adapter Implementation * * Provides NAuth integration for Fastify applications. */ export declare class FastifyAdapter implements NAuthAdapter { readonly name = "FastifyAdapter"; /** * Register a middleware handler as Fastify hook * * Handles context initialization for first hook and restoration for subsequent hooks. */ registerMiddleware(name: string, handler: NAuthMiddlewareHandler, options?: MiddlewareOptions): FastifyHook; /** * Execute handler with proper async flow control */ private executeHandler; /** * Register a response interceptor using Fastify onSend hook * * The onSend hook receives the serialized payload before sending. */ registerResponseInterceptor(handler: NAuthResponseInterceptorHandler): FastifyOnSendHook; /** * Wrap a route handler to ensure context is available * * For Fastify, this is REQUIRED for route handlers to access ContextStorage. */ wrapRouteHandler(handler: NAuthRouteHandler): FastifyRouteHandler; /** * Ensure attribute storage exists on request */ private ensureAttributes; } interface FastifyRequest { method: string; url: string; body: unknown; query: unknown; params: unknown; headers: Record; ip: string; } interface FastifyReply { code(statusCode: number): this; header(name: string, value: string | string[]): this; send(payload?: unknown): this; redirect(url: string): this; redirect(statusCode: number, url: string): this; getHeader(name: string): string | undefined; sent: boolean; } type FastifyHook = (request: FastifyRequest, reply: FastifyReply) => Promise; type FastifyOnSendHook = (request: FastifyRequest, reply: FastifyReply, payload: unknown) => Promise; type FastifyRouteHandler = (request: FastifyRequest, reply: FastifyReply) => Promise; export {}; //# sourceMappingURL=fastify.adapter.d.ts.map