@batijs/cli 0.0.244 → 0.0.245

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 (47) hide show
  1. package/dist/boilerplates/@batijs/authjs/files/$package.json.js +92 -0
  2. package/dist/boilerplates/@batijs/authjs/files/server/authjs-handler.ts +14 -13
  3. package/dist/boilerplates/@batijs/authjs/types/server/authjs-handler.d.ts +4 -2
  4. package/dist/boilerplates/@batijs/cloudflare/files/$package.json.js +2 -2
  5. package/dist/boilerplates/@batijs/compiled/files/$package.json.js +1 -1
  6. package/dist/boilerplates/@batijs/eslint/files/$package.json.js +2 -2
  7. package/dist/boilerplates/@batijs/express/files/$package.json.js +3 -4
  8. package/dist/boilerplates/@batijs/express/files/express-entry.ts +20 -18
  9. package/dist/boilerplates/@batijs/fastify/files/$package.json.js +5 -6
  10. package/dist/boilerplates/@batijs/fastify/files/fastify-entry.ts +22 -54
  11. package/dist/boilerplates/@batijs/fastify/types/fastify-entry.d.ts +0 -4
  12. package/dist/boilerplates/@batijs/firebase-auth/files/$package.json.js +5 -4
  13. package/dist/boilerplates/@batijs/firebase-auth/files/server/firebase-auth-middleware.ts +16 -18
  14. package/dist/boilerplates/@batijs/firebase-auth/types/server/firebase-auth-middleware.d.ts +8 -3
  15. package/dist/boilerplates/@batijs/h3/files/$package.json.js +4 -2
  16. package/dist/boilerplates/@batijs/h3/files/h3-entry.ts +22 -33
  17. package/dist/boilerplates/@batijs/h3/types/h3-entry.d.ts +0 -4
  18. package/dist/boilerplates/@batijs/hattip/files/$package.json.js +4 -3
  19. package/dist/boilerplates/@batijs/hattip/files/hattip-entry.ts +22 -33
  20. package/dist/boilerplates/@batijs/hono/files/$package.json.js +6 -15
  21. package/dist/boilerplates/@batijs/hono/files/hono-entry.ts +19 -17
  22. package/dist/boilerplates/@batijs/lucia-auth/files/$package.json.js +4 -2
  23. package/dist/boilerplates/@batijs/lucia-auth/files/server/lucia-auth-handlers.ts +41 -45
  24. package/dist/boilerplates/@batijs/lucia-auth/types/server/lucia-auth-handlers.d.ts +22 -10
  25. package/dist/boilerplates/@batijs/react/files/$package.json.js +4 -4
  26. package/dist/boilerplates/@batijs/shared/files/package.json +2 -2
  27. package/dist/boilerplates/@batijs/shared-server/files/$package.json.js +103 -0
  28. package/dist/boilerplates/@batijs/shared-server/files/server/create-todo-handler.ts +3 -5
  29. package/dist/boilerplates/@batijs/shared-server/files/server/vike-handler.ts +3 -5
  30. package/dist/boilerplates/@batijs/shared-server/types/server/create-todo-handler.d.ts +2 -1
  31. package/dist/boilerplates/@batijs/shared-server/types/server/vike-handler.d.ts +2 -1
  32. package/dist/boilerplates/@batijs/solid/files/$package.json.js +5 -5
  33. package/dist/boilerplates/@batijs/tailwindcss/files/$package.json.js +3 -3
  34. package/dist/boilerplates/@batijs/telefunc/files/$package.json.js +4 -3
  35. package/dist/boilerplates/@batijs/telefunc/files/server/telefunc-handler.ts +3 -5
  36. package/dist/boilerplates/@batijs/telefunc/types/server/telefunc-handler.d.ts +2 -1
  37. package/dist/boilerplates/@batijs/trpc/files/$package.json.js +1 -1
  38. package/dist/boilerplates/@batijs/ts-rest/files/$package.json.js +4 -3
  39. package/dist/boilerplates/@batijs/ts-rest/files/server/ts-rest-handler.ts +3 -6
  40. package/dist/boilerplates/@batijs/ts-rest/types/server/ts-rest-handler.d.ts +2 -1
  41. package/dist/boilerplates/@batijs/vercel/files/$package.json.js +2 -2
  42. package/dist/boilerplates/@batijs/vue/files/$package.json.js +7 -7
  43. package/dist/boilerplates/@batijs/vue/types/pages/+config.d.ts +6 -0
  44. package/dist/{chunk-MFJ4ET44.js → chunk-FWD3UPBV.js} +5 -5
  45. package/dist/index.js +14 -14
  46. package/dist/{prompt-SUR66HP4.js → prompt-EYFUFJSI.js} +4 -4
  47. package/package.json +8 -8
