@nifrajs/cli 5.1.0 → 5.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.
- package/CHANGELOG.md +3211 -0
- package/README.md +3 -0
- package/dist/agent-files.d.ts +19 -11
- package/dist/agent-files.d.ts.map +1 -1
- package/dist/agent-files.js +26 -18
- package/dist/agent-files.js.map +1 -1
- package/dist/assure-hydration.d.ts.map +1 -1
- package/dist/assure-hydration.js +1 -0
- package/dist/assure-hydration.js.map +1 -1
- package/dist/assure.d.ts.map +1 -1
- package/dist/assure.js +14 -1
- package/dist/assure.js.map +1 -1
- package/dist/capabilities-tool.d.ts.map +1 -1
- package/dist/capabilities-tool.js +131 -45
- package/dist/capabilities-tool.js.map +1 -1
- package/dist/check-diagnostics.d.ts +5 -0
- package/dist/check-diagnostics.d.ts.map +1 -1
- package/dist/check-diagnostics.js +3 -0
- package/dist/check-diagnostics.js.map +1 -1
- package/dist/check-scan.d.ts.map +1 -1
- package/dist/check-scan.js +6 -3
- package/dist/check-scan.js.map +1 -1
- package/dist/check.d.ts.map +1 -1
- package/dist/check.js +52 -12
- package/dist/check.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +23 -12
- package/dist/cli.js.map +1 -1
- package/dist/command-catalog.d.ts.map +1 -1
- package/dist/command-catalog.js +9 -5
- package/dist/command-catalog.js.map +1 -1
- package/dist/dev-bun-config.d.ts +6 -3
- package/dist/dev-bun-config.d.ts.map +1 -1
- package/dist/dev-bun-config.js +13 -10
- package/dist/dev-bun-config.js.map +1 -1
- package/dist/dev-feed-tool.d.ts +3 -2
- package/dist/dev-feed-tool.d.ts.map +1 -1
- package/dist/dev-feed-tool.js +26 -5
- package/dist/dev-feed-tool.js.map +1 -1
- package/dist/doctor.d.ts +15 -1
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +79 -61
- package/dist/doctor.js.map +1 -1
- package/dist/i18n-check.d.ts +11 -1
- package/dist/i18n-check.d.ts.map +1 -1
- package/dist/i18n-check.js +170 -17
- package/dist/i18n-check.js.map +1 -1
- package/dist/init-agents.d.ts +46 -6
- package/dist/init-agents.d.ts.map +1 -1
- package/dist/init-agents.js +193 -31
- package/dist/init-agents.js.map +1 -1
- package/dist/internal/project-specifiers.d.ts.map +1 -1
- package/dist/internal/project-specifiers.js +9 -1
- package/dist/internal/project-specifiers.js.map +1 -1
- package/dist/internal/source-facts.d.ts +6 -0
- package/dist/internal/source-facts.d.ts.map +1 -1
- package/dist/internal/source-facts.js +106 -0
- package/dist/internal/source-facts.js.map +1 -1
- package/dist/internal/workspace-packages.d.ts +22 -0
- package/dist/internal/workspace-packages.d.ts.map +1 -0
- package/dist/internal/workspace-packages.js +215 -0
- package/dist/internal/workspace-packages.js.map +1 -0
- package/dist/load.d.ts +7 -2
- package/dist/load.d.ts.map +1 -1
- package/dist/load.js +11 -2
- package/dist/load.js.map +1 -1
- package/dist/lock-links.d.ts +42 -0
- package/dist/lock-links.d.ts.map +1 -0
- package/dist/lock-links.js +144 -0
- package/dist/lock-links.js.map +1 -0
- package/dist/mcp-exec.d.ts.map +1 -1
- package/dist/mcp-exec.js +5 -2
- package/dist/mcp-exec.js.map +1 -1
- package/dist/mcp-http.js +1 -1
- package/dist/mcp-root.d.ts +6 -4
- package/dist/mcp-root.d.ts.map +1 -1
- package/dist/mcp-root.js +12 -8
- package/dist/mcp-root.js.map +1 -1
- package/dist/migrate-layout.d.ts +2 -1
- package/dist/migrate-layout.d.ts.map +1 -1
- package/dist/migrate-layout.js +434 -29
- package/dist/migrate-layout.js.map +1 -1
- package/dist/project-site.d.ts +7 -0
- package/dist/project-site.d.ts.map +1 -0
- package/dist/project-site.js +19 -0
- package/dist/project-site.js.map +1 -0
- package/dist/recipes/4.0.0.d.ts.map +1 -1
- package/dist/recipes/4.0.0.js +2 -0
- package/dist/recipes/4.0.0.js.map +1 -1
- package/dist/recipes/5.1.0.d.ts +9 -0
- package/dist/recipes/5.1.0.d.ts.map +1 -0
- package/dist/recipes/5.1.0.js +22 -0
- package/dist/recipes/5.1.0.js.map +1 -0
- package/dist/recipes/5.2.0.d.ts +10 -0
- package/dist/recipes/5.2.0.d.ts.map +1 -0
- package/dist/recipes/5.2.0.js +32 -0
- package/dist/recipes/5.2.0.js.map +1 -0
- package/dist/recipes/index.d.ts +3 -0
- package/dist/recipes/index.d.ts.map +1 -1
- package/dist/recipes/index.js +7 -0
- package/dist/recipes/index.js.map +1 -1
- package/dist/review.d.ts.map +1 -1
- package/dist/review.js +2 -0
- package/dist/review.js.map +1 -1
- package/dist/rule-explain.d.ts +26 -0
- package/dist/rule-explain.d.ts.map +1 -0
- package/dist/rule-explain.js +49 -0
- package/dist/rule-explain.js.map +1 -0
- package/dist/rules/codes.d.ts +2 -0
- package/dist/rules/codes.d.ts.map +1 -1
- package/dist/rules/codes.js +2 -0
- package/dist/rules/codes.js.map +1 -1
- package/dist/rules/contract-visibility.d.ts.map +1 -1
- package/dist/rules/contract-visibility.js +93 -21
- package/dist/rules/contract-visibility.js.map +1 -1
- package/dist/rules/explanations.d.ts +14 -0
- package/dist/rules/explanations.d.ts.map +1 -0
- package/dist/rules/explanations.js +316 -0
- package/dist/rules/explanations.js.map +1 -0
- package/dist/rules/legacy.d.ts.map +1 -1
- package/dist/rules/legacy.js +24 -1
- package/dist/rules/legacy.js.map +1 -1
- package/dist/rules/merge-auth.d.ts +12 -0
- package/dist/rules/merge-auth.d.ts.map +1 -0
- package/dist/rules/merge-auth.js +52 -0
- package/dist/rules/merge-auth.js.map +1 -0
- package/dist/rules/pages.d.ts +27 -0
- package/dist/rules/pages.d.ts.map +1 -1
- package/dist/rules/pages.js +177 -2
- package/dist/rules/pages.js.map +1 -1
- package/dist/rules/routes.d.ts +3 -2
- package/dist/rules/routes.d.ts.map +1 -1
- package/dist/rules/routes.js +4 -3
- package/dist/rules/routes.js.map +1 -1
- package/dist/rules/zones.d.ts.map +1 -1
- package/dist/rules/zones.js +3 -2
- package/dist/rules/zones.js.map +1 -1
- package/dist/typecheck-coverage.d.ts +11 -0
- package/dist/typecheck-coverage.d.ts.map +1 -1
- package/dist/typecheck-coverage.js +50 -7
- package/dist/typecheck-coverage.js.map +1 -1
- package/dist/upgrade.d.ts +37 -1
- package/dist/upgrade.d.ts.map +1 -1
- package/dist/upgrade.js +171 -20
- package/dist/upgrade.js.map +1 -1
- package/dist/verification-plan.d.ts.map +1 -1
- package/dist/verification-plan.js +2 -0
- package/dist/verification-plan.js.map +1 -1
- package/dist/version-drift.d.ts.map +1 -1
- package/dist/version-drift.js +12 -1
- package/dist/version-drift.js.map +1 -1
- package/dist/web-app-options.d.ts +1 -1
- package/dist/web-app-options.d.ts.map +1 -1
- package/dist/web-app-options.js.map +1 -1
- package/docs/examples.json +19 -1
- package/docs/llms-full.txt +625 -130
- package/docs/types.json +396 -50
- package/package.json +13 -12
- package/src/agent-files.ts +27 -17
- package/src/assure-hydration.ts +1 -0
- package/src/assure.ts +11 -1
- package/src/capabilities-tool.ts +159 -50
- package/src/check-diagnostics.ts +8 -0
- package/src/check-scan.ts +9 -3
- package/src/check.ts +67 -12
- package/src/cli.ts +24 -11
- package/src/command-catalog.ts +16 -8
- package/src/dev-bun-config.ts +13 -9
- package/src/dev-feed-tool.ts +40 -6
- package/src/doctor.ts +102 -66
- package/src/i18n-check.ts +254 -18
- package/src/init-agents.ts +221 -41
- package/src/internal/project-specifiers.ts +9 -1
- package/src/internal/source-facts.ts +124 -0
- package/src/internal/workspace-packages.ts +218 -0
- package/src/load.ts +19 -3
- package/src/lock-links.ts +173 -0
- package/src/mcp-exec.ts +5 -2
- package/src/mcp-http.ts +1 -1
- package/src/mcp-root.ts +14 -8
- package/src/migrate-layout.ts +495 -31
- package/src/project-site.ts +18 -0
- package/src/recipes/4.0.0.ts +2 -0
- package/src/recipes/5.1.0.ts +23 -0
- package/src/recipes/5.2.0.ts +33 -0
- package/src/recipes/index.ts +7 -0
- package/src/review.ts +2 -0
- package/src/rule-explain.ts +75 -0
- package/src/rules/codes.ts +2 -0
- package/src/rules/contract-visibility.ts +118 -20
- package/src/rules/explanations.ts +329 -0
- package/src/rules/legacy.ts +24 -1
- package/src/rules/merge-auth.ts +55 -0
- package/src/rules/pages.ts +221 -2
- package/src/rules/routes.ts +4 -3
- package/src/rules/zones.ts +3 -2
- package/src/typecheck-coverage.ts +51 -6
- package/src/upgrade.ts +227 -22
- package/src/verification-plan.ts +6 -0
- package/src/version-drift.ts +15 -0
- package/src/web-app-options.ts +9 -1
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
/** What `nifra explain NF-xxxx` says about each built-in rule code. */
|
|
2
|
+
import type { BuiltInCode } from "./codes.ts"
|
|
3
|
+
|
|
4
|
+
export interface RuleExplanation {
|
|
5
|
+
/** What the rule reports and why it matters. */
|
|
6
|
+
readonly why: string
|
|
7
|
+
/** What to do about a finding. */
|
|
8
|
+
readonly fix: string
|
|
9
|
+
/** A command that makes or starts the fix, when one does. */
|
|
10
|
+
readonly command?: string
|
|
11
|
+
/** The site page that covers it, as a path. */
|
|
12
|
+
readonly docs: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const RULE_EXPLANATIONS: Readonly<Record<BuiltInCode, RuleExplanation>> = Object.freeze({
|
|
16
|
+
"NF-C001": {
|
|
17
|
+
why: "The project does not typecheck, or the typecheck could not run (no tsconfig.json, no TypeScript install, or source files outside the program). Every typed contract nifra keeps between frontend and backend rests on this check.",
|
|
18
|
+
fix: "Fix the reported TypeScript errors; install TypeScript with `bun add -d typescript` and add a tsconfig.json that includes every source folder when the check did not run.",
|
|
19
|
+
docs: "/docs/types-first",
|
|
20
|
+
},
|
|
21
|
+
"NF-C002": {
|
|
22
|
+
why: "A hand-written fetch(), EventSource or WebSocket calls the project's own API, so the compiler cannot see when the route it calls changes.",
|
|
23
|
+
fix: "Call the route through client<typeof app> (`.subscribe()` for an SSE route, `.ws()` for a socket route), or mark a call no typed client covers with `// nifra-expect NF-C002: <reason>`.",
|
|
24
|
+
docs: "/docs/types-first",
|
|
25
|
+
},
|
|
26
|
+
"NF-C003": {
|
|
27
|
+
why: 'client("...") without a type argument types every response as unknown, so frontend and backend can drift without a compile error.',
|
|
28
|
+
fix: 'Write client<typeof app>("...") or client(contract, url).',
|
|
29
|
+
docs: "/docs/types-first",
|
|
30
|
+
},
|
|
31
|
+
"NF-C004": {
|
|
32
|
+
why: "Browser code (a route's frontend half, frontend/ or shared/) imports server-only code, which would ship to the browser or fail the build.",
|
|
33
|
+
fix: "Reach the server code from the route's backend half (x.backend.ts) or through a *.fn.ts server function.",
|
|
34
|
+
docs: "/docs/structure",
|
|
35
|
+
},
|
|
36
|
+
"NF-C005": {
|
|
37
|
+
why: "An import names an export that moved to another module in a nifra release, so it no longer resolves.",
|
|
38
|
+
fix: "Import it from the module the finding names.",
|
|
39
|
+
command: "nifra fix --code NF-C005",
|
|
40
|
+
docs: "/docs/cli",
|
|
41
|
+
},
|
|
42
|
+
"NF-C006": {
|
|
43
|
+
why: "SQL built by interpolating a value into the statement text turns that value into SQL, so a caller who controls it can inject statements.",
|
|
44
|
+
fix: "Pass the value as a bound parameter, or use the driver's tagged template, which binds each substitution; mark reviewed SQL with `// nifra-expect NF-C006: <reason>`.",
|
|
45
|
+
docs: "/docs/database",
|
|
46
|
+
},
|
|
47
|
+
"NF-C007": {
|
|
48
|
+
why: "A route handler returns a raw Response, so the typed client infers `data: never` and drift detection is lost for that route.",
|
|
49
|
+
fix: "Return a plain object (set status, headers and cookies on c.set), use app.sse() for a stream, or declare `{ response: t.... }`; mark an intended file or redirect with `// nifra-expect NF-C007: <reason>`.",
|
|
50
|
+
docs: "/docs/api",
|
|
51
|
+
},
|
|
52
|
+
"NF-C008": {
|
|
53
|
+
why: "Source imports a package package.json does not declare. It resolves today only through a hoisted or global install, and a clean install will not have it.",
|
|
54
|
+
fix: "Declare it with `bun add <package>`.",
|
|
55
|
+
docs: "/docs/troubleshooting",
|
|
56
|
+
},
|
|
57
|
+
"NF-C009": {
|
|
58
|
+
why: "A package resolves to more than one physical copy, so module-level state (contexts, registries, instanceof checks) splits between them.",
|
|
59
|
+
fix: "Deduplicate the installs so each resolves to one path, or declare the package single-copy in package.json's nifra.singleCopy and preload the register module.",
|
|
60
|
+
docs: "/docs/troubleshooting",
|
|
61
|
+
},
|
|
62
|
+
"NF-C010": {
|
|
63
|
+
why: "A workspace package's build output is missing or older than its source; Bun reads the source while Vite SSR and Node read the stale build.",
|
|
64
|
+
fix: "Rebuild the package with its own build script.",
|
|
65
|
+
command: "nifra fix --code NF-C010",
|
|
66
|
+
docs: "/docs/troubleshooting",
|
|
67
|
+
},
|
|
68
|
+
"NF-C011": {
|
|
69
|
+
why: "A plugin or condition is configured for a bundler phase that never sees it: Vite, Bun's client and server builds, and the server bundle each read their own settings.",
|
|
70
|
+
fix: "Move the setting to the phase the finding names.",
|
|
71
|
+
docs: "/docs/dev",
|
|
72
|
+
},
|
|
73
|
+
"NF-C012": {
|
|
74
|
+
why: "server-manifest.ts no longer matches routes/. A worker without a filesystem serves the baked route table, so the drift breaks routes at the edge without an error.",
|
|
75
|
+
fix: "Regenerate it and commit it.",
|
|
76
|
+
command: "nifra sync-manifest",
|
|
77
|
+
docs: "/docs/deployment",
|
|
78
|
+
},
|
|
79
|
+
"NF-C013": {
|
|
80
|
+
why: "nifra.manifest.json, the trust artifact reviewers sign off on, is missing, invalid or out of date with the app.",
|
|
81
|
+
fix: "Regenerate it, review the change, and commit it.",
|
|
82
|
+
command: "nifra manifest emit",
|
|
83
|
+
docs: "/docs/verification",
|
|
84
|
+
},
|
|
85
|
+
"NF-C014": {
|
|
86
|
+
why: "A route's declared effects or capabilities do not match what its code reaches through approved adapters.",
|
|
87
|
+
fix: "Align the route's declaration with the adapters it uses; never route an effect around its owned seam.",
|
|
88
|
+
docs: "/docs/capabilities",
|
|
89
|
+
},
|
|
90
|
+
"NF-C015": {
|
|
91
|
+
why: "The capability assurance configuration could not be loaded or evaluated, so no route was checked against it.",
|
|
92
|
+
fix: "Fix the error the finding quotes in nifra.assurance.ts.",
|
|
93
|
+
docs: "/docs/verification",
|
|
94
|
+
},
|
|
95
|
+
"NF-C016": {
|
|
96
|
+
why: "nifra.check.json could not be parsed, so the settings in it, such as its external-mount allowlist, were ignored.",
|
|
97
|
+
fix: "Fix the JSON error the finding quotes.",
|
|
98
|
+
docs: "/docs/cli",
|
|
99
|
+
},
|
|
100
|
+
"NF-C017": {
|
|
101
|
+
why: "A rule pack failed to load or threw while scanning; the rule registry fails closed rather than report a partial result as clean.",
|
|
102
|
+
fix: "Fix or remove the rule pack the error names, then re-run the check.",
|
|
103
|
+
docs: "/docs/cli",
|
|
104
|
+
},
|
|
105
|
+
"NF-C018": {
|
|
106
|
+
why: "A route path segment collides with a key the typed client proxy reserves, so dot access on the client cannot reach that route.",
|
|
107
|
+
fix: "Rename the segment, or call the parent node with the segment as the finding shows.",
|
|
108
|
+
command: "nifra fix --code NF-C018",
|
|
109
|
+
docs: "/docs/routing",
|
|
110
|
+
},
|
|
111
|
+
"NF-C019": {
|
|
112
|
+
why: "The same method and path are registered twice in one file, and which registration serves is undefined.",
|
|
113
|
+
fix: "Remove or rename one of them.",
|
|
114
|
+
docs: "/docs/routing",
|
|
115
|
+
},
|
|
116
|
+
"NF-C020": {
|
|
117
|
+
why: "An island enhancer adds an event listener but returns no cleanup, so the listener outlives the island on a client navigation.",
|
|
118
|
+
fix: "Return a function that removes the listener.",
|
|
119
|
+
docs: "/docs/islands",
|
|
120
|
+
},
|
|
121
|
+
"NF-C021": {
|
|
122
|
+
why: "A nano binding's returned disposer is discarded, so the binding outlives its component and leaks on soft navigation.",
|
|
123
|
+
fix: "Collect the disposer and call it on teardown.",
|
|
124
|
+
docs: "/docs/nano",
|
|
125
|
+
},
|
|
126
|
+
"NF-C022": {
|
|
127
|
+
why: "bindList is keyed by the array index, so adding, removing or reordering items reuses the wrong node and its state.",
|
|
128
|
+
fix: "Key each item by a stable id.",
|
|
129
|
+
docs: "/docs/nano",
|
|
130
|
+
},
|
|
131
|
+
"NF-C023": {
|
|
132
|
+
why: "A computed or effect reads a signal its deps array does not list, so it does not update when that signal changes.",
|
|
133
|
+
fix: "Add the missing signals to the deps array.",
|
|
134
|
+
docs: "/docs/nano",
|
|
135
|
+
},
|
|
136
|
+
"NF-C024": {
|
|
137
|
+
why: "Two route patterns match a common path (the finding shows one), so one shadows the other for some requests.",
|
|
138
|
+
fix: "Make the patterns disjoint, or mark a deliberate overlap with `// nifra-expect NF-C024: <reason>`.",
|
|
139
|
+
docs: "/docs/api",
|
|
140
|
+
},
|
|
141
|
+
"NF-C025": {
|
|
142
|
+
why: "The route-overlap analysis ran out of its safety budget before it could prove two patterns disjoint.",
|
|
143
|
+
fix: "Simplify the patterns, or after reviewing them by hand mark the pair with `// nifra-expect NF-C025: <reason>`.",
|
|
144
|
+
docs: "/docs/api",
|
|
145
|
+
},
|
|
146
|
+
"NF-C026": {
|
|
147
|
+
why: "A character after a route param reads as literal text, not as a modifier; a `?` in the middle of a path makes the route unreachable.",
|
|
148
|
+
fix: "Use optional params only as trailing whole segments (`/users/:id?`), and a constraint as one character class (`:id{[0-9]+}`).",
|
|
149
|
+
docs: "/docs/api",
|
|
150
|
+
},
|
|
151
|
+
"NF-C027": {
|
|
152
|
+
why: "A page route sits under the path the backend is mounted at. The backend answers every request there first, and its 404 is final, so the page never renders.",
|
|
153
|
+
fix: "Move the page, serve the URL from backend/app.ts, or mount the backend elsewhere with apiPrefix in backend/framework.ts.",
|
|
154
|
+
docs: "/docs/backends",
|
|
155
|
+
},
|
|
156
|
+
"NF-C028": {
|
|
157
|
+
why: "A file imports across a zone boundary the project declares, such as browser code reaching backend code, or the zone configuration itself is invalid.",
|
|
158
|
+
fix: "Import through the boundary's public entry, or move the code to the zone that may use it.",
|
|
159
|
+
docs: "/docs/structure",
|
|
160
|
+
},
|
|
161
|
+
"NF-C029": {
|
|
162
|
+
why: "Browser code reads a private environment variable. Browser code may read only NODE_ENV and the variables named with the app's public prefix; anything else is a server secret.",
|
|
163
|
+
fix: "Read it in a loader, an action or under backend/, or rename it with the public prefix when it is meant for the browser.",
|
|
164
|
+
docs: "/docs/structure",
|
|
165
|
+
},
|
|
166
|
+
"NF-C030": {
|
|
167
|
+
why: "A loader or action returns data to the browser without an output schema, so nothing limits which fields leave the server.",
|
|
168
|
+
fix: "Export the schema beside it; the fix drafts one from the function's return type.",
|
|
169
|
+
command: "nifra fix --code NF-C030",
|
|
170
|
+
docs: "/docs/data",
|
|
171
|
+
},
|
|
172
|
+
"NF-C031": {
|
|
173
|
+
why: "An output schema declares a field whose name usually holds a credential or a personal identifier, so it would be sent to the browser.",
|
|
174
|
+
fix: 'Remove the field, or wrap its schema in t.declassified("why it may reach the browser", ...).',
|
|
175
|
+
docs: "/docs/data",
|
|
176
|
+
},
|
|
177
|
+
"NF-C032": {
|
|
178
|
+
why: "Code that reaches the browser carries what looks like a credential.",
|
|
179
|
+
fix: "Read it from the environment on the server, and rotate it if it was ever committed.",
|
|
180
|
+
docs: "/docs/security",
|
|
181
|
+
},
|
|
182
|
+
"NF-C033": {
|
|
183
|
+
why: "A generated output schema no longer matches what its loader or action returns, or it could not be compared, so the output guard may drop or admit the wrong fields.",
|
|
184
|
+
fix: "Regenerate the schemas and review the change.",
|
|
185
|
+
command: "nifra schemas --write",
|
|
186
|
+
docs: "/docs/data",
|
|
187
|
+
},
|
|
188
|
+
"NF-C034": {
|
|
189
|
+
why: "A root status page imports the root layout to wrap itself, but status pages render inside their layouts, so the layout renders twice.",
|
|
190
|
+
fix: "Remove the wrap, or export `inLayouts = false` from the page.",
|
|
191
|
+
docs: "/docs/routing",
|
|
192
|
+
},
|
|
193
|
+
"NF-C035": {
|
|
194
|
+
why: "backend/framework.ts sets no apiPrefix, so the backend is reachable from loaders only and a browser call to /api reaches page routing.",
|
|
195
|
+
fix: 'Export `apiPrefix = "/api"` to serve it over HTTP, or `apiPrefix = ""` to keep it loader-only.',
|
|
196
|
+
command: "nifra fix --code NF-C035",
|
|
197
|
+
docs: "/docs/backends",
|
|
198
|
+
},
|
|
199
|
+
"NF-C036": {
|
|
200
|
+
why: "A route's path is computed in a way the static scan cannot read, so the route lints do not see that route, and capability provenance finds its module only from the app `nifra.assurance.ts` loads.",
|
|
201
|
+
fix: "Write the path as a string literal or a module-level const, or mark a deliberately computed path with `// nifra-expect NF-C036: <reason>`.",
|
|
202
|
+
docs: "/docs/capabilities",
|
|
203
|
+
},
|
|
204
|
+
"NF-C037": {
|
|
205
|
+
why: 'package.json declares `"nifra": { "kind": "api" }` over a directory with web config, which would switch off the zone checks a web app needs.',
|
|
206
|
+
fix: 'Remove "kind", or give the web app its own package.json.',
|
|
207
|
+
docs: "/docs/structure",
|
|
208
|
+
},
|
|
209
|
+
"NF-C038": {
|
|
210
|
+
why: "The root layout is still at its retired location. Until it moves, the contract gate does not run for the app and the commands that load it refuse it.",
|
|
211
|
+
fix: "Move it to the location the finding names.",
|
|
212
|
+
command: "nifra migrate layout --write",
|
|
213
|
+
docs: "/docs/migrate-5",
|
|
214
|
+
},
|
|
215
|
+
"NF-C039": {
|
|
216
|
+
why: "An app implements contract operations that backend/app.ts does not serve, so the contract lock, the typed client checks and nifra routes cannot see them; or the contract cannot be read at all.",
|
|
217
|
+
fix: "Mount the implementing app in backend/app.ts, built with stub dependencies if it needs any, and keep each operation's method and path as string literals.",
|
|
218
|
+
docs: "/docs/types-first#stub-entry",
|
|
219
|
+
},
|
|
220
|
+
"NF-C040": {
|
|
221
|
+
why: "A layout's meta reads `data`, which is the layout's own loader data, and the layout has no loader, so it is always null.",
|
|
222
|
+
fix: "Read the page's data from `pageData`.",
|
|
223
|
+
docs: "/docs/routing",
|
|
224
|
+
},
|
|
225
|
+
"NF-C041": {
|
|
226
|
+
why: "A route's frontend file exports something that runs only on the server, and that file ships to the browser whole, so the build and the server refuse it.",
|
|
227
|
+
fix: "Move the export to the route's backend half.",
|
|
228
|
+
command: "nifra fix --code NF-C041",
|
|
229
|
+
docs: "/docs/structure",
|
|
230
|
+
},
|
|
231
|
+
"NF-C042": {
|
|
232
|
+
why: "A layout loader refuses access, but the layout is not a gate. A client navigation that keeps the layout skips the loader, and an action below it runs without it.",
|
|
233
|
+
fix: "Export `gate = true` from the layout, or move the check into its middleware.",
|
|
234
|
+
docs: "/docs/data",
|
|
235
|
+
},
|
|
236
|
+
"NF-C043": {
|
|
237
|
+
why: "A merged route keeps the hooks of the server that declared it, so the authenticate() or auth plugin applied on this server before merge() never runs for it, and the merged server authenticates none of its routes.",
|
|
238
|
+
fix: "Apply the auth plugin on the merged server, or declare its routes in a group() of this server. A module that is public on purpose takes `// nifra-expect NF-C043: <reason>` on the merge line.",
|
|
239
|
+
docs: "/docs/plugins",
|
|
240
|
+
},
|
|
241
|
+
"NF-D001": {
|
|
242
|
+
why: "The doctor gate of `nifra assure` found an undeclared import or a package installed more than once.",
|
|
243
|
+
fix: "Run `nifra doctor` for the details and the fix of each finding.",
|
|
244
|
+
command: "nifra doctor",
|
|
245
|
+
docs: "/docs/troubleshooting",
|
|
246
|
+
},
|
|
247
|
+
"NF-D002": {
|
|
248
|
+
why: "The workspace pins, installs or runs more than one nifra version. The packages ship together, so a mix runs code and checks written for different releases.",
|
|
249
|
+
fix: "Upgrade everything to the highest version the finding names; the upgrade runs each release's migration steps.",
|
|
250
|
+
docs: "/docs/troubleshooting#mixed-versions",
|
|
251
|
+
},
|
|
252
|
+
"NF-D003": {
|
|
253
|
+
why: "bun.lock records dependencies a file: package no longer declares. Bun never reads that package.json again, so it installs the recorded versions beside the declared ones.",
|
|
254
|
+
fix: "Run `bun update <package>` for each package the finding names; `nifra upgrade --write` drops the entries before the next install.",
|
|
255
|
+
docs: "/docs/troubleshooting#stale-file-links",
|
|
256
|
+
},
|
|
257
|
+
"NF-A001": {
|
|
258
|
+
why: "A route fails the assurance policy in the bundle `nifra assure` builds, or declares a response contract the runtime does not enforce.",
|
|
259
|
+
fix: "Fix the route the finding names, or enforce its response contract.",
|
|
260
|
+
docs: "/docs/verification",
|
|
261
|
+
},
|
|
262
|
+
"NF-H001": {
|
|
263
|
+
why: "Hydration replay found a mismatch between the server-rendered HTML and the first client render.",
|
|
264
|
+
fix: "Render the same markup on both sides: move values that differ (time, randomness, browser-only state) into an effect.",
|
|
265
|
+
docs: "/docs/hydration",
|
|
266
|
+
},
|
|
267
|
+
"NF-H002": {
|
|
268
|
+
why: "Hydration loaded more than one copy of a framework runtime, so components and hooks from different copies do not work together.",
|
|
269
|
+
fix: "Deduplicate the framework install so one copy serves both server and client.",
|
|
270
|
+
docs: "/docs/hydration",
|
|
271
|
+
},
|
|
272
|
+
"NF-H003": {
|
|
273
|
+
why: "The client build is older than the route source, so hydration would replay an outdated bundle.",
|
|
274
|
+
fix: "Rebuild the client before checking hydration.",
|
|
275
|
+
docs: "/docs/hydration",
|
|
276
|
+
},
|
|
277
|
+
"NF-H004": {
|
|
278
|
+
why: "The hydration probe never became interactive, so the page's client code did not finish hydrating.",
|
|
279
|
+
fix: "Open the page and fix the client error that stops hydration.",
|
|
280
|
+
docs: "/docs/hydration",
|
|
281
|
+
},
|
|
282
|
+
"NF-K001": {
|
|
283
|
+
why: "The contract snapshot no longer matches the routes the backend serves, so a contract change has not been reviewed and locked.",
|
|
284
|
+
fix: "Review the change and snapshot the contracts again.",
|
|
285
|
+
command: "nifra contracts snapshot",
|
|
286
|
+
docs: "/docs/contract",
|
|
287
|
+
},
|
|
288
|
+
"NF-S001": {
|
|
289
|
+
why: "A gate's catch block swallows the error, so a failure inside an authorization check lets the request through.",
|
|
290
|
+
fix: "Rethrow, or return an explicit denial from the catch block.",
|
|
291
|
+
docs: "/docs/security",
|
|
292
|
+
},
|
|
293
|
+
"NF-S002": {
|
|
294
|
+
why: "A secret-like value is compared with `===` or similar, which leaks how much of it matched through timing.",
|
|
295
|
+
fix: "Check the lengths, then compare with a timing-safe comparison.",
|
|
296
|
+
command: "nifra fix --code NF-S002",
|
|
297
|
+
docs: "/docs/security",
|
|
298
|
+
},
|
|
299
|
+
"NF-S003": {
|
|
300
|
+
why: "A value shaped like personal data or a credential is passed straight to a log call, so it lands in the logs.",
|
|
301
|
+
fix: "Log a redacted form or an identifier instead.",
|
|
302
|
+
docs: "/docs/security",
|
|
303
|
+
},
|
|
304
|
+
"NF-S004": {
|
|
305
|
+
why: "A CORS origin predicate never looks at the origin it is given, so it allows every origin.",
|
|
306
|
+
fix: "List the allowed origins, or test the origin argument.",
|
|
307
|
+
docs: "/docs/security",
|
|
308
|
+
},
|
|
309
|
+
"NF-S005": {
|
|
310
|
+
why: "A redirect opts out of the same-origin default, so a target derived from request input becomes an open redirect.",
|
|
311
|
+
fix: "Make sure the target can never come from request input, then mark it with `// nifra-expect NF-S005: <reason>`.",
|
|
312
|
+
docs: "/docs/security",
|
|
313
|
+
},
|
|
314
|
+
"NF-S006": {
|
|
315
|
+
why: "A security option is switched to its unsafe setting; the finding names the option and what it gives up.",
|
|
316
|
+
fix: "Turn the option back on, or mark the reviewed choice with `// nifra-expect NF-S006: <reason>`.",
|
|
317
|
+
docs: "/docs/security",
|
|
318
|
+
},
|
|
319
|
+
"NF-S007": {
|
|
320
|
+
why: "A Secure cookie has no __Host- or __Secure- prefix, so a subdomain or an insecure page can set a cookie with the same name that shadows it.",
|
|
321
|
+
fix: "Give the cookie a __Host- prefix (or __Secure- when it must reach subdomains).",
|
|
322
|
+
docs: "/docs/security",
|
|
323
|
+
},
|
|
324
|
+
"NF-S008": {
|
|
325
|
+
why: "An authenticated route validates its input before it authenticates, so an unauthenticated caller reaches the body parser and reads the validation issues.",
|
|
326
|
+
fix: 'Authenticate with app.authenticate(), which runs before validation, or set `validationOrder: "auth-before-validation"` on the route.',
|
|
327
|
+
docs: "/docs/auth",
|
|
328
|
+
},
|
|
329
|
+
})
|
package/src/rules/legacy.ts
CHANGED
|
@@ -24,6 +24,7 @@ import type { DuplicateInstallFinding } from "../doctor.ts"
|
|
|
24
24
|
import { codeUnitOrder } from "../internal/code-unit-order.ts"
|
|
25
25
|
import { createWebAppProbe, withApiKindHint } from "../internal/nifra-project.ts"
|
|
26
26
|
import { unsupportedTypeScriptDiagnostic } from "../internal/typescript-import.ts"
|
|
27
|
+
import { linkLockUpdate, staleLinkLockMessage } from "../lock-links.ts"
|
|
27
28
|
import { zoneFolderOf } from "../typecheck-coverage.ts"
|
|
28
29
|
import { versionDriftMessage } from "../version-drift.ts"
|
|
29
30
|
import { MISSING_EXPECTATION_REASON } from "./comment-markers.ts"
|
|
@@ -430,7 +431,7 @@ function outsideProgramFindings(files: readonly string[]): Diagnostic[] {
|
|
|
430
431
|
kind: "manual",
|
|
431
432
|
title: "Bring the folder into the TypeScript program",
|
|
432
433
|
steps: [
|
|
433
|
-
`Add "${folder}" to the "include" array in tsconfig.json.`,
|
|
434
|
+
`Add "${folder}" to the "include" array in tsconfig.json, or in another tsconfig the typecheck runs: one tsconfig.json references, or one listed under "tsconfigs" in nifra.check.json.`,
|
|
434
435
|
'Files kept out on purpose: name them in the tsconfig "exclude", or under "typecheck": { "ignore": [...] } in nifra.check.json.',
|
|
435
436
|
"Run `nifra check` again; the newly checked files may report type errors.",
|
|
436
437
|
],
|
|
@@ -809,6 +810,27 @@ const versionDriftRule: CheckRule = {
|
|
|
809
810
|
},
|
|
810
811
|
}
|
|
811
812
|
|
|
813
|
+
/** Read from the doctor result check already collected, like {@link versionDriftRule}. */
|
|
814
|
+
const staleLinkLockRule: CheckRule = {
|
|
815
|
+
code: "NF-D003",
|
|
816
|
+
title: "Stale file: dependencies in bun.lock",
|
|
817
|
+
async scan(ctx) {
|
|
818
|
+
const stale = ctx.project.packages.doctor.staleLinkLocks
|
|
819
|
+
if (stale === undefined) return []
|
|
820
|
+
return [
|
|
821
|
+
diagnostic({
|
|
822
|
+
code: "NF-D003",
|
|
823
|
+
severity: "warn",
|
|
824
|
+
file: stale.lock,
|
|
825
|
+
message: staleLinkLockMessage(stale),
|
|
826
|
+
evidence: stale.entries.map((entry) => `${entry.package} (file:${entry.path})`),
|
|
827
|
+
fix: { recipe: "lock.refresh-file-links", command: linkLockUpdate(stale.entries) },
|
|
828
|
+
verify: "nifra doctor",
|
|
829
|
+
}),
|
|
830
|
+
]
|
|
831
|
+
},
|
|
832
|
+
}
|
|
833
|
+
|
|
812
834
|
const pipelineRule: CheckRule = {
|
|
813
835
|
code: LEGACY_RULE_CODES.pipeline!,
|
|
814
836
|
title: TITLES.pipeline!,
|
|
@@ -1149,6 +1171,7 @@ export const legacyRules: readonly CheckRule[] = Object.freeze([
|
|
|
1149
1171
|
responseRouteRule,
|
|
1150
1172
|
...doctorRules,
|
|
1151
1173
|
versionDriftRule,
|
|
1174
|
+
staleLinkLockRule,
|
|
1152
1175
|
pipelineRule,
|
|
1153
1176
|
serverManifestRule,
|
|
1154
1177
|
manifestRule,
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type Diagnostic, diagnostic } from "../diagnostics.ts"
|
|
2
|
+
import { projectSite } from "../project-site.ts"
|
|
3
|
+
import { commentBlockExpectation } from "./comment-markers.ts"
|
|
4
|
+
import type { CheckRule, RuleContext } from "./index.ts"
|
|
5
|
+
|
|
6
|
+
const MERGE_AUTH_EXPECTATION = ["NF-C043", "merge-auth"]
|
|
7
|
+
const SHOWN_ROUTES = 5
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* NF-C043: a `merge()` under a parent whose order-scoped auth - an `authenticate()` stage, or
|
|
11
|
+
* `authenticated` evidence scoped to subsequent routes - covers the parent's own routes, while the
|
|
12
|
+
* merged server authenticates none of its routes. A merged route keeps the chain of the server that
|
|
13
|
+
* declared it, so the parent's auth never runs for it. Read from the app `nifra.assurance.ts` loads
|
|
14
|
+
* (core records each such merge in a development load). A server that authenticates any route of its
|
|
15
|
+
* own is taken to have chosen its own auth and is not reported. `// nifra-expect NF-C043: <reason>` on
|
|
16
|
+
* the merge line accepts a module that is public on purpose.
|
|
17
|
+
*/
|
|
18
|
+
export const mergeAuthGapRule: CheckRule = {
|
|
19
|
+
code: "NF-C043",
|
|
20
|
+
title: "Merged routes skip the parent's authentication",
|
|
21
|
+
async scan(ctx: RuleContext) {
|
|
22
|
+
const assurance = ctx.project.policies.assurance
|
|
23
|
+
if (assurance === undefined || assurance.error !== undefined) return []
|
|
24
|
+
const source = assurance.config?.source
|
|
25
|
+
if (source === undefined) return []
|
|
26
|
+
const { reflectMergeAuthGaps } = await import("@nifrajs/core/reflection")
|
|
27
|
+
const findings: Diagnostic[] = []
|
|
28
|
+
for (const gap of reflectMergeAuthGaps(source)) {
|
|
29
|
+
const at = projectSite(ctx.root, gap.site)
|
|
30
|
+
if (at !== undefined) {
|
|
31
|
+
const lines = (ctx.project.source.read(at.file) ?? "").split("\n")
|
|
32
|
+
if (commentBlockExpectation(lines, at.line, MERGE_AUTH_EXPECTATION)?.reason !== undefined)
|
|
33
|
+
continue
|
|
34
|
+
}
|
|
35
|
+
const shown = gap.routes.slice(0, SHOWN_ROUTES).join(", ")
|
|
36
|
+
const more =
|
|
37
|
+
gap.routes.length > SHOWN_ROUTES ? ` and ${gap.routes.length - SHOWN_ROUTES} more` : ""
|
|
38
|
+
findings.push(
|
|
39
|
+
diagnostic({
|
|
40
|
+
code: "NF-C043",
|
|
41
|
+
severity: "warn",
|
|
42
|
+
...at,
|
|
43
|
+
message: `merge() adds routes that run none of this server's authentication (${gap.auth.join(", ")}): ${shown}${more}. A merged route keeps the hooks of the server that declared it, and that server authenticates none of its routes.`,
|
|
44
|
+
evidence: [
|
|
45
|
+
"merged routes keep the derive/authenticate/beforeHandle chain of the server that declared them",
|
|
46
|
+
"apply the auth plugin on the merged server, or declare its routes in a group() of this one",
|
|
47
|
+
"a module that is public on purpose: `// nifra-expect NF-C043: <reason>` on the merge line",
|
|
48
|
+
],
|
|
49
|
+
verify: "nifra check",
|
|
50
|
+
}),
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
return findings
|
|
54
|
+
},
|
|
55
|
+
}
|