@lowdefy/server 4.0.0-alpha.1 → 4.0.0-alpha.7
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.
- package/.eslintrc.yaml +1 -0
- package/README.md +17 -1
- package/next.config.js +36 -0
- package/package.json +21 -19
- package/{src/public → public}/apple-touch-icon.png +0 -0
- package/public/favicon.ico +0 -0
- package/{src/public → public}/icon-512.png +0 -0
- package/{src/public → public}/icon.svg +0 -0
- package/{src/public → public}/logo-dark-theme.png +0 -0
- package/{src/public → public}/logo-light-theme.png +0 -0
- package/{src/public → public}/logo-square-dark-theme.png +0 -0
- package/{src/public → public}/logo-square-light-theme.png +0 -0
- package/{src/public → public}/manifest.webmanifest +0 -0
- package/src/components/LowdefyContext.js +16 -13
- package/src/components/Page.js +8 -4
- package/src/components/block/CategorySwitch.js +2 -5
- package/src/components/block/Container.js +1 -2
- package/src/components/block/List.js +1 -2
- package/src/components/{components.js → createComponents.js} +9 -5
- package/src/components/createLinkComponent.js +97 -0
- package/src/{plugins/icons.js → pages/404.js} +22 -19
- package/src/pages/[pageId].js +2 -3
- package/src/pages/_app.js +5 -3
- package/src/pages/_document.js +38 -0
- package/src/pages/api/request/[pageId]/[requestId].js +8 -5
- package/src/pages/index.js +6 -10
- package/src/utils/setupLink.js +22 -14
- package/src/plugins/style.less +0 -3
- package/src/public/icon-32.png +0 -0
package/.eslintrc.yaml
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
extends: 'plugin:@next/next/core-web-vitals'
|
package/README.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @lowdefy/server
|
|
2
2
|
|
|
3
|
+
## Development
|
|
4
|
+
|
|
5
|
+
To run the server in locally as a development server, run the following:
|
|
6
|
+
|
|
7
|
+
- Run `yarn && yarn build` at the root of the repository.
|
|
8
|
+
- Add a `lowdefy.yaml` file in the server directory (`packages/server`).
|
|
9
|
+
- run `yarn dev` in the server directory.
|
|
10
|
+
|
|
11
|
+
To run the server in locally as a development server, with a next production build, run the following:
|
|
12
|
+
|
|
13
|
+
- Run `yarn && yarn build` at the root of the repository.
|
|
14
|
+
- Add a `lowdefy.yaml` file in the server directory (`packages/server`).
|
|
15
|
+
- run `yarn dev:prod` in the server directory.
|
|
16
|
+
|
|
17
|
+
> When running a development server, the `package.json` file is updated with the plugins used in the Lowdefy app. Please do not commit the changes made to the `package.json`, `.pnp.cjs` and `yarn.lock` files.
|
|
18
|
+
|
|
3
19
|
## Licence
|
|
4
20
|
|
|
5
|
-
[Apache-2.0](https://github.com/lowdefy/lowdefy/blob/main/LICENSE)
|
|
21
|
+
[Apache-2.0](https://github.com/lowdefy/lowdefy/blob/main/LICENSE)
|
package/next.config.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const withLess = require('next-with-less');
|
|
2
|
+
const lowdefyConfig = require('./build/config.json');
|
|
3
|
+
|
|
4
|
+
// TODO: Trance env and args from cli that is required on the server.
|
|
5
|
+
module.exports = withLess({
|
|
6
|
+
basePath: process.env.LOWDEFY_BASE_PATH || lowdefyConfig.basePath,
|
|
7
|
+
lessLoaderOptions: {
|
|
8
|
+
lessOptions: {
|
|
9
|
+
modifyVars: lowdefyConfig.theme.lessVariables,
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
reactStrictMode: true,
|
|
13
|
+
webpack: (config, { isServer }) => {
|
|
14
|
+
if (!isServer) {
|
|
15
|
+
config.resolve.fallback = {
|
|
16
|
+
assert: false,
|
|
17
|
+
buffer: false,
|
|
18
|
+
crypto: false,
|
|
19
|
+
events: false,
|
|
20
|
+
fs: false,
|
|
21
|
+
path: false,
|
|
22
|
+
process: require.resolve('process/browser'),
|
|
23
|
+
util: false,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return config;
|
|
27
|
+
},
|
|
28
|
+
poweredByHeader: false,
|
|
29
|
+
// productionBrowserSourceMaps: true
|
|
30
|
+
// experimental: {
|
|
31
|
+
// concurrentFeatures: true,
|
|
32
|
+
// },
|
|
33
|
+
eslint: {
|
|
34
|
+
ignoreDuringBuilds: true,
|
|
35
|
+
},
|
|
36
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowdefy/server",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.7",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
@@ -26,10 +26,12 @@
|
|
|
26
26
|
"url": "https://github.com/lowdefy/lowdefy.git"
|
|
27
27
|
},
|
|
28
28
|
"files": [
|
|
29
|
-
"src/*"
|
|
29
|
+
"src/*",
|
|
30
|
+
"public/*",
|
|
31
|
+
"next.config.js",
|
|
32
|
+
".eslintrc.yaml"
|
|
30
33
|
],
|
|
31
34
|
"scripts": {
|
|
32
|
-
"build": "yarn build:lowdefy && yarn build:next",
|
|
33
35
|
"build:lowdefy": "lowdefy-build",
|
|
34
36
|
"build:next": "next build",
|
|
35
37
|
"dev": "next dev",
|
|
@@ -38,29 +40,29 @@
|
|
|
38
40
|
"next": "next"
|
|
39
41
|
},
|
|
40
42
|
"dependencies": {
|
|
41
|
-
"@lowdefy/api": "4.0.0-alpha.
|
|
42
|
-
"@lowdefy/block-utils": "4.0.0-alpha.
|
|
43
|
-
"@lowdefy/
|
|
44
|
-
"@lowdefy/
|
|
45
|
-
"@lowdefy/
|
|
46
|
-
"@lowdefy/
|
|
47
|
-
"@lowdefy/
|
|
48
|
-
"
|
|
49
|
-
"next": "
|
|
50
|
-
"
|
|
51
|
-
"react": "18.0.0-
|
|
52
|
-
"react-dom": "18.0.0-
|
|
43
|
+
"@lowdefy/api": "4.0.0-alpha.7",
|
|
44
|
+
"@lowdefy/block-utils": "4.0.0-alpha.7",
|
|
45
|
+
"@lowdefy/engine": "4.0.0-alpha.7",
|
|
46
|
+
"@lowdefy/helpers": "4.0.0-alpha.7",
|
|
47
|
+
"@lowdefy/layout": "4.0.0-alpha.7",
|
|
48
|
+
"@lowdefy/node-utils": "4.0.0-alpha.7",
|
|
49
|
+
"@lowdefy/operators-js": "4.0.0-alpha.7",
|
|
50
|
+
"next": "12.0.10",
|
|
51
|
+
"next-auth": "4.1.2",
|
|
52
|
+
"process": "0.11.10",
|
|
53
|
+
"react": "18.0.0-rc.0",
|
|
54
|
+
"react-dom": "18.0.0-rc.0",
|
|
53
55
|
"react-icons": "4.3.1"
|
|
54
56
|
},
|
|
55
57
|
"devDependencies": {
|
|
56
|
-
"@lowdefy/build": "4.0.0-alpha.
|
|
57
|
-
"@next/eslint-plugin-next": "12.0.
|
|
58
|
+
"@lowdefy/build": "4.0.0-alpha.7",
|
|
59
|
+
"@next/eslint-plugin-next": "12.0.10",
|
|
58
60
|
"less": "4.1.2",
|
|
59
61
|
"less-loader": "10.2.0",
|
|
60
|
-
"next-with-less": "2.0.
|
|
62
|
+
"next-with-less": "2.0.4"
|
|
61
63
|
},
|
|
62
64
|
"publishConfig": {
|
|
63
65
|
"access": "public"
|
|
64
66
|
},
|
|
65
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "52ec14639d00de910cf9b8ab25bf933ca891cff5"
|
|
66
68
|
}
|
|
File without changes
|
|
Binary file
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -16,32 +16,35 @@
|
|
|
16
16
|
|
|
17
17
|
import React from 'react';
|
|
18
18
|
|
|
19
|
+
import actions from '../../build/plugins/actions.js';
|
|
19
20
|
import callRequest from '../utils/callRequest.js';
|
|
20
|
-
import blockComponents from '
|
|
21
|
-
import
|
|
21
|
+
import blockComponents from '../../build/plugins/blocks.js';
|
|
22
|
+
import operators from '../../build/plugins/operatorsClient.js';
|
|
22
23
|
|
|
23
|
-
const LowdefyContext = ({ children }) => {
|
|
24
|
-
|
|
25
|
-
_internal
|
|
24
|
+
const LowdefyContext = ({ children, lowdefy }) => {
|
|
25
|
+
if (!lowdefy._internal) {
|
|
26
|
+
lowdefy._internal = {
|
|
27
|
+
actions,
|
|
26
28
|
blockComponents,
|
|
27
29
|
callRequest,
|
|
28
|
-
components,
|
|
30
|
+
components: {},
|
|
29
31
|
document,
|
|
32
|
+
operators,
|
|
30
33
|
updaters: {},
|
|
31
34
|
window,
|
|
32
35
|
displayMessage: ({ content }) => {
|
|
33
|
-
|
|
36
|
+
console.log(content);
|
|
34
37
|
return () => undefined;
|
|
35
38
|
},
|
|
36
39
|
link: () => undefined,
|
|
37
|
-
}
|
|
38
|
-
contexts
|
|
39
|
-
inputs
|
|
40
|
-
lowdefyGlobal
|
|
41
|
-
}
|
|
40
|
+
};
|
|
41
|
+
lowdefy.contexts = {};
|
|
42
|
+
lowdefy.inputs = {};
|
|
43
|
+
lowdefy.lowdefyGlobal = {};
|
|
44
|
+
}
|
|
42
45
|
lowdefy._internal.updateBlock = (blockId) =>
|
|
43
46
|
lowdefy._internal.updaters[blockId] && lowdefy._internal.updaters[blockId]();
|
|
44
|
-
return <>{children
|
|
47
|
+
return <>{children}</>;
|
|
45
48
|
};
|
|
46
49
|
|
|
47
50
|
export default LowdefyContext;
|
package/src/components/Page.js
CHANGED
|
@@ -16,25 +16,29 @@
|
|
|
16
16
|
|
|
17
17
|
import React from 'react';
|
|
18
18
|
|
|
19
|
+
import { urlQuery } from '@lowdefy/helpers';
|
|
19
20
|
import { useRouter } from 'next/router';
|
|
20
21
|
|
|
21
22
|
import Context from './Context.js';
|
|
22
23
|
import Head from './Head.js';
|
|
23
24
|
import Block from './block/Block.js';
|
|
24
25
|
import setupLink from '../utils/setupLink.js';
|
|
26
|
+
import createComponents from './createComponents.js';
|
|
25
27
|
|
|
26
28
|
const LoadingBlock = () => <div>Loading...</div>;
|
|
27
29
|
|
|
28
30
|
const Page = ({ lowdefy, pageConfig, rootConfig }) => {
|
|
29
31
|
const router = useRouter();
|
|
30
|
-
lowdefy._internal.basePath = router.basePath;
|
|
31
|
-
lowdefy._internal.pathname = router.pathname;
|
|
32
|
-
lowdefy._internal.query = router.query;
|
|
33
32
|
lowdefy._internal.router = router;
|
|
34
|
-
lowdefy._internal.link = setupLink(
|
|
33
|
+
lowdefy._internal.link = setupLink(lowdefy);
|
|
34
|
+
lowdefy._internal.components = createComponents(lowdefy);
|
|
35
|
+
|
|
36
|
+
lowdefy.basePath = lowdefy._internal.router.basePath;
|
|
35
37
|
lowdefy.home = rootConfig.home;
|
|
36
38
|
lowdefy.lowdefyGlobal = rootConfig.lowdefyGlobal;
|
|
37
39
|
lowdefy.menus = rootConfig.menus;
|
|
40
|
+
lowdefy.urlQuery = urlQuery.parse(window.location.search.slice(1));
|
|
41
|
+
|
|
38
42
|
return (
|
|
39
43
|
<Context config={pageConfig} lowdefy={lowdefy}>
|
|
40
44
|
{(context, loading) => {
|
|
@@ -64,12 +64,10 @@ const CategorySwitch = ({ block, Blocks, context, lowdefy }) => {
|
|
|
64
64
|
setValue: block.setValue,
|
|
65
65
|
triggerEvent: block.triggerEvent,
|
|
66
66
|
})}
|
|
67
|
-
|
|
68
|
-
basePath={lowdefy._internal.basePath}
|
|
67
|
+
basePath={lowdefy.basePath}
|
|
69
68
|
blockId={block.blockId}
|
|
70
69
|
components={lowdefy._internal.components}
|
|
71
70
|
events={block.eval.events}
|
|
72
|
-
homePageId={lowdefy.homePageId}
|
|
73
71
|
key={block.blockId}
|
|
74
72
|
loading={block.loading}
|
|
75
73
|
menus={lowdefy.menus}
|
|
@@ -98,11 +96,10 @@ const CategorySwitch = ({ block, Blocks, context, lowdefy }) => {
|
|
|
98
96
|
registerMethod: block.registerMethod,
|
|
99
97
|
triggerEvent: block.triggerEvent,
|
|
100
98
|
})}
|
|
101
|
-
basePath={lowdefy.
|
|
99
|
+
basePath={lowdefy.basePath}
|
|
102
100
|
blockId={block.blockId}
|
|
103
101
|
components={lowdefy._internal.components}
|
|
104
102
|
events={block.eval.events}
|
|
105
|
-
homePageId={lowdefy.homePageId}
|
|
106
103
|
key={block.blockId}
|
|
107
104
|
loading={block.loading}
|
|
108
105
|
menus={lowdefy.menus}
|
|
@@ -65,12 +65,11 @@ const Container = ({ block, Blocks, Component, context, lowdefy }) => {
|
|
|
65
65
|
registerMethod: block.registerMethod,
|
|
66
66
|
triggerEvent: block.triggerEvent,
|
|
67
67
|
})}
|
|
68
|
-
basePath={lowdefy.
|
|
68
|
+
basePath={lowdefy.basePath}
|
|
69
69
|
blockId={block.blockId}
|
|
70
70
|
components={lowdefy._internal.components}
|
|
71
71
|
content={content}
|
|
72
72
|
events={block.eval.events}
|
|
73
|
-
homePageId={lowdefy.homePageId}
|
|
74
73
|
key={block.blockId}
|
|
75
74
|
loading={block.loading}
|
|
76
75
|
menus={lowdefy.menus}
|
|
@@ -72,11 +72,10 @@ const List = ({ block, Blocks, Component, context, lowdefy }) => {
|
|
|
72
72
|
triggerEvent: block.triggerEvent,
|
|
73
73
|
unshiftItem: block.unshiftItem,
|
|
74
74
|
})}
|
|
75
|
-
basePath={lowdefy.
|
|
75
|
+
basePath={lowdefy.basePath}
|
|
76
76
|
blockId={block.blockId}
|
|
77
77
|
components={lowdefy._internal.components}
|
|
78
78
|
events={block.eval.events}
|
|
79
|
-
homePageId={lowdefy.homePageId}
|
|
80
79
|
key={block.blockId}
|
|
81
80
|
list={contentList}
|
|
82
81
|
loading={block.loading}
|
|
@@ -14,12 +14,16 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import Link from 'next/link';
|
|
18
17
|
import { createIcon } from '@lowdefy/block-utils';
|
|
19
18
|
|
|
20
|
-
import
|
|
19
|
+
import createLinkComponent from './createLinkComponent.js';
|
|
20
|
+
import icons from '../../build/plugins/icons.js';
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
const createComponents = (lowdefy) => {
|
|
23
|
+
return {
|
|
24
|
+
Link: createLinkComponent(lowdefy),
|
|
25
|
+
Icon: createIcon(icons),
|
|
26
|
+
};
|
|
25
27
|
};
|
|
28
|
+
|
|
29
|
+
export default createComponents;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import NextLink from 'next/link';
|
|
3
|
+
import { createLink } from '@lowdefy/engine';
|
|
4
|
+
import { type } from '@lowdefy/helpers';
|
|
5
|
+
|
|
6
|
+
const createLinkComponent = (lowdefy) => {
|
|
7
|
+
const backLink = ({ ariaLabel, children, className, id, rel }) => (
|
|
8
|
+
<a
|
|
9
|
+
id={id}
|
|
10
|
+
onClick={() => lowdefy._internal.router.back()}
|
|
11
|
+
className={className}
|
|
12
|
+
rel={rel}
|
|
13
|
+
aria-label={ariaLabel || 'back'}
|
|
14
|
+
>
|
|
15
|
+
{type.isFunction(children) ? children(id) : children}
|
|
16
|
+
</a>
|
|
17
|
+
);
|
|
18
|
+
const newOriginLink = ({
|
|
19
|
+
ariaLabel,
|
|
20
|
+
children,
|
|
21
|
+
className,
|
|
22
|
+
id,
|
|
23
|
+
newTab,
|
|
24
|
+
pageId,
|
|
25
|
+
query,
|
|
26
|
+
rel,
|
|
27
|
+
url,
|
|
28
|
+
}) => {
|
|
29
|
+
return (
|
|
30
|
+
<a
|
|
31
|
+
id={id}
|
|
32
|
+
aria-label={ariaLabel}
|
|
33
|
+
className={className}
|
|
34
|
+
href={`${url}${query ? `?${query}` : ''}`}
|
|
35
|
+
rel={rel || (newTab && 'noopener noreferrer')}
|
|
36
|
+
target={newTab && '_blank'}
|
|
37
|
+
>
|
|
38
|
+
{type.isFunction(children) ? children(pageId || url || id) : children}
|
|
39
|
+
</a>
|
|
40
|
+
);
|
|
41
|
+
};
|
|
42
|
+
const sameOriginLink = ({
|
|
43
|
+
ariaLabel,
|
|
44
|
+
children,
|
|
45
|
+
className,
|
|
46
|
+
id,
|
|
47
|
+
newTab,
|
|
48
|
+
pageId,
|
|
49
|
+
pathname,
|
|
50
|
+
query,
|
|
51
|
+
rel,
|
|
52
|
+
replace,
|
|
53
|
+
scroll,
|
|
54
|
+
setInput,
|
|
55
|
+
url,
|
|
56
|
+
}) => {
|
|
57
|
+
if (newTab) {
|
|
58
|
+
return (
|
|
59
|
+
// eslint-disable-next-line react/jsx-no-target-blank
|
|
60
|
+
<a
|
|
61
|
+
id={id}
|
|
62
|
+
aria-label={ariaLabel}
|
|
63
|
+
className={className}
|
|
64
|
+
href={`${window.location.origin}${lowdefy.basePath}${pathname}${
|
|
65
|
+
query ? `?${query}` : ''
|
|
66
|
+
}`}
|
|
67
|
+
rel={rel || 'noopener noreferrer'}
|
|
68
|
+
target="_blank"
|
|
69
|
+
>
|
|
70
|
+
{type.isFunction(children) ? children(pageId || url || id) : children}
|
|
71
|
+
</a>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
return (
|
|
75
|
+
<NextLink href={{ pathname, query }} replace={replace} scroll={scroll}>
|
|
76
|
+
<a id={id} aria-label={ariaLabel} className={className} rel={rel} onClick={setInput}>
|
|
77
|
+
{type.isFunction(children) ? children(pageId || url || id) : children}
|
|
78
|
+
</a>
|
|
79
|
+
</NextLink>
|
|
80
|
+
);
|
|
81
|
+
};
|
|
82
|
+
const noLink = ({ className, children, id }) => (
|
|
83
|
+
<span id={id} className={className}>
|
|
84
|
+
{type.isFunction(children) ? children(id) : children}
|
|
85
|
+
</span>
|
|
86
|
+
);
|
|
87
|
+
return createLink({
|
|
88
|
+
backLink,
|
|
89
|
+
lowdefy,
|
|
90
|
+
newOriginLink,
|
|
91
|
+
sameOriginLink,
|
|
92
|
+
noLink,
|
|
93
|
+
disabledLink: noLink,
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export default createLinkComponent;
|
|
@@ -14,22 +14,25 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
import
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
};
|
|
17
|
+
import { createApiContext, getPageConfig, getRootConfig } from '@lowdefy/api';
|
|
18
|
+
|
|
19
|
+
import Page from '../components/Page.js';
|
|
20
|
+
|
|
21
|
+
export async function getStaticProps() {
|
|
22
|
+
// TODO: get the right api context options
|
|
23
|
+
const apiContext = await createApiContext({ buildDirectory: './build' });
|
|
24
|
+
|
|
25
|
+
const [rootConfig, pageConfig] = await Promise.all([
|
|
26
|
+
getRootConfig(apiContext),
|
|
27
|
+
getPageConfig(apiContext, { pageId: '404' }),
|
|
28
|
+
]);
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
props: {
|
|
32
|
+
pageConfig,
|
|
33
|
+
rootConfig,
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default Page;
|
package/src/pages/[pageId].js
CHANGED
|
@@ -20,10 +20,9 @@ import Page from '../components/Page.js';
|
|
|
20
20
|
|
|
21
21
|
export async function getServerSideProps(context) {
|
|
22
22
|
const { pageId } = context.params;
|
|
23
|
-
|
|
23
|
+
// TODO: get the right api context options
|
|
24
|
+
const apiContext = await createApiContext({ buildDirectory: './build' });
|
|
24
25
|
|
|
25
|
-
// TODO: Maybe we can only get rootConfig once?
|
|
26
|
-
// We can't do getServerSideProps on _app :(
|
|
27
26
|
const [rootConfig, pageConfig] = await Promise.all([
|
|
28
27
|
getRootConfig(apiContext),
|
|
29
28
|
getPageConfig(apiContext, { pageId }),
|
package/src/pages/_app.js
CHANGED
|
@@ -20,14 +20,16 @@ import { ErrorBoundary } from '@lowdefy/block-utils';
|
|
|
20
20
|
|
|
21
21
|
import LowdefyContext from '../components/LowdefyContext.js';
|
|
22
22
|
|
|
23
|
-
import '
|
|
23
|
+
import '../../build/plugins/styles.less';
|
|
24
|
+
|
|
25
|
+
const lowdefy = {};
|
|
24
26
|
|
|
25
27
|
function App({ Component, pageProps }) {
|
|
26
28
|
return (
|
|
27
29
|
<ErrorBoundary>
|
|
28
30
|
<Suspense>
|
|
29
|
-
<LowdefyContext>
|
|
30
|
-
|
|
31
|
+
<LowdefyContext lowdefy={lowdefy}>
|
|
32
|
+
<Component lowdefy={lowdefy} {...pageProps} />
|
|
31
33
|
</LowdefyContext>
|
|
32
34
|
</Suspense>
|
|
33
35
|
</ErrorBoundary>
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2021 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
|
+
class LowdefyDocument extends Document {
|
|
21
|
+
render() {
|
|
22
|
+
return (
|
|
23
|
+
<Html>
|
|
24
|
+
<Head>
|
|
25
|
+
<link rel="manifest" href="/manifest.webmanifest" />
|
|
26
|
+
<link rel="icon" type="image/svg+xml" href="/icon.svg" />
|
|
27
|
+
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
|
|
28
|
+
</Head>
|
|
29
|
+
<body>
|
|
30
|
+
<Main />
|
|
31
|
+
<NextScript />
|
|
32
|
+
</body>
|
|
33
|
+
</Html>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default LowdefyDocument;
|
|
@@ -15,20 +15,23 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import { callRequest, createApiContext } from '@lowdefy/api';
|
|
18
|
-
import
|
|
18
|
+
import { getSecretsFromEnv } from '@lowdefy/node-utils';
|
|
19
|
+
import connections from '../../../../../build/plugins/connections.js';
|
|
20
|
+
import operators from '../../../../../build/plugins/operatorsServer.js';
|
|
19
21
|
|
|
20
22
|
export default async function handler(req, res) {
|
|
21
23
|
try {
|
|
22
24
|
if (req.method !== 'POST') {
|
|
23
25
|
throw new Error('Only POST requests are supported.');
|
|
24
26
|
}
|
|
27
|
+
// TODO: configure API context
|
|
25
28
|
const apiContext = await createApiContext({
|
|
26
|
-
buildDirectory: '
|
|
29
|
+
buildDirectory: './build',
|
|
27
30
|
connections,
|
|
28
|
-
// TODO
|
|
31
|
+
// TODO: use a logger like pino
|
|
29
32
|
logger: console,
|
|
30
|
-
|
|
31
|
-
secrets:
|
|
33
|
+
operators,
|
|
34
|
+
secrets: getSecretsFromEnv(),
|
|
32
35
|
});
|
|
33
36
|
const { pageId, requestId } = req.query;
|
|
34
37
|
const { payload } = req.body;
|
package/src/pages/index.js
CHANGED
|
@@ -14,13 +14,15 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import { createApiContext,
|
|
17
|
+
import { createApiContext, getPageConfig, getRootConfig } from '@lowdefy/api';
|
|
18
18
|
|
|
19
19
|
import Page from '../components/Page.js';
|
|
20
20
|
|
|
21
21
|
export async function getServerSideProps() {
|
|
22
|
-
|
|
23
|
-
const
|
|
22
|
+
// TODO: is this build directory configurable from the cli?
|
|
23
|
+
const apiContext = await createApiContext({ buildDirectory: './build' });
|
|
24
|
+
const rootConfig = await getRootConfig(apiContext);
|
|
25
|
+
const { home } = rootConfig;
|
|
24
26
|
if (home.configured === false) {
|
|
25
27
|
return {
|
|
26
28
|
redirect: {
|
|
@@ -29,12 +31,7 @@ export async function getServerSideProps() {
|
|
|
29
31
|
},
|
|
30
32
|
};
|
|
31
33
|
}
|
|
32
|
-
|
|
33
|
-
const [rootConfig, pageConfig] = await Promise.all([
|
|
34
|
-
getRootConfig(apiContext),
|
|
35
|
-
getPageConfig(apiContext, { pageId: home.pageId }),
|
|
36
|
-
]);
|
|
37
|
-
|
|
34
|
+
const pageConfig = await getPageConfig(apiContext, { pageId: home.pageId });
|
|
38
35
|
if (!pageConfig) {
|
|
39
36
|
return {
|
|
40
37
|
redirect: {
|
|
@@ -43,7 +40,6 @@ export async function getServerSideProps() {
|
|
|
43
40
|
},
|
|
44
41
|
};
|
|
45
42
|
}
|
|
46
|
-
|
|
47
43
|
return {
|
|
48
44
|
props: {
|
|
49
45
|
pageConfig,
|
package/src/utils/setupLink.js
CHANGED
|
@@ -16,29 +16,37 @@
|
|
|
16
16
|
|
|
17
17
|
import { createLink } from '@lowdefy/engine';
|
|
18
18
|
|
|
19
|
-
function setupLink(
|
|
19
|
+
function setupLink(lowdefy) {
|
|
20
20
|
const { router, window } = lowdefy._internal;
|
|
21
|
-
const
|
|
21
|
+
const backLink = () => router.back();
|
|
22
|
+
const disabledLink = () => {};
|
|
23
|
+
const newOriginLink = ({ url, query, newTab }) => {
|
|
22
24
|
if (newTab) {
|
|
23
|
-
return window.open(`${
|
|
25
|
+
return window.open(`${url}${query ? `?${query}` : ''}`, '_blank').focus();
|
|
24
26
|
} else {
|
|
25
|
-
|
|
26
|
-
return router.push({
|
|
27
|
-
pathname: path,
|
|
28
|
-
// TODO: Do we handle urlQuery as a param here?
|
|
29
|
-
// query: {},
|
|
30
|
-
});
|
|
27
|
+
return window.location.assign(`${url}${query ? `?${query}` : ''}`);
|
|
31
28
|
}
|
|
32
29
|
};
|
|
33
|
-
const
|
|
30
|
+
const sameOriginLink = ({ newTab, pathname, query, setInput }) => {
|
|
34
31
|
if (newTab) {
|
|
35
|
-
return window
|
|
32
|
+
return window
|
|
33
|
+
.open(
|
|
34
|
+
`${window.location.origin}${lowdefy.basePath}${pathname}${query ? `?${query}` : ''}`,
|
|
35
|
+
'_blank'
|
|
36
|
+
)
|
|
37
|
+
.focus();
|
|
36
38
|
} else {
|
|
37
|
-
|
|
39
|
+
setInput();
|
|
40
|
+
return router.push({
|
|
41
|
+
pathname,
|
|
42
|
+
query,
|
|
43
|
+
});
|
|
38
44
|
}
|
|
39
45
|
};
|
|
40
|
-
const
|
|
41
|
-
|
|
46
|
+
const noLink = () => {
|
|
47
|
+
throw new Error(`Invalid Link.`);
|
|
48
|
+
};
|
|
49
|
+
return createLink({ backLink, disabledLink, lowdefy, newOriginLink, noLink, sameOriginLink });
|
|
42
50
|
}
|
|
43
51
|
|
|
44
52
|
export default setupLink;
|
package/src/plugins/style.less
DELETED
package/src/public/icon-32.png
DELETED
|
Binary file
|