@lowdefy/server 4.0.0-rc.1 → 4.0.0-rc.11

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.
@@ -21,12 +21,12 @@ import Client from '@lowdefy/client';
21
21
  import Head from 'next/head';
22
22
  import Link from 'next/link';
23
23
 
24
- import actions from '../build/plugins/actions.js';
25
- import blocks from '../build/plugins/blocks.js';
26
- import icons from '../build/plugins/icons.js';
27
- import operators from '../build/plugins/operators/client.js';
24
+ import actions from '../../build/plugins/actions.js';
25
+ import blocks from '../../build/plugins/blocks.js';
26
+ import icons from '../../build/plugins/icons.js';
27
+ import operators from '../../build/plugins/operators/client.js';
28
28
 
29
- const Page = ({ auth, pageConfig, rootConfig }) => {
29
+ const Page = ({ auth, lowdefy, pageConfig, rootConfig }) => {
30
30
  const router = useRouter();
31
31
  return (
32
32
  <Client
@@ -36,6 +36,7 @@ const Page = ({ auth, pageConfig, rootConfig }) => {
36
36
  pageConfig,
37
37
  rootConfig,
38
38
  }}
39
+ lowdefy={lowdefy}
39
40
  router={router}
40
41
  types={{
41
42
  actions,
@@ -19,12 +19,12 @@ import React from 'react';
19
19
  import AuthConfigured from './AuthConfigured.js';
20
20
  import AuthNotConfigured from './AuthNotConfigured.js';
21
21
 
22
- import authConfig from '../../build/auth.json';
22
+ import authConfig from '../../../build/auth.json';
23
23
 
24
24
  function Auth({ children, session }) {
25
25
  if (authConfig.configured === true) {
26
26
  return (
27
- <AuthConfigured session={session} authConfig={authConfig}>
27
+ <AuthConfigured serverSession={session} authConfig={authConfig}>
28
28
  {(auth) => children(auth)}
29
29
  </AuthConfigured>
30
30
  );
@@ -15,11 +15,22 @@
15
15
  */
16
16
  /* eslint-disable react/jsx-props-no-spreading */
17
17
 
18
- import React from 'react';
19
- import { SessionProvider, signIn, signOut, useSession } from 'next-auth/react';
18
+ import React, { useEffect, useRef } from 'react';
19
+ import { getSession, SessionProvider, signIn, signOut, useSession } from 'next-auth/react';
20
+
21
+ import lowdefyConfig from '../../../build/config.json';
20
22
 
21
23
  function Session({ children }) {
24
+ const wasAuthenticated = useRef(false);
22
25
  const { data: session, status } = useSession();
26
+ wasAuthenticated.current = wasAuthenticated.current || status === 'authenticated';
27
+
28
+ useEffect(() => {
29
+ if (wasAuthenticated.current && status === 'unauthenticated') {
30
+ window.location.reload();
31
+ }
32
+ }, [status]);
33
+
23
34
  // If session is passed to SessionProvider from getServerSideProps
24
35
  // we won't have a loading state here.
25
36
  // But 404 uses getStaticProps so we have this for 404.
@@ -30,10 +41,13 @@ function Session({ children }) {
30
41
  }
31
42
 
32
43
  function AuthConfigured({ authConfig, children, serverSession }) {
33
- const auth = { signIn, signOut, authConfig };
34
-
44
+ const auth = { authConfig, getSession, signIn, signOut };
45
+ let basePath = lowdefyConfig.basePath;
46
+ if (basePath) {
47
+ basePath = `${basePath}/api/auth`;
48
+ }
35
49
  return (
36
- <SessionProvider session={serverSession}>
50
+ <SessionProvider session={serverSession} basePath={basePath}>
37
51
  <Session>
38
52
  {(session) => {
39
53
  auth.session = session;
@@ -22,6 +22,7 @@ function authNotConfigured() {
22
22
  function AuthNotConfigured({ authConfig, children }) {
23
23
  const auth = {
24
24
  authConfig,
25
+ getSession: authNotConfigured,
25
26
  signIn: authNotConfigured,
26
27
  signOut: authNotConfigured,
27
28
  };
@@ -0,0 +1,63 @@
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
+ import path from 'path';
17
+ import crypto from 'crypto';
18
+ import { createApiContext } from '@lowdefy/api';
19
+ import { getSecretsFromEnv } from '@lowdefy/node-utils';
20
+
21
+ import config from '../../build/config.json';
22
+ import connections from '../../build/plugins/connections.js';
23
+ import createLogger from './log/createLogger.js';
24
+ import fileCache from './fileCache.js';
25
+ import getServerSession from './auth/getServerSession.js';
26
+ import logError from './log/logError.js';
27
+ import logRequest from './log/logRequest.js';
28
+ import operators from '../../build/plugins/operators/server.js';
29
+ import getAuthOptions from './auth/getAuthOptions.js';
30
+
31
+ function apiWrapper(handler) {
32
+ return async function wrappedHandler(req, res) {
33
+ const context = {
34
+ // Important to give absolute path so Next can trace build files
35
+ rid: crypto.randomUUID(),
36
+ buildDirectory: path.join(process.cwd(), 'build'),
37
+ config,
38
+ connections,
39
+ fileCache,
40
+ headers: req?.headers,
41
+ logger: console,
42
+ operators,
43
+ req,
44
+ res,
45
+ };
46
+ try {
47
+ context.logger = createLogger({ rid: context.rid });
48
+ context.authOptions = getAuthOptions(context);
49
+ context.session = await getServerSession(context);
50
+ context.secrets = getSecretsFromEnv();
51
+ createApiContext(context);
52
+ logRequest({ context });
53
+ // Await here so that if handler throws it is caught.
54
+ const response = await handler({ context, req, res });
55
+ return response;
56
+ } catch (error) {
57
+ logError({ error, context });
58
+ res.status(500).json({ name: error.name, message: error.message });
59
+ }
60
+ };
61
+ }
62
+
63
+ export default apiWrapper;
@@ -0,0 +1,35 @@
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 { getNextAuthConfig } from '@lowdefy/api';
18
+ import { getSecretsFromEnv } from '@lowdefy/node-utils';
19
+
20
+ import adapters from '../../../build/plugins/auth/adapters.js';
21
+ import authJson from '../../../build/auth.json';
22
+ import callbacks from '../../../build/plugins/auth/callbacks.js';
23
+ import events from '../../../build/plugins/auth/events.js';
24
+ import providers from '../../../build/plugins/auth/providers.js';
25
+
26
+ function getAuthOptions({ logger }) {
27
+ return getNextAuthConfig({
28
+ authJson,
29
+ logger,
30
+ plugins: { adapters, callbacks, events, providers },
31
+ secrets: getSecretsFromEnv(),
32
+ });
33
+ }
34
+
35
+ export default getAuthOptions;
@@ -14,13 +14,13 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
- import { unstable_getServerSession } from 'next-auth/next';
18
- import { authOptions } from '../../pages/api/auth/[...nextauth].js';
19
- import authJson from '../../build/auth.json';
17
+ import { getServerSession as getNextAuthServerSession } from 'next-auth/next';
20
18
 
21
- async function getServerSession({ req, res }) {
19
+ import authJson from '../../../build/auth.json';
20
+
21
+ function getServerSession({ authOptions, req, res }) {
22
22
  if (authJson.configured === true) {
23
- return await unstable_getServerSession(req, res, authOptions);
23
+ return getNextAuthServerSession(req, res, authOptions);
24
24
  }
25
25
  return undefined;
26
26
  }
@@ -0,0 +1,30 @@
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 pino from 'pino';
18
+
19
+ // TODO: Pino does not serialize error.cause properties if the cause object is not an Error (or Error-like)
20
+ const logger = pino({
21
+ name: 'lowdefy_server',
22
+ level: process.env.LOWDEFY_LOG_LEVEL ?? 'info',
23
+ base: { pid: undefined, hostname: undefined },
24
+ });
25
+
26
+ function createLogger(metadata = {}) {
27
+ return logger.child(metadata);
28
+ }
29
+
30
+ export default createLogger;
@@ -0,0 +1,72 @@
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
+ function logError({ context, error }) {
18
+ try {
19
+ const { headers = {}, user = {} } = context;
20
+
21
+ context.logger.error({
22
+ // TODO:
23
+ // app_name
24
+ // app_version
25
+ // lowdefy_version
26
+ // build_hash
27
+ // config_hash
28
+ err: error,
29
+ user: {
30
+ id: user.id,
31
+ roles: user.roles,
32
+ sub: user.sub,
33
+ session_id: user.session_id,
34
+ },
35
+ url: context.req.url,
36
+ method: context.req.method,
37
+ resolvedUrl: context.nextContext?.resolvedUrl,
38
+ hostname: context.req.hostname,
39
+ headers: {
40
+ 'accept-language': headers['accept-language'],
41
+ 'sec-ch-ua-mobile': headers['sec-ch-ua-mobile'],
42
+ 'sec-ch-ua-platform': headers['sec-ch-ua-platform'],
43
+ 'sec-ch-ua': headers['sec-ch-ua'],
44
+ 'user-agent': headers['user-agent'],
45
+ host: headers.host,
46
+ referer: headers.referer,
47
+ // Non localhost headers
48
+ 'x-forward-for': headers['x-forward-for'],
49
+ // Vercel headers
50
+ 'x-vercel-id': headers['x-vercel-id'],
51
+ 'x-real-ip': headers['x-real-ip'],
52
+ 'x-vercel-ip-country': headers['x-vercel-ip-country'],
53
+ 'x-vercel-ip-country-region': headers['x-vercel-ip-country-region'],
54
+ 'x-vercel-ip-city': headers['x-vercel-ip-city'],
55
+ 'x-vercel-ip-latitude': headers['x-vercel-ip-latitude'],
56
+ 'x-vercel-ip-longitude': headers['x-vercel-ip-longitude'],
57
+ 'x-vercel-ip-timezone': headers['x-vercel-ip-timezone'],
58
+ // Cloudflare headers
59
+ 'cf-connecting-ip': headers['cf-connecting-ip'],
60
+ 'cf-ray': headers['cf-ray'],
61
+ 'cf-ipcountry': headers['cf-ipcountry'],
62
+ 'cf-visitor': headers['cf-visitor'],
63
+ },
64
+ });
65
+ } catch (e) {
66
+ console.error(error);
67
+ console.error('An error occurred while logging the error.');
68
+ console.error(e);
69
+ }
70
+ }
71
+
72
+ export default logError;
@@ -0,0 +1,66 @@
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
+ // TODO: Better name needed here maybe?
18
+ function logRequest({ context }) {
19
+ const { headers = {}, user = {} } = context;
20
+ context.logger.info({
21
+ // TODO:
22
+ // app_name
23
+ // app_version
24
+ // lowdefy_version
25
+ // build_hash
26
+ // config_hash
27
+ user: {
28
+ id: user.id,
29
+ roles: user.roles,
30
+ sub: user.sub,
31
+ session_id: user.session_id, // TODO: Implement session id
32
+ },
33
+ url: context.req.url,
34
+ method: context.req.method,
35
+ resolvedUrl: context.nextContext?.resolvedUrl,
36
+ hostname: context.req.hostname,
37
+ headers: {
38
+ 'accept-language': headers['accept-language'],
39
+ 'sec-ch-ua-mobile': headers['sec-ch-ua-mobile'],
40
+ 'sec-ch-ua-platform': headers['sec-ch-ua-platform'],
41
+ 'sec-ch-ua': headers['sec-ch-ua'],
42
+ 'user-agent': headers['user-agent'],
43
+ host: headers.host,
44
+ referer: headers.referer,
45
+ 'x-forward-for': headers['x-forward-for'],
46
+ // Vercel headers
47
+ 'x-vercel-id': headers['x-vercel-id'],
48
+ 'x-real-ip': headers['x-real-ip'],
49
+ 'x-vercel-ip-country': headers['x-vercel-ip-country'],
50
+ 'x-vercel-ip-country-region': headers['x-vercel-ip-country-region'],
51
+ 'x-vercel-ip-city': headers['x-vercel-ip-city'],
52
+ 'x-vercel-ip-latitude': headers['x-vercel-ip-latitude'],
53
+ 'x-vercel-ip-longitude': headers['x-vercel-ip-longitude'],
54
+ 'x-vercel-ip-timezone': headers['x-vercel-ip-timezone'],
55
+ // Cloudflare headers
56
+ 'cf-connecting-ip': headers['cf-connecting-ip'],
57
+ 'cf-ray': headers['cf-ray'],
58
+ 'cf-ipcountry': headers['cf-ipcountry'],
59
+ 'cf-visitor': headers['cf-visitor'],
60
+ },
61
+ });
62
+ // TODO:
63
+ // Next local? nextContext.locale, nextContext.locales, nextContext.defaultLocale
64
+ }
65
+
66
+ export default logRequest;
@@ -0,0 +1,59 @@
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
+ import path from 'path';
17
+ import crypto from 'crypto';
18
+ import { createApiContext } from '@lowdefy/api';
19
+
20
+ import config from '../../build/config.json';
21
+ import createLogger from './log/createLogger.js';
22
+ import fileCache from './fileCache.js';
23
+ import getServerSession from './auth/getServerSession.js';
24
+ import logError from './log/logError.js';
25
+ import logRequest from './log/logRequest.js';
26
+ import getAuthOptions from './auth/getAuthOptions.js';
27
+
28
+ // TODO: Merge serverSidePropsWrapper and apiWrapper?
29
+ function serverSidePropsWrapper(handler) {
30
+ return async function wrappedHandler(nextContext) {
31
+ const context = {
32
+ // Important to give absolute path so Next can trace build files
33
+ rid: crypto.randomUUID(),
34
+ buildDirectory: path.join(process.cwd(), 'build'),
35
+ config,
36
+ fileCache,
37
+ headers: nextContext?.req?.headers,
38
+ logger: console,
39
+ nextContext,
40
+ req: nextContext?.req,
41
+ res: nextContext?.res,
42
+ };
43
+ try {
44
+ context.logger = createLogger({ rid: context.rid });
45
+ context.authOptions = getAuthOptions(context);
46
+ context.session = await getServerSession(context);
47
+ createApiContext(context);
48
+ logRequest({ context });
49
+ // Await here so that if handler throws it is caught.
50
+ const response = await handler({ context, nextContext });
51
+ return response;
52
+ } catch (error) {
53
+ logError({ error, context });
54
+ throw error;
55
+ }
56
+ };
57
+ }
58
+
59
+ export default serverSidePropsWrapper;
package/lowdefy/build.mjs CHANGED
@@ -16,6 +16,7 @@
16
16
  */
17
17
 
18
18
  import path from 'path';
19
+ import pino from 'pino';
19
20
  import yargs from 'yargs';
20
21
  import { hideBin } from 'yargs/helpers';
21
22
 
@@ -37,10 +38,23 @@ async function run() {
37
38
  };
38
39
 
39
40
  const customTypesMap = await createCustomPluginTypesMap({ directories });
41
+
42
+ const logger = pino({
43
+ name: 'lowdefy_build',
44
+ level: process.env.LOWDEFY_LOG_LEVEL ?? 'info',
45
+ base: { pid: undefined, hostname: undefined },
46
+ mixin: (context, level) => {
47
+ return {
48
+ ...context,
49
+ print: context.print ?? logger.levels.labels[level],
50
+ };
51
+ },
52
+ });
53
+
40
54
  await build({
41
55
  customTypesMap,
42
56
  directories,
43
- logger: console,
57
+ logger,
44
58
  refResolver: argv.refResolver || process.env.LOWDEFY_BUILD_REF_RESOLVER,
45
59
  });
46
60
  }
package/next.config.js CHANGED
@@ -2,7 +2,7 @@ const withLess = require('next-with-less');
2
2
  const lowdefyConfig = require('./build/config.json');
3
3
 
4
4
  module.exports = withLess({
5
- basePath: process.env.LOWDEFY_BASE_PATH || lowdefyConfig.basePath,
5
+ basePath: lowdefyConfig.basePath,
6
6
  reactStrictMode: true,
7
7
  webpack: (config, { isServer }) => {
8
8
  if (!isServer) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/server",
3
- "version": "4.0.0-rc.1",
3
+ "version": "4.0.0-rc.11",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -29,7 +29,7 @@
29
29
  "lib/*",
30
30
  "lowdefy/*",
31
31
  "pages/*",
32
- "public/*",
32
+ "public_default/*",
33
33
  "next.config.js",
34
34
  "package.original.json",
35
35
  ".eslintrc.yaml",
@@ -45,37 +45,40 @@
45
45
  "next": "next"
46
46
  },
47
47
  "dependencies": {
48
- "@lowdefy/actions-core": "4.0.0-rc.1",
49
- "@lowdefy/api": "4.0.0-rc.1",
50
- "@lowdefy/blocks-antd": "4.0.0-rc.1",
51
- "@lowdefy/blocks-basic": "4.0.0-rc.1",
52
- "@lowdefy/blocks-loaders": "4.0.0-rc.1",
53
- "@lowdefy/client": "4.0.0-rc.1",
54
- "@lowdefy/helpers": "4.0.0-rc.1",
55
- "@lowdefy/layout": "4.0.0-rc.1",
56
- "@lowdefy/node-utils": "4.0.0-rc.1",
57
- "@lowdefy/operators-js": "4.0.0-rc.1",
58
- "@lowdefy/plugin-next-auth": "4.0.0-rc.1",
59
- "next": "12.3.1",
60
- "next-auth": "4.18.8",
48
+ "@lowdefy/actions-core": "4.0.0-rc.11",
49
+ "@lowdefy/api": "4.0.0-rc.11",
50
+ "@lowdefy/blocks-antd": "4.0.0-rc.11",
51
+ "@lowdefy/blocks-basic": "4.0.0-rc.11",
52
+ "@lowdefy/blocks-loaders": "4.0.0-rc.11",
53
+ "@lowdefy/client": "4.0.0-rc.11",
54
+ "@lowdefy/helpers": "4.0.0-rc.11",
55
+ "@lowdefy/layout": "4.0.0-rc.11",
56
+ "@lowdefy/node-utils": "4.0.0-rc.11",
57
+ "@lowdefy/operators-js": "4.0.0-rc.11",
58
+ "@lowdefy/plugin-next-auth": "4.0.0-rc.11",
59
+ "next": "13.5.4",
60
+ "next-auth": "4.23.2",
61
+ "pino": "8.15.6",
61
62
  "process": "0.11.10",
62
63
  "react": "18.2.0",
63
64
  "react-dom": "18.2.0",
64
- "react-icons": "4.7.1"
65
+ "react-icons": "4.11.0"
65
66
  },
66
67
  "devDependencies": {
67
- "@lowdefy/build": "4.0.0-rc.1",
68
- "@next/eslint-plugin-next": "12.1.6",
69
- "less": "4.1.3",
70
- "less-loader": "11.1.0",
71
- "next-with-less": "2.0.5",
72
- "webpack": "5.75.0",
73
- "yaml": "2.2.1",
74
- "yargs": "17.6.2"
68
+ "@lowdefy/build": "4.0.0-rc.11",
69
+ "@next/eslint-plugin-next": "13.5.4",
70
+ "less": "4.2.0",
71
+ "less-loader": "11.1.3",
72
+ "next-with-less": "3.0.1",
73
+ "webpack": "5.88.2",
74
+ "yaml": "2.3.2",
75
+ "yargs": "17.7.2"
76
+ },
77
+ "engines": {
78
+ "node": ">=18"
75
79
  },
76
- "packageManager": "pnpm@7.11.0",
77
80
  "publishConfig": {
78
81
  "access": "public"
79
82
  },
80
- "gitHead": "ecc4f16c19eede929eda177db524cf13a8053379"
83
+ "gitHead": "dbc49d3688a6d2f44de25cc3f4bc071627f7ebfa"
81
84
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/server",
3
- "version": "4.0.0-rc.1",
3
+ "version": "4.0.0-rc.11",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -29,7 +29,7 @@
29
29
  "lib/*",
30
30
  "lowdefy/*",
31
31
  "pages/*",
32
- "public/*",
32
+ "public_default/*",
33
33
  "next.config.js",
34
34
  "package.original.json",
35
35
  ".eslintrc.yaml",
@@ -45,36 +45,40 @@
45
45
  "next": "next"
46
46
  },
47
47
  "dependencies": {
48
- "@lowdefy/actions-core": "4.0.0-rc.1",
49
- "@lowdefy/api": "4.0.0-rc.1",
50
- "@lowdefy/blocks-antd": "4.0.0-rc.1",
51
- "@lowdefy/blocks-basic": "4.0.0-rc.1",
52
- "@lowdefy/blocks-loaders": "4.0.0-rc.1",
53
- "@lowdefy/client": "4.0.0-rc.1",
54
- "@lowdefy/helpers": "4.0.0-rc.1",
55
- "@lowdefy/layout": "4.0.0-rc.1",
56
- "@lowdefy/node-utils": "4.0.0-rc.1",
57
- "@lowdefy/operators-js": "4.0.0-rc.1",
58
- "@lowdefy/plugin-next-auth": "4.0.0-rc.1",
59
- "next": "12.3.1",
60
- "next-auth": "4.18.8",
48
+ "@lowdefy/actions-core": "4.0.0-rc.11",
49
+ "@lowdefy/api": "4.0.0-rc.11",
50
+ "@lowdefy/blocks-antd": "4.0.0-rc.11",
51
+ "@lowdefy/blocks-basic": "4.0.0-rc.11",
52
+ "@lowdefy/blocks-loaders": "4.0.0-rc.11",
53
+ "@lowdefy/client": "4.0.0-rc.11",
54
+ "@lowdefy/helpers": "4.0.0-rc.11",
55
+ "@lowdefy/layout": "4.0.0-rc.11",
56
+ "@lowdefy/node-utils": "4.0.0-rc.11",
57
+ "@lowdefy/operators-js": "4.0.0-rc.11",
58
+ "@lowdefy/plugin-next-auth": "4.0.0-rc.11",
59
+ "next": "13.5.4",
60
+ "next-auth": "4.23.2",
61
+ "pino": "8.15.6",
61
62
  "process": "0.11.10",
62
63
  "react": "18.2.0",
63
64
  "react-dom": "18.2.0",
64
- "react-icons": "4.7.1"
65
+ "react-icons": "4.11.0"
65
66
  },
66
67
  "devDependencies": {
67
- "@lowdefy/build": "4.0.0-rc.1",
68
- "@next/eslint-plugin-next": "12.1.6",
69
- "less": "4.1.3",
70
- "less-loader": "11.1.0",
71
- "next-with-less": "2.0.5",
72
- "webpack": "5.75.0",
73
- "yaml": "2.2.1",
74
- "yargs": "17.6.2"
68
+ "@lowdefy/build": "4.0.0-rc.11",
69
+ "@next/eslint-plugin-next": "13.5.4",
70
+ "less": "4.2.0",
71
+ "less-loader": "11.1.3",
72
+ "next-with-less": "3.0.1",
73
+ "webpack": "5.88.2",
74
+ "yaml": "2.3.2",
75
+ "yargs": "17.7.2"
76
+ },
77
+ "engines": {
78
+ "node": ">=18"
75
79
  },
76
- "packageManager": "pnpm@7.11.0",
77
80
  "publishConfig": {
78
81
  "access": "public"
79
- }
82
+ },
83
+ "gitHead": "dbc49d3688a6d2f44de25cc3f4bc071627f7ebfa"
80
84
  }
package/pages/404.js CHANGED
@@ -17,21 +17,22 @@ import path from 'path';
17
17
  import { createApiContext, getPageConfig, getRootConfig } from '@lowdefy/api';
18
18
 
19
19
  import config from '../build/config.json';
20
- import fileCache from '../lib/fileCache.js';
21
- import Page from '../lib/Page.js';
20
+ import fileCache from '../lib/server/fileCache.js';
21
+ import Page from '../lib/client/Page.js';
22
22
 
23
23
  export async function getStaticProps() {
24
24
  // Important to give absolute path so Next can trace build files
25
- const apiContext = createApiContext({
25
+ const context = {
26
26
  buildDirectory: path.join(process.cwd(), 'build'),
27
27
  config,
28
28
  fileCache,
29
- logger: console,
30
- });
29
+ logger: console, // TODO: pino or console or 🤷‍♂️?
30
+ };
31
+ createApiContext(context);
31
32
 
32
33
  const [rootConfig, pageConfig] = await Promise.all([
33
- getRootConfig(apiContext),
34
- getPageConfig(apiContext, { pageId: '404' }),
34
+ getRootConfig(context),
35
+ getPageConfig(context, { pageId: '404' }),
35
36
  ]);
36
37
 
37
38
  return {
package/pages/[pageId].js CHANGED
@@ -14,32 +14,21 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
- import path from 'path';
18
- import { createApiContext, getPageConfig, getRootConfig } from '@lowdefy/api';
19
-
20
- import config from '../build/config.json';
21
- import fileCache from '../lib/fileCache.js';
22
- import getServerSession from '../lib/auth/getServerSession.js';
23
- import Page from '../lib/Page.js';
24
-
25
- export async function getServerSideProps(context) {
26
- const { pageId } = context.params;
27
- const session = await getServerSession(context);
28
- // Important to give absolute path so Next can trace build files
29
- const apiContext = createApiContext({
30
- buildDirectory: path.join(process.cwd(), 'build'),
31
- config,
32
- fileCache,
33
- logger: console,
34
- session,
35
- });
17
+ import { getPageConfig, getRootConfig } from '@lowdefy/api';
36
18
 
19
+ import serverSidePropsWrapper from '../lib/server/serverSidePropsWrapper.js';
20
+ import Page from '../lib/client/Page.js';
21
+
22
+ async function getServerSidePropsHandler({ context, nextContext }) {
23
+ const { pageId } = nextContext.params;
24
+ const { logger } = context;
37
25
  const [rootConfig, pageConfig] = await Promise.all([
38
- getRootConfig(apiContext),
39
- getPageConfig(apiContext, { pageId }),
26
+ getRootConfig(context),
27
+ getPageConfig(context, { pageId }),
40
28
  ]);
41
29
 
42
30
  if (!pageConfig) {
31
+ logger.info({ event: 'redirect_page_not_found', pageId });
43
32
  return {
44
33
  redirect: {
45
34
  destination: '/404',
@@ -47,14 +36,16 @@ export async function getServerSideProps(context) {
47
36
  },
48
37
  };
49
38
  }
50
-
39
+ logger.info({ event: 'page_view', pageId });
51
40
  return {
52
41
  props: {
53
42
  pageConfig,
54
43
  rootConfig,
55
- session,
44
+ session: context.session,
56
45
  },
57
46
  };
58
47
  }
59
48
 
49
+ export const getServerSideProps = serverSidePropsWrapper(getServerSidePropsHandler);
50
+
60
51
  export default Page;
package/pages/_app.js CHANGED
@@ -15,18 +15,26 @@
15
15
  */
16
16
  /* eslint-disable react/jsx-props-no-spreading */
17
17
 
18
- import React from 'react';
18
+ import React, { useRef } from 'react';
19
19
  import dynamic from 'next/dynamic';
20
20
 
21
- import Auth from '../lib/auth/Auth.js';
21
+ import Auth from '../lib/client/auth/Auth.js';
22
22
 
23
23
  // Must be in _app due to next specifications.
24
24
  import '../build/plugins/styles.less';
25
25
 
26
26
  function App({ Component, pageProps: { session, rootConfig, pageConfig } }) {
27
+ const lowdefyRef = useRef({});
27
28
  return (
28
29
  <Auth session={session}>
29
- {(auth) => <Component auth={auth} rootConfig={rootConfig} pageConfig={pageConfig} />}
30
+ {(auth) => (
31
+ <Component
32
+ auth={auth}
33
+ lowdefy={lowdefyRef.current}
34
+ rootConfig={rootConfig}
35
+ pageConfig={pageConfig}
36
+ />
37
+ )}
30
38
  </Auth>
31
39
  );
32
40
  }
@@ -16,16 +16,20 @@
16
16
 
17
17
  import React from 'react';
18
18
  import Document, { Html, Head, Main, NextScript } from 'next/document';
19
+
19
20
  import appJson from '../build/app.json';
21
+ import lowdefyConfig from '../build/config.json';
22
+
23
+ const basePath = lowdefyConfig.basePath ?? '';
20
24
 
21
25
  class LowdefyDocument extends Document {
22
26
  render() {
23
27
  return (
24
28
  <Html>
25
29
  <Head>
26
- <link rel="manifest" href="/manifest.webmanifest" />
27
- <link rel="icon" type="image/svg+xml" href="/icon.svg" />
28
- <link rel="apple-touch-icon" href="/apple-touch-icon.png" />
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`} />
29
33
  <meta name="viewport" content="width=device-width, initial-scale=1" />
30
34
  <script
31
35
  dangerouslySetInnerHTML={{
@@ -15,31 +15,23 @@
15
15
  */
16
16
 
17
17
  import NextAuth from 'next-auth';
18
- import { createApiContext, getNextAuthConfig } from '@lowdefy/api';
19
18
 
20
- import adapters from '../../../build/plugins/auth/adapters.js';
19
+ import apiWrapper from '../../../lib/server/apiWrapper.js';
21
20
  import authJson from '../../../build/auth.json';
22
- import callbacks from '../../../build/plugins/auth/callbacks.js';
23
- import config from '../../../build/config.json';
24
- import events from '../../../build/plugins/auth/events.js';
25
- import fileCache from '../../../lib/fileCache.js';
26
- import providers from '../../../build/plugins/auth/providers.js';
27
-
28
- export const authOptions = getNextAuthConfig(
29
- createApiContext({
30
- config,
31
- fileCache,
32
- logger: console,
33
- }),
34
- { authJson, plugins: { adapters, callbacks, events, providers } }
35
- );
36
-
37
- export default async function auth(req, res) {
21
+
22
+ async function handler({ context, req, res }) {
38
23
  if (authJson.configured === true) {
39
- return await NextAuth(req, res, authOptions);
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);
40
30
  }
41
31
 
42
32
  return res.status(404).json({
43
33
  message: 'Auth not configured',
44
34
  });
45
35
  }
36
+
37
+ export default apiWrapper(handler);
@@ -14,40 +14,19 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
- import path from 'path';
18
- import { callRequest, createApiContext } from '@lowdefy/api';
19
- import { getSecretsFromEnv } from '@lowdefy/node-utils';
17
+ import { callRequest } from '@lowdefy/api';
20
18
 
21
- import config from '../../../../build/config.json';
22
- import connections from '../../../../build/plugins/connections.js';
23
- import getServerSession from '../../../../lib/auth/getServerSession.js';
24
- import operators from '../../../../build/plugins/operators/server.js';
25
- import fileCache from '../../../../lib/fileCache.js';
19
+ import apiWrapper from '../../../../lib/server/apiWrapper.js';
26
20
 
27
- export default async function handler(req, res) {
28
- try {
29
- if (req.method !== 'POST') {
30
- throw new Error('Only POST requests are supported.');
31
- }
32
- const session = await getServerSession({ req, res });
33
- // Important to give absolute path so Next can trace build files
34
- const apiContext = createApiContext({
35
- buildDirectory: path.join(process.cwd(), 'build'),
36
- config,
37
- connections,
38
- fileCache,
39
- // logger: console,
40
- logger: { debug: () => {} },
41
- operators,
42
- secrets: getSecretsFromEnv(),
43
- session,
44
- });
45
-
46
- const { blockId, pageId, requestId } = req.query;
47
- const { payload } = req.body;
48
- const response = await callRequest(apiContext, { blockId, pageId, payload, requestId });
49
- res.status(200).json(response);
50
- } catch (error) {
51
- res.status(500).json({ name: error.name, message: error.message });
21
+ async function handler({ context, req, res }) {
22
+ if (req.method !== 'POST') {
23
+ throw new Error('Only POST requests are supported.');
52
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);
53
30
  }
31
+
32
+ export default apiWrapper(handler);
package/pages/index.js CHANGED
@@ -14,28 +14,17 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
- import path from 'path';
18
- import { createApiContext, getPageConfig, getRootConfig } from '@lowdefy/api';
17
+ import { getPageConfig, getRootConfig } from '@lowdefy/api';
19
18
 
20
- import config from '../build/config.json';
21
- import fileCache from '../lib/fileCache.js';
22
- import getServerSession from '../lib/auth/getServerSession.js';
23
- import Page from '../lib/Page.js';
19
+ import serverSidePropsWrapper from '../lib/server/serverSidePropsWrapper.js';
20
+ import Page from '../lib/client/Page.js';
24
21
 
25
- export async function getServerSideProps(context) {
26
- const session = await getServerSession(context);
27
-
28
- // Important to give absolute path so Next can trace build files
29
- const apiContext = createApiContext({
30
- buildDirectory: path.join(process.cwd(), 'build'),
31
- config,
32
- fileCache,
33
- logger: console,
34
- session,
35
- });
36
- const rootConfig = await getRootConfig(apiContext);
22
+ async function getServerSidePropsHandler({ context }) {
23
+ const rootConfig = await getRootConfig(context);
37
24
  const { home } = rootConfig;
25
+ const { logger } = context;
38
26
  if (home.configured === false) {
27
+ logger.info({ event: 'redirect_to_homepage', pageId: home.pageId });
39
28
  return {
40
29
  redirect: {
41
30
  destination: `/${home.pageId}`,
@@ -43,8 +32,9 @@ export async function getServerSideProps(context) {
43
32
  },
44
33
  };
45
34
  }
46
- const pageConfig = await getPageConfig(apiContext, { pageId: home.pageId });
35
+ const pageConfig = await getPageConfig(context, { pageId: home.pageId });
47
36
  if (!pageConfig) {
37
+ logger.info({ event: 'redirect_page_not_found', pageId: home.pageId });
48
38
  return {
49
39
  redirect: {
50
40
  destination: '/404',
@@ -52,13 +42,16 @@ export async function getServerSideProps(context) {
52
42
  },
53
43
  };
54
44
  }
45
+ logger.info({ event: 'page_view', pageId: home.pageId });
55
46
  return {
56
47
  props: {
57
48
  pageConfig,
58
49
  rootConfig,
59
- session,
50
+ session: context.session,
60
51
  },
61
52
  };
62
53
  }
63
54
 
55
+ export const getServerSideProps = serverSidePropsWrapper(getServerSidePropsHandler);
56
+
64
57
  export default Page;
Binary file
Binary file
@@ -0,0 +1,17 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
3
+ <svg width="100%" height="100%" viewBox="0 0 94 94" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">
4
+ <g transform="matrix(1,0,0,1,-979.672,-59.6924)">
5
+ <g transform="matrix(1,0,0,1.03297,-38.3284,-294.615)">
6
+ <g transform="matrix(1,0,0,1,952,232)">
7
+ <path d="M160,129.634C160,119.35 151.375,111 140.751,111L85.249,111C74.625,111 66,119.35 66,129.634L66,183.366C66,193.65 74.625,202 85.249,202L140.751,202C151.375,202 160,193.65 160,183.366L160,129.634Z"/>
8
+ </g>
9
+ <g transform="matrix(0.872141,0,0,1,1002.6,346)">
10
+ <rect x="36" y="12" width="36" height="59" style="fill:white;"/>
11
+ </g>
12
+ <g transform="matrix(0.78125,0,0,0.862069,1010.84,356.663)">
13
+ <rect x="77" y="41" width="32" height="29" style="fill:rgb(24,144,255);"/>
14
+ </g>
15
+ </g>
16
+ </g>
17
+ </svg>
@@ -0,0 +1,16 @@
1
+ {
2
+ "short_name": "Lowdefy App",
3
+ "name": "Lowdefy App",
4
+ "description": "Lowdefy App",
5
+ "icons": [
6
+ {
7
+ "src": "/public/icon-512.png",
8
+ "type": "image/png",
9
+ "sizes": "512x512"
10
+ }
11
+ ],
12
+ "start_url": "/",
13
+ "background_color": "#FFFFFF",
14
+ "display": "browser",
15
+ "scope": "/"
16
+ }
File without changes