(path, options = {})
| 77 | } |
| 78 | |
| 79 | async function apiFetch(path, options = {}) { |
| 80 | const url = BASE_URL.replace(/\/$/, '') + path; |
| 81 | const headers = { 'Content-Type': 'application/json', ...options.headers }; |
| 82 | const res = await fetch(url, { ...options, headers }); |
| 83 | const data = await res.json(); |
| 84 | if (!res.ok) throw new Error(data.error || `HTTP ${res.status}`); |
| 85 | return data; |
| 86 | } |
| 87 | |
| 88 | async function ensureAuth() { |
| 89 | if (token && Date.now() < tokenExpiresAt - 60_000) return; |
no outgoing calls
no test coverage detected