@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
package/next.config.js DELETED
@@ -1,34 +0,0 @@
1
- const { withSentryConfig } = require('@sentry/nextjs');
2
- const lowdefyConfig = require('./build/config.json');
3
- const blockPackages = require('./build/blockPackages.json');
4
- const agentFileSystems = require('./build/agentFileSystems.json');
5
- const serverExternalPackages = require('./build/serverExternalPackages.json');
6
-
7
- const nextConfig = {
8
- basePath: lowdefyConfig.basePath,
9
- reactStrictMode: true,
10
- transpilePackages: [
11
- '@lowdefy/client',
12
- '@ant-design/x',
13
- '@ant-design/x-markdown',
14
- ...blockPackages,
15
- ],
16
- serverExternalPackages,
17
- turbopack: {},
18
- poweredByHeader: false,
19
- // productionBrowserSourceMaps: true
20
- output: process.env.LOWDEFY_BUILD_OUTPUT_STANDALONE === '1' ? 'standalone' : undefined,
21
- outputFileTracingIncludes: agentFileSystems.length
22
- ? { '/api/agent/*': agentFileSystems.map((p) => `${p}/**/*`) }
23
- : undefined,
24
- };
25
-
26
- // Only wrap with Sentry if SENTRY_DSN is configured
27
- // This enables source map uploads when SENTRY_AUTH_TOKEN is present
28
- module.exports = process.env.SENTRY_DSN
29
- ? withSentryConfig(nextConfig, {
30
- // Sentry options
31
- silent: true,
32
- hideSourceMaps: true,
33
- })
34
- : nextConfig;
package/pages/404.js DELETED
@@ -1,49 +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, getPageConfig, getRootConfig } from '@lowdefy/api';
19
-
20
- import appMeta from '../lib/build/appMeta.js';
21
- import config from '../lib/build/config.js';
22
- import fileCache from '../lib/server/fileCache.js';
23
- import Page from '../lib/client/Page.js';
24
-
25
- export async function getStaticProps() {
26
- // Important to give absolute path so Next can trace build files
27
- const context = {
28
- appMeta,
29
- buildDirectory: path.join(process.cwd(), 'build'),
30
- config,
31
- fileCache,
32
- logger: console, // TODO: pino or console or 🤷‍♂️?
33
- };
34
- createApiContext(context);
35
-
36
- const [rootConfig, pageConfig] = await Promise.all([
37
- getRootConfig(context),
38
- getPageConfig(context, { pageId: '404' }),
39
- ]);
40
-
41
- return {
42
- props: {
43
- pageConfig,
44
- rootConfig,
45
- },
46
- };
47
- }
48
-
49
- export default Page;
@@ -1,85 +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 { getPageConfig, getRootConfig } from '@lowdefy/api';
18
-
19
- import serverSidePropsWrapper from '../lib/server/serverSidePropsWrapper.js';
20
- import Page from '../lib/client/Page.js';
21
-
22
- async function getServerSidePropsHandler({ context, nextContext }) {
23
- const segments = nextContext.params.pageId ?? [];
24
- const pageId = segments.join('/');
25
- const { logger, session } = context;
26
-
27
- if (!pageId) {
28
- const rootConfig = await getRootConfig(context);
29
- const { home } = rootConfig;
30
- if (home.configured === false) {
31
- logger.info({ event: 'redirect_to_homepage', pageId: home.pageId });
32
- return {
33
- redirect: {
34
- destination: `/${home.pageId}`,
35
- permanent: false,
36
- },
37
- };
38
- }
39
- const pageConfig = await getPageConfig(context, { pageId: home.pageId });
40
- if (!pageConfig) {
41
- logger.info({ event: 'redirect_page_not_found', pageId: home.pageId });
42
- return {
43
- redirect: {
44
- destination: '/404',
45
- permanent: false,
46
- },
47
- };
48
- }
49
- logger.info({ event: 'page_view', pageId: home.pageId });
50
- return {
51
- props: {
52
- pageConfig,
53
- rootConfig,
54
- session,
55
- },
56
- };
57
- }
58
-
59
- const [rootConfig, pageConfig] = await Promise.all([
60
- getRootConfig(context),
61
- getPageConfig(context, { pageId }),
62
- ]);
63
-
64
- if (!pageConfig) {
65
- logger.info({ event: 'redirect_page_not_found', pageId });
66
- return {
67
- redirect: {
68
- destination: '/404',
69
- permanent: false,
70
- },
71
- };
72
- }
73
- logger.info({ event: 'page_view', pageId });
74
- return {
75
- props: {
76
- pageConfig,
77
- rootConfig,
78
- session,
79
- },
80
- };
81
- }
82
-
83
- export const getServerSideProps = serverSidePropsWrapper(getServerSidePropsHandler);
84
-
85
- export default Page;
@@ -1,106 +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
- import Document, { Html, Head, Main, NextScript } from 'next/document';
19
-
20
- import appJson from '../lib/build/app.js';
21
- import lowdefyConfig from '../lib/build/config.js';
22
- import themeConfig from '../lib/build/theme.js';
23
-
24
- const basePath = lowdefyConfig.basePath ?? '';
25
- const VALID_COLOR_MODES = ['system', 'light', 'dark'];
26
- const configColorMode = VALID_COLOR_MODES.includes(themeConfig.darkMode)
27
- ? themeConfig.darkMode
28
- : 'system';
29
- const darkBg = themeConfig?.antd?.darkToken?.colorBgLayout ?? '#000';
30
- const lightBg = themeConfig?.antd?.lightToken?.colorBgLayout ?? '';
31
-
32
- // Escape characters that could break out of the enclosing <script> tag or
33
- // terminate a JS string literal. Used to defuse the js/bad-code-sanitization
34
- // class of injection for values embedded into the pre-hydration inline script.
35
- const SCRIPT_ESCAPES = {
36
- '<': '\\u003C',
37
- '>': '\\u003E',
38
- '\b': '\\b',
39
- '\f': '\\f',
40
- '\n': '\\n',
41
- '\r': '\\r',
42
- '\t': '\\t',
43
- '\0': '\\0',
44
- '\u2028': '\\u2028',
45
- '\u2029': '\\u2029',
46
- };
47
- function safeScriptJson(value) {
48
- return JSON.stringify(value).replace(/[<>\b\f\n\r\t\0\u2028\u2029]/g, (c) => SCRIPT_ESCAPES[c]);
49
- }
50
-
51
- class LowdefyDocument extends Document {
52
- render() {
53
- return (
54
- <Html className="lowdefy">
55
- <Head>
56
- {/* Synchronous script that creates the @layer order declaration and keeps
57
- it as the first child of <head> via MutationObserver. antd's CSS-in-JS
58
- uses prependQueue to inject <style> tags at the top of <head>, which
59
- would otherwise make @layer antd the first (lowest priority) layer.
60
- MutationObserver fires before paint, so the browser never sees the
61
- wrong cascade order. */}
62
- <script
63
- dangerouslySetInnerHTML={{
64
- __html: `(function(){var s=document.createElement("style");s.id="__lf-layer-order";s.textContent="@layer theme, base, antd, components, utilities;";document.head.prepend(s);new MutationObserver(function(){if(document.head.firstChild!==s)document.head.prepend(s)}).observe(document.head,{childList:true})})();`,
65
- }}
66
- />
67
- {/* Synchronous pre-hydration background script — prevents mode-mismatch
68
- flash on page navigation. Mirrors useDarkMode.js resolution order:
69
- configDarkMode → localStorage → prefers-color-scheme. Uses the user's
70
- configured colorBgLayout tokens when present (theme.antd.darkToken and
71
- theme.antd.lightToken), falling back to #000 in dark and no inline style
72
- in light so default behavior is unchanged. */}
73
- <script
74
- dangerouslySetInnerHTML={{
75
- __html: `(function(){var c=${safeScriptJson(configColorMode)};var db=${safeScriptJson(
76
- darkBg
77
- )};var lb=${safeScriptJson(
78
- lightBg
79
- )};var d;if(c==="dark")d=true;else if(c==="light")d=false;else{try{var p=localStorage.getItem("lowdefy_darkMode");if(p==="dark")d=true;else if(p==="light")d=false;else d=window.matchMedia("(prefers-color-scheme:dark)").matches}catch(e){d=window.matchMedia("(prefers-color-scheme:dark)").matches}}var bg=d?db:lb;if(bg)document.documentElement.style.backgroundColor=bg})();`,
80
- }}
81
- />
82
- <link rel="manifest" href={`${basePath}/manifest.webmanifest`} />
83
- <link rel="icon" type="image/svg+xml" href={`${basePath}/icon.svg`} />
84
- <link rel="apple-touch-icon" href={`${basePath}/apple-touch-icon.png`} />
85
- <meta name="viewport" content="width=device-width, initial-scale=1" />
86
- <script
87
- dangerouslySetInnerHTML={{
88
- __html: `/* start of Lowdefy append head */</script>${appJson.html.appendHead}<script>/* end of Lowdefy append head */`,
89
- }}
90
- />
91
- </Head>
92
- <body>
93
- <Main />
94
- <NextScript />
95
- <script
96
- dangerouslySetInnerHTML={{
97
- __html: `/* start of Lowdefy append body */</script>${appJson.html.appendBody}<script>/* end of Lowdefy append body */`,
98
- }}
99
- />
100
- </body>
101
- </Html>
102
- );
103
- }
104
- }
105
-
106
- export default LowdefyDocument;
@@ -1,37 +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 NextAuth from 'next-auth';
18
-
19
- import apiWrapper from '../../../lib/server/apiWrapper.js';
20
- import authJson from '../../../lib/build/auth.js';
21
-
22
- async function handler({ context, req, res }) {
23
- if (authJson.configured !== true) {
24
- return res.status(404).json({
25
- message: 'Auth not configured',
26
- });
27
- }
28
-
29
- // Required for emails in corporate networks, see:
30
- // https://next-auth.js.org/tutorials/avoid-corporate-link-checking-email-provider
31
- if (req.method === 'HEAD') {
32
- return res.status(200).end();
33
- }
34
- return NextAuth(req, res, context.authOptions);
35
- }
36
-
37
- export default apiWrapper(handler);
@@ -1,32 +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 { callEndpoint } from '@lowdefy/api';
18
-
19
- import apiWrapper from '../../../lib/server/apiWrapper.js';
20
-
21
- async function handler({ context, req, res }) {
22
- if (req.method !== 'POST') {
23
- throw new Error('Only POST requests are supported.');
24
- }
25
- const endpointId = req.query.endpointId.join('/');
26
- const { blockId, payload, pageId } = req.body;
27
- context.logger.info({ event: 'call_api_endpoint', blockId, endpointId, pageId });
28
- const response = await callEndpoint(context, { blockId, endpointId, pageId, payload });
29
- res.status(200).json(response);
30
- }
31
-
32
- export default apiWrapper(handler);
@@ -1,67 +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
- // TODO
18
- // import crypto from 'crypto';
19
-
20
- import packageJson from '../../package.json';
21
- import apiWrapper from '../../lib/server/apiWrapper.js';
22
- // import validateLicense from '../../lib/server/validateLicense.js';
23
-
24
- async function handler({ context, req, res }) {
25
- if (req.method !== 'POST') {
26
- throw new Error('Only POST requests are supported.');
27
- }
28
- const { user, machine } = req.body;
29
- const host = req.headers.host;
30
- context.logger.info({ event: 'log_usage', user, machine });
31
-
32
- // const license = await validateLicense();
33
- // if (license.entitlements.includes['OFFLINE']) {
34
- // return res.status(200).json({ offline: true });
35
- // }
36
- const timestamp = Date.now();
37
-
38
- // const data = [
39
- // `gitSha: ${context.appMeta.gitSha}`,
40
- // `host: ${host}`,
41
- // `license_key: ${license.id}`,
42
- // `machine: ${machine}`,
43
- // `timestamp: ${timestamp}`,
44
- // `user: ${user}`,
45
- // `version: ${packageJson.version}`,
46
- // ].join('\n');
47
-
48
- // const hmac = crypto.createHmac('sha256', process.env.LOWDEFY_LICENSE_KEY ?? 'NO_LICENSE');
49
- // hmac.update(data);
50
- // const sig = hmac.digest('base64');
51
-
52
- return res.status(200).json({
53
- offline: false,
54
- data: {
55
- gitSha: context.appMeta.gitSha,
56
- host,
57
- // license_key: license.id,
58
- machine,
59
- // sig,
60
- timestamp,
61
- user,
62
- version: packageJson.version,
63
- },
64
- });
65
- }
66
-
67
- export default apiWrapper(handler);
File without changes