@lowdefy/server 3.23.2 → 4.0.0-alpha.6

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.
@@ -0,0 +1,94 @@
1
+ /*
2
+ Copyright 2020-2021 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 { Area, BlockLayout, layoutParamsToArea } from '@lowdefy/layout';
19
+ import { makeCssClass } from '@lowdefy/block-utils';
20
+
21
+ import Block from './Block.js';
22
+
23
+ const List = ({ block, Blocks, Component, context, lowdefy }) => {
24
+ const content = {};
25
+ const contentList = [];
26
+ Blocks.subBlocks[block.id].forEach((SBlock) => {
27
+ Object.keys(SBlock.areas).forEach((areaKey) => {
28
+ content[areaKey] = (areaStyle) => (
29
+ <Area
30
+ id={`ar-${block.blockId}-${SBlock.id}-${areaKey}`}
31
+ key={`ar-${block.blockId}-${SBlock.id}-${areaKey}`}
32
+ area={layoutParamsToArea({
33
+ area: block.eval.areas[areaKey] || {},
34
+ areaKey,
35
+ layout: block.eval.layout || {},
36
+ })}
37
+ areaStyle={[areaStyle, block.eval.areas[areaKey] && block.eval.areas[areaKey].style]}
38
+ highlightBorders={lowdefy.lowdefyGlobal.highlightBorders}
39
+ makeCssClass={makeCssClass}
40
+ >
41
+ {SBlock.areas[areaKey].blocks.map((bl) => (
42
+ <Block
43
+ key={`ls-${bl.blockId}`}
44
+ Blocks={SBlock}
45
+ block={bl}
46
+ context={context}
47
+ lowdefy={lowdefy}
48
+ />
49
+ ))}
50
+ </Area>
51
+ );
52
+ });
53
+ contentList.push({ ...content });
54
+ });
55
+ return (
56
+ <BlockLayout
57
+ id={`bl-${block.blockId}`}
58
+ blockStyle={block.eval.style}
59
+ highlightBorders={lowdefy.lowdefyGlobal.highlightBorders}
60
+ layout={block.eval.layout || {}}
61
+ makeCssClass={makeCssClass}
62
+ >
63
+ <Component
64
+ methods={Object.assign(block.methods, {
65
+ makeCssClass,
66
+ moveItemDown: block.moveItemDown,
67
+ moveItemUp: block.moveItemUp,
68
+ pushItem: block.pushItem,
69
+ registerEvent: block.registerEvent,
70
+ registerMethod: block.registerMethod,
71
+ removeItem: block.removeItem,
72
+ triggerEvent: block.triggerEvent,
73
+ unshiftItem: block.unshiftItem,
74
+ })}
75
+ basePath={lowdefy._internal.basePath}
76
+ blockId={block.blockId}
77
+ components={lowdefy._internal.components}
78
+ events={block.eval.events}
79
+ homePageId={lowdefy.home.pageId}
80
+ key={block.blockId}
81
+ list={contentList}
82
+ loading={block.loading}
83
+ menus={lowdefy.menus}
84
+ pageId={lowdefy.pageId}
85
+ properties={block.eval.properties}
86
+ required={block.eval.required}
87
+ user={lowdefy.user}
88
+ validation={block.eval.validation}
89
+ />
90
+ </BlockLayout>
91
+ );
92
+ };
93
+
94
+ export default List;
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+ // import { Loading, makeCssClass } from '@lowdefy/block-utils';
3
+ // import { get } from '@lowdefy/helpers';
4
+ // import { BlockLayout } from '@lowdefy/layout';
5
+
6
+ const LoadingBlock = ({ block, lowdefy }) => (
7
+ <div>LoadingBlock</div>
8
+ // <BlockLayout
9
+ // id={`bl-loading-${block.blockId}`}
10
+ // blockStyle={get(block, 'eval.style') || get(block, 'meta.loading.style', { default: {} })}
11
+ // highlightBorders={lowdefy.lowdefyGlobal.highlightBorders}
12
+ // layout={get(block, 'eval.layout') || get(block, 'meta.loading.layout', { default: {} })}
13
+ // makeCssClass={makeCssClass}
14
+ // >
15
+ // <Loading
16
+ // properties={get(block, 'meta.loading.properties')}
17
+ // type={get(block, 'meta.loading.type')}
18
+ // />
19
+ // </BlockLayout>
20
+ );
21
+
22
+ export default LoadingBlock;
@@ -0,0 +1,46 @@
1
+ /*
2
+ Copyright 2020-2021 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, { useEffect, useState } from 'react';
18
+
19
+ const MountEvents = ({ asyncEventName, context, eventName, triggerEvent, children }) => {
20
+ const [loading, setLoading] = useState(true);
21
+ const [error, setError] = useState(null);
22
+ useEffect(() => {
23
+ let mounted = true;
24
+ const mount = async () => {
25
+ try {
26
+ await triggerEvent({ name: eventName, context });
27
+ if (mounted) {
28
+ triggerEvent({ name: asyncEventName, context });
29
+ setLoading(false);
30
+ }
31
+ } catch (err) {
32
+ setError(err);
33
+ }
34
+ };
35
+ mount();
36
+ return () => {
37
+ mounted = false;
38
+ };
39
+ }, [context]);
40
+
41
+ if (error) throw error;
42
+
43
+ return <>{children(loading)}</>;
44
+ };
45
+
46
+ export default MountEvents;
@@ -0,0 +1,25 @@
1
+ /*
2
+ Copyright 2020-2021 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 Link from 'next/link';
18
+ import { createIcon } from '@lowdefy/block-utils';
19
+
20
+ import icons from '../../build/plugins/icons.js';
21
+
22
+ export default {
23
+ Link,
24
+ Icon: createIcon(icons),
25
+ };
@@ -0,0 +1,38 @@
1
+ /*
2
+ Copyright 2020-2021 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 { createApiContext, getPageConfig, getRootConfig } from '@lowdefy/api';
18
+
19
+ import Page from '../components/Page.js';
20
+
21
+ export async function getStaticProps() {
22
+ // TODO: get the right api context options
23
+ const apiContext = await createApiContext({ buildDirectory: './build' });
24
+
25
+ const [rootConfig, pageConfig] = await Promise.all([
26
+ getRootConfig(apiContext),
27
+ getPageConfig(apiContext, { pageId: '404' }),
28
+ ]);
29
+
30
+ return {
31
+ props: {
32
+ pageConfig,
33
+ rootConfig,
34
+ },
35
+ };
36
+ }
37
+
38
+ export default Page;
@@ -0,0 +1,50 @@
1
+ /*
2
+ Copyright 2020-2021 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 { createApiContext, getPageConfig, getRootConfig } from '@lowdefy/api';
18
+
19
+ import Page from '../components/Page.js';
20
+
21
+ export async function getServerSideProps(context) {
22
+ const { pageId } = context.params;
23
+ // TODO: get the right api context options
24
+ const apiContext = await createApiContext({ buildDirectory: './build' });
25
+
26
+ // TODO: Maybe we can only get rootConfig once?
27
+ // We can't do getServerSideProps on _app :(
28
+ const [rootConfig, pageConfig] = await Promise.all([
29
+ getRootConfig(apiContext),
30
+ getPageConfig(apiContext, { pageId }),
31
+ ]);
32
+
33
+ if (!pageConfig) {
34
+ return {
35
+ redirect: {
36
+ destination: '/404',
37
+ permanent: false,
38
+ },
39
+ };
40
+ }
41
+
42
+ return {
43
+ props: {
44
+ pageConfig,
45
+ rootConfig,
46
+ },
47
+ };
48
+ }
49
+
50
+ export default Page;
@@ -0,0 +1,37 @@
1
+ /*
2
+ Copyright 2020-2021 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, { Suspense } from 'react';
18
+
19
+ import { ErrorBoundary } from '@lowdefy/block-utils';
20
+
21
+ import LowdefyContext from '../components/LowdefyContext.js';
22
+
23
+ import '../../build/plugins/styles.less';
24
+
25
+ function App({ Component, pageProps }) {
26
+ return (
27
+ <ErrorBoundary>
28
+ <Suspense>
29
+ <LowdefyContext>
30
+ {(lowdefy) => <Component lowdefy={lowdefy} {...pageProps} />}
31
+ </LowdefyContext>
32
+ </Suspense>
33
+ </ErrorBoundary>
34
+ );
35
+ }
36
+
37
+ export default App;
@@ -0,0 +1,38 @@
1
+ /*
2
+ Copyright 2020-2021 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
+
20
+ class LowdefyDocument extends Document {
21
+ render() {
22
+ return (
23
+ <Html>
24
+ <Head>
25
+ <link rel="manifest" href="/manifest.webmanifest" />
26
+ <link rel="icon" type="image/svg+xml" href="/icon.svg" />
27
+ <link rel="apple-touch-icon" href="/apple-touch-icon.png" />
28
+ </Head>
29
+ <body>
30
+ <Main />
31
+ <NextScript />
32
+ </body>
33
+ </Html>
34
+ );
35
+ }
36
+ }
37
+
38
+ export default LowdefyDocument;
@@ -0,0 +1,28 @@
1
+ /*
2
+ Copyright 2020-2021 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 Auth0Provider from 'next-auth/providers/auth0';
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
+ });
@@ -0,0 +1,44 @@
1
+ /*
2
+ Copyright 2020-2021 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 { callRequest, createApiContext } from '@lowdefy/api';
18
+ import { getSecretsFromEnv } from '@lowdefy/node-utils';
19
+ import connections from '../../../../../build/plugins/connections.js';
20
+ import operators from '../../../../../build/plugins/operatorsServer.js';
21
+
22
+ export default async function handler(req, res) {
23
+ try {
24
+ if (req.method !== 'POST') {
25
+ throw new Error('Only POST requests are supported.');
26
+ }
27
+ // TODO: configure API context
28
+ const apiContext = await createApiContext({
29
+ buildDirectory: './build',
30
+ connections,
31
+ // TODO: use a logger like pino
32
+ logger: console,
33
+ operators,
34
+ secrets: getSecretsFromEnv(),
35
+ });
36
+ const { pageId, requestId } = req.query;
37
+ const { payload } = req.body;
38
+
39
+ const response = await callRequest(apiContext, { pageId, payload, requestId });
40
+ res.status(200).json(response);
41
+ } catch (error) {
42
+ res.status(500).json({ name: error.name, message: error.message });
43
+ }
44
+ }
@@ -0,0 +1,50 @@
1
+ /*
2
+ Copyright 2020-2021 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 { createApiContext, getPageConfig, getRootConfig } from '@lowdefy/api';
18
+
19
+ import Page from '../components/Page.js';
20
+
21
+ export async function getServerSideProps() {
22
+ const apiContext = await createApiContext({ buildDirectory: './build' });
23
+ const rootConfig = await getRootConfig(apiContext);
24
+ const { home } = rootConfig;
25
+ if (home.configured === false) {
26
+ return {
27
+ redirect: {
28
+ destination: `/${home.pageId}`,
29
+ permanent: false,
30
+ },
31
+ };
32
+ }
33
+ const pageConfig = await getPageConfig(apiContext, { pageId: home.pageId });
34
+ if (!pageConfig) {
35
+ return {
36
+ redirect: {
37
+ destination: '/404',
38
+ permanent: false,
39
+ },
40
+ };
41
+ }
42
+ return {
43
+ props: {
44
+ pageConfig,
45
+ rootConfig,
46
+ },
47
+ };
48
+ }
49
+
50
+ export default Page;
@@ -0,0 +1,27 @@
1
+ /*
2
+ Copyright 2020-2021 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 request from './request.js';
18
+
19
+ function callRequest({ pageId, payload, requestId }) {
20
+ return request({
21
+ url: `/api/request/${pageId}/${requestId}`,
22
+ method: 'POST',
23
+ body: { payload },
24
+ });
25
+ }
26
+
27
+ export default callRequest;
@@ -0,0 +1,35 @@
1
+ /*
2
+ Copyright 2020-2021 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
+ async function request({ url, method = 'GET', body }) {
18
+ const res = await fetch(url, {
19
+ method,
20
+ headers: {
21
+ 'Content-Type': 'application/json',
22
+ },
23
+ body: JSON.stringify(body),
24
+ });
25
+ if (!res.ok) {
26
+ // TODO: check
27
+ const body = await res.json();
28
+ console.log(res);
29
+ console.log(body);
30
+ throw new Error(body.message || 'Request error');
31
+ }
32
+ return res.json();
33
+ }
34
+
35
+ export default request;
@@ -0,0 +1,44 @@
1
+ /*
2
+ Copyright 2020-2021 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 { createLink } from '@lowdefy/engine';
18
+
19
+ function setupLink({ lowdefy }) {
20
+ const { router, window } = lowdefy._internal;
21
+ const sameOriginLink = (path, newTab) => {
22
+ if (newTab) {
23
+ return window.open(`${window.location.origin}${lowdefy.basePath}${path}`, '_blank').focus();
24
+ } else {
25
+ // Next handles the basePath here.
26
+ return router.push({
27
+ pathname: path,
28
+ // TODO: Do we handle urlQuery as a param here?
29
+ // query: {},
30
+ });
31
+ }
32
+ };
33
+ const newOriginLink = (path, newTab) => {
34
+ if (newTab) {
35
+ return window.open(path, '_blank').focus();
36
+ } else {
37
+ return (window.location.href = path);
38
+ }
39
+ };
40
+ const backLink = () => window.history.back();
41
+ return createLink({ backLink, lowdefy, newOriginLink, sameOriginLink });
42
+ }
43
+
44
+ export default setupLink;