@lowdefy/server-dev 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 (64) hide show
  1. package/lib/{App.js → client/App.js} +8 -7
  2. package/lib/{Page.js → client/Page.js} +3 -2
  3. package/lib/{Reload.js → client/Reload.js} +5 -2
  4. package/lib/{RestartingPage.js → client/RestartingPage.js} +1 -1
  5. package/lib/{auth → client/auth}/Auth.js +3 -3
  6. package/lib/{auth → client/auth}/AuthConfigured.js +20 -6
  7. package/lib/{auth → client/auth}/AuthNotConfigured.js +2 -1
  8. package/lib/{setPageId.js → client/setPageId.js} +1 -1
  9. package/lib/{utils → client/utils}/request.js +1 -1
  10. package/lib/{utils → client/utils}/useMutateCache.js +4 -13
  11. package/lib/{utils → client/utils}/usePageConfig.js +1 -1
  12. package/lib/{utils → client/utils}/useRootConfig.js +1 -1
  13. package/lib/{utils → client/utils}/waitForRestartedServer.js +1 -1
  14. package/lib/server/apiWrapper.js +64 -0
  15. package/lib/server/auth/getAuthOptions.js +35 -0
  16. package/lib/{auth → server/auth}/getServerSession.js +6 -6
  17. package/lib/{fileCache.js → server/fileCache.js} +1 -1
  18. package/lib/server/log/createLogger.js +29 -0
  19. package/lib/server/log/logError.js +40 -0
  20. package/lib/server/log/logRequest.js +33 -0
  21. package/manager/getContext.mjs +1 -1
  22. package/manager/processes/initialBuild.mjs +1 -1
  23. package/manager/processes/installPlugins.mjs +1 -1
  24. package/manager/processes/lowdefyBuild.mjs +3 -2
  25. package/manager/processes/nextBuild.mjs +1 -1
  26. package/manager/processes/readDotEnv.mjs +1 -1
  27. package/manager/processes/reloadClients.mjs +1 -1
  28. package/manager/processes/restartServer.mjs +1 -1
  29. package/manager/processes/shutdownServer.mjs +1 -1
  30. package/manager/processes/startServer.mjs +1 -1
  31. package/manager/processes/startWatchers.mjs +1 -1
  32. package/manager/run.mjs +1 -1
  33. package/manager/utils/BatchChanges.mjs +1 -1
  34. package/manager/utils/createCustomPluginTypesMap.mjs +10 -3
  35. package/manager/utils/createLogger.mjs +1 -2
  36. package/manager/utils/getLowdefyVersion.mjs +1 -1
  37. package/manager/utils/getNextBin.mjs +1 -1
  38. package/manager/utils/setupWatcher.mjs +1 -1
  39. package/manager/watchers/envWatcher.mjs +1 -1
  40. package/manager/watchers/lowdefyBuildWatcher.mjs +1 -1
  41. package/manager/watchers/nextBuildWatcher.mjs +19 -10
  42. package/next.config.js +1 -1
  43. package/package.json +41 -39
  44. package/package.original.json +94 -0
  45. package/pages/404.js +2 -2
  46. package/pages/[pageId].js +2 -2
  47. package/pages/_app.js +5 -4
  48. package/pages/_document.js +8 -4
  49. package/pages/api/auth/[...nextauth].js +12 -20
  50. package/pages/api/page/[pageId].js +8 -16
  51. package/pages/api/ping.js +1 -1
  52. package/pages/api/reload.js +1 -1
  53. package/pages/api/request/[pageId]/[requestId].js +13 -31
  54. package/pages/api/root.js +7 -17
  55. package/pages/index.js +2 -2
  56. /package/{public → public_default}/apple-touch-icon.png +0 -0
  57. /package/{public → public_default}/favicon.ico +0 -0
  58. /package/{public → public_default}/icon-512.png +0 -0
  59. /package/{public → public_default}/icon.svg +0 -0
  60. /package/{public → public_default}/logo-dark-theme.png +0 -0
  61. /package/{public → public_default}/logo-light-theme.png +0 -0
  62. /package/{public → public_default}/logo-square-dark-theme.png +0 -0
  63. /package/{public → public_default}/logo-square-light-theme.png +0 -0
  64. /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.
@@ -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,
@@ -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.
@@ -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.
@@ -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.
@@ -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.
@@ -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.
@@ -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,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.0",
3
+ "version": "4.0.0-rc.10",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -29,65 +29,67 @@
29
29
  "lib/*",
30
30
  "manager/*",
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
  "start": "node manager/run.mjs",
39
41
  "lint": "next lint",
40
42
  "next": "next"
41
43
  },
