import { ApiRequestOptions } from '../hooks/useApi'; // ============================================================================ // TYPES & INTERFACES // ============================================================================ export type PermissionLevel = 'n' | 'o' | 'a'; export interface UserPermissions { view: boolean; read: PermissionLevel; create: PermissionLevel; update: PermissionLevel; delete: PermissionLevel; } export type PermissionContext = 'DATA' | 'UI' | 'RESOURCE'; // Type for the request function passed to API functions export type ApiRequestFunction = (options: ApiRequestOptions) => Promise; // ============================================================================ // API REQUEST FUNCTIONS // ============================================================================ /** * Fetch permissions for a given context and item * Endpoint: GET /api/rbac/permissions * Query params: context (required), item (optional) */ export async function fetchPermissions( request: ApiRequestFunction, context: PermissionContext, item?: string ): Promise { const params: Record = { context }; if (item) { params.item = item; } const data = await request({ url: '/api/rbac/permissions', method: 'get', params }); return data; }