@lowdefy/server-dev 0.0.0-experimental-20260928062533 → 0.0.0-experimental-20260928105334

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 (258) hide show
  1. package/client/App.jsx +24 -35
  2. package/client/Page.jsx +9 -18
  3. package/client/clientBuildImports.test.mjs +0 -2
  4. package/lib/client/ErrorBar.jsx +13 -17
  5. package/lib/client/auth/Auth.jsx +6 -11
  6. package/lib/client/auth/AuthConfigured.jsx +36 -201
  7. package/lib/client/auth/AuthNotConfigured.js +4 -46
  8. package/lib/client/utils/request.js +1 -8
  9. package/lib/client/utils/usePageConfig.js +0 -22
  10. package/lib/client/utils/usePageConfig.test.mjs +2 -2
  11. package/lib/docs/clientErrorStore.js +1 -7
  12. package/lib/docs/createDocsMcpServer.js +397 -236
  13. package/lib/docs/createDocsMcpServer.test.mjs +2 -263
  14. package/lib/docs/docs.test.mjs +6 -124
  15. package/lib/docs/evalOperatorHeadless.js +1 -7
  16. package/lib/docs/findConfig.js +39 -84
  17. package/lib/docs/getBrowser.js +42 -92
  18. package/lib/docs/getBrowser.test.mjs +3 -186
  19. package/lib/docs/getBuildStatus.js +6 -35
  20. package/lib/docs/getCoreDoc.js +1 -9
  21. package/lib/docs/getOverview.js +10 -35
  22. package/lib/docs/getSchema.js +1 -5
  23. package/lib/docs/inspectStateHeadless.js +1 -7
  24. package/lib/docs/listPlugins.js +0 -15
  25. package/lib/docs/loadState.js +3 -15
  26. package/lib/docs/runRequest.js +43 -72
  27. package/lib/docs/screenshotPage.js +3 -23
  28. package/lib/docs/screenshotPage.test.mjs +0 -16
  29. package/lib/docs/setupTestFixtures.mjs +6 -82
  30. package/lib/server/auth/{getAuth.js → getAuthConfig.js} +9 -15
  31. package/lib/server/auth/getDevSession.js +70 -0
  32. package/lib/server/auth/getDevSession.test.mjs +138 -0
  33. package/lib/server/auth/getHeadlessUser.js +8 -7
  34. package/lib/server/auth/getMockUser.js +14 -18
  35. package/lib/server/auth/headlessUser.js +2 -3
  36. package/lib/server/auth/resolveHeadlessUser.test.mjs +4 -0
  37. package/lib/server/auth/{getStrategies.js → session.js} +16 -17
  38. package/lib/server/createLowdefyContext.js +41 -95
  39. package/lib/server/createLowdefyContext.test.mjs +5 -42
  40. package/lib/server/getPageJitEnrichment.test.mjs +11 -29
  41. package/lib/server/jitPageBuilder.js +29 -45
  42. package/lib/server/log/createHandleError.js +0 -26
  43. package/lib/server/log/createHandleError.test.mjs +2 -74
  44. package/lib/server/log/logRequest.js +3 -1
  45. package/manager/getContext.mjs +1 -19
  46. package/manager/processes/lowdefyBuild.mjs +7 -29
  47. package/manager/processes/lowdefyBuild.test.mjs +1 -136
  48. package/manager/processes/restartServer.mjs +6 -20
  49. package/manager/processes/shutdownServer.mjs +0 -8
  50. package/manager/processes/startProxy.mjs +12 -110
  51. package/manager/processes/startProxy.test.mjs +0 -207
  52. package/manager/processes/startServer.mjs +2 -17
  53. package/manager/processes/startWatchers.mjs +4 -6
  54. package/manager/processes/warnAuthUrlPortMismatch.mjs +47 -0
  55. package/manager/processes/warnAuthUrlPortMismatch.test.mjs +93 -0
  56. package/manager/run.mjs +34 -60
  57. package/manager/utils/BatchChanges.mjs +5 -21
  58. package/manager/utils/createCustomPluginMessagesMap.mjs +33 -23
  59. package/manager/utils/createCustomPluginTypesMap.mjs +30 -24
  60. package/manager/utils/setupWatcher.mjs +10 -5
  61. package/manager/utils/writeBuildStatus.mjs +1 -1
  62. package/manager/watchers/envWatcher.mjs +2 -9
  63. package/manager/watchers/lowdefyBuildWatcher.mjs +18 -85
  64. package/manager/watchers/moduleBuildWatcher.mjs +79 -0
  65. package/manager/watchers/serverArtifactWatcher.mjs +120 -0
  66. package/package.json +43 -48
  67. package/package.original.json +43 -48
  68. package/src/app.js +17 -74
  69. package/src/html/renderDevPage.js +1 -4
  70. package/src/middleware/errorHandler.js +1 -49
  71. package/src/middleware/errorHandler.test.mjs +3 -173
  72. package/src/routes/agent.js +3 -5
  73. package/src/routes/apiPage.js +37 -0
  74. package/src/routes/auth.js +20 -22
  75. package/src/routes/auth.test.mjs +84 -0
  76. package/src/routes/clientError.js +13 -11
  77. package/src/routes/cron.js +1 -3
  78. package/src/routes/cronForward.js +1 -3
  79. package/src/routes/detached.js +9 -19
  80. package/src/routes/devInspect.js +3 -6
  81. package/src/routes/docs/buildStatus.js +1 -9
  82. package/src/routes/docs/find.js +1 -9
  83. package/src/routes/docs/loadState.js +1 -3
  84. package/src/routes/docs/mcp.js +2 -28
  85. package/src/routes/docs/runRequest.js +8 -24
  86. package/src/routes/docs/screenshot.js +1 -37
  87. package/src/routes/docs/snapshotState.js +1 -3
  88. package/src/routes/endpoints.js +12 -24
  89. package/src/routes/feedback.js +13 -10
  90. package/src/routes/jitPage.js +2 -42
  91. package/src/routes/mcp.js +5 -71
  92. package/src/routes/request.js +4 -6
  93. package/src/routes/request.test.mjs +5 -9
  94. package/src/routes/usage.js +2 -6
  95. package/src/routes/websocket.js +8 -25
  96. package/src/websocket/devWebSocket.js +26 -36
  97. package/vite.config.js +23 -46
  98. package/lib/client/RedirectingPage.jsx +0 -56
  99. package/lib/client/auth/authNotConfiguredParity.test.mjs +0 -61
  100. package/lib/client/auth/authTemplateSync.test.mjs +0 -40
  101. package/lib/client/auth/betterAuthSessionContract.test.mjs +0 -181
  102. package/lib/client/utils/formatErrorsForCopy.js +0 -30
  103. package/lib/client/utils/formatErrorsForCopy.test.mjs +0 -39
  104. package/lib/client/utils/getErrorBarColor.js +0 -25
  105. package/lib/client/utils/getErrorBarColor.test.mjs +0 -34
  106. package/lib/docs/JourneyStepError.js +0 -30
  107. package/lib/docs/buildEditedPages.js +0 -50
  108. package/lib/docs/buildWaitHeader.js +0 -21
  109. package/lib/docs/clientErrorStore.test.mjs +0 -46
  110. package/lib/docs/createJourneyActors.js +0 -73
  111. package/lib/docs/devEventBus.js +0 -136
  112. package/lib/docs/devEventBus.test.mjs +0 -225
  113. package/lib/docs/devToolDefinitions.js +0 -423
  114. package/lib/docs/fitResponse.js +0 -81
  115. package/lib/docs/fitResponse.test.mjs +0 -128
  116. package/lib/docs/getBuildId.js +0 -61
  117. package/lib/docs/getBuildId.test.mjs +0 -84
  118. package/lib/docs/getBuildStatus.test.mjs +0 -66
  119. package/lib/docs/getBuildStatusAfterEdits.js +0 -35
  120. package/lib/docs/getBuildStatusAfterEdits.test.mjs +0 -76
  121. package/lib/docs/getHazards.js +0 -115
  122. package/lib/docs/getHazards.test.mjs +0 -175
  123. package/lib/docs/getMailOutboxDirectory.js +0 -26
  124. package/lib/docs/getOverviewBasePath.test.mjs +0 -36
  125. package/lib/docs/getPageBuildStatus.js +0 -46
  126. package/lib/docs/getStaleStatus.js +0 -36
  127. package/lib/docs/getStaleStatus.test.mjs +0 -74
  128. package/lib/docs/isPageReady.js +0 -63
  129. package/lib/docs/isPageReady.test.mjs +0 -160
  130. package/lib/docs/loadFrameworkHazards.js +0 -40
  131. package/lib/docs/loadFrameworkHazards.test.mjs +0 -43
  132. package/lib/docs/openJourneyEmail.js +0 -41
  133. package/lib/docs/openJourneyEmail.test.mjs +0 -187
  134. package/lib/docs/pageBuildStatus.test.mjs +0 -103
  135. package/lib/docs/readJourneyEmailMatch.js +0 -57
  136. package/lib/docs/readJourneyEmailMatch.test.mjs +0 -110
  137. package/lib/docs/readMailOutbox.js +0 -37
  138. package/lib/docs/readProxyBuildWait.js +0 -38
  139. package/lib/docs/requestRestart.js +0 -30
  140. package/lib/docs/requestRestart.test.mjs +0 -49
  141. package/lib/docs/reviewPage.js +0 -70
  142. package/lib/docs/reviewPageBuilds.js +0 -46
  143. package/lib/docs/reviewPageBuilds.test.mjs +0 -169
  144. package/lib/docs/runCheck.js +0 -75
  145. package/lib/docs/runCheck.test.mjs +0 -91
  146. package/lib/docs/runCheckChild.js +0 -49
  147. package/lib/docs/runEndpoint.js +0 -141
  148. package/lib/docs/runEndpoint.test.mjs +0 -414
  149. package/lib/docs/runJourney.js +0 -911
  150. package/lib/docs/runJourney.test.mjs +0 -1524
  151. package/lib/docs/runRequest.test.mjs +0 -185
  152. package/lib/docs/searchIcons.js +0 -90
  153. package/lib/docs/searchIcons.test.mjs +0 -127
  154. package/lib/docs/selectFinalState.js +0 -66
  155. package/lib/docs/selectFinalState.test.mjs +0 -51
  156. package/lib/docs/serverErrorStore.js +0 -43
  157. package/lib/docs/serverErrorStore.test.mjs +0 -50
  158. package/lib/docs/unsettledPageNote.js +0 -24
  159. package/lib/docs/validateJourneySteps.js +0 -412
  160. package/lib/docs/validateJourneySteps.test.mjs +0 -276
  161. package/lib/docs/validateJourneyTimeout.js +0 -38
  162. package/lib/docs/validateJourneyTimeout.test.mjs +0 -29
  163. package/lib/docs/validateStateSelection.js +0 -33
  164. package/lib/docs/validateStateSelection.test.mjs +0 -33
  165. package/lib/docs/validateViewport.js +0 -51
  166. package/lib/docs/validateViewport.test.mjs +0 -54
  167. package/lib/docs/waitForBuild.js +0 -47
  168. package/lib/docs/waitForBuild.test.mjs +0 -71
  169. package/lib/docs/waitForJourneyEmail.js +0 -77
  170. package/lib/server/auth/createSystemContext.js +0 -73
  171. package/lib/server/auth/journeyActor.js +0 -37
  172. package/lib/server/getClientAddress.js +0 -70
  173. package/lib/server/getClientAddress.test.mjs +0 -53
  174. package/lib/server/jitPageBuilder.test.mjs +0 -56
  175. package/lib/server/loadDynamicJsMap.js +0 -47
  176. package/lib/server/pageBuildRecords.js +0 -84
  177. package/lib/server/pageBuildRecords.test.mjs +0 -157
  178. package/lib/server/skipStaleMapWrites.js +0 -41
  179. package/lib/server/skipStaleMapWrites.test.mjs +0 -69
  180. package/lib/vite/createDevServerExclude.js +0 -40
  181. package/lib/vite/createDevServerExclude.test.mjs +0 -79
  182. package/manager/processes/shutdownServer.test.mjs +0 -45
  183. package/manager/processes/startMailSink.mjs +0 -135
  184. package/manager/processes/startMailSink.test.mjs +0 -146
  185. package/manager/processes/startServer.test.mjs +0 -62
  186. package/manager/processes/syncServer.mjs +0 -52
  187. package/manager/processes/syncServer.test.mjs +0 -84
  188. package/manager/utils/BatchChanges.test.mjs +0 -77
  189. package/manager/utils/acquireDevInstance.mjs +0 -99
  190. package/manager/utils/acquireDevInstance.test.mjs +0 -141
  191. package/manager/utils/createBuildActivity.mjs +0 -67
  192. package/manager/utils/createBuildActivity.test.mjs +0 -58
  193. package/manager/utils/createCustomPluginTypesMap.test.mjs +0 -94
  194. package/manager/utils/createDotPathIgnore.mjs +0 -44
  195. package/manager/utils/createDotPathIgnore.test.mjs +0 -52
  196. package/manager/utils/createServerArtifactTracker.mjs +0 -83
  197. package/manager/utils/createServerArtifactTracker.test.mjs +0 -78
  198. package/manager/utils/findBuildFilesOutsideWatch.mjs +0 -41
  199. package/manager/utils/findBuildFilesOutsideWatch.test.mjs +0 -77
  200. package/manager/utils/importFresh.mjs +0 -46
  201. package/manager/utils/importFresh.test.mjs +0 -72
  202. package/manager/utils/importFreshWorker.mjs +0 -20
  203. package/manager/utils/publishBuildDirectory.mjs +0 -102
  204. package/manager/utils/publishBuildDirectory.order.test.mjs +0 -56
  205. package/manager/utils/publishBuildDirectory.test.mjs +0 -201
  206. package/manager/utils/readBasePath.mjs +0 -27
  207. package/manager/utils/readBasePath.test.mjs +0 -43
  208. package/manager/utils/readBuildStatusWait.mjs +0 -67
  209. package/manager/utils/readPluginDefinitions.mjs +0 -36
  210. package/manager/utils/resolvePorts.mjs +0 -49
  211. package/manager/utils/waitForServer.mjs +0 -43
  212. package/manager/watchers/envWatcher.test.mjs +0 -87
  213. package/manager/watchers/listServerSidePackages.mjs +0 -47
  214. package/manager/watchers/listServerSidePackages.test.mjs +0 -38
  215. package/manager/watchers/lowdefyBuildWatcher.test.mjs +0 -197
  216. package/manager/watchers/pluginSourceWatcher.mjs +0 -75
  217. package/manager/watchers/pluginSourceWatcher.test.mjs +0 -129
  218. package/manager/watchers/restartRequestWatcher.mjs +0 -71
  219. package/manager/watchers/restartRequestWatcher.test.mjs +0 -102
  220. package/manager/watchers/selectLocalPluginPackages.mjs +0 -48
  221. package/manager/watchers/selectLocalPluginPackages.test.mjs +0 -73
  222. package/manager/watchers/serverPackageWatcher.mjs +0 -38
  223. package/src/middleware/createSameOriginGuard.js +0 -37
  224. package/src/middleware/createSameOriginGuard.test.mjs +0 -102
  225. package/src/middleware/isRebindingSafeHost.js +0 -44
  226. package/src/middleware/isRebindingSafeHost.test.mjs +0 -32
  227. package/src/middleware/localDevToolsOnly.js +0 -38
  228. package/src/middleware/localDevToolsOnly.test.mjs +0 -61
  229. package/src/middleware/staleFlag.js +0 -76
  230. package/src/middleware/staleFlag.test.mjs +0 -127
  231. package/src/routes/docs/events.js +0 -50
  232. package/src/routes/docs/events.test.mjs +0 -117
  233. package/src/routes/docs/icons.js +0 -30
  234. package/src/routes/docs/journey.js +0 -87
  235. package/src/routes/docs/journey.test.mjs +0 -195
  236. package/src/routes/docs/mcp.test.mjs +0 -130
  237. package/src/routes/docs/restart.js +0 -35
  238. package/src/routes/docs/restart.test.mjs +0 -64
  239. package/src/routes/docs/runEndpoint.js +0 -53
  240. package/src/routes/docs/runEndpoint.test.mjs +0 -155
  241. package/src/routes/docs/runRequest.test.mjs +0 -82
  242. package/src/routes/docs/screenshot.test.mjs +0 -117
  243. package/src/routes/jitPage.test.mjs +0 -107
  244. package/src/routes/mcp.test.mjs +0 -215
  245. package/src/routes/mcpProtectedResourceMetadata.js +0 -34
  246. package/src/routes/mcpProtectedResourceMetadata.test.mjs +0 -65
  247. package/src/routes/mountDevPageRoutes.js +0 -25
  248. package/src/routes/mountDevPageRoutes.test.mjs +0 -30
  249. package/src/routes/mountOauthDiscovery.js +0 -44
  250. package/src/routes/mountOauthDiscovery.test.mjs +0 -79
  251. package/src/routes/normalizeMcpProtocolVersionHeader.js +0 -46
  252. package/src/routes/normalizeMcpProtocolVersionHeader.test.mjs +0 -62
  253. package/src/routes/requestBody.test.mjs +0 -123
  254. package/src/routes/user.js +0 -27
  255. package/src/routes/websocket.test.mjs +0 -51
  256. package/src/routes/wellKnownFallback.js +0 -30
  257. package/src/routes/wellKnownFallback.test.mjs +0 -32
  258. package/src/websocket/devWebSocket.test.mjs +0 -127
