@lowdefy/server 5.5.1 → 6.0.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 (62) hide show
  1. package/{pages/_app.js → client/App.jsx} +26 -34
  2. package/client/Page.jsx +109 -0
  3. package/client/main.jsx +39 -0
  4. package/lib/build/app.js +8 -1
  5. package/lib/build/appMeta.js +8 -1
  6. package/lib/build/auth.js +8 -1
  7. package/lib/build/config.js +8 -1
  8. package/lib/build/i18n.js +8 -1
  9. package/lib/build/logger.js +8 -1
  10. package/lib/build/theme.js +8 -1
  11. package/lib/client/auth/{Auth.js → Auth.jsx} +10 -2
  12. package/lib/client/auth/{AuthConfigured.js → AuthConfigured.jsx} +22 -10
  13. package/lib/client/sentry/captureSentryError.js +1 -1
  14. package/lib/client/sentry/initSentryClient.js +1 -1
  15. package/lib/client/sentry/setSentryUser.js +1 -1
  16. package/lib/server/apiWrapper.js +2 -9
  17. package/lib/server/auth/{getAuthOptions.js → getAuthConfig.js} +5 -4
  18. package/lib/server/auth/{getServerSession.js → session.js} +9 -6
  19. package/lib/server/auth/strategies.js +47 -0
  20. package/lib/server/log/createHandleError.js +15 -2
  21. package/lib/server/log/createLogger.js +18 -1
  22. package/lib/server/log/logRequest.js +41 -45
  23. package/lib/server/sentry/captureSentryError.js +1 -1
  24. package/lib/server/sentry/initSentry.js +6 -4
  25. package/lib/server/sentry/setSentryUser.js +1 -1
  26. package/lowdefy/createCustomPluginTypesMap.mjs +1 -0
  27. package/package.json +52 -39
  28. package/package.original.json +54 -41
  29. package/src/app.js +140 -0
  30. package/src/html/getAssets.js +45 -0
  31. package/src/html/renderPage.js +80 -0
  32. package/src/html/template.js +95 -0
  33. package/src/index.js +85 -0
  34. package/src/lib/getPathSegments.js +25 -0
  35. package/src/lib/safeScriptJson.js +38 -0
  36. package/src/middleware/apiContext.js +135 -0
  37. package/src/middleware/errorHandler.js +54 -0
  38. package/src/middleware/sentry.js +33 -0
  39. package/{pages/api/agent/[...path].js → src/routes/agent.js} +20 -42
  40. package/src/routes/apiPage.js +37 -0
  41. package/src/routes/auth.js +38 -0
  42. package/{pages/api/client-error.js → src/routes/clientError.js} +14 -16
  43. package/src/routes/cron.js +44 -0
  44. package/src/routes/cronForward.js +47 -0
  45. package/src/routes/detached.js +47 -0
  46. package/src/routes/endpoints.js +71 -0
  47. package/src/routes/mcp.js +34 -0
  48. package/{pages/api/request/[...path].js → src/routes/request.js} +10 -10
  49. package/src/routes/usage.js +46 -0
  50. package/src/routes/websocket.js +46 -0
  51. package/vite.config.js +61 -0
  52. package/.eslintrc.yaml +0 -1
  53. package/lib/client/Page.js +0 -56
  54. package/lib/server/serverSidePropsWrapper.js +0 -66
  55. package/next.config.js +0 -34
  56. package/pages/404.js +0 -49
  57. package/pages/[[...pageId]].js +0 -85
  58. package/pages/_document.js +0 -106
  59. package/pages/api/auth/[...nextauth].js +0 -37
  60. package/pages/api/endpoints/[...endpointId].js +0 -32
  61. package/pages/api/usage.js +0 -67
  62. /package/{postcss.config.js → postcss.config.cjs} +0 -0
