@avvyr/storefront-sdk - v0.19.0
    Preparing search index...

    Class HttpClient

    Low-level HTTP client that handles base URL construction, auth headers, query params, and error mapping. All resource modules use this.

    Behaviour can be extended without subclassing via HttpClient.interceptors (axios/TanStack-style request/response/error hooks). Interceptors can also be supplied at construction time through config.interceptors.

    Index
    • Returns string | null

    • Returns string | null

    • Returns string | null

    • Returns string

    • Om en refresh-callback redan är registrerad. Låter lagret registrera en gång.

      Returns boolean

    • A storefront URL a browser can open on its own (a link, a download): the public key goes in the query, since a link cannot send headers. Only for public, token-guarded resources.

      Parameters

      • path: string
      • Optionalparams: Record<string, unknown>

      Returns string

    • Execute an HTTP request

      Type Parameters

      • T

      Parameters

      Returns Promise<T>

    • Execute an HTTP request that returns binary content (e.g. a PDF download). Shares auth headers, the 401-refresh retry, and error mapping with request, but resolves to a Blob instead of parsed JSON. Response interceptors (JSON-shaped) are intentionally skipped.

      Parameters

      Returns Promise<Blob>

    • Execute a request whose response is a stream (Server-Sent Events) and hand back the raw Response once its headers have arrived, for the caller to read response.body from.

      Shares auth headers, the 401-refresh retry and error mapping with request. The client's timeout covers only the wait for the headers: once the server has started answering, the stream lives as long as the caller's signal allows. Response interceptors are skipped, since there is no parsed body to hand them.

      A caller abort before the headers arrive rejects with code ABORTED (not TIMEOUT).

      Parameters

      Returns Promise<Response>

    • Parameters

      • token: string | null

      Returns void

    • Seed the context from an auth response. Optional: without it the next identified request pays one extra round trip (400 CONTEXT_REQUIRED, then the retry) and heals itself.

      Parameters

      • context: string | null

      Returns void

    • Parameters

      • token: string | null

      Returns void

    • Parameters

      • fn: () => Promise<string | null>

      Returns void

    interceptors: {
        error: InterceptorManager<ErrorInterceptor>;
        request: InterceptorManager<RequestInterceptor>;
        response: InterceptorManager<ResponseInterceptor>;
    } = ...

    Extension point. Register hooks that run around every request:

    client.http.interceptors.request.use((ctx) => { ctx.headers["x-tenant"] = "acme" })
    client.http.interceptors.response.use((ctx) => { console.log(ctx.response.status) })
    client.http.interceptors.error.use((err) => { if (err.isUnauthorized) redirectToLogin() })