nucleus-core-ts 0.10.147 → 0.10.151

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. package/LICENSE +48 -48
  2. package/dist/.build-ok +1 -1
  3. package/dist/fe/components/AuthorizationPage/labels.js +13 -13
  4. package/dist/fe/components/Captcha/labels.js +17 -17
  5. package/dist/fe/components/ChatPanel/helpers.js +17 -17
  6. package/dist/fe/components/ChatPanel/labels.js +16 -16
  7. package/dist/fe/components/DataTable/labels.js +16 -16
  8. package/dist/fe/components/DevicesPage/components/DeviceCard.js +15 -15
  9. package/dist/fe/components/DevicesPage/components/DevicesPage.js +9 -9
  10. package/dist/fe/components/DevicesPage/labels.js +12 -12
  11. package/dist/fe/components/ForgotPasswordPage/labels.js +8 -8
  12. package/dist/fe/components/FormBuilder/components/FormField.js +5 -5
  13. package/dist/fe/components/FormBuilder/utils/fieldMapping.js +9 -9
  14. package/dist/fe/components/IntegrationsPage/components/ConnectionAuthFields.js +8 -8
  15. package/dist/fe/components/IntegrationsPage/components/ConnectionBasicFields.js +3 -3
  16. package/dist/fe/components/IntegrationsPage/components/ConnectionExport.js +23 -23
  17. package/dist/fe/components/IntegrationsPage/components/ConnectionForm.js +22 -22
  18. package/dist/fe/components/IntegrationsPage/components/ConnectionList.js +7 -7
  19. package/dist/fe/components/IntegrationsPage/components/ConnectionOauthFields.js +6 -6
  20. package/dist/fe/components/IntegrationsPage/components/ConnectionSettingsTab.js +24 -24
  21. package/dist/fe/components/IntegrationsPage/components/ConnectionSwitcher.js +19 -19
  22. package/dist/fe/components/IntegrationsPage/components/ConnectionTabs.js +15 -15
  23. package/dist/fe/components/IntegrationsPage/components/ConnectionTest.js +21 -21
  24. package/dist/fe/components/IntegrationsPage/components/ConnectionTransfer.js +18 -18
  25. package/dist/fe/components/IntegrationsPage/components/CredentialFields.js +19 -19
  26. package/dist/fe/components/IntegrationsPage/components/CredentialSlotRow.js +8 -8
  27. package/dist/fe/components/IntegrationsPage/components/EndpointForm.js +7 -7
  28. package/dist/fe/components/IntegrationsPage/components/EndpointFormFields.js +12 -12
  29. package/dist/fe/components/IntegrationsPage/components/EndpointList.js +7 -7
  30. package/dist/fe/components/IntegrationsPage/components/EndpointSample.js +36 -36
  31. package/dist/fe/components/IntegrationsPage/components/EndpointsTab.js +29 -29
  32. package/dist/fe/components/IntegrationsPage/components/FieldMappingRow.js +7 -7
  33. package/dist/fe/components/IntegrationsPage/components/FieldMappingRows.js +6 -6
  34. package/dist/fe/components/IntegrationsPage/components/IntegrationsPage.js +60 -60
  35. package/dist/fe/components/IntegrationsPage/components/MappingAccountFields.js +15 -15
  36. package/dist/fe/components/IntegrationsPage/components/MappingEditor.js +9 -9
  37. package/dist/fe/components/IntegrationsPage/components/MappingList.js +23 -23
  38. package/dist/fe/components/IntegrationsPage/components/MappingPasswordField.js +12 -12
  39. package/dist/fe/components/IntegrationsPage/components/MappingScheduleFields.js +23 -23
  40. package/dist/fe/components/IntegrationsPage/components/MappingWriteModeFields.js +31 -31
  41. package/dist/fe/components/IntegrationsPage/components/MappingsTab.js +56 -56
  42. package/dist/fe/components/IntegrationsPage/components/PaginationFields.js +11 -11
  43. package/dist/fe/components/IntegrationsPage/components/ParamBindingRows.js +15 -15
  44. package/dist/fe/components/IntegrationsPage/components/Primitives.js +28 -28
  45. package/dist/fe/components/IntegrationsPage/components/ReferenceCheckRows.js +9 -9
  46. package/dist/fe/components/IntegrationsPage/components/RunConfirmStep.js +6 -6
  47. package/dist/fe/components/IntegrationsPage/components/RunHistory.js +6 -6
  48. package/dist/fe/components/IntegrationsPage/components/RunHistoryRow.js +9 -9
  49. package/dist/fe/components/IntegrationsPage/components/RunPanel.js +40 -40
  50. package/dist/fe/components/IntegrationsPage/components/RunPasswordField.js +18 -18
  51. package/dist/fe/components/IntegrationsPage/components/RunPlanIssues.js +6 -6
  52. package/dist/fe/components/IntegrationsPage/components/RunPlanReferences.js +12 -12
  53. package/dist/fe/components/IntegrationsPage/components/RunPlanSuggestions.js +11 -11
  54. package/dist/fe/components/IntegrationsPage/components/RunPlanSummary.js +6 -6
  55. package/dist/fe/components/IntegrationsPage/components/RunProgressBar.js +6 -6
  56. package/dist/fe/components/IntegrationsPage/components/RunRevertConflicts.js +6 -6
  57. package/dist/fe/components/IntegrationsPage/components/Skeletons.js +7 -7
  58. package/dist/fe/components/IntegrationsPage/components/authOptions.js +4 -4
  59. package/dist/fe/components/IntegrationsPage/components/connectionDraft.js +27 -27
  60. package/dist/fe/components/IntegrationsPage/components/credentialSlots.js +25 -25
  61. package/dist/fe/components/IntegrationsPage/components/deleteIsConfirmed.js +9 -9
  62. package/dist/fe/components/IntegrationsPage/components/fieldMappingOptions.js +4 -4
  63. package/dist/fe/components/IntegrationsPage/components/formSupport.js +34 -34
  64. package/dist/fe/components/IntegrationsPage/components/jsonArray.js +14 -14
  65. package/dist/fe/components/IntegrationsPage/components/jsonObjectField.js +15 -15
  66. package/dist/fe/components/IntegrationsPage/components/mappingDraft.js +10 -10
  67. package/dist/fe/components/IntegrationsPage/components/mappingStaleness.js +22 -22
  68. package/dist/fe/components/IntegrationsPage/components/nextRuns.js +8 -8
  69. package/dist/fe/components/IntegrationsPage/components/passwordIsNeeded.js +13 -13
  70. package/dist/fe/components/IntegrationsPage/components/pathParams.js +6 -6
  71. package/dist/fe/components/IntegrationsPage/components/runFormat.js +18 -18
  72. package/dist/fe/components/IntegrationsPage/components/settleOwnership.js +18 -18
  73. package/dist/fe/components/IntegrationsPage/components/useInfiniteList.js +8 -8
  74. package/dist/fe/components/IntegrationsPage/store/index.js +20 -20
  75. package/dist/fe/components/IntegrationsPage/store/upsertInto.js +12 -12
  76. package/dist/fe/components/IntegrationsPage/text/context.js +6 -6
  77. package/dist/fe/components/IntegrationsPage/text/index.js +18 -18
  78. package/dist/fe/components/IntegrationsPage/theme/index.js +29 -29
  79. package/dist/fe/components/IntegrationsPage/types/records.js +10 -10
  80. package/dist/fe/components/IntegrationsPage/types/results.js +3 -3
  81. package/dist/fe/components/NotificationCenter/labels.js +17 -17
  82. package/dist/fe/components/ProfilePage/labels.js +10 -10
  83. package/dist/fe/components/ResetPasswordPage/labels.js +4 -4
  84. package/dist/fe/components/SetPasswordPage/labels.js +11 -11
  85. package/dist/fe/components/UsersPage/labels.js +14 -14
  86. package/dist/fe/utils/columnUtils.js +24 -24
  87. package/dist/fe/utils/searchFold.js +36 -36
  88. package/dist/index.js +6 -6
  89. package/dist/server.js +6 -6
  90. package/dist/src/Client/Proxy/authz.js +4 -4
  91. package/dist/src/Client/Proxy/httpProxy.js +136 -136
  92. package/dist/src/Client/Proxy/largeBody.js +29 -29
  93. package/dist/src/Client/Proxy/utils.js +32 -32
  94. package/dist/src/Client/Proxy/wsProxy.js +59 -59
  95. package/dist/src/Managers/Redis/index.d.ts +14 -0
  96. package/dist/src/Nucleus/routes/auth/admin/impersonationStore.d.ts +3 -4
  97. package/dist/src/Nucleus/routes/auth/refresh/issuedPair.d.ts +67 -0
  98. package/dist/src/Nucleus/routes/auth/refresh/recordIssued.d.ts +15 -6
  99. package/dist/src/Nucleus/routes/auth/refresh/refreshChain.d.ts +56 -0
  100. package/dist/src/Services/Auth/SessionStore/utils.d.ts +2 -0
  101. package/dist/src/Shared/cron.js +71 -71
  102. package/dist/src/Shared/redactSecrets.js +156 -156
  103. package/dist/src/Shared/redaction/bare.js +61 -61
  104. package/dist/src/Shared/redaction/floor.js +48 -48
  105. package/dist/src/Shared/redaction/freeText.js +70 -70
  106. package/dist/src/Shared/redaction/json.js +30 -30
  107. package/dist/src/Shared/redaction/lists.js +23 -23
  108. package/dist/src/Shared/redaction/markers.js +28 -28
  109. package/dist/src/Shared/redaction/names.js +49 -49
  110. package/dist/src/Shared/redaction/pairs.js +54 -54
  111. package/dist/src/Shared/redaction/secretString.js +29 -29
  112. package/dist/src/Shared/redaction/structured.js +52 -52
  113. package/dist/src/Shared/redaction/walk.js +25 -25
  114. package/infra/scripts/generate-project.ts +766 -766
  115. package/infra/templates/README.md +57 -57
  116. package/infra/templates/backend/.dockerignore +9 -9
  117. package/infra/templates/backend/.env.example +15 -15
  118. package/infra/templates/backend/README.md +28 -28
  119. package/infra/templates/backend/azure-pipelines.yml +135 -135
  120. package/infra/templates/backend/k8s/Dockerfile +31 -31
  121. package/infra/templates/backend/k8s/configmap.yaml +26 -26
  122. package/infra/templates/backend/k8s/deployment.yaml +85 -85
  123. package/infra/templates/backend/k8s/pvc.yaml +12 -12
  124. package/infra/templates/backend/k8s/service.yaml +13 -13
  125. package/infra/templates/backend/tsconfig.json +22 -22
  126. package/infra/templates/frontend/.dockerignore +10 -10
  127. package/infra/templates/frontend/.env.example +8 -8
  128. package/infra/templates/frontend/.env.local.example +10 -10
  129. package/infra/templates/frontend/README.md +69 -69
  130. package/infra/templates/frontend/app/[tablename]/page.tsx +37 -37
  131. package/infra/templates/frontend/app/_components/AuthWrapper/index.tsx +63 -63
  132. package/infra/templates/frontend/app/authorization/page.tsx +43 -43
  133. package/infra/templates/frontend/app/change-password/page.tsx +23 -23
  134. package/infra/templates/frontend/app/devices/page.tsx +127 -127
  135. package/infra/templates/frontend/app/forgot-password/page.tsx +20 -20
  136. package/infra/templates/frontend/app/globals.css +28 -28
  137. package/infra/templates/frontend/app/layout.tsx +35 -35
  138. package/infra/templates/frontend/app/login/page.tsx +33 -33
  139. package/infra/templates/frontend/app/page.tsx +565 -565
  140. package/infra/templates/frontend/app/profile/page.tsx +92 -92
  141. package/infra/templates/frontend/app/register/page.tsx +27 -27
  142. package/infra/templates/frontend/app/reset-password/page.tsx +60 -60
  143. package/infra/templates/frontend/app/set-password/page.tsx +43 -43
  144. package/infra/templates/frontend/app/ui-docs/page.tsx +52 -52
  145. package/infra/templates/frontend/app/users/page.tsx +52 -52
  146. package/infra/templates/frontend/app/verify-email/page.tsx +41 -41
  147. package/infra/templates/frontend/app/verify-magic-link/page.tsx +46 -46
  148. package/infra/templates/frontend/azure-pipelines.yml +137 -137
  149. package/infra/templates/frontend/code-and-design-principles.md +438 -438
  150. package/infra/templates/frontend/k8s/Dockerfile +50 -50
  151. package/infra/templates/frontend/k8s/configmap.yaml +18 -18
  152. package/infra/templates/frontend/k8s/deployment.yaml +72 -72
  153. package/infra/templates/frontend/k8s/ingress.yaml +36 -36
  154. package/infra/templates/frontend/k8s/service.yaml +14 -14
  155. package/infra/templates/frontend/lib/api/endpoints.ts +37 -37
  156. package/infra/templates/frontend/lib/api/factory.ts +44 -44
  157. package/infra/templates/frontend/lib/api/hook.ts +10 -10
  158. package/infra/templates/frontend/next.config.ts +19 -19
  159. package/infra/templates/frontend/package.json +34 -34
  160. package/infra/templates/frontend/postcss.config.mjs +5 -5
  161. package/infra/templates/frontend/server.ts +114 -114
  162. package/infra/templates/frontend/tsconfig.json +23 -23
  163. package/package.json +1 -1
  164. package/public/components/CTA.tsx +25 -25
  165. package/public/components/Capabilities.tsx +67 -67
  166. package/public/components/Features.tsx +107 -107
  167. package/public/components/Footer.tsx +58 -58
  168. package/public/components/Hero.tsx +51 -51
  169. package/public/components/Managers.tsx +55 -55
  170. package/public/components/Nav.tsx +91 -91
  171. package/public/components/Stack.tsx +36 -36
  172. package/public/components/docs/Docs.tsx +60 -60
  173. package/public/components/docs/DocsContent.tsx +176 -176
  174. package/public/components/docs/DocsRightSidebar.tsx +53 -53
  175. package/public/components/docs/DocsSidebar.tsx +54 -54
  176. package/public/components/docs/content/authentication.ts +836 -836
  177. package/public/components/docs/content/authorization.ts +268 -268
  178. package/public/components/docs/content/backupRestore.ts +173 -173
  179. package/public/components/docs/content/clientModule.ts +287 -287
  180. package/public/components/docs/content/entityCrud.ts +682 -682
  181. package/public/components/docs/content/monitoring.ts +313 -313
  182. package/public/components/docs/content/multiTenant.ts +269 -269
  183. package/public/components/docs/content/oauthApiKeys.ts +325 -325
  184. package/public/components/docs/content/pubsub.ts +131 -131
  185. package/public/components/docs/content/storageCdn.ts +171 -171
  186. package/public/components/docs/content/verification.ts +289 -289
  187. package/public/components/docs/docsData.ts +113 -113
  188. package/public/components/docs/index.ts +6 -6
  189. package/public/components/index.ts +9 -9
  190. package/public/docs.css +629 -629
  191. package/public/index.html +81 -81
  192. package/public/index.tsx +42 -42
  193. package/public/store.ts +76 -76
  194. package/public/styles.css +858 -858
  195. package/schemas/config.nucleus.json +2651 -2651
  196. package/scripts/audit-purge-noise.ts +120 -120
  197. package/scripts/build.ts +582 -582
  198. package/scripts/generate-system-tables-types.ts +18 -18
  199. package/scripts/generate-types-schema.test.ts +73 -73
  200. package/scripts/generate-types-schema.ts +1284 -1284
  201. package/scripts/packagedScripts.test.ts +87 -87
  202. package/scripts/publish.ts +276 -276
  203. package/scripts/skillCitations.test.ts +107 -107
  204. package/scripts/verify-publishable.ts +40 -40
