feat: add trpc and filters schema for root keys#3331
Conversation
|
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
|
Thank you for following the naming conventions for pull request titles! 🙏 |
📝 WalkthroughWalkthroughThis change introduces a new "Root Keys" feature in the dashboard settings. It adds backend TRPC API endpoints for querying root keys with filtering, pagination, and permission categorization. On the frontend, it implements schema definitions, a navigation component, and a page for listing root keys, integrating the new API and UI components. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant RootKeysPage (UI)
participant TRPC Client
participant TRPC Server
participant Database
User->>RootKeysPage (UI): Visit Root Keys page
RootKeysPage (UI)->>TRPC Client: Call settings.rootKeys.query (limit, cursor)
TRPC Client->>TRPC Server: Forward request
TRPC Server->>Database: Query root keys (with filters, pagination)
Database-->>TRPC Server: Return root keys and permissions
TRPC Server->>TRPC Server: Categorize permissions, build response
TRPC Server-->>TRPC Client: Return keys, meta, permission summaries
TRPC Client-->>RootKeysPage (UI): Deliver data
RootKeysPage (UI)-->>User: Render root keys list and navigation
Possibly related PRs
Suggested labels
Suggested reviewers
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 8
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (5)
apps/dashboard/app/(app)/settings/root-keys-v2/filters.schema.ts(1 hunks)apps/dashboard/app/(app)/settings/root-keys-v2/navigation.tsx(1 hunks)apps/dashboard/app/(app)/settings/root-keys-v2/page.tsx(1 hunks)apps/dashboard/lib/trpc/routers/index.ts(2 hunks)apps/dashboard/lib/trpc/routers/settings/root-keys/query.ts(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
apps/dashboard/lib/trpc/routers/index.ts (2)
apps/dashboard/lib/trpc/trpc.ts (1)
t(8-8)apps/dashboard/lib/trpc/routers/settings/root-keys/query.ts (1)
queryRootKeys(41-139)
apps/dashboard/app/(app)/settings/root-keys-v2/filters.schema.ts (2)
apps/dashboard/components/logs/validation/filter.types.ts (2)
StringConfig(33-38)FilterValue(49-62)apps/dashboard/components/logs/validation/utils/nuqs-parsers.ts (1)
parseAsFilterValueArray(29-57)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: Test Packages / Test ./internal/clickhouse
- GitHub Check: autofix
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (1)
apps/dashboard/lib/trpc/routers/index.ts (1)
88-98: Router hierarchy looks good – make sure we don’t already expose asettingsrouter elsewhere.The new import and nested
settings.rootKeys.queryroute integrate cleanly with the existing structure.
Just double-check that no othersettings:namespace already exists in a different router file to avoid name collision in the generated TRPC types.Also applies to: 125-129
| total: z.number(), | ||
| categories: z.record(z.number()), // { "API": 4, "Keys": 6, "Ratelimit": 2 } | ||
| hasCriticalPerm: z.boolean(), // delete, decrypt permissions |
There was a problem hiding this comment.
🧹 Nitpick (assertive)
Schema comment inconsistent with implementation.
Comment lists "Keys" category but categorizePermissions never returns that key.
Either add the category or update the comment to avoid confusion.
🤖 Prompt for AI Agents
In apps/dashboard/lib/trpc/routers/settings/root-keys/query.ts around lines 24
to 26, the comment for the categories schema mentions a "Keys" category that is
not returned by the categorizePermissions function. To fix this, either update
the categorizePermissions function to include the "Keys" category if it is
intended to be part of the data, or remove "Keys" from the comment to accurately
reflect the actual categories returned, ensuring the comment matches the
implementation.
There was a problem hiding this comment.
good point, didn't we get rid of the category display @ogzhanolguncu ?
pls ignore if this is already addressed in the UI PR
There was a problem hiding this comment.
Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!
| import { Button, CopyButton } from "@unkey/ui"; | ||
| import Link from "next/link"; | ||
|
|
||
| const settingsNavbar = [ |
There was a problem hiding this comment.
not a blocker here, but we should definitely put these kind of link lists into a constant to reuse in other pages, wdyt?
| let hasCriticalPerm = false; | ||
|
|
||
| for (const permission of permissions) { | ||
| if (!permission?.name || typeof permission.name !== "string") { |
There was a problem hiding this comment.
use the slug instead of name please
| } | ||
|
|
||
| // Extract category from permission name (e.g., "api.*.create_key" -> "api") | ||
| const parts = permission.name.split("."); |
| const [identifier] = parts; | ||
| let category: string; | ||
|
|
||
| switch (identifier) { |
There was a problem hiding this comment.
probably no longer necessary and already addressed in the next PR
chronark
left a comment
There was a problem hiding this comment.
only change required is using the slug instead of name on permissions
though we can merge this if you fix it in the other PR, your call
|
Yeah most of the things are fixed in the following prs |
|
ok, should I let this one through as is? |
|
Yes |
|
Unless you see something you don’t like in the db queries or something |
|
well I did not like you using permission.name, cause it needs to be permission.slug lol |
|
We can change it in the final PR 🫡 |
What does this PR do?
This PR adds a tRPC endpoint for the new root-keys page and filters schema for the upcoming table view.
The endpoint includes cursor pagination and permission categorization that groups permissions by type (API, Keys, Ratelimit, etc.) with counts. It also detects critical permissions - if a root key has permissions like
delete,removeordecrypt, we'll mark it as critical.In the following PRs we'll introduce the table view which will display
UpdatedAt,CreatedAt,Name,ExternalId(creator of the key),PermissionList(high-level summary like APIs(5), Ratelimit(3)) and actions. Users will be able to search and filter usingname,identity(externalId),permissionNameandstart(start of the key).Fixes # (issue)
If there is not an issue for this, please create one first. This is used to tracking purposes and also helps use understand why this PR exists
Type of change
How should this be tested?
Checklist
Required
pnpm buildpnpm fmtconsole.logsgit pull origin mainAppreciated
Summary by CodeRabbit