/** * API client for system settings */ export interface SystemSetting { key: string; value: string | null; description: string | null; updated_at: string | null; } export interface SupplementTableSettings { url: string; enabled: boolean; } /** * Get all system settings */ export async function getAllSettings(): Promise<{ settings: SystemSetting[] }> { const response = await fetch(`/api/system-settings`, { credentials: 'include', }); if (!response.ok) { throw new Error(`Failed to fetch settings: ${response.statusText}`); } return response.json(); } /** * Get a specific setting by key */ export async function getSetting(key: string): Promise { const response = await fetch(`/api/system-settings/${key}`, { credentials: 'include', }); if (!response.ok) { throw new Error(`Failed to fetch setting: ${response.statusText}`); } return response.json(); } /** * Update or create a setting */ export async function updateSetting( key: string, value: string, description?: string ): Promise { const response = await fetch(`/api/system-settings/${key}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, credentials: 'include', body: JSON.stringify({ value, description }), }); if (!response.ok) { throw new Error(`Failed to update setting: ${response.statusText}`); } return response.json(); } /** * Delete a setting */ export async function deleteSetting(key: string): Promise<{ message: string }> { const response = await fetch(`/api/system-settings/${key}`, { method: 'DELETE', credentials: 'include', }); if (!response.ok) { throw new Error(`Failed to delete setting: ${response.statusText}`); } return response.json(); } /** * Get supplement table settings */ export async function getSupplementTableSettings(): Promise { const response = await fetch(`/api/system-settings/supplement-table`, { credentials: 'include', }); if (!response.ok) { throw new Error(`Failed to fetch supplement table settings: ${response.statusText}`); } return response.json(); } /** * Update supplement table settings */ export async function updateSupplementTableSettings( url: string, enabled: boolean ): Promise { const response = await fetch(`/api/system-settings/supplement-table`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, credentials: 'include', body: JSON.stringify({ url, enabled }), }); if (!response.ok) { throw new Error(`Failed to update supplement table settings: ${response.statusText}`); } return response.json(); }