@nifrajs/cli 5.9.0 → 5.11.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 (136) hide show
  1. package/CHANGELOG.md +85 -0
  2. package/dist/check-diagnostics.d.ts +1 -0
  3. package/dist/check-diagnostics.d.ts.map +1 -1
  4. package/dist/check-diagnostics.js +4 -0
  5. package/dist/check-diagnostics.js.map +1 -1
  6. package/dist/check-scan.d.ts +1 -0
  7. package/dist/check-scan.d.ts.map +1 -1
  8. package/dist/check-scan.js +8 -1
  9. package/dist/check-scan.js.map +1 -1
  10. package/dist/check.d.ts.map +1 -1
  11. package/dist/check.js +7 -2
  12. package/dist/check.js.map +1 -1
  13. package/dist/cli.d.ts.map +1 -1
  14. package/dist/cli.js +21 -20
  15. package/dist/cli.js.map +1 -1
  16. package/dist/command-catalog.d.ts +1 -5
  17. package/dist/command-catalog.d.ts.map +1 -1
  18. package/dist/command-catalog.js +2 -21
  19. package/dist/command-catalog.js.map +1 -1
  20. package/dist/doctor.js +2 -2
  21. package/dist/doctor.js.map +1 -1
  22. package/dist/internal/source-facts.d.ts +30 -0
  23. package/dist/internal/source-facts.d.ts.map +1 -1
  24. package/dist/internal/source-facts.js +127 -0
  25. package/dist/internal/source-facts.js.map +1 -1
  26. package/dist/load.d.ts +4 -2
  27. package/dist/load.d.ts.map +1 -1
  28. package/dist/load.js +6 -1
  29. package/dist/load.js.map +1 -1
  30. package/dist/mcp-delegate.d.ts +17 -3
  31. package/dist/mcp-delegate.d.ts.map +1 -1
  32. package/dist/mcp-delegate.js +24 -9
  33. package/dist/mcp-delegate.js.map +1 -1
  34. package/dist/mcp-http.js +1 -1
  35. package/dist/mcp-http.js.map +1 -1
  36. package/dist/mcp-relay.d.ts +37 -0
  37. package/dist/mcp-relay.d.ts.map +1 -0
  38. package/dist/mcp-relay.js +129 -0
  39. package/dist/mcp-relay.js.map +1 -0
  40. package/dist/mcp-tool-meta.d.ts.map +1 -1
  41. package/dist/mcp-tool-meta.js +0 -1
  42. package/dist/mcp-tool-meta.js.map +1 -1
  43. package/dist/mcp.d.ts.map +1 -1
  44. package/dist/mcp.js +55 -1
  45. package/dist/mcp.js.map +1 -1
  46. package/dist/migrate-layout.d.ts.map +1 -1
  47. package/dist/migrate-layout.js +45 -33
  48. package/dist/migrate-layout.js.map +1 -1
  49. package/dist/recipes/5.10.0.d.ts +13 -0
  50. package/dist/recipes/5.10.0.d.ts.map +1 -0
  51. package/dist/recipes/5.10.0.js +45 -0
  52. package/dist/recipes/5.10.0.js.map +1 -0
  53. package/dist/recipes/5.11.0.d.ts +10 -0
  54. package/dist/recipes/5.11.0.d.ts.map +1 -0
  55. package/dist/recipes/5.11.0.js +50 -0
  56. package/dist/recipes/5.11.0.js.map +1 -0
  57. package/dist/recipes/index.d.ts.map +1 -1
  58. package/dist/recipes/index.js +4 -0
  59. package/dist/recipes/index.js.map +1 -1
  60. package/dist/review.d.ts.map +1 -1
  61. package/dist/review.js +3 -0
  62. package/dist/review.js.map +1 -1
  63. package/dist/rules/codes.d.ts +3 -0
  64. package/dist/rules/codes.d.ts.map +1 -1
  65. package/dist/rules/codes.js +3 -0
  66. package/dist/rules/codes.js.map +1 -1
  67. package/dist/rules/explanations.d.ts.map +1 -1
  68. package/dist/rules/explanations.js +15 -0
  69. package/dist/rules/explanations.js.map +1 -1
  70. package/dist/rules/internal-links.d.ts +5 -0
  71. package/dist/rules/internal-links.d.ts.map +1 -0
  72. package/dist/rules/internal-links.js +418 -0
  73. package/dist/rules/internal-links.js.map +1 -0
  74. package/dist/rules/legacy.d.ts.map +1 -1
  75. package/dist/rules/legacy.js +20 -0
  76. package/dist/rules/legacy.js.map +1 -1
  77. package/dist/rules/server-fn-namespace.d.ts +8 -0
  78. package/dist/rules/server-fn-namespace.d.ts.map +1 -0
  79. package/dist/rules/server-fn-namespace.js +43 -0
  80. package/dist/rules/server-fn-namespace.js.map +1 -0
  81. package/dist/rules/source-scan.d.ts +29 -0
  82. package/dist/rules/source-scan.d.ts.map +1 -0
  83. package/dist/rules/source-scan.js +38 -0
  84. package/dist/rules/source-scan.js.map +1 -0
  85. package/dist/rules/text-slot-boolean.d.ts.map +1 -1
  86. package/dist/rules/text-slot-boolean.js +21 -43
  87. package/dist/rules/text-slot-boolean.js.map +1 -1
  88. package/dist/source-rewrites.d.ts +0 -5
  89. package/dist/source-rewrites.d.ts.map +1 -1
  90. package/dist/source-rewrites.js +350 -10
  91. package/dist/source-rewrites.js.map +1 -1
  92. package/dist/typecheck-coverage.d.ts +9 -0
  93. package/dist/typecheck-coverage.d.ts.map +1 -1
  94. package/dist/typecheck-coverage.js +16 -0
  95. package/dist/typecheck-coverage.js.map +1 -1
  96. package/dist/upgrade.d.ts +19 -1
  97. package/dist/upgrade.d.ts.map +1 -1
  98. package/dist/upgrade.js +55 -2
  99. package/dist/upgrade.js.map +1 -1
  100. package/docs/examples.json +21 -9
  101. package/docs/llms-full.txt +800 -262
  102. package/docs/types.json +868 -128
  103. package/package.json +11 -11
  104. package/src/check-diagnostics.ts +5 -0
  105. package/src/check-scan.ts +9 -1
  106. package/src/check.ts +15 -3
  107. package/src/cli.ts +25 -20
  108. package/src/command-catalog.ts +2 -26
  109. package/src/doctor.ts +2 -2
  110. package/src/internal/source-facts.ts +155 -0
  111. package/src/load.ts +15 -3
  112. package/src/mcp-delegate.ts +37 -11
  113. package/src/mcp-http.ts +1 -1
  114. package/src/mcp-relay.ts +155 -0
  115. package/src/mcp-tool-meta.ts +0 -1
  116. package/src/mcp.ts +51 -1
  117. package/src/migrate-layout.ts +61 -29
  118. package/src/recipes/5.10.0.ts +46 -0
  119. package/src/recipes/5.11.0.ts +51 -0
  120. package/src/recipes/index.ts +4 -0
  121. package/src/review.ts +3 -0
  122. package/src/rules/codes.ts +3 -0
  123. package/src/rules/explanations.ts +15 -0
  124. package/src/rules/internal-links.ts +490 -0
  125. package/src/rules/legacy.ts +21 -0
  126. package/src/rules/server-fn-namespace.ts +47 -0
  127. package/src/rules/source-scan.ts +66 -0
  128. package/src/rules/text-slot-boolean.ts +26 -42
  129. package/src/source-rewrites.ts +383 -12
  130. package/src/typecheck-coverage.ts +23 -0
  131. package/src/upgrade.ts +71 -3
  132. package/dist/sync-routes.d.ts +0 -29
  133. package/dist/sync-routes.d.ts.map +0 -1
  134. package/dist/sync-routes.js +0 -56
  135. package/dist/sync-routes.js.map +0 -1
  136. package/src/sync-routes.ts +0 -70
