@lowdefy/server-dev 0.0.0-alpha.7 → 0.0.0-experimental-20231123101256

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 (80) hide show
  1. package/.eslintrc.yaml +1 -0
  2. package/.npmrc +1 -0
  3. package/LICENSE +201 -0
  4. package/README.md +5 -0
  5. package/lib/client/App.js +68 -0
  6. package/lib/client/Page.js +51 -0
  7. package/lib/client/Reload.js +55 -0
  8. package/lib/client/RestartingPage.js +47 -0
  9. package/lib/client/auth/Auth.js +35 -0
  10. package/lib/client/auth/AuthConfigured.js +61 -0
  11. package/lib/client/auth/AuthNotConfigured.js +33 -0
  12. package/lib/client/setPageId.js +30 -0
  13. package/lib/client/utils/request.js +38 -0
  14. package/lib/client/utils/useMutateCache.js +25 -0
  15. package/lib/client/utils/usePageConfig.js +27 -0
  16. package/lib/client/utils/useRootConfig.js +26 -0
  17. package/lib/client/utils/waitForRestartedServer.js +38 -0
  18. package/lib/server/apiWrapper.js +68 -0
  19. package/lib/server/auth/getAuthOptions.js +35 -0
  20. package/lib/server/auth/getServerSession.js +28 -0
  21. package/lib/server/fileCache.js +20 -0
  22. package/lib/server/log/createLogger.js +29 -0
  23. package/lib/server/log/logError.js +40 -0
  24. package/lib/server/log/logRequest.js +33 -0
  25. package/manager/getContext.mjs +77 -0
  26. package/manager/processes/initialBuild.mjs +27 -0
  27. package/manager/processes/installPlugins.mjs +31 -0
  28. package/manager/processes/lowdefyBuild.mjs +35 -0
  29. package/manager/processes/nextBuild.mjs +31 -0
  30. package/manager/processes/readDotEnv.mjs +26 -0
  31. package/manager/processes/reloadClients.mjs +26 -0
  32. package/manager/processes/restartServer.mjs +28 -0
  33. package/manager/processes/shutdownServer.mjs +35 -0
  34. package/manager/processes/startServer.mjs +46 -0
  35. package/manager/processes/startWatchers.mjs +31 -0
  36. package/manager/run.mjs +109 -0
  37. package/manager/utils/BatchChanges.mjs +64 -0
  38. package/manager/utils/createCustomPluginTypesMap.mjs +80 -0
  39. package/manager/utils/createLogger.mjs +33 -0
  40. package/manager/utils/createStdOutLineHandler.mjs +33 -0
  41. package/manager/utils/getLowdefyVersion.mjs +51 -0
  42. package/manager/utils/getNextBin.mjs +36 -0
  43. package/manager/utils/setupWatcher.mjs +50 -0
  44. package/manager/watchers/envWatcher.mjs +35 -0
  45. package/manager/watchers/lowdefyBuildWatcher.mjs +55 -0
  46. package/manager/watchers/nextBuildWatcher.mjs +108 -0
  47. package/next.config.js +31 -0
  48. package/package.json +67 -38
  49. package/package.original.json +98 -0
  50. package/pages/404.js +19 -0
  51. package/pages/[pageId].js +19 -0
  52. package/pages/_app.js +42 -0
  53. package/pages/_document.js +54 -0
  54. package/pages/api/auth/[...nextauth].js +37 -0
  55. package/pages/api/page/[pageId].js +32 -0
  56. package/pages/api/ping.js +19 -0
  57. package/pages/api/reload.js +50 -0
  58. package/pages/api/request/[pageId]/[requestId].js +32 -0
  59. package/pages/api/root.js +25 -0
  60. package/pages/index.js +19 -0
  61. package/public_default/favicon.ico +0 -0
  62. package/CHANGELOG.md +0 -19
  63. package/dist/server.js +0 -55
  64. package/dist/shell/_yarn_cache_object-assign-npm-4_1_1-1004ad6dec-66cf021898_zip_node_modules_object-assign_index_js.js +0 -22
  65. package/dist/shell/index.html +0 -34
  66. package/dist/shell/main.js +0 -623
  67. package/dist/shell/public/icon-32.png +0 -0
  68. package/dist/shell/src_shell_bootstrap_js.js +0 -517
  69. package/dist/shell/vendors-_yarn_cache_object-assign-npm-4_1_1-1004ad6dec-66cf021898_zip_node_modules_object-ass-b18854.js +0 -66
  70. package/dist/shell/vendors-_yarn_cache_react-npm-17_0_1-98658812fc-a76d86ec97_zip_node_modules_react_index_js.js +0 -33
  71. package/dist/shell/vendors-_yarn_virtual_ajv-errors-virtual-6c363fa7a9_0_cache_ajv-errors-npm-1_0_1-32cd0b19f8-d-940326.js +0 -996
  72. package/dist/shell/vendors-_yarn_virtual_react-dom-virtual-2d0751dec5_0_cache_react-dom-npm-17_0_1-588d0088ca-6a-73f198.js +0 -33
  73. /package/{dist/shell/public → public_default}/apple-touch-icon.png +0 -0
  74. /package/{dist/shell/public → public_default}/icon-512.png +0 -0
  75. /package/{dist/shell/public → public_default}/icon.svg +0 -0
  76. /package/{dist/shell/public → public_default}/logo-dark-theme.png +0 -0
  77. /package/{dist/shell/public → public_default}/logo-light-theme.png +0 -0
  78. /package/{dist/shell/public → public_default}/logo-square-dark-theme.png +0 -0
  79. /package/{dist/shell/public → public_default}/logo-square-light-theme.png +0 -0
  80. /package/{dist/shell/public → public_default}/manifest.webmanifest +0 -0
