@nitronjs/framework 0.3.1 → 0.3.2

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/lib/View/View.js CHANGED
@@ -109,6 +109,10 @@ class View {
109
109
 
110
110
  const devData = View.#isDev ? this.request.__devCtx : null;
111
111
 
112
+ if (!meta.lang && fastifyRequest.locale) {
113
+ meta.lang = fastifyRequest.locale;
114
+ }
115
+
112
116
  View.#setSecurityHeaders(this, nonce);
113
117
 
114
118
  return this
@@ -167,6 +171,13 @@ class View {
167
171
 
168
172
  if (result.handled) return;
169
173
 
174
+ if (result.redirect) {
175
+ return res
176
+ .code(200)
177
+ .type("application/json")
178
+ .send(JSON.stringify({ redirect: result.redirect }));
179
+ }
180
+
170
181
  if (result.status && result.status !== 200) {
171
182
  const safeError = View.#isDev ? result.error : "Request failed";
172
183
  return res.code(result.status).send({ error: safeError });
@@ -176,6 +187,7 @@ class View {
176
187
  const metadata = JSON.stringify({
177
188
  meta: result.meta || {},
178
189
  css: result.css || [],
190
+ layouts: result.layouts || [],
179
191
  translations: result.translations || {}
180
192
  });
181
193
  const body = flightPayload.length + "\n" + flightPayload + metadata;
@@ -225,6 +237,8 @@ class View {
225
237
  header: (k, v) => { originalRes.header(k, v); return mockRes; }
226
238
  };
227
239
 
240
+ originalReq._response = mockRes;
241
+
228
242
  const mockReq = {
229
243
  ...originalReq,
230
244
  url: parsedUrl.pathname,
@@ -289,6 +303,39 @@ class View {
289
303
  return this.#loadManifest()[key] || null;
290
304
  }
291
305
 
306
+ // Merge translation keys from view entry and its layout(s).
307
+ // If any source has null keys (dynamic usage), returns null to send all translations.
308
+ static #mergeTranslationKeys(entry) {
309
+ const viewKeys = entry?.translationKeys;
310
+
311
+ if (viewKeys === null) return null;
312
+
313
+ const layouts = entry?.layouts;
314
+
315
+ if (!layouts || layouts.length === 0) return viewKeys;
316
+
317
+ const manifest = this.#loadManifest();
318
+ const merged = new Set(viewKeys || []);
319
+
320
+ for (const layoutName of layouts) {
321
+ const layoutKey = `user:layout:${layoutName.toLowerCase()}`;
322
+ const layoutEntry = manifest[layoutKey];
323
+
324
+ if (!layoutEntry) continue;
325
+
326
+ const layoutKeys = layoutEntry.translationKeys;
327
+
328
+ // If any layout has dynamic keys, send all translations
329
+ if (layoutKeys === null) return null;
330
+
331
+ if (layoutKeys) {
332
+ for (const k of layoutKeys) merged.add(k);
333
+ }
334
+ }
335
+
336
+ return merged.size > 0 ? [...merged] : [];
337
+ }
338
+
292
339
  static #loadManifest() {
293
340
  let stat;
294
341
 
@@ -331,9 +378,10 @@ class View {
331
378
  }
332
379
 
333
380
  const nonce = randomBytes(16).toString("hex");
381
+ const mergedKeys = this.#mergeTranslationKeys(entry);
334
382
  const translations = Lang.getFilteredTranslations(
335
383
  fastifyRequest?.locale || Config.get("app.locale", "en"),
336
- entry?.translationKeys
384
+ mergedKeys
337
385
  );
338
386
 
339
387
  const ctx = {
package/lib/index.js CHANGED
@@ -35,6 +35,7 @@ export { default as SeederRunner } from "./Database/Seeder/SeederRunner.js";
35
35
 
36
36
  // Authentication
37
37
  export { default as Auth } from "./Auth/Auth.js";
38
+ export { default as Mfa } from "./Auth/Mfa.js";
38
39
 
39
40
  // Session
40
41
  export { default as Session } from "./Session/Session.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nitronjs/framework",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "NitronJS is a modern and extensible Node.js MVC framework built on Fastify. It focuses on clean architecture, modular structure, and developer productivity, offering built-in routing, middleware, configuration management, CLI tooling, and native React integration for scalable full-stack applications.",
5
5
  "bin": {
6
6
  "njs": "./cli/njs.js"
@@ -32,7 +32,9 @@
32
32
  "fastify": "^5.6.2",
33
33
  "mysql2": "^3.16.0",
34
34
  "nodemailer": "^7.0.11",
35
+ "otpauth": "^9.5.0",
35
36
  "postcss": "^8.5.6",
37
+ "qrcode": "^1.5.4",
36
38
  "react": "^19.2.3",
37
39
  "react-dom": "^19.2.3",
38
40
  "react-server-dom-webpack": "^19.2.4",