@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.
Files changed (197) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +11 -2
  3. package/dist/ambient-id.d.ts +9 -0
  4. package/{ambient-id.mjs → dist/ambient-id.js} +43 -39
  5. package/dist/app-composition.d.ts +21 -0
  6. package/{app-composition.mjs → dist/app-composition.js} +396 -300
  7. package/dist/async-discipline.d.ts +9 -0
  8. package/dist/async-discipline.js +77 -0
  9. package/dist/authorization.d.ts +12 -0
  10. package/{authorization.mjs → dist/authorization.js} +53 -59
  11. package/dist/boundary-schema.d.ts +15 -0
  12. package/{boundary-schema.mjs → dist/boundary-schema.js} +120 -105
  13. package/dist/builders.d.ts +21 -0
  14. package/{builders.mjs → dist/builders.js} +162 -146
  15. package/dist/cli.d.ts +15 -0
  16. package/{cli.mjs → dist/cli.js} +97 -82
  17. package/dist/comments.d.ts +52 -0
  18. package/dist/comments.js +412 -0
  19. package/dist/config-owner.d.ts +24 -0
  20. package/{config-owner.mjs → dist/config-owner.js} +256 -219
  21. package/dist/connections.d.ts +12 -0
  22. package/{connections.mjs → dist/connections.js} +138 -140
  23. package/dist/cookies.d.ts +9 -0
  24. package/{cookies.mjs → dist/cookies.js} +58 -58
  25. package/dist/cqrs.d.ts +27 -0
  26. package/{cqrs.mjs → dist/cqrs.js} +341 -282
  27. package/dist/data-access.d.ts +50 -0
  28. package/{data-access.mjs → dist/data-access.js} +238 -243
  29. package/dist/default-deny.d.ts +15 -0
  30. package/{default-deny.mjs → dist/default-deny.js} +103 -88
  31. package/dist/e2e-flow.d.ts +25 -0
  32. package/{e2e-flow.mjs → dist/e2e-flow.js} +113 -112
  33. package/dist/edge-hardening.d.ts +10 -0
  34. package/dist/edge-hardening.js +173 -0
  35. package/dist/error-handling.d.ts +21 -0
  36. package/{error-handling.mjs → dist/error-handling.js} +289 -239
  37. package/dist/event-bus.d.ts +14 -0
  38. package/{event-bus.mjs → dist/event-bus.js} +146 -129
  39. package/dist/feature-thin.d.ts +12 -0
  40. package/{feature-thin.mjs → dist/feature-thin.js} +208 -191
  41. package/dist/function-budget.d.ts +7 -0
  42. package/{function-budget.mjs → dist/function-budget.js} +24 -27
  43. package/dist/health-ready.d.ts +10 -0
  44. package/dist/health-ready.js +703 -0
  45. package/dist/idempotency.d.ts +10 -0
  46. package/{idempotency.mjs → dist/idempotency.js} +296 -226
  47. package/dist/index.d.ts +54 -0
  48. package/{index.mjs → dist/index.js} +91 -109
  49. package/dist/infra-owner.d.ts +18 -0
  50. package/{infra-owner.mjs → dist/infra-owner.js} +58 -51
  51. package/dist/injection.d.ts +30 -0
  52. package/{injection.mjs → dist/injection.js} +397 -344
  53. package/dist/input-bounds.d.ts +15 -0
  54. package/{input-bounds.mjs → dist/input-bounds.js} +143 -132
  55. package/dist/jobs.d.ts +17 -0
  56. package/{jobs.mjs → dist/jobs.js} +116 -99
  57. package/dist/jwt-alg.d.ts +6 -0
  58. package/dist/jwt-alg.js +49 -0
  59. package/dist/lib/app-roles.d.ts +25 -0
  60. package/{lib/app-roles.mjs → dist/lib/app-roles.js} +15 -17
  61. package/dist/lib/ast.d.ts +40 -0
  62. package/dist/lib/ast.js +100 -0
  63. package/dist/lib/client-idempotency.d.ts +3 -0
  64. package/{lib/client-idempotency.mjs → dist/lib/client-idempotency.js} +316 -268
  65. package/dist/lib/config.d.ts +36 -0
  66. package/{lib/config.mjs → dist/lib/config.js} +24 -27
  67. package/dist/lib/db-writes.d.ts +29 -0
  68. package/{lib/db-writes.mjs → dist/lib/db-writes.js} +27 -27
  69. package/dist/lib/declared.d.ts +77 -0
  70. package/{lib/declared.mjs → dist/lib/declared.js} +83 -78
  71. package/dist/lib/doors.d.ts +50 -0
  72. package/{lib/doors.mjs → dist/lib/doors.js} +45 -50
  73. package/dist/lib/edition.d.ts +25 -0
  74. package/{lib/edition.mjs → dist/lib/edition.js} +15 -20
  75. package/dist/lib/entity-writes.d.ts +7 -0
  76. package/{lib/entity-writes.mjs → dist/lib/entity-writes.js} +31 -22
  77. package/dist/lib/hfs.d.ts +34 -0
  78. package/{lib/hfs.mjs → dist/lib/hfs.js} +31 -29
  79. package/dist/lib/import-source.d.ts +63 -0
  80. package/dist/lib/import-source.js +134 -0
  81. package/dist/lib/path.d.ts +8 -0
  82. package/{lib/path.mjs → dist/lib/path.js} +4 -7
  83. package/dist/lib/persistence.d.ts +115 -0
  84. package/{lib/persistence.mjs → dist/lib/persistence.js} +55 -66
  85. package/dist/lib/ports.d.ts +70 -0
  86. package/{lib/ports.mjs → dist/lib/ports.js} +62 -66
  87. package/dist/lib/rule.d.ts +31 -0
  88. package/dist/lib/rule.js +2 -0
  89. package/dist/lib/runtime-root.d.ts +4 -0
  90. package/dist/lib/runtime-root.js +10 -0
  91. package/dist/lib/schema-values.d.ts +13 -0
  92. package/{lib/schema-values.mjs → dist/lib/schema-values.js} +67 -59
  93. package/dist/lib/specifier.d.ts +12 -0
  94. package/dist/lib/specifier.js +29 -0
  95. package/dist/lib/subject-values.d.ts +4 -0
  96. package/dist/lib/subject-values.js +61 -0
  97. package/dist/lib/transactions.d.ts +18 -0
  98. package/{lib/transactions.mjs → dist/lib/transactions.js} +17 -15
  99. package/dist/lib/transport-slots.d.ts +17 -0
  100. package/{lib/transport-slots.mjs → dist/lib/transport-slots.js} +2 -4
  101. package/dist/lib/types.d.ts +96 -0
  102. package/dist/lib/types.js +150 -0
  103. package/dist/lib/unit-spec.d.ts +48 -0
  104. package/{lib/unit-spec.mjs → dist/lib/unit-spec.js} +35 -44
  105. package/dist/lib/webhook-ack.d.ts +4 -0
  106. package/{lib/webhook-ack.mjs → dist/lib/webhook-ack.js} +78 -62
  107. package/dist/lib/webhook-handoff-inbox.d.ts +3 -0
  108. package/{lib/webhook-handoff-inbox.mjs → dist/lib/webhook-handoff-inbox.js} +195 -167
  109. package/dist/lib/webhook-handoff-intake.d.ts +4 -0
  110. package/{lib/webhook-handoff-intake.mjs → dist/lib/webhook-handoff-intake.js} +125 -102
  111. package/dist/lib/webhook-handoff.d.ts +15 -0
  112. package/{lib/webhook-handoff.mjs → dist/lib/webhook-handoff.js} +107 -100
  113. package/dist/lib/webhook-verifiers.d.ts +20 -0
  114. package/{lib/webhook-verifiers.mjs → dist/lib/webhook-verifiers.js} +108 -104
  115. package/dist/lib/why.d.ts +9 -0
  116. package/{lib/why.mjs → dist/lib/why.js} +6 -6
  117. package/dist/log-safety.d.ts +20 -0
  118. package/dist/log-safety.js +308 -0
  119. package/dist/module-layering.d.ts +42 -0
  120. package/dist/module-layering.js +257 -0
  121. package/dist/module-shape.d.ts +47 -0
  122. package/{module-shape.mjs → dist/module-shape.js} +278 -236
  123. package/dist/naming.d.ts +49 -0
  124. package/dist/naming.js +246 -0
  125. package/dist/observability.d.ts +25 -0
  126. package/dist/observability.js +245 -0
  127. package/dist/operations.d.ts +23 -0
  128. package/{operations.mjs → dist/operations.js} +410 -332
  129. package/dist/project-graph.d.ts +9 -0
  130. package/{project-graph.mjs → dist/project-graph.js} +8 -13
  131. package/dist/projections.d.ts +11 -0
  132. package/{projections.mjs → dist/projections.js} +60 -57
  133. package/dist/query-safety.d.ts +21 -0
  134. package/{query-safety.mjs → dist/query-safety.js} +92 -108
  135. package/dist/realtime.d.ts +15 -0
  136. package/{realtime.mjs → dist/realtime.js} +108 -106
  137. package/dist/resilience.d.ts +15 -0
  138. package/dist/resilience.js +319 -0
  139. package/dist/schema-authority.d.ts +15 -0
  140. package/{schema-authority.mjs → dist/schema-authority.js} +256 -220
  141. package/dist/service-deps.d.ts +17 -0
  142. package/{service-deps.mjs → dist/service-deps.js} +133 -130
  143. package/dist/service-isolation.d.ts +8 -0
  144. package/dist/service-isolation.js +76 -0
  145. package/dist/size-budget.d.ts +9 -0
  146. package/{size-budget.mjs → dist/size-budget.js} +27 -27
  147. package/dist/sonar-parity.d.ts +5 -0
  148. package/{sonar-parity.mjs → dist/sonar-parity.js} +7 -7
  149. package/dist/spec-no-skip.d.ts +9 -0
  150. package/dist/spec-no-skip.js +81 -0
  151. package/dist/spec-quality.d.ts +10 -0
  152. package/{spec-quality.mjs → dist/spec-quality.js} +103 -87
  153. package/dist/suppression.d.ts +26 -0
  154. package/{suppression.mjs → dist/suppression.js} +30 -45
  155. package/dist/temporal.d.ts +9 -0
  156. package/{temporal.mjs → dist/temporal.js} +75 -65
  157. package/dist/test-world.d.ts +28 -0
  158. package/{test-world.mjs → dist/test-world.js} +102 -83
  159. package/dist/testing.d.ts +51 -0
  160. package/dist/testing.js +368 -0
  161. package/dist/third-party-owner.d.ts +8 -0
  162. package/{third-party-owner.mjs → dist/third-party-owner.js} +105 -91
  163. package/dist/transport.d.ts +24 -0
  164. package/{transport.mjs → dist/transport.js} +279 -240
  165. package/dist/type-safety.d.ts +25 -0
  166. package/dist/type-safety.js +297 -0
  167. package/dist/unit-spec.d.ts +30 -0
  168. package/{unit-spec.mjs → dist/unit-spec.js} +473 -399
  169. package/dist/uploads.d.ts +9 -0
  170. package/{uploads.mjs → dist/uploads.js} +62 -54
  171. package/dist/user-copy.d.ts +9 -0
  172. package/{user-copy.mjs → dist/user-copy.js} +76 -67
  173. package/dist/webhooks.d.ts +16 -0
  174. package/{webhooks.mjs → dist/webhooks.js} +243 -231
  175. package/package.json +17 -8
  176. package/runtime/knowledge/hfs/canon-pins.yaml +22 -14
  177. package/runtime/knowledge/hfs/rules.yaml +23 -0
  178. package/runtime/scripts/lib/package-at.mjs +5 -5
  179. package/async-discipline.mjs +0 -83
  180. package/comments.mjs +0 -416
  181. package/edge-hardening.mjs +0 -139
  182. package/health-ready.mjs +0 -539
  183. package/jwt-alg.mjs +0 -45
  184. package/lib/ast.mjs +0 -88
  185. package/lib/import-source.mjs +0 -104
  186. package/lib/specifier.mjs +0 -27
  187. package/lib/subject-values.mjs +0 -55
  188. package/lib/types.mjs +0 -133
  189. package/log-safety.mjs +0 -303
  190. package/module-layering.mjs +0 -270
  191. package/naming.mjs +0 -251
  192. package/observability.mjs +0 -241
  193. package/resilience.mjs +0 -304
  194. package/service-isolation.mjs +0 -75
  195. package/spec-no-skip.mjs +0 -85
  196. package/testing.mjs +0 -384
  197. package/type-safety.mjs +0 -323
