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,195 @@
1
+ import { createSign, createPrivateKey } from 'node:crypto';
2
+ export function createFirebaseCustomToken(serviceAccount, uid, claims) {
3
+ const now = Math.floor(Date.now() / 1000);
4
+ const header = {
5
+ alg: 'RS256',
6
+ typ: 'JWT',
7
+ };
8
+ const payload = {
9
+ iss: serviceAccount.client_email,
10
+ sub: serviceAccount.client_email,
11
+ aud: 'https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit',
12
+ iat: now,
13
+ exp: now + 3600,
14
+ uid,
15
+ claims,
16
+ };
17
+ const encodedHeader = Buffer.from(JSON.stringify(header)).toString('base64url');
18
+ const encodedPayload = Buffer.from(JSON.stringify(payload)).toString('base64url');
19
+ const signatureInput = `${encodedHeader}.${encodedPayload}`;
20
+ const privateKey = createPrivateKey(serviceAccount.private_key);
21
+ const sign = createSign('RSA-SHA256');
22
+ sign.update(signatureInput);
23
+ const signature = sign.sign(privateKey, 'base64url');
24
+ return `${signatureInput}.${signature}`;
25
+ }
26
+ async function getServiceAccountAccessToken(serviceAccount, scopes = ['https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/firebase']) {
27
+ const now = Math.floor(Date.now() / 1000);
28
+ const header = {
29
+ alg: 'RS256',
30
+ typ: 'JWT',
31
+ };
32
+ const payload = {
33
+ iss: serviceAccount.client_email,
34
+ sub: serviceAccount.client_email,
35
+ aud: serviceAccount.token_uri,
36
+ iat: now,
37
+ exp: now + 3600,
38
+ scope: scopes.join(' '),
39
+ };
40
+ const encodedHeader = Buffer.from(JSON.stringify(header)).toString('base64url');
41
+ const encodedPayload = Buffer.from(JSON.stringify(payload)).toString('base64url');
42
+ const signatureInput = `${encodedHeader}.${encodedPayload}`;
43
+ const privateKey = createPrivateKey(serviceAccount.private_key);
44
+ const sign = createSign('RSA-SHA256');
45
+ sign.update(signatureInput);
46
+ const signature = sign.sign(privateKey, 'base64url');
47
+ const jwt = `${signatureInput}.${signature}`;
48
+ const response = await fetch(serviceAccount.token_uri, {
49
+ method: 'POST',
50
+ headers: {
51
+ 'Content-Type': 'application/x-www-form-urlencoded',
52
+ },
53
+ body: new URLSearchParams({
54
+ grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
55
+ assertion: jwt,
56
+ }).toString(),
57
+ });
58
+ if (!response.ok) {
59
+ const error = await response.text();
60
+ throw new Error(`Failed to get Firebase access token: ${error}`);
61
+ }
62
+ const data = await response.json();
63
+ return {
64
+ accessToken: data.access_token,
65
+ expiresAt: Date.now() + data.expires_in * 1000,
66
+ };
67
+ }
68
+ async function exchangeCustomTokenForIdToken(apiKey, customToken) {
69
+ const response = await fetch(`https://identitytoolkit.googleapis.com/v1/accounts:signInWithCustomToken?key=${apiKey}`, {
70
+ method: 'POST',
71
+ headers: {
72
+ 'Content-Type': 'application/json',
73
+ },
74
+ body: JSON.stringify({
75
+ token: customToken,
76
+ returnSecureToken: true,
77
+ }),
78
+ });
79
+ if (!response.ok) {
80
+ const error = await response.json();
81
+ throw new Error(`Failed to exchange custom token: ${error.error.message}`);
82
+ }
83
+ const data = await response.json();
84
+ return {
85
+ idToken: data.idToken,
86
+ refreshToken: data.refreshToken,
87
+ expiresAt: Date.now() + parseInt(data.expiresIn, 10) * 1000,
88
+ };
89
+ }
90
+ async function refreshFirebaseToken(apiKey, refreshToken) {
91
+ const response = await fetch(`https://securetoken.googleapis.com/v1/token?key=${apiKey}`, {
92
+ method: 'POST',
93
+ headers: {
94
+ 'Content-Type': 'application/x-www-form-urlencoded',
95
+ },
96
+ body: new URLSearchParams({
97
+ grant_type: 'refresh_token',
98
+ refresh_token: refreshToken,
99
+ }).toString(),
100
+ });
101
+ if (!response.ok) {
102
+ const error = await response.json();
103
+ throw new Error(`Failed to refresh token: ${error.error.message}`);
104
+ }
105
+ const data = await response.json();
106
+ return {
107
+ idToken: data.id_token,
108
+ refreshToken: data.refresh_token,
109
+ expiresAt: Date.now() + parseInt(data.expires_in, 10) * 1000,
110
+ };
111
+ }
112
+ export async function verifyFirebaseIdToken(projectId, idToken) {
113
+ const [, payloadB64] = idToken.split('.');
114
+ const payload = JSON.parse(Buffer.from(payloadB64, 'base64url').toString());
115
+ if (payload.iss !== `https://securetoken.google.com/${projectId}`) {
116
+ throw new Error('Invalid token issuer');
117
+ }
118
+ if (payload.aud !== projectId) {
119
+ throw new Error('Invalid token audience');
120
+ }
121
+ if (payload.exp < Date.now() / 1000) {
122
+ throw new Error('Token expired');
123
+ }
124
+ return payload;
125
+ }
126
+ export function firebase(options) {
127
+ let cachedTokens = null;
128
+ let serviceAccountToken = null;
129
+ const getToken = async () => {
130
+ if (options.tokenStorage) {
131
+ const stored = await options.tokenStorage.get();
132
+ if (stored) {
133
+ cachedTokens = stored;
134
+ }
135
+ }
136
+ if (cachedTokens && cachedTokens.expiresAt && cachedTokens.expiresAt > Date.now() + 60000) {
137
+ return cachedTokens.idToken;
138
+ }
139
+ if (cachedTokens?.refreshToken && options.apiKey) {
140
+ try {
141
+ cachedTokens = await refreshFirebaseToken(options.apiKey, cachedTokens.refreshToken);
142
+ if (options.tokenStorage) {
143
+ await options.tokenStorage.set(cachedTokens);
144
+ }
145
+ return cachedTokens.idToken;
146
+ }
147
+ catch {
148
+ }
149
+ }
150
+ if (options.idToken) {
151
+ const token = typeof options.idToken === 'function'
152
+ ? await options.idToken()
153
+ : options.idToken;
154
+ return token;
155
+ }
156
+ if (options.serviceAccount) {
157
+ if (!serviceAccountToken || serviceAccountToken.expiresAt < Date.now() + 60000) {
158
+ serviceAccountToken = await getServiceAccountAccessToken(options.serviceAccount);
159
+ }
160
+ return serviceAccountToken.accessToken;
161
+ }
162
+ if (options.customToken && options.apiKey) {
163
+ cachedTokens = await exchangeCustomTokenForIdToken(options.apiKey, options.customToken);
164
+ if (options.tokenStorage) {
165
+ await options.tokenStorage.set(cachedTokens);
166
+ }
167
+ return cachedTokens.idToken;
168
+ }
169
+ throw new Error('No valid authentication method. Provide idToken, serviceAccount, or customToken with apiKey.');
170
+ };
171
+ return async (req, next) => {
172
+ const token = await getToken();
173
+ const authReq = req.withHeader('Authorization', `Bearer ${token}`);
174
+ const response = await next(authReq);
175
+ if (response.status === 401 && cachedTokens?.refreshToken && options.apiKey) {
176
+ try {
177
+ cachedTokens = await refreshFirebaseToken(options.apiKey, cachedTokens.refreshToken);
178
+ if (options.tokenStorage) {
179
+ await options.tokenStorage.set(cachedTokens);
180
+ }
181
+ const retryReq = req.withHeader('Authorization', `Bearer ${cachedTokens.idToken}`);
182
+ return next(retryReq);
183
+ }
184
+ catch {
185
+ return response;
186
+ }
187
+ }
188
+ return response;
189
+ };
190
+ }
191
+ export function firebasePlugin(options) {
192
+ return (client) => {
193
+ client.use(firebase(options));
194
+ };
195
+ }
@@ -0,0 +1,36 @@
1
+ import { Middleware, Plugin } from '../../types/index.js';
2
+ export interface GitHubAppOptions {
3
+ appId: string | number;
4
+ privateKey: string;
5
+ installationId?: string | number;
6
+ permissions?: Record<string, 'read' | 'write'>;
7
+ repositoryIds?: number[];
8
+ repositories?: string[];
9
+ baseUrl?: string;
10
+ installationToken?: string | (() => string | Promise<string>);
11
+ tokenStorage?: {
12
+ get: () => Promise<GitHubInstallationToken | null>;
13
+ set: (token: GitHubInstallationToken) => Promise<void>;
14
+ };
15
+ }
16
+ export interface GitHubInstallationToken {
17
+ token: string;
18
+ expiresAt: number;
19
+ permissions?: Record<string, string>;
20
+ repositorySelection?: string;
21
+ }
22
+ declare function createGitHubAppJWT(appId: string | number, privateKey: string): string;
23
+ export declare function listGitHubAppInstallations(appId: string | number, privateKey: string, baseUrl?: string): Promise<Array<{
24
+ id: number;
25
+ account: {
26
+ login: string;
27
+ type: string;
28
+ };
29
+ repository_selection: string;
30
+ permissions: Record<string, string>;
31
+ }>>;
32
+ export declare function getGitHubAppInstallationForRepo(appId: string | number, privateKey: string, owner: string, repo: string, baseUrl?: string): Promise<number>;
33
+ export declare function getGitHubAppInfo(appId: string | number, privateKey: string, baseUrl?: string): Promise<Record<string, unknown>>;
34
+ export declare function githubApp(options: GitHubAppOptions): Middleware;
35
+ export declare function githubAppPlugin(options: GitHubAppOptions): Plugin;
36
+ export { createGitHubAppJWT };
@@ -0,0 +1,170 @@
1
+ import { createSign, createPrivateKey } from 'node:crypto';
2
+ function createGitHubAppJWT(appId, privateKey) {
3
+ const now = Math.floor(Date.now() / 1000);
4
+ const header = {
5
+ alg: 'RS256',
6
+ typ: 'JWT',
7
+ };
8
+ const payload = {
9
+ iat: now - 60,
10
+ exp: now + 600,
11
+ iss: appId.toString(),
12
+ };
13
+ const encodedHeader = Buffer.from(JSON.stringify(header)).toString('base64url');
14
+ const encodedPayload = Buffer.from(JSON.stringify(payload)).toString('base64url');
15
+ const signatureInput = `${encodedHeader}.${encodedPayload}`;
16
+ const key = createPrivateKey(privateKey);
17
+ const sign = createSign('RSA-SHA256');
18
+ sign.update(signatureInput);
19
+ const signature = sign.sign(key, 'base64url');
20
+ return `${signatureInput}.${signature}`;
21
+ }
22
+ async function getInstallationToken(jwt, installationId, options) {
23
+ const baseUrl = options.baseUrl || 'https://api.github.com';
24
+ const url = `${baseUrl}/app/installations/${installationId}/access_tokens`;
25
+ const body = {};
26
+ if (options.permissions) {
27
+ body.permissions = options.permissions;
28
+ }
29
+ if (options.repositoryIds) {
30
+ body.repository_ids = options.repositoryIds;
31
+ }
32
+ if (options.repositories) {
33
+ body.repositories = options.repositories;
34
+ }
35
+ const response = await fetch(url, {
36
+ method: 'POST',
37
+ headers: {
38
+ Authorization: `Bearer ${jwt}`,
39
+ Accept: 'application/vnd.github+json',
40
+ 'X-GitHub-Api-Version': '2022-11-28',
41
+ 'Content-Type': 'application/json',
42
+ },
43
+ body: Object.keys(body).length > 0 ? JSON.stringify(body) : undefined,
44
+ });
45
+ if (!response.ok) {
46
+ const error = await response.json();
47
+ throw new Error(`Failed to get installation token: ${error.message}`);
48
+ }
49
+ const data = await response.json();
50
+ return {
51
+ token: data.token,
52
+ expiresAt: new Date(data.expires_at).getTime(),
53
+ permissions: data.permissions,
54
+ repositorySelection: data.repository_selection,
55
+ };
56
+ }
57
+ export async function listGitHubAppInstallations(appId, privateKey, baseUrl) {
58
+ const jwt = createGitHubAppJWT(appId, privateKey);
59
+ const url = `${baseUrl || 'https://api.github.com'}/app/installations`;
60
+ const response = await fetch(url, {
61
+ headers: {
62
+ Authorization: `Bearer ${jwt}`,
63
+ Accept: 'application/vnd.github+json',
64
+ 'X-GitHub-Api-Version': '2022-11-28',
65
+ },
66
+ });
67
+ if (!response.ok) {
68
+ const error = await response.json();
69
+ throw new Error(`Failed to list installations: ${error.message}`);
70
+ }
71
+ return response.json();
72
+ }
73
+ export async function getGitHubAppInstallationForRepo(appId, privateKey, owner, repo, baseUrl) {
74
+ const jwt = createGitHubAppJWT(appId, privateKey);
75
+ const url = `${baseUrl || 'https://api.github.com'}/repos/${owner}/${repo}/installation`;
76
+ const response = await fetch(url, {
77
+ headers: {
78
+ Authorization: `Bearer ${jwt}`,
79
+ Accept: 'application/vnd.github+json',
80
+ 'X-GitHub-Api-Version': '2022-11-28',
81
+ },
82
+ });
83
+ if (!response.ok) {
84
+ const error = await response.json();
85
+ throw new Error(`Failed to get installation: ${error.message}`);
86
+ }
87
+ const data = await response.json();
88
+ return data.id;
89
+ }
90
+ export async function getGitHubAppInfo(appId, privateKey, baseUrl) {
91
+ const jwt = createGitHubAppJWT(appId, privateKey);
92
+ const url = `${baseUrl || 'https://api.github.com'}/app`;
93
+ const response = await fetch(url, {
94
+ headers: {
95
+ Authorization: `Bearer ${jwt}`,
96
+ Accept: 'application/vnd.github+json',
97
+ 'X-GitHub-Api-Version': '2022-11-28',
98
+ },
99
+ });
100
+ if (!response.ok) {
101
+ const error = await response.json();
102
+ throw new Error(`Failed to get app info: ${error.message}`);
103
+ }
104
+ return response.json();
105
+ }
106
+ export function githubApp(options) {
107
+ let cachedToken = null;
108
+ const getToken = async () => {
109
+ if (options.installationToken) {
110
+ const token = typeof options.installationToken === 'function'
111
+ ? await options.installationToken()
112
+ : options.installationToken;
113
+ return token;
114
+ }
115
+ if (options.tokenStorage) {
116
+ const stored = await options.tokenStorage.get();
117
+ if (stored) {
118
+ cachedToken = stored;
119
+ }
120
+ }
121
+ if (cachedToken && cachedToken.expiresAt > Date.now() + 300000) {
122
+ return cachedToken.token;
123
+ }
124
+ if (!options.installationId) {
125
+ throw new Error('Installation ID is required for GitHub App authentication');
126
+ }
127
+ const jwt = createGitHubAppJWT(options.appId, options.privateKey);
128
+ cachedToken = await getInstallationToken(jwt, options.installationId, {
129
+ baseUrl: options.baseUrl,
130
+ permissions: options.permissions,
131
+ repositoryIds: options.repositoryIds,
132
+ repositories: options.repositories,
133
+ });
134
+ if (options.tokenStorage) {
135
+ await options.tokenStorage.set(cachedToken);
136
+ }
137
+ return cachedToken.token;
138
+ };
139
+ return async (req, next) => {
140
+ const token = await getToken();
141
+ let authReq = req.withHeader('Authorization', `Bearer ${token}`);
142
+ authReq = authReq.withHeader('Accept', 'application/vnd.github+json');
143
+ authReq = authReq.withHeader('X-GitHub-Api-Version', '2022-11-28');
144
+ const response = await next(authReq);
145
+ if (response.status === 401 && options.installationId) {
146
+ cachedToken = null;
147
+ const jwt = createGitHubAppJWT(options.appId, options.privateKey);
148
+ cachedToken = await getInstallationToken(jwt, options.installationId, {
149
+ baseUrl: options.baseUrl,
150
+ permissions: options.permissions,
151
+ repositoryIds: options.repositoryIds,
152
+ repositories: options.repositories,
153
+ });
154
+ if (options.tokenStorage) {
155
+ await options.tokenStorage.set(cachedToken);
156
+ }
157
+ let retryReq = req.withHeader('Authorization', `Bearer ${cachedToken.token}`);
158
+ retryReq = retryReq.withHeader('Accept', 'application/vnd.github+json');
159
+ retryReq = retryReq.withHeader('X-GitHub-Api-Version', '2022-11-28');
160
+ return next(retryReq);
161
+ }
162
+ return response;
163
+ };
164
+ }
165
+ export function githubAppPlugin(options) {
166
+ return (client) => {
167
+ client.use(githubApp(options));
168
+ };
169
+ }
170
+ export { createGitHubAppJWT };
@@ -0,0 +1,49 @@
1
+ import { Middleware, Plugin } from '../../types/index.js';
2
+ export interface GoogleServiceAccountOptions {
3
+ credentials?: GoogleServiceAccountCredentials;
4
+ keyFile?: string;
5
+ scopes: string[];
6
+ subject?: string;
7
+ accessToken?: string | (() => string | Promise<string>);
8
+ }
9
+ export interface GoogleServiceAccountCredentials {
10
+ type: 'service_account';
11
+ project_id: string;
12
+ private_key_id: string;
13
+ private_key: string;
14
+ client_email: string;
15
+ client_id: string;
16
+ auth_uri: string;
17
+ token_uri: string;
18
+ auth_provider_x509_cert_url: string;
19
+ client_x509_cert_url: string;
20
+ universe_domain?: string;
21
+ }
22
+ export declare function getGoogleIdToken(credentials: GoogleServiceAccountCredentials, targetAudience: string): Promise<string>;
23
+ export declare function googleServiceAccount(options: GoogleServiceAccountOptions): Middleware;
24
+ export declare function googleServiceAccountPlugin(options: GoogleServiceAccountOptions): Plugin;
25
+ export declare const GoogleScopes: {
26
+ readonly CLOUD_PLATFORM: "https://www.googleapis.com/auth/cloud-platform";
27
+ readonly CLOUD_PLATFORM_READ_ONLY: "https://www.googleapis.com/auth/cloud-platform.read-only";
28
+ readonly BIGQUERY: "https://www.googleapis.com/auth/bigquery";
29
+ readonly BIGQUERY_READ_ONLY: "https://www.googleapis.com/auth/bigquery.readonly";
30
+ readonly STORAGE_FULL: "https://www.googleapis.com/auth/devstorage.full_control";
31
+ readonly STORAGE_READ_WRITE: "https://www.googleapis.com/auth/devstorage.read_write";
32
+ readonly STORAGE_READ_ONLY: "https://www.googleapis.com/auth/devstorage.read_only";
33
+ readonly COMPUTE: "https://www.googleapis.com/auth/compute";
34
+ readonly COMPUTE_READ_ONLY: "https://www.googleapis.com/auth/compute.readonly";
35
+ readonly PUBSUB: "https://www.googleapis.com/auth/pubsub";
36
+ readonly DATASTORE: "https://www.googleapis.com/auth/datastore";
37
+ readonly FIRESTORE: "https://www.googleapis.com/auth/datastore";
38
+ readonly FIREBASE: "https://www.googleapis.com/auth/firebase";
39
+ readonly DRIVE: "https://www.googleapis.com/auth/drive";
40
+ readonly DRIVE_READ_ONLY: "https://www.googleapis.com/auth/drive.readonly";
41
+ readonly GMAIL_SEND: "https://www.googleapis.com/auth/gmail.send";
42
+ readonly GMAIL_READ_ONLY: "https://www.googleapis.com/auth/gmail.readonly";
43
+ readonly CALENDAR: "https://www.googleapis.com/auth/calendar";
44
+ readonly CALENDAR_READ_ONLY: "https://www.googleapis.com/auth/calendar.readonly";
45
+ readonly SHEETS: "https://www.googleapis.com/auth/spreadsheets";
46
+ readonly SHEETS_READ_ONLY: "https://www.googleapis.com/auth/spreadsheets.readonly";
47
+ readonly ADMIN_DIRECTORY_USER: "https://www.googleapis.com/auth/admin.directory.user";
48
+ readonly ADMIN_DIRECTORY_GROUP: "https://www.googleapis.com/auth/admin.directory.group";
49
+ };
@@ -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';