@lowdefy/server 7.1.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/client/clientBuildImports.test.mjs +1 -0
- package/client/getShownPage.test.mjs +1 -0
- package/client/shouldReloadForTypes.test.mjs +1 -0
- package/lib/build/mobileConfig.js +26 -0
- package/lib/client/auth/AuthConfigured.jsx +75 -48
- package/lib/client/auth/createFetchCheckingBuild.test.mjs +3 -3
- package/lib/client/auth/sessionCaller.js +56 -0
- package/lib/client/createLogUsage.test.mjs +2 -2
- package/lib/server/getClientAddress.test.mjs +6 -7
- package/lib/server/log/createHandleError.test.mjs +5 -5
- package/lib/server/log/createLogger.test.mjs +3 -3
- package/lib/server/log/projectErrorForLog.js +6 -4
- package/lib/server/log/redactUrlQuery.test.mjs +1 -0
- package/lib/server/log/serializeErrorForLog.test.mjs +50 -113
- package/lib/server/sentry/captureSentryError.test.mjs +4 -7
- package/lib/server/sentry/initSentry.serverless.test.mjs +6 -6
- package/lib/server/sentry/initSentry.test.mjs +3 -3
- package/lib/server/sentry/scrubEvent.test.mjs +2 -0
- package/lowdefy/build.mjs +4 -1
- package/lowdefy/build.test.mjs +11 -13
- package/lowdefy/createCustomPluginMessagesMap.mjs +2 -4
- package/lowdefy/createCustomPluginTypesMap.mjs +39 -11
- package/lowdefy/createCustomPluginTypesMap.test.mjs +249 -0
- package/package.json +32 -33
- package/package.original.json +32 -33
- package/src/app.js +19 -2
- package/src/app.mobile.test.mjs +351 -0
- package/src/app.test.mjs +31 -27
- package/src/app.timeout.test.mjs +141 -0
- package/src/html/collectPageTypesAssets.test.mjs +1 -0
- package/src/html/getPageAssets.test.mjs +1 -0
- package/src/html/renderPage.contentSecurityPolicy.test.mjs +13 -10
- package/src/html/renderPage.test.mjs +16 -13
- package/src/html/template.test.mjs +1 -0
- package/src/initServer.test.mjs +12 -12
- package/src/lib/getPathSegments.js +16 -1
- package/src/lib/getRequestSurface.js +25 -0
- package/src/middleware/apiContext.js +7 -4
- package/src/middleware/apiContext.test.mjs +48 -30
- package/src/middleware/createSameOriginGuard.test.mjs +1 -0
- package/src/middleware/errorHandler.js +33 -45
- package/src/middleware/errorHandler.test.mjs +11 -11
- package/src/middleware/refuseOtherBuild.test.mjs +3 -3
- package/src/middleware/requestTimeout.js +7 -1
- package/src/middleware/stampBuildId.test.mjs +1 -0
- package/src/middleware/stampCaller.test.mjs +1 -0
- package/src/routes/agentBearer.test.mjs +175 -0
- package/src/routes/apiPage.js +12 -1
- package/src/routes/apiPage.test.mjs +5 -5
- package/src/routes/auth.test.mjs +6 -6
- package/src/routes/clientError.js +14 -2
- package/src/routes/clientError.test.mjs +106 -0
- package/src/routes/endpoints.js +24 -0
- package/src/routes/endpointsLink.test.mjs +112 -0
- package/src/routes/endpointsTextAnswer.test.mjs +8 -8
- package/src/routes/mcp.js +6 -0
- package/src/routes/mcp.test.mjs +23 -8
- package/src/routes/mcpMemberToken.test.mjs +8 -8
- package/src/routes/mcpProtectedResourceMetadata.test.mjs +2 -2
- package/src/routes/mobileRoot.js +30 -0
- package/src/routes/mobileSignIn.js +46 -0
- package/src/routes/mobileSignIn.test.mjs +58 -0
- package/src/routes/mobileSignInCallback.js +34 -0
- package/src/routes/mobileSignInCallback.test.mjs +51 -0
- package/src/routes/mountMobileWellKnown.js +35 -0
- package/src/routes/mountMobileWellKnown.test.mjs +79 -0
- package/src/routes/mountOauthDiscovery.test.mjs +5 -5
- package/src/routes/mountPageRoutes.js +9 -2
- package/src/routes/mountPageRoutes.test.mjs +33 -3
- package/src/routes/normalizeMcpProtocolVersionHeader.test.mjs +1 -0
- package/src/routes/requestBody.test.mjs +12 -12
- package/src/routes/websocket.js +4 -2
- package/src/routes/websocket.test.mjs +2 -2
- package/lib/server/log/maskCredentialKeys.js +0 -37
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
import fs from 'node:fs';
|
|
18
18
|
import path from 'node:path';
|
|
19
19
|
import { fileURLToPath } from 'node:url';
|
|
20
|
+
import { expect, test } from 'vitest';
|
|
20
21
|
|
|
21
22
|
// Everything the client imports from build/ ships in the browser bundle. build/config.json is
|
|
22
23
|
// server-only: it carries every deployment environment's settings (other environments' urls,
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
import clearReloadedForTypes from './clearReloadedForTypes.js';
|
|
18
18
|
import shouldReloadForTypes from './shouldReloadForTypes.js';
|
|
19
|
+
import { expect, test } from 'vitest';
|
|
19
20
|
|
|
20
21
|
function createWindow({ href = 'https://example.com/orders', throws = false } = {}) {
|
|
21
22
|
const stored = {};
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
// Build artifacts are read from disk because the Hono server runs as
|
|
18
|
+
// unbundled Node.js ESM — JSON imports would need import attributes, and
|
|
19
|
+
// client code imports the build JSON directly through Vite instead.
|
|
20
|
+
import fs from 'node:fs';
|
|
21
|
+
import path from 'node:path';
|
|
22
|
+
|
|
23
|
+
// {} for an app without a mobile key.
|
|
24
|
+
export default JSON.parse(
|
|
25
|
+
fs.readFileSync(path.join(process.cwd(), 'build/mobile/config.json'), 'utf8')
|
|
26
|
+
);
|
|
@@ -28,10 +28,11 @@ import { oauthProviderClient } from '@better-auth/oauth-provider/client';
|
|
|
28
28
|
import { passkeyClient } from '@better-auth/passkey/client';
|
|
29
29
|
|
|
30
30
|
import claimCallerReload from '@lowdefy/client/claimCallerReload.js';
|
|
31
|
-
import {
|
|
31
|
+
import { type } from '@lowdefy/helpers';
|
|
32
32
|
|
|
33
33
|
import bundleBuildId from '../bundleBuildId.js';
|
|
34
34
|
import createFetchCheckingBuild from './createFetchCheckingBuild.js';
|
|
35
|
+
import sessionCaller from './sessionCaller.js';
|
|
35
36
|
|
|
36
37
|
// The app basePath, from Vite's BASE_URL (`${config.basePath}/`, set in
|
|
37
38
|
// vite.config.js). build/config.json is server-only - it carries every
|
|
@@ -77,6 +78,42 @@ const sessionScoped = (params) => ({
|
|
|
77
78
|
fetchOptions: { ...params?.fetchOptions, disableSignal: true },
|
|
78
79
|
});
|
|
79
80
|
|
|
81
|
+
// Resolves once no refetch is writing the session atom. The atom writes only
|
|
82
|
+
// its latest refetch's answer, and a sign-in fires its own refetch through the
|
|
83
|
+
// session signal 10 ms after the call. A refetch started before that one has
|
|
84
|
+
// its answer dropped, and the atom still holds the session from before the
|
|
85
|
+
// sign-in until the later refetch lands.
|
|
86
|
+
async function sessionAtomSettled(sessionAtom) {
|
|
87
|
+
if (!sessionAtom.get().isRefetching) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
await new Promise((resolve) => {
|
|
91
|
+
const unlisten = sessionAtom.listen((value) => {
|
|
92
|
+
if (value.isRefetching) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
unlisten();
|
|
96
|
+
resolve();
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// The server-resolved caller - roles from the active member row and the
|
|
102
|
+
// merged attributes bag - as { user }.
|
|
103
|
+
async function fetchResolvedUser() {
|
|
104
|
+
const response = await fetchCheckingBuild(`${basePath}/api/user`, {
|
|
105
|
+
credentials: 'same-origin',
|
|
106
|
+
});
|
|
107
|
+
if (!response.ok) {
|
|
108
|
+
// /api/user itself always answers 200 { user } - user: null when no
|
|
109
|
+
// caller is admitted, which updateSession branches on. A non-OK
|
|
110
|
+
// response is a transport failure (gateway error page, 5xx) with no
|
|
111
|
+
// parsable body.
|
|
112
|
+
throw new Error(`Failed to fetch the resolved user (HTTP ${response.status}).`);
|
|
113
|
+
}
|
|
114
|
+
return response.json();
|
|
115
|
+
}
|
|
116
|
+
|
|
80
117
|
// The server resolves the caller per request and embeds it in the page
|
|
81
118
|
// config, so the first render never flashes unauthenticated. The BetterAuth
|
|
82
119
|
// client store takes over once its session fetch settles.
|
|
@@ -87,16 +124,43 @@ const sessionScoped = (params) => ({
|
|
|
87
124
|
// for the fields the session does not carry, and UpdateSession refreshes it
|
|
88
125
|
// from /api/user after a change (e.g. SetActiveOrganization). Holding it in
|
|
89
126
|
// state, not a ref, re-renders Session when it changes so _user recomputes -
|
|
90
|
-
// the same reactive footing the session half already stands on.
|
|
91
|
-
//
|
|
92
|
-
// Only the session half is passed through normalizeCaller. BetterAuth's store
|
|
93
|
-
// returns camelCase keys whatever the columns are named, so untransformed it
|
|
94
|
-
// would sit emailVerified beside the resolved caller's email_verified on one
|
|
95
|
-
// object; anything arriving from the server is already snake_case.
|
|
127
|
+
// the same reactive footing the session half already stands on. sessionCaller
|
|
128
|
+
// picks the caller rendered from the two.
|
|
96
129
|
function Session({ children, reloadSuppressedRef, serverUser }) {
|
|
97
130
|
const { data: session, isPending } = authClient.useSession();
|
|
98
131
|
const [resolvedUser, setResolvedUser] = useState(serverUser);
|
|
99
132
|
const wasAuthenticated = useRef(Boolean(serverUser));
|
|
133
|
+
const sessionId = session?.session?.id;
|
|
134
|
+
const sessionIdRef = useRef(sessionId);
|
|
135
|
+
sessionIdRef.current = sessionId;
|
|
136
|
+
const askedSessionIdRef = useRef(null);
|
|
137
|
+
|
|
138
|
+
// A session with no server-resolved caller renders as no caller
|
|
139
|
+
// (sessionCaller). It is a sign-in in another tab, a session the server
|
|
140
|
+
// refused when it served this page, or a sign-in on this page whose Login has
|
|
141
|
+
// not set the caller yet (settleSignIn), so /api/user is asked once per
|
|
142
|
+
// session for the caller the server resolves it to. A null answer - a session the server
|
|
143
|
+
// refuses - leaves the page rendering no caller, matching every response.
|
|
144
|
+
// An answer is dropped once the session changed or UpdateSession set a
|
|
145
|
+
// caller in the meantime. A failed ask is left: the page renders no caller,
|
|
146
|
+
// and if the server does resolve one, the next response reloads the page.
|
|
147
|
+
useEffect(() => {
|
|
148
|
+
if (isPending || type.isNone(sessionId) || !type.isNone(resolvedUser)) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
if (askedSessionIdRef.current === sessionId) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
askedSessionIdRef.current = sessionId;
|
|
155
|
+
fetchResolvedUser()
|
|
156
|
+
.then(({ user }) => {
|
|
157
|
+
if (type.isNone(user) || sessionIdRef.current !== sessionId) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
setResolvedUser((current) => current ?? user);
|
|
161
|
+
})
|
|
162
|
+
.catch(() => {});
|
|
163
|
+
}, [sessionId, isPending, resolvedUser]);
|
|
100
164
|
|
|
101
165
|
useEffect(() => {
|
|
102
166
|
if (session) {
|
|
@@ -130,32 +194,7 @@ function Session({ children, reloadSuppressedRef, serverUser }) {
|
|
|
130
194
|
}
|
|
131
195
|
}, [session, isPending, resolvedUser]);
|
|
132
196
|
|
|
133
|
-
|
|
134
|
-
return children(resolvedUser, setResolvedUser);
|
|
135
|
-
}
|
|
136
|
-
if (!session?.user) {
|
|
137
|
-
return children(null, setResolvedUser);
|
|
138
|
-
}
|
|
139
|
-
const resolved = resolvedUser;
|
|
140
|
-
if (!resolved) {
|
|
141
|
-
return children({ roles: [], ...normalizeCaller(session.user) }, setResolvedUser);
|
|
142
|
-
}
|
|
143
|
-
if (resolved.id !== session.user.id) {
|
|
144
|
-
// The session names another person than the resolved caller; the effect
|
|
145
|
-
// above reloads the page. Until it unloads, render the last resolved
|
|
146
|
-
// caller whole rather than mixing the new session user with the previous
|
|
147
|
-
// person's resolved fields, or falling back to a caller with no roles -
|
|
148
|
-
// blocks re-evaluate operators on render, so a role-guarded page would act
|
|
149
|
-
// on an empty role list.
|
|
150
|
-
return children(resolved, setResolvedUser);
|
|
151
|
-
}
|
|
152
|
-
// _user is one object with one meaning on both sides: the resolved caller is
|
|
153
|
-
// spread whole, so every field resolveAuthentication emits is readable in app
|
|
154
|
-
// config without this file naming it. session.user is the floor - the client
|
|
155
|
-
// store may hold a fresher one than the resolved state, and the resolved
|
|
156
|
-
// object wins wherever both carry a key.
|
|
157
|
-
const user = { ...normalizeCaller(session.user), ...resolved };
|
|
158
|
-
return children(user, setResolvedUser);
|
|
197
|
+
return children(sessionCaller({ isPending, resolvedUser, session }), setResolvedUser);
|
|
159
198
|
}
|
|
160
199
|
|
|
161
200
|
function AuthConfigured({ authConfig, children, serverUser }) {
|
|
@@ -174,24 +213,12 @@ function AuthConfigured({ authConfig, children, serverUser }) {
|
|
|
174
213
|
await sessionAtom
|
|
175
214
|
.get()
|
|
176
215
|
.refetch(disableCookieCache ? { query: { disableCookieCache: true } } : undefined);
|
|
216
|
+
await sessionAtomSettled(sessionAtom);
|
|
177
217
|
const { data, error } = sessionAtom.get();
|
|
178
218
|
return { data, error };
|
|
179
219
|
},
|
|
180
|
-
//
|
|
181
|
-
|
|
182
|
-
getResolvedUser: async () => {
|
|
183
|
-
const response = await fetchCheckingBuild(`${basePath}/api/user`, {
|
|
184
|
-
credentials: 'same-origin',
|
|
185
|
-
});
|
|
186
|
-
if (!response.ok) {
|
|
187
|
-
// /api/user itself always answers 200 { user } - user: null when no
|
|
188
|
-
// caller is admitted, which updateSession branches on. A non-OK
|
|
189
|
-
// response is a transport failure (gateway error page, 5xx) with no
|
|
190
|
-
// parsable body.
|
|
191
|
-
throw new Error(`Failed to fetch the resolved user (HTTP ${response.status}).`);
|
|
192
|
-
}
|
|
193
|
-
return response.json();
|
|
194
|
-
},
|
|
220
|
+
// For re-syncing after session changes.
|
|
221
|
+
getResolvedUser: fetchResolvedUser,
|
|
195
222
|
suppressSessionReload: () => {
|
|
196
223
|
reloadSuppressedRef.current = true;
|
|
197
224
|
},
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import {
|
|
17
|
+
import { vi, afterEach, beforeEach, expect, test } from 'vitest';
|
|
18
18
|
|
|
19
19
|
import createFetchCheckingBuild from './createFetchCheckingBuild.js';
|
|
20
20
|
|
|
@@ -26,14 +26,14 @@ function mockFetch({ status, buildId }) {
|
|
|
26
26
|
status,
|
|
27
27
|
headers: new Headers(buildId ? { 'x-lowdefy-build': buildId } : {}),
|
|
28
28
|
};
|
|
29
|
-
global.fetch =
|
|
29
|
+
global.fetch = vi.fn(() => Promise.resolve(response));
|
|
30
30
|
return response;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
function createWindow() {
|
|
34
34
|
const stored = {};
|
|
35
35
|
return {
|
|
36
|
-
location: { reload:
|
|
36
|
+
location: { reload: vi.fn() },
|
|
37
37
|
sessionStorage: {
|
|
38
38
|
getItem: (key) => stored[key] ?? null,
|
|
39
39
|
setItem: (key, value) => {
|
|
@@ -0,0 +1,56 @@
|
|
|
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 { normalizeCaller, type } from '@lowdefy/helpers';
|
|
18
|
+
|
|
19
|
+
// The caller Session renders, from the BetterAuth store's session and the last
|
|
20
|
+
// server-resolved caller.
|
|
21
|
+
//
|
|
22
|
+
// The page renders only a caller the server resolved. Every response names the
|
|
23
|
+
// caller the server answered as (x-lowdefy-caller), and a page rendering
|
|
24
|
+
// another caller reloads (shouldReloadForCaller). A session the server resolves
|
|
25
|
+
// to no caller - a removed member, an invitee whose invitation lapsed - renders
|
|
26
|
+
// as no caller, not as the session's user: rendering the session's user would
|
|
27
|
+
// mismatch every response and reload until the loop guard throws.
|
|
28
|
+
//
|
|
29
|
+
// Only the session half is passed through normalizeCaller. BetterAuth's store
|
|
30
|
+
// returns camelCase keys whatever the columns are named, so untransformed it
|
|
31
|
+
// would sit emailVerified beside the resolved caller's email_verified on one
|
|
32
|
+
// object; anything arriving from the server is already snake_case.
|
|
33
|
+
function sessionCaller({ isPending, resolvedUser, session }) {
|
|
34
|
+
if (isPending) {
|
|
35
|
+
return resolvedUser;
|
|
36
|
+
}
|
|
37
|
+
if (type.isNone(session?.user) || type.isNone(resolvedUser)) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
if (resolvedUser.id !== session.user.id) {
|
|
41
|
+
// The session names another person than the resolved caller; Session
|
|
42
|
+
// reloads the page. Until it unloads, render the last resolved caller whole
|
|
43
|
+
// rather than mixing the new session user with the previous person's
|
|
44
|
+
// resolved fields - blocks re-evaluate operators on render, so a
|
|
45
|
+
// role-guarded page would act on a mixed caller.
|
|
46
|
+
return resolvedUser;
|
|
47
|
+
}
|
|
48
|
+
// _user is one object with one meaning on both sides: the resolved caller is
|
|
49
|
+
// spread whole, so every field resolveAuthentication emits is readable in app
|
|
50
|
+
// config without this file naming it. session.user is the floor - the client
|
|
51
|
+
// store may hold a fresher one than the resolved state, and the resolved
|
|
52
|
+
// object wins wherever both carry a key.
|
|
53
|
+
return { ...normalizeCaller(session.user), ...resolvedUser };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export default sessionCaller;
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import {
|
|
17
|
+
import { vi, afterEach, beforeEach, expect, test } from 'vitest';
|
|
18
18
|
|
|
19
19
|
import createLogUsage from './createLogUsage.js';
|
|
20
20
|
|
|
@@ -32,7 +32,7 @@ beforeEach(() => {
|
|
|
32
32
|
stored[key] = value;
|
|
33
33
|
},
|
|
34
34
|
};
|
|
35
|
-
globalThis.fetch =
|
|
35
|
+
globalThis.fetch = vi.fn();
|
|
36
36
|
});
|
|
37
37
|
|
|
38
38
|
afterEach(() => {
|
|
@@ -15,18 +15,17 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import { Hono } from 'hono';
|
|
18
|
-
import {
|
|
18
|
+
import { vi, expect, test } from 'vitest';
|
|
19
19
|
|
|
20
20
|
const mockConfig = {};
|
|
21
|
-
|
|
21
|
+
vi.doMock('../build/config.js', () => ({ default: mockConfig }));
|
|
22
22
|
|
|
23
23
|
// The resolver is built from config at module load, so each case loads a fresh
|
|
24
|
-
// module instance (
|
|
25
|
-
let loadCount = 0;
|
|
24
|
+
// module instance (vi.resetModules) against its own trustedProxies.
|
|
26
25
|
async function loadGetClientAddress({ trustedProxies }) {
|
|
27
26
|
mockConfig.trustedProxies = trustedProxies;
|
|
28
|
-
|
|
29
|
-
const { default: getClientAddress } = await import(
|
|
27
|
+
vi.resetModules();
|
|
28
|
+
const { default: getClientAddress } = await import('./getClientAddress.js');
|
|
30
29
|
return getClientAddress;
|
|
31
30
|
}
|
|
32
31
|
|
|
@@ -43,7 +42,7 @@ async function resolve({ getClientAddress, clientAddressHeader, headers, peerAdd
|
|
|
43
42
|
}
|
|
44
43
|
|
|
45
44
|
function createLogger() {
|
|
46
|
-
return { warn:
|
|
45
|
+
return { warn: vi.fn() };
|
|
47
46
|
}
|
|
48
47
|
|
|
49
48
|
test('getClientAddress takes the connection peer and ignores X-Forwarded-For without trusted proxies', async () => {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import {
|
|
17
|
+
import { vi, beforeEach, expect, test } from 'vitest';
|
|
18
18
|
import { TenantIntegrityError } from '@lowdefy/errors';
|
|
19
19
|
|
|
20
20
|
const secret = 'planted-handle-error-secret';
|
|
@@ -38,14 +38,14 @@ function createAxiosError() {
|
|
|
38
38
|
function testContext({ logger, headers } = {}) {
|
|
39
39
|
return {
|
|
40
40
|
headers,
|
|
41
|
-
logger: logger ?? { error:
|
|
42
|
-
readConfigFile:
|
|
41
|
+
logger: logger ?? { error: vi.fn() },
|
|
42
|
+
readConfigFile: vi.fn(async () => null),
|
|
43
43
|
req: { url: '/api/request/page/req', method: 'POST', hostname: 'app.example.com' },
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
beforeEach(() => {
|
|
48
|
-
console.error =
|
|
48
|
+
console.error = vi.fn();
|
|
49
49
|
});
|
|
50
50
|
|
|
51
51
|
test('handleError logs the referer header with credential query parameters redacted', async () => {
|
|
@@ -64,7 +64,7 @@ test('handleError fallback output carries no axios config auth and no planted se
|
|
|
64
64
|
const logError = new Error(`Log sink rejected ${secret}`);
|
|
65
65
|
const context = testContext({
|
|
66
66
|
logger: {
|
|
67
|
-
error:
|
|
67
|
+
error: vi.fn(() => {
|
|
68
68
|
throw logError;
|
|
69
69
|
}),
|
|
70
70
|
},
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import {
|
|
17
|
+
import { vi, beforeEach, expect, test } from 'vitest';
|
|
18
18
|
import { createNodeLogger } from '@lowdefy/logger/node';
|
|
19
19
|
import { markCredential, runInCredentialScope } from '@lowdefy/node-utils';
|
|
20
20
|
|
|
@@ -30,10 +30,10 @@ const destination = {
|
|
|
30
30
|
|
|
31
31
|
// The prod logger writes to stdout; route the real logger to memory so each test reads the
|
|
32
32
|
// exact line pino would emit, after the streamWrite hook.
|
|
33
|
-
|
|
33
|
+
vi.doMock('@lowdefy/logger/node', () => ({
|
|
34
34
|
createNodeLogger: (options) => createNodeLogger({ ...options, destination }),
|
|
35
35
|
}));
|
|
36
|
-
|
|
36
|
+
vi.doMock('../../build/appMeta.js', () => ({ default: {} }));
|
|
37
37
|
|
|
38
38
|
process.env.LOWDEFY_SECRET_API_KEY = secret;
|
|
39
39
|
process.env.LOWDEFY_SECRET_SHORT = shortSecret;
|
|
@@ -16,18 +16,18 @@
|
|
|
16
16
|
|
|
17
17
|
import { lowdefyErrorNames, readErrorCodes } from '@lowdefy/errors';
|
|
18
18
|
|
|
19
|
-
import maskCredentialKeys from './maskCredentialKeys.js';
|
|
20
|
-
|
|
21
19
|
// Kept only on nodes named as a Lowdefy error class: libraries reuse some of
|
|
22
20
|
// these names for their own data - axios's `config` carries auth, params and
|
|
23
21
|
// headers - so keying on the field alone would let a library's copy through.
|
|
22
|
+
// `received` is not among them: it holds an operator's or control's evaluated
|
|
23
|
+
// input - a user's ID number, a token from an earlier step - and the log names
|
|
24
|
+
// where a fault happened, not the values it ran on. The dev server's log keeps it.
|
|
24
25
|
const lowdefyErrorFields = [
|
|
25
26
|
'configKey',
|
|
26
27
|
'source',
|
|
27
28
|
'config',
|
|
28
29
|
'handled',
|
|
29
30
|
'isLowdefyError',
|
|
30
|
-
'received',
|
|
31
31
|
'typeName',
|
|
32
32
|
'location',
|
|
33
33
|
'service',
|
|
@@ -43,6 +43,9 @@ const lowdefyErrorFields = [
|
|
|
43
43
|
'organizationId',
|
|
44
44
|
'field',
|
|
45
45
|
'endpointId',
|
|
46
|
+
// A failed request's step id (callRequestResolver), beside its endpointId and connectionId,
|
|
47
|
+
// so its error log names the step rather than its inputs.
|
|
48
|
+
'stepId',
|
|
46
49
|
];
|
|
47
50
|
|
|
48
51
|
function projectErrorForLog(err) {
|
|
@@ -52,7 +55,6 @@ function projectErrorForLog(err) {
|
|
|
52
55
|
lowdefyErrorFields.forEach((field) => {
|
|
53
56
|
props[field] = err[field];
|
|
54
57
|
});
|
|
55
|
-
props.received = maskCredentialKeys(err.received);
|
|
56
58
|
}
|
|
57
59
|
props.cause = err.cause;
|
|
58
60
|
return props;
|