const API_URL = import.meta.env.VITE_API_URL || 'http://localhost:3001'; const ORG_ID = import.meta.env.VITE_ORG_ID as string | undefined; export async function apiRequest(endpoint: string, options: RequestInit = {}): Promise { const orgHeaders: Record = ORG_ID ? { 'x-organization-id': ORG_ID } : {}; const res = await fetch(`${API_URL}${endpoint}`, { ...options, headers: { 'Content-Type': 'application/json', ...orgHeaders, ...options.headers, }, }); if (!res.ok) { const errorData = await res.json().catch(() => ({})); const error = new Error(errorData.error || 'Une erreur est survenue'); (error as any).status = res.status; throw error; } return res.json(); } export const apiClient = { getStudent: (phone: string) => apiRequest(`/v1/student/me?phone=${phone}`), // Future endpoints can be added here };