| Campo | Valor |
| --- | --- |
| Nome | ComercialRS (CRM de Vendas) |
| URL | https://comercialrs.rochasalesseguros.com.br |
| URL alternativa | https://comercialrs.rochasalesseguros.com.br/api |
| VPS Path | /var/www/comercialrs |
| Porta app | 3010 |
| Build output | /var/www/comercialrs/dist/ |
| Stack | TanStack Start (React + Vite), Supabase Cloud, Meta WhatsApp Business API |
2. Arquitetura Atual
`
NAVEGADOR USUÁRIO
↓
nginx (comercialrs.rochasalesseguros.com.br)
↓
├── /rest/v1/* → proxy → https://dauftiqcvgaydddoxqhh.supabase.co ⚠️ BLOQUEADO
├── /auth/v1/* → proxy → https://dauftiqcvgaydddoxqhh.supabase.co ⚠️ BLOQUEADO
├── /functions/* → proxy → https://dauftiqcvgaydddoxqhh.supabase.co ⚠️ BLOQUEADO
├── /storage/v1/* → proxy → https://dauftiqcvgaydddoxqhh.supabase.co ⚠️ BLOQUEADO
├── /realtime/* → proxy → https://dauftiqcvgaydddoxqhh.supabase.co ⚠️ BLOQUEADO
└── / (frontend) → arquivos estáticos em /var/www/comercialrs/dist/
META WEBHOOK (porta 8083)
↓
meta_webhook_vps_service.py
↓
Supabase Cloud DB (db.dauftiqcvgaydddoxqhh.supabase.co) ⚠️ BLOQUEADO
TAREFAS AUTOMÁTICAS
↓
task_alerts.py (cron)
↓
Supabase Cloud DB (db.dauftiqcvgaydddoxqhh.supabase.co) ⚠️ BLOQUEADO
`
3. Credenciais — Supabase Cloud (dauftiqcvgaydddoxqhh)
3.1 — Configuração do Projeto
| Campo | Valor |
| --- | --- |
| Project Ref | dauftiqcvgaydddoxqhh |
| Region | West US Oregon |
| Status | ⚠️ BLOQUEADO (402) |
| Plano | Pago (estourou egress quota em 2026-06-23) |
3.2 — .env do ComercialRS (VPS)
Arquivo: /var/www/comercialrs/.env
`
SUPABASE_URL="https://dauftiqcvgaydddoxqhh.supabase.co"
SUPABASE_PUBLISHABLE_KEY="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImRhdWZ0aXFjdmdheWRkZG94cWhoIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzI0NTEzODUsImV4cCI6MjA4ODAyNzM4NX0.OtwMAcrs2L3iH60ppShVTrOuQYSolIwITUPVf1ckswk"
VITE_SUPABASE_PROJECT_ID="dauftiqcvgaydddoxqhh"
VITE_SUPABASE_PUBLISHABLE_KEY="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImRhdWZ0aXFjdmdheWRkZG94cWhoIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzI0NTEzODUsImV4cCI6MjA4ODAyNzM4NX0.OtwMAcrs2L3iH60ppShVTrOuQYSolIwITUPVf1ckswk"
VITE_SUPABASE_URL="https://dauftiqcvgaydddoxqhh.supabase.co"
`
⚠️ ESSAS KEYS SÃO DO CLOUD — ESTÃO BLOQUEADAS
3.3 — Postgres DB (Cloud)
Usado por: meta_webhook_vps_service.py e task_alerts.py
| Campo | Valor |
| --- | --- |
| Host | db.dauftiqcvgaydddoxqhh.supabase.co |
| Port | 5432 |
| Database | postgres |
| User | postgres |
| Password | tSm?p8n57f+TX5n |
| Status | ⚠️ BLOQUEADO |
4. Credenciais — Supabase Self-Hosted (VPS)
Docker compose: /docker/deploy-vps/docker-compose.yml
Ambiente: /docker/deploy-vps/.env
4.1 — Postgres Local
| Campo | Valor |
| --- | --- |
| Host (via Docker) | deploy-vps-db-1 |
| Host (exposto) | localhost:5433 |
| Port | 5432 |
| Database | postgres |
| User | postgres |
| Password | * (ver em /docker/deploy-vps/.env) |
4.2 — Anon Key Local (Self-Hosted)
`
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InJvY2hhc2FsZXMiLCJyb2xlIjoiYW5vbiIsImlhdCI6MTc4MjE0MDAxMiwiZXhwIjoxODEzNjc2MDEyfQ.zSTyXFB2i9xsPJQ0rTCEhEL0JnMTj0brfExdqa85VWU
`
✅ FUNCIONA no localhost:8000
4.3 — JWT Secrets
| Campo | Valor |
| --- | --- |
| JWT_SECRET | OyIoGm...JXjw (ver completo em /docker/deploy-vps/.env) |
| PGRST_JWT_SECRET | OyIoGm...JXjw (mesmo do JWT_SECRET) |
| VERIFY_JWT | false |
4.4 — Containers Ativos
| Container | Status | Função |
| --- | --- | --- |
| deploy-vps-kong-1 | ✅ Up 22h | API Gateway (porta 8000 exposta) |
| deploy-vps-rest-1 | ✅ Up 20h | PostgREST (porta 3002 exposta) |
| deploy-vps-auth-1 | ✅ Up 22h | GoTrue (porta 9999 exposta) |
| deploy-vps-storage-1 | ✅ Up 23h | Storage (porta 5000 exposta) |
| deploy-vps-functions-1 | ✅ Up 22h | Edge Functions Deno (porta 9000) |
| deploy-vps-db-1 | ✅ Up 6d | PostgreSQL (porta 5433 exposta) |
| deploy-vps-studio-1 | ⚠️ Unhealthy | Supabase Studio |
| deploy-vps-meta-1 | ✅ Up 6d | Meta |
| deploy-vps-imgproxy-1 | ✅ Up 6d | Image proxy |
4.5 — Tabelas no DB Local (Self-Hosted)
`
broker_links
cms_content
custom_roles
leads
profiles (5 linhas — dados genéricos, NÃO são dados do ComercialRS)
tool_role_access
user_roles
user_profiles
`
⚠️ O DB LOCAL NÃO TEM OS DADOS DO COMERCIALRS — está vazio
5. Nginx
Arquivo: /etc/nginx/sites-enabled/comercialrs.rochasalesseguros.com.br
`
server_name: comercialrs.rochasalesseguros.com.br
root: /var/www/comercialrs/dist
ssl: letsencrypt (fullchain.pem + privkey.pem)
location /rest/v1/* → proxy → https://dauftiqcvgaydddoxqhh.supabase.co (apikey embedada)
location /auth/v1/* → proxy → https://dauftiqcvgaydddoxqhh.supabase.co (apikey embedada)
location /functions/v1/* → proxy → https://dauftiqcvgaydddoxqhh.supabase.co (apikey embedada)
location /storage/v1/* → proxy → https://dauftiqcvgaydddoxqhh.supabase.co (apikey embedada)
location /realtime/v1/* → proxy → https://dauftiqcvgaydddoxqhh.supabase.co (apikey embedada)
location / → try_files $uri $uri/ /index.html
APikey embedded no proxy (CLOUD):
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImRhdWZ0aXFjdmdheWRkZG94cWhoIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzI0NTEzODUsImV4cCI6MjA4ODAyNzM4NX0.OtwMAcrs2L3iH60ppShVTrOuQYSolIwITUPVf1ckswk
`
6. Meta WhatsApp Business API
6.1 — Webhook Server
| Campo | Valor |
| --- | --- |
| Arquivo | /var/www/comercialrs/data/meta_webhook_vps_service.py |
| Porta | 8083 |
| URL esperado | https://comercialrs.rochasalesseguros.com.br/meta-webhook |
| VERIFY_TOKEN | 1c5265...adab (ver completo no arquivo) |
6.2 — Credentials (armazenadas na tabela automations_config do Cloud)
Retornadas pela query:
`sql
SELECT meta_access_token, meta_phone_number_id FROM public.automations_config LIMIT 1
`
⚠️ Estão no DB Cloud (bloqueado)
6.3 — Fluxo
1. Meta envia webhook → /meta-webhook → meta_webhook_vps_service.py
2. Script conecta no DB Cloud db.dauftiqcvgaydddoxqhh.supabase.co (bloqueado)
3. Atualiza tasks e meeting_status
6.4 — Status Keywords
- - in_progress: iniciada, começou, andamento, start, started
- - completed: concluída, finalizada, done, fechada
- - remarketing: remarketing, remar, rmk, remercar
6.5 — Botões
Formato payload: status|TASK_ID (ex: in_progress|abc123...)
7. Edge Functions (Supabase Cloud)
7.1 — Lista Completa de Funções
`
admin-reset-user-password — Reset senha via admin
admin-update-user-email — Update email via admin
crm-lead-sync — Sync leads CRM externo
crm-mirror-health — Health check do CRM mirror
crm-sales-pipeline — Pipeline de vendas
crm-sales-sync — Sync de vendas
db-check-tables — Check tablas
db-inspect — Inspect database
dispatch-automation — Dispatch automação WhatsApp
firecrawl-extract-meeting — Extrair meeting
init-whatsapp-table — Inicializar WhatsApp table
inspect-db-profiles — Inspect profiles
resend-pending-meetings — Reenviar meetings pendentes
send-reminders — Enviar lembretes
sync-all-tasks — Sync todas tasks
sync-painel-to-chatwoot — Sync Painel → Chatwoot
sync-profiles — Sync profiles
test-network — Test network
uazapi-status-webhook — UAZAPI status webhook
update-responsibles — Update responsibles
update-profile-user-id — Update profile user_id
create-broker-links — Criar broker links
chatwoot-webhook — Webhook Chatwoot
meta-webhook — Webhook Meta
test-webhook — Test webhook
`
7.2 — Função Principal (Self-Hosted)
| Campo | Valor |
| --- | --- |
| Arquivo | /opt/rochasales/supabase/functions/main/index.ts |
| Container | deploy-vps-functions-1 |
| Tamanho | 234 linhas |
| Padrão | Inline JWT verification, REST calls via service role |
7.3 — Funções do Cloud Ausentes no Self-Hosted
- - dispatch-automation ❌
- - crm-lead-sync ❌
- - sales-overdue-alerts ❌
- - admin-reset-user-password ❌
- - admin-update-user-email ❌
- - invite-member ❌
- - uazapi-webhook ❌
- - resend-pending-meetings ❌
- - send-reminders ❌
- - E outras...
8. Tabelas do ComercialRS (Supabase Cloud)
Tabela: profiles
`sql
id uuid (PK, = auth.users.id)
user_id uuid (FK → auth.users.id)
full_name text
email text
role text
onboarding_done boolean
`
Tabela: tasks
`sql
id uuid PK
created_by uuid FK → profiles.id
responsible_id uuid FK → team_members.id
title text
status text (todo, in_progress, completed, remarketing)
due_date timestamptz
`
Tabela: team_members
`sql
id uuid PK (DIFERENTE de profiles.id)
profile_id uuid FK → profiles.id
name text
phone text
role text
`
Tabela: meetings
`sql
id uuid PK
responsible_id uuid FK → team_members.id
title text
start_date timestamptz
status text
meeting_status text
created_by uuid
`
Tabela: automations
`sql
id uuid PK
key text UNIQUE
name text
description text
icon text
status boolean
last_run_at timestamptz
`
Tabela: automations_config
Singleton global (user_id IS NULL). Campos:
- - crm_auto_sync
- - crm_last_synced_at
- - crm_last_sync_count
- - crm_last_sync_status
- - provider (n8n ou meta)
- - meta_access_token
- - meta_phone_number_id
- - meta_waba_id
- - meta_business_id
- - uazapi_url
- - uazapi_token
- - uazapi_phone
- - webhook_url
- - webhook_mode
Tabela: message_log
meta_message_id, task_id, responsible_id, phone, status
Tabela: incoming_messages
Respostas recebidas via webhook Meta
Tabela: alert_throttle
Anti-spam (janela 30min): signature, event_type, target_phone, responsible_id, task_ids, expires_at
Tabela: crm_leads
Espelho do CRM externo (sincronizado por n8n/cron)
Tabela: broker_links
(?) Usado para links de corretores
9. Automations (Edge Functions Cron)
| Automation | Trigger | Função |
| --- | --- | --- |
| whatsapp_reminders | 30min antes da reunião | dispatch-automation |
| risk_alerts | Quando reunião atrasa | sales-overdue-alerts |
| daily_briefing | 10h, 13h, 17h | send-reminders |
| weekly_closing | Sexta | send-reminders |
10. Scripts Python (VPS)
10.1 — task_alerts.py
| Campo | Valor |
| --- | --- |
| Path | /var/www/comercialrs/data/task_alerts.py |
| Função | Cron de alertas de tarefas |
| DB Host | db.dauftiqcvgaydddoxqhh.supabase.co (Cloud) |
| DB Creds | postgres / tSm?p8n57f+TX5n |
| Lock | 9000s (2h30) |
| Anti-spam | 30min via alert_throttle |
10.2 — run_task_alerts.sh
| Campo | Valor |
| --- | --- |
| Path | /var/www/comercialrs/data/run_task_alerts.sh |
| Função | Wrapper para executar task_alerts.py |
11. Build e Deploy
`bash
Build
cd /var/www/comercialrs
nvm use 20
npm run build
Output: /var/www/comercialrs/dist/
Deploy (manual)
cp -r /var/www/comercialrs/dist/* /var/www/comercialrs/dist_new/ 2>/dev/null || true
`
12. Domínios e SSL
| Domínio | SSL | Expira |
| --- | --- | --- |
| comercialrs.rochasalesseguros.com.br | letsencrypt | (?) |
SSL path: /etc/letsencrypt/live/comercialrs.rochasalesseguros.com.br/
13. Plano de Migração para Self-Hosted (definitivo)
Passo 1: Desbloquear Cloud (remover spend cap)
- - Acessar https://supabase.com/dashboard/orgs/*/billing
- - Remover spend cap ou ajustar limite
- - Cloud volta a funcionar imediatamente
Passo 2: Exportar dados do Cloud
`bash
Exportar todas as tabelas (quando Cloud estiver acessível)
via pg_dump ou scripts Python
`
Passo 3: Preparar Self-Hosted
- - Criar schema completo no VPS (tabelas que faltam)
- - Importar dados exportados
Passo 4: Migrar Edge Functions
- - Перенести все Edge Functions do Cloud para Self-Hosted
- - Deploy via
supabase functions deploy Passo 5: Trocar .env do ComercialRS
`
SUPABASE_URL="http://localhost:8000" (ou URL do Kong local)
SUPABASE_PUBLISHABLE_KEY=""
`
Passo 6: Atualizar nginx
- - Remover proxy para Cloud
- - Apontar para containers locais
Passo 7: Testar tudo
- - Login
- - Leads
- - Tasks
- - Meetings
- - WhatsApp webhook
- - Edge Functions
Rollback
- - Voltar .env original
- - Voltar nginx original
14. Contatos e Acessos
Supabase Cloud Dashboard
- - URL: https://supabase.com/dashboard/project/dauftiqcvgaydddoxqhh
- - Acesso: Conta Supabase (mesmo email do plano)
VPS
- - IP: 31.97.243.106
- - Acesso: SSH (chave ou senha)
15. Histórico de Problemas Resolvidos
| Data | Problema | Solução |
| --- | --- | --- |
| 2026-06-13 | Date filter null guard em Dashboard.tsx | Patch |
| 2026-06-13 | Alert throttle (30min anti-duplicado) | Implementado |
| 2026-06-13 | useMeetingAlerts.ts interval 30s → 150s | Patch |
| 2026-06-23 | exceed_egress_quota | Remover spend cap (pendente) |
16. Arquivos Importantes
| Arquivo | Descrição |
| --- | --- |
/var/www/comercialrs/.env | Config do app (Cloud) |
/var/www/comercialrs/data/meta_webhook_vps_service.py | Webhook Meta WhatsApp |
/var/www/comercialrs/data/task_alerts.py | Cron de alertas |
/etc/nginx/sites-enabled/comercialrs.rochasalesseguros.com.br | Nginx config |
/docker/deploy-vps/docker-compose.yml | Docker compose do Supabase |
/docker/deploy-vps/.env | Creds do Supabase Self-Hosted |
/opt/rochasales/supabase/functions/main/index.ts | Edge Function principal (VPS) |
/var/www/obsidian-vault/04-PROJECTS/COMERCIALRS-MIGRACAO-CLOUD-PARA-SELF-HOSTED-2026-06.md | Doc de migração |