@nitronjs/framework 0.3.1 → 0.3.3
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/cli/create.js +6 -3
- package/cli/njs.js +26 -23
- package/lib/Auth/Auth.js +9 -4
- package/lib/Auth/Mfa.js +518 -0
- package/lib/Build/FileAnalyzer.js +32 -4
- package/lib/Build/Manager.js +22 -7
- package/lib/Build/PropUsageAnalyzer.js +123 -12
- package/lib/Console/Commands/BuildCommand.js +2 -2
- package/lib/Console/Commands/DevCommand.js +19 -10
- package/lib/Console/Commands/MakeCommand.js +2 -2
- package/lib/Console/Commands/MigrateCommand.js +1 -1
- package/lib/Console/Commands/MigrateFreshCommand.js +1 -1
- package/lib/Console/Commands/MigrateRollbackCommand.js +1 -1
- package/lib/Console/Commands/MigrateStatusCommand.js +1 -1
- package/lib/Console/Commands/SeedCommand.js +1 -1
- package/lib/Console/Commands/StartCommand.js +2 -1
- package/lib/Console/Commands/StorageLinkCommand.js +21 -32
- package/lib/Console/Stubs/rsc-consumer.tsx +17 -1
- package/lib/Console/Stubs/vendor-dev.tsx +31 -0
- package/lib/Console/Stubs/vendor.tsx +31 -0
- package/lib/Date/DateTime.js +34 -12
- package/lib/Dev/DevIndicator.js +2 -1
- package/lib/Http/Server.js +3 -2
- package/lib/Mail/Mail.js +22 -19
- package/lib/Runtime/Entry.js +1 -1
- package/lib/View/Client/spa.js +196 -112
- package/lib/View/FlightRenderer.js +5 -1
- package/lib/View/View.js +54 -6
- package/lib/index.d.ts +2 -0
- package/lib/index.js +1 -0
- package/package.json +3 -1
- /package/skeleton/database/migrations/{2025_01_01_00_00_users.js → 2025_01_01_00_00_create_users.js} +0 -0
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
|
-
|
|
384
|
+
mergedKeys
|
|
337
385
|
);
|
|
338
386
|
|
|
339
387
|
const ctx = {
|
|
@@ -675,11 +723,6 @@ class View {
|
|
|
675
723
|
|
|
676
724
|
let runtimeScript = `<script${nonceAttr}>window.__NITRON_RUNTIME__=${JSON.stringify(runtimeData)};`;
|
|
677
725
|
|
|
678
|
-
if (hasFlightPayload) {
|
|
679
|
-
const escapedPayload = flightPayload.replace(/</g, "\\u003c").replace(/>/g, "\\u003e");
|
|
680
|
-
runtimeScript += `window.__NITRON_FLIGHT__=${JSON.stringify(escapedPayload)};`;
|
|
681
|
-
}
|
|
682
|
-
|
|
683
726
|
if (translations && Object.keys(translations).length > 0) {
|
|
684
727
|
const escapedTranslations = JSON.stringify(translations).replace(/</g, "\\u003c").replace(/>/g, "\\u003e");
|
|
685
728
|
runtimeScript += `window.__NITRON_TRANSLATIONS__=${escapedTranslations};`;
|
|
@@ -687,6 +730,11 @@ class View {
|
|
|
687
730
|
|
|
688
731
|
runtimeScript += `</script>`;
|
|
689
732
|
|
|
733
|
+
if (hasFlightPayload) {
|
|
734
|
+
const escapedPayload = flightPayload.replace(/</g, "\\u003c").replace(/>/g, "\\u003e");
|
|
735
|
+
runtimeScript += `<script${nonceAttr}>window.__NITRON_FLIGHT__=${JSON.stringify(escapedPayload)};</script>`;
|
|
736
|
+
}
|
|
737
|
+
|
|
690
738
|
const vendorScript = `<script src="/storage/js/vendor.js"${nonceAttr}></script>`;
|
|
691
739
|
|
|
692
740
|
const hmrScript = this.#isDev
|
package/lib/index.d.ts
CHANGED
|
@@ -273,8 +273,10 @@ export class DateTime {
|
|
|
273
273
|
static getDate(timestamp?: string | number | null, format?: string): string;
|
|
274
274
|
static addDays(days: number): string;
|
|
275
275
|
static addHours(hours: number): string;
|
|
276
|
+
static addMinutes(minutes: number): string;
|
|
276
277
|
static subDays(days: number): string;
|
|
277
278
|
static subHours(hours: number): string;
|
|
279
|
+
static subMinutes(minutes: number): string;
|
|
278
280
|
}
|
|
279
281
|
|
|
280
282
|
export class Str {
|
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.
|
|
3
|
+
"version": "0.3.3",
|
|
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",
|
/package/skeleton/database/migrations/{2025_01_01_00_00_users.js → 2025_01_01_00_00_create_users.js}
RENAMED
|
File without changes
|