@@ -207,7 +207,7 @@
207
207
  "name": "RESPONSE_CONTROLS",
208
208
  "topic": "Nifra - Framework contract",
209
209
  "slug": "contract",
210
- "code": "// routes/account.backend.ts - response headers and cookies, from a loader or an action.\nimport { t } from \"@nifrajs/schema\"\nimport { type LoaderContext, redirect } from \"@nifrajs/web\"\n\ndeclare function signIn(email: string, password: string): Promise<{ token: string } | null>\n\nexport const loaderOutput = t.object({ plan: t.string() })\nexport const actionOutput = t.object({ error: t.string() })\n\nexport async function loader(ctx: LoaderContext) {\n // Headers land on the rendered document.\n ctx.set.headers[\"cache-control\"] = \"public, max-age=60\"\n ctx.set.headers[\"x-robots-tag\"] = \"noindex\"\n return { plan: \"pro\" }\n}\n\nexport async function action(ctx: LoaderContext) {\n const form = await ctx.request.formData()\n const session = await signIn(String(form.get(\"email\")), String(form.get(\"password\")))\n if (session === null) return { error: \"Wrong email or password\" }\n // HttpOnly; Secure; SameSite=Lax; Path=/ unless the options say otherwise.\n ctx.set.cookie(\"session\", session.token, { maxAge: 60 * 60 * 24 * 7 })\n throw redirect(\"/dashboard\") // the cookie rides the redirect\n}"
210
+ "code": "// routes/account.backend.ts - response headers and cookies, from a loader or an action.\nimport { t } from \"@nifrajs/schema\"\nimport { type LoaderContext, rawHref, redirect } from \"@nifrajs/web\"\n\ndeclare function signIn(email: string, password: string): Promise<{ token: string } | null>\n\nexport const loaderOutput = t.object({ plan: t.string() })\nexport const actionOutput = t.object({ error: t.string() })\n\nexport async function loader(ctx: LoaderContext) {\n // Headers land on the rendered document.\n ctx.set.headers[\"cache-control\"] = \"public, max-age=60\"\n ctx.set.headers[\"x-robots-tag\"] = \"noindex\"\n return { plan: \"pro\" }\n}\n\nexport async function action(ctx: LoaderContext) {\n const form = await ctx.request.formData()\n const session = await signIn(String(form.get(\"email\")), String(form.get(\"password\")))\n if (session === null) return { error: \"Wrong email or password\" }\n // HttpOnly; Secure; SameSite=Lax; Path=/ unless the options say otherwise.\n ctx.set.cookie(\"session\", session.token, { maxAge: 60 * 60 * 24 * 7 })\n throw redirect(rawHref(\"/dashboard\")) // the cookie rides the redirect\n}"
211
211
  },
