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,5 +1 @@
1
- /** Keep untrusted report fields on one line and prevent terminal control sequences. */
2
- export function terminalText(value) {
3
- return value.replace(/[\p{Cc}\p{Bidi_Control}\u2028\u2029]/gu, " ");
4
- }
5
- //# sourceMappingURL=terminal-text.js.map
1
+ export { terminalText } from "../utils/terminal-text.js";
@@ -0,0 +1,3 @@
1
+ import { type Transferable } from "node:worker_threads";
2
+ export declare function finishAnalysis(value: unknown, transferList?: readonly Transferable[]): void;
3
+ export declare function analysisLimit(message: string): void;
@@ -0,0 +1,12 @@
1
+ import { getHeapStatistics } from "node:v8";
2
+ import { parentPort } from "node:worker_threads";
3
+ // V8 flags supplied to the host process can override a Worker's requested heap sizes.
4
+ if (getHeapStatistics().heap_size_limit > 160 * 1024 * 1024) {
5
+ throw Object.assign(new Error("Host V8 settings exceed the analysis heap limit"), { code: "ERR_ANALYSIS_HEAP_OVERRIDE" });
6
+ }
7
+ export function finishAnalysis(value, transferList = []) {
8
+ parentPort.postMessage({ kind: "result", value }, transferList);
9
+ }
10
+ export function analysisLimit(message) {
11
+ parentPort.postMessage({ kind: "limit", message });
12
+ }
@@ -0,0 +1,12 @@
1
+ import { type Transferable } from "node:worker_threads";
2
+ export declare class AnalysisLimitError extends Error {
3
+ }
4
+ export declare const ANALYSIS_TIME_LIMIT_MS = 60000;
5
+ interface AnalysisOptions {
6
+ signal?: AbortSignal;
7
+ timeoutMs?: number;
8
+ transferList?: Transferable[];
9
+ }
10
+ /** Run one analysis in its own V8 heap. The parent owns its clock and cancellation. */
11
+ export declare function runAnalysisWorker<Output>(entry: URL, input: unknown, options?: AnalysisOptions): Promise<Output>;
12
+ export {};
@@ -0,0 +1,54 @@
1
+ import { Worker } from "node:worker_threads";
2
+ export class AnalysisLimitError extends Error {
3
+ }
4
+ export const ANALYSIS_TIME_LIMIT_MS = 60_000;
5
+ /** Run one analysis in its own V8 heap. The parent owns its clock and cancellation. */
6
+ export async function runAnalysisWorker(entry, input, options = {}) {
7
+ const { signal, timeoutMs = ANALYSIS_TIME_LIMIT_MS } = options;
8
+ signal?.throwIfAborted();
9
+ // Installed packages contain JS. Source commands (tsx and Vitest) resolve .js imports to .ts.
10
+ let executable = entry;
11
+ if (import.meta.url.endsWith(".ts") && entry.pathname.endsWith(".js")) {
12
+ const source = new URL(entry);
13
+ source.pathname = source.pathname.slice(0, -3) + ".ts";
14
+ const loader = import.meta.resolve("tsx/esm/api");
15
+ executable = new URL("data:text/javascript," + encodeURIComponent(`import { register } from ${JSON.stringify(loader)}; register(); await import(${JSON.stringify(source.href)});`));
16
+ }
17
+ const worker = new Worker(executable, {
18
+ workerData: input,
19
+ transferList: options.transferList,
20
+ // Do not re-run the caller's CLI preload scripts for each page or bridge.
21
+ execArgv: [],
22
+ resourceLimits: { maxOldGenerationSizeMb: 128, maxYoungGenerationSizeMb: 16 },
23
+ });
24
+ let timer;
25
+ let abort;
26
+ try {
27
+ return await new Promise((resolve, reject) => {
28
+ abort = () => reject(signal?.reason);
29
+ signal?.addEventListener("abort", abort, { once: true });
30
+ timer = setTimeout(() => reject(new AnalysisLimitError("Analysis time limit exceeded")), timeoutMs);
31
+ worker.once("message", (message) => {
32
+ if (message.kind === "result")
33
+ resolve(message.value);
34
+ else
35
+ reject(new AnalysisLimitError(message.message));
36
+ });
37
+ worker.once("error", (error) => {
38
+ if (error.code === "ERR_WORKER_OUT_OF_MEMORY")
39
+ reject(new AnalysisLimitError("Analysis heap limit exceeded"));
40
+ else if (error.code === "ERR_ANALYSIS_HEAP_OVERRIDE")
41
+ reject(new AnalysisLimitError(error.message));
42
+ else
43
+ reject(error);
44
+ });
45
+ worker.once("exit", code => reject(new Error(`Analysis worker exited before returning a result (code ${code})`)));
46
+ });
47
+ }
48
+ finally {
49
+ clearTimeout(timer);
50
+ if (abort)
51
+ signal?.removeEventListener("abort", abort);
52
+ await worker.terminate();
53
+ }
54
+ }
@@ -0,0 +1,39 @@
1
+ import { type DefaultTreeAdapterTypes } from "parse5";
2
+ import type { HttpResponse } from "./http-types.js";
3
+ /**
4
+ * Parse memory follows created nodes, not input bytes: misnested formatting markup clones every open
5
+ * formatting element per paragraph, so a 28 KB body can build two million elements. An element or a comment counts
6
+ * as one node, an attribute as half and a text node as a quarter, about what each holds beside an element with
7
+ * children: a page of short links is 1.75 nodes a link, at about 570 bytes each.
8
+ */
9
+ export declare const MAX_HTML_NODES = 200000;
10
+ /**
11
+ * parse5 builds the name of a tag or an attribute and the parts of a doctype a character at a time, and V8 keeps
12
+ * such a string as a chain of every step, about 31 bytes a character, until it is copied: four megabytes of names
13
+ * held a worker's whole heap. One tag or doctype may hold this many such characters; an element keeps flat copies.
14
+ */
15
+ export declare const MAX_NAME_CHARS = 262144;
16
+ /**
17
+ * parse5 work for each formatting element it inserts grows with the distinct formatting elements open above it
18
+ * (other ancestors cost nothing). Charging every insertion one plus its formatting ancestors over-estimates that
19
+ * for repeated or non-formatting markup. Every copy parse5 makes of a formatting element shares its start tag's
20
+ * attribute list: the adoption agency sorts and hashes the whole list again for each copy, and every reader of the
21
+ * tree scans it once per copy, so a copy is charged for its attributes. These counters cover tree construction.
22
+ */
23
+ export declare const MAX_HTML_NESTING = 20000000;
24
+ export declare const HTML_LIMIT_DETAIL = "markup exceeds the parser's inspection limit";
25
+ export declare class HtmlLimitError extends Error {
26
+ constructor();
27
+ }
28
+ /**
29
+ * Whether one tag or doctype holds more than `max` name characters. Where a tag starts depends on the markup before
30
+ * it, so every "<" that could start one is followed as the tokenizer would follow a tag from there, all of them in
31
+ * one pass: each state carries the highest count among the tags that are in it.
32
+ */
33
+ export declare function hasOverlongNames(html: string, max?: number): boolean;
34
+ export declare function parseHtml(html: string, maxNodes?: number, maxNesting?: number): DefaultTreeAdapterTypes.Document;
35
+ /** A body over the node or formatting-nesting limit reaches no parser and reads as an incomplete representation. */
36
+ export declare function inspectableHtml<T extends HttpResponse>(response: T): T;
37
+ /** HTML elements in document order, excluding inert template and noscript contents. */
38
+ export declare function htmlElements(html: string): Generator<DefaultTreeAdapterTypes.Element>;
39
+ export declare function looksLikeHtml(body: string): boolean;
@@ -0,0 +1,261 @@
1
+ import { Parser, defaultTreeAdapter } from "parse5";
2
+ /**
3
+ * Parse memory follows created nodes, not input bytes: misnested formatting markup clones every open
4
+ * formatting element per paragraph, so a 28 KB body can build two million elements. An element or a comment counts
5
+ * as one node, an attribute as half and a text node as a quarter, about what each holds beside an element with
6
+ * children: a page of short links is 1.75 nodes a link, at about 570 bytes each.
7
+ */
8
+ export const MAX_HTML_NODES = 200_000;
9
+ /**
10
+ * parse5 builds the name of a tag or an attribute and the parts of a doctype a character at a time, and V8 keeps
11
+ * such a string as a chain of every step, about 31 bytes a character, until it is copied: four megabytes of names
12
+ * held a worker's whole heap. One tag or doctype may hold this many such characters; an element keeps flat copies.
13
+ */
14
+ export const MAX_NAME_CHARS = 262_144;
15
+ /**
16
+ * parse5 work for each formatting element it inserts grows with the distinct formatting elements open above it
17
+ * (other ancestors cost nothing). Charging every insertion one plus its formatting ancestors over-estimates that
18
+ * for repeated or non-formatting markup. Every copy parse5 makes of a formatting element shares its start tag's
19
+ * attribute list: the adoption agency sorts and hashes the whole list again for each copy, and every reader of the
20
+ * tree scans it once per copy, so a copy is charged for its attributes. These counters cover tree construction.
21
+ */
22
+ export const MAX_HTML_NESTING = 20_000_000;
23
+ export const HTML_LIMIT_DETAIL = "markup exceeds the parser's inspection limit";
24
+ const FORMATTING = new Set(["a", "b", "big", "code", "em", "font", "i", "nobr", "s", "small", "strike", "strong", "tt", "u"]);
25
+ export class HtmlLimitError extends Error {
26
+ constructor() { super("HTML " + HTML_LIMIT_DETAIL); }
27
+ }
28
+ const [TAG, BEFORE, NAME, AFTER, VALUE, BARE, DOUBLE, SINGLE, DOCTYPE] = [0, 1, 2, 3, 4, 5, 6, 7, 8];
29
+ /**
30
+ * Whether one tag or doctype holds more than `max` name characters. Where a tag starts depends on the markup before
31
+ * it, so every "<" that could start one is followed as the tokenizer would follow a tag from there, all of them in
32
+ * one pass: each state carries the highest count among the tags that are in it.
33
+ */
34
+ export function hasOverlongNames(html, max = MAX_NAME_CHARS) {
35
+ const letter = (code) => (code | 32) >= 97 && (code | 32) <= 122;
36
+ let counts = new Int32Array(9).fill(-1), next = new Int32Array(9);
37
+ let open = false;
38
+ let start = -1;
39
+ for (let i = 0; i < html.length; i++) {
40
+ if (!open && i > start) {
41
+ i = html.indexOf("<", i);
42
+ if (i < 0)
43
+ break;
44
+ }
45
+ const code = html.charCodeAt(i);
46
+ const space = code === 32 || code === 9 || code === 10 || code === 12 || code === 13;
47
+ const close = code === 62;
48
+ if (i === start && counts[TAG] < 0)
49
+ counts[TAG] = 0;
50
+ next.fill(-1);
51
+ open = false;
52
+ for (let state = 0; state < 9; state++) {
53
+ let count = counts[state];
54
+ if (count < 0)
55
+ continue;
56
+ let to = state;
57
+ if (state === DOUBLE || state === SINGLE) {
58
+ if (code === (state === DOUBLE ? 34 : 39))
59
+ to = BEFORE;
60
+ }
61
+ else if (close) {
62
+ continue;
63
+ }
64
+ else if (state === DOCTYPE) {
65
+ count++;
66
+ }
67
+ else if (state === VALUE) {
68
+ if (!space)
69
+ to = code === 34 ? DOUBLE : code === 39 ? SINGLE : BARE;
70
+ }
71
+ else if (state === BARE) {
72
+ if (space)
73
+ to = BEFORE;
74
+ }
75
+ else if (space) {
76
+ to = state === TAG || state === BEFORE ? BEFORE : AFTER;
77
+ }
78
+ else if (code === 47) {
79
+ to = BEFORE;
80
+ }
81
+ else if (code === 61 && (state === NAME || state === AFTER)) {
82
+ to = VALUE;
83
+ }
84
+ else {
85
+ // The name of the tag, or of an attribute: one that "=" opens outside a name is named for it.
86
+ if (state !== TAG)
87
+ to = NAME;
88
+ count++;
89
+ }
90
+ if (count > max)
91
+ return true;
92
+ if (count > next[to])
93
+ next[to] = count;
94
+ open = true;
95
+ }
96
+ if (code === 60) {
97
+ const ahead = html.charCodeAt(i + 1);
98
+ if (letter(ahead))
99
+ start = i + 1;
100
+ else if (ahead === 47 && letter(html.charCodeAt(i + 2)))
101
+ start = i + 2;
102
+ else if (ahead === 33 && next[DOCTYPE] < 0 && html.slice(i + 2, i + 9).toLowerCase() === "doctype") {
103
+ next[DOCTYPE] = 0;
104
+ open = true;
105
+ }
106
+ }
107
+ const spare = counts;
108
+ counts = next;
109
+ next = spare;
110
+ }
111
+ return false;
112
+ }
113
+ /**
114
+ * parse5 holds the text placed directly in a table, a word or a gap at a time, until the next tag, and calls no tree
115
+ * adapter method meanwhile: 2.5 MB of single letters there held a worker's whole heap. So this extends the parser
116
+ * itself, which parse5 exports as internal and package.json pins: `held` is called for each piece after the first.
117
+ */
118
+ class TableTextParser extends Parser {
119
+ held = () => { };
120
+ onCharacter(token) {
121
+ super.onCharacter(token);
122
+ this.report(token);
123
+ }
124
+ onWhitespaceCharacter(token) {
125
+ super.onWhitespaceCharacter(token);
126
+ this.report(token);
127
+ }
128
+ report(token) {
129
+ const pending = this.pendingCharacterTokens;
130
+ if (pending.length > 1 && pending[pending.length - 1] === token)
131
+ this.held();
132
+ }
133
+ }
134
+ export function parseHtml(html, maxNodes = MAX_HTML_NODES, maxNesting = MAX_HTML_NESTING) {
135
+ if (hasOverlongNames(html))
136
+ throw new HtmlLimitError();
137
+ let nodes = 0, nesting = 0;
138
+ const formatting = new WeakMap();
139
+ // Counted in quarters of a node.
140
+ const count = (quarters) => { if ((nodes += quarters) > maxNodes * 4)
141
+ throw new HtmlLimitError(); };
142
+ // A name of fewer than 13 characters is never a chain.
143
+ const flat = (name) => name.length < 13 ? name : (" " + name).slice(1);
144
+ const named = (attrs) => {
145
+ for (const attr of attrs)
146
+ attr.name = flat(attr.name);
147
+ return attrs;
148
+ };
149
+ const shared = new WeakMap();
150
+ const copy = (attrs) => {
151
+ // Only a second element built from one start tag is a copy; the first costs what its bytes cost to tokenize.
152
+ const weight = shared.get(attrs);
153
+ if (weight === undefined)
154
+ shared.set(attrs, attrs.reduce((sum, { name, value }) => sum + 16 + name.length + value.length, 0));
155
+ else if ((nesting += weight) > maxNesting)
156
+ throw new HtmlLimitError();
157
+ };
158
+ const nest = (parent, child) => {
159
+ // The adoption agency fills a recreated element before attaching it; its children are charged once it has a place.
160
+ const above = "tagName" in parent ? formatting.get(parent) : 0;
161
+ if (above === undefined)
162
+ return;
163
+ const placed = formatting.has(child);
164
+ formatting.set(child, above + ("tagName" in child && FORMATTING.has(child.tagName) ? 1 : 0));
165
+ if ((nesting += above + 1) > maxNesting)
166
+ throw new HtmlLimitError();
167
+ if (!placed && "childNodes" in child)
168
+ for (const node of child.childNodes)
169
+ if (!formatting.has(node))
170
+ nest(child, node);
171
+ };
172
+ // parse5 hands text over a word or a gap at a time and appends each piece to its node's value, which V8 keeps as
173
+ // a tree of every piece: five megabytes of single letters cost 150 MB. The pieces of the node being written are
174
+ // held here and joined when the parser moves to another node.
175
+ let written;
176
+ const pieces = [];
177
+ const join = () => { if (written && pieces.length)
178
+ written.value += pieces.splice(0).join(""); };
179
+ const write = (before, piece) => {
180
+ if (!before || !defaultTreeAdapter.isTextNode(before))
181
+ return false;
182
+ if (before !== written) {
183
+ join();
184
+ written = before;
185
+ }
186
+ if (pieces.push(piece) === 4096)
187
+ join();
188
+ return true;
189
+ };
190
+ const parser = new TableTextParser({ treeAdapter: { ...defaultTreeAdapter,
191
+ createElement: (tag, namespace, attrs) => (count(4 + 2 * attrs.length), FORMATTING.has(tag) && copy(attrs),
192
+ defaultTreeAdapter.createElement(flat(tag), namespace, named(attrs))),
193
+ createCommentNode: data => (count(4), defaultTreeAdapter.createCommentNode(data)),
194
+ setDocumentType: (document, ...parts) => defaultTreeAdapter.setDocumentType(document, flat(parts[0]), flat(parts[1]), flat(parts[2])),
195
+ appendChild: (parent, child) => (nest(parent, child), defaultTreeAdapter.appendChild(parent, child)),
196
+ insertBefore: (parent, child, ref) => (nest(parent, child), defaultTreeAdapter.insertBefore(parent, child, ref)),
197
+ insertText: (parent, piece) => {
198
+ if (!write(parent.childNodes[parent.childNodes.length - 1], piece))
199
+ (count(1), defaultTreeAdapter.insertText(parent, piece));
200
+ },
201
+ insertTextBefore: (parent, piece, ref) => {
202
+ // Text moved out of a table goes in front of it, and the table is its parent's last child: looked for from the
203
+ // start, each piece of that text would pass every sibling.
204
+ const { childNodes } = parent;
205
+ const at = childNodes[childNodes.length - 1] === ref ? childNodes.length - 1 : childNodes.indexOf(ref);
206
+ if (!write(childNodes[at - 1], piece))
207
+ (count(1), defaultTreeAdapter.insertTextBefore(parent, piece, ref));
208
+ },
209
+ // Attributes a repeated <html> or <body> start tag adds to the element already open.
210
+ adoptAttributes: (recipient, attrs) => {
211
+ const held = recipient.attrs.length;
212
+ defaultTreeAdapter.adoptAttributes(recipient, named(attrs));
213
+ count(2 * (recipient.attrs.length - held));
214
+ },
215
+ } });
216
+ // A piece held for a table is a text node not yet built.
217
+ parser.held = () => count(1);
218
+ parser.tokenizer.write(html, true);
219
+ join();
220
+ return parser.document;
221
+ }
222
+ /** A body over the node or formatting-nesting limit reaches no parser and reads as an incomplete representation. */
223
+ export function inspectableHtml(response) {
224
+ if (!response.ok)
225
+ return response;
226
+ try {
227
+ parseHtml(response.body);
228
+ }
229
+ catch (error) {
230
+ if (error instanceof HtmlLimitError)
231
+ return { ...response, body: "", bodyIncomplete: true };
232
+ throw error;
233
+ }
234
+ return response;
235
+ }
236
+ /** HTML elements in document order, excluding inert template and noscript contents. */
237
+ export function* htmlElements(html) {
238
+ const nodes = parseHtml(html).childNodes.slice().reverse();
239
+ while (nodes.length) {
240
+ const node = nodes.pop();
241
+ if (!("tagName" in node) || node.namespaceURI !== "http://www.w3.org/1999/xhtml")
242
+ continue;
243
+ if (node.tagName === "template" || node.tagName === "noscript")
244
+ continue;
245
+ yield node;
246
+ for (let i = node.childNodes.length - 1; i >= 0; i--)
247
+ nodes.push(node.childNodes[i]);
248
+ }
249
+ }
250
+ export function looksLikeHtml(body) {
251
+ const sample = body.trimStart().slice(0, 2048).replace(/^(?:<!--[\s\S]*?-->\s*)+/, "");
252
+ // READMEs often place a centered HTML banner before their first Markdown heading.
253
+ const banner = /^<(p|div)\b/i.exec(sample);
254
+ if (banner) {
255
+ const closing = "</" + banner[1].toLowerCase() + ">";
256
+ const close = sample.toLowerCase().indexOf(closing);
257
+ if (close >= 0 && /^[ \t]*\r?\n\s*#{1,6}[ \t]+\S/.test(sample.slice(close + closing.length)))
258
+ return false;
259
+ }
260
+ return /^(?:<!doctype\s+html|<(?:html|head|body|div|main|p|section|article|title|h[1-6])\b)/i.test(sample);
261
+ }
@@ -1,11 +1,9 @@
1
- import type { HttpResponse, HttpSuccess, HttpFailure } from "../core/types.js";
1
+ import type { ScanRequestSummary, ScanOptions } from "../core/types.js";
2
+ import type { HttpFailure, HttpResponse, HttpSuccess } from "./http-types.js";
2
3
  import { type DnsCache } from "./ssrf.js";
3
4
  import type { LookupFunction } from "node:net";
4
- /**
5
- * A DNS lookup that always resolves to `ip`, ignoring the hostname. Pins a
6
- * connection to the exact address that `validateDns` approved.
7
- */
8
- export declare function pinnedLookup(ip: string): LookupFunction;
5
+ /** Return only addresses from the validated DNS answer, including family fallback. */
6
+ export declare function pinnedLookup(addresses: readonly string[]): LookupFunction;
9
7
  export interface HttpBytesSuccess extends Omit<HttpSuccess, "body"> {
10
8
  body: Uint8Array;
11
9
  }
@@ -23,29 +21,34 @@ export declare class RequestCoordinator {
23
21
  /** Fetch attempts denied because the budget was exhausted */
24
22
  get deniedCount(): number;
25
23
  constructor(maxConcurrency?: number, maxRequests?: number);
26
- acquire(): Promise<boolean>;
24
+ acquire(signal?: AbortSignal): Promise<boolean>;
27
25
  release(): void;
28
26
  private drain;
29
27
  }
30
- export declare function runWithScanRequestContext<T>(options: {
31
- maxConcurrency?: number;
32
- maxRequests?: number;
33
- }, callback: () => Promise<T>): Promise<T>;
28
+ interface BridgeTransport {
29
+ get: typeof httpGet;
30
+ bytes: typeof httpGetBytes;
31
+ }
32
+ export declare function runWithBridgeTransport<T>(transport: BridgeTransport, callback: () => T): T;
33
+ export declare function runWithScanRequestContext<T>(options: ScanOptions, callback: () => Promise<T>): Promise<T>;
34
34
  /** Request stats for the current scan context, or null outside one. */
35
- export declare function getScanRequestStats(): {
36
- started: number;
37
- denied: number;
38
- } | null;
35
+ export declare function getScanRequestStats(): ScanRequestSummary | null;
39
36
  /** Options for httpGet (also supports POST despite the name) */
40
37
  export interface HttpGetOptions {
38
+ /** Cancel this probe while retaining the scan-wide deadline. */
39
+ signal?: AbortSignal;
41
40
  /** HTTP method (default: "GET") */
42
41
  method?: "GET" | "HEAD" | "POST";
43
42
  /** Per-request timeout in milliseconds (default: 10000) */
44
43
  timeout?: number;
44
+ /** Set false for a single bounded attempt. */
45
+ retry?: boolean;
45
46
  /** Maximum number of redirects to follow (default: 5) */
46
47
  maxRedirects?: number;
47
48
  /** Maximum response body size in bytes (default: 5MB) */
48
49
  maxBodyBytes?: number;
50
+ /** Keep up to maxBodyBytes for probes that inspect complete rejection bodies. Other probes capture at most 64 KiB. */
51
+ captureFullErrorBody?: boolean;
49
52
  /** Scan-scoped DNS cache -- caller creates and reuses across requests */
50
53
  dnsCache?: DnsCache;
51
54
  /** Custom headers to merge with defaults */
@@ -66,5 +69,9 @@ export interface HttpGetOptions {
66
69
  */
67
70
  export declare function httpGet(url: string, options?: Partial<HttpGetOptions>): Promise<HttpResponse>;
68
71
  /** Binary counterpart for internal consumers such as compressed sitemaps. */
69
- export declare function httpGetBytes(url: string, options?: Partial<HttpGetOptions>): Promise<HttpBytesResponse>;
70
- //# sourceMappingURL=http-client.d.ts.map
72
+ export declare function httpGetBytes(url: string, options?: Partial<HttpGetOptions> & {
73
+ signal?: AbortSignal;
74
+ retry?: boolean;
75
+ publicProductRead?: boolean;
76
+ }): Promise<HttpBytesResponse>;
77
+ export {};