@seip/bluebird-js 0.1.7 → 0.2.0

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 (148) hide show
  1. package/AGENTS.md +726 -620
  2. package/README.md +615 -607
  3. package/app/models/user.js +19 -0
  4. package/app/resources/html/home.html +137 -0
  5. package/app/resources/html/layouts/main.html +54 -0
  6. package/app/resources/html/notFound.html +14 -0
  7. package/app/resources/html/terms.html +46 -0
  8. package/app/resources/index.html +27 -0
  9. package/app/resources/layouts/AppLayout.jsx +89 -0
  10. package/app/resources/main.jsx +18 -0
  11. package/app/resources/pages/Dashboard.jsx +98 -0
  12. package/app/resources/pages/Home.jsx +140 -0
  13. package/app/resources/pages/Login.jsx +35 -0
  14. package/app/resources/pages/NotFound.jsx +16 -0
  15. package/app/resources/pages/Register.jsx +55 -0
  16. package/app/resources/routes.jsx +54 -0
  17. package/app/resources/spa.js +67 -0
  18. package/app/resources/styles.css +9 -0
  19. package/app/routes/api.js +85 -50
  20. package/app/routes/auth.js +209 -0
  21. package/app/routes/web.js +59 -47
  22. package/core/ai.js +30 -10
  23. package/core/app.d.ts +2 -18
  24. package/core/app.js +987 -801
  25. package/core/auth.d.ts +2 -13
  26. package/core/auth.js +444 -326
  27. package/core/cli/build.js +37 -0
  28. package/core/cli/dev.js +155 -0
  29. package/core/cli/doctor.js +37 -2
  30. package/core/cli/export.js +191 -0
  31. package/core/cli/init.js +91 -322
  32. package/core/cli/nginx.js +1 -1
  33. package/core/cli/templates.js +139 -0
  34. package/core/cli/view.js +98 -161
  35. package/core/config.js +44 -2
  36. package/core/csrf.js +156 -24
  37. package/core/database.js +1184 -1131
  38. package/core/debug.js +1 -1
  39. package/core/html.js +8 -1
  40. package/core/index.d.ts +126 -310
  41. package/core/paths.js +55 -0
  42. package/core/ratelimit.js +10 -1
  43. package/core/react/client/api.js +237 -0
  44. package/core/react/client/auth.js +236 -0
  45. package/core/react/client/components.js +1321 -0
  46. package/core/react/client/i18n.js +338 -0
  47. package/core/react/client/index.d.ts +249 -0
  48. package/core/react/client/index.js +49 -0
  49. package/core/react/client/router.js +26 -0
  50. package/core/react/client/theme.css +512 -0
  51. package/core/render-cache.js +250 -212
  52. package/core/render.d.ts +25 -21
  53. package/core/render.js +738 -736
  54. package/core/router.d.ts +2 -3
  55. package/core/router.js +171 -171
  56. package/core/seo.js +10 -0
  57. package/core/spa.js +599 -0
  58. package/core/view-loader.js +155 -613
  59. package/core/vite-plugin.d.ts +18 -0
  60. package/core/vite-plugin.js +162 -0
  61. package/core/vite.js +250 -145
  62. package/index.js +22 -18
  63. package/jsconfig.json +5 -3
  64. package/package.json +114 -92
  65. package/production.md +8 -3
  66. package/public/js/bluebird.js +1160 -0
  67. package/templates/_auth/app/database.js +19 -0
  68. package/templates/_auth/app/models/user.js +22 -0
  69. package/templates/_auth/app/routes/auth-router.js +304 -0
  70. package/templates/_base/app/resources/html/layouts/main.html +55 -0
  71. package/templates/_base/app/resources/html/notFound.html +14 -0
  72. package/templates/_base/app/resources/index.html +27 -0
  73. package/templates/_base/app/resources/styles.css +9 -0
  74. package/templates/api/app/models/note.js +18 -0
  75. package/templates/api/app/routes/api.js +82 -0
  76. package/templates/api/app/routes/auth.js +11 -0
  77. package/templates/api/index.js +19 -0
  78. package/templates/api/template.json +13 -0
  79. package/templates/auth/app/mail.js +11 -0
  80. package/templates/auth/app/models/password_reset.js +18 -0
  81. package/templates/auth/app/resources/html/home.html +21 -0
  82. package/templates/auth/app/resources/html/partials/nav.html +2 -0
  83. package/templates/auth/app/resources/layouts/AppLayout.jsx +60 -0
  84. package/templates/auth/app/resources/main.jsx +18 -0
  85. package/templates/auth/app/resources/pages/Dashboard.jsx +51 -0
  86. package/templates/auth/app/resources/pages/ForgotPassword.jsx +34 -0
  87. package/templates/auth/app/resources/pages/Login.jsx +36 -0
  88. package/templates/auth/app/resources/pages/NotFound.jsx +16 -0
  89. package/templates/auth/app/resources/pages/Profile.jsx +99 -0
  90. package/templates/auth/app/resources/pages/Register.jsx +50 -0
  91. package/templates/auth/app/resources/pages/ResetPassword.jsx +50 -0
  92. package/templates/auth/app/resources/routes.jsx +54 -0
  93. package/templates/auth/app/resources/spa.js +29 -0
  94. package/templates/auth/app/routes/api.js +17 -0
  95. package/templates/auth/app/routes/auth.js +13 -0
  96. package/templates/auth/app/routes/web.js +21 -0
  97. package/templates/auth/index.js +19 -0
  98. package/templates/auth/template.json +15 -0
  99. package/templates/blank/app/models/.gitkeep +0 -0
  100. package/templates/blank/app/resources/html/home.html +27 -0
  101. package/templates/blank/app/resources/html/partials/nav.html +1 -0
  102. package/templates/blank/app/resources/main.jsx +16 -0
  103. package/templates/blank/app/resources/pages/Home.jsx +42 -0
  104. package/templates/blank/app/resources/pages/NotFound.jsx +27 -0
  105. package/templates/blank/app/resources/routes.jsx +15 -0
  106. package/templates/blank/app/resources/spa.js +24 -0
  107. package/templates/blank/app/routes/api.js +11 -0
  108. package/templates/blank/app/routes/web.js +21 -0
  109. package/templates/blank/index.js +13 -0
  110. package/templates/blank/template.json +12 -0
  111. package/templates/blog/app/lib/blog.js +149 -0
  112. package/templates/blog/app/models/post.js +22 -0
  113. package/templates/blog/app/resources/html/home.html +28 -0
  114. package/templates/blog/app/resources/html/not-found.html +5 -0
  115. package/templates/blog/app/resources/html/partials/nav.html +2 -0
  116. package/templates/blog/app/resources/html/partials/post-card.html +9 -0
  117. package/templates/blog/app/resources/html/post.html +8 -0
  118. package/templates/blog/app/resources/layouts/AdminLayout.jsx +54 -0
  119. package/templates/blog/app/resources/main.jsx +18 -0
  120. package/templates/blog/app/resources/pages/Login.jsx +31 -0
  121. package/templates/blog/app/resources/pages/NotFound.jsx +16 -0
  122. package/templates/blog/app/resources/pages/PostEditor.jsx +51 -0
  123. package/templates/blog/app/resources/pages/Posts.jsx +83 -0
  124. package/templates/blog/app/resources/pages/Register.jsx +43 -0
  125. package/templates/blog/app/resources/routes.jsx +51 -0
  126. package/templates/blog/app/resources/spa.js +25 -0
  127. package/templates/blog/app/resources/styles.css +40 -0
  128. package/templates/blog/app/routes/api.js +77 -0
  129. package/templates/blog/app/routes/auth.js +10 -0
  130. package/templates/blog/app/routes/web.js +114 -0
  131. package/templates/blog/index.js +21 -0
  132. package/templates/blog/template.json +14 -0
  133. package/vite.config.js +11 -0
  134. package/app/views/components/Header.jsx +0 -42
  135. package/app/views/components/LiveCounter.jsx +0 -67
  136. package/app/views/layouts/main/view.jsx +0 -201
  137. package/app/views/legal/terms.html +0 -29
  138. package/app/views/pages/about.jsx +0 -98
  139. package/app/views/pages/dashboard.jsx +0 -278
  140. package/app/views/pages/index.jsx +0 -123
  141. package/app/views/pages/login.jsx +0 -141
  142. package/core/actions.d.ts +0 -4
  143. package/core/actions.js +0 -355
  144. package/core/jsx.d.ts +0 -38
  145. package/core/jsx.js +0 -1597
  146. package/core/vite.d.ts +0 -3
  147. package/public/js/bluebird-client.js +0 -3265
  148. package/public/js/tailwind.js +0 -8
