export async function api(path: string, init: RequestInit = {}): Promise { const headers = new Headers(init.headers) if (init.body && !headers.has('Content-Type')) headers.set('Content-Type', 'application/json') const response = await fetch(path, { ...init, headers }) if (response.status === 401) { window.location.assign('/auth/login') throw new Error('Authentication required') } if (!response.ok) { const body = await response.text() throw new Error(`${response.status}: ${body}`) } return response.json() as Promise } export async function apiBlob(path: string, init: RequestInit = {}): Promise { const headers = new Headers(init.headers) if (init.body && !headers.has('Content-Type')) headers.set('Content-Type', 'application/json') const response = await fetch(path, { ...init, headers }) if (response.status === 401) { window.location.assign('/auth/login') throw new Error('Authentication required') } if (!response.ok) throw new Error(`${response.status}: ${await response.text()}`) return response.blob() }