@batijs/cli 0.0.184 → 0.0.186

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.
@@ -0,0 +1,121 @@
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/hono",
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.29.0",
45
+ "@batijs/compile": "workspace:*",
46
+ "@batijs/firebase-auth": "workspace:*",
47
+ "@batijs/trpc": "workspace:^",
48
+ "@hono/node-server": "^1.11.1",
49
+ "@hono/vite-dev-server": "^0.12.0",
50
+ "@trpc/server": "^10.45.2",
51
+ "@types/node": "^18.19.14",
52
+ "firebase-admin": "^12.1.0",
53
+ hono: "^4.2.9",
54
+ telefunc: "^0.1.72",
55
+ tsx: "^4.7.2",
56
+ vike: "^0.4.168",
57
+ "vike-authjs": "^0.1.5",
58
+ vite: "^5.2.8"
59
+ },
60
+ dependencies: {
61
+ "@batijs/core": "workspace:*"
62
+ },
63
+ files: [
64
+ "dist/"
65
+ ],
66
+ bati: {
67
+ if: {
68
+ flag: "hono"
69
+ }
70
+ },
71
+ exports: {
72
+ "./hono-entry": {
73
+ types: "./dist/types/hono-entry.d.ts"
74
+ }
75
+ },
76
+ typesVersions: {
77
+ "*": {
78
+ "hono-entry": [
79
+ "./dist/types/hono-entry.d.ts"
80
+ ]
81
+ }
82
+ }
83
+ };
84
+ }
85
+ });
86
+
87
+ // files/$package.json.ts
88
+ import { addDependency, loadAsJson, setScripts } from "@batijs/core";
89
+ async function getPackageJson(props) {
90
+ const packageJson = await loadAsJson(props);
91
+ setScripts(packageJson, {
92
+ dev: {
93
+ value: "vite",
94
+ precedence: 20,
95
+ warnIfReplaced: true
96
+ },
97
+ build: {
98
+ value: "vite build",
99
+ precedence: 1,
100
+ warnIfReplaced: true
101
+ },
102
+ preview: {
103
+ value: "NODE_ENV=production tsx ./hono-entry.ts",
104
+ precedence: 20
105
+ }
106
+ });
107
+ return addDependency(packageJson, await Promise.resolve().then(() => __toESM(require_package(), 1)).then((x) => x.default), {
108
+ devDependencies: ["@hono/vite-dev-server", "@types/node"],
109
+ dependencies: [
110
+ "@hono/node-server",
111
+ "hono",
112
+ "tsx",
113
+ "vite",
114
+ "vike",
115
+ ...props.meta.BATI.has("authjs") ? ["@auth/core", "vike-authjs"] : []
116
+ ]
117
+ });
118
+ }
119
+ export {
120
+ getPackageJson as default
121
+ };
@@ -0,0 +1,26 @@
1
+ // files/$vite.config.ts.ts
2
+ import { addVitePlugin, loadAsMagicast } from "@batijs/core";
3
+ async function getViteConfig(props) {
4
+ const mod = await loadAsMagicast(props);
5
+ addVitePlugin(mod, {
6
+ from: "@hono/vite-dev-server",
7
+ constructor: "devServer",
8
+ options: {
9
+ entry: "hono-entry.ts",
10
+ exclude: [
11
+ /^\/@.+$/,
12
+ /.*\.(ts|tsx|vue)($|\?)/,
13
+ /.*\.(s?css|less)($|\?)/,
14
+ /^\/favicon\.ico$/,
15
+ /.*\.(svg|png)($|\?)/,
16
+ /^\/(public|assets|static)\/.+/,
17
+ /^\/node_modules\/.*/
18
+ ],
19
+ injectClientScript: false
20
+ }
21
+ });
22
+ return mod.generate().code;
23
+ }
24
+ export {
25
+ getViteConfig as default
26
+ };
@@ -0,0 +1,183 @@
1
+ import CredentialsProvider from "@auth/core/providers/credentials";
2
+ import { firebaseAdmin } from "@batijs/firebase-auth/libs/firebaseAdmin";
3
+ import { appRouter } from "@batijs/trpc/trpc/server";
4
+ import { serve } from "@hono/node-server";
5
+ import { serveStatic } from "@hono/node-server/serve-static";
6
+ import { fetchRequestHandler, type FetchCreateContextFnOptions } from "@trpc/server/adapters/fetch";
7
+ import { getAuth } from "firebase-admin/auth";
8
+ import { Hono } from "hono";
9
+ import { compress } from "hono/compress";
10
+ import { deleteCookie, getCookie, setCookie } from "hono/cookie";
11
+ import { telefunc } from "telefunc";
12
+ import { VikeAuth } from "vike-authjs";
13
+ import { renderPage } from "vike/server";
14
+
15
+ const isProduction = process.env.NODE_ENV === "production";
16
+ const port = process.env.PORT ? parseInt(process.env.PORT, 10) : 3000;
17
+
18
+ const app = new Hono();
19
+
20
+ app.use(compress());
21
+
22
+ if (isProduction) {
23
+ app.use(
24
+ "/*",
25
+ serveStatic({
26
+ root: `dist/client/`,
27
+ }),
28
+ );
29
+ }
30
+
31
+ if (BATI.has("authjs")) {
32
+ /**
33
+ * AuthJS
34
+ *
35
+ * TODO: Replace secret {@see https://authjs.dev/reference/core#secret}
36
+ * TODO: Choose and implement providers
37
+ *
38
+ * @link {@see https://authjs.dev/guides/providers/custom-provider}
39
+ **/
40
+ const Auth = VikeAuth({
41
+ secret: "MY_SECRET",
42
+ providers: [
43
+ CredentialsProvider({
44
+ name: "Credentials",
45
+ credentials: {
46
+ username: { label: "Username", type: "text", placeholder: "jsmith" },
47
+ password: { label: "Password", type: "password" },
48
+ },
49
+ async authorize() {
50
+ // Add logic here to look up the user from the credentials supplied
51
+ const user = { id: "1", name: "J Smith", email: "jsmith@example.com" };
52
+
53
+ // Any object returned will be saved in `user` property of the JWT
54
+ // If you return null then an error will be displayed advising the user to check their details.
55
+ // You can also Reject this callback with an Error thus the user will be sent to the error page with the error message as a query parameter
56
+ return user ?? null;
57
+ },
58
+ }),
59
+ ],
60
+ });
61
+
62
+ app.use("/api/auth/**", (c) =>
63
+ Auth({
64
+ request: c.req.raw,
65
+ }),
66
+ );
67
+ }
68
+
69
+ if (BATI.has("firebase-auth")) {
70
+ app.use(async (c, next) => {
71
+ const sessionCookie: string = getCookie(c, "__session") || "";
72
+ if (sessionCookie) {
73
+ const auth = getAuth(firebaseAdmin);
74
+ try {
75
+ const decodedIdToken = await auth.verifySessionCookie(sessionCookie, true);
76
+ const user = await auth.getUser(decodedIdToken.sub);
77
+ c.set("user", user);
78
+ } catch (error) {
79
+ console.debug("verifySessionCookie:", error);
80
+ c.set("user", null);
81
+ }
82
+ }
83
+ await next();
84
+ });
85
+
86
+ app.post("/api/sessionLogin", async (c) => {
87
+ const body = await c.req.json();
88
+ const idToken: string = body.idToken || "";
89
+
90
+ let expiresIn = 60 * 60 * 24 * 5 * 1000; // 5 days. The auth.createSessionCookie() function of Firebase expects time to be specified in miliseconds.
91
+
92
+ const auth = getAuth(firebaseAdmin);
93
+ try {
94
+ const sessionCookie = await auth.createSessionCookie(idToken, { expiresIn });
95
+ const options = { maxAge: expiresIn, httpOnly: true, secure: true };
96
+
97
+ expiresIn = 60 * 60 * 24 * 5; // 5 days. The setCookie() function of Hono expects time to be specified in seconds.
98
+ setCookie(c, "__session", sessionCookie, options);
99
+
100
+ return c.json({ status: "success" }, 200);
101
+ } catch (error) {
102
+ console.error("createSessionCookie failed :", error);
103
+ return c.text("Unathorized", 401);
104
+ }
105
+ });
106
+
107
+ app.post("/api/sessionLogout", (c) => {
108
+ deleteCookie(c, "__session");
109
+ return c.text("Logged Out", 200);
110
+ });
111
+ }
112
+
113
+ if (BATI.has("trpc")) {
114
+ /**
115
+ * tRPC route
116
+ *
117
+ * @link {@see https://trpc.io/docs/server/adapters}
118
+ **/
119
+ app.use("/api/trpc/*", (c) => {
120
+ return fetchRequestHandler({
121
+ endpoint: "/api/trpc",
122
+ req: c.req.raw,
123
+ router: appRouter,
124
+ createContext({ req, resHeaders }): FetchCreateContextFnOptions {
125
+ return { req, resHeaders };
126
+ },
127
+ });
128
+ });
129
+ }
130
+
131
+ if (BATI.has("telefunc")) {
132
+ /**
133
+ * Telefunc route
134
+ *
135
+ * @link {@see https://telefunc.com}
136
+ **/
137
+ app.post("/_telefunc", async (c) => {
138
+ const httpResponse = await telefunc({
139
+ url: c.req.url.toString(),
140
+ method: c.req.method,
141
+ body: await c.req.text(),
142
+ context: c,
143
+ });
144
+ const { body, statusCode, contentType } = httpResponse;
145
+
146
+ c.status(statusCode);
147
+ c.header("Content-Type", contentType);
148
+
149
+ return c.body(body);
150
+ });
151
+ }
152
+
153
+ app.all("*", async (c, next) => {
154
+ const pageContextInit = BATI.has("firebase-auth")
155
+ ? {
156
+ urlOriginal: c.req.url,
157
+ user: c.get("user"),
158
+ }
159
+ : {
160
+ urlOriginal: c.req.url,
161
+ };
162
+ const pageContext = await renderPage(pageContextInit);
163
+ const { httpResponse } = pageContext;
164
+ if (!httpResponse) {
165
+ return next();
166
+ } else {
167
+ const { body, statusCode, headers } = httpResponse;
168
+ headers.forEach(([name, value]) => c.header(name, value));
169
+ c.status(statusCode);
170
+
171
+ return c.body(body);
172
+ }
173
+ });
174
+
175
+ if (isProduction) {
176
+ console.log(`Server listening on http://localhost:${port}`);
177
+ serve({
178
+ fetch: app.fetch,
179
+ port: port,
180
+ });
181
+ }
182
+
183
+ export default app;
@@ -0,0 +1,10 @@
1
+ import type { UserRecord } from "firebase-admin/auth";
2
+
3
+ //# BATI.has("firebase-auth")
4
+ declare module "hono" {
5
+ interface ContextVariableMap {
6
+ user?: UserRecord | null;
7
+ }
8
+ }
9
+
10
+ export {};
@@ -0,0 +1,3 @@
1
+ import { Hono } from "hono";
2
+ declare const app: Hono<import("hono").Env, import("hono/types").BlankSchema, "/">;
3
+ export default app;
@@ -98,6 +98,17 @@
98
98
  "files"
