/** * js/api.js * Centraliza la comunicación con el Backend (Vercel Serverless Function) */ export const api = { data: null, // Guarda la última respuesta en memoria del cliente /** * Obtiene los datos de JIRA desde nuestro backend * @param {boolean} forceRefresh - Forzar bypassing de la caché del backend */ async fetchDashboardData(forceRefresh = false, period = '90d') { let url = `/api/data?period=${period}`; if (forceRefresh) url += '&refresh=1'; try { const res = await fetch(url); if (!res.ok) { const err = await res.json().catch(() => ({ error: `HTTP ${res.status}` })); throw new Error(err.error || `HTTP ${res.status}`); } const json = await res.json(); this.data = json; // Guardar en memoria global de la app return json; } catch (e) { console.error('Error al cargar datos:', e); throw e; } } };