@lowdefy/server 4.0.0-alpha.9 → 4.0.0-rc.1

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/.npmrc ADDED
@@ -0,0 +1 @@
1
+ strict-peer-dependencies=false
package/lib/Page.js ADDED
@@ -0,0 +1,51 @@
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 React from 'react';
18
+
19
+ import { useRouter } from 'next/router';
20
+ import Client from '@lowdefy/client';
21
+ import Head from 'next/head';
22
+ import Link from 'next/link';
23
+
24
+ import actions from '../build/plugins/actions.js';
25
+ import blocks from '../build/plugins/blocks.js';
26
+ import icons from '../build/plugins/icons.js';
27
+ import operators from '../build/plugins/operators/client.js';
28
+
29
+ const Page = ({ auth, pageConfig, rootConfig }) => {
30
+ const router = useRouter();
31
+ return (
32
+ <Client
33
+ auth={auth}
34
+ Components={{ Head, Link }}
35
+ config={{
36
+ pageConfig,
37
+ rootConfig,
38
+ }}
39
+ router={router}
40
+ types={{
41
+ actions,
42
+ blocks,
43
+ icons,
44
+ operators,
45
+ }}
46
+ window={window}
47
+ />
48
+ );
49
+ };
50
+
51
+ export default Page;
@@ -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
+ /* 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-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
+ /* 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-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
+ /* 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,28 @@
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 { unstable_getServerSession } from 'next-auth/next';
18
+ import { authOptions } from '../../pages/api/auth/[...nextauth].js';
19
+ import authJson from '../../build/auth.json';
20
+
21
+ async function getServerSession({ req, res }) {
22
+ if (authJson.configured === true) {
23
+ return await unstable_getServerSession(req, res, authOptions);
24
+ }
25
+ return undefined;
26
+ }
27
+
28
+ export default getServerSession;
@@ -0,0 +1,21 @@
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 { LRUCache } from '@lowdefy/helpers';
18
+
19
+ const fileCache = new LRUCache({ maxSize: 100 });
20
+
21
+ export default fileCache;
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env node
2
+ /*
3
+ Copyright 2020-2023 Lowdefy, Inc
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+ */
17
+
18
+ import path from 'path';
19
+ import yargs from 'yargs';
20
+ import { hideBin } from 'yargs/helpers';
21
+
22
+ import build from '@lowdefy/build';
23
+ import createCustomPluginTypesMap from './createCustomPluginTypesMap.mjs';
24
+
25
+ const argv = yargs(hideBin(process.argv)).argv;
26
+
27
+ async function run() {
28
+ const serverDirectory = path.resolve(
29
+ argv.serverDirectory || process.env.LOWDEFY_DIRECTORY_SERVER || process.cwd()
30
+ );
31
+ const directories = {
32
+ build: path.join(serverDirectory, 'build'),
33
+ config: path.resolve(
34
+ argv.configDirectory || process.env.LOWDEFY_DIRECTORY_CONFIG || process.cwd()
35
+ ),
36
+ server: serverDirectory,
37
+ };
38
+
39
+ const customTypesMap = await createCustomPluginTypesMap({ directories });
40
+ await build({
41
+ customTypesMap,
42
+ directories,
43
+ logger: console,
44
+ refResolver: argv.refResolver || process.env.LOWDEFY_BUILD_REF_RESOLVER,
45
+ });
46
+ }
47
+
48
+ run();
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env node
2
+ /*
3
+ Copyright 2020-2023 Lowdefy, Inc
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+ */
17
+
18
+ import path from 'path';
19
+ import { get } from '@lowdefy/helpers';
20
+ import { readFile } from '@lowdefy/node-utils';
21
+ import { createPluginTypesMap } from '@lowdefy/build';
22
+ import YAML from 'yaml';
23
+
24
+ async function getPluginDefinitions({ directories }) {
25
+ let lowdefyYaml = await readFile(path.join(directories.config, 'lowdefy.yaml'));
26
+ if (!lowdefyYaml) {
27
+ lowdefyYaml = await readFile(path.join(directories.config, 'lowdefy.yml'));
28
+ }
29
+ const lowdefy = YAML.parse(lowdefyYaml);
30
+ return get(lowdefy, 'plugins', { default: [] });
31
+ }
32
+
33
+ async function createCustomPluginTypesMap({ directories }) {
34
+ const customTypesMap = {
35
+ actions: {},
36
+ auth: {
37
+ adapters: {},
38
+ callbacks: {},
39
+ events: {},
40
+ providers: {},
41
+ },
42
+ blocks: {},
43
+ connections: {},
44
+ icons: {},
45
+ operators: {
46
+ client: {},
47
+ server: {},
48
+ },
49
+ requests: {},
50
+ styles: {
51
+ packages: {},
52
+ blocks: {},
53
+ },
54
+ };
55
+
56
+ const pluginDefinitions = await getPluginDefinitions({ directories });
57
+
58
+ for (const plugin of pluginDefinitions) {
59
+ const { default: types } = await import(`${plugin.name}/types`);
60
+ createPluginTypesMap({
61
+ packageTypes: types,
62
+ typesMap: customTypesMap,
63
+ packageName: plugin.name,
64
+ version: plugin.version,
65
+ typePrefix: plugin.typePrefix,
66
+ });
67
+ }
68
+
69
+ return customTypesMap;
70
+ }
71
+
72
+ export default createCustomPluginTypesMap;
package/next.config.js CHANGED
@@ -1,14 +1,8 @@
1
1
  const withLess = require('next-with-less');