@@ -0,0 +1,108 @@
1
+ /*
2
+ Copyright 2020-2023 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 crypto from 'crypto';
18
+ import path from 'path';
19
+ import { readFile } from '@lowdefy/node-utils';
20
+ import { type } from '@lowdefy/helpers';
21
+ import setupWatcher from '../utils/setupWatcher.mjs';
22
+
23
+ const hashes = {};
24
+
25
+ const trackedFiles = [
26
+ 'build/app.json',
27
+ 'build/auth.json',
28
+ 'build/config.json',
29
+ 'build/plugins/actions.js',
30
+ 'build/plugins/auth/adapters.js',
31
+ 'build/plugins/auth/callbacks.js',
32
+ 'build/plugins/auth/events.js',
33
+ 'build/plugins/auth/providers.js',
34
+ 'build/plugins/blocks.js',
35
+ 'build/plugins/connections.js',
36
+ 'build/plugins/icons.js',
37
+ 'build/plugins/operators/client.js',
38
+ 'build/plugins/operators/server.js',
39
+ 'build/plugins/styles.less',
40
+ 'public/styles.less',
41
+ 'package.json',
42
+ ];
43
+
44
+ async function sha1(filePath) {
45
+ let content = await readFile(filePath);
46
+ if (filePath.endsWith('.json')) {
47
+ content = JSON.stringify(
48
+ JSON.parse(content, (_, value) => {
49
+ if (!type.isObject(value)) return value;
50
+ delete value['~k'];
51
+ return value;
52
+ })
53
+ );
54
+ }
55
+ return crypto
56
+ .createHash('sha1')
57
+ .update(content || '')
58
+ .digest('base64');
59
+ }
60
+
61
+ async function nextBuildWatcher(context) {
62
+ // Initialize hashes so that app does not rebuild the first time
63
+ // Lowdefy build is run.
64
+ await Promise.all(
65
+ trackedFiles.map(async (filePath) => {
66
+ hashes[filePath] = await sha1(filePath);
67
+ })
68
+ );
69
+
70
+ const callback = async () => {
71
+ let install = false;
72
+ let build = false;
73
+ await Promise.all(
74
+ trackedFiles.map(async (filePath) => {
75
+ const hash = await sha1(filePath);
76
+ if (hashes[filePath] === hash) {
77
+ return;
78
+ }
79
+ build = true;
80
+ if (filePath.endsWith('package.json')) {
81
+ install = true;
82
+ }
83
+ hashes[filePath] = hash;
84
+ })
85
+ );
86
+ if (!build) {
87
+ context.logger.info({ print: 'succeed' }, 'Reloaded app.');
88
+ return;
89
+ }
90
+
91
+ context.shutdownServer();
92
+ if (install) {
93
+ context.logger.warn('Plugin dependencies have changed and will be reinstalled.');
94
+ await context.installPlugins();
95
+ }
96
+ await context.nextBuild();
97
+ context.restartServer();
98
+ };
99
+
100
+ return setupWatcher({
101
+ callback,
102
+ context,
103
+ watchDotfiles: true,
104
+ watchPaths: [path.join(context.directories.server, 'package.json')],
105
+ });
106
+ }
107
+
108
+ export default nextBuildWatcher;
package/next.config.js ADDED
@@ -0,0 +1,31 @@
1
+ const withLess = require('next-with-less');
2
+ const lowdefyConfig = require('./build/config.json');
3
+
4
+ module.exports = withLess({
5
+ basePath: lowdefyConfig.basePath,
6
+ // reactStrictMode: true,
7
+ webpack: (config, { isServer }) => {
8
+ if (!isServer) {
9
+ config.resolve.fallback = {
10
+ assert: false,
11
+ buffer: false,
12
+ crypto: false,
13
+ events: false,
14
+ fs: false,
15
+ path: false,
16
+ process: require.resolve('process/browser'),
17
+ util: false,
18
+ };
19
+ }
20
+ return config;
21
+ },
22
+ swcMinify: false,
23
+ compress: false,
24
+ outputFileTracing: false,
25
+ poweredByHeader: false,
26
+ generateEtags: false,
27
+ optimizeFonts: false,
28
+ eslint: {
29
+ ignoreDuringBuilds: true,
30
+ },
31
+ });
package/package.json CHANGED
@@ -1,9 +1,13 @@
1
1
  {
2
2
  "name": "@lowdefy/server-dev",
3
- "version": "0.0.0-alpha.7",
3
+ "version": "0.0.0-experimental-20231123101256",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
7
+ "keywords": [
8
+ "lowdefy",
9
+ "server"
10
+ ],
7
11
  "bugs": {
8
12
  "url": "https://github.com/lowdefy/lowdefy/issues"
9
13
  },
@@ -22,48 +26,73 @@
22
26
  "url": "https://github.com/lowdefy/lowdefy.git"
23
27
  },
24
28
  "files": [
25
- "dist/*"
29
+ "lib/*",
30
+ "manager/*",
31
+ "pages/*",
32
+ "public_default/*",
33
+ "next.config.js",
34
+ "package.original.json",
35
+ ".eslintrc.yaml",
36
+ ".npmrc"
26
37
  ],
27
- "scripts": {
28
- "babel": "babel src --out-dir dist",
29
- "build": "yarn webpack && yarn babel",
30
- "clean": "rm -rf dist && rm -rf dev",
31
- "prepublishOnly": "yarn build",
32
- "start": "nodemon dist/server.js",
33
- "version:prerelease": "yarn version prerelease",
34
- "version:patch": "yarn version patch",
35
- "version:minor": "yarn version minor",
36
- "version:major": "yarn version major",
37
- "webpack": "webpack --config webpack.config.js"
38
- },
39
38
  "dependencies": {
40
- "@lowdefy/graphql": "0.0.0-alpha.7",
41
- "@lowdefy/node-utils": "1.0.2",
42
- "apollo-server-express": "2.19.0",
43
- "express": "4.17.1",
44
- "graphql": "15.4.0"
39
+ "@lowdefy/actions-core": "0.0.0-experimental-20231123101256",
40
+ "@lowdefy/api": "0.0.0-experimental-20231123101256",
41
+ "@lowdefy/blocks-aggrid": "0.0.0-experimental-20231123101256",
42
+ "@lowdefy/blocks-antd": "0.0.0-experimental-20231123101256",
43
+ "@lowdefy/blocks-basic": "0.0.0-experimental-20231123101256",
44
+ "@lowdefy/blocks-color-selectors": "0.0.0-experimental-20231123101256",
45
+ "@lowdefy/blocks-echarts": "0.0.0-experimental-20231123101256",
46
+ "@lowdefy/blocks-loaders": "0.0.0-experimental-20231123101256",
47
+ "@lowdefy/blocks-markdown": "0.0.0-experimental-20231123101256",
48
+ "@lowdefy/blocks-qr": "0.0.0-experimental-20231123101256",
49
+ "@lowdefy/build": "0.0.0-experimental-20231123101256",
50
+ "@lowdefy/client": "0.0.0-experimental-20231123101256",
51
+ "@lowdefy/connection-axios-http": "0.0.0-experimental-20231123101256",
52
+ "@lowdefy/engine": "0.0.0-experimental-20231123101256",
53
+ "@lowdefy/helpers": "0.0.0-experimental-20231123101256",
54
+ "@lowdefy/layout": "0.0.0-experimental-20231123101256",
55
+ "@lowdefy/node-utils": "0.0.0-experimental-20231123101256",
56
+ "@lowdefy/operators-change-case": "0.0.0-experimental-20231123101256",
57
+ "@lowdefy/operators-diff": "0.0.0-experimental-20231123101256",
58
+ "@lowdefy/operators-js": "0.0.0-experimental-20231123101256",
59
+ "@lowdefy/operators-moment": "0.0.0-experimental-20231123101256",
60
+ "@lowdefy/operators-mql": "0.0.0-experimental-20231123101256",
61
+ "@lowdefy/operators-nunjucks": "0.0.0-experimental-20231123101256",
62
+ "@lowdefy/operators-uuid": "0.0.0-experimental-20231123101256",
63
+ "@lowdefy/operators-yaml": "0.0.0-experimental-20231123101256",
64
+ "@lowdefy/plugin-next-auth": "0.0.0-experimental-20231123101256",
65
+ "chokidar": "3.5.3",
66
+ "dotenv": "16.3.1",
67
+ "next": "13.5.4",
68
+ "next-auth": "4.24.5",
69
+ "opener": "1.5.2",
70
+ "pino": "8.16.2",
71
+ "process": "0.11.10",
72
+ "react": "18.2.0",
73
+ "react-dom": "18.2.0",
74
+ "react-icons": "4.12.0",
75
+ "swr": "2.2.4",
76
+ "yaml": "2.3.4",
77
+ "yargs": "17.7.2"
45
78
  },
46
79
  "devDependencies": {
47
- "@babel/cli": "7.12.10",
48
- "@babel/core": "7.12.10",
49
- "@babel/preset-env": "7.12.10",
50
- "@babel/preset-react": "7.12.10",
51
- "@lowdefy/block-tools": "1.1.0",
52
- "babel-jest": "26.6.3",
53
- "babel-loader": "8.2.2",
54
- "clean-webpack-plugin": "3.0.0",
55
- "copy-webpack-plugin": "6.4.0",
56
- "css-loader": "5.0.1",
57
- "html-webpack-plugin": "4.5.0",
58
- "jest": "26.6.3",
59
- "nodemon": "2.0.6",
60
- "react": "17.0.1",
61
- "react-dom": "17.0.1",
62
- "style-loader": "2.0.0",
63
- "webpack": "5.10.0",
64
- "webpack-cli": "4.2.0"
80
+ "@next/eslint-plugin-next": "13.5.4",
81
+ "less": "4.1.3",
82
+ "less-loader": "11.1.3",
83
+ "next-with-less": "3.0.1",
84
+ "webpack": "5.89.0"
85
+ },
86
+ "engines": {
87
+ "node": ">=18"
65
88
  },
66
89
  "publishConfig": {
67
90
  "access": "public"
91
+ },
92
+ "scripts": {
93
+ "build": "cp package.json package.original.json || copy package.json package.original.json",
94
+ "start": "node manager/run.mjs",
95
+ "lint": "next lint",
96
+ "next": "next"
68
97
  }
69
- }
98
+ }
@@ -0,0 +1,98 @@
1
+ {
2
+ "name": "@lowdefy/server-dev",
3
+ "version": "4.0.0-rc.14",
4
+ "license": "Apache-2.0",
5
+ "description": "",
6
+ "homepage": "https://lowdefy.com",
7
+ "keywords": [
8
+ "lowdefy",
9
+ "server"
10
+ ],
11
+ "bugs": {
12
+ "url": "https://github.com/lowdefy/lowdefy/issues"
13
+ },
14
+ "contributors": [
15
+ {
16
+ "name": "Sam Tolmay",
17
+ "url": "https://github.com/SamTolmay"
18
+ },
19
+ {
20
+ "name": "Gerrie van Wyk",
21
+ "url": "https://github.com/Gervwyk"
22
+ }
23
+ ],
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "https://github.com/lowdefy/lowdefy.git"
27
+ },
28
+ "files": [
29
+ "lib/*",
30
+ "manager/*",
31
+ "pages/*",
32
+ "public_default/*",
33
+ "next.config.js",
34
+ "package.original.json",
35
+ ".eslintrc.yaml",
36
+ ".npmrc"
37
+ ],
38
+ "scripts": {
39
+ "build": "cp package.json package.original.json || copy package.json package.original.json",
40
+ "start": "node manager/run.mjs",
41
+ "lint": "next lint",
42
+ "next": "next"
43
+ },
44
+ "dependencies": {
45
+ "@lowdefy/actions-core": "4.0.0-rc.14",
46
+ "@lowdefy/api": "4.0.0-rc.14",
47
+ "@lowdefy/blocks-aggrid": "4.0.0-rc.14",
48
+ "@lowdefy/blocks-antd": "4.0.0-rc.14",
49
+ "@lowdefy/blocks-basic": "4.0.0-rc.14",
50
+ "@lowdefy/blocks-color-selectors": "4.0.0-rc.14",
51
+ "@lowdefy/blocks-echarts": "4.0.0-rc.14",
52
+ "@lowdefy/blocks-loaders": "4.0.0-rc.14",
53
+ "@lowdefy/blocks-markdown": "4.0.0-rc.14",
54
+ "@lowdefy/blocks-qr": "4.0.0-rc.14",
55
+ "@lowdefy/build": "4.0.0-rc.14",
56
+ "@lowdefy/client": "4.0.0-rc.14",
57
+ "@lowdefy/connection-axios-http": "4.0.0-rc.14",
58
+ "@lowdefy/engine": "4.0.0-rc.14",
59
+ "@lowdefy/helpers": "4.0.0-rc.14",
60
+ "@lowdefy/layout": "4.0.0-rc.14",
61
+ "@lowdefy/node-utils": "4.0.0-rc.14",
62
+ "@lowdefy/operators-change-case": "4.0.0-rc.14",
63
+ "@lowdefy/operators-diff": "4.0.0-rc.14",
64
+ "@lowdefy/operators-js": "4.0.0-rc.14",
65
+ "@lowdefy/operators-moment": "4.0.0-rc.14",
66
+ "@lowdefy/operators-mql": "4.0.0-rc.14",
67
+ "@lowdefy/operators-nunjucks": "4.0.0-rc.14",
68
+ "@lowdefy/operators-uuid": "4.0.0-rc.14",
69
+ "@lowdefy/operators-yaml": "4.0.0-rc.14",
70
+ "@lowdefy/plugin-next-auth": "4.0.0-rc.14",
71
+ "chokidar": "3.5.3",
72
+ "dotenv": "16.3.1",
73
+ "next": "13.5.4",
74
+ "next-auth": "4.24.5",
75
+ "opener": "1.5.2",
76
+ "pino": "8.16.2",
77
+ "process": "0.11.10",
78
+ "react": "18.2.0",
79
+ "react-dom": "18.2.0",
80
+ "react-icons": "4.12.0",
81
+ "swr": "2.2.4",
82
+ "yaml": "2.3.4",
83
+ "yargs": "17.7.2"
84
+ },
85
+ "devDependencies": {
86
+ "@next/eslint-plugin-next": "13.5.4",
87
+ "less": "4.1.3",
88
+ "less-loader": "11.1.3",
89
+ "next-with-less": "3.0.1",
90
+ "webpack": "5.89.0"
91
+ },
92
+ "engines": {
93
+ "node": ">=18"
94
+ },
95
+ "publishConfig": {
96
+ "access": "public"
97
+ }
98
+ }
package/pages/404.js ADDED
@@ -0,0 +1,19 @@
1
+ /*
2
+ Copyright 2020-2023 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 App from '../lib/client/App.js';
18
+
19
+ export default App;
@@ -0,0 +1,19 @@
1
+ /*
2
+ Copyright 2020-2023 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 App from '../lib/client/App.js';
18
+
19
+ export default App;
package/pages/_app.js ADDED
@@ -0,0 +1,42 @@
1
+ /*
2
+ Copyright 2020-2023 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, { Suspense, useRef } from 'react';
18
+ import dynamic from 'next/dynamic';
19
+
20
+ import { ErrorBoundary } from '@lowdefy/block-utils';
21
+
22
+ import Auth from '../lib/client/auth/Auth.js';
23
+
24
+ // Must be in _app due to next specifications.
25
+ import '../build/plugins/styles.less';
26
+
27
+ function App({ Component }) {
28
+ const lowdefyRef = useRef({});
29
+ return (
30
+ <ErrorBoundary fullPage>
31
+ <Suspense fallback="">
32
+ <Auth>{(auth) => <Component auth={auth} lowdefy={lowdefyRef.current} />}</Auth>
33
+ </Suspense>
34
+ </ErrorBoundary>
35
+ );
36
+ }
37
+
38
+ const DynamicApp = dynamic(() => Promise.resolve(App), {
39
+ ssr: false,
40
+ });
41
+
42
+ export default DynamicApp;
@@ -0,0 +1,54 @@
1
+ /*
2
+ Copyright 2020-2023 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 '../build/app.json';
21
+ import lowdefyConfig from '../build/config.json';
22
+
23
+ const basePath = lowdefyConfig.basePath ?? '';
24
+
25
+ class LowdefyDocument extends Document {
26
+ render() {
27
+ return (
28
+ <Html>
29
+ <Head>
30
+ <link rel="manifest" href={`${basePath}/manifest.webmanifest`} />
31
+ <link rel="icon" type="image/svg+xml" href={`${basePath}/icon.svg`} />
32
+ <link rel="apple-touch-icon" href={`${basePath}/apple-touch-icon.png`} />
33
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
34
+ <script
35
+ dangerouslySetInnerHTML={{
36
+ __html: `/* start of Lowdefy append head */</script>${appJson.html.appendHead}<script>/* end of Lowdefy append head */`,
37
+ }}
38
+ />
39
+ </Head>
40
+ <body>
41
+ <Main />
42
+ <NextScript />
43
+ <script
44
+ dangerouslySetInnerHTML={{
45
+ __html: `/* start of Lowdefy append body */</script>${appJson.html.appendBody}<script>/* end of Lowdefy append body */`,
46
+ }}
47
+ />
48
+ </body>
49
+ </Html>
50
+ );
51
+ }
52
+ }
53
+
54
+ export default LowdefyDocument;
@@ -0,0 +1,37 @@
1
+ /*
2
+ Copyright 2020-2023 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 '../../../build/auth.json';
21
+
22
+ async function handler({ context, req, res }) {
23
+ if (authJson.configured === true) {
24
+ // Required for emails in corporate networks, see:
25
+ // https://next-auth.js.org/tutorials/avoid-corporate-link-checking-email-provider
26
+ if (req.method === 'HEAD') {
27
+ return res.status(200).end();
28
+ }
29
+ return await NextAuth(req, res, context.authOptions);
30
+ }
31
+
32
+ return res.status(404).json({
33
+ message: 'Auth not configured',
34
+ });
35
+ }
36
+
37
+ export default apiWrapper(handler);
@@ -0,0 +1,32 @@
1
+ /*
2
+ Copyright 2020-2023 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
+
21
+ async function handler({ context, req, res }) {
22
+ const { pageId } = req.query;
23
+ const pageConfig = await getPageConfig(context, { pageId });
24
+ // TODO: Do we log here?
25
+ if (pageConfig === null) {
26
+ res.status(404).send('Page not found.');
27
+ } else {
28
+ res.status(200).json(pageConfig);
29
+ }
30
+ }
31
+
32
+ export default apiWrapper(handler);
@@ -0,0 +1,19 @@
1
+ /*
2
+ Copyright 2020-2023 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
+ export default async function handler(req, res) {
18
+ res.status(200).json({ timestamp: new Date().toISOString() });
19
+ }
@@ -0,0 +1,50 @@
1
+ /*
2
+ Copyright 2020-2023 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.log(e);
35
+ }
36
+ };
37
+ watcher.on('add', () => reload());
38
+ watcher.on('change', () => reload());
39
+ watcher.on('unlink', () => reload());
40
+
41
+ // TODO: This isn't working.
42
+ req.on('close', () => {
43
+ console.log('req closed');
44
+ watcher.close().then(() => {
45
+ console.log('watcher closed');
46
+ });
47
+ });
48
+ };
49
+
50
+ export default handler;
@@ -0,0 +1,32 @@
1
+ /*
2
+ Copyright 2020-2023 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 { pageId, requestId } = req.query;
26
+ const { blockId, payload } = req.body;
27
+ context.logger.info({ event: 'call_request', pageId, requestId, blockId });
28
+ const response = await callRequest(context, { blockId, pageId, payload, requestId });
29
+ res.status(200).json(response);
30
+ }
31
+
32
+ export default apiWrapper(handler);