@lowdefy/server 0.0.0-experimental-20260720072521 → 0.0.0-experimental-20260721080548

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 (63) hide show
  1. package/.eslintrc.yaml +1 -0
  2. package/lib/build/app.js +1 -8
  3. package/lib/build/appMeta.js +1 -8
  4. package/lib/build/auth.js +1 -8
  5. package/lib/build/config.js +1 -8
  6. package/lib/build/i18n.js +1 -8
  7. package/lib/build/logger.js +1 -8
  8. package/lib/build/theme.js +1 -8
  9. package/lib/client/Page.js +56 -0
  10. package/lib/client/auth/{Auth.jsx → Auth.js} +6 -12
  11. package/lib/client/auth/AuthConfigured.js +62 -0
  12. package/lib/client/auth/AuthNotConfigured.js +3 -22
  13. package/lib/client/sentry/captureSentryError.js +1 -1
  14. package/lib/client/sentry/initSentryClient.js +1 -1
  15. package/lib/client/sentry/setSentryUser.js +1 -1
  16. package/lib/server/apiWrapper.js +94 -0
  17. package/lib/server/auth/{getAuth.js → getAuthOptions.js} +7 -16
  18. package/{src/lib/getPathSegments.js → lib/server/auth/getServerSession.js} +10 -7
  19. package/lib/server/log/createHandleError.js +1 -1
  20. package/lib/server/log/createLogger.js +1 -18
  21. package/lib/server/log/logRequest.js +46 -41
  22. package/lib/server/sentry/captureSentryError.js +1 -1
  23. package/lib/server/sentry/initSentry.js +4 -6
  24. package/lib/server/sentry/setSentryUser.js +1 -1
  25. package/lib/server/serverSidePropsWrapper.js +66 -0
  26. package/lowdefy/createCustomPluginTypesMap.mjs +2 -3
  27. package/next.config.js +34 -0
  28. package/package.json +39 -52
  29. package/package.original.json +41 -54
  30. package/pages/404.js +49 -0
  31. package/pages/[[...pageId]].js +85 -0
  32. package/{client/App.jsx → pages/_app.js} +37 -29
  33. package/pages/_document.js +106 -0
  34. package/{src/routes/agent.js → pages/api/agent/[...path].js} +42 -20
  35. package/pages/api/auth/[...nextauth].js +37 -0
  36. package/{src/routes/clientError.js → pages/api/client-error.js} +16 -14
  37. package/pages/api/endpoints/[...endpointId].js +32 -0
  38. package/{src/routes/request.js → pages/api/request/[...path].js} +10 -10
  39. package/pages/api/usage.js +67 -0
  40. package/client/Page.jsx +0 -103
  41. package/client/main.jsx +0 -39
  42. package/lib/client/auth/AuthConfigured.jsx +0 -155
  43. package/lib/server/auth/createSystemContext.js +0 -67
  44. package/lib/server/auth/getStrategies.js +0 -40
  45. package/src/app.js +0 -132
  46. package/src/html/getAssets.js +0 -45
  47. package/src/html/renderPage.js +0 -96
  48. package/src/html/template.js +0 -94
  49. package/src/index.js +0 -79
  50. package/src/lib/safeScriptJson.js +0 -38
  51. package/src/middleware/apiContext.js +0 -144
  52. package/src/middleware/errorHandler.js +0 -60
  53. package/src/middleware/sentry.js +0 -33
  54. package/src/routes/apiPage.js +0 -55
  55. package/src/routes/auth.js +0 -37
  56. package/src/routes/cron.js +0 -43
  57. package/src/routes/detached.js +0 -51
  58. package/src/routes/endpoints.js +0 -76
  59. package/src/routes/usage.js +0 -46
  60. package/src/routes/user.js +0 -27
  61. package/src/routes/websocket.js +0 -46
  62. package/vite.config.js +0 -61
  63. /package/{postcss.config.cjs → postcss.config.js} +0 -0
package/.eslintrc.yaml ADDED
@@ -0,0 +1 @@
1
+ extends: 'plugin:@next/next/core-web-vitals'
package/lib/build/app.js CHANGED
@@ -13,14 +13,7 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */
16
-
17
- // Build artifacts are read from disk because the Hono server runs as
18
- // unbundled Node.js ESM — JSON imports would need import attributes, and
19
- // client code imports the build JSON directly through Vite instead.
20
- import fs from 'node:fs';
21
- import path from 'node:path';
22
16
  import { serializer } from '@lowdefy/helpers';
