kinetex - v1.0.0-rc.1
    Preparing search index...

    Class CookieJar

    RFC 6265 §5.3 + §5.4 cookie jar implementation.

    Stores cookies in a three-level map (domain → path → name) with:

    • LRU eviction (per-domain cap of 50, global cap of 3000)
    • __Secure- / __Host- prefix enforcement (RFC 6265bis §4.1.3)
    • SameSite Strict / Lax / None enforcement
    • JSON serialization / deserialization
    const jar = new CookieJar();
    jar.setCookie("session=abc; Path=/; Secure", { url: "https://example.com/" });
    const cookies = jar.getCookies({ url: "https://example.com/page" });
    Index

    Constructors

    Accessors

    • get count(): number

      Total number of cookies currently stored in the jar.

      Returns number

    Methods

    • Destroy the jar — clears the periodic cleanup timer. Call this when the jar is no longer needed to prevent memory leaks.

      Returns void

    • Set a cookie per RFC 6265 §5.3.

      Rejects cookies that exceed size limits, fail domain/path validation, violate prefix rules, or would be immediately expired (treats those as deletes).

      Parameters

      • header: string

        Raw Set-Cookie header value (e.g. "session=abc; Path=/; Secure")

      • options: SetCookieOptions

        URL the cookie was received from + SameSite context

      Returns boolean

      true if the cookie was stored, false if rejected

    • Retrieve matching cookies per RFC 6265 §5.4.

      Filters by domain, path, secure/httpOnly flags, and SameSite context. Results are sorted by longest path first, then oldest creation time. Updates lastAccessed on returned cookies.

      Parameters

      • options: GetCookiesOptions

        URL, protocol context, and SameSite context

      Returns Cookie[]

      Array of matching Cookie objects (direct references into storage)

    • Get a Cookie header string for a request.

      Parameters

      • options: GetCookiesOptions

        URL and request context

      Returns string

      "name=value; name=value" string suitable for a Cookie header

    • Get all cookies for a specific domain.

      Parameters

      • domain: string

        The domain to get cookies for (will be canonicalized)

      Returns Cookie[]

      Array of cookies that would be sent to this domain

      jar.setCookie("session=abc", { url: "https://example.com/" });
      jar.getCookiesForDomain("example.com"); // Returns cookies for example.com
    • Process Set-Cookie headers from an HTTP response. Extracts all Set-Cookie values and calls setCookie() for each.

      Parameters

      • headers: Headers | Record<string, string | string[]>

        Response headers (Headers object or plain record)

      • options: SetCookieOptions

        URL and SameSite context for all cookies

      Returns void

    • Remove a specific cookie by domain, path, and name.

      Parameters

      • domain: string

        Domain the cookie was stored under

      • path: string

        Cookie path

      • name: string

        Cookie name

      Returns boolean

      true if a cookie was removed

    • Remove all expired cookies from the jar.

      Returns number

      Number of cookies removed

    • Remove all session cookies (cookies with no expiry / Infinity).

      Returns number

      Number of cookies removed

    • Remove all cookies for a domain and its subdomains.

      Parameters

      Returns number

      Number of cookies removed

    • Remove all cookies that would be sent to a given URL.

      Parameters

      • url: string

        Full URL whose hostname cookies should be cleared

      Returns number

      Number of cookies removed

    • Serialize all non-expired cookies to a JSON-compatible array. Session cookies (Infinity) are stored with expires: null.

      Returns CookieJSON[]

      Array of serialized cookies

    • Get a pretty-printed JSON string of all cookies.

      Returns string

      Formatted JSON string

    • Deserialize cookies from JSON and create a new CookieJar. Expired cookies in the input are silently skipped.

      Parameters

      • data: string | CookieJSON[]

        Array of serialized cookies or a JSON string

      Returns CookieJar

      A new CookieJar populated with the deserialized cookies

    • Return a snapshot of all cookies (copies, not references to internal storage).

      Returns Cookie[]

      Array of cloned Cookie objects

    • Return all cookies for a given domain (exact match + subdomains).

      Parameters

      Returns Cookie[]

      Array of cloned Cookie objects for matching domains