// engine/telemetry/telemetry-client.ts — SPEC-200: Fire-and-forget telemetry POST to Supabase.
// Never throws — all errors are silently swallowed to avoid blocking tool responses.
import { resolveGeo } from './geo-resolver.js';
const SUPABASE_URL = 'https://canusqigtzldstnjddio.supabase.co';
const SUPABASE_ANON_KEY = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImNhbnVzcWlndHpsZHN0bmpkZGlvIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzI3NTk2MjgsImV4cCI6MjA4ODMzNTYyOH0.Thw1Xgf9_iabOD75J00u35d2k5NsIpUBU9PrqOShxMU';
const TELEMETRY_ENDPOINT = `${SUPABASE_URL}/rest/v1/telemetry_events`;
/**
 * Send a telemetry event to Supabase. Fire-and-forget — never awaited by callers.
 * Enriches events with geo data (country/timezone) from a cached IP lookup.
 * No PII: properties must not contain paths, emails, or user identifiers.
 */
export function sendTelemetryEvent(event) {
    // Enrich with geo data asynchronously, then send
    resolveGeo()
        .then((geo) => {
        const properties = geo
            ? {
                ...event.properties,
                country: geo.countryCode,
                timezone: geo.timezone,
            }
            : event.properties;
        const payload = {
            event_name: event.event,
            properties,
            installation_id: event.installationId,
        };
        return fetch(TELEMETRY_ENDPOINT, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
                apikey: SUPABASE_ANON_KEY,
                Authorization: `Bearer ${SUPABASE_ANON_KEY}`,
                Prefer: 'return=minimal',
            },
            body: JSON.stringify(payload),
            signal: AbortSignal.timeout(5_000),
        });
    })
        .catch(() => {
        // Silently swallow all errors — telemetry must never break the tool
    });
}
//# sourceMappingURL=telemetry-client.js.map