@@ -1,140 +1,163 @@
1
1
  /** R263: a receipt transaction records and publishes; a reactor/job processes after commit. */
2
- import ts from "typescript"
3
- import { baseName, ownerNameOf } from "./ports.mjs"
4
- import { originsOfType, typed } from "./types.mjs"
5
-
2
+ import ts from "typescript";
3
+ import { baseName, ownerNameOf } from "./ports.js";
4
+ import { childNode, originsOfType, resolvedSymbol, typed } from "./types.js";
6
5
  /** Imported aliases and overload signatures retain the implementation's actual body. */
7
6
  const bodiesOf = (checker, call) => {
8
- const expression = call.expression
9
- let name = expression
10
- if (ts.isPropertyAccessExpression(expression)) name = expression.name
11
- if (ts.isElementAccessExpression(expression)) name = expression.argumentExpression
12
- const symbol = checker.getSymbolAtLocation(name)
13
- const target = symbol?.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol
14
- const declarations = [checker.getResolvedSignature(call)?.declaration, ...(target?.getDeclarations() ?? [])]
15
- return [...new Set(declarations.map((declaration) => declaration?.body ?? declaration?.initializer?.body).filter(Boolean))]
16
- }
17
-
7
+ const expression = call.expression;
8
+ let name = expression;
9
+ if (ts.isPropertyAccessExpression(expression))
10
+ name = expression.name;
11
+ if (ts.isElementAccessExpression(expression))
12
+ name = expression.argumentExpression;
13
+ const symbol = checker.getSymbolAtLocation(name);
14
+ const target = resolvedSymbol(checker, symbol);
15
+ const declarations = [checker.getResolvedSignature(call)?.declaration, ...(target?.getDeclarations() ?? [])];
16
+ return [...new Set(declarations.map((declaration) => childNode(declaration, "body") ?? childNode(childNode(declaration, "initializer"), "body")).filter((body) => Boolean(body)))];
17
+ };
18
18
  /** Receiver ownership is established by its declared type, including aliases and inherited ports; `accepts` also sees the type it came from. */
