@lowdefy/server-dev 4.0.0-alpha.7 → 4.0.0-alpha.8

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 (54) hide show
  1. package/package.json +27 -30
  2. package/src/components/App.js +0 -57
  3. package/src/components/Context.js +0 -62
  4. package/src/components/Head.js +0 -28
  5. package/src/components/LowdefyContext.js +0 -50
  6. package/src/components/Page.js +0 -54
  7. package/src/components/Reload.js +0 -43
  8. package/src/components/block/Block.js +0 -57
  9. package/src/components/block/CategorySwitch.js +0 -117
  10. package/src/components/block/Container.js +0 -86
  11. package/src/components/block/List.js +0 -93
  12. package/src/components/block/LoadingBlock.js +0 -22
  13. package/src/components/block/MountEvents.js +0 -46
  14. package/src/components/createComponents.js +0 -29
  15. package/src/components/createLinkComponent.js +0 -97
  16. package/src/manager/getContext.mjs +0 -79
  17. package/src/manager/processes/initialBuild.mjs +0 -27
  18. package/src/manager/processes/installPlugins.mjs +0 -36
  19. package/src/manager/processes/lowdefyBuild.mjs +0 -39
  20. package/src/manager/processes/nextBuild.mjs +0 -31
  21. package/src/manager/processes/readDotEnv.mjs +0 -28
  22. package/src/manager/processes/reloadClients.mjs +0 -26
  23. package/src/manager/processes/restartServer.mjs +0 -27
  24. package/src/manager/processes/shutdownServer.mjs +0 -35
  25. package/src/manager/processes/startNextServer.mjs +0 -45
  26. package/src/manager/processes/startServer.mjs +0 -31
  27. package/src/manager/processes/startWatchers.mjs +0 -31
  28. package/src/manager/run.mjs +0 -92
  29. package/src/manager/utils/BatchChanges.mjs +0 -67
  30. package/src/manager/utils/getLowdefyVersion.mjs +0 -51
  31. package/src/manager/utils/setupWatcher.mjs +0 -49
  32. package/src/manager/utils/spawnProcess.mjs +0 -55
  33. package/src/manager/watchers/envWatcher.mjs +0 -34
  34. package/src/manager/watchers/lowdefyBuildWatcher.mjs +0 -45
  35. package/src/manager/watchers/nextBuildWatcher.mjs +0 -93
  36. package/src/pages/404.js +0 -19
  37. package/src/pages/[pageId].js +0 -19
  38. package/src/pages/_app.js +0 -39
  39. package/src/pages/_document.js +0 -38
  40. package/src/pages/api/auth/[...nextauth].js +0 -28
  41. package/src/pages/api/page/[pageId].js +0 -29
  42. package/src/pages/api/ping.js +0 -19
  43. package/src/pages/api/reload.js +0 -50
  44. package/src/pages/api/request/[pageId]/[requestId].js +0 -45
  45. package/src/pages/api/root.js +0 -25
  46. package/src/pages/index.js +0 -19
  47. package/src/utils/callRequest.js +0 -27
  48. package/src/utils/request.js +0 -36
  49. package/src/utils/setPageId.js +0 -33
  50. package/src/utils/setupLink.js +0 -52
  51. package/src/utils/useMutateCache.js +0 -34
  52. package/src/utils/usePageConfig.js +0 -29
  53. package/src/utils/useRootConfig.js +0 -29
  54. package/src/utils/waitForRestartedServer.js +0 -32
