Repository navigation
Add package invocation token management - #546
Conversation
📝 WalkthroughWalkthroughAdds end-to-end management of package invocation bearer tokens: new D1 repo functions for listing, inserting, and revoking tokens; a server-side API handler supporting GET/POST with create and revoke actions; wildcard scope matching in the authorization service; a full client-side management UI route; router/route wiring; account page entry point; and updated contributor documentation. ChangesPackage Invocation Token Management
Sequence Diagram(s)sequenceDiagram
actor User
participant UI as AccountPackageInvocationTokensRoute
participant ApiHandler as /account/package-invocation-tokens.json
participant Repo as package-invocations/repo
participant Service as hashToken (service)
User->>UI: opens /account/package-invocation-tokens
UI->>ApiHandler: GET (credentials: include)
ApiHandler->>Repo: listPackageInvocationTokensByUserId
ApiHandler-->>UI: payload {tokens, packages, origin}
User->>UI: fills form + clicks Create token
UI->>ApiHandler: POST {action: create, name, rawToken, scopes}
ApiHandler->>Service: hashToken(rawToken)
ApiHandler->>Repo: insertPackageInvocationToken
ApiHandler-->>UI: payload + selectedTokenId
User->>UI: clicks Revoke (two-step confirm)
UI->>ApiHandler: POST {action: revoke, id}
ApiHandler->>Repo: revokePackageInvocationToken (userId scoped)
ApiHandler-->>UI: refreshed payload
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
|
🔎 Preview deployed: https://kody-pr-546.kentcdodds.workers.dev Worker: Mocks:
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 4025e21. Configure here.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/worker/client/routes/account-package-invocation-tokens.tsx`:
- Around line 218-221: When a 401 response is detected in the account package
invocation tokens route, the code currently calls
window.location.assign('/login') and returns immediately without resetting any
loading or mutating state. If the navigation is delayed or blocked, the UI
remains stuck in a disabled state. Before the return statement in each of the
three 401 handlers (at lines 218-221, 390-393, and 444-447), reset any local
state variables that control loading, mutating, or disabled states (such as
setLoading(false) or similar state reset calls) to ensure the UI is properly
cleaned up. Alternatively, consider creating a shared 401 response handler
function to centralize this logic and eliminate the duplication across all three
locations.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 4dc27727-c1fe-42f0-bcc8-769db52261e0
📒 Files selected for processing (12)
docs/contributing/package-invocation-api.mdpackages/worker/client/app.tsxpackages/worker/client/routes/account-package-invocation-tokens.tsxpackages/worker/client/routes/account.tsxpackages/worker/client/routes/index.tsxpackages/worker/src/app/handlers/account-package-invocation-tokens.node.test.tspackages/worker/src/app/handlers/account-package-invocation-tokens.tspackages/worker/src/app/router.tspackages/worker/src/app/routes.tspackages/worker/src/package-invocations/repo.tspackages/worker/src/package-invocations/service.node.test.tspackages/worker/src/package-invocations/service.ts

Summary
*wildcard support for package/export token allowlists while keeping user ownership and source checks enforced.Testing
npx vitest run --project node-unit packages/worker/src/app/handlers/account-package-invocation-tokens.node.test.ts packages/worker/src/package-invocations/service.node.test.tsnpx vitest run --project workers-unit packages/worker/src/package-invocations/http.workers.test.tsnpm run typechecknpm run format:checknpm run lint(passes with 5 pre-existing warnings outside this change)f209126.Summary by CodeRabbit
Release Notes
New Features
Documentation