@lowdefy/server-dev 4.0.0-rc.1 → 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 (44) hide show
  1. package/lib/{App.js → client/App.js} +7 -6
  2. package/lib/{Page.js → client/Page.js} +2 -1
  3. package/lib/{Reload.js → client/Reload.js} +4 -1
  4. package/lib/{auth → client/auth}/Auth.js +2 -2
  5. package/lib/{auth → client/auth}/AuthConfigured.js +19 -5
  6. package/lib/{auth → client/auth}/AuthNotConfigured.js +1 -0
  7. package/lib/server/apiWrapper.js +64 -0
  8. package/lib/server/auth/getAuthOptions.js +35 -0
  9. package/lib/{auth → server/auth}/getServerSession.js +5 -5
  10. package/lib/server/log/createLogger.js +29 -0
  11. package/lib/server/log/logError.js +40 -0
  12. package/lib/server/log/logRequest.js +33 -0
  13. package/manager/processes/lowdefyBuild.mjs +1 -0
  14. package/manager/utils/createLogger.mjs +0 -1
  15. package/manager/watchers/nextBuildWatcher.mjs +18 -9
  16. package/next.config.js +1 -1
  17. package/package.json +33 -33
  18. package/package.original.json +32 -32
  19. package/pages/404.js +1 -1
  20. package/pages/[pageId].js +1 -1
  21. package/pages/_app.js +4 -3
  22. package/pages/_document.js +7 -3
  23. package/pages/api/auth/[...nextauth].js +11 -19
  24. package/pages/api/page/[pageId].js +7 -15
  25. package/pages/api/request/[pageId]/[requestId].js +12 -30
  26. package/pages/api/root.js +6 -16
  27. package/pages/index.js +1 -1
  28. package/public_default/apple-touch-icon.png +0 -0
  29. package/public_default/favicon.ico +0 -0
  30. package/public_default/icon-512.png +0 -0
  31. package/public_default/icon.svg +17 -0
  32. package/public_default/logo-dark-theme.png +0 -0
  33. package/public_default/logo-light-theme.png +0 -0
  34. package/public_default/logo-square-dark-theme.png +0 -0
  35. package/public_default/logo-square-light-theme.png +0 -0
  36. package/public_default/manifest.webmanifest +16 -0
  37. /package/lib/{RestartingPage.js → client/RestartingPage.js} +0 -0
  38. /package/lib/{setPageId.js → client/setPageId.js} +0 -0
  39. /package/lib/{utils → client/utils}/request.js +0 -0
  40. /package/lib/{utils → client/utils}/useMutateCache.js +0 -0
  41. /package/lib/{utils → client/utils}/usePageConfig.js +0 -0
  42. /package/lib/{utils → client/utils}/useRootConfig.js +0 -0
  43. /package/lib/{utils → client/utils}/waitForRestartedServer.js +0 -0
  44. /package/lib/{fileCache.js → server/fileCache.js} +0 -0
@@ -26,12 +26,12 @@ import Page from './Page.js';
26
26
  import setPageId from './setPageId.js';
27
27
  import useRootConfig from './utils/useRootConfig.js';
28
28
 
29
- import actions from '../build/plugins/actions.js';
30
- import blocks from '../build/plugins/blocks.js';
31
- import icons from '../build/plugins/icons.js';
32
- import operators from '../build/plugins/operators/client.js';
29
+ import actions from '../../build/plugins/actions.js';
30
+ import blocks from '../../build/plugins/blocks.js';
31
+ import icons from '../../build/plugins/icons.js';
32
+ import operators from '../../build/plugins/operators/client.js';
33
33
 
