@lowdefy/server 7.2.0 → 7.3.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.
- package/package.json +28 -28
- package/package.original.json +28 -28
- package/src/app.timeout.test.mjs +141 -0
- package/src/middleware/requestTimeout.js +7 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowdefy/server",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.3.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
@@ -43,32 +43,32 @@
|
|
|
43
43
|
"@better-auth/oauth-provider": "1.7.7",
|
|
44
44
|
"@better-auth/passkey": "1.7.7",
|
|
45
45
|
"@hono/mcp": "0.3.2",
|
|
46
|
-
"@hono/node-server": "2.
|
|
47
|
-
"@lowdefy/actions-core": "7.
|
|
48
|
-
"@lowdefy/api": "7.
|
|
49
|
-
"@lowdefy/block-utils": "7.
|
|
50
|
-
"@lowdefy/blocks-aggrid": "7.
|
|
51
|
-
"@lowdefy/blocks-antd": "7.
|
|
52
|
-
"@lowdefy/blocks-antd-x": "7.
|
|
53
|
-
"@lowdefy/blocks-basic": "7.
|
|
54
|
-
"@lowdefy/blocks-captcha": "7.
|
|
55
|
-
"@lowdefy/blocks-echarts": "7.
|
|
56
|
-
"@lowdefy/blocks-files": "7.
|
|
57
|
-
"@lowdefy/blocks-loaders": "7.
|
|
58
|
-
"@lowdefy/blocks-markdown": "7.
|
|
59
|
-
"@lowdefy/blocks-table": "7.
|
|
60
|
-
"@lowdefy/blocks-tiptap": "7.
|
|
61
|
-
"@lowdefy/client": "7.
|
|
62
|
-
"@lowdefy/connection-anthropic": "7.
|
|
63
|
-
"@lowdefy/errors": "7.
|
|
64
|
-
"@lowdefy/helpers": "7.
|
|
65
|
-
"@lowdefy/layout": "7.
|
|
66
|
-
"@lowdefy/logger": "7.
|
|
67
|
-
"@lowdefy/node-utils": "7.
|
|
68
|
-
"@lowdefy/operators-js": "7.
|
|
69
|
-
"@lowdefy/operators-nunjucks": "7.
|
|
70
|
-
"@lowdefy/plugin-better-auth": "7.
|
|
71
|
-
"@lowdefy/websockets-core": "7.
|
|
46
|
+
"@hono/node-server": "2.1.3",
|
|
47
|
+
"@lowdefy/actions-core": "7.3.0",
|
|
48
|
+
"@lowdefy/api": "7.3.0",
|
|
49
|
+
"@lowdefy/block-utils": "7.3.0",
|
|
50
|
+
"@lowdefy/blocks-aggrid": "7.3.0",
|
|
51
|
+
"@lowdefy/blocks-antd": "7.3.0",
|
|
52
|
+
"@lowdefy/blocks-antd-x": "7.3.0",
|
|
53
|
+
"@lowdefy/blocks-basic": "7.3.0",
|
|
54
|
+
"@lowdefy/blocks-captcha": "7.3.0",
|
|
55
|
+
"@lowdefy/blocks-echarts": "7.3.0",
|
|
56
|
+
"@lowdefy/blocks-files": "7.3.0",
|
|
57
|
+
"@lowdefy/blocks-loaders": "7.3.0",
|
|
58
|
+
"@lowdefy/blocks-markdown": "7.3.0",
|
|
59
|
+
"@lowdefy/blocks-table": "7.3.0",
|
|
60
|
+
"@lowdefy/blocks-tiptap": "7.3.0",
|
|
61
|
+
"@lowdefy/client": "7.3.0",
|
|
62
|
+
"@lowdefy/connection-anthropic": "7.3.0",
|
|
63
|
+
"@lowdefy/errors": "7.3.0",
|
|
64
|
+
"@lowdefy/helpers": "7.3.0",
|
|
65
|
+
"@lowdefy/layout": "7.3.0",
|
|
66
|
+
"@lowdefy/logger": "7.3.0",
|
|
67
|
+
"@lowdefy/node-utils": "7.3.0",
|
|
68
|
+
"@lowdefy/operators-js": "7.3.0",
|
|
69
|
+
"@lowdefy/operators-nunjucks": "7.3.0",
|
|
70
|
+
"@lowdefy/plugin-better-auth": "7.3.0",
|
|
71
|
+
"@lowdefy/websockets-core": "7.3.0",
|
|
72
72
|
"@sentry/browser": "10.57.0",
|
|
73
73
|
"@sentry/node": "10.57.0",
|
|
74
74
|
"@sentry/node-core": "10.57.0",
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
"ws": "8.21.0"
|
|
89
89
|
},
|
|
90
90
|
"devDependencies": {
|
|
91
|
-
"@lowdefy/build": "7.
|
|
91
|
+
"@lowdefy/build": "7.3.0",
|
|
92
92
|
"@tailwindcss/postcss": "4.3.3",
|
|
93
93
|
"tailwindcss": "4.3.3",
|
|
94
94
|
"vitest": "4.1.12",
|
package/package.original.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowdefy/server",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.3.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
@@ -51,32 +51,32 @@
|
|
|
51
51
|
"@better-auth/oauth-provider": "1.7.7",
|
|
52
52
|
"@better-auth/passkey": "1.7.7",
|
|
53
53
|
"@hono/mcp": "0.3.2",
|
|
54
|
-
"@hono/node-server": "2.
|
|
55
|
-
"@lowdefy/actions-core": "7.
|
|
56
|
-
"@lowdefy/api": "7.
|
|
57
|
-
"@lowdefy/block-utils": "7.
|
|
58
|
-
"@lowdefy/blocks-aggrid": "7.
|
|
59
|
-
"@lowdefy/blocks-antd": "7.
|
|
60
|
-
"@lowdefy/blocks-antd-x": "7.
|
|
61
|
-
"@lowdefy/blocks-basic": "7.
|
|
62
|
-
"@lowdefy/blocks-captcha": "7.
|
|
63
|
-
"@lowdefy/blocks-echarts": "7.
|
|
64
|
-
"@lowdefy/blocks-files": "7.
|
|
65
|
-
"@lowdefy/blocks-loaders": "7.
|
|
66
|
-
"@lowdefy/blocks-markdown": "7.
|
|
67
|
-
"@lowdefy/blocks-table": "7.
|
|
68
|
-
"@lowdefy/blocks-tiptap": "7.
|
|
69
|
-
"@lowdefy/client": "7.
|
|
70
|
-
"@lowdefy/connection-anthropic": "7.
|
|
71
|
-
"@lowdefy/errors": "7.
|
|
72
|
-
"@lowdefy/helpers": "7.
|
|
73
|
-
"@lowdefy/layout": "7.
|
|
74
|
-
"@lowdefy/logger": "7.
|
|
75
|
-
"@lowdefy/node-utils": "7.
|
|
76
|
-
"@lowdefy/operators-js": "7.
|
|
77
|
-
"@lowdefy/operators-nunjucks": "7.
|
|
78
|
-
"@lowdefy/plugin-better-auth": "7.
|
|
79
|
-
"@lowdefy/websockets-core": "7.
|
|
54
|
+
"@hono/node-server": "2.1.3",
|
|
55
|
+
"@lowdefy/actions-core": "7.3.0",
|
|
56
|
+
"@lowdefy/api": "7.3.0",
|
|
57
|
+
"@lowdefy/block-utils": "7.3.0",
|
|
58
|
+
"@lowdefy/blocks-aggrid": "7.3.0",
|
|
59
|
+
"@lowdefy/blocks-antd": "7.3.0",
|
|
60
|
+
"@lowdefy/blocks-antd-x": "7.3.0",
|
|
61
|
+
"@lowdefy/blocks-basic": "7.3.0",
|
|
62
|
+
"@lowdefy/blocks-captcha": "7.3.0",
|
|
63
|
+
"@lowdefy/blocks-echarts": "7.3.0",
|
|
64
|
+
"@lowdefy/blocks-files": "7.3.0",
|
|
65
|
+
"@lowdefy/blocks-loaders": "7.3.0",
|
|
66
|
+
"@lowdefy/blocks-markdown": "7.3.0",
|
|
67
|
+
"@lowdefy/blocks-table": "7.3.0",
|
|
68
|
+
"@lowdefy/blocks-tiptap": "7.3.0",
|
|
69
|
+
"@lowdefy/client": "7.3.0",
|
|
70
|
+
"@lowdefy/connection-anthropic": "7.3.0",
|
|
71
|
+
"@lowdefy/errors": "7.3.0",
|
|
72
|
+
"@lowdefy/helpers": "7.3.0",
|
|
73
|
+
"@lowdefy/layout": "7.3.0",
|
|
74
|
+
"@lowdefy/logger": "7.3.0",
|
|
75
|
+
"@lowdefy/node-utils": "7.3.0",
|
|
76
|
+
"@lowdefy/operators-js": "7.3.0",
|
|
77
|
+
"@lowdefy/operators-nunjucks": "7.3.0",
|
|
78
|
+
"@lowdefy/plugin-better-auth": "7.3.0",
|
|
79
|
+
"@lowdefy/websockets-core": "7.3.0",
|
|
80
80
|
"@sentry/browser": "10.57.0",
|
|
81
81
|
"@sentry/node": "10.57.0",
|
|
82
82
|
"@sentry/node-core": "10.57.0",
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
"ws": "8.21.0"
|
|
97
97
|
},
|
|
98
98
|
"devDependencies": {
|
|
99
|
-
"@lowdefy/build": "7.
|
|
99
|
+
"@lowdefy/build": "7.3.0",
|
|
100
100
|
"@tailwindcss/postcss": "4.3.3",
|
|
101
101
|
"tailwindcss": "4.3.3",
|
|
102
102
|
"vitest": "4.1.12",
|
|
@@ -0,0 +1,141 @@
|
|
|
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
|
+
import { vi, beforeEach, expect, test } from 'vitest';
|
|
17
|
+
|
|
18
|
+
// The real app wiring and error handler with a request route that outlives the request
|
|
19
|
+
// timeout: what a request a slow upstream holds past config.requestTimeout reports.
|
|
20
|
+
const REQUEST_TIMEOUT_MS = 50;
|
|
21
|
+
|
|
22
|
+
const captureException = vi.fn();
|
|
23
|
+
const logger = { info: vi.fn(), warn: vi.fn(), error: vi.fn() };
|
|
24
|
+
// How the slow request route answers, set by each test.
|
|
25
|
+
let lateAnswer;
|
|
26
|
+
// Settles once the handler and every middleware inside apiContext have run on the late answer.
|
|
27
|
+
let lateChain;
|
|
28
|
+
|
|
29
|
+
function handler(c) {
|
|
30
|
+
return c.json({ ok: true });
|
|
31
|
+
}
|
|
32
|
+
// Answers well after the timeout.
|
|
33
|
+
async function slowHandler(c) {
|
|
34
|
+
await new Promise((resolve) => setTimeout(resolve, REQUEST_TIMEOUT_MS * 3));
|
|
35
|
+
return lateAnswer(c);
|
|
36
|
+
}
|
|
37
|
+
function largeHandler(c) {
|
|
38
|
+
return c.json({ rows: 'x'.repeat(4096) });
|
|
39
|
+
}
|
|
40
|
+
function passThrough() {
|
|
41
|
+
return (c, next) => next();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
vi.doMock('./routes/agent.js', () => ({ default: handler }));
|
|
45
|
+
vi.doMock('./routes/apiPage.js', () => ({ default: largeHandler }));
|
|
46
|
+
vi.doMock('./routes/auth.js', () => ({ default: () => handler }));
|
|
47
|
+
vi.doMock('./routes/clientError.js', () => ({ default: handler }));
|
|
48
|
+
vi.doMock('./routes/cron.js', () => ({ default: handler }));
|
|
49
|
+
vi.doMock('./routes/cronForward.js', () => ({ default: handler }));
|
|
50
|
+
vi.doMock('./routes/detached.js', () => ({ default: handler }));
|
|
51
|
+
vi.doMock('./routes/endpoints.js', () => ({ default: handler }));
|
|
52
|
+
vi.doMock('./routes/mcp.js', () => ({ default: handler }));
|
|
53
|
+
vi.doMock('./routes/mobileRoot.js', () => ({ default: handler }));
|
|
54
|
+
vi.doMock('./routes/mountOauthDiscovery.js', () => ({ default: () => {} }));
|
|
55
|
+
vi.doMock('./routes/request.js', () => ({ default: slowHandler }));
|
|
56
|
+
vi.doMock('./routes/usage.js', () => ({ default: handler }));
|
|
57
|
+
vi.doMock('./routes/user.js', () => ({ default: handler }));
|
|
58
|
+
vi.doMock('./routes/websocket.js', () => ({ default: handler }));
|
|
59
|
+
vi.doMock('./routes/wellKnownFallback.js', () => ({ default: handler }));
|
|
60
|
+
vi.doMock('./html/renderPage.js', () => ({
|
|
61
|
+
default: (c) => c.html('<html></html>'),
|
|
62
|
+
}));
|
|
63
|
+
// Production's context.handleError logs the fault and captures it to Sentry.
|
|
64
|
+
vi.doMock('./middleware/apiContext.js', () => ({
|
|
65
|
+
default: () => (c, next) => {
|
|
66
|
+
c.set('lowdefyContext', {
|
|
67
|
+
logger,
|
|
68
|
+
handleError: async (error) => {
|
|
69
|
+
logger.error(error);
|
|
70
|
+
captureException(error);
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
lateChain = next();
|
|
74
|
+
return lateChain;
|
|
75
|
+
},
|
|
76
|
+
}));
|
|
77
|
+
vi.doMock('./middleware/sentry.js', () => ({ default: passThrough }));
|
|
78
|
+
vi.doMock('../lib/build/appMeta.js', () => ({ default: { buildId: 'build-1' } }));
|
|
79
|
+
vi.doMock('../lib/build/auth.js', () => ({ default: { configured: false } }));
|
|
80
|
+
vi.doMock('../lib/build/theme.js', () => ({ default: {} }));
|
|
81
|
+
vi.doMock('../lib/build/config.js', () => ({
|
|
82
|
+
default: { requestTimeout: REQUEST_TIMEOUT_MS },
|
|
83
|
+
}));
|
|
84
|
+
vi.doMock('../lib/build/mobileConfig.js', () => ({ default: {} }));
|
|
85
|
+
vi.doMock('../lib/server/auth/getAuth.js', () => ({ default: vi.fn() }));
|
|
86
|
+
vi.doMock('../lib/server/auth/getStrategies.js', () => ({ default: vi.fn() }));
|
|
87
|
+
vi.doMock('../lib/server/log/createLogger.js', () => ({ default: () => logger }));
|
|
88
|
+
|
|
89
|
+
const { default: sentrySdk } = await import('../lib/server/sentry/sentrySdk.js');
|
|
90
|
+
const { default: createApp } = await import('./app.js');
|
|
91
|
+
|
|
92
|
+
beforeEach(() => {
|
|
93
|
+
vi.clearAllMocks();
|
|
94
|
+
sentrySdk.current = { captureException };
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
async function requestPastTimeout() {
|
|
98
|
+
const res = await createApp().request('/api/request/home/get_data', {
|
|
99
|
+
method: 'POST',
|
|
100
|
+
headers: { 'accept-encoding': 'gzip' },
|
|
101
|
+
});
|
|
102
|
+
expect(res.status).toEqual(504);
|
|
103
|
+
// Sending the 504 reads its body, as the Node server does.
|
|
104
|
+
expect(await res.text()).toEqual('');
|
|
105
|
+
// The handler answers after the 504 went out, and the middleware around it finishes.
|
|
106
|
+
await lateChain;
|
|
107
|
+
// compress, outside apiContext, finishes on the next turn.
|
|
108
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
test('a request whose handler answers after the timeout answers 504 and reports nothing', async () => {
|
|
112
|
+
lateAnswer = (c) => c.json({ rows: 'x'.repeat(4096) });
|
|
113
|
+
await requestPastTimeout();
|
|
114
|
+
expect(captureException).not.toHaveBeenCalled();
|
|
115
|
+
expect(logger.error).not.toHaveBeenCalled();
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test('a handler that sets a header after the timeout reports nothing', async () => {
|
|
119
|
+
lateAnswer = (c) => c.redirect('/home', 302);
|
|
120
|
+
await requestPastTimeout();
|
|
121
|
+
expect(captureException).not.toHaveBeenCalled();
|
|
122
|
+
expect(logger.error).not.toHaveBeenCalled();
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test('a handler that fails after the timeout is still reported', async () => {
|
|
126
|
+
const fault = new Error('The upstream write failed.');
|
|
127
|
+
lateAnswer = () => {
|
|
128
|
+
throw fault;
|
|
129
|
+
};
|
|
130
|
+
await requestPastTimeout();
|
|
131
|
+
expect(captureException).toHaveBeenCalledTimes(1);
|
|
132
|
+
expect(captureException).toHaveBeenCalledWith(fault);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test('a response in time is still compressed', async () => {
|
|
136
|
+
const res = await createApp().request('/api/page/home', {
|
|
137
|
+
headers: { 'accept-encoding': 'gzip' },
|
|
138
|
+
});
|
|
139
|
+
expect(res.status).toEqual(200);
|
|
140
|
+
expect(res.headers.get('content-encoding')).toEqual('gzip');
|
|
141
|
+
});
|
|
@@ -22,6 +22,12 @@ import { timeout } from 'hono/timeout';
|
|
|
22
22
|
// timeout signal (which apiContext folds into context.signal) cancels the upstream
|
|
23
23
|
// calls the handler is waiting on, such as an AI provider call, instead of letting
|
|
24
24
|
// them run, and bill, after the response has gone.
|
|
25
|
+
//
|
|
26
|
+
// The 504 has no body. The handler runs on after the 504 is sent, on the same context:
|
|
27
|
+
// a header set on it then, by the middleware around the handler or by the handler
|
|
28
|
+
// itself (c.redirect sets one), makes hono rebuild the sent 504 from its body. Sending
|
|
29
|
+
// it has already read that body, so the rebuild throws. A response with no body
|
|
30
|
+
// rebuilds safely. The client reads any 504 as a timeout.
|
|
25
31
|
function requestTimeout({ timeoutMs }) {
|
|
26
32
|
return function requestTimeoutMiddleware(c, next) {
|
|
27
33
|
const controller = new AbortController();
|
|
@@ -30,7 +36,7 @@ function requestTimeout({ timeoutMs }) {
|
|
|
30
36
|
controller.abort(
|
|
31
37
|
new DOMException(`The request timeout of ${timeoutMs}ms was exceeded.`, 'TimeoutError')
|
|
32
38
|
);
|
|
33
|
-
return new HTTPException(504, {
|
|
39
|
+
return new HTTPException(504, { res: new Response(null, { status: 504 }) });
|
|
34
40
|
})(c, next);
|
|
35
41
|
};
|
|
36
42
|
}
|