@@ -1,28 +0,0 @@
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
- });
@@ -1,29 +0,0 @@
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 } from '@lowdefy/api';
18
-
19
- export default async function handler(req, res) {
20
- const { pageId } = req.query;
21
- // TODO: get the right api context options
22
- const apiContext = await createApiContext({ buildDirectory: './build' });
23
- const pageConfig = await getPageConfig(apiContext, { pageId });
24
- if (pageConfig === null) {
25
- res.status(404).send('Page not found.');
26
- } else {
27
- res.status(200).json(pageConfig);
28
- }
29
- }
@@ -1,19 +0,0 @@
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
- export default async function handler(req, res) {
18
- res.status(200).json({ timestamp: new Date().toISOString() });
19
- }
@@ -1,50 +0,0 @@
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 chokidar from 'chokidar';
18
-
19
- const handler = async (req, res) => {
20
- res.setHeader('Content-Type', 'text/event-stream;charset=utf-8');
21
- res.setHeader('Cache-Control', 'no-cache, no-transform');
22
- res.setHeader('X-Accel-Buffering', 'no');
23
- res.setHeader('Connection', 'keep-alive');
24
-
25
- const watcher = chokidar.watch(['./build/reload'], {
26
- persistent: true,
27
- ignoreInitial: true,
28
- });
29
-
30
- const reload = () => {
31
- try {
32
- res.write(`event: reload\ndata: ${JSON.stringify({})}\n\n`);
33
- } catch (e) {
34
- console.log(e);
35
- }
36
- };
37
- watcher.on('add', () => reload());
38
- watcher.on('change', () => reload());
39
- watcher.on('unlink', () => reload());
40
-
41
- // TODO: This isn't working.
42
- req.on('close', () => {
43
- console.log('req closed');
44
- watcher.close().then(() => {
45
- console.log('watcher closed');
46
- });
47
- });
48
- };
49
-
50
- export default handler;
@@ -1,45 +0,0 @@
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
- // TODO: configure build directory?
29
- const apiContext = await createApiContext({
30
- buildDirectory: './build',
31
- connections,
32
- // TODO: use a logger like pino
33
- logger: console,
34
- operators,
35
- secrets: getSecretsFromEnv(),
36
- });
37
- const { pageId, requestId } = req.query;
38
- const { payload } = req.body;
39
-
40
- const response = await callRequest(apiContext, { pageId, payload, requestId });
41
- res.status(200).json(response);
42
- } catch (error) {
43
- res.status(500).json({ name: error.name, message: error.message });
44
- }
45
- }
@@ -1,25 +0,0 @@
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, getRootConfig } from '@lowdefy/api';
18
-
19
- export default async function handler(req, res) {
20
- // TODO: get the right api context options
21
- const apiContext = await createApiContext({ buildDirectory: './build' });
22
- const rootConfig = await getRootConfig(apiContext);
23
-
24
- res.status(200).json(rootConfig);
25
- }
@@ -1,19 +0,0 @@
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 App from '../components/App.js';
18
-
19
- export default App;
@@ -1,27 +0,0 @@
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(apiContext, { pageId, payload, requestId }) {
20
- return request({
21
- url: `${apiContext.config.basePath}/api/request/${pageId}/${requestId}`,
22
- method: 'POST',
23
- body: { payload },
24
- });
25
- }
26
-
27
- export default callRequest;
@@ -1,36 +0,0 @@
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: body && JSON.stringify(body),
24
- });
25
- if (res.status === 404) {
26
- return null;
27
- }
28
- if (!res.ok) {
29
- // TODO: check
30
- const body = await res.json();
31
- throw new Error(body.message || 'Request error');
32
- }
33
- return res.json();
34
- }
35
-
36
- export default request;
@@ -1,33 +0,0 @@
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
- function setPageId(lowdefy) {
18
- if (lowdefy._internal.router.pathname === `/404`) {
19
- lowdefy.pageId = '404';
20
- return false;
21
- }
22
- if (!lowdefy._internal.router.query.pageId) {
23
- lowdefy.pageId = lowdefy.home.pageId;
24
- if (lowdefy.home.configured === false) {
25
- return true;
26
- }
27
- return false;
28
- }
29
- lowdefy.pageId = lowdefy._internal.router.query.pageId;
30
- return false;
31
- }
32
-
33
- export default setPageId;
@@ -1,52 +0,0 @@
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 backLink = () => router.back();
22
- const disabledLink = () => {};
23
- const newOriginLink = ({ url, query, newTab }) => {
24
- if (newTab) {
25
- return window.open(`${url}${query ? `?${query}` : ''}`, '_blank').focus();
26
- } else {
27
- return window.location.assign(`${url}${query ? `?${query}` : ''}`);
28
- }
29
- };
30
- const sameOriginLink = ({ newTab, pathname, query, setInput }) => {
31
- if (newTab) {
32
- return window
33
- .open(
34
- `${window.location.origin}${lowdefy.basePath}${pathname}${query ? `?${query}` : ''}`,
35
- '_blank'
36
- )
37
- .focus();
38
- } else {
39
- setInput();
40
- return router.push({
41
- pathname,
42
- query,
43
- });
44
- }
45
- };
46
- const noLink = () => {
47
- throw new Error(`Invalid Link.`);
48
- };
49
- return createLink({ backLink, disabledLink, lowdefy, newOriginLink, noLink, sameOriginLink });
50
- }
51
-
52
- export default setupLink;
@@ -1,34 +0,0 @@
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 { useSWRConfig } from 'swr';
18
-
19
- function useMutateCache(basePath) {
20
- const { cache, mutate } = useSWRConfig();
21
- return () => {
22
- const keys = [`${basePath}/api/root`];
23
-
24
- for (const key of cache.keys()) {
25
- if (key.startsWith(`${basePath}/api/page`)) {
26
- keys.push(key);
27
- }
28
- }
29
- const mutations = keys.map((key) => mutate(key));
30
- return Promise.all(mutations);
31
- };
32
- }
33
-
34
- export default useMutateCache;
@@ -1,29 +0,0 @@
1
- /*
2
- Copyright 2020-2021 Lowdefy, Inc
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
6
- http://www.apache.org/licenses/LICENSE-2.0
7
- Unless required by applicable law or agreed to in writing, software
8
- distributed under the License is distributed on an "AS IS" BASIS,
9
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
- See the License for the specific language governing permissions and
11
- limitations under the License.
12
- */
13
-
14
- import useSWR from 'swr';
15
-
16
- import request from './request.js';
17
-
18
- // TODO: Handle TokenExpiredError
19
-
20
- function fetchPageConfig(url) {
21
- return request({ url });
22
- }
23
-
24
- function usePageConfig(pageId, basePath) {
25
- const { data } = useSWR(`${basePath}/api/page/${pageId}`, fetchPageConfig, { suspense: true });
26
- return { data };
27
- }
28
-
29
- export default usePageConfig;
@@ -1,29 +0,0 @@
1
- /*
2
- Copyright 2020-2021 Lowdefy, Inc
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
6
- http://www.apache.org/licenses/LICENSE-2.0
7
- Unless required by applicable law or agreed to in writing, software
8
- distributed under the License is distributed on an "AS IS" BASIS,
9
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
- See the License for the specific language governing permissions and
11
- limitations under the License.
12
- */
13
-
14
- import useSWR from 'swr';
15
-
16
- import request from './request.js';
17
-
18
- // TODO: Handle TokenExpiredError
19
-
20
- function fetchRootConfig(url) {
21
- return request({ url });
22
- }
23
-
24
- function useRootConfig(basePath) {
25
- const { data } = useSWR(`${basePath}/api/root`, fetchRootConfig, { suspense: true });
26
- return { data };
27
- }
28
-
29
- export default useRootConfig;
@@ -1,32 +0,0 @@
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 waitForRestartedServer(lowdefy) {
20
- setTimeout(async () => {
21
- try {
22
- await request({
23
- url: `${lowdefy.basePath}/api/ping`,
24
- });
25
- lowdefy._internal.window.location.reload();
26
- } catch (error) {
27
- waitForRestartedServer(lowdefy);
28
- }
29
- }, 1500);
30
- }
31
-
32
- export default waitForRestartedServer;