99
99
  ]
100
100
  },
101
+ {
102
+ "config": {
103
+ "if": {
104
+ "flag": "hono"
105
+ }
106
+ },
107
+ "folder": "@batijs/hono",
108
+ "subfolders": [
109
+ "files"
110
+ ]
111
+ },
101
112
  {
102
113
  "config": {
103
114
  "if": {
package/dist/index.js CHANGED
@@ -1537,7 +1537,7 @@ var createDefaultQueryTester = function(query, options) {
1537
1537
  // package.json
1538
1538
  var package_default = {
1539
1539
  name: "@batijs/cli",
1540
- version: "0.0.184",
1540
+ version: "0.0.186",
1541
1541
  type: "module",
1542
1542
  scripts: {
1543
1543
  "check-types": "tsc --noEmit",
@@ -1596,11 +1596,14 @@ var rulesMessages = {
1596
1596
  [RulesMessage.ERROR_AUTH_R_SERVER]: error(
1597
1597
  `A ${inverse(bold("Server"))} is required when using ${inverse(
1598
1598
  bold("Auth")
1599
- )}. Check https://vite-plugin-ssr.com/integration#server-side-tools for details and https://batijs.dev for available servers`
1599
+ )}. Check https://vike.dev/integration#server-side-tools for details and https://batijs.dev for available servers`
1600
1600
  ),
1601
1601
  [RulesMessage.ERROR_COMPILED_R_REACT]: error(
1602
1602
  `${inverse(bold("React"))} is required when using ${inverse(bold("Compiled"))}.`
1603
1603
  ),
1604
+ [RulesMessage.ERROR_AUTH0_E_HONO]: error(
1605
+ `${inverse(bold("Auth0"))} does not support running on ${inverse(bold("Hono"))} with official plugins. Check https://batijs.dev for details`
1606
+ ),
1604
1607
  [RulesMessage.INFO_HATTIP]: info(`${inverse(bold("HatTip"))} is an experimental project`)
1605
1608
  };
1606
1609
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@batijs/cli",
3
- "version": "0.0.184",
3
+ "version": "0.0.186",
4
4
  "type": "module",
5
5
  "keywords": [],
6
6
  "description": "Next-gen scaffolder. Get started with fully-functional apps, and choose any tool you want",
@@ -19,12 +19,12 @@
19
19
  "tsup": "^8.0.2",
20
20
  "typescript": "^5.4.5",
21
21
  "vite": "^5.2.11",
22
- "@batijs/compile": "0.0.184",
23
- "@batijs/build": "0.0.184"
22
+ "@batijs/compile": "0.0.186",
23
+ "@batijs/build": "0.0.186"
24
24
  },
25
25
  "dependencies": {
26
- "@batijs/features": "0.0.184",
27
- "@batijs/core": "0.0.184"
26
+ "@batijs/features": "0.0.186",
27
+ "@batijs/core": "0.0.186"
28
28
  },
29
29
  "bin": "./dist/index.js",
30
30
  "exports": {