/** * Entity Route Handler * * Base handler for entity API routes with automatic permission checking, * field filtering, and standardized responses. */ import { NextRequest, NextResponse } from 'next/server'; import type { CRUDOperation, EntityConfig } from '../entities/types'; /** * Entity handler context */ export interface EntityHandlerContext { user: { id: string; email: string; role: string; }; entity: EntityConfig; request: NextRequest; pagination?: { page: number; limit: number; offset: number; }; } /** * Entity handler options */ export interface EntityHandlerOptions { allowMetadata?: boolean; customValidation?: (context: EntityHandlerContext) => Promise<{ valid: boolean; error?: string; }>; } /** * CRUD handler functions */ export interface EntityCRUDHandlers { list?: (context: EntityHandlerContext) => Promise<{ data: Array>; total: number; }>; create?: (context: EntityHandlerContext, data: Record) => Promise>; read?: (context: EntityHandlerContext, id: string) => Promise | null>; update?: (context: EntityHandlerContext, id: string, data: Record) => Promise | null>; delete?: (context: EntityHandlerContext, id: string) => Promise; } /** * Legacy function - use createEntityListHandlers or createEntityDetailHandlers instead * @deprecated */ export declare function createEntityHandlers(entityName: string, handlers: EntityCRUDHandlers, options?: EntityHandlerOptions): { GET: (request: NextRequest) => Promise | NextResponse<{ success: boolean; data: Record[]; info: { timestamp: string; }; }>>; POST: (request: NextRequest) => Promise | NextResponse<{ success: boolean; data: Record; info: { timestamp: string; }; }>>; }; /** * Wrapper for entity auth - simplified without permissions */ export declare function withEntityAuth(entityName: string, action: CRUDOperation, options?: EntityHandlerOptions): (handler: (context: EntityHandlerContext, ...args: T) => Promise) => (request: NextRequest, ...args: T) => Promise; /** * Create standardized CRUD handlers for an entity (list and create only) */ export declare function createEntityListHandlers(entityName: string, handlers: EntityCRUDHandlers, options?: EntityHandlerOptions): { GET: (request: NextRequest) => Promise | NextResponse<{ success: boolean; data: Record[]; info: { timestamp: string; }; }>>; POST: (request: NextRequest) => Promise | NextResponse<{ success: boolean; data: Record; info: { timestamp: string; }; }>>; }; /** * Create standardized CRUD handlers for entity detail routes (with [id]) */ export declare function createEntityDetailHandlers(entityName: string, handlers: EntityCRUDHandlers, options?: EntityHandlerOptions): { GET: (request: NextRequest, routeContext: { params: Promise<{ id: string; }>; }) => Promise | NextResponse<{ success: boolean; data: Record; info: { timestamp: string; }; }>>; PATCH: (request: NextRequest, routeContext: { params: Promise<{ id: string; }>; }) => Promise | NextResponse<{ success: boolean; data: Record; info: { timestamp: string; }; }>>; DELETE: (request: NextRequest, routeContext: { params: Promise<{ id: string; }>; }) => Promise | NextResponse<{ success: boolean; data: { success: boolean; id: string; }; info: { timestamp: string; }; }>>; }; /** * Simple wrapper for single-action handlers */ export declare function withEntityAction(entityName: string, action: CRUDOperation, options?: EntityHandlerOptions): (handler: (context: EntityHandlerContext, ...args: T) => Promise) => (request: NextRequest, ...args: T) => Promise; /** * Helper to create database query context with RLS */ export declare function createQueryContext(context: EntityHandlerContext): { userId: string; userRole: string; userFlags: any[]; entityConfig: EntityConfig; }; //# sourceMappingURL=entity-handler.d.ts.map