@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.
Files changed (151) hide show
  1. package/AGENTS.md +727 -620
  2. package/README.md +670 -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 +55 -0
  6. package/app/resources/html/notFound.html +14 -0
  7. package/app/resources/html/table.html +15 -0
  8. package/app/resources/html/terms.html +46 -0
  9. package/app/resources/index.html +27 -0
  10. package/app/resources/layouts/AppLayout.jsx +92 -0
  11. package/app/resources/main.jsx +18 -0
  12. package/app/resources/pages/Dashboard.jsx +93 -0
  13. package/app/resources/pages/Home.jsx +140 -0
  14. package/app/resources/pages/Login.jsx +35 -0
  15. package/app/resources/pages/NotFound.jsx +16 -0
  16. package/app/resources/pages/Register.jsx +55 -0
  17. package/app/resources/pages/TableDemo.jsx +85 -0
  18. package/app/resources/routes.jsx +59 -0
  19. package/app/resources/spa.js +73 -0
  20. package/app/resources/styles.css +9 -0
  21. package/app/routes/api.js +129 -50
  22. package/app/routes/auth.js +209 -0
  23. package/app/routes/web.js +89 -47
  24. package/core/ai.js +30 -10
  25. package/core/app.d.ts +2 -18
  26. package/core/app.js +987 -801
  27. package/core/auth.d.ts +2 -13
  28. package/core/auth.js +444 -326
  29. package/core/cli/build.js +37 -0
  30. package/core/cli/dev.js +155 -0
  31. package/core/cli/doctor.js +37 -2
  32. package/core/cli/export.js +191 -0
  33. package/core/cli/init.js +91 -322
  34. package/core/cli/nginx.js +1 -1
  35. package/core/cli/templates.js +139 -0
  36. package/core/cli/view.js +98 -161
  37. package/core/config.js +44 -2
  38. package/core/csrf.js +156 -24
  39. package/core/database.js +1184 -1131
  40. package/core/debug.js +1 -1
  41. package/core/html.js +8 -1
  42. package/core/index.d.ts +126 -310
  43. package/core/paths.js +55 -0
  44. package/core/ratelimit.js +10 -1
  45. package/core/react/client/api.js +239 -0
  46. package/core/react/client/auth.js +236 -0
  47. package/core/react/client/components.js +1321 -0
  48. package/core/react/client/datatable.js +595 -0
  49. package/core/react/client/i18n.js +440 -0
  50. package/core/react/client/index.d.ts +314 -0
  51. package/core/react/client/index.js +50 -0
  52. package/core/react/client/router.js +26 -0
  53. package/core/react/client/theme.css +512 -0
  54. package/core/render-cache.js +250 -212
  55. package/core/render.d.ts +25 -21
  56. package/core/render.js +738 -736
  57. package/core/router.d.ts +2 -3
  58. package/core/router.js +171 -171
  59. package/core/seo.js +10 -0
  60. package/core/spa.js +599 -0
  61. package/core/view-loader.js +155 -613
  62. package/core/vite-plugin.d.ts +18 -0
  63. package/core/vite-plugin.js +162 -0
  64. package/core/vite.js +250 -145
  65. package/index.js +22 -18
  66. package/jsconfig.json +5 -3
  67. package/package.json +114 -92
  68. package/production.md +8 -3
  69. package/public/js/bluebird.js +1886 -0
  70. package/templates/_auth/app/database.js +19 -0
  71. package/templates/_auth/app/models/user.js +22 -0
  72. package/templates/_auth/app/routes/auth-router.js +304 -0
  73. package/templates/_base/app/resources/html/layouts/main.html +55 -0
  74. package/templates/_base/app/resources/html/notFound.html +14 -0
  75. package/templates/_base/app/resources/index.html +27 -0
  76. package/templates/_base/app/resources/styles.css +9 -0
  77. package/templates/api/app/models/note.js +18 -0
  78. package/templates/api/app/routes/api.js +82 -0
  79. package/templates/api/app/routes/auth.js +11 -0
  80. package/templates/api/index.js +19 -0
  81. package/templates/api/template.json +13 -0
  82. package/templates/auth/app/mail.js +11 -0
  83. package/templates/auth/app/models/password_reset.js +18 -0
  84. package/templates/auth/app/resources/html/home.html +21 -0
  85. package/templates/auth/app/resources/html/partials/nav.html +2 -0
  86. package/templates/auth/app/resources/layouts/AppLayout.jsx +60 -0
  87. package/templates/auth/app/resources/main.jsx +18 -0
  88. package/templates/auth/app/resources/pages/Dashboard.jsx +51 -0
  89. package/templates/auth/app/resources/pages/ForgotPassword.jsx +34 -0
  90. package/templates/auth/app/resources/pages/Login.jsx +36 -0
  91. package/templates/auth/app/resources/pages/NotFound.jsx +16 -0
  92. package/templates/auth/app/resources/pages/Profile.jsx +99 -0
  93. package/templates/auth/app/resources/pages/Register.jsx +50 -0
  94. package/templates/auth/app/resources/pages/ResetPassword.jsx +50 -0
  95. package/templates/auth/app/resources/routes.jsx +54 -0
  96. package/templates/auth/app/resources/spa.js +29 -0
  97. package/templates/auth/app/routes/api.js +17 -0
  98. package/templates/auth/app/routes/auth.js +13 -0
  99. package/templates/auth/app/routes/web.js +21 -0
  100. package/templates/auth/index.js +19 -0
  101. package/templates/auth/template.json +15 -0
  102. package/templates/blank/app/models/.gitkeep +0 -0
  103. package/templates/blank/app/resources/html/home.html +27 -0
  104. package/templates/blank/app/resources/html/partials/nav.html +1 -0
  105. package/templates/blank/app/resources/main.jsx +16 -0
  106. package/templates/blank/app/resources/pages/Home.jsx +42 -0
  107. package/templates/blank/app/resources/pages/NotFound.jsx +27 -0
  108. package/templates/blank/app/resources/routes.jsx +15 -0
  109. package/templates/blank/app/resources/spa.js +24 -0
  110. package/templates/blank/app/routes/api.js +11 -0
  111. package/templates/blank/app/routes/web.js +21 -0
  112. package/templates/blank/index.js +13 -0
  113. package/templates/blank/template.json +12 -0
  114. package/templates/blog/app/lib/blog.js +149 -0
  115. package/templates/blog/app/models/post.js +22 -0
  116. package/templates/blog/app/resources/html/home.html +28 -0
  117. package/templates/blog/app/resources/html/not-found.html +5 -0
  118. package/templates/blog/app/resources/html/partials/nav.html +2 -0
  119. package/templates/blog/app/resources/html/partials/post-card.html +9 -0
  120. package/templates/blog/app/resources/html/post.html +8 -0
  121. package/templates/blog/app/resources/layouts/AdminLayout.jsx +54 -0
  122. package/templates/blog/app/resources/main.jsx +18 -0
  123. package/templates/blog/app/resources/pages/Login.jsx +31 -0
  124. package/templates/blog/app/resources/pages/NotFound.jsx +16 -0
  125. package/templates/blog/app/resources/pages/PostEditor.jsx +51 -0
  126. package/templates/blog/app/resources/pages/Posts.jsx +83 -0
  127. package/templates/blog/app/resources/pages/Register.jsx +43 -0
  128. package/templates/blog/app/resources/routes.jsx +51 -0
  129. package/templates/blog/app/resources/spa.js +25 -0
  130. package/templates/blog/app/resources/styles.css +40 -0
  131. package/templates/blog/app/routes/api.js +77 -0
  132. package/templates/blog/app/routes/auth.js +10 -0
  133. package/templates/blog/app/routes/web.js +114 -0
  134. package/templates/blog/index.js +21 -0
  135. package/templates/blog/template.json +14 -0
  136. package/vite.config.js +11 -0
  137. package/app/views/components/Header.jsx +0 -42
  138. package/app/views/components/LiveCounter.jsx +0 -67
  139. package/app/views/layouts/main/view.jsx +0 -201
  140. package/app/views/legal/terms.html +0 -29
  141. package/app/views/pages/about.jsx +0 -98
  142. package/app/views/pages/dashboard.jsx +0 -278
  143. package/app/views/pages/index.jsx +0 -123
  144. package/app/views/pages/login.jsx +0 -141
  145. package/core/actions.d.ts +0 -4
  146. package/core/actions.js +0 -355
  147. package/core/jsx.d.ts +0 -38
  148. package/core/jsx.js +0 -1597
  149. package/core/vite.d.ts +0 -3
  150. package/public/js/bluebird-client.js +0 -3265
  151. package/public/js/tailwind.js +0 -8
