@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/core/router.d.ts CHANGED
@@ -1,3 +1,2 @@
1
- import { Router, RouterOptions } from "./index.js";
2
- export default Router;
3
- export { Router, RouterOptions };
1
+ export type { Router, RouterOptions, SpaMetaEntry, SpaOptions } from "./index.d.ts";
2
+ export { Router as default } from "./index.d.ts";
package/core/router.js CHANGED
@@ -1,171 +1,171 @@
1
- import express from "express";
2
- import Config from "./config.js";
3
- import Seo from "./seo.js";
4
-
5
- const props = Config.props();
6
-
7
- /**
8
- * Wraps route handlers to automatically catch async rejections and forward them to next(err).
9
- * @param {Function} fn - Handler function.
10
- * @returns {Function} Wrapped handler.
11
- */
12
- function wrapAsync(fn) {
13
- if (typeof fn !== "function") return fn;
14
- return (req, res, next) => {
15
- try {
16
- const result = fn(req, res, next);
17
- if (result && typeof result.catch === "function") {
18
- result.catch(next);
19
- }
20
- } catch (err) {
21
- next(err);
22
- }
23
- };
24
- }
25
-
26
- /**
27
- * Router wrapper class for handling Express routing logic.
28
- * When created with { seo: true }, all GET routes registered on this router
29
- * are automatically included in the generated sitemap.xml and robots.txt.
30
- */
31
- class Router {
32
- /**
33
- * Creates a new Router instance.
34
- * @param {string} [path="/"] - The base path for this router.
35
- * @param {Object} [options={}] - Router configuration options.
36
- * @param {boolean} [options.seo=false] - When true, GET routes on this router are included in sitemap/robots.txt.
37
- * @param {string[]} [options.languages=[]] - Language prefixes for SEO route generation (e.g., ["en", "es"]).
38
- * @example
39
- * const router = new Router("/", { seo: true, languages: ["en", "es"] });
40
- * router.get("/", (req, res) => {
41
- * Render.send(res, "index", { title: "Home" });
42
- * });
43
- */
44
- constructor(path = "/", options = {}) {
45
- this.router = express.Router();
46
- this.path = path;
47
- this._seo = options.seo ?? false;
48
- this._languages = options.languages || [];
49
- }
50
-
51
- /**
52
- * Registers a middleware on this router.
53
- * @param {...Function} middleware - Middleware functions.
54
- * @example
55
- * router.use(Auth.protect());
56
- * router.use(App.helmet());
57
- */
58
- use(...middleware) {
59
- const handlers = middleware.map(wrapAsync);
60
- this.router.use(...handlers);
61
- }
62
-
63
- /**
64
- * Registers a GET route handler.
65
- * If this router was created with { seo: true }, the route path is automatically
66
- * registered for sitemap.xml and robots.txt generation.
67
- * @param {string|RegExp} path - The relative path for the GET route.
68
- * @param {...Function} callback - One or more handler functions (middlewares and controller).
69
- * @example
70
- * router.get("/about", (req, res) => {
71
- * Render.send(res, "about", { title: "About Us" });
72
- * });
73
- */
74
- get(path, ...callback) {
75
- if (this._seo && typeof path === "string") {
76
- Seo.registerRoute(this.path, path, this._languages);
77
- }
78
- if (path === "/*" || path === "*") {
79
- path = /.*/;
80
- }
81
- const handlers = callback.map(wrapAsync);
82
- this.router.get(path, ...handlers);
83
- }
84
-
85
- /**
86
- * Registers a POST route handler.
87
- * @param {string} path - The relative path for the POST route.
88
- * @param {...Function} callback - One or more handler functions (middlewares and controller).
89
- * @example
90
- * router.post("/users", (req, res) => {
91
- * res.json({ message: "User created successfully" })
92
- * })
93
- */
94
- post(path, ...callback) {
95
- if (path === "/*" || path === "*") {
96
- path = /.*/;
97
- }
98
- const handlers = callback.map(wrapAsync);
99
- this.router.post(path, ...handlers);
100
- }
101
-
102
- /**
103
- * Registers a PUT route handler.
104
- * @param {string} path - The relative path for the PUT route.
105
- * @param {...Function} callback - One or more handler functions (middlewares and controller).
106
- * @example
107
- * router.put("/users/:id", (req, res) => {
108
- * res.json({ message: "User updated successfully" })
109
- * })
110
- */
111
- put(path, ...callback) {
112
- const handlers = callback.map(wrapAsync);
113
- this.router.put(path, ...handlers);
114
- }
115
-
116
- /**
117
- * Registers a DELETE route handler.
118
- * @param {string} path - The relative path for the DELETE route.
119
- * @param {...Function} callback - One or more handler functions (middlewares and controller).
120
- * @example
121
- * router.delete("/users/:id", (req, res) => {
122
- * res.json({ message: "User deleted successfully" })
123
- * })
124
- */
125
- delete(path, ...callback) {
126
- const handlers = callback.map(wrapAsync);
127
- this.router.delete(path, ...handlers);
128
- }
129
-
130
- /**
131
- * Registers a PATCH route handler.
132
- * @param {string} path - The relative path for the PATCH route.
133
- * @param {...Function} callback - One or more handler functions (middlewares and controller).
134
- * @example
135
- * router.patch("/users/:id", (req, res) => {
136
- * res.json({ message: "User patched successfully" })
137
- * })
138
- */
139
- patch(path, ...callback) {
140
- const handlers = callback.map(wrapAsync);
141
- this.router.patch(path, ...handlers);
142
- }
143
-
144
- /**
145
- * Registers an OPTIONS route handler.
146
- * @param {string} path - The relative path for the OPTIONS route.
147
- * @param {...Function} callback - One or more handler functions (middlewares and controller).
148
- */
149
- options(path, ...callback) {
150
- const handlers = callback.map(wrapAsync);
151
- this.router.options(path, ...handlers);
152
- }
153
-
154
- /**
155
- * Returns the underlying Express router instance.
156
- * @returns {import('express').Router}
157
- */
158
- getRouter() {
159
- return this.router;
160
- }
161
-
162
- /**
163
- * Returns the base path associated with this router.
164
- * @returns {string}
165
- */
166
- getPath() {
167
- return this.path;
168
- }
169
- }
170
- export { Router };
171
- export default Router;
1
+ import express from "express";
2
+ import Seo from "./seo.js";
3
+ import { createSpaMiddleware, registerSpaSeoRoutes } from "./spa.js";
4
+
5
+ /**
6
+ * Wraps route handlers to automatically catch async rejections and forward them to `next(err)`.
7
+ * @param {Function} fn - Handler function.
8
+ * @returns {Function} Wrapped handler.
9
+ */
10
+ function wrapAsync(fn) {
11
+ if (typeof fn !== "function") return fn;
12
+ return (req, res, next) => {
13
+ try {
14
+ const result = fn(req, res, next);
15
+ if (result && typeof result.catch === "function") {
16
+ result.catch(next);
17
+ }
18
+ } catch (err) {
19
+ next(err);
20
+ }
21
+ };
22
+ }
23
+
24
+ /**
25
+ * Router wrapper class for handling Express routing, HTML views, and React SPAs.
26
+ * When created with `{ seo: true }`, static GET routes and SPA routes are indexed
27
+ * in `/sitemap.xml` and `/robots.txt`.
28
+ */
29
+ class Router {
30
+ /**
31
+ * Creates a new Router instance.
32
+ * @param {string} [path="/"] - Base path for this router.
33
+ * @param {Object} [options={}] - Router configuration options.
34
+ * @param {boolean} [options.seo=false] - Register static GET routes for sitemap generation.
35
+ * @param {string[]} [options.languages=[]] - Optional language prefixes for SEO routes.
36
+ */
37
+ constructor(path = "/", options = {}) {
38
+ this.router = express.Router();
39
+ this.path = path;
40
+ this._seo = options.seo ?? false;
41
+ this._languages = options.languages || [];
42
+ this._hasSpa = false;
43
+ }
44
+
45
+ /**
46
+ * Registers a middleware on this router.
47
+ * @param {...Function} middleware
48
+ */
49
+ use(...middleware) {
50
+ const handlers = middleware.map(wrapAsync);
51
+ this.router.use(...handlers);
52
+ }
53
+
54
+ /**
55
+ * Registers a GET route handler.
56
+ * @param {string|RegExp} path
57
+ * @param {...Function} callback
58
+ */
59
+ get(path, ...callback) {
60
+ if (this._seo && typeof path === "string") {
61
+ Seo.registerRoute(this.path, path, this._languages);
62
+ }
63
+ if (path === "/*" || path === "*") {
64
+ path = /.*/;
65
+ }
66
+ const handlers = callback.map(wrapAsync);
67
+ this.router.get(path, ...handlers);
68
+ }
69
+
70
+ /**
71
+ * Registers a POST route handler.
72
+ * @param {string|RegExp} path
73
+ * @param {...Function} callback
74
+ */
75
+ post(path, ...callback) {
76
+ if (path === "/*" || path === "*") {
77
+ path = /.*/;
78
+ }
79
+ const handlers = callback.map(wrapAsync);
80
+ this.router.post(path, ...handlers);
81
+ }
82
+
83
+ /**
84
+ * Registers a PUT route handler.
85
+ * @param {string|RegExp} path
86
+ * @param {...Function} callback
87
+ */
88
+ put(path, ...callback) {
89
+ const handlers = callback.map(wrapAsync);
90
+ this.router.put(path, ...handlers);
91
+ }
92
+
93
+ /**
94
+ * Registers a DELETE route handler.
95
+ * @param {string|RegExp} path
96
+ * @param {...Function} callback
97
+ */
98
+ delete(path, ...callback) {
99
+ const handlers = callback.map(wrapAsync);
100
+ this.router.delete(path, ...handlers);
101
+ }
102
+
103
+ /**
104
+ * Registers a PATCH route handler.
105
+ * @param {string|RegExp} path
106
+ * @param {...Function} callback
107
+ */
108
+ patch(path, ...callback) {
109
+ const handlers = callback.map(wrapAsync);
110
+ this.router.patch(path, ...handlers);
111
+ }
112
+
113
+ /**
114
+ * Registers an OPTIONS route handler.
115
+ * @param {string|RegExp} path
116
+ * @param {...Function} callback
117
+ */
118
+ options(path, ...callback) {
119
+ const handlers = callback.map(wrapAsync);
120
+ this.router.options(path, ...handlers);
121
+ }
122
+
123
+ /**
124
+ * Mounts a client-rendered React SPA under `mountPath`, serving the `app/resources/index.html` shell with per-URL SEO metadata,
125
+ * JSON-LD, canonical tags, custom scripts/styles, and a full-width skeleton inside `#root`.
126
+ * @param {string} mountPath - Mount prefix (e.g. `"/app"` or `"/"`).
127
+ * @param {Object} [options={}] - SPA configuration and per-URL `meta` tree.
128
+ */
129
+ spa(mountPath, options = {}) {
130
+ this._hasSpa = true;
131
+ const cleanMount = String(mountPath || "/").replace(/\/\*+$/, "") || "/";
132
+ const baseClean = this.path === "/" ? "" : this.path.replace(/\/$/, "");
133
+ const subClean = cleanMount === "/" ? "" : `/${cleanMount.replace(/^\/+|\/+$/g, "")}`;
134
+ const fullMount = `${baseClean}${subClean}` || "/";
135
+
136
+ if ((this._seo || options.seo === true) && options.seo !== false) {
137
+ registerSpaSeoRoutes(fullMount, options, this._languages);
138
+ }
139
+
140
+ const spaMiddleware = wrapAsync(createSpaMiddleware(this.path, cleanMount, options));
141
+ this.router.use(spaMiddleware);
142
+ }
143
+
144
+ /**
145
+ * Alias for `router.spa()`.
146
+ * @param {string} mountPath
147
+ * @param {Object} [options={}]
148
+ */
149
+ SPA(mountPath, options = {}) {
150
+ return this.spa(mountPath, options);
151
+ }
152
+
153
+ /**
154
+ * Returns the underlying Express router instance.
155
+ * @returns {import('express').Router}
156
+ */
157
+ getRouter() {
158
+ return this.router;
159
+ }
160
+
161
+ /**
162
+ * Returns the base path associated with this router.
163
+ * @returns {string}
164
+ */
165
+ getPath() {
166
+ return this.path;
167
+ }
168
+ }
169
+
170
+ export { Router };
171
+ export default Router;
package/core/seo.js CHANGED
@@ -38,6 +38,16 @@ class Seo {
38
38
  }
39
39
  }
40
40
 
41
+ /**
42
+ * Removes a path from the sitemap (e.g. an unpublished or deleted blog post).
43
+ * @param {string} fullPath - Absolute path such as `/blog/my-post`.
44
+ * @returns {boolean} Whether the path was registered.
45
+ */
46
+ static unregisterRoute(fullPath) {
47
+ const clean = String(fullPath || "").trim();
48
+ return registeredSeoRoutes.delete(clean.startsWith("/") ? clean : `/${clean}`);
49
+ }
50
+
41
51
  /**
42
52
  * Returns all registered SEO route paths.
43
53
  * @returns {string[]}