Logos DX
    Preparing search index...

    Function cookiePlugin

    • Cookie plugin for FetchEngine.

      Transparently manages a cookie jar across requests:

      • beforeRequest: injects matching cookies as the Cookie header.
      • afterRequest: captures Set-Cookie response headers into the jar.

      Works in both browser (alongside native cookie jar) and Node.js (where the native fetch has no cookie jar).

      Persistence is coalesced via queueMicrotask: any burst of jar mutations in the same tick produces exactly one adapter.save() call. For graceful shutdown, call plugin.flush().

      For horizontal scaling, provide an adapter (e.g., Redis) and set syncOnRequest: true to reload the jar from the adapter before each request.

      Type Parameters

      • H = unknown
      • P = unknown
      • S = unknown

      Parameters

      Returns CookiePlugin<H, P, S>

      const cookies = cookiePlugin();
      const api = new FetchEngine({ baseUrl: '...', plugins: [cookies] });

      // Access jar directly for manual management
      cookies.jar.clear();
      cookies.jar.clearSession();

      // Graceful shutdown
      await cookies.flush();