recker 1.0.20-next.de24f7d → 1.0.20-next.e194d90

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 (433) hide show
  1. package/README.md +31 -0
  2. package/dist/ai/adaptive-timeout.d.ts +0 -1
  3. package/dist/ai/client.d.ts +0 -1
  4. package/dist/ai/client.js +6 -0
  5. package/dist/ai/index.d.ts +3 -1
  6. package/dist/ai/index.js +3 -0
  7. package/dist/ai/providers/anthropic.d.ts +0 -1
  8. package/dist/ai/providers/base.d.ts +0 -1
  9. package/dist/ai/providers/google.d.ts +59 -0
  10. package/dist/ai/providers/google.js +305 -0
  11. package/dist/ai/providers/index.d.ts +4 -1
  12. package/dist/ai/providers/index.js +2 -0
  13. package/dist/ai/providers/ollama.d.ts +44 -0
  14. package/dist/ai/providers/ollama.js +240 -0
  15. package/dist/ai/providers/openai.d.ts +0 -1
  16. package/dist/ai/rate-limiter.d.ts +0 -1
  17. package/dist/ai/vector/index.d.ts +2 -0
  18. package/dist/ai/vector/index.js +2 -0
  19. package/dist/ai/vector/similarity.d.ts +2 -0
  20. package/dist/ai/vector/similarity.js +27 -0
  21. package/dist/ai/vector/store.d.ts +27 -0
  22. package/dist/ai/vector/store.js +82 -0
  23. package/dist/bench/generator.d.ts +0 -1
  24. package/dist/bench/stats.d.ts +0 -1
  25. package/dist/cache/basic-file-storage.d.ts +12 -0
  26. package/dist/cache/basic-file-storage.js +50 -0
  27. package/dist/cache/file-storage.d.ts +25 -11
  28. package/dist/cache/file-storage.js +175 -30
  29. package/dist/cache/memory-limits.d.ts +0 -1
  30. package/dist/cache/memory-storage.d.ts +0 -1
  31. package/dist/cache/redis-storage.d.ts +0 -1
  32. package/dist/cli/handler.d.ts +2 -1
  33. package/dist/cli/handler.js +36 -5
  34. package/dist/cli/index.d.ts +0 -2
  35. package/dist/cli/index.js +559 -6
  36. package/dist/cli/presets.d.ts +0 -1
  37. package/dist/cli/tui/ai-chat.d.ts +0 -1
  38. package/dist/cli/tui/load-dashboard.d.ts +0 -1
  39. package/dist/cli/tui/scroll-buffer.d.ts +0 -1
  40. package/dist/cli/tui/search-panel.d.ts +0 -1
  41. package/dist/cli/tui/shell-search.d.ts +0 -1
  42. package/dist/cli/tui/shell.d.ts +0 -1
  43. package/dist/cli/tui/shell.js +1 -1
  44. package/dist/cli/tui/websocket.d.ts +0 -1
  45. package/dist/constants/http-status.d.ts +0 -1
  46. package/dist/constants.d.ts +0 -1
  47. package/dist/contract/index.d.ts +0 -1
  48. package/dist/cookies/memory-cookie-jar.d.ts +0 -1
  49. package/dist/core/client.d.ts +0 -1
  50. package/dist/core/client.js +1 -1
  51. package/dist/core/errors.d.ts +0 -1
  52. package/dist/core/index.d.ts +0 -1
  53. package/dist/core/request-promise.d.ts +0 -1
  54. package/dist/core/request.d.ts +0 -1
  55. package/dist/core/response.d.ts +0 -1
  56. package/dist/dns/index.d.ts +0 -1
  57. package/dist/dns/propagation.d.ts +0 -1
  58. package/dist/events/request-events.d.ts +0 -1
  59. package/dist/index.d.ts +1 -1
  60. package/dist/index.js +1 -0
  61. package/dist/mcp/client.d.ts +0 -1
  62. package/dist/mcp/contract.d.ts +0 -1
  63. package/dist/mcp/embeddings-loader.d.ts +0 -1
  64. package/dist/mcp/geoip-loader.d.ts +0 -1
  65. package/dist/mcp/index.d.ts +0 -1
  66. package/dist/mcp/ip-intel.d.ts +0 -1
  67. package/dist/mcp/search/hybrid-search.d.ts +0 -1
  68. package/dist/mcp/search/index.d.ts +0 -1
  69. package/dist/mcp/search/math.d.ts +0 -1
  70. package/dist/mcp/search/types.d.ts +0 -1
  71. package/dist/mcp/server.d.ts +6 -2
  72. package/dist/mcp/server.js +193 -151
  73. package/dist/mcp/tools/loader.d.ts +2 -0
  74. package/dist/mcp/tools/loader.js +41 -0
  75. package/dist/mcp/tools/network.d.ts +3 -0
  76. package/dist/mcp/tools/network.js +267 -0
  77. package/dist/mcp/tools/registry.d.ts +17 -0
  78. package/dist/mcp/tools/registry.js +37 -0
  79. package/dist/mcp/types.d.ts +0 -1
  80. package/dist/plugins/auth/api-key.d.ts +8 -0
  81. package/dist/plugins/auth/api-key.js +27 -0
  82. package/dist/plugins/auth/auth0.d.ts +33 -0
  83. package/dist/plugins/auth/auth0.js +94 -0
  84. package/dist/plugins/auth/aws-sigv4.d.ts +10 -0
  85. package/dist/plugins/auth/aws-sigv4.js +88 -0
  86. package/dist/plugins/auth/azure-ad.d.ts +48 -0
  87. package/dist/plugins/auth/azure-ad.js +152 -0
  88. package/dist/plugins/auth/basic.d.ts +7 -0
  89. package/dist/plugins/auth/basic.js +13 -0
  90. package/dist/plugins/auth/bearer.d.ts +8 -0
  91. package/dist/plugins/auth/bearer.js +17 -0
  92. package/dist/plugins/auth/cognito.d.ts +45 -0
  93. package/dist/plugins/auth/cognito.js +208 -0
  94. package/dist/plugins/auth/digest.d.ts +8 -0
  95. package/dist/plugins/auth/digest.js +100 -0
  96. package/dist/plugins/auth/firebase.d.ts +32 -0
  97. package/dist/plugins/auth/firebase.js +195 -0
  98. package/dist/plugins/auth/github-app.d.ts +36 -0
  99. package/dist/plugins/auth/github-app.js +170 -0
  100. package/dist/plugins/auth/google-service-account.d.ts +49 -0
  101. package/dist/plugins/auth/google-service-account.js +172 -0
  102. package/dist/plugins/auth/index.d.ts +15 -0
  103. package/dist/plugins/auth/index.js +15 -0
  104. package/dist/plugins/auth/mtls.d.ts +37 -0
  105. package/dist/plugins/auth/mtls.js +140 -0
  106. package/dist/plugins/auth/oauth2.d.ts +8 -0
  107. package/dist/plugins/auth/oauth2.js +26 -0
  108. package/dist/plugins/auth/oidc.d.ts +55 -0
  109. package/dist/plugins/auth/oidc.js +222 -0
  110. package/dist/plugins/auth/okta.d.ts +47 -0
  111. package/dist/plugins/auth/okta.js +157 -0
  112. package/dist/plugins/auth.d.ts +1 -45
  113. package/dist/plugins/auth.js +1 -268
  114. package/dist/plugins/cache.d.ts +0 -1
  115. package/dist/plugins/cache.js +1 -1
  116. package/dist/plugins/certificate-pinning.d.ts +59 -0
  117. package/dist/plugins/certificate-pinning.js +236 -0
  118. package/dist/plugins/circuit-breaker.d.ts +0 -1
  119. package/dist/plugins/compression.d.ts +0 -1
  120. package/dist/plugins/cookie-jar.d.ts +0 -1
  121. package/dist/plugins/dedup.d.ts +0 -1
  122. package/dist/plugins/graphql.d.ts +0 -1
  123. package/dist/plugins/grpc-web.d.ts +0 -1
  124. package/dist/plugins/har-player.d.ts +0 -1
  125. package/dist/plugins/har-recorder.d.ts +0 -1
  126. package/dist/plugins/hls.d.ts +0 -1
  127. package/dist/plugins/http2-push.d.ts +0 -1
  128. package/dist/plugins/http3.d.ts +0 -1
  129. package/dist/plugins/index.d.ts +27 -0
  130. package/dist/plugins/index.js +27 -0
  131. package/dist/plugins/interface-rotator.d.ts +0 -1
  132. package/dist/plugins/jsonrpc.d.ts +0 -1
  133. package/dist/plugins/logger.d.ts +0 -1
  134. package/dist/plugins/odata.d.ts +0 -1
  135. package/dist/plugins/pagination.d.ts +0 -1
  136. package/dist/plugins/proxy-rotator.d.ts +0 -1
  137. package/dist/plugins/rate-limit.d.ts +15 -0
  138. package/dist/plugins/rate-limit.js +162 -0
  139. package/dist/plugins/retry.d.ts +0 -1
  140. package/dist/plugins/retry.js +2 -2
  141. package/dist/plugins/scrape.d.ts +0 -1
  142. package/dist/plugins/server-timing.d.ts +0 -1
  143. package/dist/plugins/soap.d.ts +0 -1
  144. package/dist/plugins/user-agent.d.ts +0 -1
  145. package/dist/plugins/xml.d.ts +0 -1
  146. package/dist/plugins/xsrf.d.ts +0 -1
  147. package/dist/presets/anthropic.d.ts +0 -1
  148. package/dist/presets/aws.d.ts +0 -1
  149. package/dist/presets/azure-openai.d.ts +0 -1
  150. package/dist/presets/azure.d.ts +0 -1
  151. package/dist/presets/cloudflare.d.ts +0 -1
  152. package/dist/presets/cohere.d.ts +0 -1
  153. package/dist/presets/deepseek.d.ts +0 -1
  154. package/dist/presets/digitalocean.d.ts +0 -1
  155. package/dist/presets/discord.d.ts +0 -1
  156. package/dist/presets/fireworks.d.ts +0 -1
  157. package/dist/presets/gcp.d.ts +0 -1
  158. package/dist/presets/gemini.d.ts +0 -1
  159. package/dist/presets/github.d.ts +0 -1
  160. package/dist/presets/gitlab.d.ts +0 -1
  161. package/dist/presets/groq.d.ts +0 -1
  162. package/dist/presets/huggingface.d.ts +0 -1
  163. package/dist/presets/index.d.ts +0 -1
  164. package/dist/presets/linear.d.ts +0 -1
  165. package/dist/presets/mailgun.d.ts +0 -1
  166. package/dist/presets/meta.d.ts +0 -1
  167. package/dist/presets/mistral.d.ts +0 -1
  168. package/dist/presets/notion.d.ts +0 -1
  169. package/dist/presets/openai.d.ts +0 -1
  170. package/dist/presets/oracle.d.ts +0 -1
  171. package/dist/presets/perplexity.d.ts +0 -1
  172. package/dist/presets/registry.d.ts +0 -1
  173. package/dist/presets/replicate.d.ts +0 -1
  174. package/dist/presets/sinch.d.ts +0 -1
  175. package/dist/presets/slack.d.ts +0 -1
  176. package/dist/presets/stripe.d.ts +0 -1
  177. package/dist/presets/supabase.d.ts +0 -1
  178. package/dist/presets/tiktok.d.ts +0 -1
  179. package/dist/presets/together.d.ts +0 -1
  180. package/dist/presets/twilio.d.ts +0 -1
  181. package/dist/presets/vercel.d.ts +0 -1
  182. package/dist/presets/vultr.d.ts +0 -1
  183. package/dist/presets/xai.d.ts +0 -1
  184. package/dist/presets/youtube.d.ts +0 -1
  185. package/dist/protocols/ftp.d.ts +0 -1
  186. package/dist/protocols/index.d.ts +0 -1
  187. package/dist/protocols/sftp.d.ts +0 -1
  188. package/dist/protocols/telnet.d.ts +0 -1
  189. package/dist/recker.d.ts +0 -1
  190. package/dist/runner/request-runner.d.ts +0 -1
  191. package/dist/scrape/document.d.ts +0 -1
  192. package/dist/scrape/element.d.ts +0 -1
  193. package/dist/scrape/extractors.d.ts +0 -1
  194. package/dist/scrape/index.d.ts +0 -1
  195. package/dist/scrape/types.d.ts +0 -1
  196. package/dist/testing/index.d.ts +16 -1
  197. package/dist/testing/index.js +8 -0
  198. package/dist/testing/mock-dns-server.d.ts +69 -0
  199. package/dist/testing/mock-dns-server.js +269 -0
  200. package/dist/testing/mock-ftp-server.d.ts +89 -0
  201. package/dist/testing/mock-ftp-server.js +562 -0
  202. package/dist/testing/mock-hls-server.d.ts +80 -0
  203. package/dist/testing/mock-hls-server.js +381 -0
  204. package/dist/testing/mock-http-server.d.ts +99 -0
  205. package/dist/testing/mock-http-server.js +298 -0
  206. package/dist/testing/mock-sse-server.d.ts +76 -0
  207. package/dist/testing/mock-sse-server.js +291 -0
  208. package/dist/testing/mock-telnet-server.d.ts +59 -0
  209. package/dist/testing/mock-telnet-server.js +273 -0
  210. package/dist/testing/mock-udp-server.d.ts +0 -1
  211. package/dist/testing/mock-websocket-server.d.ts +77 -0
  212. package/dist/testing/mock-websocket-server.js +316 -0
  213. package/dist/testing/mock-whois-server.d.ts +56 -0
  214. package/dist/testing/mock-whois-server.js +234 -0
  215. package/dist/testing/mock.d.ts +0 -1
  216. package/dist/transport/base-udp.d.ts +0 -1
  217. package/dist/transport/fetch.d.ts +0 -1
  218. package/dist/transport/udp-response.d.ts +0 -1
  219. package/dist/transport/udp.d.ts +0 -1
  220. package/dist/transport/undici.d.ts +0 -1
  221. package/dist/transport/undici.js +1 -1
  222. package/dist/types/ai.d.ts +0 -1
  223. package/dist/types/index.d.ts +0 -1
  224. package/dist/types/logger.d.ts +0 -1
  225. package/dist/types/udp.d.ts +0 -1
  226. package/dist/udp/index.d.ts +0 -1
  227. package/dist/utils/agent-manager.d.ts +0 -1
  228. package/dist/utils/body.d.ts +0 -1
  229. package/dist/utils/cert.d.ts +0 -1
  230. package/dist/utils/charset.d.ts +0 -1
  231. package/dist/utils/chart.d.ts +0 -1
  232. package/dist/utils/client-pool.d.ts +0 -1
  233. package/dist/utils/colors.d.ts +0 -1
  234. package/dist/utils/concurrency.d.ts +0 -1
  235. package/dist/utils/dns-toolkit.d.ts +0 -1
  236. package/dist/utils/dns-toolkit.js +1 -1
  237. package/dist/utils/dns.d.ts +0 -1
  238. package/dist/utils/dns.js +2 -2
  239. package/dist/utils/doh.d.ts +0 -1
  240. package/dist/utils/download.d.ts +0 -1
  241. package/dist/utils/env-proxy.d.ts +0 -1
  242. package/dist/utils/header-parser.d.ts +0 -1
  243. package/dist/utils/html-cleaner.d.ts +0 -1
  244. package/dist/utils/link-header.d.ts +0 -1
  245. package/dist/utils/optional-require.d.ts +0 -1
  246. package/dist/utils/optional-require.js +1 -1
  247. package/dist/utils/progress.d.ts +0 -1
  248. package/dist/utils/rdap.d.ts +0 -1
  249. package/dist/utils/request-pool.d.ts +0 -1
  250. package/dist/utils/security-grader.d.ts +0 -1
  251. package/dist/utils/sparkline.d.ts +0 -1
  252. package/dist/utils/sse.d.ts +0 -1
  253. package/dist/utils/streaming.d.ts +0 -1
  254. package/dist/utils/system-metrics.d.ts +0 -1
  255. package/dist/utils/tls-inspector.d.ts +0 -1
  256. package/dist/utils/try-fn.d.ts +0 -1
  257. package/dist/utils/upload.d.ts +0 -1
  258. package/dist/utils/user-agent.d.ts +0 -1
  259. package/dist/utils/whois.d.ts +0 -1
  260. package/dist/webrtc/index.d.ts +0 -1
  261. package/dist/webrtc/index.js +1 -1
  262. package/dist/websocket/client.d.ts +0 -1
  263. package/package.json +12 -3
  264. package/dist/ai/adaptive-timeout.d.ts.map +0 -1
  265. package/dist/ai/client.d.ts.map +0 -1
  266. package/dist/ai/index.d.ts.map +0 -1
  267. package/dist/ai/providers/anthropic.d.ts.map +0 -1
  268. package/dist/ai/providers/base.d.ts.map +0 -1
  269. package/dist/ai/providers/index.d.ts.map +0 -1
  270. package/dist/ai/providers/openai.d.ts.map +0 -1
  271. package/dist/ai/rate-limiter.d.ts.map +0 -1
  272. package/dist/bench/generator.d.ts.map +0 -1
  273. package/dist/bench/stats.d.ts.map +0 -1
  274. package/dist/cache/file-storage.d.ts.map +0 -1
  275. package/dist/cache/memory-limits.d.ts.map +0 -1
  276. package/dist/cache/memory-storage.d.ts.map +0 -1
  277. package/dist/cache/redis-storage.d.ts.map +0 -1
  278. package/dist/cli/handler.d.ts.map +0 -1
  279. package/dist/cli/index.d.ts.map +0 -1
  280. package/dist/cli/presets.d.ts.map +0 -1
  281. package/dist/cli/tui/ai-chat.d.ts.map +0 -1
  282. package/dist/cli/tui/load-dashboard.d.ts.map +0 -1
  283. package/dist/cli/tui/scroll-buffer.d.ts.map +0 -1
  284. package/dist/cli/tui/search-panel.d.ts.map +0 -1
  285. package/dist/cli/tui/shell-search.d.ts.map +0 -1
  286. package/dist/cli/tui/shell.d.ts.map +0 -1
  287. package/dist/cli/tui/websocket.d.ts.map +0 -1
  288. package/dist/constants/http-status.d.ts.map +0 -1
  289. package/dist/constants.d.ts.map +0 -1
  290. package/dist/contract/index.d.ts.map +0 -1
  291. package/dist/cookies/memory-cookie-jar.d.ts.map +0 -1
  292. package/dist/core/client.d.ts.map +0 -1
  293. package/dist/core/errors.d.ts.map +0 -1
  294. package/dist/core/index.d.ts.map +0 -1
  295. package/dist/core/request-promise.d.ts.map +0 -1
  296. package/dist/core/request.d.ts.map +0 -1
  297. package/dist/core/response.d.ts.map +0 -1
  298. package/dist/dns/index.d.ts.map +0 -1
  299. package/dist/dns/propagation.d.ts.map +0 -1
  300. package/dist/events/request-events.d.ts.map +0 -1
  301. package/dist/index.d.ts.map +0 -1
  302. package/dist/mcp/client.d.ts.map +0 -1
  303. package/dist/mcp/contract.d.ts.map +0 -1
  304. package/dist/mcp/embeddings-loader.d.ts.map +0 -1
  305. package/dist/mcp/geoip-loader.d.ts.map +0 -1
  306. package/dist/mcp/index.d.ts.map +0 -1
  307. package/dist/mcp/ip-intel.d.ts.map +0 -1
  308. package/dist/mcp/search/hybrid-search.d.ts.map +0 -1
  309. package/dist/mcp/search/index.d.ts.map +0 -1
  310. package/dist/mcp/search/math.d.ts.map +0 -1
  311. package/dist/mcp/search/types.d.ts.map +0 -1
  312. package/dist/mcp/server.d.ts.map +0 -1
  313. package/dist/mcp/types.d.ts.map +0 -1
  314. package/dist/plugins/auth.d.ts.map +0 -1
  315. package/dist/plugins/cache.d.ts.map +0 -1
  316. package/dist/plugins/circuit-breaker.d.ts.map +0 -1
  317. package/dist/plugins/compression.d.ts.map +0 -1
  318. package/dist/plugins/cookie-jar.d.ts.map +0 -1
  319. package/dist/plugins/dedup.d.ts.map +0 -1
  320. package/dist/plugins/graphql.d.ts.map +0 -1
  321. package/dist/plugins/grpc-web.d.ts.map +0 -1
  322. package/dist/plugins/har-player.d.ts.map +0 -1
  323. package/dist/plugins/har-recorder.d.ts.map +0 -1
  324. package/dist/plugins/hls.d.ts.map +0 -1
  325. package/dist/plugins/http2-push.d.ts.map +0 -1
  326. package/dist/plugins/http3.d.ts.map +0 -1
  327. package/dist/plugins/interface-rotator.d.ts.map +0 -1
  328. package/dist/plugins/jsonrpc.d.ts.map +0 -1
  329. package/dist/plugins/logger.d.ts.map +0 -1
  330. package/dist/plugins/odata.d.ts.map +0 -1
  331. package/dist/plugins/pagination.d.ts.map +0 -1
  332. package/dist/plugins/proxy-rotator.d.ts.map +0 -1
  333. package/dist/plugins/retry.d.ts.map +0 -1
  334. package/dist/plugins/scrape.d.ts.map +0 -1
  335. package/dist/plugins/server-timing.d.ts.map +0 -1
  336. package/dist/plugins/soap.d.ts.map +0 -1
  337. package/dist/plugins/user-agent.d.ts.map +0 -1
  338. package/dist/plugins/xml.d.ts.map +0 -1
  339. package/dist/plugins/xsrf.d.ts.map +0 -1
  340. package/dist/presets/anthropic.d.ts.map +0 -1
  341. package/dist/presets/aws.d.ts.map +0 -1
  342. package/dist/presets/azure-openai.d.ts.map +0 -1
  343. package/dist/presets/azure.d.ts.map +0 -1
  344. package/dist/presets/cloudflare.d.ts.map +0 -1
  345. package/dist/presets/cohere.d.ts.map +0 -1
  346. package/dist/presets/deepseek.d.ts.map +0 -1
  347. package/dist/presets/digitalocean.d.ts.map +0 -1
  348. package/dist/presets/discord.d.ts.map +0 -1
  349. package/dist/presets/fireworks.d.ts.map +0 -1
  350. package/dist/presets/gcp.d.ts.map +0 -1
  351. package/dist/presets/gemini.d.ts.map +0 -1
  352. package/dist/presets/github.d.ts.map +0 -1
  353. package/dist/presets/gitlab.d.ts.map +0 -1
  354. package/dist/presets/groq.d.ts.map +0 -1
  355. package/dist/presets/huggingface.d.ts.map +0 -1
  356. package/dist/presets/index.d.ts.map +0 -1
  357. package/dist/presets/linear.d.ts.map +0 -1
  358. package/dist/presets/mailgun.d.ts.map +0 -1
  359. package/dist/presets/meta.d.ts.map +0 -1
  360. package/dist/presets/mistral.d.ts.map +0 -1
  361. package/dist/presets/notion.d.ts.map +0 -1
  362. package/dist/presets/openai.d.ts.map +0 -1
  363. package/dist/presets/oracle.d.ts.map +0 -1
  364. package/dist/presets/perplexity.d.ts.map +0 -1
  365. package/dist/presets/registry.d.ts.map +0 -1
  366. package/dist/presets/replicate.d.ts.map +0 -1
  367. package/dist/presets/sinch.d.ts.map +0 -1
  368. package/dist/presets/slack.d.ts.map +0 -1
  369. package/dist/presets/stripe.d.ts.map +0 -1
  370. package/dist/presets/supabase.d.ts.map +0 -1
  371. package/dist/presets/tiktok.d.ts.map +0 -1
  372. package/dist/presets/together.d.ts.map +0 -1
  373. package/dist/presets/twilio.d.ts.map +0 -1
  374. package/dist/presets/vercel.d.ts.map +0 -1
  375. package/dist/presets/vultr.d.ts.map +0 -1
  376. package/dist/presets/xai.d.ts.map +0 -1
  377. package/dist/presets/youtube.d.ts.map +0 -1
  378. package/dist/protocols/ftp.d.ts.map +0 -1
  379. package/dist/protocols/index.d.ts.map +0 -1
  380. package/dist/protocols/sftp.d.ts.map +0 -1
  381. package/dist/protocols/telnet.d.ts.map +0 -1
  382. package/dist/recker.d.ts.map +0 -1
  383. package/dist/runner/request-runner.d.ts.map +0 -1
  384. package/dist/scrape/document.d.ts.map +0 -1
  385. package/dist/scrape/element.d.ts.map +0 -1
  386. package/dist/scrape/extractors.d.ts.map +0 -1
  387. package/dist/scrape/index.d.ts.map +0 -1
  388. package/dist/scrape/types.d.ts.map +0 -1
  389. package/dist/testing/index.d.ts.map +0 -1
  390. package/dist/testing/mock-udp-server.d.ts.map +0 -1
  391. package/dist/testing/mock.d.ts.map +0 -1
  392. package/dist/transport/base-udp.d.ts.map +0 -1
  393. package/dist/transport/fetch.d.ts.map +0 -1
  394. package/dist/transport/udp-response.d.ts.map +0 -1
  395. package/dist/transport/udp.d.ts.map +0 -1
  396. package/dist/transport/undici.d.ts.map +0 -1
  397. package/dist/types/ai.d.ts.map +0 -1
  398. package/dist/types/index.d.ts.map +0 -1
  399. package/dist/types/logger.d.ts.map +0 -1
  400. package/dist/types/udp.d.ts.map +0 -1
  401. package/dist/udp/index.d.ts.map +0 -1
  402. package/dist/utils/agent-manager.d.ts.map +0 -1
  403. package/dist/utils/body.d.ts.map +0 -1
  404. package/dist/utils/cert.d.ts.map +0 -1
  405. package/dist/utils/charset.d.ts.map +0 -1
  406. package/dist/utils/chart.d.ts.map +0 -1
  407. package/dist/utils/client-pool.d.ts.map +0 -1
  408. package/dist/utils/colors.d.ts.map +0 -1
  409. package/dist/utils/concurrency.d.ts.map +0 -1
  410. package/dist/utils/dns-toolkit.d.ts.map +0 -1
  411. package/dist/utils/dns.d.ts.map +0 -1
  412. package/dist/utils/doh.d.ts.map +0 -1
  413. package/dist/utils/download.d.ts.map +0 -1
  414. package/dist/utils/env-proxy.d.ts.map +0 -1
  415. package/dist/utils/header-parser.d.ts.map +0 -1
  416. package/dist/utils/html-cleaner.d.ts.map +0 -1
  417. package/dist/utils/link-header.d.ts.map +0 -1
  418. package/dist/utils/optional-require.d.ts.map +0 -1
  419. package/dist/utils/progress.d.ts.map +0 -1
  420. package/dist/utils/rdap.d.ts.map +0 -1
  421. package/dist/utils/request-pool.d.ts.map +0 -1
  422. package/dist/utils/security-grader.d.ts.map +0 -1
  423. package/dist/utils/sparkline.d.ts.map +0 -1
  424. package/dist/utils/sse.d.ts.map +0 -1
  425. package/dist/utils/streaming.d.ts.map +0 -1
  426. package/dist/utils/system-metrics.d.ts.map +0 -1
  427. package/dist/utils/tls-inspector.d.ts.map +0 -1
  428. package/dist/utils/try-fn.d.ts.map +0 -1
  429. package/dist/utils/upload.d.ts.map +0 -1
  430. package/dist/utils/user-agent.d.ts.map +0 -1
  431. package/dist/utils/whois.d.ts.map +0 -1
  432. package/dist/webrtc/index.d.ts.map +0 -1
  433. package/dist/websocket/client.d.ts.map +0 -1
