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,75 +1,82 @@
1
- import { httpGet } from "../../utils/http-client.js";
2
- import { collectOperations } from "../schema/oas-types.js";
3
- const DOCS_URL_KEYS = ["docs_url", "documentation_url", "help_url", "docs", "documentation", "help", "more_info"];
4
- function findProtectedGetPath(spec) {
5
- if (!spec)
6
- return null;
7
- const ops = collectOperations(spec);
8
- for (const [path, method, op] of ops) {
9
- if (method !== "get" || path.includes("{"))
10
- continue;
11
- if (Array.isArray(op.security) && op.security.length > 0)
12
- return path;
13
- }
14
- if (Array.isArray(spec.security) && spec.security.length > 0) {
15
- for (const [path, method, op] of ops) {
16
- if (method === "get" && !path.includes("{") && op.security === undefined)
17
- return path;
18
- }
19
- }
20
- return null;
21
- }
1
+ import { parseReference } from "../../utils/url.js";
2
+ import { mediaType } from "../../utils/http-types.js";
3
+ import { OVERSIZED, isRecord, readJson } from "../standards/probe-evidence.js";
4
+ import { CONTEXT_JSON_SIZE, observeProbe, readProbe } from "./probe.js";
5
+ import { observeOAuth } from "./oauth-metadata.js";
6
+ const DOCS_URL_KEYS = ["doc_url", "docs_url", "documentation_url", "help_url", "docs", "documentation", "help", "more_info", "type"];
22
7
  const id = "context_auth_legibility";
23
8
  const label = "Auth Legibility";
24
9
  /** Grade how well a 401/403 rejection guides an unauthenticated agent. */
