/** * Next.js App Configuration Helpers * * Provides wrappers and middleware for Next.js API routes. * Supports both App Router and Pages Router. * * @example App Router (app/api/users/route.ts) * ```typescript * import { withCoreMiddleware } from '@plyaz/core/nextjs'; * * export const GET = withCoreMiddleware(async (req) => { * const users = await db.users.findMany(); * return Response.json(users); * }); * ``` * * @example Pages Router (pages/api/users.ts) * ```typescript * import { withCoreApiHandler } from '@plyaz/core/nextjs'; * * export default withCoreApiHandler(async (req, res) => { * const users = await db.users.findMany(); * res.json(users); * }); * ``` */ import type { ConfigureAppResult, CoreNextJsMiddlewareConfig } from '@plyaz/types/core'; import { type CoreInitOptions } from '../CoreInitializer'; /** * Next.js App Router request type */ interface NextRequest { method: string; url: string; nextUrl?: { pathname: string; }; headers: Headers; } /** * Next.js Pages Router request type */ interface NextApiRequest { method?: string; url?: string; headers: Record; socket?: { remoteAddress?: string; }; } /** * Next.js Pages Router response type */ interface NextApiResponse { status(code: number): NextApiResponse; json(body: unknown): void; setHeader(name: string, value: string): NextApiResponse; } /** * Options for Core middleware wrapper */ export interface CoreMiddlewareOptions extends Partial { /** Override source name for error tracking */ source?: string; } /** * Wrap a Next.js App Router handler with Core middleware. * * Applies: * - Rate limiting (in-memory) * - Error handling with proper ErrorResponse format * - Request logging (optional) * * @param handler - Route handler function * @param options - Middleware configuration * @returns Wrapped handler * * @example * ```typescript * // app/api/users/route.ts * import { withCoreMiddleware } from '@plyaz/core/nextjs'; * * export const GET = withCoreMiddleware(async (req) => { * const users = await db.users.findMany(); * return Response.json(users); * }, { * rateLimit: { ttl: 60, limit: 100 }, * }); * * export const POST = withCoreMiddleware(async (req) => { * const body = await req.json(); * // Throwing errors returns proper ErrorResponse * throw new ValidationError('INVALID', 400, 'Invalid input'); * }); * ``` */ export declare function withCoreMiddleware(handler: (req: T, context?: unknown) => Promise, options?: CoreMiddlewareOptions): (req: T, context?: unknown) => Promise; /** * Wrap a Next.js Pages Router handler with Core middleware. * * Applies: * - Rate limiting (in-memory) * - Error handling with proper ErrorResponse format * * @param handler - API route handler * @param options - Middleware configuration * @returns Wrapped handler * * @example * ```typescript * // pages/api/users.ts * import { withCoreApiHandler } from '@plyaz/core/nextjs'; * * export default withCoreApiHandler(async (req, res) => { * const users = await db.users.findMany(); * res.json(users); * }, { * rateLimit: { ttl: 60, limit: 100 }, * }); * ``` */ export declare function withCoreApiHandler(handler: (req: Req, res: Res) => Promise, options?: CoreMiddlewareOptions): (req: Req, res: Res) => Promise; /** * Get Next.js configuration result (for logging/debugging). * * Unlike NestJS/Express, Next.js doesn't have a central app configuration. * This returns the effective configuration based on CoreInitOptions. * * @param options - Core initialization options * @returns Configuration result */ export declare function getNextJsConfigResult(options: CoreInitOptions): ConfigureAppResult; /** * Get default Next.js middleware configuration. * * @param isProduction - Whether running in production * @returns Default configuration */ export declare function getDefaultNextJsConfig(isProduction?: boolean): CoreNextJsMiddlewareConfig; export {}; //# sourceMappingURL=configureNextApp.d.ts.map