@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
package/log-safety.mjs DELETED
@@ -1,303 +0,0 @@
1
- /**
2
- * The rule that keeps a secret or a person out of a log line.
3
- *
4
- * `no-secret-in-log` (R71 `BE_LOG_SECRET`) judges every call on the `Logger` port of `platform/logging` - the receiver
5
- * is identified by its TYPE, never by its name - and refuses two things in the fields it is given (the first argument
6
- * is the event and is judged by `no-interpolated-log-message`):
7
- *
8
- * 1. a value whose TYPE is the `Secret` brand of `platform/config` or the `Pii` brand of `identity`, or that is read
9
- * out of one (`secret.reveal()`, `person.value`): the brand says what the value IS, whatever it is called;
10
- * 2. a value whose NAME says it is a credential (`password`, `secret`, `apiKey`, `accessToken`, `authorization`,
11
- * `cookie`, `otp`) or a personal identifier (`email`, `phone`, `fullName`, `idCard`, `birthDate`). This is the
12
- * second half the convention keeps for values that never carried a brand; a name that says it MEASURES a
13
- * credential (`tokenCount`, `tokenType`, `secretName`) is not the credential, so those endings are exempt.
14
- *
15
- * A log line outlives the request, is copied to a vendor, and is read by people who never had the credential or the
16
- * consent. Log an id, a count, or a masked form instead.
17
- *
18
- * `no-secret-in-error` (R71) holds the same line for an error: a constructed error (its TYPE derives from `Error`) carries
19
- * no `Secret` value and no text value named like a credential, because its message and params reach the same logs.
20
- */
21
- import ts from "typescript"
22
- import { isCredentialName } from "./config-owner.mjs"
23
- import { keyName, wordsOf } from "./lib/ast.mjs"
24
- import { derivesFromBuiltinError, presentParts, typeOf } from "./lib/declared.mjs"
25
- import { isLoggerCall, isOwnedType } from "./lib/ports.mjs"
26
- import { isDeclarationFile } from "./lib/path.mjs"
27
-
28
- /** The `Secret` brand of `platform/config`. */
29
- const isSecretType = (context, node) => isOwnedType(context, node, { name: "Secret", capability: "config", tier: "platform" })
30
-
31
- /** The `Pii` brand of the `identity` owner. */
32
- const isPiiType = (context, node) => isOwnedType(context, node, { name: "Pii", capability: "identity" })
33
-
34
- const SECRET_WORDS = new Set(["password", "passwd", "secret", "secrets", "apikey", "authorization", "bearer", "otp", "cookie", "cookies", "credential", "credentials", "jwt", "passphrase"])
35
- const SECRET_PAIRS = [["api", "key"], ["private", "key"], ["access", "key"], ["secret", "key"], ["signing", "key"], ["client", "secret"]]
36
- const PII_WORDS = new Set(["email", "emails", "phone", "phonenumber", "fullname", "idcard", "cccd", "birthdate", "dob"])
37
- /** A name that measures or classifies a credential is not the credential. */
38
- const MEASURE_WORDS = new Set(["count", "counts", "id", "ids", "type", "types", "name", "names", "ttl", "expiry", "expires", "expiresat", "limit", "usage", "used", "budget", "max", "min", "input", "output", "total", "length", "kind", "hash", "hashed", "masked", "present", "provided", "configured", "exists", "has", "is", "reason", "status", "prefix", "suffix", "version", "rotated", "at", "summary", "source", "from", "fixture", "seed"])
39
-
40
- /** Whether a name spells a credential, given its words. */
41
- const isSecretName = (words) => {
42
- if (words.some((word) => MEASURE_WORDS.has(word))) return false
43
- if (words.some((word) => SECRET_WORDS.has(word))) return true
44
- if (words.includes("token") || words.includes("tokens")) return true
45
- return SECRET_PAIRS.some(([a, b]) => words.some((word, index) => word === a && words[index + 1] === b))
46
- }
47
-
48
- const PII_PAIRS = [["full", "name"], ["birth", "date"], ["id", "card"], ["phone", "number"]]
49
-
50
- /** Whether a name spells a personal identifier: a two-word identifier (`fullName`) or a single word, unless the name measures one. */
51
- const isPiiName = (words) =>
52
- PII_PAIRS.some(([a, b]) => words.some((word, index) => word === a && words[index + 1] === b))
53
- || (!words.some((word) => MEASURE_WORDS.has(word)) && words.some((word) => PII_WORDS.has(word)))
54
-
55
- /** A call that hides its argument: the value shown is a mask, a hash, a flag or a count. */
56
- const isHidingCall = (node) =>
57
- node.type === "CallExpression"
58
- && node.callee.type === "Identifier"
59
- && /^(?:mask|redact|hash|fingerprint|last4|truncate|Boolean|Number|String)$|^(?:mask|redact|hash|fingerprint)/i.test(node.callee.name)
60
-
61
- /**
62
- * The expressions whose TYPE an argument passes on: identifiers, member reads, call results, and what they are read
63
- * out of. A call to a masking function shows a mask, so its arguments are not followed.
64
- */
65
- const valuesIn = (node, found = []) => {
66
- if (!node || typeof node.type !== "string") return found
67
- switch (node.type) {
68
- case "Identifier":
69
- found.push(node)
70
- return found
71
- case "MemberExpression":
72
- found.push(node)
73
- return valuesIn(node.object, found)
74
- case "CallExpression":
75
- if (isHidingCall(node)) return found
76
- found.push(node)
77
- if (node.callee.type === "MemberExpression") valuesIn(node.callee.object, found)
78
- return found
79
- case "ObjectExpression":
80
- node.properties.forEach((property) => valuesIn(property, found))
81
- return found
82
- case "Property":
83
- return valuesIn(node.value, found)
84
- case "ArrayExpression":
85
- node.elements.forEach((element) => valuesIn(element, found))
86
- return found
87
- case "TemplateLiteral":
88
- node.expressions.forEach((expression) => valuesIn(expression, found))
89
- return found
90
- case "BinaryExpression":
91
- case "LogicalExpression":
92
- valuesIn(node.left, found)
93
- return valuesIn(node.right, found)
94
- case "ConditionalExpression":
95
- valuesIn(node.consequent, found)
96
- return valuesIn(node.alternate, found)
97
- case "SpreadElement":
98
- case "AwaitExpression":
99
- return valuesIn(node.argument, found)
100
- case "TSAsExpression":
101
- case "TSNonNullExpression":
102
- case "TSSatisfiesExpression":
103
- return valuesIn(node.expression, found)
104
- default:
105
- return found
106
- }
107
- }
108
-
109
- /** The names an argument reads: identifiers, member properties and object keys, not nested function bodies. */
110
- const namesIn = (node, found = []) => {
111
- if (!node || typeof node.type !== "string") return found
112
- switch (node.type) {
113
- case "Identifier":
114
- found.push({ name: node.name, node })
115
- return found
116
- case "MemberExpression":
117
- // only the last name says what the value IS: `credential.fromEmail` is an address, `payload.token` is a token
118
- if (!node.computed && node.property.type === "Identifier") found.push({ name: node.property.name, node: node.property })
119
- else namesIn(node.property, found)
120
- return found
121
- case "Property":
122
- if (isHidingCall(node.value)) return found
123
- if (!node.computed && node.key.type === "Identifier") found.push({ name: node.key.name, node: node.key })
124
- namesIn(node.value, found)
125
- return found
126
- case "ObjectExpression":
127
- node.properties.forEach((property) => namesIn(property, found))
128
- return found
129
- case "ArrayExpression":
130
- node.elements.forEach((element) => namesIn(element, found))
131
- return found
132
- case "TemplateLiteral":
133
- node.expressions.forEach((expression) => namesIn(expression, found))
134
- return found
135
- case "BinaryExpression":
136
- case "LogicalExpression":
137
- namesIn(node.left, found)
138
- namesIn(node.right, found)
139
- return found
140
- case "ConditionalExpression":
141
- namesIn(node.consequent, found)
142
- namesIn(node.alternate, found)
143
- return found
144
- case "SpreadElement":
145
- return namesIn(node.argument, found)
146
- case "TSAsExpression":
147
- case "TSNonNullExpression":
148
- return namesIn(node.expression, found)
149
- case "CallExpression":
150
- // `mask(token)` and `redact(token)` are the sanctioned way to show a credential; any other call reads its arguments
151
- if (isHidingCall(node)) return found
152
- node.arguments.forEach((argument) => namesIn(argument, found))
153
- return found
154
- default:
155
- return found
156
- }
157
- }
158
-
159
- /** A logger call carries no credential and no personal identifier, by type or by name. */
160
- export const noSecretInLog = {
161
- meta: {
162
- type: "problem",
163
- docs: { description: "Fields of a `Logger` call carry no `Secret`/`Pii` value and no credential or personal identifier by name." },
164
- schema: [],
165
- messages: {
166
- secretType:
167
- "`{{name}}` is a `Secret` (or is read out of one) and is passed to the logger. Log lines outlive the request and are copied to vendors. Log whether it was present, its length, or a masked form (`mask(...)`), never the value.",
168
- piiType:
169
- "`{{name}}` is `Pii` (or is read out of one) and is passed to the logger. Log the owning id instead, or a masked form (`mask(...)`), never the value.",
170
- secret:
171
- "`{{name}}` reads as a credential and is passed to a logger. Log lines outlive the request and are copied to vendors. Log whether it was present, its length, or a masked form (`mask(...)`), never the value.",
172
- pii:
173
- "`{{name}}` reads as a personal identifier and is passed to a logger. Log the owning id instead, or a masked form (`mask(...)`), never the raw value.",
174
- },
175
- },
176
- create(context) {
177
- const filename = context.filename || context.getFilename()
178
- if (isDeclarationFile(filename)) return {}
179
- const sourceCode = context.sourceCode || context.getSourceCode()
180
- return {
181
- CallExpression(node) {
182
- if (!isLoggerCall(context, node)) return
183
- // the first argument is the event; the rest are the cause and the fields
184
- const fields = node.arguments.slice(1)
185
- const reported = new Set()
186
- for (const argument of fields) {
187
- for (const value of valuesIn(argument)) {
188
- if (reported.has(value)) continue
189
- if (isSecretType(context, value)) {
190
- reported.add(value)
191
- context.report({ node: value, messageId: "secretType", data: { name: sourceCode.getText(value) } })
192
- } else if (isPiiType(context, value)) {
193
- reported.add(value)
194
- context.report({ node: value, messageId: "piiType", data: { name: sourceCode.getText(value) } })
195
- }
196
- }
197
- for (const { name, node: at } of namesIn(argument)) {
198
- const words = wordsOf(name)
199
- if (reported.has(name)) continue
200
- if (isSecretName(words)) {
201
- reported.add(name)
202
- context.report({ node: at, messageId: "secret", data: { name } })
203
- } else if (isPiiName(words)) {
204
- reported.add(name)
205
- context.report({ node: at, messageId: "pii", data: { name } })
206
- }
207
- }
208
- }
209
- },
210
- }
211
- },
212
- }
213
-
214
- const STRINGY = ts.TypeFlags.String | ts.TypeFlags.StringLiteral | ts.TypeFlags.TemplateLiteral
215
-
216
- /** Whether a node's type is text (a string, with `null`/`undefined` removed): the shape a raw credential travels in. */
217
- const isText = (context, node) => {
218
- const parts = presentParts(typeOf(context, node))
219
- return parts.length > 0 && parts.every((part) => (part.flags & STRINGY) && !(part.flags & ts.TypeFlags.EnumLiteral))
220
- }
221
-
222
- /** The last name a value expression ends in (`token`, `request.headers.authorization`), or null. */
223
- const ownNameOf = (node) => {
224
- if (node.type === "Identifier") return node.name
225
- if (node.type === "MemberExpression" && !node.computed && node.property.type === "Identifier") return node.property.name
226
- return null
227
- }
228
-
229
- /** The `key: value` pairs of an argument tree whose value is text, so a key can name what the value is (`{ token: raw }`). */
230
- const textPropertiesIn = (context, node, found = []) => {
231
- if (node?.type === "ObjectExpression") {
232
- for (const property of node.properties) {
233
- if (property.type !== "Property" || property.computed || isHidingCall(property.value)) continue
234
- const key = keyName(property.key)
235
- if (key && isText(context, property.value)) found.push({ name: key, node: property.key })
236
- textPropertiesIn(context, property.value, found)
237
- }
238
- } else if (node?.type === "ArrayExpression") node.elements.forEach((element) => textPropertiesIn(context, element, found))
239
- return found
240
- }
241
-
242
- /**
243
- * An error carries no secret. `no-secret-in-error` (R71) judges every `new X(...)` whose constructed TYPE derives from the
244
- * language `Error` (a `DomainError` family, a library error, `Error` itself): no argument holds a value typed by the
245
- * `Secret` brand of `platform/config` or read out of one, and no text value (a `string`) whose own name, or the key it is
246
- * given under, says it is a credential (the same last-word test `secret-compare-timing-safe` uses: `password`,
247
- * `accessToken`, `clientSecret`, `signingKey`). An error's message and params reach the error filter, the log line of the
248
- * failure, the tracing vendor and, for a declared error, the client. Personal identifiers are not judged here: an error
249
- * may name the account it refused.
250
- */
251
- export const noSecretInError = {
252
- meta: {
253
- type: "problem",
254
- docs: { description: "A constructed error carries no `Secret` value and no text value named like a credential." },
255
- schema: [],
256
- messages: {
257
- secretType:
258
- "`{{name}}` is a `Secret` (or is read out of one) and is put into an error. An error's message and params reach logs, tracing and sometimes the client. Name the failure with its code and pass an id or a masked form (`mask(...)`), never the value.",
259
- secret:
260
- "`{{name}}` reads as a credential and is put into an error. An error's message and params reach logs, tracing and sometimes the client. Name the failure with its code and pass an id or a masked form (`mask(...)`), never the value.",
261
- },
262
- },
263
- create(context) {
264
- const filename = context.filename || context.getFilename()
265
- if (isDeclarationFile(filename)) return {}
266
- const sourceCode = context.sourceCode || context.getSourceCode()
267
- return {
268
- NewExpression(node) {
269
- if (node.arguments.length === 0 || !derivesFromBuiltinError(context, typeOf(context, node))) return
270
- const reported = new Set()
271
- const report = (at, messageId, name) => {
272
- if (reported.has(at)) return
273
- reported.add(at)
274
- context.report({ node: at, messageId, data: { name } })
275
- }
276
- for (const argument of node.arguments) {
277
- for (const value of valuesIn(argument)) {
278
- if (isSecretType(context, value)) report(value, "secretType", sourceCode.getText(value))
279
- else {
280
- const name = ownNameOf(value)
281
- if (name !== null && isCredentialName(name) && isText(context, value)) report(value, "secret", name)
282
- }
283
- }
284
- for (const { name, node: at } of textPropertiesIn(context, argument)) {
285
- if (isCredentialName(name)) report(at, "secret", name)
286
- }
287
- }
288
- },
289
- }
290
- },
291
- }
292
-
293
- /** The rules this law contributes to the plugin. */
294
- export const rules = {
295
- "no-secret-in-log": noSecretInLog,
296
- "no-secret-in-error": noSecretInError,
297
- }
298
-
299
- /** Both start at error: no baseline exists, and the repositories' fix lanes clear the debt. */
300
- export const recommended = {
301
- "starci-be/no-secret-in-log": "error",
302
- "starci-be/no-secret-in-error": "error",
303
- }
@@ -1,270 +0,0 @@
1
- /**
2
- * The rules that hold the public surface of an owner (catalog R30 `BE_PUBLIC_SURFACE`, BE-CONVENTION 1.15 and 2.4).
3
- *
4
- * Every owner (a feature, a domain or platform capability, an integration) has exactly ONE `index.ts` at its root and
5
- * that file is its public surface. Four rules read import specifiers and the shape of index files against the HFS slot
6
- * view; none of them reads a path pattern, and an alias is resolved through the program's own `compilerOptions.paths`:
7
- *
8
- * - `import-owner-entry` - a cross-owner import targets the owner's `index.ts` (`@modules/domain/plan`,
9
- * `@features/api/plan`), never a file inside it, and an alias that names a tier but no owner (`@modules/domain`) names
10
- * nothing importable. A same-owner import is relative and never goes through the owner's own `index.ts`.
11
- * - `no-self-module-alias` - inside an owner, imports are relative, never the owner's own alias.
12
- * - `no-relative-capability-escape` - a relative import never walks out of its own owner.
13
- * - `no-folder-reexport` - a specifier that names a directory is refused; a nested `index.ts` (any index that is not
14
- * at its owner's root) is refused; an owner's `index.ts` holds only named `export { }` / `export type { }` lines
15
- * re-exporting from files, never `export *`, never a declaration, and at most `budget.indexExports` names.
16
- *
17
- * "Which owner does this file belong to" is `hfs.ownerOf`; "which owner does this specifier reach" is the same question
18
- * asked of the file the specifier resolves to. Nothing here touches disk.
19
- */
20
- import { posix } from "node:path"
21
- import { hfsOf } from "./lib/hfs.mjs"
22
- import { baseName } from "./lib/ports.mjs"
23
- import { resolveAlias } from "./lib/specifier.mjs"
24
-
25
- /** The tiers whose files belong to an owner with a root `index.ts`. */
26
- const OWNER_TIERS = new Set(["feature", "domain", "platform", "integrations"])
27
-
28
- /**
29
- * The owner directory (repository-relative) a file belongs to, or null.
30
- *
31
- * A slot whose "root" is the file itself (a stray file directly in a tier folder) owns nothing.
32
- *
33
- * @param {object} hfs - The HFS view.
34
- * @param {string} file - An absolute or repository-relative file path.
35
- * @returns {string | null} The owner's root directory.
36
- */
37
- const ownerDirOf = (hfs, file) => {
38
- const root = hfs.ownerOf(file)
39
- return root && root !== hfs.relative(file) ? root : null
40
- }
41
-
42
- /** The forward-slash absolute path of a repository-relative path. */
43
- const absolute = (hfs, rel) => `${hfs.repoRoot.replace(/\\/g, "/")}/${rel}`
44
-
45
- /** The owner an import path (no extension, absolute) reaches: the owner of `<path>/index.ts`, which any file or folder of that owner shares. */
46
- const ownerOfTarget = (hfs, target) => ownerDirOf(hfs, `${target}/index.ts`)
47
-
48
- /** A specifier that names a directory by construction: `.`, `./`, `..`, `../`, or a trailing `/`. */
49
- const isBareFolderSpecifier = (specifier) =>
50
- specifier === "." || specifier === "./" || specifier === ".." || specifier === "../" || specifier.endsWith("/")
51
-
52
- const isRelative = (specifier) => specifier === "." || specifier === ".." || specifier.startsWith("./") || specifier.startsWith("../")
53
-
54
- /** The absolute path a relative specifier names from a file, without touching disk. */
55
- const resolveRelative = (filename, specifier) => posix.normalize(`${posix.dirname(filename.replace(/\\/g, "/"))}/${specifier}`)
56
-
57
- /** Calls `check(node, specifier)` for every import and re-export that names a module. */
58
- const onSpecifiers = (check) => ({
59
- ImportDeclaration(node) {
60
- check(node.source, node.source.value)
61
- },
62
- ExportNamedDeclaration(node) {
63
- if (node.source) check(node.source, node.source.value)
64
- },
65
- ExportAllDeclaration(node) {
66
- if (node.source) check(node.source, node.source.value)
67
- },
68
- })
69
-
70
- /** The public-surface width: the file's slot budget, else its tier's owner-slot budget, else a back-end owner default. */
71
- const indexExportBudget = (hfs, filename) =>
72
- [hfs.slotOf(filename), `be.${hfs.tierOf(filename)}`, "be.domain", "be.feature"].map((id) => (id ? hfs.slot(id)?.budget?.indexExports : undefined)).find(Number.isInteger)
73
-
74
- // -- R30: import-owner-entry -----------------------------------------------------------------------
75
-
76
- /**
77
- * A cross-owner import targets the owner's public entry: the alias and the owner, nothing deeper. A same-owner import
78
- * is relative and never goes through the owner's own `index.ts` (BE-CONVENTION 2.4).
79
- */
80
- export const importOwnerEntry = {
81
- meta: {
82
- type: "problem",
83
- docs: { description: "Import another owner through its public entry (`index.ts`); import inside an owner relatively and never through its own `index.ts`." },
84
- schema: [],
85
- messages: {
86
- barrel:
87
- "`{{specifier}}` names a tier, not an owner. Import an owner's public entry, for example `@modules/domain/plan` or `@features/api/plan`.",
88
- deep:
89
- "`{{specifier}}` reaches into a file of another owner. Import the owner's public entry (its `index.ts`) and export what you need from there.",
90
- ownIndex:
91
- "`{{specifier}}` goes through this owner's own `index.ts`. The index is the surface other owners see; inside the owner import the file that declares the symbol, relatively.",
92
- },
93
- },
94
- create(context) {
95
- const filename = context.filename || context.getFilename()
96
- const hfs = hfsOf(context)
97
- const self = ownerDirOf(hfs, filename)
98
- return onSpecifiers((node, specifier) => {
99
- if (typeof specifier !== "string") return
100
- if (isRelative(specifier)) {
101
- if (isBareFolderSpecifier(specifier) || !self) return
102
- const target = resolveRelative(filename, specifier)
103
- if (posix.basename(target) === "index" && posix.dirname(target) === absolute(hfs, self)) {
104
- context.report({ node, messageId: "ownIndex", data: { specifier } })
105
- }
106
- return
107
- }
108
- const alias = resolveAlias(context, specifier)
109
- if (!alias) return
110
- const owner = ownerOfTarget(hfs, alias.target)
111
- if (!owner) {
112
- // an alias that reaches a tier folder but no owner in it: nothing importable is named
113
- if (OWNER_TIERS.has(hfs.tierOf(`${alias.target}/index.ts`) ?? "") || OWNER_TIERS.has(hfs.tierOf(`${alias.target}.ts`) ?? "")) {
114
- context.report({ node, messageId: "barrel", data: { specifier } })
115
- }
116
- return
117
- }
118
- // reaching one's own owner through its alias is no-self-module-alias's finding
119
- if (owner === self) return
120
- const ownerAbsolute = absolute(hfs, owner)
121
- const inside = alias.target === ownerAbsolute ? "" : alias.target.slice(ownerAbsolute.length + 1)
122
- if (inside !== "" && inside !== "index") context.report({ node, messageId: "deep", data: { specifier } })
123
- })
124
- },
125
- }
126
-
127
- // -- no-self-module-alias --------------------------------------------------------------------------
128
-
129
- /** Inside an owner, imports are relative -- never the owner's own public alias. */
130
- export const noSelfModuleAlias = {
131
- meta: {
132
- type: "problem",
133
- docs: { description: "Inside an owner, import relatively rather than through its own alias." },
134
- schema: [],
135
- messages: {
136
- self:
137
- "`{{specifier}}` reaches this owner through its own public alias. That is the owner talking to itself through its front door: a cycle magnet, and a lie about the boundary - the alias exists to say \"this comes from elsewhere\". Use a relative import.",
138
- },
139
- },
140
- create(context) {
141
- const hfs = hfsOf(context)
142
- const self = ownerDirOf(hfs, context.filename || context.getFilename())
143
- if (!self) return {}
144
- return onSpecifiers((node, specifier) => {
145
- if (typeof specifier !== "string" || isRelative(specifier)) return
146
- const alias = resolveAlias(context, specifier)
147
- if (alias && ownerOfTarget(hfs, alias.target) === self) context.report({ node, messageId: "self", data: { specifier } })
148
- })
149
- },
150
- }
151
-
152
- // -- no-folder-reexport ----------------------------------------------------------------------------
153
-
154
- /** Whether a file is an index by its role name. */
155
- const isIndexFile = (filename) => /^index\.[cm]?[jt]sx?$/.test(baseName(filename))
156
-
157
- /**
158
- * No file re-exports a folder, and an owner's index lists a bounded set of named exports.
159
- *
160
- * The public entry of an owner is a short, explicit list, one per owner root:
161
- * - a bare-dot or trailing-slash specifier names a directory by construction, in any file;
162
- * - an `index` file that is not at its owner's root is a nested barrel;
163
- * - in an `index` file: `export *` hides the surface instead of listing it, anything but a named `export { } from` /
164
- * `export type { } from` line (an import, a declaration, a default export, a local export) is refused, and more
165
- * than the manifest's `indexExports` names is not a public surface but the inside of the owner.
166
- *
167
- * What this accepts: `export { PlanModule } from "./plan.module"` and `export type { PlanSummary } from "./plan.contracts"`.
168
- */
169
- export const noFolderReexport = {
170
- meta: {
171
- type: "problem",
172
- docs: { description: "No file re-exports a folder, no `index.ts` is nested, and an owner's `index.ts` lists a bounded set of named exports." },
173
- schema: [],
174
- messages: {
175
- bareSpecifier:
176
- "`{{specifier}}` names a directory, not a file. An owner's public surface is the files call sites actually import - re-exporting a whole folder makes that surface a list nobody reads instead. Export the specific file.",
177
- indexBarrel:
178
- "`{{name}}` is a public entry and must list explicit named exports. Replace export-star with the symbols this owner exposes.",
179
- nestedIndex:
180
- "This `index.ts` is not at its owner's root ({{owner}}). An owner has exactly one `index.ts`, the public surface; a nested barrel is a second surface. Delete it and import the files directly, relatively.",
181
- onlyNamedExports:
182
- "An owner's `index.ts` holds only named `export { } from \"./file\"` and `export type { } from \"./file\"` lines. Move this out of the index into the file that owns it and re-export the name.",
183
- tooWide:
184
- "This public entry exports {{count}} names, above the budget of {{max}}. An entry that wide is the inside of the owner: split the owner, or export fewer, narrower contracts.",
185
- },
186
- },
187
- create(context) {
188
- const filename = context.filename || context.getFilename()
189
- const hfs = hfsOf(context)
190
- const isIndex = isIndexFile(filename)
191
- const max = indexExportBudget(hfs, filename)
192
- let count = 0
193
- return {
194
- ...onSpecifiers((node, specifier) => {
195
- if (typeof specifier === "string" && isBareFolderSpecifier(specifier)) context.report({ node, messageId: "bareSpecifier", data: { specifier } })
196
- }),
197
- Program(node) {
198
- if (!isIndex) return
199
- const owner = ownerDirOf(hfs, filename)
200
- if (owner && posix.dirname(hfs.relative(filename)) !== owner) context.report({ node, messageId: "nestedIndex", data: { owner } })
201
- for (const statement of node.body) {
202
- const named = statement.type === "ExportNamedDeclaration" && statement.source && !statement.declaration
203
- if (statement.type === "ExportAllDeclaration") {
204
- count += 1
205
- context.report({ node: statement, messageId: "indexBarrel", data: { name: baseName(filename) } })
206
- } else if (!named) {
207
- context.report({ node: statement, messageId: "onlyNamedExports" })
208
- } else {
209
- count += statement.specifiers.length
210
- }
211
- }
212
- },
213
- "Program:exit"(node) {
214
- if (isIndex && Number.isInteger(max) && count > max) context.report({ node, messageId: "tooWide", data: { count, max } })
215
- },
216
- }
217
- },
218
- }
219
-
220
- // -- no-relative-capability-escape -----------------------------------------------------------------
221
-
222
- /**
223
- * A relative specifier may never leave the owner it is written in. The public-entry rule already says an import from
224
- * another owner goes through its `index.ts`; a relative path can just as easily walk OUT (`../../other-owner/thing`),
225
- * reaching a sibling owner without ever naming it. A file doing that could not be moved with its owner and still
226
- * resolve, because the path assumes the sibling is sitting right there on disk.
227
- */
228
- export const noRelativeCapabilityEscape = {
229
- meta: {
230
- type: "problem",
231
- docs: { description: "A relative import may not walk out of its own owner." },
232
- schema: [],
233
- messages: {
234
- escape:
235
- "`{{specifier}}` is a relative import that leaves the `{{from}}` owner and reaches `{{to}}`. Cross an owner boundary through the other owner's public entry (its alias), never by walking out with `../`.",
236
- },
237
- },
238
- create(context) {
239
- const filename = context.filename || context.getFilename()
240
- const hfs = hfsOf(context)
241
- const self = ownerDirOf(hfs, filename)
242
- if (!self) return {}
243
- return onSpecifiers((node, specifier) => {
244
- if (typeof specifier !== "string" || !isRelative(specifier)) return
245
- const target = ownerOfTarget(hfs, resolveRelative(filename, specifier))
246
- if (target && target !== self) context.report({ node, messageId: "escape", data: { specifier, from: self, to: target } })
247
- })
248
- },
249
- }
250
-
251
- /** The rules this law contributes to the plugin. */
252
- export const rules = {
253
- "import-owner-entry": importOwnerEntry,
254
- "no-self-module-alias": noSelfModuleAlias,
255
- "no-folder-reexport": noFolderReexport,
256
- "no-relative-capability-escape": noRelativeCapabilityEscape,
257
- }
258
-
259
- /**
260
- * The level this law asks for, as the plugin's own opinion.
261
- *
262
- * All four are `error`. HFS keeps no baseline: a repository adopts them after its migration lane has moved its imports
263
- * onto owner entries, and `starciBeConfig` states them at `error` with none switched off.
264
- */
265
- export const recommended = {
266
- "starci-be/import-owner-entry": "error",
267
- "starci-be/no-self-module-alias": "error",
268
- "starci-be/no-folder-reexport": "error",
269
- "starci-be/no-relative-capability-escape": "error",
270
- }