cdp-edge 2.5.8 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +238 -202
- package/bin/cdp-edge.js +1 -0
- package/contracts/agent-versions.json +1 -1
- package/dist/commands/infra.js +1 -1
- package/dist/commands/server.js +38 -33
- package/dist/commands/setup.js +3 -0
- package/dist/commands/validate.js +251 -236
- package/dist/sdk/cdpTrack.js +6 -4
- package/dist/sdk/cdpTrack.min.js +4 -4
- package/dist/sdk/install-snippet.html +1 -1
- package/extracted-skill/tracking-events-generator/INTEGRACAO-COMPLETA.md +4 -4
- package/extracted-skill/tracking-events-generator/Premium-Tracking-Intelligence-Resumo.md +3 -3
- package/extracted-skill/tracking-events-generator/agents/master-orchestrator.md +72 -23
- package/extracted-skill/tracking-events-generator/integration-test.js +3 -3
- package/extracted-skill/tracking-events-generator/knowledge-base.md +12 -12
- package/extracted-skill/tracking-events-generator/models/checkout-proprio.md +1 -1
- package/extracted-skill/tracking-events-generator/models/multi-step-checkout.md +4 -4
- package/extracted-skill/tracking-events-generator/models/reddit/conversions-api-template.js +1 -1
- package/extracted-skill/tracking-events-generator/models/scenarios/behavior-engine.js +1 -1
- package/extracted-skill/tracking-events-generator/models/scenarios/sales-page-logic.md +1 -1
- package/extracted-skill/tracking-events-generator/models/trafego-direto.md +7 -7
- package/package.json +2 -2
- package/server-edge-tracker/index.ts +1267 -1204
- package/server-edge-tracker/modules/db.ts +2 -2
- package/server-edge-tracker/modules/dispatch/meta.ts +3 -0
- package/server-edge-tracker/modules/dispatch/tiktok.ts +1 -0
- package/server-edge-tracker/modules/dispatch/whatsapp.ts +5 -2
- package/server-edge-tracker/modules/utils.ts +1 -1
- package/server-edge-tracker/types.ts +3 -0
- package/server-edge-tracker/wrangler.toml +2 -0
- package/templates/checkout-proprio.md +1 -1
- package/templates/install/CLAUDE.md +1 -1
- package/templates/multi-step-checkout.md +4 -4
- package/templates/reddit/conversions-api-template.js +1 -1
- package/templates/scenarios/behavior-engine.js +1 -1
- package/templates/scenarios/sales-page-logic.md +1 -1
- package/templates/trafego-direto.md +7 -7
- package/templates/vsl-page.md +2 -2
- package/server-edge-tracker/.client.env +0 -5
- package/server-edge-tracker/dist-check/README.md +0 -1
- package/server-edge-tracker/dist-check/index.js +0 -5164
- package/server-edge-tracker/dist-check/index.js.map +0 -8
package/README.md
CHANGED
|
@@ -1,211 +1,247 @@
|
|
|
1
|
-
# 🚀 CDP Edge — Quantum Tracking Enterprise
|
|
2
|
-
**Padrão Quantum Tracking: 100% Cloudflare Edge.**
|
|
3
|
-
|
|
4
|
-
> **v2.
|
|
5
|
-
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
## 💻 INSTALAÇÃO
|
|
9
|
-
|
|
10
|
-
```bash
|
|
11
|
-
npx cdp-edge install
|
|
12
|
-
# ou
|
|
13
|
-
npm install -g cdp-edge
|
|
14
|
-
cdp-edge install . --name "Nome do Projeto"
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
---
|
|
18
|
-
|
|
19
|
-
## 🤖 MANIFESTO: EU, CDP EDGE
|
|
20
|
-
|
|
21
|
-
*Eu não sou um simples "script de pixel". Eu sou uma arquitetura **Enterprise Tier 10** nascida e construída 100% nativa na infraestrutura da Cloudflare.*
|
|
22
|
-
|
|
23
|
-
Quando um evento de Lead bate no endpoint `/track`:
|
|
24
|
-
1. **Fraud Gate:** Bloqueio bots silenciosamente antes de qualquer processamento (~2ms via KV)
|
|
25
|
-
2. **Quiz Scoring Engine:** Classifico as respostas do quiz com Granite 4.0 Micro — `comprador | interessado | curioso | perdido`
|
|
26
|
-
3. **A/B LTV Testing:** Sorteio de prompt via KV Cache em ~0ms
|
|
27
|
-
4. **LTV Predictor:** Machine Learning para qualificar intenção e gerar valor preditivo em BRL
|
|
28
|
-
5. **Nurture Scheduler:** Agendar sequência de follow-up baseada na qualificação (background)
|
|
29
|
-
6. **CAPI Dispatch:** Meta/GA4/TikTok recebem payload limpo com LTV e intention injetados
|
|
30
|
-
7. **Sales Engine:** Semanalmente, calculo ROAS real por campanha e atualizo o seed de Lookalike com compradores confirmados
|
|
31
|
-
|
|
32
|
-
---
|
|
33
|
-
|
|
34
|
-
## 🏗️ ARQUITETURA QUANTUM ENTERPRISE
|
|
35
|
-
|
|
36
|
-
```
|
|
37
|
-
POST /track (QuizComplete)
|
|
38
|
-
│
|
|
39
|
-
├─ [1] 🛡️ Fraud Gate (KV blocklist + velocity) ~2ms
|
|
40
|
-
├─ [2] 🤖 Quiz Scoring Engine (Granite 4.0 Micro) → comprador/interessado/curioso/perdido
|
|
41
|
-
├─ [3] 🔮 A/B LTV Sorting (KV cache ~0ms)
|
|
42
|
-
├─ [4] 🧮 LTV Prediction (Granite 4.0 Micro) — intent qualificado → High LTV
|
|
43
|
-
├─ [5] 💾 D1 Writes background (quiz_sessions + leads + nurture_sequences)
|
|
44
|
-
└─ [6] 📡 CAPI paralelo (Meta v25.0 + GA4 + TikTok v1.3)
|
|
45
|
-
|
|
46
|
-
Cron semanal (Intelligence Agent):
|
|
47
|
-
├─ ROAS Feedback — cruza leads × purchases por campanha → bid recommendation
|
|
48
|
-
├─ Nurture Queue — envia D+1/D+3/D+7 para leads qualificados
|
|
49
|
-
├─ Lookalike Seed — compradores confirmados → Meta Custom Audience
|
|
50
|
-
├─ LTV Model Training — regressão logística com dados reais
|
|
51
|
-
└─ A/B LTV Auto-winner — declara vencedor quando amostra suficiente
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
---
|
|
55
|
-
|
|
56
|
-
## 📊 BANCO DE DADOS D1 — 31 Tabelas + 12 VIEWs
|
|
57
|
-
|
|
58
|
-
```
|
|
59
|
-
CORE TRACKING ML & INTELLIGENCE SALES ENGINE
|
|
60
|
-
────────────── ───────────────────── ──────────────────
|
|
61
|
-
leads ml_segments roas_reports
|
|
62
|
-
events ml_segment_members nurture_sequences
|
|
63
|
-
sessions bid_recommendations lookalike_seeds
|
|
64
|
-
webhook_events ltv_ab_tests quiz_sessions
|
|
65
|
-
api_failures ltv_ab_variations
|
|
66
|
-
device_graph ltv_ab_assignments
|
|
67
|
-
user_profiles fraud_signals
|
|
68
|
-
intelligence_logs fraud_alerts
|
|
69
|
-
messaging_history match_quality_logs
|
|
70
|
-
automation_rules utm_mappings
|
|
71
|
-
edge_fingerprints
|
|
72
|
-
|
|
73
|
-
VIEWS (12)
|
|
74
|
-
──────────────────────────────────────────────────────────────────
|
|
75
|
-
v_active_segments v_active_bid_recs
|
|
76
|
-
v_ab_test_performance v_fraud_dashboard
|
|
77
|
-
v_quiz_qualification_summary v_quiz_dimension_impact
|
|
78
|
-
v_roas_latest v_nurture_pending
|
|
79
|
-
v_nurture_stats v_quiz_session_summary
|
|
80
|
-
v_leads_segmented v_ltv_feedback
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
---
|
|
84
|
-
|
|
85
|
-
## 🧠 CATÁLOGO DE MÓDULOS ML
|
|
86
|
-
|
|
87
|
-
| Módulo | Arquivo | Função |
|
|
88
|
-
|---|---|---|
|
|
89
|
-
| **Quiz Scoring** | `modules/ml/quiz.ts` | Análise dimensional automática das respostas |
|
|
90
|
-
| **LTV Prediction** | `modules/ml/ltv.ts` | Score 0-100 + valor BRL via Granite + A/B test |
|
|
91
|
-
| **Fraud Gate** | `modules/ml/fraud.ts` | Detecção de bots e fraude na borda |
|
|
92
|
-
| **ML Clustering** | `modules/ml/segmentation.ts` | K-means vetorial com bge-m3 embeddings |
|
|
93
|
-
| **Bidding ML** | `modules/ml/bidding.ts` | Recomendação de bid por segmento × plataforma |
|
|
94
|
-
| **ROAS Feedback** | `modules/ml/roas.ts` | ROAS real por campanha, alimenta bidding |
|
|
95
|
-
| **Match Quality** | `modules/ml/matchquality.ts` | Score de qualidade de dados para CAPI |
|
|
96
|
-
| **Logistic** | `modules/ml/logistic.ts` | Regressão logística para LTV model treinável |
|
|
97
|
-
| **Nurture Engine** | `modules/nurture.ts` | Sequências automáticas pós-qualificação |
|
|
98
|
-
|
|
99
|
-
---
|
|
100
|
-
|
|
101
|
-
## 🧠 CATÁLOGO DE AGENTES
|
|
102
|
-
|
|
103
|
-
| Categoria | Agente | Função |
|
|
104
|
-
|---|---|---|
|
|
105
|
-
| Orquestração | `master-orchestrator.md` | Coordena todo o setup |
|
|
106
|
-
| Análise | `page-analyzer.md` | Detecta CTAs, forms e nicho |
|
|
107
|
-
| Plataformas | `meta-agent.md`, `google-agent.md`, `tiktok-agent.md`... | Especialistas por plataforma |
|
|
108
|
-
| Infra | `server-tracking.md`, `devops-agent.md` | Arquitetura Cloudflare |
|
|
109
|
-
| Enterprise | `ml-clustering-agent.md` | Segmentação dinâmica ML |
|
|
110
|
-
| Enterprise | `bidding-agent.md` | Bids ML por segmento |
|
|
111
|
-
| Enterprise | `ab-ltv-agent.md` | A/B testing de prompts LTV |
|
|
112
|
-
| Enterprise | `fraud-detection-agent.md` | Detecção de fraude na borda |
|
|
113
|
-
| Infraestrutura | `zapman-agent.md` | Roteamento de leads p/ ZapMan SDR (Kanban + webhook IA) |
|
|
114
|
-
| Monitoramento | `intelligence-agent.md` | Cron — ROAS, Nurture, Lookalike, LTV training |
|
|
115
|
-
|
|
116
|
-
---
|
|
117
|
-
|
|
118
|
-
## 📋 TODOS OS ENDPOINTS
|
|
119
|
-
|
|
120
|
-
### Core
|
|
121
|
-
| Rota | Método | Função |
|
|
122
|
-
|---|---|---|
|
|
123
|
-
| `/track` | POST | Evento principal — Fraud Gate → Quiz Scoring → LTV → CAPI |
|
|
124
|
-
| `/health` | GET |
|
|
125
|
-
| `/
|
|
126
|
-
| `/webhook/
|
|
1
|
+
# 🚀 CDP Edge — Quantum Tracking Enterprise
|
|
2
|
+
**Padrão Quantum Tracking: 100% Cloudflare Edge.** Tracking server-side, first-party e orientado a performance.
|
|
3
|
+
|
|
4
|
+
> **v2.6.0** — Onboarding guiado, hardening admin, webhooks assinados e pacote pronto para release (10 de Maio de 2026)
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## 💻 INSTALAÇÃO
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npx cdp-edge install
|
|
12
|
+
# ou
|
|
13
|
+
npm install -g cdp-edge
|
|
14
|
+
cdp-edge install . --name "Nome do Projeto"
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## 🤖 MANIFESTO: EU, CDP EDGE
|
|
20
|
+
|
|
21
|
+
*Eu não sou um simples "script de pixel". Eu sou uma arquitetura **Enterprise Tier 10** nascida e construída 100% nativa na infraestrutura da Cloudflare.*
|
|
22
|
+
|
|
23
|
+
Quando um evento de Lead bate no endpoint `/track`:
|
|
24
|
+
1. **Fraud Gate:** Bloqueio bots silenciosamente antes de qualquer processamento (~2ms via KV)
|
|
25
|
+
2. **Quiz Scoring Engine:** Classifico as respostas do quiz com Granite 4.0 Micro — `comprador | interessado | curioso | perdido`
|
|
26
|
+
3. **A/B LTV Testing:** Sorteio de prompt via KV Cache em ~0ms
|
|
27
|
+
4. **LTV Predictor:** Machine Learning para qualificar intenção e gerar valor preditivo em BRL
|
|
28
|
+
5. **Nurture Scheduler:** Agendar sequência de follow-up baseada na qualificação (background)
|
|
29
|
+
6. **CAPI Dispatch:** Meta/GA4/TikTok recebem payload limpo com LTV e intention injetados
|
|
30
|
+
7. **Sales Engine:** Semanalmente, calculo ROAS real por campanha e atualizo o seed de Lookalike com compradores confirmados
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## 🏗️ ARQUITETURA QUANTUM ENTERPRISE
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
POST /track (QuizComplete)
|
|
38
|
+
│
|
|
39
|
+
├─ [1] 🛡️ Fraud Gate (KV blocklist + velocity) ~2ms
|
|
40
|
+
├─ [2] 🤖 Quiz Scoring Engine (Granite 4.0 Micro) → comprador/interessado/curioso/perdido
|
|
41
|
+
├─ [3] 🔮 A/B LTV Sorting (KV cache ~0ms)
|
|
42
|
+
├─ [4] 🧮 LTV Prediction (Granite 4.0 Micro) — intent qualificado → High LTV
|
|
43
|
+
├─ [5] 💾 D1 Writes background (quiz_sessions + leads + nurture_sequences)
|
|
44
|
+
└─ [6] 📡 CAPI paralelo (Meta v25.0 + GA4 + TikTok v1.3)
|
|
45
|
+
|
|
46
|
+
Cron semanal (Intelligence Agent):
|
|
47
|
+
├─ ROAS Feedback — cruza leads × purchases por campanha → bid recommendation
|
|
48
|
+
├─ Nurture Queue — envia D+1/D+3/D+7 para leads qualificados
|
|
49
|
+
├─ Lookalike Seed — compradores confirmados → Meta Custom Audience
|
|
50
|
+
├─ LTV Model Training — regressão logística com dados reais
|
|
51
|
+
└─ A/B LTV Auto-winner — declara vencedor quando amostra suficiente
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## 📊 BANCO DE DADOS D1 — 31 Tabelas + 12 VIEWs
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
CORE TRACKING ML & INTELLIGENCE SALES ENGINE
|
|
60
|
+
────────────── ───────────────────── ──────────────────
|
|
61
|
+
leads ml_segments roas_reports
|
|
62
|
+
events ml_segment_members nurture_sequences
|
|
63
|
+
sessions bid_recommendations lookalike_seeds
|
|
64
|
+
webhook_events ltv_ab_tests quiz_sessions
|
|
65
|
+
api_failures ltv_ab_variations
|
|
66
|
+
device_graph ltv_ab_assignments
|
|
67
|
+
user_profiles fraud_signals
|
|
68
|
+
intelligence_logs fraud_alerts
|
|
69
|
+
messaging_history match_quality_logs
|
|
70
|
+
automation_rules utm_mappings
|
|
71
|
+
edge_fingerprints
|
|
72
|
+
|
|
73
|
+
VIEWS (12)
|
|
74
|
+
──────────────────────────────────────────────────────────────────
|
|
75
|
+
v_active_segments v_active_bid_recs
|
|
76
|
+
v_ab_test_performance v_fraud_dashboard
|
|
77
|
+
v_quiz_qualification_summary v_quiz_dimension_impact
|
|
78
|
+
v_roas_latest v_nurture_pending
|
|
79
|
+
v_nurture_stats v_quiz_session_summary
|
|
80
|
+
v_leads_segmented v_ltv_feedback
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## 🧠 CATÁLOGO DE MÓDULOS ML
|
|
86
|
+
|
|
87
|
+
| Módulo | Arquivo | Função |
|
|
88
|
+
|---|---|---|
|
|
89
|
+
| **Quiz Scoring** | `modules/ml/quiz.ts` | Análise dimensional automática das respostas |
|
|
90
|
+
| **LTV Prediction** | `modules/ml/ltv.ts` | Score 0-100 + valor BRL via Granite + A/B test |
|
|
91
|
+
| **Fraud Gate** | `modules/ml/fraud.ts` | Detecção de bots e fraude na borda |
|
|
92
|
+
| **ML Clustering** | `modules/ml/segmentation.ts` | K-means vetorial com bge-m3 embeddings |
|
|
93
|
+
| **Bidding ML** | `modules/ml/bidding.ts` | Recomendação de bid por segmento × plataforma |
|
|
94
|
+
| **ROAS Feedback** | `modules/ml/roas.ts` | ROAS real por campanha, alimenta bidding |
|
|
95
|
+
| **Match Quality** | `modules/ml/matchquality.ts` | Score de qualidade de dados para CAPI |
|
|
96
|
+
| **Logistic** | `modules/ml/logistic.ts` | Regressão logística para LTV model treinável |
|
|
97
|
+
| **Nurture Engine** | `modules/nurture.ts` | Sequências automáticas pós-qualificação |
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## 🧠 CATÁLOGO DE AGENTES
|
|
102
|
+
|
|
103
|
+
| Categoria | Agente | Função |
|
|
104
|
+
|---|---|---|
|
|
105
|
+
| Orquestração | `master-orchestrator.md` | Coordena todo o setup |
|
|
106
|
+
| Análise | `page-analyzer.md` | Detecta CTAs, forms e nicho |
|
|
107
|
+
| Plataformas | `meta-agent.md`, `google-agent.md`, `tiktok-agent.md`... | Especialistas por plataforma |
|
|
108
|
+
| Infra | `server-tracking.md`, `devops-agent.md` | Arquitetura Cloudflare |
|
|
109
|
+
| Enterprise | `ml-clustering-agent.md` | Segmentação dinâmica ML |
|
|
110
|
+
| Enterprise | `bidding-agent.md` | Bids ML por segmento |
|
|
111
|
+
| Enterprise | `ab-ltv-agent.md` | A/B testing de prompts LTV |
|
|
112
|
+
| Enterprise | `fraud-detection-agent.md` | Detecção de fraude na borda |
|
|
113
|
+
| Infraestrutura | `zapman-agent.md` | Roteamento de leads p/ ZapMan SDR (Kanban + webhook IA) |
|
|
114
|
+
| Monitoramento | `intelligence-agent.md` | Cron — ROAS, Nurture, Lookalike, LTV training |
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
## 📋 TODOS OS ENDPOINTS
|
|
119
|
+
|
|
120
|
+
### Core
|
|
121
|
+
| Rota | Método | Função |
|
|
122
|
+
|---|---|---|
|
|
123
|
+
| `/track` | POST | Evento principal — Fraud Gate → Quiz Scoring → LTV → CAPI |
|
|
124
|
+
| `/health` | GET | Liveness público mínimo |
|
|
125
|
+
| `/api/health` | GET | Diagnóstico autenticado D1 + KV + AI + vars/secrets |
|
|
126
|
+
| `/webhook/ticto` | POST | Purchase webhook (HMAC) |
|
|
127
|
+
| `/webhook/whatsapp` | POST | Webhook Meta WhatsApp → ZapMan SDR |
|
|
127
128
|
| `/export/customer-match` | GET | Export leads para Google Ads |
|
|
128
|
-
| `/validate-install` | GET |
|
|
129
|
-
|
|
130
|
-
### ML Clustering (Fase 1)
|
|
131
|
-
| Rota | Método | Função |
|
|
132
|
-
|---|---|---|
|
|
133
|
-
| `/api/segmentation/cluster` | POST | K-means vetorial (bge-m3 + Granite) |
|
|
134
|
-
| `/api/segmentation/list` | GET | Segmentos ativos |
|
|
135
|
-
| `/api/segmentation/outliers` | GET | Outliers comportamentais |
|
|
136
|
-
| `/api/segmentation/update` | PUT | Atualiza metadados |
|
|
137
|
-
|
|
138
|
-
### Bidding (Fase 2)
|
|
139
|
-
| Rota | Método | Função |
|
|
140
|
-
|---|---|---|
|
|
141
|
-
| `/api/bidding/recommend` | POST | Bid por segmento × plataforma |
|
|
142
|
-
| `/api/bidding/history` | GET | Histórico de recomendações |
|
|
143
|
-
| `/api/bidding/status` | GET | Snapshot atual |
|
|
144
|
-
|
|
145
|
-
### A/B LTV (Fase 3)
|
|
146
|
-
| Rota | Método | Função |
|
|
147
|
-
|---|---|---|
|
|
148
|
-
| `/api/ltv/ab-test/create` | POST | Cria experimento |
|
|
149
|
-
| `/api/ltv/ab-test/list` | GET | Lista experimentos |
|
|
150
|
-
| `/api/ltv/ab-test/results` | GET | Accuracy por variação |
|
|
151
|
-
| `/api/ltv/ab-test/winner` | POST | Declara vencedor |
|
|
129
|
+
| `/validate-install` | GET | Diagnostico pos-deploy autenticado |
|
|
152
130
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|---|---|---|
|
|
156
|
-
| `/api/fraud/stats` | GET | Dashboard 24h |
|
|
157
|
-
| `/api/fraud/alerts` | GET | Log de sinais |
|
|
158
|
-
| `/api/fraud/blocklist` | GET | IPs bloqueados |
|
|
159
|
-
| `/api/fraud/blocklist/add` | POST | Bloquear |
|
|
160
|
-
| `/api/fraud/blocklist/remove` | DELETE | Desbloquear |
|
|
161
|
-
|
|
162
|
-
---
|
|
163
|
-
|
|
164
|
-
## 🚀 DEPLOY COMPLETO
|
|
165
|
-
|
|
166
|
-
```bash
|
|
167
|
-
cd server-edge-tracker
|
|
168
|
-
|
|
169
|
-
# Schemas D1 (ordem correta — todos idempotentes)
|
|
170
|
-
wrangler d1 execute cdp-edge-db --file=schema.sql --remote
|
|
171
|
-
wrangler d1 execute cdp-edge-db --file=migrate-v6.sql --remote
|
|
172
|
-
wrangler d1 execute cdp-edge-db --file=schema-segmentation.sql --remote
|
|
173
|
-
wrangler d1 execute cdp-edge-db --file=schema-bidding.sql --remote
|
|
174
|
-
wrangler d1 execute cdp-edge-db --file=schema-ab-ltv.sql --remote
|
|
175
|
-
wrangler d1 execute cdp-edge-db --file=schema-fraud.sql --remote
|
|
176
|
-
wrangler d1 execute cdp-edge-db --file=schema-indexes.sql --remote
|
|
177
|
-
wrangler d1 execute cdp-edge-db --file=migrate-v7.sql --remote
|
|
178
|
-
wrangler d1 execute cdp-edge-db --file=schema-ltv-feedback.sql --remote
|
|
179
|
-
wrangler d1 execute cdp-edge-db --file=schema-utm.sql --remote
|
|
180
|
-
wrangler d1 execute cdp-edge-db --file=schema-quiz.sql --remote
|
|
181
|
-
wrangler d1 execute cdp-edge-db --file=schema-sales-engine.sql --remote
|
|
182
|
-
|
|
183
|
-
# Secrets (nunca em arquivos — sempre via wrangler secret put)
|
|
184
|
-
wrangler secret put META_ACCESS_TOKEN
|
|
185
|
-
wrangler secret put GA4_API_SECRET
|
|
186
|
-
wrangler secret put TIKTOK_ACCESS_TOKEN
|
|
187
|
-
wrangler secret put ZAPMAN_API_KEY
|
|
188
|
-
|
|
189
|
-
# Deploy
|
|
190
|
-
wrangler deploy
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
---
|
|
194
|
-
|
|
195
|
-
## 🗺️ GRAPHIFY — Navegando o Código
|
|
131
|
+
Rotas administrativas (`/api/*` e `/validate-install`) exigem `Authorization: Bearer <ADMIN_API_TOKEN>`.
|
|
132
|
+
Para o diagnostico via CLI:
|
|
196
133
|
|
|
197
134
|
```bash
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
/graphify query "nurture engine → meta audience" # exploração DFS
|
|
201
|
-
/graphify path "quiz_answers" "meta capi" # menor caminho
|
|
135
|
+
wrangler secret put ADMIN_API_TOKEN
|
|
136
|
+
cdp-edge validate https://seu-dominio.com --admin-token "$ADMIN_API_TOKEN"
|
|
202
137
|
```
|
|
203
138
|
|
|
204
|
-
> Changelog completo → [CHANGELOG.md](./CHANGELOG.md)
|
|
205
|
-
|
|
206
139
|
---
|
|
207
140
|
|
|
208
|
-
|
|
209
|
-
|
|
141
|
+
## Estado atual da maquina - 10/05/2026
|
|
142
|
+
|
|
143
|
+
Esta build esta validada como pacote npm `cdp-edge@2.6.0` e Worker Cloudflare Native.
|
|
144
|
+
|
|
145
|
+
O que ela faz hoje:
|
|
146
|
+
- Recebe eventos no `POST /track` usando o endpoint canonico same-domain `/track`.
|
|
147
|
+
- Deduplica `event_id` cedo, antes de enrichments caros e antes de dispatch externo.
|
|
148
|
+
- Executa Fraud Gate antes do pipeline principal, com silent drop para bots/fraude.
|
|
149
|
+
- Enriquece leads com perfil, UTMs, device graph, geo, quiz, LTV, match quality e sinais de funil.
|
|
150
|
+
- Persiste eventos, leads, perfis, fingerprints, sinais de fraude, automacoes, webhooks, LTV e dados de inteligencia no D1.
|
|
151
|
+
- Envia eventos server-side para Meta CAPI, GA4, TikTok e demais plataformas quando os secrets existem.
|
|
152
|
+
- Processa webhooks de compra e WhatsApp, com HMAC em Ticto e assinatura Meta `x-hub-signature-256` para WhatsApp quando `META_APP_SECRET` esta configurado.
|
|
153
|
+
- Protege rotas administrativas `/api/*`, `/api/health` e `/validate-install` com `Authorization: Bearer <ADMIN_API_TOKEN>`.
|
|
154
|
+
- Mantem `/health` publico como liveness minimo, sem expor bindings, vars ou secrets.
|
|
155
|
+
- Gera SDK browser em `dist/sdk/*` durante `npm run build` e durante `npm pack`/`prepare`.
|
|
156
|
+
- Empacota sem arquivos locais sensiveis: `.client.env`, `.wrangler/` e `dist-check/` ficam fora do tarball.
|
|
157
|
+
|
|
158
|
+
Validacao local desta finalizacao:
|
|
159
|
+
- `npm run build` passou.
|
|
160
|
+
- `npm run typecheck` passou.
|
|
161
|
+
- `npm run test:unit` passou.
|
|
162
|
+
- `npm run test:integration` passou: 5 arquivos, 85 testes.
|
|
163
|
+
- `npm run agents:check` passou.
|
|
164
|
+
- `npm pack --dry-run` passou: 175 arquivos, ~569.8 kB, sem publish.
|
|
210
165
|
|
|
211
|
-
|
|
166
|
+
### ML Clustering (Fase 1)
|
|
167
|
+
| Rota | Método | Função |
|
|
168
|
+
|---|---|---|
|
|
169
|
+
| `/api/segmentation/cluster` | POST | K-means vetorial (bge-m3 + Granite) |
|
|
170
|
+
| `/api/segmentation/list` | GET | Segmentos ativos |
|
|
171
|
+
| `/api/segmentation/outliers` | GET | Outliers comportamentais |
|
|
172
|
+
| `/api/segmentation/update` | PUT | Atualiza metadados |
|
|
173
|
+
|
|
174
|
+
### Bidding (Fase 2)
|
|
175
|
+
| Rota | Método | Função |
|
|
176
|
+
|---|---|---|
|
|
177
|
+
| `/api/bidding/recommend` | POST | Bid por segmento × plataforma |
|
|
178
|
+
| `/api/bidding/history` | GET | Histórico de recomendações |
|
|
179
|
+
| `/api/bidding/status` | GET | Snapshot atual |
|
|
180
|
+
|
|
181
|
+
### A/B LTV (Fase 3)
|
|
182
|
+
| Rota | Método | Função |
|
|
183
|
+
|---|---|---|
|
|
184
|
+
| `/api/ltv/ab-test/create` | POST | Cria experimento |
|
|
185
|
+
| `/api/ltv/ab-test/list` | GET | Lista experimentos |
|
|
186
|
+
| `/api/ltv/ab-test/results` | GET | Accuracy por variação |
|
|
187
|
+
| `/api/ltv/ab-test/winner` | POST | Declara vencedor |
|
|
188
|
+
|
|
189
|
+
### Fraud (Fase 4)
|
|
190
|
+
| Rota | Método | Função |
|
|
191
|
+
|---|---|---|
|
|
192
|
+
| `/api/fraud/stats` | GET | Dashboard 24h |
|
|
193
|
+
| `/api/fraud/alerts` | GET | Log de sinais |
|
|
194
|
+
| `/api/fraud/blocklist` | GET | IPs bloqueados |
|
|
195
|
+
| `/api/fraud/blocklist/add` | POST | Bloquear |
|
|
196
|
+
| `/api/fraud/blocklist/remove` | DELETE | Desbloquear |
|
|
197
|
+
|
|
198
|
+
---
|
|
199
|
+
|
|
200
|
+
## 🚀 DEPLOY COMPLETO
|
|
201
|
+
|
|
202
|
+
```bash
|
|
203
|
+
cd server-edge-tracker
|
|
204
|
+
|
|
205
|
+
# Schemas D1 (ordem correta — todos idempotentes)
|
|
206
|
+
wrangler d1 execute cdp-edge-db --file=schema.sql --remote
|
|
207
|
+
wrangler d1 execute cdp-edge-db --file=migrate-v6.sql --remote
|
|
208
|
+
wrangler d1 execute cdp-edge-db --file=schema-segmentation.sql --remote
|
|
209
|
+
wrangler d1 execute cdp-edge-db --file=schema-bidding.sql --remote
|
|
210
|
+
wrangler d1 execute cdp-edge-db --file=schema-ab-ltv.sql --remote
|
|
211
|
+
wrangler d1 execute cdp-edge-db --file=schema-fraud.sql --remote
|
|
212
|
+
wrangler d1 execute cdp-edge-db --file=schema-indexes.sql --remote
|
|
213
|
+
wrangler d1 execute cdp-edge-db --file=migrate-v7.sql --remote
|
|
214
|
+
wrangler d1 execute cdp-edge-db --file=schema-ltv-feedback.sql --remote
|
|
215
|
+
wrangler d1 execute cdp-edge-db --file=schema-utm.sql --remote
|
|
216
|
+
wrangler d1 execute cdp-edge-db --file=schema-quiz.sql --remote
|
|
217
|
+
wrangler d1 execute cdp-edge-db --file=schema-sales-engine.sql --remote
|
|
218
|
+
|
|
219
|
+
# Secrets (nunca em arquivos — sempre via wrangler secret put)
|
|
220
|
+
wrangler secret put META_ACCESS_TOKEN
|
|
221
|
+
wrangler secret put GA4_API_SECRET
|
|
222
|
+
wrangler secret put TIKTOK_ACCESS_TOKEN
|
|
223
|
+
wrangler secret put ZAPMAN_API_KEY
|
|
224
|
+
|
|
225
|
+
# Deploy
|
|
226
|
+
wrangler deploy
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
---
|
|
230
|
+
|
|
231
|
+
## 🗺️ GRAPHIFY — Navegando o Código
|
|
232
|
+
|
|
233
|
+
```bash
|
|
234
|
+
/graphify . # gera o mapa
|
|
235
|
+
/graphify query "como funciona o quiz scoring?" # exploração BFS
|
|
236
|
+
/graphify query "nurture engine → meta audience" # exploração DFS
|
|
237
|
+
/graphify path "quiz_answers" "meta capi" # menor caminho
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
> Changelog completo → [CHANGELOG.md](./CHANGELOG.md)
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
|
|
244
|
+
### **CDP Edge — By Rica Soares**
|
|
245
|
+
> "Dados sem inteligência são apenas ruído. No Quantum Tier Enterprise, transformamos dados em ROAS."
|
|
246
|
+
|
|
247
|
+
© 2026 CDP Edge Premium. Todos os direitos reservados.
|
package/bin/cdp-edge.js
CHANGED
|
@@ -54,6 +54,7 @@ program
|
|
|
54
54
|
.command('validate <url>')
|
|
55
55
|
.description('Diagnóstico pós-deploy — verifica se o tracking está funcionando de ponta a ponta')
|
|
56
56
|
.option('--worker <url>', 'URL do Worker se diferente do site (ex: https://worker.meusite.workers.dev)')
|
|
57
|
+
.option('--admin-token <token>', 'Token Bearer ADMIN_API_TOKEN para diagnosticos admin')
|
|
57
58
|
.action(runValidate);
|
|
58
59
|
|
|
59
60
|
program
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"_comment": "Fonte de verdade para versões dos agent files. Atualizar quando modules/ ou index.ts mudarem. Use scripts/validate-agents.js para detectar drifts.",
|
|
3
|
-
"worker_version": "2.5.
|
|
3
|
+
"worker_version": "2.5.9",
|
|
4
4
|
"worker_hash_date": "2026-04-30",
|
|
5
5
|
"agents": {
|
|
6
6
|
"master-orchestrator": {
|
package/dist/commands/infra.js
CHANGED
|
@@ -42,7 +42,7 @@ ${chalk.cyan.bold('PASSO 7: Deploy')}
|
|
|
42
42
|
${chalk.cyan.bold('PASSO 8: Configurar Domínio')}
|
|
43
43
|
# No dashboard Cloudflare:
|
|
44
44
|
# 1. Workers & Pages → Routes → Add Route
|
|
45
|
-
# 2. Exemplo: seu-dominio.com/
|
|
45
|
+
# 2. Exemplo: seu-dominio.com/track/*
|
|
46
46
|
# 3. Aponte para o worker criado
|
|
47
47
|
|
|
48
48
|
${chalk.green.bold('✅ Pronto! Seu tracking Quantum Tier está ativo.')}
|
package/dist/commands/server.js
CHANGED
|
@@ -13,7 +13,7 @@ export async function runServer(dir) {
|
|
|
13
13
|
const spinner = ora('Gerando infraestrutura...').start();
|
|
14
14
|
|
|
15
15
|
try {
|
|
16
|
-
// Gerar index.js
|
|
16
|
+
// Gerar index.js
|
|
17
17
|
await generateWorker(dir);
|
|
18
18
|
|
|
19
19
|
// Gerar schema.sql
|
|
@@ -34,8 +34,8 @@ export async function runServer(dir) {
|
|
|
34
34
|
console.log(' wrangler secret put META_ACCESS_TOKEN');
|
|
35
35
|
console.log(' 2. Faça o deploy:');
|
|
36
36
|
console.log(' wrangler deploy');
|
|
37
|
-
console.log(' 3. Configure o schema D1:');
|
|
38
|
-
console.log(' wrangler d1 execute db --file=schema.sql');
|
|
37
|
+
console.log(' 3. Configure o schema D1:');
|
|
38
|
+
console.log(' wrangler d1 execute db --file=schema.sql');
|
|
39
39
|
|
|
40
40
|
} catch (error) {
|
|
41
41
|
spinner.fail('Erro ao gerar infraestrutura');
|
|
@@ -62,14 +62,14 @@ function generateWorkerCode() {
|
|
|
62
62
|
return `// CDP Edge Quantum Tier - Cloudflare Worker
|
|
63
63
|
// Auto-generated by cdp-edge npx
|
|
64
64
|
|
|
65
|
-
export default {
|
|
66
|
-
async fetch(request, env) {
|
|
65
|
+
export default {
|
|
66
|
+
async fetch(request, env, ctx) {
|
|
67
67
|
const url = new URL(request.url);
|
|
68
68
|
const path = url.pathname;
|
|
69
69
|
|
|
70
70
|
// Endpoint de tracking
|
|
71
|
-
if (path === '/
|
|
72
|
-
return handleTracking(request, env);
|
|
71
|
+
if (path === '/track') {
|
|
72
|
+
return handleTracking(request, env, ctx);
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
// Health check
|
|
@@ -83,22 +83,25 @@ export default {
|
|
|
83
83
|
}
|
|
84
84
|
};
|
|
85
85
|
|
|
86
|
-
async function handleTracking(request, env) {
|
|
87
|
-
try {
|
|
88
|
-
const body = await request.json();
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
86
|
+
async function handleTracking(request, env, ctx) {
|
|
87
|
+
try {
|
|
88
|
+
const body = await request.json();
|
|
89
|
+
const event = body.eventName || body.event_name || body.event;
|
|
90
|
+
const data = body.data || body;
|
|
91
|
+
const eventId = body.eventId || body.event_id || data.event_id || crypto.randomUUID();
|
|
92
|
+
const userId = body.userId || body.user_id || data.user_id || null;
|
|
93
|
+
|
|
94
|
+
// Persistir no D1
|
|
95
|
+
await env.DB.prepare(
|
|
96
|
+
'INSERT OR IGNORE INTO events (event_id, event_type, user_id, data, created_at) VALUES (?, ?, ?, ?, ?)'
|
|
97
|
+
).bind(eventId, event, userId, JSON.stringify(body), Date.now()).run();
|
|
98
|
+
|
|
99
|
+
// Enviar para APIs externas (background)
|
|
100
|
+
if (event === 'Purchase' || event === 'Lead') {
|
|
101
|
+
ctx.waitUntil(sendToPlatforms(event, data, env));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return new Response(JSON.stringify({ success: true, event_id: eventId }), {
|
|
102
105
|
headers: { 'Content-Type': 'application/json' }
|
|
103
106
|
});
|
|
104
107
|
} catch (error) {
|
|
@@ -128,8 +131,9 @@ CREATE TABLE IF NOT EXISTS identities (
|
|
|
128
131
|
phone TEXT,
|
|
129
132
|
created_at INTEGER NOT NULL,
|
|
130
133
|
updated_at INTEGER NOT NULL,
|
|
131
|
-
|
|
132
|
-
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
CREATE INDEX IF NOT EXISTS idx_identities_user_id ON identities(user_id);
|
|
133
137
|
|
|
134
138
|
-- Tabela de leads
|
|
135
139
|
CREATE TABLE IF NOT EXISTS leads (
|
|
@@ -149,14 +153,15 @@ CREATE TABLE IF NOT EXISTS events (
|
|
|
149
153
|
event_id TEXT NOT NULL UNIQUE,
|
|
150
154
|
event_type TEXT NOT NULL,
|
|
151
155
|
user_id TEXT,
|
|
152
|
-
data TEXT,
|
|
153
|
-
created_at INTEGER NOT NULL
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
);
|
|
158
|
-
|
|
159
|
-
|
|
156
|
+
data TEXT,
|
|
157
|
+
created_at INTEGER NOT NULL
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
CREATE INDEX IF NOT EXISTS idx_events_event_id ON events(event_id);
|
|
161
|
+
CREATE INDEX IF NOT EXISTS idx_events_event_type ON events(event_type);
|
|
162
|
+
CREATE INDEX IF NOT EXISTS idx_events_user_id ON events(user_id);
|
|
163
|
+
`;
|
|
164
|
+
}
|
|
160
165
|
|
|
161
166
|
function generateWranglerCode() {
|
|
162
167
|
return `# CDP Edge Quantum Tier - Wrangler Config
|
package/dist/commands/setup.js
CHANGED
|
@@ -12,6 +12,7 @@ import chalk from 'chalk';
|
|
|
12
12
|
import ora from 'ora';
|
|
13
13
|
import { writeFileSync } from 'fs';
|
|
14
14
|
import { join } from 'path';
|
|
15
|
+
import { randomBytes } from 'crypto';
|
|
15
16
|
|
|
16
17
|
function printBanner() {
|
|
17
18
|
console.log('');
|
|
@@ -256,6 +257,7 @@ export async function runSetupWizard(dir = '.') {
|
|
|
256
257
|
}
|
|
257
258
|
|
|
258
259
|
secrets.push({ key: 'SITE_DOMAIN', value: domain, platform: 'Worker' });
|
|
260
|
+
secrets.push({ key: 'ADMIN_API_TOKEN', value: randomBytes(32).toString('hex'), platform: 'Worker Admin' });
|
|
259
261
|
|
|
260
262
|
// Webhooks
|
|
261
263
|
const webhookUrls = {};
|
|
@@ -318,6 +320,7 @@ export async function runSetupWizard(dir = '.') {
|
|
|
318
320
|
...(Object.keys(webhookUrls).length > 0 ? ['Configurar as URLs de webhook nas plataformas de venda'] : []),
|
|
319
321
|
'Configurar Worker Route no Cloudflare: ' + domain + '/*',
|
|
320
322
|
'Testar o endpoint: https://' + domain + '/health',
|
|
323
|
+
'Validar diagnostico admin: cdp-edge validate https://' + domain + ' --admin-token <ADMIN_API_TOKEN>',
|
|
321
324
|
...(adsPlataformas.includes('meta') && creds.meta?.testCode ? ['Testar eventos no Meta Events Manager com o Test Event Code'] : []),
|
|
322
325
|
];
|
|
323
326
|
|