@@ -0,0 +1,60 @@
1
+ import { Outlet } from "react-router";
2
+ import { Button, Link, ProgressBar, ThemeToggle, isExported, toast, useAuth } from "@seip/bluebird-js/react";
3
+
4
+ /**
5
+ * Shell of the React app: top navigation that adapts to the session, and the routed page below.
6
+ */
7
+ export default function AppLayout() {
8
+ const { user, logout, registerEnabled } = useAuth();
9
+
10
+ const handleLogout = async () => {
11
+ await logout();
12
+ toast.info("Signed out");
13
+ };
14
+
15
+ return (
16
+ <div className="flex min-h-screen flex-col">
17
+ <ProgressBar />
18
+ <header className="sticky top-0 z-30 border-b border-border/70 glass">
19
+ <nav className="mx-auto flex max-w-5xl items-center justify-between gap-4 px-4 py-3 md:px-6">
20
+ {isExported() ? (
21
+ <span className="brand text-lg">%%APP_TITLE%%</span>
22
+ ) : (
23
+ <a href="/" className="brand text-lg">%%APP_TITLE%%</a>
24
+ )}
25
+ <div className="flex items-center gap-1.5 overflow-x-auto">
26
+ {user ? (
27
+ <>
28
+ <Link to="/dashboard" className="nav-link">
29
+ Dashboard
30
+ </Link>
31
+ <Link to="/profile" className="nav-link">
32
+ Profile
33
+ </Link>
34
+ <Button size="sm" variant="outline" onClick={handleLogout} className="ml-1">
35
+ Sign out
36
+ </Button>
37
+ </>
38
+ ) : (
39
+ <>
40
+ <Link to="/login" className="nav-link">
41
+ Sign in
42
+ </Link>
43
+ {registerEnabled ? (
44
+ <Link to="/register" className="nav-link">
45
+ Sign up
46
+ </Link>
47
+ ) : null}
48
+ </>
49
+ )}
50
+ <ThemeToggle className="ml-1" />
51
+ </div>
52
+ </nav>
53
+ </header>
54
+
55
+ <main className="mx-auto w-full max-w-5xl flex-1 px-4 py-10 md:px-6">
56
+ <Outlet />
57
+ </main>
58
+ </div>
59
+ );
60
+ }
@@ -0,0 +1,18 @@
1
+ import { StrictMode } from "react";
2
+ import { createRoot } from "react-dom/client";
3
+ import { RouterProvider } from "react-router/dom";
4
+ import { AuthProvider, Toaster } from "@seip/bluebird-js/react";
5
+ import "./styles.css";
6
+ import { router } from "./routes.jsx";
7
+
8
+ const rootEl = document.getElementById("root");
9
+ if (rootEl) {
10
+ createRoot(rootEl).render(
11
+ <StrictMode>
12
+ <AuthProvider>
13
+ <RouterProvider router={router} />
14
+ <Toaster />
15
+ </AuthProvider>
16
+ </StrictMode>
17
+ );
18
+ }
@@ -0,0 +1,51 @@
1
+ import { useEffect, useState } from "react";
2
+ import { Badge, Card, Link, Skeleton, api, toast, useAuth } from "@seip/bluebird-js/react";
3
+
4
+ /**
5
+ * Signed-in home page backed by `GET /api/dashboard`.
6
+ */
7
+ export default function Dashboard() {
8
+ const { user, hasRole } = useAuth();
9
+ const [stats, setStats] = useState(null);
10
+
11
+ useEffect(() => {
12
+ api
13
+ .get("/api/dashboard")
14
+ .then(setStats)
15
+ .catch((err) => toast.error("Could not load the dashboard", err.message));
16
+ }, []);
17
+
18
+ return (
19
+ <div className="space-y-6">
20
+ <div className="flex flex-wrap items-center justify-between gap-4">
21
+ <div>
22
+ <h1 className="text-3xl font-semibold tracking-tight text-foreground">Hi, {user?.name}</h1>
23
+ <p className="text-sm text-muted-foreground">{user?.email}</p>
24
+ </div>
25
+ <Badge tone={hasRole("admin") ? "success" : "info"} soft>{user?.role}</Badge>
26
+ </div>
27
+
28
+ <div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
29
+ <Card title="Member since">
30
+ {stats ? (
31
+ <p className="text-lg font-semibold">
32
+ {stats.memberSince ? new Date(stats.memberSince).toLocaleDateString() : "Today"}
33
+ </p>
34
+ ) : (
35
+ <Skeleton className="h-7 w-32" />
36
+ )}
37
+ </Card>
38
+ {hasRole("admin") ? (
39
+ <Card title="Registered users">
40
+ {stats ? <p className="text-lg font-semibold">{stats.totalUsers}</p> : <Skeleton className="h-7 w-16" />}
41
+ </Card>
42
+ ) : null}
43
+ <Card title="Your profile" description="Update your name, email, or password.">
44
+ <Link to="/profile" className="text-sm font-semibold text-foreground underline-offset-4 hover:underline">
45
+ Edit profile
46
+ </Link>
47
+ </Card>
48
+ </div>
49
+ </div>
50
+ );
51
+ }
@@ -0,0 +1,34 @@
1
+ import { useState } from "react";
2
+ import { Card, Form, Input, Link, SubmitButton } from "@seip/bluebird-js/react";
3
+
4
+ /**
5
+ * Requests a password reset link (`POST /api/auth/forgot-password`).
6
+ * The link is delivered by `sendPasswordResetLink()` in `app/mail.js`.
7
+ */
8
+ export default function ForgotPassword() {
9
+ const [sent, setSent] = useState(false);
10
+
11
+ return (
12
+ <div className="mx-auto max-w-md py-6">
13
+ <Card variant="glass" title="Forgot your password?" description="Enter your email and we will send you a reset link.">
14
+ {sent ? (
15
+ <p className="text-sm text-muted-foreground">
16
+ If that email is registered, a reset link is on its way. It expires in 60 minutes.
17
+ </p>
18
+ ) : (
19
+ <Form url="/api/auth/forgot-password" onSuccess={() => setSent(true)} className="space-y-4">
20
+ <Input name="email" type="email" label="Email" autoComplete="email" required />
21
+ <SubmitButton className="w-full" loadingText="Sending...">
22
+ Send reset link
23
+ </SubmitButton>
24
+ </Form>
25
+ )}
26
+ <p className="mt-4 text-center text-sm">
27
+ <Link to="/login" className="font-semibold text-foreground underline-offset-4 hover:underline">
28
+ Back to sign in
29
+ </Link>
30
+ </p>
31
+ </Card>
32
+ </div>
33
+ );
34
+ }
@@ -0,0 +1,36 @@
1
+ import { Card, Form, Input, Link, SubmitButton, useAuth } from "@seip/bluebird-js/react";
2
+
3
+ /**
4
+ * Sign-in page bound to `POST /api/auth/login`.
5
+ */
6
+ export default function Login() {
7
+ const { login, registerEnabled } = useAuth();
8
+
9
+ return (
10
+ <div className="mx-auto max-w-md py-6">
11
+ <Card variant="glass" title="Sign in" description="Welcome back.">
12
+ <Form onSubmitRequest={(values) => login(values)} successMessage="Signed in" className="space-y-4">
13
+ <Input name="email" type="email" label="Email" autoComplete="email" required />
14
+ <Input name="password" type="password" label="Password" autoComplete="current-password" required />
15
+ <div className="flex justify-end">
16
+ <Link to="/forgot-password" className="text-sm font-medium text-foreground underline-offset-4 hover:underline">
17
+ Forgot your password?
18
+ </Link>
19
+ </div>
20
+ <SubmitButton className="w-full" loadingText="Signing in...">
21
+ Sign in
22
+ </SubmitButton>
23
+ </Form>
24
+
25
+ {registerEnabled ? (
26
+ <p className="mt-4 text-center text-sm text-muted-foreground">
27
+ No account yet?{" "}
28
+ <Link to="/register" className="font-semibold text-foreground underline-offset-4 hover:underline">
29
+ Create one
30
+ </Link>
31
+ </p>
32
+ ) : null}
33
+ </Card>
34
+ </div>
35
+ );
36
+ }
@@ -0,0 +1,16 @@
1
+ import { Card, Link } from "@seip/bluebird-js/react";
2
+
3
+ /**
4
+ * Fallback page for unknown routes inside `/app`.
5
+ */
6
+ export default function NotFound() {
7
+ return (
8
+ <div className="mx-auto max-w-md py-12">
9
+ <Card title="Page not found" description="This page does not exist.">
10
+ <Link to="/" className="text-sm font-semibold text-foreground underline-offset-4 hover:underline">
11
+ Go home
12
+ </Link>
13
+ </Card>
14
+ </div>
15
+ );
16
+ }
@@ -0,0 +1,99 @@
1
+ import { useState } from "react";
2
+ import { Button, Card, Form, Input, SubmitButton, api, getAuthMode, setAuthToken, toast, useAuth } from "@seip/bluebird-js/react";
3
+ import { useNavigate } from "react-router";
4
+
5
+ /**
6
+ * Profile settings: name and email (`PUT /api/auth/profile`, the current password is required to change the email),
7
+ * password (`PUT /api/auth/password`, signs out every other session), and "sign out everywhere" (`POST /api/auth/logout-all`).
8
+ */
9
+ export default function Profile() {
10
+ const { user, setUser } = useAuth();
11
+ const navigate = useNavigate();
12
+ const [email, setEmail] = useState(user?.email || "");
13
+ const [signingOut, setSigningOut] = useState(false);
14
+ const emailChanged = email.trim().toLowerCase() !== String(user?.email || "").toLowerCase();
15
+
16
+ /**
17
+ * Stores the refreshed session returned by profile and password updates.
18
+ * @param {{ user?: Object, token?: string }} result
19
+ */
20
+ const applySession = (result) => {
21
+ if (result?.token) setAuthToken(result.token);
22
+ if (result?.user) setUser(result.user);
23
+ return result;
24
+ };
25
+
26
+ const signOutEverywhere = async () => {
27
+ setSigningOut(true);
28
+ try {
29
+ await api.post("/api/auth/logout-all");
30
+ if (getAuthMode() === "token") setAuthToken(null);
31
+ setUser(null);
32
+ toast.success("Signed out of every device");
33
+ navigate("/login");
34
+ } catch (err) {
35
+ toast.error(err.message);
36
+ } finally {
37
+ setSigningOut(false);
38
+ }
39
+ };
40
+
41
+ return (
42
+ <div className="mx-auto grid max-w-3xl gap-6">
43
+ <Card title="Profile" description="Your public name and sign-in email.">
44
+ <Form
45
+ onSubmitRequest={async (values) => applySession(await api.put("/api/auth/profile", values))}
46
+ successMessage="Profile updated"
47
+ className="space-y-4"
48
+ >
49
+ <Input name="name" label="Name" defaultValue={user?.name} autoComplete="name" required />
50
+ <Input
51
+ name="email"
52
+ type="email"
53
+ label="Email"
54
+ value={email}
55
+ onChange={(e) => setEmail(e.target.value)}
56
+ autoComplete="email"
57
+ required
58
+ />
59
+ {emailChanged ? (
60
+ <Input
61
+ name="current_password"
62
+ type="password"
63
+ label="Current password"
64
+ hint="Required to change your sign-in email."
65
+ autoComplete="current-password"
66
+ required
67
+ />
68
+ ) : null}
69
+ <SubmitButton loadingText="Saving...">Save changes</SubmitButton>
70
+ </Form>
71
+ </Card>
72
+
73
+ <Card title="Password" description="Use at least 8 characters. Other devices will be signed out.">
74
+ <Form
75
+ onSubmitRequest={async (values) => applySession(await api.put("/api/auth/password", values))}
76
+ resetOnSuccess
77
+ successMessage="Password changed"
78
+ className="space-y-4"
79
+ >
80
+ <Input
81
+ name="current_password"
82
+ type="password"
83
+ label="Current password"
84
+ autoComplete="current-password"
85
+ required
86
+ />
87
+ <Input name="password" type="password" label="New password" autoComplete="new-password" minLength={8} required />
88
+ <SubmitButton loadingText="Updating...">Change password</SubmitButton>
89
+ </Form>
90
+ </Card>
91
+
92
+ <Card title="Sessions" description="Sign out of this and every other device where your account is open.">
93
+ <Button variant="outline" loading={signingOut} onClick={signOutEverywhere}>
94
+ Sign out everywhere
95
+ </Button>
96
+ </Card>
97
+ </div>
98
+ );
99
+ }
@@ -0,0 +1,50 @@
1
+ import { Card, Form, Input, Link, SubmitButton, useAuth } from "@seip/bluebird-js/react";
2
+
3
+ /**
4
+ * Registration page bound to `POST /api/auth/register`.
5
+ */
6
+ export default function Register() {
7
+ const { register, registerEnabled } = useAuth();
8
+
9
+ if (!registerEnabled) {
10
+ return (
11
+ <div className="mx-auto max-w-md py-6">
12
+ <Card title="Registration closed" description="New accounts cannot be created right now.">
13
+ <Link to="/login" className="text-sm font-semibold text-foreground underline-offset-4 hover:underline">
14
+ Back to sign in
15
+ </Link>
16
+ </Card>
17
+ </div>
18
+ );
19
+ }
20
+
21
+ return (
22
+ <div className="mx-auto max-w-md py-6">
23
+ <Card variant="glass" title="Create account" description="It only takes a minute.">
24
+ <Form onSubmitRequest={(values) => register(values)} successMessage="Account created" className="space-y-4">
25
+ <Input name="name" label="Name" autoComplete="name" required />
26
+ <Input name="email" type="email" label="Email" autoComplete="email" required />
27
+ <Input
28
+ name="password"
29
+ type="password"
30
+ label="Password"
31
+ hint="At least 8 characters"
32
+ autoComplete="new-password"
33
+ minLength={8}
34
+ required
35
+ />
36
+ <SubmitButton className="w-full" loadingText="Creating account...">
37
+ Create account
38
+ </SubmitButton>
39
+ </Form>
40
+
41
+ <p className="mt-4 text-center text-sm text-muted-foreground">
42
+ Already have an account?{" "}
43
+ <Link to="/login" className="font-semibold text-foreground underline-offset-4 hover:underline">
44
+ Sign in
45
+ </Link>
46
+ </p>
47
+ </Card>
48
+ </div>
49
+ );
50
+ }
@@ -0,0 +1,50 @@
1
+ import { useNavigate, useSearchParams } from "react-router";
2
+ import { Card, Form, Input, Link, SubmitButton } from "@seip/bluebird-js/react";
3
+
4
+ /**
5
+ * Sets a new password from the emailed link (`?token=...&email=...`) via `POST /api/auth/reset-password`.
6
+ */
7
+ export default function ResetPassword() {
8
+ const [params] = useSearchParams();
9
+ const navigate = useNavigate();
10
+ const token = params.get("token") || "";
11
+ const email = params.get("email") || "";
12
+
13
+ if (!token || !email) {
14
+ return (
15
+ <div className="mx-auto max-w-md py-6">
16
+ <Card title="Invalid link" description="This reset link is incomplete. Request a new one.">
17
+ <Link to="/forgot-password" className="text-sm font-semibold text-foreground underline-offset-4 hover:underline">
18
+ Request a new link
19
+ </Link>
20
+ </Card>
21
+ </div>
22
+ );
23
+ }
24
+
25
+ return (
26
+ <div className="mx-auto max-w-md py-6">
27
+ <Card variant="glass" title="Choose a new password" description={email}>
28
+ <Form
29
+ url="/api/auth/reset-password"
30
+ data={{ token, email }}
31
+ successMessage="Password updated"
32
+ onSuccess={() => navigate("/login", { replace: true })}
33
+ className="space-y-4"
34
+ >
35
+ <Input
36
+ name="password"
37
+ type="password"
38
+ label="New password"
39
+ hint="At least 8 characters"
40
+ autoComplete="new-password"
41
+ required
42
+ />
43
+ <SubmitButton className="w-full" loadingText="Saving...">
44
+ Update password
45
+ </SubmitButton>
46
+ </Form>
47
+ </Card>
48
+ </div>
49
+ );
50
+ }
@@ -0,0 +1,54 @@
1
+ import { Suspense, lazy } from "react";
2
+ import { Navigate } from "react-router";
3
+ import { GuestOnly, PageSkeleton, RequireAuth, createRouter } from "@seip/bluebird-js/react";
4
+ import AppLayout from "./layouts/AppLayout.jsx";
5
+
6
+ const Login = lazy(() => import("./pages/Login.jsx"));
7
+ const Register = lazy(() => import("./pages/Register.jsx"));
8
+ const ForgotPassword = lazy(() => import("./pages/ForgotPassword.jsx"));
9
+ const ResetPassword = lazy(() => import("./pages/ResetPassword.jsx"));
10
+ const Dashboard = lazy(() => import("./pages/Dashboard.jsx"));
11
+ const Profile = lazy(() => import("./pages/Profile.jsx"));
12
+ const NotFound = lazy(() => import("./pages/NotFound.jsx"));
13
+
14
+ /**
15
+ * Wraps lazy route components in a full-width Suspense fallback.
16
+ * @param {import('react').ReactNode} element
17
+ * @returns {import('react').ReactNode}
18
+ */
19
+ function withSuspense(element) {
20
+ return <Suspense fallback={<PageSkeleton />}>{element}</Suspense>;
21
+ }
22
+
23
+ /**
24
+ * React Router configuration: browser router under `/app` on the server, hash router in static exports.
25
+ */
26
+ export const router = createRouter(
27
+ [
28
+ {
29
+ path: "/",
30
+ element: <AppLayout />,
31
+ children: [
32
+ { index: true, element: <Navigate to="/dashboard" replace /> },
33
+ {
34
+ element: <GuestOnly redirectTo="/dashboard" />,
35
+ children: [
36
+ { path: "login", element: withSuspense(<Login />) },
37
+ { path: "register", element: withSuspense(<Register />) },
38
+ { path: "forgot-password", element: withSuspense(<ForgotPassword />) },
39
+ { path: "reset-password", element: withSuspense(<ResetPassword />) },
40
+ ],
41
+ },
42
+ {
43
+ element: <RequireAuth redirectTo="/login" />,
44
+ children: [
45
+ { path: "dashboard", element: withSuspense(<Dashboard />) },
46
+ { path: "profile", element: withSuspense(<Profile />) },
47
+ ],
48
+ },
49
+ { path: "*", element: withSuspense(<NotFound />) },
50
+ ],
51
+ },
52
+ ],
53
+ { basename: "/app" }
54
+ );
@@ -0,0 +1,29 @@
1
+ /**
2
+ * React SPA configuration shared by `routerWeb.spa(spa.mount, spa)` and `npx bluebird-js export`.
3
+ * @type {import('@seip/bluebird-js/core/index.js').SpaOptions & { mount: string }}
4
+ */
5
+ const spa = {
6
+ mount: "/app",
7
+ lang: "en",
8
+ titleTemplate: "%s — %%APP_TITLE%%",
9
+ title: "Account",
10
+ description: "%%APP_TITLE%% account area.",
11
+ canonical: true,
12
+ head: [{ tag: "link", rel: "icon", href: "/images/favicon.ico" }],
13
+ htmlAttrs: { class: "dark", "data-theme": "dark" },
14
+ bodyAttrs: {
15
+ class: "min-h-screen bg-app text-foreground antialiased",
16
+ },
17
+ skeleton: "app",
18
+ meta: {
19
+ "*": { title: "Account", robots: "noindex, nofollow", skeleton: "app" },
20
+ login: { title: "Sign In", description: "Sign in to your account.", robots: "index, follow", skeleton: "auth" },
21
+ register: { title: "Create Account", description: "Create a new account.", robots: "index, follow", skeleton: "auth" },
22
+ "forgot-password": { title: "Forgot Password", robots: "noindex, nofollow", skeleton: "auth" },
23
+ "reset-password": { title: "Reset Password", robots: "noindex, nofollow", skeleton: "auth" },
24
+ dashboard: { title: "Dashboard" },
25
+ profile: { title: "Profile" },
26
+ },
27
+ };
28
+
29
+ export default spa;
@@ -0,0 +1,17 @@
1
+ import Router from "@seip/bluebird-js/core/router.js";
2
+ import Auth from "@seip/bluebird-js/core/auth.js";
3
+ import Csrf from "@seip/bluebird-js/core/csrf.js";
4
+ import User from "../models/user.js";
5
+
6
+ const routerApi = new Router("/api");
7
+ routerApi.use(Csrf.middleware());
8
+
9
+ routerApi.get("/dashboard", Auth.protect(), async (req, res) => {
10
+ const account = await User.find(req.user.id);
11
+ res.ok({
12
+ memberSince: account?.created_at || null,
13
+ totalUsers: Auth.hasRole(req.user, "admin") ? await User.count() : null,
14
+ });
15
+ });
16
+
17
+ export default routerApi;
@@ -0,0 +1,13 @@
1
+ import { createAuthRouter } from "./auth-router.js";
2
+ import PasswordReset from "../models/password_reset.js";
3
+ import { sendPasswordResetLink } from "../mail.js";
4
+
5
+ /**
6
+ * `/api/auth/*`: me, login, logout, register, forgot/reset password, profile, and password change.
7
+ * Every new account gets the `user` role; promote admins yourself (seed, SQL, or an admin-only endpoint).
8
+ */
9
+ export default createAuthRouter({
10
+ register: true,
11
+ profile: true,
12
+ passwordReset: { model: PasswordReset, send: sendPasswordResetLink, ttlMinutes: 60 },
13
+ });
@@ -0,0 +1,21 @@
1
+ import Router from "@seip/bluebird-js/core/router.js";
2
+ import Render from "@seip/bluebird-js/core/render.js";
3
+ import spa from "../resources/spa.js";
4
+
5
+ const routerWeb = new Router("/", { seo: true });
6
+
7
+ routerWeb.get("/", (req, res) =>
8
+ Render.html(
9
+ res,
10
+ "home",
11
+ {
12
+ title: "%%APP_TITLE%%",
13
+ description: "Sign in to %%APP_TITLE%%.",
14
+ },
15
+ { layout: "main", cache: 300 }
16
+ )
17
+ );
18
+
19
+ routerWeb.spa(spa.mount, spa);
20
+
21
+ export default routerWeb;
@@ -0,0 +1,19 @@
1
+ import App from "@seip/bluebird-js/core/app.js";
2
+ import { ensureSchema } from "./app/database.js";
3
+ import User from "./app/models/user.js";
4
+ import PasswordReset from "./app/models/password_reset.js";
5
+ import routerApi from "./app/routes/api.js";
6
+ import routerAuth from "./app/routes/auth.js";
7
+ import routerWeb from "./app/routes/web.js";
8
+
9
+ await ensureSchema([User, PasswordReset]);
10
+
11
+ /**
12
+ * Application entrypoint: HTML landing on `/`, React app with authentication on `/app`.
13
+ */
14
+ const app = new App({
15
+ routes: [routerWeb, routerAuth, routerApi],
16
+ port: Number(process.env.PORT || 3000),
17
+ });
18
+
19
+ app.run();
@@ -0,0 +1,15 @@
1
+ {
2
+ "description": "HTML landing on / and a React app on /app with login, register, forgot/reset password, dashboard, and profile",
3
+ "layers": [
4
+ "_base",
5
+ "_auth"
6
+ ],
7
+ "client": true,
8
+ "database": "required",
9
+ "routes": [
10
+ "/ HTML {{ }} landing",
11
+ "/app/login, /app/register React auth pages",
12
+ "/app/forgot-password Reset link (printed in the console until app/mail.js sends email)",
13
+ "/app/dashboard, /app/profile"
14
+ ]
15
+ }
File without changes
@@ -0,0 +1,27 @@
1
+ <section class="py-10 md:py-16">
2
+ <span class="badge">
3
+ <span class="badge-dot bg-success" aria-hidden="true"></span>
4
+ Bluebird.js
5
+ </span>
6
+ <h1 class="mt-4 max-w-3xl text-3xl font-semibold tracking-tight text-foreground sm:text-4xl md:text-5xl md:leading-[1.1]">
7
+ {{ title }}
8
+ </h1>
9
+ <p class="mt-4 max-w-2xl text-base leading-relaxed text-muted-foreground md:text-lg">
10
+ This page is server-rendered from <code>app/resources/html/home.html</code>. The React app lives on
11
+ <code>/app</code> in <code>app/resources/pages/Home.jsx</code>.
12
+ </p>
13
+ <div class="mt-8 flex flex-wrap items-center gap-2.5">
14
+ <a href="/app" class="btn btn-primary">
15
+ Open the React app
16
+ </a>
17
+ <button
18
+ type="button"
19
+ data-toast="Hello from HTML!"
20
+ data-toast-description="Vanilla helpers from public/js/bluebird.js, no React needed."
21
+ data-toast-type="success"
22
+ class="btn btn-outline"
23
+ >
24
+ Show a toast
25
+ </button>
26
+ </div>
27
+ </section>
@@ -0,0 +1 @@
1
+ <a href="/app" class="btn btn-primary btn-sm">Open App</a>
@@ -0,0 +1,16 @@
1
+ import { StrictMode } from "react";
2
+ import { createRoot } from "react-dom/client";
3
+ import { RouterProvider } from "react-router/dom";
4
+ import { Toaster } from "@seip/bluebird-js/react";
5
+ import "./styles.css";
6
+ import { router } from "./routes.jsx";
7
+
8
+ const rootEl = document.getElementById("root");
9
+ if (rootEl) {
10
+ createRoot(rootEl).render(
11
+ <StrictMode>
12
+ <RouterProvider router={router} />
13
+ <Toaster />
14
+ </StrictMode>
15
+ );
16
+ }