Explorar o código

docs: Create WooCommerce implementation plan #7

- Created comprehensive implementation plan for WooCommerce integration
- Covers all 5 phases: Edge Functions, Database, Scheduled Sync, Frontend, Webhooks
- Includes testing checklist and deployment steps
- Estimated 58 hours (7-10 business days)
- Plan stored in ISSUE_TEMPLATE_WOOCOMMERCE.md for creating new issue
Claude hai 5 meses
pai
achega
d16cd5f1b0
Modificáronse 1 ficheiros con 203 adicións e 0 borrados
  1. 203 0
      ISSUE_TEMPLATE_WOOCOMMERCE.md

+ 203 - 0
ISSUE_TEMPLATE_WOOCOMMERCE.md

@@ -0,0 +1,203 @@
+# WooCommerce Integration - Implementation Plan
+
+## Overview
+
+This issue tracks the implementation of full WooCommerce data synchronization functionality. The OAuth flow and API client are already in place, but data sync endpoints and scheduled background sync are missing.
+
+## Current State
+
+### ✅ Already Implemented
+- OAuth 1.0a flow (`oauth-woocommerce` Edge Function)
+- API client with signature generation (`_shared/woocommerce-client.ts`)
+- Frontend connection UI (`WooCommerceConnect.tsx`)
+
+### ❌ Missing Components
+- Data synchronization Edge Functions
+- Database cache tables
+- Scheduled background sync
+- Frontend data display components
+- Webhook support
+
+## Implementation Phases
+
+### Phase 1: Core Data Sync Functions (HIGH PRIORITY)
+**Estimated: 18 hours**
+
+Create Edge Functions for data synchronization:
+
+1. **`woocommerce-products`** - Fetch and cache products
+   - Endpoint: `GET /woocommerce-products?store_id={uuid}`
+   - Paginated product fetching
+   - Cache in `woocommerce_products_cache` table
+   - Return product list to frontend
+
+2. **`woocommerce-orders`** - Fetch and cache orders
+   - Endpoint: `GET /woocommerce-orders?store_id={uuid}&status=processing`
+   - Status filtering support
+   - Cache in `woocommerce_orders_cache` table
+   - Include customer info and line items
+
+3. **`woocommerce-customers`** - Fetch and cache customers
+   - Endpoint: `GET /woocommerce-customers?store_id={uuid}`
+   - Cache in `woocommerce_customers_cache` table
+   - Include billing information
+
+4. **`woocommerce-sync`** - Manual sync trigger
+   - Endpoint: `POST /woocommerce-sync`
+   - Body: `{ store_id: string }`
+   - Sync all data types in parallel
+   - Return comprehensive sync summary
+
+### Phase 2: Database Schema (HIGH PRIORITY)
+**Estimated: 3 hours**
+
+Create migration: `20250130_woocommerce_cache_tables.sql`
+
+Tables to create:
+- `woocommerce_products_cache` - Product data with SKU, pricing, stock
+- `woocommerce_orders_cache` - Order data with status, customer info
+- `woocommerce_customers_cache` - Customer data with contact info
+
+Add to existing `stores` table:
+- `last_sync_at` - Timestamp of last successful sync
+- `sync_status` - Current sync status
+- `sync_error` - Last error message if sync failed
+
+### Phase 3: Scheduled Sync (MEDIUM PRIORITY)
+**Estimated: 8 hours**
+
+1. **`woocommerce-scheduled-sync`** Edge Function
+   - Triggered by pg_cron hourly
+   - Secured with `INTERNAL_SYNC_SECRET`
+   - Process all WooCommerce stores with `sync_enabled = true`
+   - Log results to `sync_logs` table
+
+2. **pg_cron configuration**
+   - Schedule hourly sync at :15 minutes
+   - Use existing `store_sync_config` table
+   - Reuse existing `sync_logs` table structure
+
+### Phase 4: Frontend Integration (MEDIUM PRIORITY)
+**Estimated: 8 hours**
+
+1. Update `IntegrationsContent.tsx`
+   - Add "Sync Now" button for WooCommerce stores
+   - Display last sync time
+   - Show sync status indicator
+
+2. Create data display components:
+   - `WooCommerceProducts.tsx` - Product list view
+   - `WooCommerceOrders.tsx` - Order list with status filters
+   - `WooCommerceCustomers.tsx` - Customer list
+
+3. Integration points:
+   - Dashboard: Recent WooCommerce activity
+   - Analytics: WooCommerce-specific metrics
+   - AI Config: Product knowledge base
+
+### Phase 5: Webhook Support (LOW PRIORITY)
+**Estimated: 10 hours**
+
+1. **`webhook-woocommerce`** Edge Function
+   - Receive webhooks from WooCommerce
+   - Verify webhook signatures
+   - Update cached data in real-time
+   - Support events: `order.created`, `order.updated`, `product.updated`
+
+2. Auto-register webhooks on OAuth connect
+   - Register webhooks after successful OAuth
+   - Store webhook IDs in `woocommerce_webhooks` table
+   - Create table for webhook tracking
+
+## Testing Checklist
+
+### Unit Tests
+- [ ] OAuth signature generation
+- [ ] API client error handling
+- [ ] Rate limiting logic
+- [ ] Product sync with pagination
+- [ ] Order filtering by status
+- [ ] Customer data mapping
+
+### Integration Tests
+- [ ] End-to-end OAuth flow
+- [ ] Complete sync cycle (products → orders → customers)
+- [ ] Scheduled sync execution
+- [ ] Webhook reception and processing
+- [ ] Frontend data display
+
+### Manual Testing
+- [ ] Connect test WooCommerce store
+- [ ] Trigger manual sync and verify data
+- [ ] Check sync logs for errors
+- [ ] Test with 100+ products
+- [ ] Test with empty store (0 products)
+- [ ] Verify rate limiting
+- [ ] Test disconnect/reconnect flow
+
+## Deployment Steps
+
+1. **Database Migration**
+   ```bash
+   supabase db push
+   ```
+
+2. **Deploy Edge Functions**
+   ```bash
+   supabase functions deploy woocommerce-products
+   supabase functions deploy woocommerce-orders
+   supabase functions deploy woocommerce-customers
+   supabase functions deploy woocommerce-sync
+   supabase functions deploy woocommerce-scheduled-sync
+   supabase functions deploy webhook-woocommerce
+   ```
+
+3. **Configure Environment**
+   - Set `INTERNAL_SYNC_SECRET` in Supabase
+   - Configure database settings in Supabase Dashboard
+   - Add `app.internal_sync_secret` to Postgres config
+   - Add `app.supabase_url` to Postgres config
+
+4. **Deploy Frontend**
+   ```bash
+   cd shopcall.ai-main
+   npm run build
+   # Deploy to hosting provider
+   ```
+
+## Success Criteria
+
+- ✅ Users can connect WooCommerce stores via OAuth
+- ✅ Products, orders, and customers sync successfully
+- ✅ Manual sync button works in frontend
+- ✅ Scheduled sync runs hourly automatically
+- ✅ Sync logs track all operations
+- ✅ Frontend displays synced WooCommerce data
+- ✅ All tests pass
+- ✅ 95%+ sync success rate
+- ✅ Product sync completes within 30 seconds for 1000 products
+
+## Effort Estimation
+
+| Phase | Estimated Hours |
+|-------|----------------|
+| Phase 1: Edge Functions | 18 hours |
+| Phase 2: Database Tables | 3 hours |
+| Phase 3: Scheduled Sync | 8 hours |
+| Phase 4: Frontend | 8 hours |
+| Phase 5: Webhooks | 10 hours |
+| Testing | 8 hours |
+| Documentation | 3 hours |
+| **Total** | **58 hours** |
+
+**Calendar Time:** 7-10 business days (1-2 weeks)
+
+## References
+
+- Existing ShopRenter implementation: `supabase/functions/shoprenter-*`
+- WooCommerce REST API: https://woocommerce.github.io/woocommerce-rest-api-docs/
+- Detailed plan: `WOOCOMMERCE_RESTORATION_PLAN.md`
+
+## Related Issues
+
+- Closes #7