@lowdefy/server-e2e 5.6.0 → 6.1.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 (45) hide show
  1. package/{pages/_app.js → client/App.jsx} +43 -28
  2. package/client/Page.jsx +110 -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 +26 -0
  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} +5 -1
  12. package/lib/server/auth/{getServerSession.js → session.js} +5 -3
  13. package/lib/server/log/createHandleError.test.mjs +126 -0
  14. package/lib/server/scrubSecrets.js +25 -0
  15. package/lowdefy/createCustomPluginTypesMap.mjs +1 -0
  16. package/lowdefy/createCustomPluginTypesMap.test.mjs +2 -0
  17. package/package.json +49 -43
  18. package/package.original.json +52 -46
  19. package/postcss.config.cjs +1 -0
  20. package/src/app.js +78 -0
  21. package/src/html/getAssets.js +45 -0
  22. package/src/html/renderPage.js +79 -0
  23. package/src/html/template.js +95 -0
  24. package/src/index.js +40 -0
  25. package/src/lib/getPathSegments.js +25 -0
  26. package/src/lib/safeScriptJson.js +38 -0
  27. package/src/middleware/apiContext.js +84 -0
  28. package/src/middleware/apiContext.test.mjs +109 -0
  29. package/src/middleware/errorHandler.js +39 -0
  30. package/src/routes/apiPage.js +37 -0
  31. package/{pages/api/client-error.js → src/routes/clientError.js} +14 -18
  32. package/{pages/api/endpoints/[...endpointId].js → src/routes/endpoints.js} +8 -7
  33. package/{pages/api/request/[...path].js → src/routes/request.js} +10 -10
  34. package/{pages/api/auth/session.js → src/routes/sessionMock.js} +4 -5
  35. package/{pages/api → src/routes}/usage.js +11 -8
  36. package/src/routes/websocket.js +46 -0
  37. package/vite.config.js +45 -0
  38. package/.eslintrc.yaml +0 -1
  39. package/lib/client/Page.js +0 -57
  40. package/lib/server/apiWrapper.js +0 -73
  41. package/lib/server/serverSidePropsWrapper.js +0 -64
  42. package/next.config.js +0 -20
  43. package/pages/404.js +0 -49
  44. package/pages/[[...pageId]].js +0 -85
  45. package/pages/_document.js +0 -108
