@lowdefy/server-e2e 0.0.0-experimental-20260720072521 → 0.0.0-experimental-20260720135014

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 (44) hide show
  1. package/.eslintrc.yaml +1 -0
  2. package/lib/build/app.js +1 -8
  3. package/lib/build/appMeta.js +1 -8
  4. package/lib/build/auth.js +1 -8
  5. package/lib/build/config.js +1 -8
  6. package/lib/build/logger.js +1 -8
  7. package/lib/build/theme.js +1 -8
  8. package/lib/client/Page.js +57 -0
  9. package/{src/lib/getPathSegments.js → lib/client/auth/Auth.js} +22 -7
  10. package/lib/server/apiWrapper.js +80 -0
  11. package/lib/server/auth/{getUser.js → getServerSession.js} +7 -10
  12. package/lib/server/log/logRequest.js +3 -1
  13. package/lib/server/serverSidePropsWrapper.js +64 -0
  14. package/lowdefy/createCustomPluginTypesMap.mjs +2 -3
  15. package/lowdefy/createCustomPluginTypesMap.test.mjs +0 -2
  16. package/next.config.js +20 -0
  17. package/package.json +41 -50
  18. package/package.original.json +49 -53
  19. package/pages/404.js +49 -0
  20. package/pages/[[...pageId]].js +85 -0
  21. package/{client/App.jsx → pages/_app.js} +30 -45
  22. package/pages/_document.js +106 -0
  23. package/{src/routes/sessionMock.js → pages/api/auth/session.js} +5 -7
  24. package/{src/routes/clientError.js → pages/api/client-error.js} +18 -14
  25. package/{src/routes/endpoints.js → pages/api/endpoints/[...endpointId].js} +7 -8
  26. package/{src/routes/request.js → pages/api/request/[...path].js} +10 -10
  27. package/{src/routes → pages/api}/usage.js +8 -11
  28. package/client/Page.jsx +0 -93
  29. package/client/main.jsx +0 -39
  30. package/lib/build/i18n.js +0 -26
  31. package/lib/client/auth/Auth.jsx +0 -69
  32. package/postcss.config.cjs +0 -1
  33. package/src/app.js +0 -80
  34. package/src/html/getAssets.js +0 -45
  35. package/src/html/renderPage.js +0 -78
  36. package/src/html/template.js +0 -94
  37. package/src/index.js +0 -40
  38. package/src/lib/safeScriptJson.js +0 -38
  39. package/src/middleware/apiContext.js +0 -87
  40. package/src/middleware/errorHandler.js +0 -45
  41. package/src/routes/apiPage.js +0 -35
  42. package/src/routes/user.js +0 -27
  43. package/src/routes/websocket.js +0 -46
  44. package/vite.config.js +0 -45
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/server-e2e",
3
- "version": "0.0.0-experimental-20260720072521",
3
+ "version": "0.0.0-experimental-20260720135014",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Lowdefy e2e testing server with cookie-based user injection",
6
6
  "homepage": "https://lowdefy.com",
@@ -30,81 +30,77 @@
30
30
  "files": [
31
31
  "lib/*",
32
32
  "lowdefy/*",
33
+ "pages/*",
33
34
  "public_default/*",
35
+ "next.config.js",
34
36
  "package.original.json",
35
37
  ".eslintrc.yaml",
36
- ".npmrc",
37
- "src/*",
38
- "client/*",
39
- "vite.config.js",
40
- "postcss.config.cjs"
38
+ ".npmrc"
41
39
  ],
42
40
  "scripts": {
43
41
  "build": "cp package.json package.original.json || copy package.json package.original.json",
44
- "build:client": "vite build",
45
42
  "build:lowdefy": "node lowdefy/build.mjs",
46
- "prepublishOnly": "pnpm build",
47
- "start": "node src/index.js",
48
- "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
43
+ "build:next": "next build",
44
+ "dev": "next dev",
45
+ "start": "next start",
46
+ "lint": "next lint",
47
+ "next": "next",
48
+ "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
49
+ "prepublishOnly": "pnpm build"
49
50
  },
