@lowdefy/server 0.0.0-alpha.5 → 0.0.0-experimental-20251203202233

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 (51) hide show
  1. package/.eslintrc.yaml +1 -0
  2. package/.npmrc +1 -0
  3. package/LICENSE +201 -0
  4. package/README.md +0 -0
  5. package/lib/client/Page.js +54 -0
  6. package/lib/client/auth/Auth.js +36 -0
  7. package/lib/client/auth/AuthConfigured.js +62 -0
  8. package/lib/client/auth/AuthNotConfigured.js +34 -0
  9. package/lib/client/createLogUsage.js +58 -0
  10. package/lib/server/apiWrapper.js +70 -0
  11. package/lib/server/auth/getAuthOptions.js +35 -0
  12. package/lib/server/auth/getServerSession.js +28 -0
  13. package/lib/server/fileCache.js +21 -0
  14. package/{dist/createGetSecretsFromEnv.js → lib/server/log/createLogger.js} +14 -19
  15. package/lib/server/log/logError.js +72 -0
  16. package/lib/server/log/logRequest.js +66 -0
  17. package/lib/server/serverSidePropsWrapper.js +60 -0
  18. package/lowdefy/build.mjs +62 -0
  19. package/lowdefy/createCustomPluginTypesMap.mjs +72 -0
  20. package/next.config.js +29 -0
  21. package/package.json +56 -44
  22. package/package.original.json +85 -0
  23. package/pages/404.js +47 -0
  24. package/pages/[pageId].js +51 -0
  25. package/pages/_app.js +54 -0
  26. package/pages/_document.js +54 -0
  27. package/pages/api/auth/[...nextauth].js +37 -0
  28. package/pages/api/endpoints/[endpointId].js +32 -0
  29. package/pages/api/request/[pageId]/[requestId].js +32 -0
  30. package/pages/api/usage.js +68 -0
  31. package/pages/index.js +57 -0
  32. package/public_default/apple-touch-icon.png +0 -0
  33. package/public_default/favicon.ico +0 -0
  34. package/public_default/icon-512.png +0 -0
  35. package/public_default/icon.svg +17 -0
  36. package/public_default/logo-dark-theme.png +0 -0
  37. package/public_default/logo-light-theme.png +0 -0
  38. package/public_default/logo-square-dark-theme.png +0 -0
  39. package/public_default/logo-square-light-theme.png +0 -0
  40. package/public_default/manifest.webmanifest +16 -0
  41. package/dist/server.js +0 -55
  42. package/dist/shell/154.js +0 -2
  43. package/dist/shell/154.js.LICENSE.txt +0 -23
  44. package/dist/shell/425.js +0 -2
  45. package/dist/shell/425.js.LICENSE.txt +0 -43
  46. package/dist/shell/693.js +0 -2
  47. package/dist/shell/693.js.LICENSE.txt +0 -14
  48. package/dist/shell/77.js +0 -1
  49. package/dist/shell/901.js +0 -1
  50. package/dist/shell/index.html +0 -1
  51. package/dist/shell/main.js +0 -1
