cdp-edge 2.2.5 → 2.3.1

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.
Files changed (24) hide show
  1. package/README.md +57 -2
  2. package/contracts/types.ts +81 -0
  3. package/docs/whatsapp-ctwa.md +3 -2
  4. package/package.json +7 -4
  5. package/server-edge-tracker/.client.env.example +14 -0
  6. package/server-edge-tracker/deploy-client.js +76 -0
  7. package/server-edge-tracker/{index.js → index.ts} +93 -84
  8. package/server-edge-tracker/modules/{db.js → db.ts} +117 -77
  9. package/server-edge-tracker/modules/dispatch/{ga4.js → ga4.ts} +12 -10
  10. package/server-edge-tracker/modules/dispatch/{meta.js → meta.ts} +35 -28
  11. package/server-edge-tracker/modules/dispatch/{platforms.js → platforms.ts} +58 -56
  12. package/server-edge-tracker/modules/dispatch/{tiktok.js → tiktok.ts} +22 -20
  13. package/server-edge-tracker/modules/dispatch/{whatsapp.js → whatsapp.ts} +74 -28
  14. package/server-edge-tracker/modules/{intelligence.js → intelligence.ts} +175 -60
  15. package/server-edge-tracker/modules/ml/{bidding.js → bidding.ts} +37 -35
  16. package/server-edge-tracker/modules/ml/{fraud.js → fraud.ts} +48 -40
  17. package/server-edge-tracker/modules/ml/{logistic.js → logistic.ts} +44 -19
  18. package/server-edge-tracker/modules/ml/{ltv.js → ltv.ts} +135 -90
  19. package/server-edge-tracker/modules/ml/{matchquality.js → matchquality.ts} +70 -26
  20. package/server-edge-tracker/modules/ml/{segmentation.js → segmentation.ts} +109 -48
  21. package/server-edge-tracker/modules/{utils.js → utils.ts} +41 -22
  22. package/server-edge-tracker/types.ts +255 -0
  23. package/server-edge-tracker/wrangler.toml +2 -2
  24. package/docs/PixelBuilder-Documentacao-Completa (2).docx +0 -0
