recker 1.0.20 → 1.0.21-next.ab2d00f

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 (449) hide show
  1. package/README.md +55 -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 +2 -1
  50. package/dist/core/client.js +11 -7
  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 +2 -1
  60. package/dist/index.js +2 -0
  61. package/dist/mcp/cli.d.ts +2 -0
  62. package/dist/mcp/cli.js +136 -0
  63. package/dist/mcp/client.d.ts +0 -1
  64. package/dist/mcp/contract.d.ts +0 -1
  65. package/dist/mcp/embeddings-loader.d.ts +0 -1
  66. package/dist/mcp/geoip-loader.d.ts +0 -1
  67. package/dist/mcp/index.d.ts +0 -1
  68. package/dist/mcp/ip-intel.d.ts +0 -1
  69. package/dist/mcp/search/hybrid-search.d.ts +0 -1
  70. package/dist/mcp/search/index.d.ts +0 -1
  71. package/dist/mcp/search/math.d.ts +0 -1
  72. package/dist/mcp/search/types.d.ts +0 -1
  73. package/dist/mcp/server.d.ts +6 -2
  74. package/dist/mcp/server.js +193 -151
  75. package/dist/mcp/tools/loader.d.ts +2 -0
  76. package/dist/mcp/tools/loader.js +41 -0
  77. package/dist/mcp/tools/network.d.ts +3 -0
  78. package/dist/mcp/tools/network.js +267 -0
  79. package/dist/mcp/tools/registry.d.ts +17 -0
  80. package/dist/mcp/tools/registry.js +37 -0
  81. package/dist/mcp/types.d.ts +0 -1
  82. package/dist/mini.d.ts +28 -0
  83. package/dist/mini.js +94 -0
  84. package/dist/plugins/auth/api-key.d.ts +8 -0
  85. package/dist/plugins/auth/api-key.js +27 -0
  86. package/dist/plugins/auth/auth0.d.ts +33 -0
  87. package/dist/plugins/auth/auth0.js +94 -0
  88. package/dist/plugins/auth/aws-sigv4.d.ts +10 -0
  89. package/dist/plugins/auth/aws-sigv4.js +88 -0
  90. package/dist/plugins/auth/azure-ad.d.ts +48 -0
  91. package/dist/plugins/auth/azure-ad.js +152 -0
  92. package/dist/plugins/auth/basic.d.ts +7 -0
  93. package/dist/plugins/auth/basic.js +13 -0
  94. package/dist/plugins/auth/bearer.d.ts +8 -0
  95. package/dist/plugins/auth/bearer.js +17 -0
  96. package/dist/plugins/auth/cognito.d.ts +45 -0
  97. package/dist/plugins/auth/cognito.js +208 -0
  98. package/dist/plugins/auth/digest.d.ts +8 -0
  99. package/dist/plugins/auth/digest.js +100 -0
  100. package/dist/plugins/auth/firebase.d.ts +32 -0
  101. package/dist/plugins/auth/firebase.js +195 -0
  102. package/dist/plugins/auth/github-app.d.ts +36 -0
  103. package/dist/plugins/auth/github-app.js +170 -0
  104. package/dist/plugins/auth/google-service-account.d.ts +49 -0
  105. package/dist/plugins/auth/google-service-account.js +172 -0
  106. package/dist/plugins/auth/index.d.ts +15 -0
  107. package/dist/plugins/auth/index.js +15 -0
  108. package/dist/plugins/auth/mtls.d.ts +37 -0
  109. package/dist/plugins/auth/mtls.js +140 -0
  110. package/dist/plugins/auth/oauth2.d.ts +8 -0
  111. package/dist/plugins/auth/oauth2.js +26 -0
  112. package/dist/plugins/auth/oidc.d.ts +55 -0
  113. package/dist/plugins/auth/oidc.js +222 -0
  114. package/dist/plugins/auth/okta.d.ts +47 -0
  115. package/dist/plugins/auth/okta.js +157 -0
  116. package/dist/plugins/auth.d.ts +1 -45
  117. package/dist/plugins/auth.js +1 -268
  118. package/dist/plugins/cache.d.ts +1 -2
  119. package/dist/plugins/cache.js +2 -2
  120. package/dist/plugins/certificate-pinning.d.ts +59 -0
  121. package/dist/plugins/certificate-pinning.js +236 -0
  122. package/dist/plugins/circuit-breaker.d.ts +1 -2
  123. package/dist/plugins/circuit-breaker.js +1 -1
  124. package/dist/plugins/compression.d.ts +0 -1
  125. package/dist/plugins/cookie-jar.d.ts +1 -2
  126. package/dist/plugins/cookie-jar.js +1 -1
  127. package/dist/plugins/dedup.d.ts +1 -2
  128. package/dist/plugins/dedup.js +1 -1
  129. package/dist/plugins/graphql.d.ts +0 -1
  130. package/dist/plugins/grpc-web.d.ts +0 -1
  131. package/dist/plugins/har-player.d.ts +1 -2
  132. package/dist/plugins/har-player.js +1 -1
  133. package/dist/plugins/har-recorder.d.ts +1 -2
  134. package/dist/plugins/har-recorder.js +1 -1
  135. package/dist/plugins/hls.d.ts +90 -18
  136. package/dist/plugins/hls.js +343 -173
  137. package/dist/plugins/http2-push.d.ts +0 -1
  138. package/dist/plugins/http3.d.ts +0 -1
  139. package/dist/plugins/index.d.ts +27 -0
  140. package/dist/plugins/index.js +27 -0
  141. package/dist/plugins/interface-rotator.d.ts +1 -2
  142. package/dist/plugins/interface-rotator.js +1 -1
  143. package/dist/plugins/jsonrpc.d.ts +0 -1
  144. package/dist/plugins/logger.d.ts +1 -2
  145. package/dist/plugins/logger.js +1 -1
  146. package/dist/plugins/odata.d.ts +0 -1
  147. package/dist/plugins/pagination.d.ts +0 -1
  148. package/dist/plugins/proxy-rotator.d.ts +1 -2
  149. package/dist/plugins/proxy-rotator.js +1 -1
  150. package/dist/plugins/rate-limit.d.ts +15 -0
  151. package/dist/plugins/rate-limit.js +162 -0
  152. package/dist/plugins/retry.d.ts +1 -2
  153. package/dist/plugins/retry.js +3 -3
  154. package/dist/plugins/scrape.d.ts +0 -1
  155. package/dist/plugins/server-timing.d.ts +1 -2
  156. package/dist/plugins/server-timing.js +1 -1
  157. package/dist/plugins/soap.d.ts +0 -1
  158. package/dist/plugins/user-agent.d.ts +1 -2
  159. package/dist/plugins/user-agent.js +1 -1
  160. package/dist/plugins/xml.d.ts +0 -1
  161. package/dist/plugins/xsrf.d.ts +1 -2
  162. package/dist/plugins/xsrf.js +3 -3
  163. package/dist/presets/anthropic.d.ts +0 -1
  164. package/dist/presets/aws.d.ts +0 -1
  165. package/dist/presets/azure-openai.d.ts +0 -1
  166. package/dist/presets/azure.d.ts +0 -1
  167. package/dist/presets/cloudflare.d.ts +0 -1
  168. package/dist/presets/cohere.d.ts +0 -1
  169. package/dist/presets/deepseek.d.ts +0 -1
  170. package/dist/presets/digitalocean.d.ts +0 -1
  171. package/dist/presets/discord.d.ts +0 -1
  172. package/dist/presets/fireworks.d.ts +0 -1
  173. package/dist/presets/gcp.d.ts +0 -1
  174. package/dist/presets/gemini.d.ts +0 -1
  175. package/dist/presets/github.d.ts +0 -1
  176. package/dist/presets/gitlab.d.ts +0 -1
  177. package/dist/presets/groq.d.ts +0 -1
  178. package/dist/presets/huggingface.d.ts +0 -1
  179. package/dist/presets/index.d.ts +0 -1
  180. package/dist/presets/linear.d.ts +0 -1
  181. package/dist/presets/mailgun.d.ts +0 -1
  182. package/dist/presets/meta.d.ts +0 -1
  183. package/dist/presets/mistral.d.ts +0 -1
  184. package/dist/presets/notion.d.ts +0 -1
  185. package/dist/presets/openai.d.ts +0 -1
  186. package/dist/presets/oracle.d.ts +0 -1
  187. package/dist/presets/perplexity.d.ts +0 -1
  188. package/dist/presets/registry.d.ts +0 -1
  189. package/dist/presets/replicate.d.ts +0 -1
  190. package/dist/presets/sinch.d.ts +0 -1
  191. package/dist/presets/slack.d.ts +0 -1
  192. package/dist/presets/stripe.d.ts +0 -1
  193. package/dist/presets/supabase.d.ts +0 -1
  194. package/dist/presets/tiktok.d.ts +0 -1
  195. package/dist/presets/together.d.ts +0 -1
  196. package/dist/presets/twilio.d.ts +0 -1
  197. package/dist/presets/vercel.d.ts +0 -1
  198. package/dist/presets/vultr.d.ts +0 -1
  199. package/dist/presets/xai.d.ts +0 -1
  200. package/dist/presets/youtube.d.ts +0 -1
  201. package/dist/protocols/ftp.d.ts +0 -1
  202. package/dist/protocols/index.d.ts +0 -1
  203. package/dist/protocols/sftp.d.ts +0 -1
  204. package/dist/protocols/telnet.d.ts +0 -1
  205. package/dist/recker.d.ts +0 -1
  206. package/dist/runner/request-runner.d.ts +0 -1
  207. package/dist/scrape/document.d.ts +0 -1
  208. package/dist/scrape/element.d.ts +0 -1
  209. package/dist/scrape/extractors.d.ts +0 -1
  210. package/dist/scrape/index.d.ts +0 -1
  211. package/dist/scrape/types.d.ts +0 -1
  212. package/dist/testing/index.d.ts +16 -1
  213. package/dist/testing/index.js +8 -0
  214. package/dist/testing/mock-dns-server.d.ts +69 -0
  215. package/dist/testing/mock-dns-server.js +269 -0
  216. package/dist/testing/mock-ftp-server.d.ts +89 -0
  217. package/dist/testing/mock-ftp-server.js +562 -0
  218. package/dist/testing/mock-hls-server.d.ts +80 -0
  219. package/dist/testing/mock-hls-server.js +381 -0
  220. package/dist/testing/mock-http-server.d.ts +99 -0
  221. package/dist/testing/mock-http-server.js +298 -0
  222. package/dist/testing/mock-sse-server.d.ts +76 -0
  223. package/dist/testing/mock-sse-server.js +291 -0
  224. package/dist/testing/mock-telnet-server.d.ts +59 -0
  225. package/dist/testing/mock-telnet-server.js +273 -0
  226. package/dist/testing/mock-udp-server.d.ts +0 -1
  227. package/dist/testing/mock-websocket-server.d.ts +77 -0
  228. package/dist/testing/mock-websocket-server.js +316 -0
  229. package/dist/testing/mock-whois-server.d.ts +56 -0
  230. package/dist/testing/mock-whois-server.js +234 -0
  231. package/dist/testing/mock.d.ts +0 -1
  232. package/dist/transport/base-udp.d.ts +0 -1
  233. package/dist/transport/fetch.d.ts +0 -1
  234. package/dist/transport/udp-response.d.ts +0 -1
  235. package/dist/transport/udp.d.ts +0 -1
  236. package/dist/transport/undici.d.ts +0 -1
  237. package/dist/transport/undici.js +1 -1
  238. package/dist/types/ai.d.ts +0 -1
  239. package/dist/types/index.d.ts +0 -1
  240. package/dist/types/logger.d.ts +0 -1
  241. package/dist/types/udp.d.ts +0 -1
  242. package/dist/udp/index.d.ts +0 -1
  243. package/dist/utils/agent-manager.d.ts +0 -1
  244. package/dist/utils/body.d.ts +0 -1
  245. package/dist/utils/cert.d.ts +0 -1
  246. package/dist/utils/charset.d.ts +0 -1
  247. package/dist/utils/chart.d.ts +0 -1
  248. package/dist/utils/client-pool.d.ts +0 -1
  249. package/dist/utils/colors.d.ts +0 -1
  250. package/dist/utils/concurrency.d.ts +0 -1
  251. package/dist/utils/dns-toolkit.d.ts +0 -1
  252. package/dist/utils/dns-toolkit.js +1 -1
  253. package/dist/utils/dns.d.ts +0 -1
  254. package/dist/utils/dns.js +2 -2
  255. package/dist/utils/doh.d.ts +0 -1
  256. package/dist/utils/download.d.ts +0 -1
  257. package/dist/utils/env-proxy.d.ts +0 -1
  258. package/dist/utils/header-parser.d.ts +0 -1
  259. package/dist/utils/html-cleaner.d.ts +0 -1
  260. package/dist/utils/link-header.d.ts +0 -1
  261. package/dist/utils/optional-require.d.ts +0 -1
  262. package/dist/utils/optional-require.js +1 -1
  263. package/dist/utils/progress.d.ts +0 -1
  264. package/dist/utils/rdap.d.ts +0 -1
  265. package/dist/utils/request-pool.d.ts +0 -1
  266. package/dist/utils/security-grader.d.ts +0 -1
  267. package/dist/utils/sparkline.d.ts +0 -1
  268. package/dist/utils/sse.d.ts +0 -1
  269. package/dist/utils/streaming.d.ts +0 -1
  270. package/dist/utils/system-metrics.d.ts +0 -1
  271. package/dist/utils/tls-inspector.d.ts +0 -1
  272. package/dist/utils/try-fn.d.ts +0 -1
  273. package/dist/utils/upload.d.ts +0 -1
  274. package/dist/utils/user-agent.d.ts +0 -1
  275. package/dist/utils/whois.d.ts +0 -1
  276. package/dist/webrtc/index.d.ts +0 -1
  277. package/dist/webrtc/index.js +1 -1
  278. package/dist/websocket/client.d.ts +0 -1
  279. package/package.json +39 -3
  280. package/dist/ai/adaptive-timeout.d.ts.map +0 -1
  281. package/dist/ai/client.d.ts.map +0 -1
  282. package/dist/ai/index.d.ts.map +0 -1
  283. package/dist/ai/providers/anthropic.d.ts.map +0 -1
  284. package/dist/ai/providers/base.d.ts.map +0 -1
  285. package/dist/ai/providers/index.d.ts.map +0 -1
  286. package/dist/ai/providers/openai.d.ts.map +0 -1
  287. package/dist/ai/rate-limiter.d.ts.map +0 -1
  288. package/dist/bench/generator.d.ts.map +0 -1
  289. package/dist/bench/stats.d.ts.map +0 -1
  290. package/dist/cache/file-storage.d.ts.map +0 -1
  291. package/dist/cache/memory-limits.d.ts.map +0 -1
  292. package/dist/cache/memory-storage.d.ts.map +0 -1
  293. package/dist/cache/redis-storage.d.ts.map +0 -1
  294. package/dist/cli/handler.d.ts.map +0 -1
  295. package/dist/cli/index.d.ts.map +0 -1
  296. package/dist/cli/presets.d.ts.map +0 -1
  297. package/dist/cli/tui/ai-chat.d.ts.map +0 -1
  298. package/dist/cli/tui/load-dashboard.d.ts.map +0 -1
  299. package/dist/cli/tui/scroll-buffer.d.ts.map +0 -1
  300. package/dist/cli/tui/search-panel.d.ts.map +0 -1
  301. package/dist/cli/tui/shell-search.d.ts.map +0 -1
  302. package/dist/cli/tui/shell.d.ts.map +0 -1
  303. package/dist/cli/tui/websocket.d.ts.map +0 -1
  304. package/dist/constants/http-status.d.ts.map +0 -1
  305. package/dist/constants.d.ts.map +0 -1
  306. package/dist/contract/index.d.ts.map +0 -1
  307. package/dist/cookies/memory-cookie-jar.d.ts.map +0 -1
  308. package/dist/core/client.d.ts.map +0 -1
  309. package/dist/core/errors.d.ts.map +0 -1
  310. package/dist/core/index.d.ts.map +0 -1
  311. package/dist/core/request-promise.d.ts.map +0 -1
  312. package/dist/core/request.d.ts.map +0 -1
  313. package/dist/core/response.d.ts.map +0 -1
  314. package/dist/dns/index.d.ts.map +0 -1
  315. package/dist/dns/propagation.d.ts.map +0 -1
  316. package/dist/events/request-events.d.ts.map +0 -1
  317. package/dist/index.d.ts.map +0 -1
  318. package/dist/mcp/client.d.ts.map +0 -1
  319. package/dist/mcp/contract.d.ts.map +0 -1
  320. package/dist/mcp/embeddings-loader.d.ts.map +0 -1
  321. package/dist/mcp/geoip-loader.d.ts.map +0 -1
  322. package/dist/mcp/index.d.ts.map +0 -1
  323. package/dist/mcp/ip-intel.d.ts.map +0 -1
  324. package/dist/mcp/search/hybrid-search.d.ts.map +0 -1
  325. package/dist/mcp/search/index.d.ts.map +0 -1
  326. package/dist/mcp/search/math.d.ts.map +0 -1
  327. package/dist/mcp/search/types.d.ts.map +0 -1
  328. package/dist/mcp/server.d.ts.map +0 -1
  329. package/dist/mcp/types.d.ts.map +0 -1
  330. package/dist/plugins/auth.d.ts.map +0 -1
  331. package/dist/plugins/cache.d.ts.map +0 -1
  332. package/dist/plugins/circuit-breaker.d.ts.map +0 -1
  333. package/dist/plugins/compression.d.ts.map +0 -1
  334. package/dist/plugins/cookie-jar.d.ts.map +0 -1
  335. package/dist/plugins/dedup.d.ts.map +0 -1
  336. package/dist/plugins/graphql.d.ts.map +0 -1
  337. package/dist/plugins/grpc-web.d.ts.map +0 -1
  338. package/dist/plugins/har-player.d.ts.map +0 -1
  339. package/dist/plugins/har-recorder.d.ts.map +0 -1
  340. package/dist/plugins/hls.d.ts.map +0 -1
  341. package/dist/plugins/http2-push.d.ts.map +0 -1
  342. package/dist/plugins/http3.d.ts.map +0 -1
  343. package/dist/plugins/interface-rotator.d.ts.map +0 -1
  344. package/dist/plugins/jsonrpc.d.ts.map +0 -1
  345. package/dist/plugins/logger.d.ts.map +0 -1
  346. package/dist/plugins/odata.d.ts.map +0 -1
  347. package/dist/plugins/pagination.d.ts.map +0 -1
  348. package/dist/plugins/proxy-rotator.d.ts.map +0 -1
  349. package/dist/plugins/retry.d.ts.map +0 -1
  350. package/dist/plugins/scrape.d.ts.map +0 -1
  351. package/dist/plugins/server-timing.d.ts.map +0 -1
  352. package/dist/plugins/soap.d.ts.map +0 -1
  353. package/dist/plugins/user-agent.d.ts.map +0 -1
  354. package/dist/plugins/xml.d.ts.map +0 -1
  355. package/dist/plugins/xsrf.d.ts.map +0 -1
  356. package/dist/presets/anthropic.d.ts.map +0 -1
  357. package/dist/presets/aws.d.ts.map +0 -1
  358. package/dist/presets/azure-openai.d.ts.map +0 -1
  359. package/dist/presets/azure.d.ts.map +0 -1
  360. package/dist/presets/cloudflare.d.ts.map +0 -1
  361. package/dist/presets/cohere.d.ts.map +0 -1
  362. package/dist/presets/deepseek.d.ts.map +0 -1
  363. package/dist/presets/digitalocean.d.ts.map +0 -1
  364. package/dist/presets/discord.d.ts.map +0 -1
  365. package/dist/presets/fireworks.d.ts.map +0 -1
  366. package/dist/presets/gcp.d.ts.map +0 -1
  367. package/dist/presets/gemini.d.ts.map +0 -1
  368. package/dist/presets/github.d.ts.map +0 -1
  369. package/dist/presets/gitlab.d.ts.map +0 -1
  370. package/dist/presets/groq.d.ts.map +0 -1
  371. package/dist/presets/huggingface.d.ts.map +0 -1
  372. package/dist/presets/index.d.ts.map +0 -1
  373. package/dist/presets/linear.d.ts.map +0 -1
  374. package/dist/presets/mailgun.d.ts.map +0 -1
  375. package/dist/presets/meta.d.ts.map +0 -1
  376. package/dist/presets/mistral.d.ts.map +0 -1
  377. package/dist/presets/notion.d.ts.map +0 -1
  378. package/dist/presets/openai.d.ts.map +0 -1
  379. package/dist/presets/oracle.d.ts.map +0 -1
  380. package/dist/presets/perplexity.d.ts.map +0 -1
  381. package/dist/presets/registry.d.ts.map +0 -1
  382. package/dist/presets/replicate.d.ts.map +0 -1
  383. package/dist/presets/sinch.d.ts.map +0 -1
  384. package/dist/presets/slack.d.ts.map +0 -1
  385. package/dist/presets/stripe.d.ts.map +0 -1
  386. package/dist/presets/supabase.d.ts.map +0 -1
  387. package/dist/presets/tiktok.d.ts.map +0 -1
  388. package/dist/presets/together.d.ts.map +0 -1
  389. package/dist/presets/twilio.d.ts.map +0 -1
  390. package/dist/presets/vercel.d.ts.map +0 -1
  391. package/dist/presets/vultr.d.ts.map +0 -1
  392. package/dist/presets/xai.d.ts.map +0 -1
  393. package/dist/presets/youtube.d.ts.map +0 -1
  394. package/dist/protocols/ftp.d.ts.map +0 -1
  395. package/dist/protocols/index.d.ts.map +0 -1
  396. package/dist/protocols/sftp.d.ts.map +0 -1
  397. package/dist/protocols/telnet.d.ts.map +0 -1
  398. package/dist/recker.d.ts.map +0 -1
  399. package/dist/runner/request-runner.d.ts.map +0 -1
  400. package/dist/scrape/document.d.ts.map +0 -1
  401. package/dist/scrape/element.d.ts.map +0 -1
  402. package/dist/scrape/extractors.d.ts.map +0 -1
  403. package/dist/scrape/index.d.ts.map +0 -1
  404. package/dist/scrape/types.d.ts.map +0 -1
  405. package/dist/testing/index.d.ts.map +0 -1
  406. package/dist/testing/mock-udp-server.d.ts.map +0 -1
  407. package/dist/testing/mock.d.ts.map +0 -1
  408. package/dist/transport/base-udp.d.ts.map +0 -1
  409. package/dist/transport/fetch.d.ts.map +0 -1
  410. package/dist/transport/udp-response.d.ts.map +0 -1
  411. package/dist/transport/udp.d.ts.map +0 -1
  412. package/dist/transport/undici.d.ts.map +0 -1
  413. package/dist/types/ai.d.ts.map +0 -1
  414. package/dist/types/index.d.ts.map +0 -1
  415. package/dist/types/logger.d.ts.map +0 -1
  416. package/dist/types/udp.d.ts.map +0 -1
  417. package/dist/udp/index.d.ts.map +0 -1
  418. package/dist/utils/agent-manager.d.ts.map +0 -1
  419. package/dist/utils/body.d.ts.map +0 -1
  420. package/dist/utils/cert.d.ts.map +0 -1
  421. package/dist/utils/charset.d.ts.map +0 -1
  422. package/dist/utils/chart.d.ts.map +0 -1
  423. package/dist/utils/client-pool.d.ts.map +0 -1
  424. package/dist/utils/colors.d.ts.map +0 -1
  425. package/dist/utils/concurrency.d.ts.map +0 -1
  426. package/dist/utils/dns-toolkit.d.ts.map +0 -1
  427. package/dist/utils/dns.d.ts.map +0 -1
  428. package/dist/utils/doh.d.ts.map +0 -1
  429. package/dist/utils/download.d.ts.map +0 -1
  430. package/dist/utils/env-proxy.d.ts.map +0 -1
  431. package/dist/utils/header-parser.d.ts.map +0 -1
  432. package/dist/utils/html-cleaner.d.ts.map +0 -1
  433. package/dist/utils/link-header.d.ts.map +0 -1
  434. package/dist/utils/optional-require.d.ts.map +0 -1
  435. package/dist/utils/progress.d.ts.map +0 -1
  436. package/dist/utils/rdap.d.ts.map +0 -1
  437. package/dist/utils/request-pool.d.ts.map +0 -1
  438. package/dist/utils/security-grader.d.ts.map +0 -1
  439. package/dist/utils/sparkline.d.ts.map +0 -1
  440. package/dist/utils/sse.d.ts.map +0 -1
  441. package/dist/utils/streaming.d.ts.map +0 -1
  442. package/dist/utils/system-metrics.d.ts.map +0 -1
  443. package/dist/utils/tls-inspector.d.ts.map +0 -1
  444. package/dist/utils/try-fn.d.ts.map +0 -1
  445. package/dist/utils/upload.d.ts.map +0 -1
  446. package/dist/utils/user-agent.d.ts.map +0 -1
  447. package/dist/utils/whois.d.ts.map +0 -1
  448. package/dist/webrtc/index.d.ts.map +0 -1
  449. package/dist/websocket/client.d.ts.map +0 -1
