export const API_BASE_URL = process.env.WHATSAPP_ROUTER_URL; if (!API_BASE_URL) { console.error("FATAL: WHATSAPP_ROUTER_URL environment variable is not set."); process.exit(1); } export async function fetchJSON(path, options = {}) { const method = options.method || "GET"; console.log(`[API] ${method} ${API_BASE_URL}${path}`); const res = await fetch(`${API_BASE_URL}${path}`, { headers: { "Content-Type": "application/json" }, ...options, }); if (!res.ok) { const txt = await res.text(); throw new Error(`API request failed (${res.status}): ${txt}`); } return res.json(); }