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,3 +1,11 @@
1
+ const TRANSPORT_FAILURES = new Set(["timeout", "dns", "connection_refused", "network_error", "ssl_error", "ssrf_blocked"]);
2
+ /** Only the requested URL can establish its own unreachability. A redirect proves that it answered. */
3
+ export function transportFailureAt(response, requestedUrl) {
4
+ if (response.ok || response.response || response.error.statusCode !== undefined ||
5
+ !TRANSPORT_FAILURES.has(response.error.kind))
6
+ return undefined;
7
+ return URL.parse(response.error.url)?.href === new URL(requestedUrl).href ? response.error.kind : undefined;
8
+ }
1
9
  /**
2
10
  * Check HTTP status from a pre-fetched page response.
3
11
  * Does NOT make any HTTP calls -- takes the already-fetched response.
@@ -8,8 +16,11 @@ export function checkHttpStatus(pageResponse) {
8
16
  if (pageResponse.ok) {
9
17
  const { status, redirects, url } = pageResponse;
10
18
  const data = redirects.length > 0
11
- ? { redirects, finalUrl: url }
12
- : undefined;
19
+ ? { statusCode: status, redirects, finalUrl: url }
20
+ : { statusCode: status };
21
+ if (pageResponse.bodyIncomplete || status === 206 || pageResponse.headers["content-range"] !== undefined) {
22
+ return { id, label, status: "partial", detail: `HTTP ${status}, partial response body`, data };
23
+ }
13
24
  if (status >= 200 && status < 300) {
14
25
  return {
15
26
  id,
@@ -41,12 +52,15 @@ export function checkHttpStatus(pageResponse) {
41
52
  // Failure cases
42
53
  const { kind, message, statusCode } = pageResponse.error;
43
54
  switch (kind) {
55
+ case "body_too_large":
56
+ return { id, label, status: "partial", detail: "Response too large to inspect", data: { statusCode, errorKind: kind } };
44
57
  case "bot_protected":
45
58
  return {
46
59
  id,
47
60
  label,
48
61
  status: "fail",
49
62
  detail: "Bot protection detected",
63
+ data: { statusCode, errorKind: kind },
50
64
  };
51
65
  case "timeout":
52
66
  return {
@@ -54,6 +68,7 @@ export function checkHttpStatus(pageResponse) {
54
68
  label,
55
69
  status: "fail",
56
70
  detail: "Request timed out",
71
+ data: { errorKind: kind },
57
72
  };
58
73
  case "http_error":
59
74
  return {
@@ -61,6 +76,7 @@ export function checkHttpStatus(pageResponse) {
61
76
  label,
62
77
  status: "fail",
63
78
  detail: statusCode ? `HTTP ${statusCode}` : message,
79
+ data: { statusCode, errorKind: kind },
64
80
  };
65
81
  case "request_budget_exhausted":
66
82
  return {
@@ -78,4 +94,3 @@ export function checkHttpStatus(pageResponse) {
78
94
  };
79
95
  }
80
96
  }
81
- //# sourceMappingURL=http-status.js.map
@@ -1,8 +1,9 @@
1
- import type { Check } from "../../core/types.js";
1
+ import type { Check, HttpErrorKind } from "../../core/types.js";
2
2
  export interface HttpsCheckResult {
3
3
  check: Check;
4
4
  abort: boolean;
5
5
  abortReason?: string;
6
+ transportFailure?: HttpErrorKind;
6
7
  }
7
8
  /**
8
9
  * Check HTTPS availability via HEAD request to https://<domain>.
@@ -11,4 +12,3 @@ export interface HttpsCheckResult {
11
12
  * Abort-worthy errors: dns, connection_refused, ssl_error.
12
13
  */
13
14
  export declare function checkHttps(domain: string, timeout?: number): Promise<HttpsCheckResult>;
14
- //# sourceMappingURL=https-check.d.ts.map
@@ -1,3 +1,4 @@
1
+ import { transportFailureAt } from "./http-status.js";
1
2
  import { httpGet } from "../../utils/http-client.js";
2
3
  const ABORT_ERRORS = new Set(["dns", "connection_refused", "ssl_error", "ssrf_blocked"]);
3
4
  /**
@@ -7,11 +8,13 @@ const ABORT_ERRORS = new Set(["dns", "connection_refused", "ssl_error", "ssrf_bl
7
8
  * Abort-worthy errors: dns, connection_refused, ssl_error.
8
9
  */
9
10
  export async function checkHttps(domain, timeout) {
10
- const result = await httpGet("https://" + domain, {
11
+ const url = "https://" + domain;
12
+ const result = await httpGet(url, {
11
13
  method: "HEAD",
14
+ maxRedirects: 0,
12
15
  timeout,
13
16
  });
14
- if (result.ok || result.response) {
17
+ if (result.ok || result.response || result.error.kind === "http_error" || result.error.statusCode !== undefined) {
15
18
  return {
16
19
  check: {
17
20
  id: "https_available",
@@ -45,6 +48,6 @@ export async function checkHttps(domain, timeout) {
45
48
  },
46
49
  abort,
47
50
  abortReason: abort ? kind : undefined,
51
+ transportFailure: transportFailureAt(result, url),
48
52
  };
49
53
  }
50
- //# sourceMappingURL=https-check.js.map
@@ -9,5 +9,4 @@ import type { BridgeResult, ScanContext } from "../../core/types.js";
9
9
  *
10
10
  * Aborts on dns/connection_refused/ssl_error from HTTPS check.
11
11
  */
12
- export declare function runReachabilityBridge(ctx: ScanContext): Promise<BridgeResult>;
13
- //# sourceMappingURL=index.d.ts.map
12
+ export declare function runReachabilityBridge(ctx: ScanContext): Promise<BridgeResult<1>>;
@@ -1,38 +1,11 @@
1
1
  import { httpGet } from "../../utils/http-client.js";
2
2
  import { checkHttps } from "./https-check.js";
3
- import { checkHttpStatus } from "./http-status.js";
3
+ import { checkHttpStatus, transportFailureAt } from "./http-status.js";
4
4
  import { checkRobotsTxt } from "./robots-txt.js";
5
5
  import { evaluateCrawlerPolicies } from "./crawler-policy.js";
6
6
  import { checkMetaRobots, checkXRobotsTag } from "./meta-robots.js";
7
- /**
8
- * Calculate bridge score from check results.
9
- * - Pass = 1 point, Partial = 0.5 points, Fail/Error = 0 points
10
- * - Checks with data.policy === "skip" excluded from both numerator and denominator
11
- */
12
- function calculateScore(checks) {
13
- let points = 0;
14
- let maxPoints = 0;
15
- for (const check of checks) {
16
- // Skip checks excluded from scoring (e.g., crawler policy with no robots.txt)
17
- if (check.data &&
18
- check.data.policy === "skip") {
19
- continue;
20
- }
21
- // Error = probe never ran (e.g. request budget exhausted): unmeasured,
22
- // excluded from both numerator and denominator.
23
- if (check.status === "error")
24
- continue;
25
- maxPoints += 1;
26
- if (check.status === "pass")
27
- points += 1;
28
- else if (check.status === "partial")
29
- points += 0.5;
30
- // fail = 0 points
31
- }
32
- const score = maxPoints === 0 ? 0 : Math.round((points / maxPoints) * 100);
33
- const scoreLabel = score >= 80 ? "pass" : score >= 40 ? "partial" : "fail";
34
- return { score, scoreLabel };
35
- }
7
+ import { HTML_LIMIT_DETAIL, inspectableHtml } from "../../utils/html.js";
8
+ import { checkCoverage, scoreChecks } from "../../core/scoring.js";
36
9
  /**
37
10
  * Run Bridge 1: Reachability.
38
11
  *
@@ -65,27 +38,39 @@ export async function runReachabilityBridge(ctx) {
65
38
  };
66
39
  }
67
40
  // 2. Page GET (uses normalized baseUrl)
68
- const pageResponse = await httpGet(ctx.baseUrl, {
69
- timeout: ctx.options.timeout,
70
- });
41
+ const [fetchedPage, robotsResult] = await Promise.all([
42
+ httpGet(ctx.baseUrl, { timeout: ctx.options.timeout }),
43
+ checkRobotsTxt(ctx.baseUrl, ctx.options.timeout),
44
+ ]);
45
+ const pageResponse = inspectableHtml(fetchedPage);
46
+ const overLimit = pageResponse !== fetchedPage;
71
47
  // Store page body for Bridge 2 (JSON-LD, Schema.org extraction)
72
48
  if (pageResponse.ok) {
73
49
  ctx.shared.pageBody = pageResponse.body;
50
+ ctx.shared.pageUrl = pageResponse.url;
51
+ ctx.shared.pageResponse = pageResponse;
74
52
  ctx.shared.pageHeaders = pageResponse.headers;
53
+ if (overLimit)
54
+ ctx.shared.pageOverHtmlLimit = true;
75
55
  }
76
- // 3. HTTP status check (no HTTP call -- uses pageResponse)
77
- const httpStatusCheck = checkHttpStatus(pageResponse);
78
- // 4. robots.txt fetch + parse
79
- const robotsResult = await checkRobotsTxt(ctx.baseUrl, ctx.options.timeout);
56
+ // 3. HTTP status check (no HTTP call -- the transfer itself was complete even when inspection is withheld)
57
+ const httpStatusCheck = checkHttpStatus(fetchedPage);
80
58
  // Store sitemap URLs for Bridge 2 consumption
81
59
  ctx.shared.robotsSitemaps = robotsResult.parsed?.sitemaps ?? [];
60
+ // An unmeasured robots.txt was cut or never read, so it may declare a sitemap this list lacks.
61
+ if (robotsResult.parsed?.sitemapsCut || robotsResult.check.status === "error")
62
+ ctx.shared.robotsSitemapsCut = true;
82
63
  // 5. Crawler policies (uses parsed robots.txt data)
83
- const crawlerChecks = evaluateCrawlerPolicies(robotsResult.parsed, !robotsResult.parsed && robotsResult.check.status !== "partial");
64
+ const crawlerChecks = evaluateCrawlerPolicies(robotsResult.parsed, robotsResult.coverage);
84
65
  // 6. Meta robots (uses page response)
85
66
  let metaRobotsCheck;
86
67
  let xRobotsCheck;
87
68
  if (pageResponse.ok) {
88
- metaRobotsCheck = checkMetaRobots(pageResponse.body);
69
+ const incomplete = pageResponse.bodyIncomplete || pageResponse.status === 206 || pageResponse.headers["content-range"] !== undefined;
70
+ metaRobotsCheck = incomplete
71
+ ? { id: "meta_robots", label: "Meta Robots Tags", status: "error",
72
+ detail: overLimit ? "Homepage " + HTML_LIMIT_DETAIL : "Homepage body could not be fully inspected" }
73
+ : checkMetaRobots(pageResponse.body);
89
74
  xRobotsCheck = checkXRobotsTag(pageResponse.headers);
90
75
  }
91
76
  else {
@@ -102,16 +87,22 @@ export async function runReachabilityBridge(ctx) {
102
87
  metaRobotsCheck,
103
88
  xRobotsCheck,
104
89
  ];
90
+ // On an HTTP scan the separate HTTPS probe cannot prove that the HTTP origin answered.
91
+ const pageFailure = transportFailureAt(pageResponse, ctx.baseUrl);
92
+ const unreachable = pageFailure && robotsResult.transportFailure &&
93
+ (origin.protocol === "http:" || httpsResult.transportFailure);
105
94
  // 8. Calculate score
106
- const { score, scoreLabel } = calculateScore(checks);
95
+ const { score, scoreLabel } = scoreChecks(checks);
96
+ const { measured, eligible } = checkCoverage(checks);
107
97
  return {
108
98
  id: 1,
109
99
  name: "Reachability",
110
100
  status: "evaluated",
111
- score,
112
- scoreLabel,
101
+ score: unreachable ? 0 : score,
102
+ scoreLabel: unreachable ? "fail" : scoreLabel,
113
103
  checks,
104
+ ...(unreachable && { abort: true, abortReason: pageFailure }),
105
+ ...(measured < eligible && { message: `${measured} of ${eligible} eligible checks measured` }),
114
106
  durationMs: Math.round(performance.now() - start),
115
107
  };
116
108
  }
117
- //# sourceMappingURL=index.js.map
@@ -1,16 +1,3 @@
1
1
  import type { Check } from "../../core/types.js";
2
- /**
3
- * Check for restrictive meta robots tags in the HTML <head> section.
4
- * Uses regex only -- no HTML parser dependency.
5
- *
6
- * Scans for: robots, googlebot, bingbot name attributes.
7
- * Handles both attribute orders, single/double quotes, self-closing tags, case insensitivity.
8
- */
9
2
  export declare function checkMetaRobots(html: string): Check;
10
- /**
11
- * Check for X-Robots-Tag HTTP header directives.
12
- *
13
- * Headers object is expected to have lowercase keys (from Phase 2 httpGet).
14
- */
15
3
  export declare function checkXRobotsTag(headers: Record<string, string>): Check;
16
- //# sourceMappingURL=meta-robots.d.ts.map
@@ -1,110 +1,98 @@
1
- /**
2
- * Check for restrictive meta robots tags in the HTML <head> section.
3
- * Uses regex only -- no HTML parser dependency.
4
- *
5
- * Scans for: robots, googlebot, bingbot name attributes.
6
- * Handles both attribute orders, single/double quotes, self-closing tags, case insensitivity.
7
- */
8
- export function checkMetaRobots(html) {
9
- const id = "meta_robots";
10
- const label = "Meta Robots Tags";
11
- // Extract head content (case-insensitive)
12
- const headMatch = html.match(/<head[^>]*>([\s\S]*?)<\/head>/i);
13
- if (!headMatch) {
14
- return {
15
- id,
16
- label,
17
- status: "pass",
18
- detail: "No restrictive meta robots tags found",
19
- data: { directives: [] },
20
- };
21
- }
22
- const headContent = headMatch[1];
23
- const filtered = [];
24
- for (const [tag] of headContent.matchAll(/<meta(?=\s)[^<>]*>/gi)) {
25
- if (!/\sname\s*=\s*["'](?:robots|googlebot|bingbot)["']/i.test(tag))
1
+ import { htmlElements } from "../../utils/html.js";
2
+ import { AI_CRAWLERS } from "./crawler-policy.js";
3
+ const AGENTS = new Set(["*", "robots", "googlebot", "bingbot", ...AI_CRAWLERS.map(c => c.userAgent)]);
4
+ const PARTIAL = new Set(["nofollow", "noarchive", "nosnippet", "noai", "noimageai"]);
5
+ const PARAMETERIZED = new Set(["max-snippet", "max-image-preview", "max-video-preview", "unavailable_after"]);
6
+ function collect(groups, value, agent, header) {
7
+ let scope = agent;
8
+ // A weekday and calendar date in unavailable_after can be separated by a comma.
9
+ for (const part of value.toLowerCase().split(/,(?![ \t]*\d{1,2}[ \t]+[a-z]{3}\b)/i)) {
10
+ let directive = part.trim();
11
+ const prefix = /^([\w.*-]+)\s*:/.exec(directive);
12
+ if (header && prefix && !PARAMETERIZED.has(prefix[1])) {
13
+ scope = prefix[1];
14
+ directive = directive.slice(prefix[0].length).trim();
15
+ }
16
+ if (!directive || !AGENTS.has(scope))
26
17
  continue;
27
- const content = /\scontent\s*=\s*(["'])(.*?)\1/is.exec(tag)?.[2];
28
- if (!content)
18
+ const key = scope === "robots" ? "*" : scope;
19
+ const set = groups.get(key) ?? new Set();
20
+ groups.set(key, set);
21
+ if (PARAMETERIZED.has(directive.split(":", 1)[0].trim())) {
22
+ set.add(directive);
29
23
  continue;
30
- for (const value of content.split(",")) {
31
- const directive = value.trim().toLowerCase();
32
- if (directive)
33
- filtered.push(directive);
24
+ }
25
+ for (const [token] of directive.matchAll(/\S+/g)) {
26
+ if (token === "none") {
27
+ set.add("noindex");
28
+ set.add("nofollow");
29
+ }
30
+ else {
31
+ set.add(token);
32
+ }
34
33
  }
35
34
  }
36
- if (filtered.some((d) => d === "noindex")) {
37
- return {
38
- id,
39
- label,
40
- status: "fail",
41
- detail: `Restrictive meta robots directives found: ${filtered.join(", ")}`,
42
- data: { directives: filtered },
43
- };
44
- }
45
- if (filtered.some((d) => d === "nofollow")) {
46
- return {
47
- id,
48
- label,
49
- status: "partial",
50
- detail: `Restrictive meta robots directives found: ${filtered.join(", ")}`,
51
- data: { directives: filtered },
52
- };
35
+ }
36
+ function evaluate(groups) {
37
+ const global = groups.get("*");
38
+ let status = global?.has("noindex") ? "fail" : "pass";
39
+ const restrictions = [];
40
+ for (const [agent, values] of groups) {
41
+ for (const value of values) {
42
+ if (value !== "noindex" && !PARTIAL.has(value))
43
+ continue;
44
+ if (status === "pass")
45
+ status = "partial";
46
+ restrictions.push(agent === "*" ? value : agent + ": " + value);
47
+ }
53
48
  }
54
- return {
55
- id,
56
- label,
57
- status: "pass",
58
- detail: "No restrictive meta robots tags found",
59
- data: { directives: filtered },
49
+ // Status uses every token; the report keeps the first 32 of each scope, leaving out over-long tokens.
50
+ const sample = (values) => {
51
+ const kept = [];
52
+ for (const value of values) {
53
+ if (kept.length === 32)
54
+ break;
55
+ if (value.length <= 256)
56
+ kept.push(value);
57
+ }
58
+ return kept;
60
59
  };
60
+ const directives = sample(global ?? new Set());
61
+ const scoped = [...groups].filter(([agent]) => agent !== "*").map(([agent, values]) => ({ agent, total: values.size, kept: sample(values) }));
62
+ return { status, restrictions, data: {
63
+ directives, directivesTotal: global?.size ?? 0,
64
+ ...(directives.length < (global?.size ?? 0) && { directivesTruncated: true }),
65
+ ...(scoped.length && {
66
+ scopedDirectives: Object.fromEntries(scoped.map(scope => [scope.agent, scope.kept])),
67
+ scopedDirectivesTotal: Object.fromEntries(scoped.map(scope => [scope.agent, scope.total])),
68
+ ...(scoped.some(scope => scope.kept.length < scope.total) && { scopedDirectivesTruncated: true }),
69
+ }),
70
+ } };
61
71
  }
62
- /**
63
- * Check for X-Robots-Tag HTTP header directives.
64
- *
65
- * Headers object is expected to have lowercase keys (from Phase 2 httpGet).
66
- */
67
- export function checkXRobotsTag(headers) {
68
- const id = "x_robots_tag";
69
- const label = "X-Robots-Tag Header";
70
- const headerValue = headers["x-robots-tag"];
71
- if (!headerValue) {
72
- return {
73
- id,
74
- label,
75
- status: "pass",
76
- detail: "No X-Robots-Tag header",
77
- data: { directives: [], raw: "" },
78
- };
79
- }
80
- const directives = headerValue
81
- .split(",")
82
- .map((d) => d.trim().toLowerCase())
83
- .filter((d) => d.length > 0);
84
- if (directives.some((d) => d.includes("noindex"))) {
85
- return {
86
- id,
87
- label,
88
- status: "fail",
89
- detail: `X-Robots-Tag contains restrictive directives: ${directives.join(", ")}`,
90
- data: { directives, raw: headerValue },
91
- };
92
- }
93
- if (directives.some((d) => d.includes("nofollow") || d.includes("noarchive") || d === "none")) {
94
- return {
95
- id,
96
- label,
97
- status: "partial",
98
- detail: `X-Robots-Tag contains directives: ${directives.join(", ")}`,
99
- data: { directives, raw: headerValue },
100
- };
72
+ export function checkMetaRobots(html) {
73
+ const groups = new Map();
74
+ for (const element of htmlElements(html)) {
75
+ if (element.tagName === "body")
76
+ break;
77
+ if (element.tagName !== "meta")
78
+ continue;
79
+ const name = element.attrs.find(attr => attr.name === "name")?.value.toLowerCase().trim();
80
+ const content = element.attrs.find(attr => attr.name === "content")?.value;
81
+ if (content && name && AGENTS.has(name))
82
+ collect(groups, content, name, false);
101
83
  }
102
- return {
103
- id,
104
- label,
105
- status: "pass",
106
- detail: `X-Robots-Tag header present with no restrictive directives`,
107
- data: { directives, raw: headerValue },
108
- };
84
+ const { status, restrictions, data } = evaluate(groups);
85
+ const detail = status === "pass" ? "No restrictive meta robots tags found" :
86
+ `Restrictive meta robots directives found: ${restrictions.join(", ")}`;
87
+ return { id: "meta_robots", label: "Meta Robots Tags", status, detail, data };
88
+ }
89
+ export function checkXRobotsTag(headers) {
90
+ const raw = headers["x-robots-tag"] ?? "";
91
+ const groups = new Map();
92
+ collect(groups, raw, "*", true);
93
+ const { status, restrictions, data } = evaluate(groups);
94
+ const detail = !raw ? "No X-Robots-Tag header" :
95
+ status === "pass" ? "X-Robots-Tag header present with no restrictive directives" :
96
+ `X-Robots-Tag contains restrictive directives: ${restrictions.join(", ")}`;
97
+ return { id: "x_robots_tag", label: "X-Robots-Tag Header", status, detail, data: { ...data, raw } };
109
98
  }
110
- //# sourceMappingURL=meta-robots.js.map
@@ -1,8 +1,12 @@
1
1
  export interface RobotsTxtResult {
2
- parseable: boolean;
3
2
  ruleCount: number;
4
3
  groups: RobotsGroup[];
4
+ /** The Sitemap URLs from the start of the file, duplicates included, that fit SITEMAPS_LENGTH_BUDGET together. */
5
5
  sitemaps: string[];
6
+ /** Every accepted Sitemap declaration, including those left out of sitemaps. */
7
+ sitemapsTotal: number;
8
+ /** Set when a declaration left out names a URL that sitemaps does not hold. Repeats of a kept URL lose nothing. */
9
+ sitemapsCut?: true;
6
10
  }
7
11
  export interface RobotsGroup {
8
12
  userAgents: string[];
@@ -17,10 +21,6 @@ export interface RobotsRule {
17
21
  * Handles RFC 9309 edge cases: BOM, CRLF/CR/LF, comments,
18
22
  * case-insensitive directives, case-sensitive paths, group boundaries.
19
23
  */
20
- export declare function parseRobotsTxt(content: string): RobotsTxtResult;
21
- /**
22
- * Check whether a robots.txt path pattern matches a given URL path.
23
- * Supports * wildcards and $ end anchor per RFC 9309.
24
- */
24
+ export declare function parseRobotsTxt(content: string, documentUrl?: string): RobotsTxtResult;
25
25
  export declare function matchesPath(pattern: string, path: string): boolean;
26
- //# sourceMappingURL=robots-parser.d.ts.map
26
+ export declare function isAllowed(rules: RobotsRule[], path: string): boolean;
@@ -1,18 +1,22 @@
1
- // RFC 9309 robots.txt parser and path matcher
2
- // Pure logic, no I/O
1
+ import { parseReference } from "../../utils/url.js";
2
+ // Relative Sitemap lines resolved against a long robots.txt URL each become that long, so the
3
+ // retained list is bounded by total length rather than count to keep worker memory in check.
4
+ const SITEMAPS_LENGTH_BUDGET = 1_048_576;
3
5
  /**
4
6
  * Parse raw robots.txt content into structured data.
5
7
  * Handles RFC 9309 edge cases: BOM, CRLF/CR/LF, comments,
6
8
  * case-insensitive directives, case-sensitive paths, group boundaries.
7
9
  */
8
- export function parseRobotsTxt(content) {
10
+ export function parseRobotsTxt(content, documentUrl) {
9
11
  const groups = [];
10
12
  const sitemaps = [];
11
- // 1. Strip UTF-8 BOM
12
- let text = content;
13
- if (text.charCodeAt(0) === 0xfeff || text.startsWith("\xEF\xBB\xBF")) {
14
- text = text.replace(/^\xEF\xBB\xBF/, "").replace(/^\uFEFF/, "");
15
- }
13
+ let sitemapsTotal = 0;
14
+ let sitemapsLength = 0;
15
+ let sitemapsFull = false;
16
+ let sitemapsCut = false;
17
+ let kept;
18
+ // A UTF-8 BOM decoded under a declared Latin-1/windows-1252 charset arrives as "\u00EF\u00BB\u00BF".
19
+ const text = content.replace(/^(?:\uFEFF|\u00EF\u00BB\u00BF)/, "");
16
20
  // 2. Split on CRLF, CR, or LF
17
21
  const lines = text.split(/\r\n|\r|\n/);
18
22
  let currentGroup = null;
@@ -30,17 +34,20 @@ export function parseRobotsTxt(content) {
30
34
  const value = line.substring(colonIdx + 1).trim();
31
35
  switch (directive) {
32
36
  case "user-agent": {
37
+ const token = value.split(/[\s/]/, 1)[0].toLowerCase();
38
+ const agents = /^(?:\*|[a-z_-]+)$/.test(token) ? [token] : [];
33
39
  // 6. If currentGroup has rules, start a new group
34
40
  if (currentGroup && currentGroup.rules.length > 0) {
35
41
  groups.push(currentGroup);
36
- currentGroup = { userAgents: [value.toLowerCase()], rules: [] };
42
+ currentGroup = { userAgents: agents, rules: [] };
37
43
  }
38
44
  else if (currentGroup) {
39
45
  // Consecutive User-agent lines = same group
40
- currentGroup.userAgents.push(value.toLowerCase());
46
+ if (agents.length)
47
+ currentGroup.userAgents.push(token);
41
48
  }
42
49
  else {
43
- currentGroup = { userAgents: [value.toLowerCase()], rules: [] };
50
+ currentGroup = { userAgents: agents, rules: [] };
44
51
  }
45
52
  break;
46
53
  }
@@ -55,7 +62,20 @@ export function parseRobotsTxt(content) {
55
62
  }
56
63
  case "sitemap": {
57
64
  // 8. Sitemaps are not tied to any group
58
- sitemaps.push(value);
65
+ if (!value || /[\s\\<>]/.test(value))
66
+ break;
67
+ const url = parseReference(value, documentUrl);
68
+ if (url && ["http:", "https:"].includes(url.protocol) && !url.username && !url.password) {
69
+ sitemapsTotal++;
70
+ // Past the first URL that does not fit, a shorter one would follow a gap the sitemap check cannot see.
71
+ sitemapsFull ||= sitemapsLength + url.href.length > SITEMAPS_LENGTH_BUDGET;
72
+ if (sitemapsFull) {
73
+ sitemapsCut ||= !(kept ??= new Set(sitemaps)).has(url.href);
74
+ break;
75
+ }
76
+ sitemapsLength += url.href.length;
77
+ sitemaps.push(url.href);
78
+ }
59
79
  break;
60
80
  }
61
81
  default:
@@ -70,17 +90,48 @@ export function parseRobotsTxt(content) {
70
90
  // 11. Calculate ruleCount
71
91
  const ruleCount = groups.reduce((sum, g) => sum + g.rules.length, 0);
72
92
  return {
73
- parseable: true,
74
93
  ruleCount,
75
94
  groups,
76
95
  sitemaps,
96
+ sitemapsTotal,
97
+ ...(sitemapsCut && { sitemapsCut: true }),
77
98
  };
78
99
  }
100
+ // RFC 9309 compares paths by octet, with percent-encoded unreserved ASCII decoded.
101
+ function normalizePath(path) {
102
+ return path.replace(/%[a-fA-F0-9]{2}|[^\x00-\x7f]/gu, value => {
103
+ if (!value.startsWith("%"))
104
+ return encodeURIComponent(/[\uD800-\uDFFF]/u.test(value) ? "\uFFFD" : value);
105
+ const character = String.fromCharCode(Number.parseInt(value.slice(1), 16));
106
+ return /^[a-zA-Z0-9._~-]$/.test(character) ? character : value.toUpperCase();
107
+ });
108
+ }
109
+ export function matchesPath(pattern, path) {
110
+ return matchesNormalizedPath(normalizePath(pattern), normalizePath(path.startsWith("/") ? path : "/" + path));
111
+ }
112
+ export function isAllowed(rules, path) {
113
+ const target = normalizePath(path.startsWith("/") ? path : "/" + path);
114
+ let longest = -1;
115
+ let allowed = true;
116
+ for (const rule of rules) {
117
+ if (!rule.path)
118
+ continue;
119
+ const pattern = normalizePath(rule.path);
120
+ if (!matchesNormalizedPath(pattern, target))
121
+ continue;
122
+ const length = pattern.replace(/%[A-F0-9]{2}/g, "x").length;
123
+ if (length > longest || (length === longest && rule.type === "allow")) {
124
+ longest = length;
125
+ allowed = rule.type === "allow";
126
+ }
127
+ }
128
+ return allowed;
129
+ }
79
130
  /**
80
131
  * Check whether a robots.txt path pattern matches a given URL path.
81
132
  * Supports * wildcards and $ end anchor per RFC 9309.
82
133
  */
83
- export function matchesPath(pattern, path) {
134
+ function matchesNormalizedPath(pattern, path) {
84
135
  const anchored = pattern.endsWith("$");
85
136
  const glob = anchored ? pattern.slice(0, -1) : pattern;
86
137
  const [prefix, ...parts] = glob.split("*");
@@ -104,4 +155,3 @@ export function matchesPath(pattern, path) {
104
155
  }
105
156
  return true;
106
157
  }
107
- //# sourceMappingURL=robots-parser.js.map
@@ -1,8 +1,11 @@
1
- import type { Check } from "../../core/types.js";
1
+ import type { Check, HttpErrorKind } from "../../core/types.js";
2
+ import { type DirectiveInventory } from "./crawler-policy.js";
2
3
  import { type RobotsTxtResult } from "./robots-parser.js";
3
4
  export interface RobotsTxtCheckResult {
4
5
  check: Check;
5
6
  parsed: RobotsTxtResult | null;
7
+ coverage: DirectiveInventory["coverage"];
8
+ transportFailure?: HttpErrorKind;
6
9
  }
7
10
  /**
8
11
  * Fetch and parse robots.txt for the given domain.
@@ -11,4 +14,3 @@ export interface RobotsTxtCheckResult {
11
14
  * use by crawler policy evaluation.
12
15
  */
13
16
  export declare function checkRobotsTxt(origin: string, timeout?: number): Promise<RobotsTxtCheckResult>;
14
- //# sourceMappingURL=robots-txt.d.ts.map