fix(audit): corrige errores criticos y mayores, mejora UX/accesibilidad y optimiza rendimiento
- Arregla @require_auth, permisos, race conditions, locks de caja/stock - Elimina N+1 en layaway, flotilla, dashboard y global_invoice - Asegura folios atomicos para CFDI, ordenes de servicio y polizas - Protege client_secret de MercadoLibre en backend - Conecta botones/filtros de config, customers, accounting e invoicing - Mejora accesibilidad (labels/aria-label) y estados de carga/vacio - Limpia accounting.js obsoleto y consolida accounting.v9.js - Actualiza cache busting a v32 y Service Worker a v32 - Documenta todo en docs/AUDIT_Y_MEJORAS_2026-06-15.md Tests: 35 passed
This commit is contained in:
27
pos/static/js/api.js
Normal file
27
pos/static/js/api.js
Normal file
@@ -0,0 +1,27 @@
|
||||
// /home/Autopartes/pos/static/js/api.js
|
||||
// Minimal shared API helper used by standalone pages (e.g. historical_sales).
|
||||
|
||||
async function api(path, options = {}) {
|
||||
const token = localStorage.getItem('pos_token') || '';
|
||||
const url = path.startsWith('http') ? path : path;
|
||||
|
||||
const res = await fetch(url, {
|
||||
...options,
|
||||
headers: {
|
||||
'Authorization': token ? 'Bearer ' + token : '',
|
||||
'Content-Type': 'application/json',
|
||||
...(options.headers || {})
|
||||
}
|
||||
});
|
||||
|
||||
if (res.status === 401) {
|
||||
window.location.href = '/pos/login';
|
||||
throw new Error('Sesión expirada');
|
||||
}
|
||||
|
||||
const data = await res.json().catch(() => ({}));
|
||||
if (!res.ok) {
|
||||
throw new Error(data.error || data.message || 'Error ' + res.status);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
Reference in New Issue
Block a user