212
212
  {
213
213
  "name": "REUSABLE_ROUTER",
@@ -381,7 +381,7 @@
381
381
  "name": "GUARD",
382
382
  "topic": "Nifra - i18n",
383
383
  "slug": "i18n",
384
- "code": "// routes/[lang]/_layout.backend.ts - 404 unknown and draft locales, redirect /en/... to /...\nimport { defineLocales } from \"@nifrajs/i18n\"\nimport { defineI18nRouting } from \"@nifrajs/i18n/routing\"\nimport { notFound, type RouteMiddleware, redirect } from \"@nifrajs/web\"\n\nconst urls = defineI18nRouting(\n defineLocales({ default: \"en\", locales: { en: {}, hi: {}, gu: { draft: true } } }),\n)\n\nexport const middleware: RouteMiddleware = (ctx) => {\n const { pathname, search } = new URL(ctx.request.url)\n const match = urls.matchSegment(ctx.params.lang, pathname + search)\n if (match.kind === \"not-found\") notFound()\n if (match.kind === \"redirect\") return redirect(match.location, { status: 308 })\n return undefined\n}"
384
+ "code": "// routes/[lang]/_layout.backend.ts - 404 unknown and draft locales, redirect /en/... to /...\nimport { defineLocales } from \"@nifrajs/i18n\"\nimport { defineI18nRouting } from \"@nifrajs/i18n/routing\"\nimport { notFound, type RouteMiddleware, rawHref, redirect } from \"@nifrajs/web\"\n\nconst urls = defineI18nRouting(\n defineLocales({ default: \"en\", locales: { en: {}, hi: {}, gu: { draft: true } } }),\n)\n\nexport const middleware: RouteMiddleware = (ctx) => {\n const { pathname, search } = new URL(ctx.request.url)\n const match = urls.matchSegment(ctx.params.lang, pathname + search)\n if (match.kind === \"not-found\") notFound()\n if (match.kind === \"redirect\") return redirect(rawHref(match.location), { status: 308 })\n return undefined\n}"
385
385
  },
