@seip/bluebird-js 0.1.6 → 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 (152) hide show
  1. package/.vscode/extensions.json +7 -7
  2. package/.vscode/settings.json +10 -10
  3. package/AGENTS.md +266 -116
  4. package/README.md +258 -245
  5. package/app/models/user.js +19 -0
  6. package/app/resources/html/home.html +137 -0
  7. package/app/resources/html/layouts/main.html +54 -0
  8. package/app/resources/html/notFound.html +14 -0
  9. package/app/resources/html/terms.html +46 -0
  10. package/app/resources/index.html +27 -0
  11. package/app/resources/layouts/AppLayout.jsx +89 -0
  12. package/app/resources/main.jsx +18 -0
  13. package/app/resources/pages/Dashboard.jsx +98 -0
  14. package/app/resources/pages/Home.jsx +140 -0
  15. package/app/resources/pages/Login.jsx +35 -0
  16. package/app/resources/pages/NotFound.jsx +16 -0
  17. package/app/resources/pages/Register.jsx +55 -0
  18. package/app/resources/routes.jsx +54 -0
  19. package/app/resources/spa.js +67 -0
  20. package/app/resources/styles.css +9 -0
  21. package/app/routes/api.js +85 -50
  22. package/app/routes/auth.js +209 -0
  23. package/app/routes/web.js +49 -37
  24. package/core/ai.d.ts +151 -151
  25. package/core/ai.js +1071 -1051
  26. package/core/app.d.ts +2 -18
  27. package/core/app.js +978 -792
  28. package/core/auth.d.ts +2 -13
  29. package/core/auth.js +444 -326
  30. package/core/cli/backup.js +167 -167
  31. package/core/cli/build.js +37 -0
  32. package/core/cli/dev.js +155 -0
  33. package/core/cli/doctor.js +37 -2
  34. package/core/cli/export.js +191 -0
  35. package/core/cli/init.js +101 -332
  36. package/core/cli/nginx.js +1 -1
  37. package/core/cli/templates.js +139 -0
  38. package/core/cli/view.js +73 -136
  39. package/core/config.js +44 -2
  40. package/core/csrf.js +156 -24
  41. package/core/database.js +737 -684
  42. package/core/debug.js +1 -1
  43. package/core/html.js +8 -1
  44. package/core/index.d.ts +1286 -1431
  45. package/core/paths.js +55 -0
  46. package/core/ratelimit.js +10 -1
  47. package/core/react/client/api.js +237 -0
  48. package/core/react/client/auth.js +236 -0
  49. package/core/react/client/components.js +1321 -0
  50. package/core/react/client/i18n.js +338 -0
  51. package/core/react/client/index.d.ts +249 -0
  52. package/core/react/client/index.js +49 -0
  53. package/core/react/client/router.js +26 -0
  54. package/core/react/client/theme.css +512 -0
  55. package/core/render-cache.js +250 -212
  56. package/core/render.d.ts +25 -21
  57. package/core/render.js +613 -603
  58. package/core/router.d.ts +2 -3
  59. package/core/router.js +171 -171
  60. package/core/seo.js +10 -0
  61. package/core/spa.js +599 -0
  62. package/core/view-loader.js +81 -455
  63. package/core/vite-plugin.d.ts +18 -0
  64. package/core/vite-plugin.js +162 -0
  65. package/core/vite.js +250 -145
  66. package/index.js +22 -18
  67. package/jsconfig.json +5 -3
  68. package/package.json +114 -92
  69. package/production.md +8 -3
  70. package/public/js/bluebird.js +1160 -0
  71. package/templates/_auth/app/database.js +19 -0
  72. package/templates/_auth/app/models/user.js +22 -0
  73. package/templates/_auth/app/routes/auth-router.js +304 -0
  74. package/templates/_base/app/resources/html/layouts/main.html +55 -0
  75. package/templates/_base/app/resources/html/notFound.html +14 -0
  76. package/templates/_base/app/resources/index.html +27 -0
  77. package/templates/_base/app/resources/styles.css +9 -0
  78. package/templates/api/app/models/note.js +18 -0
  79. package/templates/api/app/routes/api.js +82 -0
  80. package/templates/api/app/routes/auth.js +11 -0
  81. package/templates/api/index.js +19 -0
  82. package/templates/api/template.json +13 -0
  83. package/templates/auth/app/mail.js +11 -0
  84. package/templates/auth/app/models/password_reset.js +18 -0
  85. package/templates/auth/app/resources/html/home.html +21 -0
  86. package/templates/auth/app/resources/html/partials/nav.html +2 -0
  87. package/templates/auth/app/resources/layouts/AppLayout.jsx +60 -0
  88. package/templates/auth/app/resources/main.jsx +18 -0
  89. package/templates/auth/app/resources/pages/Dashboard.jsx +51 -0
  90. package/templates/auth/app/resources/pages/ForgotPassword.jsx +34 -0
  91. package/templates/auth/app/resources/pages/Login.jsx +36 -0
  92. package/templates/auth/app/resources/pages/NotFound.jsx +16 -0
  93. package/templates/auth/app/resources/pages/Profile.jsx +99 -0
  94. package/templates/auth/app/resources/pages/Register.jsx +50 -0
  95. package/templates/auth/app/resources/pages/ResetPassword.jsx +50 -0
  96. package/templates/auth/app/resources/routes.jsx +54 -0
  97. package/templates/auth/app/resources/spa.js +29 -0
  98. package/templates/auth/app/routes/api.js +17 -0
  99. package/templates/auth/app/routes/auth.js +13 -0
  100. package/templates/auth/app/routes/web.js +21 -0
  101. package/templates/auth/index.js +19 -0
  102. package/templates/auth/template.json +15 -0
  103. package/templates/blank/app/models/.gitkeep +0 -0
  104. package/templates/blank/app/resources/html/home.html +27 -0
  105. package/templates/blank/app/resources/html/partials/nav.html +1 -0
  106. package/templates/blank/app/resources/main.jsx +16 -0
  107. package/templates/blank/app/resources/pages/Home.jsx +42 -0
  108. package/templates/blank/app/resources/pages/NotFound.jsx +27 -0
  109. package/templates/blank/app/resources/routes.jsx +15 -0
  110. package/templates/blank/app/resources/spa.js +24 -0
  111. package/templates/blank/app/routes/api.js +11 -0
  112. package/templates/blank/app/routes/web.js +21 -0
  113. package/templates/blank/index.js +13 -0
  114. package/templates/blank/template.json +12 -0
  115. package/templates/blog/app/lib/blog.js +149 -0
  116. package/templates/blog/app/models/post.js +22 -0
  117. package/templates/blog/app/resources/html/home.html +28 -0
  118. package/templates/blog/app/resources/html/not-found.html +5 -0
  119. package/templates/blog/app/resources/html/partials/nav.html +2 -0
  120. package/templates/blog/app/resources/html/partials/post-card.html +9 -0
  121. package/templates/blog/app/resources/html/post.html +8 -0
  122. package/templates/blog/app/resources/layouts/AdminLayout.jsx +54 -0
  123. package/templates/blog/app/resources/main.jsx +18 -0
  124. package/templates/blog/app/resources/pages/Login.jsx +31 -0
  125. package/templates/blog/app/resources/pages/NotFound.jsx +16 -0
  126. package/templates/blog/app/resources/pages/PostEditor.jsx +51 -0
  127. package/templates/blog/app/resources/pages/Posts.jsx +83 -0
  128. package/templates/blog/app/resources/pages/Register.jsx +43 -0
  129. package/templates/blog/app/resources/routes.jsx +51 -0
  130. package/templates/blog/app/resources/spa.js +25 -0
  131. package/templates/blog/app/resources/styles.css +40 -0
  132. package/templates/blog/app/routes/api.js +77 -0
  133. package/templates/blog/app/routes/auth.js +10 -0
  134. package/templates/blog/app/routes/web.js +114 -0
  135. package/templates/blog/index.js +21 -0
  136. package/templates/blog/template.json +14 -0
  137. package/vite.config.js +11 -0
  138. package/app/views/about.jsx +0 -98
  139. package/app/views/components/Header.jsx +0 -42
  140. package/app/views/components/LiveCounter.jsx +0 -66
  141. package/app/views/dashboard.jsx +0 -300
  142. package/app/views/index.jsx +0 -123
  143. package/app/views/layouts/main/view.jsx +0 -201
  144. package/app/views/legal/terms.html +0 -29
  145. package/app/views/login.jsx +0 -141
  146. package/core/actions.d.ts +0 -4
  147. package/core/actions.js +0 -329
  148. package/core/jsx.d.ts +0 -38
  149. package/core/jsx.js +0 -1432
  150. package/core/vite.d.ts +0 -3
  151. package/public/js/bluebird-client.js +0 -3161
  152. package/public/js/tailwind.js +0 -8
