@lowdefy/server 7.0.0 → 7.2.0

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 (72) hide show
  1. package/client/clientBuildImports.test.mjs +1 -0
  2. package/client/getShownPage.test.mjs +1 -0
  3. package/client/shouldReloadForTypes.test.mjs +1 -0
  4. package/lib/build/mobileConfig.js +26 -0
  5. package/lib/client/auth/AuthConfigured.jsx +75 -48
  6. package/lib/client/auth/createFetchCheckingBuild.test.mjs +3 -3
  7. package/lib/client/auth/sessionCaller.js +56 -0
  8. package/lib/client/createLogUsage.test.mjs +2 -2
  9. package/lib/server/getClientAddress.test.mjs +6 -7
  10. package/lib/server/log/createHandleError.test.mjs +5 -5
  11. package/lib/server/log/createLogger.test.mjs +3 -3
  12. package/lib/server/log/projectErrorForLog.js +6 -4
  13. package/lib/server/log/redactUrlQuery.test.mjs +1 -0
  14. package/lib/server/log/serializeErrorForLog.test.mjs +50 -113
  15. package/lib/server/sentry/captureSentryError.test.mjs +4 -7
  16. package/lib/server/sentry/initSentry.serverless.test.mjs +6 -6
  17. package/lib/server/sentry/initSentry.test.mjs +3 -3
  18. package/lib/server/sentry/scrubEvent.test.mjs +2 -0
  19. package/lowdefy/build.mjs +5 -1
  20. package/lowdefy/build.test.mjs +31 -13
  21. package/lowdefy/createCustomPluginMessagesMap.mjs +2 -4
  22. package/lowdefy/createCustomPluginTypesMap.mjs +39 -11
  23. package/lowdefy/createCustomPluginTypesMap.test.mjs +249 -0
  24. package/package.json +31 -32
  25. package/package.original.json +31 -32
  26. package/src/app.js +19 -2
  27. package/src/app.mobile.test.mjs +351 -0
  28. package/src/app.test.mjs +31 -27
  29. package/src/html/collectPageTypesAssets.test.mjs +1 -0
  30. package/src/html/getPageAssets.test.mjs +1 -0
  31. package/src/html/renderPage.contentSecurityPolicy.test.mjs +13 -10
  32. package/src/html/renderPage.test.mjs +16 -13
  33. package/src/html/template.test.mjs +1 -0
  34. package/src/initServer.test.mjs +12 -12
  35. package/src/lib/getPathSegments.js +16 -1
  36. package/src/lib/getRequestSurface.js +25 -0
  37. package/src/middleware/apiContext.js +7 -4
  38. package/src/middleware/apiContext.test.mjs +48 -30
  39. package/src/middleware/createSameOriginGuard.test.mjs +1 -0
  40. package/src/middleware/errorHandler.js +33 -45
  41. package/src/middleware/errorHandler.test.mjs +11 -11
  42. package/src/middleware/refuseOtherBuild.test.mjs +3 -3
  43. package/src/middleware/stampBuildId.test.mjs +1 -0
  44. package/src/middleware/stampCaller.test.mjs +1 -0
  45. package/src/routes/agentBearer.test.mjs +175 -0
  46. package/src/routes/apiPage.js +12 -1
  47. package/src/routes/apiPage.test.mjs +5 -5
  48. package/src/routes/auth.test.mjs +6 -6
  49. package/src/routes/clientError.js +14 -2
  50. package/src/routes/clientError.test.mjs +106 -0
  51. package/src/routes/endpoints.js +24 -0
  52. package/src/routes/endpointsLink.test.mjs +112 -0
  53. package/src/routes/endpointsTextAnswer.test.mjs +8 -8
  54. package/src/routes/mcp.js +6 -0
  55. package/src/routes/mcp.test.mjs +23 -8
  56. package/src/routes/mcpMemberToken.test.mjs +8 -8
  57. package/src/routes/mcpProtectedResourceMetadata.test.mjs +2 -2
  58. package/src/routes/mobileRoot.js +30 -0
  59. package/src/routes/mobileSignIn.js +46 -0
  60. package/src/routes/mobileSignIn.test.mjs +58 -0
  61. package/src/routes/mobileSignInCallback.js +34 -0
  62. package/src/routes/mobileSignInCallback.test.mjs +51 -0
  63. package/src/routes/mountMobileWellKnown.js +35 -0
  64. package/src/routes/mountMobileWellKnown.test.mjs +79 -0
  65. package/src/routes/mountOauthDiscovery.test.mjs +5 -5
  66. package/src/routes/mountPageRoutes.js +9 -2
  67. package/src/routes/mountPageRoutes.test.mjs +33 -3
  68. package/src/routes/normalizeMcpProtocolVersionHeader.test.mjs +1 -0
  69. package/src/routes/requestBody.test.mjs +12 -12
  70. package/src/routes/websocket.js +4 -2
  71. package/src/routes/websocket.test.mjs +2 -2
  72. package/lib/server/log/maskCredentialKeys.js +0 -37