package/client/App.jsx CHANGED
@@ -18,25 +18,19 @@ import React, { Suspense, useCallback, useEffect, useRef, useState } from 'react
18
18
  import useSWR from 'swr';
19
19
 
20
20
  import { ErrorBoundary } from '@lowdefy/block-utils';
21
- import { IconProvider, useDarkMode, useLocale } from '@lowdefy/client';
21
+ import { useDarkMode, useLocale } from '@lowdefy/client';
22
22
  import { StyleProvider } from '@ant-design/cssinjs';
23
23
  import { App as AntdApp, theme as antdTheme } from 'antd';
24
24
  import { XProvider } from '@ant-design/x';
25
- import { serializer } from '@lowdefy/helpers';
26
25
 
27
26
  import antdLocaleLoaders from '../build/i18n/antdLocales.js';
28
27
  import antdXLocaleLoaders from '../build/i18n/antdXLocales.js';
29
28
  import dayjsLocaleMap from '../build/i18n/dayjsLocales.js';
30
- import rawTheme from '../build/theme.json';
31
29
  import Auth from '../lib/client/auth/Auth.jsx';
32
30
  import ErrorBar from '../lib/client/ErrorBar.jsx';
33
31
  import request from '../lib/client/utils/request.js';
34
32
  import Routing from './Routing.jsx';