package/app/routes/web.js CHANGED
@@ -1,47 +1,59 @@
1
- import Router from "@seip/bluebird-js/core/router.js";
2
- import Render from "@seip/bluebird-js/core/render.js";
3
- import Auth from "@seip/bluebird-js/core/auth.js";
4
-
5
- /**
6
- * Web Router for custom actions and static HTML files.
7
- * Page GET routes (`/`, `/about`, `/login`, `/dashboard`) are automatically
8
- * generated from `app/views/*.jsx` via declarative exports (`route`, `cache`, `middlewares`, `layout`, `seo`).
9
- */
10
- const routerWeb = new Router("/", { seo: true });
11
-
12
- routerWeb.get("/terms", (req, res) => Render.html(res, "legal/terms.html", { ttl: 86400 }));
13
-
14
- routerWeb.post("/login", async (req, res) => {
15
- const email = req.body?.email || "alex@example.com";
16
- const rawPrefix = email.split("@")[0] || "alex";
17
- const name = req.body?.name || (rawPrefix.charAt(0).toUpperCase() + rawPrefix.slice(1));
18
-
19
- const user = {
20
- id: 1,
21
- name,
22
- email,
23
- role: "admin",
24
- };
25
-
26
- await Auth.login(res, user);
27
- return res.redirect("/dashboard");
28
- });
29
-
30
- routerWeb.get("/logout", async (req, res) => {
31
- if (
32
- req.headers["x-bluebird-prefetch"] ||
33
- req.headers.purpose === "prefetch" ||
34
- req.headers["sec-purpose"] === "prefetch"
35
- ) {
36
- return res.status(204).end();
37
- }
38
- await Auth.logout(res);
39
- return res.redirect("/login");
40
- });
41
-
42
- routerWeb.post("/logout", async (req, res) => {
43
- await Auth.logout(res);
44
- return res.redirect("/login");
45
- });
46
-
47
- export default routerWeb;
1
+ import Router from "@seip/bluebird-js/core/router.js";
2
+ import Render from "@seip/bluebird-js/core/render.js";
3
+ import { escapeHtml } 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.spa(spa.mount, spa);
58
+
59
+ export default routerWeb;
package/core/ai.js CHANGED
@@ -23,8 +23,29 @@ setInterval(() => {
23
23
  }, 60000).unref();
24
24
 
25
25
  /**
26
- * Accurately extracts the client's real IP address across reverse proxies and CDNs.
27
- * Checks Cloudflare, Akamai, Nginx, standard X-Forwarded-For, and cleans IPv6 mappings.
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
- headers["true-client-ip"] ||
39
- headers["x-real-ip"] ||
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
- req.socket?.remoteAddress ||
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
- import App, {
2
- AppError,
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";