@lowdefy/server-dev 4.0.0-alpha.11 → 4.0.0-alpha.14
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/lib/App.js +2 -1
- package/lib/Page.js +3 -10
- package/lib/auth/Auth.js +35 -0
- package/lib/auth/AuthConfigured.js +47 -0
- package/lib/auth/AuthNotConfigured.js +32 -0
- package/lib/auth/getServerSession.js +27 -0
- package/manager/processes/initialBuild.mjs +1 -1
- package/manager/processes/readDotEnv.mjs +2 -4
- package/manager/processes/startNextServer.mjs +0 -1
- package/manager/run.mjs +3 -1
- package/manager/watchers/envWatcher.mjs +2 -1
- package/package.json +34 -34
- package/pages/_app.js +3 -4
- package/pages/api/page/[pageId].js +2 -2
- package/pages/api/request/[pageId]/[requestId].js +5 -4
- package/pages/api/root.js +3 -2
package/lib/App.js
CHANGED
|
@@ -31,7 +31,7 @@ import blocks from '../build/plugins/blocks.js';
|
|
|
31
31
|
import icons from '../build/plugins/icons.js';
|
|
32
32
|
import operators from '../build/plugins/operators/client.js';
|
|
33
33
|
|
|
34
|
-
const App = () => {
|
|
34
|
+
const App = ({ auth }) => {
|
|
35
35
|
const router = useRouter();
|
|
36
36
|
const { data: rootConfig } = useRootConfig(router.basePath);
|
|
37
37
|
|
|
@@ -44,6 +44,7 @@ const App = () => {
|
|
|
44
44
|
<Reload basePath={router.basePath}>
|
|
45
45
|
{(resetContext) => (
|
|
46
46
|
<Page
|
|
47
|
+
auth={auth}
|
|
47
48
|
Components={{ Head, Link }}
|
|
48
49
|
config={{
|
|
49
50
|
rootConfig,
|
package/lib/Page.js
CHANGED
|
@@ -15,20 +15,14 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import React from 'react';
|
|
18
|
-
import { signIn, signOut, useSession } from 'next-auth/react';
|
|
19
|
-
|
|
20
18
|
import Client from '@lowdefy/client';
|
|
21
19
|
|
|
22
20
|
import RestartingPage from './RestartingPage.js';
|
|
23
21
|
import usePageConfig from './utils/usePageConfig.js';
|
|
24
22
|
|
|
25
|
-
const Page = ({ Components, config, pageId, resetContext, router, types }) => {
|
|
26
|
-
const { data: session, status } = useSession();
|
|
27
|
-
|
|
28
|
-
if (status === 'loading') {
|
|
29
|
-
return '';
|
|
30
|
-
}
|
|
23
|
+
const Page = ({ auth, Components, config, pageId, resetContext, router, types }) => {
|
|
31
24
|
const { data: pageConfig } = usePageConfig(pageId, router.basePath);
|
|
25
|
+
|
|
32
26
|
if (!pageConfig) {
|
|
33
27
|
router.replace(`/404`);
|
|
34
28
|
return '';
|
|
@@ -38,7 +32,7 @@ const Page = ({ Components, config, pageId, resetContext, router, types }) => {
|
|
|
38
32
|
}
|
|
39
33
|
return (
|
|
40
34
|
<Client
|
|
41
|
-
auth={
|
|
35
|
+
auth={auth}
|
|
42
36
|
Components={Components}
|
|
43
37
|
config={{
|
|
44
38
|
...config,
|
|
@@ -46,7 +40,6 @@ const Page = ({ Components, config, pageId, resetContext, router, types }) => {
|
|
|
46
40
|
}}
|
|
47
41
|
resetContext={resetContext}
|
|
48
42
|
router={router}
|
|
49
|
-
session={session}
|
|
50
43
|
stage="dev"
|
|
51
44
|
types={types}
|
|
52
45
|
window={window}
|
package/lib/auth/Auth.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2022 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
|
+
/* eslint-disable react/jsx-props-no-spreading */
|
|
17
|
+
|
|
18
|
+
import React from 'react';
|
|
19
|
+
import AuthConfigured from './AuthConfigured.js';
|
|
20
|
+
import AuthNotConfigured from './AuthNotConfigured.js';
|
|
21
|
+
|
|
22
|
+
import authConfig from '../../build/auth.json';
|
|
23
|
+
|
|
24
|
+
function Auth({ children, session }) {
|
|
25
|
+
if (authConfig.configured === true) {
|
|
26
|
+
return (
|
|
27
|
+
<AuthConfigured session={session} authConfig={authConfig}>
|
|
28
|
+
{(auth) => children(auth)}
|
|
29
|
+
</AuthConfigured>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
return <AuthNotConfigured authConfig={authConfig}>{(auth) => children(auth)}</AuthNotConfigured>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export default Auth;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2022 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
|
+
/* eslint-disable react/jsx-props-no-spreading */
|
|
17
|
+
|
|
18
|
+
import React from 'react';
|
|
19
|
+
import { SessionProvider, signIn, signOut, useSession } from 'next-auth/react';
|
|
20
|
+
|
|
21
|
+
function Session({ children }) {
|
|
22
|
+
const { data: session, status } = useSession();
|
|
23
|
+
// If session is passed to SessionProvider from getServerSideProps
|
|
24
|
+
// we won't have a loading state here.
|
|
25
|
+
// But 404 uses getStaticProps so we have this for 404.
|
|
26
|
+
if (status === 'loading') {
|
|
27
|
+
return '';
|
|
28
|
+
}
|
|
29
|
+
return children(session);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function AuthConfigured({ authConfig, children, serverSession }) {
|
|
33
|
+
const auth = { signIn, signOut, authConfig };
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<SessionProvider session={serverSession}>
|
|
37
|
+
<Session>
|
|
38
|
+
{(session) => {
|
|
39
|
+
auth.session = session;
|
|
40
|
+
return children(auth);
|
|
41
|
+
}}
|
|
42
|
+
</Session>
|
|
43
|
+
</SessionProvider>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export default AuthConfigured;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2022 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
|
+
/* eslint-disable react/jsx-props-no-spreading */
|
|
17
|
+
|
|
18
|
+
function authNotConfigured() {
|
|
19
|
+
throw new Error('Auth not configured.');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function AuthNotConfigured({ authConfig, children }) {
|
|
23
|
+
const auth = {
|
|
24
|
+
authConfig,
|
|
25
|
+
signIn: authNotConfigured,
|
|
26
|
+
signOut: authNotConfigured,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
return children(auth);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default AuthNotConfigured;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2022 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 { getSession } from 'next-auth/react';
|
|
18
|
+
import authJson from '../../build/auth.json';
|
|
19
|
+
|
|
20
|
+
async function getServerSession(context) {
|
|
21
|
+
if (authJson.configured === true) {
|
|
22
|
+
return await getSession(context);
|
|
23
|
+
}
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default getServerSession;
|
|
@@ -16,12 +16,10 @@
|
|
|
16
16
|
|
|
17
17
|
import path from 'path';
|
|
18
18
|
import dotenv from 'dotenv';
|
|
19
|
-
import { readFile } from '@lowdefy/node-utils';
|
|
20
19
|
|
|
21
20
|
function readDotEnv(context) {
|
|
22
|
-
return
|
|
23
|
-
|
|
24
|
-
context.serverEnv = dotenv.parse(dotEnv || '');
|
|
21
|
+
return () => {
|
|
22
|
+
dotenv.config({ path: path.join(context.directories.config, '.env'), silent: true });
|
|
25
23
|
};
|
|
26
24
|
}
|
|
27
25
|
|
package/manager/run.mjs
CHANGED
|
@@ -80,7 +80,9 @@ async function run() {
|
|
|
80
80
|
try {
|
|
81
81
|
const serverPromise = startServer(context);
|
|
82
82
|
await wait(800);
|
|
83
|
-
|
|
83
|
+
if (process.env.LOWDEFY_SERVER_DEV_OPEN_BROWSER === 'true') {
|
|
84
|
+
opener(`http://localhost:${context.options.port}`);
|
|
85
|
+
}
|
|
84
86
|
await serverPromise;
|
|
85
87
|
} catch (error) {
|
|
86
88
|
console.log(error);
|
|
@@ -21,7 +21,8 @@ import setupWatcher from '../utils/setupWatcher.mjs';
|
|
|
21
21
|
function envWatcher(context) {
|
|
22
22
|
const callback = async () => {
|
|
23
23
|
console.warn('.env file changed.');
|
|
24
|
-
|
|
24
|
+
context.readDotEnv();
|
|
25
|
+
await context.lowdefyBuild();
|
|
25
26
|
context.restartServer();
|
|
26
27
|
};
|
|
27
28
|
return setupWatcher({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowdefy/server-dev",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.14",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
@@ -39,50 +39,50 @@
|
|
|
39
39
|
"next": "next"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@lowdefy/actions-core": "4.0.0-alpha.
|
|
43
|
-
"@lowdefy/api": "4.0.0-alpha.
|
|
44
|
-
"@lowdefy/blocks-antd": "4.0.0-alpha.
|
|
45
|
-
"@lowdefy/blocks-basic": "4.0.0-alpha.
|
|
46
|
-
"@lowdefy/blocks-color-selectors": "4.0.0-alpha.
|
|
47
|
-
"@lowdefy/blocks-echarts": "4.0.0-alpha.
|
|
48
|
-
"@lowdefy/blocks-loaders": "4.0.0-alpha.
|
|
49
|
-
"@lowdefy/blocks-markdown": "4.0.0-alpha.
|
|
50
|
-
"@lowdefy/build": "4.0.0-alpha.
|
|
51
|
-
"@lowdefy/client": "4.0.0-alpha.
|
|
52
|
-
"@lowdefy/connection-axios-http": "4.0.0-alpha.
|
|
53
|
-
"@lowdefy/engine": "4.0.0-alpha.
|
|
54
|
-
"@lowdefy/helpers": "4.0.0-alpha.
|
|
55
|
-
"@lowdefy/layout": "4.0.0-alpha.
|
|
56
|
-
"@lowdefy/node-utils": "4.0.0-alpha.
|
|
57
|
-
"@lowdefy/operators-change-case": "4.0.0-alpha.
|
|
58
|
-
"@lowdefy/operators-diff": "4.0.0-alpha.
|
|
59
|
-
"@lowdefy/operators-js": "4.0.0-alpha.
|
|
60
|
-
"@lowdefy/operators-mql": "4.0.0-alpha.
|
|
61
|
-
"@lowdefy/operators-nunjucks": "4.0.0-alpha.
|
|
62
|
-
"@lowdefy/operators-uuid": "4.0.0-alpha.
|
|
63
|
-
"@lowdefy/operators-yaml": "4.0.0-alpha.
|
|
64
|
-
"@lowdefy/plugin-next-auth": "4.0.0-alpha.
|
|
42
|
+
"@lowdefy/actions-core": "4.0.0-alpha.14",
|
|
43
|
+
"@lowdefy/api": "4.0.0-alpha.14",
|
|
44
|
+
"@lowdefy/blocks-antd": "4.0.0-alpha.14",
|
|
45
|
+
"@lowdefy/blocks-basic": "4.0.0-alpha.14",
|
|
46
|
+
"@lowdefy/blocks-color-selectors": "4.0.0-alpha.14",
|
|
47
|
+
"@lowdefy/blocks-echarts": "4.0.0-alpha.14",
|
|
48
|
+
"@lowdefy/blocks-loaders": "4.0.0-alpha.14",
|
|
49
|
+
"@lowdefy/blocks-markdown": "4.0.0-alpha.14",
|
|
50
|
+
"@lowdefy/build": "4.0.0-alpha.14",
|
|
51
|
+
"@lowdefy/client": "4.0.0-alpha.14",
|
|
52
|
+
"@lowdefy/connection-axios-http": "4.0.0-alpha.14",
|
|
53
|
+
"@lowdefy/engine": "4.0.0-alpha.14",
|
|
54
|
+
"@lowdefy/helpers": "4.0.0-alpha.14",
|
|
55
|
+
"@lowdefy/layout": "4.0.0-alpha.14",
|
|
56
|
+
"@lowdefy/node-utils": "4.0.0-alpha.14",
|
|
57
|
+
"@lowdefy/operators-change-case": "4.0.0-alpha.14",
|
|
58
|
+
"@lowdefy/operators-diff": "4.0.0-alpha.14",
|
|
59
|
+
"@lowdefy/operators-js": "4.0.0-alpha.14",
|
|
60
|
+
"@lowdefy/operators-mql": "4.0.0-alpha.14",
|
|
61
|
+
"@lowdefy/operators-nunjucks": "4.0.0-alpha.14",
|
|
62
|
+
"@lowdefy/operators-uuid": "4.0.0-alpha.14",
|
|
63
|
+
"@lowdefy/operators-yaml": "4.0.0-alpha.14",
|
|
64
|
+
"@lowdefy/plugin-next-auth": "4.0.0-alpha.14",
|
|
65
65
|
"chokidar": "3.5.3",
|
|
66
|
-
"dotenv": "
|
|
66
|
+
"dotenv": "16.0.1",
|
|
67
67
|
"next": "12.1.6",
|
|
68
68
|
"next-auth": "4.3.4",
|
|
69
69
|
"opener": "1.5.2",
|
|
70
70
|
"process": "0.11.10",
|
|
71
|
-
"react": "
|
|
72
|
-
"react-dom": "
|
|
71
|
+
"react": "18.1.0",
|
|
72
|
+
"react-dom": "18.1.0",
|
|
73
73
|
"react-icons": "4.3.1",
|
|
74
|
-
"swr": "1.
|
|
75
|
-
"yaml": "2.
|
|
76
|
-
"yargs": "17.
|
|
74
|
+
"swr": "1.3.0",
|
|
75
|
+
"yaml": "2.1.1",
|
|
76
|
+
"yargs": "17.5.1"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
|
-
"@next/eslint-plugin-next": "12.
|
|
79
|
+
"@next/eslint-plugin-next": "12.1.6",
|
|
80
80
|
"less": "4.1.2",
|
|
81
|
-
"less-loader": "
|
|
82
|
-
"next-with-less": "2.0.
|
|
81
|
+
"less-loader": "11.0.0",
|
|
82
|
+
"next-with-less": "2.0.5"
|
|
83
83
|
},
|
|
84
84
|
"publishConfig": {
|
|
85
85
|
"access": "public"
|
|
86
86
|
},
|
|
87
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "9cc0b7280c82a16689c31aaf71be278f3a40edc6"
|
|
88
88
|
}
|
package/pages/_app.js
CHANGED
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
|
|
17
17
|
import React, { Suspense } from 'react';
|
|
18
18
|
import dynamic from 'next/dynamic';
|
|
19
|
-
|
|
19
|
+
|
|
20
|
+
import Auth from '../lib/auth/Auth.js';
|
|
20
21
|
|
|
21
22
|
// Must be in _app due to next specifications.
|
|
22
23
|
import '../build/plugins/styles.less';
|
|
@@ -24,9 +25,7 @@ import '../build/plugins/styles.less';
|
|
|
24
25
|
function App({ Component }) {
|
|
25
26
|
return (
|
|
26
27
|
<Suspense fallback="">
|
|
27
|
-
<
|
|
28
|
-
<Component />
|
|
29
|
-
</SessionProvider>
|
|
28
|
+
<Auth>{(auth) => <Component auth={auth} />}</Auth>
|
|
30
29
|
</Suspense>
|
|
31
30
|
);
|
|
32
31
|
}
|
|
@@ -15,10 +15,10 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import { createApiContext, getPageConfig } from '@lowdefy/api';
|
|
18
|
-
import
|
|
18
|
+
import getServerSession from '../../../lib/auth/getServerSession.js';
|
|
19
19
|
|
|
20
20
|
export default async function handler(req, res) {
|
|
21
|
-
const session = await
|
|
21
|
+
const session = await getServerSession({ req });
|
|
22
22
|
const apiContext = await createApiContext({
|
|
23
23
|
buildDirectory: './build',
|
|
24
24
|
logger: console,
|
|
@@ -16,8 +16,9 @@
|
|
|
16
16
|
|
|
17
17
|
import { callRequest, createApiContext } from '@lowdefy/api';
|
|
18
18
|
import { getSecretsFromEnv } from '@lowdefy/node-utils';
|
|
19
|
-
|
|
19
|
+
|
|
20
20
|
import connections from '../../../../build/plugins/connections.js';
|
|
21
|
+
import getServerSession from '../../../../lib/auth/getServerSession.js';
|
|
21
22
|
import operators from '../../../../build/plugins/operators/server.js';
|
|
22
23
|
|
|
23
24
|
export default async function handler(req, res) {
|
|
@@ -25,7 +26,7 @@ export default async function handler(req, res) {
|
|
|
25
26
|
if (req.method !== 'POST') {
|
|
26
27
|
throw new Error('Only POST requests are supported.');
|
|
27
28
|
}
|
|
28
|
-
const session = await
|
|
29
|
+
const session = await getServerSession({ req });
|
|
29
30
|
const apiContext = await createApiContext({
|
|
30
31
|
buildDirectory: './build',
|
|
31
32
|
connections,
|
|
@@ -35,9 +36,9 @@ export default async function handler(req, res) {
|
|
|
35
36
|
session,
|
|
36
37
|
});
|
|
37
38
|
|
|
38
|
-
const { pageId, requestId } = req.query;
|
|
39
|
+
const { blockId, pageId, requestId } = req.query;
|
|
39
40
|
const { payload } = req.body;
|
|
40
|
-
const response = await callRequest(apiContext, { pageId, payload, requestId });
|
|
41
|
+
const response = await callRequest(apiContext, { blockId, pageId, payload, requestId });
|
|
41
42
|
res.status(200).json(response);
|
|
42
43
|
} catch (error) {
|
|
43
44
|
res.status(500).json({ name: error.name, message: error.message });
|
package/pages/api/root.js
CHANGED
|
@@ -15,10 +15,11 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import { createApiContext, getRootConfig } from '@lowdefy/api';
|
|
18
|
-
|
|
18
|
+
|
|
19
|
+
import getServerSession from '../../lib/auth/getServerSession.js';
|
|
19
20
|
|
|
20
21
|
export default async function handler(req, res) {
|
|
21
|
-
const session = await
|
|
22
|
+
const session = await getServerSession({ req });
|
|
22
23
|
const apiContext = await createApiContext({
|
|
23
24
|
buildDirectory: './build',
|
|
24
25
|
logger: console,
|