cdp-edge 1.23.2 → 1.24.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 +82 -21
- package/bin/cdp-edge.js +10 -1
- package/contracts/agent-versions.json +42 -41
- package/contracts/types.ts +81 -0
- package/dist/commands/install.js +6 -1
- package/dist/commands/server.js +4 -4
- package/docs/whatsapp-ctwa.md +3 -2
- package/extracted-skill/tracking-events-generator/agents/database-agent.md +5 -4
- package/extracted-skill/tracking-events-generator/agents/fraud-detection-agent.md +0 -1
- package/extracted-skill/tracking-events-generator/agents/linkedin-agent.md +1 -1
- package/extracted-skill/tracking-events-generator/agents/ltv-predictor-agent.md +4 -4
- package/extracted-skill/tracking-events-generator/agents/ml-clustering-agent.md +81 -70
- package/extracted-skill/tracking-events-generator/agents/page-analyzer.md +6 -2
- package/extracted-skill/tracking-events-generator/cdpTrack.js +7 -0
- package/extracted-skill/tracking-events-generator/models/lancamento-imobiliario.md +344 -0
- package/extracted-skill/tracking-events-generator/route-intent-capture.js +222 -0
- package/package.json +9 -5
- package/server-edge-tracker/INSTALAR.md +5 -5
- package/server-edge-tracker/{index.js → index.ts} +186 -72
- package/server-edge-tracker/modules/{db.js → db.ts} +180 -69
- package/server-edge-tracker/modules/dispatch/{ga4.js → ga4.ts} +12 -10
- package/server-edge-tracker/modules/dispatch/meta.ts +138 -0
- package/server-edge-tracker/modules/dispatch/{platforms.js → platforms.ts} +58 -56
- package/server-edge-tracker/modules/dispatch/{tiktok.js → tiktok.ts} +22 -20
- package/server-edge-tracker/modules/dispatch/{whatsapp.js → whatsapp.ts} +59 -25
- package/server-edge-tracker/modules/{intelligence.js → intelligence.ts} +175 -60
- package/server-edge-tracker/modules/ml/{bidding.js → bidding.ts} +37 -35
- package/server-edge-tracker/modules/ml/{fraud.js → fraud.ts} +49 -56
- package/server-edge-tracker/modules/ml/{logistic.js → logistic.ts} +44 -19
- package/server-edge-tracker/modules/ml/{ltv.js → ltv.ts} +179 -83
- package/server-edge-tracker/modules/ml/{matchquality.js → matchquality.ts} +70 -26
- package/server-edge-tracker/modules/ml/segmentation.ts +407 -0
- package/server-edge-tracker/modules/utils.ts +186 -0
- package/server-edge-tracker/schema-ltv-feedback.sql +11 -0
- package/server-edge-tracker/types.ts +251 -0
- package/server-edge-tracker/wrangler.toml +24 -6
- package/templates/lancamento-imobiliario.md +344 -0
- package/docs/PixelBuilder-Documentacao-Completa (2).docx +0 -0
- package/server-edge-tracker/modules/dispatch/meta.js +0 -119
- package/server-edge-tracker/modules/ml/segmentation.js +0 -316
- package/server-edge-tracker/modules/utils.js +0 -89
- package/server-edge-tracker/worker.js +0 -4577
package/README.md
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
**Padrão Quantum Tracking: 100% Cloudflare Edge.** Sem GTM. Sem Stape. Sem cookies de terceiros.
|
|
4
4
|
|
|
5
|
-
> **v2.
|
|
5
|
+
> **v2.2.5** — Versão Dinâmica · Correção de banner e CLI · Cloudflare Workers · Meta CAPI v22.0 · GA4 MP · TikTok Events API v1.3
|
|
6
|
+
|
|
7
|
+
> ⚠️ **REGRA DE OURO (SQUAD):** Todas as atualizações, correções ou novas features devem OBRIGATORIAMENTE ser documentadas de forma sincronizada neste `README.md`, no arquivo de instruções `CLAUDE.md` e no dossiê de diretoria `CDP-EDGE-BUSINESS-BOOK.md`. Nenhuma alteração passa sem esse tripé.
|
|
6
8
|
|
|
7
9
|
---
|
|
8
10
|
|
|
@@ -14,7 +16,7 @@
|
|
|
14
16
|
Meu ecossistema opera como um Cérebro de Conversão Privado na borda. Quando um evento de Lead bate no endpoint `/track`:
|
|
15
17
|
1. **O Escudo Frontal (Fraud Gate):** Inspeciono IP, ASN e Velocity na borda. Bloqueio bots silenciosamente antes mesmo deles carregarem.
|
|
16
18
|
2. **A Roleta Invisível (A/B LTV):** Faço o sorteio de prompts para testes A/B via KV Cache em ~0ms.
|
|
17
|
-
3. **O Cérebro Financeiro (LTV Predictor):** Rodo Machine Learning (
|
|
19
|
+
3. **O Cérebro Financeiro (LTV Predictor):** Rodo Machine Learning (Granite 4.0 Micro) para qualificar a intenção e gerar o LTV Preditivo.
|
|
18
20
|
4. **Envio para as Plataformas:** O Facebook/Google/LinkedIn recebem um payload limpo (sem bot) recheado com valor financeiro de intenção extrema.
|
|
19
21
|
5. **Máquina Autônoma (Background):** Meu banco SQLite (D1) retroalimenta os processos de Clustering (Fase 1) e Bidding (Fase 2) de forma autônoma pelas costas do usuário (`ctx.waitUntil`).
|
|
20
22
|
|
|
@@ -25,6 +27,60 @@ Meu ecossistema opera como um Cérebro de Conversão Privado na borda. Quando um
|
|
|
25
27
|
|
|
26
28
|
---
|
|
27
29
|
|
|
30
|
+
## 📋 CHANGELOG v2.2.5+ — Migração TypeScript (12 de Abril de 2026)
|
|
31
|
+
|
|
32
|
+
### 🔷 Worker 100% TypeScript — Migração Completa
|
|
33
|
+
|
|
34
|
+
Todo o código server-side (`server-edge-tracker/`) foi migrado de JavaScript para **TypeScript nativo**. O Wrangler compila diretamente o `.ts` sem etapa de build separada.
|
|
35
|
+
|
|
36
|
+
**Arquivos migrados (JS → TS):**
|
|
37
|
+
- `index.ts` — entry point do Worker (era `index.js`)
|
|
38
|
+
- `types.ts` — novo arquivo centralizado com `Env`, `TrackPayload`, tipos de webhook
|
|
39
|
+
- `modules/utils.ts`, `modules/db.ts`, `modules/intelligence.ts`
|
|
40
|
+
- `modules/dispatch/` — `meta.ts`, `ga4.ts`, `tiktok.ts`, `platforms.ts`, `whatsapp.ts`
|
|
41
|
+
- `modules/ml/` — `ltv.ts`, `fraud.ts`, `bidding.ts`, `segmentation.ts`, `logistic.ts`, `matchquality.ts`
|
|
42
|
+
|
|
43
|
+
**Infraestrutura:**
|
|
44
|
+
- `tsconfig.json` adicionado (`target: ESNext`, `moduleResolution: bundler`, `strict: true`)
|
|
45
|
+
- `wrangler.toml` — `main = "index.ts"` (TypeScript nativo, sem transpile manual)
|
|
46
|
+
- `npm run typecheck` — novo script para validação de tipos (`tsc --noEmit`)
|
|
47
|
+
|
|
48
|
+
**Testes de integração:**
|
|
49
|
+
- `tests/integration/setup.js` atualizado para compilar o `.ts` com esbuild em memória antes de passar ao Miniflare (esbuild já é dep transitiva do Miniflare 3)
|
|
50
|
+
|
|
51
|
+
**Breaking change:** nenhuma — API HTTP e comportamento em runtime são idênticos.
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## 📋 CHANGELOG v2.2.5 (11 de Abril de 2026)
|
|
56
|
+
|
|
57
|
+
### 🔧 Correção de Versão Dinâmica
|
|
58
|
+
|
|
59
|
+
- **Versão Dinâmica**: `bin/cdp-edge.js` e `dist/commands/install.js` agora leem a versão do `package.json` dinamicamente
|
|
60
|
+
- **Banner Corrigido**: O banner de instalação agora mostra sempre a versão correta (`cdp-edge --version`)
|
|
61
|
+
- **Compatibilidade**: Garante que a versão exibida no CLI e banner esteja sempre sincronizada com o `package.json`
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## 📋 CHANGELOG v2.2.0 (10 de Abril de 2026)
|
|
66
|
+
|
|
67
|
+
### 🤖 AI Engine Upgrade — Novos Modelos
|
|
68
|
+
|
|
69
|
+
- **LTV Prediction**: `@cf/meta/llama-3.1-8b-instruct` → **`@cf/ibm-granite/granite-4.0-h-micro`** (menor latência, otimizado para edge e function calling)
|
|
70
|
+
- **ML Clustering**: algoritmo LLM simulado → **K-means vetorial real** com embeddings `@cf/baai/bge-m3` (distância cosseno, K-means++ inicialização, silhouette score real)
|
|
71
|
+
- Granite continua sendo usado para naming dos segmentos pós-clustering
|
|
72
|
+
|
|
73
|
+
### 🧹 Limpeza (Zero Lixo)
|
|
74
|
+
|
|
75
|
+
- Removido: detecção de emails descartáveis (mailinator, guerrilla, tempmail, etc.) do Fraud Gate e do agente `fraud-detection-agent.md`
|
|
76
|
+
- Removido: secrets `WEBHOOK_SECRET_HOTMART` e `WEBHOOK_SECRET_KIWIFY` (wrangler + wrangler.toml)
|
|
77
|
+
|
|
78
|
+
### 🔧 Observability
|
|
79
|
+
|
|
80
|
+
- Adicionado bloco `[observability]` no `wrangler.toml` (`logs.enabled = true`, `traces.enabled = false`)
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
28
84
|
## 📋 CHANGELOG v2.0.7 (10 de Abril de 2026)
|
|
29
85
|
|
|
30
86
|
### 🔧 Audit Completo — 45 Agentes
|
|
@@ -36,7 +92,7 @@ Meu ecossistema opera como um Cérebro de Conversão Privado na borda. Quando um
|
|
|
36
92
|
- **YouTube events**: `video_milestone`/`video_progress_25/50/75` → `video_25`/`video_50`/`video_75` (alinhado ao VALID_EVENT_NAMES do worker)
|
|
37
93
|
- **LinkedIn CAPI**: endpoint `/rest/conversionEvents` + header `LinkedIn-Version: 202401` em `contracts/api-versions.json`
|
|
38
94
|
- **Workers AI model**: `llama-3-8b-instruct` → `@cf/meta/llama-3.1-8b-instruct`
|
|
39
|
-
- **
|
|
95
|
+
- **index.ts**: Content-Length guard (413 se > 64KB), payload validation (allowlist 19 events, 512 chars, value range), PII removido dos logs
|
|
40
96
|
- **Testes**: bugs críticos em `deduplication.test.js` corrigidos (template literals escapados, prefixo errado)
|
|
41
97
|
- **npm**: lodash 4.17.23 → 4.18.1, node-fetch removido
|
|
42
98
|
|
|
@@ -78,14 +134,14 @@ Meu ecossistema opera como um Cérebro de Conversão Privado na borda. Quando um
|
|
|
78
134
|
- **`GET /api/fraud/blocklist`** — IPs/fingerprints atualmente bloqueados
|
|
79
135
|
- **`POST /api/fraud/blocklist/add`** — Bloquear IP ou fingerprint (via KV, efeito imediato)
|
|
80
136
|
- **`DELETE /api/fraud/blocklist/remove`** — Remover do blocklist
|
|
81
|
-
- Sinais detectados: bot_score, datacenter IP, velocity attack,
|
|
137
|
+
- Sinais detectados: bot_score, datacenter IP, velocity attack, headless UA, sem Accept-Language
|
|
82
138
|
- Schema D1: `fraud_signals`, `fraud_alerts` + VIEW `v_fraud_dashboard`
|
|
83
139
|
- Agente: `fraud-detection-agent.md`
|
|
84
140
|
|
|
85
141
|
### 🔧 Fix: `wrangler.toml` atualizado
|
|
86
142
|
- Todos os placeholders (`SEU_D1_DATABASE_ID`, `SEU_KV_NAMESPACE_ID`) substituídos pelos IDs reais da conta Cloudflare
|
|
87
|
-
- D1: `
|
|
88
|
-
- KV: `
|
|
143
|
+
- D1: `SEU_DATABASE_ID`
|
|
144
|
+
- KV: `SEU_KV_ID`
|
|
89
145
|
|
|
90
146
|
---
|
|
91
147
|
|
|
@@ -98,7 +154,7 @@ graph TD
|
|
|
98
154
|
FraudGate -->|score ≥ 80: Silent Drop 200| Void[/dev/null]
|
|
99
155
|
FraudGate -->|score < 80: Permitido| Worker[Cloudflare Worker Agent]
|
|
100
156
|
Worker -->|Identity Graph + _cdp_uid| D1[(D1 SQL — 21 tabelas)]
|
|
101
|
-
Worker -->|LTV + A/B Prompt| AI[Workers AI
|
|
157
|
+
Worker -->|LTV + A/B Prompt| AI[Workers AI Granite 4.0 Micro]
|
|
102
158
|
Worker -->|Segmento ML| Cluster[ML Clustering Engine]
|
|
103
159
|
Cluster -->|Bid otimizado| Bidding[Bidding Recommendations]
|
|
104
160
|
Worker -->|Background| Queue[Cloudflare Queues]
|
|
@@ -138,7 +194,7 @@ O sistema é composto por **43+ agentes** coordenados pelo **Master Orchestrator
|
|
|
138
194
|
### 🤖 Enterprise Intelligence (Fase 1–4)
|
|
139
195
|
| Agente | Endpoint Principal | Impacto |
|
|
140
196
|
|---|---|---|
|
|
141
|
-
| **ML Clustering Agent** | `POST /api/segmentation/cluster` |
|
|
197
|
+
| **ML Clustering Agent** | `POST /api/segmentation/cluster` | K-means vetorial real (bge-m3 embeddings + Granite naming) |
|
|
142
198
|
| **Bidding Agent** | `POST /api/bidding/recommend` | -20% CPA via bid por segmento de LTV |
|
|
143
199
|
| **A/B LTV Agent** | `POST /api/ltv/ab-test/create` | +25% precisão LTV via test de prompts |
|
|
144
200
|
| **Fraud Detection Agent** | Auto em `/track` | Bloqueia click fraud, bots, velocity attacks |
|
|
@@ -187,7 +243,7 @@ POST /track (evento Lead)
|
|
|
187
243
|
├─ [2] 🔮 A/B LTV Testing — sorteia variação ativa (KV cache ~0ms)
|
|
188
244
|
│ └─ passa customSystemPrompt para predictLtv()
|
|
189
245
|
│
|
|
190
|
-
├─ [3] 🧮 LTV Prediction — Workers AI
|
|
246
|
+
├─ [3] 🧮 LTV Prediction — Workers AI Granite 4.0 Micro
|
|
191
247
|
│ └─ Score 0-100 → class High/Medium/Low → valor em BRL
|
|
192
248
|
│
|
|
193
249
|
├─ [4] 💾 D1 Writes (background via ctx.waitUntil)
|
|
@@ -203,27 +259,34 @@ POST /track (evento Lead)
|
|
|
203
259
|
|
|
204
260
|
## 💻 INSTALAÇÃO E USO
|
|
205
261
|
|
|
206
|
-
|
|
262
|
+
### OPÇÃO 1 — Instalação via npm (Recomendada)
|
|
263
|
+
|
|
264
|
+
Abra o terminal dentro da pasta do projeto do cliente e rode:
|
|
207
265
|
|
|
208
|
-
|
|
266
|
+
```bash
|
|
267
|
+
npx cdp-edge install
|
|
268
|
+
```
|
|
209
269
|
|
|
210
|
-
|
|
270
|
+
Ou instale globalmente e use em qualquer projeto:
|
|
211
271
|
|
|
212
272
|
```bash
|
|
213
|
-
|
|
273
|
+
npm install -g cdp-edge
|
|
274
|
+
cdp-edge install . --name "Nome do Projeto"
|
|
214
275
|
```
|
|
215
|
-
*(O ponto no final garante que os arquivos desçam diretamente dentro da pasta atual).*
|
|
216
276
|
|
|
217
|
-
|
|
277
|
+
> **Já tem o CDP Edge instalado globalmente?** Atualize para a versão mais recente:
|
|
278
|
+
> ```bash
|
|
279
|
+
> npm install -g cdp-edge@latest
|
|
280
|
+
> ```
|
|
218
281
|
|
|
219
|
-
|
|
282
|
+
### OPÇÃO 2 — Instalação via Git Clone
|
|
220
283
|
|
|
221
284
|
```bash
|
|
222
|
-
|
|
223
|
-
cdp-edge install . --name "Nome do Projeto"
|
|
285
|
+
git clone https://github.com/ricardosoli777/CDP-Edge-Premium.git .
|
|
224
286
|
```
|
|
287
|
+
*(O ponto no final garante que os arquivos desçam diretamente dentro da pasta atual).*
|
|
225
288
|
|
|
226
|
-
###
|
|
289
|
+
### Ativar no Claude Code
|
|
227
290
|
|
|
228
291
|
```bash
|
|
229
292
|
claude .
|
|
@@ -279,8 +342,6 @@ wrangler deploy
|
|
|
279
342
|
|---|---|---|
|
|
280
343
|
| `/track` | POST | Evento principal (browser → CAPI) |
|
|
281
344
|
| `/health` | GET | Smoke test completo |
|
|
282
|
-
| `/webhook/hotmart` | POST | Webhook Hotmart Purchase |
|
|
283
|
-
| `/webhook/kiwify` | POST | Webhook Kiwify Purchase |
|
|
284
345
|
| `/webhook/ticto` | POST | Webhook Ticto Purchase |
|
|
285
346
|
|
|
286
347
|
### Intelligence ML
|
package/bin/cdp-edge.js
CHANGED
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
* Sistema multi-agente para tracking digital Quantum Tier
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import fs from 'fs';
|
|
9
|
+
import path from 'path';
|
|
10
|
+
import { fileURLToPath } from 'url';
|
|
8
11
|
import { Command } from 'commander';
|
|
9
12
|
import { runSetupWizard } from '../dist/commands/setup.js';
|
|
10
13
|
import { runAnalyze } from '../dist/commands/analyze.js';
|
|
@@ -13,12 +16,18 @@ import { runValidate } from '../dist/commands/validate.js';
|
|
|
13
16
|
import { runInfra } from '../dist/commands/infra.js';
|
|
14
17
|
import { runInstall } from '../dist/commands/install.js';
|
|
15
18
|
|
|
19
|
+
// Ler versão do package.json
|
|
20
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
21
|
+
const packageJsonPath = path.join(__dirname, '..', 'package.json');
|
|
22
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
23
|
+
const CDP_VERSION = packageJson.version;
|
|
24
|
+
|
|
16
25
|
const program = new Command();
|
|
17
26
|
|
|
18
27
|
program
|
|
19
28
|
.name('cdp-edge')
|
|
20
29
|
.description('CDP Edge Quantum Tier - Sistema multi-agente para tracking digital Cloudflare Native')
|
|
21
|
-
.version(
|
|
30
|
+
.version(CDP_VERSION);
|
|
22
31
|
|
|
23
32
|
// Comando padrão (wizard interativo)
|
|
24
33
|
program
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
|
-
"_comment": "Fonte de verdade para versões dos agent files. Atualizar
|
|
3
|
-
"worker_version": "2.
|
|
4
|
-
"worker_hash_date": "2026-04-
|
|
2
|
+
"_comment": "Fonte de verdade para versões dos agent files. Atualizar quando modules/ ou index.js mudarem. Use scripts/validate-agents.js para detectar drifts.",
|
|
3
|
+
"worker_version": "2.2.3",
|
|
4
|
+
"worker_hash_date": "2026-04-11",
|
|
5
5
|
"agents": {
|
|
6
6
|
"master-orchestrator": {
|
|
7
7
|
"version": "2.0.7",
|
|
8
8
|
"last_synced": "2026-04-10",
|
|
9
9
|
"depends_on": [
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
10
|
+
"index.js:fetch",
|
|
11
|
+
"index.js:endpoints",
|
|
12
|
+
"modules/utils.js:VALID_EVENT_NAMES"
|
|
13
13
|
],
|
|
14
14
|
"critical_sections": [
|
|
15
15
|
"endpoints",
|
|
@@ -23,10 +23,10 @@
|
|
|
23
23
|
"version": "2.0.7",
|
|
24
24
|
"last_synced": "2026-04-10",
|
|
25
25
|
"depends_on": [
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
26
|
+
"index.js:fetch",
|
|
27
|
+
"modules/db.js:saveLead",
|
|
28
|
+
"modules/db.js:upsertProfile",
|
|
29
|
+
"index.js:bindings"
|
|
30
30
|
],
|
|
31
31
|
"critical_sections": [
|
|
32
32
|
"endpoint /track",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"version": "2.0.7",
|
|
41
41
|
"last_synced": "2026-04-10",
|
|
42
42
|
"depends_on": [
|
|
43
|
-
"
|
|
43
|
+
"modules/dispatch/meta.js:sendMetaCapi",
|
|
44
44
|
"contracts/api-versions.json:meta"
|
|
45
45
|
],
|
|
46
46
|
"critical_sections": [
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"version": "2.0.7",
|
|
55
55
|
"last_synced": "2026-04-10",
|
|
56
56
|
"depends_on": [
|
|
57
|
-
"
|
|
57
|
+
"modules/dispatch/ga4.js:sendGA4Mp",
|
|
58
58
|
"contracts/api-versions.json:google"
|
|
59
59
|
],
|
|
60
60
|
"critical_sections": [
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"version": "2.0.7",
|
|
68
68
|
"last_synced": "2026-04-10",
|
|
69
69
|
"depends_on": [
|
|
70
|
-
"
|
|
70
|
+
"modules/dispatch/tiktok.js:sendTikTokApi",
|
|
71
71
|
"contracts/api-versions.json:tiktok"
|
|
72
72
|
],
|
|
73
73
|
"critical_sections": [
|
|
@@ -93,8 +93,8 @@
|
|
|
93
93
|
"version": "2.0.7",
|
|
94
94
|
"last_synced": "2026-04-10",
|
|
95
95
|
"depends_on": [
|
|
96
|
-
"
|
|
97
|
-
"
|
|
96
|
+
"modules/dispatch/whatsapp.js:sendWhatsApp",
|
|
97
|
+
"modules/dispatch/whatsapp.js:processWhatsAppWebhook"
|
|
98
98
|
],
|
|
99
99
|
"critical_sections": [
|
|
100
100
|
"WHATSAPP_ACCESS_TOKEN",
|
|
@@ -107,8 +107,7 @@
|
|
|
107
107
|
"version": "2.0.7",
|
|
108
108
|
"last_synced": "2026-04-10",
|
|
109
109
|
"depends_on": [
|
|
110
|
-
"
|
|
111
|
-
"worker.js:checkApiVersionsIntelligence"
|
|
110
|
+
"modules/intelligence.js:runIntelligenceAgent"
|
|
112
111
|
],
|
|
113
112
|
"critical_sections": [
|
|
114
113
|
"cron schedule",
|
|
@@ -121,8 +120,8 @@
|
|
|
121
120
|
"version": "2.0.7",
|
|
122
121
|
"last_synced": "2026-04-10",
|
|
123
122
|
"depends_on": [
|
|
124
|
-
"
|
|
125
|
-
"
|
|
123
|
+
"modules/ml/fraud.js:checkFraudGate",
|
|
124
|
+
"modules/ml/fraud.js:handleFraudAlerts",
|
|
126
125
|
"schema-fraud.sql"
|
|
127
126
|
],
|
|
128
127
|
"critical_sections": [
|
|
@@ -136,7 +135,7 @@
|
|
|
136
135
|
"version": "2.0.7",
|
|
137
136
|
"last_synced": "2026-04-10",
|
|
138
137
|
"depends_on": [
|
|
139
|
-
"
|
|
138
|
+
"modules/ml/segmentation.js:handleSegmentationCluster",
|
|
140
139
|
"schema-segmentation.sql"
|
|
141
140
|
],
|
|
142
141
|
"critical_sections": [
|
|
@@ -150,7 +149,7 @@
|
|
|
150
149
|
"version": "2.0.7",
|
|
151
150
|
"last_synced": "2026-04-10",
|
|
152
151
|
"depends_on": [
|
|
153
|
-
"
|
|
152
|
+
"modules/ml/bidding.js:handleBiddingRecommend",
|
|
154
153
|
"schema-bidding.sql"
|
|
155
154
|
],
|
|
156
155
|
"critical_sections": [
|
|
@@ -163,8 +162,8 @@
|
|
|
163
162
|
"version": "2.0.7",
|
|
164
163
|
"last_synced": "2026-04-10",
|
|
165
164
|
"depends_on": [
|
|
166
|
-
"
|
|
167
|
-
"
|
|
165
|
+
"modules/ml/ltv.js:predictLtv",
|
|
166
|
+
"modules/ml/ltv.js:getLtvAbVariation",
|
|
168
167
|
"schema-ab-ltv.sql"
|
|
169
168
|
],
|
|
170
169
|
"critical_sections": [
|
|
@@ -177,8 +176,8 @@
|
|
|
177
176
|
"version": "2.0.7",
|
|
178
177
|
"last_synced": "2026-04-10",
|
|
179
178
|
"depends_on": [
|
|
180
|
-
"
|
|
181
|
-
"
|
|
179
|
+
"modules/ml/fraud.js:checkFraudGate",
|
|
180
|
+
"modules/dispatch/whatsapp.js:verifyHmac"
|
|
182
181
|
],
|
|
183
182
|
"critical_sections": [
|
|
184
183
|
"env.DB.prepare",
|
|
@@ -191,9 +190,9 @@
|
|
|
191
190
|
"version": "2.0.7",
|
|
192
191
|
"last_synced": "2026-04-10",
|
|
193
192
|
"depends_on": [
|
|
194
|
-
"
|
|
195
|
-
"
|
|
196
|
-
"
|
|
193
|
+
"modules/db.js:saveLead",
|
|
194
|
+
"modules/dispatch/meta.js:sendMetaCapi",
|
|
195
|
+
"modules/dispatch/tiktok.js:sendTikTokApi"
|
|
197
196
|
],
|
|
198
197
|
"critical_sections": [
|
|
199
198
|
"env.DB.prepare",
|
|
@@ -225,7 +224,8 @@
|
|
|
225
224
|
"version": "2.0.7",
|
|
226
225
|
"last_synced": "2026-04-10",
|
|
227
226
|
"depends_on": [
|
|
228
|
-
"
|
|
227
|
+
"index.js",
|
|
228
|
+
"modules/",
|
|
229
229
|
"all agents"
|
|
230
230
|
],
|
|
231
231
|
"critical_sections": [
|
|
@@ -239,7 +239,7 @@
|
|
|
239
239
|
"version": "2.0.7",
|
|
240
240
|
"last_synced": "2026-04-10",
|
|
241
241
|
"depends_on": [
|
|
242
|
-
"
|
|
242
|
+
"modules/ml/ltv.js:predictLtv"
|
|
243
243
|
],
|
|
244
244
|
"critical_sections": [
|
|
245
245
|
"@cf/meta/llama-3.1-8b-instruct model name"
|
|
@@ -268,7 +268,7 @@
|
|
|
268
268
|
"version": "2.0.7",
|
|
269
269
|
"last_synced": "2026-04-10",
|
|
270
270
|
"depends_on": [
|
|
271
|
-
"
|
|
271
|
+
"index.js:GET /health"
|
|
272
272
|
],
|
|
273
273
|
"critical_sections": [
|
|
274
274
|
"env.DB.prepare",
|
|
@@ -280,7 +280,7 @@
|
|
|
280
280
|
"version": "2.0.7",
|
|
281
281
|
"last_synced": "2026-04-10",
|
|
282
282
|
"depends_on": [
|
|
283
|
-
"
|
|
283
|
+
"modules/intelligence.js:runIntelligenceAgent"
|
|
284
284
|
],
|
|
285
285
|
"critical_sections": [
|
|
286
286
|
"env.DB.prepare",
|
|
@@ -305,7 +305,7 @@
|
|
|
305
305
|
"version": "2.0.7",
|
|
306
306
|
"last_synced": "2026-04-10",
|
|
307
307
|
"depends_on": [
|
|
308
|
-
"
|
|
308
|
+
"index.js",
|
|
309
309
|
"all endpoints"
|
|
310
310
|
],
|
|
311
311
|
"critical_sections": [
|
|
@@ -319,8 +319,8 @@
|
|
|
319
319
|
"version": "2.0.7",
|
|
320
320
|
"last_synced": "2026-04-10",
|
|
321
321
|
"depends_on": [
|
|
322
|
-
"
|
|
323
|
-
"
|
|
322
|
+
"modules/db.js:saveLead",
|
|
323
|
+
"modules/db.js:upsertProfile"
|
|
324
324
|
],
|
|
325
325
|
"critical_sections": [
|
|
326
326
|
"env.DB.prepare",
|
|
@@ -332,7 +332,8 @@
|
|
|
332
332
|
"version": "2.0.7",
|
|
333
333
|
"last_synced": "2026-04-10",
|
|
334
334
|
"depends_on": [
|
|
335
|
-
"
|
|
335
|
+
"index.js",
|
|
336
|
+
"modules/"
|
|
336
337
|
],
|
|
337
338
|
"critical_sections": [
|
|
338
339
|
"env.GEO_CACHE (not env.CACHE_KV)"
|
|
@@ -353,12 +354,12 @@
|
|
|
353
354
|
}
|
|
354
355
|
},
|
|
355
356
|
"change_triggers": {
|
|
356
|
-
"
|
|
357
|
-
"
|
|
358
|
-
"
|
|
359
|
-
"
|
|
357
|
+
"index.js:addNewEndpoint": "Atualizar: master-orchestrator, server-tracking, browser-tracking, debug-agent, intelligence-agent",
|
|
358
|
+
"index.js:changeSecretName": "Atualizar: devops-agent, server-tracking, intelligence-agent, whatsapp-ctwa-setup-agent, database-agent",
|
|
359
|
+
"modules/utils.js:VALID_EVENT_NAMES": "Atualizar: master-orchestrator, youtube-agent, validator-agent, browser-tracking",
|
|
360
|
+
"modules/ml/ltv.js:changeAIModel": "Atualizar: ml-clustering-agent, ab-ltv-agent, ltv-predictor-agent",
|
|
360
361
|
"schema.sql:addTable": "Atualizar: database-agent (table count), devops-agent (migration order)",
|
|
361
362
|
"wrangler.toml:addBinding": "Atualizar: devops-agent, database-agent, debug-agent",
|
|
362
363
|
"contracts/api-versions.json:bumpVersion": "Atualizar: agent especialista + master-orchestrator"
|
|
363
364
|
}
|
|
364
|
-
}
|
|
365
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// CDP Edge Premium - API Contracts & Typings
|
|
2
|
+
|
|
3
|
+
export interface QuantumEventPayload {
|
|
4
|
+
eventName: string;
|
|
5
|
+
eventId: string;
|
|
6
|
+
userId: string;
|
|
7
|
+
email?: string | null;
|
|
8
|
+
phone?: string | null;
|
|
9
|
+
firstName?: string | null;
|
|
10
|
+
lastName?: string | null;
|
|
11
|
+
city?: string | null;
|
|
12
|
+
state?: string | null;
|
|
13
|
+
zip?: string | null;
|
|
14
|
+
country?: string | null;
|
|
15
|
+
|
|
16
|
+
// Identifiers
|
|
17
|
+
fbp?: string | null;
|
|
18
|
+
fbc?: string | null;
|
|
19
|
+
ttp?: string | null;
|
|
20
|
+
gaClientId?: string | null;
|
|
21
|
+
|
|
22
|
+
// Parameters
|
|
23
|
+
value?: number | null;
|
|
24
|
+
currency?: string;
|
|
25
|
+
contentIds?: string[];
|
|
26
|
+
contentName?: string;
|
|
27
|
+
contentType?: string;
|
|
28
|
+
pageUrl?: string;
|
|
29
|
+
orderId?: string;
|
|
30
|
+
|
|
31
|
+
// Quantum Tracking Details
|
|
32
|
+
intentScoreNum?: number | null;
|
|
33
|
+
metaSignal?: number;
|
|
34
|
+
distanceBucket?: string;
|
|
35
|
+
funnelLevel?: string;
|
|
36
|
+
botScore?: number;
|
|
37
|
+
|
|
38
|
+
// Any extra params
|
|
39
|
+
[key: string]: any;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface AgencyContext {
|
|
43
|
+
// Required Env mappings for specialists
|
|
44
|
+
META_ACCESS_TOKEN?: string;
|
|
45
|
+
META_PIXEL_ID?: string;
|
|
46
|
+
GA4_API_SECRET?: string;
|
|
47
|
+
GA4_MEASUREMENT_ID?: string;
|
|
48
|
+
TIKTOK_ACCESS_TOKEN?: string;
|
|
49
|
+
TIKTOK_PIXEL_ID?: string;
|
|
50
|
+
PINTEREST_ACCESS_TOKEN?: string;
|
|
51
|
+
PINTEREST_AD_ACCOUNT_ID?: string;
|
|
52
|
+
REDDIT_ACCESS_TOKEN?: string;
|
|
53
|
+
REDDIT_AD_ACCOUNT_ID?: string;
|
|
54
|
+
LINKEDIN_ACCESS_TOKEN?: string;
|
|
55
|
+
LINKEDIN_AD_ACCOUNT_ID?: string;
|
|
56
|
+
SPOTIFY_ACCESS_TOKEN?: string;
|
|
57
|
+
SPOTIFY_AD_ACCOUNT_ID?: string;
|
|
58
|
+
|
|
59
|
+
// Databases and Stores
|
|
60
|
+
DB?: any; // D1 Database
|
|
61
|
+
GEO_CACHE?: any; // KV Namespace
|
|
62
|
+
RATE_LIMITER?: any;
|
|
63
|
+
SITE_DOMAIN?: string;
|
|
64
|
+
|
|
65
|
+
[key: string]: any;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface ApiVersionsConfig {
|
|
69
|
+
metadata: {
|
|
70
|
+
version: string;
|
|
71
|
+
};
|
|
72
|
+
meta: any;
|
|
73
|
+
google: any;
|
|
74
|
+
tiktok: any;
|
|
75
|
+
pinterest: any;
|
|
76
|
+
reddit: any;
|
|
77
|
+
linkedin: any;
|
|
78
|
+
bing: any;
|
|
79
|
+
youtube: any;
|
|
80
|
+
spotify: any;
|
|
81
|
+
}
|
package/dist/commands/install.js
CHANGED
|
@@ -18,6 +18,11 @@ import chalk from 'chalk';
|
|
|
18
18
|
|
|
19
19
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
20
20
|
|
|
21
|
+
// Ler versão do package.json
|
|
22
|
+
const packageJsonPath = path.join(__dirname, '..', '..', 'package.json');
|
|
23
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
24
|
+
const CDP_VERSION = packageJson.version;
|
|
25
|
+
|
|
21
26
|
// Raiz do pacote CDP Edge (2 níveis acima de dist/commands/)
|
|
22
27
|
const CDP_EDGE_ROOT = path.resolve(__dirname, '..', '..');
|
|
23
28
|
|
|
@@ -32,7 +37,7 @@ function printBanner() {
|
|
|
32
37
|
console.log(chalk.cyan('╚██████╗██████╔╝██║ ███████╗██████╔╝╚██████╔╝███████╗'));
|
|
33
38
|
console.log(chalk.cyan(' ╚═════╝╚═════╝ ╚═╝ ╚══════╝╚═════╝ ╚═════╝╚══════╝'));
|
|
34
39
|
console.log('');
|
|
35
|
-
console.log(chalk.gray(
|
|
40
|
+
console.log(chalk.gray(` Customer Data Platform on the Edge · Global Edge Tracking · v${CDP_VERSION}`));
|
|
36
41
|
console.log('');
|
|
37
42
|
console.log(chalk.gray('═'.repeat(68)));
|
|
38
43
|
console.log('');
|
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
|
|
16
|
+
// Gerar index.js
|
|
17
17
|
await generateWorker(dir);
|
|
18
18
|
|
|
19
19
|
// Gerar schema.sql
|
|
@@ -25,7 +25,7 @@ export async function runServer(dir) {
|
|
|
25
25
|
spinner.succeed(chalk.green('Infraestrutura gerada!'));
|
|
26
26
|
|
|
27
27
|
console.log('\n' + chalk.yellow('Arquivos gerados:'));
|
|
28
|
-
console.log(` ${chalk.gray('├─')}
|
|
28
|
+
console.log(` ${chalk.gray('├─')} index.js`);
|
|
29
29
|
console.log(` ${chalk.gray('├─')} schema.sql`);
|
|
30
30
|
console.log(` ${chalk.gray('└─')} wrangler.toml`);
|
|
31
31
|
|
|
@@ -44,7 +44,7 @@ export async function runServer(dir) {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
async function generateWorker(dir) {
|
|
47
|
-
const workerPath = join(dir, '
|
|
47
|
+
const workerPath = join(dir, 'index.js');
|
|
48
48
|
await fs.writeFile(workerPath, generateWorkerCode());
|
|
49
49
|
}
|
|
50
50
|
|
|
@@ -163,7 +163,7 @@ function generateWranglerCode() {
|
|
|
163
163
|
# Auto-generated by cdp-edge npx
|
|
164
164
|
|
|
165
165
|
name = "cdp-edge-worker"
|
|
166
|
-
main = "
|
|
166
|
+
main = "index.js"
|
|
167
167
|
compatibility_date = "2024-01-01"
|
|
168
168
|
|
|
169
169
|
[[d1_databases]]
|
package/docs/whatsapp-ctwa.md
CHANGED
|
@@ -199,11 +199,12 @@ fetch('https://SEU_WORKER.SEU_USUARIO.workers.dev/track', {
|
|
|
199
199
|
|
|
200
200
|
| Arquivo | Descrição |
|
|
201
201
|
|---------|-----------|
|
|
202
|
-
| `server-edge-tracker/
|
|
202
|
+
| `server-edge-tracker/modules/dispatch/whatsapp.ts` | Funções `processWhatsAppWebhook()`, `sendWhatsApp()`, `verifyHmac()` |
|
|
203
|
+
| `server-edge-tracker/index.ts` | Rotas `/webhook/whatsapp` (GET verify + POST mensagens) |
|
|
203
204
|
| `server-edge-tracker/migrate-v6.sql` | Migration que criou a tabela `whatsapp_contacts` |
|
|
204
205
|
| `server-edge-tracker/wrangler.toml` | Secret `WA_WEBHOOK_VERIFY_TOKEN` documentado |
|
|
205
206
|
| `server-edge-tracker/schema.sql` | Schema completo do D1 (referência) |
|
|
206
207
|
|
|
207
208
|
---
|
|
208
209
|
|
|
209
|
-
*Implementado em: 30 de março de 2026. CDP Edge v1.2 — WhatsApp CTWA Module.*
|
|
210
|
+
*Implementado em: 30 de março de 2026. CDP Edge v1.2 — WhatsApp CTWA Module. Migrado para TypeScript (`whatsapp.ts`) em 12 de abril de 2026 (v2.2.5+).*
|
|
@@ -467,9 +467,10 @@ await env.AUDIT_LOGS.put(logKey, JSON.stringify({
|
|
|
467
467
|
|
|
468
468
|
### Modelo em Uso
|
|
469
469
|
```
|
|
470
|
-
@cf/
|
|
471
|
-
|
|
472
|
-
|
|
470
|
+
@cf/ibm-granite/granite-4.0-h-micro ← LTV Prediction + Naming de Clusters
|
|
471
|
+
@cf/baai/bge-m3 ← Embeddings para K-means vetorial (ML Clustering)
|
|
472
|
+
Custo Granite: ~20-35 neurônios/requisição (3x mais eficiente que Llama 3.1 8B)
|
|
473
|
+
Limite Free: 10.000 neurônios/dia (~350 predições/dia com Granite)
|
|
473
474
|
```
|
|
474
475
|
|
|
475
476
|
### Uso no Worker (LTV Prediction)
|
|
@@ -485,7 +486,7 @@ async function predictLtv(leadData, env) {
|
|
|
485
486
|
Responda apenas: {"class": "high|medium|low", "value": 0-1000}
|
|
486
487
|
`;
|
|
487
488
|
|
|
488
|
-
const response = await env.AI.run('@cf/
|
|
489
|
+
const response = await env.AI.run('@cf/ibm-granite/granite-4.0-h-micro', {
|
|
489
490
|
messages: [{ role: 'user', content: prompt }],
|
|
490
491
|
max_tokens: 50
|
|
491
492
|
});
|
|
@@ -71,7 +71,6 @@ checkFraudGate(env, request, payload)
|
|
|
71
71
|
| IP de datacenter | ASN = AWS, GCP, Azure, DigitalOcean, Linode | +35 pts |
|
|
72
72
|
| Sem headers de browser | Accept-Language ausente | +20 pts |
|
|
73
73
|
| Geo impossível | IP country ≠ país esperado (BR fora da LATAM) | +10 pts |
|
|
74
|
-
| Email temporário | @mailinator, @guerrilla, @tempmail, etc. | +25 pts |
|
|
75
74
|
|
|
76
75
|
### 4. Threshold de Ação
|
|
77
76
|
```
|
|
@@ -43,7 +43,7 @@ import { predictLtv } from './ltv-predictor.js';
|
|
|
43
43
|
* @param {Request} request - request original
|
|
44
44
|
*/
|
|
45
45
|
async function dispatchLinkedIn(env, leadData, request) {
|
|
46
|
-
// 1. Obter LTV predito pelo ML (Workers AI —
|
|
46
|
+
// 1. Obter LTV predito pelo ML (Workers AI — Granite 4.0 Micro)
|
|
47
47
|
let conversionValue = 0;
|
|
48
48
|
try {
|
|
49
49
|
const ltvResult = await predictLtv(env, leadData, request);
|