@batijs/cli 0.0.259 → 0.0.260
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/dist/boilerplates/@batijs/authjs/files/$package.json.js +1 -1
- package/dist/boilerplates/@batijs/authjs/files/server/authjs-handler.ts +2 -2
- package/dist/boilerplates/@batijs/authjs/types/server/authjs-handler.d.ts +2 -3
- package/dist/boilerplates/@batijs/cloudflare/files/$package.json.js +1 -1
- package/dist/boilerplates/@batijs/cloudflare/files/$tsconfig.json.js +10 -0
- package/dist/boilerplates/@batijs/d1/files/$README.md.js +0 -4
- package/dist/boilerplates/@batijs/d1/files/$package.json.js +96 -0
- package/dist/boilerplates/@batijs/d1/files/$wrangler.toml.js +1 -0
- package/dist/boilerplates/@batijs/d1/files/database/d1/helpers.ts +17 -0
- package/dist/boilerplates/@batijs/d1/files/vike.d.ts +8 -0
- package/dist/boilerplates/@batijs/d1/types/database/d1/helpers.d.ts +6 -0
- package/dist/boilerplates/@batijs/d1-sqlite/files/$package.json.js +10 -0
- package/dist/boilerplates/@batijs/d1-sqlite/files/database/d1/queries/lucia-auth.ts +28 -0
- package/dist/boilerplates/@batijs/d1-sqlite/files/database/d1/queries/todos.ts +10 -0
- package/dist/boilerplates/@batijs/d1-sqlite/files/database/migrations/lucia-auth.sql +20 -0
- package/dist/boilerplates/@batijs/d1-sqlite/files/database/migrations/todos.sql +4 -0
- package/dist/boilerplates/@batijs/d1-sqlite/types/database/d1/queries/lucia-auth.d.ts +5 -0
- package/dist/boilerplates/@batijs/d1-sqlite/types/database/d1/queries/todos.d.ts +6 -0
- package/dist/boilerplates/@batijs/drizzle/files/$.env.js +1 -0
- package/dist/boilerplates/@batijs/drizzle/files/$README.md.js +0 -3
- package/dist/boilerplates/@batijs/drizzle/files/$package.json.js +7 -14
- package/dist/boilerplates/@batijs/drizzle/files/database/drizzle/db.ts +10 -12
- package/dist/boilerplates/@batijs/drizzle/files/database/drizzle/queries/lucia-auth.ts +38 -9
- package/dist/boilerplates/@batijs/drizzle/files/database/drizzle/queries/todos.ts +16 -5
- package/dist/boilerplates/@batijs/drizzle/files/drizzle.config.ts +7 -4
- package/dist/boilerplates/@batijs/drizzle/types/database/drizzle/db.d.ts +2 -2
- package/dist/boilerplates/@batijs/drizzle/types/database/drizzle/queries/lucia-auth.d.ts +19 -6
- package/dist/boilerplates/@batijs/drizzle/types/database/drizzle/queries/todos.d.ts +9 -2
- package/dist/boilerplates/@batijs/eslint/files/$package.json.js +1 -1
- package/dist/boilerplates/@batijs/eslint/files/eslint.config.js +2 -1
- package/dist/boilerplates/@batijs/express/files/$package.json.js +2 -1
- package/dist/boilerplates/@batijs/express/files/express-entry.ts +13 -12
- package/dist/boilerplates/@batijs/fastify/files/$package.json.js +2 -1
- package/dist/boilerplates/@batijs/fastify/files/fastify-entry.ts +17 -24
- package/dist/boilerplates/@batijs/firebase-auth/files/$package.json.js +2 -2
- package/dist/boilerplates/@batijs/firebase-auth/files/server/firebase-auth-middleware.ts +2 -2
- package/dist/boilerplates/@batijs/firebase-auth/types/server/firebase-auth-middleware.d.ts +2 -6
- package/dist/boilerplates/@batijs/h3/files/$package.json.js +1 -0
- package/dist/boilerplates/@batijs/h3/files/h3-entry.ts +12 -2
- package/dist/boilerplates/@batijs/hattip/files/$package.json.js +3 -1
- package/dist/boilerplates/@batijs/hattip/files/hattip-entry.ts +12 -12
- package/dist/boilerplates/@batijs/hono/files/$package.json.js +14 -3
- package/dist/boilerplates/@batijs/hono/files/hono-entry.ts +12 -12
- package/dist/boilerplates/@batijs/lucia-auth/files/$package.json.js +4 -1
- package/dist/boilerplates/@batijs/lucia-auth/files/lib/lucia-auth.ts +75 -39
- package/dist/boilerplates/@batijs/lucia-auth/files/server/lucia-auth-handlers.ts +77 -33
- package/dist/boilerplates/@batijs/lucia-auth/types/lib/lucia-auth.d.ts +30 -10
- package/dist/boilerplates/@batijs/lucia-auth/types/server/lucia-auth-handlers.d.ts +13 -13
- package/dist/boilerplates/@batijs/react-lucia-auth/files/pages/login/+Page.tsx +2 -1
- package/dist/boilerplates/@batijs/shared/files/vite.config.ts +6 -0
- package/dist/boilerplates/@batijs/shared-db/files/server/db-middleware.ts +37 -0
- package/dist/boilerplates/@batijs/shared-db/types/server/db-middleware.d.ts +17 -0
- package/dist/boilerplates/@batijs/shared-no-db/files/$package.json.js +2 -1
- package/dist/boilerplates/@batijs/shared-server/files/$package.json.js +5 -2
- package/dist/boilerplates/@batijs/shared-server/files/server/create-todo-handler.ts +22 -4
- package/dist/boilerplates/@batijs/shared-server/files/server/vike-handler.ts +2 -2
- package/dist/boilerplates/@batijs/shared-server/types/server/create-todo-handler.d.ts +19 -1
- package/dist/boilerplates/@batijs/shared-todo/files/pages/todo/+data.ts +10 -4
- package/dist/boilerplates/@batijs/shared-todo/files/vike.d.ts +19 -0
- package/dist/boilerplates/@batijs/shared-todo/types/pages/todo/+data.d.ts +2 -1
- package/dist/boilerplates/@batijs/solid-lucia-auth/files/pages/login/+Page.tsx +2 -1
- package/dist/boilerplates/@batijs/sqlite/files/$.env.js +1 -0
- package/dist/boilerplates/@batijs/sqlite/files/$package.json.js +10 -1
- package/dist/boilerplates/@batijs/sqlite/files/database/sqlite/queries/lucia-auth.ts +16 -15
- package/dist/boilerplates/@batijs/sqlite/files/database/sqlite/queries/todos.ts +5 -5
- package/dist/boilerplates/@batijs/sqlite/types/database/sqlite/queries/lucia-auth.d.ts +5 -5
- package/dist/boilerplates/@batijs/sqlite/types/database/sqlite/queries/todos.d.ts +3 -2
- package/dist/boilerplates/@batijs/telefunc/files/$package.json.js +5 -3
- package/dist/boilerplates/@batijs/telefunc/files/pages/todo/TodoList.telefunc.ts +10 -3
- package/dist/boilerplates/@batijs/telefunc/files/server/telefunc-handler.ts +15 -2
- package/dist/boilerplates/@batijs/telefunc/files/vike.d.ts +20 -0
- package/dist/boilerplates/@batijs/trpc/files/$package.json.js +10 -7
- package/dist/boilerplates/@batijs/trpc/files/server/trpc-handler.ts +22 -0
- package/dist/boilerplates/@batijs/trpc/files/trpc/server.ts +20 -4
- package/dist/boilerplates/@batijs/trpc/types/server/trpc-handler.d.ts +1 -0
- package/dist/boilerplates/@batijs/trpc/types/trpc/client.d.ts +36 -4
- package/dist/boilerplates/@batijs/trpc/types/trpc/server.d.ts +75 -8
- package/dist/boilerplates/@batijs/ts-rest/files/$package.json.js +4 -3
- package/dist/boilerplates/@batijs/ts-rest/files/server/ts-rest-handler.ts +48 -27
- package/dist/boilerplates/@batijs/vue-lucia-auth/files/pages/login/+Page.vue +2 -1
- package/dist/boilerplates/boilerplates.json +50 -3
- package/dist/index.js +2 -1
- package/package.json +5 -5
- package/dist/boilerplates/@batijs/drizzle/files/database/drizzle/seed.ts +0 -13
- package/dist/boilerplates/@batijs/drizzle/types/database/drizzle/seed.d.ts +0 -1
- package/dist/boilerplates/@batijs/trpc/files/$vite.config.ts.js +0 -13
- package/dist/boilerplates/@batijs/trpc/files/trpc/vite-plugin.ts +0 -49
- package/dist/boilerplates/@batijs/trpc/types/trpc/vite-plugin.d.ts +0 -12
|
@@ -48,6 +48,7 @@ var require_package = __commonJS({
|
|
|
48
48
|
"@batijs/lucia-auth": "workspace:*",
|
|
49
49
|
"@batijs/shared-server": "workspace:^",
|
|
50
50
|
"@batijs/shared-todo": "workspace:^",
|
|
51
|
+
"@batijs/shared-db": "workspace:^",
|
|
51
52
|
"@batijs/telefunc": "workspace:*",
|
|
52
53
|
"@batijs/trpc": "workspace:*",
|
|
53
54
|
"@batijs/ts-rest": "workspace:*",
|
|
@@ -55,7 +56,7 @@ var require_package = __commonJS({
|
|
|
55
56
|
"@types/cookie-parser": "^1.4.7",
|
|
56
57
|
"@types/express": "^4.17.21",
|
|
57
58
|
"@types/node": "^18.19.14",
|
|
58
|
-
"@universal-middleware/express": "^0.2.
|
|
59
|
+
"@universal-middleware/express": "^0.2.3",
|
|
59
60
|
"cookie-parser": "^1.4.6",
|
|
60
61
|
"cross-env": "^7.0.3",
|
|
61
62
|
dotenv: "^16.4.5",
|
|
@@ -15,17 +15,18 @@ import {
|
|
|
15
15
|
luciaAuthLogoutHandler,
|
|
16
16
|
luciaAuthSignupHandler,
|
|
17
17
|
luciaCsrfMiddleware,
|
|
18
|
+
luciaDbMiddleware,
|
|
18
19
|
luciaGithubCallbackHandler,
|
|
19
20
|
luciaGithubLoginHandler,
|
|
20
21
|
} from "@batijs/lucia-auth/server/lucia-auth-handlers";
|
|
21
22
|
import { createTodoHandler } from "@batijs/shared-server/server/create-todo-handler";
|
|
22
23
|
import { vikeHandler } from "@batijs/shared-server/server/vike-handler";
|
|
23
24
|
import { telefuncHandler } from "@batijs/telefunc/server/telefunc-handler";
|
|
24
|
-
import { appRouter } from "@batijs/trpc/trpc/server";
|
|
25
25
|
import { tsRestHandler } from "@batijs/ts-rest/server/ts-rest-handler";
|
|
26
|
-
import * as trpcExpress from "@trpc/server/adapters/express";
|
|
27
26
|
import { createHandler, createMiddleware } from "@universal-middleware/express";
|
|
27
|
+
import { dbMiddleware } from "@batijs/shared-db/server/db-middleware";
|
|
28
28
|
import express from "express";
|
|
29
|
+
import { trpcHandler } from "@batijs/trpc/server/trpc-handler";
|
|
29
30
|
|
|
30
31
|
const __filename = fileURLToPath(import.meta.url);
|
|
31
32
|
const __dirname = dirname(__filename);
|
|
@@ -54,6 +55,13 @@ async function startServer() {
|
|
|
54
55
|
app.use(viteDevMiddleware);
|
|
55
56
|
}
|
|
56
57
|
|
|
58
|
+
if (BATI.hasDatabase) {
|
|
59
|
+
/**
|
|
60
|
+
* Make database available in Context as `context.db`
|
|
61
|
+
*/
|
|
62
|
+
app.use(createMiddleware(dbMiddleware)());
|
|
63
|
+
}
|
|
64
|
+
|
|
57
65
|
if (BATI.has("authjs") || BATI.has("auth0")) {
|
|
58
66
|
/**
|
|
59
67
|
* Append Auth.js session to context
|
|
@@ -74,6 +82,7 @@ async function startServer() {
|
|
|
74
82
|
}
|
|
75
83
|
|
|
76
84
|
if (BATI.has("lucia-auth")) {
|
|
85
|
+
app.use(createMiddleware(luciaDbMiddleware)());
|
|
77
86
|
app.use(createMiddleware(luciaCsrfMiddleware)());
|
|
78
87
|
app.use(createMiddleware(luciaAuthContextMiddleware)());
|
|
79
88
|
app.use(createMiddleware(luciaAuthCookieMiddleware)());
|
|
@@ -89,17 +98,9 @@ async function startServer() {
|
|
|
89
98
|
/**
|
|
90
99
|
* tRPC route
|
|
91
100
|
*
|
|
92
|
-
* @link {@see https://trpc.io/docs/server/adapters/
|
|
101
|
+
* @link {@see https://trpc.io/docs/server/adapters/fetch}
|
|
93
102
|
**/
|
|
94
|
-
app.use(
|
|
95
|
-
"/api/trpc",
|
|
96
|
-
trpcExpress.createExpressMiddleware({
|
|
97
|
-
router: appRouter,
|
|
98
|
-
createContext({ req, res }: trpcExpress.CreateExpressContextOptions) {
|
|
99
|
-
return { req, res };
|
|
100
|
-
},
|
|
101
|
-
}),
|
|
102
|
-
);
|
|
103
|
+
app.use("/api/trpc", createHandler(trpcHandler)("/api/trpc"));
|
|
103
104
|
}
|
|
104
105
|
|
|
105
106
|
if (BATI.has("telefunc")) {
|
|
@@ -48,6 +48,7 @@ var require_package = __commonJS({
|
|
|
48
48
|
"@batijs/lucia-auth": "workspace:*",
|
|
49
49
|
"@batijs/shared-server": "workspace:^",
|
|
50
50
|
"@batijs/shared-todo": "workspace:^",
|
|
51
|
+
"@batijs/shared-db": "workspace:^",
|
|
51
52
|
"@batijs/telefunc": "workspace:^",
|
|
52
53
|
"@batijs/trpc": "workspace:^",
|
|
53
54
|
"@batijs/ts-rest": "workspace:*",
|
|
@@ -56,7 +57,7 @@ var require_package = __commonJS({
|
|
|
56
57
|
"@trpc/server": "^10.45.2",
|
|
57
58
|
"@types/express": "^4.17.21",
|
|
58
59
|
"@types/node": "^18.19.14",
|
|
59
|
-
"@universal-middleware/fastify": "^0.2.
|
|
60
|
+
"@universal-middleware/fastify": "^0.2.3",
|
|
60
61
|
"cross-env": "^7.0.3",
|
|
61
62
|
dotenv: "^16.4.5",
|
|
62
63
|
fastify: "^4.28.1",
|
|
@@ -15,21 +15,18 @@ import {
|
|
|
15
15
|
luciaAuthLogoutHandler,
|
|
16
16
|
luciaAuthSignupHandler,
|
|
17
17
|
luciaCsrfMiddleware,
|
|
18
|
+
luciaDbMiddleware,
|
|
18
19
|
luciaGithubCallbackHandler,
|
|
19
20
|
luciaGithubLoginHandler,
|
|
20
21
|
} from "@batijs/lucia-auth/server/lucia-auth-handlers";
|
|
21
22
|
import { createTodoHandler } from "@batijs/shared-server/server/create-todo-handler";
|
|
22
23
|
import { vikeHandler } from "@batijs/shared-server/server/vike-handler";
|
|
23
24
|
import { telefuncHandler } from "@batijs/telefunc/server/telefunc-handler";
|
|
24
|
-
import { appRouter, type AppRouter } from "@batijs/trpc/trpc/server";
|
|
25
25
|
import { tsRestHandler } from "@batijs/ts-rest/server/ts-rest-handler";
|
|
26
|
-
import {
|
|
27
|
-
type CreateFastifyContextOptions,
|
|
28
|
-
fastifyTRPCPlugin,
|
|
29
|
-
type FastifyTRPCPluginOptions,
|
|
30
|
-
} from "@trpc/server/adapters/fastify";
|
|
31
26
|
import Fastify from "fastify";
|
|
32
27
|
import { createHandler, createMiddleware } from "@universal-middleware/fastify";
|
|
28
|
+
import { dbMiddleware } from "@batijs/shared-db/server/db-middleware";
|
|
29
|
+
import { trpcHandler } from "@batijs/trpc/server/trpc-handler";
|
|
33
30
|
|
|
34
31
|
const __filename = fileURLToPath(import.meta.url);
|
|
35
32
|
const __dirname = dirname(__filename);
|
|
@@ -68,11 +65,18 @@ async function startServer() {
|
|
|
68
65
|
app.use(viteDevMiddleware);
|
|
69
66
|
}
|
|
70
67
|
|
|
68
|
+
if (BATI.hasDatabase) {
|
|
69
|
+
/**
|
|
70
|
+
* Make database available in Context as `context.db`
|
|
71
|
+
*/
|
|
72
|
+
await app.register(createMiddleware(dbMiddleware)());
|
|
73
|
+
}
|
|
74
|
+
|
|
71
75
|
if (BATI.has("authjs") || BATI.has("auth0")) {
|
|
72
76
|
/**
|
|
73
77
|
* Append Auth.js session to context
|
|
74
78
|
**/
|
|
75
|
-
app.register(createMiddleware(authjsSessionMiddleware)());
|
|
79
|
+
await app.register(createMiddleware(authjsSessionMiddleware)());
|
|
76
80
|
|
|
77
81
|
/**
|
|
78
82
|
* Auth.js route
|
|
@@ -88,9 +92,10 @@ async function startServer() {
|
|
|
88
92
|
}
|
|
89
93
|
|
|
90
94
|
if (BATI.has("lucia-auth")) {
|
|
91
|
-
app.register(createMiddleware(
|
|
92
|
-
app.register(createMiddleware(
|
|
93
|
-
app.register(createMiddleware(
|
|
95
|
+
await app.register(createMiddleware(luciaDbMiddleware)());
|
|
96
|
+
await app.register(createMiddleware(luciaCsrfMiddleware)());
|
|
97
|
+
await app.register(createMiddleware(luciaAuthContextMiddleware)());
|
|
98
|
+
await app.register(createMiddleware(luciaAuthCookieMiddleware)());
|
|
94
99
|
|
|
95
100
|
app.post("/api/signup", createHandler(luciaAuthSignupHandler)());
|
|
96
101
|
app.post("/api/login", createHandler(luciaAuthLoginHandler)());
|
|
@@ -103,21 +108,9 @@ async function startServer() {
|
|
|
103
108
|
/**
|
|
104
109
|
* tRPC route
|
|
105
110
|
*
|
|
106
|
-
* @link {@see https://trpc.io/docs/server/adapters/
|
|
111
|
+
* @link {@see https://trpc.io/docs/server/adapters/fetch}
|
|
107
112
|
**/
|
|
108
|
-
|
|
109
|
-
prefix: "/api/trpc",
|
|
110
|
-
trpcOptions: {
|
|
111
|
-
router: appRouter,
|
|
112
|
-
createContext({ req, res }: CreateFastifyContextOptions) {
|
|
113
|
-
return { req, res };
|
|
114
|
-
},
|
|
115
|
-
onError({ path, error }) {
|
|
116
|
-
// report to error monitoring
|
|
117
|
-
console.error(`Error in tRPC handler on path '${path}':`, error);
|
|
118
|
-
},
|
|
119
|
-
} satisfies FastifyTRPCPluginOptions<AppRouter>["trpcOptions"],
|
|
120
|
-
});
|
|
113
|
+
app.all("/api/trpc/*", createHandler(trpcHandler)("/api/trpc"));
|
|
121
114
|
}
|
|
122
115
|
|
|
123
116
|
if (BATI.has("telefunc")) {
|
|
@@ -44,10 +44,10 @@ 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.
|
|
47
|
+
"@universal-middleware/core": "^0.2.6",
|
|
48
48
|
cookie: "^0.6.0",
|
|
49
49
|
dotenv: "^16.4.5",
|
|
50
|
-
firebase: "^10.13.
|
|
50
|
+
firebase: "^10.13.1",
|
|
51
51
|
"firebase-admin": "^12.4.0",
|
|
52
52
|
firebaseui: "^6.1.0",
|
|
53
53
|
vike: "^0.4.193",
|
|
@@ -3,7 +3,7 @@ import { getAuth } from "firebase-admin/auth";
|
|
|
3
3
|
import { firebaseAdmin } from "../libs/firebaseAdmin";
|
|
4
4
|
import type { Get, UniversalHandler, UniversalMiddleware } from "@universal-middleware/core";
|
|
5
5
|
|
|
6
|
-
export const firebaseAuthMiddleware = (
|
|
6
|
+
export const firebaseAuthMiddleware: Get<[], UniversalMiddleware> = () => async (request, context) => {
|
|
7
7
|
if (!request.headers.has("cookie")) return;
|
|
8
8
|
|
|
9
9
|
const cookies = parse(request.headers.get("cookie")!);
|
|
@@ -24,7 +24,7 @@ export const firebaseAuthMiddleware = (() => async (request, context) => {
|
|
|
24
24
|
user: null,
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
|
-
}
|
|
27
|
+
};
|
|
28
28
|
|
|
29
29
|
export const firebaseAuthLoginHandler: Get<[], UniversalHandler> = () => async (request) => {
|
|
30
30
|
const body = await request.json();
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import type { Get, UniversalHandler } from "@universal-middleware/core";
|
|
2
|
-
export declare const firebaseAuthMiddleware:
|
|
3
|
-
user: import("firebase-admin/auth").UserRecord;
|
|
4
|
-
} | {
|
|
5
|
-
user: null;
|
|
6
|
-
} | undefined>;
|
|
1
|
+
import type { Get, UniversalHandler, UniversalMiddleware } from "@universal-middleware/core";
|
|
2
|
+
export declare const firebaseAuthMiddleware: Get<[], UniversalMiddleware>;
|
|
7
3
|
export declare const firebaseAuthLoginHandler: Get<[], UniversalHandler>;
|
|
8
4
|
export declare const firebaseAuthLogoutHandler: Get<[], UniversalHandler>;
|
|
@@ -48,6 +48,7 @@ var require_package = __commonJS({
|
|
|
48
48
|
"@batijs/lucia-auth": "workspace:*",
|
|
49
49
|
"@batijs/shared-server": "workspace:^",
|
|
50
50
|
"@batijs/shared-todo": "workspace:^",
|
|
51
|
+
"@batijs/shared-db": "workspace:^",
|
|
51
52
|
"@batijs/telefunc": "workspace:^",
|
|
52
53
|
"@batijs/trpc": "workspace:^",
|
|
53
54
|
"@batijs/ts-rest": "workspace:*",
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
luciaAuthLogoutHandler,
|
|
17
17
|
luciaAuthSignupHandler,
|
|
18
18
|
luciaCsrfMiddleware,
|
|
19
|
+
luciaDbMiddleware,
|
|
19
20
|
luciaGithubCallbackHandler,
|
|
20
21
|
luciaGithubLoginHandler,
|
|
21
22
|
} from "@batijs/lucia-auth/server/lucia-auth-handlers";
|
|
@@ -30,7 +31,8 @@ import installWhatwgNodeFetch from "@hattip/polyfills/whatwg-node";
|
|
|
30
31
|
import { type NodeHTTPCreateContextFnOptions, nodeHTTPRequestHandler } from "@trpc/server/adapters/node-http";
|
|
31
32
|
import { createApp, createRouter, eventHandler, fromNodeMiddleware, toNodeListener } from "h3";
|
|
32
33
|
import serveStatic from "serve-static";
|
|
33
|
-
import { createHandler, createMiddleware } from "@universal-middleware/h3";
|
|
34
|
+
import { createHandler, createMiddleware, getContext } from "@universal-middleware/h3";
|
|
35
|
+
import { dbMiddleware } from "@batijs/shared-db/server/db-middleware";
|
|
34
36
|
|
|
35
37
|
installWhatwgNodeFetch();
|
|
36
38
|
installGetSetCookie();
|
|
@@ -65,6 +67,13 @@ async function startServer() {
|
|
|
65
67
|
|
|
66
68
|
const router = createRouter();
|
|
67
69
|
|
|
70
|
+
if (BATI.hasDatabase) {
|
|
71
|
+
/**
|
|
72
|
+
* Make database available in Context as `context.db`
|
|
73
|
+
*/
|
|
74
|
+
app.use(createMiddleware(dbMiddleware)());
|
|
75
|
+
}
|
|
76
|
+
|
|
68
77
|
if (BATI.has("authjs") || BATI.has("auth0")) {
|
|
69
78
|
/**
|
|
70
79
|
* Append Auth.js session to context
|
|
@@ -85,6 +94,7 @@ async function startServer() {
|
|
|
85
94
|
}
|
|
86
95
|
|
|
87
96
|
if (BATI.has("lucia-auth")) {
|
|
97
|
+
app.use(createMiddleware(luciaDbMiddleware)());
|
|
88
98
|
app.use(createMiddleware(luciaCsrfMiddleware)());
|
|
89
99
|
app.use(createMiddleware(luciaAuthContextMiddleware)());
|
|
90
100
|
app.use(createMiddleware(luciaAuthCookieMiddleware)());
|
|
@@ -111,7 +121,7 @@ async function startServer() {
|
|
|
111
121
|
path: event.context.params!.path,
|
|
112
122
|
router: appRouter,
|
|
113
123
|
createContext({ req, res }: NodeHTTPCreateContextFnOptions<IncomingMessage, ServerResponse>) {
|
|
114
|
-
return { req, res };
|
|
124
|
+
return { ...getContext(event)!, req, res } as BATI.Any;
|
|
115
125
|
},
|
|
116
126
|
}),
|
|
117
127
|
),
|
|
@@ -48,9 +48,11 @@ var require_package = __commonJS({
|
|
|
48
48
|
"@batijs/lucia-auth": "workspace:*",
|
|
49
49
|
"@batijs/shared-server": "workspace:^",
|
|
50
50
|
"@batijs/shared-todo": "workspace:^",
|
|
51
|
+
"@batijs/shared-db": "workspace:^",
|
|
51
52
|
"@batijs/telefunc": "workspace:^",
|
|
52
53
|
"@batijs/trpc": "workspace:^",
|
|
53
54
|
"@batijs/ts-rest": "workspace:*",
|
|
55
|
+
"@cloudflare/workers-types": "^4.20240821.1",
|
|
54
56
|
"@hattip/adapter-node": "^0.0.47",
|
|
55
57
|
"@hattip/adapter-vercel-edge": "^0.0.47",
|
|
56
58
|
"@hattip/core": "^0.0.47",
|
|
@@ -58,7 +60,7 @@ var require_package = __commonJS({
|
|
|
58
60
|
"@hattip/vite": "^0.0.47",
|
|
59
61
|
"@trpc/server": "^10.45.2",
|
|
60
62
|
"@types/node": "^18.19.14",
|
|
61
|
-
"@universal-middleware/hattip": "^0.2.
|
|
63
|
+
"@universal-middleware/hattip": "^0.2.4",
|
|
62
64
|
"cross-env": "^7.0.3",
|
|
63
65
|
dotenv: "^16.4.5",
|
|
64
66
|
hattip: "^0.0.33",
|
|
@@ -13,22 +13,30 @@ import {
|
|
|
13
13
|
luciaAuthLogoutHandler,
|
|
14
14
|
luciaAuthSignupHandler,
|
|
15
15
|
luciaCsrfMiddleware,
|
|
16
|
+
luciaDbMiddleware,
|
|
16
17
|
luciaGithubCallbackHandler,
|
|
17
18
|
luciaGithubLoginHandler,
|
|
18
19
|
} from "@batijs/lucia-auth/server/lucia-auth-handlers";
|
|
19
20
|
import { createTodoHandler } from "@batijs/shared-server/server/create-todo-handler";
|
|
20
21
|
import { vikeHandler } from "@batijs/shared-server/server/vike-handler";
|
|
21
22
|
import { telefuncHandler } from "@batijs/telefunc/server/telefunc-handler";
|
|
22
|
-
import { appRouter } from "@batijs/trpc/trpc/server";
|
|
23
23
|
import { tsRestHandler } from "@batijs/ts-rest/server/ts-rest-handler";
|
|
24
24
|
import type { HattipHandler } from "@hattip/core";
|
|
25
25
|
import { createRouter } from "@hattip/router";
|
|
26
|
-
import { fetchRequestHandler } from "@trpc/server/adapters/fetch";
|
|
27
26
|
import vercelAdapter from "@hattip/adapter-vercel-edge";
|
|
28
27
|
import { createHandler, createMiddleware } from "@universal-middleware/hattip";
|
|
28
|
+
import { dbMiddleware } from "@batijs/shared-db/server/db-middleware";
|
|
29
|
+
import { trpcHandler } from "@batijs/trpc/server/trpc-handler";
|
|
29
30
|
|
|
30
31
|
const router = createRouter();
|
|
31
32
|
|
|
33
|
+
if (BATI.hasDatabase) {
|
|
34
|
+
/**
|
|
35
|
+
* Make database available in Context as `context.db`
|
|
36
|
+
*/
|
|
37
|
+
router.use(createMiddleware(dbMiddleware)());
|
|
38
|
+
}
|
|
39
|
+
|
|
32
40
|
if (BATI.has("telefunc")) {
|
|
33
41
|
/**
|
|
34
42
|
* Telefunc route
|
|
@@ -44,16 +52,7 @@ if (BATI.has("trpc")) {
|
|
|
44
52
|
*
|
|
45
53
|
* @link {@see https://trpc.io/docs/server/adapters/fetch}
|
|
46
54
|
**/
|
|
47
|
-
router.use("/api/trpc/*", (
|
|
48
|
-
return fetchRequestHandler({
|
|
49
|
-
router: appRouter,
|
|
50
|
-
req: context.request,
|
|
51
|
-
endpoint: "/api/trpc",
|
|
52
|
-
createContext({ req }) {
|
|
53
|
-
return { req };
|
|
54
|
-
},
|
|
55
|
-
});
|
|
56
|
-
});
|
|
55
|
+
router.use("/api/trpc/*", createHandler(trpcHandler)("/api/trpc"));
|
|
57
56
|
}
|
|
58
57
|
|
|
59
58
|
if (BATI.has("ts-rest")) {
|
|
@@ -80,6 +79,7 @@ if (BATI.has("firebase-auth")) {
|
|
|
80
79
|
}
|
|
81
80
|
|
|
82
81
|
if (BATI.has("lucia-auth")) {
|
|
82
|
+
router.use(createMiddleware(luciaDbMiddleware)());
|
|
83
83
|
router.use(createMiddleware(luciaCsrfMiddleware)());
|
|
84
84
|
router.use(createMiddleware(luciaAuthContextMiddleware)());
|
|
85
85
|
router.use(createMiddleware(luciaAuthCookieMiddleware)());
|
|
@@ -51,11 +51,13 @@ var require_package = __commonJS({
|
|
|
51
51
|
"@batijs/telefunc": "workspace:^",
|
|
52
52
|
"@batijs/trpc": "workspace:^",
|
|
53
53
|
"@batijs/ts-rest": "workspace:*",
|
|
54
|
+
"@batijs/shared-db": "workspace:*",
|
|
55
|
+
"@cloudflare/workers-types": "^4.20240821.1",
|
|
54
56
|
"@hono/node-server": "^1.12.2",
|
|
55
|
-
"@hono/vite-dev-server": "^0.15.
|
|
57
|
+
"@hono/vite-dev-server": "^0.15.1",
|
|
56
58
|
"@trpc/server": "^10.45.2",
|
|
57
59
|
"@types/node": "^18.19.14",
|
|
58
|
-
"@universal-middleware/hono": "^0.2.
|
|
60
|
+
"@universal-middleware/hono": "^0.2.5",
|
|
59
61
|
"cross-env": "^7.0.3",
|
|
60
62
|
dotenv: "^16.4.5",
|
|
61
63
|
hono: "^4.5.8",
|
|
@@ -119,7 +121,16 @@ async function getPackageJson(props) {
|
|
|
119
121
|
});
|
|
120
122
|
return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)).then((x) => x.default), {
|
|
121
123
|
devDependencies: ["@hono/vite-dev-server", "@types/node"],
|
|
122
|
-
dependencies: [
|
|
124
|
+
dependencies: [
|
|
125
|
+
"@hono/node-server",
|
|
126
|
+
"@universal-middleware/hono",
|
|
127
|
+
"cross-env",
|
|
128
|
+
"hono",
|
|
129
|
+
"tsx",
|
|
130
|
+
"vite",
|
|
131
|
+
"vike",
|
|
132
|
+
"dotenv"
|
|
133
|
+
]
|
|
123
134
|
});
|
|
124
135
|
}
|
|
125
136
|
export {
|
|
@@ -13,21 +13,29 @@ import {
|
|
|
13
13
|
luciaAuthLogoutHandler,
|
|
14
14
|
luciaAuthSignupHandler,
|
|
15
15
|
luciaCsrfMiddleware,
|
|
16
|
+
luciaDbMiddleware,
|
|
16
17
|
luciaGithubCallbackHandler,
|
|
17
18
|
luciaGithubLoginHandler,
|
|
18
19
|
} from "@batijs/lucia-auth/server/lucia-auth-handlers";
|
|
19
20
|
import { createTodoHandler } from "@batijs/shared-server/server/create-todo-handler";
|
|
20
21
|
import { vikeHandler } from "@batijs/shared-server/server/vike-handler";
|
|
21
22
|
import { telefuncHandler } from "@batijs/telefunc/server/telefunc-handler";
|
|
22
|
-
import { appRouter } from "@batijs/trpc/trpc/server";
|
|
23
23
|
import { tsRestHandler } from "@batijs/ts-rest/server/ts-rest-handler";
|
|
24
|
-
import { type FetchCreateContextFnOptions, fetchRequestHandler } from "@trpc/server/adapters/fetch";
|
|
25
24
|
import { Hono } from "hono";
|
|
26
25
|
import { handle } from "hono/vercel";
|
|
27
26
|
import { createHandler, createMiddleware } from "@universal-middleware/hono";
|
|
27
|
+
import { dbMiddleware } from "@batijs/shared-db/server/db-middleware";
|
|
28
|
+
import { trpcHandler } from "@batijs/trpc/server/trpc-handler";
|
|
28
29
|
|
|
29
30
|
const app = new Hono();
|
|
30
31
|
|
|
32
|
+
if (BATI.hasDatabase) {
|
|
33
|
+
/**
|
|
34
|
+
* Make database available in Context as `context.db`
|
|
35
|
+
*/
|
|
36
|
+
app.use(createMiddleware(dbMiddleware)());
|
|
37
|
+
}
|
|
38
|
+
|
|
31
39
|
if (BATI.has("authjs") || BATI.has("auth0")) {
|
|
32
40
|
/**
|
|
33
41
|
* Append Auth.js session to context
|
|
@@ -48,6 +56,7 @@ if (BATI.has("firebase-auth")) {
|
|
|
48
56
|
}
|
|
49
57
|
|
|
50
58
|
if (BATI.has("lucia-auth")) {
|
|
59
|
+
app.use(createMiddleware(luciaDbMiddleware)());
|
|
51
60
|
app.use(createMiddleware(luciaCsrfMiddleware)());
|
|
52
61
|
app.use(createMiddleware(luciaAuthContextMiddleware)());
|
|
53
62
|
app.use(createMiddleware(luciaAuthCookieMiddleware)());
|
|
@@ -65,16 +74,7 @@ if (BATI.has("trpc")) {
|
|
|
65
74
|
*
|
|
66
75
|
* @link {@see https://trpc.io/docs/server/adapters}
|
|
67
76
|
**/
|
|
68
|
-
app.use("/api/trpc/*", (
|
|
69
|
-
return fetchRequestHandler({
|
|
70
|
-
endpoint: "/api/trpc",
|
|
71
|
-
req: c.req.raw,
|
|
72
|
-
router: appRouter,
|
|
73
|
-
createContext({ req, resHeaders }): FetchCreateContextFnOptions {
|
|
74
|
-
return { req, resHeaders };
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
});
|
|
77
|
+
app.use("/api/trpc/*", createHandler(trpcHandler)("/api/trpc"));
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
if (BATI.has("telefunc")) {
|
|
@@ -43,13 +43,16 @@ var require_package = __commonJS({
|
|
|
43
43
|
devDependencies: {
|
|
44
44
|
"@batijs/compile": "workspace:*",
|
|
45
45
|
"@batijs/drizzle": "workspace:*",
|
|
46
|
+
"@batijs/d1": "workspace:*",
|
|
47
|
+
"@batijs/d1-sqlite": "workspace:*",
|
|
46
48
|
"@batijs/sqlite": "workspace:*",
|
|
49
|
+
"@cloudflare/workers-types": "^4.20240821.1",
|
|
47
50
|
"@lucia-auth/adapter-drizzle": "^1.1.0",
|
|
48
51
|
"@lucia-auth/adapter-sqlite": "^3.0.2",
|
|
49
52
|
"@types/better-sqlite3": "^7.6.11",
|
|
50
53
|
"@types/cookie": "^0.6.0",
|
|
51
54
|
"@types/node": "^18.19.14",
|
|
52
|
-
"@universal-middleware/core": "^0.2.
|
|
55
|
+
"@universal-middleware/core": "^0.2.6",
|
|
53
56
|
arctic: "^1.9.2",
|
|
54
57
|
"better-sqlite3": "^11.2.1",
|
|
55
58
|
cookie: "^0.6.0",
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import "dotenv/config";
|
|
2
|
-
import { Lucia } from "lucia";
|
|
3
|
-
import { BetterSqlite3Adapter } from "@lucia-auth/adapter-sqlite";
|
|
2
|
+
import { Lucia, type Register } from "lucia";
|
|
3
|
+
import { BetterSqlite3Adapter, D1Adapter } from "@lucia-auth/adapter-sqlite";
|
|
4
4
|
import { GitHub } from "arctic";
|
|
5
5
|
import { DrizzleSQLiteAdapter } from "@lucia-auth/adapter-drizzle";
|
|
6
|
-
import {
|
|
7
|
-
import { sessionTable, userTable } from "@batijs/drizzle/database/drizzle/schema/lucia-auth";
|
|
6
|
+
import { dbD1, dbSqlite } from "@batijs/drizzle/database/drizzle/db";
|
|
8
7
|
import { db as sqliteDb } from "@batijs/sqlite/database/sqlite/db";
|
|
8
|
+
import { sessionTable, userTable } from "@batijs/drizzle/database/drizzle/schema/lucia-auth";
|
|
9
|
+
import { D1Database } from "@cloudflare/workers-types";
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Polyfill needed if you're using Node.js 18 or below
|
|
@@ -20,40 +21,57 @@ if (!globalThis.crypto) {
|
|
|
20
21
|
});
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
24
|
+
export function initializeLucia(
|
|
25
|
+
db: BATI.If<
|
|
26
|
+
{
|
|
27
|
+
'BATI.has("sqlite") && !BATI.hasD1': ReturnType<typeof sqliteDb>;
|
|
28
|
+
'BATI.has("drizzle") && !BATI.hasD1': ReturnType<typeof dbSqlite>;
|
|
29
|
+
'BATI.has("drizzle")': ReturnType<typeof dbD1>;
|
|
30
|
+
"BATI.hasD1": D1Database;
|
|
31
|
+
},
|
|
32
|
+
"union"
|
|
33
|
+
>,
|
|
34
|
+
) {
|
|
35
|
+
/**
|
|
36
|
+
* Database setup
|
|
37
|
+
*
|
|
38
|
+
* @link {@see https://lucia-auth.com/database/#database-setup}
|
|
39
|
+
**/
|
|
40
|
+
const adapter = BATI.has("drizzle")
|
|
41
|
+
? new DrizzleSQLiteAdapter(db as BATI.Any, sessionTable, userTable)
|
|
42
|
+
: BATI.hasD1
|
|
43
|
+
? new D1Adapter(db as BATI.Any, {
|
|
44
|
+
user: "users",
|
|
45
|
+
session: "sessions",
|
|
46
|
+
})
|
|
47
|
+
: new BetterSqlite3Adapter(db as BATI.Any, {
|
|
48
|
+
user: "users",
|
|
49
|
+
session: "sessions",
|
|
50
|
+
});
|
|
34
51
|
|
|
35
|
-
/**
|
|
36
|
-
* Initialize Lucia
|
|
37
|
-
*
|
|
38
|
-
* @link {@see https://lucia-auth.com/getting-started/#initialize-lucia}
|
|
39
|
-
*/
|
|
40
|
-
export const lucia = new Lucia(adapter, {
|
|
41
52
|
/**
|
|
42
|
-
* Lucia
|
|
53
|
+
* Initialize Lucia
|
|
43
54
|
*
|
|
44
|
-
* @link {@see https://lucia-auth.com/
|
|
55
|
+
* @link {@see https://lucia-auth.com/getting-started/#initialize-lucia}
|
|
45
56
|
*/
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
57
|
+
return new Lucia(adapter, {
|
|
58
|
+
/**
|
|
59
|
+
* Lucia Configuration
|
|
60
|
+
*
|
|
61
|
+
* @link {@see https://lucia-auth.com/basics/configuration}
|
|
62
|
+
*/
|
|
63
|
+
sessionCookie: {
|
|
64
|
+
attributes: {
|
|
65
|
+
secure: process.env.NODE_ENV === "production",
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
getUserAttributes: (attributes) => {
|
|
69
|
+
return {
|
|
70
|
+
username: attributes.username,
|
|
71
|
+
};
|
|
49
72
|
},
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return {
|
|
53
|
-
username: attributes.username,
|
|
54
|
-
};
|
|
55
|
-
},
|
|
56
|
-
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
57
75
|
|
|
58
76
|
/**
|
|
59
77
|
* Initialize OAuth provider
|
|
@@ -69,25 +87,43 @@ export const github = new GitHub(process.env.GITHUB_CLIENT_ID as string, process
|
|
|
69
87
|
*/
|
|
70
88
|
declare module "lucia" {
|
|
71
89
|
interface Register {
|
|
72
|
-
Lucia: typeof
|
|
90
|
+
Lucia: ReturnType<typeof initializeLucia>;
|
|
73
91
|
DatabaseUserAttributes: Omit<DatabaseUser, "id">;
|
|
74
92
|
}
|
|
75
93
|
}
|
|
76
94
|
|
|
95
|
+
declare global {
|
|
96
|
+
namespace Universal {
|
|
97
|
+
interface Context {
|
|
98
|
+
lucia: Register["Lucia"];
|
|
99
|
+
db: BATI.If<{
|
|
100
|
+
'BATI.has("sqlite") && !BATI.hasD1': ReturnType<typeof sqliteDb>;
|
|
101
|
+
'BATI.has("drizzle") && !BATI.hasD1': ReturnType<typeof dbSqlite>;
|
|
102
|
+
'BATI.has("drizzle")': ReturnType<typeof dbD1>;
|
|
103
|
+
"BATI.hasD1": D1Database;
|
|
104
|
+
}>;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
77
109
|
export interface DatabaseUser {
|
|
78
110
|
id: string;
|
|
79
111
|
username: string;
|
|
80
|
-
password?: string;
|
|
112
|
+
password?: string | null;
|
|
81
113
|
}
|
|
82
114
|
|
|
115
|
+
//# !BATI.has("drizzle")
|
|
83
116
|
export interface DatabaseOAuthAccount {
|
|
84
117
|
provider_id: string;
|
|
85
118
|
provider_user_id: string;
|
|
86
|
-
/*{ @if (it.BATI.has("drizzle")) }*/
|
|
87
|
-
userId: string;
|
|
88
|
-
/*{ #else }*/
|
|
89
119
|
user_id: string;
|
|
90
|
-
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
//# BATI.has("drizzle")
|
|
123
|
+
export interface DatabaseOAuthAccount {
|
|
124
|
+
providerId: string;
|
|
125
|
+
providerUserId: string;
|
|
126
|
+
userId: string;
|
|
91
127
|
}
|
|
92
128
|
|
|
93
129
|
export interface GitHubUser {
|