@starci/eslint-canon-be 3.5.0 → 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 (195) hide show
  1. package/CHANGELOG.md +15 -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 +17 -10
  177. package/async-discipline.mjs +0 -83
  178. package/comments.mjs +0 -416
  179. package/edge-hardening.mjs +0 -139
  180. package/health-ready.mjs +0 -539
  181. package/jwt-alg.mjs +0 -45
  182. package/lib/ast.mjs +0 -88
  183. package/lib/import-source.mjs +0 -104
  184. package/lib/specifier.mjs +0 -27
  185. package/lib/subject-values.mjs +0 -55
  186. package/lib/types.mjs +0 -133
  187. package/log-safety.mjs +0 -303
  188. package/module-layering.mjs +0 -270
  189. package/naming.mjs +0 -251
  190. package/observability.mjs +0 -241
  191. package/resilience.mjs +0 -304
  192. package/service-isolation.mjs +0 -75
  193. package/spec-no-skip.mjs +0 -85
  194. package/testing.mjs +0 -384
  195. package/type-safety.mjs +0 -323
@@ -11,39 +11,37 @@
11
11
  * name (`lib/types.mjs`); a spec is recognised by its file name (`*.e2e-spec.ts`), which is part of the slot
12
12
  * vocabulary.
13
13
  */
14
- import { basename } from "node:path"
15
- import ts from "typescript"
16
- import { hfsOf, inTestWorld } from "./lib/hfs.mjs"
17
- import { isPackageType, typeOrigins, typed } from "./lib/types.mjs"
18
-
14
+ import { basename } from "node:path";
15
+ import ts from "typescript";
16
+ import { hfsOf, inTestWorld } from "./lib/hfs.js";
17
+ import { isPackageType, typeOrigins, typed } from "./lib/types.js";
19
18
  /** Files this law governs. A flow is a named lane, not every file that happens to touch a database. */
20
- const isE2eSpec = (filename) => /\.e2e-spec\.ts$/.test(basename(String(filename || "").replace(/\\/g, "/")))
21
-
19
+ const isE2eSpec = (filename) => /\.e2e-spec\.ts$/.test(basename(String(filename || "").replace(/\\/g, "/")));
22
20
  /** The in-process dispatchers of `@nestjs/cqrs`: a flow enters through transport, not through them. */
23
- const BUS_TYPES = ["CommandBus", "QueryBus", "EventBus"]
24
-
21
+ const BUS_TYPES = ["CommandBus", "QueryBus", "EventBus"];
25
22
  /** The role suffixes of the actors a flow never invokes itself: a handler, a consumer, a job. */
26
- const ACTOR_FILE = /\.(?:handler|consumer|job)\.ts$/
27
-
23
+ const ACTOR_FILE = /\.(?:handler|consumer|job)\.ts$/;
28
24
  /**
29
25
  * What a name in scope is: `{ global: true }` when nothing in the file declares it, `{ source, imported }` when it is an
30
26
  * import binding, else null (a local declaration).
31
27
  */
32
28
  const bindingOf = (context, node, name) => {
33
- let scope = (context.sourceCode || context.getSourceCode()).getScope(node)
29
+ let scope = (context.sourceCode || context.getSourceCode()).getScope(node);
34
30
  while (scope) {
35
- const variable = scope.set.get(name)
31
+ const variable = scope.set.get(name);
36
32
  if (variable) {
37
- if (variable.defs.length === 0) return { global: true }
38
- const definition = variable.defs[0]
39
- if (definition.type !== "ImportBinding" || definition.node.type !== "ImportSpecifier") return null
40
- return { source: definition.parent.source.value, imported: definition.node.imported.name ?? definition.node.imported.value }
33
+ if (variable.defs.length === 0)
34
+ return { global: true };
35
+ const definition = variable.defs[0];
36
+ if (!definition || definition.type !== "ImportBinding" || definition.node.type !== "ImportSpecifier" || definition.parent?.type !== "ImportDeclaration")
37
+ return null;
38
+ const imported = definition.node.imported;
39
+ return { source: definition.parent.source.value, imported: imported.type === "Identifier" ? imported.name : imported.value };
41
40
  }
42
- scope = scope.upper
41
+ scope = scope.upper;
43
42
  }
44
- return { global: true }
45
- }
46
-
43
+ return { global: true };
44
+ };
47
45
  /** E2E enters through production transport and never invokes an internal actor directly. */