42
44
  "dependencies": {
43
- "@lowdefy/actions-core": "4.0.0-rc.0",
44
- "@lowdefy/api": "4.0.0-rc.0",
45
- "@lowdefy/blocks-antd": "4.0.0-rc.0",
46
- "@lowdefy/blocks-basic": "4.0.0-rc.0",
47
- "@lowdefy/blocks-color-selectors": "4.0.0-rc.0",
48
- "@lowdefy/blocks-echarts": "4.0.0-rc.0",
49
- "@lowdefy/blocks-loaders": "4.0.0-rc.0",
50
- "@lowdefy/blocks-markdown": "4.0.0-rc.0",
51
- "@lowdefy/blocks-qr": "4.0.0-rc.0",
52
- "@lowdefy/build": "4.0.0-rc.0",
53
- "@lowdefy/client": "4.0.0-rc.0",
54
- "@lowdefy/connection-axios-http": "4.0.0-rc.0",
55
- "@lowdefy/engine": "4.0.0-rc.0",
56
- "@lowdefy/helpers": "4.0.0-rc.0",
57
- "@lowdefy/layout": "4.0.0-rc.0",
58
- "@lowdefy/node-utils": "4.0.0-rc.0",
59
- "@lowdefy/operators-change-case": "4.0.0-rc.0",
60
- "@lowdefy/operators-diff": "4.0.0-rc.0",
61
- "@lowdefy/operators-js": "4.0.0-rc.0",
62
- "@lowdefy/operators-mql": "4.0.0-rc.0",
63
- "@lowdefy/operators-nunjucks": "4.0.0-rc.0",
64
- "@lowdefy/operators-uuid": "4.0.0-rc.0",
65
- "@lowdefy/operators-yaml": "4.0.0-rc.0",
66
- "@lowdefy/plugin-next-auth": "4.0.0-rc.0",
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",
67
69
  "chokidar": "3.5.3",
68
- "dotenv": "16.0.1",
69
- "next": "12.3.1",
70
- "next-auth": "4.10.3",
70
+ "dotenv": "16.0.3",
71
+ "next": "12.3.4",
72
+ "next-auth": "4.20.1",
71
73
  "opener": "1.5.2",
72
- "pino": "8.1.0",
74
+ "pino": "8.8.0",
73
75
  "process": "0.11.10",
74
76
  "react": "18.2.0",
75
77
  "react-dom": "18.2.0",
76
- "react-icons": "4.3.1",
77
- "swr": "1.3.0",
78
- "yaml": "2.1.1",
79
- "yargs": "17.5.1"
78
+ "react-icons": "4.7.1",
79
+ "swr": "2.0.0",
80
+ "yaml": "2.2.2",
81
+ "yargs": "17.7.2"
80
82
  },
81
83
  "devDependencies": {
82
- "@next/eslint-plugin-next": "12.1.6",
83
- "less": "4.1.2",
84
- "less-loader": "11.0.0",
84
+ "@next/eslint-plugin-next": "12.3.4",
85
+ "less": "4.1.3",
86
+ "less-loader": "11.1.0",
85
87
  "next-with-less": "2.0.5",
86
- "webpack": "5.74.0"
88
+ "webpack": "5.88.2"
87
89
  },
88
90
  "packageManager": "pnpm@7.11.0",
89
91
  "publishConfig": {
90
92
  "access": "public"
91
93
  },
92
- "gitHead": "f6872d7ff6da421710096536fce7b2016ef8f35c"
94
+ "gitHead": "537af074f27770e32da9da8d48490f2eda94b406"
93
95
  }
@@ -0,0 +1,94 @@
1
+ {
2
+ "name": "@lowdefy/server-dev",
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
+ "manager/*",
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
+ "start": "node manager/run.mjs",
41
+ "lint": "next lint",
42
+ "next": "next"
43
+ },
44
+ "dependencies": {
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
+ "chokidar": "3.5.3",
70
+ "dotenv": "16.0.3",
71
+ "next": "12.3.4",
72
+ "next-auth": "4.20.1",
73
+ "opener": "1.5.2",
74
+ "pino": "8.8.0",
75
+ "process": "0.11.10",
76
+ "react": "18.2.0",
77
+ "react-dom": "18.2.0",
78
+ "react-icons": "4.7.1",
79
+ "swr": "2.0.0",
80
+ "yaml": "2.2.2",
81
+ "yargs": "17.7.2"
82
+ },
83
+ "devDependencies": {
84
+ "@next/eslint-plugin-next": "12.3.4",
85
+ "less": "4.1.3",
86
+ "less-loader": "11.1.0",
87
+ "next-with-less": "2.0.5",
88
+ "webpack": "5.88.2"
89
+ },
90
+ "packageManager": "pnpm@7.11.0",
91
+ "publishConfig": {
92
+ "access": "public"
93
+ }
94
+ }
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.
@@ -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
@@ -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,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
@@ -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,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
  }
@@ -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
 
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);
@@ -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,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);
package/pages/api/ping.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.
@@ -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.
@@ -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,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
@@ -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,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);