@lowdefy/server-dev 5.6.0 → 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 (214) hide show
  1. package/{pages/_app.js → client/App.jsx} +21 -33
  2. package/client/DevStreamContext.js +30 -0
  3. package/client/Inspector.jsx +226 -0
  4. package/{lib/client/Page.js → client/Page.jsx} +4 -8
  5. package/client/Reload.jsx +85 -0
  6. package/client/Routing.jsx +117 -0
  7. package/client/feedback/FeedbackMount.jsx +83 -0
  8. package/client/feedback/FeedbackOverlay.jsx +901 -0
  9. package/client/feedback/captureTabScreenshot.js +84 -0
  10. package/client/feedback/copyToClipboard.js +45 -0
  11. package/client/feedback/drawAnnotationsSvg.js +119 -0
  12. package/client/feedback/elementInspect.js +99 -0
  13. package/client/feedback/feedbackStyles.js +301 -0
  14. package/client/feedback/pinResponsiveImages.js +59 -0
  15. package/client/feedback/sendFeedback.js +39 -0
  16. package/client/feedback/useFeedbackToggle.js +70 -0
  17. package/client/main.jsx +42 -0
  18. package/client/openInEditor/OpenInEditorListener.jsx +268 -0
  19. package/client/openInEditor/findBlockLocation.js +51 -0
  20. package/lib/build/app.js +8 -1
  21. package/lib/build/appMeta.js +8 -1
  22. package/lib/build/auth.js +8 -1
  23. package/lib/build/config.js +8 -1
  24. package/lib/build/i18n.js +8 -1
  25. package/lib/build/logger.js +8 -1
  26. package/lib/build/theme.js +8 -1
  27. package/lib/client/auth/{Auth.js → Auth.jsx} +11 -2
  28. package/lib/client/auth/{AuthConfigured.js → AuthConfigured.jsx} +23 -10
  29. package/lib/client/setPageId.js +6 -5
  30. package/lib/client/utils/useMutateCache.js +14 -1
  31. package/lib/client/utils/usePageConfig.js +45 -43
  32. package/lib/client/utils/usePageConfig.test.mjs +62 -0
  33. package/lib/docs/captureAnnotatedScreenshot.js +88 -0
  34. package/lib/docs/checkpointPaths.js +91 -0
  35. package/lib/docs/checkpointStore.js +240 -0
  36. package/lib/docs/checkpointToMocks.js +65 -0
  37. package/lib/docs/clientErrorStore.js +36 -0
  38. package/lib/docs/configCheckpoints.test.mjs +156 -0
  39. package/lib/docs/createConfigCheckpoint.js +92 -0
  40. package/lib/docs/createDocsMcpServer.js +531 -0
  41. package/lib/docs/createDocsMcpServer.test.mjs +141 -0
  42. package/lib/docs/devMockRegistry.js +68 -0
  43. package/lib/docs/docs.test.mjs +448 -0
  44. package/lib/docs/enrichFeedback.js +71 -0
  45. package/lib/docs/evalOperator.js +47 -0
  46. package/lib/docs/evalOperator.test.mjs +157 -0
  47. package/lib/docs/evalOperatorHeadless.js +87 -0
  48. package/lib/docs/evalOperatorHeadless.test.mjs +72 -0
  49. package/lib/docs/evalOperatorInTab.js +48 -0
  50. package/lib/docs/findConfig.js +260 -0
  51. package/lib/docs/formatFeedback.js +121 -0
  52. package/lib/docs/formatFeedback.test.mjs +204 -0
  53. package/lib/docs/getAppMap.js +180 -0
  54. package/lib/docs/getBrowser.js +127 -0
  55. package/lib/docs/getBrowser.test.mjs +122 -0
  56. package/lib/docs/getBuildStatus.js +37 -0
  57. package/lib/docs/getCoreDoc.js +63 -0
  58. package/lib/docs/getDocsManifest.js +40 -0
  59. package/lib/docs/getExamples.js +58 -0
  60. package/lib/docs/getOverview.js +115 -0
  61. package/lib/docs/getPageConfig.js +53 -0
  62. package/lib/docs/getPluginDoc.js +55 -0
  63. package/lib/docs/getSchema.js +65 -0
  64. package/lib/docs/inspectState.js +47 -0
  65. package/lib/docs/inspectState.test.mjs +140 -0
  66. package/lib/docs/inspectStateFromTab.js +40 -0
  67. package/lib/docs/inspectStateHeadless.js +84 -0
  68. package/lib/docs/inspectStateHeadless.test.mjs +60 -0
  69. package/lib/docs/isWriteRequestsAllowed.js +50 -0
  70. package/lib/docs/listConfigCheckpoints.js +55 -0
  71. package/lib/docs/listPlugins.js +80 -0
  72. package/lib/docs/listTypes.js +105 -0
  73. package/lib/docs/loadState.js +152 -0
  74. package/lib/docs/mapPageBuildErrors.js +28 -0
  75. package/lib/docs/normalizeTypeKind.js +40 -0
  76. package/{pages/api/endpoints/[...endpointId].js → lib/docs/readBuildArtifact.js} +15 -12
  77. package/lib/docs/readPageArtifact.js +26 -0
  78. package/lib/docs/resolvePluginDir.js +49 -0
  79. package/lib/docs/resolveSource.js +48 -0
  80. package/lib/docs/resolveSource.test.mjs +100 -0
  81. package/lib/docs/revertConfigCheckpoint.js +73 -0
  82. package/lib/docs/runRequest.js +141 -0
  83. package/lib/docs/saveAnnotatedScreenshot.js +43 -0
  84. package/lib/docs/scaffoldPage.js +75 -0
  85. package/lib/docs/scaffoldPage.test.mjs +97 -0
  86. package/lib/docs/screenshotPage.js +110 -0
  87. package/lib/docs/screenshotPage.test.mjs +59 -0
  88. package/lib/docs/screenshotPageClip.test.mjs +102 -0
  89. package/lib/docs/searchDocs.js +67 -0
  90. package/lib/docs/setupTestFixtures.mjs +335 -0
  91. package/lib/docs/snapshotState.js +59 -0
  92. package/lib/docs/stateCheckpoints.test.mjs +366 -0
  93. package/lib/docs/tabAvailable.js +28 -0
  94. package/lib/docs/tabChannel.js +119 -0
  95. package/lib/docs/tabChannel.test.mjs +130 -0
  96. package/lib/server/auth/{getAuthOptions.js → getAuthConfig.js} +7 -4
  97. package/lib/server/auth/getDevSession.js +70 -0
  98. package/lib/server/auth/getDevSession.test.mjs +138 -0
  99. package/lib/server/auth/getHeadlessUser.js +40 -0
  100. package/lib/server/auth/{getMockSession.js → getMockUser.js} +8 -21
  101. package/lib/server/auth/headlessUser.js +29 -0
  102. package/lib/server/auth/resolveHeadlessUser.js +38 -0
  103. package/lib/server/auth/resolveHeadlessUser.test.mjs +78 -0
  104. package/lib/server/auth/session.js +39 -0
  105. package/lib/server/auth/strategies.js +47 -0
  106. package/lib/server/createLowdefyContext.js +122 -0
  107. package/lib/server/getPageJitEnrichment.test.mjs +105 -0
  108. package/lib/server/jitPageBuilder.js +125 -12
  109. package/lib/server/log/createHandleError.test.mjs +126 -0
  110. package/manager/getContext.mjs +3 -7
  111. package/manager/processes/initialBuild.mjs +0 -2
  112. package/manager/processes/installPlugins.mjs +19 -11
  113. package/manager/processes/lowdefyBuild.mjs +29 -7
  114. package/manager/processes/lowdefyBuild.test.mjs +102 -0
  115. package/manager/processes/readDotEnv.mjs +13 -1
  116. package/manager/processes/shutdownServer.mjs +6 -6
  117. package/manager/processes/startProxy.mjs +160 -0
  118. package/manager/processes/startProxy.test.mjs +102 -0
  119. package/manager/processes/startServer.mjs +33 -16
  120. package/manager/processes/startWatchers.mjs +2 -2
  121. package/manager/processes/warnAuthUrlPortMismatch.mjs +47 -0
  122. package/manager/processes/warnAuthUrlPortMismatch.test.mjs +93 -0
  123. package/manager/run.mjs +50 -0
  124. package/manager/utils/createCustomPluginMessagesMap.mjs +8 -1
  125. package/manager/utils/createCustomPluginTypesMap.mjs +1 -0
  126. package/manager/utils/formatNoticeBox.mjs +30 -0
  127. package/manager/utils/{getNextBin.mjs → getViteBin.mjs} +7 -10
  128. package/manager/utils/updatePageTailwindCss.mjs +7 -1
  129. package/manager/utils/writeBuildStatus.mjs +39 -0
  130. package/manager/utils/writeBuildStatus.test.mjs +76 -0
  131. package/manager/watchers/lowdefyBuildWatcher.mjs +0 -1
  132. package/manager/watchers/moduleBuildWatcher.mjs +0 -1
  133. package/manager/watchers/{nextBuildWatcher.mjs → serverArtifactWatcher.mjs} +18 -20
  134. package/package.json +61 -47
  135. package/package.original.json +64 -50
  136. package/postcss.config.cjs +1 -0
  137. package/src/app.js +175 -0
  138. package/src/html/renderDevPage.js +86 -0
  139. package/src/lib/getPathSegments.js +25 -0
  140. package/src/lib/safeScriptJson.js +38 -0
  141. package/src/middleware/apiContext.js +32 -0
  142. package/src/middleware/errorHandler.js +48 -0
  143. package/src/middleware/errorHandler.test.mjs +235 -0
  144. package/src/routes/agent.js +64 -0
  145. package/src/routes/apiPage.js +37 -0
  146. package/src/routes/auth.js +49 -0
  147. package/src/routes/auth.test.mjs +84 -0
  148. package/src/routes/clientError.js +57 -0
  149. package/src/routes/cron.js +47 -0
  150. package/src/routes/cronForward.js +47 -0
  151. package/src/routes/detached.js +47 -0
  152. package/src/routes/devInspect.js +111 -0
  153. package/src/routes/devInspect.test.mjs +119 -0
  154. package/{pages/[[...pageId]].js → src/routes/devTools.js} +4 -2
  155. package/{pages/404.js → src/routes/docs/appMap.js} +6 -2
  156. package/{pages/api/dev-tools.js → src/routes/docs/buildStatus.js} +5 -4
  157. package/src/routes/docs/checkpointsCreate.js +28 -0
  158. package/src/routes/docs/checkpointsList.js +23 -0
  159. package/{pages/api/icons/dynamic.js → src/routes/docs/checkpointsRevert.js} +11 -12
  160. package/src/routes/docs/content.js +31 -0
  161. package/src/routes/docs/evalOperator.js +56 -0
  162. package/src/routes/docs/examples.js +33 -0
  163. package/src/routes/docs/find.js +30 -0
  164. package/src/routes/docs/index.js +23 -0
  165. package/src/routes/docs/inspectState.js +44 -0
  166. package/src/routes/docs/loadState.js +49 -0
  167. package/src/routes/docs/mcp.js +30 -0
  168. package/src/routes/docs/pageConfig.js +36 -0
  169. package/src/routes/docs/parseUserParam.js +52 -0
  170. package/src/routes/docs/parseUserParam.test.mjs +45 -0
  171. package/src/routes/docs/pluginDoc.js +33 -0
  172. package/src/routes/docs/plugins.js +23 -0
  173. package/src/routes/docs/runRequest.js +36 -0
  174. package/{lib/server/auth/getServerSession.js → src/routes/docs/schema.js} +17 -15
  175. package/src/routes/docs/screenshot.js +72 -0
  176. package/src/routes/docs/search.js +27 -0
  177. package/src/routes/docs/snapshotState.js +36 -0
  178. package/src/routes/docs/stateCheckpointsList.js +26 -0
  179. package/src/routes/docs/types.js +33 -0
  180. package/src/routes/endpoints.js +71 -0
  181. package/src/routes/feedback.js +110 -0
  182. package/src/routes/feedback.test.mjs +204 -0
  183. package/src/routes/jitPage.js +86 -0
  184. package/src/routes/mcp.js +34 -0
  185. package/{pages/api → src/routes}/ping.js +4 -2
  186. package/src/routes/reload.js +79 -0
  187. package/src/routes/request.js +74 -0
  188. package/src/routes/request.test.mjs +124 -0
  189. package/{pages/api → src/routes}/root.js +4 -4
  190. package/src/routes/usage.js +46 -0
  191. package/src/routes/websocket.js +33 -0
  192. package/src/websocket/devWebSocket.js +78 -0
  193. package/vite.config.js +111 -0
  194. package/.eslintrc.yaml +0 -1
  195. package/lib/client/App.js +0 -80
  196. package/lib/client/Reload.js +0 -60
  197. package/lib/server/apiWrapper.js +0 -109
  198. package/lib/server/compileCss.js +0 -39
  199. package/manager/processes/compileCss.mjs +0 -54
  200. package/manager/processes/nextBuild.mjs +0 -50
  201. package/next.config.js +0 -25
  202. package/pages/_document.js +0 -109
  203. package/pages/api/agent/[...path].js +0 -86
  204. package/pages/api/auth/[...nextauth].js +0 -48
  205. package/pages/api/client-error.js +0 -45
  206. package/pages/api/js/[env].js +0 -42
  207. package/pages/api/page/[...pageId].js +0 -74
  208. package/pages/api/reload.js +0 -53
  209. package/pages/api/request/[...path].js +0 -41
  210. /package/lib/client/{BuildErrorPage.js → BuildErrorPage.jsx} +0 -0
  211. /package/lib/client/{BuildingPage.js → BuildingPage.jsx} +0 -0
  212. /package/lib/client/{ErrorBar.js → ErrorBar.jsx} +0 -0
  213. /package/lib/client/{InstallingPluginsPage.js → InstallingPluginsPage.jsx} +0 -0
  214. /package/lib/client/{RestartingPage.js → RestartingPage.jsx} +0 -0
