cdp-edge 1.18.3 → 1.19.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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  **Padrão Quantum Tracking: 100% Cloudflare Edge.** Sem GTM. Sem Stape. Sem cookies de terceiros.
4
4
 
5
- > **v2.0.0** — Enterprise-Level Intelligence Engine · Cloudflare Workers · Meta CAPI v22.0 · GA4 MP · TikTok Events API v1.3
5
+ > **v2.0.3** — Enterprise-Level Intelligence Engine · Cloudflare Workers · Meta CAPI v22.0 · GA4 MP · TikTok Events API v1.3
6
6
 
7
7
  ---
8
8
 
@@ -25,6 +25,23 @@ Meu ecossistema opera como um Cérebro de Conversão Privado na borda. Quando um
25
25
 
26
26
  ---
27
27
 
28
+ ## 📋 CHANGELOG v2.0.3 (10 de Abril de 2026)
29
+
30
+ ### 🔧 Audit Completo — 45 Agentes
31
+
32
+ - **Endpoints corrigidos**: `/api/tracking` → `/track`, `/api/wh/` → `/webhook/` em todos os agentes
33
+ - **Secrets WhatsApp**: `WA_PHONE_ID`/`WA_ACCESS_TOKEN`/`WHATSAPP_TOKEN` → `WHATSAPP_PHONE_NUMBER_ID`/`WHATSAPP_ACCESS_TOKEN`
34
+ - **`env.DB.prepare`**: corrigido em 8 agentes (attribution, crm, dashboard, debug, performance, security, master-feedback-loop)
35
+ - **`env.GEO_CACHE`**: substituiu `KV.` bare em dashboard-agent, performance-agent, performance-optimization-agent
36
+ - **YouTube events**: `video_milestone`/`video_progress_25/50/75` → `video_25`/`video_50`/`video_75` (alinhado ao VALID_EVENT_NAMES do worker)
37
+ - **LinkedIn CAPI**: endpoint `/rest/conversionEvents` + header `LinkedIn-Version: 202401` em `contracts/api-versions.json`
38
+ - **Workers AI model**: `llama-3-8b-instruct` → `@cf/meta/llama-3.1-8b-instruct`
39
+ - **worker.js**: Content-Length guard (413 se > 64KB), payload validation (allowlist 19 events, 512 chars, value range), PII removido dos logs
40
+ - **Testes**: bugs críticos em `deduplication.test.js` corrigidos (template literals escapados, prefixo errado)
41
+ - **npm**: lodash 4.17.23 → 4.18.1, node-fetch removido
42
+
43
+ ---
44
+
28
45
  ## 📋 CHANGELOG v2.0.0 (9 de Abril de 2026)
29
46
 
30
47
  ### 🆕 Sprint Enterprise — Fases 1 a 4
