Creates a BaseEPClient.
When shared is provided the constructor reuses those pre-built resources
instead of allocating new ones; this is the mechanism used by the facade to
ensure all sub-clients share one cache and one rate-limiter.
Client configuration (used when shared is absent)
Optionalshared: EPSharedResourcesPre-built shared resources (passed by facade to sub-clients)
Protected ReadonlybaseEuropean Parliament API base URL.
Protected ReadonlycacheLRU cache for API responses.
Private ReadonlycacheShared cache hit/miss counters (shared via EPSharedResources when used as sub-client).
Protected ReadonlyenableEnable automatic retry on transient failures.
Protected ReadonlymaxMaximum allowed response body size in bytes.
Protected ReadonlymaxMaximum number of retry attempts.
Protected ReadonlyrateToken bucket rate limiter.
Protected ReadonlytimeoutRequest timeout in milliseconds.
PrivatebuildPrivateBuilds the full request URL from endpoint + optional params.
Optionalparams: Record<string, unknown>Clears all entries from the LRU cache.
PrivatefetchPrivatefetchPrivateExecutes the HTTP fetch with timeout/abort support and response size guard.
Fully resolved request URL
Relative endpoint path (for error messages)
OptionalminimumTimeoutMs: numberOptional per-request minimum timeout (ms).
When provided, the effective timeout is Math.max(minimumTimeoutMs, this.timeoutMs),
so it acts as a floor that the global timeout can still extend.
Use for known slow EP API endpoints (e.g. procedures/feed, events/feed).
ProtectedgetProtectedExecutes a cached, rate-limited GET request to the EP API.
Expected response type (extends Record<string, unknown>)
API endpoint path (relative to baseURL)
Optionalparams: Record<string, unknown>Optional query parameters
OptionalminimumTimeoutMs: numberOptional per-request minimum timeout in milliseconds.
When provided, the effective timeout is Math.max(minimumTimeoutMs, this.timeoutMs),
so the global timeout (set via --timeout or EP_REQUEST_TIMEOUT_MS) can still
extend it beyond the per-endpoint minimum.
Use for known slow EP API endpoints such as procedures/feed and events/feed.
Promise resolving to the typed API response
PrivategetPrivateGenerates a deterministic cache key.
API endpoint path
Optionalparams: Record<string, unknown>Optional query parameters
JSON string used as cache key
Returns cache statistics for monitoring and debugging.
{ size, maxSize, hitRate, hits, misses }
PrivatereadPrivateshouldPrivateReturns true when an error should trigger a retry.
Retries on:
Does NOT retry on 4xx client errors (except 429).
PrivatetoPrivateConverts a caught error to a typed APIError.
For timeout errors, the actual timeout value is read from the
TimeoutError instance (which carries the effective value used
by withTimeoutAndAbort), avoiding the need to re-validate or
recompute the per-endpoint minimum here.
The caught error
Relative endpoint path (for error messages)
Private StaticparsePrivateParses a byte buffer as JSON-LD. Returns an empty JSON-LD shape for
zero-byte bodies (the EP API sends these for out-of-range offsets).
Non-empty bodies must contain valid JSON; any SyntaxError is allowed
to propagate so callers (including single-entity endpoints) fail fast
instead of receiving a misleading empty-list shape.
Private StaticparsePrivate StaticresolvePrivateResolves all EPClientConfig options to their final values with defaults applied. Extracted to keep constructor complexity within limits.
Private StaticvalidatePrivateValidates the Content-Type header of an API response. Throws if the response is not JSON (e.g. HTML error pages from reverse proxies). Cancels the response body before throwing to allow connection reuse.
A missing or empty Content-Type header is treated as acceptable because the EP API occasionally omits it on valid JSON responses, and rejecting those would cause false-negative failures.
Base class for European Parliament API sub-clients.
Holds the shared HTTP machinery: LRU cache, token-bucket rate limiter, timeout/abort controller, and retry logic. Sub-clients extend this class and call the protected
get()helper for all HTTP requests.BaseEPClient