2
2
  const lowdefyConfig = require('./build/config.json');
3
3
 
4
- // TODO: Trace env and args from cli that is required on the server.
5
4
  module.exports = withLess({
6
5
  basePath: process.env.LOWDEFY_BASE_PATH || lowdefyConfig.basePath,
7
- lessLoaderOptions: {
8
- lessOptions: {
9
- modifyVars: lowdefyConfig.theme.lessVariables,
10
- },
11
- },
12
6
  reactStrictMode: true,
13
7
  webpack: (config, { isServer }) => {
14
8
  if (!isServer) {
@@ -27,9 +21,8 @@ module.exports = withLess({
27
21
  },
28
22
  poweredByHeader: false,
29
23
  // productionBrowserSourceMaps: true
30
- // experimental: {
31
- // concurrentFeatures: true,
32
- // },
24
+ output: process.env.LOWDEFY_BUILD_OUTPUT_STANDALONE === '1' ? 'standalone' : undefined,
25
+ outputFileTracing: true,
33
26
  eslint: {
34
27
  ignoreDuringBuilds: true,
35
28
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/server",
3
- "version": "4.0.0-alpha.9",
3
+ "version": "4.0.0-rc.1",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -26,12 +26,17 @@
26
26
  "url": "https://github.com/lowdefy/lowdefy.git"
27
27
  },
28
28
  "files": [
29
- "src/*",
29
+ "lib/*",
30
+ "lowdefy/*",
31
+ "pages/*",
30
32
  "public/*",
31
33
  "next.config.js",
32
- ".eslintrc.yaml"
34
+ "package.original.json",
35
+ ".eslintrc.yaml",
36
+ ".npmrc"
33
37
  ],
34
38
  "scripts": {
39
+ "build": "cp package.json package.original.json || copy package.json package.original.json",
35
40
  "build:lowdefy": "node lowdefy/build.mjs",
36
41
  "build:next": "next build",
37
42
  "dev": "next dev",
@@ -40,34 +45,37 @@
40
45
  "next": "next"
41
46
  },
42
47
  "dependencies": {
43
- "@lowdefy/actions-core": "4.0.0-alpha.9",
44
- "@lowdefy/api": "4.0.0-alpha.9",
45
- "@lowdefy/blocks-antd": "4.0.0-alpha.9",
46
- "@lowdefy/blocks-basic": "4.0.0-alpha.9",
47
- "@lowdefy/blocks-loaders": "4.0.0-alpha.9",
48
- "@lowdefy/client": "4.0.0-alpha.9",
49
- "@lowdefy/helpers": "4.0.0-alpha.9",
50
- "@lowdefy/layout": "4.0.0-alpha.9",
51
- "@lowdefy/node-utils": "4.0.0-alpha.9",
52
- "@lowdefy/operators-js": "4.0.0-alpha.9",
53
- "next": "12.0.10",
54
- "next-auth": "4.1.2",
48
+ "@lowdefy/actions-core": "4.0.0-rc.1",
49
+ "@lowdefy/api": "4.0.0-rc.1",
50
+ "@lowdefy/blocks-antd": "4.0.0-rc.1",
51
+ "@lowdefy/blocks-basic": "4.0.0-rc.1",
52
+ "@lowdefy/blocks-loaders": "4.0.0-rc.1",
53
+ "@lowdefy/client": "4.0.0-rc.1",
54
+ "@lowdefy/helpers": "4.0.0-rc.1",
55
+ "@lowdefy/layout": "4.0.0-rc.1",
56
+ "@lowdefy/node-utils": "4.0.0-rc.1",
57
+ "@lowdefy/operators-js": "4.0.0-rc.1",
58
+ "@lowdefy/plugin-next-auth": "4.0.0-rc.1",
59
+ "next": "12.3.1",
60
+ "next-auth": "4.18.8",
55
61
  "process": "0.11.10",
56
- "react": "17.0.2",
57
- "react-dom": "17.0.2",
58
- "react-icons": "4.3.1"
62
+ "react": "18.2.0",
63
+ "react-dom": "18.2.0",
64
+ "react-icons": "4.7.1"
59
65
  },
60
66
  "devDependencies": {
61
- "@lowdefy/build": "4.0.0-alpha.9",
62
- "@next/eslint-plugin-next": "12.0.10",
63
- "less": "4.1.2",
64
- "less-loader": "10.2.0",
65
- "next-with-less": "2.0.4",
66
- "yaml": "1.10.2",
67
- "yargs": "17.3.1"
67
+ "@lowdefy/build": "4.0.0-rc.1",
68
+ "@next/eslint-plugin-next": "12.1.6",
69
+ "less": "4.1.3",
70
+ "less-loader": "11.1.0",
71
+ "next-with-less": "2.0.5",
72
+ "webpack": "5.75.0",
73
+ "yaml": "2.2.1",
74
+ "yargs": "17.6.2"
68
75
  },
76
+ "packageManager": "pnpm@7.11.0",
69
77
  "publishConfig": {
70
78
  "access": "public"
71
79
  },
72
- "gitHead": "98b544eca231bdcfca6c3a8601a891835d5ce571"
80
+ "gitHead": "ecc4f16c19eede929eda177db524cf13a8053379"
73
81
  }
@@ -0,0 +1,80 @@
1
+ {
2
+ "name": "@lowdefy/server",
3
+ "version": "4.0.0-rc.1",
4
+ "license": "Apache-2.0",
5
+ "description": "",
6
+ "homepage": "https://lowdefy.com",
7
+ "keywords": [
8
+ "lowdefy",
9
+ "server"
10
+ ],
11
+ "bugs": {
12
+ "url": "https://github.com/lowdefy/lowdefy/issues"
13
+ },
14
+ "contributors": [
15
+ {
16
+ "name": "Sam Tolmay",
17
+ "url": "https://github.com/SamTolmay"
18
+ },
19
+ {
20
+ "name": "Gerrie van Wyk",
21
+ "url": "https://github.com/Gervwyk"
22
+ }
23
+ ],
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "https://github.com/lowdefy/lowdefy.git"
27
+ },
28
+ "files": [
29
+ "lib/*",
30
+ "lowdefy/*",
31
+ "pages/*",
32
+ "public/*",
33
+ "next.config.js",
34
+ "package.original.json",
35
+ ".eslintrc.yaml",
36
+ ".npmrc"
37
+ ],
38
+ "scripts": {
39
+ "build": "cp package.json package.original.json || copy package.json package.original.json",
40
+ "build:lowdefy": "node lowdefy/build.mjs",
41
+ "build:next": "next build",
42
+ "dev": "next dev",
43
+ "start": "next start",
44
+ "lint": "next lint",
45
+ "next": "next"
46
+ },
47
+ "dependencies": {
48
+ "@lowdefy/actions-core": "4.0.0-rc.1",
49
+ "@lowdefy/api": "4.0.0-rc.1",
50
+ "@lowdefy/blocks-antd": "4.0.0-rc.1",
51
+ "@lowdefy/blocks-basic": "4.0.0-rc.1",
52
+ "@lowdefy/blocks-loaders": "4.0.0-rc.1",
53
+ "@lowdefy/client": "4.0.0-rc.1",
54
+ "@lowdefy/helpers": "4.0.0-rc.1",
55
+ "@lowdefy/layout": "4.0.0-rc.1",
56
+ "@lowdefy/node-utils": "4.0.0-rc.1",
57
+ "@lowdefy/operators-js": "4.0.0-rc.1",
58
+ "@lowdefy/plugin-next-auth": "4.0.0-rc.1",
59
+ "next": "12.3.1",
60
+ "next-auth": "4.18.8",
61
+ "process": "0.11.10",
62
+ "react": "18.2.0",
63
+ "react-dom": "18.2.0",
64
+ "react-icons": "4.7.1"
65
+ },
66
+ "devDependencies": {
67
+ "@lowdefy/build": "4.0.0-rc.1",
68
+ "@next/eslint-plugin-next": "12.1.6",
69
+ "less": "4.1.3",
70
+ "less-loader": "11.1.0",
71
+ "next-with-less": "2.0.5",
72
+ "webpack": "5.75.0",
73
+ "yaml": "2.2.1",
74
+ "yargs": "17.6.2"
75
+ },
76
+ "packageManager": "pnpm@7.11.0",
77
+ "publishConfig": {
78
+ "access": "public"
79
+ }
80
+ }
package/pages/404.js ADDED
@@ -0,0 +1,45 @@
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 { createApiContext, getPageConfig, getRootConfig } from '@lowdefy/api';
18
+
19
+ import config from '../build/config.json';
20
+ import fileCache from '../lib/fileCache.js';
21
+ import Page from '../lib/Page.js';
22
+
23
+ export async function getStaticProps() {
24
+ // Important to give absolute path so Next can trace build files
25
+ const apiContext = createApiContext({
26
+ buildDirectory: path.join(process.cwd(), 'build'),
27
+ config,
28
+ fileCache,
29
+ logger: console,
30
+ });
31
+
32
+ const [rootConfig, pageConfig] = await Promise.all([
33
+ getRootConfig(apiContext),
34
+ getPageConfig(apiContext, { pageId: '404' }),
35
+ ]);
36
+
37
+ return {
38
+ props: {
39
+ pageConfig,
40
+ rootConfig,
41
+ },
42
+ };
43
+ }
44
+
45
+ export default Page;
@@ -0,0 +1,60 @@
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 path from 'path';
18
+ import { createApiContext, getPageConfig, getRootConfig } from '@lowdefy/api';
19
+
20
+ import config from '../build/config.json';
21
+ import fileCache from '../lib/fileCache.js';
22
+ import getServerSession from '../lib/auth/getServerSession.js';
23
+ import Page from '../lib/Page.js';
24
+
25
+ export async function getServerSideProps(context) {
26
+ const { pageId } = context.params;
27
+ const session = await getServerSession(context);
28
+ // Important to give absolute path so Next can trace build files
29
+ const apiContext = createApiContext({
30
+ buildDirectory: path.join(process.cwd(), 'build'),
31
+ config,
32
+ fileCache,
33
+ logger: console,
34
+ session,
35
+ });
36
+
37
+ const [rootConfig, pageConfig] = await Promise.all([
38
+ getRootConfig(apiContext),
39
+ getPageConfig(apiContext, { pageId }),
40
+ ]);
41
+
42
+ if (!pageConfig) {
43
+ return {
44
+ redirect: {
45
+ destination: '/404',
46
+ permanent: false,
47
+ },
48
+ };
49
+ }
50
+
51
+ return {
52
+ props: {
53
+ pageConfig,
54
+ rootConfig,
55
+ session,
56
+ },
57
+ };
58
+ }
59
+
60
+ export default Page;
package/pages/_app.js ADDED
@@ -0,0 +1,38 @@
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
+ /* eslint-disable react/jsx-props-no-spreading */
17
+
18
+ import React from 'react';
19
+ import dynamic from 'next/dynamic';
20
+
21
+ import Auth from '../lib/auth/Auth.js';
22
+
23
+ // Must be in _app due to next specifications.
24
+ import '../build/plugins/styles.less';
25
+
26
+ function App({ Component, pageProps: { session, rootConfig, pageConfig } }) {
27
+ return (
28
+ <Auth session={session}>
29
+ {(auth) => <Component auth={auth} rootConfig={rootConfig} pageConfig={pageConfig} />}
30
+ </Auth>
31
+ );
32
+ }
33
+
34
+ const DynamicApp = dynamic(() => Promise.resolve(App), {
35
+ ssr: false,
36
+ });
37
+
38
+ export default DynamicApp;
@@ -0,0 +1,50 @@
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 React from 'react';
18
+ import Document, { Html, Head, Main, NextScript } from 'next/document';
19
+ import appJson from '../build/app.json';
20
+
21
+ class LowdefyDocument extends Document {
22
+ render() {
23
+ return (
24
+ <Html>
25
+ <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" />
29
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
30
+ <script
31
+ dangerouslySetInnerHTML={{
32
+ __html: `/* start of Lowdefy append head */</script>${appJson.html.appendHead}<script>/* end of Lowdefy append head */`,
33
+ }}
34
+ />
35
+ </Head>
36
+ <body>
37
+ <Main />
38
+ <NextScript />
39
+ <script
40
+ dangerouslySetInnerHTML={{
41
+ __html: `/* start of Lowdefy append body */</script>${appJson.html.appendBody}<script>/* end of Lowdefy append body */`,
42
+ }}
43
+ />
44
+ </body>
45
+ </Html>
46
+ );
47
+ }
48
+ }
49
+
50
+ export default LowdefyDocument;
@@ -0,0 +1,45 @@
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 NextAuth from 'next-auth';
18
+ import { createApiContext, getNextAuthConfig } from '@lowdefy/api';
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 config from '../../../build/config.json';
24
+ import events from '../../../build/plugins/auth/events.js';
25
+ import fileCache from '../../../lib/fileCache.js';
26
+ import providers from '../../../build/plugins/auth/providers.js';
27
+
28
+ export const authOptions = getNextAuthConfig(
29
+ createApiContext({
30
+ config,
31
+ fileCache,
32
+ logger: console,
33
+ }),
34
+ { authJson, plugins: { adapters, callbacks, events, providers } }
35
+ );
36
+
37
+ export default async function auth(req, res) {
38
+ if (authJson.configured === true) {
39
+ return await NextAuth(req, res, authOptions);
40
+ }
41
+
42
+ return res.status(404).json({
43
+ message: 'Auth not configured',
44
+ });
45
+ }
@@ -0,0 +1,53 @@
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 path from 'path';
18
+ import { callRequest, 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 getServerSession from '../../../../lib/auth/getServerSession.js';
24
+ import operators from '../../../../build/plugins/operators/server.js';
25
+ import fileCache from '../../../../lib/fileCache.js';
26
+
27
+ export default async function handler(req, res) {
28
+ try {
29
+ if (req.method !== 'POST') {
30
+ throw new Error('Only POST requests are supported.');
31
+ }
32
+ const session = await getServerSession({ req, res });
33
+ // Important to give absolute path so Next can trace build files
34
+ const apiContext = createApiContext({
35
+ buildDirectory: path.join(process.cwd(), 'build'),
36
+ config,
37
+ connections,
38
+ fileCache,
39
+ // logger: console,
40
+ logger: { debug: () => {} },
41
+ operators,
42
+ secrets: getSecretsFromEnv(),
43
+ session,
44
+ });
45
+
46
+ const { blockId, pageId, requestId } = req.query;
47
+ const { payload } = req.body;
48
+ const response = await callRequest(apiContext, { blockId, pageId, payload, requestId });
49
+ res.status(200).json(response);
50
+ } catch (error) {
51
+ res.status(500).json({ name: error.name, message: error.message });
52
+ }
53
+ }
package/pages/index.js ADDED
@@ -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
+
17
+ import path from 'path';
18
+ import { createApiContext, getPageConfig, getRootConfig } from '@lowdefy/api';
19
+
20
+ import config from '../build/config.json';
21
+ import fileCache from '../lib/fileCache.js';
22
+ import getServerSession from '../lib/auth/getServerSession.js';
23
+ import Page from '../lib/Page.js';
24
+
25
+ export async function getServerSideProps(context) {
26
+ const session = await getServerSession(context);
27
+
28
+ // Important to give absolute path so Next can trace build files
29
+ const apiContext = createApiContext({
30
+ buildDirectory: path.join(process.cwd(), 'build'),
31
+ config,
32
+ fileCache,
33
+ logger: console,
34
+ session,
35
+ });
36
+ const rootConfig = await getRootConfig(apiContext);
37
+ const { home } = rootConfig;
38
+ if (home.configured === false) {
39
+ return {
40
+ redirect: {
41
+ destination: `/${home.pageId}`,
42
+ permanent: false,
43
+ },
44
+ };
45
+ }
46
+ const pageConfig = await getPageConfig(apiContext, { pageId: home.pageId });
47
+ if (!pageConfig) {
48
+ return {
49
+ redirect: {
50
+ destination: '/404',
51
+ permanent: false,
52
+ },
53
+ };
54
+ }
55
+ return {
56
+ props: {
57
+ pageConfig,
58
+ rootConfig,
59
+ session,
60
+ },
61
+ };
62
+ }
63
+
64
+ export default Page;
Binary file
Binary file
Binary file
package/public/icon.svg DELETED
@@ -1,17 +0,0 @@
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>
Binary file
Binary file
Binary file
Binary file
@@ -1,16 +0,0 @@
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
- }