Commit dac4fb7
feat: add RECOUP_ORG_ID constant for accountId override (#109)
* feat: add RECOUP_ORG_ID constant for admin organization access
Add the Recoup admin organization UUID constant to support the accountId
override feature. API keys from this organization have universal access
and can specify any accountId when creating chats.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* feat: add getApiKeyDetails function for org context resolution
Adds a new authentication utility that extracts both accountId and orgId
from an API key. This is needed for the accountId override feature where
org API keys can specify a target accountId.
- Returns accountId from the API key's account field
- Returns orgId if the account is an organization (exists in account_organization_ids)
- Returns null orgId for personal API keys
- Includes 7 unit tests covering all scenarios
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* feat: add canAccessAccount validation function for org access control
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* docs: add Supabase database operations architecture to CLAUDE.md
Document that all Supabase calls must be in lib/supabase/[table_name]/[function].ts
- Add directory structure example
- Add naming conventions (select, insert, update, delete, get)
- Add code pattern template
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* feat: add optional accountId to createChat validation schema
Add accountId field to POST /api/chats validation schema to enable
account override for organization API keys. Includes 9 unit tests
for the validation logic.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* feat: add accountId override support to createChatHandler
Allow org API keys to create chat rooms for accounts within their org.
- When accountId provided, validates access via getApiKeyDetails + canAccessAccount
- Returns 403 if access denied, 500 if API key validation fails
- Recoup admin org has universal access to all accounts
- Includes 6 unit tests
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* docs: strengthen Supabase architecture rule in CLAUDE.md
- Add CRITICAL marker: NEVER import serverClient outside lib/supabase/
- Add 3-step process for database access in domain code
- Add WRONG vs CORRECT code examples
- Make rule more prominent and actionable
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* refactor: use getAccountOrganizations in canAccessAccount
Replace direct Supabase query with existing getAccountOrganizations()
lib function, following the architecture pattern documented in CLAUDE.md.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* refactor: use isOrganization supabase lib in getApiKeyDetails
Extracted direct Supabase call from getApiKeyDetails.ts into a new
isOrganization() function in lib/supabase/account_organization_ids/.
This follows the architecture pattern of using supabase lib functions
instead of direct queries.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* refactor: move canAccessAccount from lib/auth to lib/organizations
canAccessAccount is about organization access control, not authentication.
Moving it to lib/organizations for better code organization.
- Moved lib/auth/canAccessAccount.ts to lib/organizations/canAccessAccount.ts
- Moved tests to lib/organizations/__tests__/canAccessAccount.test.ts
- Updated imports in createChatHandler.ts and its tests
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* refactor: move getApiKeyDetails from lib/auth to lib/keys
Move getApiKeyDetails to lib/keys since it's about API key operations,
not authentication. Updated imports in createChatHandler and its tests.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* refactor: extract validateOverrideAccountId and remove isOrganization
- Create lib/accounts/validateOverrideAccountId.ts for SRP
- Update createChatHandler to use validateOverrideAccountId
- Replace isOrganization with getAccountOrganizations in getApiKeyDetails
- Extend getAccountOrganizations to support organizationId-only queries
- Delete isOrganization.ts and its tests
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>1 parent b6402e7 commit dac4fb7
File tree
13 files changed
+951
-13
lines changed- lib
- accounts
- __tests__
- chats
- __tests__
- keys
- __tests__
- organizations
- __tests__
- supabase/account_organization_ids
13 files changed
+951
-13
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
54 | 138 | | |
55 | 139 | | |
56 | 140 | | |
| |||
Lines changed: 131 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
0 commit comments