export async function fetchJson(url, options = {}) { const response = await fetch(url, options); const text = await response.text(); if (!response.ok) { throw new Error(`HTTP ${response.status}: ${text.slice(0, 200)}`); } return text ? JSON.parse(text) : null; } export async function postJson(url, body, { headers = {}, ...options } = {}) { return fetchJson(url, { ...options, method: 'POST', headers: { 'content-type': 'application/json', ...headers, }, body: JSON.stringify(body), }); }