@@ -0,0 +1,58 @@
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 { vi, beforeEach, expect, test } from 'vitest';
18
+
19
+ const authJson = {};
20
+ const handleMobileSignIn = vi.fn(() => new Response('mobile sign-in'));
21
+
22
+ vi.doMock('@lowdefy/api', () => ({ handleMobileSignIn }));
23
+ vi.doMock('../../lib/build/auth.js', () => ({ default: authJson }));
24
+ vi.doMock('../../lib/build/config.js', () => ({ default: {} }));
25
+ vi.doMock('../../lib/build/theme.js', () => ({
26
+ default: { antd: { token: { colorPrimary: '#00aa55' } } },
27
+ }));
28
+ vi.doMock('../../lib/server/auth/getAuth.js', () => ({ default: () => null }));
29
+ const { default: mobileSignInHandler } = await import('./mobileSignIn.js');
30
+
31
+ function createContext() {
32
+ return {
33
+ get: () => ({ logger: {} }),
34
+ req: { raw: new Request('http://localhost/auth/mobile') },
35
+ };
36
+ }
37
+
38
+ beforeEach(() => {
39
+ delete authJson.mobile;
40
+ handleMobileSignIn.mockClear();
41
+ });
42
+
43
+ test('mobileSignInHandler falls through to the app pages when the app has no mobile section', async () => {
44
+ const next = vi.fn(() => 'page');
45
+ expect(await mobileSignInHandler(createContext(), next)).toEqual('page');
46
+ expect(handleMobileSignIn).not.toHaveBeenCalled();
47
+ });
48
+
49
+ test('mobileSignInHandler serves the mobile sign-in page when the app has a mobile section', async () => {
50
+ authJson.mobile = { shells: [] };
51
+ const next = vi.fn();
52
+ const res = await mobileSignInHandler(createContext(), next);
53
+ expect(await res.text()).toEqual('mobile sign-in');
54
+ expect(next).not.toHaveBeenCalled();
55
+ expect(handleMobileSignIn).toHaveBeenCalledWith(
56
+ expect.objectContaining({ basePath: '', primaryColor: '#00aa55' })
57
+ );
58
+ });
@@ -0,0 +1,34 @@
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 { handleMobileSignInCallback } from '@lowdefy/api';
18
+ import { type } from '@lowdefy/helpers';
19
+
20
+ import authJson from '../../lib/build/auth.js';
21
+ import themeConfig from '../../lib/build/theme.js';
22
+
23
+ // GET /auth/mobile/callback - the Android app link the sign-in sheet returns
24
+ // to. Android opens it in the shell; this page shows only when the link is not
25
+ // verified, and asks the person to return to the app. An app without a mobile
26
+ // section has no such page, so the path falls through to the app's own pages.
27
+ function mobileSignInCallbackHandler(c, next) {
28
+ if (type.isNone(authJson.mobile)) {
29
+ return next();
30
+ }
31
+ return handleMobileSignInCallback({ primaryColor: themeConfig.antd?.token?.colorPrimary });
32
+ }
33
+
34
+ export default mobileSignInCallbackHandler;
@@ -0,0 +1,51 @@
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 { vi, beforeEach, expect, test } from 'vitest';
18
+
19
+ const authJson = {};
20
+
21
+ vi.doMock('../../lib/build/auth.js', () => ({ default: authJson }));
22
+ vi.doMock('../../lib/build/theme.js', () => ({
23
+ default: { antd: { token: { colorPrimary: '#00aa55' } } },
24
+ }));
25
+ const { default: mobileSignInCallbackHandler } = await import('./mobileSignInCallback.js');
26
+
27
+ beforeEach(() => {
28
+ delete authJson.mobile;
29
+ });
30
+
31
+ test('mobileSignInCallbackHandler falls through to the app pages when the app has no mobile section', async () => {
32
+ const next = vi.fn(() => 'page');
33
+ expect(await mobileSignInCallbackHandler({}, next)).toEqual('page');
34
+ });
35
+
36
+ test('mobileSignInCallbackHandler asks the person to return to the app and never echoes the token', async () => {
37
+ authJson.mobile = { shells: [] };
38
+ const next = vi.fn();
39
+ const res = await mobileSignInCallbackHandler(
40
+ { req: { raw: new Request('http://localhost/auth/mobile/callback?token=ott-secret&state=s') } },
41
+ next
42
+ );
43
+ expect(next).not.toHaveBeenCalled();
44
+ expect(res.status).toEqual(200);
45
+ expect(res.headers.get('cache-control')).toEqual('no-store');
46
+ expect(res.headers.get('referrer-policy')).toEqual('no-referrer');
47
+ const html = await res.text();
48
+ expect(html).toContain('Return to the app');
49
+ expect(html).toContain('--primary: #00aa55;');
50
+ expect(html).not.toContain('ott-secret');
51
+ });
@@ -0,0 +1,35 @@
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 { createAppleAppSiteAssociation, createAssetLinks } from '@lowdefy/api';
18
+
19
+ // The universal link (iOS) and app link (Android) documents for the app's
20
+ // shells, from mobile.shells. Both are public, unauthenticated and constant per
21
+ // build, so they are built once and mount outside the api context, before the
22
+ // /.well-known/* catch-all. A document no shell needs is not mounted, so the
23
+ // catch-all answers 404 for it.
24
+ function mountMobileWellKnown({ app, basePath, mobileConfig }) {
25
+ const appleAppSiteAssociation = createAppleAppSiteAssociation({ mobileConfig, basePath });
26
+ if (appleAppSiteAssociation !== null) {
27
+ app.get('/.well-known/apple-app-site-association', (c) => c.json(appleAppSiteAssociation));
28
+ }
29
+ const assetLinks = createAssetLinks({ mobileConfig });
30
+ if (assetLinks !== null) {
31
+ app.get('/.well-known/assetlinks.json', (c) => c.json(assetLinks));
32
+ }
33
+ }
34
+
35
+ export default mountMobileWellKnown;
@@ -0,0 +1,79 @@
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 { expect, test } from 'vitest';
18
+ import { Hono } from 'hono';
19
+
20
+ import mountMobileWellKnown from './mountMobileWellKnown.js';
21
+ import wellKnownFallbackHandler from './wellKnownFallback.js';
22
+
23
+ function createApp({ mobileConfig, basePath = '' }) {
24
+ const app = new Hono();
25
+ mountMobileWellKnown({ app, basePath, mobileConfig });
26
+ app.all('/.well-known/*', wellKnownFallbackHandler);
27
+ return app;
28
+ }
29
+
30
+ test('mountMobileWellKnown serves both documents when shells take iOS and Android links', async () => {
31
+ const app = createApp({
32
+ mobileConfig: {
33
+ shells: [
34
+ { id: 'ios', ios: { bundleId: 'com.example.ios', teamId: 'TEAM1' } },
35
+ { id: 'droid', android: { package: 'com.example.droid', sha256: ['AA:BB'] } },
36
+ ],
37
+ },
38
+ basePath: '/app',
39
+ });
40
+ const aasa = await app.request('/.well-known/apple-app-site-association');
41
+ expect(aasa.status).toEqual(200);
42
+ const aasaBody = await aasa.json();
43
+ expect(aasaBody.applinks.details[0].appIDs).toEqual(['TEAM1.com.example.ios']);
44
+ expect(aasaBody.applinks.details[0].components).toEqual([
45
+ { '/': '/app/api/*', exclude: true },
46
+ { '/': '/app/*' },
47
+ ]);
48
+ const assetLinks = await app.request('/.well-known/assetlinks.json');
49
+ expect(assetLinks.status).toEqual(200);
50
+ const assetLinksBody = await assetLinks.json();
51
+ expect(assetLinksBody[0].target.package_name).toEqual('com.example.droid');
52
+ // The sign-in sheet's Android app link (/auth/mobile/callback) is verified by this relation.
53
+ expect(assetLinksBody[0].relation).toEqual(['delegate_permission/common.handle_all_urls']);
54
+ });
55
+
56
+ test('mountMobileWellKnown leaves both to the 404 catch-all for an app without shells', async () => {
57
+ const app = createApp({ mobileConfig: {} });
58
+ const aasa = await app.request('/.well-known/apple-app-site-association');
59
+ expect(aasa.status).toEqual(404);
60
+ expect((await aasa.json()).name).toEqual('NotFoundError');
61
+ const assetLinks = await app.request('/.well-known/assetlinks.json');
62
+ expect(assetLinks.status).toEqual(404);
63
+ });
64
+
65
+ test('mountMobileWellKnown serves only the document a shell needs', async () => {
66
+ const app = createApp({
67
+ mobileConfig: { shells: [{ id: 'ios', ios: { bundleId: 'com.example.ios', teamId: 'T' } }] },
68
+ });
69
+ expect((await app.request('/.well-known/apple-app-site-association')).status).toEqual(200);
70
+ expect((await app.request('/.well-known/assetlinks.json')).status).toEqual(404);
71
+ });
72
+
73
+ test('the catch-all still answers other well-known paths', async () => {
74
+ const app = createApp({
75
+ mobileConfig: { shells: [{ id: 'ios', ios: { bundleId: 'com.example.ios', teamId: 'T' } }] },
76
+ });
77
+ const res = await app.request('/.well-known/openid-configuration');
78
+ expect(res.status).toEqual(404);
79
+ });
@@ -15,25 +15,25 @@
15
15
  */
