export interface AdminSettings { cartExpiryHours: number; verifyTokenHours: number; passwordResetHours: number; greetingFormat: string; greetingFallback: string; } export async function fetchAdminSettings(): Promise { const res = await fetch('/api/admin/settings'); if (!res.ok) throw new Error('Could not load settings'); return res.json(); } export async function updateAdminSettings(settings: AdminSettings): Promise { const res = await fetch('/api/admin/settings', { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(settings) }); const body = await res.json(); // The refusal names the field that was rejected, and it is the only useful // thing to say. Without this check a 400 was returned as though it were the // saved settings, and the form reported success for a save the server refused. if (!res.ok) throw new Error(body?.error || 'Could not save settings'); return body; }