19
19
  const hasOrigin = (checker, receiver, accepts, seen = new Set()) => {
20
- const type = receiver && checker.getTypeAtLocation(receiver)
20
+ const type = receiver && checker.getTypeAtLocation(receiver);
21
21
  const read = (current) => {
22
- if (!current || seen.has(current)) return false
23
- seen.add(current)
24
- if (originsOfType(checker, current).some((origin) => accepts(origin, current))) return true
25
- const parts = current.isUnionOrIntersection() ? current.types : []
26
- const bases = current.isClassOrInterface() ? checker.getBaseTypes(current) ?? [] : []
27
- return [...parts, ...bases].some(read)
28
- }
29
- return read(type)
30
- }
31
-
22
+ if (!current || seen.has(current))
23
+ return false;
24
+ seen.add(current);
25
+ if (originsOfType(checker, current).some((origin) => accepts(origin, current)))
26
+ return true;
27
+ const parts = current.isUnionOrIntersection() ? current.types : [];
28
+ const bases = current.isClassOrInterface() ? checker.getBaseTypes(current) ?? [] : [];
29
+ return [...parts, ...bases].some(read);
30
+ };
31
+ return read(type);
32
+ };
32
33
  /** Bracket access with a literal key has the same meaning as a dotted method/property. */
33
34
  const memberName = (expression) => {
34
- if (ts.isPropertyAccessExpression(expression)) return expression.name.text
35
- if (ts.isElementAccessExpression(expression) && ts.isStringLiteralLike(expression.argumentExpression)) return expression.argumentExpression.text
36
- return null
37
- }
38
-
35
+ if (ts.isPropertyAccessExpression(expression))
36
+ return expression.name.text;
37
+ if (ts.isElementAccessExpression(expression) && ts.isStringLiteralLike(expression.argumentExpression))
38
+ return expression.argumentExpression.text;
39
+ return null;
40
+ };
39
41
  /** A callback named process is the former in-transaction processing contract, including aliases and methods. */
40
42
  const isProcessCallback = (checker, node) => {
41
- if (!(ts.isPropertyAssignment(node) || ts.isShorthandPropertyAssignment(node) || ts.isMethodDeclaration(node))) return false
42
- const name = ts.isComputedPropertyName(node.name) ? node.name.expression : node.name
43
- if (!(ts.isIdentifier(name) || ts.isStringLiteralLike(name)) || name.text !== "process") return false
44
- return !!node.body || checker.getTypeAtLocation(node.initializer ?? node.name).getCallSignatures().length > 0
45
- }
46
-
43
+ if (!(ts.isPropertyAssignment(node) || ts.isShorthandPropertyAssignment(node) || ts.isMethodDeclaration(node)))
44
+ return false;
45
+ const name = ts.isComputedPropertyName(node.name) ? node.name.expression : node.name;
46
+ if (!(ts.isIdentifier(name) || ts.isStringLiteralLike(name)) || name.text !== "process")
47
+ return false;
48
+ return !!childNode(node, "body") || checker.getTypeAtLocation(childNode(node, "initializer") ?? node.name).getCallSignatures().length > 0;
49
+ };
47
50
  /** Persisting receipt data and publishing through platform ports are allowed; domain/CQRS processing is deferred. */
