feat: refactor GET /api/organizations to use auth-derived accountId

Merged
SW
9mo ago
+280-55

Summary

  • Refactor GET /api/organizations to use validateAuthContext + buildGetOrganizationsParams pattern (matching pulses, chats, sandboxes)
  • Account ID is now derived from API key authentication instead of requiring a mandatory query parameter
  • Rename parameter from accountId to account_id (snake_case consistency)
  • account_id is now optional — only used by org keys to filter to a specific member

Changes

ActionFile
NEWlib/organizations/buildGetOrganizationsParams.ts
NEWlib/organizations/__tests__/buildGetOrganizationsParams.test.ts (7 tests)
NEWlib/organizations/validateGetOrganizationsRequest.ts
MODIFYlib/organizations/getOrganizationsHandler.ts
MODIFYapp/api/organizations/route.ts (JSDoc only)
DELETElib/organizations/validateOrganizationsQuery.ts

Test plan

  • 7 unit tests pass for buildGetOrganizationsParams
  • recoup orgs list CLI works without code changes (derives account from API key)
  • curl -H "x-api-key: $KEY" .../api/organizations returns orgs for authenticated account
  • curl .../api/organizations returns 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) to account_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.