@starci/eslint-canon-be 1.7.1 → 1.8.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 +5 -0
- package/README.md +1 -1
- package/authorization.mjs +106 -106
- package/e2e-flow.mjs +222 -222
- package/observability.mjs +275 -275
- package/package.json +1 -1
- package/schema-authority.mjs +39 -15
- package/transport.mjs +168 -168
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.8.0 - 2026-09-30
|
|
4
|
+
|
|
5
|
+
- Breaking (hotfix ahead of 2.0.0, owner rule "no repositories"): `sql-only-in-repository` is removed. `sql-text-only` (R36) takes its place: raw SQL text is written only in a `<name>.sql.ts` (the capability's `persistence/<name>.sql.ts`, or a test builder's `src/tests/fixtures/builders/<area>.sql.ts`); everywhere else `.query(...)` takes an imported text constant, never a string literal or template; `createQueryBuilder` is refused everywhere. Migrations keep their inline SQL.
|
|
6
|
+
- New: `no-repository-file` (R36): a `*.repository.ts` file is a finding. Move its SQL text into `<name>.sql.ts` and run it from the capability service on the shared EntityManager.
|
|
7
|
+
|
|
3
8
|
## 1.7.1 - 2026-09-30
|
|
4
9
|
|
|
5
10
|
- Fixed: eslint no longer fails to start in a product repository with `HFS slot manifest not found at <repo>/knowledge/hfs/slots.yaml`. `lib/slots.mjs` used to look for the manifest at a path above the package (the product repository, or a linked runtime copy that no longer exists). The package now depends on `@starci/hfs` and resolves the manifest and the YAML reader as `@starci/hfs/runtime/knowledge/hfs/slots.yaml` and `@starci/hfs/runtime/engine/yaml.mjs`, so what the canon reads travels with the installed packages. `STARCI_HFS_SLOTS` still overrides the manifest file.
|
package/README.md
CHANGED
|
@@ -54,7 +54,7 @@ A sample, not the list:
|
|
|
54
54
|
| Area | What the rules hold |
|
|
55
55
|
|---|---|
|
|
56
56
|
| **Errors** | A `catch` rethrows, logs through the logger port or returns an outcome carrying its cause; an error lives in its capability's `errors/`, extends `DomainError`, and no bare `Error` or framework exception escapes (`catch-must-account`, `error-home`) |
|
|
57
|
-
| **Schema authority** | Migrations only: no `synchronize`, no `migrationsRun`, no runtime DDL, no entity glob; raw SQL only in a
|
|
57
|
+
| **Schema authority** | Migrations only: no `synchronize`, no `migrationsRun`, no runtime DDL, no entity glob; raw SQL text only in a `<name>.sql.ts`, no `*.repository.ts` file; no ORM entity in a contract (`no-runtime-schema`, `sql-text-only`, `no-repository-file`, `no-entity-in-contract`) |
|
|
58
58
|
| **Config and secrets** | `process.env` only in `platform/config`; no literal default for a secret, password, token, key or URL; secrets compare with `timingSafeEqual` (`no-direct-env-read`, `no-secret-default`, `secret-compare-timing-safe`) |
|
|
59
59
|
| **Default deny** | Typed bodies and arguments, no `GraphQLJSON` tunnel, no `switch (operation)`, and `@Public` carries a reason (`no-untyped-body`, `public-needs-reason`) |
|
|
60
60
|
| **Module shape** | `@Global()` only on the manifest allowlist; typed `ConfigurableModuleBuilder`; static `register`; one module per file; no `new` of a provider; no module-level `let` |
|
package/authorization.mjs
CHANGED
|
@@ -1,106 +1,106 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The rule that holds `authorization.md`.
|
|
3
|
-
*
|
|
4
|
-
* ONE rule, and the honest reason is worth stating: authorization is decided against a row, and a
|
|
5
|
-
* parser does not know which row a handler is reaching for or what owning it means. AUTHZ-3, -4 and
|
|
6
|
-
* -5 all turn on that, so a rule aimed at them would fire on shape rather than on meaning - and a
|
|
7
|
-
* rule that fires on shape is one authors learn to disable, which leaves the law worse off than when
|
|
8
|
-
* nothing enforced it.
|
|
9
|
-
*
|
|
10
|
-
* AUTHZ-1 was measured and deliberately left alone. A handler checking `if (!user)` reads like
|
|
11
|
-
* duplication of the door's guard and is not: the guard belongs to one door and the handler belongs
|
|
12
|
-
* to every caller of the bus. A rule refusing it would fire on the majority of correct handlers in
|
|
13
|
-
* this tree, which is a gate contradicting canon rather than holding it.
|
|
14
|
-
*
|
|
15
|
-
* What IS checkable in one file is the door: a resolver method that READS the authenticated user
|
|
16
|
-
* while nothing on that method or its class establishes the identity. That failure looks like
|
|
17
|
-
* nothing at all - the parameter still says `user`, the handler still receives one - and the only
|
|
18
|
-
* missing piece is the line that proved it belonged to the caller.
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
/** Parameter decorators that read an already-authenticated identity off the request. */
|
|
22
|
-
const IDENTITY_PARAM_DECORATORS = new Set([
|
|
23
|
-
"KeycloakGraphQLUser",
|
|
24
|
-
"KeycloakUser",
|
|
25
|
-
"CurrentUser",
|
|
26
|
-
])
|
|
27
|
-
|
|
28
|
-
/** The decorator that establishes the identity a door then reads. */
|
|
29
|
-
const GUARD_DECORATOR = "UseGuards"
|
|
30
|
-
|
|
31
|
-
/** Reads the callee name off a decorator expression, whether or not it is called. */
|
|
32
|
-
const decoratorName = (decorator) => {
|
|
33
|
-
const expression = decorator.expression
|
|
34
|
-
if (!expression) return undefined
|
|
35
|
-
if (expression.type === "CallExpression") {
|
|
36
|
-
return expression.callee && expression.callee.type === "Identifier"
|
|
37
|
-
? expression.callee.name
|
|
38
|
-
: undefined
|
|
39
|
-
}
|
|
40
|
-
return expression.type === "Identifier" ? expression.name : undefined
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/** Whether any decorator in the list is the guard. */
|
|
44
|
-
const hasGuard = (decorators) =>
|
|
45
|
-
(decorators || []).some((decorator) => decoratorName(decorator) === GUARD_DECORATOR)
|
|
46
|
-
|
|
47
|
-
/** The identity parameter on a method, when it has one. */
|
|
48
|
-
const identityParameter = (node) => {
|
|
49
|
-
for (const parameter of node.value && node.value.params ? node.value.params : []) {
|
|
50
|
-
// a decorated parameter carries its decorators on the parameter node itself, and TS-ESTree
|
|
51
|
-
// wraps a typed+decorated parameter in TSParameterProperty for constructor promotion
|
|
52
|
-
const carrier = parameter.type === "TSParameterProperty" ? parameter.parameter : parameter
|
|
53
|
-
const decorators = parameter.decorators || (carrier && carrier.decorators) || []
|
|
54
|
-
for (const decorator of decorators) {
|
|
55
|
-
if (IDENTITY_PARAM_DECORATORS.has(decoratorName(decorator))) return parameter
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return undefined
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// -- AUTHZ-2 ---------------------------------------------------------------------------------------
|
|
62
|
-
|
|
63
|
-
/** A door that reads an identity carries the guard that establishes it. */
|
|
64
|
-
export const identityNeedsGuard = {
|
|
65
|
-
meta: {
|
|
66
|
-
type: "problem",
|
|
67
|
-
docs: {
|
|
68
|
-
description:
|
|
69
|
-
"A resolver or controller method reading the authenticated user must carry a guard on that method or its class.",
|
|
70
|
-
},
|
|
71
|
-
schema: [],
|
|
72
|
-
messages: {
|
|
73
|
-
unguarded:
|
|
74
|
-
"This door reads the authenticated user through `@{{decorator}}()` while neither the method nor its class carries `@UseGuards(...)`. Nothing established the identity, so what reaches the handler is whatever the pipeline left there - and the failure is silent, because the parameter still says `user` and the handler still receives one. Put the guard on the door that reads the identity.",
|
|
75
|
-
},
|
|
76
|
-
},
|
|
77
|
-
create(context) {
|
|
78
|
-
return {
|
|
79
|
-
MethodDefinition(node) {
|
|
80
|
-
const parameter = identityParameter(node)
|
|
81
|
-
if (!parameter) return
|
|
82
|
-
if (hasGuard(node.decorators)) return
|
|
83
|
-
|
|
84
|
-
// the guard may sit on the class instead, covering every method on it
|
|
85
|
-
const classBody = node.parent
|
|
86
|
-
const classNode = classBody && classBody.parent
|
|
87
|
-
if (classNode && hasGuard(classNode.decorators)) return
|
|
88
|
-
|
|
89
|
-
const carrier = parameter.type === "TSParameterProperty" ? parameter.parameter : parameter
|
|
90
|
-
const decorators = parameter.decorators || (carrier && carrier.decorators) || []
|
|
91
|
-
const named = decorators.map(decoratorName).find((name) => IDENTITY_PARAM_DECORATORS.has(name))
|
|
92
|
-
context.report({ node: parameter, messageId: "unguarded", data: { decorator: named } })
|
|
93
|
-
},
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/** Every rule this module ships, by the name a config switches it on under. */
|
|
99
|
-
export const rules = {
|
|
100
|
-
"identity-needs-guard": identityNeedsGuard,
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/** The level a consuming repository switches this on at. */
|
|
104
|
-
export const recommended = {
|
|
105
|
-
"starci-be/identity-needs-guard": "error",
|
|
106
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* The rule that holds `authorization.md`.
|
|
3
|
+
*
|
|
4
|
+
* ONE rule, and the honest reason is worth stating: authorization is decided against a row, and a
|
|
5
|
+
* parser does not know which row a handler is reaching for or what owning it means. AUTHZ-3, -4 and
|
|
6
|
+
* -5 all turn on that, so a rule aimed at them would fire on shape rather than on meaning - and a
|
|
7
|
+
* rule that fires on shape is one authors learn to disable, which leaves the law worse off than when
|
|
8
|
+
* nothing enforced it.
|
|
9
|
+
*
|
|
10
|
+
* AUTHZ-1 was measured and deliberately left alone. A handler checking `if (!user)` reads like
|
|
11
|
+
* duplication of the door's guard and is not: the guard belongs to one door and the handler belongs
|
|
12
|
+
* to every caller of the bus. A rule refusing it would fire on the majority of correct handlers in
|
|
13
|
+
* this tree, which is a gate contradicting canon rather than holding it.
|
|
14
|
+
*
|
|
15
|
+
* What IS checkable in one file is the door: a resolver method that READS the authenticated user
|
|
16
|
+
* while nothing on that method or its class establishes the identity. That failure looks like
|
|
17
|
+
* nothing at all - the parameter still says `user`, the handler still receives one - and the only
|
|
18
|
+
* missing piece is the line that proved it belonged to the caller.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/** Parameter decorators that read an already-authenticated identity off the request. */
|
|
22
|
+
const IDENTITY_PARAM_DECORATORS = new Set([
|
|
23
|
+
"KeycloakGraphQLUser",
|
|
24
|
+
"KeycloakUser",
|
|
25
|
+
"CurrentUser",
|
|
26
|
+
])
|
|
27
|
+
|
|
28
|
+
/** The decorator that establishes the identity a door then reads. */
|
|
29
|
+
const GUARD_DECORATOR = "UseGuards"
|
|
30
|
+
|
|
31
|
+
/** Reads the callee name off a decorator expression, whether or not it is called. */
|
|
32
|
+
const decoratorName = (decorator) => {
|
|
33
|
+
const expression = decorator.expression
|
|
34
|
+
if (!expression) return undefined
|
|
35
|
+
if (expression.type === "CallExpression") {
|
|
36
|
+
return expression.callee && expression.callee.type === "Identifier"
|
|
37
|
+
? expression.callee.name
|
|
38
|
+
: undefined
|
|
39
|
+
}
|
|
40
|
+
return expression.type === "Identifier" ? expression.name : undefined
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Whether any decorator in the list is the guard. */
|
|
44
|
+
const hasGuard = (decorators) =>
|
|
45
|
+
(decorators || []).some((decorator) => decoratorName(decorator) === GUARD_DECORATOR)
|
|
46
|
+
|
|
47
|
+
/** The identity parameter on a method, when it has one. */
|
|
48
|
+
const identityParameter = (node) => {
|
|
49
|
+
for (const parameter of node.value && node.value.params ? node.value.params : []) {
|
|
50
|
+
// a decorated parameter carries its decorators on the parameter node itself, and TS-ESTree
|
|
51
|
+
// wraps a typed+decorated parameter in TSParameterProperty for constructor promotion
|
|
52
|
+
const carrier = parameter.type === "TSParameterProperty" ? parameter.parameter : parameter
|
|
53
|
+
const decorators = parameter.decorators || (carrier && carrier.decorators) || []
|
|
54
|
+
for (const decorator of decorators) {
|
|
55
|
+
if (IDENTITY_PARAM_DECORATORS.has(decoratorName(decorator))) return parameter
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return undefined
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// -- AUTHZ-2 ---------------------------------------------------------------------------------------
|
|
62
|
+
|
|
63
|
+
/** A door that reads an identity carries the guard that establishes it. */
|
|
64
|
+
export const identityNeedsGuard = {
|
|
65
|
+
meta: {
|
|
66
|
+
type: "problem",
|
|
67
|
+
docs: {
|
|
68
|
+
description:
|
|
69
|
+
"A resolver or controller method reading the authenticated user must carry a guard on that method or its class.",
|
|
70
|
+
},
|
|
71
|
+
schema: [],
|
|
72
|
+
messages: {
|
|
73
|
+
unguarded:
|
|
74
|
+
"This door reads the authenticated user through `@{{decorator}}()` while neither the method nor its class carries `@UseGuards(...)`. Nothing established the identity, so what reaches the handler is whatever the pipeline left there - and the failure is silent, because the parameter still says `user` and the handler still receives one. Put the guard on the door that reads the identity.",
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
create(context) {
|
|
78
|
+
return {
|
|
79
|
+
MethodDefinition(node) {
|
|
80
|
+
const parameter = identityParameter(node)
|
|
81
|
+
if (!parameter) return
|
|
82
|
+
if (hasGuard(node.decorators)) return
|
|
83
|
+
|
|
84
|
+
// the guard may sit on the class instead, covering every method on it
|
|
85
|
+
const classBody = node.parent
|
|
86
|
+
const classNode = classBody && classBody.parent
|
|
87
|
+
if (classNode && hasGuard(classNode.decorators)) return
|
|
88
|
+
|
|
89
|
+
const carrier = parameter.type === "TSParameterProperty" ? parameter.parameter : parameter
|
|
90
|
+
const decorators = parameter.decorators || (carrier && carrier.decorators) || []
|
|
91
|
+
const named = decorators.map(decoratorName).find((name) => IDENTITY_PARAM_DECORATORS.has(name))
|
|
92
|
+
context.report({ node: parameter, messageId: "unguarded", data: { decorator: named } })
|
|
93
|
+
},
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Every rule this module ships, by the name a config switches it on under. */
|
|
99
|
+
export const rules = {
|
|
100
|
+
"identity-needs-guard": identityNeedsGuard,
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** The level a consuming repository switches this on at. */
|
|
104
|
+
export const recommended = {
|
|
105
|
+
"starci-be/identity-needs-guard": "error",
|
|
106
|
+
}
|