
const { createClient } = require('@supabase/supabase-js');
const dotenv = require('dotenv');
const path = require('path');
const fs = require('fs');

const envPaths = [path.join(__dirname, '.env'), path.join(__dirname, '..', '.env')];
for (const p of envPaths) { if (fs.existsSync(p)) dotenv.config({ path: p }); }

const supabaseUrl = process.env.SUPABASE_URL || 'https://dtaegtkfdwgdbyolcxht.supabase.co';
const supabaseKey = process.env.SUPABASE_SERVICE_ROLE_KEY;
const supabase = createClient(supabaseUrl, supabaseKey);

async function checkLogs() {
    const { data, error } = await supabase
        .from('logs')
        .select('*')
        .order('created_at', { ascending: false })
        .limit(100);

    if (error) {
        console.error('Error fetching logs:', error);
        return;
    }

    data.forEach(log => {
        console.log(`[${log.created_at}] [${log.event}] ${log.message}`);
        if (log.payload && Object.keys(log.payload).length > 0) {
            console.log('   Payload:', JSON.stringify(log.payload));
        }
    });
}
checkLogs();