50
51
  "dependencies": {
51
52
  "@ant-design/cssinjs": "2.1.2",
52
- "@ant-design/x": "2.7.0",
53
- "@hono/node-server": "2.0.4",
54
- "@lowdefy/actions-core": "0.0.0-experimental-20260720072521",
55
- "@lowdefy/api": "0.0.0-experimental-20260720072521",
56
- "@lowdefy/block-utils": "0.0.0-experimental-20260720072521",
57
- "@lowdefy/blocks-aggrid": "0.0.0-experimental-20260720072521",
58
- "@lowdefy/blocks-antd": "0.0.0-experimental-20260720072521",
59
- "@lowdefy/blocks-antd-x": "0.0.0-experimental-20260720072521",
60
- "@lowdefy/blocks-basic": "0.0.0-experimental-20260720072521",
61
- "@lowdefy/blocks-captcha": "0.0.0-experimental-20260720072521",
62
- "@lowdefy/blocks-echarts": "0.0.0-experimental-20260720072521",
63
- "@lowdefy/blocks-loaders": "0.0.0-experimental-20260720072521",
64
- "@lowdefy/blocks-markdown": "0.0.0-experimental-20260720072521",
65
- "@lowdefy/blocks-tiptap": "0.0.0-experimental-20260720072521",
66
- "@lowdefy/client": "0.0.0-experimental-20260720072521",
67
- "@lowdefy/connection-axios-http": "0.0.0-experimental-20260720072521",
68
- "@lowdefy/connection-mongodb": "0.0.0-experimental-20260720072521",
69
- "@lowdefy/errors": "0.0.0-experimental-20260720072521",
70
- "@lowdefy/helpers": "0.0.0-experimental-20260720072521",
71
- "@lowdefy/layout": "0.0.0-experimental-20260720072521",
72
- "@lowdefy/logger": "0.0.0-experimental-20260720072521",
73
- "@lowdefy/node-utils": "0.0.0-experimental-20260720072521",
74
- "@lowdefy/operators-js": "0.0.0-experimental-20260720072521",
75
- "@lowdefy/operators-nunjucks": "0.0.0-experimental-20260720072521",
76
- "@lowdefy/operators-uuid": "0.0.0-experimental-20260720072521",
77
- "@lowdefy/websockets-core": "0.0.0-experimental-20260720072521",
78
- "@tailwindcss/postcss": "4.3.1",
79
- "@vitejs/plugin-react": "6.0.2",
53
+ "@lowdefy/actions-core": "0.0.0-experimental-20260720135014",
54
+ "@lowdefy/api": "0.0.0-experimental-20260720135014",
55
+ "@lowdefy/block-utils": "0.0.0-experimental-20260720135014",
56
+ "@lowdefy/blocks-antd": "0.0.0-experimental-20260720135014",
57
+ "@lowdefy/blocks-antd-x": "0.0.0-experimental-20260720135014",
58
+ "@lowdefy/blocks-basic": "0.0.0-experimental-20260720135014",
59
+ "@lowdefy/blocks-loaders": "0.0.0-experimental-20260720135014",
60
+ "@lowdefy/blocks-markdown": "0.0.0-experimental-20260720135014",
61
+ "@lowdefy/blocks-tiptap": "0.0.0-experimental-20260720135014",
62
+ "@lowdefy/client": "0.0.0-experimental-20260720135014",
63
+ "@lowdefy/connection-axios-http": "0.0.0-experimental-20260720135014",
64
+ "@lowdefy/connection-mongodb": "0.0.0-experimental-20260720135014",
65
+ "@lowdefy/errors": "0.0.0-experimental-20260720135014",
66
+ "@lowdefy/helpers": "0.0.0-experimental-20260720135014",
67
+ "@lowdefy/layout": "0.0.0-experimental-20260720135014",
68
+ "@lowdefy/logger": "0.0.0-experimental-20260720135014",
69
+ "@lowdefy/node-utils": "0.0.0-experimental-20260720135014",
70
+ "@lowdefy/operators-js": "0.0.0-experimental-20260720135014",
71
+ "@lowdefy/operators-nunjucks": "0.0.0-experimental-20260720135014",
72
+ "@lowdefy/operators-uuid": "0.0.0-experimental-20260720135014",
73
+ "@tailwindcss/postcss": "4.2.1",
80
74
  "antd": "6.3.1",
81
- "dayjs": "1.11.20",
82
- "hono": "4.12.25",
83
- "pino": "10.3.1",
75
+ "dayjs": "1.11.19",
76
+ "next": "16.1.6",
77
+ "pino": "8.16.2",
84
78
  "react": "18.2.0",
85
79
  "react-dom": "18.2.0",
86
80
  "react-icons": "5.6.0",
87
- "tailwindcss": "4.3.1",
88
- "uuid": "14.0.0",
89
- "vite": "8.0.16",
90
- "ws": "8.18.0"
81
+ "tailwindcss": "4.2.1",
82
+ "uuid": "13.0.0"
91
83
  },
