@lowdefy/server-dev 4.0.0-rc.0 → 4.0.0-rc.10
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 → client/App.js} +8 -7
- package/lib/{Page.js → client/Page.js} +3 -2
- package/lib/{Reload.js → client/Reload.js} +5 -2
- package/lib/{RestartingPage.js → client/RestartingPage.js} +1 -1
- package/lib/{auth → client/auth}/Auth.js +3 -3
- package/lib/{auth → client/auth}/AuthConfigured.js +20 -6
- package/lib/{auth → client/auth}/AuthNotConfigured.js +2 -1
- package/lib/{setPageId.js → client/setPageId.js} +1 -1
- package/lib/{utils → client/utils}/request.js +1 -1
- package/lib/{utils → client/utils}/useMutateCache.js +4 -13
- package/lib/{utils → client/utils}/usePageConfig.js +1 -1
- package/lib/{utils → client/utils}/useRootConfig.js +1 -1
- package/lib/{utils → client/utils}/waitForRestartedServer.js +1 -1
- package/lib/server/apiWrapper.js +64 -0
- package/lib/server/auth/getAuthOptions.js +35 -0
- package/lib/{auth → server/auth}/getServerSession.js +6 -6
- package/lib/{fileCache.js → server/fileCache.js} +1 -1
- package/lib/server/log/createLogger.js +29 -0
- package/lib/server/log/logError.js +40 -0
- package/lib/server/log/logRequest.js +33 -0
- package/manager/getContext.mjs +1 -1
- package/manager/processes/initialBuild.mjs +1 -1
- package/manager/processes/installPlugins.mjs +1 -1
- package/manager/processes/lowdefyBuild.mjs +3 -2
- package/manager/processes/nextBuild.mjs +1 -1
- package/manager/processes/readDotEnv.mjs +1 -1
- package/manager/processes/reloadClients.mjs +1 -1
- package/manager/processes/restartServer.mjs +1 -1
- package/manager/processes/shutdownServer.mjs +1 -1
- package/manager/processes/startServer.mjs +1 -1
- package/manager/processes/startWatchers.mjs +1 -1
- package/manager/run.mjs +1 -1
- package/manager/utils/BatchChanges.mjs +1 -1
- package/manager/utils/createCustomPluginTypesMap.mjs +10 -3
- package/manager/utils/createLogger.mjs +1 -2
- package/manager/utils/getLowdefyVersion.mjs +1 -1
- package/manager/utils/getNextBin.mjs +1 -1
- package/manager/utils/setupWatcher.mjs +1 -1
- package/manager/watchers/envWatcher.mjs +1 -1
- package/manager/watchers/lowdefyBuildWatcher.mjs +1 -1
- package/manager/watchers/nextBuildWatcher.mjs +19 -10
- package/next.config.js +1 -1
- package/package.json +41 -39
- package/package.original.json +94 -0
- package/pages/404.js +2 -2
- package/pages/[pageId].js +2 -2
- package/pages/_app.js +5 -4
- package/pages/_document.js +8 -4
- package/pages/api/auth/[...nextauth].js +12 -20
- package/pages/api/page/[pageId].js +8 -16
- package/pages/api/ping.js +1 -1
- package/pages/api/reload.js +1 -1
- package/pages/api/request/[pageId]/[requestId].js +13 -31
- package/pages/api/root.js +7 -17
- package/pages/index.js +2 -2
- /package/{public → public_default}/apple-touch-icon.png +0 -0
- /package/{public → public_default}/favicon.ico +0 -0
- /package/{public → public_default}/icon-512.png +0 -0
- /package/{public → public_default}/icon.svg +0 -0
- /package/{public → public_default}/logo-dark-theme.png +0 -0
- /package/{public → public_default}/logo-light-theme.png +0 -0
- /package/{public → public_default}/logo-square-dark-theme.png +0 -0
- /package/{public → public_default}/logo-square-light-theme.png +0 -0
- /package/{public → public_default}/manifest.webmanifest +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -26,12 +26,12 @@ import Page from './Page.js';
|
|
|
26
26
|
import setPageId from './setPageId.js';
|
|
27
27
|
import useRootConfig from './utils/useRootConfig.js';
|
|
28
28
|
|
|
29
|
-
import actions from '
|
|
30
|
-
import blocks from '
|
|
31
|
-
import icons from '
|
|
32
|
-
import operators from '
|
|
29
|
+
import actions from '../../build/plugins/actions.js';
|
|
30
|
+
import blocks from '../../build/plugins/blocks.js';
|
|
31
|
+
import icons from '../../build/plugins/icons.js';
|
|
32
|
+
import operators from '../../build/plugins/operators/client.js';
|
|
33
33
|
|
|
34
|
-
const App = ({ auth }) => {
|
|
34
|
+
const App = ({ auth, lowdefy }) => {
|
|
35
35
|
const router = useRouter();
|
|
36
36
|
const { data: rootConfig } = useRootConfig(router.basePath);
|
|
37
37
|
|
|
@@ -41,7 +41,7 @@ const App = ({ auth }) => {
|
|
|
41
41
|
return '';
|
|
42
42
|
}
|
|
43
43
|
return (
|
|
44
|
-
<Reload basePath={router.basePath}>
|
|
44
|
+
<Reload basePath={router.basePath} lowdefy={lowdefy}>
|
|
45
45
|
{(resetContext) => (
|
|
46
46
|
<Page
|
|
47
47
|
auth={auth}
|
|
@@ -49,6 +49,7 @@ const App = ({ auth }) => {
|
|
|
49
49
|
config={{
|
|
50
50
|
rootConfig,
|
|
51
51
|
}}
|
|
52
|
+
lowdefy={lowdefy}
|
|
52
53
|
pageId={pageId}
|
|
53
54
|
resetContext={resetContext}
|
|
54
55
|
router={router}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -20,7 +20,7 @@ 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 = ({ auth, Components, config, pageId, resetContext, router, types }) => {
|
|
23
|
+
const Page = ({ auth, Components, config, lowdefy, pageId, resetContext, router, types }) => {
|
|
24
24
|
const { data: pageConfig } = usePageConfig(pageId, router.basePath);
|
|
25
25
|
|
|
26
26
|
if (!pageConfig) {
|
|
@@ -38,6 +38,7 @@ const Page = ({ auth, Components, config, pageId, resetContext, router, types })
|
|
|
38
38
|
...config,
|
|
39
39
|
pageConfig,
|
|
40
40
|
}}
|
|
41
|
+
lowdefy={lowdefy}
|
|
41
42
|
resetContext={resetContext}
|
|
42
43
|
router={router}
|
|
43
44
|
stage="dev"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -19,7 +19,7 @@ import React, { useEffect, useState } from 'react';
|
|
|
19
19
|
import useMutateCache from './utils/useMutateCache.js';
|
|
20
20
|
import waitForRestartedServer from './utils/waitForRestartedServer.js';
|
|
21
21
|
|
|
22
|
-
const Reload = ({ children, basePath }) => {
|
|
22
|
+
const Reload = ({ children, basePath, lowdefy }) => {
|
|
23
23
|
const [reset, setReset] = useState(false);
|
|
24
24
|
const [restarting, setRestarting] = useState(false);
|
|
25
25
|
const mutateCache = useMutateCache(basePath);
|
|
@@ -31,6 +31,9 @@ const Reload = ({ children, basePath }) => {
|
|
|
31
31
|
// TODO: We need to pass a flag when a rebuild will happen so that client does not trigger render.
|
|
32
32
|
setTimeout(async () => {
|
|
33
33
|
await mutateCache();
|
|
34
|
+
if (lowdefy._internal?.initialised) {
|
|
35
|
+
lowdefy._internal.initialised = false;
|
|
36
|
+
}
|
|
34
37
|
setReset(true);
|
|
35
38
|
console.log('Reloaded config.');
|
|
36
39
|
}, 600);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -19,12 +19,12 @@ import React from 'react';
|
|
|
19
19
|
import AuthConfigured from './AuthConfigured.js';
|
|
20
20
|
import AuthNotConfigured from './AuthNotConfigured.js';
|
|
21
21
|
|
|
22
|
-
import authConfig from '
|
|
22
|
+
import authConfig from '../../../build/auth.json';
|
|
23
23
|
|
|
24
24
|
function Auth({ children, session }) {
|
|
25
25
|
if (authConfig.configured === true) {
|
|
26
26
|
return (
|
|
27
|
-
<AuthConfigured
|
|
27
|
+
<AuthConfigured serverSession={session} authConfig={authConfig}>
|
|
28
28
|
{(auth) => children(auth)}
|
|
29
29
|
</AuthConfigured>
|
|
30
30
|
);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -15,11 +15,22 @@
|
|
|
15
15
|
*/
|
|
16
16
|
/* eslint-disable react/jsx-props-no-spreading */
|
|
17
17
|
|
|
18
|
-
import React from 'react';
|
|
19
|
-
import { SessionProvider, signIn, signOut, useSession } from 'next-auth/react';
|
|
18
|
+
import React, { useEffect, useRef } from 'react';
|
|
19
|
+
import { getSession, SessionProvider, signIn, signOut, useSession } from 'next-auth/react';
|
|
20
|
+
|
|
21
|
+
import lowdefyConfig from '../../../build/config.json';
|
|
20
22
|
|
|
21
23
|
function Session({ children }) {
|
|
24
|
+
const wasAuthenticated = useRef(false);
|
|
22
25
|
const { data: session, status } = useSession();
|
|
26
|
+
wasAuthenticated.current = wasAuthenticated.current || status === 'authenticated';
|
|
27
|
+
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (wasAuthenticated.current && status === 'unauthenticated') {
|
|
30
|
+
window.location.reload();
|
|
31
|
+
}
|
|
32
|
+
}, [status]);
|
|
33
|
+
|
|
23
34
|
// If session is passed to SessionProvider from getServerSideProps
|
|
24
35
|
// we won't have a loading state here.
|
|
25
36
|
// But 404 uses getStaticProps so we have this for 404.
|
|
@@ -30,10 +41,13 @@ function Session({ children }) {
|
|
|
30
41
|
}
|
|
31
42
|
|
|
32
43
|
function AuthConfigured({ authConfig, children, serverSession }) {
|
|
33
|
-
const auth = { signIn, signOut
|
|
34
|
-
|
|
44
|
+
const auth = { authConfig, getSession, signIn, signOut };
|
|
45
|
+
let basePath = lowdefyConfig.basePath;
|
|
46
|
+
if (basePath) {
|
|
47
|
+
basePath = `${basePath}/api/auth`;
|
|
48
|
+
}
|
|
35
49
|
return (
|
|
36
|
-
<SessionProvider session={serverSession}>
|
|
50
|
+
<SessionProvider session={serverSession} basePath={basePath}>
|
|
37
51
|
<Session>
|
|
38
52
|
{(session) => {
|
|
39
53
|
auth.session = session;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -22,6 +22,7 @@ function authNotConfigured() {
|
|
|
22
22
|
function AuthNotConfigured({ authConfig, children }) {
|
|
23
23
|
const auth = {
|
|
24
24
|
authConfig,
|
|
25
|
+
getSession: authNotConfigured,
|
|
25
26
|
signIn: authNotConfigured,
|
|
26
27
|
signOut: authNotConfigured,
|
|
27
28
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -17,18 +17,9 @@
|
|
|
17
17
|
import { useSWRConfig } from 'swr';
|
|
18
18
|
|
|
19
19
|
function useMutateCache(basePath) {
|
|
20
|
-
const {
|
|
21
|
-
return () =>
|
|
22
|
-
|
|
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
|
-
};
|
|
20
|
+
const { mutate } = useSWRConfig();
|
|
21
|
+
return () =>
|
|
22
|
+
mutate((key) => key.startsWith(`${basePath}/api/page`) || key === `${basePath}/api/root`);
|
|
32
23
|
}
|
|
33
24
|
|
|
34
25
|
export default useMutateCache;
|
|
@@ -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
|
+
import path from 'path';
|
|
17
|
+
import crypto from 'crypto';
|
|
18
|
+
import { 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 createLogger from './log/createLogger.js';
|
|
24
|
+
import fileCache from './fileCache.js';
|
|
25
|
+
import getServerSession from './auth/getServerSession.js';
|
|
26
|
+
import logRequest from './log/logRequest.js';
|
|
27
|
+
import logError from './log/logError.js';
|
|
28
|
+
import operators from '../../build/plugins/operators/server.js';
|
|
29
|
+
import getAuthOptions from './auth/getAuthOptions.js';
|
|
30
|
+
|
|
31
|
+
function apiWrapper(handler) {
|
|
32
|
+
return async function wrappedHandler(req, res) {
|
|
33
|
+
const context = {
|
|
34
|
+
// Important to give absolute path so Next can trace build files
|
|
35
|
+
rid: crypto.randomUUID(),
|
|
36
|
+
buildDirectory: path.join(process.cwd(), 'build'),
|
|
37
|
+
config,
|
|
38
|
+
connections,
|
|
39
|
+
fileCache,
|
|
40
|
+
headers: req?.headers,
|
|
41
|
+
logger: console,
|
|
42
|
+
operators,
|
|
43
|
+
req,
|
|
44
|
+
res,
|
|
45
|
+
};
|
|
46
|
+
try {
|
|
47
|
+
context.logger = createLogger({ rid: context.rid });
|
|
48
|
+
context.authOptions = getAuthOptions(context);
|
|
49
|
+
context.session = await getServerSession(context);
|
|
50
|
+
context.secrets = getSecretsFromEnv();
|
|
51
|
+
createApiContext(context);
|
|
52
|
+
logRequest({ context });
|
|
53
|
+
// Await here so that if handler throws it is caught.
|
|
54
|
+
const response = await handler({ context, req, res });
|
|
55
|
+
// TODO: Log response time?
|
|
56
|
+
return response;
|
|
57
|
+
} catch (error) {
|
|
58
|
+
logError({ error, context });
|
|
59
|
+
res.status(500).json({ name: error.name, message: error.message });
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export default apiWrapper;
|
|
@@ -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
|
+
|
|
17
|
+
import { getNextAuthConfig } from '@lowdefy/api';
|
|
18
|
+
import { getSecretsFromEnv } from '@lowdefy/node-utils';
|
|
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 events from '../../../build/plugins/auth/events.js';
|
|
24
|
+
import providers from '../../../build/plugins/auth/providers.js';
|
|
25
|
+
|
|
26
|
+
function getAuthOptions({ logger }) {
|
|
27
|
+
return getNextAuthConfig({
|
|
28
|
+
authJson,
|
|
29
|
+
logger,
|
|
30
|
+
plugins: { adapters, callbacks, events, providers },
|
|
31
|
+
secrets: getSecretsFromEnv(),
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export default getAuthOptions;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -14,13 +14,13 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import {
|
|
18
|
-
import { authOptions } from '../../pages/api/auth/[...nextauth].js';
|
|
19
|
-
import authJson from '../../build/auth.json';
|
|
17
|
+
import { getServerSession as getNextAuthServerSession } from 'next-auth/next';
|
|
20
18
|
|
|
21
|
-
|
|
19
|
+
import authJson from '../../../build/auth.json';
|
|
20
|
+
|
|
21
|
+
function getServerSession({ authOptions, req, res }) {
|
|
22
22
|
if (authJson.configured === true) {
|
|
23
|
-
return
|
|
23
|
+
return getNextAuthServerSession(req, res, authOptions);
|
|
24
24
|
}
|
|
25
25
|
return undefined;
|
|
26
26
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
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 pino from 'pino';
|
|
18
|
+
|
|
19
|
+
const logger = pino({
|
|
20
|
+
name: 'lowdefy_server',
|
|
21
|
+
level: process.env.LOWDEFY_LOG_LEVEL ?? 'info',
|
|
22
|
+
base: { pid: undefined, hostname: undefined },
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
function createLogger(metadata = {}) {
|
|
26
|
+
return logger.child(metadata);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export default createLogger;
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
function logError({ context, error }) {
|
|
18
|
+
try {
|
|
19
|
+
const { user = {} } = context;
|
|
20
|
+
|
|
21
|
+
context.logger.error({
|
|
22
|
+
err: error,
|
|
23
|
+
user: {
|
|
24
|
+
id: user.id,
|
|
25
|
+
roles: user.roles,
|
|
26
|
+
sub: user.sub,
|
|
27
|
+
session_id: user.session_id,
|
|
28
|
+
},
|
|
29
|
+
url: context.req.url,
|
|
30
|
+
method: context.req.method,
|
|
31
|
+
resolvedUrl: context.nextContext?.resolvedUrl,
|
|
32
|
+
});
|
|
33
|
+
} catch (e) {
|
|
34
|
+
console.error(error);
|
|
35
|
+
console.error('An error occurred while logging the error.');
|
|
36
|
+
console.error(e);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export default logError;
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
// TODO: Better name needed here maybe?
|
|
18
|
+
function logRequest({ context }) {
|
|
19
|
+
const { user = {} } = context;
|
|
20
|
+
context.logger.debug({
|
|
21
|
+
user: {
|
|
22
|
+
id: user.id,
|
|
23
|
+
roles: user.roles,
|
|
24
|
+
sub: user.sub,
|
|
25
|
+
session_id: user.session_id,
|
|
26
|
+
},
|
|
27
|
+
url: context.req.url,
|
|
28
|
+
method: context.req.method,
|
|
29
|
+
resolvedUrl: context.nextContext?.resolvedUrl,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default logRequest;
|
package/manager/getContext.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
Copyright 2020-
|
|
2
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
3
3
|
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
you may not use this file except in compliance with the License.
|
|
@@ -19,7 +19,8 @@ import createCustomPluginTypesMap from '../utils/createCustomPluginTypesMap.mjs'
|
|
|
19
19
|
|
|
20
20
|
function lowdefyBuild({ directories, logger, options }) {
|
|
21
21
|
return async () => {
|
|
22
|
-
|
|
22
|
+
logger.info({ print: 'spin' }, 'Building config...');
|
|
23
|
+
const customTypesMap = await createCustomPluginTypesMap({ directories, logger });
|
|
23
24
|
await build({
|
|
24
25
|
customTypesMap,
|
|
25
26
|
directories,
|
package/manager/run.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/*
|
|
3
|
-
Copyright 2020-
|
|
3
|
+
Copyright 2020-2023 Lowdefy, Inc
|
|
4
4
|
|
|
5
5
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
6
|
you may not use this file except in compliance with the License.
|
|
@@ -30,7 +30,7 @@ async function getPluginDefinitions({ directories }) {
|
|
|
30
30
|
return get(lowdefy, 'plugins', { default: [] });
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
async function createCustomPluginTypesMap({ directories }) {
|
|
33
|
+
async function createCustomPluginTypesMap({ directories, logger }) {
|
|
34
34
|
const customTypesMap = {
|
|
35
35
|
actions: {},
|
|
36
36
|
auth: {
|
|
@@ -56,7 +56,14 @@ async function createCustomPluginTypesMap({ directories }) {
|
|
|
56
56
|
const pluginDefinitions = await getPluginDefinitions({ directories });
|
|
57
57
|
|
|
58
58
|
for (const plugin of pluginDefinitions) {
|
|
59
|
-
|
|
59
|
+
let types;
|
|
60
|
+
try {
|
|
61
|
+
types = (await import(`${plugin.name}/types`)).default;
|
|
62
|
+
} catch (e) {
|
|
63
|
+
logger.error(`Failed to import plugin "${plugin.name}".`);
|
|
64
|
+
logger.info('If the plugin was added while the server was running, restart the server.');
|
|
65
|
+
throw new Error(`Failed to import plugin "${plugin.name}".`);
|
|
66
|
+
}
|
|
60
67
|
createPluginTypesMap({
|
|
61
68
|
packageTypes: types,
|
|
62
69
|
typesMap: customTypesMap,
|