@@ -0,0 +1,38 @@
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 { authHandler } from '@hono/auth-js';
18
+
19
+ import authJson from '../../lib/build/auth.js';
20
+
21
+ // Replaces pages/api/auth/[...nextauth].js. Hono routes HEAD requests through
22
+ // GET handlers, so the corporate-email pre-check branch must live inside the
23
+ // middleware, before delegating to the Auth.js handler. See:
24
+ // https://next-auth.js.org/tutorials/avoid-corporate-link-checking-email-provider
25
+ function authMiddleware() {
26
+ const handler = authJson.configured === true ? authHandler() : null;
27
+ return async function auth(c, next) {
28
+ if (authJson.configured !== true) {
29
+ return c.json({ message: 'Auth not configured' }, 404);
30
+ }
31
+ if (c.req.method === 'HEAD') {
32
+ return c.body(null, 200);
33
+ }
34
+ return handler(c, next);
35
+ };
36
+ }
37
+
38
+ export default authMiddleware;
@@ -16,34 +16,32 @@
16
16
 
17
17
  import { logClientError } from '@lowdefy/api';
18
18
 
19
- import apiWrapper from '../../lib/server/apiWrapper.js';
20
19
  import captureSentryError from '../../lib/server/sentry/captureSentryError.js';
21
20
 
