The SyncService runs a background loop every 30 seconds that drains the local sync queue to Supabase when online. Every data mutation logs a pending entry that is picked up and applied to the remote database.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Carlos-Gnd/FERRED-Inventario-y-Ventas/llms.txt
Use this file to discover all available pages before exploring further.
Ciclo de sincronización
SyncService.start() is called once during server bootstrap. It runs an initial cycle immediately and then schedules subsequent runs with setInterval.
SyncService.start()
Called once at startup. Fires the first
run() immediately and schedules repeating calls every 30 seconds (INTERVAL_MS = 30_000).checkConnectivity()
Pings Prisma with
SELECT 1. Returns true if the remote database is reachable, false otherwise. If offline, the cycle exits early — no sync attempt is made.sync.service.ts
logPendiente()
Every mutation (create, update, delete) callslogPendiente() to durably record the change before it is applied remotely. The function always writes to the local SQLite sync_log table first, then attempts to mirror the entry in the remote SyncLog table if the service is online.
sync.service.ts
| Parameter | Type | Description |
|---|---|---|
tabla | string | Target table name. Must be in TABLAS_PERMITIDAS. |
operacion | 'CREATE' | 'UPDATE' | 'DELETE' | The type of mutation. |
payload | object | The record data to sync. Scalar fields only. |
usuarioId | number (optional) | The user who performed the mutation, for audit purposes. |
Tablas sincronizadas
Only tables in theTABLAS_PERMITIDAS set are accepted by logPendiente() and aplicarOperacion(). Attempting to sync any other table throws an error that is recorded in the sync entry.
| Table | Description |
|---|---|
producto | Product catalog |
categoria | Product categories |
usuario | Branch users |
stockSucursal | Per-branch stock levels |
facturaDte | Electronic invoices (DTE) |
detalleVenta | Sale line items |
proveedor | Suppliers |
recepcionMercancia | Merchandise receipts |
detalleRecepcion | Receipt line items |
pushPendientes()
pushPendientes() reads up to 50 entries with status = 'PENDIENTE' and fewer than MAX_INTENTOS (5) attempts, then processes each one sequentially.
sync.service.ts
OfflineCache is fully cleared so that subsequent reads reflect the up-to-date remote state.
Estados del SyncLog
| Status | Description |
|---|---|
PENDIENTE | The entry has not yet been applied to Supabase. It will be picked up in the next sync cycle. |
SINCRONIZADO | The entry was successfully applied to Supabase. sinc_en is stamped with the UTC timestamp of completion. |
ERROR | The entry exhausted all MAX_INTENTOS (5) retry attempts. It will no longer be retried and must be resolved manually. |
PENDIENTE to ERROR happens inside marcarError() in sync.local.ts. Each failed attempt increments intentos. When intentos >= MAX_INTENTOS, the status is set to ERROR; otherwise it remains PENDIENTE and will be retried in the next cycle.
GET /api/inventario/sync-pendientes
This endpoint returns a real-time count of sync log entries grouped by status for the authenticated user’s scope. Admins see counts across all users; non-admin users see only their own entries.response