48
46
  export const e2eUsesProductionTransport = {
49
47
  meta: {
@@ -57,50 +55,57 @@ export const e2eUsesProductionTransport = {
57
55
  },
58
56
  },
59
57
  create(context) {
60
- if (!isE2eSpec(context.filename || context.getFilename())) return {}
58
+ if (!isE2eSpec(context.filename || context.getFilename()))
59
+ return {};
61
60
  return {
62
61
  ImportDeclaration(node) {
63
- if (node.source.value !== "@nestjs/cqrs") return
62
+ if (node.source.value !== "@nestjs/cqrs")
63
+ return;
64
64
  for (const specifier of node.specifiers) {
65
- if (specifier.type !== "ImportSpecifier") continue
66
- const imported = specifier.imported.name || specifier.imported.value
67
- if (BUS_TYPES.includes(imported)) context.report({ node: specifier, messageId: "busImport", data: { name: imported } })
65
+ if (specifier.type !== "ImportSpecifier")
66
+ continue;
67
+ const imported = specifier.imported.type === "Identifier" ? specifier.imported.name : specifier.imported.value;
68
+ if (BUS_TYPES.includes(imported))
69
+ context.report({ node: specifier, messageId: "busImport", data: { name: imported } });
68
70
  }
69
71
  },
70
72
  CallExpression(node) {
71
- const callee = node.callee
72
- if (callee.type !== "MemberExpression" || callee.computed || callee.property.type !== "Identifier") return
73
- const method = callee.property.name
74
- const bus = BUS_TYPES.find((name) => isPackageType(context, callee.object, name, "@nestjs/cqrs"))
73
+ const callee = node.callee;
74
+ if (callee.type !== "MemberExpression" || callee.computed || callee.property.type !== "Identifier")
75
+ return;
76
+ const method = callee.property.name;
77
+ const bus = BUS_TYPES.find((name) => isPackageType(context, callee.object, name, "@nestjs/cqrs"));
75
78
  if (bus) {
76
- context.report({ node: callee.property, messageId: "direct", data: { method, name: bus } })
77
- return
79
+ context.report({ node: callee.property, messageId: "direct", data: { method, name: bus } });
80
+ return;
78
81
  }
79
- const actor = typeOrigins(context, callee.object).find((origin) => ACTOR_FILE.test(origin.file))
80
- if (actor) context.report({ node: callee.property, messageId: "actor", data: { method, name: actor.name, file: basename(actor.file) } })
82
+ const actor = typeOrigins(context, callee.object).find((origin) => ACTOR_FILE.test(origin.file));
83
+ if (actor)
84
+ context.report({ node: callee.property, messageId: "actor", data: { method, name: actor.name, file: basename(actor.file) } });
81
85
  },
82
- }
86
+ };
83
87
  },
84
- }
85
-
88
+ };
86
89
  // -- E2E-3 ----------------------------------------------------------------------------------------
87
-
88
90
  /** The modules whose `setTimeout`/`setInterval` are timers. */
89
- const TIMER_MODULES = ["timers", "node:timers", "timers/promises", "node:timers/promises"]
90
-
91
+ const TIMER_MODULES = ["timers", "node:timers", "timers/promises", "node:timers/promises"];
91
92
  /** Whether a call awaits a fixed duration: a global or imported timer, or a `Promise<void>` call given one number. */
