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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/App.js CHANGED
@@ -29,9 +29,9 @@ import useRootConfig from './utils/useRootConfig.js';
29
29
  import actions from '../build/plugins/actions.js';
30
30
  import blocks from '../build/plugins/blocks.js';
31
31
  import icons from '../build/plugins/icons.js';
32
- import operators from '../build/plugins/operatorsClient.js';
32
+ import operators from '../build/plugins/operators/client.js';
33
33
 
34
- const App = () => {
34
+ const App = ({ auth }) => {
35
35
  const router = useRouter();
36
36
  const { data: rootConfig } = useRootConfig(router.basePath);
37
37
 
@@ -44,6 +44,7 @@ const App = () => {
44
44
  <Reload basePath={router.basePath}>
45
45
  {(resetContext) => (
46
46
  <Page
47
+ auth={auth}
47
48
  Components={{ Head, Link }}
48
49
  config={{
49
50
  rootConfig,
package/lib/Page.js CHANGED
@@ -20,8 +20,9 @@ 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 = ({ Components, config, pageId, resetContext, router, types }) => {
23
+ const Page = ({ auth, Components, config, pageId, resetContext, router, types }) => {
24
24
  const { data: pageConfig } = usePageConfig(pageId, router.basePath);
25
+
25
26
  if (!pageConfig) {
26
27
  router.replace(`/404`);
27
28
  return '';
@@ -31,6 +32,7 @@ const Page = ({ Components, config, pageId, resetContext, router, types }) => {
31
32
  }
32
33
  return (
33
34
  <Client
35
+ auth={auth}
34
36
  Components={Components}
35
37
  config={{
36
38
  ...config,
@@ -0,0 +1,35 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
16
+ /* eslint-disable react/jsx-props-no-spreading */
17
+
18
+ import React from 'react';
19
+ import AuthConfigured from './AuthConfigured.js';
20
+ import AuthNotConfigured from './AuthNotConfigured.js';
21
+
22
+ import authConfig from '../../build/auth.json';
23
+
24
+ function Auth({ children, session }) {
25
+ if (authConfig.configured === true) {
26
+ return (
27
+ <AuthConfigured session={session} authConfig={authConfig}>
28
+ {(auth) => children(auth)}
29
+ </AuthConfigured>
30
+ );
31
+ }
32
+ return <AuthNotConfigured authConfig={authConfig}>{(auth) => children(auth)}</AuthNotConfigured>;
33
+ }
34
+
35
+ export default Auth;
@@ -0,0 +1,47 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
16
+ /* eslint-disable react/jsx-props-no-spreading */
17
+
18
+ import React from 'react';
19
+ import { SessionProvider, signIn, signOut, useSession } from 'next-auth/react';
20
+
21
+ function Session({ children }) {
22
+ const { data: session, status } = useSession();
23
+ // If session is passed to SessionProvider from getServerSideProps
24
+ // we won't have a loading state here.
25
+ // But 404 uses getStaticProps so we have this for 404.
26
+ if (status === 'loading') {
27
+ return '';
28
+ }
29
+ return children(session);
30
+ }
31
+
32
+ function AuthConfigured({ authConfig, children, serverSession }) {
33
+ const auth = { signIn, signOut, authConfig };
34
+
35
+ return (
36
+ <SessionProvider session={serverSession}>
37
+ <Session>
38
+ {(session) => {
39
+ auth.session = session;
40
+ return children(auth);
41
+ }}
42
+ </Session>
43
+ </SessionProvider>
44
+ );
45
+ }
46
+
47
+ export default AuthConfigured;
@@ -0,0 +1,32 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
16
+ /* eslint-disable react/jsx-props-no-spreading */
17
+
18
+ function authNotConfigured() {
19
+ throw new Error('Auth not configured.');
20
+ }
21
+
22
+ function AuthNotConfigured({ authConfig, children }) {
23
+ const auth = {
24
+ authConfig,
25
+ signIn: authNotConfigured,
26
+ signOut: authNotConfigured,
27
+ };
28
+
29
+ return children(auth);
30
+ }
31
+
32
+ export default AuthNotConfigured;
@@ -0,0 +1,27 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
16
+
17
+ import { getSession } from 'next-auth/react';
18
+ import authJson from '../../build/auth.json';
19
+
20
+ async function getServerSession(context) {
21
+ if (authJson.configured === true) {
22
+ return await getSession(context);
23
+ }
24
+ return undefined;
25
+ }
26
+
27
+ export default getServerSession;
@@ -15,8 +15,6 @@ import useSWR from 'swr';
15
15
 
16
16
  import request from './request.js';
17
17
 
18
- // TODO: Handle TokenExpiredError
19
-
20
18
  function fetchPageConfig(url) {
21
19
  return request({ url });
22
20
  }
@@ -12,11 +12,8 @@
12
12
  */
13
13
 
14
14
  import useSWR from 'swr';
15
-
16
15
  import request from './request.js';
17
16
 
18
- // TODO: Handle TokenExpiredError
19
-
20
17
  function fetchRootConfig(url) {
21
18
  return request({ url });
22
19
  }
@@ -16,7 +16,7 @@
16
16
  /* eslint-disable no-console */
17
17
 
18
18
  import path from 'path';
19
- import { createRequire } from 'module';
19
+
20
20
  import yargs from 'yargs';
21
21
  import { hideBin } from 'yargs/helpers';
22
22
 
@@ -30,19 +30,16 @@ import restartServer from './processes/restartServer.mjs';
30
30
  import shutdownServer from './processes/shutdownServer.mjs';
31
31
  import startWatchers from './processes/startWatchers.mjs';
32
32
 
33
+ import getNextBin from './utils/getNextBin.mjs';
34
+
33
35
  const argv = yargs(hideBin(process.argv)).array('watch').array('watchIgnore').argv;
34
- const require = createRequire(import.meta.url);
35
36
 
36
37
  async function getContext() {
37
38
  const env = process.env;
38
39
 
39
- const nextPageJson = require('next/package.json');
40
40
  const context = {
41
41
  bin: {
42
- next: path.join(
43
- require.resolve('next').replace(nextPageJson.main.substring(1), ''),
44
- nextPageJson.bin.next
45
- ),
42
+ next: getNextBin(),
46
43
  },
47
44
  directories: {
48
45
  build: path.resolve(process.cwd(), './build'),
@@ -65,6 +62,8 @@ async function getContext() {
65
62
  version: env.npm_package_version,
66
63
  };
67
64
 
65
+ context.packageManagerCmd =
66
+ process.platform === 'win32' ? `${context.packageManager}.cmd` : context.packageManager;
68
67
  context.initialBuild = initialBuild(context);
69
68
  context.installPlugins = installPlugins(context);
70
69
  context.lowdefyBuild = lowdefyBuild(context);
@@ -17,10 +17,10 @@
17
17
 
18
18
  function initialBuild(context) {
19
19
  return async () => {
20
+ context.readDotEnv();
20
21
  await context.lowdefyBuild();
21
22
  await context.installPlugins();
22
23
  await context.nextBuild();
23
- await context.readDotEnv();
24
24
  };
25
25
  }
26
26
 
@@ -21,12 +21,12 @@ const args = {
21
21
  yarn: ['install'],
22
22
  };
23
23
 
24
- function installPlugins({ packageManager, options }) {
24
+ function installPlugins({ packageManager, packageManagerCmd, options }) {
25
25
  return async () => {
26
26
  console.log('Installing plugins...');
27
27
  await spawnProcess({
28
28
  logger: console,
29
- command: packageManager, // npm or yarn
29
+ command: packageManagerCmd,
30
30
  args: args[packageManager],
31
31
  silent: !options.verbose,
32
32
  });
@@ -25,6 +25,7 @@ function lowdefyBuild({ directories, options }) {
25
25
  directories,
26
26
  logger: console,
27
27
  refResolver: options.refResolver,
28
+ stage: 'dev',
28
29
  });
29
30
  };
30
31
  }
@@ -16,12 +16,10 @@
16
16
 
17
17
  import path from 'path';
18
18
  import dotenv from 'dotenv';
19
- import { readFile } from '@lowdefy/node-utils';
20
19
 
21
20
  function readDotEnv(context) {
22
- return async () => {
23
- const dotEnv = await readFile(path.join(context.directories.config, '.env'));
24
- context.serverEnv = dotenv.parse(dotEnv || '');
21
+ return () => {
22
+ dotenv.config({ path: path.join(context.directories.config, '.env'), silent: true });
25
23
  };
26
24
  }
27
25
 
@@ -27,7 +27,6 @@ function startServerProcess(context) {
27
27
  processOptions: {
28
28
  env: {
29
29
  ...process.env,
30
- ...context.serverEnv,
31
30
  PORT: context.options.port,
32
31
  },
33
32
  },
package/manager/run.mjs CHANGED
@@ -80,7 +80,9 @@ async function run() {
80
80
  try {
81
81
  const serverPromise = startServer(context);
82
82
  await wait(800);
83
- opener(`http://localhost:${context.options.port}`);
83
+ if (process.env.LOWDEFY_SERVER_DEV_OPEN_BROWSER === 'true') {
84
+ opener(`http://localhost:${context.options.port}`);
85
+ }
84
86
  await serverPromise;
85
87
  } catch (error) {
86
88
  console.log(error);
@@ -33,6 +33,11 @@ async function getPluginDefinitions({ directories }) {
33
33
  async function createCustomPluginTypesMap({ directories }) {
34
34
  const customTypesMap = {
35
35
  actions: {},
36
+ auth: {
37
+ callbacks: {},
38
+ events: {},
39
+ providers: {},
40
+ },
36
41
  blocks: {},
37
42
  connections: {},
38
43
  icons: {},
@@ -0,0 +1,36 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
16
+
17
+ import path from 'path';
18
+ import { createRequire } from 'module';
19
+
20
+ function getNextBin() {
21
+ const require = createRequire(import.meta.url);
22
+ const nextPackageJson = require('next/package.json');
23
+
24
+ const nextPath = require.resolve('next');
25
+ let nextMainFragment = nextPackageJson.main.substring(1);
26
+ let nextBinFragment = nextPackageJson.bin.next;
27
+
28
+ if (process.platform === 'win32') {
29
+ nextMainFragment = nextMainFragment.replaceAll('/', '\\');
30
+ nextBinFragment = nextBinFragment.replaceAll('/', '\\');
31
+ }
32
+
33
+ return path.join(nextPath.replace(nextMainFragment, ''), nextBinFragment);
34
+ }
35
+
36
+ export default getNextBin;
@@ -21,13 +21,14 @@ import setupWatcher from '../utils/setupWatcher.mjs';
21
21
  function envWatcher(context) {
22
22
  const callback = async () => {
23
23
  console.warn('.env file changed.');
24
- await context.readDotEnv();
24
+ context.readDotEnv();
25
+ await context.lowdefyBuild();
25
26
  context.restartServer();
26
27
  };
27
28
  return setupWatcher({
28
29
  callback,
29
- watchPaths: [path.join(context.directories.config, '.env')],
30
30
  watchDotfiles: true,
31
+ watchPaths: [path.join(context.directories.config, '.env')],
31
32
  });
32
33
  }
33
34
 
@@ -23,13 +23,17 @@ import setupWatcher from '../utils/setupWatcher.mjs';
23
23
  const hashes = {};
24
24
 
25
25
  const watchedFiles = [
26
+ 'build/auth.json',
26
27
  'build/config.json',
27
28
  'build/plugins/actions.js',
29
+ 'build/plugins/auth/callbacks.js',
30
+ 'build/plugins/auth/events.js',
31
+ 'build/plugins/auth/providers.js',
28
32
  'build/plugins/blocks.js',
29
33
  'build/plugins/connections.js',
30
34
  'build/plugins/icons.js',
31
- 'build/plugins/operatorsClient.js',
32
- 'build/plugins/operatorsServer.js',
35
+ 'build/plugins/operators/client.js',
36
+ 'build/plugins/operators/server.js',
33
37
  'build/plugins/styles.less',
34
38
  'package.json',
35
39
  ];
@@ -83,8 +87,10 @@ async function nextBuildWatcher(context) {
83
87
 
84
88
  return setupWatcher({
85
89
  callback,
90
+ watchDotfiles: true,
86
91
  watchPaths: [
87
92
  path.join(context.directories.build, 'plugins'),
93
+ path.join(context.directories.build, 'auth.json'),
88
94
  path.join(context.directories.build, 'config.json'),
89
95
  path.join(context.directories.server, 'package.json'),
90
96
  ],
package/next.config.js CHANGED
@@ -18,7 +18,7 @@ module.exports = withLess({
18
18
  events: false,
19
19
  fs: false,
20
20
  path: false,
21
- process: false,
21
+ process: require.resolve('process/browser'),
22
22
  util: false,
23
23
  };
24
24
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/server-dev",
3
- "version": "4.0.0-alpha.10",
3
+ "version": "4.0.0-alpha.13",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -39,48 +39,50 @@
39
39
  "next": "next"
40
40
  },
41
41
  "dependencies": {
42
- "@lowdefy/actions-core": "4.0.0-alpha.10",
43
- "@lowdefy/api": "4.0.0-alpha.10",
44
- "@lowdefy/blocks-antd": "4.0.0-alpha.10",
45
- "@lowdefy/blocks-basic": "4.0.0-alpha.10",
46
- "@lowdefy/blocks-color-selectors": "4.0.0-alpha.10",
47
- "@lowdefy/blocks-echarts": "4.0.0-alpha.10",
48
- "@lowdefy/blocks-loaders": "4.0.0-alpha.10",
49
- "@lowdefy/blocks-markdown": "4.0.0-alpha.10",
50
- "@lowdefy/build": "4.0.0-alpha.10",
51
- "@lowdefy/client": "4.0.0-alpha.10",
52
- "@lowdefy/connection-axios-http": "4.0.0-alpha.10",
53
- "@lowdefy/engine": "4.0.0-alpha.10",
54
- "@lowdefy/helpers": "4.0.0-alpha.10",
55
- "@lowdefy/layout": "4.0.0-alpha.10",
56
- "@lowdefy/node-utils": "4.0.0-alpha.10",
57
- "@lowdefy/operators-change-case": "4.0.0-alpha.10",
58
- "@lowdefy/operators-diff": "4.0.0-alpha.10",
59
- "@lowdefy/operators-js": "4.0.0-alpha.10",
60
- "@lowdefy/operators-mql": "4.0.0-alpha.10",
61
- "@lowdefy/operators-nunjucks": "4.0.0-alpha.10",
62
- "@lowdefy/operators-uuid": "4.0.0-alpha.10",
63
- "@lowdefy/operators-yaml": "4.0.0-alpha.10",
42
+ "@lowdefy/actions-core": "4.0.0-alpha.13",
43
+ "@lowdefy/api": "4.0.0-alpha.13",
44
+ "@lowdefy/blocks-antd": "4.0.0-alpha.13",
45
+ "@lowdefy/blocks-basic": "4.0.0-alpha.13",
46
+ "@lowdefy/blocks-color-selectors": "4.0.0-alpha.13",
47
+ "@lowdefy/blocks-echarts": "4.0.0-alpha.13",
48
+ "@lowdefy/blocks-loaders": "4.0.0-alpha.13",
49
+ "@lowdefy/blocks-markdown": "4.0.0-alpha.13",
50
+ "@lowdefy/build": "4.0.0-alpha.13",
51
+ "@lowdefy/client": "4.0.0-alpha.13",
52
+ "@lowdefy/connection-axios-http": "4.0.0-alpha.13",
53
+ "@lowdefy/engine": "4.0.0-alpha.13",
54
+ "@lowdefy/helpers": "4.0.0-alpha.13",
55
+ "@lowdefy/layout": "4.0.0-alpha.13",
56
+ "@lowdefy/node-utils": "4.0.0-alpha.13",
57
+ "@lowdefy/operators-change-case": "4.0.0-alpha.13",
58
+ "@lowdefy/operators-diff": "4.0.0-alpha.13",
59
+ "@lowdefy/operators-js": "4.0.0-alpha.13",
60
+ "@lowdefy/operators-mql": "4.0.0-alpha.13",
61
+ "@lowdefy/operators-nunjucks": "4.0.0-alpha.13",
62
+ "@lowdefy/operators-uuid": "4.0.0-alpha.13",
63
+ "@lowdefy/operators-yaml": "4.0.0-alpha.13",
64
+ "@lowdefy/plugin-next-auth": "4.0.0-alpha.13",
64
65
  "chokidar": "3.5.3",
65
- "dotenv": "15.0.0",
66
- "next": "12.0.10",
67
- "next-auth": "4.1.2",
66
+ "dotenv": "16.0.1",
67
+ "next": "12.1.6",
68
+ "next-auth": "4.3.4",
68
69
  "opener": "1.5.2",
69
- "react": "17.0.2",
70
- "react-dom": "17.0.2",
70
+ "process": "0.11.10",
71
+ "react": "18.1.0",
72
+ "react-dom": "18.1.0",
71
73
  "react-icons": "4.3.1",
72
- "swr": "1.1.2",
73
- "yaml": "2.0.0-10",
74
- "yargs": "17.3.1"
74
+ "swr": "1.3.0",
75
+ "yaml": "2.1.1",
76
+ "yargs": "17.5.1"
75
77
  },
76
78
  "devDependencies": {
77
- "@next/eslint-plugin-next": "12.0.10",
79
+ "@next/eslint-plugin-next": "12.1.6",
78
80
  "less": "4.1.2",
79
- "less-loader": "10.2.0",
80
- "next-with-less": "2.0.4"
81
+ "less-loader": "11.0.0",
82
+ "next-with-less": "2.0.5"
81
83
  },
82
84
  "publishConfig": {
83
85
  "access": "public"
84
86
  },
85
- "gitHead": "d697b4b5f354697d9481a371b90a00ca0944f486"
87
+ "gitHead": "e99b4b6c1f59804982fc148c0fe39dcf13b35d77"
86
88
  }
package/pages/_app.js CHANGED
@@ -17,13 +17,15 @@
17
17
  import React, { Suspense } from 'react';
18
18
  import dynamic from 'next/dynamic';
19
19
 
20
+ import Auth from '../lib/auth/Auth.js';
21
+
20
22
  // Must be in _app due to next specifications.
21
23
  import '../build/plugins/styles.less';
22
24
 
23
- function App({ Component, pageProps }) {
25
+ function App({ Component }) {
24
26
  return (
25
27
  <Suspense fallback="">
26
- <Component {...pageProps} />
28
+ <Auth>{(auth) => <Component auth={auth} />}</Auth>
27
29
  </Suspense>
28
30
  );
29
31
  }
@@ -15,14 +15,11 @@
15
15
  */
16
16
 
17
17
  import NextAuth from 'next-auth';
18
- import Auth0Provider from 'next-auth/providers/auth0';
18
+ import { getNextAuthConfig } from '@lowdefy/api';
19
19
 
20
- export default NextAuth({
21
- providers: [
22
- Auth0Provider({
23
- clientId: process.env.AUTH0_CLIENT_ID,
24
- clientSecret: process.env.AUTH0_CLIENT_SECRET,
25
- issuer: process.env.AUTH0_ISSUER,
26
- }),
27
- ],
28
- });
20
+ import authJson from '../../../build/auth.json';
21
+ import callbacks from '../../../build/plugins/auth/callbacks.js';
22
+ import events from '../../../build/plugins/auth/events.js';
23
+ import providers from '../../../build/plugins/auth/providers.js';
24
+
25
+ export default NextAuth(getNextAuthConfig({ authJson, plugins: { callbacks, events, providers } }));
@@ -15,11 +15,17 @@
15
15
  */
16
16
 
17
17
  import { createApiContext, getPageConfig } from '@lowdefy/api';
18
+ import getServerSession from '../../../lib/auth/getServerSession.js';
18
19
 
19
20
  export default async function handler(req, res) {
21
+ const session = await getServerSession({ req });
22
+ const apiContext = await createApiContext({
23
+ buildDirectory: './build',
24
+ logger: console,
25
+ session,
26
+ });
27
+
20
28
  const { pageId } = req.query;
21
- // TODO: get the right api context options
22
- const apiContext = await createApiContext({ buildDirectory: './build' });
23
29
  const pageConfig = await getPageConfig(apiContext, { pageId });
24
30
  if (pageConfig === null) {
25
31
  res.status(404).send('Page not found.');
@@ -16,28 +16,29 @@
16
16
 
17
17
  import { callRequest, createApiContext } from '@lowdefy/api';
18
18
  import { getSecretsFromEnv } from '@lowdefy/node-utils';
19
+
19
20
  import connections from '../../../../build/plugins/connections.js';
20
- import operators from '../../../../build/plugins/operatorsServer.js';
21
+ import getServerSession from '../../../../lib/auth/getServerSession.js';
22
+ import operators from '../../../../build/plugins/operators/server.js';
21
23
 
22
24
  export default async function handler(req, res) {
23
25
  try {
24
26
  if (req.method !== 'POST') {
25
27
  throw new Error('Only POST requests are supported.');
26
28
  }
27
- // TODO: configure API context
28
- // TODO: configure build directory?
29
+ const session = await getServerSession({ req });
29
30
  const apiContext = await createApiContext({
30
31
  buildDirectory: './build',
31
32
  connections,
32
- // TODO: use a logger like pino
33
33
  logger: console,
34
34
  operators,
35
35
  secrets: getSecretsFromEnv(),
36
+ session,
36
37
  });
37
- const { pageId, requestId } = req.query;
38
- const { payload } = req.body;
39
38
 
40
- const response = await callRequest(apiContext, { pageId, payload, requestId });
39
+ const { blockId, pageId, requestId } = req.query;
40
+ const { payload } = req.body;
41
+ const response = await callRequest(apiContext, { blockId, pageId, payload, requestId });
41
42
  res.status(200).json(response);
42
43
  } catch (error) {
43
44
  res.status(500).json({ name: error.name, message: error.message });
package/pages/api/root.js CHANGED
@@ -16,9 +16,15 @@
16
16
 
17
17
  import { createApiContext, getRootConfig } from '@lowdefy/api';
18
18
 
19
+ import getServerSession from '../../lib/auth/getServerSession.js';
20
+
19
21
  export default async function handler(req, res) {
20
- // TODO: get the right api context options
21
- const apiContext = await createApiContext({ buildDirectory: './build' });
22
+ const session = await getServerSession({ req });
23
+ const apiContext = await createApiContext({
24
+ buildDirectory: './build',
25
+ logger: console,
26
+ session,
27
+ });
22
28
  const rootConfig = await getRootConfig(apiContext);
23
29
 
24
30
  res.status(200).json(rootConfig);