@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.
- 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 +5 -1
- package/lowdefy/build.test.mjs +31 -13
- package/lowdefy/createCustomPluginMessagesMap.mjs +2 -4
- package/lowdefy/createCustomPluginTypesMap.mjs +39 -11
- package/lowdefy/createCustomPluginTypesMap.test.mjs +249 -0
- package/package.json +31 -32
- package/package.original.json +31 -32
- package/src/app.js +19 -2
- package/src/app.mobile.test.mjs +351 -0
- package/src/app.test.mjs +31 -27
- 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/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
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
|
|
17
17
|
import { OperatorError, RequestError, ServiceError, UserError } from '@lowdefy/errors';
|
|
18
18
|
|
|
19
|
-
import maskCredentialKeys from './maskCredentialKeys.js';
|
|
20
19
|
import projectErrorForLog from './projectErrorForLog.js';
|
|
21
20
|
import serializeErrorForLog from './serializeErrorForLog.js';
|
|
21
|
+
import { expect, test } from 'vitest';
|
|
22
22
|
|
|
23
23
|
const allowedErrorKeys = new Set([
|
|
24
24
|
'name',
|
|
@@ -32,7 +32,6 @@ const allowedErrorKeys = new Set([
|
|
|
32
32
|
'config',
|
|
33
33
|
'handled',
|
|
34
34
|
'isLowdefyError',
|
|
35
|
-
'received',
|
|
36
35
|
'typeName',
|
|
37
36
|
'location',
|
|
38
37
|
'service',
|
|
@@ -43,10 +42,12 @@ const allowedErrorKeys = new Set([
|
|
|
43
42
|
'blockId',
|
|
44
43
|
'pageId',
|
|
45
44
|
'isReject',
|
|
45
|
+
'endpointId',
|
|
46
|
+
'stepId',
|
|
47
|
+
'connectionId',
|
|
46
48
|
]);
|
|
47
49
|
|
|
48
|
-
// Every serialized error node carries `stack
|
|
49
|
-
// `received` in these fixtures never do.
|
|
50
|
+
// Every serialized error node carries `stack`.
|
|
50
51
|
function collectErrorNodes(value, nodes = []) {
|
|
51
52
|
if (value === null || typeof value !== 'object') return nodes;
|
|
52
53
|
if (!Array.isArray(value) && Object.hasOwn(value, 'stack')) nodes.push(value);
|
|
@@ -129,54 +130,36 @@ test('serializeErrorForLog drops input from a Node ERR_INVALID_URL error', () =>
|
|
|
129
130
|
expect(Object.keys(serialized)).not.toContain('input');
|
|
130
131
|
});
|
|
131
132
|
|
|
132
|
-
test('serializeErrorForLog
|
|
133
|
-
const received = {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
headers: { Authorization: 'Bearer runtime-token-1', Accept: 'application/json' },
|
|
137
|
-
params: { access_token: 'runtime-token-2', page: 2 },
|
|
138
|
-
'x-api-key': 'runtime-token-3',
|
|
139
|
-
};
|
|
140
|
-
const error = new RequestError('Upstream failed.', {
|
|
141
|
-
typeName: 'AxiosHttp',
|
|
133
|
+
test('serializeErrorForLog leaves out the evaluated input an operator error carries as received', () => {
|
|
134
|
+
const received = { idNumber: '8001015009087' };
|
|
135
|
+
const error = new OperatorError('_string.concat failed.', {
|
|
136
|
+
typeName: '_string.concat',
|
|
142
137
|
received,
|
|
143
|
-
cause: new OperatorError('Inner failed.', { typeName: '
|
|
138
|
+
cause: new OperatorError('Inner failed.', { typeName: '_get', received }),
|
|
144
139
|
});
|
|
145
|
-
const expectedReceived = {
|
|
146
|
-
url: 'https://api.example.com/items',
|
|
147
|
-
method: 'get',
|
|
148
|
-
headers: { Authorization: '[REDACTED]', Accept: 'application/json' },
|
|
149
|
-
params: { access_token: '[REDACTED]', page: 2 },
|
|
150
|
-
'x-api-key': '[REDACTED]',
|
|
151
|
-
};
|
|
152
140
|
const serialized = serializeErrorForLog(error);
|
|
153
|
-
expect(serialized.
|
|
154
|
-
expect(serialized.
|
|
155
|
-
expect(
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
test('serializeErrorForLog does not mutate the received it masks', () => {
|
|
159
|
-
const received = { headers: { Authorization: 'Bearer runtime-token' } };
|
|
160
|
-
serializeErrorForLog(new RequestError('Upstream failed.', { received }));
|
|
161
|
-
expect(received).toEqual({ headers: { Authorization: 'Bearer runtime-token' } });
|
|
141
|
+
expect(serialized.typeName).toEqual('_string.concat');
|
|
142
|
+
expect(serialized.received).toBeUndefined();
|
|
143
|
+
expect(serialized.cause.received).toBeUndefined();
|
|
144
|
+
expect(JSON.stringify(serialized)).not.toMatch(/8001015009087/);
|
|
162
145
|
});
|
|
163
146
|
|
|
164
|
-
|
|
147
|
+
// metaData is the one kept free-form field, so an error placed in it is walked like any other value.
|
|
148
|
+
test('serializeErrorForLog projects an Error nested seven levels deep inside a kept field', () => {
|
|
165
149
|
let nested = createAxiosError();
|
|
166
150
|
for (let level = 7; level >= 1; level -= 1) {
|
|
167
|
-
|
|
151
|
+
const wrapper = new RequestError(`Level ${level}.`);
|
|
152
|
+
wrapper.metaData = nested;
|
|
153
|
+
nested = wrapper;
|
|
168
154
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
received: { page: 1 },
|
|
172
|
-
cause: new OperatorError('Cause.', { received: nested }),
|
|
173
|
-
});
|
|
155
|
+
const error = new RequestError('Top.', { cause: new OperatorError('Cause.') });
|
|
156
|
+
error.cause.metaData = nested;
|
|
174
157
|
const serialized = serializeErrorForLog(error);
|
|
175
158
|
|
|
176
|
-
let node = serialized.cause.
|
|
159
|
+
let node = serialized.cause.metaData;
|
|
177
160
|
for (let level = 1; level <= 7; level += 1) {
|
|
178
161
|
expect(node.message).toEqual(`Level ${level}.`);
|
|
179
|
-
node = node.
|
|
162
|
+
node = node.metaData;
|
|
180
163
|
}
|
|
181
164
|
expect(node.name).toEqual('AxiosError');
|
|
182
165
|
expect(node.statusCode).toEqual(401);
|
|
@@ -191,6 +174,33 @@ test('serializeErrorForLog projects an Error nested seven levels deep inside a c
|
|
|
191
174
|
expect(JSON.stringify(serialized)).not.toMatch(/planted/);
|
|
192
175
|
});
|
|
193
176
|
|
|
177
|
+
test("serializeErrorForLog keeps a failed request's ids and leaves out the connection's error it keeps for the dev tools", () => {
|
|
178
|
+
const driverError = new Error('Document failed validation');
|
|
179
|
+
driverError.name = 'MongoServerError';
|
|
180
|
+
driverError.errInfo = { details: { document: { message: 'planted-chat-text' } } };
|
|
181
|
+
const error = new RequestError('Document failed validation', {
|
|
182
|
+
cause: new Error('Document failed validation'),
|
|
183
|
+
typeName: 'MongoDBInsertOne',
|
|
184
|
+
location: 'threads/save_thread',
|
|
185
|
+
});
|
|
186
|
+
Object.assign(error, {
|
|
187
|
+
endpointId: 'save-thread',
|
|
188
|
+
stepId: 'save_thread',
|
|
189
|
+
connectionId: 'threads',
|
|
190
|
+
});
|
|
191
|
+
Object.defineProperty(error, 'devCause', { value: driverError });
|
|
192
|
+
|
|
193
|
+
const serialized = serializeErrorForLog(error);
|
|
194
|
+
|
|
195
|
+
expect(serialized).toMatchObject({
|
|
196
|
+
name: 'RequestError',
|
|
197
|
+
endpointId: 'save-thread',
|
|
198
|
+
stepId: 'save_thread',
|
|
199
|
+
connectionId: 'threads',
|
|
200
|
+
});
|
|
201
|
+
expect(JSON.stringify(serialized)).not.toMatch(/planted/);
|
|
202
|
+
});
|
|
203
|
+
|
|
194
204
|
test('serializeErrorForLog keeps UserError metaData, blockId, pageId and isReject', () => {
|
|
195
205
|
const error = new UserError('Please fill in the form.', {
|
|
196
206
|
blockId: 'submit_button',
|
|
@@ -258,79 +268,6 @@ test('projectErrorForLog reads statusCode from the node and passes the cause thr
|
|
|
258
268
|
expect(projected.cause).toBe(cause);
|
|
259
269
|
});
|
|
260
270
|
|
|
261
|
-
test('maskCredentialKeys masks keys containing each credential word after lower-casing and removing - and _', () => {
|
|
262
|
-
expect(
|
|
263
|
-
maskCredentialKeys({
|
|
264
|
-
Authorization: 'a',
|
|
265
|
-
access_token: 'b',
|
|
266
|
-
'x-api-key': 'c',
|
|
267
|
-
client_secret: 'd',
|
|
268
|
-
Password: 'e',
|
|
269
|
-
Cookie: 'f',
|
|
270
|
-
API_KEY: 'g',
|
|
271
|
-
tokenCount: 3,
|
|
272
|
-
name: 'kept',
|
|
273
|
-
})
|
|
274
|
-
).toEqual({
|
|
275
|
-
Authorization: '[REDACTED]',
|
|
276
|
-
access_token: '[REDACTED]',
|
|
277
|
-
'x-api-key': '[REDACTED]',
|
|
278
|
-
client_secret: '[REDACTED]',
|
|
279
|
-
Password: '[REDACTED]',
|
|
280
|
-
Cookie: '[REDACTED]',
|
|
281
|
-
API_KEY: '[REDACTED]',
|
|
282
|
-
tokenCount: '[REDACTED]',
|
|
283
|
-
name: 'kept',
|
|
284
|
-
});
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
test('maskCredentialKeys replaces a whole object value under a credential key', () => {
|
|
288
|
-
expect(maskCredentialKeys({ tokens: { access: 'a', refresh: 'b' } })).toEqual({
|
|
289
|
-
tokens: '[REDACTED]',
|
|
290
|
-
});
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
test('maskCredentialKeys recurses into arrays and nested objects', () => {
|
|
294
|
-
expect(
|
|
295
|
-
maskCredentialKeys({ items: [{ secret: 'a', id: 1 }, [{ cookie: 'b' }], 'plain'] })
|
|
296
|
-
).toEqual({ items: [{ secret: '[REDACTED]', id: 1 }, [{ cookie: '[REDACTED]' }], 'plain'] });
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
test('maskCredentialKeys returns primitives, Dates, Errors and class instances unchanged', () => {
|
|
300
|
-
class Client {
|
|
301
|
-
constructor() {
|
|
302
|
-
this.password = 'internal';
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
const date = new Date(0);
|
|
306
|
-
const error = new Error('x');
|
|
307
|
-
const client = new Client();
|
|
308
|
-
expect(maskCredentialKeys('text')).toEqual('text');
|
|
309
|
-
expect(maskCredentialKeys(undefined)).toBeUndefined();
|
|
310
|
-
expect(maskCredentialKeys(date)).toBe(date);
|
|
311
|
-
expect(maskCredentialKeys(error)).toBe(error);
|
|
312
|
-
expect(maskCredentialKeys(client)).toBe(client);
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
test('serializeErrorForLog marks a class instance in received by type name only', () => {
|
|
316
|
-
class Client {
|
|
317
|
-
constructor() {
|
|
318
|
-
this.password = 'planted';
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
const serialized = serializeErrorForLog(
|
|
322
|
-
new RequestError('Failed.', { received: { client: new Client() } })
|
|
323
|
-
);
|
|
324
|
-
expect(serialized.received).toEqual({ client: '[Object: Client]' });
|
|
325
|
-
});
|
|
326
|
-
|
|
327
|
-
test('serializeErrorForLog marks a cycle in received as circular', () => {
|
|
328
|
-
const received = { name: 'loop' };
|
|
329
|
-
received.self = received;
|
|
330
|
-
const serialized = serializeErrorForLog(new RequestError('Failed.', { received }));
|
|
331
|
-
expect(serialized.received).toEqual({ name: 'loop', self: '[Circular]' });
|
|
332
|
-
});
|
|
333
|
-
|
|
334
271
|
test('serializeErrorForLog returns a non-Error value unchanged', () => {
|
|
335
272
|
expect(serializeErrorForLog('plain string')).toEqual('plain string');
|
|
336
273
|
expect(serializeErrorForLog({ message: 'object' })).toEqual({ message: 'object' });
|
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import {
|
|
17
|
+
import { vi, beforeEach, expect, test } from 'vitest';
|
|
18
18
|
import { RequestError, TenantIntegrityError } from '@lowdefy/errors';
|
|
19
19
|
|
|
20
|
-
const captureException =
|
|
20
|
+
const captureException = vi.fn();
|
|
21
21
|
|
|
22
22
|
const { default: sentrySdk } = await import('./sentrySdk.js');
|
|
23
23
|
const { default: captureSentryError } = await import('./captureSentryError.js');
|
|
@@ -52,7 +52,7 @@ function createRequestError() {
|
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
test('captureSentryError sends the log projection as extra.error, without axios config
|
|
55
|
+
test('captureSentryError sends the log projection as extra.error, without axios config or received', () => {
|
|
56
56
|
const error = createRequestError();
|
|
57
57
|
captureSentryError({ error, context: { rid: 'req-1', pageId: 'orders' } });
|
|
58
58
|
expect(captureException).toHaveBeenCalledTimes(1);
|
|
@@ -60,10 +60,7 @@ test('captureSentryError sends the log projection as extra.error, without axios
|
|
|
60
60
|
expect(captured).toBe(error);
|
|
61
61
|
expect(extra.error.typeName).toEqual('AxiosHttp');
|
|
62
62
|
expect(extra.error.statusCode).toEqual(401);
|
|
63
|
-
expect(extra.error.received).
|
|
64
|
-
url: 'https://api.example.com/items',
|
|
65
|
-
headers: { Authorization: '[REDACTED]', Accept: 'application/json' },
|
|
66
|
-
});
|
|
63
|
+
expect(extra.error.received).toBeUndefined();
|
|
67
64
|
expect(extra.error.cause).toEqual({
|
|
68
65
|
name: 'AxiosError',
|
|
69
66
|
message: 'Request failed with status code 401',
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
import http from 'node:http';
|
|
18
18
|
|
|
19
|
-
import {
|
|
19
|
+
import { vi, afterAll, beforeEach, expect, test } from 'vitest';
|
|
20
20
|
import * as RealLight from '@sentry/node-core/light';
|
|
21
21
|
|
|
22
22
|
const envelopes = [];
|
|
@@ -31,16 +31,16 @@ function createStubTransport() {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
const imported = { node: false, light: false };
|
|
34
|
-
const nodeInit =
|
|
35
|
-
const nodeHttpIntegration =
|
|
34
|
+
const nodeInit = vi.fn();
|
|
35
|
+
const nodeHttpIntegration = vi.fn(() => ({ name: 'Http' }));
|
|
36
36
|
|
|
37
37
|
// @sentry/node is a stub that records its import, so a test can tell which SDK started. The light
|
|
38
38
|
// SDK is real, with its network transport swapped for memory.
|
|
39
|
-
|
|
39
|
+
vi.doMock('@sentry/node', () => {
|
|
40
40
|
imported.node = true;
|
|
41
41
|
return { init: nodeInit, httpIntegration: nodeHttpIntegration };
|
|
42
42
|
});
|
|
43
|
-
|
|
43
|
+
vi.doMock('@sentry/node-core/light', () => {
|
|
44
44
|
imported.light = true;
|
|
45
45
|
return {
|
|
46
46
|
...RealLight,
|
|
@@ -48,7 +48,7 @@ jest.unstable_mockModule('@sentry/node-core/light', () => {
|
|
|
48
48
|
};
|
|
49
49
|
});
|
|
50
50
|
const loggerConfig = { sentry: {} };
|
|
51
|
-
|
|
51
|
+
vi.doMock('../../build/logger.js', () => ({ default: loggerConfig }));
|
|
52
52
|
|
|
53
53
|
const { default: initSentryServer } = await import('./initSentry.js');
|
|
54
54
|
const { default: sentrySdk } = await import('./sentrySdk.js');
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
import http from 'node:http';
|
|
18
18
|
|
|
19
|
-
import {
|
|
19
|
+
import { vi, afterAll, beforeEach, expect, test } from 'vitest';
|
|
20
20
|
import { Hono } from 'hono';
|
|
21
21
|
import { serve } from '@hono/node-server';
|
|
22
22
|
import * as RealSentry from '@sentry/node';
|
|
@@ -39,7 +39,7 @@ const httpIntegrations = [];
|
|
|
39
39
|
|
|
40
40
|
// The real SDK with its network transport swapped for memory, so each test reads the exact
|
|
41
41
|
// event Sentry would send, after the hooks initSentry installs.
|
|
42
|
-
|
|
42
|
+
vi.doMock('@sentry/node', () => ({
|
|
43
43
|
...RealSentry,
|
|
44
44
|
init: (options) => RealSentry.init({ ...options, transport: createStubTransport }),
|
|
45
45
|
httpIntegration: (options) => {
|
|
@@ -48,7 +48,7 @@ jest.unstable_mockModule('@sentry/node', () => ({
|
|
|
48
48
|
return integration;
|
|
49
49
|
},
|
|
50
50
|
}));
|
|
51
|
-
|
|
51
|
+
vi.doMock('../../build/logger.js', () => ({
|
|
52
52
|
default: { sentry: { tracesSampleRate: 1 } },
|
|
53
53
|
}));
|
|
54
54
|
|
package/lowdefy/build.mjs
CHANGED
|
@@ -39,7 +39,9 @@ async function run() {
|
|
|
39
39
|
server: serverDirectory,
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
-
const customTypesMap = await createCustomPluginTypesMap({
|
|
42
|
+
const { customTypesMap, customTypesMapMobile } = await createCustomPluginTypesMap({
|
|
43
|
+
directories,
|
|
44
|
+
});
|
|
43
45
|
const customMessagesMap = await createCustomPluginMessagesMap({ directories });
|
|
44
46
|
|
|
45
47
|
let logger;
|
|
@@ -52,8 +54,10 @@ async function run() {
|
|
|
52
54
|
await build({
|
|
53
55
|
customMessagesMap,
|
|
54
56
|
customTypesMap,
|
|
57
|
+
customTypesMapMobile,
|
|
55
58
|
directories,
|
|
56
59
|
logger,
|
|
60
|
+
pluginInstallFollows: process.env.LOWDEFY_BUILD_PLUGIN_INSTALL_FOLLOWS === 'true',
|
|
57
61
|
refResolver: argv.refResolver || process.env.LOWDEFY_BUILD_REF_RESOLVER,
|
|
58
62
|
skipPluginChecks: process.env.LOWDEFY_BUILD_SKIP_PLUGIN_CHECKS === 'true',
|
|
59
63
|
});
|
package/lowdefy/build.test.mjs
CHANGED
|
@@ -14,34 +14,34 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import {
|
|
17
|
+
import { vi, afterAll, beforeEach, expect, test } from 'vitest';
|
|
18
18
|
|
|
19
|
-
const mockBuild =
|
|
19
|
+
const mockBuild = vi.fn();
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
createNodeLogger:
|
|
21
|
+
vi.doMock('@lowdefy/build', () => ({ default: mockBuild }));
|
|
22
|
+
vi.doMock('@lowdefy/logger/node', () => ({
|
|
23
|
+
createNodeLogger: vi.fn(() => 'logger'),
|
|
24
24
|
}));
|
|
25
|
-
|
|
26
|
-
default:
|
|
25
|
+
vi.doMock('./createCustomPluginTypesMap.mjs', () => ({
|
|
26
|
+
default: vi.fn().mockResolvedValue({ customTypesMap: {}, customTypesMapMobile: {} }),
|
|
27
27
|
}));
|
|
28
|
-
|
|
29
|
-
default:
|
|
28
|
+
vi.doMock('./createCustomPluginMessagesMap.mjs', () => ({
|
|
29
|
+
default: vi.fn().mockResolvedValue({}),
|
|
30
30
|
}));
|
|
31
31
|
|
|
32
32
|
const savedSkip = process.env.LOWDEFY_BUILD_SKIP_PLUGIN_CHECKS;
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
const savedInstallFollows = process.env.LOWDEFY_BUILD_PLUGIN_INSTALL_FOLLOWS;
|
|
35
34
|
// build.mjs runs the build when imported, so each case loads a fresh module
|
|
36
35
|
// instance and waits for the build call.
|
|
37
36
|
async function runScript() {
|
|
38
|
-
|
|
39
|
-
await import(
|
|
37
|
+
vi.resetModules();
|
|
38
|
+
await import('./build.mjs');
|
|
40
39
|
await new Promise((resolve) => setImmediate(resolve));
|
|
41
40
|
}
|
|
42
41
|
|
|
43
42
|
beforeEach(() => {
|
|
44
43
|
delete process.env.LOWDEFY_BUILD_SKIP_PLUGIN_CHECKS;
|
|
44
|
+
delete process.env.LOWDEFY_BUILD_PLUGIN_INSTALL_FOLLOWS;
|
|
45
45
|
mockBuild.mockReset();
|
|
46
46
|
mockBuild.mockResolvedValue();
|
|
47
47
|
});
|
|
@@ -52,6 +52,11 @@ afterAll(() => {
|
|
|
52
52
|
} else {
|
|
53
53
|
process.env.LOWDEFY_BUILD_SKIP_PLUGIN_CHECKS = savedSkip;
|
|
54
54
|
}
|
|
55
|
+
if (savedInstallFollows === undefined) {
|
|
56
|
+
delete process.env.LOWDEFY_BUILD_PLUGIN_INSTALL_FOLLOWS;
|
|
57
|
+
} else {
|
|
58
|
+
process.env.LOWDEFY_BUILD_PLUGIN_INSTALL_FOLLOWS = savedInstallFollows;
|
|
59
|
+
}
|
|
55
60
|
});
|
|
56
61
|
|
|
57
62
|
test('build passes skipPluginChecks true when LOWDEFY_BUILD_SKIP_PLUGIN_CHECKS is true', async () => {
|
|
@@ -66,3 +71,16 @@ test('build passes skipPluginChecks false when LOWDEFY_BUILD_SKIP_PLUGIN_CHECKS
|
|
|
66
71
|
expect(mockBuild).toHaveBeenCalledTimes(1);
|
|
67
72
|
expect(mockBuild.mock.calls[0][0].skipPluginChecks).toBe(false);
|
|
68
73
|
});
|
|
74
|
+
|
|
75
|
+
test('build passes pluginInstallFollows true when LOWDEFY_BUILD_PLUGIN_INSTALL_FOLLOWS is true', async () => {
|
|
76
|
+
process.env.LOWDEFY_BUILD_PLUGIN_INSTALL_FOLLOWS = 'true';
|
|
77
|
+
await runScript();
|
|
78
|
+
expect(mockBuild).toHaveBeenCalledTimes(1);
|
|
79
|
+
expect(mockBuild.mock.calls[0][0].pluginInstallFollows).toBe(true);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test('build passes pluginInstallFollows false when LOWDEFY_BUILD_PLUGIN_INSTALL_FOLLOWS is unset', async () => {
|
|
83
|
+
await runScript();
|
|
84
|
+
expect(mockBuild).toHaveBeenCalledTimes(1);
|
|
85
|
+
expect(mockBuild.mock.calls[0][0].pluginInstallFollows).toBe(false);
|
|
86
|
+
});
|
|
@@ -17,8 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
import { createRequire } from 'node:module';
|
|
19
19
|
import path from 'path';
|
|
20
|
-
import {
|
|
21
|
-
import { readFile } from '@lowdefy/node-utils';
|
|
20
|
+
import { collectPluginDefinitions, readFile } from '@lowdefy/node-utils';
|
|
22
21
|
import YAML from 'yaml';
|
|
23
22
|
|
|
24
23
|
const require = createRequire(import.meta.url);
|
|
@@ -31,8 +30,7 @@ async function getPluginDefinitions({ directories }) {
|
|
|
31
30
|
if (!lowdefyYaml) {
|
|
32
31
|
return [];
|
|
33
32
|
}
|
|
34
|
-
|
|
35
|
-
return get(lowdefy, 'plugins', { default: [] });
|
|
33
|
+
return collectPluginDefinitions({ lowdefy: YAML.parse(lowdefyYaml) }).plugins;
|
|
36
34
|
}
|
|
37
35
|
|
|
38
36
|
async function createCustomPluginMessagesMap({ directories }) {
|
|
@@ -17,9 +17,8 @@
|
|
|
17
17
|
|
|
18
18
|
import { createRequire } from 'node:module';
|
|
19
19
|
import path from 'path';
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import { createPluginTypesMap } from '@lowdefy/build';
|
|
20
|
+
import { collectPluginDefinitions, hasTypesExport, readFile } from '@lowdefy/node-utils';
|
|
21
|
+
import { createPluginTypesMap, createPluginTypesMapMobile } from '@lowdefy/build';
|
|
23
22
|
import YAML from 'yaml';
|
|
24
23
|
|
|
25
24
|
const require = createRequire(import.meta.url);
|
|
@@ -30,10 +29,19 @@ async function getPluginDefinitions({ directories }) {
|
|
|
30
29
|
lowdefyYaml = await readFile(path.join(directories.config, 'lowdefy.yml'));
|
|
31
30
|
}
|
|
32
31
|
if (!lowdefyYaml) {
|
|
33
|
-
return [];
|
|
32
|
+
return { plugins: [], shellPlugins: [] };
|
|
34
33
|
}
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
return collectPluginDefinitions({ lowdefy: YAML.parse(lowdefyYaml) });
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// A plugin only shells list may be native-only, with no ./types export: it
|
|
38
|
+
// adds no types. Root plugins must export ./types.
|
|
39
|
+
function readPluginTypes({ plugin }) {
|
|
40
|
+
if (plugin.shellOnly && !hasTypesExport({ name: plugin.name, require })) {
|
|
41
|
+
return {};
|
|
42
|
+
}
|
|
43
|
+
const types = require(`${plugin.name}/types`);
|
|
44
|
+
return types.default ?? types;
|
|
37
45
|
}
|
|
38
46
|
|
|
39
47
|
async function createCustomPluginTypesMap({ directories }) {
|
|
@@ -59,20 +67,40 @@ async function createCustomPluginTypesMap({ directories }) {
|
|
|
59
67
|
websockets: {},
|
|
60
68
|
};
|
|
61
69
|
|
|
62
|
-
const
|
|
70
|
+
const { plugins, shellPlugins } = await getPluginDefinitions({ directories });
|
|
71
|
+
const customTypesMapMobile = {
|
|
72
|
+
actions: {},
|
|
73
|
+
blockMetas: {},
|
|
74
|
+
blocks: {},
|
|
75
|
+
icons: {},
|
|
76
|
+
operators: {
|
|
77
|
+
client: {},
|
|
78
|
+
},
|
|
79
|
+
plugins: shellPlugins.map((plugin) => plugin.name),
|
|
80
|
+
};
|
|
63
81
|
|
|
64
|
-
|
|
65
|
-
|
|
82
|
+
const packageTypes = new Map();
|
|
83
|
+
for (const plugin of plugins) {
|
|
84
|
+
packageTypes.set(plugin.name, readPluginTypes({ plugin }));
|
|
66
85
|
createPluginTypesMap({
|
|
67
|
-
packageTypes:
|
|
86
|
+
packageTypes: packageTypes.get(plugin.name),
|
|
68
87
|
typesMap: customTypesMap,
|
|
69
88
|
packageName: plugin.name,
|
|
70
89
|
version: plugin.version,
|
|
71
90
|
typePrefix: plugin.typePrefix,
|
|
72
91
|
});
|
|
73
92
|
}
|
|
93
|
+
for (const plugin of shellPlugins) {
|
|
94
|
+
createPluginTypesMapMobile({
|
|
95
|
+
packageTypes: packageTypes.get(plugin.name),
|
|
96
|
+
typesMap: customTypesMapMobile,
|
|
97
|
+
packageName: plugin.name,
|
|
98
|
+
version: plugin.version,
|
|
99
|
+
typePrefix: plugin.typePrefix,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
74
102
|
|
|
75
|
-
return customTypesMap;
|
|
103
|
+
return { customTypesMap, customTypesMapMobile };
|
|
76
104
|
}
|
|
77
105
|
|
|
78
106
|
export default createCustomPluginTypesMap;
|