/** * CDP Edge — Server Types * Tipos para o Cloudflare Worker e bindings */ import { D1Database, KVNamespace, Queue, R2Bucket } from '@cloudflare/workers-types'; // ── Environment Bindings ───────────────────────────────────────────────────── export interface Env { // D1 Database DB?: D1Database; // KV Namespace GEO_CACHE?: KVNamespace; // R2 Bucket AUDIT_LOGS?: R2Bucket; // Workers AI AI?: any; // Rate Limiter RATE_LIMITER?: any; // Queue — Retry de eventos com falha de rede RETRY_QUEUE?: Queue; // Public Variables META_PIXEL_ID?: string; GA4_MEASUREMENT_ID?: string; TIKTOK_PIXEL_ID?: string; SITE_DOMAIN?: string; DISABLE_EXTERNAL_DISPATCH?: string; // Secrets ADMIN_API_TOKEN?: string; META_ACCESS_TOKEN?: string; GA4_API_SECRET?: string; TIKTOK_ACCESS_TOKEN?: string; META_APP_SECRET?: string; WA_WEBHOOK_VERIFY_TOKEN?: string; // WhatsApp Cloud API — nomes canônicos (Meta Cloud API v25.0) WHATSAPP_ACCESS_TOKEN?: string; // canonical: Bearer token do System User WHATSAPP_PHONE_NUMBER_ID?: string; // canonical: ID numérico do número no Meta Business // WhatsApp Cloud API — nomes legados (backwards compat) WA_ACCESS_TOKEN?: string; WA_PHONE_ID?: string; WA_NOTIFY_NUMBER?: string; CALLMEBOT_PHONE?: string; WEBHOOK_SECRET_TICTO?: string; WEBHOOK_SECRET_HOTMART?: string; WEBHOOK_SECRET_KIWIFY?: string; META_TEST_CODE?: string; META_AD_ACCOUNT_ID?: string; META_AUDIENCE_ID?: string; PINTEREST_ACCESS_TOKEN?: string; PINTEREST_AD_ACCOUNT_ID?: string; REDDIT_ACCESS_TOKEN?: string; REDDIT_AD_ACCOUNT_ID?: string; LINKEDIN_ACCESS_TOKEN?: string; LINKEDIN_CONVERSION_ID?: string; LINKEDIN_AD_ACCOUNT_ID?: string; SPOTIFY_ACCESS_TOKEN?: string; SPOTIFY_AD_ACCOUNT_ID?: string; // Email and Notification RESEND_API_KEY?: string; RESEND_FROM_EMAIL?: string; CALLMEBOT_APIKEY?: string; // ZapMan SDR — forward WhatsApp webhooks para qualificação de leads ZAPMAN_WEBHOOK_URL?: string; // URL completa: https://zapman-api.arkitekt.space/webhook/{instance_id}?token={secret} ZAPMAN_API_URL?: string; // Base URL do ZapMan: https://zapman-api.arkitekt.space ZAPMAN_API_KEY?: string; // DASHBOARD_SECRET do ZapMan (X-API-Key) ZAPMAN_CRM_INSTANCE?: string; // ID da instância ZapMan para associar o lead (ex: Ramon-SDR) // Fraud Gate — defaults parametrizáveis por projeto (vazio = comportamento legado) ALLOWED_COUNTRIES?: string; // CSV ISO-2, ex: "BR" ou "BR,PT,AO". Vazio = sem geo-fence FRAUD_DROP_THRESHOLD?: string; // Score mínimo pra drop. Default "50" (antes era 80) FRAUD_BLOCK_DATACENTERS?: string; // "1" = drop direto se ASN é datacenter (kill-switch) FRAUD_GEO_PENALTY?: string; // Pontos somados quando country não está em ALLOWED_COUNTRIES. Default "50" } // ── Event Payload Types ─────────────────────────────────────────────────────── export interface TrackPayload { eventName?: string; eventId?: string; event_id?: string; userId?: string; email?: string | null; phone?: string | null; firstName?: string | null; lastName?: string | null; city?: string | null; state?: string | null; zip?: string | null; country?: string | null; dob?: string | null; // Identifiers fbp?: string | null; fbc?: string | null; fbclid?: string | null; ttp?: string | null; gclid?: string | null; wbraid?: string | null; gbraid?: string | null; ttclid?: string | null; rclid?: string | null; msclkid?: string | null; li_fat_id?: string | null; gaClientId?: string | null; sessionId?: string | null; // Parameters value?: number | null; currency?: string | null; contentIds?: string[] | null; contentName?: string | null; contentType?: string | null; pageUrl?: string | null; orderId?: string | null; productName?: string | null; // Quantum Tracking Details intent_score?: string | number | null; intentScoreNum?: number | null; intent_bucket?: string | null; intent_penalized?: boolean; metaSignal?: number | null; metaSignalBucket?: string | null; distanceBucket?: string | null; distanceKm?: number | null; funnel_stage?: string | null; funnelDepth?: string | null; funnelLevel?: string | null; internalEvent?: string | null; botScore?: number | null; // Real Estate property_lat?: string | number | null; propertyLat?: string | number | null; property_lng?: string | number | null; propertyLng?: string | number | null; // Engagement engagementScore?: number | null; intentionLevel?: string | null; userScore?: number | null; scrollScore?: number | null; timeLevel?: string | null; // UTM utmSource?: string | null; utmMedium?: string | null; utmCampaign?: string | null; utmContent?: string | null; utmTerm?: string | null; utmRestored?: boolean; // LTV ltvClass?: string | null; ltvScore?: number | null; // Additional fields [key: string]: any; } export interface BehavioralData { engagement_score?: number; totalScore?: number; intention_level?: string; user_score?: number; scroll_score?: number; time_level?: string; email?: string | null; phone?: string | null; first_name?: string | null; firstName?: string | null; last_name?: string | null; lastName?: string | null; city?: string | null; state?: string | null; zip?: string | null; dob?: string | null; } // ── Webhook Types ───────────────────────────────────────────────────────────── export interface HotmartWebhook { data?: { buyer?: { email?: string; phone?: string; name?: string; }; purchase?: { status?: string; transaction?: string; price?: { value?: number; currency_value?: string; }; }; product?: { id?: string; ucode?: string; name?: string; }; }; [key: string]: any; } export interface KiwifyWebhook { order_status?: string; order_id?: string; order_value?: string; Customer?: { email?: string; mobile?: string; full_name?: string; }; Product?: { product_id?: string; product_name?: string; }; [key: string]: any; } export interface TictoWebhook { status?: string; customer?: { email?: string; phone?: string; name?: string; }; order?: { hash?: string; transaction_hash?: string; id?: string; paid_amount?: number; total?: number; amount?: number; }; item?: { product_id?: string; product_name?: string; }; tracking?: { user_id?: string; fbclid?: string; utm_source?: string; src?: string; utm_medium?: string; utm_campaign?: string; utm_content?: string; }; url_params?: { user_id?: string; fbclid?: string; utm_source?: string; src?: string; utm_medium?: string; utm_campaign?: string; utm_content?: string; }; [key: string]: any; } // ── Queue Message Types ─────────────────────────────────────────────────────── export interface QueueMessage { eventType: string; payload: TrackPayload; platform: string; attempt?: number; } // ── Promise Settled Result Helpers ───────────────────────────────────────────── export interface PromiseResult { status: 'fulfilled' | 'rejected'; value?: T; reason?: Error | string; }