@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.
- package/CHANGELOG.md +15 -0
- package/README.md +11 -2
- package/dist/ambient-id.d.ts +9 -0
- package/{ambient-id.mjs → dist/ambient-id.js} +43 -39
- package/dist/app-composition.d.ts +21 -0
- package/{app-composition.mjs → dist/app-composition.js} +396 -300
- package/dist/async-discipline.d.ts +9 -0
- package/dist/async-discipline.js +77 -0
- package/dist/authorization.d.ts +12 -0
- package/{authorization.mjs → dist/authorization.js} +53 -59
- package/dist/boundary-schema.d.ts +15 -0
- package/{boundary-schema.mjs → dist/boundary-schema.js} +120 -105
- package/dist/builders.d.ts +21 -0
- package/{builders.mjs → dist/builders.js} +162 -146
- package/dist/cli.d.ts +15 -0
- package/{cli.mjs → dist/cli.js} +97 -82
- package/dist/comments.d.ts +52 -0
- package/dist/comments.js +412 -0
- package/dist/config-owner.d.ts +24 -0
- package/{config-owner.mjs → dist/config-owner.js} +256 -219
- package/dist/connections.d.ts +12 -0
- package/{connections.mjs → dist/connections.js} +138 -140
- package/dist/cookies.d.ts +9 -0
- package/{cookies.mjs → dist/cookies.js} +58 -58
- package/dist/cqrs.d.ts +27 -0
- package/{cqrs.mjs → dist/cqrs.js} +341 -282
- package/dist/data-access.d.ts +50 -0
- package/{data-access.mjs → dist/data-access.js} +238 -243
- package/dist/default-deny.d.ts +15 -0
- package/{default-deny.mjs → dist/default-deny.js} +103 -88
- package/dist/e2e-flow.d.ts +25 -0
- package/{e2e-flow.mjs → dist/e2e-flow.js} +113 -112
- package/dist/edge-hardening.d.ts +10 -0
- package/dist/edge-hardening.js +173 -0
- package/dist/error-handling.d.ts +21 -0
- package/{error-handling.mjs → dist/error-handling.js} +289 -239
- package/dist/event-bus.d.ts +14 -0
- package/{event-bus.mjs → dist/event-bus.js} +146 -129
- package/dist/feature-thin.d.ts +12 -0
- package/{feature-thin.mjs → dist/feature-thin.js} +208 -191
- package/dist/function-budget.d.ts +7 -0
- package/{function-budget.mjs → dist/function-budget.js} +24 -27
- package/dist/health-ready.d.ts +10 -0
- package/dist/health-ready.js +703 -0
- package/dist/idempotency.d.ts +10 -0
- package/{idempotency.mjs → dist/idempotency.js} +296 -226
- package/dist/index.d.ts +54 -0
- package/{index.mjs → dist/index.js} +91 -109
- package/dist/infra-owner.d.ts +18 -0
- package/{infra-owner.mjs → dist/infra-owner.js} +58 -51
- package/dist/injection.d.ts +30 -0
- package/{injection.mjs → dist/injection.js} +397 -344
- package/dist/input-bounds.d.ts +15 -0
- package/{input-bounds.mjs → dist/input-bounds.js} +143 -132
- package/dist/jobs.d.ts +17 -0
- package/{jobs.mjs → dist/jobs.js} +116 -99
- package/dist/jwt-alg.d.ts +6 -0
- package/dist/jwt-alg.js +49 -0
- package/dist/lib/app-roles.d.ts +25 -0
- package/{lib/app-roles.mjs → dist/lib/app-roles.js} +15 -17
- package/dist/lib/ast.d.ts +40 -0
- package/dist/lib/ast.js +100 -0
- package/dist/lib/client-idempotency.d.ts +3 -0
- package/{lib/client-idempotency.mjs → dist/lib/client-idempotency.js} +316 -268
- package/dist/lib/config.d.ts +36 -0
- package/{lib/config.mjs → dist/lib/config.js} +24 -27
- package/dist/lib/db-writes.d.ts +29 -0
- package/{lib/db-writes.mjs → dist/lib/db-writes.js} +27 -27
- package/dist/lib/declared.d.ts +77 -0
- package/{lib/declared.mjs → dist/lib/declared.js} +83 -78
- package/dist/lib/doors.d.ts +50 -0
- package/{lib/doors.mjs → dist/lib/doors.js} +45 -50
- package/dist/lib/edition.d.ts +25 -0
- package/{lib/edition.mjs → dist/lib/edition.js} +15 -20
- package/dist/lib/entity-writes.d.ts +7 -0
- package/{lib/entity-writes.mjs → dist/lib/entity-writes.js} +31 -22
- package/dist/lib/hfs.d.ts +34 -0
- package/{lib/hfs.mjs → dist/lib/hfs.js} +31 -29
- package/dist/lib/import-source.d.ts +63 -0
- package/dist/lib/import-source.js +134 -0
- package/dist/lib/path.d.ts +8 -0
- package/{lib/path.mjs → dist/lib/path.js} +4 -7
- package/dist/lib/persistence.d.ts +115 -0
- package/{lib/persistence.mjs → dist/lib/persistence.js} +55 -66
- package/dist/lib/ports.d.ts +70 -0
- package/{lib/ports.mjs → dist/lib/ports.js} +62 -66
- package/dist/lib/rule.d.ts +31 -0
- package/dist/lib/rule.js +2 -0
- package/dist/lib/runtime-root.d.ts +4 -0
- package/dist/lib/runtime-root.js +10 -0
- package/dist/lib/schema-values.d.ts +13 -0
- package/{lib/schema-values.mjs → dist/lib/schema-values.js} +67 -59
- package/dist/lib/specifier.d.ts +12 -0
- package/dist/lib/specifier.js +29 -0
- package/dist/lib/subject-values.d.ts +4 -0
- package/dist/lib/subject-values.js +61 -0
- package/dist/lib/transactions.d.ts +18 -0
- package/{lib/transactions.mjs → dist/lib/transactions.js} +17 -15
- package/dist/lib/transport-slots.d.ts +17 -0
- package/{lib/transport-slots.mjs → dist/lib/transport-slots.js} +2 -4
- package/dist/lib/types.d.ts +96 -0
- package/dist/lib/types.js +150 -0
- package/dist/lib/unit-spec.d.ts +48 -0
- package/{lib/unit-spec.mjs → dist/lib/unit-spec.js} +35 -44
- package/dist/lib/webhook-ack.d.ts +4 -0
- package/{lib/webhook-ack.mjs → dist/lib/webhook-ack.js} +78 -62
- package/dist/lib/webhook-handoff-inbox.d.ts +3 -0
- package/{lib/webhook-handoff-inbox.mjs → dist/lib/webhook-handoff-inbox.js} +195 -167
- package/dist/lib/webhook-handoff-intake.d.ts +4 -0
- package/{lib/webhook-handoff-intake.mjs → dist/lib/webhook-handoff-intake.js} +125 -102
- package/dist/lib/webhook-handoff.d.ts +15 -0
- package/{lib/webhook-handoff.mjs → dist/lib/webhook-handoff.js} +107 -100
- package/dist/lib/webhook-verifiers.d.ts +20 -0
- package/{lib/webhook-verifiers.mjs → dist/lib/webhook-verifiers.js} +108 -104
- package/dist/lib/why.d.ts +9 -0
- package/{lib/why.mjs → dist/lib/why.js} +6 -6
- package/dist/log-safety.d.ts +20 -0
- package/dist/log-safety.js +308 -0
- package/dist/module-layering.d.ts +42 -0
- package/dist/module-layering.js +257 -0
- package/dist/module-shape.d.ts +47 -0
- package/{module-shape.mjs → dist/module-shape.js} +278 -236
- package/dist/naming.d.ts +49 -0
- package/dist/naming.js +246 -0
- package/dist/observability.d.ts +25 -0
- package/dist/observability.js +245 -0
- package/dist/operations.d.ts +23 -0
- package/{operations.mjs → dist/operations.js} +410 -332
- package/dist/project-graph.d.ts +9 -0
- package/{project-graph.mjs → dist/project-graph.js} +8 -13
- package/dist/projections.d.ts +11 -0
- package/{projections.mjs → dist/projections.js} +60 -57
- package/dist/query-safety.d.ts +21 -0
- package/{query-safety.mjs → dist/query-safety.js} +92 -108
- package/dist/realtime.d.ts +15 -0
- package/{realtime.mjs → dist/realtime.js} +108 -106
- package/dist/resilience.d.ts +15 -0
- package/dist/resilience.js +319 -0
- package/dist/schema-authority.d.ts +15 -0
- package/{schema-authority.mjs → dist/schema-authority.js} +256 -220
- package/dist/service-deps.d.ts +17 -0
- package/{service-deps.mjs → dist/service-deps.js} +133 -130
- package/dist/service-isolation.d.ts +8 -0
- package/dist/service-isolation.js +76 -0
- package/dist/size-budget.d.ts +9 -0
- package/{size-budget.mjs → dist/size-budget.js} +27 -27
- package/dist/sonar-parity.d.ts +5 -0
- package/{sonar-parity.mjs → dist/sonar-parity.js} +7 -7
- package/dist/spec-no-skip.d.ts +9 -0
- package/dist/spec-no-skip.js +81 -0
- package/dist/spec-quality.d.ts +10 -0
- package/{spec-quality.mjs → dist/spec-quality.js} +103 -87
- package/dist/suppression.d.ts +26 -0
- package/{suppression.mjs → dist/suppression.js} +30 -45
- package/dist/temporal.d.ts +9 -0
- package/{temporal.mjs → dist/temporal.js} +75 -65
- package/dist/test-world.d.ts +28 -0
- package/{test-world.mjs → dist/test-world.js} +102 -83
- package/dist/testing.d.ts +51 -0
- package/dist/testing.js +368 -0
- package/dist/third-party-owner.d.ts +8 -0
- package/{third-party-owner.mjs → dist/third-party-owner.js} +105 -91
- package/dist/transport.d.ts +24 -0
- package/{transport.mjs → dist/transport.js} +279 -240
- package/dist/type-safety.d.ts +25 -0
- package/dist/type-safety.js +297 -0
- package/dist/unit-spec.d.ts +30 -0
- package/{unit-spec.mjs → dist/unit-spec.js} +473 -399
- package/dist/uploads.d.ts +9 -0
- package/{uploads.mjs → dist/uploads.js} +62 -54
- package/dist/user-copy.d.ts +9 -0
- package/{user-copy.mjs → dist/user-copy.js} +76 -67
- package/dist/webhooks.d.ts +16 -0
- package/{webhooks.mjs → dist/webhooks.js} +243 -231
- package/package.json +17 -8
- package/runtime/knowledge/hfs/canon-pins.yaml +17 -10
- package/async-discipline.mjs +0 -83
- package/comments.mjs +0 -416
- package/edge-hardening.mjs +0 -139
- package/health-ready.mjs +0 -539
- package/jwt-alg.mjs +0 -45
- package/lib/ast.mjs +0 -88
- package/lib/import-source.mjs +0 -104
- package/lib/specifier.mjs +0 -27
- package/lib/subject-values.mjs +0 -55
- package/lib/types.mjs +0 -133
- package/log-safety.mjs +0 -303
- package/module-layering.mjs +0 -270
- package/naming.mjs +0 -251
- package/observability.mjs +0 -241
- package/resilience.mjs +0 -304
- package/service-isolation.mjs +0 -75
- package/spec-no-skip.mjs +0 -85
- package/testing.mjs +0 -384
- package/type-safety.mjs +0 -323
package/edge-hardening.mjs
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
/** R261: every API entrypoint declares its browser and proxy boundary. */
|
|
2
|
-
import { keyName, staticText, walk } from "./lib/ast.mjs"
|
|
3
|
-
import { hfsOf } from "./lib/hfs.mjs"
|
|
4
|
-
|
|
5
|
-
const unwrap = (node) => {
|
|
6
|
-
while (node && ["TSAsExpression", "TSTypeAssertion", "TSSatisfiesExpression", "TSNonNullExpression", "AwaitExpression", "ChainExpression"].includes(node.type)) node = node.expression ?? node.argument
|
|
7
|
-
return node
|
|
8
|
-
}
|
|
9
|
-
const property = (node, name, constants = new Map(), seen = new Set()) => {
|
|
10
|
-
if (node?.type !== "ObjectExpression") return undefined
|
|
11
|
-
for (const entry of [...node.properties].reverse()) {
|
|
12
|
-
if (entry.type === "SpreadElement") {
|
|
13
|
-
const spread = resolve(entry.argument, constants, seen)
|
|
14
|
-
if (spread?.type !== "ObjectExpression") return undefined
|
|
15
|
-
const value = property(spread, name, constants, seen)
|
|
16
|
-
if (value !== undefined) return value
|
|
17
|
-
} else {
|
|
18
|
-
const key = entry.computed ? staticText(entry.key) : keyName(entry.key)
|
|
19
|
-
if (key === null) return undefined
|
|
20
|
-
if (key === name) return entry.value
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return undefined
|
|
24
|
-
}
|
|
25
|
-
const method = (node) => node?.type === "MemberExpression" ? (node.computed ? staticText(node.property) : keyName(node.property)) : null
|
|
26
|
-
|
|
27
|
-
/** Only declared API entrypoints are judged; workers have no browser edge. */
|
|
28
|
-
const isApiMain = (context) => {
|
|
29
|
-
const hfs = hfsOf(context)
|
|
30
|
-
const file = hfs.relative(context.filename ?? context.getFilename())
|
|
31
|
-
return hfs.slotOf(context.filename ?? context.getFilename()) === "be.app.api"
|
|
32
|
-
&& hfs.apps.some((app) => app.kind === "api" && file === `apps/${app.name}/src/main.ts`)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** Resolve local constants without making an identifier's spelling a security proof. */
|
|
36
|
-
const resolve = (node, constants, seen = new Set()) => {
|
|
37
|
-
node = unwrap(node)
|
|
38
|
-
if (node?.type === "Identifier" && constants.has(node.name) && !seen.has(node.name)) return resolve(constants.get(node.name), constants, new Set([...seen, node.name]))
|
|
39
|
-
if (node?.type === "MemberExpression" && method(node) !== null) {
|
|
40
|
-
const value = property(resolve(node.object, constants, seen), method(node), constants, seen)
|
|
41
|
-
if (value !== undefined) return resolve(value, constants, seen)
|
|
42
|
-
}
|
|
43
|
-
return node
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const allowedOrigin = (node) => {
|
|
47
|
-
const value = staticText(node)
|
|
48
|
-
if (value === null || value.includes("*") || value.endsWith("/")) return false
|
|
49
|
-
try {
|
|
50
|
-
const url = new URL(value)
|
|
51
|
-
return value === url.origin && (url.protocol === "https:" || (url.protocol === "http:" && ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname)))
|
|
52
|
-
} catch { return false }
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/** Config owns a dynamic allowlist; literal lists must contain exact origins. */
|
|
56
|
-
const allowlist = (node, constants) => {
|
|
57
|
-
node = resolve(node, constants)
|
|
58
|
-
if (node?.type === "MemberExpression") return method(node) === "allowedOrigins"
|
|
59
|
-
if (node?.type !== "ArrayExpression" || node.elements.length === 0) return false
|
|
60
|
-
return node.elements.every((entry) => entry?.type === "SpreadElement"
|
|
61
|
-
? allowlist(entry.argument, constants)
|
|
62
|
-
: allowedOrigin(resolve(entry, constants)))
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const hopCount = (node, constants) => {
|
|
66
|
-
node = resolve(node, constants)
|
|
67
|
-
return node?.type === "Literal" && Number.isSafeInteger(node.value) && node.value >= 0
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const audit = (program) => {
|
|
71
|
-
const constants = new Map()
|
|
72
|
-
const helpers = new Set()
|
|
73
|
-
const middleware = new Set()
|
|
74
|
-
const factories = new Set()
|
|
75
|
-
const applications = new Set()
|
|
76
|
-
const calls = []
|
|
77
|
-
walk(program, (node) => {
|
|
78
|
-
if (node.type === "ImportDeclaration") {
|
|
79
|
-
if (node.source.value === "@nestjs/core") {
|
|
80
|
-
for (const specifier of node.specifiers) if (specifier.imported?.name === "NestFactory") factories.add(specifier.local.name)
|
|
81
|
-
}
|
|
82
|
-
if (/^@modules\/platform\/http-security(?:\/|$)/.test(node.source.value)) {
|
|
83
|
-
for (const specifier of node.specifiers) {
|
|
84
|
-
if (["applyHttpSecurity", "configureHttpSecurity"].includes(specifier.imported?.name)) helpers.add(specifier.local.name)
|
|
85
|
-
if (["securityHeaders", "createSecurityHeadersMiddleware"].includes(specifier.imported?.name)) middleware.add(specifier.local.name)
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
if (node.type === "VariableDeclarator" && node.id.type === "Identifier" && node.init) constants.set(node.id.name, node.init)
|
|
90
|
-
if (node.type === "CallExpression") calls.push(node)
|
|
91
|
-
})
|
|
92
|
-
for (const [name, initializer] of constants) {
|
|
93
|
-
const node = resolve(initializer, constants)
|
|
94
|
-
if (node?.type === "CallExpression" && method(node.callee) === "create" && factories.has(node.callee.object.name)) applications.add(name)
|
|
95
|
-
}
|
|
96
|
-
const isApplication = (node) => {
|
|
97
|
-
if (node?.type === "Identifier" && applications.has(node.name)) return true
|
|
98
|
-
node = resolve(node, constants)
|
|
99
|
-
if (node?.type !== "CallExpression") return false
|
|
100
|
-
if (method(node.callee) === "create" && factories.has(node.callee.object.name)) return true
|
|
101
|
-
return ["getInstance", "getHttpAdapter"].includes(method(node.callee)) && isApplication(node.callee.object)
|
|
102
|
-
}
|
|
103
|
-
const direct = calls.filter((call) => call.callee.type === "MemberExpression" && isApplication(call.callee.object))
|
|
104
|
-
const applied = calls.filter((call) => call.callee.type === "Identifier" && helpers.has(call.callee.name) && isApplication(call.arguments[0]))
|
|
105
|
-
const helperCors = applied.some((call) => {
|
|
106
|
-
const config = resolve(call.arguments[1], constants)
|
|
107
|
-
return config?.type === "MemberExpression" || allowlist(property(config, "allowedOrigins", constants), constants)
|
|
108
|
-
})
|
|
109
|
-
const corsCalls = direct.filter((call) => method(call.callee) === "enableCors")
|
|
110
|
-
const cors = (helperCors || corsCalls.length > 0) && corsCalls.every((call) => allowlist(property(resolve(call.arguments[0], constants), "origin", constants), constants))
|
|
111
|
-
const headers = applied.length > 0 || direct.some((call) => method(call.callee) === "use" && call.arguments.some((argument) => {
|
|
112
|
-
const candidate = resolve(argument, constants)
|
|
113
|
-
return (candidate?.type === "Identifier" && middleware.has(candidate.name))
|
|
114
|
-
|| (candidate?.type === "CallExpression" && candidate.callee.type === "Identifier" && middleware.has(candidate.callee.name))
|
|
115
|
-
}))
|
|
116
|
-
const poweredCalls = direct.filter((call) => ["set", "enable", "disable"].includes(method(call.callee)) && staticText(call.arguments[0])?.toLowerCase() === "x-powered-by")
|
|
117
|
-
const poweredOff = (applied.length > 0 || poweredCalls.some((call) => method(call.callee) === "disable" || (method(call.callee) === "set" && call.arguments[1]?.value === false)))
|
|
118
|
-
&& poweredCalls.every((call) => method(call.callee) === "disable" || (method(call.callee) === "set" && call.arguments[1]?.value === false))
|
|
119
|
-
const proxyCalls = direct.filter((call) => method(call.callee) === "set" && staticText(call.arguments[0]) === "trust proxy")
|
|
120
|
-
const proxy = (proxyCalls.length > 0 || applied.length > 0)
|
|
121
|
-
&& proxyCalls.every((call) => hopCount(call.arguments[1], constants))
|
|
122
|
-
&& applied.every((call) => hopCount(property(resolve(call.arguments[2], constants), "trustProxy", constants), constants))
|
|
123
|
-
return { cors, headers: headers && poweredOff, proxy }
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const edgeRule = (field, code, description) => ({
|
|
127
|
-
meta: { type: "problem", docs: { description }, schema: [], messages: { boundary: `${code}: ${description}` } },
|
|
128
|
-
create(context) {
|
|
129
|
-
if (!isApiMain(context)) return {}
|
|
130
|
-
return { "Program:exit"(node) { if (!audit(node)[field]) context.report({ node, messageId: "boundary" }) } }
|
|
131
|
-
},
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
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.")
|
|
135
|
-
export const securityHeaders = edgeRule("headers", "BE_SECURITY_HEADERS", "Apply the platform/http-security response middleware and disable x-powered-by.")
|
|
136
|
-
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.")
|
|
137
|
-
|
|
138
|
-
export const rules = { "cors-allowlist": corsAllowlist, "security-headers": securityHeaders, "trust-proxy": trustProxy }
|
|
139
|
-
export const recommended = Object.fromEntries(Object.keys(rules).map((name) => [`starci-be/${name}`, "error"]))
|