23
-
24
- const raw = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'build/app.json'), 'utf8'));
17
+ import raw from '../../build/app.json';
25
18
 
26
19
  export default serializer.deserialize(raw);
@@ -13,14 +13,7 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */
16
-
17
- // Build artifacts are read from disk because the Hono server runs as
18
- // unbundled Node.js ESM — JSON imports would need import attributes, and
19
- // client code imports the build JSON directly through Vite instead.
20
- import fs from 'node:fs';
21
- import path from 'node:path';
22
16
  import { serializer } from '@lowdefy/helpers';
23
-
24
- const raw = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'build/appMeta.json'), 'utf8'));
17
+ import raw from '../../build/appMeta.json';
25
18
 
26
19
  export default serializer.deserialize(raw);
package/lib/build/auth.js CHANGED
@@ -13,14 +13,7 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */
16
-
17
- // Build artifacts are read from disk because the Hono server runs as
18
- // unbundled Node.js ESM — JSON imports would need import attributes, and
19
- // client code imports the build JSON directly through Vite instead.
20
- import fs from 'node:fs';
21
- import path from 'node:path';
22
16
  import { serializer } from '@lowdefy/helpers';
23
-
24
- const raw = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'build/auth.json'), 'utf8'));
17
+ import raw from '../../build/auth.json';
25
18
 
26
19
  export default serializer.deserialize(raw);
@@ -13,14 +13,7 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */
16
-
17
- // Build artifacts are read from disk because the Hono server runs as
18
- // unbundled Node.js ESM — JSON imports would need import attributes, and
19
- // client code imports the build JSON directly through Vite instead.
20
- import fs from 'node:fs';
21
- import path from 'node:path';
22
16
  import { serializer } from '@lowdefy/helpers';
23
-
24
- const raw = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'build/config.json'), 'utf8'));
17
+ import raw from '../../build/config.json';
25
18
 
26
19
  export default serializer.deserialize(raw);
package/lib/build/i18n.js CHANGED
@@ -13,14 +13,7 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */
16
-
17
- // Build artifacts are read from disk because the Hono server runs as
18
- // unbundled Node.js ESM — JSON imports would need import attributes, and
19
- // client code imports the build JSON directly through Vite instead.
20
- import fs from 'node:fs';
21
- import path from 'node:path';
22
16
  import { serializer } from '@lowdefy/helpers';
23
-
24
- const raw = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'build/i18n.json'), 'utf8'));
17
+ import raw from '../../build/i18n.json';
25
18
 
26
19
  export default serializer.deserialize(raw);
@@ -13,14 +13,7 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */
16
-
17
- // Build artifacts are read from disk because the Hono server runs as
18
- // unbundled Node.js ESM — JSON imports would need import attributes, and
19
- // client code imports the build JSON directly through Vite instead.
20
- import fs from 'node:fs';
21
- import path from 'node:path';
22
16
  import { serializer } from '@lowdefy/helpers';
23
-
24
- const raw = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'build/logger.json'), 'utf8'));
17
+ import raw from '../../build/logger.json';
25
18
 
26
19
  export default serializer.deserialize(raw);
@@ -13,14 +13,7 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */
16
-
17
- // Build artifacts are read from disk because the Hono server runs as
18
- // unbundled Node.js ESM — JSON imports would need import attributes, and
19
- // client code imports the build JSON directly through Vite instead.
20
- import fs from 'node:fs';
21
- import path from 'node:path';
22
16
  import { serializer } from '@lowdefy/helpers';
23
-
24
- const raw = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'build/theme.json'), 'utf8'));
17
+ import raw from '../../build/theme.json';
25
18
 
26
19
  export default serializer.deserialize(raw);
@@ -0,0 +1,56 @@
1
+ /*
2
+ Copyright 2020-2026 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 blockMetas from '../../build/plugins/blockMetas.json';
26
+ import blocks from '../../build/plugins/blocks.js';
27
+ import icons from '../../build/plugins/icons.js';
28
+ import operators from '../../build/plugins/operators/client.js';
29
+ import jsMap from '../../build/plugins/operators/clientJsMap.js';
30
+
31
+ const Page = ({ auth, lowdefy, pageConfig, rootConfig }) => {
32
+ const router = useRouter();
33
+ return (
34
+ <Client
35
+ auth={auth}
36
+ Components={{ Head, Link }}
37
+ config={{
38
+ pageConfig,
39
+ rootConfig,
40
+ }}
41
+ jsMap={jsMap}
42
+ lowdefy={lowdefy}
43
+ router={router}
44
+ types={{
45
+ actions,
46
+ blockMetas,
47
+ blocks,
48
+ icons,
49
+ operators,
50
+ }}
51
+ window={window}
52
+ />
53
+ );
54
+ };
55
+
56
+ export default Page;
@@ -14,24 +14,18 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
+ /* eslint-disable react/jsx-props-no-spreading */
18
+
17
19
  import React from 'react';