48
51
  const isBusinessOrigin = (hfs, origin) => {
49
- if (origin.module === "@nestjs/cqrs") return ["CommandBus", "QueryBus"].includes(origin.name)
50
- return origin.module === null && hfs.tierOf(origin.file) === "domain" && baseName(origin.file).endsWith(".service.ts")
51
- }
52
-
52
+ if (origin.module === "@nestjs/cqrs")
53
+ return ["CommandBus", "QueryBus"].includes(origin.name);
54
+ return origin.module === null && hfs.tierOf(origin.file) === "domain" && baseName(origin.file).endsWith(".service.ts");
55
+ };
53
56
  /**
54
57
  * A domain receipt port records a delivery and processes nothing: a class with no base class whose constructor takes only platform
55
58
  * ports (and TypeORM), at least one of them the platform `Inbox`. It cannot reach another domain service or the CQRS buses, so a call
56
59
  * on it inside the receipt transaction is the inbox record itself (owner ruling 2026-10-17 "Theo y tro": the owner delegated the decision to main).
57
60
  */
58
61
  const isReceiptPort = (checker, hfs, type) => {
59
- const declaration = type.getSymbol()?.getDeclarations()?.find(ts.isClassDeclaration)
60
- const constructor = declaration && !declaration.heritageClauses ? declaration.members.find(ts.isConstructorDeclaration) : undefined
61
- if (!constructor || constructor.parameters.length === 0) return false
62
- const dependencies = constructor.parameters.map((parameter) => originsOfType(checker, checker.getTypeAtLocation(parameter)))
63
- const isPort = (origin) => origin.module === "typeorm" || (origin.module === null && hfs.tierOf(origin.file) === "platform")
64
- const isInbox = (origin) => origin.module === null && origin.name === "Inbox" && hfs.tierOf(origin.file) === "platform" && ownerNameOf(hfs, origin.file) === "inbox"
65
- return dependencies.every((origins) => origins.length > 0 && origins.every(isPort)) && dependencies.some((origins) => origins.some(isInbox))
66
- }
67
-
62
+ const declaration = type.getSymbol()?.getDeclarations()?.find(ts.isClassDeclaration);
63
+ const constructor = declaration && !declaration.heritageClauses ? declaration.members.find(ts.isConstructorDeclaration) : undefined;
64
+ if (!constructor || constructor.parameters.length === 0)
65
+ return false;
66
+ const dependencies = constructor.parameters.map((parameter) => originsOfType(checker, checker.getTypeAtLocation(parameter)));
67
+ const isPort = (origin) => origin.module === "typeorm" || (origin.module === null && hfs.tierOf(origin.file) === "platform");
68
+ const isInbox = (origin) => origin.module === null && origin.name === "Inbox" && hfs.tierOf(origin.file) === "platform" && ownerNameOf(hfs, origin.file) === "inbox";
69
+ return dependencies.every((origins) => origins.length > 0 && origins.every(isPort)) && dependencies.some((origins) => origins.some(isInbox));
70
+ };
68
71
  /** The transaction port's package establishes when the callback runs before commit. */
69
72
  const isTransactionCall = (checker, call, receiver) => memberName(call.expression) === "transaction"
70
- && hasOrigin(checker, receiver, (origin) => origin.module === "typeorm" && ["EntityManager", "DataSource"].includes(origin.name))
71
-
73
+ && hasOrigin(checker, receiver, (origin) => origin.module === "typeorm" && ["EntityManager", "DataSource"].includes(origin.name));
72
74
  /** Extracting, binding or destructuring a method preserves its domain/bus receiver. */
73
75
  const isBusinessCall = (checker, hfs, expression, seen = new Set()) => {
74
- if (!expression || seen.has(expression)) return false
75
- seen.add(expression)
76
- const accepts = (origin, type) => isBusinessOrigin(hfs, origin) && !isReceiptPort(checker, hfs, type)
77
- if (ts.isParenthesizedExpression(expression) || ts.isAsExpression(expression) || ts.isSatisfiesExpression(expression)) return isBusinessCall(checker, hfs, expression.expression, seen)
76
+ if (!expression || seen.has(expression))
77
+ return false;
78
+ seen.add(expression);
79
+ const accepts = (origin, type) => isBusinessOrigin(hfs, origin) && !isReceiptPort(checker, hfs, type);
80
+ if (ts.isParenthesizedExpression(expression) || ts.isAsExpression(expression) || ts.isSatisfiesExpression(expression))
81
+ return isBusinessCall(checker, hfs, expression.expression, seen);
78
82
  if (ts.isPropertyAccessExpression(expression) || ts.isElementAccessExpression(expression)) {
79
- if (hasOrigin(checker, expression.expression, accepts)) return true
80
- if (["bind", "call", "apply"].includes(memberName(expression))) return isBusinessCall(checker, hfs, expression.expression, seen)
83
+ if (hasOrigin(checker, expression.expression, accepts))
84
+ return true;
85
+ if (["bind", "call", "apply"].includes(memberName(expression) ?? ""))
86
+ return isBusinessCall(checker, hfs, expression.expression, seen);
81
87
  }
82
- if (ts.isCallExpression(expression)) return isBusinessCall(checker, hfs, expression.expression, seen)
88
+ if (ts.isCallExpression(expression))
89
+ return isBusinessCall(checker, hfs, expression.expression, seen);
83
90
  const name = ts.isPropertyAccessExpression(expression) ? expression.name
84
- : ts.isElementAccessExpression(expression) ? expression.argumentExpression : expression
85
- const symbol = checker.getSymbolAtLocation(name)
86
- const target = symbol?.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol
91
+ : ts.isElementAccessExpression(expression) ? expression.argumentExpression : expression;
92
+ const symbol = checker.getSymbolAtLocation(name);
93
+ const target = resolvedSymbol(checker, symbol);
87
94
  return target?.getDeclarations()?.some((declaration) => {
88
- if (ts.isBindingElement(declaration)) return hasOrigin(checker, declaration.parent.parent.initializer, accepts)
89
- return isBusinessCall(checker, hfs, declaration.initializer, seen)
90
- }) ?? false
91
- }
92
-
95
+ if (ts.isBindingElement(declaration))
96
+ return hasOrigin(checker, childNode(declaration.parent.parent, "initializer"), accepts);
97
+ return isBusinessCall(checker, hfs, childNode(declaration, "initializer"), seen);
98
+ }) ?? false;
99
+ };
93
100
  /** Passing a const callback into transaction does not move its work past commit. */
