release: admin credits rollup + events endpoints (#573)
Merged
SW
6mo ago+808+808+012345678901234567890123456789-28-28-01234567890123456789
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 periodGET /api/admins/credits/events— drilldown of rawusage_eventsrows 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_eventsfor 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_DAYStolib/admins/and unify "all" to returnnull; updateprivy/andslack/imports. - Extract small helpers:
aggregateRollupByAccount,enrichRollupPageWithAccountDetails,selectAllUsageEvents, and Supabase wrappersselectUsageEvents+countUsageEvents.
- Move