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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/App.js CHANGED
@@ -29,7 +29,7 @@ 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
34
  const App = () => {
35
35
  const router = useRouter();
package/lib/Page.js CHANGED
@@ -15,12 +15,19 @@
15
15
  */
16
16
 
17
17
  import React from 'react';
18
+ import { signIn, signOut, useSession } from 'next-auth/react';
19
+
18
20
  import Client from '@lowdefy/client';
19
21
 
20
22
  import RestartingPage from './RestartingPage.js';
21
23
  import usePageConfig from './utils/usePageConfig.js';
22
24
 
23
25
  const Page = ({ Components, config, pageId, resetContext, router, types }) => {
26
+ const { data: session, status } = useSession();
27
+
28
+ if (status === 'loading') {
29
+ return '';
30
+ }
24
31
  const { data: pageConfig } = usePageConfig(pageId, router.basePath);
25
32
  if (!pageConfig) {
26
33
  router.replace(`/404`);
@@ -31,6 +38,7 @@ const Page = ({ Components, config, pageId, resetContext, router, types }) => {
31
38
  }
32
39
  return (
33
40
  <Client
41
+ auth={{ signIn, signOut }}
34
42
  Components={Components}
35
43
  config={{
36
44
  ...config,
@@ -38,6 +46,7 @@ const Page = ({ Components, config, pageId, resetContext, router, types }) => {
38
46
  }}
39
47
  resetContext={resetContext}
40
48
  router={router}
49
+ session={session}
41
50
  stage="dev"
42
51
  types={types}
43
52
  window={window}
@@ -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);
@@ -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
  }
@@ -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;
@@ -26,8 +26,8 @@ function envWatcher(context) {
26
26
  };
27
27
  return setupWatcher({
28
28
  callback,
29
- watchPaths: [path.join(context.directories.config, '.env')],
30
29
  watchDotfiles: true,
30
+ watchPaths: [path.join(context.directories.config, '.env')],
31
31
  });
32
32
  }
33
33
 
@@ -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.11",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -39,33 +39,35 @@
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.11",
43
+ "@lowdefy/api": "4.0.0-alpha.11",
44
+ "@lowdefy/blocks-antd": "4.0.0-alpha.11",
45
+ "@lowdefy/blocks-basic": "4.0.0-alpha.11",
46
+ "@lowdefy/blocks-color-selectors": "4.0.0-alpha.11",
47
+ "@lowdefy/blocks-echarts": "4.0.0-alpha.11",
48
+ "@lowdefy/blocks-loaders": "4.0.0-alpha.11",
49
+ "@lowdefy/blocks-markdown": "4.0.0-alpha.11",
50
+ "@lowdefy/build": "4.0.0-alpha.11",
51
+ "@lowdefy/client": "4.0.0-alpha.11",
52
+ "@lowdefy/connection-axios-http": "4.0.0-alpha.11",
53
+ "@lowdefy/engine": "4.0.0-alpha.11",
54
+ "@lowdefy/helpers": "4.0.0-alpha.11",
55
+ "@lowdefy/layout": "4.0.0-alpha.11",
56
+ "@lowdefy/node-utils": "4.0.0-alpha.11",
57
+ "@lowdefy/operators-change-case": "4.0.0-alpha.11",
58
+ "@lowdefy/operators-diff": "4.0.0-alpha.11",
59
+ "@lowdefy/operators-js": "4.0.0-alpha.11",
60
+ "@lowdefy/operators-mql": "4.0.0-alpha.11",
61
+ "@lowdefy/operators-nunjucks": "4.0.0-alpha.11",
62
+ "@lowdefy/operators-uuid": "4.0.0-alpha.11",
63
+ "@lowdefy/operators-yaml": "4.0.0-alpha.11",
64
+ "@lowdefy/plugin-next-auth": "4.0.0-alpha.11",
64
65
  "chokidar": "3.5.3",
65
66
  "dotenv": "15.0.0",
66
- "next": "12.0.10",
67
- "next-auth": "4.1.2",
67
+ "next": "12.1.6",
68
+ "next-auth": "4.3.4",
68
69
  "opener": "1.5.2",
70
+ "process": "0.11.10",
69
71
  "react": "17.0.2",
70
72
  "react-dom": "17.0.2",
71
73
  "react-icons": "4.3.1",
@@ -82,5 +84,5 @@
82
84
  "publishConfig": {
83
85
  "access": "public"
84
86
  },
85
- "gitHead": "d697b4b5f354697d9481a371b90a00ca0944f486"
87
+ "gitHead": "810fb2d8cb9ee8b0586b55fbbf26a5a5a0da3b2a"
86
88
  }
package/pages/_app.js CHANGED
@@ -16,14 +16,17 @@
16
16
 
17
17
  import React, { Suspense } from 'react';
18
18
  import dynamic from 'next/dynamic';
19
+ import { SessionProvider } from 'next-auth/react';
19
20
 
20
21
  // Must be in _app due to next specifications.
21
22
  import '../build/plugins/styles.less';
22
23
 
23
- function App({ Component, pageProps }) {
24
+ function App({ Component }) {
24
25
  return (
25
26
  <Suspense fallback="">
26
- <Component {...pageProps} />
27
+ <SessionProvider>
28
+ <Component />
29
+ </SessionProvider>
27
30
  </Suspense>
28
31
  );
29
32
  }
@@ -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 { getSession } from 'next-auth/react';
18
19
 
19
20
  export default async function handler(req, res) {
21
+ const session = await getSession({ 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,27 +16,27 @@
16
16
 
17
17
  import { callRequest, createApiContext } from '@lowdefy/api';
18
18
  import { getSecretsFromEnv } from '@lowdefy/node-utils';
19
+ import { getSession } from 'next-auth/react';
19
20
  import connections from '../../../../build/plugins/connections.js';
20
- import operators from '../../../../build/plugins/operatorsServer.js';
21
+ import operators from '../../../../build/plugins/operators/server.js';
21
22
 
22
23
  export default async function handler(req, res) {
23
24
  try {
24
25
  if (req.method !== 'POST') {
25
26
  throw new Error('Only POST requests are supported.');
26
27
  }
27
- // TODO: configure API context
28
- // TODO: configure build directory?
28
+ const session = await getSession({ req });
29
29
  const apiContext = await createApiContext({
30
30
  buildDirectory: './build',
31
31
  connections,
32
- // TODO: use a logger like pino
33
32
  logger: console,
34
33
  operators,
35
34
  secrets: getSecretsFromEnv(),
35
+ session,
36
36
  });
37
+
37
38
  const { pageId, requestId } = req.query;
38
39
  const { payload } = req.body;
39
-
40
40
  const response = await callRequest(apiContext, { pageId, payload, requestId });
41
41
  res.status(200).json(response);
42
42
  } catch (error) {
package/pages/api/root.js CHANGED
@@ -15,10 +15,15 @@
15
15
  */
16
16
 
17
17
  import { createApiContext, getRootConfig } from '@lowdefy/api';
18
+ import { getSession } from 'next-auth/react';
18
19
 
19
20
  export default async function handler(req, res) {
20
- // TODO: get the right api context options
21
- const apiContext = await createApiContext({ buildDirectory: './build' });
21
+ const session = await getSession({ req });
22
+ const apiContext = await createApiContext({
23
+ buildDirectory: './build',
24
+ logger: console,
25
+ session,
26
+ });
22
27
  const rootConfig = await getRootConfig(apiContext);
23
28
 
24
29
  res.status(200).json(rootConfig);