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.
- package/README.md +31 -0
- package/dist/ai/adaptive-timeout.d.ts +0 -1
- package/dist/ai/client.d.ts +0 -1
- package/dist/ai/client.js +6 -0
- package/dist/ai/index.d.ts +3 -1
- package/dist/ai/index.js +3 -0
- package/dist/ai/providers/anthropic.d.ts +0 -1
- package/dist/ai/providers/base.d.ts +0 -1
- package/dist/ai/providers/google.d.ts +59 -0
- package/dist/ai/providers/google.js +305 -0
- package/dist/ai/providers/index.d.ts +4 -1
- package/dist/ai/providers/index.js +2 -0
- package/dist/ai/providers/ollama.d.ts +44 -0
- package/dist/ai/providers/ollama.js +240 -0
- package/dist/ai/providers/openai.d.ts +0 -1
- package/dist/ai/rate-limiter.d.ts +0 -1
- package/dist/ai/vector/index.d.ts +2 -0
- package/dist/ai/vector/index.js +2 -0
- package/dist/ai/vector/similarity.d.ts +2 -0
- package/dist/ai/vector/similarity.js +27 -0
- package/dist/ai/vector/store.d.ts +27 -0
- package/dist/ai/vector/store.js +82 -0
- package/dist/bench/generator.d.ts +0 -1
- package/dist/bench/stats.d.ts +0 -1
- package/dist/cache/basic-file-storage.d.ts +12 -0
- package/dist/cache/basic-file-storage.js +50 -0
- package/dist/cache/file-storage.d.ts +25 -11
- package/dist/cache/file-storage.js +175 -30
- package/dist/cache/memory-limits.d.ts +0 -1
- package/dist/cache/memory-storage.d.ts +0 -1
- package/dist/cache/redis-storage.d.ts +0 -1
- package/dist/cli/handler.d.ts +2 -1
- package/dist/cli/handler.js +36 -5
- package/dist/cli/index.d.ts +0 -2
- package/dist/cli/index.js +559 -6
- package/dist/cli/presets.d.ts +0 -1
- package/dist/cli/tui/ai-chat.d.ts +0 -1
- package/dist/cli/tui/load-dashboard.d.ts +0 -1
- package/dist/cli/tui/scroll-buffer.d.ts +0 -1
- package/dist/cli/tui/search-panel.d.ts +0 -1
- package/dist/cli/tui/shell-search.d.ts +0 -1
- package/dist/cli/tui/shell.d.ts +0 -1
- package/dist/cli/tui/shell.js +1 -1
- package/dist/cli/tui/websocket.d.ts +0 -1
- package/dist/constants/http-status.d.ts +0 -1
- package/dist/constants.d.ts +0 -1
- package/dist/contract/index.d.ts +0 -1
- package/dist/cookies/memory-cookie-jar.d.ts +0 -1
- package/dist/core/client.d.ts +0 -1
- package/dist/core/client.js +1 -1
- package/dist/core/errors.d.ts +0 -1
- package/dist/core/index.d.ts +0 -1
- package/dist/core/request-promise.d.ts +0 -1
- package/dist/core/request.d.ts +0 -1
- package/dist/core/response.d.ts +0 -1
- package/dist/dns/index.d.ts +0 -1
- package/dist/dns/propagation.d.ts +0 -1
- package/dist/events/request-events.d.ts +0 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -0
- package/dist/mcp/client.d.ts +0 -1
- package/dist/mcp/contract.d.ts +0 -1
- package/dist/mcp/embeddings-loader.d.ts +0 -1
- package/dist/mcp/geoip-loader.d.ts +0 -1
- package/dist/mcp/index.d.ts +0 -1
- package/dist/mcp/ip-intel.d.ts +0 -1
- package/dist/mcp/search/hybrid-search.d.ts +0 -1
- package/dist/mcp/search/index.d.ts +0 -1
- package/dist/mcp/search/math.d.ts +0 -1
- package/dist/mcp/search/types.d.ts +0 -1
- package/dist/mcp/server.d.ts +6 -2
- package/dist/mcp/server.js +193 -151
- package/dist/mcp/tools/loader.d.ts +2 -0
- package/dist/mcp/tools/loader.js +41 -0
- package/dist/mcp/tools/network.d.ts +3 -0
- package/dist/mcp/tools/network.js +267 -0
- package/dist/mcp/tools/registry.d.ts +17 -0
- package/dist/mcp/tools/registry.js +37 -0
- package/dist/mcp/types.d.ts +0 -1
- package/dist/plugins/auth/api-key.d.ts +8 -0
- package/dist/plugins/auth/api-key.js +27 -0
- package/dist/plugins/auth/auth0.d.ts +33 -0
- package/dist/plugins/auth/auth0.js +94 -0
- package/dist/plugins/auth/aws-sigv4.d.ts +10 -0
- package/dist/plugins/auth/aws-sigv4.js +88 -0
- package/dist/plugins/auth/azure-ad.d.ts +48 -0
- package/dist/plugins/auth/azure-ad.js +152 -0
- package/dist/plugins/auth/basic.d.ts +7 -0
- package/dist/plugins/auth/basic.js +13 -0
- package/dist/plugins/auth/bearer.d.ts +8 -0
- package/dist/plugins/auth/bearer.js +17 -0
- package/dist/plugins/auth/cognito.d.ts +45 -0
- package/dist/plugins/auth/cognito.js +208 -0
- package/dist/plugins/auth/digest.d.ts +8 -0
- package/dist/plugins/auth/digest.js +100 -0
- package/dist/plugins/auth/firebase.d.ts +32 -0
- package/dist/plugins/auth/firebase.js +195 -0
- package/dist/plugins/auth/github-app.d.ts +36 -0
- package/dist/plugins/auth/github-app.js +170 -0
- package/dist/plugins/auth/google-service-account.d.ts +49 -0
- package/dist/plugins/auth/google-service-account.js +172 -0
- package/dist/plugins/auth/index.d.ts +15 -0
- package/dist/plugins/auth/index.js +15 -0
- package/dist/plugins/auth/mtls.d.ts +37 -0
- package/dist/plugins/auth/mtls.js +140 -0
- package/dist/plugins/auth/oauth2.d.ts +8 -0
- package/dist/plugins/auth/oauth2.js +26 -0
- package/dist/plugins/auth/oidc.d.ts +55 -0
- package/dist/plugins/auth/oidc.js +222 -0
- package/dist/plugins/auth/okta.d.ts +47 -0
- package/dist/plugins/auth/okta.js +157 -0
- package/dist/plugins/auth.d.ts +1 -45
- package/dist/plugins/auth.js +1 -268
- package/dist/plugins/cache.d.ts +0 -1
- package/dist/plugins/cache.js +1 -1
- package/dist/plugins/certificate-pinning.d.ts +59 -0
- package/dist/plugins/certificate-pinning.js +236 -0
- package/dist/plugins/circuit-breaker.d.ts +0 -1
- package/dist/plugins/compression.d.ts +0 -1
- package/dist/plugins/cookie-jar.d.ts +0 -1
- package/dist/plugins/dedup.d.ts +0 -1
- package/dist/plugins/graphql.d.ts +0 -1
- package/dist/plugins/grpc-web.d.ts +0 -1
- package/dist/plugins/har-player.d.ts +0 -1
- package/dist/plugins/har-recorder.d.ts +0 -1
- package/dist/plugins/hls.d.ts +0 -1
- package/dist/plugins/http2-push.d.ts +0 -1
- package/dist/plugins/http3.d.ts +0 -1
- package/dist/plugins/index.d.ts +27 -0
- package/dist/plugins/index.js +27 -0
- package/dist/plugins/interface-rotator.d.ts +0 -1
- package/dist/plugins/jsonrpc.d.ts +0 -1
- package/dist/plugins/logger.d.ts +0 -1
- package/dist/plugins/odata.d.ts +0 -1
- package/dist/plugins/pagination.d.ts +0 -1
- package/dist/plugins/proxy-rotator.d.ts +0 -1
- package/dist/plugins/rate-limit.d.ts +15 -0
- package/dist/plugins/rate-limit.js +162 -0
- package/dist/plugins/retry.d.ts +0 -1
- package/dist/plugins/retry.js +2 -2
- package/dist/plugins/scrape.d.ts +0 -1
- package/dist/plugins/server-timing.d.ts +0 -1
- package/dist/plugins/soap.d.ts +0 -1
- package/dist/plugins/user-agent.d.ts +0 -1
- package/dist/plugins/xml.d.ts +0 -1
- package/dist/plugins/xsrf.d.ts +0 -1
- package/dist/presets/anthropic.d.ts +0 -1
- package/dist/presets/aws.d.ts +0 -1
- package/dist/presets/azure-openai.d.ts +0 -1
- package/dist/presets/azure.d.ts +0 -1
- package/dist/presets/cloudflare.d.ts +0 -1
- package/dist/presets/cohere.d.ts +0 -1
- package/dist/presets/deepseek.d.ts +0 -1
- package/dist/presets/digitalocean.d.ts +0 -1
- package/dist/presets/discord.d.ts +0 -1
- package/dist/presets/fireworks.d.ts +0 -1
- package/dist/presets/gcp.d.ts +0 -1
- package/dist/presets/gemini.d.ts +0 -1
- package/dist/presets/github.d.ts +0 -1
- package/dist/presets/gitlab.d.ts +0 -1
- package/dist/presets/groq.d.ts +0 -1
- package/dist/presets/huggingface.d.ts +0 -1
- package/dist/presets/index.d.ts +0 -1
- package/dist/presets/linear.d.ts +0 -1
- package/dist/presets/mailgun.d.ts +0 -1
- package/dist/presets/meta.d.ts +0 -1
- package/dist/presets/mistral.d.ts +0 -1
- package/dist/presets/notion.d.ts +0 -1
- package/dist/presets/openai.d.ts +0 -1
- package/dist/presets/oracle.d.ts +0 -1
- package/dist/presets/perplexity.d.ts +0 -1
- package/dist/presets/registry.d.ts +0 -1
- package/dist/presets/replicate.d.ts +0 -1
- package/dist/presets/sinch.d.ts +0 -1
- package/dist/presets/slack.d.ts +0 -1
- package/dist/presets/stripe.d.ts +0 -1
- package/dist/presets/supabase.d.ts +0 -1
- package/dist/presets/tiktok.d.ts +0 -1
- package/dist/presets/together.d.ts +0 -1
- package/dist/presets/twilio.d.ts +0 -1
- package/dist/presets/vercel.d.ts +0 -1
- package/dist/presets/vultr.d.ts +0 -1
- package/dist/presets/xai.d.ts +0 -1
- package/dist/presets/youtube.d.ts +0 -1
- package/dist/protocols/ftp.d.ts +0 -1
- package/dist/protocols/index.d.ts +0 -1
- package/dist/protocols/sftp.d.ts +0 -1
- package/dist/protocols/telnet.d.ts +0 -1
- package/dist/recker.d.ts +0 -1
- package/dist/runner/request-runner.d.ts +0 -1
- package/dist/scrape/document.d.ts +0 -1
- package/dist/scrape/element.d.ts +0 -1
- package/dist/scrape/extractors.d.ts +0 -1
- package/dist/scrape/index.d.ts +0 -1
- package/dist/scrape/types.d.ts +0 -1
- package/dist/testing/index.d.ts +16 -1
- package/dist/testing/index.js +8 -0
- package/dist/testing/mock-dns-server.d.ts +69 -0
- package/dist/testing/mock-dns-server.js +269 -0
- package/dist/testing/mock-ftp-server.d.ts +89 -0
- package/dist/testing/mock-ftp-server.js +562 -0
- package/dist/testing/mock-hls-server.d.ts +80 -0
- package/dist/testing/mock-hls-server.js +381 -0
- package/dist/testing/mock-http-server.d.ts +99 -0
- package/dist/testing/mock-http-server.js +298 -0
- package/dist/testing/mock-sse-server.d.ts +76 -0
- package/dist/testing/mock-sse-server.js +291 -0
- package/dist/testing/mock-telnet-server.d.ts +59 -0
- package/dist/testing/mock-telnet-server.js +273 -0
- package/dist/testing/mock-udp-server.d.ts +0 -1
- package/dist/testing/mock-websocket-server.d.ts +77 -0
- package/dist/testing/mock-websocket-server.js +316 -0
- package/dist/testing/mock-whois-server.d.ts +56 -0
- package/dist/testing/mock-whois-server.js +234 -0
- package/dist/testing/mock.d.ts +0 -1
- package/dist/transport/base-udp.d.ts +0 -1
- package/dist/transport/fetch.d.ts +0 -1
- package/dist/transport/udp-response.d.ts +0 -1
- package/dist/transport/udp.d.ts +0 -1
- package/dist/transport/undici.d.ts +0 -1
- package/dist/transport/undici.js +1 -1
- package/dist/types/ai.d.ts +0 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/logger.d.ts +0 -1
- package/dist/types/udp.d.ts +0 -1
- package/dist/udp/index.d.ts +0 -1
- package/dist/utils/agent-manager.d.ts +0 -1
- package/dist/utils/body.d.ts +0 -1
- package/dist/utils/cert.d.ts +0 -1
- package/dist/utils/charset.d.ts +0 -1
- package/dist/utils/chart.d.ts +0 -1
- package/dist/utils/client-pool.d.ts +0 -1
- package/dist/utils/colors.d.ts +0 -1
- package/dist/utils/concurrency.d.ts +0 -1
- package/dist/utils/dns-toolkit.d.ts +0 -1
- package/dist/utils/dns-toolkit.js +1 -1
- package/dist/utils/dns.d.ts +0 -1
- package/dist/utils/dns.js +2 -2
- package/dist/utils/doh.d.ts +0 -1
- package/dist/utils/download.d.ts +0 -1
- package/dist/utils/env-proxy.d.ts +0 -1
- package/dist/utils/header-parser.d.ts +0 -1
- package/dist/utils/html-cleaner.d.ts +0 -1
- package/dist/utils/link-header.d.ts +0 -1
- package/dist/utils/optional-require.d.ts +0 -1
- package/dist/utils/optional-require.js +1 -1
- package/dist/utils/progress.d.ts +0 -1
- package/dist/utils/rdap.d.ts +0 -1
- package/dist/utils/request-pool.d.ts +0 -1
- package/dist/utils/security-grader.d.ts +0 -1
- package/dist/utils/sparkline.d.ts +0 -1
- package/dist/utils/sse.d.ts +0 -1
- package/dist/utils/streaming.d.ts +0 -1
- package/dist/utils/system-metrics.d.ts +0 -1
- package/dist/utils/tls-inspector.d.ts +0 -1
- package/dist/utils/try-fn.d.ts +0 -1
- package/dist/utils/upload.d.ts +0 -1
- package/dist/utils/user-agent.d.ts +0 -1
- package/dist/utils/whois.d.ts +0 -1
- package/dist/webrtc/index.d.ts +0 -1
- package/dist/webrtc/index.js +1 -1
- package/dist/websocket/client.d.ts +0 -1
- package/package.json +12 -3
- package/dist/ai/adaptive-timeout.d.ts.map +0 -1
- package/dist/ai/client.d.ts.map +0 -1
- package/dist/ai/index.d.ts.map +0 -1
- package/dist/ai/providers/anthropic.d.ts.map +0 -1
- package/dist/ai/providers/base.d.ts.map +0 -1
- package/dist/ai/providers/index.d.ts.map +0 -1
- package/dist/ai/providers/openai.d.ts.map +0 -1
- package/dist/ai/rate-limiter.d.ts.map +0 -1
- package/dist/bench/generator.d.ts.map +0 -1
- package/dist/bench/stats.d.ts.map +0 -1
- package/dist/cache/file-storage.d.ts.map +0 -1
- package/dist/cache/memory-limits.d.ts.map +0 -1
- package/dist/cache/memory-storage.d.ts.map +0 -1
- package/dist/cache/redis-storage.d.ts.map +0 -1
- package/dist/cli/handler.d.ts.map +0 -1
- package/dist/cli/index.d.ts.map +0 -1
- package/dist/cli/presets.d.ts.map +0 -1
- package/dist/cli/tui/ai-chat.d.ts.map +0 -1
- package/dist/cli/tui/load-dashboard.d.ts.map +0 -1
- package/dist/cli/tui/scroll-buffer.d.ts.map +0 -1
- package/dist/cli/tui/search-panel.d.ts.map +0 -1
- package/dist/cli/tui/shell-search.d.ts.map +0 -1
- package/dist/cli/tui/shell.d.ts.map +0 -1
- package/dist/cli/tui/websocket.d.ts.map +0 -1
- package/dist/constants/http-status.d.ts.map +0 -1
- package/dist/constants.d.ts.map +0 -1
- package/dist/contract/index.d.ts.map +0 -1
- package/dist/cookies/memory-cookie-jar.d.ts.map +0 -1
- package/dist/core/client.d.ts.map +0 -1
- package/dist/core/errors.d.ts.map +0 -1
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/request-promise.d.ts.map +0 -1
- package/dist/core/request.d.ts.map +0 -1
- package/dist/core/response.d.ts.map +0 -1
- package/dist/dns/index.d.ts.map +0 -1
- package/dist/dns/propagation.d.ts.map +0 -1
- package/dist/events/request-events.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/mcp/client.d.ts.map +0 -1
- package/dist/mcp/contract.d.ts.map +0 -1
- package/dist/mcp/embeddings-loader.d.ts.map +0 -1
- package/dist/mcp/geoip-loader.d.ts.map +0 -1
- package/dist/mcp/index.d.ts.map +0 -1
- package/dist/mcp/ip-intel.d.ts.map +0 -1
- package/dist/mcp/search/hybrid-search.d.ts.map +0 -1
- package/dist/mcp/search/index.d.ts.map +0 -1
- package/dist/mcp/search/math.d.ts.map +0 -1
- package/dist/mcp/search/types.d.ts.map +0 -1
- package/dist/mcp/server.d.ts.map +0 -1
- package/dist/mcp/types.d.ts.map +0 -1
- package/dist/plugins/auth.d.ts.map +0 -1
- package/dist/plugins/cache.d.ts.map +0 -1
- package/dist/plugins/circuit-breaker.d.ts.map +0 -1
- package/dist/plugins/compression.d.ts.map +0 -1
- package/dist/plugins/cookie-jar.d.ts.map +0 -1
- package/dist/plugins/dedup.d.ts.map +0 -1
- package/dist/plugins/graphql.d.ts.map +0 -1
- package/dist/plugins/grpc-web.d.ts.map +0 -1
- package/dist/plugins/har-player.d.ts.map +0 -1
- package/dist/plugins/har-recorder.d.ts.map +0 -1
- package/dist/plugins/hls.d.ts.map +0 -1
- package/dist/plugins/http2-push.d.ts.map +0 -1
- package/dist/plugins/http3.d.ts.map +0 -1
- package/dist/plugins/interface-rotator.d.ts.map +0 -1
- package/dist/plugins/jsonrpc.d.ts.map +0 -1
- package/dist/plugins/logger.d.ts.map +0 -1
- package/dist/plugins/odata.d.ts.map +0 -1
- package/dist/plugins/pagination.d.ts.map +0 -1
- package/dist/plugins/proxy-rotator.d.ts.map +0 -1
- package/dist/plugins/retry.d.ts.map +0 -1
- package/dist/plugins/scrape.d.ts.map +0 -1
- package/dist/plugins/server-timing.d.ts.map +0 -1
- package/dist/plugins/soap.d.ts.map +0 -1
- package/dist/plugins/user-agent.d.ts.map +0 -1
- package/dist/plugins/xml.d.ts.map +0 -1
- package/dist/plugins/xsrf.d.ts.map +0 -1
- package/dist/presets/anthropic.d.ts.map +0 -1
- package/dist/presets/aws.d.ts.map +0 -1
- package/dist/presets/azure-openai.d.ts.map +0 -1
- package/dist/presets/azure.d.ts.map +0 -1
- package/dist/presets/cloudflare.d.ts.map +0 -1
- package/dist/presets/cohere.d.ts.map +0 -1
- package/dist/presets/deepseek.d.ts.map +0 -1
- package/dist/presets/digitalocean.d.ts.map +0 -1
- package/dist/presets/discord.d.ts.map +0 -1
- package/dist/presets/fireworks.d.ts.map +0 -1
- package/dist/presets/gcp.d.ts.map +0 -1
- package/dist/presets/gemini.d.ts.map +0 -1
- package/dist/presets/github.d.ts.map +0 -1
- package/dist/presets/gitlab.d.ts.map +0 -1
- package/dist/presets/groq.d.ts.map +0 -1
- package/dist/presets/huggingface.d.ts.map +0 -1
- package/dist/presets/index.d.ts.map +0 -1
- package/dist/presets/linear.d.ts.map +0 -1
- package/dist/presets/mailgun.d.ts.map +0 -1
- package/dist/presets/meta.d.ts.map +0 -1
- package/dist/presets/mistral.d.ts.map +0 -1
- package/dist/presets/notion.d.ts.map +0 -1
- package/dist/presets/openai.d.ts.map +0 -1
- package/dist/presets/oracle.d.ts.map +0 -1
- package/dist/presets/perplexity.d.ts.map +0 -1
- package/dist/presets/registry.d.ts.map +0 -1
- package/dist/presets/replicate.d.ts.map +0 -1
- package/dist/presets/sinch.d.ts.map +0 -1
- package/dist/presets/slack.d.ts.map +0 -1
- package/dist/presets/stripe.d.ts.map +0 -1
- package/dist/presets/supabase.d.ts.map +0 -1
- package/dist/presets/tiktok.d.ts.map +0 -1
- package/dist/presets/together.d.ts.map +0 -1
- package/dist/presets/twilio.d.ts.map +0 -1
- package/dist/presets/vercel.d.ts.map +0 -1
- package/dist/presets/vultr.d.ts.map +0 -1
- package/dist/presets/xai.d.ts.map +0 -1
- package/dist/presets/youtube.d.ts.map +0 -1
- package/dist/protocols/ftp.d.ts.map +0 -1
- package/dist/protocols/index.d.ts.map +0 -1
- package/dist/protocols/sftp.d.ts.map +0 -1
- package/dist/protocols/telnet.d.ts.map +0 -1
- package/dist/recker.d.ts.map +0 -1
- package/dist/runner/request-runner.d.ts.map +0 -1
- package/dist/scrape/document.d.ts.map +0 -1
- package/dist/scrape/element.d.ts.map +0 -1
- package/dist/scrape/extractors.d.ts.map +0 -1
- package/dist/scrape/index.d.ts.map +0 -1
- package/dist/scrape/types.d.ts.map +0 -1
- package/dist/testing/index.d.ts.map +0 -1
- package/dist/testing/mock-udp-server.d.ts.map +0 -1
- package/dist/testing/mock.d.ts.map +0 -1
- package/dist/transport/base-udp.d.ts.map +0 -1
- package/dist/transport/fetch.d.ts.map +0 -1
- package/dist/transport/udp-response.d.ts.map +0 -1
- package/dist/transport/udp.d.ts.map +0 -1
- package/dist/transport/undici.d.ts.map +0 -1
- package/dist/types/ai.d.ts.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/logger.d.ts.map +0 -1
- package/dist/types/udp.d.ts.map +0 -1
- package/dist/udp/index.d.ts.map +0 -1
- package/dist/utils/agent-manager.d.ts.map +0 -1
- package/dist/utils/body.d.ts.map +0 -1
- package/dist/utils/cert.d.ts.map +0 -1
- package/dist/utils/charset.d.ts.map +0 -1
- package/dist/utils/chart.d.ts.map +0 -1
- package/dist/utils/client-pool.d.ts.map +0 -1
- package/dist/utils/colors.d.ts.map +0 -1
- package/dist/utils/concurrency.d.ts.map +0 -1
- package/dist/utils/dns-toolkit.d.ts.map +0 -1
- package/dist/utils/dns.d.ts.map +0 -1
- package/dist/utils/doh.d.ts.map +0 -1
- package/dist/utils/download.d.ts.map +0 -1
- package/dist/utils/env-proxy.d.ts.map +0 -1
- package/dist/utils/header-parser.d.ts.map +0 -1
- package/dist/utils/html-cleaner.d.ts.map +0 -1
- package/dist/utils/link-header.d.ts.map +0 -1
- package/dist/utils/optional-require.d.ts.map +0 -1
- package/dist/utils/progress.d.ts.map +0 -1
- package/dist/utils/rdap.d.ts.map +0 -1
- package/dist/utils/request-pool.d.ts.map +0 -1
- package/dist/utils/security-grader.d.ts.map +0 -1
- package/dist/utils/sparkline.d.ts.map +0 -1
- package/dist/utils/sse.d.ts.map +0 -1
- package/dist/utils/streaming.d.ts.map +0 -1
- package/dist/utils/system-metrics.d.ts.map +0 -1
- package/dist/utils/tls-inspector.d.ts.map +0 -1
- package/dist/utils/try-fn.d.ts.map +0 -1
- package/dist/utils/upload.d.ts.map +0 -1
- package/dist/utils/user-agent.d.ts.map +0 -1
- package/dist/utils/whois.d.ts.map +0 -1
- package/dist/webrtc/index.d.ts.map +0 -1
- package/dist/websocket/client.d.ts.map +0 -1
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { oidc, generatePKCE } from './oidc.js';
|
|
2
|
+
function getAzureADIssuer(options) {
|
|
3
|
+
if (options.b2c) {
|
|
4
|
+
return `https://${options.b2c.tenantName}.b2clogin.com/${options.b2c.tenantName}.onmicrosoft.com/${options.b2c.policy}/v2.0`;
|
|
5
|
+
}
|
|
6
|
+
const cloudInstance = options.cloudInstance || 'https://login.microsoftonline.com';
|
|
7
|
+
return `${cloudInstance}/${options.tenantId}/v2.0`;
|
|
8
|
+
}
|
|
9
|
+
function getAzureADTokenEndpoint(options) {
|
|
10
|
+
if (options.b2c) {
|
|
11
|
+
return `https://${options.b2c.tenantName}.b2clogin.com/${options.b2c.tenantName}.onmicrosoft.com/${options.b2c.policy}/oauth2/v2.0/token`;
|
|
12
|
+
}
|
|
13
|
+
const cloudInstance = options.cloudInstance || 'https://login.microsoftonline.com';
|
|
14
|
+
return `${cloudInstance}/${options.tenantId}/oauth2/v2.0/token`;
|
|
15
|
+
}
|
|
16
|
+
export async function generateAzureADAuthUrl(options) {
|
|
17
|
+
const pkce = options.usePKCE ? generatePKCE() : undefined;
|
|
18
|
+
let authorizeUrl;
|
|
19
|
+
if (options.b2c) {
|
|
20
|
+
authorizeUrl = `https://${options.b2c.tenantName}.b2clogin.com/${options.b2c.tenantName}.onmicrosoft.com/${options.b2c.policy}/oauth2/v2.0/authorize`;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
const cloudInstance = options.cloudInstance || 'https://login.microsoftonline.com';
|
|
24
|
+
authorizeUrl = `${cloudInstance}/${options.tenantId}/oauth2/v2.0/authorize`;
|
|
25
|
+
}
|
|
26
|
+
const params = new URLSearchParams({
|
|
27
|
+
response_type: 'code',
|
|
28
|
+
client_id: options.clientId,
|
|
29
|
+
redirect_uri: options.redirectUri,
|
|
30
|
+
scope: (options.scopes || ['openid', 'profile', 'email']).join(' '),
|
|
31
|
+
response_mode: 'query',
|
|
32
|
+
});
|
|
33
|
+
if (options.state) {
|
|
34
|
+
params.set('state', options.state);
|
|
35
|
+
}
|
|
36
|
+
if (options.nonce) {
|
|
37
|
+
params.set('nonce', options.nonce);
|
|
38
|
+
}
|
|
39
|
+
if (pkce) {
|
|
40
|
+
params.set('code_challenge', pkce.codeChallenge);
|
|
41
|
+
params.set('code_challenge_method', 'S256');
|
|
42
|
+
}
|
|
43
|
+
if (options.prompt) {
|
|
44
|
+
params.set('prompt', options.prompt);
|
|
45
|
+
}
|
|
46
|
+
if (options.loginHint) {
|
|
47
|
+
params.set('login_hint', options.loginHint);
|
|
48
|
+
}
|
|
49
|
+
if (options.domainHint) {
|
|
50
|
+
params.set('domain_hint', options.domainHint);
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
url: `${authorizeUrl}?${params.toString()}`,
|
|
54
|
+
codeVerifier: pkce?.codeVerifier,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export async function exchangeAzureADCode(options) {
|
|
58
|
+
const tokenUrl = getAzureADTokenEndpoint(options);
|
|
59
|
+
const params = new URLSearchParams({
|
|
60
|
+
grant_type: 'authorization_code',
|
|
61
|
+
client_id: options.clientId,
|
|
62
|
+
code: options.code,
|
|
63
|
+
redirect_uri: options.redirectUri,
|
|
64
|
+
scope: (options.scopes || ['openid', 'profile', 'email']).join(' '),
|
|
65
|
+
});
|
|
66
|
+
if (options.clientSecret) {
|
|
67
|
+
params.set('client_secret', options.clientSecret);
|
|
68
|
+
}
|
|
69
|
+
if (options.codeVerifier) {
|
|
70
|
+
params.set('code_verifier', options.codeVerifier);
|
|
71
|
+
}
|
|
72
|
+
const response = await fetch(tokenUrl, {
|
|
73
|
+
method: 'POST',
|
|
74
|
+
headers: {
|
|
75
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
76
|
+
},
|
|
77
|
+
body: params.toString(),
|
|
78
|
+
});
|
|
79
|
+
if (!response.ok) {
|
|
80
|
+
const error = await response.json();
|
|
81
|
+
throw new Error(`Azure AD token exchange failed: ${error.error_description || error.error}`);
|
|
82
|
+
}
|
|
83
|
+
const data = await response.json();
|
|
84
|
+
return {
|
|
85
|
+
accessToken: data.access_token,
|
|
86
|
+
refreshToken: data.refresh_token,
|
|
87
|
+
idToken: data.id_token,
|
|
88
|
+
expiresAt: data.expires_in ? Date.now() + data.expires_in * 1000 : undefined,
|
|
89
|
+
tokenType: data.token_type || 'Bearer',
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
export async function azureADOnBehalfOf(options) {
|
|
93
|
+
const tokenUrl = getAzureADTokenEndpoint(options);
|
|
94
|
+
const params = new URLSearchParams({
|
|
95
|
+
grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
|
|
96
|
+
client_id: options.clientId,
|
|
97
|
+
assertion: options.assertion,
|
|
98
|
+
scope: options.scope,
|
|
99
|
+
requested_token_use: 'on_behalf_of',
|
|
100
|
+
});
|
|
101
|
+
if (options.clientSecret) {
|
|
102
|
+
params.set('client_secret', options.clientSecret);
|
|
103
|
+
}
|
|
104
|
+
const response = await fetch(tokenUrl, {
|
|
105
|
+
method: 'POST',
|
|
106
|
+
headers: {
|
|
107
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
108
|
+
},
|
|
109
|
+
body: params.toString(),
|
|
110
|
+
});
|
|
111
|
+
if (!response.ok) {
|
|
112
|
+
const error = await response.json();
|
|
113
|
+
throw new Error(`Azure AD OBO flow failed: ${error.error_description || error.error}`);
|
|
114
|
+
}
|
|
115
|
+
const data = await response.json();
|
|
116
|
+
return {
|
|
117
|
+
accessToken: data.access_token,
|
|
118
|
+
refreshToken: data.refresh_token,
|
|
119
|
+
expiresAt: data.expires_in ? Date.now() + data.expires_in * 1000 : undefined,
|
|
120
|
+
tokenType: data.token_type || 'Bearer',
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
export async function getAzureADUserInfo(accessToken) {
|
|
124
|
+
const response = await fetch('https://graph.microsoft.com/v1.0/me', {
|
|
125
|
+
headers: {
|
|
126
|
+
Authorization: `Bearer ${accessToken}`,
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
if (!response.ok) {
|
|
130
|
+
throw new Error(`Failed to get user info: ${response.status}`);
|
|
131
|
+
}
|
|
132
|
+
return response.json();
|
|
133
|
+
}
|
|
134
|
+
export function azureAD(options) {
|
|
135
|
+
const issuer = getAzureADIssuer(options);
|
|
136
|
+
const scopes = options.scopes || ['openid', 'profile', 'email', 'offline_access'];
|
|
137
|
+
return oidc({
|
|
138
|
+
issuer,
|
|
139
|
+
clientId: options.clientId,
|
|
140
|
+
clientSecret: options.clientSecret,
|
|
141
|
+
scopes,
|
|
142
|
+
accessToken: options.accessToken,
|
|
143
|
+
refreshToken: options.refreshToken,
|
|
144
|
+
tokenStorage: options.tokenStorage,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
export function azureADPlugin(options) {
|
|
148
|
+
return (client) => {
|
|
149
|
+
client.use(azureAD(options));
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
export { azureAD as entraId, azureADPlugin as entraIdPlugin };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Middleware, Plugin } from '../../types/index.js';
|
|
2
|
+
export interface BasicAuthOptions {
|
|
3
|
+
username: string;
|
|
4
|
+
password: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function basicAuth(options: BasicAuthOptions): Middleware;
|
|
7
|
+
export declare function basicAuthPlugin(options: BasicAuthOptions): Plugin;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function basicAuth(options) {
|
|
2
|
+
const credentials = Buffer.from(`${options.username}:${options.password}`).toString('base64');
|
|
3
|
+
const authHeader = `Basic ${credentials}`;
|
|
4
|
+
return async (req, next) => {
|
|
5
|
+
const newReq = req.withHeader('Authorization', authHeader);
|
|
6
|
+
return next(newReq);
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export function basicAuthPlugin(options) {
|
|
10
|
+
return (client) => {
|
|
11
|
+
client.use(basicAuth(options));
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Middleware, Plugin } from '../../types/index.js';
|
|
2
|
+
export interface BearerAuthOptions {
|
|
3
|
+
token: string | (() => string | Promise<string>);
|
|
4
|
+
type?: string;
|
|
5
|
+
headerName?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function bearerAuth(options: BearerAuthOptions): Middleware;
|
|
8
|
+
export declare function bearerAuthPlugin(options: BearerAuthOptions): Plugin;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export function bearerAuth(options) {
|
|
2
|
+
const type = options.type ?? 'Bearer';
|
|
3
|
+
const headerName = options.headerName ?? 'Authorization';
|
|
4
|
+
return async (req, next) => {
|
|
5
|
+
const token = typeof options.token === 'function'
|
|
6
|
+
? await options.token()
|
|
7
|
+
: options.token;
|
|
8
|
+
const authHeader = `${type} ${token}`;
|
|
9
|
+
const newReq = req.withHeader(headerName, authHeader);
|
|
10
|
+
return next(newReq);
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export function bearerAuthPlugin(options) {
|
|
14
|
+
return (client) => {
|
|
15
|
+
client.use(bearerAuth(options));
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Middleware, Plugin } from '../../types/index.js';
|
|
2
|
+
export interface CognitoOptions {
|
|
3
|
+
region: string;
|
|
4
|
+
userPoolId: string;
|
|
5
|
+
clientId: string;
|
|
6
|
+
clientSecret?: string;
|
|
7
|
+
accessToken?: string | (() => string | Promise<string>);
|
|
8
|
+
idToken?: string;
|
|
9
|
+
refreshToken?: string;
|
|
10
|
+
username?: string;
|
|
11
|
+
password?: string;
|
|
12
|
+
useSRP?: boolean;
|
|
13
|
+
tokenStorage?: {
|
|
14
|
+
get: () => Promise<CognitoTokens | null>;
|
|
15
|
+
set: (tokens: CognitoTokens) => Promise<void>;
|
|
16
|
+
};
|
|
17
|
+
identityPoolId?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface CognitoTokens {
|
|
20
|
+
accessToken: string;
|
|
21
|
+
idToken?: string;
|
|
22
|
+
refreshToken?: string;
|
|
23
|
+
expiresAt?: number;
|
|
24
|
+
tokenType?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface CognitoAWSCredentials {
|
|
27
|
+
accessKeyId: string;
|
|
28
|
+
secretAccessKey: string;
|
|
29
|
+
sessionToken: string;
|
|
30
|
+
expiresAt: number;
|
|
31
|
+
}
|
|
32
|
+
export declare function getCognitoIdentityCredentials(options: {
|
|
33
|
+
region: string;
|
|
34
|
+
identityPoolId: string;
|
|
35
|
+
idToken: string;
|
|
36
|
+
userPoolId: string;
|
|
37
|
+
}): Promise<CognitoAWSCredentials>;
|
|
38
|
+
export declare function getCognitoHostedUIUrl(options: CognitoOptions & {
|
|
39
|
+
redirectUri: string;
|
|
40
|
+
responseType?: 'code' | 'token';
|
|
41
|
+
scopes?: string[];
|
|
42
|
+
state?: string;
|
|
43
|
+
}): string;
|
|
44
|
+
export declare function cognito(options: CognitoOptions): Middleware;
|
|
45
|
+
export declare function cognitoPlugin(options: CognitoOptions): Plugin;
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { createHmac } from 'node:crypto';
|
|
2
|
+
function generateSecretHash(username, clientId, clientSecret) {
|
|
3
|
+
return createHmac('sha256', clientSecret)
|
|
4
|
+
.update(username + clientId)
|
|
5
|
+
.digest('base64');
|
|
6
|
+
}
|
|
7
|
+
async function authenticateUserPassword(options) {
|
|
8
|
+
if (!options.username || !options.password) {
|
|
9
|
+
throw new Error('Username and password are required for USER_PASSWORD_AUTH');
|
|
10
|
+
}
|
|
11
|
+
const endpoint = `https://cognito-idp.${options.region}.amazonaws.com/`;
|
|
12
|
+
const authParameters = {
|
|
13
|
+
USERNAME: options.username,
|
|
14
|
+
PASSWORD: options.password,
|
|
15
|
+
};
|
|
16
|
+
if (options.clientSecret) {
|
|
17
|
+
authParameters.SECRET_HASH = generateSecretHash(options.username, options.clientId, options.clientSecret);
|
|
18
|
+
}
|
|
19
|
+
const response = await fetch(endpoint, {
|
|
20
|
+
method: 'POST',
|
|
21
|
+
headers: {
|
|
22
|
+
'Content-Type': 'application/x-amz-json-1.1',
|
|
23
|
+
'X-Amz-Target': 'AWSCognitoIdentityProviderService.InitiateAuth',
|
|
24
|
+
},
|
|
25
|
+
body: JSON.stringify({
|
|
26
|
+
AuthFlow: 'USER_PASSWORD_AUTH',
|
|
27
|
+
ClientId: options.clientId,
|
|
28
|
+
AuthParameters: authParameters,
|
|
29
|
+
}),
|
|
30
|
+
});
|
|
31
|
+
if (!response.ok) {
|
|
32
|
+
const error = await response.json();
|
|
33
|
+
throw new Error(`Cognito authentication failed: ${error.message || error.__type}`);
|
|
34
|
+
}
|
|
35
|
+
const data = await response.json();
|
|
36
|
+
if (data.ChallengeName) {
|
|
37
|
+
throw new Error(`Cognito challenge required: ${data.ChallengeName}`);
|
|
38
|
+
}
|
|
39
|
+
if (!data.AuthenticationResult) {
|
|
40
|
+
throw new Error('Cognito authentication failed: No result');
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
accessToken: data.AuthenticationResult.AccessToken,
|
|
44
|
+
idToken: data.AuthenticationResult.IdToken,
|
|
45
|
+
refreshToken: data.AuthenticationResult.RefreshToken,
|
|
46
|
+
expiresAt: Date.now() + data.AuthenticationResult.ExpiresIn * 1000,
|
|
47
|
+
tokenType: data.AuthenticationResult.TokenType,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
async function refreshCognitoTokens(options, refreshToken) {
|
|
51
|
+
const endpoint = `https://cognito-idp.${options.region}.amazonaws.com/`;
|
|
52
|
+
const authParameters = {
|
|
53
|
+
REFRESH_TOKEN: refreshToken,
|
|
54
|
+
};
|
|
55
|
+
if (options.clientSecret && options.username) {
|
|
56
|
+
authParameters.SECRET_HASH = generateSecretHash(options.username, options.clientId, options.clientSecret);
|
|
57
|
+
}
|
|
58
|
+
const response = await fetch(endpoint, {
|
|
59
|
+
method: 'POST',
|
|
60
|
+
headers: {
|
|
61
|
+
'Content-Type': 'application/x-amz-json-1.1',
|
|
62
|
+
'X-Amz-Target': 'AWSCognitoIdentityProviderService.InitiateAuth',
|
|
63
|
+
},
|
|
64
|
+
body: JSON.stringify({
|
|
65
|
+
AuthFlow: 'REFRESH_TOKEN_AUTH',
|
|
66
|
+
ClientId: options.clientId,
|
|
67
|
+
AuthParameters: authParameters,
|
|
68
|
+
}),
|
|
69
|
+
});
|
|
70
|
+
if (!response.ok) {
|
|
71
|
+
const error = await response.json();
|
|
72
|
+
throw new Error(`Cognito token refresh failed: ${error.message || error.__type}`);
|
|
73
|
+
}
|
|
74
|
+
const data = await response.json();
|
|
75
|
+
return {
|
|
76
|
+
accessToken: data.AuthenticationResult.AccessToken,
|
|
77
|
+
idToken: data.AuthenticationResult.IdToken,
|
|
78
|
+
refreshToken: refreshToken,
|
|
79
|
+
expiresAt: Date.now() + data.AuthenticationResult.ExpiresIn * 1000,
|
|
80
|
+
tokenType: data.AuthenticationResult.TokenType,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
export async function getCognitoIdentityCredentials(options) {
|
|
84
|
+
const identityEndpoint = `https://cognito-identity.${options.region}.amazonaws.com/`;
|
|
85
|
+
const logins = {
|
|
86
|
+
[`cognito-idp.${options.region}.amazonaws.com/${options.userPoolId}`]: options.idToken,
|
|
87
|
+
};
|
|
88
|
+
const getIdResponse = await fetch(identityEndpoint, {
|
|
89
|
+
method: 'POST',
|
|
90
|
+
headers: {
|
|
91
|
+
'Content-Type': 'application/x-amz-json-1.1',
|
|
92
|
+
'X-Amz-Target': 'AWSCognitoIdentityService.GetId',
|
|
93
|
+
},
|
|
94
|
+
body: JSON.stringify({
|
|
95
|
+
IdentityPoolId: options.identityPoolId,
|
|
96
|
+
Logins: logins,
|
|
97
|
+
}),
|
|
98
|
+
});
|
|
99
|
+
if (!getIdResponse.ok) {
|
|
100
|
+
const error = await getIdResponse.json();
|
|
101
|
+
throw new Error(`Failed to get identity ID: ${error.message || error.__type}`);
|
|
102
|
+
}
|
|
103
|
+
const { IdentityId } = await getIdResponse.json();
|
|
104
|
+
const getCredentialsResponse = await fetch(identityEndpoint, {
|
|
105
|
+
method: 'POST',
|
|
106
|
+
headers: {
|
|
107
|
+
'Content-Type': 'application/x-amz-json-1.1',
|
|
108
|
+
'X-Amz-Target': 'AWSCognitoIdentityService.GetCredentialsForIdentity',
|
|
109
|
+
},
|
|
110
|
+
body: JSON.stringify({
|
|
111
|
+
IdentityId,
|
|
112
|
+
Logins: logins,
|
|
113
|
+
}),
|
|
114
|
+
});
|
|
115
|
+
if (!getCredentialsResponse.ok) {
|
|
116
|
+
const error = await getCredentialsResponse.json();
|
|
117
|
+
throw new Error(`Failed to get credentials: ${error.message || error.__type}`);
|
|
118
|
+
}
|
|
119
|
+
const data = await getCredentialsResponse.json();
|
|
120
|
+
return {
|
|
121
|
+
accessKeyId: data.Credentials.AccessKeyId,
|
|
122
|
+
secretAccessKey: data.Credentials.SecretKey,
|
|
123
|
+
sessionToken: data.Credentials.SessionToken,
|
|
124
|
+
expiresAt: data.Credentials.Expiration * 1000,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
export function getCognitoHostedUIUrl(options) {
|
|
128
|
+
const domain = `https://${options.userPoolId.split('_')[1].toLowerCase()}.auth.${options.region}.amazoncognito.com`;
|
|
129
|
+
const params = new URLSearchParams({
|
|
130
|
+
response_type: options.responseType || 'code',
|
|
131
|
+
client_id: options.clientId,
|
|
132
|
+
redirect_uri: options.redirectUri,
|
|
133
|
+
scope: (options.scopes || ['openid', 'profile', 'email']).join(' '),
|
|
134
|
+
});
|
|
135
|
+
if (options.state) {
|
|
136
|
+
params.set('state', options.state);
|
|
137
|
+
}
|
|
138
|
+
return `${domain}/login?${params.toString()}`;
|
|
139
|
+
}
|
|
140
|
+
export function cognito(options) {
|
|
141
|
+
let cachedTokens = null;
|
|
142
|
+
const getTokens = async () => {
|
|
143
|
+
if (options.tokenStorage) {
|
|
144
|
+
const stored = await options.tokenStorage.get();
|
|
145
|
+
if (stored) {
|
|
146
|
+
cachedTokens = stored;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (cachedTokens && cachedTokens.expiresAt && cachedTokens.expiresAt > Date.now() + 60000) {
|
|
150
|
+
return cachedTokens;
|
|
151
|
+
}
|
|
152
|
+
if (cachedTokens?.refreshToken || options.refreshToken) {
|
|
153
|
+
const refreshToken = cachedTokens?.refreshToken || options.refreshToken;
|
|
154
|
+
try {
|
|
155
|
+
cachedTokens = await refreshCognitoTokens(options, refreshToken);
|
|
156
|
+
if (options.tokenStorage) {
|
|
157
|
+
await options.tokenStorage.set(cachedTokens);
|
|
158
|
+
}
|
|
159
|
+
return cachedTokens;
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (options.accessToken) {
|
|
165
|
+
const token = typeof options.accessToken === 'function'
|
|
166
|
+
? await options.accessToken()
|
|
167
|
+
: options.accessToken;
|
|
168
|
+
return {
|
|
169
|
+
accessToken: token,
|
|
170
|
+
idToken: options.idToken,
|
|
171
|
+
tokenType: 'Bearer',
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
if (options.username && options.password) {
|
|
175
|
+
cachedTokens = await authenticateUserPassword(options);
|
|
176
|
+
if (options.tokenStorage) {
|
|
177
|
+
await options.tokenStorage.set(cachedTokens);
|
|
178
|
+
}
|
|
179
|
+
return cachedTokens;
|
|
180
|
+
}
|
|
181
|
+
throw new Error('No valid authentication method. Provide accessToken, refreshToken, or username/password.');
|
|
182
|
+
};
|
|
183
|
+
return async (req, next) => {
|
|
184
|
+
const tokens = await getTokens();
|
|
185
|
+
const authReq = req.withHeader('Authorization', `Bearer ${tokens.accessToken}`);
|
|
186
|
+
const response = await next(authReq);
|
|
187
|
+
if (response.status === 401 && (cachedTokens?.refreshToken || options.refreshToken)) {
|
|
188
|
+
try {
|
|
189
|
+
const refreshToken = cachedTokens?.refreshToken || options.refreshToken;
|
|
190
|
+
cachedTokens = await refreshCognitoTokens(options, refreshToken);
|
|
191
|
+
if (options.tokenStorage) {
|
|
192
|
+
await options.tokenStorage.set(cachedTokens);
|
|
193
|
+
}
|
|
194
|
+
const retryReq = req.withHeader('Authorization', `Bearer ${cachedTokens.accessToken}`);
|
|
195
|
+
return next(retryReq);
|
|
196
|
+
}
|
|
197
|
+
catch {
|
|
198
|
+
return response;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return response;
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
export function cognitoPlugin(options) {
|
|
205
|
+
return (client) => {
|
|
206
|
+
client.use(cognito(options));
|
|
207
|
+
};
|
|
208
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Middleware, Plugin } from '../../types/index.js';
|
|
2
|
+
export interface DigestAuthOptions {
|
|
3
|
+
username: string;
|
|
4
|
+
password: string;
|
|
5
|
+
preemptive?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function digestAuth(options: DigestAuthOptions): Middleware;
|
|
8
|
+
export declare function digestAuthPlugin(options: DigestAuthOptions): Plugin;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
2
|
+
function parseDigestChallenge(header) {
|
|
3
|
+
if (!header.toLowerCase().startsWith('digest ')) {
|
|
4
|
+
return null;
|
|
5
|
+
}
|
|
6
|
+
const params = {};
|
|
7
|
+
const regex = /(\w+)=(?:"([^"]+)"|([^\s,]+))/g;
|
|
8
|
+
let match;
|
|
9
|
+
while ((match = regex.exec(header)) !== null) {
|
|
10
|
+
params[match[1].toLowerCase()] = match[2] || match[3];
|
|
11
|
+
}
|
|
12
|
+
if (!params.realm || !params.nonce) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
realm: params.realm,
|
|
17
|
+
nonce: params.nonce,
|
|
18
|
+
qop: params.qop,
|
|
19
|
+
opaque: params.opaque,
|
|
20
|
+
algorithm: params.algorithm,
|
|
21
|
+
stale: params.stale === 'true',
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function md5(str) {
|
|
25
|
+
return createHash('md5').update(str).digest('hex');
|
|
26
|
+
}
|
|
27
|
+
function sha256(str) {
|
|
28
|
+
return createHash('sha256').update(str).digest('hex');
|
|
29
|
+
}
|
|
30
|
+
function generateDigestHeader(method, uri, username, password, challenge, nc) {
|
|
31
|
+
const algorithm = challenge.algorithm?.toUpperCase() || 'MD5';
|
|
32
|
+
const hashFn = algorithm.includes('SHA-256') ? sha256 : md5;
|
|
33
|
+
const cnonce = randomBytes(8).toString('hex');
|
|
34
|
+
const ncStr = nc.toString(16).padStart(8, '0');
|
|
35
|
+
let ha1 = hashFn(`${username}:${challenge.realm}:${password}`);
|
|
36
|
+
if (algorithm.endsWith('-SESS')) {
|
|
37
|
+
ha1 = hashFn(`${ha1}:${challenge.nonce}:${cnonce}`);
|
|
38
|
+
}
|
|
39
|
+
const ha2 = hashFn(`${method}:${uri}`);
|
|
40
|
+
let response;
|
|
41
|
+
if (challenge.qop) {
|
|
42
|
+
response = hashFn(`${ha1}:${challenge.nonce}:${ncStr}:${cnonce}:${challenge.qop}:${ha2}`);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
response = hashFn(`${ha1}:${challenge.nonce}:${ha2}`);
|
|
46
|
+
}
|
|
47
|
+
const parts = [
|
|
48
|
+
`username="${username}"`,
|
|
49
|
+
`realm="${challenge.realm}"`,
|
|
50
|
+
`nonce="${challenge.nonce}"`,
|
|
51
|
+
`uri="${uri}"`,
|
|
52
|
+
`response="${response}"`,
|
|
53
|
+
];
|
|
54
|
+
if (challenge.qop) {
|
|
55
|
+
parts.push(`qop=${challenge.qop.split(',')[0].trim()}`);
|
|
56
|
+
parts.push(`nc=${ncStr}`);
|
|
57
|
+
parts.push(`cnonce="${cnonce}"`);
|
|
58
|
+
}
|
|
59
|
+
if (challenge.opaque) {
|
|
60
|
+
parts.push(`opaque="${challenge.opaque}"`);
|
|
61
|
+
}
|
|
62
|
+
if (algorithm !== 'MD5') {
|
|
63
|
+
parts.push(`algorithm=${algorithm}`);
|
|
64
|
+
}
|
|
65
|
+
return `Digest ${parts.join(', ')}`;
|
|
66
|
+
}
|
|
67
|
+
export function digestAuth(options) {
|
|
68
|
+
let nc = 0;
|
|
69
|
+
let lastChallenge = null;
|
|
70
|
+
return async (req, next) => {
|
|
71
|
+
if (lastChallenge && options.preemptive) {
|
|
72
|
+
nc++;
|
|
73
|
+
const uri = new URL(req.url).pathname + new URL(req.url).search;
|
|
74
|
+
const authHeader = generateDigestHeader(req.method, uri, options.username, options.password, lastChallenge, nc);
|
|
75
|
+
const newReq = req.withHeader('Authorization', authHeader);
|
|
76
|
+
return next(newReq);
|
|
77
|
+
}
|
|
78
|
+
const response = await next(req);
|
|
79
|
+
if (response.status === 401) {
|
|
80
|
+
const wwwAuth = response.headers.get('WWW-Authenticate');
|
|
81
|
+
if (wwwAuth) {
|
|
82
|
+
const challenge = parseDigestChallenge(wwwAuth);
|
|
83
|
+
if (challenge) {
|
|
84
|
+
lastChallenge = challenge;
|
|
85
|
+
nc++;
|
|
86
|
+
const uri = new URL(req.url).pathname + new URL(req.url).search;
|
|
87
|
+
const authHeader = generateDigestHeader(req.method, uri, options.username, options.password, challenge, nc);
|
|
88
|
+
const newReq = req.withHeader('Authorization', authHeader);
|
|
89
|
+
return next(newReq);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return response;
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
export function digestAuthPlugin(options) {
|
|
97
|
+
return (client) => {
|
|
98
|
+
client.use(digestAuth(options));
|
|
99
|
+
};
|
|
100
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Middleware, Plugin } from '../../types/index.js';
|
|
2
|
+
export interface FirebaseAuthOptions {
|
|
3
|
+
projectId: string;
|
|
4
|
+
idToken?: string | (() => string | Promise<string>);
|
|
5
|
+
serviceAccount?: FirebaseServiceAccount;
|
|
6
|
+
serviceAccountPath?: string;
|
|
7
|
+
apiKey?: string;
|
|
8
|
+
customToken?: string;
|
|
9
|
+
tokenStorage?: {
|
|
10
|
+
get: () => Promise<FirebaseTokens | null>;
|
|
11
|
+
set: (tokens: FirebaseTokens) => Promise<void>;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export interface FirebaseServiceAccount {
|
|
15
|
+
type: 'service_account';
|
|
16
|
+
project_id: string;
|
|
17
|
+
private_key_id: string;
|
|
18
|
+
private_key: string;
|
|
19
|
+
client_email: string;
|
|
20
|
+
client_id: string;
|
|
21
|
+
auth_uri: string;
|
|
22
|
+
token_uri: string;
|
|
23
|
+
}
|
|
24
|
+
export interface FirebaseTokens {
|
|
25
|
+
idToken: string;
|
|
26
|
+
refreshToken?: string;
|
|
27
|
+
expiresAt?: number;
|
|
28
|
+
}
|
|
29
|
+
export declare function createFirebaseCustomToken(serviceAccount: FirebaseServiceAccount, uid: string, claims?: Record<string, unknown>): string;
|
|
30
|
+
export declare function verifyFirebaseIdToken(projectId: string, idToken: string): Promise<Record<string, unknown>>;
|
|
31
|
+
export declare function firebase(options: FirebaseAuthOptions): Middleware;
|
|
32
|
+
export declare function firebasePlugin(options: FirebaseAuthOptions): Plugin;
|