/ dashboard-v2 / frontend / src / api.js
api.js
 1  /**
 2   * API fetch wrappers — one per endpoint.
 3   * All return parsed JSON. Throw on non-2xx.
 4   */
 5  
 6  async function apiFetch(path) {
 7    const res = await fetch(`/api/v1/${path}`);
 8    if (!res.ok) throw new Error(`API ${path}: ${res.status} ${res.statusText}`);
 9    return res.json();
10  }
11  
12  export const fetchOverview = () => apiFetch('overview');
13  export const fetchOutreach = () => apiFetch('outreach');
14  export const fetchConversations = () => apiFetch('conversations');
15  export const fetchOperations = () => apiFetch('operations');
16  export const fetchQuality = () => apiFetch('quality');
17  export const fetchCompliance = () => apiFetch('compliance');
18  export const fetchReview = () => apiFetch('review');
19  
20  export async function refreshCache() {
21    const res = await fetch('/api/v1/cache/refresh', { method: 'POST' });
22    if (!res.ok) throw new Error('Cache refresh failed');
23    return res.json();
24  }