22
- async function handler({ context, req, res }) {
23
- if (req.method !== 'POST') {
21
+ async function clientErrorHandler(c) {
22
+ if (c.req.method !== 'POST') {
24
23
  throw new Error('Only POST requests are supported.');
25
24
  }
25
+ const context = c.get('lowdefyContext');
26
26
 
27
- const origin = req.headers.origin;
27
+ const origin = c.req.header('origin');
28
28
  if (!origin) {
29
- res.status(403).json({ error: 'Forbidden' });
30
- return;
29
+ return c.json({ error: 'Forbidden' }, 403);
31
30
  }
32
31
  try {
33
- if (new URL(origin).host !== req.headers.host) {
34
- res.status(403).json({ error: 'Forbidden' });
35
- return;
32
+ if (new URL(origin).host !== c.req.header('host')) {
33
+ return c.json({ error: 'Forbidden' }, 403);
36
34
  }
37
35
  } catch {
38
- res.status(403).json({ error: 'Forbidden' });
39
- return;
36
+ return c.json({ error: 'Forbidden' }, 403);
40
37
  }
41
38
 
39
+ const body = await c.req.json();
42
40
  // Strip received from payload — prod doesn't need it for schema validation
43
- if (req.body?.['~e']) {
44
- delete req.body['~e'].received;
41
+ if (body?.['~e']) {
42
+ delete body['~e'].received;
45
43
  }
46
- const { error, ...response } = await logClientError(context, req.body);
44
+ const { error, ...response } = await logClientError(context, body);
47
45
 
48
46
  // Capture client error to Sentry (no-op if Sentry not configured)
49
47
  captureSentryError({
@@ -52,7 +50,7 @@ async function handler({ context, req, res }) {
52
50
  configLocation: response.source ? { source: response.source, config: response.config } : null,
53
51
  });
54
52
 
55
- res.status(200).json({ success: true });
53
+ return c.json({ success: true });
56
54
  }
57
55
 
58
- export default apiWrapper(handler);
56
+ export default clientErrorHandler;
@@ -0,0 +1,44 @@
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 { runScheduledEndpoint } from '@lowdefy/api';
18
+
19
+ import getPathSegments from '../lib/getPathSegments.js';
20
+
21
+ // Triggered by Vercel Cron: an HTTP GET to /api/cron/<endpointId>. Vercel auto-sends the value of
22
+ // the project env var named exactly CRON_SECRET as `Authorization: Bearer <value>`, and the firing
23
+ // cron expression in the `x-vercel-cron-schedule` header. Fails closed if CRON_SECRET is unset.
24
+ async function cronHandler(c) {
25
+ if (c.req.method !== 'GET') {
26
+ throw new Error('Only GET requests are supported.');
27
+ }
28
+ const context = c.get('lowdefyContext');
29
+
30
+ const secret = process.env.CRON_SECRET;
31
+ if (!secret || c.req.header('authorization') !== `Bearer ${secret}`) {
32
+ context.logger.warn({ event: 'cron_unauthorized' });
33
+ return c.json({ error: 'Unauthorized' }, 401);
34
+ }
35
+
36
+ const endpointId = getPathSegments(c, '/api/cron/').join('/');
37
+ const cron = c.req.header('x-vercel-cron-schedule');
38
+ const environment = c.req.header('x-lowdefy-cron-environment');
39
+ context.logger.info({ event: 'call_cron_endpoint', endpointId, cron, environment });
40
+ const response = await runScheduledEndpoint(context, { endpointId, cron, environment });
41
+ return c.json(response);
42
+ }
43
+
44
+ export default cronHandler;
@@ -0,0 +1,47 @@
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 { forwardScheduledEndpoint } from '@lowdefy/api';
18
+
19
+ import getPathSegments from '../lib/getPathSegments.js';
20
+
21
+ // Triggered by Vercel Cron on the production deployment: an HTTP GET to
22
+ // /api/cron-forward/<environment>/<endpointId>, registered by `lowdefy vercel-output` for the
23
+ // schedules of every environment declared with a url in config.cron.environments. Vercel fires crons
24
+ // only on production, so production pings that environment's own /api/cron/<endpointId> (with the
25
+ // environment's CRON_SECRET) and answers immediately. Same transport auth as cron (CRON_SECRET,
26
+ // fails closed).
27
+ async function cronForwardHandler(c) {
28
+ if (c.req.method !== 'GET') {
29
+ throw new Error('Only GET requests are supported.');
30
+ }
31
+ const context = c.get('lowdefyContext');
32
+
33
+ const secret = process.env.CRON_SECRET;
34
+ if (!secret || c.req.header('authorization') !== `Bearer ${secret}`) {
35
+ context.logger.warn({ event: 'cron_forward_unauthorized' });
36
+ return c.json({ error: 'Unauthorized' }, 401);
37
+ }
38
+
39
+ const [environment, ...endpointSegments] = getPathSegments(c, '/api/cron-forward/');
40
+ const endpointId = endpointSegments.join('/');
41
+ const cron = c.req.header('x-vercel-cron-schedule');
42
+ context.logger.info({ event: 'call_cron_forward', environment, endpointId, cron });
43
+ const response = await forwardScheduledEndpoint(context, { environment, endpointId, cron });
44
+ return c.json(response);
45
+ }
46
+
47
+ export default cronForwardHandler;
@@ -0,0 +1,47 @@
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 { runDetachedEndpoint } from '@lowdefy/api';
18
+
19
+ import getPathSegments from '../lib/getPathSegments.js';
20
+
21
+ // Target of a CallApi step with `detached: true`: the calling invocation
22
+ // fire-and-forgets a POST here, so the endpoint runs in its OWN function
23
+ // invocation with a fresh duration budget (chainable bounded work without a
24
+ // queue). Same transport auth as cron (CRON_SECRET, fails closed) and the same
25
+ // system execution context — InternalApi endpoints are callable, `_user` is
26
+ // undefined. Delivery is at-most-once with no retry: targets must be
27
+ // idempotent.
28
+ async function detachedHandler(c) {
29
+ if (c.req.method !== 'POST') {
30
+ throw new Error('Only POST requests are supported.');
31
+ }
32
+ const context = c.get('lowdefyContext');
33
+
34
+ const secret = process.env.CRON_SECRET;
35
+ if (!secret || c.req.header('authorization') !== `Bearer ${secret}`) {
36
+ context.logger.warn({ event: 'detached_unauthorized' });
37
+ return c.json({ error: 'Unauthorized' }, 401);
38
+ }
39
+
40
+ const endpointId = getPathSegments(c, '/api/detached/').join('/');
41
+ const { payload } = await c.req.json();
42
+ context.logger.info({ event: 'call_detached_endpoint', endpointId });
43
+ const response = await runDetachedEndpoint(context, { endpointId, payload });
44
+ return c.json(response);
45
+ }
46
+
47
+ export default detachedHandler;
@@ -0,0 +1,71 @@
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 { callEndpoint, getEndpointConfig, runWebhookEndpoint } from '@lowdefy/api';
18
+
19
+ import getPathSegments from '../lib/getPathSegments.js';
20
+
21
+ async function endpointsHandler(c) {
22
+ if (c.req.method !== 'POST') {
23
+ throw new Error('Only POST requests are supported.');
24
+ }
25
+ const context = c.get('lowdefyContext');
26
+ const endpointId = getPathSegments(c, '/api/endpoints/').join('/');
27
+
28
+ // Endpoints opting in with `webhook: true` are third-party webhook receivers
29
+ // (SNS, Event Grid, Stripe, ...): they take the request RAW — body in the
30
+ // caller's own format (not the { payload } envelope), plus query + headers —
31
+ // and their return value is sent back verbatim, because webhook handshakes
32
+ // (e.g. Event Grid's validationResponse) require exact response shapes.
33
+ // The config lookup is a cached file read; an unknown endpoint falls through
34
+ // to the standard path so its error shape is unchanged. Everything about
35
+ // non-webhook endpoints is untouched.
36
+ let endpointConfig = null;
37
+ try {
38
+ endpointConfig = await getEndpointConfig(context, { endpointId });
39
+ } catch {
40
+ /* unknown endpoint — the standard path below reports it exactly as before */
41
+ }
42
+ if (endpointConfig?.webhook === true) {
43
+ // SNS posts JSON as text/plain — parse regardless of content-type; an
44
+ // unparseable body arrives as the raw string.
45
+ const raw = await c.req.text();
46
+ let body = raw;
47
+ try {
48
+ body = JSON.parse(raw);
49
+ } catch {
50
+ /* non-JSON body — raw string passthrough */
51
+ }
52
+ context.logger.info({ event: 'call_webhook_endpoint', endpointId });
53
+ const result = await runWebhookEndpoint(context, {
54
+ endpointId,
55
+ body,
56
+ query: c.req.query(),
57
+ headers: c.req.header(),
58
+ });
59
+ if (!result.success) {
60
+ return c.json({ error: 'Webhook failed.' }, 500);
61
+ }
62
+ return c.json(result.response ?? { ok: true });
63
+ }
64
+
65
+ const { blockId, payload, pageId } = await c.req.json();
66
+ context.logger.info({ event: 'call_api_endpoint', blockId, endpointId, pageId });
67
+ const response = await callEndpoint(context, { blockId, endpointId, pageId, payload });
68
+ return c.json(response);
69
+ }
70
+
71
+ export default endpointsHandler;
@@ -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 { StreamableHTTPTransport } from '@hono/mcp';
18
+ import { createMcpServer } from '@lowdefy/api';
19
+
20
+ // Stateless per-request MCP server over the app's configured endpoints. The
21
+ // apiContext middleware has already resolved the caller's session, so tool
22
+ // listing and calls are authorized per request.
23
+ async function mcpHandler(c) {
24
+ const context = c.get('lowdefyContext');
25
+ const server = await createMcpServer({ context });
26
+ if (!server) {
27
+ return c.json({ error: 'MCP is not configured.' }, 404);
28
+ }
29
+ const transport = new StreamableHTTPTransport();
30
+ await server.connect(transport);
31
+ return transport.handleRequest(c);
32
+ }
33
+
34
+ export default mcpHandler;
@@ -16,23 +16,23 @@
16
16
 
17
17
  import { callRequest } from '@lowdefy/api';
18
18
 
19
- import apiWrapper from '../../../lib/server/apiWrapper.js';
19
+ import getPathSegments from '../lib/getPathSegments.js';
20
20
 
21
- async function handler({ context, req, res }) {
22
- if (req.method !== 'POST') {
21
+ async function requestHandler(c) {
22
+ if (c.req.method !== 'POST') {
23
23
  throw new Error('Only POST requests are supported.');
24
24
  }
25
- const segments = req.query.path;
26
- if (!Array.isArray(segments) || segments.length < 2) {
27
- res.status(400).json({ error: 'Invalid request path' });
28
- return;
25
+ const context = c.get('lowdefyContext');
26
+ const segments = getPathSegments(c, '/api/request/');
27
+ if (segments.length < 2) {
28
+ return c.json({ error: 'Invalid request path' }, 400);
29
29
  }
30
30
  const requestId = segments[segments.length - 1];
31
31
  const pageId = segments.slice(0, -1).join('/');
32
- const { actionId, blockId, payload } = req.body;
32
+ const { actionId, blockId, payload } = await c.req.json();
33
33
  context.logger.info({ event: 'call_request', pageId, requestId, blockId, actionId });
34
34
  const response = await callRequest(context, { blockId, pageId, payload, requestId });
35
- res.status(200).json(response);
35
+ return c.json(response);
36
36
  }
37
37
 
38
- export default apiWrapper(handler);
38
+ export default requestHandler;
@@ -0,0 +1,46 @@
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 fs from 'node:fs';
18
+ import path from 'node:path';
19
+
20
+ const packageJson = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'package.json'), 'utf8'));
21
+
22
+ async function usageHandler(c) {
23
+ if (c.req.method !== 'POST') {
24
+ throw new Error('Only POST requests are supported.');
25
+ }
26
+ const context = c.get('lowdefyContext');
27
+ const { user, machine } = await c.req.json();
28
+ const host = c.req.header('host');
29
+ context.logger.info({ event: 'log_usage', user, machine });
30
+
31
+ const timestamp = Date.now();
32
+
33
+ return c.json({
34
+ offline: false,
35
+ data: {
36
+ gitSha: context.appMeta.gitSha,
37
+ host,
38
+ machine,
39
+ timestamp,
40
+ user,
41
+ version: packageJson.version,
42
+ },
43
+ });
44
+ }
45
+
46
+ export default usageHandler;
@@ -0,0 +1,46 @@
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 { upgradeWebSocket } from '@hono/node-server';
18
+ import { createChannelRegistry, createWebSocketConnection } from '@lowdefy/api';
19
+
20
+ // One registry per server process — channels and their running source
21
+ // resolvers are shared across all websocket connections on this instance.
22
+ const registry = createChannelRegistry();
23
+
24
+ const websocketHandler = upgradeWebSocket((c) => {
25
+ const context = c.get('lowdefyContext');
26
+ let connection;
27
+ return {
28
+ onOpen(event, ws) {
29
+ connection = createWebSocketConnection(context, {
30
+ registry,
31
+ send: (message) => ws.send(message),
32
+ });
33
+ },
34
+ onMessage(event) {
35
+ connection?.handleMessage(event.data);
36
+ },
37
+ onClose() {
38
+ connection?.close();
39
+ },
40
+ onError(event) {
41
+ context.logger.debug({ event: 'ws_error' }, String(event?.error ?? 'WebSocket error'));
42
+ },
43
+ };
44
+ });
45
+
46
+ export default websocketHandler;
package/vite.config.js ADDED
@@ -0,0 +1,61 @@
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 fs from 'node:fs';
18
+ import { defineConfig } from 'vite';
19
+ import react from '@vitejs/plugin-react';
20
+ import { sentryVitePlugin } from '@sentry/vite-plugin';
21
+
22
+ // basePath from the Lowdefy build — assets are served under it.
23
+ let basePath = '';
24
+ try {
25
+ const config = JSON.parse(fs.readFileSync('./build/config.json', 'utf8'));
26
+ basePath = config.basePath ?? '';
27
+ } catch (e) {
28
+ // No build yet (e.g. editor tooling) — default base.
29
+ }
30
+
31
+ const uploadSourceMaps = Boolean(process.env.SENTRY_AUTH_TOKEN);
32
+
33
+ export default defineConfig(({ mode }) => ({
34
+ base: `${basePath}/`,
35
+ plugins: [
36
+ react(),
37
+ uploadSourceMaps &&
38
+ sentryVitePlugin({
39
+ org: process.env.SENTRY_ORG,
40
+ project: process.env.SENTRY_PROJECT,
41
+ authToken: process.env.SENTRY_AUTH_TOKEN,
42
+ }),
43
+ ].filter(Boolean),
44
+ define: {
45
+ // Vite does not replace process.env.NODE_ENV inside dependencies —
46
+ // plugin and client code branch on it.
47
+ 'process.env.NODE_ENV': JSON.stringify(mode === 'production' ? 'production' : 'development'),
48
+ },
49
+ build: {
50
+ outDir: 'dist/client',
51
+ manifest: true,
52
+ sourcemap: uploadSourceMaps,
53
+ rollupOptions: {
54
+ input: 'client/main.jsx',
55
+ },
56
+ },
57
+ resolve: {
58
+ // linked plugin packages (pnpm link: / workspace) must share one React.
59
+ dedupe: ['react', 'react-dom'],
60
+ },
61
+ }));
package/.eslintrc.yaml DELETED
@@ -1 +0,0 @@
1
- extends: 'plugin:@next/next/core-web-vitals'
@@ -1,56 +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 React from 'react';
18
-
19
- import { useRouter } from 'next/router';
20
- import Client from '@lowdefy/client';
21
- import Head from 'next/head';
22
- import Link from 'next/link';
23
-
24
- import actions from '../../build/plugins/actions.js';
25
- import blockMetas from '../../build/plugins/blockMetas.json';
26
- import blocks from '../../build/plugins/blocks.js';
27
- import icons from '../../build/plugins/icons.js';
28
- import operators from '../../build/plugins/operators/client.js';
29
- import jsMap from '../../build/plugins/operators/clientJsMap.js';
30
-
31
- const Page = ({ auth, lowdefy, pageConfig, rootConfig }) => {
32
- const router = useRouter();
33
- return (
34
- <Client
35
- auth={auth}
36
- Components={{ Head, Link }}
37
- config={{
38
- pageConfig,
39
- rootConfig,
40
- }}
41
- jsMap={jsMap}
42
- lowdefy={lowdefy}
43
- router={router}
44
- types={{
45
- actions,
46
- blockMetas,
47
- blocks,
48
- icons,
49
- operators,
50
- }}
51
- window={window}
52
- />
53
- );
54
- };
55
-
56
- export default Page;
@@ -1,66 +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 path from 'path';
18
- import { createApiContext } from '@lowdefy/api';
19
- import { v4 as uuid } from 'uuid';
20
-
21
- import appMeta from '../build/appMeta.js';
22
- import config from '../build/config.js';
23
- import createLogger from './log/createLogger.js';
24
- import fileCache from './fileCache.js';
25
- import getServerSession from './auth/getServerSession.js';
26
- import createHandleError from './log/createHandleError.js';
27
- import logRequest from './log/logRequest.js';
28
- import getAuthOptions from './auth/getAuthOptions.js';
29
-
30
- // TODO: Merge serverSidePropsWrapper and apiWrapper?
31
- function serverSidePropsWrapper(handler) {
32
- return async function wrappedHandler(nextContext) {
33
- const context = {
34
- // Important to give absolute path so Next can trace build files
35
- rid: uuid(),
36
- appMeta,
37
- buildDirectory: path.join(process.cwd(), 'build'),
38
- config,
39
- fileCache,
40
- handleError: async (err) => {
41
- console.error(err);
42
- },
43
- headers: nextContext?.req?.headers,
44
- logger: console,
45
- nextContext,
46
- req: nextContext?.req,
47
- res: nextContext?.res,
48
- };
49
- try {
50
- context.logger = createLogger({ rid: context.rid });
51
- context.handleError = createHandleError({ context });
52
- context.authOptions = getAuthOptions(context);
53
- context.session = await getServerSession(context);
54
- createApiContext(context);
55
- logRequest({ context });
56
- // Await here so that if handler throws it is caught.
57
- const response = await handler({ context, nextContext });
58
- return response;
59
- } catch (error) {
60
- await context.handleError(error);
61
- throw error;
62
- }
63
- };
64
- }
65
-
66
- export default serverSidePropsWrapper;