94
101
  const callbackBodies = (checker, expression, seen = new Set()) => {
95
- if (!expression || seen.has(expression)) return []
96
- seen.add(expression)
97
- if (expression.body) return [expression.body]
98
- if (ts.isAsExpression(expression) || ts.isSatisfiesExpression(expression) || ts.isParenthesizedExpression(expression)) return callbackBodies(checker, expression.expression, seen)
99
- if (ts.isCallExpression(expression) && memberName(expression.expression) === "bind") return callbackBodies(checker, expression.expression.expression, seen)
100
- const reference = ts.isPropertyAccessExpression(expression) ? expression.name : expression
101
- const symbol = checker.getSymbolAtLocation(reference)
102
- return symbol?.getDeclarations()?.flatMap((declaration) => declaration.body ? [declaration.body] : callbackBodies(checker, declaration.initializer, seen)) ?? []
103
- }
104
-
102
+ if (!expression || seen.has(expression))
103
+ return [];
104
+ seen.add(expression);
105
+ const body = childNode(expression, "body");
106
+ if (body)
107
+ return [body];
108
+ if (ts.isAsExpression(expression) || ts.isSatisfiesExpression(expression) || ts.isParenthesizedExpression(expression))
109
+ return callbackBodies(checker, expression.expression, seen);
110
+ if (ts.isCallExpression(expression) && memberName(expression.expression) === "bind")
111
+ return callbackBodies(checker, childNode(expression.expression, "expression"), seen);
112
+ const reference = ts.isPropertyAccessExpression(expression) ? expression.name : expression;
113
+ const symbol = checker.getSymbolAtLocation(reference);
114
+ return symbol?.getDeclarations()?.flatMap((declaration) => {
115
+ const declared = childNode(declaration, "body");
116
+ return declared ? [declared] : callbackBodies(checker, childNode(declaration, "initializer"), seen);
117
+ }) ?? [];
118
+ };
105
119
  /** Old inline process callbacks and business dispatch inside the receipt transaction violate handoff. */
106
120
  const processesDelivery = (checker, hfs, body) => {
107
- let found = false
108
- const visited = [new Set(), new Set()]
121
+ let found = false;
122
+ const outside = new Set();
123
+ const inside = new Set();
109
124
  const visit = (node, inTransaction = false) => {
110
- const nodes = visited[Number(inTransaction)]
111
- if (found || nodes.has(node)) return
112
- nodes.add(node)
113
- if (isProcessCallback(checker, node)) found = true
125
+ const nodes = inTransaction ? inside : outside;
126
+ if (found || nodes.has(node))
127
+ return;
128
+ nodes.add(node);
129
+ if (isProcessCallback(checker, node))
130
+ found = true;
114
131
  if (ts.isCallExpression(node)) {
115
- if (inTransaction && isBusinessCall(checker, hfs, node.expression)) found = true
116
- const member = ts.isPropertyAccessExpression(node.expression) || ts.isElementAccessExpression(node.expression)
117
- if (member && isTransactionCall(checker, node, node.expression.expression)) {
132
+ if (inTransaction && isBusinessCall(checker, hfs, node.expression))
133
+ found = true;
134
+ const callee = node.expression;
135
+ if ((ts.isPropertyAccessExpression(callee) || ts.isElementAccessExpression(callee)) && isTransactionCall(checker, node, callee.expression)) {
118
136
  for (const argument of node.arguments) {
119
- visit(argument, true)
120
- for (const callback of callbackBodies(checker, argument)) visit(callback, true)
137
+ visit(argument, true);
138
+ for (const callback of callbackBodies(checker, argument))
139
+ visit(callback, true);
121
140
  }
122
- return
141
+ return;
123
142
  }
124
- if (inTransaction) for (const callback of callbackBodies(checker, node.expression)) visit(callback, true)
143
+ if (inTransaction)
144
+ for (const callback of callbackBodies(checker, node.expression))
145
+ visit(callback, true);
125
146
  }
126
- ts.forEachChild(node, (child) => visit(child, inTransaction))
127
- }
128
- visit(body)
129
- return found
130
- }
131
-
147
+ ts.forEachChild(node, (child) => visit(child, inTransaction));
148
+ };
149
+ visit(body);
150
+ return found;
151
+ };
132
152
  /** Inspect the linted intake method or the implementation resolved at a webhook door's domain call. */