386
386
  {
387
387
  "name": "LOCALES",
@@ -395,12 +395,24 @@
395
395
  "slug": "i18n",
396
396
  "code": "// routes/index.backend.ts - resolve the locale + return only that catalog's messages.\nimport { negotiateLocale } from \"@nifrajs/i18n\"\nimport { t } from \"@nifrajs/schema\"\nimport { catalogs, locales } from \"../shared/catalogs\"\nimport type { Route } from \"./+types/index\"\n\n// A catalog is open-ended, so its schema is the explicit opt-out of the strict default.\nexport const loaderOutput = t.object({ locale: t.string(), messages: t.looseObject({}) })\nexport async function loader({ request }: Route.LoaderArgs) {\n const locale = negotiateLocale(request, { locales, defaultLocale: \"en\", queryParam: \"lang\", cookie: \"lang\" })\n return { locale, messages: catalogs[locale] } // ?lang= → cookie → Accept-Language → default\n}"
397
397
  },
398
+ {
399
+ "name": "TRANSLATED_PATHNAMES",
400
+ "topic": "Nifra - i18n",
401
+ "slug": "i18n",
402
+ "code": "// shared/i18n.ts - explicit STATIC pathname translations, not content or dynamic slug translation.\nimport { defineLocales } from \"@nifrajs/i18n\"\nimport { defineI18nRouting } from \"@nifrajs/i18n/routing\"\n\nconst locales = defineLocales({ default: \"en\", locales: { en: {}, fr: {}, de: {} } })\nexport const urls = defineI18nRouting(locales, {\n pathnames: {\n \"/about\": { fr: \"/a-propos\", de: \"/ueber-uns\" },\n \"/contact\": { fr: \"/contactez-nous\" }, // Missing German name; availability is separate below.\n },\n // Always the canonical key, even when the incoming URL is /fr/contactez-nous.\n pageLocales: (path) => path === \"/contact\" ? [\"en\", \"fr\"] : undefined,\n})\n\nurls.localizePathname(\"/about\", \"fr\") // \"/fr/a-propos\"\nurls.localizePathname(\"/fr/a-propos\", \"de\") // \"/de/ueber-uns\"\nurls.unlocalizePathname(\"/de/ueber-uns\") // { locale: \"de\", pathname: \"/about\" }\nurls.alternates(\"/fr/a-propos\").canonical // \"/fr/a-propos\"\nurls.staticPathnames() // [\"/about\", \"/fr/a-propos\", \"/de/ueber-uns\", \"/contact\", \"/fr/contactez-nous\"]"
403
+ },
398
404
  {
399
405
  "name": "DIMENSIONS",
400
406
  "topic": "Nifra - images",
401
407
  "slug": "images",
402
408
  "code": "import { imageDimensions, readImageDimensions } from \"@nifrajs/image\"\n\n// Pure-JS header read - PNG / JPEG / GIF / WebP. No decode, no codec, no deps.\nconst info = await readImageDimensions(Bun.file(\"public/hero.jpg\"))\n// → { width: 1200, height: 630, format: \"jpeg\" } (null if unrecognized)\n\n// Build-time tooling: pre-read sizes into a manifest so <Image> is CLS-safe\n// without hardcoding width/height at every call site. The sync variant takes the\n// raw header bytes you already have in memory (no file read):\nconst headerBytes = await Bun.file(\"public/hero.jpg\").bytes()\nimageDimensions(headerBytes)"
403
409
  },