@@ -0,0 +1,255 @@
1
+ /**
2
+ * CDP Edge — Server Types
3
+ * Tipos para o Cloudflare Worker e bindings
4
+ */
5
+
6
+ import { D1Database, KVNamespace, R2Bucket } from '@cloudflare/workers-types';
7
+
8
+ // ── Environment Bindings ─────────────────────────────────────────────────────
9
+ export interface Env {
10
+ // D1 Database
11
+ DB?: D1Database;
12
+
13
+ // KV Namespace
14
+ GEO_CACHE?: KVNamespace;
15
+
16
+ // R2 Bucket
17
+ AUDIT_LOGS?: R2Bucket;
18
+
19
+ // Workers AI
20
+ AI?: any;
21
+
22
+ // Rate Limiter
23
+ RATE_LIMITER?: any;
24
+
25
+ // Public Variables
26
+ META_PIXEL_ID?: string;
27
+ GA4_MEASUREMENT_ID?: string;
28
+ TIKTOK_PIXEL_ID?: string;
29
+ SITE_DOMAIN?: string;
30
+
31
+ // Secrets
32
+ META_ACCESS_TOKEN?: string;
33
+ GA4_API_SECRET?: string;
34
+ TIKTOK_ACCESS_TOKEN?: string;
35
+ WA_WEBHOOK_VERIFY_TOKEN?: string;
36
+ // WhatsApp Cloud API — nomes canônicos (Meta Cloud API v22.0)
37
+ WHATSAPP_ACCESS_TOKEN?: string; // canonical: Bearer token do System User
38
+ WHATSAPP_PHONE_NUMBER_ID?: string; // canonical: ID numérico do número no Meta Business
39
+ // WhatsApp Cloud API — nomes legados (backwards compat)
40
+ WA_ACCESS_TOKEN?: string;
41
+ WA_PHONE_ID?: string;
42
+ WA_NOTIFY_NUMBER?: string;
43
+ CALLMEBOT_PHONE?: string;
44
+ WEBHOOK_SECRET_TICTO?: string;
45
+ WEBHOOK_SECRET_HOTMART?: string;
46
+ WEBHOOK_SECRET_KIWIFY?: string;
47
+ META_TEST_CODE?: string;
48
+ META_AD_ACCOUNT_ID?: string;
49
+ META_AUDIENCE_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_CONVERSION_ID?: string;
56
+ LINKEDIN_AD_ACCOUNT_ID?: string;
57
+ SPOTIFY_ACCESS_TOKEN?: string;
58
+ SPOTIFY_AD_ACCOUNT_ID?: string;
59
+
60
+ // Email and Notification
61
+ RESEND_API_KEY?: string;
62
+ RESEND_FROM_EMAIL?: string;
63
+ CALLMEBOT_APIKEY?: string;
64
+ }
65
+
66
+ // ── Event Payload Types ───────────────────────────────────────────────────────
67
+ export interface TrackPayload {
68
+ eventName?: string;
69
+ eventId?: string;
70
+ event_id?: string;
71
+ userId?: string;
72
+ email?: string | null;
73
+ phone?: string | null;
74
+ firstName?: string | null;
75
+ lastName?: string | null;
76
+ city?: string | null;
77
+ state?: string | null;
78
+ zip?: string | null;
79
+ country?: string | null;
80
+ dob?: string | null;
81
+
82
+ // Identifiers
83
+ fbp?: string | null;
84
+ fbc?: string | null;
85
+ ttp?: string | null;
86
+ gaClientId?: string | null;
87
+
88
+ // Parameters
89
+ value?: number | null;
90
+ currency?: string | null;
91
+ contentIds?: string[] | null;
92
+ contentName?: string | null;
93
+ contentType?: string | null;
94
+ pageUrl?: string | null;
95
+ orderId?: string | null;
96
+ productName?: string | null;
97
+
98
+ // Quantum Tracking Details
99
+ intent_score?: string | number | null;
100
+ intentScoreNum?: number | null;
101
+ intent_bucket?: string | null;
102
+ intent_penalized?: boolean;
103
+ metaSignal?: number | null;
104
+ metaSignalBucket?: string | null;
105
+ distanceBucket?: string | null;
106
+ distanceKm?: number | null;
107
+ funnel_stage?: string | null;
108
+ funnelDepth?: string | null;
109
+ funnelLevel?: string | null;
110
+ internalEvent?: string | null;
111
+ botScore?: number | null;
112
+
113
+ // Real Estate
114
+ property_lat?: string | number | null;
115
+ propertyLat?: string | number | null;
116
+ property_lng?: string | number | null;
117
+ propertyLng?: string | number | null;
118
+
119
+ // Engagement
120
+ engagementScore?: number | null;
121
+ intentionLevel?: string | null;
122
+ userScore?: number | null;
123
+ scrollScore?: number | null;
124
+ timeLevel?: string | null;
125
+
126
+ // UTM
127
+ utmSource?: string | null;
128
+ utmMedium?: string | null;
129
+ utmCampaign?: string | null;
130
+ utmContent?: string | null;
131
+ utmTerm?: string | null;
132
+ utmRestored?: boolean;
133
+
134
+ // LTV
135
+ ltvClass?: string | null;
136
+ ltvScore?: number | null;
137
+
138
+ // Additional fields
139
+ [key: string]: any;
140
+ }
141
+
142
+ export interface BehavioralData {
143
+ engagement_score?: number;
144
+ totalScore?: number;
145
+ intention_level?: string;
146
+ user_score?: number;
147
+ scroll_score?: number;
148
+ time_level?: string;
149
+ email?: string | null;
150
+ phone?: string | null;
151
+ first_name?: string | null;
152
+ firstName?: string | null;
153
+ last_name?: string | null;
154
+ lastName?: string | null;
155
+ city?: string | null;
156
+ state?: string | null;
157
+ zip?: string | null;
158
+ dob?: string | null;
159
+ }
160
+
161
+ // ── Webhook Types ─────────────────────────────────────────────────────────────
162
+ export interface HotmartWebhook {
163
+ data?: {
164
+ buyer?: {
165
+ email?: string;
166
+ phone?: string;
167
+ name?: string;
168
+ };
169
+ purchase?: {
170
+ status?: string;
171
+ transaction?: string;
172
+ price?: {
173
+ value?: number;
174
+ currency_value?: string;
175
+ };
176
+ };
177
+ product?: {
178
+ id?: string;
179
+ ucode?: string;
180
+ name?: string;
181
+ };
182
+ };
183
+ [key: string]: any;
184
+ }
185
+
186
+ export interface KiwifyWebhook {
187
+ order_status?: string;
188
+ order_id?: string;
189
+ order_value?: string;
190
+ Customer?: {
191
+ email?: string;
192
+ mobile?: string;
193
+ full_name?: string;
194
+ };
195
+ Product?: {
196
+ product_id?: string;
197
+ product_name?: string;
198
+ };
199
+ [key: string]: any;
200
+ }
201
+
202
+ export interface TictoWebhook {
203
+ status?: string;
204
+ customer?: {
205
+ email?: string;
206
+ phone?: string;
207
+ name?: string;
208
+ };
209
+ order?: {
210
+ hash?: string;
211
+ transaction_hash?: string;
212
+ id?: string;
213
+ paid_amount?: number;
214
+ total?: number;
215
+ amount?: number;
216
+ };
217
+ item?: {
218
+ product_id?: string;
219
+ product_name?: string;
220
+ };
221
+ tracking?: {
222
+ user_id?: string;
223
+ fbclid?: string;
224
+ utm_source?: string;
225
+ src?: string;
226
+ utm_medium?: string;
227
+ utm_campaign?: string;
228
+ utm_content?: string;
229
+ };
230
+ url_params?: {
231
+ user_id?: string;
232
+ fbclid?: string;
233
+ utm_source?: string;
234
+ src?: string;
235
+ utm_medium?: string;
236
+ utm_campaign?: string;
237
+ utm_content?: string;
238
+ };
239
+ [key: string]: any;
240
+ }
241
+
242
+ // ── Queue Message Types ───────────────────────────────────────────────────────
243
+ export interface QueueMessage {
244
+ eventType: string;
245
+ payload: TrackPayload;
246
+ platform: string;
247
+ attempt?: number;
248
+ }
249
+
250
+ // ── Promise Settled Result Helpers ─────────────────────────────────────────────
251
+ export interface PromiseResult<T> {
252
+ status: 'fulfilled' | 'rejected';
253
+ value?: T;
254
+ reason?: Error | string;
255
+ }
@@ -1,7 +1,7 @@
1
1
  name = "server-edge-tracker"
2
2
  # Entry point: worker.js (monólito original, 100% compatível)
3
- # Para usar a versão modular ES Modules: altere para main = "index.js"
4
- main = "index.js"
3
+ # Para usar a versão modular ES Modules: altere para main = "index.ts"
4
+ main = "index.ts"
5
5
  compatibility_date = "2025-01-01"
6
6
  compatibility_flags = ["nodejs_compat"]
7
7
  workers_dev = true