@seip/bluebird-js 0.1.7 → 0.2.1
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/AGENTS.md +727 -620
- package/README.md +670 -607
- package/app/models/user.js +19 -0
- package/app/resources/html/home.html +137 -0
- package/app/resources/html/layouts/main.html +55 -0
- package/app/resources/html/notFound.html +14 -0
- package/app/resources/html/table.html +15 -0
- package/app/resources/html/terms.html +46 -0
- package/app/resources/index.html +27 -0
- package/app/resources/layouts/AppLayout.jsx +92 -0
- package/app/resources/main.jsx +18 -0
- package/app/resources/pages/Dashboard.jsx +93 -0
- package/app/resources/pages/Home.jsx +140 -0
- package/app/resources/pages/Login.jsx +35 -0
- package/app/resources/pages/NotFound.jsx +16 -0
- package/app/resources/pages/Register.jsx +55 -0
- package/app/resources/pages/TableDemo.jsx +85 -0
- package/app/resources/routes.jsx +59 -0
- package/app/resources/spa.js +73 -0
- package/app/resources/styles.css +9 -0
- package/app/routes/api.js +129 -50
- package/app/routes/auth.js +209 -0
- package/app/routes/web.js +89 -47
- package/core/ai.js +30 -10
- package/core/app.d.ts +2 -18
- package/core/app.js +987 -801
- package/core/auth.d.ts +2 -13
- package/core/auth.js +444 -326
- package/core/cli/build.js +37 -0
- package/core/cli/dev.js +155 -0
- package/core/cli/doctor.js +37 -2
- package/core/cli/export.js +191 -0
- package/core/cli/init.js +91 -322
- package/core/cli/nginx.js +1 -1
- package/core/cli/templates.js +139 -0
- package/core/cli/view.js +98 -161
- package/core/config.js +44 -2
- package/core/csrf.js +156 -24
- package/core/database.js +1184 -1131
- package/core/debug.js +1 -1
- package/core/html.js +8 -1
- package/core/index.d.ts +126 -310
- package/core/paths.js +55 -0
- package/core/ratelimit.js +10 -1
- package/core/react/client/api.js +239 -0
- package/core/react/client/auth.js +236 -0
- package/core/react/client/components.js +1321 -0
- package/core/react/client/datatable.js +595 -0
- package/core/react/client/i18n.js +440 -0
- package/core/react/client/index.d.ts +314 -0
- package/core/react/client/index.js +50 -0
- package/core/react/client/router.js +26 -0
- package/core/react/client/theme.css +512 -0
- package/core/render-cache.js +250 -212
- package/core/render.d.ts +25 -21
- package/core/render.js +738 -736
- package/core/router.d.ts +2 -3
- package/core/router.js +171 -171
- package/core/seo.js +10 -0
- package/core/spa.js +599 -0
- package/core/view-loader.js +155 -613
- package/core/vite-plugin.d.ts +18 -0
- package/core/vite-plugin.js +162 -0
- package/core/vite.js +250 -145
- package/index.js +22 -18
- package/jsconfig.json +5 -3
- package/package.json +114 -92
- package/production.md +8 -3
- package/public/js/bluebird.js +1886 -0
- package/templates/_auth/app/database.js +19 -0
- package/templates/_auth/app/models/user.js +22 -0
- package/templates/_auth/app/routes/auth-router.js +304 -0
- package/templates/_base/app/resources/html/layouts/main.html +55 -0
- package/templates/_base/app/resources/html/notFound.html +14 -0
- package/templates/_base/app/resources/index.html +27 -0
- package/templates/_base/app/resources/styles.css +9 -0
- package/templates/api/app/models/note.js +18 -0
- package/templates/api/app/routes/api.js +82 -0
- package/templates/api/app/routes/auth.js +11 -0
- package/templates/api/index.js +19 -0
- package/templates/api/template.json +13 -0
- package/templates/auth/app/mail.js +11 -0
- package/templates/auth/app/models/password_reset.js +18 -0
- package/templates/auth/app/resources/html/home.html +21 -0
- package/templates/auth/app/resources/html/partials/nav.html +2 -0
- package/templates/auth/app/resources/layouts/AppLayout.jsx +60 -0
- package/templates/auth/app/resources/main.jsx +18 -0
- package/templates/auth/app/resources/pages/Dashboard.jsx +51 -0
- package/templates/auth/app/resources/pages/ForgotPassword.jsx +34 -0
- package/templates/auth/app/resources/pages/Login.jsx +36 -0
- package/templates/auth/app/resources/pages/NotFound.jsx +16 -0
- package/templates/auth/app/resources/pages/Profile.jsx +99 -0
- package/templates/auth/app/resources/pages/Register.jsx +50 -0
- package/templates/auth/app/resources/pages/ResetPassword.jsx +50 -0
- package/templates/auth/app/resources/routes.jsx +54 -0
- package/templates/auth/app/resources/spa.js +29 -0
- package/templates/auth/app/routes/api.js +17 -0
- package/templates/auth/app/routes/auth.js +13 -0
- package/templates/auth/app/routes/web.js +21 -0
- package/templates/auth/index.js +19 -0
- package/templates/auth/template.json +15 -0
- package/templates/blank/app/models/.gitkeep +0 -0
- package/templates/blank/app/resources/html/home.html +27 -0
- package/templates/blank/app/resources/html/partials/nav.html +1 -0
- package/templates/blank/app/resources/main.jsx +16 -0
- package/templates/blank/app/resources/pages/Home.jsx +42 -0
- package/templates/blank/app/resources/pages/NotFound.jsx +27 -0
- package/templates/blank/app/resources/routes.jsx +15 -0
- package/templates/blank/app/resources/spa.js +24 -0
- package/templates/blank/app/routes/api.js +11 -0
- package/templates/blank/app/routes/web.js +21 -0
- package/templates/blank/index.js +13 -0
- package/templates/blank/template.json +12 -0
- package/templates/blog/app/lib/blog.js +149 -0
- package/templates/blog/app/models/post.js +22 -0
- package/templates/blog/app/resources/html/home.html +28 -0
- package/templates/blog/app/resources/html/not-found.html +5 -0
- package/templates/blog/app/resources/html/partials/nav.html +2 -0
- package/templates/blog/app/resources/html/partials/post-card.html +9 -0
- package/templates/blog/app/resources/html/post.html +8 -0
- package/templates/blog/app/resources/layouts/AdminLayout.jsx +54 -0
- package/templates/blog/app/resources/main.jsx +18 -0
- package/templates/blog/app/resources/pages/Login.jsx +31 -0
- package/templates/blog/app/resources/pages/NotFound.jsx +16 -0
- package/templates/blog/app/resources/pages/PostEditor.jsx +51 -0
- package/templates/blog/app/resources/pages/Posts.jsx +83 -0
- package/templates/blog/app/resources/pages/Register.jsx +43 -0
- package/templates/blog/app/resources/routes.jsx +51 -0
- package/templates/blog/app/resources/spa.js +25 -0
- package/templates/blog/app/resources/styles.css +40 -0
- package/templates/blog/app/routes/api.js +77 -0
- package/templates/blog/app/routes/auth.js +10 -0
- package/templates/blog/app/routes/web.js +114 -0
- package/templates/blog/index.js +21 -0
- package/templates/blog/template.json +14 -0
- package/vite.config.js +11 -0
- package/app/views/components/Header.jsx +0 -42
- package/app/views/components/LiveCounter.jsx +0 -67
- package/app/views/layouts/main/view.jsx +0 -201
- package/app/views/legal/terms.html +0 -29
- package/app/views/pages/about.jsx +0 -98
- package/app/views/pages/dashboard.jsx +0 -278
- package/app/views/pages/index.jsx +0 -123
- package/app/views/pages/login.jsx +0 -141
- package/core/actions.d.ts +0 -4
- package/core/actions.js +0 -355
- package/core/jsx.d.ts +0 -38
- package/core/jsx.js +0 -1597
- package/core/vite.d.ts +0 -3
- package/public/js/bluebird-client.js +0 -3265
- package/public/js/tailwind.js +0 -8
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import Router from "@seip/bluebird-js/core/router.js";
|
|
2
|
+
import Auth from "@seip/bluebird-js/core/auth.js";
|
|
3
|
+
import Hash from "@seip/bluebird-js/core/hash.js";
|
|
4
|
+
import Validator from "@seip/bluebird-js/core/validate.js";
|
|
5
|
+
import App from "@seip/bluebird-js/core/app.js";
|
|
6
|
+
import Csrf from "@seip/bluebird-js/core/csrf.js";
|
|
7
|
+
import { DB_TYPE } from "@seip/bluebird-js/core/database.js";
|
|
8
|
+
import User from "../models/user.js";
|
|
9
|
+
|
|
10
|
+
/** @type {Promise<string>|null} */
|
|
11
|
+
let dummyHash = null;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Verifies a password in constant work: unknown emails are checked against a dummy hash so response
|
|
15
|
+
* times do not reveal which accounts exist.
|
|
16
|
+
* @param {string} password
|
|
17
|
+
* @param {string|undefined} storedHash
|
|
18
|
+
* @returns {Promise<boolean>}
|
|
19
|
+
*/
|
|
20
|
+
async function verifyPassword(password, storedHash) {
|
|
21
|
+
if (storedHash) return Hash.verify(password, storedHash);
|
|
22
|
+
dummyHash ??= Hash.make("bluebird-dummy-password");
|
|
23
|
+
await Hash.verify(password, await dummyHash);
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Strips sensitive fields and returns a public user summary for tokens and API responses.
|
|
29
|
+
* @param {Object} user
|
|
30
|
+
* @returns {{ id: number|string, name: string, email: string, role: string }}
|
|
31
|
+
*/
|
|
32
|
+
function toPublicUser(user) {
|
|
33
|
+
return {
|
|
34
|
+
id: user.id,
|
|
35
|
+
name: user.name,
|
|
36
|
+
email: user.email,
|
|
37
|
+
role: user.role || "user",
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Signs the user in. Browser sessions receive an HttpOnly cookie; bearer clients (`X-Auth-Mode: token`,
|
|
43
|
+
* used by static exports in Electron/Capacitor) receive the token in the JSON body instead.
|
|
44
|
+
* @param {import('express').Request} req
|
|
45
|
+
* @param {import('express').Response} res
|
|
46
|
+
* @param {Object} publicUser
|
|
47
|
+
* @returns {Promise<{ user: Object, token?: string }>}
|
|
48
|
+
*/
|
|
49
|
+
async function issueSession(req, res, publicUser) {
|
|
50
|
+
const tokenMode = String(req.headers["x-auth-mode"] || "").toLowerCase() === "token";
|
|
51
|
+
const token = await Auth.login(res, publicUser, "auth", tokenMode ? { setCookie: false } : {});
|
|
52
|
+
return tokenMode ? { user: publicUser, token } : { user: publicUser };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Creates a REST authentication router (`/login`, `/logout`, `/me`, and optional `/register`).
|
|
57
|
+
* Registration is disabled by default and enabled via `{ register: true }`.
|
|
58
|
+
* @param {Object} [options={}]
|
|
59
|
+
* @param {string} [options.basePath="/api/auth"] - Base mount path.
|
|
60
|
+
* @param {boolean} [options.register=false] - Enable `POST /register`.
|
|
61
|
+
* @param {string} [options.defaultRole="user"] - Default role assigned to newly registered users.
|
|
62
|
+
* @param {Object|false} [options.rateLimit] - Rate limiting config applied to login and registration.
|
|
63
|
+
* @returns {Router}
|
|
64
|
+
*/
|
|
65
|
+
export function createAuthRouter(options = {}) {
|
|
66
|
+
const {
|
|
67
|
+
basePath = "/api/auth",
|
|
68
|
+
register = false,
|
|
69
|
+
defaultRole = "user",
|
|
70
|
+
rateLimit = { max: 25, windowMs: 60000 },
|
|
71
|
+
} = options;
|
|
72
|
+
|
|
73
|
+
const routerAuth = new Router(basePath);
|
|
74
|
+
routerAuth.use(Csrf.middleware());
|
|
75
|
+
const memoryUsers = new Map();
|
|
76
|
+
let schemaReady = false;
|
|
77
|
+
let memorySeq = 1;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Ensures the `users` table exists when backed by a SQL database.
|
|
81
|
+
* @returns {Promise<void>}
|
|
82
|
+
*/
|
|
83
|
+
async function ensureUsersTable() {
|
|
84
|
+
if (schemaReady || DB_TYPE === "none") return;
|
|
85
|
+
const db = User.getDatabase();
|
|
86
|
+
await db.init();
|
|
87
|
+
await db.query(User.toDDL(db.type));
|
|
88
|
+
schemaReady = true;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Finds a user record by email including the hashed password field.
|
|
93
|
+
* @param {string} email
|
|
94
|
+
* @returns {Promise<Object|null>}
|
|
95
|
+
*/
|
|
96
|
+
async function findByEmail(email) {
|
|
97
|
+
const cleanEmail = String(email || "").trim().toLowerCase();
|
|
98
|
+
if (DB_TYPE === "none") {
|
|
99
|
+
return memoryUsers.get(cleanEmail) || null;
|
|
100
|
+
}
|
|
101
|
+
await ensureUsersTable();
|
|
102
|
+
return User.find({ email: cleanEmail }, { withHidden: true });
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Creates a user record with a hashed password and default role.
|
|
107
|
+
* @param {{ name: string, email: string, password: string, role: string }} payload
|
|
108
|
+
* @returns {Promise<Object>}
|
|
109
|
+
*/
|
|
110
|
+
async function createUser(payload) {
|
|
111
|
+
const cleanEmail = String(payload.email || "").trim().toLowerCase();
|
|
112
|
+
if (DB_TYPE === "none") {
|
|
113
|
+
const record = {
|
|
114
|
+
id: memorySeq++,
|
|
115
|
+
name: String(payload.name).trim(),
|
|
116
|
+
email: cleanEmail,
|
|
117
|
+
password: await Hash.make(payload.password),
|
|
118
|
+
role: payload.role || defaultRole,
|
|
119
|
+
};
|
|
120
|
+
memoryUsers.set(cleanEmail, record);
|
|
121
|
+
return record;
|
|
122
|
+
}
|
|
123
|
+
await ensureUsersTable();
|
|
124
|
+
const id = await User.create({
|
|
125
|
+
name: String(payload.name).trim(),
|
|
126
|
+
email: cleanEmail,
|
|
127
|
+
password: payload.password,
|
|
128
|
+
role: payload.role || defaultRole,
|
|
129
|
+
});
|
|
130
|
+
return User.find(id);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const loginValidator = new Validator(
|
|
134
|
+
{
|
|
135
|
+
email: { required: true, email: true },
|
|
136
|
+
password: { required: true, min: 6 },
|
|
137
|
+
},
|
|
138
|
+
"en"
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
const registerValidator = new Validator(
|
|
142
|
+
{
|
|
143
|
+
name: { required: true, min: 2, max: 150 },
|
|
144
|
+
email: { required: true, email: true },
|
|
145
|
+
password: { required: true, min: 6, max: 120 },
|
|
146
|
+
},
|
|
147
|
+
"en"
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
const limiter = rateLimit ? App.rateLimit(rateLimit) : (req, res, next) => next();
|
|
151
|
+
|
|
152
|
+
routerAuth.get("/me", Auth.optional(), (req, res) => {
|
|
153
|
+
const user = req.user ? toPublicUser(req.user) : null;
|
|
154
|
+
res.ok(
|
|
155
|
+
{
|
|
156
|
+
user,
|
|
157
|
+
authenticated: Boolean(user),
|
|
158
|
+
registerEnabled: Boolean(register),
|
|
159
|
+
},
|
|
160
|
+
user ? "Authenticated" : "Guest session"
|
|
161
|
+
);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
routerAuth.post("/login", limiter, loginValidator.middleware(), async (req, res) => {
|
|
165
|
+
const email = String(req.body.email || "").trim().toLowerCase();
|
|
166
|
+
const password = String(req.body.password || "");
|
|
167
|
+
const found = await findByEmail(email);
|
|
168
|
+
|
|
169
|
+
if (!(await verifyPassword(password, found?.password))) {
|
|
170
|
+
return res.error("Invalid email or password", 401, [
|
|
171
|
+
{ field: "email", message: "Invalid email or password" },
|
|
172
|
+
]);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return res.ok(await issueSession(req, res, toPublicUser(found)), "Signed in");
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
routerAuth.post("/register", limiter, registerValidator.middleware(), async (req, res) => {
|
|
179
|
+
if (!register) {
|
|
180
|
+
return res.forbidden("Registration is disabled");
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const email = String(req.body.email || "").trim().toLowerCase();
|
|
184
|
+
const existing = await findByEmail(email);
|
|
185
|
+
if (existing) {
|
|
186
|
+
return res.error("Email is already registered", 409, [
|
|
187
|
+
{ field: "email", message: "Email is already registered" },
|
|
188
|
+
]);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const created = await createUser({
|
|
192
|
+
name: req.body.name,
|
|
193
|
+
email,
|
|
194
|
+
password: req.body.password,
|
|
195
|
+
role: defaultRole,
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
return res.created(await issueSession(req, res, toPublicUser(created)), "Account created");
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
routerAuth.post("/logout", async (req, res) => {
|
|
202
|
+
await Auth.logout(res, "auth", {}, req);
|
|
203
|
+
return res.ok({ loggedOut: true }, "Signed out");
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
return routerAuth;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export default createAuthRouter({ register: true });
|
package/app/routes/web.js
CHANGED
|
@@ -1,47 +1,89 @@
|
|
|
1
|
-
import Router from "@seip/bluebird-js/core/router.js";
|
|
2
|
-
import Render from "@seip/bluebird-js/core/render.js";
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
1
|
+
import Router from "@seip/bluebird-js/core/router.js";
|
|
2
|
+
import Render from "@seip/bluebird-js/core/render.js";
|
|
3
|
+
import { SafeHtml, escapeHtml, safeJson } from "@seip/bluebird-js/core/html.js";
|
|
4
|
+
import spa from "../resources/spa.js";
|
|
5
|
+
|
|
6
|
+
const routerWeb = new Router("/", { seo: true });
|
|
7
|
+
|
|
8
|
+
routerWeb.get("/", (req, res) => {
|
|
9
|
+
const slides = [
|
|
10
|
+
{
|
|
11
|
+
badge: "HTML SSR",
|
|
12
|
+
title: "Fast HTML {{ }} Templates",
|
|
13
|
+
description: "Serve SEO-ready landings and storefronts directly from app/resources/html/ with layouts, partials, and {{if}} / {{each}}.",
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
badge: "React SPA",
|
|
17
|
+
title: "React Router + Vite on /app",
|
|
18
|
+
description: "Client-side React workspace with zero SSR friction, per-URL SEO metadata, and a full-width skeleton in #root.",
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
badge: "Auth & UI",
|
|
22
|
+
title: "Tailwind v4 Dark & Light Ready",
|
|
23
|
+
description: "Built-in AuthProvider with optional roles, vanilla data-* helpers, and reusable React UI components.",
|
|
24
|
+
},
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
const features = [
|
|
28
|
+
{ name: "HTML SSR Engine", detail: "{{var}}, {{{raw}}}, {{if}}/{{else}}, {{each}}, {{> partial}}" },
|
|
29
|
+
{ name: "Router.spa()", detail: "Per-URL title, meta, keywords, JSON-LD, canonical, and skeleton" },
|
|
30
|
+
{ name: "Auth + Roles", detail: "AuthProvider synced with /api/auth/me and Auth.protect({ roles })" },
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
const badges = ["Express 5", "HTML {{ }}", "Vite 7", "React 19", "React Router", "Tailwind v4"];
|
|
34
|
+
const highlightsHtml = badges
|
|
35
|
+
.map(
|
|
36
|
+
(label) =>
|
|
37
|
+
`<span class="badge bg-card/80 text-foreground backdrop-blur-sm">${escapeHtml(label)}</span>`
|
|
38
|
+
)
|
|
39
|
+
.join("");
|
|
40
|
+
|
|
41
|
+
return Render.html(
|
|
42
|
+
res,
|
|
43
|
+
"home",
|
|
44
|
+
{
|
|
45
|
+
title: "Bluebird.js — HTML SSR + React SPA",
|
|
46
|
+
description: "Express + HTML {{ }} SSR templates + React Router SPA with Vite and Tailwind CSS v4.",
|
|
47
|
+
slides,
|
|
48
|
+
features,
|
|
49
|
+
highlightsHtml,
|
|
50
|
+
},
|
|
51
|
+
{ layout: "main", cache: 300 }
|
|
52
|
+
);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
routerWeb.get("/terms", Render.view("terms", { title: "Terms of Service" }, { cache: 86400, ttl: 86400 }));
|
|
56
|
+
|
|
57
|
+
routerWeb.get("/table", (req, res) =>
|
|
58
|
+
Render.html(
|
|
59
|
+
res,
|
|
60
|
+
"table",
|
|
61
|
+
{
|
|
62
|
+
title: "DataTable — Bluebird.js",
|
|
63
|
+
tableConfig: new SafeHtml(
|
|
64
|
+
safeJson({
|
|
65
|
+
caption: "People",
|
|
66
|
+
defaultSort: { key: "name" },
|
|
67
|
+
columns: [
|
|
68
|
+
{ key: "name", label: "Name", sortable: true, primary: true },
|
|
69
|
+
{ key: "email", label: "Email", sortable: true },
|
|
70
|
+
{ key: "role", label: "Role", sortable: true, format: "badge" },
|
|
71
|
+
{ key: "status", label: "Status", sortable: true, format: "badge", tones: { active: "success", invited: "info", suspended: "warning" } },
|
|
72
|
+
{ key: "sales", label: "Sales", sortable: true, format: "currency", numeric: true },
|
|
73
|
+
{ key: "joined", label: "Joined", sortable: true, format: "date", mobile: "details" },
|
|
74
|
+
],
|
|
75
|
+
actions: [
|
|
76
|
+
{ action: "view", href: "/app/table" },
|
|
77
|
+
{ action: "invite", label: "Resend invite", when: { key: "status", value: "invited" } },
|
|
78
|
+
{ action: "delete", url: "/api/demo/people/:id" },
|
|
79
|
+
],
|
|
80
|
+
})
|
|
81
|
+
),
|
|
82
|
+
},
|
|
83
|
+
{ layout: "main" }
|
|
84
|
+
)
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
routerWeb.spa(spa.mount, spa);
|
|
88
|
+
|
|
89
|
+
export default routerWeb;
|
package/core/ai.js
CHANGED
|
@@ -23,8 +23,29 @@ setInterval(() => {
|
|
|
23
23
|
}, 60000).unref();
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
26
|
+
* Checks whether an address belongs to a local or private network (where a reverse proxy would live).
|
|
27
|
+
* @param {string} address
|
|
28
|
+
* @returns {boolean}
|
|
29
|
+
*/
|
|
30
|
+
function isPrivateAddress(address) {
|
|
31
|
+
const ip = String(address || "").replace(/^::ffff:/, "");
|
|
32
|
+
return (
|
|
33
|
+
ip === "::1" ||
|
|
34
|
+
/^127./.test(ip) ||
|
|
35
|
+
/^10./.test(ip) ||
|
|
36
|
+
/^192.168./.test(ip) ||
|
|
37
|
+
/^172.(1[6-9]|2d|3[01])./.test(ip) ||
|
|
38
|
+
/^169.254./.test(ip) ||
|
|
39
|
+
/^f[cd][0-9a-f]{2}:/i.test(ip) ||
|
|
40
|
+
/^fe80:/i.test(ip)
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Extracts the client's real IP address across reverse proxies and CDNs, and cleans IPv6 mappings.
|
|
46
|
+
* Proxy headers (Cloudflare `cf-connecting-ip`, `true-client-ip`, Nginx `x-real-ip`, `x-forwarded-for`) are only
|
|
47
|
+
* trusted when the request arrives from a local/private reverse proxy; a client connecting directly cannot spoof
|
|
48
|
+
* them to dodge rate limits. On Express requests the address honors the app's `trust proxy` setting (`req.ip`).
|
|
28
49
|
* @param {import('express').Request|Object} req
|
|
29
50
|
* @returns {string}
|
|
30
51
|
*/
|
|
@@ -32,17 +53,16 @@ export function getClientIp(req) {
|
|
|
32
53
|
if (!req) return "127.0.0.1";
|
|
33
54
|
|
|
34
55
|
const headers = req.headers || {};
|
|
56
|
+
const peer = req.socket?.remoteAddress || req.connection?.remoteAddress || "";
|
|
57
|
+
const viaProxy = !peer || isPrivateAddress(peer);
|
|
58
|
+
const expressIp = req.app && typeof req.ip === "string" ? req.ip : "";
|
|
35
59
|
|
|
36
60
|
let ip =
|
|
37
|
-
headers["cf-connecting-ip"] ||
|
|
38
|
-
|
|
39
|
-
headers["x-
|
|
40
|
-
headers["x-forwarded-for"] ||
|
|
41
|
-
headers["x-client-ip"] ||
|
|
42
|
-
headers["x-cluster-client-ip"] ||
|
|
61
|
+
(viaProxy && (headers["cf-connecting-ip"] || headers["true-client-ip"] || headers["x-real-ip"])) ||
|
|
62
|
+
expressIp ||
|
|
63
|
+
(viaProxy && (headers["x-forwarded-for"] || headers["x-client-ip"] || headers["x-cluster-client-ip"])) ||
|
|
43
64
|
req.ip ||
|
|
44
|
-
|
|
45
|
-
req.connection?.remoteAddress ||
|
|
65
|
+
peer ||
|
|
46
66
|
"127.0.0.1";
|
|
47
67
|
|
|
48
68
|
if (typeof ip === "string") {
|
package/core/app.d.ts
CHANGED
|
@@ -1,18 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
WebSocketManager,
|
|
4
|
-
AppOptions,
|
|
5
|
-
CorsOptions,
|
|
6
|
-
SecurityHeadersOptions,
|
|
7
|
-
AppStaticOptions,
|
|
8
|
-
} from "./index.js";
|
|
9
|
-
export default App;
|
|
10
|
-
export {
|
|
11
|
-
App,
|
|
12
|
-
AppError,
|
|
13
|
-
WebSocketManager,
|
|
14
|
-
AppOptions,
|
|
15
|
-
CorsOptions,
|
|
16
|
-
SecurityHeadersOptions,
|
|
17
|
-
AppStaticOptions,
|
|
18
|
-
};
|
|
1
|
+
export type { App, AppError, AppOptions, CorsOptions, SecurityHeadersOptions, ViteOptions } from "./index.d.ts";
|
|
2
|
+
export { App as default } from "./index.d.ts";
|