92
93
  const waitsForDuration = (context, node) => {
93
- const callee = node.callee
94
- const binding = callee.type === "Identifier" ? bindingOf(context, node, callee.name) : null
95
- if (binding?.global && (callee.name === "setTimeout" || callee.name === "setInterval")) return true
96
- if (binding?.source && TIMER_MODULES.includes(binding.source) && (binding.imported === "setTimeout" || binding.imported === "setInterval")) return true
97
- if (node.arguments.length !== 1 || node.arguments[0].type === "SpreadElement") return false
98
- const { checker, toTs } = typed(context)
99
- const argument = checker.getTypeAtLocation(toTs(node.arguments[0]))
100
- if (!(argument.flags & (ts.TypeFlags.Number | ts.TypeFlags.NumberLiteral))) return false
101
- return checker.typeToString(checker.getTypeAtLocation(toTs(node))) === "Promise<void>"
102
- }
103
-
94
+ const callee = node.callee;
95
+ const binding = callee.type === "Identifier" ? bindingOf(context, node, callee.name) : null;
96
+ if (binding?.global && callee.type === "Identifier" && (callee.name === "setTimeout" || callee.name === "setInterval"))
97
+ return true;
98
+ if (binding?.source && TIMER_MODULES.includes(binding.source) && (binding.imported === "setTimeout" || binding.imported === "setInterval"))
99
+ return true;
100
+ const [first] = node.arguments;
101
+ if (node.arguments.length !== 1 || !first || first.type === "SpreadElement")
102
+ return false;
103
+ const { checker, toTs } = typed(context);
104
+ const argument = checker.getTypeAtLocation(toTs(first));
105
+ if (!(argument.flags & (ts.TypeFlags.Number | ts.TypeFlags.NumberLiteral)))
106
+ return false;
107
+ return checker.typeToString(checker.getTypeAtLocation(toTs(node))) === "Promise<void>";
108
+ };
104
109
  /** A flow polls until the state settles; it never waits for a duration. */
105
110
  export const noSleepInFlow = {
106
111
  meta: {
@@ -108,41 +113,40 @@ export const noSleepInFlow = {
108
113
  docs: { description: "A flow polls for the state it needs, with a deadline. It never sleeps." },
109
114
  schema: [],
110
115
  messages: {
111
- sleep:
112
- "This call waits for a DURATION, and a duration is a guess about somebody else's machine. It is too long on the machine that passes - every run pays it - and too short on the one that matters, where it fails as a flake nobody can reproduce. Poll for the state you are actually waiting for with `waitFor`, which carries a deadline, so the test says what it wanted rather than how long it was willing to sit there.",
113
- timer:
114
- "A promise around `setTimeout` is a sleep with the name taken off. The objection is the same: nothing here says which state the flow is waiting for, so the failure message when it expires names a timeout instead of the thing that never happened. Poll the state with `waitFor`.",
116
+ sleep: "This call waits for a DURATION, and a duration is a guess about somebody else's machine. It is too long on the machine that passes - every run pays it - and too short on the one that matters, where it fails as a flake nobody can reproduce. Poll for the state you are actually waiting for with `waitFor`, which carries a deadline, so the test says what it wanted rather than how long it was willing to sit there.",
117
+ timer: "A promise around `setTimeout` is a sleep with the name taken off. The objection is the same: nothing here says which state the flow is waiting for, so the failure message when it expires names a timeout instead of the thing that never happened. Poll the state with `waitFor`.",
115
118
  },
116
119
  },
117
120
  create(context) {
118
- if (!isE2eSpec(context.filename || context.getFilename())) return {}
121
+ if (!isE2eSpec(context.filename || context.getFilename()))
122
+ return {};
119
123
  const insidePromise = (node) => {
120
124
  for (let current = node.parent; current; current = current.parent) {
121
- if (current.type === "NewExpression" && current.callee.type === "Identifier" && current.callee.name === "Promise") return current
125
+ if (current.type === "NewExpression" && current.callee.type === "Identifier" && current.callee.name === "Promise")
126
+ return current;
122
127
  }
123
- return null
124
- }
125
- const reportedPromises = new Set()
128
+ return null;
129
+ };
130
+ const reportedPromises = new Set();
126
131
  return {
127
132
  CallExpression(node) {
128
- if (!waitsForDuration(context, node)) return
133
+ if (!waitsForDuration(context, node))
134
+ return;
129
135
  // A timer wrapped in `new Promise` is one finding, on the promise, not two on one sleep.
130
- const wrapper = insidePromise(node)
136
+ const wrapper = insidePromise(node);
131
137
  if (wrapper) {
132
138
  if (!reportedPromises.has(wrapper)) {
133
- reportedPromises.add(wrapper)
134
- context.report({ node: wrapper, messageId: "timer" })
139
+ reportedPromises.add(wrapper);
140
+ context.report({ node: wrapper, messageId: "timer" });
135
141
  }
136
- return
142
+ return;
137
143
  }
138
- context.report({ node, messageId: "sleep" })
144
+ context.report({ node, messageId: "sleep" });
139
145
  },
140
- }
146
+ };
141
147
  },