133
153
  export const webhookIntakeProcessesDelivery = (context, hfs, node) => {
134
- const { checker, toTs } = typed(context)
135
- const reference = toTs(node)
136
- if (!reference) return false
137
- let bodies = reference.body ? [reference.body] : []
138
- if (ts.isCallExpression(reference)) bodies = [reference, ...bodiesOf(checker, reference)]
139
- return bodies.some((body) => processesDelivery(checker, hfs, body))
140
- }
154
+ const { checker, toTs } = typed(context);
155
+ const reference = toTs(node);
156
+ if (!reference)
157
+ return false;
158
+ const own = childNode(reference, "body");
159
+ let bodies = own ? [own] : [];
160
+ if (ts.isCallExpression(reference))
161
+ bodies = [reference, ...bodiesOf(checker, reference)];
162
+ return bodies.some((body) => processesDelivery(checker, hfs, body));
163
+ };
@@ -0,0 +1,15 @@
1
+ import type { TSESTree } from "@typescript-eslint/utils";
2
+ import type { Context, Node } from "./rule.js";
3
+ import type { HfsView } from "./hfs.js";
4
+ /** A bus or feature handler receiver is never a webhook's delegating call. */
5
+ export declare const isWebhookForbiddenReceiver: (context: Context, hfs: HfsView, node: Node) => boolean;
6
+ /**
7
+ * Forbidden import sites in a door or its declaring HTTP module. Named, type-only, namespace, dynamic and re-exported
8
+ * imports all resolve to the actual export; an inline import type is judged by its resolved type.
9
+ */
10
+ export declare const webhookForbiddenReferences: (context: Context, hfs: HfsView, program: TSESTree.Program) => Node[];
11
+ /**
12
+ * Inspect a resolved domain intake's own body, closures included. Dynamic receivers, erased types, external signatures and
13
+ * calls through further helpers remain semantic review: this check does not prove the full inbox/outbox transaction.
14
+ */
15
+ export declare const webhookIntakeDispatchesCommand: (context: Context, hfs: HfsView, call: Node) => boolean;
@@ -1,138 +1,145 @@
1
1
  /** Typed webhook handoff checks: the HTTP door records a delivery; only a later consumer dispatches commands. */
2
- import ts from "typescript"
3
- import { walk } from "./ast.mjs"
4
- import { injectedMembers } from "./doors.mjs"
5
- import { moduleReferences } from "./import-source.mjs"
6
- import { baseName } from "./ports.mjs"
7
- import { moduleOf, originsOfType, typed } from "./types.mjs"
8
-
9
- const CQRS = "@nestjs/cqrs"
10
- const BUSES = new Set(["CommandBus", "QueryBus"])
11
-
2
+ import ts from "typescript";
3
+ import { walk } from "./ast.js";
4
+ import { injectedMembers } from "./doors.js";
5
+ import { moduleReferences, visitModuleReference } from "./import-source.js";
6
+ import { baseName } from "./ports.js";
7
+ import { childNode, moduleOf, originsOfType, resolvedSymbol, typed } from "./types.js";
8
+ const CQRS = "@nestjs/cqrs";
9
+ const BUSES = new Set(["CommandBus", "QueryBus"]);
12
10
  /** A feature handler has a feature owner and the closed handler role, regardless of its imported alias. */
13
- const isFeatureHandler = (hfs, file) => hfs.tierOf(file) === "feature" && baseName(file).endsWith(".handler.ts")
14
-
11
+ const isFeatureHandler = (hfs, file) => hfs.tierOf(file) === "feature" && baseName(file).endsWith(".handler.ts");
15
12
  /** The bus's package and declared name, or the feature handler's declaring file, establish the forbidden origin. */
16
- const forbiddenOrigin = (hfs, origin, buses) =>
17
- (origin.module === CQRS && buses.has(origin.name)) || isFeatureHandler(hfs, origin.file)
18
-
13
+ const forbiddenOrigin = (hfs, origin, buses) => (origin.module === CQRS && buses.has(origin.name)) || isFeatureHandler(hfs, origin.file);
19
14
  /** Include unions, intersections and class inheritance, so an alias or a subclass cannot conceal the bus. */
20
15
  const hasForbiddenType = (checker, hfs, type, buses = BUSES, seen = new Set()) => {
21
- if (!type || seen.has(type)) return false
22
- seen.add(type)
23
- if (originsOfType(checker, type).some((origin) => forbiddenOrigin(hfs, origin, buses))) return true
24
- const parts = type.isUnionOrIntersection() ? type.types : []
25
- const bases = type.isClassOrInterface() ? checker.getBaseTypes(type) ?? [] : []
26
- return [...parts, ...bases].some((part) => hasForbiddenType(checker, hfs, part, buses, seen))
27
- }
28
-
16
+ if (!type || seen.has(type))
17
+ return false;
18
+ seen.add(type);
19
+ if (originsOfType(checker, type).some((origin) => forbiddenOrigin(hfs, origin, buses)))
20
+ return true;
21
+ const parts = type.isUnionOrIntersection() ? type.types : [];
22
+ const bases = type.isClassOrInterface() ? checker.getBaseTypes(type) ?? [] : [];
23
+ return [...parts, ...bases].some((part) => hasForbiddenType(checker, hfs, part, buses, seen));
24
+ };
29
25
  /** A bus or feature handler receiver is never a webhook's delegating call. */
30
26
  export const isWebhookForbiddenReceiver = (context, hfs, node) => {
31
- const { checker, toTs } = typed(context)
32
- const reference = toTs(node)
33
- return reference ? hasForbiddenType(checker, hfs, checker.getTypeAtLocation(reference)) : false
34
- }
35
-
27
+ const { checker, toTs } = typed(context);
28
+ const reference = toTs(node);
29
+ return reference ? hasForbiddenType(checker, hfs, checker.getTypeAtLocation(reference)) : false;
30
+ };
36
31
  /** Resolve an imported/exported alias once before inspecting the actual declaration. */
37
- const targetOf = (checker, symbol) => symbol?.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol
38
-
32
+ const targetOf = (checker, symbol) => resolvedSymbol(checker, symbol);
39
33
  /** A module export's origin, including a bus subclass or an alias of its type. */
