@starci/eslint-canon-be 3.4.57 → 3.6.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 +19 -0
- package/README.md +11 -2
- package/dist/ambient-id.d.ts +9 -0
- package/{ambient-id.mjs → dist/ambient-id.js} +43 -39
- package/dist/app-composition.d.ts +21 -0
- package/{app-composition.mjs → dist/app-composition.js} +396 -300
- package/dist/async-discipline.d.ts +9 -0
- package/dist/async-discipline.js +77 -0
- package/dist/authorization.d.ts +12 -0
- package/{authorization.mjs → dist/authorization.js} +53 -59
- package/dist/boundary-schema.d.ts +15 -0
- package/{boundary-schema.mjs → dist/boundary-schema.js} +120 -105
- package/dist/builders.d.ts +21 -0
- package/{builders.mjs → dist/builders.js} +162 -146
- package/dist/cli.d.ts +15 -0
- package/{cli.mjs → dist/cli.js} +97 -82
- package/dist/comments.d.ts +52 -0
- package/dist/comments.js +412 -0
- package/dist/config-owner.d.ts +24 -0
- package/{config-owner.mjs → dist/config-owner.js} +256 -219
- package/dist/connections.d.ts +12 -0
- package/{connections.mjs → dist/connections.js} +138 -140
- package/dist/cookies.d.ts +9 -0
- package/{cookies.mjs → dist/cookies.js} +58 -58
- package/dist/cqrs.d.ts +27 -0
- package/{cqrs.mjs → dist/cqrs.js} +341 -282
- package/dist/data-access.d.ts +50 -0
- package/{data-access.mjs → dist/data-access.js} +238 -243
- package/dist/default-deny.d.ts +15 -0
- package/{default-deny.mjs → dist/default-deny.js} +103 -88
- package/dist/e2e-flow.d.ts +25 -0
- package/{e2e-flow.mjs → dist/e2e-flow.js} +113 -112
- package/dist/edge-hardening.d.ts +10 -0
- package/dist/edge-hardening.js +173 -0
- package/dist/error-handling.d.ts +21 -0
- package/{error-handling.mjs → dist/error-handling.js} +289 -239
- package/dist/event-bus.d.ts +14 -0
- package/{event-bus.mjs → dist/event-bus.js} +146 -129
- package/dist/feature-thin.d.ts +12 -0
- package/{feature-thin.mjs → dist/feature-thin.js} +208 -191
- package/dist/function-budget.d.ts +7 -0
- package/{function-budget.mjs → dist/function-budget.js} +24 -27
- package/dist/health-ready.d.ts +10 -0
- package/dist/health-ready.js +703 -0
- package/dist/idempotency.d.ts +10 -0
- package/{idempotency.mjs → dist/idempotency.js} +296 -226
- package/dist/index.d.ts +54 -0
- package/{index.mjs → dist/index.js} +91 -109
- package/dist/infra-owner.d.ts +18 -0
- package/{infra-owner.mjs → dist/infra-owner.js} +58 -51
- package/dist/injection.d.ts +30 -0
- package/{injection.mjs → dist/injection.js} +397 -344
- package/dist/input-bounds.d.ts +15 -0
- package/{input-bounds.mjs → dist/input-bounds.js} +143 -132
- package/dist/jobs.d.ts +17 -0
- package/{jobs.mjs → dist/jobs.js} +116 -99
- package/dist/jwt-alg.d.ts +6 -0
- package/dist/jwt-alg.js +49 -0
- package/dist/lib/app-roles.d.ts +25 -0
- package/{lib/app-roles.mjs → dist/lib/app-roles.js} +15 -17
- package/dist/lib/ast.d.ts +40 -0
- package/dist/lib/ast.js +100 -0
- package/dist/lib/client-idempotency.d.ts +3 -0
- package/{lib/client-idempotency.mjs → dist/lib/client-idempotency.js} +316 -268
- package/dist/lib/config.d.ts +36 -0
- package/{lib/config.mjs → dist/lib/config.js} +24 -27
- package/dist/lib/db-writes.d.ts +29 -0
- package/{lib/db-writes.mjs → dist/lib/db-writes.js} +27 -27
- package/dist/lib/declared.d.ts +77 -0
- package/{lib/declared.mjs → dist/lib/declared.js} +83 -78
- package/dist/lib/doors.d.ts +50 -0
- package/{lib/doors.mjs → dist/lib/doors.js} +45 -50
- package/dist/lib/edition.d.ts +25 -0
- package/{lib/edition.mjs → dist/lib/edition.js} +15 -20
- package/dist/lib/entity-writes.d.ts +7 -0
- package/{lib/entity-writes.mjs → dist/lib/entity-writes.js} +31 -22
- package/dist/lib/hfs.d.ts +34 -0
- package/{lib/hfs.mjs → dist/lib/hfs.js} +31 -29
- package/dist/lib/import-source.d.ts +63 -0
- package/dist/lib/import-source.js +134 -0
- package/dist/lib/path.d.ts +8 -0
- package/{lib/path.mjs → dist/lib/path.js} +4 -7
- package/dist/lib/persistence.d.ts +115 -0
- package/{lib/persistence.mjs → dist/lib/persistence.js} +55 -66
- package/dist/lib/ports.d.ts +70 -0
- package/{lib/ports.mjs → dist/lib/ports.js} +62 -66
- package/dist/lib/rule.d.ts +31 -0
- package/dist/lib/rule.js +2 -0
- package/dist/lib/runtime-root.d.ts +4 -0
- package/dist/lib/runtime-root.js +10 -0
- package/dist/lib/schema-values.d.ts +13 -0
- package/{lib/schema-values.mjs → dist/lib/schema-values.js} +67 -59
- package/dist/lib/specifier.d.ts +12 -0
- package/dist/lib/specifier.js +29 -0
- package/dist/lib/subject-values.d.ts +4 -0
- package/dist/lib/subject-values.js +61 -0
- package/dist/lib/transactions.d.ts +18 -0
- package/{lib/transactions.mjs → dist/lib/transactions.js} +17 -15
- package/dist/lib/transport-slots.d.ts +17 -0
- package/{lib/transport-slots.mjs → dist/lib/transport-slots.js} +2 -4
- package/dist/lib/types.d.ts +96 -0
- package/dist/lib/types.js +150 -0
- package/dist/lib/unit-spec.d.ts +48 -0
- package/{lib/unit-spec.mjs → dist/lib/unit-spec.js} +35 -44
- package/dist/lib/webhook-ack.d.ts +4 -0
- package/{lib/webhook-ack.mjs → dist/lib/webhook-ack.js} +78 -62
- package/dist/lib/webhook-handoff-inbox.d.ts +3 -0
- package/{lib/webhook-handoff-inbox.mjs → dist/lib/webhook-handoff-inbox.js} +195 -167
- package/dist/lib/webhook-handoff-intake.d.ts +4 -0
- package/{lib/webhook-handoff-intake.mjs → dist/lib/webhook-handoff-intake.js} +125 -102
- package/dist/lib/webhook-handoff.d.ts +15 -0
- package/{lib/webhook-handoff.mjs → dist/lib/webhook-handoff.js} +107 -100
- package/dist/lib/webhook-verifiers.d.ts +20 -0
- package/{lib/webhook-verifiers.mjs → dist/lib/webhook-verifiers.js} +108 -104
- package/dist/lib/why.d.ts +9 -0
- package/{lib/why.mjs → dist/lib/why.js} +6 -6
- package/dist/log-safety.d.ts +20 -0
- package/dist/log-safety.js +308 -0
- package/dist/module-layering.d.ts +42 -0
- package/dist/module-layering.js +257 -0
- package/dist/module-shape.d.ts +47 -0
- package/{module-shape.mjs → dist/module-shape.js} +278 -236
- package/dist/naming.d.ts +49 -0
- package/dist/naming.js +246 -0
- package/dist/observability.d.ts +25 -0
- package/dist/observability.js +245 -0
- package/dist/operations.d.ts +23 -0
- package/{operations.mjs → dist/operations.js} +410 -332
- package/dist/project-graph.d.ts +9 -0
- package/{project-graph.mjs → dist/project-graph.js} +8 -13
- package/dist/projections.d.ts +11 -0
- package/{projections.mjs → dist/projections.js} +60 -57
- package/dist/query-safety.d.ts +21 -0
- package/{query-safety.mjs → dist/query-safety.js} +92 -108
- package/dist/realtime.d.ts +15 -0
- package/{realtime.mjs → dist/realtime.js} +108 -106
- package/dist/resilience.d.ts +15 -0
- package/dist/resilience.js +319 -0
- package/dist/schema-authority.d.ts +15 -0
- package/{schema-authority.mjs → dist/schema-authority.js} +256 -220
- package/dist/service-deps.d.ts +17 -0
- package/{service-deps.mjs → dist/service-deps.js} +133 -130
- package/dist/service-isolation.d.ts +8 -0
- package/dist/service-isolation.js +76 -0
- package/dist/size-budget.d.ts +9 -0
- package/{size-budget.mjs → dist/size-budget.js} +27 -27
- package/dist/sonar-parity.d.ts +5 -0
- package/{sonar-parity.mjs → dist/sonar-parity.js} +7 -7
- package/dist/spec-no-skip.d.ts +9 -0
- package/dist/spec-no-skip.js +81 -0
- package/dist/spec-quality.d.ts +10 -0
- package/{spec-quality.mjs → dist/spec-quality.js} +103 -87
- package/dist/suppression.d.ts +26 -0
- package/{suppression.mjs → dist/suppression.js} +30 -45
- package/dist/temporal.d.ts +9 -0
- package/{temporal.mjs → dist/temporal.js} +75 -65
- package/dist/test-world.d.ts +28 -0
- package/{test-world.mjs → dist/test-world.js} +102 -83
- package/dist/testing.d.ts +51 -0
- package/dist/testing.js +368 -0
- package/dist/third-party-owner.d.ts +8 -0
- package/{third-party-owner.mjs → dist/third-party-owner.js} +105 -91
- package/dist/transport.d.ts +24 -0
- package/{transport.mjs → dist/transport.js} +279 -240
- package/dist/type-safety.d.ts +25 -0
- package/dist/type-safety.js +297 -0
- package/dist/unit-spec.d.ts +30 -0
- package/{unit-spec.mjs → dist/unit-spec.js} +473 -399
- package/dist/uploads.d.ts +9 -0
- package/{uploads.mjs → dist/uploads.js} +62 -54
- package/dist/user-copy.d.ts +9 -0
- package/{user-copy.mjs → dist/user-copy.js} +76 -67
- package/dist/webhooks.d.ts +16 -0
- package/{webhooks.mjs → dist/webhooks.js} +243 -231
- package/package.json +17 -8
- package/runtime/knowledge/hfs/canon-pins.yaml +22 -14
- package/runtime/knowledge/hfs/rules.yaml +23 -0
- package/runtime/scripts/lib/package-at.mjs +5 -5
- package/async-discipline.mjs +0 -83
- package/comments.mjs +0 -416
- package/edge-hardening.mjs +0 -139
- package/health-ready.mjs +0 -539
- package/jwt-alg.mjs +0 -45
- package/lib/ast.mjs +0 -88
- package/lib/import-source.mjs +0 -104
- package/lib/specifier.mjs +0 -27
- package/lib/subject-values.mjs +0 -55
- package/lib/types.mjs +0 -133
- package/log-safety.mjs +0 -303
- package/module-layering.mjs +0 -270
- package/naming.mjs +0 -251
- package/observability.mjs +0 -241
- package/resilience.mjs +0 -304
- package/service-isolation.mjs +0 -75
- package/spec-no-skip.mjs +0 -85
- package/testing.mjs +0 -384
- package/type-safety.mjs +0 -323
|
@@ -1,217 +1,238 @@
|
|
|
1
1
|
/** R263 extends inbox dedupe to scalar delivery ids and signed raw-body intakes. */
|
|
2
|
-
import ts from "typescript"
|
|
3
|
-
import { walk } from "./ast.
|
|
4
|
-
import { hfsOf } from "./hfs.
|
|
5
|
-
import { baseName, isOwnedType, ownerNameOf } from "./ports.
|
|
6
|
-
import { resolveVariable } from "./transactions.
|
|
7
|
-
import { isPackageType, typed } from "./types.
|
|
8
|
-
import { webhookIntakeProcessesDelivery } from "./webhook-handoff-intake.
|
|
9
|
-
|
|
10
|
-
const DELIVERY_ID = /Id$/
|
|
11
|
-
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
import { memberKeyValue, nameOrValue, walk } from "./ast.js";
|
|
4
|
+
import { hfsOf } from "./hfs.js";
|
|
5
|
+
import { baseName, isOwnedType, ownerNameOf } from "./ports.js";
|
|
6
|
+
import { resolveVariable } from "./transactions.js";
|
|
7
|
+
import { isPackageType, typed } from "./types.js";
|
|
8
|
+
import { webhookIntakeProcessesDelivery } from "./webhook-handoff-intake.js";
|
|
9
|
+
const DELIVERY_ID = /Id$/;
|
|
12
10
|
/** The slot of provider webhook doors (`<provider>.webhook.ts`), the only entrance of a delivery intake. */
|
|
13
|
-
const DOOR_SLOT = "be.feature.webhooks.http"
|
|
14
|
-
|
|
11
|
+
const DOOR_SLOT = "be.feature.webhooks.http";
|
|
15
12
|
/** The method declarations each program's webhook doors call, computed once per program. */
|
|
16
|
-
const reachedByProgram = new WeakMap()
|
|
17
|
-
|
|
13
|
+
const reachedByProgram = new WeakMap();
|
|
18
14
|
/** Declarations a call resolves to: its signature's declaration and its (alias-resolved) callee symbol's declarations. */
|
|
19
15
|
const calledDeclarations = (checker, call) => {
|
|
20
|
-
const expression = call.expression
|
|
16
|
+
const expression = call.expression;
|
|
21
17
|
const name = ts.isPropertyAccessExpression(expression) ? expression.name
|
|
22
|
-
: ts.isElementAccessExpression(expression) ? expression.argumentExpression : expression
|
|
23
|
-
const symbol = checker.getSymbolAtLocation(name)
|
|
24
|
-
const target = symbol && symbol.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol
|
|
25
|
-
return [checker.getResolvedSignature(call)?.declaration, ...(target?.getDeclarations() ?? [])].filter(Boolean)
|
|
26
|
-
}
|
|
27
|
-
|
|
18
|
+
: ts.isElementAccessExpression(expression) ? expression.argumentExpression : expression;
|
|
19
|
+
const symbol = checker.getSymbolAtLocation(name);
|
|
20
|
+
const target = symbol && symbol.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
|
|
21
|
+
return [checker.getResolvedSignature(call)?.declaration, ...(target?.getDeclarations() ?? [])].filter((declaration) => Boolean(declaration));
|
|
22
|
+
};
|
|
28
23
|
/** Every method a webhook door file (slot be.feature.webhooks.http, `*.webhook.ts`) calls, by resolved declaration. */
|
|
29
24
|
const doorCalledDeclarations = (context, hfs) => {
|
|
30
|
-
const { program, checker } = typed(context)
|
|
31
|
-
const cached = reachedByProgram.get(program)
|
|
32
|
-
if (cached)
|
|
33
|
-
|
|
25
|
+
const { program, checker } = typed(context);
|
|
26
|
+
const cached = reachedByProgram.get(program);
|
|
27
|
+
if (cached)
|
|
28
|
+
return cached;
|
|
29
|
+
const reached = new Set();
|
|
34
30
|
for (const source of program.getSourceFiles()) {
|
|
35
|
-
if (hfs.slotOf(source.fileName) !== DOOR_SLOT || !baseName(source.fileName).endsWith(".webhook.ts"))
|
|
31
|
+
if (hfs.slotOf(source.fileName) !== DOOR_SLOT || !baseName(source.fileName).endsWith(".webhook.ts"))
|
|
32
|
+
continue;
|
|
36
33
|
const visit = (node) => {
|
|
37
|
-
if (ts.isCallExpression(node))
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
34
|
+
if (ts.isCallExpression(node))
|
|
35
|
+
for (const declaration of calledDeclarations(checker, node))
|
|
36
|
+
reached.add(declaration);
|
|
37
|
+
ts.forEachChild(node, visit);
|
|
38
|
+
};
|
|
39
|
+
visit(source);
|
|
41
40
|
}
|
|
42
|
-
reachedByProgram.set(program, reached)
|
|
43
|
-
return reached
|
|
44
|
-
}
|
|
45
|
-
|
|
41
|
+
reachedByProgram.set(program, reached);
|
|
42
|
+
return reached;
|
|
43
|
+
};
|
|
46
44
|
/** A method is a webhook delivery intake only when a webhook door's call resolves to it. */
|
|
47
45
|
const isDoorIntake = (context, hfs, method) => {
|
|
48
|
-
const declaration = typed(context).toTs(method)
|
|
49
|
-
return !!declaration && doorCalledDeclarations(context, hfs).has(declaration)
|
|
50
|
-
}
|
|
51
|
-
|
|
46
|
+
const declaration = typed(context).toTs(method);
|
|
47
|
+
return !!declaration && doorCalledDeclarations(context, hfs).has(declaration);
|
|
48
|
+
};
|
|
52
49
|
/** Defaults keep the same first-parameter binding. */
|
|
53
|
-
const parameterOf = (parameter) => parameter?.type === "AssignmentPattern" ? parameter.left : parameter
|
|
54
|
-
|
|
50
|
+
const parameterOf = (parameter) => parameter?.type === "AssignmentPattern" ? parameter.left : parameter;
|
|
55
51
|
/** The extra delivery contracts missed by the existing eventId-object rule. */
|
|
56
52
|
const deliveryKey = (context, method) => {
|
|
57
|
-
const first = parameterOf(method.value.params[0])
|
|
58
|
-
if (!first)
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
const
|
|
64
|
-
|
|
53
|
+
const first = parameterOf(method.value.params[0]);
|
|
54
|
+
if (!first)
|
|
55
|
+
return null;
|
|
56
|
+
if (first.type === "Identifier" && DELIVERY_ID.test(first.name))
|
|
57
|
+
return { parameter: first };
|
|
58
|
+
const { checker, toTs } = typed(context);
|
|
59
|
+
const type = checker.getTypeAtLocation(toTs(first));
|
|
60
|
+
const parts = type.isUnion() ? type.types : [type];
|
|
61
|
+
const ids = [...new Set(parts.flatMap((part) => checker.getPropertiesOfType(part).map((property) => property.getName()).filter((name) => DELIVERY_ID.test(name))))];
|
|
62
|
+
if (ids.length)
|
|
63
|
+
return { parameter: first, properties: ids };
|
|
65
64
|
const raw = first.type === "Identifier" && first.name === "rawBody"
|
|
66
|
-
&& method.value.params.slice(1).some((parameter) =>
|
|
67
|
-
|
|
65
|
+
&& method.value.params.slice(1).some((parameter) => {
|
|
66
|
+
const bound = parameterOf(parameter);
|
|
67
|
+
return bound?.type === "Identifier" && bound.name === "signature";
|
|
68
|
+
})
|
|
69
|
+
|| parts.some((part) => checker.getPropertyOfType(part, "rawBody") && checker.getPropertyOfType(part, "signature"));
|
|
68
70
|
// A declared verifier class proves authenticity; its ordinary domain intake owns dedupe.
|
|
69
|
-
const owner = method.parent?.parent
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
71
|
+
const owner = method.parent?.parent;
|
|
72
|
+
const ownerName = owner?.type === "ClassDeclaration" || owner?.type === "ClassExpression" ? owner.id?.name : undefined;
|
|
73
|
+
if (raw && !/(?:Verifier|verify)$/.test(ownerName ?? ""))
|
|
74
|
+
return { parameter: first, raw: true };
|
|
75
|
+
return null;
|
|
76
|
+
};
|
|
74
77
|
/** Identifiers are compared by lexical binding, so a same-spelled shadow is not a key. */
|
|
75
78
|
const sameBinding = (context, left, right) => left?.type === "Identifier" && right?.type === "Identifier"
|
|
76
79
|
&& resolveVariable(context.sourceCode, left) !== null
|
|
77
|
-
&& resolveVariable(context.sourceCode, left) === resolveVariable(context.sourceCode, right)
|
|
78
|
-
|
|
80
|
+
&& resolveVariable(context.sourceCode, left) === resolveVariable(context.sourceCode, right);
|
|
79
81
|
/** A decoded key comes from the raw input or a later delivery-id parameter, never a widened constant. */
|
|
80
82
|
const rawKeySource = (context, expression, key, seen = new Set()) => {
|
|
81
|
-
if (!expression || seen.has(expression))
|
|
82
|
-
|
|
83
|
-
|
|
83
|
+
if (!expression || seen.has(expression))
|
|
84
|
+
return false;
|
|
85
|
+
seen.add(expression);
|
|
86
|
+
let sourced = false;
|
|
84
87
|
walk(expression, (node) => {
|
|
85
|
-
if (node.type !== "Identifier")
|
|
86
|
-
|
|
87
|
-
|
|
88
|
+
if (node.type !== "Identifier")
|
|
89
|
+
return;
|
|
90
|
+
if (sameBinding(context, node, key.parameter))
|
|
91
|
+
sourced = true;
|
|
92
|
+
const variable = resolveVariable(context.sourceCode, node);
|
|
88
93
|
for (const definition of variable?.defs ?? []) {
|
|
89
94
|
if (definition.type === "Parameter" && (DELIVERY_ID.test(node.name)
|
|
90
95
|
|| node.parent?.type === "MemberExpression" && node.parent.object === node
|
|
91
|
-
&& DELIVERY_ID.test(node.parent
|
|
92
|
-
|
|
96
|
+
&& DELIVERY_ID.test(String(memberKeyValue(node.parent)))))
|
|
97
|
+
sourced = true;
|
|
98
|
+
if (definition.type === "Variable" && rawKeySource(context, definition.node.init, key, seen))
|
|
99
|
+
sourced = true;
|
|
93
100
|
}
|
|
94
|
-
}, { intoFunctions: false })
|
|
95
|
-
return sourced
|
|
96
|
-
}
|
|
97
|
-
|
|
101
|
+
}, { intoFunctions: false });
|
|
102
|
+
return sourced;
|
|
103
|
+
};
|
|
98
104
|
/** Scalar ids and object ids must actually key the claim; a raw payload itself is never a delivery key. */
|
|
99
105
|
const usesKey = (context, argument, key) => {
|
|
100
|
-
if (!argument)
|
|
106
|
+
if (!argument)
|
|
107
|
+
return false;
|
|
101
108
|
if (key.raw) {
|
|
102
|
-
if (sameBinding(context, argument, key.parameter) || argument.type === "Literal")
|
|
109
|
+
if (sameBinding(context, argument, key.parameter) || argument.type === "Literal")
|
|
110
|
+
return false;
|
|
103
111
|
const name = argument.type === "Identifier" ? argument.name
|
|
104
|
-
: argument.type === "MemberExpression" ? argument
|
|
105
|
-
if (!name || !DELIVERY_ID.test(name))
|
|
106
|
-
|
|
107
|
-
const
|
|
108
|
-
const
|
|
112
|
+
: argument.type === "MemberExpression" ? memberKeyValue(argument) : null;
|
|
113
|
+
if (!name || !DELIVERY_ID.test(String(name)))
|
|
114
|
+
return false;
|
|
115
|
+
const { checker, toTs } = typed(context);
|
|
116
|
+
const type = checker.getTypeAtLocation(toTs(argument));
|
|
117
|
+
const parts = type.isUnion() ? type.types : [type];
|
|
109
118
|
return parts.every((part) => part.flags & ts.TypeFlags.StringLike && !(part.flags & ts.TypeFlags.StringLiteral))
|
|
110
|
-
&& rawKeySource(context, argument, key)
|
|
119
|
+
&& rawKeySource(context, argument, key);
|
|
111
120
|
}
|
|
112
121
|
if (key.parameter.type === "ObjectPattern") {
|
|
113
122
|
return key.parameter.properties.some((property) => property.type === "Property"
|
|
114
|
-
&& key.properties?.
|
|
115
|
-
&& sameBinding(context, argument, parameterOf(property.value)))
|
|
123
|
+
&& key.properties?.some((name) => name === nameOrValue(property.key))
|
|
124
|
+
&& sameBinding(context, argument, parameterOf(property.value)));
|
|
116
125
|
}
|
|
117
|
-
if (!key.properties)
|
|
126
|
+
if (!key.properties)
|
|
127
|
+
return sameBinding(context, argument, key.parameter);
|
|
118
128
|
return argument.type === "MemberExpression" && !argument.optional
|
|
119
129
|
&& sameBinding(context, argument.object, key.parameter)
|
|
120
|
-
&& key.properties.
|
|
121
|
-
}
|
|
122
|
-
|
|
130
|
+
&& key.properties.some((name) => name === memberKeyValue(argument));
|
|
131
|
+
};
|
|
123
132
|
/** Find the first completed await, without treating a nested helper as work performed here. */
|
|
124
133
|
const firstAwait = (body) => {
|
|
125
|
-
let result = null
|
|
134
|
+
let result = null;
|
|
126
135
|
walk(body, (node) => {
|
|
127
|
-
if (node.type === "AwaitExpression" && (!result || node.range[1] < result.range[1]))
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
136
|
+
if (node.type === "AwaitExpression" && (!result || node.range[1] < result.range[1]))
|
|
137
|
+
result = node;
|
|
138
|
+
}, { intoFunctions: false });
|
|
139
|
+
return result;
|
|
140
|
+
};
|
|
132
141
|
/** A parameter's binding cannot be overwritten before the claim and still prove the delivered id. */
|
|
133
142
|
const preservesKey = (context, key, call) => {
|
|
134
|
-
const parameter = key.raw ? call.arguments[1] : key.parameter
|
|
135
|
-
if (parameter
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
143
|
+
const parameter = key.raw ? call.arguments[1] : key.parameter;
|
|
144
|
+
if (parameter?.type !== "Identifier")
|
|
145
|
+
return true;
|
|
146
|
+
const variable = resolveVariable(context.sourceCode, parameter);
|
|
147
|
+
return variable !== null && !variable.references.some((reference) => reference.isWrite() && !reference.init
|
|
148
|
+
&& reference.identifier.range[0] < call.range[1]);
|
|
149
|
+
};
|
|
141
150
|
/** Scalar/DTO claims are the first statement; a raw intake may first bind its decoded key. */
|
|
142
151
|
const claimsBeforeWork = (context, body, statement, key, call) => {
|
|
143
|
-
const index = body.body.
|
|
144
|
-
if (index === 0)
|
|
145
|
-
|
|
146
|
-
|
|
152
|
+
const index = body.body.findIndex((entry) => entry === statement);
|
|
153
|
+
if (index === 0)
|
|
154
|
+
return true;
|
|
155
|
+
if (index < 0 || !key.raw)
|
|
156
|
+
return false;
|
|
157
|
+
const dependencies = new Set();
|
|
147
158
|
const read = (expression) => {
|
|
148
|
-
if (!expression)
|
|
159
|
+
if (!expression)
|
|
160
|
+
return;
|
|
149
161
|
walk(expression, (node) => {
|
|
150
|
-
if (node.type !== "Identifier")
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
dependencies.
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
162
|
+
if (node.type !== "Identifier")
|
|
163
|
+
return;
|
|
164
|
+
const variable = resolveVariable(context.sourceCode, node);
|
|
165
|
+
if (!variable || dependencies.has(variable))
|
|
166
|
+
return;
|
|
167
|
+
dependencies.add(variable);
|
|
168
|
+
for (const definition of variable.defs)
|
|
169
|
+
if (definition.type === "Variable")
|
|
170
|
+
read(definition.node.init);
|
|
171
|
+
}, { intoFunctions: false });
|
|
172
|
+
};
|
|
173
|
+
read(call.arguments[1]);
|
|
158
174
|
return body.body.slice(0, index).every((entry) => entry.type === "VariableDeclaration" && entry.kind === "const"
|
|
159
|
-
&& entry.declarations.every((declaration) => declaration.id.type === "Identifier" && dependencies.has(resolveVariable(context.sourceCode, declaration.id))))
|
|
160
|
-
}
|
|
161
|
-
|
|
175
|
+
&& entry.declarations.every((declaration) => declaration.id.type === "Identifier" && dependencies.has(resolveVariable(context.sourceCode, declaration.id))));
|
|
176
|
+
};
|
|
162
177
|
/** A claim cannot be made conditionally or after another operation in its own statement. */
|
|
163
178
|
const priorWork = (expression, call) => {
|
|
164
|
-
let found = false
|
|
179
|
+
let found = false;
|
|
165
180
|
walk(expression, (node) => {
|
|
166
181
|
if (node !== call && ["CallExpression", "NewExpression", "AssignmentExpression", "UpdateExpression", "ConditionalExpression", "LogicalExpression"].includes(node.type)
|
|
167
|
-
&& node.range[1] < call.range[1])
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
182
|
+
&& node.range[1] < call.range[1])
|
|
183
|
+
found = true;
|
|
184
|
+
}, { intoFunctions: false });
|
|
185
|
+
return found;
|
|
186
|
+
};
|
|
172
187
|
/** Select TypeORM's actual inline transaction callback, never a later ignored callback. */
|
|
173
188
|
const claimBody = (context, body) => {
|
|
174
|
-
if (body.body.length !== 1)
|
|
175
|
-
|
|
189
|
+
if (body.body.length !== 1)
|
|
190
|
+
return { body, manager: null };
|
|
191
|
+
const [statement] = body.body;
|
|
192
|
+
if (!statement)
|
|
193
|
+
return { body, manager: null };
|
|
176
194
|
const expression = statement.type === "ReturnStatement" ? statement.argument
|
|
177
|
-
: statement.type === "ExpressionStatement" && statement.expression.type === "AwaitExpression" ? statement.expression : null
|
|
178
|
-
const call = expression?.type === "AwaitExpression" ? expression.argument : expression
|
|
179
|
-
|
|
180
|
-
|
|
195
|
+
: statement.type === "ExpressionStatement" && statement.expression.type === "AwaitExpression" ? statement.expression : null;
|
|
196
|
+
const call = expression?.type === "AwaitExpression" ? expression.argument : expression;
|
|
197
|
+
if (call?.type !== "CallExpression")
|
|
198
|
+
return { body, manager: null };
|
|
199
|
+
const callee = call.callee;
|
|
200
|
+
if (callee.type !== "MemberExpression" || callee.computed
|
|
181
201
|
|| callee.property.name !== "transaction" || !isPackageType(context, callee.object, "EntityManager", "typeorm")
|
|
182
|
-
|| priorWork(call, call))
|
|
183
|
-
|
|
202
|
+
|| priorWork(call, call))
|
|
203
|
+
return { body, manager: null };
|
|
204
|
+
const first = call.arguments[0];
|
|
184
205
|
const callback = call.arguments.length === 1 ? first
|
|
185
|
-
: call.arguments.length === 2 && first
|
|
186
|
-
&& ["READ UNCOMMITTED", "READ COMMITTED", "REPEATABLE READ", "SERIALIZABLE"].includes(first.value) ? call.arguments[1] : null
|
|
187
|
-
if (!callback ||
|
|
188
|
-
|| !callback.async || callback.body.type !== "BlockStatement" || callback.params.length !== 1)
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
}
|
|
193
|
-
|
|
206
|
+
: call.arguments.length === 2 && first?.type === "Literal" && typeof first.value === "string"
|
|
207
|
+
&& ["READ UNCOMMITTED", "READ COMMITTED", "REPEATABLE READ", "SERIALIZABLE"].includes(first.value) ? call.arguments[1] : null;
|
|
208
|
+
if (!callback || (callback.type !== "ArrowFunctionExpression" && callback.type !== "FunctionExpression")
|
|
209
|
+
|| !callback.async || callback.body.type !== "BlockStatement" || callback.params.length !== 1)
|
|
210
|
+
return { body, manager: null };
|
|
211
|
+
const manager = callback.params[0];
|
|
212
|
+
return manager?.type === "Identifier" && isPackageType(context, manager, "EntityManager", "typeorm")
|
|
213
|
+
? { body: callback.body, manager } : { body, manager: null };
|
|
214
|
+
};
|
|
194
215
|
/** Match an immediate false refusal with no work before the return. */
|
|
195
216
|
const rejectsDuplicate = (context, awaited, body) => {
|
|
196
217
|
const rejects = (test, target) => test?.type === "UnaryExpression" && test.operator === "!" && (test.argument === target || sameBinding(context, test.argument, target))
|
|
197
218
|
|| test?.type === "BinaryExpression" && test.operator === "==="
|
|
198
219
|
&& ((test.left === target && test.right.type === "Literal" && test.right.value === false)
|
|
199
|
-
|| (test.right === target && test.left.type === "Literal" && test.left.value === false))
|
|
220
|
+
|| (test.right === target && test.left.type === "Literal" && test.left.value === false));
|
|
200
221
|
const returns = (statement) => statement?.type === "ReturnStatement" && !statement.argument
|
|
201
|
-
|| statement?.type === "BlockStatement" && statement.body.length === 1 && returns(statement.body[0])
|
|
202
|
-
const parent = awaited.parent
|
|
203
|
-
if (
|
|
204
|
-
const branch = parent.parent
|
|
205
|
-
return body.body.
|
|
222
|
+
|| statement?.type === "BlockStatement" && statement.body.length === 1 && returns(statement.body[0]);
|
|
223
|
+
const parent = awaited.parent;
|
|
224
|
+
if (parent.type === "UnaryExpression" || parent.type === "BinaryExpression") {
|
|
225
|
+
const branch = parent.parent;
|
|
226
|
+
return body.body.some((entry) => entry === branch) && branch.type === "IfStatement" && rejects(branch.test, awaited) && returns(branch.consequent);
|
|
206
227
|
}
|
|
207
|
-
if (parent.type !== "VariableDeclarator" || parent.id.type !== "Identifier" || parent.init !== awaited)
|
|
208
|
-
|
|
209
|
-
const
|
|
210
|
-
const
|
|
228
|
+
if (parent.type !== "VariableDeclarator" || parent.id.type !== "Identifier" || parent.init !== awaited)
|
|
229
|
+
return false;
|
|
230
|
+
const declaration = parent.parent;
|
|
231
|
+
const index = body.body.indexOf(declaration);
|
|
232
|
+
const branch = body.body[index + 1];
|
|
211
233
|
return index !== -1 && declaration.declarations.length === 1
|
|
212
|
-
&& branch?.type === "IfStatement" && rejects(branch.test, parent.id) && returns(branch.consequent)
|
|
213
|
-
}
|
|
214
|
-
|
|
234
|
+
&& branch?.type === "IfStatement" && rejects(branch.test, parent.id) && returns(branch.consequent);
|
|
235
|
+
};
|
|
215
236
|
/** A public service intake with a delivery key claims that same key first and refuses replays. */
|
|
216
237
|
export const webhookInboxKey = {
|
|
217
238
|
meta: {
|
|
@@ -224,26 +245,32 @@ export const webhookInboxKey = {
|
|
|
224
245
|
},
|
|
225
246
|
},
|
|
226
247
|
create(context) {
|
|
227
|
-
const hfs = hfsOf(context)
|
|
228
|
-
const slot = hfs.slotOf(context.filename)
|
|
229
|
-
if (!slot || slot.startsWith("be.tests.") || !baseName(context.filename).endsWith(".service.ts"))
|
|
230
|
-
|
|
248
|
+
const hfs = hfsOf(context);
|
|
249
|
+
const slot = hfs.slotOf(context.filename);
|
|
250
|
+
if (!slot || slot.startsWith("be.tests.") || !baseName(context.filename).endsWith(".service.ts"))
|
|
251
|
+
return {};
|
|
252
|
+
if (slot.startsWith("be.platform") && ["event-bus", "http-security"].includes(ownerNameOf(hfs, context.filename) ?? ""))
|
|
253
|
+
return {};
|
|
231
254
|
return {
|
|
232
255
|
MethodDefinition(method) {
|
|
233
256
|
if (method.kind !== "method" || method.static || method.key.type === "PrivateIdentifier" || !method.value.body
|
|
234
|
-
||
|
|
257
|
+
|| method.accessibility === "private" || method.accessibility === "protected")
|
|
258
|
+
return;
|
|
235
259
|
// A service no webhook door reaches is an ordinary domain service, whatever its first parameter is called.
|
|
236
|
-
if (!isDoorIntake(context, hfs, method))
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
if (
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
const
|
|
260
|
+
if (!isDoorIntake(context, hfs, method))
|
|
261
|
+
return;
|
|
262
|
+
const key = deliveryKey(context, method);
|
|
263
|
+
if (!key)
|
|
264
|
+
return;
|
|
265
|
+
if (webhookIntakeProcessesDelivery(context, hfs, method))
|
|
266
|
+
context.report({ node: method.key, messageId: "handoff" });
|
|
267
|
+
const { body, manager } = claimBody(context, method.value.body);
|
|
268
|
+
const awaited = firstAwait(body);
|
|
269
|
+
const call = awaited?.argument;
|
|
270
|
+
const parent = awaited?.parent;
|
|
244
271
|
const statement = parent?.type === "VariableDeclarator" ? parent.parent
|
|
245
|
-
:
|
|
246
|
-
const claims = call?.type === "CallExpression" && !call.optional
|
|
272
|
+
: parent?.type === "UnaryExpression" || parent?.type === "BinaryExpression" ? parent.parent : parent;
|
|
273
|
+
const claims = awaited !== null && call?.type === "CallExpression" && !call.optional
|
|
247
274
|
&& call.callee.type === "MemberExpression" && !call.callee.computed && !call.callee.optional
|
|
248
275
|
&& call.callee.property.name === "claim" && call.arguments.length >= 2
|
|
249
276
|
&& isOwnedType(context, call.callee.object, { name: "Inbox", capability: "inbox", tier: "platform" })
|
|
@@ -252,9 +279,10 @@ export const webhookInboxKey = {
|
|
|
252
279
|
&& (!manager || sameBinding(context, call.arguments[2], manager))
|
|
253
280
|
&& claimsBeforeWork(context, body, statement, key, call)
|
|
254
281
|
&& !priorWork(statement, call)
|
|
255
|
-
&& rejectsDuplicate(context, awaited, body)
|
|
256
|
-
if (!claims)
|
|
282
|
+
&& rejectsDuplicate(context, awaited, body);
|
|
283
|
+
if (!claims)
|
|
284
|
+
context.report({ node: method.key, messageId: "key" });
|
|
257
285
|
},
|
|
258
|
-
}
|
|
286
|
+
};
|
|
259
287
|
},
|
|
260
|
-
}
|
|
288
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Context, Node } from "./rule.js";
|
|
2
|
+
import type { HfsView } from "./hfs.js";
|
|
3
|
+
/** Inspect the linted intake method or the implementation resolved at a webhook door's domain call. */
|
|
4
|
+
export declare const webhookIntakeProcessesDelivery: (context: Context, hfs: HfsView, node: Node) => boolean;
|