142
- }
143
-
148
+ };
144
149
  // -- E2E-7 ----------------------------------------------------------------------------------------
145
-
146
150
  /**
147
151
  * A step asserts one outcome. A branch means the test is prepared for either, which is no assertion.
148
152
  *
@@ -158,56 +162,53 @@ export const noBranchInFlowStep = {
158
162
  docs: { description: "A flow step takes no branch: it asserts the one outcome the business promises." },
159
163
  schema: [],
160
164
  messages: {
161
- branch:
162
- "A branch inside a step means this test passes down either path, so a green run stops being evidence that the business worked - it only proves the code reached the end. The flow knows which outcome it is asserting: state it. If two outcomes are both legitimate, they are two steps, or two flows.",
165
+ branch: "A branch inside a step means this test passes down either path, so a green run stops being evidence that the business worked - it only proves the code reached the end. The flow knows which outcome it is asserting: state it. If two outcomes are both legitimate, they are two steps, or two flows.",
163
166
  },
164
167
  },
165
168
  create(context) {
166
- if (!isE2eSpec(context.filename || context.getFilename())) return {}
167
- const hfs = hfsOf(context)
168
-
169
+ if (!isE2eSpec(context.filename || context.getFilename()))
170
+ return {};
171
+ const hfs = hfsOf(context);
169
172
  /** True when the call is `world.waitFor(...)` on the test world's own handle. */
170
- const isWorldPoll = (call) =>
171
- call.callee.type === "MemberExpression" &&
173
+ const isWorldPoll = (call) => call.callee.type === "MemberExpression" &&
172
174
  !call.callee.computed &&
173
175
  call.callee.property.type === "Identifier" &&
174
176
  call.callee.property.name === "waitFor" &&
175
- typeOrigins(context, call.callee.object).some((origin) => inTestWorld(hfs, origin.file))
176
-
177
+ typeOrigins(context, call.callee.object).some((origin) => inTestWorld(hfs, origin.file));
177
178
  /** True when this node sits inside the callback of an `it(...)` or `test(...)`, and not inside a `waitFor` probe. */
178
179
  const insideStep = (node) => {
179
- let child = node
180
+ let child = node;
180
181
  for (let current = node.parent; current; current = current.parent) {
181
182
  if (current.type === "CallExpression") {
182
- const isFunction = child.type === "ArrowFunctionExpression" || child.type === "FunctionExpression"
183
- if (isFunction && current.arguments.includes(child) && isWorldPoll(current)) return false
184
- const callee = current.callee
185
- const name = callee && (callee.name || (callee.object && callee.object.name))
186
- if (name === "it" || name === "test") return true
183
+ const isFunction = child.type === "ArrowFunctionExpression" || child.type === "FunctionExpression";
184
+ if (isFunction && current.arguments.some((argument) => argument === child) && isWorldPoll(current))
185
+ return false;
186
+ const callee = current.callee;
187
+ const name = callee.type === "Identifier" ? callee.name : callee.type === "MemberExpression" && callee.object.type === "Identifier" ? callee.object.name : undefined;
188
+ if (name === "it" || name === "test")
189
+ return true;
187
190
  }
188
- child = current
191
+ child = current;
189
192
  }
190
- return false
191
- }
192
-
193
+ return false;
194
+ };
193
195
  const report = (node) => {
194
- if (insideStep(node)) context.report({ node, messageId: "branch" })
195
- }
196
-
196
+ if (insideStep(node))
197
+ context.report({ node, messageId: "branch" });
198
+ };
197
199
  return {
198
200
  IfStatement: report,
199
201
  ConditionalExpression: report,
200
202
  SwitchStatement: report,
201
203
  LogicalExpression(node) {
202
204
  // `a && b` used as a STATEMENT is a hidden if; the same operator inside an assertion is not
203
- if (node.parent && node.parent.type === "ExpressionStatement") report(node)
205
+ if (node.parent && node.parent.type === "ExpressionStatement")
206
+ report(node);
204
207
  },
205
- }
208
+ };
206
209
  },
