@lowdefy/server 4.0.0-alpha.12 → 4.0.0-alpha.15

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/Page.js CHANGED
@@ -20,34 +20,23 @@ import { useRouter } from 'next/router';
20
20
  import Client from '@lowdefy/client';
21
21
  import Head from 'next/head';
22
22
  import Link from 'next/link';
23
- import { signIn, signOut, useSession } from 'next-auth/react';
24
23
 
25
24
  import actions from '../build/plugins/actions.js';
26
25
  import blocks from '../build/plugins/blocks.js';
27
26
  import icons from '../build/plugins/icons.js';
28
27
  import operators from '../build/plugins/operators/client.js';
29
28
 
30
- const Page = ({ pageConfig, rootConfig }) => {
29
+ const Page = ({ auth, pageConfig, rootConfig }) => {
31
30
  const router = useRouter();
32
- const { data: session, status } = useSession();
33
-
34
- // If session is passed to SessionProvider from getServerSideProps
35
- // we won't have a loading state here.
36
- // But 404 uses getStaticProps so we have this for 404.
37
- if (status === 'loading') {
38
- return '';
39
- }
40
-
41
31
  return (
42
32
  <Client
43
- auth={{ signIn, signOut }}
33
+ auth={auth}
44
34
  Components={{ Head, Link }}
45
35
  config={{
46
36
  pageConfig,
47
37
  rootConfig,
48
38
  }}
49
39
  router={router}
50
- session={session}
51
40
  types={{
52
41
  actions,
53
42
  blocks,
@@ -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;
package/lowdefy/build.mjs CHANGED
@@ -25,18 +25,15 @@ import createCustomPluginTypesMap from './createCustomPluginTypesMap.mjs';
25
25
  const argv = yargs(hideBin(process.argv)).argv;
26
26
 
27
27
  async function run() {
28
+ const serverDirectory = path.resolve(
29
+ argv.serverDirectory || process.env.LOWDEFY_DIRECTORY_SERVER || process.cwd()
30
+ );
28
31
  const directories = {
29
- build: path.resolve(
30
- argv.buildDirectory ||
31
- process.env.LOWDEFY_DIRECTORY_BUILD ||
32
- path.join(process.cwd(), 'build')
33
- ),
32
+ build: path.join(serverDirectory, 'build'),
34
33
  config: path.resolve(
35
34
  argv.configDirectory || process.env.LOWDEFY_DIRECTORY_CONFIG || process.cwd()
36
35
  ),
37
- server: path.resolve(
38
- argv.serverDirectory || process.env.LOWDEFY_DIRECTORY_SERVER || process.cwd()
39
- ),
36
+ server: serverDirectory,
40
37
  };
41
38
 
42
39
  const customTypesMap = await createCustomPluginTypesMap({ directories });
package/next.config.js CHANGED
@@ -30,6 +30,7 @@ module.exports = withLess({
30
30
  // experimental: {
31
31
  // concurrentFeatures: true,
32
32
  // },
33
+ outputFileTracing: true,
33
34
  eslint: {
34
35
  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.12",
3
+ "version": "4.0.0-alpha.15",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -42,35 +42,35 @@
42
42
  "next": "next"
43
43
  },
44
44
  "dependencies": {
45
- "@lowdefy/actions-core": "4.0.0-alpha.12",
46
- "@lowdefy/api": "4.0.0-alpha.12",
47
- "@lowdefy/blocks-antd": "4.0.0-alpha.12",
48
- "@lowdefy/blocks-basic": "4.0.0-alpha.12",
49
- "@lowdefy/blocks-loaders": "4.0.0-alpha.12",
50
- "@lowdefy/client": "4.0.0-alpha.12",
51
- "@lowdefy/helpers": "4.0.0-alpha.12",
52
- "@lowdefy/layout": "4.0.0-alpha.12",
53
- "@lowdefy/node-utils": "4.0.0-alpha.12",
54
- "@lowdefy/operators-js": "4.0.0-alpha.12",
55
- "@lowdefy/plugin-next-auth": "4.0.0-alpha.12",
56
- "next": "12.0.10",
45
+ "@lowdefy/actions-core": "4.0.0-alpha.15",
46
+ "@lowdefy/api": "4.0.0-alpha.15",
47
+ "@lowdefy/blocks-antd": "4.0.0-alpha.15",
48
+ "@lowdefy/blocks-basic": "4.0.0-alpha.15",
49
+ "@lowdefy/blocks-loaders": "4.0.0-alpha.15",
50
+ "@lowdefy/client": "4.0.0-alpha.15",
51
+ "@lowdefy/helpers": "4.0.0-alpha.15",
52
+ "@lowdefy/layout": "4.0.0-alpha.15",
53
+ "@lowdefy/node-utils": "4.0.0-alpha.15",
54
+ "@lowdefy/operators-js": "4.0.0-alpha.15",
55
+ "@lowdefy/plugin-next-auth": "4.0.0-alpha.15",
56
+ "next": "12.1.6",
57
57
  "next-auth": "4.3.4",
58
58
  "process": "0.11.10",
59
- "react": "17.0.2",
60
- "react-dom": "17.0.2",
59
+ "react": "18.1.0",
60
+ "react-dom": "18.1.0",
61
61
  "react-icons": "4.3.1"
62
62
  },
63
63
  "devDependencies": {
64
- "@lowdefy/build": "4.0.0-alpha.12",
65
- "@next/eslint-plugin-next": "12.0.10",
64
+ "@lowdefy/build": "4.0.0-alpha.15",
65
+ "@next/eslint-plugin-next": "12.1.6",
66
66
  "less": "4.1.2",
67
- "less-loader": "10.2.0",
68
- "next-with-less": "2.0.4",
69
- "yaml": "1.10.2",
70
- "yargs": "17.3.1"
67
+ "less-loader": "11.0.0",
68
+ "next-with-less": "2.0.5",
69
+ "yaml": "2.1.1",
70
+ "yargs": "17.5.1"
71
71
  },
72
72
  "publishConfig": {
73
73
  "access": "public"
74
74
  },
75
- "gitHead": "41b6138a81bee7da362dad06345bc9f87b2c2133"
75
+ "gitHead": "b4e4538475e997f95baa37f01f39689240e6f01c"
76
76
  }
package/pages/404.js CHANGED
@@ -13,13 +13,14 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */
16
-
16
+ import path from 'path';
17
17
  import { createApiContext, getPageConfig, getRootConfig } from '@lowdefy/api';
18
18
 
19
19
  import Page from '../lib/Page.js';
20
20
 
21
21
  export async function getStaticProps() {
22
- const apiContext = await createApiContext({ buildDirectory: './build' });
22
+ // Important to give absolute path so Next can trace build files
23
+ const apiContext = await createApiContext({ buildDirectory: path.join(process.cwd(), 'build') });
23
24
 
24
25
  const [rootConfig, pageConfig] = await Promise.all([
25
26
  getRootConfig(apiContext),
package/pages/[pageId].js CHANGED
@@ -14,16 +14,18 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
+ import path from 'path';
17
18
  import { createApiContext, getPageConfig, getRootConfig } from '@lowdefy/api';
18
- import { getSession } from 'next-auth/react';
19
19
 
20
+ import getServerSession from '../lib/auth/getServerSession.js';
20
21
  import Page from '../lib/Page.js';
21
22
 
22
23
  export async function getServerSideProps(context) {
23
24
  const { pageId } = context.params;
24
- const session = await getSession(context);
25
+ const session = await getServerSession(context);
26
+ // Important to give absolute path so Next can trace build files
25
27
  const apiContext = await createApiContext({
26
- buildDirectory: './build',
28
+ buildDirectory: path.join(process.cwd(), 'build'),
27
29
  logger: console,
28
30
  session,
29
31
  });
package/pages/_app.js CHANGED
@@ -13,20 +13,21 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */
16
+ /* eslint-disable react/jsx-props-no-spreading */
16
17
 
17
18
  import React from 'react';
18
19
  import dynamic from 'next/dynamic';
19
- import { SessionProvider } from 'next-auth/react';
20
+
21
+ import Auth from '../lib/auth/Auth.js';
20
22
 
21
23
  // Must be in _app due to next specifications.
22
24
  import '../build/plugins/styles.less';
23
25
 
24
- // TODO: SessionProvider requires basebath
25
- function App({ Component, pageProps: { session, ...pageProps } }) {
26
+ function App({ Component, pageProps: { session, rootConfig, pageConfig } }) {
26
27
  return (
27
- <SessionProvider session={session}>
28
- <Component {...pageProps} />
29
- </SessionProvider>
28
+ <Auth session={session}>
29
+ {(auth) => <Component auth={auth} rootConfig={rootConfig} pageConfig={pageConfig} />}
30
+ </Auth>
30
31
  );
31
32
  }
32
33
 
@@ -22,4 +22,16 @@ import callbacks from '../../../build/plugins/auth/callbacks.js';
22
22
  import events from '../../../build/plugins/auth/events.js';
23
23
  import providers from '../../../build/plugins/auth/providers.js';
24
24
 
25
- export default NextAuth(getNextAuthConfig({ authJson, plugins: { callbacks, events, providers } }));
25
+ export default async function auth(req, res) {
26
+ if (authJson.configured === true) {
27
+ return await NextAuth(
28
+ req,
29
+ res,
30
+ getNextAuthConfig({ authJson, plugins: { callbacks, events, providers } })
31
+ );
32
+ }
33
+
34
+ return res.status(404).json({
35
+ message: 'Auth not configured',
36
+ });
37
+ }
@@ -14,9 +14,12 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
+ import path from 'path';
17
18
  import { callRequest, createApiContext } from '@lowdefy/api';
18
19
  import { getSecretsFromEnv } from '@lowdefy/node-utils';
19
- import { getSession } from 'next-auth/react';
20
+
21
+ import getServerSession from '../../../../lib/auth/getServerSession.js';
22
+
20
23
  import connections from '../../../../build/plugins/connections.js';
21
24
  import operators from '../../../../build/plugins/operators/server.js';
22
25
 
@@ -25,9 +28,10 @@ export default async function handler(req, res) {
25
28
  if (req.method !== 'POST') {
26
29
  throw new Error('Only POST requests are supported.');
27
30
  }
28
- const session = await getSession({ req });
31
+ const session = await getServerSession({ req });
32
+ // Important to give absolute path so Next can trace build files
29
33
  const apiContext = await createApiContext({
30
- buildDirectory: './build',
34
+ buildDirectory: path.join(process.cwd(), 'build'),
31
35
  connections,
32
36
  // logger: console,
33
37
  logger: { debug: () => {} },
@@ -36,9 +40,9 @@ export default async function handler(req, res) {
36
40
  session,
37
41
  });
38
42
 
39
- const { pageId, requestId } = req.query;
43
+ const { blockId, pageId, requestId } = req.query;
40
44
  const { payload } = req.body;
41
- const response = await callRequest(apiContext, { pageId, payload, requestId });
45
+ const response = await callRequest(apiContext, { blockId, pageId, payload, requestId });
42
46
  res.status(200).json(response);
43
47
  } catch (error) {
44
48
  res.status(500).json({ name: error.name, message: error.message });
package/pages/index.js CHANGED
@@ -14,15 +14,18 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
+ import path from 'path';
17
18
  import { createApiContext, getPageConfig, getRootConfig } from '@lowdefy/api';
18
- import { getSession } from 'next-auth/react';
19
19
 
20
+ import getServerSession from '../lib/auth/getServerSession.js';
20
21
  import Page from '../lib/Page.js';
21
22
 
22
23
  export async function getServerSideProps(context) {
23
- const session = await getSession(context);
24
+ const session = await getServerSession(context);
25
+
26
+ // Important to give absolute path so Next can trace build files
24
27
  const apiContext = await createApiContext({
25
- buildDirectory: './build',
28
+ buildDirectory: path.join(process.cwd(), 'build'),
26
29
  logger: console,
27
30
  session,
28
31
  });