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,287 +1,287 @@
1
- import type { DocItem } from '../docsData'
2
-
3
- export const clientModuleItems: DocItem[] = [
4
- {
5
- id: 'api-caller',
6
- title: 'ApiCaller',
7
- subItems: [
8
- {
9
- id: 'api-caller-overview',
10
- title: 'How ApiCaller Works',
11
- content: `
12
- ## ApiCaller — Type-Safe API Client
13
-
14
- The ApiCaller module (\`nucleus-core-ts/client\`) provides a type-safe, auto-generated API client for your frontend. It reads your entity definitions and generates endpoint functions with full TypeScript types.
15
-
16
- ### Entry Points
17
-
18
- | Import Path | Description |
19
- |------------|-------------|
20
- | \`nucleus-core-ts/client\` | ApiCaller, endpoint generator, types |
21
- | \`nucleus-core-ts/fe\` | React components, hooks, stores |
22
- | \`nucleus-core-ts/proxy\` | HTTP + WS reverse proxy |
23
-
24
- ### How It Works
25
-
26
- 1. Your config.json defines entities with columns and types
27
- 2. \`generateAllEndpoints()\` reads these definitions and creates typed endpoint objects
28
- 3. Each endpoint object contains the HTTP method, path, and TypeScript payload/response types
29
- 4. The \`useApiActions()\` hook (or \`createServerApiActions()\`) creates callable functions from these endpoints
30
-
31
- ### Endpoint Generation
32
-
33
- \`\`\`typescript
34
- import { generateAllEndpoints } from 'nucleus-core-ts/client'
35
-
36
- const endpoints = generateAllEndpoints({
37
- config: configJson,
38
- baseUrl: '/api'
39
- })
40
-
41
- // endpoints.PRODUCTS_LIST → { method: 'GET', path: '/products', ... }
42
- // endpoints.PRODUCTS_CREATE → { method: 'POST', path: '/products', ... }
43
- // endpoints.PRODUCTS_UPDATE → { method: 'PUT', path: '/products/:id', ... }
44
- // endpoints.PRODUCTS_DELETE → { method: 'DELETE', path: '/products/:id', ... }
45
- // endpoints.ME → { method: 'GET', path: '/auth/me', ... }
46
- // endpoints.LOGIN → { method: 'POST', path: '/auth/login', ... }
47
- \`\`\`
48
-
49
- ### Endpoint Naming Convention
50
-
51
- For entity "products":
52
-
53
- | Endpoint Key | Method | Path |
54
- |-------------|--------|------|
55
- | \`PRODUCTS_LIST\` | GET | /products |
56
- | \`PRODUCTS_GET\` | GET | /products/:id |
57
- | \`PRODUCTS_CREATE\` | POST | /products |
58
- | \`PRODUCTS_UPDATE\` | PUT | /products/:id |
59
- | \`PRODUCTS_PATCH\` | PATCH | /products/:id |
60
- | \`PRODUCTS_DELETE\` | DELETE | /products/:id |
61
- | \`PRODUCTS_TOGGLE\` | PATCH | /products/:id/toggle |
62
- | \`PRODUCTS_BULK_CREATE\` | POST | /products/bulk |
63
- | \`PRODUCTS_BULK_UPDATE\` | PUT | /products/bulk |
64
- | \`PRODUCTS_BULK_DELETE\` | DELETE | /products/bulk |
65
-
66
- ### serviceId Routing
67
-
68
- When entities have a \`serviceId\`, the endpoint generator routes API calls to the correct backend service:
69
-
70
- \`\`\`json
71
- {
72
- "table_name": "blog_posts",
73
- "serviceId": "blog-api"
74
- }
75
- \`\`\`
76
-
77
- The generated endpoint will use the blog-api's base URL instead of the default IDP URL. This is configured in your frontend's API config.
78
- `,
79
- },
80
- {
81
- id: 'use-api-actions',
82
- title: 'useApiActions Hook',
83
- content: `
84
- ## useApiActions — React Hook for API Calls
85
-
86
- The \`useApiActions()\` hook creates callable API functions from your endpoint definitions. It handles token management, error handling, and request/response typing.
87
-
88
- ### Basic Usage
89
-
90
- \`\`\`typescript
91
- import { useApiActions } from 'nucleus-core-ts/fe'
92
-
93
- function ProductList() {
94
- const actions = useApiActions()
95
-
96
- const loadProducts = async () => {
97
- const result = await actions.PRODUCTS_LIST?.start({
98
- query: { page: 1, limit: 20 }
99
- })
100
- if (result?.success) {
101
- // result.data.items is typed as Product[]
102
- }
103
- }
104
-
105
- return <button onClick={loadProducts}>Load</button>
106
- }
107
- \`\`\`
108
-
109
- ### Features
110
-
111
- - **Auto token injection** — Access token is automatically included in every request
112
- - **Transparent refresh** — If the access token expires mid-request, the hook refreshes it and retries
113
- - **Type safety** — Request payloads and responses are fully typed based on your entity definitions
114
- - **Error handling** — Network errors, auth errors, and validation errors are normalized
115
- - **Optional chaining** — \`actions.ENDPOINT?.start()\` is safe — returns undefined if the endpoint doesn't exist
116
-
117
- ### Server-Side Usage
118
-
119
- For server-side rendering (Next.js Server Components, server actions):
120
-
121
- \`\`\`typescript
122
- import { createServerApiActions } from 'nucleus-core-ts/client'
123
-
124
- const serverActions = createServerApiActions({
125
- baseUrl: process.env.API_URL,
126
- getToken: () => cookies().get('access_token')?.value
127
- })
128
-
129
- const products = await serverActions.PRODUCTS_LIST.start({
130
- query: { limit: 10 }
131
- })
132
- \`\`\`
133
- `,
134
- },
135
- ],
136
- },
137
- {
138
- id: 'proxy-module',
139
- title: 'Proxy',
140
- subItems: [
141
- {
142
- id: 'proxy-overview',
143
- title: 'HTTP & WebSocket Proxy',
144
- content: `
145
- ## HTTP & WebSocket Proxy
146
-
147
- The proxy module (\`nucleus-core-ts/proxy\`) provides a reverse proxy for Next.js applications that need to forward API requests to the Nucleus backend. It handles both HTTP and WebSocket proxying with automatic token refresh.
148
-
149
- ### Why a Proxy?
150
-
151
- In a typical Next.js setup, the frontend runs on \`localhost:3000\` and the API on \`localhost:9000\`. Browser cookies are domain-specific, and CORS can be tricky. The proxy solves this by:
152
-
153
- 1. Running as Next.js middleware or API route
154
- 2. Forwarding requests to the backend with cookies intact
155
- 3. Handling token refresh transparently
156
- 4. Proxying WebSocket connections for PubSub
157
-
158
- ### HTTP Proxy
159
-
160
- The HTTP proxy intercepts requests matching a pattern (e.g., \`/api/*\`) and forwards them to the backend:
161
-
162
- \`\`\`
163
- Browser → Next.js (/api/products) → Proxy → Nucleus Backend (/products)
164
- \`\`\`
165
-
166
- Features:
167
- - **Cookie forwarding** — Auth cookies are passed through
168
- - **Token refresh** — If the backend returns 401, the proxy calls \`/auth/refresh\`, gets new tokens, retries the request, and sets the new cookies on the response
169
- - **Path rewriting** — Strips the \`/api\` prefix (configurable)
170
- - **Header forwarding** — All headers are forwarded, including \`x-forwarded-for\`
171
-
172
- ### WebSocket Proxy
173
-
174
- For PubSub WebSocket connections:
175
-
176
- \`\`\`
177
- Browser (ws://localhost:3000/api/events) → Proxy → Backend (ws://localhost:9000/api/events/subscribe)
178
- \`\`\`
179
-
180
- The WS proxy handles:
181
- - Connection upgrade
182
- - Token injection in the upgrade request
183
- - Bidirectional message forwarding
184
- - Automatic reconnection on disconnect
185
-
186
- ### Configuration
187
-
188
- The proxy is typically configured in your Next.js \`next.config.ts\` rewrites or as middleware. The exact setup depends on your deployment architecture.
189
- `,
190
- },
191
- ],
192
- },
193
- {
194
- id: 'server-fetch',
195
- title: 'ServerFetch',
196
- subItems: [
197
- {
198
- id: 'server-fetch-overview',
199
- title: 'Server-Side HTTP Client',
200
- content: `
201
- ## ServerFetch — Server-Side HTTP Client
202
-
203
- The ServerFetch module provides a server-side HTTP client with retry logic and error handling. It's used internally by the proxy and can be used in your own server-side code.
204
-
205
- ### Features
206
-
207
- - **Automatic retry** — Failed requests are retried with exponential backoff
208
- - **Token management** — Access tokens are injected and refreshed automatically
209
- - **Timeout handling** — Configurable request timeouts
210
- - **Error normalization** — Network errors, timeouts, and HTTP errors are normalized into a consistent format
211
-
212
- ### Usage
213
-
214
- \`\`\`typescript
215
- import { serverFetch } from 'nucleus-core-ts/client'
216
-
217
- const response = await serverFetch({
218
- url: 'http://backend:9000/products',
219
- method: 'GET',
220
- headers: {
221
- 'Authorization': 'Bearer ' + accessToken
222
- },
223
- retry: {
224
- maxRetries: 3,
225
- backoffMs: 1000
226
- },
227
- timeoutMs: 10000
228
- })
229
- \`\`\`
230
- `,
231
- },
232
- ],
233
- },
234
- {
235
- id: 'fe-components',
236
- title: 'Frontend Components',
237
- subItems: [
238
- {
239
- id: 'fe-components-overview',
240
- title: 'Included React Components',
241
- content: `
242
- ## Frontend Components (\`nucleus-core-ts/fe\`)
243
-
244
- Nucleus ships with 27 production-ready React component families that you can use in your frontend. These components use \`h-state\` for state management and are fully themed.
245
-
246
- ### Component Families
247
-
248
- | Component | Description |
249
- |-----------|-------------|
250
- | **LoginPage** | Complete login form with email/password, deviceHint, captcha support |
251
- | **RegisterPage** | Registration form with password policy indicator, terms/privacy |
252
- | **ProfilePage** | User profile editor with avatar, personal info |
253
- | **DevicesPage** | Active sessions list, device approval, revoke sessions |
254
- | **UsersPage** | Admin user management table with CRUD |
255
- | **AuthorizationPage** | Role/claim management with assignment UI |
256
- | **VerificationFlowPage** | Visual flow builder (drag-and-drop steps, edges) |
257
- | **VerificationPanel** | Inline verification status and decision UI |
258
- | **NotificationCenter** | Bell icon with dropdown, unseen count, mark as read |
259
- | **DataTable** | Generic data table with sorting, filtering, pagination |
260
- | **FormBuilder** | Dynamic form generator from entity column definitions |
261
- | **PasswordResetPage** | Request + confirm password reset |
262
- | **PasswordSetPage** | Set password for invited users |
263
- | **MagicLinkPage** | Request magic link form |
264
- | **CaptchaWidget** | Captcha challenge renderer (math, image, puzzle, text) |
265
-
266
- ### Hooks
267
-
268
- | Hook | Description |
269
- |------|-------------|
270
- | \`useApiActions()\` | API client with auto-generated endpoints |
271
- | \`usePubSub()\` | WebSocket connection with h-state integration |
272
- | \`useAuth()\` | Authentication state and actions |
273
-
274
- ### Theming
275
-
276
- All components respect the global theme (light/dark) and can be customized via CSS custom properties. Components use semantic HTML and are accessible.
277
-
278
- ### Import
279
-
280
- \`\`\`typescript
281
- import { LoginPage, DataTable, useApiActions } from 'nucleus-core-ts/fe'
282
- \`\`\`
283
- `,
284
- },
285
- ],
286
- },
287
- ]
1
+ import type { DocItem } from '../docsData'
2
+
3
+ export const clientModuleItems: DocItem[] = [
4
+ {
5
+ id: 'api-caller',
6
+ title: 'ApiCaller',
7
+ subItems: [
8
+ {
9
+ id: 'api-caller-overview',
10
+ title: 'How ApiCaller Works',
11
+ content: `
12
+ ## ApiCaller — Type-Safe API Client
13
+
14
+ The ApiCaller module (\`nucleus-core-ts/client\`) provides a type-safe, auto-generated API client for your frontend. It reads your entity definitions and generates endpoint functions with full TypeScript types.
15
+
16
+ ### Entry Points
17
+
18
+ | Import Path | Description |
19
+ |------------|-------------|
20
+ | \`nucleus-core-ts/client\` | ApiCaller, endpoint generator, types |
21
+ | \`nucleus-core-ts/fe\` | React components, hooks, stores |
22
+ | \`nucleus-core-ts/proxy\` | HTTP + WS reverse proxy |
23
+
24
+ ### How It Works
25
+
26
+ 1. Your config.json defines entities with columns and types
27
+ 2. \`generateAllEndpoints()\` reads these definitions and creates typed endpoint objects
28
+ 3. Each endpoint object contains the HTTP method, path, and TypeScript payload/response types
29
+ 4. The \`useApiActions()\` hook (or \`createServerApiActions()\`) creates callable functions from these endpoints
30
+
31
+ ### Endpoint Generation
32
+
33
+ \`\`\`typescript
34
+ import { generateAllEndpoints } from 'nucleus-core-ts/client'
35
+
36
+ const endpoints = generateAllEndpoints({
37
+ config: configJson,
38
+ baseUrl: '/api'
39
+ })
40
+
41
+ // endpoints.PRODUCTS_LIST → { method: 'GET', path: '/products', ... }
42
+ // endpoints.PRODUCTS_CREATE → { method: 'POST', path: '/products', ... }
43
+ // endpoints.PRODUCTS_UPDATE → { method: 'PUT', path: '/products/:id', ... }
44
+ // endpoints.PRODUCTS_DELETE → { method: 'DELETE', path: '/products/:id', ... }
45
+ // endpoints.ME → { method: 'GET', path: '/auth/me', ... }
46
+ // endpoints.LOGIN → { method: 'POST', path: '/auth/login', ... }
47
+ \`\`\`
48
+
49
+ ### Endpoint Naming Convention
50
+
51
+ For entity "products":
52
+
53
+ | Endpoint Key | Method | Path |
54
+ |-------------|--------|------|
55
+ | \`PRODUCTS_LIST\` | GET | /products |
56
+ | \`PRODUCTS_GET\` | GET | /products/:id |
57
+ | \`PRODUCTS_CREATE\` | POST | /products |
58
+ | \`PRODUCTS_UPDATE\` | PUT | /products/:id |
59
+ | \`PRODUCTS_PATCH\` | PATCH | /products/:id |
60
+ | \`PRODUCTS_DELETE\` | DELETE | /products/:id |
61
+ | \`PRODUCTS_TOGGLE\` | PATCH | /products/:id/toggle |
62
+ | \`PRODUCTS_BULK_CREATE\` | POST | /products/bulk |
63
+ | \`PRODUCTS_BULK_UPDATE\` | PUT | /products/bulk |
64
+ | \`PRODUCTS_BULK_DELETE\` | DELETE | /products/bulk |
65
+
66
+ ### serviceId Routing
67
+
68
+ When entities have a \`serviceId\`, the endpoint generator routes API calls to the correct backend service:
69
+
70
+ \`\`\`json
71
+ {
72
+ "table_name": "blog_posts",
73
+ "serviceId": "blog-api"
74
+ }
75
+ \`\`\`
76
+
77
+ The generated endpoint will use the blog-api's base URL instead of the default IDP URL. This is configured in your frontend's API config.
78
+ `,
79
+ },
80
+ {
81
+ id: 'use-api-actions',
82
+ title: 'useApiActions Hook',
83
+ content: `
84
+ ## useApiActions — React Hook for API Calls
85
+
86
+ The \`useApiActions()\` hook creates callable API functions from your endpoint definitions. It handles token management, error handling, and request/response typing.
87
+
88
+ ### Basic Usage
89
+
90
+ \`\`\`typescript
91
+ import { useApiActions } from 'nucleus-core-ts/fe'
92
+
93
+ function ProductList() {
94
+ const actions = useApiActions()
95
+
96
+ const loadProducts = async () => {
97
+ const result = await actions.PRODUCTS_LIST?.start({
98
+ query: { page: 1, limit: 20 }
99
+ })
100
+ if (result?.success) {
101
+ // result.data.items is typed as Product[]
102
+ }
103
+ }
104
+
105
+ return <button onClick={loadProducts}>Load</button>
106
+ }
107
+ \`\`\`
108
+
109
+ ### Features
110
+
111
+ - **Auto token injection** — Access token is automatically included in every request
112
+ - **Transparent refresh** — If the access token expires mid-request, the hook refreshes it and retries
113
+ - **Type safety** — Request payloads and responses are fully typed based on your entity definitions
114
+ - **Error handling** — Network errors, auth errors, and validation errors are normalized
115
+ - **Optional chaining** — \`actions.ENDPOINT?.start()\` is safe — returns undefined if the endpoint doesn't exist
116
+
117
+ ### Server-Side Usage
118
+
119
+ For server-side rendering (Next.js Server Components, server actions):
120
+
121
+ \`\`\`typescript
122
+ import { createServerApiActions } from 'nucleus-core-ts/client'
123
+
124
+ const serverActions = createServerApiActions({
125
+ baseUrl: process.env.API_URL,
126
+ getToken: () => cookies().get('access_token')?.value
127
+ })
128
+
129
+ const products = await serverActions.PRODUCTS_LIST.start({
130
+ query: { limit: 10 }
131
+ })
132
+ \`\`\`
133
+ `,
134
+ },
135
+ ],
136
+ },
137
+ {
138
+ id: 'proxy-module',
139
+ title: 'Proxy',
140
+ subItems: [
141
+ {
142
+ id: 'proxy-overview',
143
+ title: 'HTTP & WebSocket Proxy',
144
+ content: `
145
+ ## HTTP & WebSocket Proxy
146
+
147
+ The proxy module (\`nucleus-core-ts/proxy\`) provides a reverse proxy for Next.js applications that need to forward API requests to the Nucleus backend. It handles both HTTP and WebSocket proxying with automatic token refresh.
148
+
149
+ ### Why a Proxy?
150
+
151
+ In a typical Next.js setup, the frontend runs on \`localhost:3000\` and the API on \`localhost:9000\`. Browser cookies are domain-specific, and CORS can be tricky. The proxy solves this by:
152
+
153
+ 1. Running as Next.js middleware or API route
154
+ 2. Forwarding requests to the backend with cookies intact
155
+ 3. Handling token refresh transparently
156
+ 4. Proxying WebSocket connections for PubSub
157
+
158
+ ### HTTP Proxy
159
+
160
+ The HTTP proxy intercepts requests matching a pattern (e.g., \`/api/*\`) and forwards them to the backend:
161
+
162
+ \`\`\`
163
+ Browser → Next.js (/api/products) → Proxy → Nucleus Backend (/products)
164
+ \`\`\`
165
+
166
+ Features:
167
+ - **Cookie forwarding** — Auth cookies are passed through
168
+ - **Token refresh** — If the backend returns 401, the proxy calls \`/auth/refresh\`, gets new tokens, retries the request, and sets the new cookies on the response
169
+ - **Path rewriting** — Strips the \`/api\` prefix (configurable)
170
+ - **Header forwarding** — All headers are forwarded, including \`x-forwarded-for\`
171
+
172
+ ### WebSocket Proxy
173
+
174
+ For PubSub WebSocket connections:
175
+
176
+ \`\`\`
177
+ Browser (ws://localhost:3000/api/events) → Proxy → Backend (ws://localhost:9000/api/events/subscribe)
178
+ \`\`\`
179
+
180
+ The WS proxy handles:
181
+ - Connection upgrade
182
+ - Token injection in the upgrade request
183
+ - Bidirectional message forwarding
184
+ - Automatic reconnection on disconnect
185
+
186
+ ### Configuration
187
+
188
+ The proxy is typically configured in your Next.js \`next.config.ts\` rewrites or as middleware. The exact setup depends on your deployment architecture.
189
+ `,
190
+ },
191
+ ],
192
+ },
193
+ {
194
+ id: 'server-fetch',
195
+ title: 'ServerFetch',
196
+ subItems: [
197
+ {
198
+ id: 'server-fetch-overview',
199
+ title: 'Server-Side HTTP Client',
200
+ content: `
201
+ ## ServerFetch — Server-Side HTTP Client
202
+
203
+ The ServerFetch module provides a server-side HTTP client with retry logic and error handling. It's used internally by the proxy and can be used in your own server-side code.
204
+
205
+ ### Features
206
+
207
+ - **Automatic retry** — Failed requests are retried with exponential backoff
208
+ - **Token management** — Access tokens are injected and refreshed automatically
209
+ - **Timeout handling** — Configurable request timeouts
210
+ - **Error normalization** — Network errors, timeouts, and HTTP errors are normalized into a consistent format
211
+
212
+ ### Usage
213
+
214
+ \`\`\`typescript
215
+ import { serverFetch } from 'nucleus-core-ts/client'
216
+
217
+ const response = await serverFetch({
218
+ url: 'http://backend:9000/products',
219
+ method: 'GET',
220
+ headers: {
221
+ 'Authorization': 'Bearer ' + accessToken
222
+ },
223
+ retry: {
224
+ maxRetries: 3,
225
+ backoffMs: 1000
226
+ },
227
+ timeoutMs: 10000
228
+ })
229
+ \`\`\`
230
+ `,
231
+ },
232
+ ],
233
+ },
234
+ {
235
+ id: 'fe-components',
236
+ title: 'Frontend Components',
237
+ subItems: [
238
+ {
239
+ id: 'fe-components-overview',
240
+ title: 'Included React Components',
241
+ content: `
242
+ ## Frontend Components (\`nucleus-core-ts/fe\`)
243
+
244
+ Nucleus ships with 27 production-ready React component families that you can use in your frontend. These components use \`h-state\` for state management and are fully themed.
245
+
246
+ ### Component Families
247
+
248
+ | Component | Description |
249
+ |-----------|-------------|
250
+ | **LoginPage** | Complete login form with email/password, deviceHint, captcha support |
251
+ | **RegisterPage** | Registration form with password policy indicator, terms/privacy |
252
+ | **ProfilePage** | User profile editor with avatar, personal info |
253
+ | **DevicesPage** | Active sessions list, device approval, revoke sessions |
254
+ | **UsersPage** | Admin user management table with CRUD |
255
+ | **AuthorizationPage** | Role/claim management with assignment UI |
256
+ | **VerificationFlowPage** | Visual flow builder (drag-and-drop steps, edges) |
257
+ | **VerificationPanel** | Inline verification status and decision UI |
258
+ | **NotificationCenter** | Bell icon with dropdown, unseen count, mark as read |
259
+ | **DataTable** | Generic data table with sorting, filtering, pagination |
260
+ | **FormBuilder** | Dynamic form generator from entity column definitions |
261
+ | **PasswordResetPage** | Request + confirm password reset |
262
+ | **PasswordSetPage** | Set password for invited users |
263
+ | **MagicLinkPage** | Request magic link form |
264
+ | **CaptchaWidget** | Captcha challenge renderer (math, image, puzzle, text) |
265
+
266
+ ### Hooks
267
+
268
+ | Hook | Description |
269
+ |------|-------------|
270
+ | \`useApiActions()\` | API client with auto-generated endpoints |
271
+ | \`usePubSub()\` | WebSocket connection with h-state integration |
272
+ | \`useAuth()\` | Authentication state and actions |
273
+
274
+ ### Theming
275
+
276
+ All components respect the global theme (light/dark) and can be customized via CSS custom properties. Components use semantic HTML and are accessible.
277
+
278
+ ### Import
279
+
280
+ \`\`\`typescript
281
+ import { LoginPage, DataTable, useApiActions } from 'nucleus-core-ts/fe'
282
+ \`\`\`
283
+ `,
284
+ },
285
+ ],
286
+ },
287
+ ]