@@ -0,0 +1,88 @@
1
+ import { createHash, createHmac } from 'node:crypto';
2
+ function sha256(str) {
3
+ return createHash('sha256').update(str).digest('hex');
4
+ }
5
+ export function awsSignatureV4(options) {
6
+ return async (req, next) => {
7
+ const url = new URL(req.url);
8
+ const host = url.host;
9
+ const pathname = url.pathname;
10
+ const queryString = url.search.slice(1);
11
+ const now = new Date();
12
+ const amzDate = now.toISOString().replace(/[:-]|\.\d{3}/g, '');
13
+ const dateStamp = amzDate.slice(0, 8);
14
+ const method = req.method;
15
+ const canonicalUri = pathname || '/';
16
+ const canonicalQueryString = queryString
17
+ .split('&')
18
+ .filter(Boolean)
19
+ .sort()
20
+ .join('&');
21
+ let payload = '';
22
+ if (req.body) {
23
+ if (typeof req.body === 'string') {
24
+ payload = req.body;
25
+ }
26
+ else if (req.body instanceof ArrayBuffer) {
27
+ payload = Buffer.from(req.body).toString();
28
+ }
29
+ }
30
+ const payloadHash = sha256(payload);
31
+ const headers = {
32
+ host,
33
+ 'x-amz-date': amzDate,
34
+ 'x-amz-content-sha256': payloadHash,
35
+ };
36
+ if (options.sessionToken) {
37
+ headers['x-amz-security-token'] = options.sessionToken;
38
+ }
39
+ req.headers.forEach((value, key) => {
40
+ headers[key.toLowerCase()] = value;
41
+ });
42
+ const signedHeaders = Object.keys(headers).sort().join(';');
43
+ const canonicalHeaders = Object.keys(headers)
44
+ .sort()
45
+ .map(key => `${key}:${headers[key].trim()}\n`)
46
+ .join('');
47
+ const canonicalRequest = [
48
+ method,
49
+ canonicalUri,
50
+ canonicalQueryString,
51
+ canonicalHeaders,
52
+ signedHeaders,
53
+ payloadHash,
54
+ ].join('\n');
55
+ const algorithm = 'AWS4-HMAC-SHA256';
56
+ const credentialScope = `${dateStamp}/${options.region}/${options.service}/aws4_request`;
57
+ const stringToSign = [
58
+ algorithm,
59
+ amzDate,
60
+ credentialScope,
61
+ sha256(canonicalRequest),
62
+ ].join('\n');
63
+ const getSignatureKey = (key, dateStamp, regionName, serviceName) => {
64
+ const kDate = createHmac('sha256', `AWS4${key}`).update(dateStamp).digest();
65
+ const kRegion = createHmac('sha256', kDate).update(regionName).digest();
66
+ const kService = createHmac('sha256', kRegion).update(serviceName).digest();
67
+ const kSigning = createHmac('sha256', kService).update('aws4_request').digest();
68
+ return kSigning;
69
+ };
70
+ const signingKey = getSignatureKey(options.secretAccessKey, dateStamp, options.region, options.service);
71
+ const signature = createHmac('sha256', signingKey)
72
+ .update(stringToSign)
73
+ .digest('hex');
74
+ const authorizationHeader = `${algorithm} Credential=${options.accessKeyId}/${credentialScope}, SignedHeaders=${signedHeaders}, Signature=${signature}`;
75
+ let newReq = req.withHeader('Authorization', authorizationHeader);
76
+ newReq = newReq.withHeader('x-amz-date', amzDate);
77
+ newReq = newReq.withHeader('x-amz-content-sha256', payloadHash);
78
+ if (options.sessionToken) {
79
+ newReq = newReq.withHeader('x-amz-security-token', options.sessionToken);
80
+ }
81
+ return next(newReq);
82
+ };
83
+ }
84
+ export function awsSignatureV4Plugin(options) {
85
+ return (client) => {
86
+ client.use(awsSignatureV4(options));
87
+ };
88
+ }
@@ -0,0 +1,48 @@
1
+ import { Middleware, Plugin } from '../../types/index.js';
2
+ import { OIDCTokens } from './oidc.js';
3
+ export interface AzureADOptions {
4
+ tenantId: string;
5
+ clientId: string;
6
+ clientSecret?: string;
7
+ clientCertificate?: {
8
+ thumbprint: string;
9
+ privateKey: string;
10
+ };
11
+ scopes?: string[];
12
+ accessToken?: string | (() => string | Promise<string>);
13
+ refreshToken?: string;
14
+ tokenStorage?: {
15
+ get: () => Promise<OIDCTokens | null>;
16
+ set: (tokens: OIDCTokens) => Promise<void>;
17
+ };
18
+ cloudInstance?: string;
19
+ b2c?: {
20
+ tenantName: string;
21
+ policy: string;
22
+ };
23
+ }
24
+ export declare function generateAzureADAuthUrl(options: AzureADOptions & {
25
+ redirectUri: string;
26
+ state?: string;
27
+ nonce?: string;
28
+ usePKCE?: boolean;
29
+ prompt?: 'login' | 'none' | 'consent' | 'select_account';
30
+ loginHint?: string;
31
+ domainHint?: string;
32
+ }): Promise<{
33
+ url: string;
34
+ codeVerifier?: string;
35
+ }>;
36
+ export declare function exchangeAzureADCode(options: AzureADOptions & {
37
+ code: string;
38
+ redirectUri: string;
39
+ codeVerifier?: string;
40
+ }): Promise<OIDCTokens>;
41
+ export declare function azureADOnBehalfOf(options: AzureADOptions & {
42
+ assertion: string;
43
+ scope: string;
44
+ }): Promise<OIDCTokens>;
45
+ export declare function getAzureADUserInfo(accessToken: string): Promise<Record<string, unknown>>;
46
+ export declare function azureAD(options: AzureADOptions): Middleware;
47
+ export declare function azureADPlugin(options: AzureADOptions): Plugin;
48
+ export { azureAD as entraId, azureADPlugin as entraIdPlugin };
@@ -0,0 +1,152 @@
1
+ import { oidc, generatePKCE } from './oidc.js';
2
+ function getAzureADIssuer(options) {
3
+ if (options.b2c) {
4
+ return `https://${options.b2c.tenantName}.b2clogin.com/${options.b2c.tenantName}.onmicrosoft.com/${options.b2c.policy}/v2.0`;
5
+ }
6
+ const cloudInstance = options.cloudInstance || 'https://login.microsoftonline.com';
7
+ return `${cloudInstance}/${options.tenantId}/v2.0`;
8
+ }
9
+ function getAzureADTokenEndpoint(options) {
10
+ if (options.b2c) {
11
+ return `https://${options.b2c.tenantName}.b2clogin.com/${options.b2c.tenantName}.onmicrosoft.com/${options.b2c.policy}/oauth2/v2.0/token`;
12
+ }
13
+ const cloudInstance = options.cloudInstance || 'https://login.microsoftonline.com';
14
+ return `${cloudInstance}/${options.tenantId}/oauth2/v2.0/token`;
15
+ }
16
+ export async function generateAzureADAuthUrl(options) {
17
+ const pkce = options.usePKCE ? generatePKCE() : undefined;
18
+ let authorizeUrl;
19
+ if (options.b2c) {
20
+ authorizeUrl = `https://${options.b2c.tenantName}.b2clogin.com/${options.b2c.tenantName}.onmicrosoft.com/${options.b2c.policy}/oauth2/v2.0/authorize`;
21
+ }
22
+ else {
23
+ const cloudInstance = options.cloudInstance || 'https://login.microsoftonline.com';
24
+ authorizeUrl = `${cloudInstance}/${options.tenantId}/oauth2/v2.0/authorize`;
25
+ }
26
+ const params = new URLSearchParams({
27
+ response_type: 'code',
28
+ client_id: options.clientId,
29
+ redirect_uri: options.redirectUri,
30
+ scope: (options.scopes || ['openid', 'profile', 'email']).join(' '),
31
+ response_mode: 'query',
32
+ });
33
+ if (options.state) {
34
+ params.set('state', options.state);
35
+ }
36
+ if (options.nonce) {
37
+ params.set('nonce', options.nonce);
38
+ }
39
+ if (pkce) {
40
+ params.set('code_challenge', pkce.codeChallenge);
41
+ params.set('code_challenge_method', 'S256');
42
+ }
43
+ if (options.prompt) {
44
+ params.set('prompt', options.prompt);
45
+ }
46
+ if (options.loginHint) {
47
+ params.set('login_hint', options.loginHint);
48
+ }
49
+ if (options.domainHint) {
50
+ params.set('domain_hint', options.domainHint);
51
+ }
52
+ return {
53
+ url: `${authorizeUrl}?${params.toString()}`,
54
+ codeVerifier: pkce?.codeVerifier,
55
+ };
56
+ }
57
+ export async function exchangeAzureADCode(options) {
58
+ const tokenUrl = getAzureADTokenEndpoint(options);
59
+ const params = new URLSearchParams({
60
+ grant_type: 'authorization_code',
61
+ client_id: options.clientId,
62
+ code: options.code,
63
+ redirect_uri: options.redirectUri,
64
+ scope: (options.scopes || ['openid', 'profile', 'email']).join(' '),
65
+ });
66
+ if (options.clientSecret) {
67
+ params.set('client_secret', options.clientSecret);
68
+ }
69
+ if (options.codeVerifier) {
70
+ params.set('code_verifier', options.codeVerifier);
71
+ }
72
+ const response = await fetch(tokenUrl, {
73
+ method: 'POST',
74
+ headers: {
75
+ 'Content-Type': 'application/x-www-form-urlencoded',
76
+ },
77
+ body: params.toString(),
78
+ });
79
+ if (!response.ok) {
80
+ const error = await response.json();
81
+ throw new Error(`Azure AD token exchange failed: ${error.error_description || error.error}`);
82
+ }
83
+ const data = await response.json();
84
+ return {
85
+ accessToken: data.access_token,
86
+ refreshToken: data.refresh_token,
87
+ idToken: data.id_token,
88
+ expiresAt: data.expires_in ? Date.now() + data.expires_in * 1000 : undefined,
89
+ tokenType: data.token_type || 'Bearer',
90
+ };
91
+ }
92
+ export async function azureADOnBehalfOf(options) {
93
+ const tokenUrl = getAzureADTokenEndpoint(options);
94
+ const params = new URLSearchParams({
95
+ grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
96
+ client_id: options.clientId,
97
+ assertion: options.assertion,
98
+ scope: options.scope,
99
+ requested_token_use: 'on_behalf_of',
100
+ });
101
+ if (options.clientSecret) {
102
+ params.set('client_secret', options.clientSecret);
103
+ }
104
+ const response = await fetch(tokenUrl, {
105
+ method: 'POST',
106
+ headers: {
107
+ 'Content-Type': 'application/x-www-form-urlencoded',
108
+ },
109
+ body: params.toString(),
110
+ });
111
+ if (!response.ok) {
112
+ const error = await response.json();
113
+ throw new Error(`Azure AD OBO flow failed: ${error.error_description || error.error}`);
114
+ }
115
+ const data = await response.json();
116
+ return {
117
+ accessToken: data.access_token,
118
+ refreshToken: data.refresh_token,
119
+ expiresAt: data.expires_in ? Date.now() + data.expires_in * 1000 : undefined,
120
+ tokenType: data.token_type || 'Bearer',
121
+ };
122
+ }
123
+ export async function getAzureADUserInfo(accessToken) {
124
+ const response = await fetch('https://graph.microsoft.com/v1.0/me', {
125
+ headers: {
126
+ Authorization: `Bearer ${accessToken}`,
127
+ },
128
+ });
129
+ if (!response.ok) {
130
+ throw new Error(`Failed to get user info: ${response.status}`);
131
+ }
132
+ return response.json();
133
+ }
134
+ export function azureAD(options) {
135
+ const issuer = getAzureADIssuer(options);
136
+ const scopes = options.scopes || ['openid', 'profile', 'email', 'offline_access'];
137
+ return oidc({
138
+ issuer,
139
+ clientId: options.clientId,
140
+ clientSecret: options.clientSecret,
141
+ scopes,
142
+ accessToken: options.accessToken,
143
+ refreshToken: options.refreshToken,
144
+ tokenStorage: options.tokenStorage,
145
+ });
146
+ }
147
+ export function azureADPlugin(options) {
148
+ return (client) => {
149
+ client.use(azureAD(options));
150
+ };
151
+ }
152
+ export { azureAD as entraId, azureADPlugin as entraIdPlugin };
@@ -0,0 +1,7 @@
1
+ import { Middleware, Plugin } from '../../types/index.js';
2
+ export interface BasicAuthOptions {
3
+ username: string;
4
+ password: string;
5
+ }
6
+ export declare function basicAuth(options: BasicAuthOptions): Middleware;
7
+ export declare function basicAuthPlugin(options: BasicAuthOptions): Plugin;
@@ -0,0 +1,13 @@
1
+ export function basicAuth(options) {
2
+ const credentials = Buffer.from(`${options.username}:${options.password}`).toString('base64');
3
+ const authHeader = `Basic ${credentials}`;
4
+ return async (req, next) => {
5
+ const newReq = req.withHeader('Authorization', authHeader);
6
+ return next(newReq);
7
+ };
8
+ }
9
+ export function basicAuthPlugin(options) {
10
+ return (client) => {
11
+ client.use(basicAuth(options));
12
+ };
13
+ }
@@ -0,0 +1,8 @@
1
+ import { Middleware, Plugin } from '../../types/index.js';
2
+ export interface BearerAuthOptions {
3
+ token: string | (() => string | Promise<string>);
4
+ type?: string;
5
+ headerName?: string;
6
+ }
7
+ export declare function bearerAuth(options: BearerAuthOptions): Middleware;
8
+ export declare function bearerAuthPlugin(options: BearerAuthOptions): Plugin;
@@ -0,0 +1,17 @@
1
+ export function bearerAuth(options) {
2
+ const type = options.type ?? 'Bearer';
3
+ const headerName = options.headerName ?? 'Authorization';
4
+ return async (req, next) => {
5
+ const token = typeof options.token === 'function'
6
+ ? await options.token()
7
+ : options.token;
8
+ const authHeader = `${type} ${token}`;
9
+ const newReq = req.withHeader(headerName, authHeader);
10
+ return next(newReq);
11
+ };
12
+ }
13
+ export function bearerAuthPlugin(options) {
14
+ return (client) => {
15
+ client.use(bearerAuth(options));
16
+ };
17
+ }
@@ -0,0 +1,45 @@
1
+ import { Middleware, Plugin } from '../../types/index.js';
2
+ export interface CognitoOptions {
3
+ region: string;
4
+ userPoolId: string;
5
+ clientId: string;
6
+ clientSecret?: string;
7
+ accessToken?: string | (() => string | Promise<string>);
8
+ idToken?: string;
9
+ refreshToken?: string;
10
+ username?: string;
11
+ password?: string;
12
+ useSRP?: boolean;
13
+ tokenStorage?: {
14
+ get: () => Promise<CognitoTokens | null>;
15
+ set: (tokens: CognitoTokens) => Promise<void>;
16
+ };
17
+ identityPoolId?: string;
18
+ }
19
+ export interface CognitoTokens {
20
+ accessToken: string;
21
+ idToken?: string;
22
+ refreshToken?: string;
23
+ expiresAt?: number;
24
+ tokenType?: string;
25
+ }
26
+ export interface CognitoAWSCredentials {
27
+ accessKeyId: string;
28
+ secretAccessKey: string;
29
+ sessionToken: string;
30
+ expiresAt: number;
31
+ }
32
+ export declare function getCognitoIdentityCredentials(options: {
33
+ region: string;
34
+ identityPoolId: string;
35
+ idToken: string;
36
+ userPoolId: string;
37
+ }): Promise<CognitoAWSCredentials>;
38
+ export declare function getCognitoHostedUIUrl(options: CognitoOptions & {
39
+ redirectUri: string;
40
+ responseType?: 'code' | 'token';
41
+ scopes?: string[];
42
+ state?: string;
43
+ }): string;
44
+ export declare function cognito(options: CognitoOptions): Middleware;
45
+ export declare function cognitoPlugin(options: CognitoOptions): Plugin;
@@ -0,0 +1,208 @@
1
+ import { createHmac } from 'node:crypto';
2
+ function generateSecretHash(username, clientId, clientSecret) {
3
+ return createHmac('sha256', clientSecret)
4
+ .update(username + clientId)
5
+ .digest('base64');
6
+ }
7
+ async function authenticateUserPassword(options) {
8
+ if (!options.username || !options.password) {
9
+ throw new Error('Username and password are required for USER_PASSWORD_AUTH');
10
+ }
11
+ const endpoint = `https://cognito-idp.${options.region}.amazonaws.com/`;
12
+ const authParameters = {
13
+ USERNAME: options.username,
14
+ PASSWORD: options.password,
15
+ };
16
+ if (options.clientSecret) {
17
+ authParameters.SECRET_HASH = generateSecretHash(options.username, options.clientId, options.clientSecret);
18
+ }
19
+ const response = await fetch(endpoint, {
20
+ method: 'POST',
21
+ headers: {
22
+ 'Content-Type': 'application/x-amz-json-1.1',
23
+ 'X-Amz-Target': 'AWSCognitoIdentityProviderService.InitiateAuth',
24
+ },
25
+ body: JSON.stringify({
26
+ AuthFlow: 'USER_PASSWORD_AUTH',
27
+ ClientId: options.clientId,
28
+ AuthParameters: authParameters,
29
+ }),
30
+ });
31
+ if (!response.ok) {
32
+ const error = await response.json();
33
+ throw new Error(`Cognito authentication failed: ${error.message || error.__type}`);
34
+ }
35
+ const data = await response.json();
36
+ if (data.ChallengeName) {
37
+ throw new Error(`Cognito challenge required: ${data.ChallengeName}`);
38
+ }
39
+ if (!data.AuthenticationResult) {
40
+ throw new Error('Cognito authentication failed: No result');
41
+ }
42
+ return {
43
+ accessToken: data.AuthenticationResult.AccessToken,
44
+ idToken: data.AuthenticationResult.IdToken,
45
+ refreshToken: data.AuthenticationResult.RefreshToken,
46
+ expiresAt: Date.now() + data.AuthenticationResult.ExpiresIn * 1000,
47
+ tokenType: data.AuthenticationResult.TokenType,
48
+ };
49
+ }
50
+ async function refreshCognitoTokens(options, refreshToken) {
51
+ const endpoint = `https://cognito-idp.${options.region}.amazonaws.com/`;
52
+ const authParameters = {
53
+ REFRESH_TOKEN: refreshToken,
54
+ };
55
+ if (options.clientSecret && options.username) {
56
+ authParameters.SECRET_HASH = generateSecretHash(options.username, options.clientId, options.clientSecret);
57
+ }
58
+ const response = await fetch(endpoint, {
59
+ method: 'POST',
60
+ headers: {
61
+ 'Content-Type': 'application/x-amz-json-1.1',
62
+ 'X-Amz-Target': 'AWSCognitoIdentityProviderService.InitiateAuth',
63
+ },
64
+ body: JSON.stringify({
65
+ AuthFlow: 'REFRESH_TOKEN_AUTH',
66
+ ClientId: options.clientId,
67
+ AuthParameters: authParameters,
68
+ }),
69
+ });
70
+ if (!response.ok) {
71
+ const error = await response.json();
72
+ throw new Error(`Cognito token refresh failed: ${error.message || error.__type}`);
73
+ }
74
+ const data = await response.json();
75
+ return {
76
+ accessToken: data.AuthenticationResult.AccessToken,
77
+ idToken: data.AuthenticationResult.IdToken,
78
+ refreshToken: refreshToken,
79
+ expiresAt: Date.now() + data.AuthenticationResult.ExpiresIn * 1000,
80
+ tokenType: data.AuthenticationResult.TokenType,
81
+ };
82
+ }
83
+ export async function getCognitoIdentityCredentials(options) {
84
+ const identityEndpoint = `https://cognito-identity.${options.region}.amazonaws.com/`;
85
+ const logins = {
86
+ [`cognito-idp.${options.region}.amazonaws.com/${options.userPoolId}`]: options.idToken,
87
+ };
88
+ const getIdResponse = await fetch(identityEndpoint, {
89
+ method: 'POST',
90
+ headers: {
91
+ 'Content-Type': 'application/x-amz-json-1.1',
92
+ 'X-Amz-Target': 'AWSCognitoIdentityService.GetId',
93
+ },
94
+ body: JSON.stringify({
95
+ IdentityPoolId: options.identityPoolId,
96
+ Logins: logins,
97
+ }),
98
+ });
99
+ if (!getIdResponse.ok) {
100
+ const error = await getIdResponse.json();
101
+ throw new Error(`Failed to get identity ID: ${error.message || error.__type}`);
102
+ }
103
+ const { IdentityId } = await getIdResponse.json();
104
+ const getCredentialsResponse = await fetch(identityEndpoint, {
105
+ method: 'POST',
106
+ headers: {
107
+ 'Content-Type': 'application/x-amz-json-1.1',
108
+ 'X-Amz-Target': 'AWSCognitoIdentityService.GetCredentialsForIdentity',
109
+ },
110
+ body: JSON.stringify({
111
+ IdentityId,
112
+ Logins: logins,
113
+ }),
114
+ });
115
+ if (!getCredentialsResponse.ok) {
116
+ const error = await getCredentialsResponse.json();
117
+ throw new Error(`Failed to get credentials: ${error.message || error.__type}`);
118
+ }
119
+ const data = await getCredentialsResponse.json();
120
+ return {
121
+ accessKeyId: data.Credentials.AccessKeyId,
122
+ secretAccessKey: data.Credentials.SecretKey,
123
+ sessionToken: data.Credentials.SessionToken,
124
+ expiresAt: data.Credentials.Expiration * 1000,
125
+ };
126
+ }
127
+ export function getCognitoHostedUIUrl(options) {
128
+ const domain = `https://${options.userPoolId.split('_')[1].toLowerCase()}.auth.${options.region}.amazoncognito.com`;
129
+ const params = new URLSearchParams({
130
+ response_type: options.responseType || 'code',
131
+ client_id: options.clientId,
132
+ redirect_uri: options.redirectUri,
133
+ scope: (options.scopes || ['openid', 'profile', 'email']).join(' '),
134
+ });
135
+ if (options.state) {
136
+ params.set('state', options.state);
137
+ }
138
+ return `${domain}/login?${params.toString()}`;
139
+ }
140
+ export function cognito(options) {
141
+ let cachedTokens = null;
142
+ const getTokens = async () => {
143
+ if (options.tokenStorage) {
144
+ const stored = await options.tokenStorage.get();
145
+ if (stored) {
146
+ cachedTokens = stored;
147
+ }
148
+ }
149
+ if (cachedTokens && cachedTokens.expiresAt && cachedTokens.expiresAt > Date.now() + 60000) {
150
+ return cachedTokens;
151
+ }
152
+ if (cachedTokens?.refreshToken || options.refreshToken) {
153
+ const refreshToken = cachedTokens?.refreshToken || options.refreshToken;
154
+ try {
155
+ cachedTokens = await refreshCognitoTokens(options, refreshToken);
156
+ if (options.tokenStorage) {
157
+ await options.tokenStorage.set(cachedTokens);
158
+ }
159
+ return cachedTokens;
160
+ }
161
+ catch {
162
+ }
163
+ }
164
+ if (options.accessToken) {
165
+ const token = typeof options.accessToken === 'function'
166
+ ? await options.accessToken()
167
+ : options.accessToken;
168
+ return {
169
+ accessToken: token,
170
+ idToken: options.idToken,
171
+ tokenType: 'Bearer',
172
+ };
173
+ }
174
+ if (options.username && options.password) {
175
+ cachedTokens = await authenticateUserPassword(options);
176
+ if (options.tokenStorage) {
177
+ await options.tokenStorage.set(cachedTokens);
178
+ }
179
+ return cachedTokens;
180
+ }
181
+ throw new Error('No valid authentication method. Provide accessToken, refreshToken, or username/password.');
182
+ };
183
+ return async (req, next) => {
184
+ const tokens = await getTokens();
185
+ const authReq = req.withHeader('Authorization', `Bearer ${tokens.accessToken}`);
186
+ const response = await next(authReq);
187
+ if (response.status === 401 && (cachedTokens?.refreshToken || options.refreshToken)) {
188
+ try {
189
+ const refreshToken = cachedTokens?.refreshToken || options.refreshToken;
190
+ cachedTokens = await refreshCognitoTokens(options, refreshToken);
191
+ if (options.tokenStorage) {
192
+ await options.tokenStorage.set(cachedTokens);
193
+ }
194
+ const retryReq = req.withHeader('Authorization', `Bearer ${cachedTokens.accessToken}`);
195
+ return next(retryReq);
196
+ }
197
+ catch {
198
+ return response;
199
+ }
200
+ }
201
+ return response;
202
+ };
203
+ }
204
+ export function cognitoPlugin(options) {
205
+ return (client) => {
206
+ client.use(cognito(options));
207
+ };
208
+ }
@@ -0,0 +1,8 @@
1
+ import { Middleware, Plugin } from '../../types/index.js';
2
+ export interface DigestAuthOptions {
3
+ username: string;
4
+ password: string;
5
+ preemptive?: boolean;
6
+ }
7
+ export declare function digestAuth(options: DigestAuthOptions): Middleware;
8
+ export declare function digestAuthPlugin(options: DigestAuthOptions): Plugin;