const fetch = require('node-fetch')

const SUPA = process.env.SUPA_URL || process.env.SUPA || 'http://192.168.1.62:18000'
// 支持两种环境变量名：SUPA_KEY 或 SERVICE_ROLE_KEY（自托管 .env 里常见）
const KEY = process.env.SUPA_KEY || process.env.SERVICE_ROLE_KEY || 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoic2VydmljZV9yb2xlIiwiaXNzIjoic3VwYWJhc2UtMSIsImlhdCI6MTc3MTk4OTAwNywiZXhwIjoxODAzNTI1MDA3fQ.TBZeJIYEGdcKMMXAAJAka-09c4hO8_e_wyW8V5tkJ2Y';
const USER = 'a8e3a568-fc1f-4237-bcc5-5722e2fca0a3';

(async () => {
  try {
    const url = `${SUPA.replace(/\/$/, '')}/rest/v1/push_devices?user_id=eq.${encodeURIComponent(USER)}`
    console.log('GET', url)
    const resp = await fetch(url, {
      method: 'GET',
      headers: {
        apikey: KEY,
        Authorization: `Bearer ${KEY}`,
        Accept: 'application/json'
      },
      timeout: 10000
    })
    console.log('status', resp.status)
    const txt = await resp.text()
    console.log('body:', txt)
  } catch (e) {
    console.error('probe error', e && e.message ? e.message : e)
    process.exit(1)
  }
})()
