release: admin credits rollup + events endpoints (#573)

Merged
SW
6mo ago
+808-28

Summary

Promotes the admin credits dashboard endpoints from test to main. See #573 for full context, contract details, and preview testing results.

  • GET /api/admins/credits/rollup — per-account credit usage totals over selected period
  • GET /api/admins/credits/events — drilldown of raw usage_events rows for one account

Also includes the lib/admins refactor that promoted getCutoffMs + PERIOD_DAYS out of lib/admins/privy/ into shared lib/admins/.

Test plan

  • Preview deployment fully tested via #573 comment — 11 scenarios green
  • CI on #573 passed (lint, format, tests)
  • Smoke test on prod after deploy

Summary by cubic

Adds two admin-only credits endpoints to power the dashboard: a per-account rollup and an events drilldown, with period filters and paging. Centralizes period cutoff logic under lib/admins and updates callers.

  • New Features

    • GET /api/admins/credits/rollup — per-account totals for the selected period; joined with account name and latest email; returns page, limit, rows, total_count.
    • GET /api/admins/credits/events — raw usage_events for one account and period; returns page, limit, events, total_count.
    • Periods: all | daily | weekly | monthly (default monthly). Deterministic ordering and CORS preflight on both routes.
    • Rollup aggregation fetches all matching events in batches to avoid Supabase row caps.
  • Refactors

    • Move getCutoffMs + PERIOD_DAYS to lib/admins/ and unify "all" to return null; update privy/ and slack/ imports.
    • Extract small helpers: aggregateRollupByAccount, enrichRollupPageWithAccountDetails, selectAllUsageEvents, and Supabase wrappers selectUsageEvents + countUsageEvents.