40
34
  const forbiddenExport = (checker, hfs, original) => {
41
- const symbol = targetOf(checker, original)
42
- if (!symbol) return false
43
- const declarations = symbol.getDeclarations() ?? []
35
+ const symbol = targetOf(checker, original);
36
+ if (!symbol)
37
+ return false;
38
+ const declarations = symbol.getDeclarations() ?? [];
44
39
  if (declarations.some((declaration) => {
45
- const file = declaration.getSourceFile().fileName.replace(/\\/g, "/")
46
- return isFeatureHandler(hfs, file) || (moduleOf(declaration, file) === CQRS && BUSES.has(symbol.getName()))
47
- })) return true
48
- if (declarations.length === 0) return false
49
- const type = checker.getTypeOfSymbolAtLocation(symbol, declarations[0])
50
- if (hasForbiddenType(checker, hfs, type)) return true
40
+ const file = declaration.getSourceFile().fileName.replace(/\\/g, "/");
41
+ return isFeatureHandler(hfs, file) || (moduleOf(declaration, file) === CQRS && BUSES.has(symbol.getName()));
42
+ }))
43
+ return true;
44
+ const [first] = declarations;
45
+ if (first === undefined)
46
+ return false;
47
+ const type = checker.getTypeOfSymbolAtLocation(symbol, first);
48
+ if (hasForbiddenType(checker, hfs, type))
49
+ return true;
51
50
  return !!(symbol.flags & (ts.SymbolFlags.Class | ts.SymbolFlags.Interface | ts.SymbolFlags.TypeAlias))
52
- && hasForbiddenType(checker, hfs, checker.getDeclaredTypeOfSymbol(symbol))
53
- }
54
-
51
+ && hasForbiddenType(checker, hfs, checker.getDeclaredTypeOfSymbol(symbol));
52
+ };
55
53
  /** Inspect selected exports of the referenced module, so barrels and renamed imports keep their real owner. */
56
54
  const forbiddenModuleReference = (checker, toTs, hfs, reference) => {
57
- const { source, value, names } = reference
58
- if (value === CQRS && names.some((name) => BUSES.has(name) || name === "*" || name === "default")) return true
59
- const sourceNode = toTs(source)
60
- const module = sourceNode ? targetOf(checker, checker.getSymbolAtLocation(sourceNode)) : null
61
- if (!module) return false
62
- const exports = checker.getExportsOfModule(module)
63
- const wholeModule = names.includes("*") || (names.includes("default") && !exports.some((symbol) => symbol.getName() === "default"))
64
- return exports.some((symbol) => (wholeModule || names.includes(symbol.getName())) && forbiddenExport(checker, hfs, symbol))
65
- }
66
-
55
+ const { source, value, names } = reference;
56
+ if (value === CQRS && names.some((name) => BUSES.has(name ?? "") || name === "*" || name === "default"))
57
+ return true;
58
+ const sourceNode = toTs(source);
59
+ const module = sourceNode ? targetOf(checker, checker.getSymbolAtLocation(sourceNode)) : null;
60
+ if (!module)
61
+ return false;
62
+ const exports = checker.getExportsOfModule(module);
63
+ const wholeModule = names.includes("*") || (names.includes("default") && !exports.some((symbol) => symbol.getName() === "default"));
64
+ return exports.some((symbol) => (wholeModule || names.includes(symbol.getName())) && forbiddenExport(checker, hfs, symbol));
65
+ };
67
66
  /**
68
67
  * Forbidden import sites in a door or its declaring HTTP module. Named, type-only, namespace, dynamic and re-exported
69
68
  * imports all resolve to the actual export; an inline import type is judged by its resolved type.
70
69
  */
71
70
  export const webhookForbiddenReferences = (context, hfs, program) => {
72
- const { checker, toTs } = typed(context)
73
- const nodes = new Set()
71
+ const { checker, toTs } = typed(context);
72
+ const nodes = new Set();
74
73
  const visitors = moduleReferences((reference) => {
75
- if (forbiddenModuleReference(checker, toTs, hfs, reference)) nodes.add(reference.node)
76
- })
74
+ if (forbiddenModuleReference(checker, toTs, hfs, reference))
75
+ nodes.add(reference.node);
76
+ });
77
77
  walk(program, (node) => {
78
- visitors[node.type]?.(node)
79
- if (node.type !== "TSImportType") return
80
- const typeNode = toTs(node)
81
- if (typeNode && hasForbiddenType(checker, hfs, checker.getTypeAtLocation(typeNode))) nodes.add(node)
82
- })
78
+ visitModuleReference(visitors, node);
79
+ if (node.type !== "TSImportType")
80
+ return;
81
+ const typeNode = toTs(node);
82
+ if (typeNode && hasForbiddenType(checker, hfs, checker.getTypeAtLocation(typeNode)))
83
+ nodes.add(node);
84
+ });
83
85
  // An ambiently supplied type still cannot be injected; an import finding already refuses the same dependency.
84
- if (nodes.size === 0) walk(program, (node) => {
85
- if (node.type !== "ClassDeclaration") return
86
- for (const member of injectedMembers(context, node)) {
87
- if (member.annotation && isWebhookForbiddenReceiver(context, hfs, member.annotation)) nodes.add(member.node)
88
- }
89
- })
90
- return [...nodes]
91
- }
92
-
86
+ if (nodes.size === 0)
87
+ walk(program, (node) => {
88
+ if (node.type !== "ClassDeclaration")
89
+ return;
90
+ for (const member of injectedMembers(context, node)) {
91
+ if (member.annotation && isWebhookForbiddenReceiver(context, hfs, member.annotation))
92
+ nodes.add(member.node);
93
+ }
94
+ });
95
+ return [...nodes];
96
+ };
93
97
  /** The symbol of a called member, including a statically resolved bracket access. */