207
- }
208
-
210
+ };
209
211
  // -- E2E-8 (the per-file half: a spec builds no wiring of its own) --------------------------------
210
-
211
212
  /** A flow boots through the shared setup; it does not build its own copy of the app. */
212
213
  export const noWiringInFlowSpec = {
213
214
  meta: {
@@ -215,36 +216,36 @@ export const noWiringInFlowSpec = {
215
216
  docs: { description: "An e2e spec boots through the shared setup and builds no testing module of its own (E2E-8)." },
216
217
  schema: [],
217
218
  messages: {
218
- wiring:
219
- "`Test.createTestingModule(...)` builds this flow's own copy of the app. The world is stood up in one place, `src/tests/world/` through `useTestWorld({ apps })`, which boots the real app; a spec file carries no wiring of its own. When the wiring changes, every flow that inlined its own module has to change with it, and two flows standing the world up slightly differently is how nobody learns where they differ. Boot through the world; nothing is overridden, an external service is the world's network fake (`world.fake.<provider>`).",
219
+ wiring: "`Test.createTestingModule(...)` builds this flow's own copy of the app. The world is stood up in one place, `src/tests/world/` through `useTestWorld({ apps })`, which boots the real app; a spec file carries no wiring of its own. When the wiring changes, every flow that inlined its own module has to change with it, and two flows standing the world up slightly differently is how nobody learns where they differ. Boot through the world; nothing is overridden, an external service is the world's network fake (`world.fake.<provider>`).",
220
220
  },
221
221
  },
222
222
  create(context) {
223
- if (!isE2eSpec(context.filename || context.getFilename())) return {}
223
+ if (!isE2eSpec(context.filename || context.getFilename()))
224
+ return {};
224
225
  return {
225
226
  CallExpression(node) {
226
- const callee = node.callee
227
- if (callee.type !== "MemberExpression" || callee.computed || callee.property.name !== "createTestingModule") return
228
- if (callee.object.type !== "Identifier") return
229
- const binding = bindingOf(context, node, callee.object.name)
230
- if (binding?.source === "@nestjs/testing" && binding.imported === "Test") context.report({ node: callee, messageId: "wiring" })
227
+ const callee = node.callee;
228
+ if (callee.type !== "MemberExpression" || callee.computed || callee.property.name !== "createTestingModule")
229
+ return;
230
+ if (callee.object.type !== "Identifier")
231
+ return;
232
+ const binding = bindingOf(context, node, callee.object.name);
233
+ if (binding?.source === "@nestjs/testing" && binding.imported === "Test")
234
+ context.report({ node: callee, messageId: "wiring" });
231
235
  },
232
- }
236
+ };
233
237
  },
234
- }
235
-
236
-
238
+ };
237
239
  export const rules = {
238
240
  "e2e-uses-production-transport": e2eUsesProductionTransport,
239
241
  "no-sleep-in-flow": noSleepInFlow,
240
242
  "no-branch-in-flow-step": noBranchInFlowStep,
241
243
  "no-wiring-in-flow-spec": noWiringInFlowSpec,
242
- }
243
-
244
+ };
244
245
  /** Every rule of this law ships at `error`. */