@@ -0,0 +1,298 @@
1
+ import { EventEmitter } from 'node:events';
2
+ import { createServer } from 'node:http';
3
+ export class MockHttpServer extends EventEmitter {
4
+ options;
5
+ httpServer = null;
6
+ routes = [];
7
+ _port = 0;
8
+ _started = false;
9
+ stats = {
10
+ totalRequests: 0,
11
+ requestsByMethod: {},
12
+ requestsByPath: {},
13
+ requestLog: [],
14
+ };
15
+ constructor(options = {}) {
16
+ super();
17
+ this.options = {
18
+ port: 0,
19
+ host: '127.0.0.1',
20
+ defaultResponse: { status: 404, body: { error: 'Not Found' } },
21
+ delay: 0,
22
+ cors: true,
23
+ corsOrigin: '*',
24
+ ...options,
25
+ };
26
+ }
27
+ get port() {
28
+ return this._port;
29
+ }
30
+ get address() {
31
+ return this.options.host;
32
+ }
33
+ get url() {
34
+ return `http://${this.options.host}:${this._port}`;
35
+ }
36
+ get isRunning() {
37
+ return this._started;
38
+ }
39
+ get statistics() {
40
+ return { ...this.stats };
41
+ }
42
+ get routeCount() {
43
+ return this.routes.length;
44
+ }
45
+ async start() {
46
+ if (this._started) {
47
+ throw new Error('Server already started');
48
+ }
49
+ return new Promise((resolve, reject) => {
50
+ this.httpServer = createServer((req, res) => this.handleRequest(req, res));
51
+ this.httpServer.on('error', reject);
52
+ this.httpServer.listen(this.options.port, this.options.host, () => {
53
+ const addr = this.httpServer.address();
54
+ this._port = typeof addr === 'string' ? 0 : addr?.port ?? 0;
55
+ this._started = true;
56
+ this.emit('listening', this._port);
57
+ resolve();
58
+ });
59
+ });
60
+ }
61
+ async stop() {
62
+ if (!this._started)
63
+ return;
64
+ return new Promise((resolve) => {
65
+ this.httpServer?.close(() => {
66
+ this._started = false;
67
+ this.httpServer = null;
68
+ this.emit('close');
69
+ resolve();
70
+ });
71
+ });
72
+ }
73
+ reset() {
74
+ this.routes = [];
75
+ this.stats = {
76
+ totalRequests: 0,
77
+ requestsByMethod: {},
78
+ requestsByPath: {},
79
+ requestLog: [],
80
+ };
81
+ this.emit('reset');
82
+ }
83
+ route(method, path, handler, options = {}) {
84
+ const pattern = this.pathToRegex(path);
85
+ this.routes.push({
86
+ method: method.toUpperCase(),
87
+ pattern,
88
+ pathPattern: path,
89
+ handler,
90
+ times: options.times,
91
+ callCount: 0,
92
+ });
93
+ return this;
94
+ }
95
+ get(path, handler, options) {
96
+ return this.route('GET', path, handler, options);
97
+ }
98
+ post(path, handler, options) {
99
+ return this.route('POST', path, handler, options);
100
+ }
101
+ put(path, handler, options) {
102
+ return this.route('PUT', path, handler, options);
103
+ }
104
+ patch(path, handler, options) {
105
+ return this.route('PATCH', path, handler, options);
106
+ }
107
+ delete(path, handler, options) {
108
+ return this.route('DELETE', path, handler, options);
109
+ }
110
+ head(path, handler, options) {
111
+ return this.route('HEAD', path, handler, options);
112
+ }
113
+ optionsRoute(path, handler, options) {
114
+ return this.route('OPTIONS', path, handler, options);
115
+ }
116
+ any(path, handler, options) {
117
+ return this.route('*', path, handler, options);
118
+ }
119
+ removeRoute(method, path) {
120
+ const index = this.routes.findIndex((r) => r.method === method.toUpperCase() && r.pathPattern === path);
121
+ if (index >= 0) {
122
+ this.routes.splice(index, 1);
123
+ return true;
124
+ }
125
+ return false;
126
+ }
127
+ clearRoutes() {
128
+ this.routes = [];
129
+ }
130
+ async handleRequest(req, res) {
131
+ const startTime = Date.now();
132
+ const method = req.method?.toUpperCase() ?? 'GET';
133
+ const urlParts = new URL(req.url ?? '/', `http://${req.headers.host}`);
134
+ const path = urlParts.pathname;
135
+ const query = Object.fromEntries(urlParts.searchParams);
136
+ this.stats.totalRequests++;
137
+ this.stats.requestsByMethod[method] = (this.stats.requestsByMethod[method] ?? 0) + 1;
138
+ this.stats.requestsByPath[path] = (this.stats.requestsByPath[path] ?? 0) + 1;
139
+ if (this.options.cors && method === 'OPTIONS') {
140
+ this.sendCorsHeaders(res);
141
+ res.writeHead(204);
142
+ res.end();
143
+ return;
144
+ }
145
+ const body = await this.parseBody(req);
146
+ const mockReq = {
147
+ method,
148
+ path,
149
+ query,
150
+ headers: req.headers,
151
+ body,
152
+ raw: req,
153
+ };
154
+ this.emit('request', mockReq);
155
+ const route = this.findRoute(method, path);
156
+ let response;
157
+ if (route) {
158
+ route.callCount++;
159
+ if (route.times !== undefined && route.callCount > route.times) {
160
+ response = this.options.defaultResponse;
161
+ }
162
+ else {
163
+ response = typeof route.handler === 'function'
164
+ ? await route.handler(mockReq)
165
+ : route.handler;
166
+ }
167
+ }
168
+ else {
169
+ response = this.options.defaultResponse;
170
+ }
171
+ await this.sendResponse(res, response);
172
+ const duration = Date.now() - startTime;
173
+ this.stats.requestLog.push({
174
+ method,
175
+ path,
176
+ status: response.status ?? 200,
177
+ timestamp: startTime,
178
+ duration,
179
+ });
180
+ this.emit('response', mockReq, response, duration);
181
+ }
182
+ findRoute(method, path) {
183
+ for (const route of this.routes) {
184
+ if ((route.method === method || route.method === '*') && route.pattern.test(path)) {
185
+ return route;
186
+ }
187
+ }
188
+ return undefined;
189
+ }
190
+ async sendResponse(res, response) {
191
+ if (response.drop) {
192
+ res.destroy();
193
+ return;
194
+ }
195
+ const delay = response.delay ?? this.options.delay;
196
+ if (delay > 0) {
197
+ await new Promise((resolve) => setTimeout(resolve, delay));
198
+ }
199
+ if (this.options.cors) {
200
+ this.sendCorsHeaders(res);
201
+ }
202
+ const status = response.status ?? 200;
203
+ const headers = {
204
+ 'Content-Type': 'application/json',
205
+ ...response.headers,
206
+ };
207
+ if (response.stream) {
208
+ res.writeHead(status, headers);
209
+ for (const chunk of response.stream.chunks) {
210
+ res.write(chunk);
211
+ await new Promise((resolve) => setTimeout(resolve, response.stream.interval));
212
+ }
213
+ res.end();
214
+ return;
215
+ }
216
+ let body = '';
217
+ if (response.body !== undefined) {
218
+ if (typeof response.body === 'string' || Buffer.isBuffer(response.body)) {
219
+ body = response.body;
220
+ if (typeof response.body === 'string' && !headers['Content-Type'].includes('json')) {
221
+ headers['Content-Type'] = 'text/plain';
222
+ }
223
+ }
224
+ else {
225
+ body = JSON.stringify(response.body);
226
+ }
227
+ }
228
+ headers['Content-Length'] = String(Buffer.byteLength(body));
229
+ res.writeHead(status, headers);
230
+ res.end(body);
231
+ }
232
+ sendCorsHeaders(res) {
233
+ res.setHeader('Access-Control-Allow-Origin', this.options.corsOrigin);
234
+ res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, PATCH, DELETE, OPTIONS');
235
+ res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
236
+ res.setHeader('Access-Control-Max-Age', '86400');
237
+ }
238
+ async parseBody(req) {
239
+ return new Promise((resolve) => {
240
+ const chunks = [];
241
+ req.on('data', (chunk) => chunks.push(chunk));
242
+ req.on('end', () => {
243
+ if (chunks.length === 0) {
244
+ resolve(undefined);
245
+ return;
246
+ }
247
+ const raw = Buffer.concat(chunks).toString('utf-8');
248
+ const contentType = req.headers['content-type'] ?? '';
249
+ if (contentType.includes('application/json')) {
250
+ try {
251
+ resolve(JSON.parse(raw));
252
+ }
253
+ catch {
254
+ resolve(raw);
255
+ }
256
+ }
257
+ else {
258
+ resolve(raw);
259
+ }
260
+ });
261
+ req.on('error', () => resolve(undefined));
262
+ });
263
+ }
264
+ pathToRegex(path) {
265
+ const escaped = path.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
266
+ const withParams = escaped.replace(/:(\w+)/g, '([^/]+)');
267
+ return new RegExp(`^${withParams}$`);
268
+ }
269
+ async waitForRequests(count, timeout = 5000) {
270
+ const start = Date.now();
271
+ while (this.stats.totalRequests < count) {
272
+ if (Date.now() - start > timeout) {
273
+ throw new Error(`Timeout waiting for ${count} requests (have ${this.stats.totalRequests})`);
274
+ }
275
+ await new Promise((resolve) => setTimeout(resolve, 10));
276
+ }
277
+ }
278
+ getCallCount(method, path) {
279
+ const route = this.routes.find((r) => r.method === method.toUpperCase() && r.pathPattern === path);
280
+ return route?.callCount ?? 0;
281
+ }
282
+ static async create(options = {}) {
283
+ const server = new MockHttpServer(options);
284
+ await server.start();
285
+ return server;
286
+ }
287
+ }
288
+ export async function createMockHttpServer(routes, options) {
289
+ const server = new MockHttpServer(options);
290
+ if (routes) {
291
+ for (const [key, response] of Object.entries(routes)) {
292
+ const [method, path] = key.includes(' ') ? key.split(' ') : ['GET', key];
293
+ server.route(method, path, response);
294
+ }
295
+ }
296
+ await server.start();
297
+ return server;
298
+ }
@@ -0,0 +1,76 @@
1
+ import { EventEmitter } from 'node:events';
2
+ import { type ServerResponse } from 'node:http';
3
+ export interface MockSSEServerOptions {
4
+ port?: number;
5
+ host?: string;
6
+ path?: string;
7
+ retryInterval?: number;
8
+ sendRetry?: boolean;
9
+ maxConnections?: number;
10
+ keepAliveInterval?: number;
11
+ corsOrigin?: string;
12
+ }
13
+ export interface SSEEvent {
14
+ event?: string;
15
+ data: string;
16
+ id?: string;
17
+ retry?: number;
18
+ }
19
+ export interface MockSSEClient {
20
+ id: string;
21
+ response: ServerResponse;
22
+ connectedAt: number;
23
+ lastEventId?: string;
24
+ eventsSent: number;
25
+ metadata: Record<string, any>;
26
+ }
27
+ export interface MockSSEStats {
28
+ totalConnections: number;
29
+ currentConnections: number;
30
+ totalEventsSent: number;
31
+ eventLog: Array<{
32
+ event: SSEEvent;
33
+ timestamp: number;
34
+ clientCount: number;
35
+ }>;
36
+ }
37
+ export declare class MockSSEServer extends EventEmitter {
38
+ private options;
39
+ private httpServer;
40
+ private clients;
41
+ private _port;
42
+ private _started;
43
+ private clientIdCounter;
44
+ private periodicIntervals;
45
+ private keepAliveInterval;
46
+ private eventIdCounter;
47
+ private stats;
48
+ constructor(options?: MockSSEServerOptions);
49
+ get port(): number;
50
+ get address(): string;
51
+ get url(): string;
52
+ get isRunning(): boolean;
53
+ get connectionCount(): number;
54
+ get statistics(): MockSSEStats;
55
+ get allClients(): MockSSEClient[];
56
+ start(): Promise<void>;
57
+ stop(): Promise<void>;
58
+ reset(): void;
59
+ sendEvent(event: SSEEvent): number;
60
+ sendEventTo(clientId: string, event: SSEEvent): boolean;
61
+ sendData(data: string, event?: string): number;
62
+ sendJSON(data: any, event?: string): number;
63
+ sendComment(comment: string): void;
64
+ startPeriodicEvents(eventType: string, intervalMs: number, dataGenerator?: () => string): void;
65
+ stopPeriodicEvents(eventType?: string): void;
66
+ getClient(id: string): MockSSEClient | undefined;
67
+ disconnectClient(id: string): void;
68
+ disconnectAll(): void;
69
+ waitForConnections(count: number, timeout?: number): Promise<MockSSEClient[]>;
70
+ private handleRequest;
71
+ private formatEvent;
72
+ private writeToClient;
73
+ nextEventId(): string;
74
+ static create(options?: MockSSEServerOptions): Promise<MockSSEServer>;
75
+ }
76
+ export declare function createMockSSEServer(options?: MockSSEServerOptions): Promise<MockSSEServer>;
@@ -0,0 +1,291 @@
1
+ import { EventEmitter } from 'node:events';
2
+ import { createServer } from 'node:http';
3
+ export class MockSSEServer extends EventEmitter {
4
+ options;
5
+ httpServer = null;
6
+ clients = new Map();
7
+ _port = 0;
8
+ _started = false;
9
+ clientIdCounter = 0;
10
+ periodicIntervals = new Map();
11
+ keepAliveInterval = null;
12
+ eventIdCounter = 0;
13
+ stats = {
14
+ totalConnections: 0,
15
+ currentConnections: 0,
16
+ totalEventsSent: 0,
17
+ eventLog: [],
18
+ };
19
+ constructor(options = {}) {
20
+ super();
21
+ this.options = {
22
+ port: 0,
23
+ host: '127.0.0.1',
24
+ path: '/events',
25
+ retryInterval: 3000,
26
+ sendRetry: true,
27
+ maxConnections: 0,
28
+ keepAliveInterval: 15000,
29
+ corsOrigin: '*',
30
+ ...options,
31
+ };
32
+ }
33
+ get port() {
34
+ return this._port;
35
+ }
36
+ get address() {
37
+ return this.options.host;
38
+ }
39
+ get url() {
40
+ return `http://${this.options.host}:${this._port}${this.options.path}`;
41
+ }
42
+ get isRunning() {
43
+ return this._started;
44
+ }
45
+ get connectionCount() {
46
+ return this.clients.size;
47
+ }
48
+ get statistics() {
49
+ return { ...this.stats };
50
+ }
51
+ get allClients() {
52
+ return [...this.clients.values()];
53
+ }
54
+ async start() {
55
+ if (this._started) {
56
+ throw new Error('Server already started');
57
+ }
58
+ return new Promise((resolve, reject) => {
59
+ this.httpServer = createServer((req, res) => this.handleRequest(req, res));
60
+ this.httpServer.on('error', reject);
61
+ this.httpServer.listen(this.options.port, this.options.host, () => {
62
+ const addr = this.httpServer.address();
63
+ this._port = typeof addr === 'string' ? 0 : addr?.port ?? 0;
64
+ this._started = true;
65
+ if (this.options.keepAliveInterval > 0) {
66
+ this.keepAliveInterval = setInterval(() => {
67
+ this.sendComment('keep-alive');
68
+ }, this.options.keepAliveInterval);
69
+ }
70
+ this.emit('listening', this._port);
71
+ resolve();
72
+ });
73
+ });
74
+ }
75
+ async stop() {
76
+ if (!this._started)
77
+ return;
78
+ if (this.keepAliveInterval) {
79
+ clearInterval(this.keepAliveInterval);
80
+ this.keepAliveInterval = null;
81
+ }
82
+ for (const interval of this.periodicIntervals.values()) {
83
+ clearInterval(interval);
84
+ }
85
+ this.periodicIntervals.clear();
86
+ for (const client of this.clients.values()) {
87
+ client.response.end();
88
+ }
89
+ this.clients.clear();
90
+ return new Promise((resolve) => {
91
+ this.httpServer?.close(() => {
92
+ this._started = false;
93
+ this.httpServer = null;
94
+ this.emit('close');
95
+ resolve();
96
+ });
97
+ });
98
+ }
99
+ reset() {
100
+ this.stats = {
101
+ totalConnections: 0,
102
+ currentConnections: 0,
103
+ totalEventsSent: 0,
104
+ eventLog: [],
105
+ };
106
+ this.eventIdCounter = 0;
107
+ for (const interval of this.periodicIntervals.values()) {
108
+ clearInterval(interval);
109
+ }
110
+ this.periodicIntervals.clear();
111
+ this.emit('reset');
112
+ }
113
+ sendEvent(event) {
114
+ let sent = 0;
115
+ const formatted = this.formatEvent(event);
116
+ for (const client of this.clients.values()) {
117
+ if (this.writeToClient(client, formatted)) {
118
+ client.eventsSent++;
119
+ sent++;
120
+ }
121
+ }
122
+ this.stats.totalEventsSent += sent;
123
+ this.stats.eventLog.push({
124
+ event,
125
+ timestamp: Date.now(),
126
+ clientCount: sent,
127
+ });
128
+ this.emit('event', event, sent);
129
+ return sent;
130
+ }
131
+ sendEventTo(clientId, event) {
132
+ const client = this.clients.get(clientId);
133
+ if (!client)
134
+ return false;
135
+ const formatted = this.formatEvent(event);
136
+ if (this.writeToClient(client, formatted)) {
137
+ client.eventsSent++;
138
+ this.stats.totalEventsSent++;
139
+ return true;
140
+ }
141
+ return false;
142
+ }
143
+ sendData(data, event) {
144
+ return this.sendEvent({ data, event });
145
+ }
146
+ sendJSON(data, event) {
147
+ return this.sendEvent({ data: JSON.stringify(data), event });
148
+ }
149
+ sendComment(comment) {
150
+ const formatted = `: ${comment}\n\n`;
151
+ for (const client of this.clients.values()) {
152
+ this.writeToClient(client, formatted);
153
+ }
154
+ }
155
+ startPeriodicEvents(eventType, intervalMs, dataGenerator) {
156
+ if (this.periodicIntervals.has(eventType)) {
157
+ clearInterval(this.periodicIntervals.get(eventType));
158
+ }
159
+ const interval = setInterval(() => {
160
+ const data = dataGenerator?.() ?? new Date().toISOString();
161
+ this.sendEvent({ event: eventType, data });
162
+ }, intervalMs);
163
+ this.periodicIntervals.set(eventType, interval);
164
+ }
165
+ stopPeriodicEvents(eventType) {
166
+ if (eventType) {
167
+ const interval = this.periodicIntervals.get(eventType);
168
+ if (interval) {
169
+ clearInterval(interval);
170
+ this.periodicIntervals.delete(eventType);
171
+ }
172
+ }
173
+ else {
174
+ for (const interval of this.periodicIntervals.values()) {
175
+ clearInterval(interval);
176
+ }
177
+ this.periodicIntervals.clear();
178
+ }
179
+ }
180
+ getClient(id) {
181
+ return this.clients.get(id);
182
+ }
183
+ disconnectClient(id) {
184
+ const client = this.clients.get(id);
185
+ if (client) {
186
+ client.response.end();
187
+ this.clients.delete(id);
188
+ this.stats.currentConnections--;
189
+ this.emit('disconnect', client);
190
+ }
191
+ }
192
+ disconnectAll() {
193
+ for (const client of this.clients.values()) {
194
+ client.response.end();
195
+ }
196
+ this.clients.clear();
197
+ this.stats.currentConnections = 0;
198
+ }
199
+ async waitForConnections(count, timeout = 5000) {
200
+ const start = Date.now();
201
+ while (this.clients.size < count) {
202
+ if (Date.now() - start > timeout) {
203
+ throw new Error(`Timeout waiting for ${count} connections (have ${this.clients.size})`);
204
+ }
205
+ await new Promise((resolve) => setTimeout(resolve, 10));
206
+ }
207
+ return [...this.clients.values()].slice(0, count);
208
+ }
209
+ handleRequest(req, res) {
210
+ if (req.method !== 'GET' || req.url !== this.options.path) {
211
+ res.writeHead(404);
212
+ res.end('Not Found');
213
+ return;
214
+ }
215
+ if (this.options.maxConnections > 0 && this.clients.size >= this.options.maxConnections) {
216
+ res.writeHead(503);
217
+ res.end('Max connections reached');
218
+ return;
219
+ }
220
+ const lastEventId = req.headers['last-event-id'];
221
+ res.writeHead(200, {
222
+ 'Content-Type': 'text/event-stream',
223
+ 'Cache-Control': 'no-cache',
224
+ 'Connection': 'keep-alive',
225
+ 'Access-Control-Allow-Origin': this.options.corsOrigin,
226
+ 'X-Accel-Buffering': 'no',
227
+ });
228
+ if (this.options.sendRetry) {
229
+ res.write(`retry: ${this.options.retryInterval}\n\n`);
230
+ }
231
+ const clientId = `sse-client-${++this.clientIdCounter}`;
232
+ const client = {
233
+ id: clientId,
234
+ response: res,
235
+ connectedAt: Date.now(),
236
+ lastEventId,
237
+ eventsSent: 0,
238
+ metadata: {},
239
+ };
240
+ this.clients.set(clientId, client);
241
+ this.stats.totalConnections++;
242
+ this.stats.currentConnections++;
243
+ this.emit('connection', client);
244
+ req.on('close', () => {
245
+ this.clients.delete(clientId);
246
+ this.stats.currentConnections--;
247
+ this.emit('disconnect', client);
248
+ });
249
+ res.on('error', (err) => {
250
+ this.emit('clientError', client, err);
251
+ this.clients.delete(clientId);
252
+ this.stats.currentConnections--;
253
+ });
254
+ }
255
+ formatEvent(event) {
256
+ const lines = [];
257
+ if (event.id) {
258
+ lines.push(`id: ${event.id}`);
259
+ }
260
+ if (event.event) {
261
+ lines.push(`event: ${event.event}`);
262
+ }
263
+ if (event.retry !== undefined) {
264
+ lines.push(`retry: ${event.retry}`);
265
+ }
266
+ const dataLines = event.data.split('\n');
267
+ for (const line of dataLines) {
268
+ lines.push(`data: ${line}`);
269
+ }
270
+ return lines.join('\n') + '\n\n';
271
+ }
272
+ writeToClient(client, data) {
273
+ try {
274
+ return client.response.write(data);
275
+ }
276
+ catch {
277
+ return false;
278
+ }
279
+ }
280
+ nextEventId() {
281
+ return String(++this.eventIdCounter);
282
+ }
283
+ static async create(options = {}) {
284
+ const server = new MockSSEServer(options);
285
+ await server.start();
286
+ return server;
287
+ }
288
+ }
289
+ export async function createMockSSEServer(options) {
290
+ return MockSSEServer.create(options);
291
+ }