94
98
  const calledSymbol = (checker, expression) => {
95
- if (ts.isPropertyAccessExpression(expression)) return targetOf(checker, checker.getSymbolAtLocation(expression.name))
96
- if (ts.isElementAccessExpression(expression)) return targetOf(checker, checker.getSymbolAtLocation(expression.argumentExpression))
97
- return targetOf(checker, checker.getSymbolAtLocation(expression))
98
- }
99
-
99
+ if (ts.isPropertyAccessExpression(expression))
100
+ return targetOf(checker, checker.getSymbolAtLocation(expression.name));
101
+ if (ts.isElementAccessExpression(expression))
102
+ return targetOf(checker, checker.getSymbolAtLocation(expression.argumentExpression));
103
+ return targetOf(checker, checker.getSymbolAtLocation(expression));
104
+ };
100
105
  /** Overload declarations point back to their implementation; arrow-valued service members also carry a body. */
101
106
  const bodyOf = (declaration) => {
102
- if (declaration?.body) return declaration.body
103
- const initializer = declaration?.initializer
104
- return initializer && (ts.isArrowFunction(initializer) || ts.isFunctionExpression(initializer)) ? initializer.body : null
105
- }
106
-
107
+ const body = childNode(declaration, "body");
108
+ if (body)
109
+ return body;
110
+ const initializer = childNode(declaration, "initializer");
111
+ return initializer && (ts.isArrowFunction(initializer) || ts.isFunctionExpression(initializer)) ? initializer.body : null;
112
+ };
107
113
  /** Bodies the checker actually resolves at the intake call, never every other method of the service. */
108
114
  const calledBodies = (checker, call) => {
109
- const signature = checker.getResolvedSignature(call)?.declaration
110
- const declarations = calledSymbol(checker, call.expression)?.getDeclarations() ?? []
111
- return [...new Set([signature, ...declarations].map(bodyOf).filter(Boolean))]
112
- }
113
-
115
+ const signature = checker.getResolvedSignature(call)?.declaration;
116
+ const declarations = calledSymbol(checker, call.expression)?.getDeclarations() ?? [];
117
+ return [...new Set([signature, ...declarations].map((declaration) => bodyOf(declaration)).filter((body) => Boolean(body)))];
118
+ };
114
119
  /** A method body dispatches on a CQRS bus or feature handler when the receiver's genuine declared type proves it. */
115
120
  const dispatchesCommand = (checker, hfs, body) => {
116
- let found = false
121
+ let found = false;
117
122
  const visit = (node) => {
118
- if (found) return
123
+ if (found)
124
+ return;
119
125
  if (ts.isCallExpression(node) && (ts.isPropertyAccessExpression(node.expression) || ts.isElementAccessExpression(node.expression))) {
120
- const type = checker.getTypeAtLocation(node.expression.expression)
121
- if (hasForbiddenType(checker, hfs, type)) found = true
126
+ const type = checker.getTypeAtLocation(node.expression.expression);
127
+ if (hasForbiddenType(checker, hfs, type))
128
+ found = true;
122
129
  }
123
- ts.forEachChild(node, visit)
124
- }
125
- visit(body)
126
- return found
127
- }
128
-
130
+ ts.forEachChild(node, visit);
131
+ };
132
+ visit(body);
133
+ return found;
134
+ };
129
135
  /**
130
136
  * Inspect a resolved domain intake's own body, closures included. Dynamic receivers, erased types, external signatures and
131
137
  * calls through further helpers remain semantic review: this check does not prove the full inbox/outbox transaction.
132
138
  */
133
139
  export const webhookIntakeDispatchesCommand = (context, hfs, call) => {
134
- const { checker, toTs } = typed(context)
135
- const reference = toTs(call)
136
- if (!reference || !ts.isCallExpression(reference)) return false
137
- return calledBodies(checker, reference).some((body) => dispatchesCommand(checker, hfs, body))
138
- }
140
+ const { checker, toTs } = typed(context);
141
+ const reference = toTs(call);
142
+ if (!reference || !ts.isCallExpression(reference))
143
+ return false;
144
+ return calledBodies(checker, reference).some((body) => dispatchesCommand(checker, hfs, body));
145
+ };
@@ -0,0 +1,20 @@
1
+ import type { TSESTree } from "@typescript-eslint/utils";
2
+ import type { Context, Node } from "./rule.js";
3
+ import type { HfsView } from "./hfs.js";
4
+ /** A webhook challenge handler's first statements: the verification call, the bound result and the echoing return. */
5
+ export interface WebhookChallenge {
6
+ readonly call: TSESTree.CallExpression;
7
+ readonly result: TSESTree.Identifier | null;
8
+ readonly echo: TSESTree.Statement | undefined;
9
+ readonly statements: TSESTree.Statement[];
10
+ }
11
+ /** The shared platform proof, identified by its declared owner. */
12
+ export declare const isWebhookSignatureType: (context: Context, node: Node) => boolean;
13
+ /** A service declared by a domain owner, rather than a similarly named local or package type. */
14
+ export declare const isWebhookDomainServiceType: (context: Context, hfs: HfsView, node: Node) => boolean;
15
+ /** POST's first statement remains the proof itself, before the intake or acknowledgement. */
16
+ export declare const firstWebhookVerification: (context: Context, hfs: HfsView, method: TSESTree.MethodDefinition) => TSESTree.CallExpression | null;
17
+ /** The optional GET proves once, binding its result with const or returning the verifier call directly. */
18
+ export declare const firstWebhookChallenge: (context: Context, hfs: HfsView, method: TSESTree.MethodDefinition) => WebhookChallenge | null;
19
+ /** The GET echoes only the original proof's value, with no intervening work or transformation. */
20
+ export declare const isWebhookChallengeReturn: (context: Context, node: Node, challenge: WebhookChallenge | null | undefined) => boolean;