245
246
  export const recommended = {
246
247
  "starci-be/e2e-uses-production-transport": "error",
247
248
  "starci-be/no-sleep-in-flow": "error",
248
249
  "starci-be/no-branch-in-flow-step": "error",
249
250
  "starci-be/no-wiring-in-flow-spec": "error",
250
- }
251
+ };
@@ -0,0 +1,10 @@
1
+ import type { Recommended, RuleModule } from "./lib/rule.js";
2
+ export declare const corsAllowlist: RuleModule;
3
+ export declare const securityHeaders: RuleModule;
4
+ export declare const trustProxy: RuleModule;
5
+ export declare const rules: {
6
+ "cors-allowlist": RuleModule;
7
+ "security-headers": RuleModule;
8
+ "trust-proxy": RuleModule;
9
+ };
10
+ export declare const recommended: Recommended;
@@ -0,0 +1,173 @@
1
+ /** R261: every API entrypoint declares its browser and proxy boundary. */
2
+ import { keyName, staticText, walk } from "./lib/ast.js";
3
+ import { hfsOf } from "./lib/hfs.js";
4
+ const isWrapper = (node) => ["TSAsExpression", "TSTypeAssertion", "TSSatisfiesExpression", "TSNonNullExpression", "AwaitExpression", "ChainExpression"].includes(node.type);
5
+ const unwrap = (node) => {
6
+ while (node && isWrapper(node))
7
+ node = node.type === "AwaitExpression" ? node.argument : node.expression;
8
+ return node;
9
+ };
10
+ const property = (node, name, constants = new Map(), seen = new Set()) => {
11
+ if (node?.type !== "ObjectExpression")
12
+ return undefined;
13
+ for (const entry of [...node.properties].reverse()) {
14
+ if (entry.type === "SpreadElement") {
15
+ const spread = resolve(entry.argument, constants, seen);
16
+ if (spread?.type !== "ObjectExpression")
17
+ return undefined;
18
+ const value = property(spread, name, constants, seen);
19
+ if (value !== undefined)
20
+ return value;
21
+ }
22
+ else {
23
+ const key = entry.computed ? staticText(entry.key) : keyName(entry.key);
24
+ if (key === null)
25
+ return undefined;
26
+ if (key === name)
27
+ return entry.value;
28
+ }
29
+ }
30
+ return undefined;
31
+ };
32
+ const method = (node) => node?.type === "MemberExpression" ? (node.computed ? staticText(node.property) : keyName(node.property)) : null;
33
+ /** Only declared API entrypoints are judged; workers have no browser edge. */
34
+ const isApiMain = (context) => {
35
+ const hfs = hfsOf(context);
36
+ const file = hfs.relative(context.filename ?? context.getFilename());
37
+ return hfs.slotOf(context.filename ?? context.getFilename()) === "be.app.api"
38
+ && hfs.apps.some((app) => app.kind === "api" && file === `apps/${app.name}/src/main.ts`);
39
+ };
40
+ /** Resolve local constants without making an identifier's spelling a security proof. */
41
+ const resolve = (node, constants, seen = new Set()) => {
42
+ node = unwrap(node);
43
+ if (node?.type === "Identifier" && constants.has(node.name) && !seen.has(node.name))
44
+ return resolve(constants.get(node.name), constants, new Set([...seen, node.name]));
45
+ if (node?.type === "MemberExpression" && method(node) !== null) {
46
+ const value = property(resolve(node.object, constants, seen), method(node), constants, seen);
47
+ if (value !== undefined)
48
+ return resolve(value, constants, seen);
49
+ }
50
+ return node;
51
+ };
52
+ const allowedOrigin = (node) => {
53
+ const value = staticText(node);
54
+ if (value === null || value.includes("*") || value.endsWith("/"))
55
+ return false;
56
+ try {
57
+ const url = new URL(value);
58
+ return value === url.origin && (url.protocol === "https:" || (url.protocol === "http:" && ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname)));
59
+ }
60
+ catch {
61
+ return false;
62
+ }
63
+ };
64
+ /** Config owns a dynamic allowlist; literal lists must contain exact origins. */
65
+ const allowlist = (node, constants) => {
66
+ node = resolve(node, constants);
67
+ if (node?.type === "MemberExpression")
68
+ return method(node) === "allowedOrigins";
69
+ if (node?.type !== "ArrayExpression" || node.elements.length === 0)
70
+ return false;
71
+ return node.elements.every((entry) => entry?.type === "SpreadElement"
72
+ ? allowlist(entry.argument, constants)
73
+ : allowedOrigin(resolve(entry, constants)));
74
+ };
75
+ const hopCount = (node, constants) => {
76
+ node = resolve(node, constants);
77
+ return node?.type === "Literal" && Number.isSafeInteger(node.value) && typeof node.value === "number" && node.value >= 0;
78
+ };
79
+ /** Whether a node is a member access whose static name is one of the given names. */
80
+ const isMethodIn = (node, names) => {
81
+ const name = method(node);
82
+ return name !== null && names.includes(name);
83
+ };
84
+ /** The imported name of an import specifier, or undefined for a default, namespace or string-named import. */
85
+ const importedName = (specifier) => specifier.type === "ImportSpecifier" && specifier.imported.type === "Identifier" ? specifier.imported.name : undefined;
86
+ /** Whether an import specifier imports one of the given names. */
87
+ const importsOneOf = (specifier, names) => {
88
+ const name = importedName(specifier);
89
+ return name !== undefined && names.includes(name);
90
+ };
91
+ /** The value of a literal argument, or undefined for any other node. */
92
+ const literalValue = (node) => (node?.type === "Literal" ? node.value : undefined);
93
+ /** Whether a call is `<factory>.create(...)` on an imported `NestFactory`. */
94
+ const isFactoryCreate = (node, factories) => method(node.callee) === "create" && node.callee.type === "MemberExpression" && node.callee.object.type === "Identifier" && factories.has(node.callee.object.name);
95
+ const audit = (program) => {
96
+ const constants = new Map();
97
+ const helpers = new Set();
98
+ const middleware = new Set();
99
+ const factories = new Set();
100
+ const applications = new Set();
101
+ const calls = [];
102
+ walk(program, (node) => {
103
+ if (node.type === "ImportDeclaration") {
104
+ if (node.source.value === "@nestjs/core") {
105
+ for (const specifier of node.specifiers)
106
+ if (importedName(specifier) === "NestFactory")
107
+ factories.add(specifier.local.name);
108
+ }
109
+ if (/^@modules\/platform\/http-security(?:\/|$)/.test(node.source.value)) {
110
+ for (const specifier of node.specifiers) {
111
+ if (importsOneOf(specifier, ["applyHttpSecurity", "configureHttpSecurity"]))
112
+ helpers.add(specifier.local.name);
113
+ if (importsOneOf(specifier, ["securityHeaders", "createSecurityHeadersMiddleware"]))
114
+ middleware.add(specifier.local.name);
115
+ }
116
+ }
117
+ }
118
+ if (node.type === "VariableDeclarator" && node.id.type === "Identifier" && node.init)
119
+ constants.set(node.id.name, node.init);
120
+ if (node.type === "CallExpression")
121
+ calls.push(node);
122
+ });
123
+ for (const [name, initializer] of constants) {
124
+ const node = resolve(initializer, constants);
125
+ if (node?.type === "CallExpression" && isFactoryCreate(node, factories))
126
+ applications.add(name);
127
+ }
128
+ const isApplication = (node) => {
129
+ if (node?.type === "Identifier" && applications.has(node.name))
130
+ return true;
131
+ node = resolve(node, constants);
132
+ if (node?.type !== "CallExpression")
133
+ return false;
134
+ if (isFactoryCreate(node, factories))
135
+ return true;
136
+ return isMethodIn(node.callee, ["getInstance", "getHttpAdapter"]) && node.callee.type === "MemberExpression" && isApplication(node.callee.object);
137
+ };
138
+ const direct = calls.filter((call) => call.callee.type === "MemberExpression" && isApplication(call.callee.object));
139
+ const applied = calls.filter((call) => call.callee.type === "Identifier" && helpers.has(call.callee.name) && isApplication(call.arguments[0]));
140
+ const helperCors = applied.some((call) => {
141
+ const config = resolve(call.arguments[1], constants);
142
+ return config?.type === "MemberExpression" || allowlist(property(config, "allowedOrigins", constants), constants);
143
+ });
144
+ const corsCalls = direct.filter((call) => method(call.callee) === "enableCors");
145
+ const cors = (helperCors || corsCalls.length > 0) && corsCalls.every((call) => allowlist(property(resolve(call.arguments[0], constants), "origin", constants), constants));
146
+ const headers = applied.length > 0 || direct.some((call) => method(call.callee) === "use" && call.arguments.some((argument) => {
147
+ const candidate = resolve(argument, constants);
148
+ return (candidate?.type === "Identifier" && middleware.has(candidate.name))
149
+ || (candidate?.type === "CallExpression" && candidate.callee.type === "Identifier" && middleware.has(candidate.callee.name));
150
+ }));
151
+ const poweredCalls = direct.filter((call) => isMethodIn(call.callee, ["set", "enable", "disable"]) && staticText(call.arguments[0])?.toLowerCase() === "x-powered-by");
152
+ const poweredOff = (applied.length > 0 || poweredCalls.some((call) => method(call.callee) === "disable" || (method(call.callee) === "set" && literalValue(call.arguments[1]) === false)))
153
+ && poweredCalls.every((call) => method(call.callee) === "disable" || (method(call.callee) === "set" && literalValue(call.arguments[1]) === false));
154
+ const proxyCalls = direct.filter((call) => method(call.callee) === "set" && staticText(call.arguments[0]) === "trust proxy");
155
+ const proxy = (proxyCalls.length > 0 || applied.length > 0)
156
+ && proxyCalls.every((call) => hopCount(call.arguments[1], constants))
157
+ && applied.every((call) => hopCount(property(resolve(call.arguments[2], constants), "trustProxy", constants), constants));
158
+ return { cors, headers: headers && poweredOff, proxy };
159
+ };
160
+ const edgeRule = (field, code, description) => ({
161
+ meta: { type: "problem", docs: { description }, schema: [], messages: { boundary: `${code}: ${description}` } },
162
+ create(context) {
163
+ if (!isApiMain(context))
164
+ return {};
165
+ return { "Program:exit"(node) { if (!audit(node)[field])
166
+ context.report({ node, messageId: "boundary" }); } };
167
+ },
168
+ });
169
+ export const corsAllowlist = edgeRule("cors", "BE_CORS_ALLOWLIST", "Configure CORS with an explicit origin allowlist from http-security config; wildcard, open and missing origins are refused.");
170
+ export const securityHeaders = edgeRule("headers", "BE_SECURITY_HEADERS", "Apply the platform/http-security response middleware and disable x-powered-by.");
171
+ export const trustProxy = edgeRule("proxy", "BE_TRUST_PROXY", "Declare trust proxy as a nonnegative integer hop count; blanket trust and undeclared proxy trust are refused.");
172
+ export const rules = { "cors-allowlist": corsAllowlist, "security-headers": securityHeaders, "trust-proxy": trustProxy };
173
+ export const recommended = Object.fromEntries(Object.keys(rules).map((name) => [`starci-be/${name}`, "error"]));
@@ -0,0 +1,21 @@
1
+ import type { Recommended, RuleModule } from "./lib/rule.js";
2
+ /** Every failure is rethrown, logged through the logger port, or returned as an outcome carrying its cause. */
3
+ export declare const catchMustAccount: RuleModule;
4
+ /** A catch that replaces the caught failure passes the caught value on as the replacement's `cause` (BE-ERROR-4). */
5
+ export declare const replacementThrowCarriesCause: RuleModule;
6
+ /** An error class is declared at its owner in `errors/<capability>.error.ts` and derives from `DomainError`. */
7
+ export declare const errorHome: RuleModule;
8
+ /** Every thrown value is a `DomainError` of the owner that throws it. */
9
+ export declare const throwDomainError: RuleModule;
10
+ /** The one shape of an owner's `errors/<capability>.error.ts`. */
11
+ export declare const errorFamilyShape: RuleModule;
12
+ /** The rules this law contributes to the plugin. */
13
+ export declare const rules: {
14
+ "catch-must-account": RuleModule;
15
+ "replacement-throw-carries-cause": RuleModule;
16
+ "error-home": RuleModule;
17
+ "throw-domain-error": RuleModule;
18
+ "error-family-shape": RuleModule;
19
+ };
20
+ /** All start at error: HFS has no baseline, and the migration lanes clear the debt before a repository adopts them. */
21
+ export declare const recommended: Recommended;