92
84
  "devDependencies": {
93
85
  "@jest/globals": "28.1.3",
94
- "@lowdefy/build": "0.0.0-experimental-20260720072521",
86
+ "@lowdefy/build": "0.0.0-experimental-20260720135014",
95
87
  "@next/eslint-plugin-next": "16.1.6",
96
- "@tailwindcss/postcss": "4.3.1",
88
+ "@tailwindcss/postcss": "4.2.1",
97
89
  "jest": "28.1.3",
98
- "tailwindcss": "4.3.1",
90
+ "tailwindcss": "4.2.1",
99
91
  "webpack": "5.94.0",
100
- "yaml": "2.9.0",
101
- "yargs": "18.0.0"
92
+ "yaml": "2.3.4",
93
+ "yargs": "17.7.2"
102
94
  },
103
95
  "engines": {
104
- "node": ">=22"
96
+ "node": ">=18"
97
+ },
98
+ "pnpm": {
99
+ "onlyBuiltDependencies": [
100
+ "better-sqlite3"
101
+ ]
105
102
  },
106
103
  "publishConfig": {
107
104
  "access": "public"
108
- },
109
- "type": "module"
105
+ }
110
106
  }
package/pages/404.js ADDED
@@ -0,0 +1,49 @@
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;
@@ -0,0 +1,85 @@
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;
@@ -14,20 +14,24 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
+ // CSS layer order — MUST be the first CSS import. Next.js treats this as critical
18
+ // CSS that loads before hydration, locking the cascade priority (antd > base/preflight)
19
+ // before antd's StyleProvider injects @layer antd {} at runtime.
20
+ import '../build/layer-order.css';
21
+
17
22
  import React, { useCallback, useRef } from 'react';
23
+ import dynamic from 'next/dynamic';
18
24
 
19
25
  import { ErrorBoundary } from '@lowdefy/block-utils';
20
- import { useDarkMode, useLocale } from '@lowdefy/client';
26
+ import { useDarkMode } from '@lowdefy/client';
21
27
  import { StyleProvider } from '@ant-design/cssinjs';
22
- import { App as AntdApp, theme as antdTheme } from 'antd';
23
- import { XProvider } from '@ant-design/x';
28
+ import { App as AntdApp, ConfigProvider, theme as antdTheme } from 'antd';
24
29
 
25
- import antdLocaleLoaders from '../build/i18n/antdLocales.js';
26
- import antdXLocaleLoaders from '../build/i18n/antdXLocales.js';
27
- import dayjsLocaleMap from '../build/i18n/dayjsLocales.js';
28
- import Auth from '../lib/client/auth/Auth.jsx';
30
+ import Auth from '../lib/client/auth/Auth.js';
29
31
  import createLogUsage from '../lib/client/createLogUsage.js';
30
- import Page from './Page.jsx';
32
+
33
+ // Must be in _app due to next specifications.
34
+ import '../build/globals.css';
31
35
 