35
33
 
36
- // rootConfig arrives after the first render; the build-written theme gives
37
- // the icon provider its settings until then.
38
- const buildTheme = serializer.deserialize(rawTheme);
39
-
40
34
  function ThemeTokenResolver({ lowdefyRef, children }) {
41
35
  const { token } = antdTheme.useToken();
42
36
  if (!lowdefyRef.current.theme) {
@@ -46,7 +40,7 @@ function ThemeTokenResolver({ lowdefyRef, children }) {
46
40
  return children;
47
41
  }
48
42
 
49
- function App({ config, router }) {
43
+ function App({ router }) {
50
44
  const lowdefyRef = useRef({});
51
45
  const [runtimeErrors, setRuntimeErrors] = useState([]);
52
46
  // Subscribe to rootConfig SWR cache — deduplicates with Routing's fetch.
@@ -94,7 +88,6 @@ function App({ config, router }) {
94
88
  message: error.message,
95
89
  source: error.source,
96
90
  stack: error.stack,
97
- prodError: error.prodError === true,
98
91
  },
99
92
  ]);
100
93
  }, []);
@@ -137,33 +130,29 @@ function App({ config, router }) {
137
130
  algorithm,
138
131
  }}
139
132
  >
140
- {/* Message, Notification and ConfirmModal render in the App.useApp()
141
- holders here, above the Client's icon provider. */}
142
- <IconProvider icons={rootConfig?.theme.icons ?? buildTheme.icons}>
143
- <AntdApp>
144
- <ThemeTokenResolver lowdefyRef={lowdefyRef}>
145
- <ErrorBoundary fullPage onError={handleError}>
146
- <Suspense
147
- fallback={
148
- <div
149
- style={{
150
- minHeight: '100vh',
151
- background: 'var(--ant-color-bg-layout)',
152
- }}
153
- />
154
- }
155
- >
156
- <Auth user={config?.user}>
157
- {(auth) => {
158
- return <Routing auth={auth} lowdefy={lowdefyRef.current} router={router} />;
133
+ <AntdApp>
134
+ <ThemeTokenResolver lowdefyRef={lowdefyRef}>
135
+ <ErrorBoundary fullPage onError={handleError}>
136
+ <Suspense
137
+ fallback={
138
+ <div
139
+ style={{
140
+ minHeight: '100vh',
141
+ background: 'var(--ant-color-bg-layout)',
159
142
  }}
160
- </Auth>
161
- </Suspense>
162
- </ErrorBoundary>
163
- <ErrorBar errors={runtimeErrors} />
164
- </ThemeTokenResolver>
165
- </AntdApp>
166
- </IconProvider>
143
+ />
144
+ }
145
+ >
146
+ <Auth>
147
+ {(auth) => {
148
+ return <Routing auth={auth} lowdefy={lowdefyRef.current} router={router} />;
149
+ }}
150
+ </Auth>
151
+ </Suspense>
152
+ </ErrorBoundary>
153
+ <ErrorBar errors={runtimeErrors} />
154
+ </ThemeTokenResolver>
155
+ </AntdApp>
167
156
  </XProvider>
168
157
  </StyleProvider>
169
158
  );
package/client/Page.jsx CHANGED
@@ -15,11 +15,11 @@
15
15
  */
16
16
 
17
17
  import React, { useEffect, useRef } from 'react';
18
+ import { GenIcon } from 'react-icons/lib';
18
19
  import Client from '@lowdefy/client';
19
20
 
20
21
  import BuildErrorPage from '../lib/client/BuildErrorPage.jsx';
21
22
  import InstallingPluginsPage from '../lib/client/InstallingPluginsPage.jsx';
22
- import RedirectingPage from '../lib/client/RedirectingPage.jsx';
23
23
  import usePageConfig from '../lib/client/utils/usePageConfig.js';
24
24
 
25
25
  const Page = ({
@@ -46,22 +46,10 @@ const Page = ({
46
46
  }
47
47
  }, [pageConfig?._warnings, lowdefy]);
48
48
 
49
- // Full load to the sign-in page so it can return here after sign-in — an
50
- // effect, not a fetcher side effect, so the redirect re-fires if the same
51
- // cached result renders again.
52
- useEffect(() => {
53
- if (pageConfig?.authRedirect) {
54
- window.location.assign(pageConfig.authRedirect);
55
- }
56
- }, [pageConfig?.authRedirect]);
57
-
58
49
  if (!pageConfig) {
59
50
  router.replace({ pathname: '/404' });
60
51
  return '';
61
52
  }
62
- if (pageConfig.authRedirect) {
63
- return <RedirectingPage redirect={pageConfig.authRedirect} />;
64
- }
65
53
  if (pageConfig.buildError) {
66
54
  return (
67
55
  <BuildErrorPage
@@ -78,12 +66,15 @@ const Page = ({
78
66
  // Merge dynamic JS entries fetched after JIT build with the static jsMap
79
67
  const mergedJsMap = pageConfig._jsEntries ? { ...jsMap, ...pageConfig._jsEntries } : jsMap;
80
68
 
81
- // Merge JIT-delivered icon data into the static icons map. Icons are data
82
- // (IconData), and createIcon looks up Icons[name] on every render from the
83
- // captured reference, so mutating the original object makes them available
84
- // immediately.
69
+ // Merge JIT-discovered icon data into the static icons object.
70
+ // createIcon.js looks up Icons[name] on every render from the captured reference,
71
+ // so mutating the original object makes new icons available immediately.
85
72
  if (pageConfig._dynamicIcons) {
86
- Object.assign(types.icons, pageConfig._dynamicIcons);
73
+ for (const [name, data] of Object.entries(pageConfig._dynamicIcons)) {
74
+ if (!types.icons[name]) {
75
+ types.icons[name] = GenIcon(data);
76
+ }
77
+ }
87
78
  }
88
79
 
89
80
  return (
@@ -36,8 +36,6 @@ const allowed = new Set([
36
36
  'plugins/icons.js',
37
37
  'plugins/operators/client.js',
38
38
  'plugins/operators/clientJsMap.js',
39
- // The whole theme already reaches the browser in the root config.
40
- 'theme.json',
41
39
  ]);
42
40
 
43
41
  const root = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');
@@ -16,17 +16,15 @@
16
16
 
17
17
  import React, { useCallback, useState } from 'react';
18
18
 
19
- import formatErrorsForCopy from './utils/formatErrorsForCopy.js';
20
- import getErrorBarColor from './utils/getErrorBarColor.js';
21
-
22
19
  function getBarStyle(errors) {
20
+ const hasError = errors.some((e) => e.type !== 'ConfigWarning');
23
21
  return {
24
22
  position: 'fixed',
25
23
  bottom: 0,
26
24
  left: 0,
27
25
  right: 0,
28
26
  height: 28,
29
- backgroundColor: getErrorBarColor(errors),
27
+ backgroundColor: hasError ? '#cf1322' : '#d48806',
30
28
  color: '#fff',
31
29
  display: 'flex',
32
30
  alignItems: 'center',
@@ -40,6 +38,17 @@ function getBarStyle(errors) {
40
38
  };
41
39
  }
42
40
 
41
+ function formatErrorsForCopy(errors) {
42
+ return errors
43
+ .map((e) => {
44
+ let text = `[${e.type}] ${e.message}`;
45
+ if (e.source) text += `\n Source: ${e.source}`;
46
+ if (e.stack) text += `\n${e.stack}`;
47
+ return text;
48
+ })
49
+ .join('\n\n');
50
+ }
51
+
43
52
  function CopyIcon() {
44
53
  return (
45
54
  <svg
@@ -103,19 +112,6 @@ const ErrorBar = ({ errors }) => {
103
112
  }}
104
113
  >
105
114
  <span style={{ opacity: 0.8 }}>{latest.type}: </span>
106
- {latest.prodError === true && (
107
- <span
108
- style={{
109
- backgroundColor: 'rgba(255,255,255,0.25)',
110
- borderRadius: 8,
111
- padding: '1px 7px',
112
- fontSize: 11,
113
- marginRight: 6,
114
- }}
115
- >
116
- fails in prod
117
- </span>
118
- )}
119
115
  <span>{latest.message}</span>
120
116
  {latest.source && <span style={{ opacity: 0.7, marginLeft: 8 }}>{latest.source}</span>}
121
117
  </div>
@@ -14,6 +14,8 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
+ /* eslint-disable react/jsx-props-no-spreading */
18
+
17
19
  import React from 'react';
18
20
  import AuthConfigured from './AuthConfigured.jsx';
19
21
  import AuthNotConfigured from './AuthNotConfigured.js';
@@ -23,27 +25,20 @@ import { serializer } from '@lowdefy/helpers';
23
25
  // Client code imports the build JSON directly — Vite handles JSON imports;
24
26
  // the lib/build/*.js wrappers are server-only (they read from disk).
25
27
  // Deserialize to restore arrays from their ~arr build markers (providers
26
- // must be a real array for provider lookups in createAuthMethods).
28
+ // must be a real array for single-provider inference in createAuthMethods).
27
29
  import rawAuthConfig from '../../../build/auth.json';
28
30
 
29
31
  const authConfig = serializer.deserialize(rawAuthConfig);
30
32
 
31
- function Auth({ children, user }) {
33
+ function Auth({ children, session }) {
32
34
  if (authConfig.configured === true) {
33
35
  return (
34
- <AuthConfigured serverUser={user} authConfig={authConfig}>
36
+ <AuthConfigured serverSession={session} authConfig={authConfig}>
35
37
  {(auth) => children(auth)}
36
38
  </AuthConfigured>
37
39
  );
38
40
  }
39
- // An app whose only auth key is auth.dev has no auth stack, but the dev
40
- // server still resolves a caller for auth.dev.mockUser - pass it through so
41
- // _user reads the same identity in the browser as on the server.
42
- return (
43
- <AuthNotConfigured authConfig={authConfig} user={user}>
44
- {(auth) => children(auth)}
45
- </AuthNotConfigured>
46
- );
41
+ return <AuthNotConfigured authConfig={authConfig}>{(auth) => children(auth)}</AuthNotConfigured>;
47
42
  }
48
43
 
49
44
  export default Auth;
@@ -14,224 +14,59 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
- import React, { useEffect, useRef, useState } from 'react';
18
- import { createAuthClient } from 'better-auth/react';
19
- import {
20
- adminClient,
21
- emailOTPClient,
22
- magicLinkClient,
23
- organizationClient,
24
- phoneNumberClient,
25
- twoFactorClient,
26
- } from 'better-auth/client/plugins';
27
- import { oauthProviderClient } from '@better-auth/oauth-provider/client';
28
- import { passkeyClient } from '@better-auth/passkey/client';
17
+ /* eslint-disable react/jsx-props-no-spreading */
29
18
 
30
- import { normalizeCaller } from '@lowdefy/helpers';
19
+ import React, { useEffect, useRef } from 'react';
20
+ import {
21
+ authConfigManager,
22
+ getSession,
23
+ SessionProvider,
24
+ signIn,
25
+ signOut,
26
+ useSession,
27
+ } from '@hono/auth-js/react';
31
28
 
32
29
  // The app basePath, from Vite's BASE_URL (`${config.basePath}/`, set in
33
30
  // vite.config.js). build/config.json is server-only - it carries every
34
31
  // deployment environment's settings - so it is never imported into the client.
35
32
  const basePath = import.meta.env.BASE_URL.replace(/\/$/, '');
36
33
 
37
- // GenericOAuth providers have no client plugin here. BetterAuth 1.7.0 dropped
38
- // genericOAuthClient from better-auth/client/plugins, and nothing replaces it:
39
- // through 1.6.x it was a marker plugin carrying only an id, a version, an empty
40
- // $InferServerPlugin for TypeScript inference, and the generic-oauth error
41
- // codes - no actions, atoms, fetch plugins or path methods. signIn.oauth2 is
42
- // resolved by the client's dynamic path proxy from the call itself
43
- // (signIn.oauth2 -> POST /sign-in/oauth2, POST because providerId is always
44
- // sent), so the sign-in a Lowdefy GenericOAuth provider makes is unaffected.
45
- const authClient = createAuthClient({
46
- baseURL: `${window.location.origin}${basePath}/api/auth`,
47
- plugins: [
48
- adminClient(),
49
- emailOTPClient(),
50
- magicLinkClient(),
51
- oauthProviderClient(),
52
- organizationClient(),
53
- passkeyClient(),
54
- phoneNumberClient(),
55
- twoFactorClient(),
56
- ],
57
- });
58
-
59
- // UpdateSession owns session freshness - suppress BetterAuth's own
60
- // signal-driven refetch on the calls that would otherwise fire one, so
61
- // nothing competes with (and aborts) the refetch UpdateSession awaits.
62
- // Only calls that mutate an existing session are suppressed - calls that
63
- // can establish one (the sign-ins, and the two-factor, phone-number,
64
- // email-otp and passkey verifies) keep their signal: its refetch is what makes the store
65
- // notice a login when no navigation follows.
66
- // disableSignal silences all atomListeners for the call, including the
67
- // organization plugin's org atoms - none are exposed to app config, so a
68
- // future design exposing one must refresh it through its own action.
69
- const sessionScoped = (params) => ({
70
- ...params,
71
- fetchOptions: { ...params?.fetchOptions, disableSignal: true },
72
- });
34
+ // @hono/auth-js/react configures its fetch paths through a module-level
35
+ // manager instead of SessionProvider props.
36
+ if (basePath) {
37
+ authConfigManager.setConfig({ basePath: `${basePath}/api/auth` });
38
+ }
73
39
 
74
- // The server resolves the caller per request and embeds it in the page
75
- // config, so the first render never flashes unauthenticated. The BetterAuth
76
- // client store takes over once its session fetch settles.
77
- //
78
- // Roles and merged attributes resolve server-side from the active member row
79
- // - the base session carries neither. The last server-resolved caller is
80
- // held in state: while the session user is unchanged it stays authoritative
81
- // for the fields the session does not carry, and UpdateSession refreshes it
82
- // from /api/user after a change (e.g. SetActiveOrganization). Holding it in
83
- // state, not a ref, re-renders Session when it changes so _user recomputes -
84
- // the same reactive footing the session half already stands on.
85
- //
86
- // Only the session half is passed through normalizeCaller. BetterAuth's store
87
- // returns camelCase keys whatever the columns are named, so untransformed it
88
- // would sit emailVerified beside the resolved caller's email_verified on one
89
- // object; anything arriving from the server is already snake_case.
90
- function Session({ children, reloadSuppressedRef, serverUser }) {
91
- const { data: session, isPending } = authClient.useSession();
92
- const [resolvedUser, setResolvedUser] = useState(serverUser);
93
- const wasAuthenticated = useRef(Boolean(serverUser));
40
+ function Session({ children }) {
41
+ const wasAuthenticated = useRef(false);
42
+ const { data: session, status } = useSession();
43
+ wasAuthenticated.current = wasAuthenticated.current || status === 'authenticated';
94
44
 
95
45
  useEffect(() => {
96
- if (session) {
97
- wasAuthenticated.current = true;
98
- }
99
- // Reload after sign-out (or session revocation) so the server can apply
100
- // the page auth fork - a protected page redirects to the login page.
101
- // A logout with a callbackUrl suppresses the reload - its own navigation
102
- // would otherwise race this one.
103
- if (wasAuthenticated.current && !isPending && !session && !reloadSuppressedRef.current) {
46
+ if (wasAuthenticated.current && status === 'unauthenticated') {
104
47
  window.location.reload();
105
48
  }
106
- }, [session, isPending]);
49
+ }, [status]);
107
50
 
108
- if (isPending) {
109
- return children(resolvedUser, setResolvedUser);
110
- }
111
- if (!session?.user) {
112
- return children(null, setResolvedUser);
113
- }
114
- const resolved = resolvedUser;
115
- if (!resolved) {
116
- return children({ roles: [], ...normalizeCaller(session.user) }, setResolvedUser);
117
- }
118
- if (resolved.id !== session.user.id) {
119
- // The ref has not caught up with a changed session user - a sign-in as a
120
- // different person lands between the session refetch and the /api/user
121
- // result. Render the last resolved caller whole rather than mixing the new
122
- // session user with the previous person's resolved fields, or falling back
123
- // to a caller with no roles - blocks re-evaluate operators on render, so a
124
- // role-guarded page would act on an empty role list. UpdateSession closes
125
- // the window when it lands the new caller; a flow that changes the session
126
- // user without chaining it leaves the previous caller rendered until the
127
- // next page load.
128
- return children(resolved, setResolvedUser);
51
+ // If session is passed to SessionProvider from the server-rendered config
52
+ // we won't have a loading state here, but unauthenticated first loads do.
53
+ if (status === 'loading') {
54
+ return '';
129
55
  }
130
- // _user is one object with one meaning on both sides: the resolved caller is
131
- // spread whole, so every field resolveAuthentication emits is readable in app
132
- // config without this file naming it. session.user is the floor - the client
133
- // store may hold a fresher one than the resolved state, and the resolved
134
- // object wins wherever both carry a key.
135
- const user = { ...normalizeCaller(session.user), ...resolved };
136
- return children(user, setResolvedUser);
56
+ return children(session);
137
57
  }
138
58
 
139
- function AuthConfigured({ authConfig, children, serverUser }) {
140
- const reloadSuppressedRef = useRef(false);
141
- const auth = {
142
- authConfig,
143
- getSession: ({ disableCookieCache } = {}) =>
144
- authClient.getSession(disableCookieCache ? { query: { disableCookieCache: true } } : {}),
145
- // Refetches the session through the session atom - the store's only
146
- // writer - and resolves only after the store is written. fetchSession
147
- // returns undefined and never rejects (failures are written into the
148
- // atom), so the atom's own { data, error } is read back and returned,
149
- // keeping unwrap working and surfacing a failed refresh to the action.
150
- refreshSession: async ({ disableCookieCache } = {}) => {
151
- const sessionAtom = authClient.$store.atoms.session;
152
- await sessionAtom
153
- .get()
154
- .refetch(disableCookieCache ? { query: { disableCookieCache: true } } : undefined);
155
- const { data, error } = sessionAtom.get();
156
- return { data, error };
157
- },
158
- // The server-resolved caller - roles from the active member row and the
159
- // merged attributes bag - for re-syncing after session changes.
160
- getResolvedUser: async () => {
161
- const response = await fetch(`${basePath}/api/user`, {
162
- credentials: 'same-origin',
163
- });
164
- if (!response.ok) {
165
- // /api/user itself always answers 200 { user } - user: null when no
166
- // caller is admitted, which updateSession branches on. A non-OK
167
- // response is a transport failure (gateway error page, 5xx) with no
168
- // parsable body.
169
- throw new Error(`Failed to fetch the resolved user (HTTP ${response.status}).`);
170
- }
171
- return response.json();
172
- },
173
- suppressSignOutReload: () => {
174
- reloadSuppressedRef.current = true;
175
- },
176
- acceptInvitation: (params) => authClient.organization.acceptInvitation(sessionScoped(params)),
177
- // addPasskey runs the WebAuthn browser ceremony itself - options fetch,
178
- // authenticator prompt, verification.
179
- addPasskey: (params) => authClient.passkey.addPasskey(params),
180
- changePassword: (params) => authClient.changePassword(sessionScoped(params)),
181
- deletePasskey: (params) => authClient.passkey.deletePasskey(params),
182
- updatePasskey: (params) => authClient.passkey.updatePasskey(params),
183
- leaveOrganization: (params) => authClient.organization.leave(sessionScoped(params)),
184
- // The caller's memberships from the org plugin, keyed on the session
185
- // alone - not the active organization. sessionScoped so the list read
186
- // does not also fire the org-list atom's own refetch of the same route.
187
- listOrganizations: () => authClient.organization.list(sessionScoped()),
188
- // POST /oauth2/consent. The signed authorization query is not passed
189
- // here - the oauthProviderClient fetch plugin stamps it onto the body as
190
- // oauth_query from window.location.search, so the call must run while
191
- // the page still holds the query the oauth-provider redirect arrived
192
- // with.
193
- oauth2Consent: (params) => authClient.oauth2.consent(params),
194
- // POST /oauth2/continue - resumes the authorization after the post-login
195
- // organization choice (the page runs SetActiveOrganization first). Same
196
- // oauth_query contract as oauth2Consent: the signed query rides from
197
- // window.location.search, so the call must run before any navigation.
198
- oauth2Continue: (params) => authClient.oauth2.continue(params),
199
- // The one-time email code: send, then sign in with it.
200
- emailOtpSend: (params) => authClient.emailOtp.sendVerificationOtp(params),
201
- emailOtpVerify: (params) => authClient.signIn.emailOtp(params),
202
- phoneNumberRequestPasswordReset: (params) =>
203
- authClient.phoneNumber.requestPasswordReset(params),
204
- phoneNumberResetPassword: (params) => authClient.phoneNumber.resetPassword(params),
205
- phoneNumberSendOtp: (params) => authClient.phoneNumber.sendOtp(params),
206
- phoneNumberVerify: (params) => authClient.phoneNumber.verify(params),
207
- requestPasswordReset: (params) => authClient.requestPasswordReset(params),
208
- resetPassword: (params) => authClient.resetPassword(params),
209
- revokeOtherSessions: () => authClient.revokeOtherSessions(sessionScoped()),
210
- sendVerificationEmail: (params) => authClient.sendVerificationEmail(params),
211
- setActiveOrganization: (params) => authClient.organization.setActive(sessionScoped(params)),
212
- signInEmail: (params) => authClient.signIn.email(params),
213
- signInMagicLink: (params) => authClient.signIn.magicLink(params),
214
- signInOauth2: (params) => authClient.signIn.oauth2(params),
215
- signInPasskey: (params) => authClient.signIn.passkey(params),
216
- signInPhoneNumber: (params) => authClient.signIn.phoneNumber(params),
217
- signInSocial: (params) => authClient.signIn.social(params),
218
- signOut: () => authClient.signOut(),
219
- signUpEmail: (params) => authClient.signUp.email(params),
220
- twoFactorDisable: (params) => authClient.twoFactor.disable(sessionScoped(params)),
221
- twoFactorEnable: (params) => authClient.twoFactor.enable(sessionScoped(params)),
222
- twoFactorGenerateBackupCodes: (params) =>
223
- authClient.twoFactor.generateBackupCodes(sessionScoped(params)),
224
- twoFactorVerifyBackupCode: (params) => authClient.twoFactor.verifyBackupCode(params),
225
- twoFactorVerifyTotp: (params) => authClient.twoFactor.verifyTotp(params),
226
- };
59
+ function AuthConfigured({ authConfig, children, serverSession }) {
60
+ const auth = { authConfig, getSession, signIn, signOut };
227
61
  return (
228
- <Session reloadSuppressedRef={reloadSuppressedRef} serverUser={serverUser}>
229
- {(user, setResolvedUser) => {
230
- auth.user = user;
231
- auth.updateResolvedUser = (resolved) => setResolvedUser(resolved);
232
- return children(auth);
233
- }}
234
- </Session>
62
+ <SessionProvider session={serverSession}>
63
+ <Session>
64
+ {(session) => {
65
+ auth.session = session;
66
+ return children(auth);
67
+ }}
68
+ </Session>
69
+ </SessionProvider>
235
70
  );
236
71
  }
237
72
 
@@ -13,60 +13,18 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */
16
-
17
- import { ConfigError } from '@lowdefy/errors';
16
+ /* eslint-disable react/jsx-props-no-spreading */
18
17
 
19
18
  function authNotConfigured() {
20
- throw new ConfigError(
21
- 'Auth is not configured. Add an "auth" section to lowdefy.yaml to use auth actions.'
22
- );
19
+ throw new Error('Auth not configured.');
23
20
  }
24
21
 
25
- // Every key AuthConfigured exposes must be present here, or an auth action in an
26
- // app without an auth section fails with "auth.x is not a function" instead of
27
- // the ConfigError that names the missing config.
28
- function AuthNotConfigured({ authConfig, children, user = null }) {
22
+ function AuthNotConfigured({ authConfig, children }) {
29
23
  const auth = {
30
24
  authConfig,
31
- user,
32
- acceptInvitation: authNotConfigured,
33
- addPasskey: authNotConfigured,
34
- changePassword: authNotConfigured,
35
- deletePasskey: authNotConfigured,
36
- getResolvedUser: authNotConfigured,
37
25
  getSession: authNotConfigured,
38
- leaveOrganization: authNotConfigured,
39
- listOrganizations: authNotConfigured,
40
- oauth2Consent: authNotConfigured,
41
- oauth2Continue: authNotConfigured,
42
- emailOtpSend: authNotConfigured,
43
- emailOtpVerify: authNotConfigured,
44
- phoneNumberRequestPasswordReset: authNotConfigured,
45
- phoneNumberResetPassword: authNotConfigured,
46
- phoneNumberSendOtp: authNotConfigured,
47
- phoneNumberVerify: authNotConfigured,
48
- refreshSession: authNotConfigured,
49
- requestPasswordReset: authNotConfigured,
50
- resetPassword: authNotConfigured,
51
- revokeOtherSessions: authNotConfigured,
52
- sendVerificationEmail: authNotConfigured,
53
- setActiveOrganization: authNotConfigured,
54
- signInEmail: authNotConfigured,
55
- signInMagicLink: authNotConfigured,
56
- signInOauth2: authNotConfigured,
57
- signInPasskey: authNotConfigured,
58
- signInPhoneNumber: authNotConfigured,
59
- signInSocial: authNotConfigured,
26
+ signIn: authNotConfigured,
60
27
  signOut: authNotConfigured,
61
- signUpEmail: authNotConfigured,
62
- suppressSignOutReload: authNotConfigured,
63
- twoFactorDisable: authNotConfigured,
64
- twoFactorEnable: authNotConfigured,
65
- twoFactorGenerateBackupCodes: authNotConfigured,
66
- twoFactorVerifyBackupCode: authNotConfigured,
67
- twoFactorVerifyTotp: authNotConfigured,
68
- updatePasskey: authNotConfigured,
69
- updateResolvedUser: authNotConfigured,
70
28
  };
71
29
 
72
30
  return children(auth);
@@ -14,8 +14,6 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
- import { serializer } from '@lowdefy/helpers';
18
-
19
17
  async function request({ url, method = 'GET', body }) {
20
18
  const res = await fetch(url, {
21
19
  method,
@@ -29,12 +27,7 @@ async function request({ url, method = 'GET', body }) {
29
27
  }
30
28
  if (!res.ok) {
31
29
  const body = await res.json();
32
- // A Lowdefy error envelope is revived rather than flattened to its message,
33
- // so the class, configKey and source survive to the error handler.
34
- if (body?.['~e']) {
35
- throw serializer.deserialize(body);
36
- }
37
- throw new Error(body?.message ?? 'Request error');
30
+ throw new Error(body?.['~e']?.message ?? body?.message ?? 'Request error');
38
31
  }
39
32
  return res.json();
40
33
  }
@@ -13,8 +13,6 @@
13
13
 
14
14
  import useSWR from 'swr';
15
15
 
16
- import { serializer } from '@lowdefy/helpers';
17
-
18
16
  import { getNavVersion, getReloadVersion } from './useMutateCache.js';
19
17
 
20
18
  // URLs whose config is server-resolved per request — learned from the fetched
@@ -30,7 +28,6 @@ function parseJsModule(text) {
30
28
  }
31
29
 
32
30
  export async function fetchPageConfig(url) {
33
- const basePath = url.replace(/\/api\/page\/.*$/, '');
34
31
  // A stalled request (server restart mid-request, exhausted sockets) must
35
32
  // become a visible error, never an eternal Suspense fallback — the reload
36
33
  // recovery path cannot fire while the page tree is suspended.
@@ -51,20 +48,6 @@ export async function fetchPageConfig(url) {
51
48
  if (res.status === 404) {
52
49
  return null;
53
50
  }
54
- if (res.status === 401 || res.status === 403) {
55
- // 401: logged-out navigation to a protected page. 403: authorised but second
56
- // factor not yet enrolled. Page renders a redirect screen and full-loads to
57
- // the destination so it can return here afterwards. Returning a settled value
58
- // (never a parked promise) keeps the SWR key healthy: if the navigation is
59
- // dropped, the tab still recovers on the next reload event or via the manual
60
- // link on the redirect screen.
61
- const { redirect } = await res.json();
62
- const authRedirect = redirect ?? `${basePath}/404`;
63
- console.warn(
64
- `Lowdefy dev: "${url}" returned ${res.status} - redirecting to "${authRedirect}".`
65
- );
66
- return { authRedirect };
67
- }
68
51
  const data = await res.json();
69
52
  if (data?.buildError) {
70
53
  return data;
@@ -73,11 +56,6 @@ export async function fetchPageConfig(url) {
73
56
  return data;
74
57
  }
75
58
  if (!res.ok) {
76
- // A Lowdefy error envelope is revived rather than flattened to its message,
77
- // so the class, configKey and source survive to the error handler.
78
- if (data?.['~e']) {
79
- throw serializer.deserialize(data);
80
- }
81
59
  throw new Error(data.message || 'Request error');
82
60
  }
83
61