API Core - v1.5.0
    Preparing search index...

    Class RateLimitGate

    Tracks an upstream rate-limit window and lets callers check whether the gate is currently closed.

    Used by the consuming API clients to honor HTTP 429 responses: record the rate-limit on the error path (respecting Retry-After when present) and consult isPaused / remaining on the request path to fail fast without hammering the upstream server.

    Index
    • get isPaused(): boolean

      Whether the gate is currently closed (caller should not make requests).

      Returns boolean

      true while the rate-limit window is active.

    • Convenience: record the rate-limit and emit a formatted error log in one call. Centralizes the log message format so the consuming API clients stay consistent, and avoids repeating the recordRateLimit(...) + logger.error(...) pair at each 429 call site.

      Parameters

      • logger: { error: (...data: unknown[]) => void }

        Logger used to emit the error line.

        • error: (...data: unknown[]) => void

          Error-level log sink.

      • retryAfter: unknown

        Header value from the 429 response (delta-seconds or HTTP-date).

      Returns void

    • Record a rate-limit response from upstream.

      Accepts the raw Retry-After header value in either RFC 9110 form: delta-seconds ("120") or an HTTP-date ("Wed, 21 Oct 2026 07:28:00 GMT"). Unparsable, zero, negative, past-dated, or missing values fall back to the configured duration.

      Parameters

      • OptionalretryAfter: unknown

        Header value from the 429 response.

      Returns void

    • Atomic read of the gate's state. All fields are computed against a single Temporal.Now.instant() capture, so remaining and unblockAt cannot observe inconsistent "one null, one not" pairs that separate getter reads might hit near the boundary.

      Returned as a discriminated union on isPaused so callers do not need to null-check remaining / unblockAt after narrowing.

      Returns
          | { isPaused: false; remaining: null; unblockAt: null }
          | {
              isPaused: true;
              remaining: Temporal.Duration;
              unblockAt: Temporal.Instant;
          }

      The current pause state and derived timing fields.