package/pages/_app.js ADDED
@@ -0,0 +1,54 @@
1
+ /*
2
+ Copyright 2020-2024 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, { useRef } from 'react';
18
+ import dynamic from 'next/dynamic';
19
+
20
+ import { ErrorBoundary } from '@lowdefy/block-utils';
21
+
22
+ import Auth from '../lib/client/auth/Auth.js';
23
+ import createLogUsage from '../lib/client/createLogUsage.js';
24
+
25
+ // Must be in _app due to next specifications.
26
+ import '../build/plugins/styles.less';
27
+
28
+ function App({ Component, pageProps: { session, rootConfig, pageConfig } }) {
29
+ const usageDataRef = useRef({});
30
+ const lowdefyRef = useRef({ eventCallback: createLogUsage({ usageDataRef }) });
31
+ return (
32
+ <ErrorBoundary fullPage>
33
+ <Auth session={session}>
34
+ {(auth) => {
35
+ usageDataRef.current.user = auth.session?.hashed_id;
36
+ return (
37
+ <Component
38
+ auth={auth}
39
+ lowdefy={lowdefyRef.current}
40
+ rootConfig={rootConfig}
41
+ pageConfig={pageConfig}
42
+ />
43
+ );
44
+ }}
45
+ </Auth>
46
+ </ErrorBoundary>
47
+ );
48
+ }
49
+
50
+ const DynamicApp = dynamic(() => Promise.resolve(App), {
51
+ ssr: false,
52
+ });
53
+
54
+ export default DynamicApp;
@@ -0,0 +1,54 @@
1
+ /*
2
+ Copyright 2020-2024 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
+ import appJson from '../build/app.json';
21
+ import lowdefyConfig from '../build/config.json';
22
+
23
+ const basePath = lowdefyConfig.basePath ?? '';
24
+
25
+ class LowdefyDocument extends Document {
26
+ render() {
27
+ return (
28
+ <Html>
29
+ <Head>
30
+ <link rel="manifest" href={`${basePath}/manifest.webmanifest`} />
31
+ <link rel="icon" type="image/svg+xml" href={`${basePath}/icon.svg`} />
32
+ <link rel="apple-touch-icon" href={`${basePath}/apple-touch-icon.png`} />
33
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
34
+ <script
35
+ dangerouslySetInnerHTML={{
36
+ __html: `/* start of Lowdefy append head */</script>${appJson.html.appendHead}<script>/* end of Lowdefy append head */`,
37
+ }}
38
+ />
39
+ </Head>
40
+ <body>
41
+ <Main />
42
+ <NextScript />
43
+ <script
44
+ dangerouslySetInnerHTML={{
45
+ __html: `/* start of Lowdefy append body */</script>${appJson.html.appendBody}<script>/* end of Lowdefy append body */`,
46
+ }}
47
+ />
48
+ </body>
49
+ </Html>
50
+ );
51
+ }
52
+ }
53
+
54
+ export default LowdefyDocument;
@@ -0,0 +1,37 @@
1
+ /*
2
+ Copyright 2020-2024 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
+
19
+ import apiWrapper from '../../../lib/server/apiWrapper.js';
20
+ import authJson from '../../../build/auth.json';
21
+
22
+ async function handler({ context, req, res }) {
23
+ if (authJson.configured !== true) {
24
+ return res.status(404).json({
25
+ message: 'Auth not configured',
26
+ });
27
+ }
28
+
29
+ // Required for emails in corporate networks, see:
30
+ // https://next-auth.js.org/tutorials/avoid-corporate-link-checking-email-provider
31
+ if (req.method === 'HEAD') {
32
+ return res.status(200).end();
33
+ }
34
+ return NextAuth(req, res, context.authOptions);
35
+ }
36
+
37
+ export default apiWrapper(handler);
@@ -0,0 +1,32 @@
1
+ /*
2
+ Copyright 2020-2024 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 { callEndpoint } from '@lowdefy/api';
18
+
19
+ import apiWrapper from '../../../lib/server/apiWrapper.js';
20
+
21
+ async function handler({ context, req, res }) {
22
+ if (req.method !== 'POST') {
23
+ throw new Error('Only POST requests are supported.');
24
+ }
25
+ const { endpointId } = req.query;
26
+ const { blockId, payload, pageId } = req.body;
27
+ context.logger.info({ event: 'call_api_endpoint', blockId, endpointId, pageId });
28
+ const response = await callEndpoint(context, { blockId, endpointId, pageId, payload });
29
+ res.status(200).json(response);
30
+ }
31
+
32
+ export default apiWrapper(handler);
@@ -0,0 +1,32 @@
1
+ /*
2
+ Copyright 2020-2024 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 } from '@lowdefy/api';
18
+
19
+ import apiWrapper from '../../../../lib/server/apiWrapper.js';
20
+
21
+ async function handler({ context, req, res }) {
22
+ if (req.method !== 'POST') {
23
+ throw new Error('Only POST requests are supported.');
24
+ }
25
+ const { pageId, requestId } = req.query;
26
+ const { blockId, payload } = req.body;
27
+ context.logger.info({ event: 'call_request', pageId, requestId, blockId });
28
+ const response = await callRequest(context, { blockId, pageId, payload, requestId });
29
+ res.status(200).json(response);
30
+ }
31
+
32
+ export default apiWrapper(handler);
@@ -0,0 +1,68 @@
1
+ /*
2
+ Copyright 2020-2024 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
18
+ // import crypto from 'crypto';
19
+
20
+ import appJson from '../../build/app.json';
21
+ import packageJson from '../../package.json';
22
+ import apiWrapper from '../../lib/server/apiWrapper.js';
23
+ // import validateLicense from '../../lib/server/validateLicense.js';
24
+
25
+ async function handler({ context, req, res }) {
26
+ if (req.method !== 'POST') {
27
+ throw new Error('Only POST requests are supported.');
28
+ }
29
+ const { user, machine } = req.body;
30
+ const host = req.headers.host;
31
+ context.logger.info({ event: 'log_usage', user, machine });
32
+
33
+ // const license = await validateLicense();
34
+ // if (license.entitlements.includes['OFFLINE']) {
35
+ // return res.status(200).json({ offline: true });
36
+ // }
37
+ const timestamp = Date.now();
38
+
39
+ // const data = [
40
+ // `git_sha: ${appJson.git_sha}`,
41
+ // `host: ${host}`,
42
+ // `license_key: ${license.id}`,
43
+ // `machine: ${machine}`,
44
+ // `timestamp: ${timestamp}`,
45
+ // `user: ${user}`,
46
+ // `version: ${packageJson.version}`,
47
+ // ].join('\n');
48
+
49
+ // const hmac = crypto.createHmac('sha256', process.env.LOWDEFY_LICENSE_KEY ?? 'NO_LICENSE');
50
+ // hmac.update(data);
51
+ // const sig = hmac.digest('base64');
52
+
53
+ return res.status(200).json({
54
+ offline: false,
55
+ data: {
56
+ git_sha: appJson.git_sha,
57
+ host,
58
+ // license_key: license.id,
59
+ machine,
60
+ // sig,
61
+ timestamp,
62
+ user,
63
+ version: packageJson.version,
64
+ },
65
+ });
66
+ }
67
+
68
+ export default apiWrapper(handler);
package/pages/index.js ADDED
@@ -0,0 +1,57 @@
1
+ /*
2
+ Copyright 2020-2024 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 { getPageConfig, getRootConfig } from '@lowdefy/api';
18
+
19
+ import serverSidePropsWrapper from '../lib/server/serverSidePropsWrapper.js';
20
+ import Page from '../lib/client/Page.js';
21
+
22
+ async function getServerSidePropsHandler({ context }) {
23
+ const rootConfig = await getRootConfig(context);
24
+ const { home } = rootConfig;
25
+ const { logger, session } = context;
26
+ if (home.configured === false) {
27
+ logger.info({ event: 'redirect_to_homepage', pageId: home.pageId });
28
+ return {
29
+ redirect: {
30
+ destination: `/${home.pageId}`,
31
+ permanent: false,
32
+ },
33
+ };
34
+ }
35
+ const pageConfig = await getPageConfig(context, { pageId: home.pageId });
36
+ if (!pageConfig) {
37
+ logger.info({ event: 'redirect_page_not_found', pageId: home.pageId });
38
+ return {
39
+ redirect: {
40
+ destination: '/404',
41
+ permanent: false,
42
+ },
43
+ };
44
+ }
45
+ logger.info({ event: 'page_view', pageId: home.pageId });
46
+ return {
47
+ props: {
48
+ pageConfig,
49
+ rootConfig,
50
+ session,
51
+ },
52
+ };
53
+ }
54
+
55
+ export const getServerSideProps = serverSidePropsWrapper(getServerSidePropsHandler);
56
+
57
+ export default Page;
Binary file
Binary file
@@ -0,0 +1,17 @@
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>
@@ -0,0 +1,16 @@
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
+ }
package/dist/server.js DELETED
@@ -1,55 +0,0 @@
1
- "use strict";
2
-
3
- var _path = _interopRequireDefault(require("path"));
4
-
5
- var _express = _interopRequireDefault(require("express"));
6
-
7
- var _apolloServerExpress = require("apollo-server-express");
8
-
9
- var _graphql = require("@lowdefy/graphql");
10
-
11
- var _createGetSecretsFromEnv = _interopRequireDefault(require("./createGetSecretsFromEnv"));
12
-
13
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
-
15
- /*
16
- Copyright 2020 Lowdefy, Inc
17
-
18
- Licensed under the Apache License, Version 2.0 (the "License");
19
- you may not use this file except in compliance with the License.
20
- You may obtain a copy of the License at
21
-
22
- http://www.apache.org/licenses/LICENSE-2.0
23
-
24
- Unless required by applicable law or agreed to in writing, software
25
- distributed under the License is distributed on an "AS IS" BASIS,
26
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27
- See the License for the specific language governing permissions and
28
- limitations under the License.
29
- */
30
- var config = {
31
- CONFIGURATION_BASE_PATH: _path.default.resolve(process.cwd(), './.lowdefy/build'),
32
- logger: console,
33
- getSecrets: (0, _createGetSecretsFromEnv.default)()
34
- };
35
- var context = (0, _graphql.createContext)(config);
36
- var server = new _apolloServerExpress.ApolloServer({
37
- typeDefs: _graphql.typeDefs,
38
- resolvers: _graphql.resolvers,
39
- context
40
- });
41
- var app = (0, _express.default)();
42
- server.applyMiddleware({
43
- app,
44
- path: '/api/graphql'
45
- }); // Serve Webpack shell files from './shell/dist'
46
-
47
- app.use(_express.default.static('dist/shell')); // Redirect all 404 to index.html with status 200
48
- // This should always be the last route
49
-
50
- app.use((req, res) => {
51
- res.sendFile(_path.default.resolve(process.cwd(), 'dist/shell/index.html'));
52
- });
53
- app.listen({
54
- port: 3000
55
- }, () => console.log("\uD83D\uDE80 Server ready at http://localhost:3000"));