Repository navigation
feat(admin): add paginated API key listing - #593
Conversation
|
@Zuliyat Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Miracle656
left a comment
There was a problem hiding this comment.
#505 is assigned to you, so this is the one I'm reviewing for it — #569 implements the same issue and I've said so there. It needs a rebase, and there's a detail worth knowing before you do.
Part of #505 already shipped
main now has a GET /admin/keys (src/api/admin.ts:123). It lists keys, so "there is no way to see what keys exist" is solved — what it does not have is pagination or a revoked filter:
const keys = await prisma.apiKey.findMany({ ... }) // no take, no skip, no revoked filterSo your PR is now a replacement of that handler rather than a new route, and that changes the merge. As it stands, both sides register GET /admin/keys:
routes on main: 2 × '/admin/keys' (POST + GET)
routes on pr593: 2 × '/admin/keys' (POST + GET)
Merged naively that is three registrations of /admin/keys across two handlers, and Fastify refuses duplicate routes at startup — the app would not boot.
The branch is missing two routes
main has /admin/keys/:id/rotate and /admin/webhook-delivery-failures; this branch has neither, because it predates them. The conflict in src/api/admin.ts is one 80-line hunk that git has aligned your new handler against webhook-delivery-failures, which is why it looks stranger than it is.
I did not resolve this by hand, and the reason is specific: picking which parts of main's existing handler survive — the selected columns, the response shape — against yours is a behaviour decision on an endpoint that exposes API key metadata, and you know which you intended. A rebase makes those choices yours instead of mine.
What to do
Rebase on current main and fold your pagination into the existing GET /admin/keys rather than adding a second one. Keep parsePageValue and MAX_KEY_PAGE_SIZE — a cap on page size is the right instinct for an admin listing, and bounding offset is more than most do. admin_auth_failures_total.inc() on the 401 path matches what main already does, so that lines up.
Also note #595 is open to replace the hand-rolled validation in this same file with zod, and #574 adds an admin auth hook. Whoever lands first moves src/api/admin.ts under the others; yours is the one with an assigned issue behind it, so it has first claim.
docs/admin-api-keys.md is a good addition — an admin endpoint that is only discoverable by reading the route file is one nobody uses.
# Conflicts: # src/__tests__/auth.test.ts # src/api/admin.ts
|
Merged into The rebase is right. The pagination is folded into the existing
if (!/^(0|[1-9]\d*)$/.test(value)) return nullso
The conflict
tsc clean, 1,734 tests pass. |
Summary
GET /admin/keysendpoint with bounded limit/offset pagination.revoked=true.Fixes #505
Verification
git diff --checkpassed.