@@ -1,73 +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, redactErrorResponse } 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 connections from '../../build/plugins/connections.js';
24
- import createLogger from './log/createLogger.js';
25
- import fileCache from './fileCache.js';
26
- import getE2eSecrets from './getE2eSecrets.js';
27
- import getServerSession from './auth/getServerSession.js';
28
- import createHandleError from './log/createHandleError.js';
29
- import logRequest from './log/logRequest.js';
30
- import operators from '../../build/plugins/operators/server.js';
31
- import jsMap from '../../build/plugins/operators/serverJsMap.js';
32
-
33
- const secrets = getE2eSecrets();
34
-
35
- function apiWrapper(handler) {
36
- return async function wrappedHandler(req, res) {
37
- const context = {
38
- // Important to give absolute path so Next can trace build files
39
- rid: uuid(),
40
- appMeta,
41
- buildDirectory: path.join(process.cwd(), 'build'),
42
- configDirectory: process.env.LOWDEFY_DIRECTORY_CONFIG || process.cwd(),
43
- config,
44
- connections,
45
- fileCache,
46
- headers: req?.headers,
47
- jsMap,
48
- handleError: async (err) => {
49
- console.error(err);
50
- },
51
- logger: console,
52
- operators,
53
- req,
54
- res,
55
- secrets,
56
- };
57
- try {
58
- context.logger = createLogger({ rid: context.rid });
59
- context.handleError = createHandleError({ context });
60
- context.session = getServerSession(context);
61
- createApiContext(context);
62
- logRequest({ context });
63
- // Await here so that if handler throws it is caught.
64
- const response = await handler({ context, req, res });
65
- return response;
66
- } catch (error) {
67
- await context.handleError(error);
68
- res.status(500).json(redactErrorResponse(context, error));
69
- }
70
- };
71
- }
72
-
73
- export default apiWrapper;
@@ -1,64 +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
-
29
- function serverSidePropsWrapper(handler) {
30
- return async function wrappedHandler(nextContext) {
31
- const context = {
32
- // Important to give absolute path so Next can trace build files
33
- rid: uuid(),
34
- appMeta,
35
- buildDirectory: path.join(process.cwd(), 'build'),
36
- configDirectory: process.env.LOWDEFY_DIRECTORY_CONFIG || process.cwd(),
37
- config,
38
- fileCache,
39
- handleError: async (err) => {
40
- console.error(err);
41
- },
42
- headers: nextContext?.req?.headers,
43
- logger: console,
44
- nextContext,
45
- req: nextContext?.req,
46
- res: nextContext?.res,
47
- };
48
- try {
49
- context.logger = createLogger({ rid: context.rid });
50
- context.handleError = createHandleError({ context });
51
- context.session = getServerSession(context);
52
- createApiContext(context);
53
- logRequest({ context });
54
- // Await here so that if handler throws it is caught.
55
- const response = await handler({ context, nextContext });
56
- return response;
57
- } catch (error) {
58
- await context.handleError(error);
59
- throw error;
60
- }
61
- };
62
- }
63
-
64
- export default serverSidePropsWrapper;
package/next.config.js DELETED
@@ -1,20 +0,0 @@
1
- const lowdefyConfig = require('./build/config.json');
2
- const blockPackages = require('./build/blockPackages.json');
3
- const serverExternalPackages = require('./build/serverExternalPackages.json');
4
-
5
- const nextConfig = {
6
- basePath: lowdefyConfig.basePath,
7
- reactStrictMode: true,
8
- transpilePackages: [
9
- '@lowdefy/client',
10
- '@ant-design/x',
11
- '@ant-design/x-markdown',
12
- ...blockPackages,
13
- ],
14
- serverExternalPackages,
15
- turbopack: {},
16
- poweredByHeader: false,
17
- output: process.env.LOWDEFY_BUILD_OUTPUT_STANDALONE === '1' ? 'standalone' : undefined,
18
- };
19
-
20
- module.exports = 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,108 +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 script setting the <html> background and
68
- color-scheme — prevents a mode-mismatch flash of the page and of
69
- browser chrome (scrollbars, form controls) on page navigation.
70
- Mirrors useDarkMode.js resolution order:
71
- configDarkMode → localStorage → prefers-color-scheme. Uses the user's
72
- configured colorBgLayout tokens when present (theme.antd.darkToken and
73
- theme.antd.lightToken), falling back to #000 in dark and no inline style
74
- in light so default behavior is unchanged. */}
75
- <script
76
- dangerouslySetInnerHTML={{
77
- __html: `(function(){var c=${safeScriptJson(configColorMode)};var db=${safeScriptJson(
78
- darkBg
79
- )};var lb=${safeScriptJson(
80
- lightBg
81
- )};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;document.documentElement.style.colorScheme=d?"dark":"light";if(bg)document.documentElement.style.backgroundColor=bg})();`,
82
- }}
83
- />
84
- <link rel="manifest" href={`${basePath}/manifest.webmanifest`} />
85
- <link rel="icon" type="image/svg+xml" href={`${basePath}/icon.svg`} />
86
- <link rel="apple-touch-icon" href={`${basePath}/apple-touch-icon.png`} />
87
- <meta name="viewport" content="width=device-width, initial-scale=1" />
88
- <script
89
- dangerouslySetInnerHTML={{
90
- __html: `/* start of Lowdefy append head */</script>${appJson.html.appendHead}<script>/* end of Lowdefy append head */`,
91
- }}
92
- />
93
- </Head>
94
- <body>
95
- <Main />
96
- <NextScript />
97
- <script
98
- dangerouslySetInnerHTML={{
99
- __html: `/* start of Lowdefy append body */</script>${appJson.html.appendBody}<script>/* end of Lowdefy append body */`,
100
- }}
101
- />
102
- </body>
103
- </Html>
104
- );
105
- }
106
- }
107
-
108
- export default LowdefyDocument;