@lowdefy/server 4.0.0-alpha.10 → 4.0.0-alpha.13

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
@@ -24,12 +24,13 @@ import Link from 'next/link';
24
24
  import actions from '../build/plugins/actions.js';
25
25
  import blocks from '../build/plugins/blocks.js';
26
26
  import icons from '../build/plugins/icons.js';
27
- import operators from '../build/plugins/operatorsClient.js';
27
+ import operators from '../build/plugins/operators/client.js';
28
28
 
29
- const Page = ({ pageConfig, rootConfig }) => {
29
+ const Page = ({ auth, pageConfig, rootConfig }) => {
30
30
  const router = useRouter();
31
31
  return (
32
32
  <Client
33
+ auth={auth}
33
34
  Components={{ Head, Link }}
34
35
  config={{
35
36
  pageConfig,
@@ -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;
@@ -33,6 +33,11 @@ async function getPluginDefinitions({ directories }) {
33
33
  async function createCustomPluginTypesMap({ directories }) {
34
34
  const customTypesMap = {
35
35
  actions: {},
36
+ auth: {
37
+ callbacks: {},
38
+ events: {},
39
+ providers: {},
40
+ },
36
41
  blocks: {},
37
42
  connections: {},
38
43
  icons: {},
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/server",
3
- "version": "4.0.0-alpha.10",
3
+ "version": "4.0.0-alpha.13",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -42,34 +42,35 @@
42
42
  "next": "next"
43
43
  },
44
44
  "dependencies": {
45
- "@lowdefy/actions-core": "4.0.0-alpha.10",
46
- "@lowdefy/api": "4.0.0-alpha.10",
47
- "@lowdefy/blocks-antd": "4.0.0-alpha.10",
48
- "@lowdefy/blocks-basic": "4.0.0-alpha.10",
49
- "@lowdefy/blocks-loaders": "4.0.0-alpha.10",
50
- "@lowdefy/client": "4.0.0-alpha.10",
51
- "@lowdefy/helpers": "4.0.0-alpha.10",
52
- "@lowdefy/layout": "4.0.0-alpha.10",
53
- "@lowdefy/node-utils": "4.0.0-alpha.10",
54
- "@lowdefy/operators-js": "4.0.0-alpha.10",
55
- "next": "12.0.10",
56
- "next-auth": "4.1.2",
45
+ "@lowdefy/actions-core": "4.0.0-alpha.13",
46
+ "@lowdefy/api": "4.0.0-alpha.13",
47
+ "@lowdefy/blocks-antd": "4.0.0-alpha.13",
48
+ "@lowdefy/blocks-basic": "4.0.0-alpha.13",
49
+ "@lowdefy/blocks-loaders": "4.0.0-alpha.13",
50
+ "@lowdefy/client": "4.0.0-alpha.13",
51
+ "@lowdefy/helpers": "4.0.0-alpha.13",
52
+ "@lowdefy/layout": "4.0.0-alpha.13",
53
+ "@lowdefy/node-utils": "4.0.0-alpha.13",
54
+ "@lowdefy/operators-js": "4.0.0-alpha.13",
55
+ "@lowdefy/plugin-next-auth": "4.0.0-alpha.13",
56
+ "next": "12.1.6",
57
+ "next-auth": "4.3.4",
57
58
  "process": "0.11.10",
58
- "react": "17.0.2",
59
- "react-dom": "17.0.2",
59
+ "react": "18.1.0",
60
+ "react-dom": "18.1.0",
60
61
  "react-icons": "4.3.1"
61
62
  },
62
63
  "devDependencies": {
63
- "@lowdefy/build": "4.0.0-alpha.10",
64
- "@next/eslint-plugin-next": "12.0.10",
64
+ "@lowdefy/build": "4.0.0-alpha.13",
65
+ "@next/eslint-plugin-next": "12.1.6",
65
66
  "less": "4.1.2",
66
- "less-loader": "10.2.0",
67
- "next-with-less": "2.0.4",
68
- "yaml": "1.10.2",
69
- "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"
70
71
  },
71
72
  "publishConfig": {
72
73
  "access": "public"
73
74
  },
74
- "gitHead": "d697b4b5f354697d9481a371b90a00ca0944f486"
75
+ "gitHead": "e99b4b6c1f59804982fc148c0fe39dcf13b35d77"
75
76
  }
package/pages/404.js CHANGED
@@ -19,7 +19,6 @@ import { createApiContext, getPageConfig, getRootConfig } from '@lowdefy/api';
19
19
  import Page from '../lib/Page.js';
20
20
 
21
21
  export async function getStaticProps() {
22
- // TODO: get the right api context options
23
22
  const apiContext = await createApiContext({ buildDirectory: './build' });
24
23
 
25
24
  const [rootConfig, pageConfig] = await Promise.all([
package/pages/[pageId].js CHANGED
@@ -16,12 +16,17 @@
16
16
 
17
17
  import { createApiContext, getPageConfig, getRootConfig } from '@lowdefy/api';
18
18
 
19
+ import getServerSession from '../lib/auth/getServerSession.js';
19
20
  import Page from '../lib/Page.js';
20
21
 
21
22
  export async function getServerSideProps(context) {
22
23
  const { pageId } = context.params;
23
- // TODO: get the right api context options
24
- const apiContext = await createApiContext({ buildDirectory: './build' });
24
+ const session = await getServerSession(context);
25
+ const apiContext = await createApiContext({
26
+ buildDirectory: './build',
27
+ logger: console,
28
+ session,
29
+ });
25
30
 
26
31
  const [rootConfig, pageConfig] = await Promise.all([
27
32
  getRootConfig(apiContext),
@@ -41,6 +46,7 @@ export async function getServerSideProps(context) {
41
46
  props: {
42
47
  pageConfig,
43
48
  rootConfig,
49
+ session,
44
50
  },
45
51
  };
46
52
  }
package/pages/_app.js CHANGED
@@ -13,15 +13,22 @@
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
20
 
21
+ import Auth from '../lib/auth/Auth.js';
22
+
20
23
  // Must be in _app due to next specifications.
21
24
  import '../build/plugins/styles.less';
22
25
 
23
- function App({ Component, pageProps }) {
24
- return <Component {...pageProps} />;
26
+ function App({ Component, pageProps: { session, rootConfig, pageConfig } }) {
27
+ return (
28
+ <Auth session={session}>
29
+ {(auth) => <Component auth={auth} rootConfig={rootConfig} pageConfig={pageConfig} />}
30
+ </Auth>
31
+ );
25
32
  }
26
33
 
27
34
  const DynamicApp = dynamic(() => Promise.resolve(App), {
@@ -15,14 +15,23 @@
15
15
  */
16
16
 
17
17
  import NextAuth from 'next-auth';
18
- import Auth0Provider from 'next-auth/providers/auth0';
18
+ import { getNextAuthConfig } from '@lowdefy/api';
19
19
 
20
- export default NextAuth({
21
- providers: [
22
- Auth0Provider({
23
- clientId: process.env.AUTH0_CLIENT_ID,
24
- clientSecret: process.env.AUTH0_CLIENT_SECRET,
25
- issuer: process.env.AUTH0_ISSUER,
26
- }),
27
- ],
28
- });
20
+ import authJson from '../../../build/auth.json';
21
+ import callbacks from '../../../build/plugins/auth/callbacks.js';
22
+ import events from '../../../build/plugins/auth/events.js';
23
+ import providers from '../../../build/plugins/auth/providers.js';
24
+
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
+ }
@@ -16,27 +16,31 @@
16
16
 
17
17
  import { callRequest, createApiContext } from '@lowdefy/api';
18
18
  import { getSecretsFromEnv } from '@lowdefy/node-utils';
19
+
20
+ import getServerSession from '../../../../lib/auth/getServerSession.js';
21
+
19
22
  import connections from '../../../../build/plugins/connections.js';
20
- import operators from '../../../../build/plugins/operatorsServer.js';
23
+ import operators from '../../../../build/plugins/operators/server.js';
21
24
 
22
25
  export default async function handler(req, res) {
23
26
  try {
24
27
  if (req.method !== 'POST') {
25
28
  throw new Error('Only POST requests are supported.');
26
29
  }
27
- // TODO: configure API context
30
+ const session = await getServerSession({ req });
28
31
  const apiContext = await createApiContext({
29
32
  buildDirectory: './build',
30
33
  connections,
31
- // TODO: use a logger like pino
32
- logger: console,
34
+ // logger: console,
35
+ logger: { debug: () => {} },
33
36
  operators,
34
37
  secrets: getSecretsFromEnv(),
38
+ session,
35
39
  });
36
- const { pageId, requestId } = req.query;
37
- const { payload } = req.body;
38
40
 
39
- const response = await callRequest(apiContext, { pageId, payload, requestId });
41
+ const { blockId, pageId, requestId } = req.query;
42
+ const { payload } = req.body;
43
+ const response = await callRequest(apiContext, { blockId, pageId, payload, requestId });
40
44
  res.status(200).json(response);
41
45
  } catch (error) {
42
46
  res.status(500).json({ name: error.name, message: error.message });
package/pages/index.js CHANGED
@@ -16,11 +16,17 @@
16
16
 
17
17
  import { createApiContext, getPageConfig, getRootConfig } from '@lowdefy/api';
18
18
 
19
+ import getServerSession from '../lib/auth/getServerSession.js';
19
20
  import Page from '../lib/Page.js';
20
21
 
21
- export async function getServerSideProps() {
22
- // TODO: is this build directory configurable from the cli?
23
- const apiContext = await createApiContext({ buildDirectory: './build' });
22
+ export async function getServerSideProps(context) {
23
+ const session = await getServerSession(context);
24
+
25
+ const apiContext = await createApiContext({
26
+ buildDirectory: './build',
27
+ logger: console,
28
+ session,
29
+ });
24
30
  const rootConfig = await getRootConfig(apiContext);
25
31
  const { home } = rootConfig;
26
32
  if (home.configured === false) {
@@ -44,6 +50,7 @@ export async function getServerSideProps() {
44
50
  props: {
45
51
  pageConfig,
46
52
  rootConfig,
53
+ session,
47
54
  },
48
55
  };
49
56
  }