25
- function gradeRejection(response, probeUrl) {
10
+ function gradeRejection(response, probe) {
26
11
  const signals = [];
27
- const contentType = (response.headers["content-type"] ?? "").split(";")[0].trim().toLowerCase();
12
+ const contentType = mediaType(response.headers);
28
13
  if (response.headers["www-authenticate"])
29
14
  signals.push("www-authenticate");
30
- let isJson = false;
31
- if (contentType === "application/json" || contentType === "application/problem+json") {
32
- try {
33
- JSON.parse(response.body);
34
- isJson = true;
35
- signals.push("json_error_body");
36
- }
37
- catch { /* invalid JSON */ }
38
- }
39
- if (isJson) {
15
+ if (contentType === "application/json" || contentType.endsWith("+json")) {
40
16
  try {
41
- const parsed = JSON.parse(response.body);
42
- const hasDocsUrl = Object.entries(parsed).some(([key, val]) => DOCS_URL_KEYS.includes(key.toLowerCase()) && typeof val === "string" && val.startsWith("http"));
43
- if (hasDocsUrl)
44
- signals.push("docs_url");
17
+ const parsed = readJson(response.body, CONTEXT_JSON_SIZE);
18
+ if (parsed === OVERSIZED) {
19
+ return { id, label, status: "error", detail: "Authentication rejection body too large to inspect",
20
+ data: { ...probe, measurement: "unmeasured", signals: [] } };
21
+ }
22
+ if (isRecord(parsed)) {
23
+ signals.push("json_error_body");
24
+ const fields = [...Object.entries(parsed), ...Object.entries(isRecord(parsed.error) ? parsed.error : {})];
25
+ const webLink = (value) => {
26
+ if (typeof value !== "string")
27
+ return false;
28
+ const url = parseReference(value);
29
+ return url?.protocol === "http:" || url?.protocol === "https:";
30
+ };
31
+ const hasDocsUrl = fields.some(([key, value]) => DOCS_URL_KEYS.includes(key.toLowerCase()) && webLink(value)) ||
32
+ (contentType === "application/vnd.api+json" && Array.isArray(parsed.errors) && parsed.errors.some(error => {
33
+ if (!isRecord(error) || !isRecord(error.links))
34
+ return false;
35
+ const about = error.links.about;
36
+ return webLink(isRecord(about) ? about.href : about);
37
+ }));
38
+ if (hasDocsUrl)
39
+ signals.push("docs_url");
40
+ }
45
41
  }
46
- catch { /* already handled */ }
42
+ catch { /* Invalid JSON supplies no structured error evidence. */ }
47
43
  }
44
+ const data = { ...probe, measurement: "challenged", httpStatus: response.status, signals };
48
45
  if (signals.length >= 3)
49
- return { id, label, status: "pass", detail: `API guides unauthenticated agents toward auth: ${signals.join(", ")}`, data: { probeUrl, signals } };
46
+ return { id, label, status: "pass", detail: `API guides unauthenticated agents toward auth: ${signals.join(", ")}`, data };
50
47
  if (signals.length >= 1)
51
- return { id, label, status: "partial", detail: `API rejects with some guidance (${signals.join(", ")}) but missing: ${["www-authenticate", "json_error_body", "docs_url"].filter((s) => !signals.includes(s)).join(", ")}`, data: { probeUrl, signals } };
52
- return { id, label, status: "fail", detail: "API returns opaque rejection with no guidance for agents", data: { probeUrl, signals: [] } };
48
+ return { id, label, status: "partial", detail: `API rejects with some guidance (${signals.join(", ")}) but missing: ${["www-authenticate", "json_error_body", "docs_url"].filter((s) => !signals.includes(s)).join(", ")}`, data };
49
+ return { id, label, status: "fail", detail: "API returns opaque rejection with no guidance for agents", data };
53
50
  }
54
- export async function checkAuthLegibility(ctx) {
55
- const spec = ctx.shared.openApiSpec;
56
- const protectedPath = findProtectedGetPath(spec);
57
- const probeUrl = protectedPath ? `${ctx.baseUrl}${protectedPath}` : `${ctx.baseUrl}/api`;
58
- const probeTimeout = Math.min(ctx.options.timeout ?? 10000, 5000);
59
- const result = await httpGet(probeUrl, { timeout: probeTimeout });
60
- if (!result.ok) {
61
- if (result.error.kind === "request_budget_exhausted") {
62
- return { id, label, status: "error", detail: "Auth legibility probe skipped: scan request budget exhausted", data: { probeUrl, signals: [] } };
63
- }
64
- // A 401/403 is a reachable, gradeable rejection — the whole point of this
65
- // check. It arrives as a failure (httpGet rejects non-2xx) but carries the
66
- // response, so grade it rather than reporting "could not reach".
67
- if (result.response && (result.response.status === 401 || result.response.status === 403)) {
68
- return gradeRejection(result.response, probeUrl);
51
+ export async function checkAuthLegibility(ctx, cache) {
52
+ const probeResult = await readProbe(ctx, "auth", cache);
53
+ if (!probeResult) {
54
+ const check = { id, label, status: "error", detail: "OpenAPI inspection exceeded its work limit during probe selection",
55
+ data: { measurement: "unmeasured", measured: false } };
56
+ return check;
57
+ }
58
+ const { selected, result, timeout } = probeResult;
59
+ const { data: probe, attributable, html } = observeProbe(selected, result);
60
+ const { httpStatus } = probe;
61
+ if (!result.ok && attributable && result.error.kind === "http_error" &&
62
+ result.response && (httpStatus === 401 || httpStatus === 403)) {
63
+ const check = gradeRejection(result.response, probe);
64
+ if (probe.probeSource === "protected_operation") {
65
+ const oauth = await observeOAuth(result.response.headers["www-authenticate"] ?? "", probe.probeUrl, timeout);
66
+ if (oauth)
67
+ check.data = { ...check.data, oauth };
69
68
  }
70
- return { id, label, status: "fail", detail: `Could not reach ${probeUrl} to test auth response quality`, data: { probeUrl, signals: [] } };
69
+ return check;
70
+ }
71
+ if (result.ok && attributable && !html) {
72
+ return {
73
+ id, label, status: "partial", detail: `Auth probe returned HTTP ${httpStatus} without an authentication challenge`,
74
+ data: { ...probe, measurement: "no_challenge", signals: ["no_auth_required"] },
75
+ };
71
76
  }
72
- // 2xx: the endpoint did not require auth, so legibility can't be assessed.
73
- return { id, label, status: "partial", detail: "Endpoint does not require authentication — auth legibility could not be tested", data: { probeUrl, signals: ["no_auth_required"] } };
77
+ return {
78
+ id, label, status: "error",
79
+ detail: `Could not measure authentication guidance for the selected GET (${httpStatus === null ? "no HTTP response" : `HTTP ${httpStatus}`})`,
80
+ data: { ...probe, ...(!result.ok && { errorKind: result.error.kind }), measurement: "unmeasured", signals: [] },
81
+ };
74
82
  }
75
- //# sourceMappingURL=auth-legibility.js.map
@@ -1,3 +1,2 @@
1
1
  import type { BridgeResult, ScanContext } from "../../core/types.js";
2
- export declare function runContextBridge(ctx: ScanContext): Promise<BridgeResult>;
3
- //# sourceMappingURL=index.d.ts.map
2
+ export declare function runContextBridge(ctx: ScanContext): Promise<BridgeResult<5>>;
@@ -1,3 +1,5 @@
1
+ import { scoreChecks } from "../../core/scoring.js";
2
+ import { incompleteHomepage, unmeasured } from "../standards/probe-evidence.js";
1
3
  import { checkRateLimitHeaders } from "./rate-limits.js";
2
4
  import { checkAuthClarity } from "./auth-clarity.js";
3
5
  import { checkAuthLegibility } from "./auth-legibility.js";
@@ -13,58 +15,35 @@ const CHECK_WEIGHTS = {
13
15
  context_contact_info: 1,
14
16
  context_agents_json: 2,
15
17
  };
16
- function calculateWeightedScore(checks) {
17
- let earned = 0;
18
- let maxPoints = 0;
19
- for (const check of checks) {
20
- const weight = CHECK_WEIGHTS[check.id] ?? 1;
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
- // Every other check counts toward a FIXED denominator regardless of spec
26
- // presence — a spec-gated check that can't be answered without a spec
27
- // fails, it isn't excused. Excusing it made the score non-monotone.
28
- maxPoints += weight;
29
- if (check.status === "pass")
30
- earned += weight;
31
- else if (check.status === "partial")
32
- earned += weight * 0.5;
33
- }
34
- if (maxPoints === 0)
35
- return { score: null, scoreLabel: null };
36
- const score = Math.round((earned / maxPoints) * 100);
37
- const scoreLabel = score >= 60 ? "pass" : score >= 30 ? "partial" : "fail";
38
- return { score, scoreLabel };
39
- }
40
18
  export async function runContextBridge(ctx) {
41
19
  const start = performance.now();
42
20
  const hasSpec = ctx.shared.openApiDetected === true && ctx.shared.openApiSpec != null;
43
- const spec = hasSpec ? ctx.shared.openApiSpec : undefined;
21
+ const spec = hasSpec ? ctx.shared.openApiSpec ?? undefined : undefined;
44
22
  const llmsTxtBody = ctx.shared.llmsTxtBody ?? null;
45
23
  const pageBody = ctx.shared.pageBody ?? null;
46
- const securityTxtBody = ctx.shared.securityTxtBody ?? null;
47
- // Rate-limit probe first — populates ctx.shared.contextProbeHeaders
48
- const rateLimitCheck = await checkRateLimitHeaders(ctx);
49
- const contextProbeHeaders = ctx.shared.contextProbeHeaders ?? {};
50
- // Auth legibility + agents.json probes in parallel
51
- const [authLegibilityCheck, agentsJsonCheck] = await Promise.all([
52
- checkAuthLegibility(ctx),
53
- checkAgentsJson(ctx.baseUrl, ctx.options.timeout),
24
+ const cache = new Map();
25
+ const [rate, authLegibilityCheck, agentsJsonCheck] = await Promise.all([
26
+ checkRateLimitHeaders(ctx, cache), checkAuthLegibility(ctx, cache), checkAgentsJson(ctx.baseUrl, ctx.options.timeout),
54
27
  ]);
55
28
  // Synchronous checks
56
29
  const authClarityCheck = checkAuthClarity(spec);
57
- const tosCheck = checkTosUrl(spec, llmsTxtBody, pageBody, ctx.baseUrl);
58
- const versioningCheck = checkVersioningSignal(spec, contextProbeHeaders);
59
- const contactCheck = checkContactInfo(spec, securityTxtBody);
30
+ const tosCheck = checkTosUrl(spec, llmsTxtBody, pageBody, ctx.shared.pageUrl ?? ctx.baseUrl, ctx.shared.pageTermsUrl);
31
+ const versioningCheck = checkVersioningSignal(spec, rate.headers);
32
+ const contactCheck = checkContactInfo(spec, ctx.shared.securityTxtContact ?? null);
33
+ const unreadContract = !hasSpec && !!(ctx.shared.openApiDiscoveryIncomplete || ctx.shared.openApiDetected);
34
+ const unreadIndex = ctx.shared.rootLlmsResponse && unmeasured(ctx.shared.rootLlmsResponse);
35
+ const evidence = (check, unavailable) => unavailable && check.status === "fail"
36
+ ? { id: check.id, label: check.label, status: "error", detail: "One or more sources for this check could not be fully inspected." }
37
+ : check;
60
38
  const checks = [
61
- rateLimitCheck, authClarityCheck, authLegibilityCheck,
62
- tosCheck, versioningCheck, contactCheck, agentsJsonCheck,
39
+ rate.check, evidence(authClarityCheck, unreadContract), authLegibilityCheck,
40
+ evidence(tosCheck, unreadContract || incompleteHomepage(ctx.shared) || !!unreadIndex),
41
+ evidence(versioningCheck, unreadContract),
42
+ evidence(contactCheck, unreadContract || !!ctx.shared.securityTxtIncomplete), agentsJsonCheck,
63
43
  ];
64
- const { score, scoreLabel } = calculateWeightedScore(checks);
44
+ const { score, scoreLabel } = scoreChecks(checks, CHECK_WEIGHTS, 60, 30);
65
45
  return {
66
46
  id: 5, name: "Context", status: "evaluated", score, scoreLabel, checks,
67
47
  durationMs: Math.round(performance.now() - start),
68
48
  };
69
49
  }
70
- //# sourceMappingURL=index.js.map
@@ -0,0 +1,14 @@
1
+ type Verification = "verified" | "external" | "invalid_binding" | "unavailable";
2
+ export interface OAuthObservation {
3
+ resourceMetadata: string;
4
+ verification: Verification;
5
+ resourceMetadataHasQuery?: true;
6
+ issuer?: string;
7
+ registrationEndpoint?: string;
8
+ deviceAuthorizationEndpoint?: string;
9
+ registrationHasQuery?: true;
10
+ deviceAuthorizationHasQuery?: true;
11
+ }
12
+ /** RFC 9728 section 3.3 and RFC 8414 section 3.3 bind the two documents to this GET. */
13
+ export declare function observeOAuth(header: string, resource: string, timeout: number): Promise<OAuthObservation | undefined>;
14
+ export {};
@@ -0,0 +1,127 @@
1
+ import { parseReference } from "../../utils/url.js";
2
+ import { mediaType } from "../../utils/http-types.js";
3
+ import { httpGet } from "../../utils/http-client.js";
4
+ import { readJson } from "../standards/probe-evidence.js";
5
+ // Commas separate challenges and parameters outside quoted strings (RFC 9110).
6
+ function bearerMetadata(header) {
7
+ if (header.length > 8192)
8
+ return;
9
+ let part = "", quoted = false, escaped = false;
10
+ const parts = [];
11
+ for (const char of header) {
12
+ if (char === "," && !quoted) {
13
+ parts.push(part.trim());
14
+ part = "";
15
+ continue;
16
+ }
17
+ part += char;
18
+ if (escaped)
19
+ escaped = false;
20
+ else if (quoted && char === "\\")
21
+ escaped = true;
22
+ else if (char === '"')
23
+ quoted = !quoted;
24
+ }
25
+ if (quoted)
26
+ return;
27
+ parts.push(part.trim());
28
+ let bearer = false;
29
+ let result;
30
+ for (const item of parts) {
31
+ let parameter = item;
32
+ const scheme = /^([\w!#$%&'*+.^`|~-]+)(?:[ \t]+([^= \t].*)|$)/.exec(item);
33
+ if (scheme) {
34
+ bearer = scheme[1].toLowerCase() === "bearer";
35
+ parameter = scheme[2] ?? "";
36
+ }
37
+ if (!bearer)
38
+ continue;
39
+ const match = /^resource_metadata\s*=\s*"([^"\\]+)"$/i.exec(parameter);
40
+ if (match) {
41
+ if (result !== undefined)
42
+ return;
43
+ result = match[1];
44
+ }
45
+ }
46
+ return result;
47
+ }
48
+ function httpsUrl(value) {
49
+ if (typeof value !== "string" || value.length > 8192 || !/^https:\/\//i.test(value) || /[\s\\]/u.test(value))
50
+ return;
51
+ const url = parseReference(value);
52
+ if (url?.protocol === "https:" && !url.username && !url.password && !value.includes("#"))
53
+ return url;
54
+ }
55
+ // Store only the public location, even when the advertised metadata URL had a query.
56
+ function display(url) { return url.origin + url.pathname; }
57
+ async function document(url, timeout) {
58
+ const response = await httpGet(url.href, { timeout, retry: false, maxRedirects: 0,
59
+ maxBodyBytes: 64 * 1024, headers: { Accept: "application/json" } });
60
+ if (!response.ok && response.error.kind === "http_error" && [404, 410].includes(response.error.statusCode ?? 0))
61
+ return null;
62
+ if (!response.ok || response.url !== url.href || response.status !== 200 || response.bodyIncomplete ||
63
+ response.headers["content-range"] !== undefined || response.redirects.length || mediaType(response.headers) !== "application/json")
64
+ return;
65
+ try {
66
+ const data = readJson(response.body);
67
+ if (data && typeof data === "object" && !Array.isArray(data))
68
+ return data;
69
+ }
70
+ catch { /* An unreadable document cannot establish a binding. */ }
71
+ }
72
+ /** RFC 9728 section 3.3 and RFC 8414 section 3.3 bind the two documents to this GET. */
73
+ export async function observeOAuth(header, resource, timeout) {
74
+ const metadata = httpsUrl(bearerMetadata(header));
75
+ if (!metadata)
76
+ return;
77
+ const origin = new URL(resource).origin;
78
+ const observation = { resourceMetadata: display(metadata), verification: "external" };
79
+ if (metadata.search)
80
+ observation.resourceMetadataHasQuery = true;
81
+ if (metadata.origin !== origin)
82
+ return observation;
83
+ observation.verification = "unavailable";
84
+ const protectedResource = await document(metadata, timeout);
85
+ if (!protectedResource)
86
+ return observation;
87
+ if (protectedResource.resource !== resource)
88
+ return { ...observation, verification: "invalid_binding" };
89
+ if (!Array.isArray(protectedResource.authorization_servers))
90
+ return observation;
91
+ const issuers = [];
92
+ for (const value of protectedResource.authorization_servers) {
93
+ const url = httpsUrl(value);
94
+ if (url && typeof value === "string" && !value.includes("?"))
95
+ issuers.push({ value, url });
96
+ }
97
+ const entry = issuers.find(({ url }) => url.origin === origin) ?? issuers[0];
98
+ if (!entry)
99
+ return observation;
100
+ observation.issuer = entry.value;
101
+ if (entry.url.origin !== origin)
102
+ return { ...observation, verification: "external" };
103
+ const path = entry.url.pathname.replace(/\/$/, "");
104
+ let server = await document(new URL("/.well-known/oauth-authorization-server" + path, origin), timeout);
105
+ if (server === null)
106
+ server = await document(new URL(path + "/.well-known/openid-configuration", origin), timeout);
107
+ if (server === null && path)
108
+ server = await document(new URL("/.well-known/openid-configuration" + path, origin), timeout);
109
+ if (!server)
110
+ return observation;
111
+ if (server.issuer !== entry.value)
112
+ return { ...observation, verification: "invalid_binding" };
113
+ observation.verification = "verified";
114
+ const registration = httpsUrl(server.registration_endpoint);
115
+ const device = httpsUrl(server.device_authorization_endpoint);
116
+ if (registration) {
117
+ observation.registrationEndpoint = display(registration);
118
+ if (registration.search)
119
+ observation.registrationHasQuery = true;
120
+ }
121
+ if (device) {
122
+ observation.deviceAuthorizationEndpoint = display(device);
123
+ if (device.search)
124
+ observation.deviceAuthorizationHasQuery = true;
125
+ }
126
+ return observation;
127
+ }
@@ -0,0 +1,33 @@
1
+ import type { HttpResponse, ScanContext } from "../../core/types.js";
2
+ import { SchemaWorkBudget } from "../schema/schema-sources.js";
3
+ /**
4
+ * The bridge holds the parsed OpenAPI document, which can be most of its heap, while it reads the answers to its
5
+ * own requests. So it parses a JSON body of at most this many characters, about 10 MB parsed.
6
+ */
7
+ export declare const CONTEXT_JSON_SIZE = 262144;
8
+ export interface Probe {
9
+ probeUrl: string;
10
+ method: "GET";
11
+ probeSource: "operation" | "protected_operation" | "fallback";
12
+ }
13
+ /** Prefer explicit operation security to inherited security for an auth sample. */
14
+ export declare function selectProbe(ctx: ScanContext, purpose: "rate" | "auth", budget?: SchemaWorkBudget): Probe;
15
+ export type ProbeCache = Map<string, Promise<HttpResponse>>;
16
+ export declare function readProbe(ctx: ScanContext, purpose: "auth" | "rate", cache?: ProbeCache): Promise<{
17
+ selected: Probe;
18
+ result: HttpResponse;
19
+ timeout: number;
20
+ } | null>;
21
+ export declare function observeProbe(probe: Probe, result: HttpResponse): {
22
+ data: {
23
+ responseHasQuery?: boolean | undefined;
24
+ responseUrl?: string | undefined;
25
+ httpStatus: number | null;
26
+ probeUrl: string;
27
+ method: "GET";
28
+ probeSource: "operation" | "protected_operation" | "fallback";
29
+ };
30
+ response: Pick<import("../../utils/http-types.js").HttpSuccess, "status" | "headers" | "body" | "bodyIncomplete"> | undefined;
31
+ html: boolean;
32
+ attributable: boolean;
33
+ };
@@ -0,0 +1,157 @@
1
+ import { effectiveOrigin, MAX_URL_LENGTH, parseReference } from "../../utils/url.js";
2
+ import { mediaType } from "../../utils/http-types.js";
3
+ import { httpGet } from "../../utils/http-client.js";
4
+ import { OVERSIZED, readJson } from "../standards/probe-evidence.js";
5
+ import { collectOperations, openApiServerUrl, swaggerBasePath } from "../schema/oas-types.js";
6
+ import { operationParameters, resolvePathItem, resolveRequestBody, SchemaWorkBudget, SchemaWorkLimit } from "../schema/schema-sources.js";
7
+ /**
8
+ * The bridge holds the parsed OpenAPI document, which can be most of its heap, while it reads the answers to its
9
+ * own requests. So it parses a JSON body of at most this many characters, about 10 MB parsed.
10
+ */
11
+ export const CONTEXT_JSON_SIZE = 262_144;
12
+ /** OpenAPI resolves server URLs against the document which defined them. */
13
+ function serverBase(spec, servers, origin, documentUrl, budget) {
14
+ const document = documentUrl ? URL.parse(documentUrl) : null;
15
+ if (spec.swagger === "2.0") {
16
+ if (spec.host === undefined && document && document.origin !== origin)
17
+ return null;
18
+ return swaggerBasePath(spec, origin);
19
+ }
20
+ if (servers !== undefined && !Array.isArray(servers))
21
+ return null;
22
+ for (const server of servers?.length ? servers : [{ url: "/" }]) {
23
+ budget.charge();
24
+ const raw = openApiServerUrl(server);
25
+ if (!raw || /[?#\\\s]/.test(raw) || (!document && !/^(?:\/|https?:\/\/)/i.test(raw)))
26
+ continue;
27
+ const url = parseReference(raw, document?.href ?? origin);
28
+ if (url?.origin === origin && !url.username && !url.password)
29
+ return url.pathname.replace(/\/$/, "");
30
+ }
31
+ return null;
32
+ }
33
+ /** Prefer explicit operation security to inherited security for an auth sample. */
34
+ export function selectProbe(ctx, purpose, budget = new SchemaWorkBudget()) {
35
+ const spec = ctx.shared.openApiSpec;
36
+ const documentUrl = ctx.shared.openApiCheck?.data?.documentUrl;
37
+ const site = effectiveOrigin(ctx.baseUrl, ctx.shared.pageUrl);
38
+ const fallback = { method: "GET", probeSource: "fallback", probeUrl: site + "/api" };
39
+ if (!spec)
40
+ return fallback;
41
+ const document = typeof documentUrl === "string" ? documentUrl : undefined;
42
+ // The canonical origin widens the probe scope only when the contract itself was served there.
43
+ const origins = site !== ctx.baseUrl && document && URL.parse(document)?.origin === site ? [site, ctx.baseUrl] : [ctx.baseUrl];
44
+ // A server on the canonical origin is preferred; one that names the scan origin is still in scope.
45
+ const locate = (servers) => {
46
+ for (const origin of origins) {
47
+ const base = serverBase(spec, servers, origin, document, budget);
48
+ if (base !== null)
49
+ return { origin, base };
50
+ }
51
+ return null;
52
+ };
53
+ const isProtected = (security) => Array.isArray(security) && security.length > 0 &&
54
+ security.every(s => {
55
+ budget.charge();
56
+ return s && typeof s === "object" && !Array.isArray(s) && Object.keys(s).length > 0;
57
+ });
58
+ let defaultServer;
59
+ let defaultProtection;
60
+ let inherited;
61
+ for (const [path, method, op] of collectOperations(spec, budget)) {
62
+ if (method !== "get" || /[{}?#\s]/.test(path))
63
+ continue;
64
+ const item = resolvePathItem(spec, path, budget);
65
+ if (!item)
66
+ continue;
67
+ for (const group of [item.parameters, op.parameters])
68
+ if (Array.isArray(group))
69
+ budget.charge(group.length);
70
+ if ([item.parameters, op.parameters].some(value => value !== undefined &&
71
+ (!Array.isArray(value) || value.some(p => !p || typeof p !== "object" || Array.isArray(p)))))
72
+ continue;
73
+ if (operationParameters(spec, path, op, budget).some(p => !p.name || !p.in || p.required || p.$ref || p.in === "path"))
74
+ continue;
75
+ if (op.requestBody && spec.swagger !== "2.0") {
76
+ const body = resolveRequestBody(spec, op, budget);
77
+ if (!body || body.required)
78
+ continue;
79
+ }
80
+ const servers = op.servers !== undefined ? op.servers : item.servers;
81
+ let server;
82
+ if (servers === undefined || spec.swagger === "2.0") {
83
+ if (defaultServer === undefined)
84
+ defaultServer = locate(spec.servers);
85
+ server = defaultServer;
86
+ }
87
+ else {
88
+ server = locate(servers);
89
+ }
90
+ if (server === null)
91
+ continue;
92
+ const { origin, base } = server;
93
+ const url = new URL(origin + base + path);
94
+ if (url.origin !== origin || url.pathname !== base + path)
95
+ continue;
96
+ // Another operation or the fallback can still be measured; a longer URL is one the scanner never requests.
97
+ if (url.href.length > MAX_URL_LENGTH)
98
+ continue;
99
+ const protectedGet = op.security === undefined
100
+ ? (defaultProtection ??= isProtected(spec.security)) : isProtected(op.security);
101
+ if (purpose === "rate") {
102
+ const candidate = { method: "GET", probeSource: "operation", probeUrl: url.href };
103
+ if (!protectedGet)
104
+ return candidate;
105
+ inherited ??= candidate;
106
+ continue;
107
+ }
108
+ if (!protectedGet)
109
+ continue;
110
+ const candidate = { method: "GET", probeSource: "protected_operation", probeUrl: url.href };
111
+ if (op.security !== undefined)
112
+ return candidate;
113
+ inherited ??= candidate;
114
+ }
115
+ return inherited ?? fallback;
116
+ }
117
+ export async function readProbe(ctx, purpose, cache) {
118
+ let selected;
119
+ try {
120
+ selected = selectProbe(ctx, purpose);
121
+ }
122
+ catch (error) {
123
+ if (error instanceof SchemaWorkLimit)
124
+ return null;
125
+ throw error;
126
+ }
127
+ const timeout = Math.min(ctx.options.timeout ?? 10_000, 5000);
128
+ const result = cache?.get(selected.probeUrl) ?? httpGet(selected.probeUrl, { timeout, captureFullErrorBody: true });
129
+ cache?.set(selected.probeUrl, result);
130
+ return { selected, result: await result, timeout };
131
+ }
132
+ export function observeProbe(probe, result) {
133
+ const httpStatus = result.ok ? result.status : result.response?.status ?? result.error.statusCode ?? null;
134
+ const final = httpStatus !== null ? URL.parse(result.ok ? result.url : result.error.url) : null;
135
+ const responseUrl = final && ["http:", "https:"].includes(final.protocol) ? final.origin + final.pathname : undefined;
136
+ const hasQuery = final?.href.split("#", 1)[0].includes("?") === true;
137
+ const data = { ...probe, httpStatus, ...(responseUrl && { responseUrl }), ...(hasQuery && { responseHasQuery: true }) };
138
+ const response = result.ok ? result : result.response;
139
+ const incomplete = response && (httpStatus === 206 || response.headers["content-range"] !== undefined ||
140
+ ("bodyIncomplete" in response && response.bodyIncomplete === true));
141
+ const contentType = mediaType(response?.headers);
142
+ const sample = response?.body.trimStart().slice(0, 512) ?? "";
143
+ const html = contentType === "text/html" || contentType === "application/xhtml+xml" || /^<(?:!doctype\s+html|html|head|body)\b/i.test(sample);
144
+ let json = false;
145
+ if (probe.probeSource === "fallback" && response && !html && /^[{\[]/.test(sample) &&
146
+ (!contentType || contentType === "application/json" || contentType.endsWith("+json"))) {
147
+ try {
148
+ json = readJson(response.body, CONTEXT_JSON_SIZE) !== OVERSIZED;
149
+ }
150
+ catch { /* A truncated or invalid body cannot establish an API fallback, nor can one too large to parse. */ }
151
+ }
152
+ const authChallenge = (httpStatus === 401 || httpStatus === 403) && Boolean(response?.headers["www-authenticate"]);
153
+ const sameResource = responseUrl === probe.probeUrl && !hasQuery && !final?.username && !final?.password;
154
+ const attributable = sameResource && !incomplete && httpStatus !== null && (httpStatus < 300 || httpStatus >= 400) &&
155
+ (probe.probeSource !== "fallback" || (!html && (json || authChallenge)));
156
+ return { data, response, html, attributable };
157
+ }
@@ -1,3 +1,6 @@
1
1
  import type { Check, ScanContext } from "../../core/types.js";
2
- export declare function checkRateLimitHeaders(ctx: ScanContext): Promise<Check>;
3
- //# sourceMappingURL=rate-limits.d.ts.map
2
+ import { type ProbeCache } from "./probe.js";
3
+ export declare function checkRateLimitHeaders(ctx: ScanContext, cache?: ProbeCache): Promise<{
4
+ check: Check;
5
+ headers: Record<string, string>;
6
+ }>;