@@ -1,141 +0,0 @@
1
- import { script } from "@seip/bluebird-js/core/html.js";
2
-
3
- export const route = "/login";
4
- export const layout = "main";
5
- export const seo = true;
6
-
7
- export const head = () => ({
8
- title: "Sign In — Blue Bird Framework",
9
- description: "Test native JWT authentication, encrypted cookies, and protected routes.",
10
- });
11
-
12
- /**
13
- * Login page React JSX view module.
14
- */
15
- export default function LoginView() {
16
- return (
17
- <>
18
- <section className="py-10 md:py-14 border-b border-slate-800/80">
19
- <h1 className="mt-3 text-3xl md:text-5xl font-extrabold tracking-tight bg-gradient-to-r from-sky-400 via-blue-500 to-indigo-400 bg-clip-text text-transparent">
20
- Authentication Demo
21
- </h1>
22
- <p className="mt-4 text-base md:text-lg text-slate-300 max-w-2xl leading-relaxed">
23
- Test native AES-256-GCM JWT auth cookies, Auth.protect middleware, and seamless View Transitions.
24
- </p>
25
- </section>
26
-
27
- <div className="mt-8 max-w-2xl">
28
- <div className="rounded-xl border border-sky-500/30 bg-sky-500/10 p-4 text-sky-200 mb-6">
29
- <strong className="font-semibold block text-sky-400 mb-1">Interactive Auth Testing</strong>
30
- <p className="text-sm leading-relaxed text-slate-300">
31
- Submit credentials below to generate an encrypted JWT session cookie with{" "}
32
- <code className="text-sky-300 font-mono text-xs px-1.5 py-0.5 rounded bg-slate-900 border border-slate-800">
33
- Auth.login(res, user)
34
- </code>
35
- . Try visiting <strong className="text-white">/dashboard</strong> directly before and after logging in to verify the{" "}
36
- <code className="text-sky-300 font-mono text-xs px-1.5 py-0.5 rounded bg-slate-900 border border-slate-800">
37
- Auth.protect({'{'} redirect: "/login" {'}'})
38
- </code>{" "}
39
- middleware!
40
- </p>
41
- </div>
42
-
43
- <article className="rounded-2xl border border-slate-800 bg-slate-900/60 p-6 md:p-8">
44
- <header className="mb-6">
45
- <h3 className="text-xl font-bold text-slate-100">Sign In</h3>
46
- <p className="text-sm text-slate-400 mt-1">
47
- Enter your test credentials below to start a secure session.
48
- </p>
49
- </header>
50
-
51
- <form action="/login" method="POST" id="loginForm" className="space-y-4">
52
- <div>
53
- <label
54
- htmlFor="email"
55
- className="block text-xs font-semibold uppercase tracking-wider text-slate-400 mb-1.5"
56
- >
57
- Email Address
58
- </label>
59
- <input
60
- type="email"
61
- id="email"
62
- name="email"
63
- value="alex@example.com"
64
- placeholder="alex@example.com"
65
- required
66
- className="w-full rounded-lg border border-slate-700 bg-slate-950 px-3.5 py-2.5 text-sm text-slate-100 placeholder-slate-500 focus:border-sky-500 focus:outline-none focus:ring-2 focus:ring-sky-500/20"
67
- />
68
- </div>
69
-
70
- <div>
71
- <label
72
- htmlFor="password"
73
- className="block text-xs font-semibold uppercase tracking-wider text-slate-400 mb-1.5"
74
- >
75
- Password
76
- </label>
77
- <input
78
- type="password"
79
- id="password"
80
- name="password"
81
- value="password123"
82
- placeholder="••••••••"
83
- required
84
- className="w-full rounded-lg border border-slate-700 bg-slate-950 px-3.5 py-2.5 text-sm text-slate-100 placeholder-slate-500 focus:border-sky-500 focus:outline-none focus:ring-2 focus:ring-sky-500/20"
85
- />
86
- </div>
87
-
88
- <div className="flex items-center justify-between gap-4 pt-4">
89
- <button
90
- type="submit"
91
- id="submitBtn"
92
- className="bg-sky-500 hover:bg-sky-400 text-slate-950 font-semibold px-5 py-2.5 rounded-lg text-sm transition-colors shadow-lg shadow-sky-500/20"
93
- >
94
- Sign In &rarr;
95
- </button>
96
- <a
97
- href="/dashboard"
98
- className="px-4 py-2.5 rounded-lg border border-slate-700 bg-slate-900/80 hover:bg-slate-800 text-slate-300 text-sm font-medium transition-colors"
99
- >
100
- Try /dashboard (Protected)
101
- </a>
102
- </div>
103
- </form>
104
- </article>
105
-
106
- <article className="mt-8 rounded-2xl border border-slate-800 bg-slate-900/40 p-6">
107
- <header>
108
- <h4 className="font-bold text-slate-200">What is being tested here?</h4>
109
- </header>
110
- <div className="grid grid-cols-1 md:grid-cols-2 gap-4 mt-4">
111
- <div className="rounded-xl border border-slate-800/80 bg-slate-950/60 p-4">
112
- <h5 className="font-bold text-sm text-slate-200 mb-1">1. Auth.protect Middleware</h5>
113
- <p className="text-xs text-slate-400 leading-relaxed">
114
- When an unauthenticated client requests <code className="text-sky-300 font-mono">/dashboard</code>, the server issues a 302 redirect to{" "}
115
- <code className="text-sky-300 font-mono">/login</code>. The client router automatically follows the transition smoothly.
116
- </p>
117
- </div>
118
- <div className="rounded-xl border border-slate-800/80 bg-slate-950/60 p-4">
119
- <h5 className="font-bold text-sm text-slate-200 mb-1">2. Encrypted JWT Cookies</h5>
120
- <p className="text-xs text-slate-400 leading-relaxed">
121
- Session cookies are encrypted with AES-256-GCM and marked HttpOnly and SameSite=Lax to protect against token exfiltration.
122
- </p>
123
- </div>
124
- </div>
125
- </article>
126
- </div>
127
-
128
- {script(() => {
129
- const form = document.getElementById("loginForm");
130
- const btn = document.getElementById("submitBtn");
131
- form?.addEventListener("submit", () => {
132
- if (btn) {
133
- btn.textContent = "Signing In...";
134
- btn.setAttribute("disabled", "true");
135
- }
136
- });
137
- })}
138
- </>
139
- );
140
- }
141
-
package/core/actions.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import { Actions, ActionDefinitionOptions, ActionContext } from "./index.js";
2
- export default Actions;
3
- export { Actions, ActionDefinitionOptions, ActionContext };
4
-
package/core/actions.js DELETED
@@ -1,329 +0,0 @@
1
- import Csrf from "./csrf.js";
2
- import Validator from "./validate.js";
3
- import Render from "./render.js";
4
-
5
- const DEFAULT_MAX_BYTES = 64 * 1024;
6
- const DEFAULT_MAX_DEPTH = 6;
7
- const DEFAULT_MAX_KEYS = 100;
8
- const BANNED_KEYS = new Set(["__proto__", "constructor", "prototype"]);
9
-
10
- /**
11
- * Recursively sanitizes and validates an incoming action payload object to prevent
12
- * prototype pollution (`__proto__`, `constructor`, `prototype`), excessive nesting depth,
13
- * and key-flooding memory attacks.
14
- *
15
- * @param {any} input
16
- * @param {number} [maxDepth=DEFAULT_MAX_DEPTH]
17
- * @param {number} [maxKeys=DEFAULT_MAX_KEYS]
18
- * @param {number} [currentDepth=0]
19
- * @param {{ count: number }} [keyCounter={ count: 0 }]
20
- * @returns {any}
21
- */
22
- export function sanitizeActionPayload(
23
- input,
24
- maxDepth = DEFAULT_MAX_DEPTH,
25
- maxKeys = DEFAULT_MAX_KEYS,
26
- currentDepth = 0,
27
- keyCounter = { count: 0 }
28
- ) {
29
- if (input === null || input === undefined) return input;
30
- if (typeof input !== "object") return input;
31
-
32
- if (currentDepth > maxDepth) {
33
- const err = new Error("Payload nesting depth limit exceeded.");
34
- err.statusCode = 413;
35
- throw err;
36
- }
37
-
38
- if (Array.isArray(input)) {
39
- if (input.length > maxKeys) {
40
- const err = new Error(`Payload array length exceeds maximum allowed (${maxKeys}).`);
41
- err.statusCode = 413;
42
- throw err;
43
- }
44
- return input.map((item) =>
45
- sanitizeActionPayload(item, maxDepth, maxKeys, currentDepth + 1, keyCounter)
46
- );
47
- }
48
-
49
- const clean = Object.create(null);
50
- const entries = Object.entries(input);
51
- for (const [k, v] of entries) {
52
- if (BANNED_KEYS.has(k)) continue;
53
- keyCounter.count++;
54
- if (keyCounter.count > maxKeys) {
55
- const err = new Error(`Payload key count exceeds maximum allowed (${maxKeys}).`);
56
- err.statusCode = 413;
57
- throw err;
58
- }
59
- clean[k] = sanitizeActionPayload(v, maxDepth, maxKeys, currentDepth + 1, keyCounter);
60
- }
61
-
62
- return { ...clean };
63
- }
64
-
65
- /**
66
- * Parses byte size strings like "64kb", "1mb", or numbers into integer bytes.
67
- * @param {number|string} [limit]
68
- * @returns {number}
69
- */
70
- export function parseByteLimit(limit) {
71
- if (typeof limit === "number" && limit > 0) return limit;
72
- if (typeof limit === "string") {
73
- const match = limit.trim().match(/^(\d+(?:\.\d+)?)\s*(b|kb|mb)?$/i);
74
- if (match) {
75
- const num = parseFloat(match[1]);
76
- const unit = (match[2] || "b").toLowerCase();
77
- if (unit === "mb") return Math.floor(num * 1024 * 1024);
78
- if (unit === "kb") return Math.floor(num * 1024);
79
- return Math.floor(num);
80
- }
81
- }
82
- return DEFAULT_MAX_BYTES;
83
- }
84
-
85
- /**
86
- * Native Server Actions manager for Bluebird.js.
87
- * Wraps server mutation handlers with automatic CSRF verification, strict payload size/depth/key
88
- * guards, optional schema validation, and reactive partial SSR re-rendering.
89
- */
90
- export class Actions {
91
- /**
92
- * Defines a single server action or a map of server actions with security and validation options.
93
- *
94
- * @example
95
- * // Single action with schema validation and 32KB max payload
96
- * export const actions = {
97
- * updateProfile: Actions.define(
98
- * {
99
- * schema: { name: { required: true, min: 2 } },
100
- * maxBytes: "32kb",
101
- * },
102
- * async ({ body, req, user }) => {
103
- * await User.update(user.id, body, { only: ["name"] });
104
- * return { updated: true };
105
- * }
106
- * ),
107
- * };
108
- *
109
- * @param {Object|Function} optionsOrMap - Options object, action map, or handler function.
110
- * @param {Function} [handlerFn] - Action handler function when first argument is options.
111
- * @returns {Object}
112
- */
113
- static define(optionsOrMap, handlerFn) {
114
- if (typeof optionsOrMap === "function") {
115
- return {
116
- __bb_action__: true,
117
- options: {},
118
- handler: optionsOrMap,
119
- };
120
- }
121
-
122
- if (typeof handlerFn === "function") {
123
- return {
124
- __bb_action__: true,
125
- options: optionsOrMap || {},
126
- handler: handlerFn,
127
- };
128
- }
129
-
130
- if (optionsOrMap && typeof optionsOrMap === "object") {
131
- const out = {};
132
- for (const [key, val] of Object.entries(optionsOrMap)) {
133
- if (typeof val === "function") {
134
- out[key] = { __bb_action__: true, options: {}, handler: val };
135
- } else if (val && typeof val === "object" && typeof val.handler === "function") {
136
- out[key] = {
137
- __bb_action__: true,
138
- options: val.options || val,
139
- handler: val.handler,
140
- };
141
- }
142
- }
143
- return out;
144
- }
145
-
146
- return {};
147
- }
148
-
149
- /**
150
- * Express route handler that dispatches incoming POST requests to the matching Server Action
151
- * exported by a view module (`export const actions = { ... }`).
152
- *
153
- * Security checks performed automatically before invoking the action:
154
- * 1. CSRF verification (header `x-csrf-token` or body `_csrf` matched against signed `_csrf` cookie).
155
- * 2. Payload byte size guard (`Content-Length` and serialized body byte length, default 64KB).
156
- * 3. Prototype pollution & deep-nesting guard (`__proto__`, `constructor`, `prototype`, maxDepth, maxKeys).
157
- * 4. Optional `Validator` schema check if `schema` is configured on the action.
158
- *
159
- * @param {string} viewName - View name associated with the route.
160
- * @param {Record<string, any>} actionsMap - Exported `actions` object from the view module.
161
- * @returns {Function} Express route handler.
162
- */
163
- static createDispatcher(viewName, actionsMap) {
164
- return async (req, res) => {
165
- const actionName =
166
- req.headers["x-bluebird-action"] ||
167
- req.body?._action ||
168
- req.query?._action ||
169
- "default";
170
-
171
- const rawAction =
172
- actionsMap[actionName] ||
173
- (actionName === "default" && typeof actionsMap === "function" ? actionsMap : null);
174
-
175
- if (!rawAction) {
176
- return res.status(404).json({
177
- status: "error",
178
- message: `Action '${String(actionName)}' not found on view '${viewName}'.`,
179
- });
180
- }
181
-
182
- const actionDef =
183
- typeof rawAction === "function"
184
- ? { options: {}, handler: rawAction }
185
- : rawAction;
186
- const opts = actionDef.options || {};
187
- const handler = actionDef.handler;
188
-
189
- if (typeof handler !== "function") {
190
- return res.status(404).json({
191
- status: "error",
192
- message: `Invalid handler for action '${String(actionName)}'.`,
193
- });
194
- }
195
-
196
- const maxBytes = parseByteLimit(opts.maxBytes ?? opts.limit ?? DEFAULT_MAX_BYTES);
197
- const maxDepth = opts.maxDepth ?? DEFAULT_MAX_DEPTH;
198
- const maxKeys = opts.maxKeys ?? DEFAULT_MAX_KEYS;
199
-
200
- const contentLength = parseInt(req.headers["content-length"] || "0", 10);
201
- if (contentLength > maxBytes) {
202
- return res.status(413).json({
203
- status: "error",
204
- message: `Action payload too large (exceeds ${maxBytes} bytes).`,
205
- });
206
- }
207
-
208
- const rawBodyStr = JSON.stringify(req.body || {});
209
- if (Buffer.byteLength(rawBodyStr, "utf-8") > maxBytes) {
210
- return res.status(413).json({
211
- status: "error",
212
- message: `Action payload size exceeds maximum allowed (${maxBytes} bytes).`,
213
- });
214
- }
215
-
216
- if (opts.csrf !== false) {
217
- const cookieToken = req.cookies?.["_csrf"];
218
- const headerToken =
219
- req.headers["x-csrf-token"] ||
220
- req.body?._csrf ||
221
- req.query?._csrf;
222
-
223
- if (
224
- !cookieToken ||
225
- !headerToken ||
226
- cookieToken !== headerToken ||
227
- !Csrf.verifyToken(headerToken)
228
- ) {
229
- return res.status(403).json({
230
- status: "error",
231
- message: "Invalid or missing CSRF token for server action.",
232
- });
233
- }
234
- }
235
-
236
- let safeBody = {};
237
- try {
238
- safeBody = sanitizeActionPayload(req.body || {}, maxDepth, maxKeys);
239
- delete safeBody._csrf;
240
- delete safeBody._action;
241
- } catch (err) {
242
- return res.status(err.statusCode || 400).json({
243
- status: "error",
244
- message: err.message || "Invalid action payload.",
245
- });
246
- }
247
-
248
- if (opts.schema) {
249
- const validator =
250
- opts.schema instanceof Validator
251
- ? opts.schema
252
- : new Validator(opts.schema, req.lang || "en");
253
- const validation = await validator.validate(safeBody);
254
- if (!validation.success) {
255
- return res.status(400).json({
256
- status: "error",
257
- message: validation.message?.[0] || "Validation failed.",
258
- errors: validation.errors,
259
- });
260
- }
261
- }
262
-
263
- const ctx = {
264
- req,
265
- res,
266
- user: req.user,
267
- body: safeBody,
268
- payload: safeBody,
269
- params: req.params || {},
270
- query: req.query || {},
271
- action: String(actionName),
272
- };
273
-
274
- const result = await handler(ctx, safeBody);
275
- if (res.headersSent) return;
276
-
277
- if (result && typeof result === "object" && typeof result.redirect === "string") {
278
- return Render.redirect(req, res, result.redirect);
279
- }
280
-
281
- const wantsPartial =
282
- req.headers["x-bluebird-partial"] === "1" ||
283
- req.query?._partial === "1" ||
284
- (result && typeof result === "object" && result.reRender === true);
285
-
286
- if (wantsPartial) {
287
- const extraProps =
288
- result && typeof result === "object" && !Array.isArray(result)
289
- ? result.props || result
290
- : {};
291
- return Render.send(res, viewName, {
292
- user: req.user,
293
- params: req.params,
294
- query: req.query,
295
- actionResult: result,
296
- ...extraProps,
297
- _layout: false,
298
- });
299
- }
300
-
301
- const expectsJson =
302
- req.headers["x-bluebird-action"] ||
303
- req.headers["x-requested-with"] === "XMLHttpRequest" ||
304
- req.headers.accept?.includes("application/json");
305
-
306
- if (expectsJson) {
307
- return res.status(200).json({
308
- status: "success",
309
- action: String(actionName),
310
- data: result ?? null,
311
- });
312
- }
313
-
314
- const extraProps =
315
- result && typeof result === "object" && !Array.isArray(result)
316
- ? result.props || result
317
- : {};
318
- return Render.send(res, viewName, {
319
- user: req.user,
320
- params: req.params,
321
- query: req.query,
322
- actionResult: result,
323
- ...extraProps,
324
- });
325
- };
326
- }
327
- }
328
-
329
- export default Actions;
package/core/jsx.d.ts DELETED
@@ -1,38 +0,0 @@
1
- import {
2
- h,
3
- createElement,
4
- jsx,
5
- jsxs,
6
- Fragment,
7
- Island,
8
- Client,
9
- IslandComponentProps,
10
- isJsxElement,
11
- renderJsxToString,
12
- compileJsx,
13
- registerJsxLoader,
14
- useState,
15
- useEffect,
16
- useRef,
17
- useMemo,
18
- useCallback,
19
- } from "./index.js";
20
- export {
21
- h,
22
- createElement,
23
- jsx,
24
- jsxs,
25
- Fragment,
26
- Island,
27
- Client,
28
- IslandComponentProps,
29
- isJsxElement,
30
- renderJsxToString,
31
- compileJsx,
32
- registerJsxLoader,
33
- useState,
34
- useEffect,
35
- useRef,
36
- useMemo,
37
- useCallback,
38
- };