@@ -0,0 +1,92 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __commonJS = (cb, mod) => function __require() {
8
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
19
+ // If the importer is in node compatibility mode or this is not an ESM
20
+ // file that has been converted to a CommonJS file using a Babel-
21
+ // compatible transform (i.e. "__esModule" has not been set), then set
22
+ // "default" to the CommonJS "module.exports" for node compatibility.
23
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
24
+ mod
25
+ ));
26
+
27
+ // package.json
28
+ var require_package = __commonJS({
29
+ "package.json"(exports, module) {
30
+ module.exports = {
31
+ name: "@batijs/authjs",
32
+ private: true,
33
+ version: "0.0.1",
34
+ description: "",
35
+ type: "module",
36
+ scripts: {
37
+ "check-types": "tsc --noEmit",
38
+ build: "bati-compile-boilerplate"
39
+ },
40
+ keywords: [],
41
+ author: "",
42
+ license: "MIT",
43
+ devDependencies: {
44
+ "@auth/core": "^0.34.2",
45
+ "@universal-middleware/core": "^0.2.3",
46
+ "@batijs/compile": "workspace:*",
47
+ "@types/node": "^18.19.14",
48
+ dotenv: "^16.4.5"
49
+ },
50
+ dependencies: {
51
+ "@batijs/core": "workspace:*"
52
+ },
53
+ files: [
54
+ "dist/"
55
+ ],
56
+ bati: {
57
+ if: {
58
+ flag: {
59
+ $in: [
60
+ "authjs",
61
+ "auth0"
62
+ ]
63
+ }
64
+ }
65
+ },
66
+ exports: {
67
+ "./server/authjs-handler": {
68
+ types: "./dist/types/server/authjs-handler.d.ts"
69
+ }
70
+ },
71
+ typesVersions: {
72
+ "*": {
73
+ "server/authjs-handler": [
74
+ "./dist/types/server/authjs-handler.d.ts"
75
+ ]
76
+ }
77
+ }
78
+ };
79
+ }
80
+ });
81
+
82
+ // files/$package.json.ts
83
+ import { addDependency, loadAsJson } from "@batijs/core";
84
+ async function getPackageJson(props) {
85
+ const packageJson = await loadAsJson(props);
86
+ return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)).then((x) => x.default), {
87
+ dependencies: ["@auth/core", "@universal-middleware/core", "dotenv"]
88
+ });
89
+ }
90
+ export {
91
+ getPackageJson as default
92
+ };
@@ -1,7 +1,8 @@
1
- import { Auth, createActionURL, setEnvDefaults, type AuthConfig } from "@auth/core";
1
+ import { Auth, type AuthConfig, createActionURL, setEnvDefaults } from "@auth/core";
2
2
  import Auth0 from "@auth/core/providers/auth0";
3
3
  import CredentialsProvider from "@auth/core/providers/credentials";
4
4
  import type { Session } from "@auth/core/types";
5
+ import type { Get, UniversalHandler, UniversalMiddleware } from "@universal-middleware/core";
5
6
 
6
7
  const env: Record<string, string | undefined> =
7
8
  typeof process?.env !== "undefined"
@@ -76,25 +77,25 @@ export async function getSession(req: Request, config: Omit<AuthConfig, "raw">):
76
77
  * Add Auth.js session to context