@@ -0,0 +1,364 @@
1
+ {
2
+ "_comment": "Fonte de verdade para versões dos agent files. Atualizar manualmente quando worker.js mudar. Use scripts/validate-agents.js para detectar drifts.",
3
+ "worker_version": "2.0.3",
4
+ "worker_hash_date": "2026-04-10",
5
+ "agents": {
6
+ "master-orchestrator": {
7
+ "version": "2.0.3",
8
+ "last_synced": "2026-04-10",
9
+ "depends_on": [
10
+ "worker.js:fetch",
11
+ "worker.js:endpoints",
12
+ "worker.js:events"
13
+ ],
14
+ "critical_sections": [
15
+ "endpoints",
16
+ "event_names",
17
+ "secret_names",
18
+ "phases"
19
+ ],
20
+ "status": "synced"
21
+ },
22
+ "server-tracking": {
23
+ "version": "2.0.3",
24
+ "last_synced": "2026-04-10",
25
+ "depends_on": [
26
+ "worker.js:fetch",
27
+ "worker.js:saveLead",
28
+ "worker.js:upsertProfile",
29
+ "worker.js:secrets"
30
+ ],
31
+ "critical_sections": [
32
+ "endpoint /track",
33
+ "secret names",
34
+ "D1 binding",
35
+ "identity graph"
36
+ ],
37
+ "status": "synced"
38
+ },
39
+ "meta-agent": {
40
+ "version": "2.0.3",
41
+ "last_synced": "2026-04-10",
42
+ "depends_on": [
43
+ "worker.js:sendMetaCapi",
44
+ "contracts/api-versions.json:meta"
45
+ ],
46
+ "critical_sections": [
47
+ "Meta CAPI version",
48
+ "endpoint pattern",
49
+ "event names"
50
+ ],
51
+ "status": "synced"
52
+ },
53
+ "google-agent": {
54
+ "version": "2.0.3",
55
+ "last_synced": "2026-04-10",
56
+ "depends_on": [
57
+ "worker.js:sendGA4Mp",
58
+ "contracts/api-versions.json:google"
59
+ ],
60
+ "critical_sections": [
61
+ "GA4 Measurement Protocol endpoint",
62
+ "event names"
63
+ ],
64
+ "status": "synced"
65
+ },
66
+ "tiktok-agent": {
67
+ "version": "2.0.3",
68
+ "last_synced": "2026-04-10",
69
+ "depends_on": [
70
+ "worker.js:sendTikTokApi",
71
+ "contracts/api-versions.json:tiktok"
72
+ ],
73
+ "critical_sections": [
74
+ "TikTok Events API v1.3",
75
+ "endpoint pattern",
76
+ "event names"
77
+ ],
78
+ "status": "synced"
79
+ },
80
+ "youtube-agent": {
81
+ "version": "2.0.3",
82
+ "last_synced": "2026-04-10",
83
+ "depends_on": [
84
+ "contracts/api-versions.json:youtube"
85
+ ],
86
+ "critical_sections": [
87
+ "video milestone events: video_25/50/75/video_complete",
88
+ "YT IFrame API"
89
+ ],
90
+ "status": "synced"
91
+ },
92
+ "whatsapp-ctwa-setup-agent": {
93
+ "version": "2.0.3",
94
+ "last_synced": "2026-04-10",
95
+ "depends_on": [
96
+ "worker.js:sendWhatsApp",
97
+ "worker.js:processWhatsAppWebhook"
98
+ ],
99
+ "critical_sections": [
100
+ "WHATSAPP_ACCESS_TOKEN",
101
+ "WHATSAPP_PHONE_NUMBER_ID",
102
+ "WA_WEBHOOK_VERIFY_TOKEN"
103
+ ],
104
+ "status": "synced"
105
+ },
106
+ "intelligence-agent": {
107
+ "version": "2.0.3",
108
+ "last_synced": "2026-04-10",
109
+ "depends_on": [
110
+ "worker.js:runIntelligenceAgent",
111
+ "worker.js:checkApiVersionsIntelligence"
112
+ ],
113
+ "critical_sections": [
114
+ "cron schedule",
115
+ "endpoint /track",
116
+ "secret names"
117
+ ],
118
+ "status": "synced"
119
+ },
120
+ "fraud-detection-agent": {
121
+ "version": "2.0.3",
122
+ "last_synced": "2026-04-10",
123
+ "depends_on": [
124
+ "worker.js:checkFraudGate",
125
+ "worker.js:handleFraudAlerts",
126
+ "schema-fraud.sql"
127
+ ],
128
+ "critical_sections": [
129
+ "fraud score threshold",
130
+ "KV blocklist",
131
+ "endpoints /api/fraud/"
132
+ ],
133
+ "status": "synced"
134
+ },
135
+ "ml-clustering-agent": {
136
+ "version": "2.0.3",
137
+ "last_synced": "2026-04-10",
138
+ "depends_on": [
139
+ "worker.js:handleSegmentationCluster",
140
+ "schema-segmentation.sql"
141
+ ],
142
+ "critical_sections": [
143
+ "Workers AI model",
144
+ "endpoints /api/segmentation/",
145
+ "D1 binding"
146
+ ],
147
+ "status": "synced"
148
+ },
149
+ "bidding-agent": {
150
+ "version": "2.0.3",
151
+ "last_synced": "2026-04-10",
152
+ "depends_on": [
153
+ "worker.js:handleBiddingRecommend",
154
+ "schema-bidding.sql"
155
+ ],
156
+ "critical_sections": [
157
+ "endpoints /api/bidding/",
158
+ "segment multipliers"
159
+ ],
160
+ "status": "synced"
161
+ },
162
+ "ab-ltv-agent": {
163
+ "version": "2.0.3",
164
+ "last_synced": "2026-04-10",
165
+ "depends_on": [
166
+ "worker.js:predictLtv",
167
+ "worker.js:getLtvAbVariation",
168
+ "schema-ab-ltv.sql"
169
+ ],
170
+ "critical_sections": [
171
+ "Workers AI model @cf/meta/llama-3.1-8b-instruct",
172
+ "endpoints /api/ltv/"
173
+ ],
174
+ "status": "synced"
175
+ },
176
+ "security-enterprise-agent": {
177
+ "version": "2.0.3",
178
+ "last_synced": "2026-04-10",
179
+ "depends_on": [
180
+ "worker.js:checkFraudGate",
181
+ "worker.js:verifyHmac"
182
+ ],
183
+ "critical_sections": [
184
+ "env.DB.prepare",
185
+ "env.GEO_CACHE",
186
+ "HMAC validation"
187
+ ],
188
+ "status": "synced"
189
+ },
190
+ "attribution-agent": {
191
+ "version": "2.0.3",
192
+ "last_synced": "2026-04-10",
193
+ "depends_on": [
194
+ "worker.js:saveLead",
195
+ "worker.js:sendMetaCapi",
196
+ "worker.js:sendTikTokApi"
197
+ ],
198
+ "critical_sections": [
199
+ "env.DB.prepare",
200
+ "env.META_ACCESS_TOKEN",
201
+ "env.TIKTOK_ACCESS_TOKEN"
202
+ ],
203
+ "status": "synced"
204
+ },
205
+ "devops-agent": {
206
+ "version": "2.0.3",
207
+ "last_synced": "2026-04-10",
208
+ "depends_on": [
209
+ "wrangler.toml",
210
+ "schema.sql",
211
+ "schema-segmentation.sql",
212
+ "schema-bidding.sql",
213
+ "schema-ab-ltv.sql",
214
+ "schema-fraud.sql"
215
+ ],
216
+ "critical_sections": [
217
+ "D1 binding names",
218
+ "secret names",
219
+ "schema execution order",
220
+ "Workers AI binding"
221
+ ],
222
+ "status": "synced"
223
+ },
224
+ "validator-agent": {
225
+ "version": "2.0.3",
226
+ "last_synced": "2026-04-10",
227
+ "depends_on": [
228
+ "worker.js",
229
+ "all agents"
230
+ ],
231
+ "critical_sections": [
232
+ "canonical event names 19",
233
+ "canonical secret names",
234
+ "canonical endpoints"
235
+ ],
236
+ "status": "synced"
237
+ },
238
+ "ltv-predictor-agent": {
239
+ "version": "2.0.3",
240
+ "last_synced": "2026-04-10",
241
+ "depends_on": [
242
+ "worker.js:predictLtv"
243
+ ],
244
+ "critical_sections": [
245
+ "@cf/meta/llama-3.1-8b-instruct model name"
246
+ ],
247
+ "status": "synced"
248
+ },
249
+ "database-agent": {
250
+ "version": "2.0.3",
251
+ "last_synced": "2026-04-10",
252
+ "depends_on": [
253
+ "schema.sql",
254
+ "schema-segmentation.sql",
255
+ "schema-bidding.sql",
256
+ "schema-ab-ltv.sql",
257
+ "schema-fraud.sql",
258
+ "schema-indexes.sql"
259
+ ],
260
+ "critical_sections": [
261
+ "table count (24 tables)",
262
+ "binding: DB",
263
+ "KV: GEO_CACHE"
264
+ ],
265
+ "status": "synced"
266
+ },
267
+ "performance-agent": {
268
+ "version": "2.0.3",
269
+ "last_synced": "2026-04-10",
270
+ "depends_on": [
271
+ "worker.js:getHealthMetrics"
272
+ ],
273
+ "critical_sections": [
274
+ "env.DB.prepare",
275
+ "env.GEO_CACHE"
276
+ ],
277
+ "status": "synced"
278
+ },
279
+ "dashboard-agent": {
280
+ "version": "2.0.3",
281
+ "last_synced": "2026-04-10",
282
+ "depends_on": [
283
+ "worker.js:generateDailyReport"
284
+ ],
285
+ "critical_sections": [
286
+ "env.DB.prepare",
287
+ "env.GEO_CACHE"
288
+ ],
289
+ "status": "synced"
290
+ },
291
+ "browser-tracking": {
292
+ "version": "2.0.3",
293
+ "last_synced": "2026-04-10",
294
+ "depends_on": [
295
+ "extracted-skill/tracking-events-generator/cdpTrack.js"
296
+ ],
297
+ "critical_sections": [
298
+ "endpoint /track",
299
+ "event_id deduplication",
300
+ "cdp_uid cookie"
301
+ ],
302
+ "status": "synced"
303
+ },
304
+ "debug-agent": {
305
+ "version": "2.0.3",
306
+ "last_synced": "2026-04-10",
307
+ "depends_on": [
308
+ "worker.js",
309
+ "all endpoints"
310
+ ],
311
+ "critical_sections": [
312
+ "endpoint /track",
313
+ "endpoint /health",
314
+ "D1 binding"
315
+ ],
316
+ "status": "synced"
317
+ },
318
+ "crm-integration-agent": {
319
+ "version": "2.0.3",
320
+ "last_synced": "2026-04-10",
321
+ "depends_on": [
322
+ "worker.js:saveLead",
323
+ "worker.js:upsertProfile"
324
+ ],
325
+ "critical_sections": [
326
+ "env.DB.prepare",
327
+ "leads table schema"
328
+ ],
329
+ "status": "synced"
330
+ },
331
+ "performance-optimization-agent": {
332
+ "version": "2.0.3",
333
+ "last_synced": "2026-04-10",
334
+ "depends_on": [
335
+ "worker.js"
336
+ ],
337
+ "critical_sections": [
338
+ "env.GEO_CACHE (not env.CACHE_KV)"
339
+ ],
340
+ "status": "synced"
341
+ },
342
+ "master-feedback-loop": {
343
+ "version": "2.0.3",
344
+ "last_synced": "2026-04-10",
345
+ "depends_on": [
346
+ "all agents"
347
+ ],
348
+ "critical_sections": [
349
+ "env.DB.prepare",
350
+ "cron schedule"
351
+ ],
352
+ "status": "synced"
353
+ }
354
+ },
355
+ "change_triggers": {
356
+ "worker.js:addNewEndpoint": "Atualizar: master-orchestrator, server-tracking, browser-tracking, debug-agent, intelligence-agent",
357
+ "worker.js:changeSecretName": "Atualizar: devops-agent, server-tracking, intelligence-agent, whatsapp-ctwa-setup-agent, database-agent",
358
+ "worker.js:changeEventName": "Atualizar: master-orchestrator, youtube-agent, validator-agent, browser-tracking",
359
+ "worker.js:changeAIModel": "Atualizar: ml-clustering-agent, ab-ltv-agent, ltv-predictor-agent",
360
+ "schema.sql:addTable": "Atualizar: database-agent (table count), devops-agent (migration order)",
361
+ "wrangler.toml:addBinding": "Atualizar: devops-agent, database-agent, debug-agent",
362
+ "contracts/api-versions.json:bumpVersion": "Atualizar: agent especialista + master-orchestrator"
363
+ }
364
+ }
@@ -32,7 +32,7 @@ function printBanner() {
32
32
  console.log(chalk.cyan('╚██████╗██████╔╝██║ ███████╗██████╔╝╚██████╔╝███████╗'));
33
33
  console.log(chalk.cyan(' ╚═════╝╚═════╝ ╚═╝ ╚══════╝╚═════╝ ╚═════╝╚══════╝'));
34
34
  console.log('');
35
- console.log(chalk.gray(' Customer Data Platform on the Edge · Global Edge Tracking · v2.0.2'));
35
+ console.log(chalk.gray(' Customer Data Platform on the Edge · Global Edge Tracking · v2.0.3'));
36
36
  console.log('');
37
37
  console.log(chalk.gray('═'.repeat(68)));
38
38
  console.log('');
@@ -19,7 +19,7 @@ function printBanner() {
19
19
  console.log(chalk.cyan('╚██████╗██████╔╝██║ ███████╗██████╔╝╚██████╔╝███████╗'));
20
20
  console.log(chalk.cyan(' ╚═════╝╚═════╝ ╚═╝ ╚══════╝╚═════╝ ╚═════╝╚══════╝'));
21
21
  console.log('');
22
- console.log(chalk.gray(' Customer Data Platform on the Edge · Global Edge Tracking · v2.0.2'));
22
+ console.log(chalk.gray(' Customer Data Platform on the Edge · Global Edge Tracking · v2.0.3'));
23
23
  console.log('');
24
24
  console.log(chalk.gray('═'.repeat(68)));
25
25
  console.log('');
@@ -526,7 +526,7 @@ async function syncIdentity(DB, body) {
526
526
  const fp = body.fingerprint || null;
527
527
  if (!fp || !DB) return body;
528
528
 
529
- const existing = await DB.prepare(
529
+ const existing = await env.DB.prepare(
530
530
  'SELECT * FROM identity_graph WHERE fingerprint = ?'
531
531
  ).bind(fp).first();
532
532
 
@@ -541,7 +541,7 @@ async function syncIdentity(DB, body) {
541
541
  visit_count: (existing.visit_count || 1) + 1
542
542
  };
543
543
  } else {
544
- await DB.prepare(`
544
+ await env.DB.prepare(`
545
545
  INSERT OR IGNORE INTO identity_graph (fingerprint, fbp, fbc, ga_client_id, external_id, ttclid, first_utm)
546
546
  VALUES (?, ?, ?, ?, ?, ?, ?)
547
547
  `).bind(fp, body.fbp, body.fbc, body.ga_client_id, body.external_id, body.ttclid, JSON.stringify(body.utm || {})).run();
@@ -635,7 +635,7 @@ function buildCookieHeader(visitor, umbrellaDomain) {
635
635
  async function logBehavioralEvent(DB, body, visitor, engagementScore) {
636
636
  if (!DB) return;
637
637
 
638
- await DB.prepare(`
638
+ await env.DB.prepare(`
639
639
  INSERT OR REPLACE INTO behavioral_events (
640
640
  event_id, user_id, session_id,
641
641
  engagement_score, time_level, scroll_score, click_score, video_score, hover_score, intention_level,
@@ -972,7 +972,7 @@ CREATE INDEX IF NOT EXISTS idx_retry_scheduled ON retry_queue(scheduled_at, stat
972
972
  async function logEventSuccess(DB, platform, eventId) {
973
973
  if (!DB) return;
974
974
 
975
- await DB.prepare(`
975
+ await env.DB.prepare(`
976
976
  UPDATE events_log
977
977
  SET status = 'success',
978
978
  retry_count = 0,
@@ -988,7 +988,7 @@ async function logEventFailure(DB, platform, eventId, errorMessage, retryCount)
988
988
  const maxRetries = 3;
989
989
  const isFinalFailure = retryCount >= maxRetries;
990
990
 
991
- await DB.prepare(`
991
+ await env.DB.prepare(`
992
992
  UPDATE events_log
993
993
  SET status = ?,
994
994
  retry_count = ?,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cdp-edge",
3
- "version": "1.18.3",
3
+ "version": "1.19.0",
4
4
  "description": "CDP Edge - Quantum Tracking - Sistema multi-agente para tracking digital Cloudflare Native (Workers + D1)",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -28,7 +28,12 @@
28
28
  "test:unit:hash": "node tests/unit/hashing.test.js",
29
29
  "test:unit:dedup": "node tests/unit/deduplication.test.js",
30
30
  "test:unit:payload": "node tests/unit/payload-validation.test.js",
31
- "test:all": "npm run test:unit"
31
+ "test:all": "npm run test:unit",
32
+ "test:integration": "cd tests/integration && npx vitest run",
33
+ "agents:check": "node scripts/validate-agents.js",
34
+ "agents:sync": "node scripts/sync-agents.js",
35
+ "agents:sync:list": "node scripts/sync-agents.js --list",
36
+ "agents:sync:all": "node scripts/sync-agents.js --apply-all"
32
37
  },
33
38
  "keywords": [
34
39
  "pixel",