// peepless's stats as a Supabase Edge Function, next to the `peepless` counter.
//
//   supabase secrets set PEEPLESS_STATS_TOKEN=$(openssl rand -hex 32)
//   supabase functions deploy peepless-stats --no-verify-jwt
//
// --no-verify-jwt because the caller sends the stats token, not a Supabase key, in Authorization.
// Then, from a server:
//   GET https://<project-ref>.supabase.co/functions/v1/peepless-stats?project=my-app
//   Authorization: Bearer <PEEPLESS_STATS_TOKEN>
// answers the last 30 days as JSON (add &since=YYYY-MM-DD&until=YYYY-MM-DD for others).
// Until the secret is set, it answers 503. Never put the token in browser code.
import { createStatsHandler, supabaseStore } from 'npm:peepless@0/server'

const handler = createStatsHandler({
  store: supabaseStore({
    url: Deno.env.get('SUPABASE_URL')!,
    key: Deno.env.get('SUPABASE_SERVICE_ROLE_KEY')!,
  }),
  token: Deno.env.get('PEEPLESS_STATS_TOKEN'),
})

Deno.serve(handler)
