@lowdefy/server 4.0.0-rc.0 → 4.0.0-rc.10

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.
Files changed (33) hide show
  1. package/lib/{Page.js → client/Page.js} +7 -6
  2. package/lib/{auth → client/auth}/Auth.js +3 -3
  3. package/lib/{auth → client/auth}/AuthConfigured.js +20 -6
  4. package/lib/{auth → client/auth}/AuthNotConfigured.js +2 -1
  5. package/lib/server/apiWrapper.js +63 -0
  6. package/lib/server/auth/getAuthOptions.js +35 -0
  7. package/lib/{auth → server/auth}/getServerSession.js +6 -6
  8. package/lib/{fileCache.js → server/fileCache.js} +1 -1
  9. package/lib/server/log/createLogger.js +30 -0
  10. package/lib/server/log/logError.js +72 -0
  11. package/lib/server/log/logRequest.js +66 -0
  12. package/lib/server/serverSidePropsWrapper.js +59 -0
  13. package/lowdefy/build.mjs +16 -2
  14. package/lowdefy/createCustomPluginTypesMap.mjs +1 -1
  15. package/next.config.js +2 -7
  16. package/package.json +27 -24
  17. package/package.original.json +81 -0
  18. package/pages/404.js +9 -8
  19. package/pages/[pageId].js +15 -24
  20. package/pages/_app.js +12 -4
  21. package/pages/_document.js +8 -4
  22. package/pages/api/auth/[...nextauth].js +12 -20
  23. package/pages/api/request/[pageId]/[requestId].js +13 -34
  24. package/pages/index.js +14 -21
  25. /package/{public → public_default}/apple-touch-icon.png +0 -0
  26. /package/{public → public_default}/favicon.ico +0 -0
  27. /package/{public → public_default}/icon-512.png +0 -0
  28. /package/{public → public_default}/icon.svg +0 -0
  29. /package/{public → public_default}/logo-dark-theme.png +0 -0
  30. /package/{public → public_default}/logo-light-theme.png +0 -0
  31. /package/{public → public_default}/logo-square-dark-theme.png +0 -0
  32. /package/{public → public_default}/logo-square-light-theme.png +0 -0
  33. /package/{public → public_default}/manifest.webmanifest +0 -0
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2022 Lowdefy, Inc
2
+ Copyright 2020-2023 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -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,
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2022 Lowdefy, Inc
2
+ Copyright 2020-2023 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -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
  );
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2022 Lowdefy, Inc
2
+ Copyright 2020-2023 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -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;
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2022 Lowdefy, Inc
2
+ Copyright 2020-2023 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -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;
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2022 Lowdefy, Inc
2
+ Copyright 2020-2023 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -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
  }
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2022 Lowdefy, Inc
2
+ Copyright 2020-2023 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -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
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  /*
3
- Copyright 2020-2022 Lowdefy, Inc
3
+ Copyright 2020-2023 Lowdefy, Inc
4
4
 
5
5
  Licensed under the Apache License, Version 2.0 (the "License");
6
6
  you may not use this file except in compliance with the License.
@@ -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
  }
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  /*
3
- Copyright 2020-2022 Lowdefy, Inc
3
+ Copyright 2020-2023 Lowdefy, Inc
4
4
 
5
5
  Licensed under the Apache License, Version 2.0 (the "License");
6
6
  you may not use this file except in compliance with the License.
package/next.config.js CHANGED
@@ -1,9 +1,8 @@
1
1
  const withLess = require('next-with-less');
2
2
  const lowdefyConfig = require('./build/config.json');
3
3
 
4
- // TODO: Trace env and args from cli that is required on the server.
5
4
  module.exports = withLess({
6
- basePath: process.env.LOWDEFY_BASE_PATH || lowdefyConfig.basePath,
5
+ basePath: lowdefyConfig.basePath,
7
6
  reactStrictMode: true,
8
7
  webpack: (config, { isServer }) => {
9
8
  if (!isServer) {
@@ -22,11 +21,7 @@ module.exports = withLess({
22
21
  },
23
22
  poweredByHeader: false,
24
23
  // productionBrowserSourceMaps: true
25
- experimental: {
26
- // TODO: Convert from experimental.outputStandalone to output: 'standalone' when upgrading to Next 13
27
- outputStandalone: process.env.LOWDEFY_BUILD_OUTPUT_STANDALONE === '1' || false,
28
- // concurrentFeatures: true,
29
- },
24
+ output: process.env.LOWDEFY_BUILD_OUTPUT_STANDALONE === '1' ? 'standalone' : undefined,
30
25
  outputFileTracing: true,
31
26
  eslint: {
32
27
  ignoreDuringBuilds: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/server",
3
- "version": "4.0.0-rc.0",
3
+ "version": "4.0.0-rc.10",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -29,12 +29,14 @@
29
29
  "lib/*",
30
30
  "lowdefy/*",
31
31
  "pages/*",
32
- "public/*",
32
+ "public_default/*",
33
33
  "next.config.js",
34
+ "package.original.json",
34
35
  ".eslintrc.yaml",
35
36
  ".npmrc"
36
37
  ],
37
38
  "scripts": {
39
+ "build": "cp package.json package.original.json || copy package.json package.original.json",
38
40
  "build:lowdefy": "node lowdefy/build.mjs",
39
41
  "build:next": "next build",
40
42
  "dev": "next dev",
@@ -43,37 +45,38 @@
43
45
  "next": "next"
44
46
  },
45
47
  "dependencies": {
46
- "@lowdefy/actions-core": "4.0.0-rc.0",
47
- "@lowdefy/api": "4.0.0-rc.0",
48
- "@lowdefy/blocks-antd": "4.0.0-rc.0",
49
- "@lowdefy/blocks-basic": "4.0.0-rc.0",
50
- "@lowdefy/blocks-loaders": "4.0.0-rc.0",
51
- "@lowdefy/client": "4.0.0-rc.0",
52
- "@lowdefy/helpers": "4.0.0-rc.0",
53
- "@lowdefy/layout": "4.0.0-rc.0",
54
- "@lowdefy/node-utils": "4.0.0-rc.0",
55
- "@lowdefy/operators-js": "4.0.0-rc.0",
56
- "@lowdefy/plugin-next-auth": "4.0.0-rc.0",
57
- "next": "12.3.1",
58
- "next-auth": "4.10.3",
48
+ "@lowdefy/actions-core": "4.0.0-rc.10",
49
+ "@lowdefy/api": "4.0.0-rc.10",
50
+ "@lowdefy/blocks-antd": "4.0.0-rc.10",
51
+ "@lowdefy/blocks-basic": "4.0.0-rc.10",
52
+ "@lowdefy/blocks-loaders": "4.0.0-rc.10",
53
+ "@lowdefy/client": "4.0.0-rc.10",
54
+ "@lowdefy/helpers": "4.0.0-rc.10",
55
+ "@lowdefy/layout": "4.0.0-rc.10",
56
+ "@lowdefy/node-utils": "4.0.0-rc.10",
57
+ "@lowdefy/operators-js": "4.0.0-rc.10",
58
+ "@lowdefy/plugin-next-auth": "4.0.0-rc.10",
59
+ "next": "12.3.4",
60
+ "next-auth": "4.20.1",
61
+ "pino": "8.8.0",
59
62
  "process": "0.11.10",
60
63
  "react": "18.2.0",
61
64
  "react-dom": "18.2.0",
62
- "react-icons": "4.3.1"
65
+ "react-icons": "4.7.1"
63
66
  },
64
67
  "devDependencies": {
65
- "@lowdefy/build": "4.0.0-rc.0",
66
- "@next/eslint-plugin-next": "12.1.6",
67
- "less": "4.1.2",
68
- "less-loader": "11.0.0",
68
+ "@lowdefy/build": "4.0.0-rc.10",
69
+ "@next/eslint-plugin-next": "12.3.4",
70
+ "less": "4.1.3",
71
+ "less-loader": "11.1.0",
69
72
  "next-with-less": "2.0.5",
70
- "webpack": "5.74.0",
71
- "yaml": "2.1.1",
72
- "yargs": "17.5.1"
73
+ "webpack": "5.88.2",
74
+ "yaml": "2.2.2",
75
+ "yargs": "17.7.2"
73
76
  },
74
77
  "packageManager": "pnpm@7.11.0",
75
78
  "publishConfig": {
76
79
  "access": "public"
77
80
  },
78
- "gitHead": "f6872d7ff6da421710096536fce7b2016ef8f35c"
81
+ "gitHead": "537af074f27770e32da9da8d48490f2eda94b406"
79
82
  }
@@ -0,0 +1,81 @@
1
+ {
2
+ "name": "@lowdefy/server",
3
+ "version": "4.0.0-rc.10",
4
+ "license": "Apache-2.0",
5
+ "description": "",
6
+ "homepage": "https://lowdefy.com",
7
+ "keywords": [
8
+ "lowdefy",
9
+ "server"
10
+ ],
11
+ "bugs": {
12
+ "url": "https://github.com/lowdefy/lowdefy/issues"
13
+ },
14
+ "contributors": [
15
+ {
16
+ "name": "Sam Tolmay",
17
+ "url": "https://github.com/SamTolmay"
18
+ },
19
+ {
20
+ "name": "Gerrie van Wyk",
21
+ "url": "https://github.com/Gervwyk"
22
+ }
23
+ ],
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "https://github.com/lowdefy/lowdefy.git"
27
+ },
28
+ "files": [
29
+ "lib/*",
30
+ "lowdefy/*",
31
+ "pages/*",
32
+ "public_default/*",
33
+ "next.config.js",
34
+ "package.original.json",
35
+ ".eslintrc.yaml",
36
+ ".npmrc"
37
+ ],
38
+ "scripts": {
39
+ "build": "cp package.json package.original.json || copy package.json package.original.json",
40
+ "build:lowdefy": "node lowdefy/build.mjs",
41
+ "build:next": "next build",
42
+ "dev": "next dev",
43
+ "start": "next start",
44
+ "lint": "next lint",
45
+ "next": "next"
46
+ },
47
+ "dependencies": {
48
+ "@lowdefy/actions-core": "4.0.0-rc.10",
49
+ "@lowdefy/api": "4.0.0-rc.10",
50
+ "@lowdefy/blocks-antd": "4.0.0-rc.10",
51
+ "@lowdefy/blocks-basic": "4.0.0-rc.10",
52
+ "@lowdefy/blocks-loaders": "4.0.0-rc.10",
53
+ "@lowdefy/client": "4.0.0-rc.10",
54
+ "@lowdefy/helpers": "4.0.0-rc.10",
55
+ "@lowdefy/layout": "4.0.0-rc.10",
56
+ "@lowdefy/node-utils": "4.0.0-rc.10",
57
+ "@lowdefy/operators-js": "4.0.0-rc.10",
58
+ "@lowdefy/plugin-next-auth": "4.0.0-rc.10",
59
+ "next": "12.3.4",
60
+ "next-auth": "4.20.1",
61
+ "pino": "8.8.0",
62
+ "process": "0.11.10",
63
+ "react": "18.2.0",
64
+ "react-dom": "18.2.0",
65
+ "react-icons": "4.7.1"
66
+ },
67
+ "devDependencies": {
68
+ "@lowdefy/build": "4.0.0-rc.10",
69
+ "@next/eslint-plugin-next": "12.3.4",
70
+ "less": "4.1.3",
71
+ "less-loader": "11.1.0",
72
+ "next-with-less": "2.0.5",
73
+ "webpack": "5.88.2",
74
+ "yaml": "2.2.2",
75
+ "yargs": "17.7.2"
76
+ },
77
+ "packageManager": "pnpm@7.11.0",
78
+ "publishConfig": {
79
+ "access": "public"
80
+ }
81
+ }
package/pages/404.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2022 Lowdefy, Inc
2
+ Copyright 2020-2023 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -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
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2022 Lowdefy, Inc
2
+ Copyright 2020-2023 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -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
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2022 Lowdefy, Inc
2
+ Copyright 2020-2023 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -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
  }
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2022 Lowdefy, Inc
2
+ Copyright 2020-2023 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -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={{
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2022 Lowdefy, Inc
2
+ Copyright 2020-2023 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -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);
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2022 Lowdefy, Inc
2
+ Copyright 2020-2023 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -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
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2020-2022 Lowdefy, Inc
2
+ Copyright 2020-2023 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -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;
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes