milieu-cli 0.3.2 → 0.4.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 (330) hide show
  1. package/README.md +177 -76
  2. package/dist/bridges/context/agents-json.d.ts +0 -1
  3. package/dist/bridges/context/agents-json.js +21 -12
  4. package/dist/bridges/context/auth-clarity.d.ts +0 -1
  5. package/dist/bridges/context/auth-clarity.js +11 -9
  6. package/dist/bridges/context/auth-legibility.d.ts +2 -2
  7. package/dist/bridges/context/auth-legibility.js +67 -60
  8. package/dist/bridges/context/index.d.ts +1 -2
  9. package/dist/bridges/context/index.js +19 -40
  10. package/dist/bridges/context/oauth-metadata.d.ts +14 -0
  11. package/dist/bridges/context/oauth-metadata.js +127 -0
  12. package/dist/bridges/context/probe.d.ts +33 -0
  13. package/dist/bridges/context/probe.js +157 -0
  14. package/dist/bridges/context/rate-limits.d.ts +5 -2
  15. package/dist/bridges/context/rate-limits.js +27 -51
  16. package/dist/bridges/context/tos-contact.d.ts +13 -4
  17. package/dist/bridges/context/tos-contact.js +108 -46
  18. package/dist/bridges/context/versioning.d.ts +1 -2
  19. package/dist/bridges/context/versioning.js +42 -7
  20. package/dist/bridges/index.d.ts +0 -1
  21. package/dist/bridges/index.js +0 -1
  22. package/dist/bridges/reachability/crawler-policy.d.ts +30 -10
  23. package/dist/bridges/reachability/crawler-policy.js +41 -56
  24. package/dist/bridges/reachability/http-status.d.ts +3 -2
  25. package/dist/bridges/reachability/http-status.js +18 -3
  26. package/dist/bridges/reachability/https-check.d.ts +2 -2
  27. package/dist/bridges/reachability/https-check.js +6 -3
  28. package/dist/bridges/reachability/index.d.ts +1 -2
  29. package/dist/bridges/reachability/index.js +34 -43
  30. package/dist/bridges/reachability/meta-robots.d.ts +0 -13
  31. package/dist/bridges/reachability/meta-robots.js +89 -101
  32. package/dist/bridges/reachability/robots-parser.d.ts +7 -7
  33. package/dist/bridges/reachability/robots-parser.js +65 -15
  34. package/dist/bridges/reachability/robots-txt.d.ts +4 -2
  35. package/dist/bridges/reachability/robots-txt.js +33 -60
  36. package/dist/bridges/schema/descriptions.d.ts +2 -2
  37. package/dist/bridges/schema/descriptions.js +79 -44
  38. package/dist/bridges/schema/error-schemas.d.ts +2 -2
  39. package/dist/bridges/schema/error-schemas.js +31 -18
  40. package/dist/bridges/schema/index.d.ts +2 -2
  41. package/dist/bridges/schema/index.js +48 -30
  42. package/dist/bridges/schema/oas-types.d.ts +65 -26
  43. package/dist/bridges/schema/oas-types.js +37 -7
  44. package/dist/bridges/schema/operation-ids.d.ts +2 -2
  45. package/dist/bridges/schema/operation-ids.js +2 -3
  46. package/dist/bridges/schema/required-fields.d.ts +2 -2
  47. package/dist/bridges/schema/required-fields.js +12 -10
  48. package/dist/bridges/schema/schema-sources.d.ts +19 -0
  49. package/dist/bridges/schema/schema-sources.js +182 -0
  50. package/dist/bridges/schema/schema-types.d.ts +2 -2
  51. package/dist/bridges/schema/schema-types.js +20 -21
  52. package/dist/bridges/separation/api-presence.d.ts +3 -15
  53. package/dist/bridges/separation/api-presence.js +34 -85
  54. package/dist/bridges/separation/developer-docs.d.ts +6 -18
  55. package/dist/bridges/separation/developer-docs.js +100 -99
  56. package/dist/bridges/separation/docs-discovery.d.ts +28 -0
  57. package/dist/bridges/separation/docs-discovery.js +95 -0
  58. package/dist/bridges/separation/evidence-summary.d.ts +2 -0
  59. package/dist/bridges/separation/evidence-summary.js +67 -0
  60. package/dist/bridges/separation/index.d.ts +2 -19
  61. package/dist/bridges/separation/index.js +35 -39
  62. package/dist/bridges/separation/published-routes.d.ts +69 -0
  63. package/dist/bridges/separation/published-routes.js +271 -0
  64. package/dist/bridges/separation/sdk-references.d.ts +8 -3
  65. package/dist/bridges/separation/sdk-references.js +86 -61
  66. package/dist/bridges/separation/webhook-support.d.ts +3 -23
  67. package/dist/bridges/separation/webhook-support.js +61 -162
  68. package/dist/bridges/standards/a2a-agent-card.d.ts +0 -1
  69. package/dist/bridges/standards/a2a-agent-card.js +24 -9
  70. package/dist/bridges/standards/graphql.d.ts +3 -4
  71. package/dist/bridges/standards/graphql.js +70 -66
  72. package/dist/bridges/standards/index.d.ts +1 -2
  73. package/dist/bridges/standards/index.js +57 -47
  74. package/dist/bridges/standards/json-ld.d.ts +25 -11
  75. package/dist/bridges/standards/json-ld.js +114 -56
  76. package/dist/bridges/standards/llms-txt.d.ts +4 -2
  77. package/dist/bridges/standards/llms-txt.js +46 -32
  78. package/dist/bridges/standards/markdown-negotiation.d.ts +4 -1
  79. package/dist/bridges/standards/markdown-negotiation.js +16 -11
  80. package/dist/bridges/standards/mcp.d.ts +3 -12
  81. package/dist/bridges/standards/mcp.js +89 -132
  82. package/dist/bridges/standards/openapi.d.ts +7 -15
  83. package/dist/bridges/standards/openapi.js +657 -207
  84. package/dist/bridges/standards/probe-evidence.d.ts +30 -0
  85. package/dist/bridges/standards/probe-evidence.js +90 -0
  86. package/dist/bridges/standards/schema-org.d.ts +15 -9
  87. package/dist/bridges/standards/schema-org.js +38 -64
  88. package/dist/bridges/standards/sitemap.d.ts +2 -3
  89. package/dist/bridges/standards/sitemap.js +161 -169
  90. package/dist/bridges/standards/well-known.d.ts +3 -7
  91. package/dist/bridges/standards/well-known.js +28 -12
  92. package/dist/cli/index.d.ts +1 -1
  93. package/dist/cli/index.js +107 -22
  94. package/dist/cli/journey-commands.d.ts +3 -0
  95. package/dist/cli/journey-commands.js +35 -0
  96. package/dist/cli/read-report.d.ts +2 -0
  97. package/dist/cli/read-report.js +11 -0
  98. package/dist/core/bridge-output.d.ts +11 -0
  99. package/dist/core/bridge-output.js +86 -0
  100. package/dist/core/bridge-session.d.ts +28 -0
  101. package/dist/core/bridge-session.js +58 -0
  102. package/dist/core/bridge-worker.d.ts +1 -0
  103. package/dist/core/bridge-worker.js +66 -0
  104. package/dist/core/diff.d.ts +79 -0
  105. package/dist/core/diff.js +499 -0
  106. package/dist/core/explanations.d.ts +1 -3
  107. package/dist/core/explanations.js +36 -59
  108. package/dist/core/index.d.ts +4 -2
  109. package/dist/core/index.js +2 -3
  110. package/dist/core/scan-options.d.ts +0 -1
  111. package/dist/core/scan-options.js +14 -6
  112. package/dist/core/scan.d.ts +0 -1
  113. package/dist/core/scan.js +91 -41
  114. package/dist/core/scoring.d.ts +6 -0
  115. package/dist/core/scoring.js +27 -0
  116. package/dist/core/types.d.ts +97 -61
  117. package/dist/core/types.js +9 -3
  118. package/dist/core/validate-report.d.ts +5 -0
  119. package/dist/core/validate-report.js +95 -0
  120. package/dist/core/version.d.ts +0 -1
  121. package/dist/core/version.js +0 -1
  122. package/dist/index.d.ts +0 -1
  123. package/dist/index.js +0 -1
  124. package/dist/journey/body-worker.d.ts +27 -0
  125. package/dist/journey/body-worker.js +140 -0
  126. package/dist/journey/case.d.ts +74 -0
  127. package/dist/journey/case.js +187 -0
  128. package/dist/journey/cli.d.ts +14 -0
  129. package/dist/journey/cli.js +226 -0
  130. package/dist/journey/compare.d.ts +43 -0
  131. package/dist/journey/compare.js +83 -0
  132. package/dist/journey/contracts.d.ts +143 -0
  133. package/dist/journey/contracts.js +37 -0
  134. package/dist/journey/decision.d.ts +72 -0
  135. package/dist/journey/decision.js +121 -0
  136. package/dist/journey/demo.d.ts +36 -0
  137. package/dist/journey/demo.js +137 -0
  138. package/dist/journey/document.d.ts +8 -0
  139. package/dist/journey/document.js +113 -0
  140. package/dist/journey/excerpt.d.ts +6 -0
  141. package/dist/journey/excerpt.js +54 -0
  142. package/dist/journey/name-guidance.d.ts +2 -0
  143. package/dist/journey/name-guidance.js +41 -0
  144. package/dist/journey/providers.d.ts +34 -0
  145. package/dist/journey/providers.js +197 -0
  146. package/dist/journey/report-validation.d.ts +3 -0
  147. package/dist/journey/report-validation.js +457 -0
  148. package/dist/journey/runner.d.ts +12 -0
  149. package/dist/journey/runner.js +321 -0
  150. package/dist/journey/scope.d.ts +8 -0
  151. package/dist/journey/scope.js +50 -0
  152. package/dist/journey/transport.d.ts +3 -0
  153. package/dist/journey/transport.js +45 -0
  154. package/dist/journey/verify.d.ts +21 -0
  155. package/dist/journey/verify.js +213 -0
  156. package/dist/render/colors.d.ts +6 -7
  157. package/dist/render/colors.js +16 -25
  158. package/dist/render/discovery-guidance.d.ts +3 -0
  159. package/dist/render/discovery-guidance.js +66 -0
  160. package/dist/render/format-bridge.d.ts +1 -2
  161. package/dist/render/format-bridge.js +22 -17
  162. package/dist/render/format-diff.d.ts +2 -0
  163. package/dist/render/format-diff.js +169 -0
  164. package/dist/render/format-scan.d.ts +0 -1
  165. package/dist/render/format-scan.js +6 -4
  166. package/dist/render/format-verbose.d.ts +0 -1
  167. package/dist/render/format-verbose.js +7 -4
  168. package/dist/render/index.d.ts +0 -1
  169. package/dist/render/index.js +1 -2
  170. package/dist/render/oauth-observations.d.ts +4 -0
  171. package/dist/render/oauth-observations.js +27 -0
  172. package/dist/render/progress-bar.d.ts +1 -2
  173. package/dist/render/progress-bar.js +8 -6
  174. package/dist/render/robots-inventory.d.ts +3 -0
  175. package/dist/render/robots-inventory.js +38 -0
  176. package/dist/render/symbols.d.ts +4 -10
  177. package/dist/render/symbols.js +15 -17
  178. package/dist/render/terminal-text.d.ts +1 -3
  179. package/dist/render/terminal-text.js +1 -5
  180. package/dist/utils/analysis-worker-entry.d.ts +3 -0
  181. package/dist/utils/analysis-worker-entry.js +12 -0
  182. package/dist/utils/analysis-worker.d.ts +12 -0
  183. package/dist/utils/analysis-worker.js +54 -0
  184. package/dist/utils/html.d.ts +39 -0
  185. package/dist/utils/html.js +261 -0
  186. package/dist/utils/http-client.d.ts +24 -17
  187. package/dist/utils/http-client.js +166 -200
  188. package/dist/utils/http-types.d.ts +43 -0
  189. package/dist/utils/http-types.js +11 -0
  190. package/dist/utils/index.d.ts +0 -1
  191. package/dist/utils/index.js +0 -1
  192. package/dist/utils/package-registry.d.ts +11 -0
  193. package/dist/utils/package-registry.js +69 -0
  194. package/dist/utils/read-json-file.d.ts +3 -0
  195. package/dist/utils/read-json-file.js +41 -0
  196. package/dist/utils/record.d.ts +1 -0
  197. package/dist/utils/record.js +3 -0
  198. package/dist/utils/response-body.d.ts +7 -0
  199. package/dist/utils/response-body.js +71 -0
  200. package/dist/utils/ssrf.d.ts +11 -15
  201. package/dist/utils/ssrf.js +80 -44
  202. package/dist/utils/terminal-text.d.ts +2 -0
  203. package/dist/utils/terminal-text.js +4 -0
  204. package/dist/utils/url.d.ts +29 -1
  205. package/dist/utils/url.js +147 -17
  206. package/docs/examples/onboarding/account-claim.json +25 -0
  207. package/docs/examples/onboarding/pages/account-claim.html +3 -0
  208. package/docs/examples/onboarding/pages/production-activation.html +3 -0
  209. package/docs/examples/onboarding/pages/test-credential.html +3 -0
  210. package/docs/examples/onboarding/production-activation.json +25 -0
  211. package/docs/examples/onboarding/test-credential.json +25 -0
  212. package/docs/journey-qualification.md +46 -0
  213. package/docs/journeys.md +83 -0
  214. package/package.json +28 -8
  215. package/dist/bridges/context/agents-json.d.ts.map +0 -1
  216. package/dist/bridges/context/agents-json.js.map +0 -1
  217. package/dist/bridges/context/auth-clarity.d.ts.map +0 -1
  218. package/dist/bridges/context/auth-clarity.js.map +0 -1
  219. package/dist/bridges/context/auth-legibility.d.ts.map +0 -1
  220. package/dist/bridges/context/auth-legibility.js.map +0 -1
  221. package/dist/bridges/context/index.d.ts.map +0 -1
  222. package/dist/bridges/context/index.js.map +0 -1
  223. package/dist/bridges/context/rate-limits.d.ts.map +0 -1
  224. package/dist/bridges/context/rate-limits.js.map +0 -1
  225. package/dist/bridges/context/tos-contact.d.ts.map +0 -1
  226. package/dist/bridges/context/tos-contact.js.map +0 -1
  227. package/dist/bridges/context/versioning.d.ts.map +0 -1
  228. package/dist/bridges/context/versioning.js.map +0 -1
  229. package/dist/bridges/index.d.ts.map +0 -1
  230. package/dist/bridges/index.js.map +0 -1
  231. package/dist/bridges/reachability/crawler-policy.d.ts.map +0 -1
  232. package/dist/bridges/reachability/crawler-policy.js.map +0 -1
  233. package/dist/bridges/reachability/http-status.d.ts.map +0 -1
  234. package/dist/bridges/reachability/http-status.js.map +0 -1
  235. package/dist/bridges/reachability/https-check.d.ts.map +0 -1
  236. package/dist/bridges/reachability/https-check.js.map +0 -1
  237. package/dist/bridges/reachability/index.d.ts.map +0 -1
  238. package/dist/bridges/reachability/index.js.map +0 -1
  239. package/dist/bridges/reachability/meta-robots.d.ts.map +0 -1
  240. package/dist/bridges/reachability/meta-robots.js.map +0 -1
  241. package/dist/bridges/reachability/robots-parser.d.ts.map +0 -1
  242. package/dist/bridges/reachability/robots-parser.js.map +0 -1
  243. package/dist/bridges/reachability/robots-txt.d.ts.map +0 -1
  244. package/dist/bridges/reachability/robots-txt.js.map +0 -1
  245. package/dist/bridges/schema/descriptions.d.ts.map +0 -1
  246. package/dist/bridges/schema/descriptions.js.map +0 -1
  247. package/dist/bridges/schema/error-schemas.d.ts.map +0 -1
  248. package/dist/bridges/schema/error-schemas.js.map +0 -1
  249. package/dist/bridges/schema/index.d.ts.map +0 -1
  250. package/dist/bridges/schema/index.js.map +0 -1
  251. package/dist/bridges/schema/oas-types.d.ts.map +0 -1
  252. package/dist/bridges/schema/oas-types.js.map +0 -1
  253. package/dist/bridges/schema/operation-ids.d.ts.map +0 -1
  254. package/dist/bridges/schema/operation-ids.js.map +0 -1
  255. package/dist/bridges/schema/required-fields.d.ts.map +0 -1
  256. package/dist/bridges/schema/required-fields.js.map +0 -1
  257. package/dist/bridges/schema/schema-types.d.ts.map +0 -1
  258. package/dist/bridges/schema/schema-types.js.map +0 -1
  259. package/dist/bridges/separation/api-presence.d.ts.map +0 -1
  260. package/dist/bridges/separation/api-presence.js.map +0 -1
  261. package/dist/bridges/separation/developer-docs.d.ts.map +0 -1
  262. package/dist/bridges/separation/developer-docs.js.map +0 -1
  263. package/dist/bridges/separation/index.d.ts.map +0 -1
  264. package/dist/bridges/separation/index.js.map +0 -1
  265. package/dist/bridges/separation/sdk-references.d.ts.map +0 -1
  266. package/dist/bridges/separation/sdk-references.js.map +0 -1
  267. package/dist/bridges/separation/webhook-support.d.ts.map +0 -1
  268. package/dist/bridges/separation/webhook-support.js.map +0 -1
  269. package/dist/bridges/standards/a2a-agent-card.d.ts.map +0 -1
  270. package/dist/bridges/standards/a2a-agent-card.js.map +0 -1
  271. package/dist/bridges/standards/graphql.d.ts.map +0 -1
  272. package/dist/bridges/standards/graphql.js.map +0 -1
  273. package/dist/bridges/standards/index.d.ts.map +0 -1
  274. package/dist/bridges/standards/index.js.map +0 -1
  275. package/dist/bridges/standards/json-ld.d.ts.map +0 -1
  276. package/dist/bridges/standards/json-ld.js.map +0 -1
  277. package/dist/bridges/standards/llms-txt.d.ts.map +0 -1
  278. package/dist/bridges/standards/llms-txt.js.map +0 -1
  279. package/dist/bridges/standards/markdown-negotiation.d.ts.map +0 -1
  280. package/dist/bridges/standards/markdown-negotiation.js.map +0 -1
  281. package/dist/bridges/standards/mcp.d.ts.map +0 -1
  282. package/dist/bridges/standards/mcp.js.map +0 -1
  283. package/dist/bridges/standards/openapi.d.ts.map +0 -1
  284. package/dist/bridges/standards/openapi.js.map +0 -1
  285. package/dist/bridges/standards/schema-org.d.ts.map +0 -1
  286. package/dist/bridges/standards/schema-org.js.map +0 -1
  287. package/dist/bridges/standards/sitemap.d.ts.map +0 -1
  288. package/dist/bridges/standards/sitemap.js.map +0 -1
  289. package/dist/bridges/standards/well-known.d.ts.map +0 -1
  290. package/dist/bridges/standards/well-known.js.map +0 -1
  291. package/dist/cli/index.d.ts.map +0 -1
  292. package/dist/cli/index.js.map +0 -1
  293. package/dist/core/explanations.d.ts.map +0 -1
  294. package/dist/core/explanations.js.map +0 -1
  295. package/dist/core/index.d.ts.map +0 -1
  296. package/dist/core/index.js.map +0 -1
  297. package/dist/core/scan-options.d.ts.map +0 -1
  298. package/dist/core/scan-options.js.map +0 -1
  299. package/dist/core/scan.d.ts.map +0 -1
  300. package/dist/core/scan.js.map +0 -1
  301. package/dist/core/types.d.ts.map +0 -1
  302. package/dist/core/types.js.map +0 -1
  303. package/dist/core/version.d.ts.map +0 -1
  304. package/dist/core/version.js.map +0 -1
  305. package/dist/index.d.ts.map +0 -1
  306. package/dist/index.js.map +0 -1
  307. package/dist/render/colors.d.ts.map +0 -1
  308. package/dist/render/colors.js.map +0 -1
  309. package/dist/render/format-bridge.d.ts.map +0 -1
  310. package/dist/render/format-bridge.js.map +0 -1
  311. package/dist/render/format-scan.d.ts.map +0 -1
  312. package/dist/render/format-scan.js.map +0 -1
  313. package/dist/render/format-verbose.d.ts.map +0 -1
  314. package/dist/render/format-verbose.js.map +0 -1
  315. package/dist/render/index.d.ts.map +0 -1
  316. package/dist/render/index.js.map +0 -1
  317. package/dist/render/progress-bar.d.ts.map +0 -1
  318. package/dist/render/progress-bar.js.map +0 -1
  319. package/dist/render/symbols.d.ts.map +0 -1
  320. package/dist/render/symbols.js.map +0 -1
  321. package/dist/render/terminal-text.d.ts.map +0 -1
  322. package/dist/render/terminal-text.js.map +0 -1
  323. package/dist/utils/http-client.d.ts.map +0 -1
  324. package/dist/utils/http-client.js.map +0 -1
  325. package/dist/utils/index.d.ts.map +0 -1
  326. package/dist/utils/index.js.map +0 -1
  327. package/dist/utils/ssrf.d.ts.map +0 -1
  328. package/dist/utils/ssrf.js.map +0 -1
  329. package/dist/utils/url.d.ts.map +0 -1
  330. package/dist/utils/url.js.map +0 -1
@@ -1,6 +1,9 @@
1
+ import { mediaType } from "../../utils/http-types.js";
1
2
  import { httpGet } from "../../utils/http-client.js";
3
+ import { transportFailureAt } from "./http-status.js";
4
+ import { directiveInventory } from "./crawler-policy.js";
2
5
  import { parseRobotsTxt } from "./robots-parser.js";
3
- const DIRECTIVE_PATTERN = /\b(user-agent|disallow|allow)\s*:/i;
6
+ const DIRECTIVE_PATTERN = /^[ \t]*(?:user-agent|disallow|allow|sitemap)[ \t]*:/im;
4
7
  /**
5
8
  * Fetch and parse robots.txt for the given domain.
6
9
  *
@@ -11,77 +14,47 @@ export async function checkRobotsTxt(origin, timeout) {
11
14
  const id = "robots_txt";
12
15
  const label = "robots.txt";
13
16
  const domain = new URL(origin).host;
14
- const result = await httpGet(origin + "/robots.txt", {
15
- timeout,
17
+ const url = origin + "/robots.txt";
18
+ const result = await httpGet(url, {
19
+ timeout, maxBodyBytes: 500 * 1024,
16
20
  });
21
+ function observation(check, inventory, parsed = null) {
22
+ return { parsed, coverage: inventory.coverage, check: { ...check, data: { ...check.data, directiveInventory: inventory } } };
23
+ }
17
24
  if (!result.ok) {
18
25
  if (result.error.kind === "request_budget_exhausted") {
19
- return {
20
- check: { id, label, status: "error", detail: "robots.txt probe skipped: scan request budget exhausted" },
21
- parsed: null,
22
- };
26
+ return observation({ id, label, status: "error", detail: "robots.txt probe skipped: scan request budget exhausted" }, { coverage: "unavailable" });
23
27
  }
24
- // 404 = no robots.txt
28
+ const status = result.error.statusCode;
29
+ // RFC 9309 permits crawling when robots.txt returns 4xx.
25
30
  if (result.error.kind === "http_error" &&
26
- result.error.statusCode === 404) {
27
- return {
28
- check: {
29
- id,
30
- label,
31
- status: "partial",
32
- detail: `No robots.txt found at ${domain}`,
33
- },
34
- parsed: null,
35
- };
31
+ status !== undefined && status >= 400 && status < 500) {
32
+ return observation({ id, label, status: "partial", detail: `No robots.txt found at ${domain} (HTTP ${status})`, data: { statusCode: status } }, { coverage: "absent" });
36
33
  }
37
34
  // Other errors
38
- return {
39
- check: {
40
- id,
41
- label,
42
- status: "fail",
43
- detail: result.error.message,
44
- },
45
- parsed: null,
46
- };
35
+ return { ...observation({ id, label, status: "error", detail: result.error.message }, { coverage: "unavailable" }),
36
+ transportFailure: transportFailureAt(result, url) };
47
37
  }
48
38
  // Success -- validate content type
49
- const contentType = result.headers["content-type"] ?? "";
50
- const isTextPlain = contentType.toLowerCase().includes("text/plain");
39
+ const isTextPlain = mediaType(result.headers) === "text/plain";
40
+ const onlyComments = result.body.split(/[\r\n]/).every(line => !line.trim() || line.trimStart().startsWith("#"));
51
41
  const hasDirectives = DIRECTIVE_PATTERN.test(result.body);
52
- if (!isTextPlain && !hasDirectives) {
53
- return {
54
- check: {
55
- id,
56
- label,
57
- status: "fail",
58
- detail: `robots.txt at ${domain} is not a text file (robots.txt is per-origin)`,
59
- },
60
- parsed: null,
61
- };
42
+ if (result.body.trimStart().startsWith("<") || !(hasDirectives || (isTextPlain && onlyComments))) {
43
+ return observation({ id, label, status: "fail", detail: `robots.txt at ${domain} is not a text file (robots.txt is per-origin)` }, { coverage: "unavailable" });
62
44
  }
63
45
  // Parse
64
- const parsed = parseRobotsTxt(result.body);
46
+ const parsed = parseRobotsTxt(result.body, result.url);
47
+ const inventory = result.bodyIncomplete || result.status === 206 || result.headers["content-range"] !== undefined
48
+ ? { coverage: "incomplete" } : directiveInventory(parsed);
49
+ if (inventory.coverage === "incomplete") {
50
+ return observation({ id, label, status: "error", detail: `Only part of robots.txt at ${domain} was available` }, inventory);
51
+ }
65
52
  if (parsed.ruleCount === 0 && parsed.groups.length === 0) {
66
- return {
67
- check: {
68
- id,
69
- label,
70
- status: "partial",
71
- detail: `robots.txt at ${domain} exists but has no rules`,
72
- },
73
- parsed,
74
- };
53
+ return observation({ id, label, status: "partial", detail: `robots.txt at ${domain} exists but has no rules` }, inventory, parsed);
75
54
  }
76
- return {
77
- check: {
78
- id,
79
- label,
80
- status: "pass",
81
- detail: `robots.txt at ${domain} found with ${parsed.ruleCount} rules`,
82
- data: { ruleCount: parsed.ruleCount, sitemaps: parsed.sitemaps },
83
- },
84
- parsed,
85
- };
55
+ // A clipped URL names a different sitemap, so an over-long one is counted but not stored.
56
+ const sitemaps = parsed.sitemaps.filter(href => href.length <= 2048).slice(0, 32);
57
+ return observation({ id, label, status: "pass", detail: `robots.txt at ${domain} found with ${parsed.ruleCount} rules`,
58
+ data: { ruleCount: parsed.ruleCount, sitemaps, sitemapsTotal: parsed.sitemapsTotal,
59
+ ...(sitemaps.length < parsed.sitemapsTotal && { sitemapsTruncated: true }) } }, inventory, parsed);
86
60
  }
87
- //# sourceMappingURL=robots-txt.js.map
@@ -1,4 +1,4 @@
1
1
  import type { Check } from "../../core/types.js";
2
2
  import type { ParsedOpenApiSpec } from "./oas-types.js";
3
- export declare function checkDescriptions(spec: ParsedOpenApiSpec | undefined): Check;
4
- //# sourceMappingURL=descriptions.d.ts.map
3
+ import { type SchemaWorkBudget } from "./schema-sources.js";
4
+ export declare function checkDescriptions(spec: ParsedOpenApiSpec | undefined, ops?: [string, string, import("./oas-types.js").OasOperation][], budget?: SchemaWorkBudget): Check;
@@ -1,56 +1,91 @@
1
1
  import { collectOperations } from "./oas-types.js";
2
- export function checkDescriptions(spec) {
2
+ import { operationParameters, requestSchemas, schemaForFields } from "./schema-sources.js";
3
+ /**
4
+ * Keys a parameter's name or description for counting it once. A string is its
5
+ * own key. Only strings are graded, so other values need not be told apart
6
+ * exactly: a primitive is keyed as JSON prints it, and every object or array
7
+ * shares one key, because printing one can expand shared YAML aliases far past
8
+ * the size of the document.
9
+ */
10
+ function valueTokens() {
11
+ const printed = new Map();
12
+ return value => {
13
+ if (typeof value === "string")
14
+ return value;
15
+ const text = typeof value === "object" && value !== null ? "object" : JSON.stringify(value) ?? "null";
16
+ let token = printed.get(text);
17
+ if (token === undefined)
18
+ printed.set(text, token = printed.size);
19
+ return token;
20
+ };
21
+ }
22
+ export function checkDescriptions(spec, ops = collectOperations(spec), budget) {
23
+ budget?.charge(ops.length);
3
24
  const id = "schema_descriptions";
4
25
  const label = "Field Descriptions";
5
- const ops = collectOperations(spec);
6
- const items = [];
7
- let queryCount = 0;
8
- let bodySchemaCount = 0;
9
- for (const [, , op] of ops) {
10
- if (Array.isArray(op.parameters)) {
11
- for (const param of op.parameters) {
12
- if (param?.in === "path") {
13
- items.push({ hasDescription: typeof param.description === "string" && param.description.trim() !== "" });
14
- }
15
- else if (param?.in === "query" && queryCount < 20) {
16
- queryCount++;
17
- items.push({ hasDescription: typeof param.description === "string" && param.description.trim() !== "" });
18
- }
19
- if (items.length >= 30)
20
- break;
21
- }
26
+ let sampled = 0;
27
+ let withDescription = 0;
28
+ // A parameter counts once per path, location, name and description, however
29
+ // many operations inherit it. Only operations of one path can repeat it, so
30
+ // what a path has counted is dropped after the last of them.
31
+ const counted = new Map();
32
+ const lastOperation = new Map(ops.map(([path], index) => [path, index]));
33
+ const nameToken = valueTokens();
34
+ const descriptionToken = valueTokens();
35
+ // Looking for text reads a blank description to its end, so one shared by
36
+ // many operations is read once.
37
+ const hasText = new Map();
38
+ function count(description) {
39
+ sampled++;
40
+ if (typeof description !== "string")
41
+ return;
42
+ let text = hasText.get(description);
43
+ if (text === undefined)
44
+ hasText.set(description, text = description.trim() !== "");
45
+ if (text)
46
+ withDescription++;
47
+ }
48
+ for (const [index, [path, , op]] of ops.entries()) {
49
+ let names = counted.get(path);
50
+ for (const param of operationParameters(spec, path, op, budget)) {
51
+ if (param.$ref !== undefined)
52
+ return { id, label, status: "error", detail: "A referenced parameter could not be inspected" };
53
+ if (param.in !== "path" && param.in !== "query")
54
+ continue;
55
+ if (!names)
56
+ counted.set(path, names = { path: new Map(), query: new Map() });
57
+ const name = nameToken(param.name);
58
+ let descriptions = names[param.in].get(name);
59
+ if (!descriptions)
60
+ names[param.in].set(name, descriptions = new Set());
61
+ const description = descriptionToken(param.description);
62
+ if (descriptions.has(description))
63
+ continue;
64
+ descriptions.add(description);
65
+ count(param.description);
22
66
  }
23
- if (items.length >= 30)
24
- break;
25
- if (op.requestBody?.content && bodySchemaCount < 3) {
26
- for (const mediaType of Object.values(op.requestBody.content)) {
27
- if (bodySchemaCount >= 3)
28
- break;
29
- const schema = mediaType?.schema;
30
- if (!schema?.properties)
31
- continue;
32
- bodySchemaCount++;
33
- for (const prop of Object.values(schema.properties)) {
34
- items.push({ hasDescription: typeof prop?.description === "string" && prop.description.trim() !== "" });
35
- if (items.length >= 30)
36
- break;
37
- }
38
- if (items.length >= 30)
39
- break;
67
+ for (const raw of requestSchemas(spec, path, op, budget)) {
68
+ const schema = schemaForFields(spec, raw, budget);
69
+ if (!schema)
70
+ return { id, label, status: "error", detail: "Could not inspect all request fields due to a reference or schema composition" };
71
+ const properties = Object.values(schema.properties ?? {});
72
+ budget?.charge(properties.length);
73
+ for (const field of properties) {
74
+ const prop = schemaForFields(spec, field, budget);
75
+ if (!prop && field && typeof field === "object")
76
+ return { id, label, status: "error", detail: "Could not inspect a referenced or composed request property" };
77
+ count(prop?.description);
40
78
  }
41
79
  }
42
- if (items.length >= 30)
43
- break;
80
+ if (lastOperation.get(path) === index)
81
+ counted.delete(path);
44
82
  }
45
- const sampled = items.length;
46
83
  if (sampled === 0)
47
- return { id, label, status: "pass", detail: "No parameters or properties to evaluate", data: { sampled: 0, withDescription: 0 } };
48
- const withDescription = items.filter((i) => i.hasDescription).length;
84
+ return { id, label, status: "error", detail: "No parameters or properties to evaluate", data: { sampled, withDescription } };
49
85
  const ratio = withDescription / sampled;
50
86
  if (ratio >= 0.8)
51
- return { id, label, status: "pass", detail: `${withDescription} of ${sampled} sampled fields have descriptions`, data: { sampled, withDescription } };
87
+ return { id, label, status: "pass", detail: `${withDescription} of ${sampled} fields have descriptions`, data: { sampled, withDescription } };
52
88
  if (ratio >= 0.4)
53
- return { id, label, status: "partial", detail: `${withDescription} of ${sampled} sampled fields have descriptions`, data: { sampled, withDescription } };
54
- return { id, label, status: "fail", detail: `Only ${withDescription} of ${sampled} sampled fields have descriptions`, data: { sampled, withDescription } };
89
+ return { id, label, status: "partial", detail: `${withDescription} of ${sampled} fields have descriptions`, data: { sampled, withDescription } };
90
+ return { id, label, status: "fail", detail: `Only ${withDescription} of ${sampled} fields have descriptions`, data: { sampled, withDescription } };
55
91
  }
56
- //# sourceMappingURL=descriptions.js.map
@@ -1,4 +1,4 @@
1
1
  import type { Check } from "../../core/types.js";
2
2
  import type { ParsedOpenApiSpec } from "./oas-types.js";
3
- export declare function checkErrorSchemas(spec: ParsedOpenApiSpec | undefined): Check;
4
- //# sourceMappingURL=error-schemas.d.ts.map
3
+ import { type SchemaWorkBudget } from "./schema-sources.js";
4
+ export declare function checkErrorSchemas(spec: ParsedOpenApiSpec | undefined, ops?: [string, string, import("./oas-types.js").OasOperation][], budget?: SchemaWorkBudget): Check;
@@ -1,30 +1,43 @@
1
1
  import { collectOperations } from "./oas-types.js";
2
- export function checkErrorSchemas(spec) {
2
+ import { responseSchemas } from "./schema-sources.js";
3
+ export function checkErrorSchemas(spec, ops = collectOperations(spec), budget) {
4
+ budget?.charge(ops.length);
3
5
  const id = "schema_error_responses";
4
6
  const label = "Error Response Schemas";
5
- const ops = collectOperations(spec);
6
7
  let total4xx = 0;
8
+ let totalDefault = 0;
7
9
  let withSchema = 0;
10
+ let defaultWithSchema = 0;
8
11
  for (const [, , op] of ops) {
9
12
  if (!op.responses)
10
13
  continue;
11
- for (const [code, resp] of Object.entries(op.responses)) {
12
- if (!code.startsWith("4"))
13
- continue;
14
- total4xx++;
15
- if (resp?.content) {
16
- const hasSchema = Object.values(resp.content).some((mt) => mt?.schema != null);
17
- if (hasSchema)
18
- withSchema++;
14
+ const responseCodes = Object.keys(op.responses);
15
+ budget?.charge(responseCodes.length);
16
+ const explicit = responseCodes.filter(code => /^4(?:\d{2}|XX)$/i.test(code));
17
+ const codes = explicit.length ? explicit : Object.hasOwn(op.responses, "default") ? ["default"] : [];
18
+ for (const code of codes) {
19
+ if (code === "default")
20
+ totalDefault++;
21
+ else
22
+ total4xx++;
23
+ const schemas = responseSchemas(spec, op.responses[code], budget);
24
+ if (schemas.some(schema => schema !== undefined)) {
25
+ withSchema++;
26
+ if (code === "default")
27
+ defaultWithSchema++;
28
+ }
29
+ else if (schemas.includes(undefined)) {
30
+ return { id, label, status: "error", detail: "A referenced error response or body schema could not be inspected" };
19
31
  }
20
32
  }
21
33
  }
22
- if (total4xx === 0)
23
- return { id, label, status: "fail", detail: "No 4xx error responses defined in spec", data: { total4xx: 0, withSchema: 0 } };
24
- if (withSchema === total4xx)
25
- return { id, label, status: "pass", detail: `All ${total4xx} error responses have body schemas`, data: { total4xx, withSchema } };
26
- if (withSchema >= 1)
27
- return { id, label, status: "partial", detail: `${withSchema} of ${total4xx} error responses have body schemas`, data: { total4xx, withSchema } };
28
- return { id, label, status: "fail", detail: `None of ${total4xx} error responses have body schemas`, data: { total4xx, withSchema: 0 } };
34
+ const total = total4xx + totalDefault;
35
+ const data = { total4xx, withSchema, ...(totalDefault > 0 && { totalDefault, defaultWithSchema }) };
36
+ if (!total)
37
+ return { id, label, status: "fail", detail: "No 4xx or default error responses defined in spec", data };
38
+ if (withSchema === total)
39
+ return { id, label, status: "pass", detail: `All ${total} error responses have body schemas`, data };
40
+ if (withSchema)
41
+ return { id, label, status: "partial", detail: `${withSchema} of ${total} error responses have body schemas`, data };
42
+ return { id, label, status: "fail", detail: `None of ${total} error responses have body schemas`, data };
29
43
  }
30
- //# sourceMappingURL=error-schemas.js.map
@@ -1,3 +1,3 @@
1
1
  import type { BridgeResult, ScanContext } from "../../core/types.js";
2
- export declare function runSchemaBridge(ctx: ScanContext): Promise<BridgeResult>;
3
- //# sourceMappingURL=index.d.ts.map
2
+ import { SchemaWorkBudget } from "./schema-sources.js";
3
+ export declare function runSchemaBridge(ctx: ScanContext, budget?: SchemaWorkBudget): Promise<BridgeResult<4>>;
@@ -1,3 +1,6 @@
1
+ import { scoreChecks } from "../../core/scoring.js";
2
+ import { collectOperations, unreadPathItemCount } from "./oas-types.js";
3
+ import { SchemaWorkBudget, SchemaWorkLimit } from "./schema-sources.js";
1
4
  import { checkOperationIds } from "./operation-ids.js";
2
5
  import { checkSchemaTypes } from "./schema-types.js";
3
6
  import { checkErrorSchemas } from "./error-schemas.js";
@@ -17,24 +20,19 @@ const NO_SPEC_CHECKS = [
17
20
  { id: "schema_required_fields", label: "Required Fields" },
18
21
  { id: "schema_descriptions", label: "Field Descriptions" },
19
22
  ];
20
- function calculateScore(checks) {
21
- let points = 0;
22
- let maxPoints = 0;
23
- for (const check of checks) {
24
- maxPoints += 1;
25
- if (check.status === "pass")
26
- points += 1;
27
- else if (check.status === "partial")
28
- points += 0.5;
29
- }
30
- const score = maxPoints === 0 ? 0 : Math.round((points / maxPoints) * 100);
31
- const scoreLabel = score >= 80 ? "pass" : score >= 40 ? "partial" : "fail";
32
- return { score, scoreLabel };
33
- }
34
- export async function runSchemaBridge(ctx) {
23
+ export async function runSchemaBridge(ctx, budget = new SchemaWorkBudget()) {
35
24
  const start = performance.now();
36
25
  const hasSpec = ctx.shared.openApiDetected === true && ctx.shared.openApiSpec != null;
37
- const spec = hasSpec ? ctx.shared.openApiSpec : undefined;
26
+ const spec = hasSpec ? ctx.shared.openApiSpec ?? undefined : undefined;
27
+ if (!hasSpec && (ctx.shared.openApiDiscoveryIncomplete || ctx.shared.openApiDetected)) {
28
+ const message = ctx.shared.openApiDiscoveryIncomplete
29
+ ? "OpenAPI discovery was incomplete, so schema quality could not be measured."
30
+ : "An OpenAPI document was indicated, but its contents were unavailable for schema evaluation.";
31
+ return {
32
+ id: 4, name: "Schema", status: "not_evaluated", score: null, scoreLabel: null,
33
+ checks: [], durationMs: Math.round(performance.now() - start), message,
34
+ };
35
+ }
38
36
  // No spec → all five checks fail over a FIXED denominator (score 0), not
39
37
  // null. Excluding Bridge 4 from the average when there's no spec made the
40
38
  // overall score non-monotone: publishing a mediocre spec could lower it.
@@ -44,23 +42,43 @@ export async function runSchemaBridge(ctx) {
44
42
  const checks = NO_SPEC_CHECKS.map(({ id, label }) => ({
45
43
  id, label, status: "fail", detail: NO_SPEC_MESSAGES[id],
46
44
  }));
47
- const { score, scoreLabel } = calculateScore(checks);
45
+ const { score, scoreLabel } = scoreChecks(checks);
48
46
  return {
49
47
  id: 4, name: "Schema", status: "evaluated", score, scoreLabel, checks,
50
48
  durationMs: Math.round(performance.now() - start),
51
49
  };
52
50
  }
53
- const checks = [
54
- checkOperationIds(spec),
55
- checkSchemaTypes(spec),
56
- checkErrorSchemas(spec),
57
- checkRequiredFields(spec),
58
- checkDescriptions(spec),
59
- ];
60
- const { score, scoreLabel } = calculateScore(checks);
61
- return {
62
- id: 4, name: "Schema", status: "evaluated", score, scoreLabel, checks,
63
- durationMs: Math.round(performance.now() - start),
64
- };
51
+ try {
52
+ // Every Schema check grades the operation collection. Even one unread
53
+ // path can hide operations, request fields and error responses.
54
+ const unread = unreadPathItemCount(spec, budget);
55
+ if (unread) {
56
+ return {
57
+ id: 4, name: "Schema", status: "not_evaluated", score: null, scoreLabel: null, checks: [],
58
+ durationMs: Math.round(performance.now() - start),
59
+ message: `${unread} referenced OpenAPI path item(s) could not be inspected, so the full set of operations is unknown.`,
60
+ };
61
+ }
62
+ const ops = collectOperations(spec, budget);
63
+ const checks = [
64
+ checkOperationIds(spec, ops, budget),
65
+ checkSchemaTypes(spec, ops, budget),
66
+ checkErrorSchemas(spec, ops, budget),
67
+ checkRequiredFields(spec, ops, budget),
68
+ checkDescriptions(spec, ops, budget),
69
+ ];
70
+ const { score, scoreLabel } = scoreChecks(checks);
71
+ return {
72
+ id: 4, name: "Schema", status: "evaluated", score, scoreLabel, checks,
73
+ durationMs: Math.round(performance.now() - start),
74
+ };
75
+ }
76
+ catch (error) {
77
+ if (!(error instanceof SchemaWorkLimit))
78
+ throw error;
79
+ return {
80
+ id: 4, name: "Schema", status: "not_evaluated", score: null, scoreLabel: null, checks: [],
81
+ durationMs: Math.round(performance.now() - start), message: error.message,
82
+ };
83
+ }
65
84
  }
66
- //# sourceMappingURL=index.js.map
@@ -1,39 +1,68 @@
1
+ import { type SchemaWorkBudget } from "./schema-sources.js";
2
+ export interface OasParameter {
3
+ $ref?: string;
4
+ name?: string;
5
+ description?: string;
6
+ required?: boolean;
7
+ in?: string;
8
+ type?: string;
9
+ schema?: OasSchema;
10
+ }
11
+ export interface OasResponse {
12
+ $ref?: string;
13
+ description?: string;
14
+ schema?: OasSchema;
15
+ content?: Record<string, {
16
+ schema?: OasSchema;
17
+ }>;
18
+ }
19
+ export interface OasRequestBody {
20
+ $ref?: string;
21
+ description?: string;
22
+ required?: boolean;
23
+ content?: Record<string, {
24
+ schema?: OasSchema;
25
+ }>;
26
+ }
1
27
  export interface OasOperation {
2
28
  operationId?: string;
3
29
  description?: string;
4
30
  summary?: string;
5
- parameters?: Array<{
6
- name: string;
7
- description?: string;
8
- required?: boolean;
9
- in?: string;
10
- schema?: {
11
- type?: string;
12
- };
13
- }>;
14
- requestBody?: {
15
- required?: boolean;
16
- content?: Record<string, {
17
- schema?: OasSchema;
18
- }>;
19
- };
20
- responses?: Record<string, {
21
- description?: string;
22
- content?: Record<string, {
23
- schema?: OasSchema;
24
- }>;
25
- }>;
31
+ parameters?: OasParameter[];
32
+ requestBody?: OasRequestBody;
33
+ responses?: Record<string, OasResponse>;
26
34
  security?: Array<Record<string, string[]>>;
35
+ servers?: unknown;
27
36
  }
28
- export interface OasSchema {
29
- type?: string;
37
+ export type OasPathItem = Partial<Record<typeof HTTP_METHODS[number], OasOperation>> & {
38
+ $ref?: string;
39
+ summary?: string;
40
+ description?: string;
41
+ parameters?: OasParameter[];
42
+ servers?: unknown;
43
+ };
44
+ export type OasSchema = boolean | OasSchemaObject;
45
+ export interface OasSchemaObject {
46
+ type?: string | string[];
30
47
  $ref?: string;
31
48
  properties?: Record<string, OasSchema>;
32
49
  required?: string[];
33
50
  description?: string;
34
51
  items?: OasSchema;
52
+ allOf?: OasSchema[];
53
+ oneOf?: OasSchema[];
54
+ anyOf?: OasSchema[];
35
55
  }
36
56
  export interface ParsedOpenApiSpec {
57
+ servers?: unknown;
58
+ swagger?: string;
59
+ openapi?: string;
60
+ basePath?: string;
61
+ host?: string;
62
+ schemes?: string[];
63
+ parameters?: Record<string, OasParameter>;
64
+ responses?: Record<string, OasResponse>;
65
+ definitions?: Record<string, OasSchema>;
37
66
  info?: {
38
67
  title?: string;
39
68
  version?: string;
@@ -49,7 +78,7 @@ export interface ParsedOpenApiSpec {
49
78
  url?: string;
50
79
  };
51
80
  };
52
- paths?: Record<string, Record<string, OasOperation>>;
81
+ paths?: Record<string, OasPathItem>;
53
82
  components?: {
54
83
  securitySchemes?: Record<string, {
55
84
  type?: string;
@@ -60,6 +89,10 @@ export interface ParsedOpenApiSpec {
60
89
  flows?: unknown;
61
90
  }>;
62
91
  schemas?: Record<string, OasSchema>;
92
+ requestBodies?: Record<string, OasRequestBody>;
93
+ responses?: Record<string, OasResponse>;
94
+ parameters?: Record<string, OasParameter>;
95
+ pathItems?: Record<string, OasPathItem>;
63
96
  };
64
97
  security?: Array<Record<string, string[]>>;
65
98
  securityDefinitions?: Record<string, {
@@ -69,9 +102,15 @@ export interface ParsedOpenApiSpec {
69
102
  in?: string;
70
103
  }>;
71
104
  }
105
+ declare const HTTP_METHODS: readonly ["get", "post", "put", "patch", "delete", "options", "head", "trace"];
106
+ export declare function unreadPathItemCount(spec: ParsedOpenApiSpec | undefined, budget?: SchemaWorkBudget): number;
72
107
  /**
73
108
  * Collect all operations from a parsed spec.
74
109
  * Returns [path, method, operation] tuples.
75
110
  */
76
- export declare function collectOperations(spec: ParsedOpenApiSpec | undefined): Array<[string, string, OasOperation]>;
77
- //# sourceMappingURL=oas-types.d.ts.map
111
+ export declare function collectOperations(spec: ParsedOpenApiSpec | undefined, budget?: SchemaWorkBudget): Array<[string, string, OasOperation]>;
112
+ /** Expand an OpenAPI server template using its published variable defaults. */
113
+ export declare function openApiServerUrl(server: unknown): string | null;
114
+ /** The base path of a Swagger server when it can be sampled on the scan origin. */
115
+ export declare function swaggerBasePath(spec: ParsedOpenApiSpec, origin: string): string | null;
116
+ export {};
@@ -1,20 +1,30 @@
1
+ import { isRecord } from "../../utils/record.js";
2
+ import { resolvePathItem } from "./schema-sources.js";
1
3
  const HTTP_METHODS = [
2
4
  "get", "post", "put", "patch", "delete", "options", "head", "trace",
3
5
  ];
6
+ // Context probes append only root-relative paths on the scanned origin.
7
+ function apiPath(path) {
8
+ return path.startsWith("/") && !path.startsWith("//") && !path.includes("\\");
9
+ }
10
+ export function unreadPathItemCount(spec, budget) {
11
+ const paths = Object.entries(spec?.paths ?? {});
12
+ budget?.charge(paths.length);
13
+ return paths.filter(([path, item]) => apiPath(path) && item?.$ref !== undefined && !resolvePathItem(spec, path, budget)).length;
14
+ }
4
15
  /**
5
16
  * Collect all operations from a parsed spec.
6
17
  * Returns [path, method, operation] tuples.
7
18
  */
8
- export function collectOperations(spec) {
19
+ export function collectOperations(spec, budget) {
9
20
  if (!spec?.paths)
10
21
  return [];
11
22
  const ops = [];
12
- for (const [path, pathItem] of Object.entries(spec.paths)) {
13
- // Only root-relative paths belong to this API. Context probes append
14
- // these keys to the scanned origin, so never accept authority fragments.
15
- if (!path.startsWith("/") || path.startsWith("//") || path.includes("\\"))
23
+ for (const path of Object.keys(spec.paths)) {
24
+ if (!apiPath(path))
16
25
  continue;
17
- if (!pathItem || typeof pathItem !== "object" || Array.isArray(pathItem))
26
+ const pathItem = resolvePathItem(spec, path, budget);
27
+ if (!pathItem)
18
28
  continue;
19
29
  for (const method of HTTP_METHODS) {
20
30
  const op = pathItem[method];
@@ -25,4 +35,24 @@ export function collectOperations(spec) {
25
35
  }
26
36
  return ops;
27
37
  }
28
- //# sourceMappingURL=oas-types.js.map
38
+ /** Expand an OpenAPI server template using its published variable defaults. */
39
+ export function openApiServerUrl(server) {
40
+ if (!isRecord(server) || typeof server.url !== "string" || server.url.length > 8192)
41
+ return null;
42
+ const variables = isRecord(server.variables) ? server.variables : {};
43
+ const raw = server.url.replace(/\{([^{}]+)\}/g, (token, name) => {
44
+ const variable = Object.hasOwn(variables, name) ? variables[name] : undefined;
45
+ return isRecord(variable) && typeof variable.default === "string" && variable.default.length <= 255 ? variable.default : token;
46
+ });
47
+ return raw && raw.length <= 8192 && !/[{}]/.test(raw) ? raw : null;
48
+ }
49
+ /** The base path of a Swagger server when it can be sampled on the scan origin. */
50
+ export function swaggerBasePath(spec, origin) {
51
+ const url = new URL(origin);
52
+ if (spec.host !== undefined && spec.host !== url.host)
53
+ return null;
54
+ if (spec.schemes !== undefined && (!Array.isArray(spec.schemes) || !spec.schemes.includes(url.protocol.slice(0, -1))))
55
+ return null;
56
+ const base = spec.basePath ?? "/";
57
+ return typeof base === "string" && /^\/(?!\/)/.test(base) && !/[{}?#\\]/.test(base) ? base.replace(/\/$/, "") : null;
58
+ }
@@ -1,4 +1,4 @@
1
+ import type { SchemaWorkBudget } from "./schema-sources.js";
1
2
  import type { Check } from "../../core/types.js";
2
3
  import type { ParsedOpenApiSpec } from "./oas-types.js";
3
- export declare function checkOperationIds(spec: ParsedOpenApiSpec | undefined): Check;
4
- //# sourceMappingURL=operation-ids.d.ts.map
4
+ export declare function checkOperationIds(spec: ParsedOpenApiSpec | undefined, ops?: [string, string, import("./oas-types.js").OasOperation][], budget?: SchemaWorkBudget): Check;