410
+ {
411
+ "name": "IMPORT_PLUGINS",
412
+ "topic": "Nifra - images",
413
+ "slug": "images",
414
+ "code": "// backend/framework.ts — add these beside your existing framework plugins:\nimport { imageBunPlugin } from \"@nifrajs/image/plugins\"\n\nconst images = { root: process.cwd() }\nexport const clientPlugins = [imageBunPlugin(images)]\nexport const serverPlugins = [imageBunPlugin(images)]\n\n// For the Vite pipeline instead (including component mode):\n// import { imageVitePlugin } from \"@nifrajs/image/plugins\"\n// export const vitePlugins = [imageVitePlugin(images)]"
415
+ },
404
416
  {
405
417
  "name": "LOADERS",
406
418
  "topic": "Nifra - images",
@@ -487,19 +499,19 @@
487
499
  },
488
500
  {
489
501
  "name": "BACKEND",
490
- "topic": "Nifra - Partial prerendering (experimental)",
502
+ "topic": "Nifra - Partial prerendering",
491
503
  "slug": "partial-prerendering",
492
504
  "code": "import { t } from \"@nifrajs/schema\"\nimport type { BoundaryRequestCtx } from \"@nifrajs/web\"\nimport { defineShellLoader } from \"@nifrajs/web/ppr\"\nimport type { Route } from \"./+types/[id]\"\n\nconst titles: Readonly<Record<string, string>> = { \"1\": \"Sencha\", \"2\": \"Hojicha\" }\nconst cartCount = (request: Request): number => (request.headers.has(\"cookie\") ? 2 : 0)\n\n// The shell: no request, no cookies. It is built once and shared by every visitor.\nexport const shellLoader = defineShellLoader(async ({ params }) => ({\n title: titles[params.id ?? \"\"] ?? \"Tea\",\n}))\nexport const shellOutput = t.object({ title: t.string() })\nexport const revalidate = 60\nexport const revalidateTags = [\"catalog\"]\nexport const shellVariations = { search: { size: [\"50g\", \"100g\"] } }\n\n// The holes: each runs per request, under its own deadline.\nexport const boundaryLoaders = {\n cart: {\n load: (ctx: BoundaryRequestCtx) => ({ count: cartCount(ctx.request) }),\n output: t.object({ count: t.number() }),\n },\n} satisfies Route.BoundaryLoaders"
493
505
  },
494
506
  {
495
507
  "name": "SERVER",
496
- "topic": "Nifra - Partial prerendering (experimental)",
508
+ "topic": "Nifra - Partial prerendering",
497
509
  "slug": "partial-prerendering",
498
- "code": "import { createCspPolicy, createWebApp } from \"@nifrajs/web\"\nimport { discoverRoutes } from \"@nifrajs/web/fs\"\nimport { compileShells, partialPrerendering } from \"@nifrajs/web/ppr\"\nimport { reactAdapter } from \"@nifrajs/web-react\"\n\nconst routesDir = \"./routes\"\nconst manifest = discoverRoutes(routesDir)\n// The content-hashed client entry from your build; a shell check record is valid for it only.\nconst clientEntry = \"/assets/entry-4c5ndncr.js\"\n\n// Fails a route whose shell reaches a module that reads the visitor. That route renders whole.\nconst shellChecks = await compileShells({\n routesDir,\n manifest,\n deployment: clientEntry,\n requestScoped: (file) => file.endsWith(\"/lib/session.ts\"),\n onFailure: (routeId, error) => console.warn(routeId, error),\n})\n\nexport const app = createWebApp({\n adapter: reactAdapter,\n manifest,\n clientEntry,\n // Hashes, not a nonce: a shell is one document for every visitor.\n csp: createCspPolicy({\n header: ({ sources }) => `script-src 'self' ${sources}; object-src 'none'; base-uri 'none'`,\n }),\n experimental: {\n ppr: partialPrerendering({ shellChecks, origin: \"https://shop.example\" }),\n },\n})"
510
+ "code": "import { createCspPolicy, createWebApp } from \"@nifrajs/web\"\nimport { discoverRoutes } from \"@nifrajs/web/fs\"\nimport { compileShells, partialPrerendering } from \"@nifrajs/web/ppr\"\nimport { reactAdapter } from \"@nifrajs/web-react\"\n\nconst routesDir = \"./routes\"\nconst manifest = discoverRoutes(routesDir)\n// The content-hashed client entry from your build; a shell check record is valid for it only.\nconst clientEntry = \"/assets/entry-4c5ndncr.js\"\n\n// Fails a route whose shell reaches a module that reads the visitor. That route renders whole.\nconst shellChecks = await compileShells({\n routesDir,\n manifest,\n deployment: clientEntry,\n requestScoped: (file) => file.endsWith(\"/lib/session.ts\"),\n onFailure: (routeId, error) => console.warn(routeId, error),\n})\n\nexport const app = createWebApp({\n adapter: reactAdapter,\n manifest,\n clientEntry,\n // Hashes, not a nonce: a shell is one document for every visitor.\n csp: createCspPolicy({\n header: ({ sources }) => `script-src 'self' ${sources}; object-src 'none'; base-uri 'none'`,\n }),\n ppr: partialPrerendering({ shellChecks, origin: \"https://shop.example\" }),\n})"
499
511
  },
