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,172 @@
1
+ import { createSign, createPrivateKey } from 'node:crypto';
2
+ function createServiceAccountJWT(credentials, scopes, subject) {
3
+ const now = Math.floor(Date.now() / 1000);
4
+ const header = {
5
+ alg: 'RS256',
6
+ typ: 'JWT',
7
+ kid: credentials.private_key_id,
8
+ };
9
+ const payload = {
10
+ iss: credentials.client_email,
11
+ aud: credentials.token_uri,
12
+ iat: now,
13
+ exp: now + 3600,
14
+ scope: scopes.join(' '),
15
+ };
16
+ if (subject) {
17
+ payload.sub = subject;
18
+ }
19
+ const encodedHeader = Buffer.from(JSON.stringify(header)).toString('base64url');
20
+ const encodedPayload = Buffer.from(JSON.stringify(payload)).toString('base64url');
21
+ const signatureInput = `${encodedHeader}.${encodedPayload}`;
22
+ const privateKey = createPrivateKey(credentials.private_key);
23
+ const sign = createSign('RSA-SHA256');
24
+ sign.update(signatureInput);
25
+ const signature = sign.sign(privateKey, 'base64url');
26
+ return `${signatureInput}.${signature}`;
27
+ }
28
+ async function exchangeJWTForAccessToken(credentials, jwt) {
29
+ const response = await fetch(credentials.token_uri, {
30
+ method: 'POST',
31
+ headers: {
32
+ 'Content-Type': 'application/x-www-form-urlencoded',
33
+ },
34
+ body: new URLSearchParams({
35
+ grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
36
+ assertion: jwt,
37
+ }).toString(),
38
+ });
39
+ if (!response.ok) {
40
+ const error = await response.json();
41
+ throw new Error(`Failed to get access token: ${error.error_description || error.error}`);
42
+ }
43
+ const data = await response.json();
44
+ return {
45
+ accessToken: data.access_token,
46
+ expiresAt: Date.now() + data.expires_in * 1000,
47
+ };
48
+ }
49
+ export async function getGoogleIdToken(credentials, targetAudience) {
50
+ const now = Math.floor(Date.now() / 1000);
51
+ const header = {
52
+ alg: 'RS256',
53
+ typ: 'JWT',
54
+ kid: credentials.private_key_id,
55
+ };
56
+ const payload = {
57
+ iss: credentials.client_email,
58
+ aud: credentials.token_uri,
59
+ iat: now,
60
+ exp: now + 3600,
61
+ target_audience: targetAudience,
62
+ };
63
+ const encodedHeader = Buffer.from(JSON.stringify(header)).toString('base64url');
64
+ const encodedPayload = Buffer.from(JSON.stringify(payload)).toString('base64url');
65
+ const signatureInput = `${encodedHeader}.${encodedPayload}`;
66
+ const privateKey = createPrivateKey(credentials.private_key);
67
+ const sign = createSign('RSA-SHA256');
68
+ sign.update(signatureInput);
69
+ const signature = sign.sign(privateKey, 'base64url');
70
+ const jwt = `${signatureInput}.${signature}`;
71
+ const response = await fetch(credentials.token_uri, {
72
+ method: 'POST',
73
+ headers: {
74
+ 'Content-Type': 'application/x-www-form-urlencoded',
75
+ },
76
+ body: new URLSearchParams({
77
+ grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
78
+ assertion: jwt,
79
+ }).toString(),
80
+ });
81
+ if (!response.ok) {
82
+ const error = await response.json();
83
+ throw new Error(`Failed to get ID token: ${error.error_description || error.error}`);
84
+ }
85
+ const data = await response.json();
86
+ return data.id_token;
87
+ }
88
+ async function loadCredentialsFromFile(keyFile) {
89
+ const fs = await import('node:fs/promises');
90
+ const content = await fs.readFile(keyFile, 'utf-8');
91
+ return JSON.parse(content);
92
+ }
93
+ export function googleServiceAccount(options) {
94
+ let cachedToken = null;
95
+ let credentialsLoaded = null;
96
+ const getCredentials = async () => {
97
+ if (credentialsLoaded) {
98
+ return credentialsLoaded;
99
+ }
100
+ if (options.credentials) {
101
+ credentialsLoaded = options.credentials;
102
+ return credentialsLoaded;
103
+ }
104
+ if (options.keyFile) {
105
+ credentialsLoaded = await loadCredentialsFromFile(options.keyFile);
106
+ return credentialsLoaded;
107
+ }
108
+ const adcPath = process.env.GOOGLE_APPLICATION_CREDENTIALS;
109
+ if (adcPath) {
110
+ credentialsLoaded = await loadCredentialsFromFile(adcPath);
111
+ return credentialsLoaded;
112
+ }
113
+ throw new Error('No credentials provided. Set credentials, keyFile, or GOOGLE_APPLICATION_CREDENTIALS environment variable.');
114
+ };
115
+ const getAccessToken = async () => {
116
+ if (options.accessToken) {
117
+ const token = typeof options.accessToken === 'function'
118
+ ? await options.accessToken()
119
+ : options.accessToken;
120
+ return token;
121
+ }
122
+ if (cachedToken && cachedToken.expiresAt > Date.now() + 60000) {
123
+ return cachedToken.accessToken;
124
+ }
125
+ const credentials = await getCredentials();
126
+ const jwt = createServiceAccountJWT(credentials, options.scopes, options.subject);
127
+ cachedToken = await exchangeJWTForAccessToken(credentials, jwt);
128
+ return cachedToken.accessToken;
129
+ };
130
+ return async (req, next) => {
131
+ const token = await getAccessToken();
132
+ const authReq = req.withHeader('Authorization', `Bearer ${token}`);
133
+ const response = await next(authReq);
134
+ if (response.status === 401) {
135
+ cachedToken = null;
136
+ const newToken = await getAccessToken();
137
+ const retryReq = req.withHeader('Authorization', `Bearer ${newToken}`);
138
+ return next(retryReq);
139
+ }
140
+ return response;
141
+ };
142
+ }
143
+ export function googleServiceAccountPlugin(options) {
144
+ return (client) => {
145
+ client.use(googleServiceAccount(options));
146
+ };
147
+ }
148
+ export const GoogleScopes = {
149
+ CLOUD_PLATFORM: 'https://www.googleapis.com/auth/cloud-platform',
150
+ CLOUD_PLATFORM_READ_ONLY: 'https://www.googleapis.com/auth/cloud-platform.read-only',
151
+ BIGQUERY: 'https://www.googleapis.com/auth/bigquery',
152
+ BIGQUERY_READ_ONLY: 'https://www.googleapis.com/auth/bigquery.readonly',
153
+ STORAGE_FULL: 'https://www.googleapis.com/auth/devstorage.full_control',
154
+ STORAGE_READ_WRITE: 'https://www.googleapis.com/auth/devstorage.read_write',
155
+ STORAGE_READ_ONLY: 'https://www.googleapis.com/auth/devstorage.read_only',
156
+ COMPUTE: 'https://www.googleapis.com/auth/compute',
157
+ COMPUTE_READ_ONLY: 'https://www.googleapis.com/auth/compute.readonly',
158
+ PUBSUB: 'https://www.googleapis.com/auth/pubsub',
159
+ DATASTORE: 'https://www.googleapis.com/auth/datastore',
160
+ FIRESTORE: 'https://www.googleapis.com/auth/datastore',
161
+ FIREBASE: 'https://www.googleapis.com/auth/firebase',
162
+ DRIVE: 'https://www.googleapis.com/auth/drive',
163
+ DRIVE_READ_ONLY: 'https://www.googleapis.com/auth/drive.readonly',
164
+ GMAIL_SEND: 'https://www.googleapis.com/auth/gmail.send',
165
+ GMAIL_READ_ONLY: 'https://www.googleapis.com/auth/gmail.readonly',
166
+ CALENDAR: 'https://www.googleapis.com/auth/calendar',
167
+ CALENDAR_READ_ONLY: 'https://www.googleapis.com/auth/calendar.readonly',
168
+ SHEETS: 'https://www.googleapis.com/auth/spreadsheets',
169
+ SHEETS_READ_ONLY: 'https://www.googleapis.com/auth/spreadsheets.readonly',
170
+ ADMIN_DIRECTORY_USER: 'https://www.googleapis.com/auth/admin.directory.user',
171
+ ADMIN_DIRECTORY_GROUP: 'https://www.googleapis.com/auth/admin.directory.group',
172
+ };
@@ -0,0 +1,15 @@
1
+ export { basicAuth, basicAuthPlugin, type BasicAuthOptions, } from './basic.js';
2
+ export { bearerAuth, bearerAuthPlugin, type BearerAuthOptions, } from './bearer.js';
3
+ export { apiKeyAuth, apiKeyAuthPlugin, type ApiKeyAuthOptions, } from './api-key.js';
4
+ export { digestAuth, digestAuthPlugin, type DigestAuthOptions, } from './digest.js';
5
+ export { oauth2, oauth2Plugin, type OAuth2Options, } from './oauth2.js';
6
+ export { awsSignatureV4, awsSignatureV4Plugin, type AWSSignatureV4Options, } from './aws-sigv4.js';
7
+ export { oidc, oidcPlugin, generatePKCE, generateAuthorizationUrl, fetchDiscoveryDocument, exchangeCode, refreshTokens, clientCredentialsFlow, type OIDCOptions, type OIDCTokens, type OIDCDiscoveryDocument, } from './oidc.js';
8
+ export { auth0, auth0Plugin, generateAuth0AuthUrl, exchangeAuth0Code, getAuth0UserInfo, type Auth0Options, } from './auth0.js';
9
+ export { cognito, cognitoPlugin, getCognitoIdentityCredentials, getCognitoHostedUIUrl, type CognitoOptions, type CognitoTokens, type CognitoAWSCredentials, } from './cognito.js';
10
+ export { okta, oktaPlugin, generateOktaAuthUrl, exchangeOktaCode, getOktaUserInfo, introspectOktaToken, revokeOktaToken, type OktaOptions, } from './okta.js';
11
+ export { azureAD, azureADPlugin, entraId, entraIdPlugin, generateAzureADAuthUrl, exchangeAzureADCode, azureADOnBehalfOf, getAzureADUserInfo, type AzureADOptions, } from './azure-ad.js';
12
+ export { firebase, firebasePlugin, createFirebaseCustomToken, verifyFirebaseIdToken, type FirebaseAuthOptions, type FirebaseServiceAccount, type FirebaseTokens, } from './firebase.js';
13
+ export { googleServiceAccount, googleServiceAccountPlugin, getGoogleIdToken, GoogleScopes, type GoogleServiceAccountOptions, type GoogleServiceAccountCredentials, } from './google-service-account.js';
14
+ export { githubApp, githubAppPlugin, createGitHubAppJWT, listGitHubAppInstallations, getGitHubAppInstallationForRepo, getGitHubAppInfo, type GitHubAppOptions, type GitHubInstallationToken, } from './github-app.js';
15
+ export { mtls, mtlsPlugin, createMTLSAgent, parseCertificateInfo, isCertificateValid, verifyCertificateFingerprint, type MTLSOptions, type MTLSCertificateInfo, } from './mtls.js';
@@ -0,0 +1,15 @@
1
+ export { basicAuth, basicAuthPlugin, } from './basic.js';
2
+ export { bearerAuth, bearerAuthPlugin, } from './bearer.js';
3
+ export { apiKeyAuth, apiKeyAuthPlugin, } from './api-key.js';
4
+ export { digestAuth, digestAuthPlugin, } from './digest.js';
5
+ export { oauth2, oauth2Plugin, } from './oauth2.js';
6
+ export { awsSignatureV4, awsSignatureV4Plugin, } from './aws-sigv4.js';
7
+ export { oidc, oidcPlugin, generatePKCE, generateAuthorizationUrl, fetchDiscoveryDocument, exchangeCode, refreshTokens, clientCredentialsFlow, } from './oidc.js';
8
+ export { auth0, auth0Plugin, generateAuth0AuthUrl, exchangeAuth0Code, getAuth0UserInfo, } from './auth0.js';
9
+ export { cognito, cognitoPlugin, getCognitoIdentityCredentials, getCognitoHostedUIUrl, } from './cognito.js';
10
+ export { okta, oktaPlugin, generateOktaAuthUrl, exchangeOktaCode, getOktaUserInfo, introspectOktaToken, revokeOktaToken, } from './okta.js';
11
+ export { azureAD, azureADPlugin, entraId, entraIdPlugin, generateAzureADAuthUrl, exchangeAzureADCode, azureADOnBehalfOf, getAzureADUserInfo, } from './azure-ad.js';
12
+ export { firebase, firebasePlugin, createFirebaseCustomToken, verifyFirebaseIdToken, } from './firebase.js';
13
+ export { googleServiceAccount, googleServiceAccountPlugin, getGoogleIdToken, GoogleScopes, } from './google-service-account.js';
14
+ export { githubApp, githubAppPlugin, createGitHubAppJWT, listGitHubAppInstallations, getGitHubAppInstallationForRepo, getGitHubAppInfo, } from './github-app.js';
15
+ export { mtls, mtlsPlugin, createMTLSAgent, parseCertificateInfo, isCertificateValid, verifyCertificateFingerprint, } from './mtls.js';
@@ -0,0 +1,37 @@
1
+ import { Middleware, Plugin } from '../../types/index.js';
2
+ import type { Dispatcher } from 'undici';
3
+ export interface MTLSOptions {
4
+ cert: string | Buffer;
5
+ key: string | Buffer;
6
+ ca?: string | Buffer | Array<string | Buffer>;
7
+ passphrase?: string;
8
+ certPath?: string;
9
+ keyPath?: string;
10
+ caPath?: string;
11
+ rejectUnauthorized?: boolean;
12
+ pfx?: string | Buffer;
13
+ pfxPassphrase?: string;
14
+ servername?: string;
15
+ minVersion?: 'TLSv1.2' | 'TLSv1.3';
16
+ maxVersion?: 'TLSv1.2' | 'TLSv1.3';
17
+ ciphers?: string;
18
+ ALPNProtocols?: string[];
19
+ }
20
+ export interface MTLSCertificateInfo {
21
+ subject: Record<string, string>;
22
+ issuer: Record<string, string>;
23
+ validFrom: Date;
24
+ validTo: Date;
25
+ fingerprint: string;
26
+ serialNumber: string;
27
+ }
28
+ export declare function parseCertificateInfo(cert: string | Buffer): MTLSCertificateInfo | null;
29
+ export declare function isCertificateValid(cert: string | Buffer, bufferDays?: number): {
30
+ valid: boolean;
31
+ expiresAt?: Date;
32
+ error?: string;
33
+ };
34
+ export declare function mtls(options: MTLSOptions): Middleware;
35
+ export declare function mtlsPlugin(options: MTLSOptions): Plugin;
36
+ export declare function createMTLSAgent(options: MTLSOptions): Promise<Dispatcher>;
37
+ export declare function verifyCertificateFingerprint(cert: string | Buffer, expectedFingerprint: string): boolean;
@@ -0,0 +1,140 @@
1
+ async function loadCertificateFile(path) {
2
+ const fs = await import('node:fs/promises');
3
+ return fs.readFile(path);
4
+ }
5
+ export function parseCertificateInfo(cert) {
6
+ try {
7
+ const crypto = require('node:crypto');
8
+ const x509 = new crypto.X509Certificate(cert);
9
+ return {
10
+ subject: parseX509Name(x509.subject),
11
+ issuer: parseX509Name(x509.issuer),
12
+ validFrom: new Date(x509.validFrom),
13
+ validTo: new Date(x509.validTo),
14
+ fingerprint: x509.fingerprint256,
15
+ serialNumber: x509.serialNumber,
16
+ };
17
+ }
18
+ catch {
19
+ return null;
20
+ }
21
+ }
22
+ function parseX509Name(name) {
23
+ const result = {};
24
+ const parts = name.split('\n');
25
+ for (const part of parts) {
26
+ const [key, value] = part.split('=');
27
+ if (key && value) {
28
+ result[key.trim()] = value.trim();
29
+ }
30
+ }
31
+ return result;
32
+ }
33
+ export function isCertificateValid(cert, bufferDays = 30) {
34
+ const info = parseCertificateInfo(cert);
35
+ if (!info) {
36
+ return { valid: false, error: 'Failed to parse certificate' };
37
+ }
38
+ const now = new Date();
39
+ const bufferMs = bufferDays * 24 * 60 * 60 * 1000;
40
+ if (now < info.validFrom) {
41
+ return { valid: false, expiresAt: info.validTo, error: 'Certificate not yet valid' };
42
+ }
43
+ if (now > info.validTo) {
44
+ return { valid: false, expiresAt: info.validTo, error: 'Certificate expired' };
45
+ }
46
+ if (now.getTime() + bufferMs > info.validTo.getTime()) {
47
+ return { valid: true, expiresAt: info.validTo, error: `Certificate expires soon (${info.validTo.toISOString()})` };
48
+ }
49
+ return { valid: true, expiresAt: info.validTo };
50
+ }
51
+ async function createTLSOptions(options) {
52
+ const tlsOptions = {};
53
+ if (options.certPath) {
54
+ tlsOptions.cert = await loadCertificateFile(options.certPath);
55
+ }
56
+ else if (options.cert) {
57
+ tlsOptions.cert = options.cert;
58
+ }
59
+ if (options.keyPath) {
60
+ tlsOptions.key = await loadCertificateFile(options.keyPath);
61
+ }
62
+ else if (options.key) {
63
+ tlsOptions.key = options.key;
64
+ }
65
+ if (options.caPath) {
66
+ tlsOptions.ca = await loadCertificateFile(options.caPath);
67
+ }
68
+ else if (options.ca) {
69
+ tlsOptions.ca = options.ca;
70
+ }
71
+ if (options.passphrase) {
72
+ tlsOptions.passphrase = options.passphrase;
73
+ }
74
+ if (options.pfx) {
75
+ tlsOptions.pfx = options.pfx;
76
+ if (options.pfxPassphrase) {
77
+ tlsOptions.passphrase = options.pfxPassphrase;
78
+ }
79
+ }
80
+ if (options.rejectUnauthorized !== undefined) {
81
+ tlsOptions.rejectUnauthorized = options.rejectUnauthorized;
82
+ }
83
+ if (options.servername) {
84
+ tlsOptions.servername = options.servername;
85
+ }
86
+ if (options.minVersion) {
87
+ tlsOptions.minVersion = options.minVersion;
88
+ }
89
+ if (options.maxVersion) {
90
+ tlsOptions.maxVersion = options.maxVersion;
91
+ }
92
+ if (options.ciphers) {
93
+ tlsOptions.ciphers = options.ciphers;
94
+ }
95
+ if (options.ALPNProtocols) {
96
+ tlsOptions.ALPNProtocols = options.ALPNProtocols;
97
+ }
98
+ return tlsOptions;
99
+ }
100
+ export function mtls(options) {
101
+ let validated = false;
102
+ return async (req, next) => {
103
+ if (!validated) {
104
+ if (options.cert || options.certPath) {
105
+ const cert = options.cert || (options.certPath ? await loadCertificateFile(options.certPath) : null);
106
+ if (cert) {
107
+ const validation = isCertificateValid(cert);
108
+ if (!validation.valid) {
109
+ throw new Error(`mTLS certificate error: ${validation.error}`);
110
+ }
111
+ }
112
+ }
113
+ validated = true;
114
+ }
115
+ return next(req);
116
+ };
117
+ }
118
+ export function mtlsPlugin(options) {
119
+ return (client) => {
120
+ client.use(mtls(options));
121
+ };
122
+ }
123
+ export async function createMTLSAgent(options) {
124
+ const { Agent } = await import('undici');
125
+ const tlsOptions = await createTLSOptions(options);
126
+ return new Agent({
127
+ connect: {
128
+ ...tlsOptions,
129
+ },
130
+ });
131
+ }
132
+ export function verifyCertificateFingerprint(cert, expectedFingerprint) {
133
+ const info = parseCertificateInfo(cert);
134
+ if (!info) {
135
+ return false;
136
+ }
137
+ const normalizedExpected = expectedFingerprint.replace(/:/g, '').toLowerCase();
138
+ const normalizedActual = info.fingerprint.replace(/:/g, '').toLowerCase();
139
+ return normalizedExpected === normalizedActual;
140
+ }
@@ -0,0 +1,8 @@
1
+ import { Middleware, Plugin } from '../../types/index.js';
2
+ export interface OAuth2Options {
3
+ accessToken: string | (() => string | Promise<string>);
4
+ tokenType?: string;
5
+ onTokenExpired?: () => Promise<string>;
6
+ }
7
+ export declare function oauth2(options: OAuth2Options): Middleware;
8
+ export declare function oauth2Plugin(options: OAuth2Options): Plugin;
@@ -0,0 +1,26 @@
1
+ export function oauth2(options) {
2
+ const tokenType = options.tokenType ?? 'Bearer';
3
+ return async (req, next) => {
4
+ const token = typeof options.accessToken === 'function'
5
+ ? await options.accessToken()
6
+ : options.accessToken;
7
+ const authReq = req.withHeader('Authorization', `${tokenType} ${token}`);
8
+ const response = await next(authReq);
9
+ if (response.status === 401 && options.onTokenExpired) {
10
+ try {
11
+ const newToken = await options.onTokenExpired();
12
+ const retryReq = req.withHeader('Authorization', `${tokenType} ${newToken}`);
13
+ return next(retryReq);
14
+ }
15
+ catch {
16
+ return response;
17
+ }
18
+ }
19
+ return response;
20
+ };
21
+ }
22
+ export function oauth2Plugin(options) {
23
+ return (client) => {
24
+ client.use(oauth2(options));
25
+ };
26
+ }
@@ -0,0 +1,55 @@
1
+ import { Middleware, Plugin } from '../../types/index.js';
2
+ export interface OIDCOptions {
3
+ issuer: string;
4
+ clientId: string;
5
+ clientSecret?: string;
6
+ redirectUri?: string;
7
+ scopes?: string[];
8
+ accessToken?: string | (() => string | Promise<string>);
9
+ refreshToken?: string;
10
+ tokenStorage?: {
11
+ get: () => Promise<OIDCTokens | null>;
12
+ set: (tokens: OIDCTokens) => Promise<void>;
13
+ };
14
+ audience?: string;
15
+ fetch?: typeof fetch;
16
+ }
17
+ export interface OIDCTokens {
18
+ accessToken: string;
19
+ refreshToken?: string;
20
+ idToken?: string;
21
+ expiresAt?: number;
22
+ tokenType?: string;
23
+ }
24
+ export interface OIDCDiscoveryDocument {
25
+ issuer: string;
26
+ authorization_endpoint: string;
27
+ token_endpoint: string;
28
+ userinfo_endpoint?: string;
29
+ jwks_uri: string;
30
+ revocation_endpoint?: string;
31
+ introspection_endpoint?: string;
32
+ end_session_endpoint?: string;
33
+ scopes_supported?: string[];
34
+ response_types_supported: string[];
35
+ grant_types_supported?: string[];
36
+ token_endpoint_auth_methods_supported?: string[];
37
+ }
38
+ declare function fetchDiscoveryDocument(issuer: string, customFetch?: typeof fetch): Promise<OIDCDiscoveryDocument>;
39
+ declare function exchangeCode(discovery: OIDCDiscoveryDocument, options: OIDCOptions, code: string, codeVerifier?: string, customFetch?: typeof fetch): Promise<OIDCTokens>;
40
+ declare function refreshTokens(discovery: OIDCDiscoveryDocument, options: OIDCOptions, refreshToken: string, customFetch?: typeof fetch): Promise<OIDCTokens>;
41
+ declare function clientCredentialsFlow(discovery: OIDCDiscoveryDocument, options: OIDCOptions, customFetch?: typeof fetch): Promise<OIDCTokens>;
42
+ export declare function generatePKCE(): {
43
+ codeVerifier: string;
44
+ codeChallenge: string;
45
+ };
46
+ export declare function generateAuthorizationUrl(options: OIDCOptions & {
47
+ state?: string;
48
+ nonce?: string;
49
+ pkce?: {
50
+ codeChallenge: string;
51
+ };
52
+ }): Promise<string>;
53
+ export declare function oidc(options: OIDCOptions): Middleware;
54
+ export declare function oidcPlugin(options: OIDCOptions): Plugin;
55
+ export { fetchDiscoveryDocument, exchangeCode, refreshTokens, clientCredentialsFlow };