@ddd-ts-kit/eslint-plugin 0.13.0 → 0.14.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/README.md +1 -0
- package/dist/rules/authz-fields-by-schema.d.ts +5 -0
- package/dist/rules/authz-fields-by-schema.d.ts.map +1 -0
- package/dist/rules/authz-fields-by-schema.js +63 -0
- package/dist/rules/authz-fields-by-schema.js.map +1 -0
- package/dist/rules/rules.d.ts.map +1 -1
- package/dist/rules/rules.js +2 -0
- package/dist/rules/rules.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/rules/authz-fields-by-schema.md +50 -0
- package/docs/rules/clean-formatted.md +1 -1
- package/docs/rules/presentation-shared-cache-varies.md +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -130,6 +130,7 @@ is an error whatever the configured limit). `strict` sets every rule to `error`.
|
|
|
130
130
|
| [`authz/declared`](docs/rules/authz-declared.md) | `ddd-ts-kit/authz-declared` | a registered command or query says `.requires(...)` or `.public()`, or its class carries `@Requires` or `@Public` (required on every message of the declared style), a route declares `security`, an authorized message forwards its actor | `error` | custom |
|
|
131
131
|
| [`authz/in-application`](docs/rules/authz-in-application.md) | `ddd-ts-kit/authz-in-application` | no role test in `presentation/`, no authorization in `infrastructure/`, no actor, session, execution context or rights in `domain/`; in the declared style `Requires`, `Public`, `Policy` and the `Access` port stay in `application/` | `error` | custom |
|
|
132
132
|
| [`authz/actor-explicit`](docs/rules/authz-actor-explicit.md) | `ddd-ts-kit/authz-actor-explicit` | no `ExecutionScope`, `ActorContext` (type or value: the class is the token) or `AsyncLocalStorage`, no read of the ambient context, no `stampCreation`, `stampUpdate` or `tenantScopeOf` in `domain/` and `application/` | `error` | custom |
|
|
133
|
+
| [`authz/fields-by-schema`](docs/rules/authz-fields-by-schema.md) | `ddd-ts-kit/authz-fields-by-schema` | no test on the roles of the actor, comparison with a role or `isAdmin` under `application/queries/`: a field reserved to some callers is marked with `withFieldAccess` | `error` | custom |
|
|
133
134
|
| [`aspects/outside-in`](docs/rules/aspects-outside-in.md) | `ddd-ts-kit/aspects-outside-in` | `@ddd-ts-kit/aspects/decorators` is imported only in `infrastructure/` and in the platform | `error` | custom |
|
|
134
135
|
| [`tracing/platform-only`](docs/rules/tracing-platform-only.md) | `ddd-ts-kit/tracing-platform-only` | `@ddd-ts-kit/tracing` and `@opentelemetry/*` are imported only by the platform directory, `main.ts` and `apps/` | `error` | custom |
|
|
135
136
|
| [`standard/no-parallel-interface`](docs/rules/standard-no-parallel-interface.md) | `ddd-ts-kit/standard-no-parallel-interface` | no declared `ILogger`, `UserContext`, `PaginatedResult`, `CronJob`, `ErrorTracker` and the like next to the standard interfaces of the kernel (`standardInterfaces` in the config) | `warn` | custom |
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type TSESLint } from '@typescript-eslint/utils';
|
|
2
|
+
type MessageId = 'roles' | 'roleTest';
|
|
3
|
+
export declare const authzFieldsBySchema: TSESLint.RuleModule<MessageId, [], import("../index.js").RuleDocs, TSESLint.RuleListener>;
|
|
4
|
+
export {};
|
|
5
|
+
//# sourceMappingURL=authz-fields-by-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authz-fields-by-schema.d.ts","sourceRoot":"","sources":["../../src/rules/authz-fields-by-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,QAAQ,EAAiB,MAAM,0BAA0B,CAAC;AAIxF,KAAK,SAAS,GAAG,OAAO,GAAG,UAAU,CAAC;AAQtC,eAAO,MAAM,mBAAmB,2FAwB9B,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/utils';
|
|
2
|
+
import { defineRule } from '../support/rule/define-rule.js';
|
|
3
|
+
import { propertyName } from '../support/globals/property-name.js';
|
|
4
|
+
const ROLE_SEARCHES = new Set(['includes', 'some', 'every', 'find', 'indexOf']);
|
|
5
|
+
const EQUALITY = new Set(['===', '!==', '==', '!=']);
|
|
6
|
+
const INSTEAD = 'Answer every field the read model holds and mark the one reserved to some callers on the response schema: `withFieldAccess(schema, { internalNote: { read: { permission } } })` of @ddd-ts-kit/http. It is left out of JSON, XML and CSV alike for an actor who may not read it, the contract says so, and a form shows it read-only or not at all.';
|
|
7
|
+
export const authzFieldsBySchema = defineRule({
|
|
8
|
+
id: 'authz/fields-by-schema',
|
|
9
|
+
type: 'problem',
|
|
10
|
+
recommended: 'error',
|
|
11
|
+
description: 'A query never shapes its answer by the roles of the actor: a field reserved to some callers is marked on the response schema with withFieldAccess.',
|
|
12
|
+
messages: {
|
|
13
|
+
roles: `The query tests {{access}}: an answer shaped by role differs in every representation and in no contract. ${INSTEAD}`,
|
|
14
|
+
roleTest: `The query compares {{access}} with a role name. ${INSTEAD}`,
|
|
15
|
+
},
|
|
16
|
+
create({ file, sourceCode, report }) {
|
|
17
|
+
const { location } = file;
|
|
18
|
+
if (location.area !== 'context' ||
|
|
19
|
+
location.layer !== 'application' ||
|
|
20
|
+
file.isTest ||
|
|
21
|
+
location.inside[0] !== 'queries') {
|
|
22
|
+
return {};
|
|
23
|
+
}
|
|
24
|
+
return listeners(sourceCode, report);
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
function listeners(sourceCode, report) {
|
|
28
|
+
const roleTest = (node, tested) => {
|
|
29
|
+
if (namedAs(tested, 'role')) {
|
|
30
|
+
report({ node, messageId: 'roleTest', data: { access: sourceCode.getText(tested) } });
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
return {
|
|
34
|
+
CallExpression(node) {
|
|
35
|
+
const { callee } = node;
|
|
36
|
+
if (callee.type !== AST_NODE_TYPES.MemberExpression || !ROLE_SEARCHES.has(propertyName(callee) ?? '')) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (namedAs(callee.object, 'roles')) {
|
|
40
|
+
report({ node, messageId: 'roles', data: { access: sourceCode.getText(callee.object) } });
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
MemberExpression(node) {
|
|
44
|
+
if (propertyName(node) === 'isAdmin') {
|
|
45
|
+
report({ node, messageId: 'roles', data: { access: sourceCode.getText(node) } });
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
BinaryExpression(node) {
|
|
49
|
+
if (EQUALITY.has(node.operator)) {
|
|
50
|
+
roleTest(node, node.left);
|
|
51
|
+
roleTest(node, node.right);
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/** `roles` or `role`, held by the actor (`query.actor.roles`) or taken out of it first (`const { roles } = query.actor`). */
|
|
57
|
+
function namedAs(node, name) {
|
|
58
|
+
if (node.type === AST_NODE_TYPES.Identifier) {
|
|
59
|
+
return node.name === name;
|
|
60
|
+
}
|
|
61
|
+
return node.type === AST_NODE_TYPES.MemberExpression && propertyName(node) === name;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=authz-fields-by-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authz-fields-by-schema.js","sourceRoot":"","sources":["../../src/rules/authz-fields-by-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAgC,MAAM,0BAA0B,CAAC;AACxF,OAAO,EAAE,UAAU,EAAe,MAAM,gCAAgC,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AAInE,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;AAChF,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AAErD,MAAM,OAAO,GACX,qVAAqV,CAAC;AAExV,MAAM,CAAC,MAAM,mBAAmB,GAAG,UA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CAAC;
|
|
1
|
+
{"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../src/rules/rules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,OAAO,EAAE,MAAM,4BAA4B,CAAC;AA4IlE,+HAA+H;AAC/H,eAAO,MAAM,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEnD,CAAC"}
|
package/dist/rules/rules.js
CHANGED
|
@@ -4,6 +4,7 @@ import { applicationHandlerShape } from './application-handler-shape.js';
|
|
|
4
4
|
import { aspectsOutsideIn } from './aspects-outside-in.js';
|
|
5
5
|
import { authzActorExplicit } from './authz-actor-explicit.js';
|
|
6
6
|
import { authzDeclared } from './authz-declared.js';
|
|
7
|
+
import { authzFieldsBySchema } from './authz-fields-by-schema.js';
|
|
7
8
|
import { authzInApplication } from './authz-in-application.js';
|
|
8
9
|
import { cleanFileSize } from './clean-file-size.js';
|
|
9
10
|
import { cleanFunctionCeiling } from './clean-function-ceiling.js';
|
|
@@ -107,6 +108,7 @@ const ALL = [
|
|
|
107
108
|
authzDeclared,
|
|
108
109
|
authzInApplication,
|
|
109
110
|
authzActorExplicit,
|
|
111
|
+
authzFieldsBySchema,
|
|
110
112
|
aspectsOutsideIn,
|
|
111
113
|
tracingPlatformOnly,
|
|
112
114
|
standardNoParallelInterface,
|
package/dist/rules/rules.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rules.js","sourceRoot":"","sources":["../../src/rules/rules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAgB,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,iCAAiC,EAAE,MAAM,2CAA2C,CAAC;AAC9F,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D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AChB,mBAAmB;IACnB,2BAA2B;IAC3B,2BAA2B;IAC3B,wBAAwB;IACxB,gCAAgC;IAChC,kBAAkB;IAClB,2BAA2B;IAC3B,oBAAoB;IACpB,yBAAyB;IACzB,gBAAgB;IAChB,4BAA4B;IAC5B,6BAA6B;IAC7B,wBAAwB;IACxB,iBAAiB;IACjB,sBAAsB;IACtB,gBAAgB;IAChB,gBAAgB;IAChB,2BAA2B;IAC3B,+BAA+B;IAC/B,0BAA0B;IAC1B,6BAA6B;CAC9B,CAAC;AAEF,+HAA+H;AAC/H,MAAM,CAAC,MAAM,KAAK,GAAsC,MAAM,CAAC,WAAW,CACxE,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAC7C,CAAC"}
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.14.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = '0.
|
|
1
|
+
export const VERSION = '0.14.0';
|
|
2
2
|
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# ddd-ts-kit/authz-fields-by-schema
|
|
2
|
+
|
|
3
|
+
Architecture id: `authz/fields-by-schema`. Default severity: `error` in `recommended`, `error` in `strict`.
|
|
4
|
+
|
|
5
|
+
Applies to: `application/queries/` of a context, tests excluded.
|
|
6
|
+
|
|
7
|
+
## Why
|
|
8
|
+
|
|
9
|
+
A query that removes a field for the callers without a role answers one way in JSON and is
|
|
10
|
+
forgotten in the CSV export, the XML of a partner and the form of the front end; nobody reading
|
|
11
|
+
the contract knows the field may be missing. Marked on the response schema with
|
|
12
|
+
`withFieldAccess` of `@ddd-ts-kit/http`, the field is reserved to a permission or a policy once:
|
|
13
|
+
the pipeline leaves it out of every representation for an actor who may not read it, refuses it
|
|
14
|
+
in a request body from one who may not set it, the contract says so with `x-field-access`, and a
|
|
15
|
+
form described by the server shows it read-only or not at all. Which rows the actor may read at
|
|
16
|
+
all stays the access scope of the query.
|
|
17
|
+
|
|
18
|
+
## Reported
|
|
19
|
+
|
|
20
|
+
- a call of `includes`, `some`, `every`, `find` or `indexOf` on a `roles` property
|
|
21
|
+
- a comparison (`===`, `!==`, `==`, `!=`) of a `role` property
|
|
22
|
+
- a read of an `isAdmin` property
|
|
23
|
+
|
|
24
|
+
Incorrect:
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
export class GetAppointmentHandler {
|
|
28
|
+
async execute(query: GetAppointmentQuery): Promise<AppointmentView> {
|
|
29
|
+
const view = await this.appointments.findById(query.appointmentId);
|
|
30
|
+
|
|
31
|
+
return query.actor.roles.includes('practitioner') ? view : { ...view, internalNote: undefined };
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Correct:
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
// application/queries/get-appointment/get-appointment.handler.ts
|
|
40
|
+
return this.appointments.findById(query.appointmentId);
|
|
41
|
+
|
|
42
|
+
// presentation/http/appointments/get-appointment/get-appointment.controller.ts
|
|
43
|
+
const answer = withFieldAccess(classSchema(GetAppointmentAnswer), {
|
|
44
|
+
internalNote: { read: { permission: schedulingPermissions['appointment.note.read'] } },
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Checker
|
|
49
|
+
|
|
50
|
+
`ddd-ts-kit check` reports the same tests under the same id, from the text of the file.
|
|
@@ -24,7 +24,7 @@ The presets enable no rule that decides where a token goes, so the two never fig
|
|
|
24
24
|
## Limits
|
|
25
25
|
|
|
26
26
|
- Markdown and YAML are not formatted.
|
|
27
|
-
- Generated artifacts compared byte for byte by their own check (`openapi/*.json`, `asyncapi.json`, `.dependency-cruiser.cjs`) and build outputs are left out in `biome.json`.
|
|
27
|
+
- Generated artifacts compared byte for byte by their own check (`openapi/*.json`, `openapi/forms/`, `asyncapi.json`, `.dependency-cruiser.cjs`) and build outputs are left out in `biome.json`.
|
|
28
28
|
- A string literal, a URL or a regular expression longer than 120 columns stays on its line: a formatter does not cut a token.
|
|
29
29
|
|
|
30
30
|
## With the CLI checker
|
|
@@ -41,7 +41,7 @@ export class AgendaRoutes {}
|
|
|
41
41
|
|
|
42
42
|
A controller that names its group and writes no `guards` of its own takes the guards of the group, which another file declares: it is not judged here, and `@ddd-ts-kit/http` refuses the same declaration with a `DeclarationError` when the routes are built, for every route whatever the file. The rule is the editor's early view of that refusal.
|
|
43
43
|
|
|
44
|
-
What a non-empty `vary` names is held when the routes are mounted, where the options of the application are known: it must name `Authorization`, `Cookie` or the header the tenant is read from (`vary: ['Accept-Language']` alone is refused), and a cache that ignores `Vary` (Cloudflare, Bunny) refuses a varying public answer. The rule does not judge that: one file does not show the options.
|
|
44
|
+
What a non-empty `vary` names is held when the routes are mounted, where the options of the application are known: it must name `Authorization`, `Cookie` or the header the tenant is read from (`vary: ['Accept-Language']` alone is refused), and a cache that ignores `Vary` (Cloudflare, Bunny) refuses a varying public answer. An answer whose schema reserves fields to some callers (`withFieldAccess`) must name `Authorization` or `Cookie` there too, even on a route anybody may call. The rule does not judge that: one file does not show the options nor the marks of the schema.
|
|
45
45
|
|
|
46
46
|
## Options
|
|
47
47
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ddd-ts-kit/eslint-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "AST-accurate ESLint rules for DDD and Clean Architecture in TypeScript: layer and context isolation, domain purity, clean code ordering.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|