18
- import AuthConfigured from './AuthConfigured.jsx';
20
+ import AuthConfigured from './AuthConfigured.js';
19
21
  import AuthNotConfigured from './AuthNotConfigured.js';
20
22
 
21
- import { serializer } from '@lowdefy/helpers';
22
-
23
- // Client code imports the build JSON directly — Vite handles JSON imports;
24
- // the lib/build/*.js wrappers are server-only (they read from disk).
25
- // Deserialize to restore arrays from their ~arr build markers (providers
26
- // must be a real array for provider lookups in createAuthMethods).
27
- import rawAuthConfig from '../../../build/auth.json';
28
-
29
- const authConfig = serializer.deserialize(rawAuthConfig);
23
+ import authConfig from '../../build/auth.js';
30
24
 
31
- function Auth({ children, user }) {
25
+ function Auth({ children, session }) {
32
26
  if (authConfig.configured === true) {
33
27
  return (
34
- <AuthConfigured serverUser={user} authConfig={authConfig}>
28
+ <AuthConfigured serverSession={session} authConfig={authConfig}>
35
29
  {(auth) => children(auth)}
36
30
  </AuthConfigured>
37
31
  );
@@ -0,0 +1,62 @@
1
+ /*
2
+ Copyright 2020-2026 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
+ /* eslint-disable react/jsx-props-no-spreading */
18
+
19
+ import React, { useEffect, useRef } from 'react';
20
+ import { getSession, SessionProvider, signIn, signOut, useSession } from 'next-auth/react';
21
+
22
+ import lowdefyConfig from '../../build/config.js';
23
+
24
+ function Session({ children }) {
25
+ const wasAuthenticated = useRef(false);
26
+ const { data: session, status } = useSession();
27
+ wasAuthenticated.current = wasAuthenticated.current || status === 'authenticated';
28
+
29
+ useEffect(() => {
30
+ if (wasAuthenticated.current && status === 'unauthenticated') {
31
+ window.location.reload();
32
+ }
33
+ }, [status]);
34
+
35
+ // If session is passed to SessionProvider from getServerSideProps
36
+ // we won't have a loading state here.
37
+ // But 404 uses getStaticProps so we have this for 404.
38
+ if (status === 'loading') {
39
+ return '';
40
+ }
41
+ return children(session);
42
+ }
43
+
44
+ function AuthConfigured({ authConfig, children, serverSession }) {
45
+ const auth = { authConfig, getSession, signIn, signOut };
46
+ let basePath = lowdefyConfig.basePath;
47
+ if (basePath) {
48
+ basePath = `${basePath}/api/auth`;
49
+ }
50
+ return (
51
+ <SessionProvider session={serverSession} basePath={basePath}>
52
+ <Session>
53
+ {(session) => {
54
+ auth.session = session;
55
+ return children(auth);
56
+ }}
57
+ </Session>
58
+ </SessionProvider>
59
+ );
60
+ }
61
+
62
+ export default AuthConfigured;
@@ -14,6 +14,8 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
+ /* eslint-disable react/jsx-props-no-spreading */
18
+
17
19
  function authNotConfigured() {
18
20
  throw new Error('Auth not configured.');
19
21
  }
@@ -21,30 +23,9 @@ function authNotConfigured() {
21
23
  function AuthNotConfigured({ authConfig, children }) {
22
24
  const auth = {
23
25
  authConfig,
24
- user: null,
25
- acceptInvitation: authNotConfigured,
26
- addPasskey: authNotConfigured,
27
- changePassword: authNotConfigured,
28
- deletePasskey: authNotConfigured,
29
- getResolvedUser: authNotConfigured,
30
26
  getSession: authNotConfigured,
31
- impersonateUser: authNotConfigured,
32
- requestPasswordReset: authNotConfigured,
33
- resetPassword: authNotConfigured,
34
- revokeOtherSessions: authNotConfigured,
35
- sendVerificationEmail: authNotConfigured,
36
- setActiveOrganization: authNotConfigured,
37
- signInEmail: authNotConfigured,
38
- signInMagicLink: authNotConfigured,
39
- signInOauth2: authNotConfigured,
40
- signInSocial: authNotConfigured,
27
+ signIn: authNotConfigured,
41
28
  signOut: authNotConfigured,
42
- signUpEmail: authNotConfigured,
43
- stopImpersonating: authNotConfigured,
44
- twoFactorDisable: authNotConfigured,
45
- twoFactorEnable: authNotConfigured,
46
- twoFactorVerifyBackupCode: authNotConfigured,
47
- twoFactorVerifyTotp: authNotConfigured,
48
29
  };
49
30
 
50
31
  return children(auth);
@@ -14,7 +14,7 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
- import * as Sentry from '@sentry/browser';
17
+ import * as Sentry from '@sentry/nextjs';
18
18
 
19
19
  function captureSentryError({ error, pageId, blockId, configLocation }) {
20
20
  const tags = {};
@@ -14,7 +14,7 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
- import * as Sentry from '@sentry/browser';
17
+ import * as Sentry from '@sentry/nextjs';
18
18
 
19
19
  let initialized = false;
20
20
 
@@ -14,7 +14,7 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
- import * as Sentry from '@sentry/browser';
17
+ import * as Sentry from '@sentry/nextjs';
18
18
 
19
19
  function setSentryUser({ user, sentryConfig }) {
20
20
  // No-op if no user
@@ -0,0 +1,94 @@
1
+ /*
2
+ Copyright 2020-2026 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 } from '@lowdefy/api';
19
+ import { getSecretsFromEnv } from '@lowdefy/node-utils';
20
+ import { serializer } from '@lowdefy/helpers';
21
+ import { v4 as uuid } from 'uuid';
22
+
23
+ import agents from '../../build/plugins/agents.js';
24
+ import appMeta from '../build/appMeta.js';
25
+ import config from '../build/config.js';
26
+ import i18nConfig from '../build/i18n.js';
27
+ import connections from '../../build/plugins/connections.js';
28
+ import createLogger from './log/createLogger.js';
29
+ import fileCache from './fileCache.js';
30
+ import getServerSession from './auth/getServerSession.js';
31
+ import createHandleError from './log/createHandleError.js';
32
+ import logRequest from './log/logRequest.js';
33
+ import operators from '../../build/plugins/operators/server.js';
34
+ import jsMap from '../../build/plugins/operators/serverJsMap.js';
35
+ import getAuthOptions from './auth/getAuthOptions.js';
36
+ import loggerConfig from '../build/logger.js';
37
+ import setSentryUser from './sentry/setSentryUser.js';
38
+
39
+ const secrets = getSecretsFromEnv();
40
+
41
+ function apiWrapper(handler) {
42
+ return async function wrappedHandler(req, res) {
43
+ const context = {
44
+ // Important to give absolute path so Next can trace build files
45
+ rid: uuid(),
46
+ agents,
47
+ appMeta,
48
+ buildDirectory: path.join(process.cwd(), 'build'),
49
+ config,
50
+ connections,
51
+ fileCache,
52
+ headers: req?.headers,
53
+ i18n: i18nConfig,
54
+ jsMap,
55
+ handleError: async (err) => {
56
+ console.error(err);
57
+ },
58
+ logger: console,
59
+ operators,
60
+ req,
61
+ res,
62
+ secrets,
63
+ };
64
+ try {
65
+ context.logger = createLogger({ rid: context.rid });
66
+ context.handleError = createHandleError({ context });
67
+ context.authOptions = getAuthOptions(context);
68
+ if (!req.url.startsWith('/api/auth')) {
69
+ context.session = await getServerSession(context);
70
+ // Set Sentry user context for authenticated requests
71
+ setSentryUser({
72
+ user: context.session?.user,
73
+ sentryConfig: loggerConfig.sentry,
74
+ });
75
+ }
76
+ createApiContext(context);
77
+ logRequest({ context });
78
+ // Await here so that if handler throws it is caught.
79
+ const response = await handler({ context, req, res });
80
+ return response;
81
+ } catch (error) {
82
+ await context.handleError(error);
83
+ const serialized = serializer.serialize(error);
84
+ if (serialized?.['~e']) {
85
+ delete serialized['~e'].received;
86
+ delete serialized['~e'].stack;
87
+ delete serialized['~e'].configKey;
88
+ }
89
+ res.status(500).json(serialized);
90
+ }
91
+ };
92
+ }
93
+
94
+ export default apiWrapper;
@@ -14,32 +14,23 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
- import { getBetterAuth } from '@lowdefy/api';
17
+ import { getNextAuthConfig } from '@lowdefy/api';
18
18
  import { getSecretsFromEnv } from '@lowdefy/node-utils';
19
19
 
20
20
  import adapters from '../../../build/plugins/auth/adapters.js';
21
- import appMeta from '../../build/appMeta.js';
22
21
  import authJson from '../../build/auth.js';
23
- import createSystemContext from './createSystemContext.js';
24
- import lowdefyConfig from '../../build/config.js';
22
+ import callbacks from '../../../build/plugins/auth/callbacks.js';
23
+ import events from '../../../build/plugins/auth/events.js';
25
24
  import providers from '../../../build/plugins/auth/providers.js';
26
25
 
27
- // Returns the BetterAuth instance (memoized in @lowdefy/api), or null when
28
- // auth is not configured - it handles /api/auth/* and resolves the session
29
- // for every request.
30
- function getAuth({ logger }) {
31
- if (authJson.configured !== true) {
32
- return null;
33
- }
34
- return getBetterAuth({
26
+ function getAuthOptions({ appMeta, logger }) {
27
+ return getNextAuthConfig({
35
28
  appMeta,
36
29
  authJson,
37
- config: lowdefyConfig,
38
- createSystemContext,
39
30
  logger,
40
- plugins: { adapters, providers },
31
+ plugins: { adapters, callbacks, events, providers },
41
32
  secrets: getSecretsFromEnv(),
42
33
  });
43
34
  }
44
35
 
45
- export default getAuth;
36
+ export default getAuthOptions;
@@ -14,12 +14,15 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
- // Splits the rest of a catch-all route into decoded segments, independent of
18
- // any configured basePath. Mirrors the Next.js [...param] query arrays —
19
- // nested ids (slashes in pageId or endpointId) are real.
20
- function getPathSegments(c, prefix) {
21
- const rest = c.req.path.split(prefix)[1] ?? '';
22
- return rest.split('/').filter(Boolean).map(decodeURIComponent);
17
+ import { getServerSession as getNextAuthServerSession } from 'next-auth/next';
18
+
19
+ import authJson from '../../build/auth.js';
20
+
21
+ function getServerSession({ authOptions, req, res }) {
22
+ if (authJson.configured === true) {
23
+ return getNextAuthServerSession(req, res, authOptions);
24
+ }
25
+ return undefined;
23
26
  }
24
27
 
25
- export default getPathSegments;
28
+ export default getServerSession;
@@ -114,7 +114,7 @@ function createHandleError({ context }) {
114
114
  host: headers.host,
115
115
  referer: headers.referer,
116
116
  // Non localhost headers
117
- 'x-forwarded-for': headers['x-forwarded-for'],
117
+ 'x-forward-for': headers['x-forward-for'],
118
118
  // Vercel headers
119
119
  'x-vercel-id': headers['x-vercel-id'],
120
120
  'x-real-ip': headers['x-real-ip'],
@@ -15,27 +15,10 @@
15
15
  */
16
16
 
17
17
  import { createNodeLogger } from '@lowdefy/logger/node';
18
- import { type } from '@lowdefy/helpers';
19
-
20
- import appMeta from '../../build/appMeta.js';
21
-
22
- // Deploy identity on every log line — pid/hostname are stripped, so these
23
- // fields are what correlates a line to an app build across replicas.
24
- const base = { pid: undefined, hostname: undefined };
25
- if (!type.isNone(appMeta.name)) {
26
- base.app_name = appMeta.name;
27
- }
28
- if (!type.isNone(appMeta.version)) {
29
- base.app_version = appMeta.version;
30
- }
31
- if (!type.isNone(appMeta.gitSha)) {
32
- base.git_sha = appMeta.gitSha;
33
- }
34
-
35
18
  const logger = createNodeLogger({
36
19
  name: 'lowdefy_server',
37
20
  level: process.env.LOWDEFY_LOG_LEVEL ?? 'info',
38
- base,
21
+ base: { pid: undefined, hostname: undefined },
39
22
  });
40
23
 
41
24
  function createLogger(metadata = {}) {
@@ -14,48 +14,53 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
- // Emits one access-log line per request, after the response is finalized.
18
- function logRequest({ context, status, durationMs }) {
19
- const { headers = {} } = context;
20
- const user = context.user ?? {};
21
- context.logger.info(
22
- {
23
- user: {
24
- id: user.id,
25
- roles: user.roles,
26
- },
27
- url: context.req.url,
28
- method: context.req.method,
29
- hostname: context.req.hostname,
30
- status,
31
- duration_ms: durationMs,
32
- headers: {
33
- 'accept-language': headers['accept-language'],
34
- 'sec-ch-ua-mobile': headers['sec-ch-ua-mobile'],
35
- 'sec-ch-ua-platform': headers['sec-ch-ua-platform'],
36
- 'sec-ch-ua': headers['sec-ch-ua'],
37
- 'user-agent': headers['user-agent'],
38
- host: headers.host,
39
- referer: headers.referer,
40
- 'x-forwarded-for': headers['x-forwarded-for'],
41
- // Vercel headers
42
- 'x-vercel-id': headers['x-vercel-id'],
43
- 'x-real-ip': headers['x-real-ip'],
44
- 'x-vercel-ip-country': headers['x-vercel-ip-country'],
45
- 'x-vercel-ip-country-region': headers['x-vercel-ip-country-region'],
46
- 'x-vercel-ip-city': headers['x-vercel-ip-city'],
47
- 'x-vercel-ip-latitude': headers['x-vercel-ip-latitude'],
48
- 'x-vercel-ip-longitude': headers['x-vercel-ip-longitude'],
49
- 'x-vercel-ip-timezone': headers['x-vercel-ip-timezone'],
50
- // Cloudflare headers
51
- 'cf-connecting-ip': headers['cf-connecting-ip'],
52
- 'cf-ray': headers['cf-ray'],
53
- 'cf-ipcountry': headers['cf-ipcountry'],
54
- 'cf-visitor': headers['cf-visitor'],
55
- },
17
+ // TODO: Better name needed here maybe?
18
+ function logRequest({ context }) {
19
+ const { headers = {}, user = {} } = context;
20
+ context.logger.info({
21
+ // TODO:
22
+ // app_name
23
+ // app_version
24
+ // lowdefy_version
25
+ // build_hash
26
+ // config_hash
27
+ user: {
28
+ id: user.id,
29
+ roles: user.roles,
30
+ sub: user.sub,
31
+ session_id: user.session_id, // TODO: Implement session id
56
32
  },
57
- 'request completed'
58
- );
33
+ url: context.req.url,
34
+ method: context.req.method,
35
+ resolvedUrl: context.nextContext?.resolvedUrl,
36
+ hostname: context.req.hostname,
37
+ headers: {
38
+ 'accept-language': headers['accept-language'],
39
+ 'sec-ch-ua-mobile': headers['sec-ch-ua-mobile'],
40
+ 'sec-ch-ua-platform': headers['sec-ch-ua-platform'],
41
+ 'sec-ch-ua': headers['sec-ch-ua'],
42
+ 'user-agent': headers['user-agent'],
43
+ host: headers.host,
44
+ referer: headers.referer,
45
+ 'x-forward-for': headers['x-forward-for'],
46
+ // Vercel headers
47
+ 'x-vercel-id': headers['x-vercel-id'],
48
+ 'x-real-ip': headers['x-real-ip'],
49
+ 'x-vercel-ip-country': headers['x-vercel-ip-country'],
50
+ 'x-vercel-ip-country-region': headers['x-vercel-ip-country-region'],
51
+ 'x-vercel-ip-city': headers['x-vercel-ip-city'],
52
+ 'x-vercel-ip-latitude': headers['x-vercel-ip-latitude'],
53
+ 'x-vercel-ip-longitude': headers['x-vercel-ip-longitude'],
54
+ 'x-vercel-ip-timezone': headers['x-vercel-ip-timezone'],
55
+ // Cloudflare headers
56
+ 'cf-connecting-ip': headers['cf-connecting-ip'],
57
+ 'cf-ray': headers['cf-ray'],
58
+ 'cf-ipcountry': headers['cf-ipcountry'],
59
+ 'cf-visitor': headers['cf-visitor'],
60
+ },
61
+ });
62
+ // TODO:
63
+ // Next local? nextContext.locale, nextContext.locales, nextContext.defaultLocale
59
64
  }
60
65
 
61
66
  export default logRequest;
@@ -14,7 +14,7 @@
14
14
  limitations under the License.
15
15
  */
16
16
 
17
- import * as Sentry from '@sentry/node';
17
+ import * as Sentry from '@sentry/nextjs';
18
18
 
19
19
  function captureSentryError({ error, context, configLocation }) {
20
20
  // No-op if Sentry not initialized (DSN not set)