77
78
  * @link {@see https://authjs.dev/getting-started/session-management/get-session}
78
79
  **/
79
- export async function authjsSessionMiddleware(
80
- request: Request,
81
- context: Record<string | number | symbol, unknown>,
82
- ): Promise<void> {
80
+ export const authjsSessionMiddleware = (() => async (request, context) => {
83
81
  try {
84
- context.session = await getSession(request, authjsConfig);
82
+ return {
83
+ ...context,
84
+ session: await getSession(request, authjsConfig),
85
+ };
85
86
  } catch (error) {
86
87
  console.debug("authjsSessionMiddleware:", error);
87
- context.user = null;
88
+ return {
89
+ ...context,
90
+ session: null,
91
+ };
88
92
  }
89
- }
93
+ }) satisfies Get<[], UniversalMiddleware>;
90
94
 
91
95
  /**
92
96
  * Auth.js route
93
97
  * @link {@see https://authjs.dev/getting-started/installation}
94
98
  **/
95
- export function authjsHandler<Context extends Record<string | number | symbol, unknown>>(
96
- request: Request,
97
- _context?: Context,
98
- ): Promise<Response> {
99
+ export const authjsHandler = (() => async (request) => {
99
100
  return Auth(request, authjsConfig);
100
- }
101
+ }) satisfies Get<[], UniversalHandler>;
@@ -8,9 +8,11 @@ export declare function getSession(req: Request, config: Omit<AuthConfig, "raw">
8
8
  * Add Auth.js session to context
9
9
  * @link {@see https://authjs.dev/getting-started/session-management/get-session}
10
10
  **/
11
- export declare function authjsSessionMiddleware(request: Request, context: Record<string | number | symbol, unknown>): Promise<void>;
11
+ export declare const authjsSessionMiddleware: () => (request: Request, context: Universal.Context) => Promise<{
12
+ session: Session | null;
13
+ }>;
12
14
  /**
13
15
  * Auth.js route
14
16
  * @link {@see https://authjs.dev/getting-started/installation}
15
17
  **/
16
- export declare function authjsHandler<Context extends Record<string | number | symbol, unknown>>(request: Request, _context?: Context): Promise<Response>;
18
+ export declare const authjsHandler: () => (request: Request) => Promise<Response>;
@@ -45,8 +45,8 @@ var require_package = __commonJS({
45
45
  "@hattip/adapter-cloudflare-workers": "^0.0.47",
46
46
  "@types/node": "^18.19.14",
47
47
  "npm-run-all2": "^6.2.2",
48
- "vike-cloudflare": "^0.0.5",
49
- wrangler: "^3.70.0"
48
+ "vike-cloudflare": "^0.0.6",
49
+ wrangler: "^3.72.0"
50
50
  },
51
51
  dependencies: {
52
52
  "@batijs/core": "workspace:*"
@@ -43,7 +43,7 @@ var require_package = __commonJS({
43
43
  devDependencies: {
44
44
  "@batijs/compile": "workspace:*",
45
45
  "@types/node": "^18.19.14",
46
- vite: "^5.4.0",
46
+ vite: "^5.4.1",
47
47
  "vite-plugin-compiled-react": "^1.1.3"
48
48
  },
49
49
  dependencies: {
@@ -47,10 +47,10 @@ var require_package = __commonJS({
47
47
  "eslint-config-prettier": "^9.1.0",
48
48
  "eslint-plugin-prettier": "^5.2.1",
49
49
  "eslint-plugin-react": "^7.35.0",
50
- "eslint-plugin-solid": "^0.14.1",
50
+ "eslint-plugin-solid": "^0.14.2",
51
51
  "eslint-plugin-vue": "^9.27.0",
52
52
  globals: "^15.9.0",
53
- "typescript-eslint": "^8.0.1",
53
+ "typescript-eslint": "^8.1.0",
54
54
  "vue-eslint-parser": "^9.4.3"
55
55
  },
56
56
  dependencies: {
@@ -55,7 +55,7 @@ var require_package = __commonJS({
55
55
  "@types/cookie-parser": "^1.4.7",
56
56
  "@types/express": "^4.17.21",
57
57
  "@types/node": "^18.19.14",
58
- "@universal-middleware/express": "^0.1.1",
58
+ "@universal-middleware/express": "^0.2.1",
59
59
  "cookie-parser": "^1.4.6",
60
60
  "cross-env": "^7.0.3",
61
61
  dotenv: "^16.4.5",
@@ -63,8 +63,8 @@ var require_package = __commonJS({
63
63
  "express-openid-connect": "^2.17.1",
64
64
  telefunc: "^0.1.76",
65
65
  tsx: "^4.17.0",
66
- vike: "^0.4.183",
67
- vite: "^5.4.0"
66
+ vike: "^0.4.187",
67
+ vite: "^5.4.1"
68
68
  },
69
69
  dependencies: {
70
70
  "@batijs/core": "workspace:*"
@@ -125,7 +125,6 @@ async function getPackageJson(props) {
125
125
  "tsx",
126
126
  "vite",
127
127
  "vike",
128
- ...props.meta.BATI.has("authjs") || props.meta.BATI.has("auth0") ? ["@auth/core", "dotenv"] : [],
129
128
  ...props.meta.BATI.has("firebase-auth") ? ["cookie-parser"] : []
130
129
  ]
131
130
  });
@@ -9,9 +9,10 @@ import {
9
9
  firebaseAuthMiddleware,
10
10
  } from "@batijs/firebase-auth/server/firebase-auth-middleware";
11
11
  import {
12
+ luciaAuthContextMiddleware,
13
+ luciaAuthCookieMiddleware,
12
14
  luciaAuthLoginHandler,
13
15
  luciaAuthLogoutHandler,
14
- luciaAuthMiddleware,
15
16
  luciaAuthSignupHandler,
16
17
  luciaCsrfMiddleware,
17
18
  luciaGithubCallbackHandler,
@@ -57,30 +58,31 @@ async function startServer() {
57
58
  /**
58
59
  * Append Auth.js session to context
59
60
  **/
60
- app.use(createMiddleware(authjsSessionMiddleware));
61
+ app.use(createMiddleware(authjsSessionMiddleware)());
61
62
 
62
63
  /**
63
64
  * Auth.js route
64
65
  * @link {@see https://authjs.dev/getting-started/installation}
65
66
  **/
66
- app.all("/api/auth/*", createHandler(authjsHandler));
67
+ app.all("/api/auth/*", createHandler(authjsHandler)());
67
68
  }
68
69
 
69
70
  if (BATI.has("firebase-auth")) {
70
- app.use(createMiddleware(firebaseAuthMiddleware));
71
- app.post("/api/sessionLogin", createHandler(firebaseAuthLoginHandler));
72
- app.post("/api/sessionLogout", createHandler(firebaseAuthLogoutHandler));
71
+ app.use(createMiddleware(firebaseAuthMiddleware)());
72
+ app.post("/api/sessionLogin", createHandler(firebaseAuthLoginHandler)());
73
+ app.post("/api/sessionLogout", createHandler(firebaseAuthLogoutHandler)());
73
74
  }
74
75
 
75
76
  if (BATI.has("lucia-auth")) {
76
- app.use(createMiddleware(luciaCsrfMiddleware));
77
- app.use(createMiddleware(luciaAuthMiddleware));
78
-
79
- app.post("/api/signup", createHandler(luciaAuthSignupHandler));
80
- app.post("/api/login", createHandler(luciaAuthLoginHandler));
81
- app.post("/api/logout", createHandler(luciaAuthLogoutHandler));
82
- app.get("/api/login/github", createHandler(luciaGithubLoginHandler));
83
- app.get("/api/login/github/callback", createHandler(luciaGithubCallbackHandler));
77
+ app.use(createMiddleware(luciaCsrfMiddleware)());
78
+ app.use(createMiddleware(luciaAuthContextMiddleware)());
79
+ app.use(createMiddleware(luciaAuthCookieMiddleware)());
80
+
81
+ app.post("/api/signup", createHandler(luciaAuthSignupHandler)());
82
+ app.post("/api/login", createHandler(luciaAuthLoginHandler)());
83
+ app.post("/api/logout", createHandler(luciaAuthLogoutHandler)());
84
+ app.get("/api/login/github", createHandler(luciaGithubLoginHandler)());
85
+ app.get("/api/login/github/callback", createHandler(luciaGithubCallbackHandler)());
84
86
  }
85
87
 
86
88
  if (BATI.has("trpc")) {
@@ -106,15 +108,15 @@ async function startServer() {
106
108
  *
107
109
  * @link {@see https://telefunc.com}
108
110
  **/
109
- app.post("/_telefunc", createHandler(telefuncHandler));
111
+ app.post("/_telefunc", createHandler(telefuncHandler)());
110
112
  }
111
113
 
112
114
  if (BATI.has("ts-rest")) {
113
- app.all("/api/*", createHandler(tsRestHandler));
115
+ app.all("/api/*", createHandler(tsRestHandler)());
114
116
  }
115
117
 
116
118
  if (!BATI.has("telefunc") && !BATI.has("trpc") && !BATI.has("ts-rest")) {
117
- app.post("/api/todo/create", createHandler(createTodoHandler));
119
+ app.post("/api/todo/create", createHandler(createTodoHandler)());
118
120
  }
119
121
 
120
122
  /**
@@ -122,7 +124,7 @@ async function startServer() {
122
124
  *
123
125
  * @link {@see https://vike.dev}
124
126
  **/
125
- app.all("*", createHandler(vikeHandler));
127
+ app.all("*", createHandler(vikeHandler)());
126
128
 
127
129
  app.listen(port, () => {
128
130
  console.log(`Server listening on http://localhost:${port}`);
@@ -56,14 +56,14 @@ var require_package = __commonJS({
56
56
  "@trpc/server": "^10.45.2",
57
57
  "@types/express": "^4.17.21",
58
58
  "@types/node": "^18.19.14",
59
- "@universal-middleware/express": "^0.1.1",
59
+ "@universal-middleware/fastify": "^0.2.1",
60
60
  "cross-env": "^7.0.3",
61
61
  dotenv: "^16.4.5",
62
62
  fastify: "^4.28.1",
63
63
  telefunc: "^0.1.76",
64
64
  tsx: "^4.17.0",
65
- vike: "^0.4.183",
66
- vite: "^5.4.0"
65
+ vike: "^0.4.187",
66
+ vite: "^5.4.1"
67
67
  },
68
68
  dependencies: {
69
69
  "@batijs/core": "workspace:*"
@@ -117,13 +117,12 @@ async function getPackageJson(props) {
117
117
  dependencies: [
118
118
  "@fastify/middie",
119
119
  "@fastify/static",
120
- "@universal-middleware/express",
120
+ "@universal-middleware/fastify",
121
121
  "cross-env",
122
122
  "fastify",
123
123
  "tsx",
124
124
  "vike",
125
- "vite",
126
- ...props.meta.BATI.has("authjs") || props.meta.BATI.has("auth0") ? ["@auth/core", "dotenv"] : []
125
+ "vite"
127
126
  ]
128
127
  });
129
128
  }
@@ -9,9 +9,10 @@ import {
9
9
  firebaseAuthMiddleware,
10
10
  } from "@batijs/firebase-auth/server/firebase-auth-middleware";
11
11
  import {
12
+ luciaAuthContextMiddleware,
13
+ luciaAuthCookieMiddleware,
12
14
  luciaAuthLoginHandler,
13
15
  luciaAuthLogoutHandler,
14
- luciaAuthMiddleware,
15
16
  luciaAuthSignupHandler,
16
17
  luciaCsrfMiddleware,
17
18
  luciaGithubCallbackHandler,
@@ -27,9 +28,8 @@ import {
27
28
  fastifyTRPCPlugin,
28
29
  type FastifyTRPCPluginOptions,
29
30
  } from "@trpc/server/adapters/fastify";
30
- import { createRequestAdapter } from "@universal-middleware/express";
31
31
  import Fastify from "fastify";
32
- import type { RouteHandlerMethod } from "fastify/types/route";
32
+ import { createHandler, createMiddleware } from "@universal-middleware/fastify";
33
33
 
34
34
  const __filename = fileURLToPath(import.meta.url);
35
35
  const __dirname = dirname(__filename);
@@ -37,44 +37,11 @@ const root = __dirname;
37
37
  const port = process.env.PORT ? parseInt(process.env.PORT, 10) : 3000;
38
38
  const hmrPort = process.env.HMR_PORT ? parseInt(process.env.HMR_PORT, 10) : 24678;
39
39
 
40
- interface Middleware<Context extends Record<string | number | symbol, unknown>> {
41
- (request: Request, context: Context): Response | void | Promise<Response> | Promise<void>;
42
- }
43
-
44
- export function handlerAdapter<Context extends Record<string | number | symbol, unknown>>(
45
- handler: Middleware<Context>,
46
- ) {
47
- const requestAdapter = createRequestAdapter();
48
- return (async (request, reply) => {
49
- const config = request.routeOptions.config as unknown as Record<string, unknown>;
50
- config.context ??= {};
51
- const response = await handler(requestAdapter(request.raw), config.context as Context);
52
-
53
- if (response) {
54
- if (!response.body) {
55
- // Fastify currently doesn't send a response for body is null.
56
- // To mimic express behavior, we convert the body to an empty ReadableStream.
57
- Object.defineProperty(response, "body", {
58
- value: new ReadableStream({
59
- start(controller) {
60
- controller.close();
61
- },
62
- }),
63
- writable: false,
64
- configurable: true,
65
- });
66
- }
67
-
68
- return reply.send(response);
69
- }
70
- }) satisfies RouteHandlerMethod;
71
- }
72
-
73
40
  async function startServer() {
74
41
  const app = Fastify();
75
42
 
76
43
  // Avoid pre-parsing body, otherwise it will cause issue with universal handlers
77
- // This will probably change in the future though, you can follow https://github.com/magne4000/universal-handler for updates
44
+ // This will probably change in the future though, you can follow https://github.com/magne4000/universal-middleware for updates
78
45
  app.removeAllContentTypeParsers();
79
46
  app.addContentTypeParser("*", function (_request, _payload, done) {
80
47
  done(null, "");
@@ -105,30 +72,31 @@ async function startServer() {
105
72
  /**
106
73
  * Append Auth.js session to context
107
74
  **/
108
- app.addHook("onRequest", handlerAdapter(authjsSessionMiddleware));
75
+ app.register(createMiddleware(authjsSessionMiddleware)());
109
76
 
110
77
  /**
111
78
  * Auth.js route
112
79
  * @link {@see https://authjs.dev/getting-started/installation}
113
80
  **/
114
- app.all("/api/auth/*", handlerAdapter(authjsHandler));
81
+ app.all("/api/auth/*", createHandler(authjsHandler)());
115
82
  }
116
83
 
117
84
  if (BATI.has("firebase-auth")) {
118
- app.addHook("onRequest", handlerAdapter(firebaseAuthMiddleware));
119
- app.post("/api/sessionLogin", handlerAdapter(firebaseAuthLoginHandler));
120
- app.post("/api/sessionLogout", handlerAdapter(firebaseAuthLogoutHandler));
85
+ app.register(createMiddleware(firebaseAuthMiddleware)());
86
+ app.post("/api/sessionLogin", createHandler(firebaseAuthLoginHandler)());
87
+ app.post("/api/sessionLogout", createHandler(firebaseAuthLogoutHandler)());
121
88
  }
122
89
 
123
90
  if (BATI.has("lucia-auth")) {
124
- app.addHook("onRequest", handlerAdapter(luciaCsrfMiddleware));
125
- app.addHook("onRequest", handlerAdapter(luciaAuthMiddleware));
126
-
127
- app.post("/api/signup", handlerAdapter(luciaAuthSignupHandler));
128
- app.post("/api/login", handlerAdapter(luciaAuthLoginHandler));
129
- app.post("/api/logout", handlerAdapter(luciaAuthLogoutHandler));
130
- app.get("/api/login/github", handlerAdapter(luciaGithubLoginHandler));
131
- app.get("/api/login/github/callback", handlerAdapter(luciaGithubCallbackHandler));
91
+ app.register(createMiddleware(luciaCsrfMiddleware)());
92
+ app.register(createMiddleware(luciaAuthContextMiddleware)());
93
+ app.register(createMiddleware(luciaAuthCookieMiddleware)());
94
+
95
+ app.post("/api/signup", createHandler(luciaAuthSignupHandler)());
96
+ app.post("/api/login", createHandler(luciaAuthLoginHandler)());
97
+ app.post("/api/logout", createHandler(luciaAuthLogoutHandler)());
98
+ app.get("/api/login/github", createHandler(luciaGithubLoginHandler)());
99
+ app.get("/api/login/github/callback", createHandler(luciaGithubCallbackHandler)());
132
100
  }
133
101
 
134
102
  if (BATI.has("trpc")) {
@@ -158,15 +126,15 @@ async function startServer() {
158
126
  *
159
127
  * @link {@see https://telefunc.com}
160
128
  **/
161
- app.post<{ Body: string }>("/_telefunc", handlerAdapter(telefuncHandler));
129
+ app.post<{ Body: string }>("/_telefunc", createHandler(telefuncHandler)());
162
130
  }
163
131
 
164
132
  if (BATI.has("ts-rest")) {
165
- app.all("/api/*", handlerAdapter(tsRestHandler));
133
+ app.all("/api/*", createHandler(tsRestHandler));
166
134
  }
167
135
 
168
136
  if (!BATI.has("telefunc") && !BATI.has("trpc") && !BATI.has("ts-rest")) {
169
- app.post("/api/todo/create", handlerAdapter(createTodoHandler));
137
+ app.post("/api/todo/create", createHandler(createTodoHandler)());
170
138
  }
171
139
 
172
140
  /**
@@ -174,7 +142,7 @@ async function startServer() {
174
142
  *
175
143
  * @link {@see https://vike.dev}
176
144
  **/
177
- app.all("/*", handlerAdapter(vikeHandler));
145
+ app.all("/*", createHandler(vikeHandler)());
178
146
 
179
147
  return app;
180
148
  }
@@ -1,7 +1,3 @@
1
1
  import "dotenv/config";
2
- interface Middleware<Context extends Record<string | number | symbol, unknown>> {
3
- (request: Request, context: Context): Response | void | Promise<Response> | Promise<void>;
4
- }
5
- export declare function handlerAdapter<Context extends Record<string | number | symbol, unknown>>(handler: Middleware<Context>): (this: import("fastify").FastifyInstance<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>, request: import("fastify").FastifyRequest<import("fastify").RouteGenericInterface, import("fastify").RawServerDefault, import("http").IncomingMessage, import("fastify").FastifySchema, import("fastify").FastifyTypeProviderDefault, unknown, import("fastify").FastifyBaseLogger, import("fastify/types/type-provider").ResolveFastifyRequestType<import("fastify").FastifyTypeProviderDefault, import("fastify").FastifySchema, import("fastify").RouteGenericInterface>>, reply: import("fastify").FastifyReply<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").RouteGenericInterface, unknown, import("fastify").FastifySchema, import("fastify").FastifyTypeProviderDefault, unknown>) => Promise<undefined>;
6
2
  declare const _default: (req: Request, res: Response) => Promise<void>;
7
3
  export default _default;
@@ -44,13 +44,14 @@ var require_package = __commonJS({
44
44
  "@batijs/compile": "workspace:*",
45
45
  "@types/cookie": "^0.6.0",
46
46
  "@types/node": "^18.19.14",
47
+ "@universal-middleware/core": "^0.2.3",
47
48
  cookie: "^0.6.0",
48
49
  dotenv: "^16.4.5",
49
- firebase: "^10.12.5",
50
+ firebase: "^10.13.0",
50
51
  "firebase-admin": "^12.3.1",
51
52
  firebaseui: "^6.1.0",
52
- vike: "^0.4.183",
53
- vite: "^5.4.0"
53
+ vike: "^0.4.187",
54
+ vite: "^5.4.1"
54
55
  },
55
56
  dependencies: {
56
57
  "@batijs/core": "workspace:*"
@@ -115,7 +116,7 @@ async function getPackageJson(props) {
115
116
  const packageJson = await loadAsJson(props);
116
117
  return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)).then((x) => x.default), {
117
118
  devDependencies: ["dotenv", "@types/cookie"],
118
- dependencies: ["firebase", "firebase-admin", "firebaseui", "cookie"]
119
+ dependencies: ["firebase", "firebase-admin", "firebaseui", "cookie", "@universal-middleware/core"]
119
120
  });
120
121
  }
121
122
  export {
@@ -1,12 +1,9 @@
1
1
  import { parse, serialize } from "cookie";
2
2
  import { getAuth } from "firebase-admin/auth";
3
3
  import { firebaseAdmin } from "../libs/firebaseAdmin";
4
+ import type { Get, UniversalHandler, UniversalMiddleware } from "@universal-middleware/core";
4
5
 
5
- export async function firebaseAuthMiddleware(
6
- request: Request,
7
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
- context: any,
9
- ): Promise<void> {
6
+ export const firebaseAuthMiddleware = (() => async (request, context) => {
10
7
  if (!request.headers.has("cookie")) return;
11
8
 
12
9
  const cookies = parse(request.headers.get("cookie")!);
@@ -15,17 +12,21 @@ export async function firebaseAuthMiddleware(
15
12
  try {
16
13
  const auth = getAuth(firebaseAdmin);
17
14
  const decodedIdToken = await auth.verifySessionCookie(sessionCookie, true);
18
- context.user = await auth.getUser(decodedIdToken.sub);
15
+ const user = await auth.getUser(decodedIdToken.sub);
16
+ return {
17
+ ...context,
18
+ user,
19
+ };
19
20
  } catch (error) {
20
21
  console.debug("verifySessionCookie:", error);
21
- context.user = null;
22
+ return {
23
+ ...context,
24
+ user: null,
25
+ };
22
26
  }
23
- }
27
+ }) satisfies Get<[], UniversalMiddleware>;
24
28
 
25
- export async function firebaseAuthLoginHandler<Context extends Record<string | number | symbol, unknown>>(
26
- request: Request,
27
- _context?: Context,
28
- ): Promise<Response> {
29
+ export const firebaseAuthLoginHandler: Get<[], UniversalHandler> = () => async (request) => {
29
30
  const body = await request.json();
30
31
  const idToken: string = (body as { idToken?: string }).idToken || "";
31
32
 
@@ -50,12 +51,9 @@ export async function firebaseAuthLoginHandler<Context extends Record<string | n
50
51
  status: 401,
51
52
  });
52
53
  }
53
- }
54
+ };
54
55
 
55
- export async function firebaseAuthLogoutHandler<Context extends Record<string | number | symbol, unknown>>(
56
- _request: Request,
57
- _context?: Context,
58
- ): Promise<Response> {
56
+ export const firebaseAuthLogoutHandler: Get<[], UniversalHandler> = () => async () => {
59
57
  return new Response(JSON.stringify({ status: "success" }), {
60
58
  status: 200,
61
59
  headers: {
@@ -69,4 +67,4 @@ export async function firebaseAuthLogoutHandler<Context extends Record<string |
69
67
  }),
70
68
  },
71
69
  });
72
- }
70
+ };
@@ -1,3 +1,8 @@
1
- export declare function firebaseAuthMiddleware(request: Request, context: any): Promise<void>;
2
- export declare function firebaseAuthLoginHandler<Context extends Record<string | number | symbol, unknown>>(request: Request, _context?: Context): Promise<Response>;
3
- export declare function firebaseAuthLogoutHandler<Context extends Record<string | number | symbol, unknown>>(_request: Request, _context?: Context): Promise<Response>;
1
+ import type { Get, UniversalHandler } from "@universal-middleware/core";
2
+ export declare const firebaseAuthMiddleware: () => (request: Request, context: Universal.Context) => Promise<{
3
+ user: import("firebase-admin/auth").UserRecord;
4
+ } | {
5
+ user: null;
6
+ } | undefined>;
7
+ export declare const firebaseAuthLoginHandler: Get<[], UniversalHandler>;
8
+ export declare const firebaseAuthLogoutHandler: Get<[], UniversalHandler>;
@@ -56,14 +56,15 @@ var require_package = __commonJS({
56
56
  "@types/express": "^4.17.21",
57
57
  "@types/node": "^18.19.14",
58
58
  "@types/serve-static": "^1.15.7",
59
+ "@universal-middleware/h3": "^0.2.0",
59
60
  "cross-env": "^7.0.3",
60
61
  dotenv: "^16.4.5",
61
62
  h3: "~1.12.0",
62
63
  "serve-static": "^1.15.0",
63
64
  telefunc: "^0.1.76",
64
65
  tsx: "^4.17.0",
65
- vike: "^0.4.183",
66
- vite: "^5.4.0"
66
+ vike: "^0.4.187",
67
+ vite: "^5.4.1"
67
68
  },
68
69
  dependencies: {
69
70
  "@batijs/core": "workspace:*"
@@ -125,6 +126,7 @@ async function getPackageJson(props) {
125
126
  "tsx",
126
127
  "vike",
127
128
  "vite",
129
+ "@universal-middleware/h3",
128
130
  ...props.meta.BATI.has("authjs") || props.meta.BATI.has("auth0") ? ["@auth/core"] : []
129
131
  ]
130
132
  });