@j0hanz/superfetch 2.1.3 → 2.1.5
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/dist/cache.d.ts +1 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +37 -6
- package/dist/cache.js.map +1 -0
- package/dist/config.d.ts +1 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +1 -0
- package/dist/config.js.map +1 -0
- package/dist/crypto.d.ts +1 -0
- package/dist/crypto.d.ts.map +1 -0
- package/dist/crypto.js +1 -0
- package/dist/crypto.js.map +1 -0
- package/dist/errors.d.ts +1 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +1 -0
- package/dist/errors.js.map +1 -0
- package/dist/fetch.d.ts +1 -0
- package/dist/fetch.d.ts.map +1 -0
- package/dist/fetch.js +1 -0
- package/dist/fetch.js.map +1 -0
- package/dist/http.d.ts +2 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +34 -5
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/mcp.d.ts +1 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +1 -0
- package/dist/mcp.js.map +1 -0
- package/dist/observability.d.ts +1 -0
- package/dist/observability.d.ts.map +1 -0
- package/dist/observability.js +1 -0
- package/dist/observability.js.map +1 -0
- package/dist/tools.d.ts +1 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +1 -0
- package/dist/tools.js.map +1 -0
- package/dist/transform.d.ts +1 -0
- package/dist/transform.d.ts.map +1 -0
- package/dist/transform.js +1 -0
- package/dist/transform.js.map +1 -0
- package/dist/utils.d.ts +1 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +1 -0
- package/dist/utils.js.map +1 -0
- package/dist/workers/transform-worker.d.ts +1 -0
- package/dist/workers/transform-worker.d.ts.map +1 -0
- package/dist/workers/transform-worker.js +1 -0
- package/dist/workers/transform-worker.js.map +1 -0
- package/package.json +8 -5
- package/dist/config/auth-config.d.ts +0 -16
- package/dist/config/auth-config.js +0 -53
- package/dist/config/constants.d.ts +0 -17
- package/dist/config/constants.d.ts.map +0 -1
- package/dist/config/constants.js +0 -22
- package/dist/config/constants.js.map +0 -1
- package/dist/config/env-parsers.d.ts +0 -8
- package/dist/config/env-parsers.js +0 -96
- package/dist/config/formatting.d.ts +0 -7
- package/dist/config/formatting.d.ts.map +0 -1
- package/dist/config/formatting.js +0 -9
- package/dist/config/formatting.js.map +0 -1
- package/dist/config/index.d.ts +0 -61
- package/dist/config/index.d.ts.map +0 -1
- package/dist/config/index.js +0 -107
- package/dist/config/index.js.map +0 -1
- package/dist/config/types/content.d.ts +0 -41
- package/dist/config/types/content.d.ts.map +0 -1
- package/dist/config/types/content.js +0 -1
- package/dist/config/types/content.js.map +0 -1
- package/dist/config/types/runtime.d.ts +0 -72
- package/dist/config/types/runtime.d.ts.map +0 -1
- package/dist/config/types/runtime.js +0 -1
- package/dist/config/types/runtime.js.map +0 -1
- package/dist/config/types/tools.d.ts +0 -28
- package/dist/config/types/tools.d.ts.map +0 -1
- package/dist/config/types/tools.js +0 -1
- package/dist/config/types/tools.js.map +0 -1
- package/dist/config/types.d.ts +0 -4
- package/dist/config/types.d.ts.map +0 -1
- package/dist/config/types.js +0 -2
- package/dist/config/types.js.map +0 -1
- package/dist/errors/app-error.d.ts +0 -7
- package/dist/errors/app-error.d.ts.map +0 -1
- package/dist/errors/app-error.js +0 -16
- package/dist/errors/app-error.js.map +0 -1
- package/dist/errors/index.d.ts +0 -2
- package/dist/errors/index.d.ts.map +0 -1
- package/dist/errors/index.js +0 -2
- package/dist/errors/index.js.map +0 -1
- package/dist/http/accept-policy.d.ts +0 -3
- package/dist/http/accept-policy.js +0 -45
- package/dist/http/async-handler.d.ts +0 -2
- package/dist/http/async-handler.js +0 -5
- package/dist/http/auth-introspection.d.ts +0 -2
- package/dist/http/auth-introspection.js +0 -141
- package/dist/http/auth-static.d.ts +0 -2
- package/dist/http/auth-static.js +0 -23
- package/dist/http/auth.d.ts +0 -3
- package/dist/http/auth.d.ts.map +0 -1
- package/dist/http/auth.js +0 -269
- package/dist/http/auth.js.map +0 -1
- package/dist/http/base-middleware.d.ts +0 -7
- package/dist/http/base-middleware.js +0 -143
- package/dist/http/cors.d.ts +0 -2
- package/dist/http/cors.d.ts.map +0 -1
- package/dist/http/cors.js +0 -9
- package/dist/http/cors.js.map +0 -1
- package/dist/http/download-routes.d.ts +0 -2
- package/dist/http/download-routes.d.ts.map +0 -1
- package/dist/http/download-routes.js +0 -104
- package/dist/http/download-routes.js.map +0 -1
- package/dist/http/error-handler.d.ts +0 -2
- package/dist/http/error-handler.js +0 -55
- package/dist/http/host-allowlist.d.ts +0 -3
- package/dist/http/host-allowlist.js +0 -117
- package/dist/http/jsonrpc-http.d.ts +0 -2
- package/dist/http/jsonrpc-http.js +0 -10
- package/dist/http/mcp-routes.d.ts +0 -9
- package/dist/http/mcp-routes.d.ts.map +0 -1
- package/dist/http/mcp-routes.js +0 -204
- package/dist/http/mcp-routes.js.map +0 -1
- package/dist/http/mcp-session-eviction.d.ts +0 -3
- package/dist/http/mcp-session-eviction.js +0 -24
- package/dist/http/mcp-session-helpers.d.ts +0 -12
- package/dist/http/mcp-session-helpers.d.ts.map +0 -1
- package/dist/http/mcp-session-helpers.js +0 -64
- package/dist/http/mcp-session-helpers.js.map +0 -1
- package/dist/http/mcp-session-init.d.ts +0 -7
- package/dist/http/mcp-session-init.js +0 -94
- package/dist/http/mcp-session-slots.d.ts +0 -17
- package/dist/http/mcp-session-slots.js +0 -55
- package/dist/http/mcp-session-transport-init.d.ts +0 -7
- package/dist/http/mcp-session-transport-init.js +0 -41
- package/dist/http/mcp-session-transport.d.ts +0 -7
- package/dist/http/mcp-session-transport.js +0 -57
- package/dist/http/mcp-session-types.d.ts +0 -5
- package/dist/http/mcp-session-types.js +0 -1
- package/dist/http/mcp-session.d.ts +0 -10
- package/dist/http/mcp-session.d.ts.map +0 -1
- package/dist/http/mcp-session.js +0 -23
- package/dist/http/mcp-session.js.map +0 -1
- package/dist/http/mcp-sessions.d.ts +0 -41
- package/dist/http/mcp-sessions.js +0 -392
- package/dist/http/mcp-validation.d.ts +0 -3
- package/dist/http/mcp-validation.d.ts.map +0 -1
- package/dist/http/mcp-validation.js +0 -14
- package/dist/http/mcp-validation.js.map +0 -1
- package/dist/http/protocol-policy.d.ts +0 -2
- package/dist/http/protocol-policy.js +0 -31
- package/dist/http/rate-limit.d.ts +0 -12
- package/dist/http/rate-limit.d.ts.map +0 -1
- package/dist/http/rate-limit.js +0 -93
- package/dist/http/rate-limit.js.map +0 -1
- package/dist/http/server-config.d.ts +0 -1
- package/dist/http/server-config.js +0 -40
- package/dist/http/server-middleware.d.ts +0 -7
- package/dist/http/server-middleware.d.ts.map +0 -1
- package/dist/http/server-middleware.js +0 -52
- package/dist/http/server-middleware.js.map +0 -1
- package/dist/http/server-shutdown.d.ts +0 -4
- package/dist/http/server-shutdown.js +0 -43
- package/dist/http/server-tuning.d.ts +0 -9
- package/dist/http/server-tuning.js +0 -45
- package/dist/http/server.d.ts +0 -3
- package/dist/http/server.d.ts.map +0 -1
- package/dist/http/server.js +0 -291
- package/dist/http/server.js.map +0 -1
- package/dist/http/session-cleanup.d.ts +0 -2
- package/dist/http/session-cleanup.d.ts.map +0 -1
- package/dist/http/session-cleanup.js +0 -40
- package/dist/http/session-cleanup.js.map +0 -1
- package/dist/http/sessions.d.ts +0 -14
- package/dist/http/sessions.d.ts.map +0 -1
- package/dist/http/sessions.js +0 -63
- package/dist/http/sessions.js.map +0 -1
- package/dist/middleware/error-handler.d.ts +0 -2
- package/dist/middleware/error-handler.d.ts.map +0 -1
- package/dist/middleware/error-handler.js +0 -56
- package/dist/middleware/error-handler.js.map +0 -1
- package/dist/middleware/rate-limiter.d.ts +0 -16
- package/dist/middleware/rate-limiter.d.ts.map +0 -1
- package/dist/middleware/rate-limiter.js +0 -111
- package/dist/middleware/rate-limiter.js.map +0 -1
- package/dist/parsers/base-html-element-parser.d.ts +0 -43
- package/dist/parsers/base-html-element-parser.d.ts.map +0 -1
- package/dist/parsers/base-html-element-parser.js +0 -59
- package/dist/parsers/base-html-element-parser.js.map +0 -1
- package/dist/parsers/heading-element-parser.d.ts +0 -14
- package/dist/parsers/heading-element-parser.d.ts.map +0 -1
- package/dist/parsers/heading-element-parser.js +0 -26
- package/dist/parsers/heading-element-parser.js.map +0 -1
- package/dist/parsers/image-element-parser.d.ts +0 -16
- package/dist/parsers/image-element-parser.d.ts.map +0 -1
- package/dist/parsers/image-element-parser.js +0 -33
- package/dist/parsers/image-element-parser.js.map +0 -1
- package/dist/parsers/link-element-parser.d.ts +0 -15
- package/dist/parsers/link-element-parser.d.ts.map +0 -1
- package/dist/parsers/link-element-parser.js +0 -28
- package/dist/parsers/link-element-parser.js.map +0 -1
- package/dist/parsers/open-graph-parser.d.ts +0 -17
- package/dist/parsers/open-graph-parser.d.ts.map +0 -1
- package/dist/parsers/open-graph-parser.js +0 -41
- package/dist/parsers/open-graph-parser.js.map +0 -1
- package/dist/parsers/schema-org-parser.d.ts +0 -17
- package/dist/parsers/schema-org-parser.d.ts.map +0 -1
- package/dist/parsers/schema-org-parser.js +0 -32
- package/dist/parsers/schema-org-parser.js.map +0 -1
- package/dist/parsers/standard-meta-parser.d.ts +0 -18
- package/dist/parsers/standard-meta-parser.d.ts.map +0 -1
- package/dist/parsers/standard-meta-parser.js +0 -32
- package/dist/parsers/standard-meta-parser.js.map +0 -1
- package/dist/parsers/twitter-card-parser.d.ts +0 -17
- package/dist/parsers/twitter-card-parser.d.ts.map +0 -1
- package/dist/parsers/twitter-card-parser.js +0 -41
- package/dist/parsers/twitter-card-parser.js.map +0 -1
- package/dist/prompts/index.d.ts +0 -3
- package/dist/prompts/index.d.ts.map +0 -1
- package/dist/prompts/index.js +0 -73
- package/dist/prompts/index.js.map +0 -1
- package/dist/resources/cached-content-params.d.ts +0 -5
- package/dist/resources/cached-content-params.js +0 -36
- package/dist/resources/cached-content.d.ts +0 -2
- package/dist/resources/cached-content.d.ts.map +0 -1
- package/dist/resources/cached-content.js +0 -132
- package/dist/resources/cached-content.js.map +0 -1
- package/dist/resources/index.d.ts +0 -2
- package/dist/resources/index.d.ts.map +0 -1
- package/dist/resources/index.js +0 -4
- package/dist/resources/index.js.map +0 -1
- package/dist/server.d.ts +0 -3
- package/dist/server.d.ts.map +0 -1
- package/dist/server.js +0 -94
- package/dist/server.js.map +0 -1
- package/dist/services/cache-events.d.ts +0 -8
- package/dist/services/cache-events.js +0 -19
- package/dist/services/cache-keys.d.ts +0 -7
- package/dist/services/cache-keys.js +0 -57
- package/dist/services/cache.d.ts +0 -17
- package/dist/services/cache.d.ts.map +0 -1
- package/dist/services/cache.js +0 -145
- package/dist/services/cache.js.map +0 -1
- package/dist/services/cache.service.d.ts +0 -52
- package/dist/services/cache.service.d.ts.map +0 -1
- package/dist/services/cache.service.js +0 -113
- package/dist/services/cache.service.js.map +0 -1
- package/dist/services/card-extractor.d.ts +0 -6
- package/dist/services/card-extractor.d.ts.map +0 -1
- package/dist/services/card-extractor.js +0 -199
- package/dist/services/card-extractor.js.map +0 -1
- package/dist/services/context.d.ts +0 -10
- package/dist/services/context.d.ts.map +0 -1
- package/dist/services/context.js +0 -14
- package/dist/services/context.js.map +0 -1
- package/dist/services/extractor.d.ts +0 -5
- package/dist/services/extractor.d.ts.map +0 -1
- package/dist/services/extractor.js +0 -142
- package/dist/services/extractor.js.map +0 -1
- package/dist/services/extractor.service.d.ts +0 -18
- package/dist/services/extractor.service.d.ts.map +0 -1
- package/dist/services/extractor.service.js +0 -75
- package/dist/services/extractor.service.js.map +0 -1
- package/dist/services/fetcher/agents.d.ts +0 -3
- package/dist/services/fetcher/agents.d.ts.map +0 -1
- package/dist/services/fetcher/agents.js +0 -100
- package/dist/services/fetcher/agents.js.map +0 -1
- package/dist/services/fetcher/dns-selection.d.ts +0 -2
- package/dist/services/fetcher/dns-selection.js +0 -72
- package/dist/services/fetcher/errors.d.ts +0 -4
- package/dist/services/fetcher/errors.d.ts.map +0 -1
- package/dist/services/fetcher/errors.js +0 -70
- package/dist/services/fetcher/errors.js.map +0 -1
- package/dist/services/fetcher/headers.d.ts +0 -2
- package/dist/services/fetcher/headers.d.ts.map +0 -1
- package/dist/services/fetcher/headers.js +0 -6
- package/dist/services/fetcher/headers.js.map +0 -1
- package/dist/services/fetcher/interceptors.d.ts +0 -10
- package/dist/services/fetcher/interceptors.d.ts.map +0 -1
- package/dist/services/fetcher/interceptors.js +0 -108
- package/dist/services/fetcher/interceptors.js.map +0 -1
- package/dist/services/fetcher/redirects.d.ts +0 -4
- package/dist/services/fetcher/redirects.d.ts.map +0 -1
- package/dist/services/fetcher/redirects.js +0 -78
- package/dist/services/fetcher/redirects.js.map +0 -1
- package/dist/services/fetcher/response.d.ts +0 -4
- package/dist/services/fetcher/response.d.ts.map +0 -1
- package/dist/services/fetcher/response.js +0 -104
- package/dist/services/fetcher/response.js.map +0 -1
- package/dist/services/fetcher/retry-policy.d.ts +0 -1
- package/dist/services/fetcher/retry-policy.d.ts.map +0 -1
- package/dist/services/fetcher/retry-policy.js +0 -131
- package/dist/services/fetcher/retry-policy.js.map +0 -1
- package/dist/services/fetcher.d.ts +0 -25
- package/dist/services/fetcher.d.ts.map +0 -1
- package/dist/services/fetcher.js +0 -607
- package/dist/services/fetcher.js.map +0 -1
- package/dist/services/fetcher.service.d.ts +0 -18
- package/dist/services/fetcher.service.d.ts.map +0 -1
- package/dist/services/fetcher.service.js +0 -122
- package/dist/services/fetcher.service.js.map +0 -1
- package/dist/services/fifo-queue.d.ts +0 -8
- package/dist/services/fifo-queue.js +0 -25
- package/dist/services/logger.d.ts +0 -5
- package/dist/services/logger.d.ts.map +0 -1
- package/dist/services/logger.js +0 -52
- package/dist/services/logger.js.map +0 -1
- package/dist/services/logger.service.d.ts +0 -5
- package/dist/services/logger.service.d.ts.map +0 -1
- package/dist/services/logger.service.js +0 -57
- package/dist/services/logger.service.js.map +0 -1
- package/dist/services/metadata-collector.d.ts +0 -2
- package/dist/services/metadata-collector.js +0 -80
- package/dist/services/parser.d.ts +0 -6
- package/dist/services/parser.d.ts.map +0 -1
- package/dist/services/parser.js +0 -278
- package/dist/services/parser.js.map +0 -1
- package/dist/services/parser.service.d.ts +0 -42
- package/dist/services/parser.service.d.ts.map +0 -1
- package/dist/services/parser.service.js +0 -209
- package/dist/services/parser.service.js.map +0 -1
- package/dist/services/session-manager.d.ts +0 -18
- package/dist/services/session-manager.d.ts.map +0 -1
- package/dist/services/session-manager.js +0 -73
- package/dist/services/session-manager.js.map +0 -1
- package/dist/services/telemetry.d.ts +0 -19
- package/dist/services/telemetry.js +0 -43
- package/dist/services/transform-worker-pool.d.ts +0 -11
- package/dist/services/transform-worker-pool.js +0 -244
- package/dist/services/transform-worker-types.d.ts +0 -32
- package/dist/services/transform-worker-types.js +0 -14
- package/dist/strategies/exponential-backoff-strategy.d.ts +0 -13
- package/dist/strategies/exponential-backoff-strategy.d.ts.map +0 -1
- package/dist/strategies/exponential-backoff-strategy.js +0 -32
- package/dist/strategies/exponential-backoff-strategy.js.map +0 -1
- package/dist/tools/handlers/fetch-links/link-extractor.d.ts +0 -4
- package/dist/tools/handlers/fetch-links/link-extractor.d.ts.map +0 -1
- package/dist/tools/handlers/fetch-links/link-extractor.js +0 -159
- package/dist/tools/handlers/fetch-links/link-extractor.js.map +0 -1
- package/dist/tools/handlers/fetch-links.tool.d.ts +0 -5
- package/dist/tools/handlers/fetch-links.tool.d.ts.map +0 -1
- package/dist/tools/handlers/fetch-links.tool.js +0 -98
- package/dist/tools/handlers/fetch-links.tool.js.map +0 -1
- package/dist/tools/handlers/fetch-markdown.tool.d.ts +0 -11
- package/dist/tools/handlers/fetch-markdown.tool.d.ts.map +0 -1
- package/dist/tools/handlers/fetch-markdown.tool.js +0 -97
- package/dist/tools/handlers/fetch-markdown.tool.js.map +0 -1
- package/dist/tools/handlers/fetch-single.shared.d.ts +0 -31
- package/dist/tools/handlers/fetch-single.shared.d.ts.map +0 -1
- package/dist/tools/handlers/fetch-single.shared.js +0 -223
- package/dist/tools/handlers/fetch-single.shared.js.map +0 -1
- package/dist/tools/handlers/fetch-url.tool.d.ts +0 -10
- package/dist/tools/handlers/fetch-url.tool.d.ts.map +0 -1
- package/dist/tools/handlers/fetch-url.tool.js +0 -119
- package/dist/tools/handlers/fetch-url.tool.js.map +0 -1
- package/dist/tools/handlers/fetch-urls/processor.d.ts +0 -13
- package/dist/tools/handlers/fetch-urls/processor.d.ts.map +0 -1
- package/dist/tools/handlers/fetch-urls/processor.js +0 -153
- package/dist/tools/handlers/fetch-urls/processor.js.map +0 -1
- package/dist/tools/handlers/fetch-urls/response.d.ts +0 -3
- package/dist/tools/handlers/fetch-urls/response.d.ts.map +0 -1
- package/dist/tools/handlers/fetch-urls/response.js +0 -79
- package/dist/tools/handlers/fetch-urls/response.js.map +0 -1
- package/dist/tools/handlers/fetch-urls/validation.d.ts +0 -5
- package/dist/tools/handlers/fetch-urls/validation.d.ts.map +0 -1
- package/dist/tools/handlers/fetch-urls/validation.js +0 -18
- package/dist/tools/handlers/fetch-urls/validation.js.map +0 -1
- package/dist/tools/handlers/fetch-urls.tool.d.ts +0 -5
- package/dist/tools/handlers/fetch-urls.tool.d.ts.map +0 -1
- package/dist/tools/handlers/fetch-urls.tool.js +0 -124
- package/dist/tools/handlers/fetch-urls.tool.js.map +0 -1
- package/dist/tools/index.d.ts +0 -3
- package/dist/tools/index.d.ts.map +0 -1
- package/dist/tools/index.js +0 -37
- package/dist/tools/index.js.map +0 -1
- package/dist/tools/schemas.d.ts +0 -12
- package/dist/tools/schemas.d.ts.map +0 -1
- package/dist/tools/schemas.js +0 -21
- package/dist/tools/schemas.js.map +0 -1
- package/dist/tools/utils/cache-vary.d.ts +0 -1
- package/dist/tools/utils/cache-vary.d.ts.map +0 -1
- package/dist/tools/utils/cache-vary.js +0 -12
- package/dist/tools/utils/cache-vary.js.map +0 -1
- package/dist/tools/utils/cached-markdown.d.ts +0 -5
- package/dist/tools/utils/cached-markdown.js +0 -46
- package/dist/tools/utils/common.d.ts +0 -5
- package/dist/tools/utils/common.d.ts.map +0 -1
- package/dist/tools/utils/common.js +0 -42
- package/dist/tools/utils/common.js.map +0 -1
- package/dist/tools/utils/content-shaping.d.ts +0 -4
- package/dist/tools/utils/content-shaping.js +0 -67
- package/dist/tools/utils/content-transform-async.d.ts +0 -6
- package/dist/tools/utils/content-transform-async.js +0 -33
- package/dist/tools/utils/content-transform-core.d.ts +0 -5
- package/dist/tools/utils/content-transform-core.js +0 -180
- package/dist/tools/utils/content-transform-workers.d.ts +0 -1
- package/dist/tools/utils/content-transform-workers.js +0 -1
- package/dist/tools/utils/content-transform.d.ts +0 -3
- package/dist/tools/utils/content-transform.d.ts.map +0 -1
- package/dist/tools/utils/content-transform.js +0 -41
- package/dist/tools/utils/content-transform.js.map +0 -1
- package/dist/tools/utils/fetch-pipeline.d.ts +0 -2
- package/dist/tools/utils/fetch-pipeline.d.ts.map +0 -1
- package/dist/tools/utils/fetch-pipeline.js +0 -98
- package/dist/tools/utils/fetch-pipeline.js.map +0 -1
- package/dist/tools/utils/frontmatter.d.ts +0 -3
- package/dist/tools/utils/frontmatter.js +0 -73
- package/dist/tools/utils/index.d.ts +0 -4
- package/dist/tools/utils/index.d.ts.map +0 -1
- package/dist/tools/utils/index.js +0 -3
- package/dist/tools/utils/index.js.map +0 -1
- package/dist/tools/utils/inline-content.d.ts +0 -10
- package/dist/tools/utils/inline-content.d.ts.map +0 -1
- package/dist/tools/utils/inline-content.js +0 -35
- package/dist/tools/utils/inline-content.js.map +0 -1
- package/dist/tools/utils/markdown-heuristics.d.ts +0 -1
- package/dist/tools/utils/markdown-heuristics.js +0 -19
- package/dist/tools/utils/markdown-signals.d.ts +0 -1
- package/dist/tools/utils/markdown-signals.js +0 -19
- package/dist/tools/utils/markdown-toc.d.ts +0 -3
- package/dist/tools/utils/markdown-toc.d.ts.map +0 -1
- package/dist/tools/utils/markdown-toc.js +0 -35
- package/dist/tools/utils/markdown-toc.js.map +0 -1
- package/dist/tools/utils/raw-markdown-frontmatter.d.ts +0 -3
- package/dist/tools/utils/raw-markdown-frontmatter.js +0 -73
- package/dist/tools/utils/raw-markdown.d.ts +0 -6
- package/dist/tools/utils/raw-markdown.js +0 -149
- package/dist/tools/utils/response-builder.d.ts +0 -3
- package/dist/tools/utils/response-builder.d.ts.map +0 -1
- package/dist/tools/utils/response-builder.js +0 -24
- package/dist/tools/utils/response-builder.js.map +0 -1
- package/dist/tools/utils/tool-response.d.ts +0 -9
- package/dist/tools/utils/tool-response.d.ts.map +0 -1
- package/dist/tools/utils/tool-response.js +0 -19
- package/dist/tools/utils/tool-response.js.map +0 -1
- package/dist/transformers/jsonl.transformer.d.ts +0 -2
- package/dist/transformers/jsonl.transformer.d.ts.map +0 -1
- package/dist/transformers/jsonl.transformer.js +0 -75
- package/dist/transformers/jsonl.transformer.js.map +0 -1
- package/dist/transformers/markdown/fenced-code-rule.d.ts +0 -2
- package/dist/transformers/markdown/fenced-code-rule.js +0 -38
- package/dist/transformers/markdown/frontmatter.d.ts +0 -2
- package/dist/transformers/markdown/frontmatter.js +0 -45
- package/dist/transformers/markdown/noise-rule.d.ts +0 -2
- package/dist/transformers/markdown/noise-rule.js +0 -80
- package/dist/transformers/markdown/turndown-instance.d.ts +0 -2
- package/dist/transformers/markdown/turndown-instance.js +0 -19
- package/dist/transformers/markdown.d.ts +0 -5
- package/dist/transformers/markdown.js +0 -314
- package/dist/transformers/markdown.transformer.d.ts +0 -2
- package/dist/transformers/markdown.transformer.d.ts.map +0 -1
- package/dist/transformers/markdown.transformer.js +0 -14
- package/dist/transformers/markdown.transformer.js.map +0 -1
- package/dist/types/content.types.d.ts +0 -63
- package/dist/types/content.types.d.ts.map +0 -1
- package/dist/types/content.types.js +0 -2
- package/dist/types/content.types.js.map +0 -1
- package/dist/types/index.d.ts +0 -2
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -2
- package/dist/types/index.js.map +0 -1
- package/dist/types/schemas.d.ts +0 -49
- package/dist/types/schemas.d.ts.map +0 -1
- package/dist/types/schemas.js +0 -5
- package/dist/types/schemas.js.map +0 -1
- package/dist/utils/cached-payload.d.ts +0 -7
- package/dist/utils/cached-payload.js +0 -36
- package/dist/utils/cancellation.d.ts +0 -1
- package/dist/utils/cancellation.js +0 -18
- package/dist/utils/code-language-bash.d.ts +0 -1
- package/dist/utils/code-language-bash.js +0 -48
- package/dist/utils/code-language-core.d.ts +0 -2
- package/dist/utils/code-language-core.js +0 -13
- package/dist/utils/code-language-detectors.d.ts +0 -5
- package/dist/utils/code-language-detectors.js +0 -142
- package/dist/utils/code-language-helpers.d.ts +0 -5
- package/dist/utils/code-language-helpers.js +0 -62
- package/dist/utils/code-language-parsing.d.ts +0 -5
- package/dist/utils/code-language-parsing.js +0 -62
- package/dist/utils/code-language.d.ts +0 -2
- package/dist/utils/code-language.d.ts.map +0 -1
- package/dist/utils/code-language.js +0 -260
- package/dist/utils/code-language.js.map +0 -1
- package/dist/utils/concurrency.d.ts +0 -3
- package/dist/utils/concurrency.d.ts.map +0 -1
- package/dist/utils/concurrency.js +0 -38
- package/dist/utils/concurrency.js.map +0 -1
- package/dist/utils/content-cleaner.d.ts +0 -5
- package/dist/utils/content-cleaner.d.ts.map +0 -1
- package/dist/utils/content-cleaner.js +0 -77
- package/dist/utils/content-cleaner.js.map +0 -1
- package/dist/utils/crypto.d.ts +0 -2
- package/dist/utils/crypto.d.ts.map +0 -1
- package/dist/utils/crypto.js +0 -32
- package/dist/utils/crypto.js.map +0 -1
- package/dist/utils/download-url.d.ts +0 -16
- package/dist/utils/download-url.d.ts.map +0 -1
- package/dist/utils/download-url.js +0 -30
- package/dist/utils/download-url.js.map +0 -1
- package/dist/utils/error-details.d.ts +0 -3
- package/dist/utils/error-details.js +0 -12
- package/dist/utils/error-utils.d.ts +0 -3
- package/dist/utils/error-utils.d.ts.map +0 -1
- package/dist/utils/error-utils.js +0 -12
- package/dist/utils/error-utils.js.map +0 -1
- package/dist/utils/filename-generator.d.ts +0 -1
- package/dist/utils/filename-generator.d.ts.map +0 -1
- package/dist/utils/filename-generator.js +0 -81
- package/dist/utils/filename-generator.js.map +0 -1
- package/dist/utils/guards.d.ts +0 -1
- package/dist/utils/guards.js +0 -3
- package/dist/utils/header-normalizer.d.ts +0 -5
- package/dist/utils/header-normalizer.d.ts.map +0 -1
- package/dist/utils/header-normalizer.js +0 -31
- package/dist/utils/header-normalizer.js.map +0 -1
- package/dist/utils/host-normalizer.d.ts +0 -1
- package/dist/utils/host-normalizer.js +0 -37
- package/dist/utils/html-truncator.d.ts +0 -1
- package/dist/utils/html-truncator.d.ts.map +0 -1
- package/dist/utils/html-truncator.js +0 -13
- package/dist/utils/html-truncator.js.map +0 -1
- package/dist/utils/ip-address.d.ts +0 -4
- package/dist/utils/ip-address.js +0 -6
- package/dist/utils/language-detector.d.ts +0 -2
- package/dist/utils/language-detector.d.ts.map +0 -1
- package/dist/utils/language-detector.js +0 -39
- package/dist/utils/language-detector.js.map +0 -1
- package/dist/utils/sanitizer.d.ts +0 -2
- package/dist/utils/sanitizer.d.ts.map +0 -1
- package/dist/utils/sanitizer.js +0 -20
- package/dist/utils/sanitizer.js.map +0 -1
- package/dist/utils/tool-error-handler.d.ts +0 -3
- package/dist/utils/tool-error-handler.d.ts.map +0 -1
- package/dist/utils/tool-error-handler.js +0 -31
- package/dist/utils/tool-error-handler.js.map +0 -1
- package/dist/utils/url-redactor.d.ts +0 -1
- package/dist/utils/url-redactor.js +0 -13
- package/dist/utils/url-sanitizer.d.ts +0 -2
- package/dist/utils/url-sanitizer.d.ts.map +0 -1
- package/dist/utils/url-sanitizer.js +0 -12
- package/dist/utils/url-sanitizer.js.map +0 -1
- package/dist/utils/url-transformer.d.ts +0 -7
- package/dist/utils/url-transformer.js +0 -147
- package/dist/utils/url-validator.d.ts +0 -6
- package/dist/utils/url-validator.d.ts.map +0 -1
- package/dist/utils/url-validator.js +0 -156
- package/dist/utils/url-validator.js.map +0 -1
- package/dist/workers/content-transform.worker.d.ts +0 -1
- package/dist/workers/content-transform.worker.js +0 -40
package/dist/http/auth-static.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { InvalidTokenError } from '@modelcontextprotocol/sdk/server/auth/errors.js';
|
|
2
|
-
import { config } from '../config/index.js';
|
|
3
|
-
import { timingSafeEqualUtf8 } from '../utils/crypto.js';
|
|
4
|
-
const STATIC_TOKEN_TTL_SECONDS = 60 * 60 * 24;
|
|
5
|
-
function buildStaticAuthInfo(token) {
|
|
6
|
-
return {
|
|
7
|
-
token,
|
|
8
|
-
clientId: 'static-token',
|
|
9
|
-
scopes: config.auth.requiredScopes,
|
|
10
|
-
expiresAt: Math.floor(Date.now() / 1000) + STATIC_TOKEN_TTL_SECONDS,
|
|
11
|
-
resource: config.auth.resourceUrl,
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
export function verifyStaticToken(token) {
|
|
15
|
-
if (config.auth.staticTokens.length === 0) {
|
|
16
|
-
throw new InvalidTokenError('No static tokens configured');
|
|
17
|
-
}
|
|
18
|
-
const matched = config.auth.staticTokens.some((candidate) => timingSafeEqualUtf8(candidate, token));
|
|
19
|
-
if (!matched) {
|
|
20
|
-
throw new InvalidTokenError('Invalid token');
|
|
21
|
-
}
|
|
22
|
-
return buildStaticAuthInfo(token);
|
|
23
|
-
}
|
package/dist/http/auth.d.ts
DELETED
package/dist/http/auth.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/http/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAsC/D,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,MAAM,GAChB,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,KAAK,IAAI,CAa3D"}
|
package/dist/http/auth.js
DELETED
|
@@ -1,269 +0,0 @@
|
|
|
1
|
-
import { InvalidTokenError, ServerError, } from '@modelcontextprotocol/sdk/server/auth/errors.js';
|
|
2
|
-
import { requireBearerAuth } from '@modelcontextprotocol/sdk/server/auth/middleware/bearerAuth.js';
|
|
3
|
-
import { getOAuthProtectedResourceMetadataUrl, mcpAuthMetadataRouter, } from '@modelcontextprotocol/sdk/server/auth/router.js';
|
|
4
|
-
import { config } from '../config/index.js';
|
|
5
|
-
import { timingSafeEqualUtf8 } from '../utils/crypto.js';
|
|
6
|
-
import { isRecord } from '../utils/guards.js';
|
|
7
|
-
const STATIC_TOKEN_TTL_SECONDS = 60 * 60 * 24;
|
|
8
|
-
function stripHash(url) {
|
|
9
|
-
const copy = new URL(url.href);
|
|
10
|
-
copy.hash = '';
|
|
11
|
-
return copy.href;
|
|
12
|
-
}
|
|
13
|
-
function parseScopes(value) {
|
|
14
|
-
if (typeof value === 'string') {
|
|
15
|
-
return value
|
|
16
|
-
.split(' ')
|
|
17
|
-
.map((scope) => scope.trim())
|
|
18
|
-
.filter((scope) => scope.length > 0);
|
|
19
|
-
}
|
|
20
|
-
if (Array.isArray(value)) {
|
|
21
|
-
return value.filter((scope) => typeof scope === 'string');
|
|
22
|
-
}
|
|
23
|
-
return [];
|
|
24
|
-
}
|
|
25
|
-
function parseResourceUrl(value) {
|
|
26
|
-
if (typeof value !== 'string')
|
|
27
|
-
return undefined;
|
|
28
|
-
if (!URL.canParse(value))
|
|
29
|
-
return undefined;
|
|
30
|
-
return new URL(value);
|
|
31
|
-
}
|
|
32
|
-
function parseAudResource(aud) {
|
|
33
|
-
if (typeof aud === 'string') {
|
|
34
|
-
return parseResourceUrl(aud);
|
|
35
|
-
}
|
|
36
|
-
if (Array.isArray(aud)) {
|
|
37
|
-
for (const entry of aud) {
|
|
38
|
-
const parsed = parseResourceUrl(entry);
|
|
39
|
-
if (parsed)
|
|
40
|
-
return parsed;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return undefined;
|
|
44
|
-
}
|
|
45
|
-
function extractResource(data) {
|
|
46
|
-
const resource = parseResourceUrl(data.resource);
|
|
47
|
-
if (resource)
|
|
48
|
-
return resource;
|
|
49
|
-
return parseAudResource(data.aud);
|
|
50
|
-
}
|
|
51
|
-
function extractScopes(data) {
|
|
52
|
-
if (data.scope !== undefined) {
|
|
53
|
-
return parseScopes(data.scope);
|
|
54
|
-
}
|
|
55
|
-
if (data.scopes !== undefined) {
|
|
56
|
-
return parseScopes(data.scopes);
|
|
57
|
-
}
|
|
58
|
-
if (data.scp !== undefined) {
|
|
59
|
-
return parseScopes(data.scp);
|
|
60
|
-
}
|
|
61
|
-
return [];
|
|
62
|
-
}
|
|
63
|
-
function readExpiresAt(data) {
|
|
64
|
-
const expiresAt = typeof data.exp === 'number' ? data.exp : Number.NaN;
|
|
65
|
-
if (!Number.isFinite(expiresAt)) {
|
|
66
|
-
throw new InvalidTokenError('Token has no expiration time');
|
|
67
|
-
}
|
|
68
|
-
return expiresAt;
|
|
69
|
-
}
|
|
70
|
-
function resolveClientId(data) {
|
|
71
|
-
if (typeof data.client_id === 'string')
|
|
72
|
-
return data.client_id;
|
|
73
|
-
if (typeof data.cid === 'string')
|
|
74
|
-
return data.cid;
|
|
75
|
-
if (typeof data.sub === 'string')
|
|
76
|
-
return data.sub;
|
|
77
|
-
return 'unknown';
|
|
78
|
-
}
|
|
79
|
-
function ensureResourceMatch(resource) {
|
|
80
|
-
if (resource && stripHash(resource) !== stripHash(config.auth.resourceUrl)) {
|
|
81
|
-
throw new InvalidTokenError('Token resource mismatch');
|
|
82
|
-
}
|
|
83
|
-
return resource;
|
|
84
|
-
}
|
|
85
|
-
function buildIntrospectionAuthInfo(token, data) {
|
|
86
|
-
const resource = ensureResourceMatch(extractResource(data));
|
|
87
|
-
return {
|
|
88
|
-
token,
|
|
89
|
-
clientId: resolveClientId(data),
|
|
90
|
-
scopes: extractScopes(data),
|
|
91
|
-
expiresAt: readExpiresAt(data),
|
|
92
|
-
resource: resource ?? config.auth.resourceUrl,
|
|
93
|
-
extra: data,
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
function buildBasicAuthHeader(clientId, clientSecret) {
|
|
97
|
-
const secret = clientSecret ?? '';
|
|
98
|
-
const basic = Buffer.from(`${clientId}:${secret}`, 'utf8').toString('base64');
|
|
99
|
-
return `Basic ${basic}`;
|
|
100
|
-
}
|
|
101
|
-
function buildIntrospectionRequest(token, resourceUrl, clientId, clientSecret) {
|
|
102
|
-
const body = new URLSearchParams({
|
|
103
|
-
token,
|
|
104
|
-
token_type_hint: 'access_token',
|
|
105
|
-
resource: stripHash(resourceUrl),
|
|
106
|
-
}).toString();
|
|
107
|
-
const headers = {
|
|
108
|
-
'content-type': 'application/x-www-form-urlencoded',
|
|
109
|
-
};
|
|
110
|
-
if (clientId) {
|
|
111
|
-
headers.authorization = buildBasicAuthHeader(clientId, clientSecret);
|
|
112
|
-
}
|
|
113
|
-
return { body, headers };
|
|
114
|
-
}
|
|
115
|
-
async function requestIntrospection(introspectionUrl, request, timeoutMs) {
|
|
116
|
-
const response = await fetch(introspectionUrl, {
|
|
117
|
-
method: 'POST',
|
|
118
|
-
headers: request.headers,
|
|
119
|
-
body: request.body,
|
|
120
|
-
signal: AbortSignal.timeout(timeoutMs),
|
|
121
|
-
});
|
|
122
|
-
if (!response.ok) {
|
|
123
|
-
await response.body?.cancel();
|
|
124
|
-
throw new ServerError(`Token introspection failed: ${response.status}`);
|
|
125
|
-
}
|
|
126
|
-
return response.json();
|
|
127
|
-
}
|
|
128
|
-
function parseIntrospectionPayload(payload) {
|
|
129
|
-
if (!isRecord(payload) || Array.isArray(payload)) {
|
|
130
|
-
throw new ServerError('Invalid introspection response');
|
|
131
|
-
}
|
|
132
|
-
if (payload.active !== true) {
|
|
133
|
-
throw new InvalidTokenError('Token is inactive');
|
|
134
|
-
}
|
|
135
|
-
return payload;
|
|
136
|
-
}
|
|
137
|
-
async function verifyWithIntrospection(token) {
|
|
138
|
-
const { auth } = config;
|
|
139
|
-
if (!auth.introspectionUrl) {
|
|
140
|
-
throw new ServerError('Token introspection is not configured');
|
|
141
|
-
}
|
|
142
|
-
const request = buildIntrospectionRequest(token, auth.resourceUrl, auth.clientId, auth.clientSecret);
|
|
143
|
-
const payload = await requestIntrospection(auth.introspectionUrl, request, auth.introspectionTimeoutMs);
|
|
144
|
-
return buildIntrospectionAuthInfo(token, parseIntrospectionPayload(payload));
|
|
145
|
-
}
|
|
146
|
-
function buildStaticAuthInfo(token) {
|
|
147
|
-
return {
|
|
148
|
-
token,
|
|
149
|
-
clientId: 'static-token',
|
|
150
|
-
scopes: config.auth.requiredScopes,
|
|
151
|
-
expiresAt: Math.floor(Date.now() / 1000) + STATIC_TOKEN_TTL_SECONDS,
|
|
152
|
-
resource: config.auth.resourceUrl,
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
function verifyStaticToken(token) {
|
|
156
|
-
if (config.auth.staticTokens.length === 0) {
|
|
157
|
-
throw new InvalidTokenError('No static tokens configured');
|
|
158
|
-
}
|
|
159
|
-
const matched = config.auth.staticTokens.some((candidate) => timingSafeEqualUtf8(candidate, token));
|
|
160
|
-
if (!matched) {
|
|
161
|
-
throw new InvalidTokenError('Invalid token');
|
|
162
|
-
}
|
|
163
|
-
return buildStaticAuthInfo(token);
|
|
164
|
-
}
|
|
165
|
-
function normalizeHeaderValue(header) {
|
|
166
|
-
return Array.isArray(header) ? header[0] : header;
|
|
167
|
-
}
|
|
168
|
-
function getApiKeyHeader(req) {
|
|
169
|
-
const apiKeyHeader = normalizeHeaderValue(req.headers['x-api-key']);
|
|
170
|
-
return apiKeyHeader ? apiKeyHeader.trim() : null;
|
|
171
|
-
}
|
|
172
|
-
function createLegacyApiKeyMiddleware() {
|
|
173
|
-
return (req, _res, next) => {
|
|
174
|
-
if (config.auth.mode !== 'static') {
|
|
175
|
-
next();
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
if (!req.headers.authorization) {
|
|
179
|
-
const apiKey = getApiKeyHeader(req);
|
|
180
|
-
if (apiKey) {
|
|
181
|
-
req.headers.authorization = `Bearer ${apiKey}`;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
next();
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
async function verifyAccessToken(token) {
|
|
188
|
-
if (config.auth.mode === 'oauth') {
|
|
189
|
-
return verifyWithIntrospection(token);
|
|
190
|
-
}
|
|
191
|
-
return verifyStaticToken(token);
|
|
192
|
-
}
|
|
193
|
-
function resolveMetadataUrl() {
|
|
194
|
-
if (config.auth.mode !== 'oauth')
|
|
195
|
-
return null;
|
|
196
|
-
return getOAuthProtectedResourceMetadataUrl(new URL(config.auth.resourceUrl));
|
|
197
|
-
}
|
|
198
|
-
function resolveOptionalScopes(requiredScopes) {
|
|
199
|
-
return requiredScopes.length > 0 ? [...requiredScopes] : undefined;
|
|
200
|
-
}
|
|
201
|
-
function resolveOAuthMetadataParams(authConfig) {
|
|
202
|
-
const { issuerUrl, authorizationUrl, tokenUrl, revocationUrl, registrationUrl, requiredScopes, } = authConfig;
|
|
203
|
-
if (!issuerUrl || !authorizationUrl || !tokenUrl)
|
|
204
|
-
return null;
|
|
205
|
-
return {
|
|
206
|
-
issuerUrl,
|
|
207
|
-
authorizationUrl,
|
|
208
|
-
tokenUrl,
|
|
209
|
-
revocationUrl,
|
|
210
|
-
registrationUrl,
|
|
211
|
-
requiredScopes,
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
function buildBaseOAuthMetadata(params) {
|
|
215
|
-
return {
|
|
216
|
-
issuer: params.issuerUrl.href,
|
|
217
|
-
authorization_endpoint: params.authorizationUrl.href,
|
|
218
|
-
response_types_supported: ['code'],
|
|
219
|
-
code_challenge_methods_supported: ['S256'],
|
|
220
|
-
token_endpoint: params.tokenUrl.href,
|
|
221
|
-
token_endpoint_auth_methods_supported: ['client_secret_post', 'none'],
|
|
222
|
-
grant_types_supported: ['authorization_code', 'refresh_token'],
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
function applyOptionalScopes(metadata, requiredScopes) {
|
|
226
|
-
const scopesSupported = resolveOptionalScopes(requiredScopes);
|
|
227
|
-
if (scopesSupported !== undefined) {
|
|
228
|
-
metadata.scopes_supported = scopesSupported;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
function applyOptionalEndpoint(metadata, key, url) {
|
|
232
|
-
if (!url)
|
|
233
|
-
return;
|
|
234
|
-
metadata[key] = url.href;
|
|
235
|
-
}
|
|
236
|
-
function buildOAuthMetadata(params) {
|
|
237
|
-
const oauthMetadata = buildBaseOAuthMetadata(params);
|
|
238
|
-
applyOptionalScopes(oauthMetadata, params.requiredScopes);
|
|
239
|
-
applyOptionalEndpoint(oauthMetadata, 'revocation_endpoint', params.revocationUrl);
|
|
240
|
-
applyOptionalEndpoint(oauthMetadata, 'registration_endpoint', params.registrationUrl);
|
|
241
|
-
return oauthMetadata;
|
|
242
|
-
}
|
|
243
|
-
export function createAuthMiddleware() {
|
|
244
|
-
const metadataUrl = resolveMetadataUrl();
|
|
245
|
-
const authHandler = requireBearerAuth({
|
|
246
|
-
verifier: { verifyAccessToken },
|
|
247
|
-
requiredScopes: config.auth.requiredScopes,
|
|
248
|
-
...(metadataUrl ? { resourceMetadataUrl: metadataUrl } : {}),
|
|
249
|
-
});
|
|
250
|
-
const legacyHandler = createLegacyApiKeyMiddleware();
|
|
251
|
-
return (req, res, next) => {
|
|
252
|
-
legacyHandler(req, res, () => {
|
|
253
|
-
authHandler(req, res, next);
|
|
254
|
-
});
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
export function createAuthMetadataRouter() {
|
|
258
|
-
if (config.auth.mode !== 'oauth')
|
|
259
|
-
return null;
|
|
260
|
-
const oauthMetadataParams = resolveOAuthMetadataParams(config.auth);
|
|
261
|
-
if (!oauthMetadataParams)
|
|
262
|
-
return null;
|
|
263
|
-
return mcpAuthMetadataRouter({
|
|
264
|
-
oauthMetadata: buildOAuthMetadata(oauthMetadataParams),
|
|
265
|
-
resourceServerUrl: config.auth.resourceUrl,
|
|
266
|
-
scopesSupported: config.auth.requiredScopes,
|
|
267
|
-
resourceName: config.server.name,
|
|
268
|
-
});
|
|
269
|
-
}
|
package/dist/http/auth.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/http/auth.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD,SAAS,oBAAoB,CAC3B,MAAqC;IAErC,OAAO,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;AACpD,CAAC;AAED,SAAS,gBAAgB,CAAC,CAAS,EAAE,CAAS;IAC5C,OAAO,mBAAmB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AACnC,CAAC;AAED,SAAS,mBAAmB,CAAC,GAAY,EAAE,SAAiB;IAC1D,IAAI,CAAC,SAAS;QAAE,OAAO,KAAK,CAAC;IAE7B,MAAM,WAAW,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC;IACxC,IAAI,WAAW,EAAE,CAAC;QAChB,OAAO,gBAAgB,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;IAClD,CAAC;IAED,MAAM,YAAY,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC;IAC1C,OAAO,YAAY,CAAC,CAAC,CAAC,gBAAgB,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AAC1E,CAAC;AAED,SAAS,cAAc,CAAC,GAAY;IAClC,MAAM,UAAU,GAAG,oBAAoB,CAAC,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IACnE,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,SAAS,CAAC;QAAE,OAAO,IAAI,CAAC;IACpD,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;IACxD,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AACzC,CAAC;AAED,SAAS,eAAe,CAAC,GAAY;IACnC,MAAM,YAAY,GAAG,oBAAoB,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;IACpE,OAAO,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,oBAAoB,CAClC,SAAiB;IAEjB,OAAO,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAQ,EAAE;QAC/D,IAAI,mBAAmB,CAAC,GAAG,EAAE,SAAS,CAAC,EAAE,CAAC;YACxC,IAAI,EAAE,CAAC;YACP,OAAO;QACT,CAAC;QAED,GAAG,CAAC,GAAG,CACL,kBAAkB,EAClB,+FAA+F,CAChG,CAAC;QACF,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC,CAAC;IAClD,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import { config } from '../config/index.js';
|
|
3
|
-
import { runWithRequestContext } from '../services/context.js';
|
|
4
|
-
import { logDebug } from '../services/logger.js';
|
|
5
|
-
import { normalizeHost } from '../utils/host-normalizer.js';
|
|
6
|
-
import { getSessionId } from './mcp-sessions.js';
|
|
7
|
-
const LOOPBACK_HOSTS = new Set(['localhost', '127.0.0.1', '::1']);
|
|
8
|
-
function getNonEmptyStringHeader(value) {
|
|
9
|
-
if (typeof value !== 'string')
|
|
10
|
-
return null;
|
|
11
|
-
const trimmed = value.trim();
|
|
12
|
-
return trimmed === '' ? null : trimmed;
|
|
13
|
-
}
|
|
14
|
-
function respondHostNotAllowed(res) {
|
|
15
|
-
res.status(403).json({
|
|
16
|
-
error: 'Host not allowed',
|
|
17
|
-
code: 'HOST_NOT_ALLOWED',
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
function respondOriginNotAllowed(res) {
|
|
21
|
-
res.status(403).json({
|
|
22
|
-
error: 'Origin not allowed',
|
|
23
|
-
code: 'ORIGIN_NOT_ALLOWED',
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
function tryParseOriginHostname(originHeader) {
|
|
27
|
-
try {
|
|
28
|
-
return new URL(originHeader).hostname.toLowerCase();
|
|
29
|
-
}
|
|
30
|
-
catch {
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
function isWildcardHost(host) {
|
|
35
|
-
return host === '0.0.0.0' || host === '::';
|
|
36
|
-
}
|
|
37
|
-
function addLoopbackHosts(allowedHosts) {
|
|
38
|
-
for (const host of LOOPBACK_HOSTS) {
|
|
39
|
-
allowedHosts.add(host);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
function addConfiguredHost(allowedHosts) {
|
|
43
|
-
const configuredHost = normalizeHost(config.server.host);
|
|
44
|
-
if (!configuredHost)
|
|
45
|
-
return;
|
|
46
|
-
if (isWildcardHost(configuredHost))
|
|
47
|
-
return;
|
|
48
|
-
allowedHosts.add(configuredHost);
|
|
49
|
-
}
|
|
50
|
-
function addExplicitAllowedHosts(allowedHosts) {
|
|
51
|
-
for (const host of config.security.allowedHosts) {
|
|
52
|
-
const normalized = normalizeHost(host);
|
|
53
|
-
if (!normalized) {
|
|
54
|
-
logDebug('Ignoring invalid allowed host entry', { host });
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
allowedHosts.add(normalized);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
function buildAllowedHosts() {
|
|
61
|
-
const allowedHosts = new Set();
|
|
62
|
-
addLoopbackHosts(allowedHosts);
|
|
63
|
-
addConfiguredHost(allowedHosts);
|
|
64
|
-
addExplicitAllowedHosts(allowedHosts);
|
|
65
|
-
return allowedHosts;
|
|
66
|
-
}
|
|
67
|
-
function createHostValidationMiddleware() {
|
|
68
|
-
const allowedHosts = buildAllowedHosts();
|
|
69
|
-
return (req, res, next) => {
|
|
70
|
-
const hostHeader = typeof req.headers.host === 'string' ? req.headers.host : '';
|
|
71
|
-
const normalized = normalizeHost(hostHeader);
|
|
72
|
-
if (!normalized || !allowedHosts.has(normalized)) {
|
|
73
|
-
respondHostNotAllowed(res);
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
next();
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
function createOriginValidationMiddleware() {
|
|
80
|
-
const allowedHosts = buildAllowedHosts();
|
|
81
|
-
return (req, res, next) => {
|
|
82
|
-
const originHeader = getNonEmptyStringHeader(req.headers.origin);
|
|
83
|
-
if (!originHeader) {
|
|
84
|
-
next();
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
const originHostname = tryParseOriginHostname(originHeader);
|
|
88
|
-
if (!originHostname || !allowedHosts.has(originHostname)) {
|
|
89
|
-
respondOriginNotAllowed(res);
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
next();
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
function createJsonParseErrorHandler() {
|
|
96
|
-
return (err, _req, res, next) => {
|
|
97
|
-
if (err instanceof SyntaxError && 'body' in err) {
|
|
98
|
-
res.status(400).json({
|
|
99
|
-
jsonrpc: '2.0',
|
|
100
|
-
error: {
|
|
101
|
-
code: -32700,
|
|
102
|
-
message: 'Parse error: Invalid JSON',
|
|
103
|
-
},
|
|
104
|
-
id: null,
|
|
105
|
-
});
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
next();
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
function createContextMiddleware() {
|
|
112
|
-
return (req, _res, next) => {
|
|
113
|
-
const requestId = randomUUID();
|
|
114
|
-
const sessionId = getSessionId(req);
|
|
115
|
-
const context = sessionId === undefined
|
|
116
|
-
? { requestId, operationId: requestId }
|
|
117
|
-
: { requestId, operationId: requestId, sessionId };
|
|
118
|
-
runWithRequestContext(context, () => {
|
|
119
|
-
next();
|
|
120
|
-
});
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
function registerHealthRoute(app) {
|
|
124
|
-
app.get('/health', (_req, res) => {
|
|
125
|
-
res.json({
|
|
126
|
-
status: 'healthy',
|
|
127
|
-
name: config.server.name,
|
|
128
|
-
version: config.server.version,
|
|
129
|
-
uptime: process.uptime(),
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
export function attachBaseMiddleware(options) {
|
|
134
|
-
const { app, jsonParser, rateLimitMiddleware, corsMiddleware } = options;
|
|
135
|
-
app.use(createHostValidationMiddleware());
|
|
136
|
-
app.use(createOriginValidationMiddleware());
|
|
137
|
-
app.use(jsonParser);
|
|
138
|
-
app.use(createContextMiddleware());
|
|
139
|
-
app.use(createJsonParseErrorHandler());
|
|
140
|
-
app.use(corsMiddleware);
|
|
141
|
-
app.use('/mcp', rateLimitMiddleware);
|
|
142
|
-
registerHealthRoute(app);
|
|
143
|
-
}
|
package/dist/http/cors.d.ts
DELETED
package/dist/http/cors.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cors.d.ts","sourceRoot":"","sources":["../../src/http/cors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE/D,UAAU,WAAW;IACnB,QAAQ,CAAC,cAAc,EAAE,MAAM,EAAE,CAAC;IAClC,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC;CACnC;AAgBD,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,WAAW,GACnB,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,KAAK,IAAI,CAoB3D"}
|
package/dist/http/cors.js
DELETED
package/dist/http/cors.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cors.js","sourceRoot":"","sources":["../../src/http/cors.ts"],"names":[],"mappings":"AAOA,SAAS,eAAe,CACtB,MAA0B,EAC1B,OAAoB;IAEpB,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IACzB,IAAI,OAAO,CAAC,eAAe;QAAE,OAAO,IAAI,CAAC;IACzC,IAAI,OAAO,CAAC,cAAc,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACtD,OAAO,OAAO,CAAC,cAAc,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AACjD,CAAC;AAED,SAAS,aAAa,CAAC,MAAc;IACnC,OAAO,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AAC9B,CAAC;AAED,MAAM,UAAU,oBAAoB,CAClC,OAAoB;IAEpB,OAAO,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAQ,EAAE;QAC/D,MAAM,MAAM,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;QAClC,IAAI,uBAAuB,CAAC,MAAM,CAAC,EAAE,CAAC;YACpC,IAAI,EAAE,CAAC;YACP,OAAO;QACT,CAAC;QAED,IAAI,CAAC,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;YAC5C,IAAI,EAAE,CAAC;YACP,OAAO;QACT,CAAC;QAED,IAAI,GAAG,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAC7B,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;YACpB,OAAO;QACT,CAAC;QAED,IAAI,EAAE,CAAC;IAC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AAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAoFD,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,cAAc,EACtB,UAAU,EAAE,UAAU,GACrB,eAAe,GAAG,IAAI,CAmBxB;AA+CD,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAQzD"}
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { config } from '../config/index.js';
|
|
2
|
-
import * as cache from '../services/cache.js';
|
|
3
|
-
import { logDebug } from '../services/logger.js';
|
|
4
|
-
import { parseCachedPayload, resolveCachedPayloadContent, } from '../utils/cached-payload.js';
|
|
5
|
-
import { generateSafeFilename } from '../utils/filename-generator.js';
|
|
6
|
-
const HASH_PATTERN = /^[a-f0-9.]+$/i;
|
|
7
|
-
function validateNamespace(namespace) {
|
|
8
|
-
return namespace === 'markdown';
|
|
9
|
-
}
|
|
10
|
-
function validateHash(hash) {
|
|
11
|
-
return HASH_PATTERN.test(hash) && hash.length >= 8 && hash.length <= 64;
|
|
12
|
-
}
|
|
13
|
-
function isSingleParam(value) {
|
|
14
|
-
return typeof value === 'string';
|
|
15
|
-
}
|
|
16
|
-
function parseDownloadParams(req) {
|
|
17
|
-
const { namespace, hash } = req.params;
|
|
18
|
-
if (!isSingleParam(namespace) || !isSingleParam(hash))
|
|
19
|
-
return null;
|
|
20
|
-
if (!namespace || !hash)
|
|
21
|
-
return null;
|
|
22
|
-
if (!validateNamespace(namespace))
|
|
23
|
-
return null;
|
|
24
|
-
if (!validateHash(hash))
|
|
25
|
-
return null;
|
|
26
|
-
return { namespace, hash };
|
|
27
|
-
}
|
|
28
|
-
function buildCacheKeyFromParams(params) {
|
|
29
|
-
return `${params.namespace}:${params.hash}`;
|
|
30
|
-
}
|
|
31
|
-
function respondBadRequest(res, message) {
|
|
32
|
-
res.status(400).json({
|
|
33
|
-
error: message,
|
|
34
|
-
code: 'BAD_REQUEST',
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
function respondNotFound(res) {
|
|
38
|
-
res.status(404).json({
|
|
39
|
-
error: 'Content not found or expired',
|
|
40
|
-
code: 'NOT_FOUND',
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
function respondServiceUnavailable(res) {
|
|
44
|
-
res.status(503).json({
|
|
45
|
-
error: 'Download service is disabled',
|
|
46
|
-
code: 'SERVICE_UNAVAILABLE',
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
function resolveDownloadPayload(params, cacheEntry) {
|
|
50
|
-
const payload = parseCachedPayload(cacheEntry.content);
|
|
51
|
-
if (!payload)
|
|
52
|
-
return null;
|
|
53
|
-
const content = resolveCachedPayloadContent(payload);
|
|
54
|
-
if (!content)
|
|
55
|
-
return null;
|
|
56
|
-
const safeTitle = typeof payload.title === 'string' ? payload.title : undefined;
|
|
57
|
-
const fileName = generateSafeFilename(cacheEntry.url, cacheEntry.title ?? safeTitle, params.hash, '.md');
|
|
58
|
-
return {
|
|
59
|
-
content,
|
|
60
|
-
contentType: 'text/markdown; charset=utf-8',
|
|
61
|
-
fileName,
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
function buildContentDisposition(fileName) {
|
|
65
|
-
const encodedName = encodeURIComponent(fileName).replace(/'/g, '%27');
|
|
66
|
-
return `attachment; filename="${fileName}"; filename*=UTF-8''${encodedName}`;
|
|
67
|
-
}
|
|
68
|
-
function sendDownloadPayload(res, payload) {
|
|
69
|
-
const disposition = buildContentDisposition(payload.fileName);
|
|
70
|
-
res.setHeader('Content-Type', payload.contentType);
|
|
71
|
-
res.setHeader('Content-Disposition', disposition);
|
|
72
|
-
res.setHeader('Cache-Control', `private, max-age=${config.cache.ttl}`);
|
|
73
|
-
res.setHeader('X-Content-Type-Options', 'nosniff');
|
|
74
|
-
res.send(payload.content);
|
|
75
|
-
}
|
|
76
|
-
function handleDownload(req, res) {
|
|
77
|
-
if (!config.cache.enabled) {
|
|
78
|
-
respondServiceUnavailable(res);
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
const params = parseDownloadParams(req);
|
|
82
|
-
if (!params) {
|
|
83
|
-
respondBadRequest(res, 'Invalid namespace or hash format');
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
const cacheKey = buildCacheKeyFromParams(params);
|
|
87
|
-
const cacheEntry = cache.get(cacheKey);
|
|
88
|
-
if (!cacheEntry) {
|
|
89
|
-
logDebug('Download request for missing cache key', { cacheKey });
|
|
90
|
-
respondNotFound(res);
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
const payload = resolveDownloadPayload(params, cacheEntry);
|
|
94
|
-
if (!payload) {
|
|
95
|
-
logDebug('Download payload unavailable', { cacheKey });
|
|
96
|
-
respondNotFound(res);
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
logDebug('Serving download', { cacheKey, fileName: payload.fileName });
|
|
100
|
-
sendDownloadPayload(res, payload);
|
|
101
|
-
}
|
|
102
|
-
export function registerDownloadRoutes(app) {
|
|
103
|
-
app.get('/mcp/downloads/:namespace/:hash', handleDownload);
|
|
104
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"download-routes.js","sourceRoot":"","sources":["../../src/http/download-routes.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAG5C,OAAO,KAAK,KAAK,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAEtE,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC,CAAC;AACtD,MAAM,YAAY,GAAG,eAAe,CAAC;AAmBrC,SAAS,iBAAiB,CAAC,SAAiB;IAC1C,OAAO,gBAAgB,CAAC,GAAG,CAAC,SAAS,CAAC,C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,CAAC,cAAc,CAAC,CAAC,CAAC;AAC3E,CAAC"}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { FetchError } from '../errors/app-error.js';
|
|
2
|
-
import { logError } from '../services/logger.js';
|
|
3
|
-
function getStatusCode(fetchError) {
|
|
4
|
-
return fetchError ? fetchError.statusCode : 500;
|
|
5
|
-
}
|
|
6
|
-
function getErrorCode(fetchError) {
|
|
7
|
-
return fetchError ? fetchError.code : 'INTERNAL_ERROR';
|
|
8
|
-
}
|
|
9
|
-
function getFetchErrorMessage(fetchError) {
|
|
10
|
-
return fetchError ? fetchError.message : 'Internal Server Error';
|
|
11
|
-
}
|
|
12
|
-
function getErrorDetails(fetchError) {
|
|
13
|
-
if (fetchError && Object.keys(fetchError.details).length > 0) {
|
|
14
|
-
return fetchError.details;
|
|
15
|
-
}
|
|
16
|
-
return undefined;
|
|
17
|
-
}
|
|
18
|
-
function resolveRetryAfter(fetchError) {
|
|
19
|
-
if (fetchError?.statusCode !== 429)
|
|
20
|
-
return undefined;
|
|
21
|
-
const { retryAfter } = fetchError.details;
|
|
22
|
-
return isRetryAfterValue(retryAfter) ? String(retryAfter) : undefined;
|
|
23
|
-
}
|
|
24
|
-
function isRetryAfterValue(value) {
|
|
25
|
-
return typeof value === 'number' || typeof value === 'string';
|
|
26
|
-
}
|
|
27
|
-
function setRetryAfterHeader(res, fetchError) {
|
|
28
|
-
const retryAfter = resolveRetryAfter(fetchError);
|
|
29
|
-
if (retryAfter === undefined)
|
|
30
|
-
return;
|
|
31
|
-
res.set('Retry-After', retryAfter);
|
|
32
|
-
}
|
|
33
|
-
function buildErrorResponse(fetchError) {
|
|
34
|
-
const details = getErrorDetails(fetchError);
|
|
35
|
-
const response = {
|
|
36
|
-
error: {
|
|
37
|
-
message: getFetchErrorMessage(fetchError),
|
|
38
|
-
code: getErrorCode(fetchError),
|
|
39
|
-
statusCode: getStatusCode(fetchError),
|
|
40
|
-
...(details && { details }),
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
return response;
|
|
44
|
-
}
|
|
45
|
-
export function errorHandler(err, req, res, next) {
|
|
46
|
-
if (res.headersSent) {
|
|
47
|
-
next(err);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
const fetchError = err instanceof FetchError ? err : null;
|
|
51
|
-
const statusCode = getStatusCode(fetchError);
|
|
52
|
-
logError(`HTTP ${statusCode}: ${err.message} - ${req.method} ${req.path}`, err);
|
|
53
|
-
setRetryAfterHeader(res, fetchError);
|
|
54
|
-
res.status(statusCode).json(buildErrorResponse(fetchError));
|
|
55
|
-
}
|