import { F as FilterConfig, C as CheckProfanityResult } from '../types-B9c_ik4k.js'; export { L as Language } from '../types-B9c_ik4k.js'; /** * Next.js Middleware and Utilities for glin-profanity * * Provides middleware, API route helpers, and React components * for integrating profanity detection in Next.js applications. * * @example * ```typescript * // middleware.ts * import { createProfanityMiddleware } from 'glin-profanity/nextjs'; * * export const middleware = createProfanityMiddleware({ * paths: ['/api/chat', '/api/comments'], * blockProfanity: true, * }); * * // API Route * import { withProfanityCheck } from 'glin-profanity/nextjs'; * * export const POST = withProfanityCheck(async (req, profanityResult) => { * if (profanityResult.blocked) { * return Response.json({ error: profanityResult.reason }, { status: 400 }); * } * // Continue processing... * }); * ``` * * @packageDocumentation * @module glin-profanity/nextjs */ /** * Middleware configuration */ interface ProfanityMiddlewareConfig { /** Paths to check (glob patterns supported) */ paths?: string[]; /** Paths to exclude */ excludePaths?: string[]; /** Block requests with profanity (return 400) */ blockProfanity?: boolean; /** Add profanity result to request headers */ addHeaders?: boolean; /** Custom response for blocked requests */ blockedResponse?: { status?: number; message?: string; }; /** Fields in request body to check */ checkFields?: string[]; /** Filter configuration */ filterConfig?: Partial; } /** * Profanity check result for middleware */ interface MiddlewareProfanityResult { /** Whether the request was blocked */ blocked: boolean; /** Reason for blocking (if blocked) */ reason?: string; /** Profane words found */ profaneWords: string[]; /** Fields that contained profanity */ flaggedFields: string[]; /** Full check result */ checkResult?: CheckProfanityResult; } /** * Creates Next.js middleware for profanity detection * * @example * ```typescript * // middleware.ts * import { createProfanityMiddleware } from 'glin-profanity/nextjs'; * * export const middleware = createProfanityMiddleware({ * paths: ['/api/chat', '/api/comments/*'], * blockProfanity: true, * checkFields: ['message', 'content', 'text'], * }); * * export const config = { * matcher: ['/api/:path*'], * }; * ``` */ declare function createProfanityMiddleware(config?: ProfanityMiddlewareConfig): (request: Request) => Promise; /** * Higher-order function to wrap API route handlers with profanity checking * * @example * ```typescript * // app/api/chat/route.ts * import { withProfanityCheck } from 'glin-profanity/nextjs'; * * export const POST = withProfanityCheck( * async (req, profanityResult) => { * if (profanityResult.blocked) { * return Response.json({ error: profanityResult.reason }, { status: 400 }); * } * * const { message } = await req.json(); * // Process message... * return Response.json({ success: true }); * }, * { * checkFields: ['message'], * blockProfanity: false, // Handle manually * } * ); * ``` */ declare function withProfanityCheck(handler: (request: Request, profanityResult: MiddlewareProfanityResult) => Promise, config?: { checkFields?: string[]; blockProfanity?: boolean; filterConfig?: Partial; }): (request: Request) => Promise; /** * Server action wrapper for profanity checking * * @example * ```typescript * // actions.ts * 'use server'; * import { createServerAction } from 'glin-profanity/nextjs'; * * export const submitComment = createServerAction( * async (data: { comment: string }) => { * // Save to database * await db.comments.create({ data }); * return { success: true }; * }, * { * checkFields: ['comment'], * onProfanity: (result) => { * return { error: 'Please remove inappropriate language' }; * }, * } * ); * ``` */ declare function createServerAction, TOutput>(action: (data: TInput) => Promise, config?: { checkFields?: string[]; filterConfig?: Partial; onProfanity?: (result: MiddlewareProfanityResult) => TOutput; }): (data: TInput) => Promise; /** * Utility functions for use in API routes */ declare const profanityUtils: { /** * Quick check for profanity in a single string */ check(text: string, config?: Partial): CheckProfanityResult; /** * Check and optionally censor text */ censor(text: string, replacement?: string, config?: Partial): string; /** * Check multiple fields in an object */ checkObject(obj: Record, fields: string[], config?: Partial): { containsProfanity: boolean; flaggedFields: string[]; profaneWords: string[]; }; }; export { CheckProfanityResult, FilterConfig, type MiddlewareProfanityResult, type ProfanityMiddlewareConfig, createProfanityMiddleware, createServerAction, profanityUtils, withProfanityCheck };