500
512
  {
501
513
  "name": "SHARED_BACKEND",
502
- "topic": "Nifra - Partial prerendering (experimental)",
514
+ "topic": "Nifra - Partial prerendering",
503
515
  "slug": "partial-prerendering",
504
516
  "code": "import { t } from \"@nifrajs/schema\"\nimport type { ShellCtx } from \"@nifrajs/web\"\nimport type { Route } from \"./+types/[id]\"\n\nconst prices: Readonly<Record<string, string>> = { \"1\": \"$12.00\", \"2\": \"$9.50\" }\n\nexport const boundaryLoaders = {\n // Inline, with revalidate: the build checks this loader with the shell, so its frame is stored.\n price: {\n load: async ({ params }: ShellCtx) => ({ amount: prices[params.id ?? \"\"] ?? \"-\" }),\n output: t.object({ amount: t.string() }),\n revalidate: 10,\n revalidateTags: ({ params }) => [`price:${params.id}`],\n },\n} satisfies Route.BoundaryLoaders"
505
517
  },
@@ -633,7 +645,7 @@
633
645
  "name": "MIDDLEWARE",
634
646
  "topic": "Nifra - Routing",
635
647
  "slug": "routing",
636
- "code": "// routes/account/_layout.backend.ts - runs before every page under /account\nimport { type RouteMiddleware, redirect } from \"@nifrajs/web\"\n\nexport const middleware: RouteMiddleware = ({ request, set }) => {\n set.headers[\"cache-control\"] = \"private, no-store\"\n const signedIn = request.headers.get(\"cookie\")?.includes(\"session=\") ?? false\n return signedIn ? undefined : redirect(\"/login\")\n}"
648
+ "code": "// routes/account/_layout.backend.ts - runs before every page under /account\nimport { type RouteMiddleware, rawHref, redirect } from \"@nifrajs/web\"\n\nexport const middleware: RouteMiddleware = ({ request, set }) => {\n set.headers[\"cache-control\"] = \"private, no-store\"\n const signedIn = request.headers.get(\"cookie\")?.includes(\"session=\") ?? false\n return signedIn ? undefined : redirect(rawHref(\"/login\"))\n}"
637
649
  },