@@ -1,268 +1,268 @@
1
- import type { DocItem } from '../docsData'
2
-
3
- export const authorizationItems: DocItem[] = [
4
- {
5
- id: 'rbac-overview',
6
- title: 'RBAC Overview',
7
- subItems: [
8
- {
9
- id: 'how-rbac-works',
10
- title: 'How RBAC Works',
11
- content: `
12
- ## How RBAC Works in Nucleus
13
-
14
- Nucleus implements Role-Based Access Control (RBAC) with a **claims-based permission model**. Instead of checking "is this user an admin?", the system checks "does this user have the \`post.products\` claim?" — which is far more granular and flexible.
15
-
16
- ### The Permission Hierarchy
17
-
18
- \`\`\`
19
- User → has Roles → Roles have Claims → Claims grant Actions on Entities
20
- \`\`\`
21
-
22
- **Users** are assigned one or more **Roles**. Each Role contains a set of **Claims**. A Claim is a permission to perform a specific action on a specific entity. Claims follow the format \`{method}.{entity_name}\`.
23
-
24
- ### Claim Format Examples
25
-
26
- | Claim | Meaning |
27
- |-------|---------|
28
- | \`get.products\` | Can read products |
29
- | \`post.products\` | Can create products |
30
- | \`put.products\` | Can update products |
31
- | \`delete.products\` | Can delete products |
32
- | \`patch.products\` | Can partially update products |
33
- | \`toggle.products\` | Can toggle product fields |
34
- | \`get.users\` | Can read users |
35
- | \`post.orders\` | Can create orders |
36
-
37
- ### How Authorization Is Checked
38
-
39
- On every non-public request, after JWT authentication, the authorization middleware runs:
40
-
41
- 1. Extract the HTTP method and entity name from the request path
42
- 2. Build the required claim: \`{method}.{entity_name}\`
43
- 3. Check if the user's claims (from the JWT or database) include this claim
44
- 4. If yes → proceed. If no → 403 Forbidden.
45
-
46
- ### The Godmin Role
47
-
48
- The **godmin** (god admin) is a special super-admin role. A user with the godmin role bypasses ALL authorization checks — they can do anything. Godmin is automatically seeded on first startup if configured:
49
-
50
- \`\`\`json
51
- {
52
- "authorization": {
53
- "enabled": true,
54
- "godminEmail": "admin@example.com",
55
- "godminPassword": "SecurePass123!"
56
- }
57
- }
58
- \`\`\`
59
-
60
- On startup, Nucleus:
61
- 1. Creates the "godmin" role if it doesn't exist
62
- 2. Assigns ALL claims to the godmin role
63
- 3. Creates the user with the configured email/password if they don't exist
64
- 4. Assigns the godmin role to that user
65
-
66
- ### System Tables
67
-
68
- Authorization uses these tables:
69
-
70
- | Table | Purpose |
71
- |-------|---------|
72
- | \`roles\` | Role definitions (id, name, description) |
73
- | \`claims\` | Permission definitions (id, action, resource, scope) |
74
- | \`userRoles\` | Many-to-many: which users have which roles |
75
- | \`roleClaims\` | Many-to-many: which roles have which claims |
76
- `,
77
- },
78
- {
79
- id: 'auto-seed-claims',
80
- title: 'Auto Claim Seeding',
81
- content: `
82
- ## Auto Claim Seeding
83
-
84
- When \`autoSeedClaims\` is true, Nucleus automatically generates claims for every entity on startup. For each entity in your config, it creates claims for: \`get\`, \`post\`, \`put\`, \`delete\`, \`patch\`, and \`toggle\`.
85
-
86
- ### How It Works
87
-
88
- On startup, the claim seeder:
89
-
90
- 1. Reads all entities from your config
91
- 2. For each entity, generates 6 claims (one per HTTP method)
92
- 3. Checks the database for existing claims
93
- 4. Inserts only the missing ones (idempotent — safe to run repeatedly)
94
- 5. Assigns all new claims to the godmin role
95
-
96
- ### External Entities
97
-
98
- If you're running an IDP in "full" mode with consumer services, the IDP doesn't know about the consumer's entities. Use \`externalEntities\` to tell the IDP about them so it can seed claims:
99
-
100
- \`\`\`json
101
- {
102
- "authorization": {
103
- "enabled": true,
104
- "autoSeedClaims": true,
105
- "externalEntities": [
106
- { "table_name": "blog_posts" },
107
- { "table_name": "blog_comments" },
108
- { "table_name": "blog_categories" }
109
- ]
110
- }
111
- }
112
- \`\`\`
113
-
114
- This way, the IDP seeds claims like \`get.blog_posts\`, \`post.blog_comments\`, etc. — and when a consumer service validates a JWT, the claims are already embedded in the token.
115
-
116
- ### Skip Tables / Columns
117
-
118
- \`\`\`json
119
- {
120
- "authorization": {
121
- "skipTables": ["audit_logs", "backup_logs"],
122
- "skipColumns": ["internalField"]
123
- }
124
- }
125
- \`\`\`
126
-
127
- Tables in \`skipTables\` won't have claims generated. Columns in \`skipColumns\` won't have field-level claims generated.
128
- `,
129
- },
130
- ],
131
- },
132
- {
133
- id: 'scopes',
134
- title: 'Scopes & Filters',
135
- subItems: [
136
- {
137
- id: 'scope-filters',
138
- title: 'Scope Filters (Row-Level Security)',
139
- content: `
140
- ## Scope Filters — Row-Level Security
141
-
142
- Scopes add row-level security to claims. Instead of just "can this user read products?", scopes answer "which products can this user read?"
143
-
144
- ### How Scopes Work
145
-
146
- A scope is a JSON filter attached to a claim on a specific role. When a user with that role makes a request, the scope filter is automatically applied to the database query.
147
-
148
- ### Example: Users Can Only See Their Own Orders
149
-
150
- On the "customer" role, set the scope for the \`get.orders\` claim to:
151
-
152
- \`\`\`json
153
- {
154
- "userId": "$self"
155
- }
156
- \`\`\`
157
-
158
- The special \`$self\` variable is replaced with the authenticated user's ID at runtime. So when a customer calls \`GET /orders\`, Nucleus automatically adds \`WHERE userId = '{their-user-id}'\` to the query. They only see their own orders.
159
-
160
- ### Scope Filter Syntax
161
-
162
- Scopes support standard filter operators:
163
-
164
- \`\`\`json
165
- {
166
- "status": "active",
167
- "departmentId": "$self.departmentId",
168
- "createdAt": { "$gte": "2024-01-01" }
169
- }
170
- \`\`\`
171
-
172
- ### Field-Level Filtering
173
-
174
- Beyond row filtering, authorization can also restrict which **fields** are returned in the response. If a role's claim doesn't include certain field-level claims, those fields are stripped from the API response.
175
-
176
- ### Relation-Level Filtering
177
-
178
- Similarly, if a role doesn't have claims for related entities, those relations are excluded from the response even if the client requests them via the \`with\` query parameter.
179
-
180
- ### Configuration
181
-
182
- \`\`\`json
183
- {
184
- "authorization": {
185
- "enabled": true,
186
- "autoSeedClaims": true,
187
- "excludedPaths": ["/health", "/swagger"],
188
- "publicPaths": ["/auth/login", "/auth/register"]
189
- }
190
- }
191
- \`\`\`
192
-
193
- | Field | Description |
194
- |-------|-------------|
195
- | \`excludedPaths\` | Paths that bypass authorization entirely |
196
- | \`publicPaths\` | Paths accessible without authentication |
197
- `,
198
- },
199
- {
200
- id: 'consumer-auth-check',
201
- title: 'Consumer /auth/check',
202
- content: `
203
- ## Consumer Mode — /auth/check
204
-
205
- When a consumer-mode service has authorization enabled, it needs to verify claims against the IDP because it doesn't have the authorization tables locally.
206
-
207
- ### How It Works
208
-
209
- 1. Consumer service receives a request with a JWT
210
- 2. JWT is verified locally (stateless — fast)
211
- 3. For authorization, the consumer calls the IDP's \`POST /auth/check\` endpoint
212
- 4. The IDP checks the user's roles and claims in its database
213
- 5. Returns the authorization result to the consumer
214
-
215
- ### Configuration (Consumer Side)
216
-
217
- \`\`\`json
218
- {
219
- "authentication": {
220
- "mode": "consumer",
221
- "idpUrl": "IDP_URL"
222
- },
223
- "authorization": {
224
- "enabled": true
225
- }
226
- }
227
- \`\`\`
228
-
229
- The \`idpUrl\` is the URL of your IDP service. In your .env: \`IDP_URL=http://idp-api:9000\` (or the Kubernetes service DNS name).
230
-
231
- ### /auth/check Endpoint (IDP Side)
232
-
233
- \`\`\`
234
- POST /auth/check
235
- \`\`\`
236
-
237
- \`\`\`json
238
- {
239
- "userId": "user-uuid",
240
- "method": "GET",
241
- "entity": "blog_posts"
242
- }
243
- \`\`\`
244
-
245
- Returns:
246
-
247
- \`\`\`json
248
- {
249
- "authorized": true,
250
- "scopes": { "userId": "$self" },
251
- "fieldFilters": ["internalNotes"],
252
- "relationFilters": ["auditLogs"]
253
- }
254
- \`\`\`
255
-
256
- The consumer service uses the returned scopes to apply row-level filtering, and the field/relation filters to strip unauthorized data from the response.
257
-
258
- ### Performance Note
259
-
260
- The \`/auth/check\` call adds a network hop per request. For high-throughput consumer services, consider:
261
- - Caching authorization results in Redis with a short TTL
262
- - Embedding all necessary claims in the JWT payload (which Nucleus does by default for the access token)
263
- - Using the JWT claims directly for simple checks, falling back to \`/auth/check\` only for scope resolution
264
- `,
265
- },
266
- ],
267
- },
268
- ]
1
+ import type { DocItem } from '../docsData'
2
+
3
+ export const authorizationItems: DocItem[] = [
4
+ {
5
+ id: 'rbac-overview',
6
+ title: 'RBAC Overview',
7
+ subItems: [
8
+ {
9
+ id: 'how-rbac-works',
10
+ title: 'How RBAC Works',
11
+ content: `
12
+ ## How RBAC Works in Nucleus
13
+
14
+ Nucleus implements Role-Based Access Control (RBAC) with a **claims-based permission model**. Instead of checking "is this user an admin?", the system checks "does this user have the \`post.products\` claim?" — which is far more granular and flexible.
15
+
16
+ ### The Permission Hierarchy
17
+
18
+ \`\`\`
19
+ User → has Roles → Roles have Claims → Claims grant Actions on Entities
20
+ \`\`\`
21
+
22
+ **Users** are assigned one or more **Roles**. Each Role contains a set of **Claims**. A Claim is a permission to perform a specific action on a specific entity. Claims follow the format \`{method}.{entity_name}\`.
23
+
24
+ ### Claim Format Examples
25
+
26
+ | Claim | Meaning |
27
+ |-------|---------|
28
+ | \`get.products\` | Can read products |
29
+ | \`post.products\` | Can create products |
30
+ | \`put.products\` | Can update products |
31
+ | \`delete.products\` | Can delete products |
32
+ | \`patch.products\` | Can partially update products |
33
+ | \`toggle.products\` | Can toggle product fields |
34
+ | \`get.users\` | Can read users |
35
+ | \`post.orders\` | Can create orders |
36
+
37
+ ### How Authorization Is Checked
38
+
39
+ On every non-public request, after JWT authentication, the authorization middleware runs:
40
+
41
+ 1. Extract the HTTP method and entity name from the request path
42
+ 2. Build the required claim: \`{method}.{entity_name}\`
43
+ 3. Check if the user's claims (from the JWT or database) include this claim
44
+ 4. If yes → proceed. If no → 403 Forbidden.
45
+
46
+ ### The Godmin Role
47
+
48
+ The **godmin** (god admin) is a special super-admin role. A user with the godmin role bypasses ALL authorization checks — they can do anything. Godmin is automatically seeded on first startup if configured:
49
+
50
+ \`\`\`json
51
+ {
52
+ "authorization": {
53
+ "enabled": true,
54
+ "godminEmail": "admin@example.com",
55
+ "godminPassword": "SecurePass123!"
56
+ }
57
+ }
58
+ \`\`\`
59
+
60
+ On startup, Nucleus:
61
+ 1. Creates the "godmin" role if it doesn't exist
62
+ 2. Assigns ALL claims to the godmin role
63
+ 3. Creates the user with the configured email/password if they don't exist
64
+ 4. Assigns the godmin role to that user
65
+
66
+ ### System Tables
67
+
68
+ Authorization uses these tables:
69
+
70
+ | Table | Purpose |
71
+ |-------|---------|
72
+ | \`roles\` | Role definitions (id, name, description) |
73
+ | \`claims\` | Permission definitions (id, action, resource, scope) |
74
+ | \`userRoles\` | Many-to-many: which users have which roles |
75
+ | \`roleClaims\` | Many-to-many: which roles have which claims |
76
+ `,
77
+ },
78
+ {
79
+ id: 'auto-seed-claims',
80
+ title: 'Auto Claim Seeding',
81
+ content: `
82
+ ## Auto Claim Seeding
83
+
84
+ When \`autoSeedClaims\` is true, Nucleus automatically generates claims for every entity on startup. For each entity in your config, it creates claims for: \`get\`, \`post\`, \`put\`, \`delete\`, \`patch\`, and \`toggle\`.
85
+
86
+ ### How It Works
87
+
88
+ On startup, the claim seeder:
89
+
90
+ 1. Reads all entities from your config
91
+ 2. For each entity, generates 6 claims (one per HTTP method)
92
+ 3. Checks the database for existing claims
93
+ 4. Inserts only the missing ones (idempotent — safe to run repeatedly)
94
+ 5. Assigns all new claims to the godmin role
95
+
96
+ ### External Entities
97
+
98
+ If you're running an IDP in "full" mode with consumer services, the IDP doesn't know about the consumer's entities. Use \`externalEntities\` to tell the IDP about them so it can seed claims:
99
+
100
+ \`\`\`json
101
+ {
102
+ "authorization": {
103
+ "enabled": true,
104
+ "autoSeedClaims": true,
105
+ "externalEntities": [
106
+ { "table_name": "blog_posts" },
107
+ { "table_name": "blog_comments" },
108
+ { "table_name": "blog_categories" }
109
+ ]
110
+ }
111
+ }
112
+ \`\`\`
113
+
114
+ This way, the IDP seeds claims like \`get.blog_posts\`, \`post.blog_comments\`, etc. — and when a consumer service validates a JWT, the claims are already embedded in the token.
115
+
116
+ ### Skip Tables / Columns
117
+
118
+ \`\`\`json
119
+ {
120
+ "authorization": {
121
+ "skipTables": ["audit_logs", "backup_logs"],
122
+ "skipColumns": ["internalField"]
123
+ }
124
+ }
125
+ \`\`\`
126
+
127
+ Tables in \`skipTables\` won't have claims generated. Columns in \`skipColumns\` won't have field-level claims generated.
128
+ `,
129
+ },
130
+ ],
131
+ },
132
+ {
133
+ id: 'scopes',
134
+ title: 'Scopes & Filters',
135
+ subItems: [
136
+ {
137
+ id: 'scope-filters',
138
+ title: 'Scope Filters (Row-Level Security)',
139
+ content: `
140
+ ## Scope Filters — Row-Level Security
141
+
142
+ Scopes add row-level security to claims. Instead of just "can this user read products?", scopes answer "which products can this user read?"
143
+
144
+ ### How Scopes Work
145
+
146
+ A scope is a JSON filter attached to a claim on a specific role. When a user with that role makes a request, the scope filter is automatically applied to the database query.
147
+
148
+ ### Example: Users Can Only See Their Own Orders
149
+
150
+ On the "customer" role, set the scope for the \`get.orders\` claim to:
151
+
152
+ \`\`\`json
153
+ {
154
+ "userId": "$self"
155
+ }
156
+ \`\`\`
157
+
158
+ The special \`$self\` variable is replaced with the authenticated user's ID at runtime. So when a customer calls \`GET /orders\`, Nucleus automatically adds \`WHERE userId = '{their-user-id}'\` to the query. They only see their own orders.
159
+
160
+ ### Scope Filter Syntax
161
+
162
+ Scopes support standard filter operators:
163
+
164
+ \`\`\`json
165
+ {
166
+ "status": "active",
167
+ "departmentId": "$self.departmentId",
168
+ "createdAt": { "$gte": "2024-01-01" }
169
+ }
170
+ \`\`\`
171
+
172
+ ### Field-Level Filtering
173
+
174
+ Beyond row filtering, authorization can also restrict which **fields** are returned in the response. If a role's claim doesn't include certain field-level claims, those fields are stripped from the API response.
175
+
176
+ ### Relation-Level Filtering
177
+
178
+ Similarly, if a role doesn't have claims for related entities, those relations are excluded from the response even if the client requests them via the \`with\` query parameter.
179
+
180
+ ### Configuration
181
+
182
+ \`\`\`json
183
+ {
184
+ "authorization": {
185
+ "enabled": true,
186
+ "autoSeedClaims": true,
187
+ "excludedPaths": ["/health", "/swagger"],
188
+ "publicPaths": ["/auth/login", "/auth/register"]
189
+ }
190
+ }
191
+ \`\`\`
192
+
193
+ | Field | Description |
194
+ |-------|-------------|
195
+ | \`excludedPaths\` | Paths that bypass authorization entirely |
196
+ | \`publicPaths\` | Paths accessible without authentication |
197
+ `,
198
+ },
199
+ {
200
+ id: 'consumer-auth-check',
201
+ title: 'Consumer /auth/check',
202
+ content: `
203
+ ## Consumer Mode — /auth/check
204
+
205
+ When a consumer-mode service has authorization enabled, it needs to verify claims against the IDP because it doesn't have the authorization tables locally.
206
+
207
+ ### How It Works
208
+
209
+ 1. Consumer service receives a request with a JWT
210
+ 2. JWT is verified locally (stateless — fast)
211
+ 3. For authorization, the consumer calls the IDP's \`POST /auth/check\` endpoint
212
+ 4. The IDP checks the user's roles and claims in its database
213
+ 5. Returns the authorization result to the consumer
214
+
215
+ ### Configuration (Consumer Side)
216
+
217
+ \`\`\`json
218
+ {
219
+ "authentication": {
220
+ "mode": "consumer",
221
+ "idpUrl": "IDP_URL"
222
+ },
223
+ "authorization": {
224
+ "enabled": true
225
+ }
226
+ }
227
+ \`\`\`
228
+
229
+ The \`idpUrl\` is the URL of your IDP service. In your .env: \`IDP_URL=http://idp-api:9000\` (or the Kubernetes service DNS name).
230
+
231
+ ### /auth/check Endpoint (IDP Side)
232
+
233
+ \`\`\`
234
+ POST /auth/check
235
+ \`\`\`
236
+
237
+ \`\`\`json
238
+ {
239
+ "userId": "user-uuid",
240
+ "method": "GET",
241
+ "entity": "blog_posts"
242
+ }
243
+ \`\`\`
244
+
245
+ Returns:
246
+
247
+ \`\`\`json
248
+ {
249
+ "authorized": true,
250
+ "scopes": { "userId": "$self" },
251
+ "fieldFilters": ["internalNotes"],
252
+ "relationFilters": ["auditLogs"]
253
+ }
254
+ \`\`\`
255
+
256
+ The consumer service uses the returned scopes to apply row-level filtering, and the field/relation filters to strip unauthorized data from the response.
257
+
258
+ ### Performance Note
259
+
260
+ The \`/auth/check\` call adds a network hop per request. For high-throughput consumer services, consider:
261
+ - Caching authorization results in Redis with a short TTL
262
+ - Embedding all necessary claims in the JWT payload (which Nucleus does by default for the access token)
263
+ - Using the JWT claims directly for simple checks, falling back to \`/auth/check\` only for scope resolution
264
+ `,
265
+ },
266
+ ],
267
+ },
268
+ ]