34
- const App = ({ auth }) => {
34
+ const App = ({ auth, lowdefy }) => {
35
35
  const router = useRouter();
36
36
  const { data: rootConfig } = useRootConfig(router.basePath);
37
37
 
@@ -41,7 +41,7 @@ const App = ({ auth }) => {
41
41
  return '';
42
42
  }
43
43
  return (
44
- <Reload basePath={router.basePath}>
44
+ <Reload basePath={router.basePath} lowdefy={lowdefy}>
45
45
  {(resetContext) => (
46
46
  <Page
47
47
  auth={auth}
@@ -49,6 +49,7 @@ const App = ({ auth }) => {
49
49
  config={{
50
50
  rootConfig,
51
51
  }}
52
+ lowdefy={lowdefy}
52
53
  pageId={pageId}
53
54
  resetContext={resetContext}
54
55
  router={router}
@@ -20,7 +20,7 @@ import Client from '@lowdefy/client';
20
20
  import RestartingPage from './RestartingPage.js';
21
21
  import usePageConfig from './utils/usePageConfig.js';
22
22
 
23
- const Page = ({ auth, Components, config, pageId, resetContext, router, types }) => {
23
+ const Page = ({ auth, Components, config, lowdefy, pageId, resetContext, router, types }) => {
24
24
  const { data: pageConfig } = usePageConfig(pageId, router.basePath);
25
25
 
26
26
  if (!pageConfig) {
@@ -38,6 +38,7 @@ const Page = ({ auth, Components, config, pageId, resetContext, router, types })
38
38
  ...config,
39
39
  pageConfig,
40
40
  }}
41
+ lowdefy={lowdefy}
41
42
  resetContext={resetContext}
42
43
  router={router}
43
44
  stage="dev"
@@ -19,7 +19,7 @@ import React, { useEffect, useState } from 'react';
19
19
  import useMutateCache from './utils/useMutateCache.js';
20
20
  import waitForRestartedServer from './utils/waitForRestartedServer.js';
21
21
 
22
- const Reload = ({ children, basePath }) => {
22
+ const Reload = ({ children, basePath, lowdefy }) => {
23
23
  const [reset, setReset] = useState(false);
24
24
  const [restarting, setRestarting] = useState(false);
25
25
  const mutateCache = useMutateCache(basePath);
@@ -31,6 +31,9 @@ const Reload = ({ children, basePath }) => {
31
31
  // TODO: We need to pass a flag when a rebuild will happen so that client does not trigger render.
32
32
  setTimeout(async () => {
33
33
  await mutateCache();
34
+ if (lowdefy._internal?.initialised) {
35
+ lowdefy._internal.initialised = false;
36
+ }
34
37
  setReset(true);
35
38
  console.log('Reloaded config.');
36
39
  }, 600);
@@ -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,64 @@
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 logRequest from './log/logRequest.js';
27
+ import logError from './log/logError.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
+ // TODO: Log response time?
56
+ return response;
57
+ } catch (error) {
58
+ logError({ error, context });
59
+ res.status(500).json({ name: error.name, message: error.message });
60
+ }
61
+ };
62
+ }
63
+
64
+ 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,29 @@
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
+ const logger = pino({
20
+ name: 'lowdefy_server',
21
+ level: process.env.LOWDEFY_LOG_LEVEL ?? 'info',
22
+ base: { pid: undefined, hostname: undefined },
23
+ });
24
+
25
+ function createLogger(metadata = {}) {
26
+ return logger.child(metadata);
27
+ }
28
+
29
+ export default createLogger;
@@ -0,0 +1,40 @@
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 { user = {} } = context;
20
+
21
+ context.logger.error({
22
+ err: error,
23
+ user: {
24
+ id: user.id,
25
+ roles: user.roles,
26
+ sub: user.sub,
27
+ session_id: user.session_id,
28
+ },
29
+ url: context.req.url,
30
+ method: context.req.method,
31
+ resolvedUrl: context.nextContext?.resolvedUrl,
32
+ });
33
+ } catch (e) {
34
+ console.error(error);
35
+ console.error('An error occurred while logging the error.');
36
+ console.error(e);
37
+ }
38
+ }
39
+
40
+ export default logError;
@@ -0,0 +1,33 @@
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 { user = {} } = context;
20
+ context.logger.debug({
21
+ user: {
22
+ id: user.id,
23
+ roles: user.roles,
24
+ sub: user.sub,
25
+ session_id: user.session_id,
26
+ },
27
+ url: context.req.url,
28
+ method: context.req.method,
29
+ resolvedUrl: context.nextContext?.resolvedUrl,
30
+ });
31
+ }
32
+
33
+ export default logRequest;
@@ -19,6 +19,7 @@ import createCustomPluginTypesMap from '../utils/createCustomPluginTypesMap.mjs'
19
19
 
20
20
  function lowdefyBuild({ directories, logger, options }) {
21
21
  return async () => {
22
+ logger.info({ print: 'spin' }, 'Building config...');
22
23
  const customTypesMap = await createCustomPluginTypesMap({ directories, logger });
23
24
  await build({
24
25
  customTypesMap,
@@ -20,7 +20,6 @@ function createLogger({ level = 'info' }) {
20
20
  name: 'lowdefy build',
21
21
  level,
22
22
  base: { pid: undefined, hostname: undefined },
23
- // TODO: Add log as custom level
24
23
  mixin: (context, level) => {
25
24
  return {
26
25
  ...context,
@@ -17,11 +17,12 @@
17
17
  import crypto from 'crypto';
18
18
  import path from 'path';
19
19
  import { readFile } from '@lowdefy/node-utils';
20
+ import { type } from '@lowdefy/helpers';
20
21
  import setupWatcher from '../utils/setupWatcher.mjs';
21
22
 
22
23
  const hashes = {};
23
24
 
24
- const watchedFiles = [
25
+ const trackedFiles = [
25
26
  'build/app.json',
26
27
  'build/auth.json',
27
28
  'build/config.json',
@@ -41,7 +42,16 @@ const watchedFiles = [
41
42
  ];
42
43
 
43
44
  async function sha1(filePath) {
44
- const content = await readFile(filePath);
45
+ let content = await readFile(filePath);
46
+ if (filePath.endsWith('.json')) {
47
+ content = JSON.stringify(
48
+ JSON.parse(content, (_, value) => {
49
+ if (!type.isObject(value)) return value;
50
+ delete value['~k'];
51
+ return value;
52
+ })
53
+ );
54
+ }
45
55
  return crypto
46
56
  .createHash('sha1')
47
57
  .update(content || '')
@@ -52,17 +62,16 @@ async function nextBuildWatcher(context) {
52
62
  // Initialize hashes so that app does not rebuild the first time
53
63
  // Lowdefy build is run.
54
64
  await Promise.all(
55
- watchedFiles.map(async (filePath) => {
56
- const fullPath = path.resolve(context.directories.server, filePath);
57
- hashes[fullPath] = await sha1(fullPath);
65
+ trackedFiles.map(async (filePath) => {
66
+ hashes[filePath] = await sha1(filePath);
58
67
  })
59
68
  );
60
69
 
61
- const callback = async (filePaths) => {
70
+ const callback = async () => {
62
71
  let install = false;
63
72
  let build = false;
64
73
  await Promise.all(
65
- filePaths.flat().map(async (filePath) => {
74
+ trackedFiles.map(async (filePath) => {
66
75
  const hash = await sha1(filePath);
67
76
  if (hashes[filePath] === hash) {
68
77
  return;
@@ -74,7 +83,6 @@ async function nextBuildWatcher(context) {
74
83
  hashes[filePath] = hash;
75
84
  })
76
85
  );
77
-
78
86
  if (!build) {
79
87
  context.logger.info({ print: 'succeed' }, 'Reloaded app.');
80
88
  return;
@@ -82,6 +90,7 @@ async function nextBuildWatcher(context) {
82
90
 
83
91
  context.shutdownServer();
84
92
  if (install) {
93
+ context.logger.warn('Plugin dependencies have changed and will be reinstalled.');
85
94
  await context.installPlugins();
86
95
  }
87
96
  await context.nextBuild();
@@ -92,7 +101,7 @@ async function nextBuildWatcher(context) {
92
101
  callback,
93
102
  context,
94
103
  watchDotfiles: true,
95
- watchPaths: watchedFiles.map((filePath) => path.join(context.directories.server, filePath)),
104
+ watchPaths: [path.join(context.directories.server, 'package.json')],
96
105
  });
97
106
  }
98
107
 
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-dev",
3
- "version": "4.0.0-rc.1",
3
+ "version": "4.0.0-rc.10",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -29,7 +29,7 @@
29
29
  "lib/*",
30
30
  "manager/*",
31
31
  "pages/*",
32
- "public/*",
32
+ "public_default/*",
33
33
  "next.config.js",
34
34
  "package.original.json",
35
35
  ".eslintrc.yaml",
@@ -42,34 +42,34 @@
42
42
  "next": "next"
43
43
  },
44
44
  "dependencies": {
45
- "@lowdefy/actions-core": "4.0.0-rc.1",
46
- "@lowdefy/api": "4.0.0-rc.1",
47
- "@lowdefy/blocks-antd": "4.0.0-rc.1",
48
- "@lowdefy/blocks-basic": "4.0.0-rc.1",
49
- "@lowdefy/blocks-color-selectors": "4.0.0-rc.1",
50
- "@lowdefy/blocks-echarts": "4.0.0-rc.1",
51
- "@lowdefy/blocks-loaders": "4.0.0-rc.1",
52
- "@lowdefy/blocks-markdown": "4.0.0-rc.1",
53
- "@lowdefy/blocks-qr": "4.0.0-rc.1",
54
- "@lowdefy/build": "4.0.0-rc.1",
55
- "@lowdefy/client": "4.0.0-rc.1",
56
- "@lowdefy/connection-axios-http": "4.0.0-rc.1",
57
- "@lowdefy/engine": "4.0.0-rc.1",
58
- "@lowdefy/helpers": "4.0.0-rc.1",
59
- "@lowdefy/layout": "4.0.0-rc.1",
60
- "@lowdefy/node-utils": "4.0.0-rc.1",
61
- "@lowdefy/operators-change-case": "4.0.0-rc.1",
62
- "@lowdefy/operators-diff": "4.0.0-rc.1",
63
- "@lowdefy/operators-js": "4.0.0-rc.1",
64
- "@lowdefy/operators-mql": "4.0.0-rc.1",
65
- "@lowdefy/operators-nunjucks": "4.0.0-rc.1",
66
- "@lowdefy/operators-uuid": "4.0.0-rc.1",
67
- "@lowdefy/operators-yaml": "4.0.0-rc.1",
68
- "@lowdefy/plugin-next-auth": "4.0.0-rc.1",
45
+ "@lowdefy/actions-core": "4.0.0-rc.10",
46
+ "@lowdefy/api": "4.0.0-rc.10",
47
+ "@lowdefy/blocks-antd": "4.0.0-rc.10",
48
+ "@lowdefy/blocks-basic": "4.0.0-rc.10",
49
+ "@lowdefy/blocks-color-selectors": "4.0.0-rc.10",
50
+ "@lowdefy/blocks-echarts": "4.0.0-rc.10",
51
+ "@lowdefy/blocks-loaders": "4.0.0-rc.10",
52
+ "@lowdefy/blocks-markdown": "4.0.0-rc.10",
53
+ "@lowdefy/blocks-qr": "4.0.0-rc.10",
54
+ "@lowdefy/build": "4.0.0-rc.10",
55
+ "@lowdefy/client": "4.0.0-rc.10",
56
+ "@lowdefy/connection-axios-http": "4.0.0-rc.10",
57
+ "@lowdefy/engine": "4.0.0-rc.10",
58
+ "@lowdefy/helpers": "4.0.0-rc.10",
59
+ "@lowdefy/layout": "4.0.0-rc.10",
60
+ "@lowdefy/node-utils": "4.0.0-rc.10",
61
+ "@lowdefy/operators-change-case": "4.0.0-rc.10",
62
+ "@lowdefy/operators-diff": "4.0.0-rc.10",
63
+ "@lowdefy/operators-js": "4.0.0-rc.10",
64
+ "@lowdefy/operators-mql": "4.0.0-rc.10",
65
+ "@lowdefy/operators-nunjucks": "4.0.0-rc.10",
66
+ "@lowdefy/operators-uuid": "4.0.0-rc.10",
67
+ "@lowdefy/operators-yaml": "4.0.0-rc.10",
68
+ "@lowdefy/plugin-next-auth": "4.0.0-rc.10",
69
69
  "chokidar": "3.5.3",
70
70
  "dotenv": "16.0.3",
71
- "next": "12.3.1",
72
- "next-auth": "4.18.8",
71
+ "next": "12.3.4",
72
+ "next-auth": "4.20.1",
73
73
  "opener": "1.5.2",
74
74
  "pino": "8.8.0",
75
75
  "process": "0.11.10",
@@ -77,19 +77,19 @@
77
77
  "react-dom": "18.2.0",
78
78
  "react-icons": "4.7.1",
79
79
  "swr": "2.0.0",
80
- "yaml": "2.2.1",
81
- "yargs": "17.6.2"
80
+ "yaml": "2.2.2",
81
+ "yargs": "17.7.2"
82
82
  },
83
83
  "devDependencies": {
84
- "@next/eslint-plugin-next": "12.1.6",
84
+ "@next/eslint-plugin-next": "12.3.4",
85
85
  "less": "4.1.3",
86
86
  "less-loader": "11.1.0",
87
87
  "next-with-less": "2.0.5",
88
- "webpack": "5.75.0"
88
+ "webpack": "5.88.2"
89
89
  },
90
90
  "packageManager": "pnpm@7.11.0",
91
91
  "publishConfig": {
92
92
  "access": "public"
93
93
  },
94
- "gitHead": "ecc4f16c19eede929eda177db524cf13a8053379"
94
+ "gitHead": "537af074f27770e32da9da8d48490f2eda94b406"
95
95
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/server-dev",
3
- "version": "4.0.0-rc.1",
3
+ "version": "4.0.0-rc.10",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -29,7 +29,7 @@
29
29
  "lib/*",
30
30
  "manager/*",
31
31
  "pages/*",
32
- "public/*",
32
+ "public_default/*",
33
33
  "next.config.js",
34
34
  "package.original.json",
35
35
  ".eslintrc.yaml",
@@ -42,34 +42,34 @@
42
42
  "next": "next"
43
43
  },
44
44
  "dependencies": {
45
- "@lowdefy/actions-core": "4.0.0-rc.1",
46
- "@lowdefy/api": "4.0.0-rc.1",
47
- "@lowdefy/blocks-antd": "4.0.0-rc.1",
48
- "@lowdefy/blocks-basic": "4.0.0-rc.1",
49
- "@lowdefy/blocks-color-selectors": "4.0.0-rc.1",
50
- "@lowdefy/blocks-echarts": "4.0.0-rc.1",
51
- "@lowdefy/blocks-loaders": "4.0.0-rc.1",
52
- "@lowdefy/blocks-markdown": "4.0.0-rc.1",
53
- "@lowdefy/blocks-qr": "4.0.0-rc.1",
54
- "@lowdefy/build": "4.0.0-rc.1",
55
- "@lowdefy/client": "4.0.0-rc.1",
56
- "@lowdefy/connection-axios-http": "4.0.0-rc.1",
57
- "@lowdefy/engine": "4.0.0-rc.1",
58
- "@lowdefy/helpers": "4.0.0-rc.1",
59
- "@lowdefy/layout": "4.0.0-rc.1",
60
- "@lowdefy/node-utils": "4.0.0-rc.1",
61
- "@lowdefy/operators-change-case": "4.0.0-rc.1",
62
- "@lowdefy/operators-diff": "4.0.0-rc.1",
63
- "@lowdefy/operators-js": "4.0.0-rc.1",
64
- "@lowdefy/operators-mql": "4.0.0-rc.1",
65
- "@lowdefy/operators-nunjucks": "4.0.0-rc.1",
66
- "@lowdefy/operators-uuid": "4.0.0-rc.1",
67
- "@lowdefy/operators-yaml": "4.0.0-rc.1",
68
- "@lowdefy/plugin-next-auth": "4.0.0-rc.1",
45
+ "@lowdefy/actions-core": "4.0.0-rc.10",
46
+ "@lowdefy/api": "4.0.0-rc.10",
47
+ "@lowdefy/blocks-antd": "4.0.0-rc.10",
48
+ "@lowdefy/blocks-basic": "4.0.0-rc.10",
49
+ "@lowdefy/blocks-color-selectors": "4.0.0-rc.10",
50
+ "@lowdefy/blocks-echarts": "4.0.0-rc.10",
51
+ "@lowdefy/blocks-loaders": "4.0.0-rc.10",
52
+ "@lowdefy/blocks-markdown": "4.0.0-rc.10",
53
+ "@lowdefy/blocks-qr": "4.0.0-rc.10",
54
+ "@lowdefy/build": "4.0.0-rc.10",
55
+ "@lowdefy/client": "4.0.0-rc.10",
56
+ "@lowdefy/connection-axios-http": "4.0.0-rc.10",
57
+ "@lowdefy/engine": "4.0.0-rc.10",
58
+ "@lowdefy/helpers": "4.0.0-rc.10",
59
+ "@lowdefy/layout": "4.0.0-rc.10",
60
+ "@lowdefy/node-utils": "4.0.0-rc.10",
61
+ "@lowdefy/operators-change-case": "4.0.0-rc.10",
62
+ "@lowdefy/operators-diff": "4.0.0-rc.10",
63
+ "@lowdefy/operators-js": "4.0.0-rc.10",
64
+ "@lowdefy/operators-mql": "4.0.0-rc.10",
65
+ "@lowdefy/operators-nunjucks": "4.0.0-rc.10",
66
+ "@lowdefy/operators-uuid": "4.0.0-rc.10",
67
+ "@lowdefy/operators-yaml": "4.0.0-rc.10",
68
+ "@lowdefy/plugin-next-auth": "4.0.0-rc.10",
69
69
  "chokidar": "3.5.3",
70
70
  "dotenv": "16.0.3",
71
- "next": "12.3.1",
72
- "next-auth": "4.18.8",
71
+ "next": "12.3.4",
72
+ "next-auth": "4.20.1",
73
73
  "opener": "1.5.2",
74
74
  "pino": "8.8.0",
75
75
  "process": "0.11.10",
@@ -77,15 +77,15 @@
77
77
  "react-dom": "18.2.0",
78
78
  "react-icons": "4.7.1",
79
79
  "swr": "2.0.0",
80
- "yaml": "2.2.1",
81
- "yargs": "17.6.2"
80
+ "yaml": "2.2.2",
81
+ "yargs": "17.7.2"
82
82
  },
83
83
  "devDependencies": {
84
- "@next/eslint-plugin-next": "12.1.6",
84
+ "@next/eslint-plugin-next": "12.3.4",
85
85
  "less": "4.1.3",
86
86
  "less-loader": "11.1.0",
87
87
  "next-with-less": "2.0.5",
88
- "webpack": "5.75.0"
88
+ "webpack": "5.88.2"
89
89
  },
90
90
  "packageManager": "pnpm@7.11.0",
91
91
  "publishConfig": {
package/pages/404.js CHANGED
@@ -14,6 +14,6 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
- import App from '../lib/App.js';
17
+ import App from '../lib/client/App.js';
18
18
 
19
19
  export default App;
package/pages/[pageId].js CHANGED
@@ -14,6 +14,6 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
- import App from '../lib/App.js';
17
+ import App from '../lib/client/App.js';
18
18
 
19
19
  export default App;
package/pages/_app.js CHANGED
@@ -14,18 +14,19 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
- import React, { Suspense } from 'react';
17
+ import React, { Suspense, useRef } from 'react';
18
18
  import dynamic from 'next/dynamic';
19
19
 
20
- import Auth from '../lib/auth/Auth.js';
20
+ import Auth from '../lib/client/auth/Auth.js';
21
21
 
22
22
  // Must be in _app due to next specifications.
23
23
  import '../build/plugins/styles.less';
24
24
 
25
25
  function App({ Component }) {
26
+ const lowdefyRef = useRef({});
26
27
  return (
27
28
  <Suspense fallback="">
28
- <Auth>{(auth) => <Component auth={auth} />}</Auth>
29
+ <Auth>{(auth) => <Component auth={auth} lowdefy={lowdefyRef.current} />}</Auth>
29
30
  </Suspense>
30
31
  );
31
32
  }
@@ -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
 
19
+ import apiWrapper from '../../../lib/server/apiWrapper.js';
20
20
  import authJson from '../../../build/auth.json';
21
- import config from '../../../build/config.json';
22
- import adapters from '../../../build/plugins/auth/adapters.js';
23
- import callbacks from '../../../build/plugins/auth/callbacks.js';
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,27 +14,19 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
- import { createApiContext, getPageConfig } from '@lowdefy/api';
17
+ import { getPageConfig } from '@lowdefy/api';
18
18
 
19
- import config from '../../../build/config.json';
20
- import fileCache from '../../../lib/fileCache.js';
21
- import getServerSession from '../../../lib/auth/getServerSession.js';
22
-
23
- export default async function handler(req, res) {
24
- const session = await getServerSession({ req, res });
25
- const apiContext = createApiContext({
26
- buildDirectory: './build',
27
- config,
28
- fileCache,
29
- logger: console,
30
- session,
31
- });
19
+ import apiWrapper from '../../../lib/server/apiWrapper.js';
32
20
 
21
+ async function handler({ context, req, res }) {
33
22
  const { pageId } = req.query;
34
- const pageConfig = await getPageConfig(apiContext, { pageId });
23
+ const pageConfig = await getPageConfig(context, { pageId });
24
+ // TODO: Do we log here?
35
25
  if (pageConfig === null) {
36
26
  res.status(404).send('Page not found.');
37
27
  } else {
38
28
  res.status(200).json(pageConfig);
39
29
  }
40
30
  }
31
+
32
+ export default apiWrapper(handler);
@@ -14,37 +14,19 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
- import { callRequest, createApiContext } from '@lowdefy/api';
18
- import { getSecretsFromEnv } from '@lowdefy/node-utils';
17
+ import { callRequest } from '@lowdefy/api';
19
18
 
20
- import config from '../../../../build/config.json';
21
- import connections from '../../../../build/plugins/connections.js';
22
- import fileCache from '../../../../lib/fileCache.js';
23
- import getServerSession from '../../../../lib/auth/getServerSession.js';
24
- import operators from '../../../../build/plugins/operators/server.js';
19
+ import apiWrapper from '../../../../lib/server/apiWrapper.js';
25
20
 
26
- export default async function handler(req, res) {
27
- try {
28
- if (req.method !== 'POST') {
29
- throw new Error('Only POST requests are supported.');
30
- }
31
- const session = await getServerSession({ req, res });
32
- const apiContext = createApiContext({
33
- buildDirectory: './build',
34
- config,
35
- connections,
36
- fileCache,
37
- logger: console,
38
- operators,
39
- secrets: getSecretsFromEnv(),
40
- session,
41
- });
42
-
43
- const { blockId, pageId, requestId } = req.query;
44
- const { payload } = req.body;
45
- const response = await callRequest(apiContext, { blockId, pageId, payload, requestId });
46
- res.status(200).json(response);
47
- } catch (error) {
48
- 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.');
49
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);
50
30
  }
31
+
32
+ export default apiWrapper(handler);
package/pages/api/root.js CHANGED
@@ -14,22 +14,12 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
- import { createApiContext, getRootConfig } from '@lowdefy/api';
18
-
19
- import config from '../../build/config.json';
20
- import fileCache from '../../lib/fileCache.js';
21
- import getServerSession from '../../lib/auth/getServerSession.js';
22
-
23
- export default async function handler(req, res) {
24
- const session = await getServerSession({ req, res });
25
- const apiContext = createApiContext({
26
- buildDirectory: './build',
27
- config,
28
- fileCache,
29
- logger: console,
30
- session,
31
- });
32
- const rootConfig = await getRootConfig(apiContext);
17
+ import { getRootConfig } from '@lowdefy/api';
18
+ import apiWrapper from '../../lib/server/apiWrapper.js';
33
19
 
20
+ async function handler({ context, res }) {
21
+ const rootConfig = await getRootConfig(context);
34
22
  res.status(200).json(rootConfig);
35
23
  }
24
+
25
+ export default apiWrapper(handler);
package/pages/index.js CHANGED
@@ -14,6 +14,6 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
- import App from '../lib/App.js';
17
+ import App from '../lib/client/App.js';
18
18
 
19
19
  export default App;
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
File without changes
File without changes
File without changes
File without changes
File without changes