@@ -1,109 +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
- <link id="tailwind-jit-css" rel="stylesheet" href={`${basePath}/tailwind-jit.css`} />
88
- <meta name="viewport" content="width=device-width, initial-scale=1" />
89
- <script
90
- dangerouslySetInnerHTML={{
91
- __html: `/* start of Lowdefy append head */</script>${appJson.html.appendHead}<script>/* end of Lowdefy append head */`,
92
- }}
93
- />
94
- </Head>
95
- <body>
96
- <Main />
97
- <NextScript />
98
- <script
99
- dangerouslySetInnerHTML={{
100
- __html: `/* start of Lowdefy append body */</script>${appJson.html.appendBody}<script>/* end of Lowdefy append body */`,
101
- }}
102
- />
103
- </body>
104
- </Html>
105
- );
106
- }
107
- }
108
-
109
- export default LowdefyDocument;
@@ -1,86 +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 { callAgent } from '@lowdefy/api';
18
- import { translate, type } from '@lowdefy/helpers';
19
-
20
- import apiWrapper from '../../../lib/server/apiWrapper.js';
21
-
22
- async function handler({ context, req, res }) {
23
- const t = (key, values) => translate({ key, values, i18n: context.i18n });
24
- if (req.method !== 'POST') {
25
- throw new Error(t('agent.runtime.methodNotAllowed'));
26
- }
27
- const segments = req.query.path;
28
- if (!Array.isArray(segments) || segments.length < 2) {
29
- res.status(400).json({ error: t('agent.runtime.invalidPath') });
30
- return;
31
- }
32
- const agentId = segments[segments.length - 1];
33
- const pageId = segments.slice(0, -1).join('/');
34
- context.logger.info({ color: 'gray' }, `Agent: ${pageId} → ${agentId}`);
35
- const { conversationId } = req.query;
36
- const { messages, urlQuery, sharedState } = req.body;
37
- if (!Array.isArray(messages)) {
38
- res.status(400).json({ error: t('agent.runtime.messagesMustBeArray') });
39
- return;
40
- }
41
- if (urlQuery != null && (typeof urlQuery !== 'object' || Array.isArray(urlQuery))) {
42
- res.status(400).json({ error: t('agent.runtime.urlQueryMustBeObject') });
43
- return;
44
- }
45
- if (sharedState != null && !type.isObject(sharedState)) {
46
- res.status(400).json({ error: t('agent.runtime.sharedStateMustBeObject') });
47
- return;
48
- }
49
- const { response: webResponse } = await callAgent(context, {
50
- agentId,
51
- pageId,
52
- messages,
53
- conversationId: conversationId ?? undefined,
54
- sharedState: sharedState ?? undefined,
55
- urlQuery: urlQuery ?? undefined,
56
- });
57
-
58
- // Stream the Web Response body to the Next.js response
59
- res.setHeader('Content-Type', 'text/event-stream');
60
- res.setHeader('Cache-Control', 'no-cache');
61
- res.setHeader('Connection', 'keep-alive');
62
- res.setHeader('Content-Encoding', 'none');
63
- res.setHeader('Transfer-Encoding', 'chunked');
64
-
65
- const reader = webResponse.body.getReader();
66
- const decoder = new TextDecoder();
67
- let done = false;
68
- while (!done) {
69
- const { value, done: readerDone } = await reader.read();
70
- done = readerDone;
71
- if (value) {
72
- res.write(decoder.decode(value, { stream: true }));
73
- }
74
- }
75
- res.end();
76
- }
77
-
78
- export const config = {
79
- api: {
80
- bodyParser: {
81
- sizeLimit: '10mb',
82
- },
83
- },
84
- };
85
-
86
- export default apiWrapper(handler);
@@ -1,48 +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
- import getMockSession from '../../../lib/server/auth/getMockSession.js';
22
-
23
- async function handler({ context, req, res }) {
24
- if (authJson.configured !== true) {
25
- return res.status(404).json({
26
- message: 'Auth not configured',
27
- });
28
- }
29
-
30
- // Required for emails in corporate networks, see:
31
- // https://next-auth.js.org/tutorials/avoid-corporate-link-checking-email-provider
32
- if (req.method === 'HEAD') {
33
- return res.status(200).end();
34
- }
35
-
36
- // Return mock session for session requests (dev server only)
37
- const nextauthPath = req.query.nextauth ?? [];
38
- if (nextauthPath[0] === 'session') {
39
- const mockSession = await getMockSession();
40
- if (mockSession) {
41
- return res.status(200).json(mockSession);
42
- }
43
- }
44
-
45
- return NextAuth(req, res, context.authOptions);
46
- }
47
-
48
- export default apiWrapper(handler);
@@ -1,45 +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 { logClientError } 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
-
26
- const origin = req.headers.origin;
27
- if (!origin) {
28
- res.status(403).json({ error: 'Forbidden' });
29
- return;
30
- }
31
- try {
32
- if (new URL(origin).host !== req.headers.host) {
33
- res.status(403).json({ error: 'Forbidden' });
34
- return;
35
- }
36
- } catch {
37
- res.status(403).json({ error: 'Forbidden' });
38
- return;
39
- }
40
-
41
- const { error, ...response } = await logClientError(context, req.body);
42
- res.status(200).json(response);
43
- }
44
-
45
- export default apiWrapper(handler);
@@ -1,42 +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 fs from 'fs';
18
- import path from 'path';
19
-
20
- async function handler(req, res) {
21
- const { env } = req.query;
22
-
23
- if (env !== 'client' && env !== 'server') {
24
- res.status(400).send('Invalid env parameter. Use "client" or "server".');
25
- return;
26
- }
27
-
28
- const fileName = env === 'client' ? 'clientJsMap.js' : 'serverJsMap.js';
29
- const filePath = path.join(process.cwd(), 'build', 'plugins', 'operators', fileName);
30
-
31
- try {
32
- const content = fs.readFileSync(filePath, 'utf8');
33
- res.setHeader('Content-Type', 'application/javascript');
34
- res.status(200).send(content);
35
- } catch {
36
- // Return empty default export if file doesn't exist yet
37
- res.setHeader('Content-Type', 'application/javascript');
38
- res.status(200).send('export default {};');
39
- }
40
- }
41
-
42
- export default handler;
@@ -1,74 +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 } from '@lowdefy/api';
18
-
19
- import apiWrapper from '../../../lib/server/apiWrapper.js';
20
- import buildPageIfNeeded from '../../../lib/server/jitPageBuilder.js';
21
-
22
- async function handler({ context, req, res }) {
23
- const pageId = req.query.pageId.join('/');
24
-
25
- // Attempt JIT build if page not yet compiled
26
- let buildResult;
27
- try {
28
- buildResult = await buildPageIfNeeded({
29
- pageId,
30
- buildDirectory: context.buildDirectory,
31
- configDirectory: context.configDirectory,
32
- });
33
- } catch (error) {
34
- const rawErrors = error.buildErrors ?? [error];
35
- const errors = [];
36
- for (const err of rawErrors) {
37
- await context.handleError(err);
38
- errors.push({
39
- type: err.name ?? 'Error',
40
- message: err.message,
41
- source: err.source ?? null,
42
- stack: err.stack ?? null,
43
- });
44
- }
45
- res.status(500).json({
46
- buildError: true,
47
- errors,
48
- // Keep top-level message/source for backward compatibility
49
- message: error.message,
50
- source: error.source ?? null,
51
- });
52
- return;
53
- }
54
-
55
- if (buildResult && buildResult.installing) {
56
- res.status(200).json({
57
- installing: true,
58
- packages: buildResult.packages,
59
- });
60
- return;
61
- }
62
-
63
- const pageConfig = await getPageConfig(context, { pageId });
64
- if (pageConfig === null) {
65
- res.status(404).send('Page not found.');
66
- } else {
67
- if (buildResult?.warnings?.length > 0) {
68
- pageConfig._warnings = buildResult.warnings;
69
- }
70
- res.status(200).json(pageConfig);
71
- }
72
- }
73
-
74
- export default apiWrapper(handler);
@@ -1,53 +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 chokidar from 'chokidar';
18
-
19
- const handler = async (req, res) => {
20
- res.setHeader('Content-Type', 'text/event-stream;charset=utf-8');
21
- res.setHeader('Cache-Control', 'no-cache, no-transform');
22
- res.setHeader('X-Accel-Buffering', 'no');
23
- res.setHeader('Connection', 'keep-alive');
24
-
25
- const watcher = chokidar.watch(['./build/reload'], {
26
- persistent: true,
27
- ignoreInitial: true,
28
- });
29
-
30
- const reload = () => {
31
- try {
32
- res.write(`event: reload\ndata: ${JSON.stringify({})}\n\n`);
33
- } catch (e) {
34
- console.error(e);
35
- }
36
- };
37
- watcher.on('add', () => reload());
38
- watcher.on('change', () => reload());
39
- // Do not reload on unlink — cleanBuildDirectory deletes build/reload during
40
- // skeleton rebuilds, which would send a premature SSE event before the new
41
- // build artifacts are written. The real reload comes via add/change when
42
- // reloadClients() creates the file after the build completes.
43
-
44
- // TODO: This isn't working.
45
- req.on('close', () => {
46
- console.log('req closed');
47
- watcher.close().then(() => {
48
- console.log('watcher closed');
49
- });
50
- });
51
- };
52
-
53
- export default handler;
@@ -1,41 +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 { callRequest } 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 segments = req.query.path;
26
- if (!Array.isArray(segments) || segments.length < 2) {
27
- res.status(400).json({ error: 'Invalid request path' });
28
- return;
29
- }
30
- const requestId = segments[segments.length - 1];
31
- const pageId = segments.slice(0, -1).join('/');
32
- const { actionId, blockId, payload } = req.body;
33
- context.logger.info(
34
- { color: 'gray' },
35
- `Request: ${pageId} · ${blockId} · ${actionId} → ${requestId}`
36
- );
37
- const response = await callRequest(context, { blockId, pageId, payload, requestId });
38
- res.status(200).json(response);
39
- }
40
-
41
- export default apiWrapper(handler);
File without changes