16
16
 
17
17
  import { Hono } from 'hono';
18
- import { jest } from '@jest/globals';
18
+ import { vi, beforeEach, expect, test } from 'vitest';
19
19
 
20
- const mockCreateAsMetadataHandler = jest.fn(
20
+ const mockCreateAsMetadataHandler = vi.fn(
21
21
  () => async () =>
22
22
  new Response(JSON.stringify({ issuer: 'https://app.test.com/api/auth' }), {
23
23
  status: 200,
24
24
  headers: { 'content-type': 'application/json' },
25
25
  })
26
26
  );
27
- jest.unstable_mockModule('@lowdefy/api', () => ({
27
+ vi.doMock('@lowdefy/api', () => ({
28
28
  createAsMetadataHandler: mockCreateAsMetadataHandler,
29
29
  }));
30
30
 
31
- jest.unstable_mockModule('./mcpProtectedResourceMetadata.js', () => ({
31
+ vi.doMock('./mcpProtectedResourceMetadata.js', () => ({
32
32
  default: (c) => c.json({ resource: 'mcp' }),
33
33
  }));
34
34
 
35
35
  const mockAuthJson = { configured: true };
36
- jest.unstable_mockModule('../../lib/build/auth.js', () => ({
36
+ vi.doMock('../../lib/build/auth.js', () => ({
37
37
  default: mockAuthJson,
38
38
  }));
39
39
 
@@ -15,14 +15,21 @@
15
15
  */
16
16
 
17
17
  import getRequestPath from '../lib/getRequestPath.js';
18
+ import mobileSignInCallbackHandler from './mobileSignInCallback.js';
19
+ import mobileSignInHandler from './mobileSignIn.js';
18
20
 
19
- // `/` (home) and `/404` are fixed routes ahead of the page matcher; every other
20
- // path renders the page it matches. `.*`, not `.+`: under a basePath,
21
+ // `/` (home), `/404`, `/auth/mobile` (the sign-in page a phone shell opens, and
22
+ // its confirmation post) and `/auth/mobile/callback` (its Android app link) are
23
+ // fixed routes ahead of the page matcher; every other path renders the page
24
+ // it matches. `.*`, not `.+`: under a basePath,
21
25
  // `<basePath>/` arrives with an empty rest, and is the app root like
22
26
  // `<basePath>` itself.
23
27
  function mountPageRoutes({ app, basePath, renderPage }) {
24
28
  app.get('/', (c) => renderPage(c, { path: '', matchedPath: '' }));
25
29
  app.get('/404', (c) => renderPage(c, { path: '404', matchedPath: '404', status: 404 }));
30
+ app.get('/auth/mobile', mobileSignInHandler);
31
+ app.post('/auth/mobile', mobileSignInHandler);
32
+ app.get('/auth/mobile/callback', mobileSignInCallbackHandler);
26
33
  app.get('/:rest{.*}', (c) => renderPage(c, getRequestPath({ c, basePath, prefix: '/' })));
27
34
  }
28
35
 
@@ -15,10 +15,18 @@
15
15
  */
16
16
 
17
17
  import { Hono } from 'hono';
18
+ import { vi, expect, test } from 'vitest';
18
19
 
19
- import mountPageRoutes from './mountPageRoutes.js';
20
+ vi.doMock('./mobileSignIn.js', () => ({
21
+ default: (c) => c.json({ mobileSignIn: c.req.query('shell'), method: c.req.method }),
22
+ }));
23
+ vi.doMock('./mobileSignInCallback.js', () => ({
24
+ default: (c) => c.json({ mobileSignInCallback: true }),
25
+ }));
20
26
 
21
- function request({ basePath, path }) {
27
+ const { default: mountPageRoutes } = await import('./mountPageRoutes.js');
28
+
29
+ function request({ basePath, path, method = 'GET' }) {
22
30
  const app = basePath === '' ? new Hono() : new Hono().basePath(basePath);
23
31
  mountPageRoutes({
24
32
  app,
@@ -26,7 +34,7 @@ function request({ basePath, path }) {
26
34
  renderPage: (c, { path: pagePath, matchedPath, status = 200 }) =>
27
35
  c.json({ path: pagePath, matchedPath }, status),
28
36
  });
29
- return app.request(path);
37
+ return app.request(path, { method });
30
38
  }
31
39
 
32
40
  test.each([
@@ -54,3 +62,25 @@ test.each([[''], ['/app']])(
54
62
  expect(await res.json()).toEqual({ path: '404', matchedPath: '404' });
55
63
  }
56
64
  );
65
+
66
+ test.each([[''], ['/app']])(
67
+ 'with basePath "%s", /auth/mobile is the mobile sign-in route, not a page',
68
+ async (basePath) => {
69
+ const res = await request({ basePath, path: `${basePath}/auth/mobile?shell=field&state=s` });
70
+ expect(await res.json()).toEqual({ mobileSignIn: 'field', method: 'GET' });
71
+ const posted = await request({
72
+ basePath,
73
+ path: `${basePath}/auth/mobile?shell=field&state=s`,
74
+ method: 'POST',
75
+ });
76
+ expect(await posted.json()).toEqual({ mobileSignIn: 'field', method: 'POST' });
77
+ }
78
+ );
79
+
80
+ test.each([[''], ['/app']])(
81
+ 'with basePath "%s", /auth/mobile/callback is the sign-in app link route, not a page',
82
+ async (basePath) => {
83
+ const res = await request({ basePath, path: `${basePath}/auth/mobile/callback?state=s` });
84
+ expect(await res.json()).toEqual({ mobileSignInCallback: true });
85
+ }
86
+ );
@@ -17,6 +17,7 @@
17
17
  import { Hono } from 'hono';
18
18
 
19
19
  import normalizeMcpProtocolVersionHeader from './normalizeMcpProtocolVersionHeader.js';
20
+ import { expect, test } from 'vitest';
20
21
 
21
22
  function createApp() {
22
23
  const app = new Hono();
@@ -15,23 +15,23 @@
15
15
  */
16
16
 
17
17
  import { Hono } from 'hono';
18
- import { jest } from '@jest/globals';
18
+ import { vi, afterAll, beforeAll, expect, test } from 'vitest';
19
19
 
20
20
  import { isSameOriginRequest, parseRequestBody } from '@lowdefy/api';
21
21
 
22
- const mockCallEndpoint = jest.fn();
23
- const mockGetEndpointConfig = jest.fn().mockRejectedValue(new Error('not found'));
24
- const mockRunWebhookEndpoint = jest.fn();
25
- jest.unstable_mockModule('@lowdefy/api', () => ({
26
- acceptDetachedEndpoint: jest.fn(),
27
- callAgent: jest.fn(),
22
+ const mockCallEndpoint = vi.fn();
23
+ const mockGetEndpointConfig = vi.fn().mockRejectedValue(new Error('not found'));
24
+ const mockRunWebhookEndpoint = vi.fn();
25
+ vi.doMock('@lowdefy/api', () => ({
26
+ acceptDetachedEndpoint: vi.fn(),
27
+ callAgent: vi.fn(),
28
28
  callEndpoint: mockCallEndpoint,
29
- callRequest: jest.fn(),
29
+ callRequest: vi.fn(),
30
30
  getEndpointConfig: mockGetEndpointConfig,
31
- logClientError: jest.fn(),
31
+ logClientError: vi.fn(),
32
32
  isSameOriginRequest,
33
33
  parseRequestBody,
34
- redactErrorResponse: jest.fn(),
34
+ redactErrorResponse: vi.fn(),
35
35
  runWebhookEndpoint: mockRunWebhookEndpoint,
36
36
  }));
37
37
 
@@ -45,12 +45,12 @@ const routes = {
45
45
  '/api/usage': (await import('./usage.js')).default,
46
46
  };
47
47
 
48
- const logger = { debug: jest.fn(), error: jest.fn(), info: jest.fn(), warn: jest.fn() };
48
+ const logger = { debug: vi.fn(), error: vi.fn(), info: vi.fn(), warn: vi.fn() };
49
49
 
50
50
  function createApp() {
51
51
  const app = new Hono();
52
52
  app.use('*', async (c, next) => {
53
- c.set('lowdefyContext', { logger, handleError: jest.fn() });
53
+ c.set('lowdefyContext', { logger, handleError: vi.fn() });
54
54
  await next();
55
55
  });
56
56
  Object.entries(routes).forEach(([path, handler]) => app.all(path, handler));
@@ -33,7 +33,8 @@ const upgrade = upgradeWebSocket((c) => {
33
33
  return {
34
34
  onOpen(event, ws) {
35
35
  // The upgrade's headers stay with the connection: its caller is resolved
36
- // from them again while the socket is open.
36
+ // from them again while the socket is open - a browser's session cookie,
37
+ // or a phone shell's "Authorization: Bearer" session, read the same way.
37
38
  connection = createWebSocketConnection(context, {
38
39
  closeSocket: ({ code, reason }) => ws.close(code, reason),
39
40
  headers: c.req.raw.headers,
@@ -57,7 +58,8 @@ const upgrade = upgradeWebSocket((c) => {
57
58
  });
58
59
 
59
60
  // Upgrades are accepted from the app's own pages and from clients that send no
60
- // Origin; isWebSocketOriginAllowed holds the rule and logs a refusal.
61
+ // Origin (a phone shell sends the app's own); isWebSocketOriginAllowed holds the
62
+ // rule and logs a refusal.
61
63
  function websocketHandler(c, next) {
62
64
  const context = c.get('lowdefyContext');
63
65
  if (!isWebSocketOriginAllowed({ context, getHeader: (name) => c.req.header(name) })) {
@@ -15,11 +15,11 @@
15
15
  */
16
16
 
17
17
  import { Hono } from 'hono';
18
- import { jest } from '@jest/globals';
18
+ import { vi, afterAll, beforeAll, expect, test } from 'vitest';
19
19
  import { serve } from '@hono/node-server';
20
20
  import WebSocket, { WebSocketServer } from 'ws';
21
21
 
22
- jest.unstable_mockModule('../../lib/server/auth/getStrategies.js', () => ({
22
+ vi.doMock('../../lib/server/auth/getStrategies.js', () => ({
23
23
  default: () => [],
24
24
  }));
25
25
 
@@ -1,37 +0,0 @@
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 { mapPlainValues } from '@lowdefy/helpers';
18
-
19
- // `received` is the one kept log field holding values fetched at runtime (a token
20
- // from an earlier step sent as a header), which the by-value secret scrub
21
- // cannot recognise, so credential-looking keys are masked by name instead.
22
- const credentialKeyParts = ['authorization', 'token', 'secret', 'password', 'apikey', 'cookie'];
23
-
24
- function isCredentialKey(key) {
25
- const normalized = key.toLowerCase().replace(/[-_]/g, '');
26
- return credentialKeyParts.some((part) => normalized.includes(part));
27
- }
28
-
29
- // Shared references and cycles are copied as such, so the serializer walk still
30
- // marks them '[Circular]'.
31
- function maskCredentialKeys(value) {
32
- return mapPlainValues(value, (item, key) =>
33
- key !== undefined && isCredentialKey(key) ? '[REDACTED]' : item
34
- );
35
- }
36
-
37
- export default maskCredentialKeys;