32
36
  function ThemeTokenResolver({ lowdefyRef, children }) {
33
37
  const { token } = antdTheme.useToken();
@@ -38,9 +42,7 @@ function ThemeTokenResolver({ lowdefyRef, children }) {
38
42
  return children;
39
43
  }
40
44
 
41
- function App({ config }) {
42
- const { rootConfig, user } = config;
43
-
45
+ function App({ Component, pageProps: { session, rootConfig, pageConfig } }) {
44
46
  const usageDataRef = useRef({});
45
47
  const lowdefyRef = useRef({ eventCallback: createLogUsage({ usageDataRef }) });
46
48
  if (rootConfig?.theme) {
@@ -52,21 +54,6 @@ function App({ config }) {
52
54
  configDarkMode: lowdefyRef.current.theme?.darkMode,
53
55
  });
54
56
 
55
- const {
56
- active: activeLocale,
57
- antdLocale,
58
- antdXLocale,
59
- } = useLocale({
60
- i18n: rootConfig?.i18n,
61
- antdLocaleLoaders,
62
- antdXLocaleLoaders,
63
- dayjsLocaleMap,
64
- });
65
-
66
- if (rootConfig?.i18n?.defaultLocale) {
67
- lowdefyRef.current.i18n = { ...rootConfig.i18n, active: activeLocale };
68
- }
69
-
70
57
  const {
71
58
  lightToken: _lightToken,
72
59
  darkToken: _darkToken,
@@ -83,22 +70,9 @@ function App({ config }) {
83
70
  }
84
71
  }, []);
85
72
 
86
- // XProvider extends antd's ConfigProvider; merging antd + antd-X locale packs
87
- // gives X components (Bubble, Sender, Conversations, ...) their built-in strings
88
- // alongside antd's. antd X ships only en_US + zh_CN; other locales fall back
89
- // to en_US for X-native strings.
90
- const mergedLocale =
91
- antdLocale || antdXLocale ? { ...(antdLocale ?? {}), ...(antdXLocale ?? {}) } : undefined;
92
-
93
73
  return (
94
74
  <StyleProvider layer>
95
- <XProvider
96
- locale={mergedLocale}
97
- form={
98
- antdLocale?.Form?.defaultValidateMessages
99
- ? { validateMessages: antdLocale.Form.defaultValidateMessages }
100
- : undefined
101
- }
75
+ <ConfigProvider
102
76
  theme={{
103
77
  ...antdConfig,
104
78
  token,
@@ -111,18 +85,29 @@ function App({ config }) {
111
85
  <AntdApp>
112
86
  <ThemeTokenResolver lowdefyRef={lowdefyRef}>
113
87
  <ErrorBoundary fullPage onError={handleError}>
114
- <Auth user={user}>
88
+ <Auth session={session}>
115
89
  {(auth) => {
116
- usageDataRef.current.user = auth.user?.id;
117
- return <Page auth={auth} config={config} lowdefy={lowdefyRef.current} />;
90
+ usageDataRef.current.user = auth.session?.hashed_id;
91
+ return (
92
+ <Component
93
+ auth={auth}
94
+ lowdefy={lowdefyRef.current}
95
+ rootConfig={rootConfig}
96
+ pageConfig={pageConfig}
97
+ />
98
+ );
118
99
  }}
119
100
  </Auth>
120
101
  </ErrorBoundary>
121
102
  </ThemeTokenResolver>
122
103
  </AntdApp>
123
- </XProvider>
104
+ </ConfigProvider>
124
105
  </StyleProvider>
125
106
  );
126
107
  }
127
108
 
128
- export default App;
109
+ const DynamicApp = dynamic(() => Promise.resolve(App), {
110
+ ssr: false,
111
+ });
112
+
113
+ export default DynamicApp;
@@ -0,0 +1,106 @@
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;
@@ -14,12 +14,10 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
- async function sessionMockHandler(c) {
18
- const context = c.get('lowdefyContext');
19
- if (!context.user) {
20
- return c.json(null);
21
- }
22
- return c.json({ session: { id: 'e2e' }, user: context.user });
17
+ import apiWrapper from '../../../lib/server/apiWrapper.js';
18
+
19
+ async function handler({ context, req, res }) {
20
+ return res.status(200).json(context.session ?? {});
23
21
  }
24
22
 
25
- export default sessionMockHandler;
23
+ export default apiWrapper(handler);
@@ -16,32 +16,36 @@
16
16
 
17
17
  import { logClientError } from '@lowdefy/api';
18
18
 
19
- async function clientErrorHandler(c) {
20
- if (c.req.method !== 'POST') {
19
+ import apiWrapper from '../../lib/server/apiWrapper.js';
20
+
21
+ async function handler({ context, req, res }) {
22
+ if (req.method !== 'POST') {
21
23
  throw new Error('Only POST requests are supported.');
22
24
  }
23
- const context = c.get('lowdefyContext');
24
25
 
25
- const origin = c.req.header('origin');
26
+ const origin = req.headers.origin;
26
27
  if (!origin) {
27
- return c.json({ error: 'Forbidden' }, 403);
28
+ res.status(403).json({ error: 'Forbidden' });
29
+ return;
28
30
  }
29
31
  try {
30
- if (new URL(origin).host !== c.req.header('host')) {
31
- return c.json({ error: 'Forbidden' }, 403);
32
+ if (new URL(origin).host !== req.headers.host) {
33
+ res.status(403).json({ error: 'Forbidden' });
34
+ return;
32
35
  }
33
36
  } catch {
34
- return c.json({ error: 'Forbidden' }, 403);
37
+ res.status(403).json({ error: 'Forbidden' });
38
+ return;
35
39
  }
36
40
 
37
- const body = await c.req.json();
38
41
  // Strip received from payload — prod doesn't need it for schema validation
39
- if (body?.['~e']) {
40
- delete body['~e'].received;
42
+ if (req.body?.['~e']) {
43
+ delete req.body['~e'].received;
41
44
  }
42
- await logClientError(context, body);
45
+ // eslint-disable-next-line no-unused-vars
46
+ const { error, ...response } = await logClientError(context, req.body);
43
47
 
44
- return c.json({ success: true });
48
+ res.status(200).json({ success: true });
45
49
  }
46
50
 
47
- export default clientErrorHandler;
51
+ export default apiWrapper(handler);
@@ -16,18 +16,17 @@
16
16
 
17
17
  import { callEndpoint } from '@lowdefy/api';
18
18
 
19
- import getPathSegments from '../lib/getPathSegments.js';
19
+ import apiWrapper from '../../../lib/server/apiWrapper.js';
20
20
 
21
- async function endpointsHandler(c) {
22
- if (c.req.method !== 'POST') {
21
+ async function handler({ context, req, res }) {
22
+ if (req.method !== 'POST') {
23
23
  throw new Error('Only POST requests are supported.');
24
24
  }
25
- const context = c.get('lowdefyContext');
26
- const endpointId = getPathSegments(c, '/api/endpoints/').join('/');
27
- const { blockId, payload, pageId } = await c.req.json();
25
+ const endpointId = req.query.endpointId.join('/');
26
+ const { blockId, payload, pageId } = req.body;
28
27
  context.logger.info({ event: 'call_api_endpoint', blockId, endpointId, pageId });
29
28
  const response = await callEndpoint(context, { blockId, endpointId, pageId, payload });
30
- return c.json(response);
29
+ res.status(200).json(response);
31
30
  }
32
31
 
33
- export default endpointsHandler;
32
+ export default apiWrapper(handler);
@@ -16,23 +16,23 @@
16
16
 
17
17
  import { callRequest } from '@lowdefy/api';
18
18
 
19
- import getPathSegments from '../lib/getPathSegments.js';
19
+ import apiWrapper from '../../../lib/server/apiWrapper.js';
20
20
 
21
- async function requestHandler(c) {
22
- if (c.req.method !== 'POST') {
21
+ async function handler({ context, req, res }) {
22
+ if (req.method !== 'POST') {
23
23
  throw new Error('Only POST requests are supported.');
24
24
  }
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);
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;
29
29
  }
30
30
  const requestId = segments[segments.length - 1];
31
31
  const pageId = segments.slice(0, -1).join('/');
32
- const { actionId, blockId, payload } = await c.req.json();
32
+ const { actionId, blockId, payload } = req.body;
33
33
  context.logger.info({ event: 'call_request', pageId, requestId, blockId, actionId });
34
34
  const response = await callRequest(context, { blockId, pageId, payload, requestId });
35
- return c.json(response);
35
+ res.status(200).json(response);
36
36
  }
37
37
 
38
- export default requestHandler;
38
+ export default apiWrapper(handler);