/** * Permission Middleware for API Endpoints * * Helper functions to integrate permission checks into API routes. * Maps HTTP methods to entity actions and validates permissions. */ import type { Permission } from '../permissions/types'; import { NextResponse } from 'next/server'; /** * Special mapping for list operations (GET on collection) */ export declare const LIST_ACTION = "list"; /** * Get the permission string for an entity action * * @param entitySlug - Entity slug (e.g., 'customers', 'tasks') * @param action - Action being performed (e.g., 'create', 'read', 'list') * @returns Permission string (e.g., 'customers.create') * * @example * ```typescript * const permission = getEntityPermission('customers', 'create') * // => 'customers.create' * ``` */ export declare function getEntityPermission(entitySlug: string, action: string): Permission; /** * Get entity action from HTTP method and context * * @param method - HTTP method (GET, POST, PATCH, DELETE) * @param isCollection - Whether this is a collection endpoint (true) or single entity (false) * @returns Action string (e.g., 'list', 'read', 'create', 'update', 'delete') * * @example * ```typescript * // GET /api/v1/customers (list) * const action = getActionFromMethod('GET', true) * // => 'list' * * // GET /api/v1/customers/123 (read single) * const action = getActionFromMethod('GET', false) * // => 'read' * ``` */ export declare function getActionFromMethod(method: string, isCollection: boolean): string; /** * Check if user has permission for entity action * * This is the main permission check function for API endpoints. * Returns either success indicator or error Response. * * @param userId - User ID * @param teamId - Team ID * @param entitySlug - Entity slug (e.g., 'customers') * @param action - Action being performed (e.g., 'create', 'read', 'list') * @returns Success indicator or error Response * * @example * ```typescript * // In API route handler * const permCheck = await checkEntityPermission(userId, teamId, 'customers', 'create') * if (!permCheck.allowed) { * return permCheck.error * } * // Continue with operation... * ``` */ export declare function checkEntityPermission(userId: string, teamId: string, entitySlug: string, action: string): Promise<{ allowed: true; } | { allowed: false; error: NextResponse; }>; /** * Helper for common API pattern: check permission and return early if denied * * @param userId - User ID * @param teamId - Team ID * @param entitySlug - Entity slug * @param method - HTTP method * @param isCollection - Whether this is a collection endpoint * @returns null if allowed, error Response if denied * * @example * ```typescript * // Simplified usage in API routes * const error = await checkEntityPermissionOrFail(userId, teamId, 'customers', 'POST', true) * if (error) return error * * // Continue with operation... * ``` */ export declare function checkEntityPermissionOrFail(userId: string, teamId: string, entitySlug: string, method: string, isCollection: boolean): Promise; //# sourceMappingURL=permission-middleware.d.ts.map