@lowdefy/server 7.1.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 +4 -1
  20. package/lowdefy/build.test.mjs +11 -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
@@ -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`; free-form values under
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 masks credential keys in received and keeps the other received properties', () => {
133
- const received = {
134
- url: 'https://api.example.com/items',
135
- method: 'get',
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: '_step', received }),
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.received).toEqual(expectedReceived);
154
- expect(serialized.cause.received).toEqual(expectedReceived);
155
- expect(JSON.stringify(serialized)).not.toMatch(/runtime-token/);
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
- test('serializeErrorForLog projects an Error nested seven levels deep inside a cause property', () => {
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
- nested = new RequestError(`Level ${level}.`, { received: nested });
151
+ const wrapper = new RequestError(`Level ${level}.`);
152
+ wrapper.metaData = nested;
153
+ nested = wrapper;
168
154
  }
169
- // An explicit received, so the top node does not inherit the cause's.
170
- const error = new RequestError('Top.', {
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.received;
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.received;
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 { jest } from '@jest/globals';
17
+ import { vi, beforeEach, expect, test } from 'vitest';
18
18
  import { RequestError, TenantIntegrityError } from '@lowdefy/errors';
19
19
 
20
- const captureException = jest.fn();
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 and with received credential keys masked', () => {
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).toEqual({
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 { jest } from '@jest/globals';
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 = jest.fn();
35
- const nodeHttpIntegration = jest.fn(() => ({ name: 'Http' }));
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
- jest.unstable_mockModule('@sentry/node', () => {
39
+ vi.doMock('@sentry/node', () => {
40
40
  imported.node = true;
41
41
  return { init: nodeInit, httpIntegration: nodeHttpIntegration };
42
42
  });
43
- jest.unstable_mockModule('@sentry/node-core/light', () => {
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
- jest.unstable_mockModule('../../build/logger.js', () => ({ default: loggerConfig }));
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 { jest } from '@jest/globals';
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
- jest.unstable_mockModule('@sentry/node', () => ({
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
- jest.unstable_mockModule('../../build/logger.js', () => ({
51
+ vi.doMock('../../build/logger.js', () => ({
52
52
  default: { sentry: { tracesSampleRate: 1 } },
53
53
  }));
54
54
 
@@ -14,6 +14,8 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
+ import { expect, test } from 'vitest';
18
+
17
19
  const secret = 'planted/secret+value=1';
18
20
  const shortSecret = 'short77';
19
21
 
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({ directories });
42
+ const { customTypesMap, customTypesMapMobile } = await createCustomPluginTypesMap({
43
+ directories,
44
+ });
43
45
  const customMessagesMap = await createCustomPluginMessagesMap({ directories });
44
46
 
45
47
  let logger;
@@ -52,6 +54,7 @@ async function run() {
52
54
  await build({
53
55
  customMessagesMap,
54
56
  customTypesMap,
57
+ customTypesMapMobile,
55
58
  directories,
56
59
  logger,
57
60
  pluginInstallFollows: process.env.LOWDEFY_BUILD_PLUGIN_INSTALL_FOLLOWS === 'true',
@@ -14,30 +14,28 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
- import { jest } from '@jest/globals';
17
+ import { vi, afterAll, beforeEach, expect, test } from 'vitest';
18
18
 
19
- const mockBuild = jest.fn();
19
+ const mockBuild = vi.fn();
20
20
 
21
- jest.unstable_mockModule('@lowdefy/build', () => ({ default: mockBuild }));
22
- jest.unstable_mockModule('@lowdefy/logger/node', () => ({
23
- createNodeLogger: jest.fn(() => 'logger'),
21
+ vi.doMock('@lowdefy/build', () => ({ default: mockBuild }));
22
+ vi.doMock('@lowdefy/logger/node', () => ({
23
+ createNodeLogger: vi.fn(() => 'logger'),
24
24
  }));
25
- jest.unstable_mockModule('./createCustomPluginTypesMap.mjs', () => ({
26
- default: jest.fn().mockResolvedValue({}),
25
+ vi.doMock('./createCustomPluginTypesMap.mjs', () => ({
26
+ default: vi.fn().mockResolvedValue({ customTypesMap: {}, customTypesMapMobile: {} }),
27
27
  }));
28
- jest.unstable_mockModule('./createCustomPluginMessagesMap.mjs', () => ({
29
- default: jest.fn().mockResolvedValue({}),
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
33
  const savedInstallFollows = process.env.LOWDEFY_BUILD_PLUGIN_INSTALL_FOLLOWS;
34
- let loadCount = 0;
35
-
36
34
  // build.mjs runs the build when imported, so each case loads a fresh module
37
35
  // instance and waits for the build call.
38
36
  async function runScript() {
39
- loadCount += 1;
40
- await import(`./build.mjs?case=${loadCount}`);
37
+ vi.resetModules();
38
+ await import('./build.mjs');
41
39
  await new Promise((resolve) => setImmediate(resolve));
42
40
  }
43
41
 
@@ -17,8 +17,7 @@
17
17
 
18
18
  import { createRequire } from 'node:module';
19
19
  import path from 'path';
20
- import { get } from '@lowdefy/helpers';
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
- const lowdefy = YAML.parse(lowdefyYaml);
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 { get } from '@lowdefy/helpers';
21
- import { readFile } from '@lowdefy/node-utils';
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
- const lowdefy = YAML.parse(lowdefyYaml);
36
- return get(lowdefy, 'plugins', { default: [] });
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 pluginDefinitions = await getPluginDefinitions({ directories });
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
- for (const plugin of pluginDefinitions) {
65
- const types = require(`${plugin.name}/types`);
82
+ const packageTypes = new Map();
83
+ for (const plugin of plugins) {
84
+ packageTypes.set(plugin.name, readPluginTypes({ plugin }));
66
85
  createPluginTypesMap({
67
- packageTypes: types.default ?? types,
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;