638
650
  {
639
651
  "name": "ROUTE_BACKEND",
@@ -651,7 +663,7 @@
651
663
  "name": "BOUNDED",
652
664
  "topic": "Nifra - security & hardening",
653
665
  "slug": "security",
654
- "code": "import { server } from \"@nifrajs/core/server\"\n\nconst app = server()\n\n// A schema route is ALREADY bounded - the validated read enforces `maxBodyBytes`.\n// But a raw-body / file / BYO-validation route reads the body directly, which\n// `maxBodyBytes` does not cover. `c.boundedBody` caps that read:\napp.post(\"/import\", async (c) => {\n const bytes = await c.boundedBody(5 * 1024 * 1024) // cap THIS route at 5 MiB\n // Over-cap throws a flat 413; a malformed Content-Length a 400 - as control-flow\n // Responses (caught by the lifecycle like `throw redirect()`), so a handler can't\n // accidentally ignore the cap. The over-cap length is rejected BEFORE buffering;\n // a chunked / length-less body is aborted mid-stream once it crosses the cap.\n return { received: bytes.byteLength } // a returned object is serialized as JSON 200\n})\n\napp.post(\"/rpc\", async (c) => {\n const body = await c.boundedJson<{ method: string }>() // default: the server's maxBodyBytes\n // …bad JSON → 400. Then validate `body` with your schema before trusting it.\n return { method: body.method }\n})"
666
+ "code": "import { server } from \"@nifrajs/core/server\"\n\nconst app = server()\n\n// Every route is bounded, including raw-body / file / BYO-validation routes that\n// read c.req directly. Raise the route cap when this endpoint needs more than the default:\napp.post(\"/import\", { bodyLimit: 5 * 1024 * 1024 }, async (c) => {\n const bytes = await c.req.arrayBuffer() // the direct read is capped at 5 MiB\n // An over-cap Content-Length is rejected BEFORE buffering; chunked bodies are\n // aborted mid-stream. Both answer a flat 413 through the request lifecycle.\n return { received: bytes.byteLength } // a returned object is serialized as JSON 200\n})\n\napp.post(\"/rpc\", async (c) => {\n const body = await c.boundedJson<{ method: string }>() // default: the server's maxBodyBytes\n // …bad JSON → 400. Then validate `body` with your schema before trusting it.\n return { method: body.method }\n})"
655
667
  },
656
668
  {
657
669
  "name": "CONTRACT_REPORTS",
@@ -669,7 +681,7 @@
669
681
  "name": "GATING",
670
682
  "topic": "Nifra - security & hardening",
671
683
  "slug": "security",
672
- "code": "import { server } from \"@nifrajs/core/server\"\nimport { jwt, csrf, ipRestriction, bodyLimit } from \"@nifrajs/middleware\"\n\nconst app = server()\n // JWT: the algorithm allowlist is REQUIRED; alg:none and RSA/HMAC confusion are rejected; exp enforced.\n .use(jwt({ key: process.env.JWT_SECRET!, algorithms: [\"HS256\"], issuer: \"my-app\" }))\n // Signed double-submit CSRF (HMAC) + Origin/Referer check on unsafe methods. Secret must be >= 32 bytes.\n .use(csrf({ secret: process.env.CSRF_SECRET! }))\n // Allow/deny by IPv4/IPv6 + CIDR, judged against c.clientIp: the socket peer, or the chain your\n // server({ clientIp }) trust declaration names. FAILS CLOSED with no caller IP; a raw\n // X-Forwarded-For is never believed.\n .use(ipRestriction({ allow: [\"10.0.0.0/8\", \"::1\"] }))\n // Reject oversized bodies at the EDGE by Content-Length, before routing - fails closed (411) on a\n // length-less body. (The schema / c.boundedBody cap is the read-time guard; this is the cheap pre-filter.)\n .use(bodyLimit({ maxBytes: 1_000_000 }))"
684
+ "code": "import { server } from \"@nifrajs/core/server\"\nimport { jwt, csrf, ipRestriction, bodyLimit } from \"@nifrajs/middleware\"\n\nconst app = server()\n // JWT: the algorithm allowlist is REQUIRED; alg:none and RSA/HMAC confusion are rejected; exp enforced.\n .use(jwt({ key: process.env.JWT_SECRET!, algorithms: [\"HS256\"], issuer: \"my-app\" }))\n // Signed double-submit CSRF (HMAC) + Origin/Referer check on unsafe methods. Secret must be >= 32 bytes.\n .use(csrf({ secret: process.env.CSRF_SECRET! }))\n // Allow/deny by IPv4/IPv6 + CIDR, judged against c.clientIp: the socket peer, or the chain your\n // server({ clientIp }) trust declaration names. FAILS CLOSED with no caller IP; a raw\n // X-Forwarded-For is never believed.\n .use(ipRestriction({ allow: [\"10.0.0.0/8\", \"::1\"] }))\n // Reject oversized bodies at the EDGE by Content-Length, before routing - fails closed (411) on a\n // length-less body. This is the cheap pre-filter; the route's cap on direct and\n // framework reads is the read-time guard.\n .use(bodyLimit({ maxBytes: 1_000_000 }))"
673
685
  },
674
686
  {
675
687
  "name": "LOGGING",