feat: refactor GET /api/organizations to use auth-derived accountId
Merged
SW
9mo ago+280+280+012345678901234567890123456789-55-55-01234567890123456789
Summary
- Refactor
GET /api/organizationsto usevalidateAuthContext+buildGetOrganizationsParamspattern (matching pulses, chats, sandboxes) - Account ID is now derived from API key authentication instead of requiring a mandatory query parameter
- Rename parameter from
accountIdtoaccount_id(snake_case consistency) account_idis now optional ā only used by org keys to filter to a specific member
Changes
| Action | File |
|---|---|
| NEW | lib/organizations/buildGetOrganizationsParams.ts |
| NEW | lib/organizations/__tests__/buildGetOrganizationsParams.test.ts (7 tests) |
| NEW | lib/organizations/validateGetOrganizationsRequest.ts |
| MODIFY | lib/organizations/getOrganizationsHandler.ts |
| MODIFY | app/api/organizations/route.ts (JSDoc only) |
| DELETE | lib/organizations/validateOrganizationsQuery.ts |
Test plan
- 7 unit tests pass for
buildGetOrganizationsParams -
recoup orgs listCLI works without code changes (derives account from API key) -
curl -H "x-api-key: $KEY" .../api/organizationsreturns orgs for authenticated account -
curl .../api/organizationsreturns 401 (was previously 400 for missing accountId)
š¤ Generated with Claude Code
Summary by CodeRabbit
-
Documentation
- Updated GET /api/organizations API documentation with authentication requirements (x-api-key or bearer token).
- Changed query parameter from
accountId(required) toaccount_id(optional) for filtering. - Clarified endpoint behavior varies by key type (personal, organization, or Recoup admin).
-
Refactor
- Refactored internal request validation and parameter handling logic.