@lowdefy/server-dev 0.0.0-experimental-20260829143236 → 0.0.0-experimental-20260829185302

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.
@@ -188,6 +188,11 @@ function AuthConfigured({ authConfig, children, serverUser }) {
188
188
  // the page still holds the query the oauth-provider redirect arrived
189
189
  // with.
190
190
  oauth2Consent: (params) => authClient.oauth2.consent(params),
191
+ // POST /oauth2/continue - resumes the authorization after the post-login
192
+ // organization choice (the page runs SetActiveOrganization first). Same
193
+ // oauth_query contract as oauth2Consent: the signed query rides from
194
+ // window.location.search, so the call must run before any navigation.
195
+ oauth2Continue: (params) => authClient.oauth2.continue(params),
191
196
  phoneNumberRequestPasswordReset: (params) =>
192
197
  authClient.phoneNumber.requestPasswordReset(params),
193
198
  phoneNumberResetPassword: (params) => authClient.phoneNumber.resetPassword(params),
@@ -14,10 +14,17 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
+ import { ConfigError } from '@lowdefy/errors';
18
+
17
19
  function authNotConfigured() {
18
- throw new Error('Auth not configured.');
20
+ throw new ConfigError(
21
+ 'Auth is not configured. Add an "auth" section to lowdefy.yaml to use auth actions.'
22
+ );
19
23
  }
20
24
 
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.
21
28
  function AuthNotConfigured({ authConfig, children }) {
22
29
  const auth = {
23
30
  authConfig,
@@ -26,10 +33,17 @@ function AuthNotConfigured({ authConfig, children }) {
26
33
  addPasskey: authNotConfigured,
27
34
  changePassword: authNotConfigured,
28
35
  deletePasskey: authNotConfigured,
29
- updatePasskey: authNotConfigured,
30
36
  getResolvedUser: authNotConfigured,
31
37
  getSession: authNotConfigured,
32
38
  leaveOrganization: authNotConfigured,
39
+ listOrganizations: authNotConfigured,
40
+ oauth2Consent: authNotConfigured,
41
+ oauth2Continue: authNotConfigured,
42
+ phoneNumberRequestPasswordReset: authNotConfigured,
43
+ phoneNumberResetPassword: authNotConfigured,
44
+ phoneNumberSendOtp: authNotConfigured,
45
+ phoneNumberVerify: authNotConfigured,
46
+ refreshSession: authNotConfigured,
33
47
  requestPasswordReset: authNotConfigured,
34
48
  resetPassword: authNotConfigured,
35
49
  revokeOtherSessions: authNotConfigured,
@@ -38,14 +52,19 @@ function AuthNotConfigured({ authConfig, children }) {
38
52
  signInEmail: authNotConfigured,
39
53
  signInMagicLink: authNotConfigured,
40
54
  signInOauth2: authNotConfigured,
55
+ signInPasskey: authNotConfigured,
56
+ signInPhoneNumber: authNotConfigured,
41
57
  signInSocial: authNotConfigured,
42
58
  signOut: authNotConfigured,
43
59
  signUpEmail: authNotConfigured,
60
+ suppressSignOutReload: authNotConfigured,
44
61
  twoFactorDisable: authNotConfigured,
45
62
  twoFactorEnable: authNotConfigured,
46
63
  twoFactorGenerateBackupCodes: authNotConfigured,
47
64
  twoFactorVerifyBackupCode: authNotConfigured,
48
65
  twoFactorVerifyTotp: authNotConfigured,
66
+ updatePasskey: authNotConfigured,
67
+ updateResolvedUser: authNotConfigured,
49
68
  };
50
69
 
51
70
  return children(auth);
@@ -0,0 +1,61 @@
1
+ /*
2
+ Copyright 2020-2026 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
16
+
17
+ import { readFile } from 'node:fs/promises';
18
+ import path from 'node:path';
19
+ import { fileURLToPath } from 'node:url';
20
+
21
+ import AuthNotConfigured from './AuthNotConfigured.js';
22
+
23
+ const authDir = path.dirname(fileURLToPath(import.meta.url));
24
+
25
+ // The keys of the `const auth = { ... }` literal plus the `auth.x =` assignments
26
+ // made after it - both reach the app through the same context object.
27
+ function readExposedKeys(source) {
28
+ const literal = source.slice(source.indexOf('const auth = {'), source.indexOf('\n };'));
29
+ const keys = [...literal.matchAll(/^ {4}([a-zA-Z0-9_]+)[:,]/gm)].map((match) => match[1]);
30
+ const assigned = [...source.matchAll(/^ +auth\.([a-zA-Z0-9_]+) =/gm)].map((match) => match[1]);
31
+ return [...new Set([...keys, ...assigned])].sort();
32
+ }
33
+
34
+ function callAuthNotConfigured() {
35
+ let auth;
36
+ AuthNotConfigured({ authConfig: { enabled: false }, children: (value) => (auth = value) });
37
+ return auth;
38
+ }
39
+
40
+ // An app with no auth section still renders every block and action. A method
41
+ // AuthConfigured exposes but AuthNotConfigured omits surfaces as
42
+ // "auth.x is not a function" instead of the ConfigError naming the missing config.
43
+ test('AuthNotConfigured exposes every key AuthConfigured exposes', async () => {
44
+ const source = await readFile(path.join(authDir, 'AuthConfigured.jsx'), 'utf8');
45
+ const auth = callAuthNotConfigured();
46
+ expect(Object.keys(auth).sort()).toEqual(readExposedKeys(source));
47
+ });
48
+
49
+ test('AuthNotConfigured keeps authConfig and a null user', () => {
50
+ const auth = callAuthNotConfigured();
51
+ expect(auth.authConfig).toEqual({ enabled: false });
52
+ expect(auth.user).toBeNull();
53
+ });
54
+
55
+ test('AuthNotConfigured methods throw a ConfigError naming the missing auth config', () => {
56
+ const auth = callAuthNotConfigured();
57
+ expect(() => auth.signInEmail({})).toThrow(
58
+ 'Auth is not configured. Add an "auth" section to lowdefy.yaml to use auth actions.'
59
+ );
60
+ expect(() => auth.signInEmail({})).toThrow(expect.objectContaining({ name: 'ConfigError' }));
61
+ });
@@ -14,6 +14,8 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
+ import { serializer } from '@lowdefy/helpers';
18
+
17
19
  async function request({ url, method = 'GET', body }) {
18
20
  const res = await fetch(url, {
19
21
  method,
@@ -27,7 +29,12 @@ async function request({ url, method = 'GET', body }) {
27
29
  }
28
30
  if (!res.ok) {
29
31
  const body = await res.json();
30
- throw new Error(body?.['~e']?.message ?? body?.message ?? 'Request error');
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');
31
38
  }
32
39
  return res.json();
33
40
  }
@@ -13,6 +13,8 @@
13
13
 
14
14
  import useSWR from 'swr';
15
15
 
16
+ import { serializer } from '@lowdefy/helpers';
17
+
16
18
  import { getNavVersion, getReloadVersion } from './useMutateCache.js';
17
19
 
18
20
  // URLs whose config is server-resolved per request — learned from the fetched
@@ -71,6 +73,11 @@ export async function fetchPageConfig(url) {
71
73
  return data;
72
74
  }
73
75
  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
+ }
74
81
  throw new Error(data.message || 'Request error');
75
82
  }
76
83
 
@@ -15,7 +15,7 @@
15
15
  */
16
16
 
17
17
  import path from 'node:path';
18
- import { resolveConfigLocation } from '@lowdefy/errors';
18
+ import { ConfigError, resolveConfigLocation } from '@lowdefy/errors';
19
19
  import { type } from '@lowdefy/helpers';
20
20
 
21
21
  import buildPageIfNeeded from '../server/jitPageBuilder.js';
@@ -182,7 +182,7 @@ function scanKeyMapWithDeIndex({ id, keyMap, refMap, configDirectory, pageScope
182
182
  // "no matches" as a normal result and try another id or pageId.
183
183
  async function findConfig({ id, pageId }) {
184
184
  if (type.isNone(id) || !type.isString(id)) {
185
- throw new Error(
185
+ throw new ConfigError(
186
186
  `findConfig requires an "id" string. Received ${JSON.stringify(id)}. ` +
187
187
  'Use GET /lowdefy-docs/find/:id.'
188
188
  );
@@ -14,8 +14,9 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
- import { type } from '@lowdefy/helpers';
18
17
  import { callRequest } from '@lowdefy/api';
18
+ import { ConfigError } from '@lowdefy/errors';
19
+ import { type } from '@lowdefy/helpers';
19
20
 
20
21
  import isWriteRequestsAllowed from './isWriteRequestsAllowed.js';
21
22
  import readBuildArtifact from './readBuildArtifact.js';
@@ -58,10 +59,12 @@ function truncateResponse(result) {
58
59
  // returned as data so an agent can reason about them.
59
60
  async function runRequest({ pageId, requestId, payload = {}, honoContext }) {
60
61
  if (type.isUndefined(pageId) || !type.isString(pageId)) {
61
- throw new Error(`run_request requires a "pageId" string. Received ${JSON.stringify(pageId)}.`);
62
+ throw new ConfigError(
63
+ `run_request requires a "pageId" string. Received ${JSON.stringify(pageId)}.`
64
+ );
62
65
  }
63
66
  if (type.isUndefined(requestId) || !type.isString(requestId)) {
64
- throw new Error(
67
+ throw new ConfigError(
65
68
  `run_request requires a "requestId" string. Received ${JSON.stringify(requestId)}.`
66
69
  );
67
70
  }
@@ -14,6 +14,7 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
+ import { ConfigError } from '@lowdefy/errors';
17
18
  import { serializer } from '@lowdefy/helpers';
18
19
 
19
20
  import authJson from '../../build/auth.js';
@@ -30,7 +31,9 @@ function getMockUser() {
30
31
  try {
31
32
  mockUser = JSON.parse(mockUserJson);
32
33
  } catch (error) {
33
- throw new Error('Invalid JSON in LOWDEFY_DEV_USER environment variable.', { cause: error });
34
+ throw new ConfigError('Invalid JSON in LOWDEFY_DEV_USER environment variable.', {
35
+ cause: error,
36
+ });
34
37
  }
35
38
  } else {
36
39
  mockUser = authJson.dev?.mockUser;
@@ -44,7 +47,7 @@ function getMockUser() {
44
47
  mockUser = serializer.deserialize(mockUser);
45
48
 
46
49
  if (authJson.configured !== true) {
47
- throw new Error(
50
+ throw new ConfigError(
48
51
  'Mock user configured but auth is not configured in lowdefy.yaml. ' +
49
52
  'Add auth configuration to use mock user feature.'
50
53
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/server-dev",
3
- "version": "0.0.0-experimental-20260829143236",
3
+ "version": "0.0.0-experimental-20260829185302",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -45,39 +45,39 @@
45
45
  "@hono/mcp": "0.3.0",
46
46
  "@hono/node-server": "2.0.4",
47
47
  "@hono/vite-dev-server": "0.26.0",
48
- "@lowdefy/actions-core": "0.0.0-experimental-20260829143236",
49
- "@lowdefy/api": "0.0.0-experimental-20260829143236",
50
- "@lowdefy/block-utils": "0.0.0-experimental-20260829143236",
51
- "@lowdefy/blocks-aggrid": "0.0.0-experimental-20260829143236",
52
- "@lowdefy/blocks-antd": "0.0.0-experimental-20260829143236",
53
- "@lowdefy/blocks-antd-x": "0.0.0-experimental-20260829143236",
54
- "@lowdefy/blocks-basic": "0.0.0-experimental-20260829143236",
55
- "@lowdefy/blocks-captcha": "0.0.0-experimental-20260829143236",
56
- "@lowdefy/blocks-echarts": "0.0.0-experimental-20260829143236",
57
- "@lowdefy/blocks-loaders": "0.0.0-experimental-20260829143236",
58
- "@lowdefy/blocks-markdown": "0.0.0-experimental-20260829143236",
59
- "@lowdefy/blocks-tiptap": "0.0.0-experimental-20260829143236",
60
- "@lowdefy/build": "0.0.0-experimental-20260829143236",
61
- "@lowdefy/client": "0.0.0-experimental-20260829143236",
62
- "@lowdefy/connection-axios-http": "0.0.0-experimental-20260829143236",
63
- "@lowdefy/connection-mongodb": "0.0.0-experimental-20260829143236",
64
- "@lowdefy/docs-content": "0.0.0-experimental-20260829143236",
65
- "@lowdefy/engine": "0.0.0-experimental-20260829143236",
66
- "@lowdefy/errors": "0.0.0-experimental-20260829143236",
67
- "@lowdefy/helpers": "0.0.0-experimental-20260829143236",
68
- "@lowdefy/layout": "0.0.0-experimental-20260829143236",
69
- "@lowdefy/logger": "0.0.0-experimental-20260829143236",
70
- "@lowdefy/node-utils": "0.0.0-experimental-20260829143236",
71
- "@lowdefy/operators-change-case": "0.0.0-experimental-20260829143236",
72
- "@lowdefy/operators-dayjs": "0.0.0-experimental-20260829143236",
73
- "@lowdefy/operators-diff": "0.0.0-experimental-20260829143236",
74
- "@lowdefy/operators-js": "0.0.0-experimental-20260829143236",
75
- "@lowdefy/operators-mql": "0.0.0-experimental-20260829143236",
76
- "@lowdefy/operators-nunjucks": "0.0.0-experimental-20260829143236",
77
- "@lowdefy/operators-uuid": "0.0.0-experimental-20260829143236",
78
- "@lowdefy/operators-yaml": "0.0.0-experimental-20260829143236",
79
- "@lowdefy/plugin-better-auth": "0.0.0-experimental-20260829143236",
80
- "@lowdefy/websockets-core": "0.0.0-experimental-20260829143236",
48
+ "@lowdefy/actions-core": "0.0.0-experimental-20260829185302",
49
+ "@lowdefy/api": "0.0.0-experimental-20260829185302",
50
+ "@lowdefy/block-utils": "0.0.0-experimental-20260829185302",
51
+ "@lowdefy/blocks-aggrid": "0.0.0-experimental-20260829185302",
52
+ "@lowdefy/blocks-antd": "0.0.0-experimental-20260829185302",
53
+ "@lowdefy/blocks-antd-x": "0.0.0-experimental-20260829185302",
54
+ "@lowdefy/blocks-basic": "0.0.0-experimental-20260829185302",
55
+ "@lowdefy/blocks-captcha": "0.0.0-experimental-20260829185302",
56
+ "@lowdefy/blocks-echarts": "0.0.0-experimental-20260829185302",
57
+ "@lowdefy/blocks-loaders": "0.0.0-experimental-20260829185302",
58
+ "@lowdefy/blocks-markdown": "0.0.0-experimental-20260829185302",
59
+ "@lowdefy/blocks-tiptap": "0.0.0-experimental-20260829185302",
60
+ "@lowdefy/build": "0.0.0-experimental-20260829185302",
61
+ "@lowdefy/client": "0.0.0-experimental-20260829185302",
62
+ "@lowdefy/connection-axios-http": "0.0.0-experimental-20260829185302",
63
+ "@lowdefy/connection-mongodb": "0.0.0-experimental-20260829185302",
64
+ "@lowdefy/docs-content": "0.0.0-experimental-20260829185302",
65
+ "@lowdefy/engine": "0.0.0-experimental-20260829185302",
66
+ "@lowdefy/errors": "0.0.0-experimental-20260829185302",
67
+ "@lowdefy/helpers": "0.0.0-experimental-20260829185302",
68
+ "@lowdefy/layout": "0.0.0-experimental-20260829185302",
69
+ "@lowdefy/logger": "0.0.0-experimental-20260829185302",
70
+ "@lowdefy/node-utils": "0.0.0-experimental-20260829185302",
71
+ "@lowdefy/operators-change-case": "0.0.0-experimental-20260829185302",
72
+ "@lowdefy/operators-dayjs": "0.0.0-experimental-20260829185302",
73
+ "@lowdefy/operators-diff": "0.0.0-experimental-20260829185302",
74
+ "@lowdefy/operators-js": "0.0.0-experimental-20260829185302",
75
+ "@lowdefy/operators-mql": "0.0.0-experimental-20260829185302",
76
+ "@lowdefy/operators-nunjucks": "0.0.0-experimental-20260829185302",
77
+ "@lowdefy/operators-uuid": "0.0.0-experimental-20260829185302",
78
+ "@lowdefy/operators-yaml": "0.0.0-experimental-20260829185302",
79
+ "@lowdefy/plugin-better-auth": "0.0.0-experimental-20260829185302",
80
+ "@lowdefy/websockets-core": "0.0.0-experimental-20260829185302",
81
81
  "@modelcontextprotocol/sdk": "1.29.0",
82
82
  "@tailwindcss/postcss": "4.3.1",
83
83
  "@vitejs/plugin-react": "6.0.2",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/server-dev",
3
- "version": "0.0.0-experimental-20260829143236",
3
+ "version": "0.0.0-experimental-20260829185302",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -51,39 +51,39 @@
51
51
  "@hono/mcp": "0.3.0",
52
52
  "@hono/node-server": "2.0.4",
53
53
  "@hono/vite-dev-server": "0.26.0",
54
- "@lowdefy/actions-core": "0.0.0-experimental-20260829143236",
55
- "@lowdefy/api": "0.0.0-experimental-20260829143236",
56
- "@lowdefy/block-utils": "0.0.0-experimental-20260829143236",
57
- "@lowdefy/blocks-aggrid": "0.0.0-experimental-20260829143236",
58
- "@lowdefy/blocks-antd": "0.0.0-experimental-20260829143236",
59
- "@lowdefy/blocks-antd-x": "0.0.0-experimental-20260829143236",
60
- "@lowdefy/blocks-basic": "0.0.0-experimental-20260829143236",
61
- "@lowdefy/blocks-captcha": "0.0.0-experimental-20260829143236",
62
- "@lowdefy/blocks-echarts": "0.0.0-experimental-20260829143236",
63
- "@lowdefy/blocks-loaders": "0.0.0-experimental-20260829143236",
64
- "@lowdefy/blocks-markdown": "0.0.0-experimental-20260829143236",
65
- "@lowdefy/blocks-tiptap": "0.0.0-experimental-20260829143236",
66
- "@lowdefy/build": "0.0.0-experimental-20260829143236",
67
- "@lowdefy/client": "0.0.0-experimental-20260829143236",
68
- "@lowdefy/connection-axios-http": "0.0.0-experimental-20260829143236",
69
- "@lowdefy/connection-mongodb": "0.0.0-experimental-20260829143236",
70
- "@lowdefy/docs-content": "0.0.0-experimental-20260829143236",
71
- "@lowdefy/engine": "0.0.0-experimental-20260829143236",
72
- "@lowdefy/errors": "0.0.0-experimental-20260829143236",
73
- "@lowdefy/helpers": "0.0.0-experimental-20260829143236",
74
- "@lowdefy/layout": "0.0.0-experimental-20260829143236",
75
- "@lowdefy/logger": "0.0.0-experimental-20260829143236",
76
- "@lowdefy/node-utils": "0.0.0-experimental-20260829143236",
77
- "@lowdefy/operators-change-case": "0.0.0-experimental-20260829143236",
78
- "@lowdefy/operators-dayjs": "0.0.0-experimental-20260829143236",
79
- "@lowdefy/operators-diff": "0.0.0-experimental-20260829143236",
80
- "@lowdefy/operators-js": "0.0.0-experimental-20260829143236",
81
- "@lowdefy/operators-mql": "0.0.0-experimental-20260829143236",
82
- "@lowdefy/operators-nunjucks": "0.0.0-experimental-20260829143236",
83
- "@lowdefy/operators-uuid": "0.0.0-experimental-20260829143236",
84
- "@lowdefy/operators-yaml": "0.0.0-experimental-20260829143236",
85
- "@lowdefy/plugin-better-auth": "0.0.0-experimental-20260829143236",
86
- "@lowdefy/websockets-core": "0.0.0-experimental-20260829143236",
54
+ "@lowdefy/actions-core": "0.0.0-experimental-20260829185302",
55
+ "@lowdefy/api": "0.0.0-experimental-20260829185302",
56
+ "@lowdefy/block-utils": "0.0.0-experimental-20260829185302",
57
+ "@lowdefy/blocks-aggrid": "0.0.0-experimental-20260829185302",
58
+ "@lowdefy/blocks-antd": "0.0.0-experimental-20260829185302",
59
+ "@lowdefy/blocks-antd-x": "0.0.0-experimental-20260829185302",
60
+ "@lowdefy/blocks-basic": "0.0.0-experimental-20260829185302",
61
+ "@lowdefy/blocks-captcha": "0.0.0-experimental-20260829185302",
62
+ "@lowdefy/blocks-echarts": "0.0.0-experimental-20260829185302",
63
+ "@lowdefy/blocks-loaders": "0.0.0-experimental-20260829185302",
64
+ "@lowdefy/blocks-markdown": "0.0.0-experimental-20260829185302",
65
+ "@lowdefy/blocks-tiptap": "0.0.0-experimental-20260829185302",
66
+ "@lowdefy/build": "0.0.0-experimental-20260829185302",
67
+ "@lowdefy/client": "0.0.0-experimental-20260829185302",
68
+ "@lowdefy/connection-axios-http": "0.0.0-experimental-20260829185302",
69
+ "@lowdefy/connection-mongodb": "0.0.0-experimental-20260829185302",
70
+ "@lowdefy/docs-content": "0.0.0-experimental-20260829185302",
71
+ "@lowdefy/engine": "0.0.0-experimental-20260829185302",
72
+ "@lowdefy/errors": "0.0.0-experimental-20260829185302",
73
+ "@lowdefy/helpers": "0.0.0-experimental-20260829185302",
74
+ "@lowdefy/layout": "0.0.0-experimental-20260829185302",
75
+ "@lowdefy/logger": "0.0.0-experimental-20260829185302",
76
+ "@lowdefy/node-utils": "0.0.0-experimental-20260829185302",
77
+ "@lowdefy/operators-change-case": "0.0.0-experimental-20260829185302",
78
+ "@lowdefy/operators-dayjs": "0.0.0-experimental-20260829185302",
79
+ "@lowdefy/operators-diff": "0.0.0-experimental-20260829185302",
80
+ "@lowdefy/operators-js": "0.0.0-experimental-20260829185302",
81
+ "@lowdefy/operators-mql": "0.0.0-experimental-20260829185302",
82
+ "@lowdefy/operators-nunjucks": "0.0.0-experimental-20260829185302",
83
+ "@lowdefy/operators-uuid": "0.0.0-experimental-20260829185302",
84
+ "@lowdefy/operators-yaml": "0.0.0-experimental-20260829185302",
85
+ "@lowdefy/plugin-better-auth": "0.0.0-experimental-20260829185302",
86
+ "@lowdefy/websockets-core": "0.0.0-experimental-20260829185302",
87
87
  "@modelcontextprotocol/sdk": "1.29.0",
88
88
  "@tailwindcss/postcss": "4.3.1",
89
89
  "@vitejs/plugin-react": "6.0.2",
@@ -33,6 +33,16 @@ function createErrorHandler({ basePath = '', logger }) {
33
33
  }
34
34
  return c.text('Unauthorized', 401);
35
35
  }
36
+ // An authenticated caller whose roles do not permit the resource. Expected
37
+ // traffic, not a fault: one warning line, no structured error log and no
38
+ // Sentry capture.
39
+ if (error.name === 'AuthorizationError') {
40
+ logger.warn(`Forbidden: ${c.req.method} ${c.req.path}`);
41
+ if (path.startsWith('/api/')) {
42
+ return c.json({ name: error.name, message: error.message }, 403);
43
+ }
44
+ return c.text('Forbidden', 403);
45
+ }
36
46
  // An authorized caller who has not enrolled a second factor under
37
47
  // auth.twoFactor.required. 403, not 401 - a 401 reads to the client as a dead
38
48
  // session and bounces the user to sign-in, which is the loop the gate exists to
@@ -19,9 +19,9 @@ import { jest } from '@jest/globals';
19
19
 
20
20
  import createErrorHandler from './errorHandler.js';
21
21
 
22
- // This is the only test coverage of the hono 500 redaction path: the file here is
23
- // byte-identical to its `server` and `server-e2e` counterparts, and `server` has no
24
- // test script at all. Keep the three in sync when changing any of them.
22
+ // The handler here is byte-identical to its `server-e2e` counterpart (and to
23
+ // `server`'s apart from the Sentry capture, which `server` tests separately).
24
+ // Keep the three in sync when changing any of them.
25
25
 
26
26
  // A string that must never reach a client. It is put on `received` at every
27
27
  // level of the cause chain, so a single JSON.stringify search over the body
@@ -55,6 +55,13 @@ function createAuthenticationError(message) {
55
55
  return error;
56
56
  }
57
57
 
58
+ function createAuthorizationError(message) {
59
+ const error = new Error(message);
60
+ error.name = 'AuthorizationError';
61
+ error.received = SECRET;
62
+ return error;
63
+ }
64
+
58
65
  function createTwoFactorEnrolmentRequiredError(message) {
59
66
  const error = new Error(message);
60
67
  error.name = 'TwoFactorEnrolmentRequiredError';
@@ -112,6 +119,47 @@ test('errorHandler returns text Unauthorized at 401 for an AuthenticationError o
112
119
  expect(logger.warn).toHaveBeenCalledTimes(1);
113
120
  });
114
121
 
122
+ test('errorHandler returns 403 with only name and message for an AuthorizationError on an api path', async () => {
123
+ const logger = createLogger();
124
+ const context = { handleError: jest.fn() };
125
+ const res = await createApp({
126
+ context,
127
+ error: createAuthorizationError('Forbidden.'),
128
+ logger,
129
+ }).request('/api/request/getUsers');
130
+
131
+ expect(res.status).toEqual(403);
132
+ expect(await res.json()).toEqual({ name: 'AuthorizationError', message: 'Forbidden.' });
133
+ expect(logger.warn).toHaveBeenCalledTimes(1);
134
+ expect(logger.warn.mock.calls[0][0]).toMatch(/Forbidden: GET \/api\/request\/getUsers/);
135
+ expect(logger.error).not.toHaveBeenCalled();
136
+ expect(context.handleError).not.toHaveBeenCalled();
137
+ });
138
+
139
+ test('errorHandler does not send an AuthorizationError through the redactor', async () => {
140
+ const res = await createApp({
141
+ error: createAuthorizationError('Forbidden.'),
142
+ logger: createLogger(),
143
+ }).request('/api/request/getUsers');
144
+
145
+ const body = await res.json();
146
+ expect(body['~e']).toBeUndefined();
147
+ expect(JSON.stringify(body)).not.toContain(SECRET);
148
+ });
149
+
150
+ test('errorHandler returns text Forbidden at 403 for an AuthorizationError on a page path', async () => {
151
+ const logger = createLogger();
152
+ const res = await createApp({
153
+ error: createAuthorizationError('Forbidden.'),
154
+ logger,
155
+ }).request('/home');
156
+
157
+ expect(res.status).toEqual(403);
158
+ expect(await res.text()).toEqual('Forbidden');
159
+ expect(logger.warn).toHaveBeenCalledTimes(1);
160
+ expect(logger.error).not.toHaveBeenCalled();
161
+ });
162
+
115
163
  test('errorHandler returns 403 with only name and message for a TwoFactorEnrolmentRequiredError on an api path', async () => {
116
164
  const logger = createLogger();
117
165
  const context = { handleError: jest.fn() };
@@ -23,7 +23,9 @@ async function agentHandler(c) {
23
23
  const context = c.get('lowdefyContext');
24
24
  const t = (key, values) => translate({ key, values, i18n: context.i18n });
25
25
  if (c.req.method !== 'POST') {
26
- throw new Error(t('agent.runtime.methodNotAllowed'));
26
+ // A wrong-method request is client-caused: answer 405 rather than raising a
27
+ // fault that would be logged at error level and answered with a 500.
28
+ return c.json({ error: t('agent.runtime.methodNotAllowed') }, 405);
27
29
  }
28
30
  const segments = getPathSegments(c, '/api/agent/');
29
31
  if (segments.length < 2) {
@@ -20,7 +20,9 @@ import clientErrorStore from '../../lib/docs/clientErrorStore.js';
20
20
 
21
21
  async function clientErrorHandler(c) {
22
22
  if (c.req.method !== 'POST') {
23
- throw new Error('Only POST requests are supported.');
23
+ // A wrong-method request is client-caused: answer 405 rather than raising a
24
+ // fault that would be logged at error level and answered with a 500.
25
+ return c.json({ error: 'Method not allowed.' }, 405);
24
26
  }
25
27
  const context = c.get('lowdefyContext');
26
28
 
@@ -24,7 +24,9 @@ import getPathSegments from '../lib/getPathSegments.js';
24
24
  // expression in the `x-vercel-cron-schedule` header. Fails closed if CRON_SECRET is unset.
25
25
  async function cronHandler(c) {
26
26
  if (c.req.method !== 'GET') {
27
- throw new Error('Only GET requests are supported.');
27
+ // A wrong-method request is client-caused: answer 405 rather than raising a
28
+ // fault that would be logged at error level and answered with a 500.
29
+ return c.json({ error: 'Method not allowed.' }, 405);
28
30
  }
29
31
  const context = c.get('lowdefyContext');
30
32
 
@@ -29,7 +29,9 @@ import getPathSegments from '../lib/getPathSegments.js';
29
29
  // with no retry: targets must be idempotent.
30
30
  async function detachedHandler(c) {
31
31
  if (c.req.method !== 'POST') {
32
- throw new Error('Only POST requests are supported.');
32
+ // A wrong-method request is client-caused: answer 405 rather than raising a
33
+ // fault that would be logged at error level and answered with a 500.
34
+ return c.json({ error: 'Method not allowed.' }, 405);
33
35
  }
34
36
  const context = c.get('lowdefyContext');
35
37
 
@@ -76,7 +76,9 @@ async function devInspectHandler(c) {
76
76
  }
77
77
 
78
78
  if (c.req.method !== 'POST') {
79
- throw new Error('Only GET and POST requests are supported.');
79
+ // A wrong-method request is client-caused: answer 405 rather than raising a
80
+ // fault that would be logged at error level and answered with a 500.
81
+ return c.json({ error: 'Method not allowed.' }, 405);
80
82
  }
81
83
 
82
84
  if (!checkOrigin(c)) {
@@ -14,8 +14,13 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
+ import { ConfigError } from '@lowdefy/errors';
18
+
17
19
  import findConfig from '../../../lib/docs/findConfig.js';
18
20
 
21
+ // findConfig throws a ConfigError only for a missing or non-string id; every
22
+ // other failure is a fault and propagates to the error handler rather than
23
+ // being reported to the caller as bad input.
19
24
  async function docsFindHandler(c) {
20
25
  const id = c.req.param('id');
21
26
  const pageId = c.req.query('pageId');
@@ -23,7 +28,10 @@ async function docsFindHandler(c) {
23
28
  const result = await findConfig({ id, pageId });
24
29
  return c.json(result);
25
30
  } catch (error) {
26
- return c.json({ error: error.message }, 400);
31
+ if (error instanceof ConfigError) {
32
+ return c.json({ error: error.message }, 400);
33
+ }
34
+ throw error;
27
35
  }
28
36
  }
29
37
 
@@ -14,10 +14,13 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
+ import { ConfigError } from '@lowdefy/errors';
18
+
17
19
  import runRequest from '../../../lib/docs/runRequest.js';
18
20
 
19
21
  // Refusals and request errors are returned as 200 data (see runRequest.js) —
20
- // only malformed input (missing pageId/requestId) is a 400.
22
+ // only malformed input (missing pageId/requestId, thrown as a ConfigError) is a
23
+ // 400. Anything else is a fault and propagates to the error handler.
21
24
  async function docsRunRequestHandler(c) {
22
25
  // Parse the body from a clone: runRequest builds a Lowdefy context whose
23
26
  // resolveAuthentication reads c.req.raw (headers) to resolve the caller,
@@ -27,7 +30,10 @@ async function docsRunRequestHandler(c) {
27
30
  const result = await runRequest({ pageId, requestId, payload, honoContext: c });
28
31
  return c.json(result);
29
32
  } catch (error) {
30
- return c.json({ error: error.message }, 400);
33
+ if (error instanceof ConfigError) {
34
+ return c.json({ error: error.message }, 400);
35
+ }
36
+ throw error;
31
37
  }
32
38
  }
33
39
 
@@ -20,7 +20,9 @@ import getPathSegments from '../lib/getPathSegments.js';
20
20
 
21
21
  async function endpointsHandler(c) {
22
22
  if (c.req.method !== 'POST') {
23
- throw new Error('Only POST requests are supported.');
23
+ // A wrong-method request is client-caused: answer 405 rather than raising a
24
+ // fault that would be logged at error level and answered with a 500.
25
+ return c.json({ error: 'Method not allowed.' }, 405);
24
26
  }
25
27
  const context = c.get('lowdefyContext');
26
28
  const endpointId = getPathSegments(c, '/api/endpoints/').join('/');
@@ -23,7 +23,9 @@ import { getMock } from '../../lib/docs/devMockRegistry.js';
23
23
 
24
24
  async function requestHandler(c) {
25
25
  if (c.req.method !== 'POST') {
26
- throw new Error('Only POST requests are supported.');
26
+ // A wrong-method request is client-caused: answer 405 rather than raising a
27
+ // fault that would be logged at error level and answered with a 500.
28
+ return c.json({ error: 'Method not allowed.' }, 405);
27
29
  }
28
30
  const context = c.get('lowdefyContext');
29
31
  const segments = getPathSegments(c, '/api/request/');
@@ -115,10 +115,13 @@ test('requestHandler replays a dev mock without building or calling the request'
115
115
  expect(mockCallRequest).not.toHaveBeenCalled();
116
116
  });
117
117
 
118
- test('requestHandler rejects non-POST methods', async () => {
119
- const app = createApp();
120
- app.onError((err, c) => c.json({ error: err.message }, 500));
121
- const res = await app.request('/api/request/dashboard/get_rows');
122
- expect(res.status).toEqual(500);
118
+ // A GET to the request route is client-caused, so it must answer 405 rather
119
+ // than throwing into the error handler and being logged as a fault with a 500.
120
+ test('requestHandler returns 405 without building or calling the request for a non-POST method', async () => {
121
+ const res = await createApp().request('/api/request/dashboard/get_rows');
122
+
123
+ expect(res.status).toEqual(405);
124
+ expect(await res.json()).toEqual({ error: 'Method not allowed.' });
123
125
  expect(mockBuildPageIfNeeded).not.toHaveBeenCalled();
126
+ expect(mockCallRequest).not.toHaveBeenCalled();
124
127
  });
@@ -21,7 +21,9 @@ const packageJson = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'package
21
21
 
22
22
  async function usageHandler(c) {
23
23
  if (c.req.method !== 'POST') {
24
- throw new Error('Only POST requests are supported.');
24
+ // A wrong-method request is client-caused: answer 405 rather than raising a
25
+ // fault that would be logged at error level and answered with a 500.
26
+ return c.json({ error: 'Method not allowed.' }, 405);
25
27
  }
26
28
  const context = c.get('lowdefyContext');
27
29
  const { user, machine } = await c.req.json();