From 1b8ab9fecfe59aa390da59339f1b53912015d988 Mon Sep 17 00:00:00 2001 From: Marco Gallegos Date: Sun, 18 Jan 2026 09:31:50 -0600 Subject: [PATCH] docs: Document all Supabase connection fixes and API improvements - Update README with Node.js 20 requirement and recent fixes - Enhance API documentation with improved endpoints and troubleshooting - Add Supabase connection issue resolution to troubleshooting guide - Document lazy client initialization and enhanced error diagnostics - Include recent improvements section in README --- README.md | 21 ++++++++++++------- docs/API.md | 46 ++++++++++++++++++++++++++++++++++++++--- docs/TROUBLESHOOTING.md | 8 +++++++ 3 files changed, 65 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index f9e9ba4..38ca438 100644 --- a/README.md +++ b/README.md @@ -189,11 +189,11 @@ El PRD es la fuente de verdad funcional. El README es la guía de ejecución. ## 7. Requisitos de Entorno -* Node.js 18+ -* Cuenta Supabase -* Cuenta Stripe -* Proyecto Google Cloud (Calendar API) -* Credenciales WhatsApp API + * Node.js 20+ (actualizado para compatibilidad con Supabase) + * Cuenta Supabase + * Cuenta Stripe + * Proyecto Google Cloud (Calendar API) + * Credenciales WhatsApp API Variables de entorno obligatorias: @@ -327,9 +327,16 @@ El sitio estará disponible en **http://localhost:2311** - ⏳ Recibos digitales por email - ⏳ Landing page para believers (booking público) - ⏳ Tests unitarios -- ⏳ Archivos SEO (robots.txt, sitemap.xml) + - ⏳ Archivos SEO (robots.txt, sitemap.xml) -### Fase Actual + ### Correcciones Recientes ✅ (Enero 2026) + - ✅ **Cliente Supabase Mejorado**: Inicialización lazy con validación de variables de entorno + - ✅ **APIs con Diagnóstico Avanzado**: Logging detallado en `/api/services` y `/api/locations` + - ✅ **Compatibilidad Node.js**: Actualización a Node 20 para compatibilidad con Supabase + - ✅ **Solución "fetch failed"**: Corrección del error de conectividad con Supabase en producción + - ✅ **Dockerfile Optimizado**: Imagen de producción con Node 20 y configuraciones mejoradas + + ### Fase Actual **Fase 1 — Cimientos y CRM**: 100% completado - Infraestructura base: 100% - Esquema de base de datos: 100% diff --git a/docs/API.md b/docs/API.md index 4aa25dc..0c3990f 100644 --- a/docs/API.md +++ b/docs/API.md @@ -13,11 +13,12 @@ AnchorOS is a comprehensive salon management system built with Next.js, Supabase ### Public APIs #### Services -- `GET /api/services` - List all available services +- `GET /api/services` - List all available services (with detailed logging and error diagnostics) +- `GET /api/services?location_id={id}` - Filter services by location - `POST /api/services` - Create new service (Admin only) #### Locations -- `GET /api/locations` - List all salon locations +- `GET /api/locations` - List all salon locations (with detailed logging and error diagnostics) #### Availability - `GET /api/availability/time-slots` - Get available time slots for booking @@ -142,7 +143,7 @@ Default business hours (updated via migration): ## Deployment ### Prerequisites -- Node.js 18+ +- Node.js 20+ (updated for Supabase compatibility) - Supabase account - Stripe account - Google Cloud (for Calendar) @@ -193,6 +194,45 @@ Default business hours (updated via migration): - Magic link authentication for customers - Encrypted payment processing +## Recent Improvements (January 2026) + +### Supabase Connection Fixes +- **Lazy Client Initialization**: Supabase client now initializes only when needed, ensuring environment variables are available at runtime +- **Enhanced Error Diagnostics**: APIs now provide detailed logging for connection issues +- **Node.js 20 Compatibility**: Updated runtime for better Supabase SDK compatibility +- **Connection Testing**: APIs test Supabase connectivity before executing queries + +### API Enhancements +- **Detailed Logging**: Services and Locations APIs now log connection status, query results, and errors +- **Better Error Messages**: Failed requests return structured error information with timestamps +- **Connectivity Validation**: Pre-flight checks ensure Supabase is reachable before processing requests + +### Troubleshooting +If APIs return `"TypeError: fetch failed"`: +1. Verify Supabase environment variables are correctly set in deployment platform +2. Check Supabase service status and connectivity +3. Review deployment logs for initialization errors +4. Ensure Node.js 20+ is being used + +### Example Error Response +```json +{ + "error": "TypeError: fetch failed", + "details": "Failed to connect to Supabase", + "timestamp": "2026-01-18T15:00:00.000Z" +} +``` + +### Example Success Response +```json +{ + "success": true, + "services": [...], + "count": 22, + "timestamp": "2026-01-18T15:00:00.000Z" +} +``` + ## Support For API issues or feature requests, please check the TASKS.md for current priorities or create an issue in the repository. \ No newline at end of file diff --git a/docs/TROUBLESHOOTING.md b/docs/TROUBLESHOOTING.md index d36111a..f0bee56 100644 --- a/docs/TROUBLESHOOTING.md +++ b/docs/TROUBLESHOOTING.md @@ -20,6 +20,14 @@ Esta guía ayuda a resolver problemas comunes durante el setup y desarrollo de A - Verificar políticas en Supabase Dashboard > Authentication > Policies - Para kioskos: asegurar API key válida en headers `x-kiosk-api-key` +#### Error: "TypeError: fetch failed" (Resuelto Enero 2026) +- **Causa**: Cliente Supabase se inicializa antes de que las variables de entorno estén disponibles en runtime +- **Solución**: + - Cliente ahora usa inicialización lazy (solo cuando se necesita) + - APIs incluyen pruebas de conectividad antes de ejecutar queries + - Logs detallados muestran el estado de conexión + - Actualizado a Node.js 20 para compatibilidad con Supabase + #### Error: "Magic link not received" - **Causa**: SMTP no configurado en Supabase - **Solución**: