@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
@@ -1,147 +1,151 @@
1
1
  /** Typed webhook proofs shared by the webhook and thin-feature laws. */
2
- import { dirname } from "node:path"
3
- import ts from "typescript"
4
- import { walk } from "./ast.mjs"
5
- import { baseName, isOwnedType } from "./ports.mjs"
6
- import { originsOfType, typeOrigins, typed } from "./types.mjs"
7
-
2
+ import { dirname } from "node:path";
3
+ import ts from "typescript";
4
+ import { walk } from "./ast.js";
5
+ import { baseName, isOwnedType } from "./ports.js";
6
+ import { originsOfType, typeOrigins, typed } from "./types.js";
8
7
  /** The shared platform proof, identified by its declared owner. */
9
- export const isWebhookSignatureType = (context, node) => isOwnedType(context, node, { name: "WebhookSignatureService", capability: "http-security", tier: "platform" })
10
-
8
+ export const isWebhookSignatureType = (context, node) => isOwnedType(context, node, { name: "WebhookSignatureService", capability: "http-security", tier: "platform" });
11
9
  /** A service declared by a domain owner, rather than a similarly named local or package type. */
12
- export const isWebhookDomainServiceType = (context, hfs, node) =>
13
- typeOrigins(context, node).some((origin) => origin.module === null && hfs.tierOf(origin.file) === "domain" && baseName(origin.file).endsWith(".service.ts"))
14
-
10
+ export const isWebhookDomainServiceType = (context, hfs, node) => typeOrigins(context, node).some((origin) => origin.module === null && hfs.tierOf(origin.file) === "domain" && baseName(origin.file).endsWith(".service.ts"));
15
11
  /** The method symbol named by a property access, resolving imported aliases. */
16
12
  const methodSymbol = (checker, expression) => {
17
- if (!expression || !ts.isPropertyAccessExpression(expression)) return null
18
- const symbol = checker.getSymbolAtLocation(expression.name)
19
- return symbol && symbol.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol ?? null
20
- }
21
-
13
+ if (!expression || !ts.isPropertyAccessExpression(expression))
14
+ return null;
15
+ const symbol = checker.getSymbolAtLocation(expression.name);
16
+ return symbol && symbol.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol ?? null;
17
+ };
22
18
  /** Unwrap static TypeScript annotations around a declaration's array literal. */
23
19
  const arrayOf = (expression) => {
24
- while (expression && (ts.isAsExpression(expression) || ts.isSatisfiesExpression(expression) || ts.isParenthesizedExpression(expression))) expression = expression.expression
25
- return expression && ts.isArrayLiteralExpression(expression) ? expression : null
26
- }
27
-
20
+ while (expression && (ts.isAsExpression(expression) || ts.isSatisfiesExpression(expression) || ts.isParenthesizedExpression(expression)))
21
+ expression = expression.expression;
22
+ return expression && ts.isArrayLiteralExpression(expression) ? expression : null;
23
+ };
28
24
  /** All possible receiver types must be declared verifier classes; a type alias cannot rename a general service into one. */
29
25
  const isDomainVerifierType = (context, hfs, receiver) => {
30
- const { checker, toTs } = typed(context)
31
- const type = checker.getTypeAtLocation(toTs(receiver))
32
- const parts = type.isUnion() ? type.types : [type]
26
+ const { checker, toTs } = typed(context);
27
+ const type = checker.getTypeAtLocation(toTs(receiver));
28
+ const parts = type.isUnion() ? type.types : [type];
33
29
  return parts.every((part) => part.getSymbol()?.getDeclarations()?.some((declaration) => {
34
- const file = declaration.getSourceFile().fileName.replace(/\\/g, "/")
30
+ const file = declaration.getSourceFile().fileName.replace(/\\/g, "/");
35
31
  return ts.isClassDeclaration(declaration) && declaration.name && /(?:Verifier|verify)$/.test(declaration.name.text)
36
- && hfs.tierOf(file) === "domain" && baseName(file).endsWith(".service.ts")
37
- }))
38
- }
39
-
32
+ && hfs.tierOf(file) === "domain" && baseName(file).endsWith(".service.ts");
33
+ }));
34
+ };
40
35
  /**
41
36
  * A provider's adjacent HTTP module may export webhookVerifiers as an array of
42
37
  * domain methods, e.g. [BillingService.prototype.receiveCassoWebhook] as const.
43
38
  * Compare symbols, so spelling an arbitrary receiver or alias as a verifier grants nothing.
44
39
  */
45
40
  const declaresMethod = (checker, statement, method) => {
46
- if (!ts.isVariableStatement(statement) || !(statement.declarationList.flags & ts.NodeFlags.Const)) return false
47
- if (!statement.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword)) return false
41
+ if (!ts.isVariableStatement(statement) || !(statement.declarationList.flags & ts.NodeFlags.Const))
42
+ return false;
43
+ if (!statement.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword))
44
+ return false;
48
45
  return statement.declarationList.declarations.some((declaration) => ts.isIdentifier(declaration.name)
49
46
  && declaration.name.text === "webhookVerifiers"
50
- && arrayOf(declaration.initializer)?.elements.some((entry) => methodSymbol(checker, entry) === method))
51
- }
52
-
47
+ && arrayOf(declaration.initializer)?.elements.some((entry) => methodSymbol(checker, entry) === method));
48
+ };
53
49
  /** The module declaration is adjacent to this exact provider door, not another feature's proof list. */
54
50
  const isProviderModule = (context, source) => {
55
- const file = source.fileName.replace(/\\/g, "/")
56
- const directory = dirname(context.filename).replace(/\\/g, "/")
57
- const moduleName = `${baseName(context.filename).slice(0, -".webhook.ts".length)}-http.module.ts`
58
- return dirname(file).replace(/\\/g, "/") === directory && baseName(file) === moduleName
59
- }
60
-
51
+ const file = source.fileName.replace(/\\/g, "/");
52
+ const directory = dirname(context.filename).replace(/\\/g, "/");
53
+ const moduleName = `${baseName(context.filename).slice(0, -".webhook.ts".length)}-http.module.ts`;
54
+ return dirname(file).replace(/\\/g, "/") === directory && baseName(file) === moduleName;
55
+ };
61
56
  /** A general domain service method is a verifier only when this provider's module declares its resolved symbol. */
62
57
  const isModuleDeclaredVerifier = (context, call) => {
63
- const { program, checker, toTs } = typed(context)
64
- const method = methodSymbol(checker, toTs(call.callee))
65
- if (method === null) return false
58
+ const { program, checker, toTs } = typed(context);
59
+ const method = methodSymbol(checker, toTs(call.callee));
60
+ if (method === null)
61
+ return false;
66
62
  return program.getSourceFiles().some((source) => isProviderModule(context, source)
67
- && source.statements.some((statement) => declaresMethod(checker, statement, method)))
68
- }
69
-
63
+ && source.statements.some((statement) => declaresMethod(checker, statement, method)));
64
+ };
70
65
  /** A direct, unconditional method call to the shared proof or a declared domain verifier. */
71
66
  const isWebhookVerificationCall = (context, hfs, call, domainOnly = false) => {
72
- if (call?.type !== "CallExpression" || call.optional) return false
73
- const callee = call.callee
74
- if (callee.type !== "MemberExpression" || callee.computed || callee.optional || callee.property.type !== "Identifier") return false
75
- const { checker, toTs } = typed(context)
76
- const receiverType = checker.getTypeAtLocation(toTs(callee.object))
77
- const parts = receiverType.isUnion() ? receiverType.types : [receiverType]
78
- if (!domainOnly && callee.property.name === "verify" && parts.every((part) => originsOfType(checker, part).some((origin) => origin.module === null && origin.name === "WebhookSignatureService" && hfs.tierOf(origin.file) === "platform" && hfs.ownerOf(origin.file)?.split("/").at(-1) === "http-security"))) return true
79
- if (!isWebhookDomainServiceType(context, hfs, callee.object)) return false
80
- return isDomainVerifierType(context, hfs, callee.object) || isModuleDeclaredVerifier(context, call)
81
- }
82
-
67
+ if (call?.type !== "CallExpression" || call.optional)
68
+ return false;
69
+ const callee = call.callee;
70
+ if (callee.type !== "MemberExpression" || callee.computed || callee.optional || callee.property.type !== "Identifier")
71
+ return false;
72
+ const { checker, toTs } = typed(context);
73
+ const receiverType = checker.getTypeAtLocation(toTs(callee.object));
74
+ const parts = receiverType.isUnion() ? receiverType.types : [receiverType];
75
+ if (!domainOnly && callee.property.name === "verify" && parts.every((part) => originsOfType(checker, part).some((origin) => origin.module === null && origin.name === "WebhookSignatureService" && hfs.tierOf(origin.file) === "platform" && hfs.ownerOf(origin.file)?.split("/").at(-1) === "http-security")))
76
+ return true;
77
+ if (!isWebhookDomainServiceType(context, hfs, callee.object))
78
+ return false;
79
+ return isDomainVerifierType(context, hfs, callee.object) || isModuleDeclaredVerifier(context, call);
80
+ };
83
81
  /** Expressions that can execute work or skip the proof before its call is entered. */
84
- const PRE_PROOF_WORK = new Set(["CallExpression", "NewExpression", "ImportExpression", "TaggedTemplateExpression", "AssignmentExpression", "UpdateExpression", "AwaitExpression", "YieldExpression", "ChainExpression", "ConditionalExpression", "LogicalExpression", "SequenceExpression"])
85
-
82
+ const PRE_PROOF_WORK = new Set(["CallExpression", "NewExpression", "ImportExpression", "TaggedTemplateExpression", "AssignmentExpression", "UpdateExpression", "AwaitExpression", "YieldExpression", "ChainExpression", "ConditionalExpression", "LogicalExpression", "SequenceExpression"]);
86
83
  /**
87
84
  * The first statement must itself be the proof (awaited if it returns a thenable).
88
85
  * Its receiver and arguments may pass delivery data, but cannot run another call first.
89
86
  */
90
87
  const completedVerification = (context, hfs, expression, domainOnly = false) => {
91
- let call = expression
92
- const awaited = call?.type === "AwaitExpression"
93
- if (awaited) call = call.argument
94
- if (!isWebhookVerificationCall(context, hfs, call, domainOnly)) return null
95
- let work = false
88
+ let call = expression;
89
+ const awaited = call?.type === "AwaitExpression";
90
+ if (awaited && call?.type === "AwaitExpression")
91
+ call = call.argument;
92
+ if (!isWebhookVerificationCall(context, hfs, call, domainOnly))
93
+ return null;
94
+ let work = false;
96
95
  walk(call, (child) => {
97
- if (child !== call && (PRE_PROOF_WORK.has(child.type) || (child.type === "UnaryExpression" && child.operator === "delete"))) work = true
98
- })
99
- if (work) return null
100
- const { checker, toTs } = typed(context)
101
- const signature = checker.getResolvedSignature(toTs(call))
102
- if (!signature) return null
103
- const returned = checker.getReturnTypeOfSignature(signature)
104
- const parts = returned.isUnion() ? returned.types : [returned]
105
- if (!awaited && parts.some((part) => checker.getApparentType(part).getProperty("then"))) return null
106
- return call
107
- }
108
-
96
+ if (child !== call && (PRE_PROOF_WORK.has(child.type) || (child.type === "UnaryExpression" && child.operator === "delete")))
97
+ work = true;
98
+ });
99
+ if (work)
100
+ return null;
101
+ const { checker, toTs } = typed(context);
102
+ const signature = checker.getResolvedSignature(toTs(call));
103
+ if (!signature)
104
+ return null;
105
+ const returned = checker.getReturnTypeOfSignature(signature);
106
+ const parts = returned.isUnion() ? returned.types : [returned];
107
+ if (!awaited && parts.some((part) => checker.getApparentType(part).getProperty("then")))
108
+ return null;
109
+ return call;
110
+ };
109
111
  /** POST's first statement remains the proof itself, before the intake or acknowledgement. */
110
112
  export const firstWebhookVerification = (context, hfs, method) => {
111
- const first = method.value.body?.body[0]
112
- return completedVerification(context, hfs, first?.type === "ExpressionStatement" ? first.expression : null)
113
- }
114
-
113
+ const first = method.value.body?.body[0];
114
+ return completedVerification(context, hfs, first?.type === "ExpressionStatement" ? first.expression : null);
115
+ };
115
116
  /** A challenge verifier must produce an echo value, rather than a void proof. */
116
117
  const hasChallengeResult = (context, call) => {
117
- const { checker, toTs } = typed(context)
118
- const signature = checker.getResolvedSignature(toTs(call))
119
- const returned = signature && checker.getReturnTypeOfSignature(signature)
120
- const value = returned && (checker.getAwaitedType(returned) ?? returned)
121
- const parts = value?.isUnion() ? value.types : [value]
122
- return parts.every((part) => part && !(part.flags & (ts.TypeFlags.Void | ts.TypeFlags.Undefined | ts.TypeFlags.Never)))
123
- }
124
-
118
+ const { checker, toTs } = typed(context);
119
+ const signature = checker.getResolvedSignature(toTs(call));
120
+ const returned = signature && checker.getReturnTypeOfSignature(signature);
121
+ const value = returned && (checker.getAwaitedType(returned) ?? returned);
122
+ const parts = value?.isUnion() ? value.types : [value];
123
+ return parts.every((part) => part && !(part.flags & (ts.TypeFlags.Void | ts.TypeFlags.Undefined | ts.TypeFlags.Never)));
124
+ };
125
125
  /** The optional GET proves once, binding its result with const or returning the verifier call directly. */
126
126
  export const firstWebhookChallenge = (context, hfs, method) => {
127
- const statements = method.value.body?.body ?? []
128
- const first = statements[0]
127
+ const statements = method.value.body?.body ?? [];
128
+ const first = statements[0];
129
129
  if (first?.type === "ReturnStatement") {
130
- const call = completedVerification(context, hfs, first.argument, true)
131
- return call && hasChallengeResult(context, call) ? { call, result: null, echo: first, statements } : null
130
+ const call = completedVerification(context, hfs, first.argument, true);
131
+ return call && hasChallengeResult(context, call) ? { call, result: null, echo: first, statements } : null;
132
132
  }
133
- if (first?.type !== "VariableDeclaration" || first.kind !== "const" || first.declarations.length !== 1) return null
134
- const binding = first.declarations[0]
135
- if (binding.id.type !== "Identifier") return null
136
- const call = completedVerification(context, hfs, binding.init, true)
137
- return call && hasChallengeResult(context, call) ? { call, result: binding.id, echo: statements[1], statements } : null
138
- }
139
-
133
+ if (first?.type !== "VariableDeclaration" || first.kind !== "const" || first.declarations.length !== 1)
134
+ return null;
135
+ const [binding] = first.declarations;
136
+ if (!binding || binding.id.type !== "Identifier")
137
+ return null;
138
+ const call = completedVerification(context, hfs, binding.init, true);
139
+ return call && hasChallengeResult(context, call) ? { call, result: binding.id, echo: statements[1], statements } : null;
140
+ };
140
141
  /** The GET echoes only the original proof's value, with no intervening work or transformation. */
141
142
  export const isWebhookChallengeReturn = (context, node, challenge) => {
142
- if (!challenge || node !== challenge.echo || node.type !== "ReturnStatement") return false
143
- if (challenge.result === null) return challenge.statements.length === 1
144
- if (challenge.statements.length !== 2 || node.argument?.type !== "Identifier") return false
145
- const { checker, toTs } = typed(context)
146
- return checker.getSymbolAtLocation(toTs(node.argument)) === checker.getSymbolAtLocation(toTs(challenge.result))
147
- }
143
+ if (!challenge || node !== challenge.echo || node.type !== "ReturnStatement")
144
+ return false;
145
+ if (challenge.result === null)
146
+ return challenge.statements.length === 1;
147
+ if (challenge.statements.length !== 2 || node.argument?.type !== "Identifier")
148
+ return false;
149
+ const { checker, toTs } = typed(context);
150
+ return checker.getSymbolAtLocation(toTs(node.argument)) === checker.getSymbolAtLocation(toTs(challenge.result));
151
+ };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The catalogue sub-codes the back-end laws publish: `{ <rule id>: { code } }`.
3
+ * A rule's own code comes from its enforcer row in knowledge/hfs/rules.yaml; a SECOND code a rule emits
4
+ * (one rule, several failure codes) is named here so scripts/checks/check-hfs-rules.mjs sees it as emitted.
5
+ * Append-only: each alpha.15 batch adds its own secondary codes at the end (union-merged).
6
+ */
7
+ export declare const why: Readonly<Record<string, {
8
+ readonly code: string;
9
+ }>>;
@@ -5,9 +5,9 @@
5
5
  * Append-only: each alpha.15 batch adds its own secondary codes at the end (union-merged).
6
6
  */
7
7
  export const why = {
8
- "webhook-inbox-key": { code: "BE_WEBHOOK_INBOX_KEY" },
9
- "rest-route-declared": { code: "BE_REST_ROUTE_UNDECLARED" },
10
- "security-headers": { code: "BE_SECURITY_HEADERS" },
11
- "trust-proxy": { code: "BE_TRUST_PROXY" },
12
- "health-signals": { code: "BE_HEALTH_SIGNALS" },
13
- }
8
+ "webhook-inbox-key": { code: "BE_WEBHOOK_INBOX_KEY" },
9
+ "rest-route-declared": { code: "BE_REST_ROUTE_UNDECLARED" },
10
+ "security-headers": { code: "BE_SECURITY_HEADERS" },
11
+ "trust-proxy": { code: "BE_TRUST_PROXY" },
12
+ "health-signals": { code: "BE_HEALTH_SIGNALS" },
13
+ };
@@ -0,0 +1,20 @@
1
+ import type { Recommended, RuleModule } from "./lib/rule.js";
2
+ /** A logger call carries no credential and no personal identifier, by type or by name. */
3
+ export declare const noSecretInLog: RuleModule;
4
+ /**
5
+ * An error carries no secret. `no-secret-in-error` (R71) judges every `new X(...)` whose constructed TYPE derives from the
6
+ * language `Error` (a `DomainError` family, a library error, `Error` itself): no argument holds a value typed by the
7
+ * `Secret` brand of `platform/config` or read out of one, and no text value (a `string`) whose own name, or the key it is
8
+ * given under, says it is a credential (the same last-word test `secret-compare-timing-safe` uses: `password`,
9
+ * `accessToken`, `clientSecret`, `signingKey`). An error's message and params reach the error filter, the log line of the
10
+ * failure, the tracing vendor and, for a declared error, the client. Personal identifiers are not judged here: an error
11
+ * may name the account it refused.
12
+ */
13
+ export declare const noSecretInError: RuleModule;
14
+ /** The rules this law contributes to the plugin. */
15
+ export declare const rules: {
16
+ "no-secret-in-log": RuleModule;
17
+ "no-secret-in-error": RuleModule;
18
+ };
19
+ /** Both start at error: no baseline exists, and the repositories' fix lanes clear the debt. */
20
+ export declare const recommended: Recommended;
@@ -0,0 +1,308 @@
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.js";
23
+ import { keyName, wordsOf } from "./lib/ast.js";
24
+ import { derivesFromBuiltinError, presentParts, typeOf } from "./lib/declared.js";
25
+ import { isLoggerCall, isOwnedType } from "./lib/ports.js";
26
+ import { isDeclarationFile } from "./lib/path.js";
27
+ /** The `Secret` brand of `platform/config`. */
28
+ const isSecretType = (context, node) => isOwnedType(context, node, { name: "Secret", capability: "config", tier: "platform" });
29
+ /** The `Pii` brand of the `identity` owner. */
30
+ const isPiiType = (context, node) => isOwnedType(context, node, { name: "Pii", capability: "identity" });
31
+ const SECRET_WORDS = new Set(["password", "passwd", "secret", "secrets", "apikey", "authorization", "bearer", "otp", "cookie", "cookies", "credential", "credentials", "jwt", "passphrase"]);
32
+ const SECRET_PAIRS = [["api", "key"], ["private", "key"], ["access", "key"], ["secret", "key"], ["signing", "key"], ["client", "secret"]];
33
+ const PII_WORDS = new Set(["email", "emails", "phone", "phonenumber", "fullname", "idcard", "cccd", "birthdate", "dob"]);
34
+ /** A name that measures or classifies a credential is not the credential. */
35
+ 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"]);
36
+ /** Whether a name spells a credential, given its words. */
37
+ const isSecretName = (words) => {
38
+ if (words.some((word) => MEASURE_WORDS.has(word)))
39
+ return false;
40
+ if (words.some((word) => SECRET_WORDS.has(word)))
41
+ return true;
42
+ if (words.includes("token") || words.includes("tokens"))
43
+ return true;
44
+ return SECRET_PAIRS.some(([a, b]) => words.some((word, index) => word === a && words[index + 1] === b));
45
+ };
46
+ const PII_PAIRS = [["full", "name"], ["birth", "date"], ["id", "card"], ["phone", "number"]];
47
+ /** Whether a name spells a personal identifier: a two-word identifier (`fullName`) or a single word, unless the name measures one. */
48
+ const isPiiName = (words) => PII_PAIRS.some(([a, b]) => words.some((word, index) => word === a && words[index + 1] === b))
49
+ || (!words.some((word) => MEASURE_WORDS.has(word)) && words.some((word) => PII_WORDS.has(word)));
50
+ /** A call that hides its argument: the value shown is a mask, a hash, a flag or a count. */
51
+ const isHidingCall = (node) => node.type === "CallExpression"
52
+ && node.callee.type === "Identifier"
53
+ && /^(?:mask|redact|hash|fingerprint|last4|truncate|Boolean|Number|String)$|^(?:mask|redact|hash|fingerprint)/i.test(node.callee.name);
54
+ /**
55
+ * The expressions whose TYPE an argument passes on: identifiers, member reads, call results, and what they are read
56
+ * out of. A call to a masking function shows a mask, so its arguments are not followed.
57
+ */
58
+ const valuesIn = (node, found = []) => {
59
+ if (!node || typeof node.type !== "string")
60
+ return found;
61
+ switch (node.type) {
62
+ case "Identifier":
63
+ found.push(node);
64
+ return found;
65
+ case "MemberExpression":
66
+ found.push(node);
67
+ return valuesIn(node.object, found);
68
+ case "CallExpression":
69
+ if (isHidingCall(node))
70
+ return found;
71
+ found.push(node);
72
+ if (node.callee.type === "MemberExpression")
73
+ valuesIn(node.callee.object, found);
74
+ return found;
75
+ case "ObjectExpression":
76
+ node.properties.forEach((property) => valuesIn(property, found));
77
+ return found;
78
+ case "Property":
79
+ return valuesIn(node.value, found);
80
+ case "ArrayExpression":
81
+ node.elements.forEach((element) => valuesIn(element, found));
82
+ return found;
83
+ case "TemplateLiteral":
84
+ node.expressions.forEach((expression) => valuesIn(expression, found));
85
+ return found;
86
+ case "BinaryExpression":
87
+ case "LogicalExpression":
88
+ valuesIn(node.left, found);
89
+ return valuesIn(node.right, found);
90
+ case "ConditionalExpression":
91
+ valuesIn(node.consequent, found);
92
+ return valuesIn(node.alternate, found);
93
+ case "SpreadElement":
94
+ case "AwaitExpression":
95
+ return valuesIn(node.argument, found);
96
+ case "TSAsExpression":
97
+ case "TSNonNullExpression":
98
+ case "TSSatisfiesExpression":
99
+ return valuesIn(node.expression, found);
100
+ default:
101
+ return found;
102
+ }
103
+ };
104
+ /** The names an argument reads: identifiers, member properties and object keys, not nested function bodies. */
105
+ const namesIn = (node, found = []) => {
106
+ if (!node || typeof node.type !== "string")
107
+ return found;
108
+ switch (node.type) {
109
+ case "Identifier":
110
+ found.push({ name: node.name, node });
111
+ return found;
112
+ case "MemberExpression":
113
+ // only the last name says what the value IS: `credential.fromEmail` is an address, `payload.token` is a token
114
+ if (!node.computed && node.property.type === "Identifier")
115
+ found.push({ name: node.property.name, node: node.property });
116
+ else
117
+ namesIn(node.property, found);
118
+ return found;
119
+ case "Property":
120
+ if (isHidingCall(node.value))
121
+ return found;
122
+ if (!node.computed && node.key.type === "Identifier")
123
+ 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))
152
+ return found;
153
+ node.arguments.forEach((argument) => namesIn(argument, found));
154
+ return found;
155
+ default:
156
+ return found;
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: "`{{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.",
167
+ piiType: "`{{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.",
168
+ secret: "`{{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.",
169
+ pii: "`{{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.",
170
+ },
171
+ },
172
+ create(context) {
173
+ const filename = context.filename || context.getFilename();
174
+ if (isDeclarationFile(filename))
175
+ return {};
176
+ const sourceCode = context.sourceCode || context.getSourceCode();
177
+ return {
178
+ CallExpression(node) {
179
+ if (!isLoggerCall(context, node))
180
+ return;
181
+ // the first argument is the event; the rest are the cause and the fields
182
+ const fields = node.arguments.slice(1);
183
+ const reported = new Set();
184
+ for (const argument of fields) {
185
+ for (const value of valuesIn(argument)) {
186
+ if (reported.has(value))
187
+ continue;
188
+ if (isSecretType(context, value)) {
189
+ reported.add(value);
190
+ context.report({ node: value, messageId: "secretType", data: { name: sourceCode.getText(value) } });
191
+ }
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))
200
+ continue;
201
+ if (isSecretName(words)) {
202
+ reported.add(name);
203
+ context.report({ node: at, messageId: "secret", data: { name } });
204
+ }
205
+ else if (isPiiName(words)) {
206
+ reported.add(name);
207
+ context.report({ node: at, messageId: "pii", data: { name } });
208
+ }
209
+ }
210
+ }
211
+ },
212
+ };
213
+ },
214
+ };
215
+ const STRINGY = ts.TypeFlags.String | ts.TypeFlags.StringLiteral | ts.TypeFlags.TemplateLiteral;
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
+ /** The last name a value expression ends in (`token`, `request.headers.authorization`), or null. */
222
+ const ownNameOf = (node) => {
223
+ if (node.type === "Identifier")
224
+ return node.name;
225
+ if (node.type === "MemberExpression" && !node.computed && node.property.type === "Identifier")
226
+ return node.property.name;
227
+ return null;
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))
234
+ continue;
235
+ const key = keyName(property.key);
236
+ if (key && isText(context, property.value))
237
+ found.push({ name: key, node: property.key });
238
+ textPropertiesIn(context, property.value, found);
239
+ }
240
+ }
241
+ else if (node?.type === "ArrayExpression")
242
+ node.elements.forEach((element) => textPropertiesIn(context, element, found));
243
+ return found;
244
+ };
245
+ /**
246
+ * An error carries no secret. `no-secret-in-error` (R71) judges every `new X(...)` whose constructed TYPE derives from the
247
+ * language `Error` (a `DomainError` family, a library error, `Error` itself): no argument holds a value typed by the
248
+ * `Secret` brand of `platform/config` or read out of one, and no text value (a `string`) whose own name, or the key it is
249
+ * given under, says it is a credential (the same last-word test `secret-compare-timing-safe` uses: `password`,
250
+ * `accessToken`, `clientSecret`, `signingKey`). An error's message and params reach the error filter, the log line of the
251
+ * failure, the tracing vendor and, for a declared error, the client. Personal identifiers are not judged here: an error
252
+ * may name the account it refused.
253
+ */
254
+ export const noSecretInError = {
255
+ meta: {
256
+ type: "problem",
257
+ docs: { description: "A constructed error carries no `Secret` value and no text value named like a credential." },
258
+ schema: [],
259
+ messages: {
260
+ secretType: "`{{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.",
261
+ secret: "`{{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.",
262
+ },
263
+ },
264
+ create(context) {
265
+ const filename = context.filename || context.getFilename();
266
+ if (isDeclarationFile(filename))
267
+ return {};
268
+ const sourceCode = context.sourceCode || context.getSourceCode();
269
+ return {
270
+ NewExpression(node) {
271
+ if (node.arguments.length === 0 || !derivesFromBuiltinError(context, typeOf(context, node)))
272
+ return;
273
+ const reported = new Set();
274
+ const report = (at, messageId, name) => {
275
+ if (reported.has(at))
276
+ return;
277
+ reported.add(at);
278
+ context.report({ node: at, messageId, data: { name } });
279
+ };
280
+ for (const argument of node.arguments) {
281
+ for (const value of valuesIn(argument)) {
282
+ if (isSecretType(context, value))
283
+ report(value, "secretType", sourceCode.getText(value));
284
+ else {
285
+ const name = ownNameOf(value);
286
+ if (name !== null && isCredentialName(name) && isText(context, value))
287
+ report(value, "secret", name);
288
+ }
289
+ }
290
+ for (const { name, node: at } of textPropertiesIn(context, argument)) {
291
+ if (isCredentialName(name))
292
+ report(at, "secret", name);
293
+ }
294
+ }
295
+ },
296
+ };
297
+ },
298
+ };
299
+ /** The rules this law contributes to the plugin. */
300
+ export const rules = {
301
+ "no-secret-in-log": noSecretInLog,
302
+ "no-secret-in-error": noSecretInError,
303
+ };
304
+ /** Both start at error: no baseline exists, and the repositories' fix lanes clear the debt. */
305
+ export const recommended = {
306
+ "starci-be/no-secret-in-log": "error",
307
+ "starci-be/no-secret-in-error": "error",
308
+ };