@rosschiu/kiban-sdk
    Preparing search index...

    Interface ApiClientConfig

    Construction options for createApiClient.

    interface ApiClientConfig {
        baseUrl: string;
        correlationId?: () => string;
        fetchFn?: {
            (input: URL | RequestInfo, init?: RequestInit): Promise<Response>;
            (input: string | URL | Request, init?: RequestInit): Promise<Response>;
        };
        getAccessToken?: () => string | null | undefined;
        getAccessTokenExpiresAt?: () => number | null | undefined;
        refreshAccessToken?: () => Promise<string | null | undefined>;
    }
    Index
    baseUrl: string

    Gateway origin, e.g. https://127.0.0.1:8443. No trailing slash required.

    correlationId?: () => string

    Injectable correlation id generator; defaults to crypto.randomUUID().

    fetchFn?: {
        (input: URL | RequestInfo, init?: RequestInit): Promise<Response>;
        (input: string | URL | Request, init?: RequestInit): Promise<Response>;
    }

    Injectable for tests; defaults to global fetch.

    Type Declaration

      • (input: URL | RequestInfo, init?: RequestInit): Promise<Response>
      • Parameters

        • input: URL | RequestInfo
        • Optionalinit: RequestInit

        Returns Promise<Response>

      • (input: string | URL | Request, init?: RequestInit): Promise<Response>
      • Parameters

        • input: string | URL | Request
        • Optionalinit: RequestInit

        Returns Promise<Response>

    getAccessToken?: () => string | null | undefined

    Returns the current bearer token, or null/undefined when signed out.

    getAccessTokenExpiresAt?: () => number | null | undefined

    Returns the current access token's expiry as epoch milliseconds (a Session's getTokens()?.expiresAt). When set together with refreshAccessToken, a token that expires within the next 30 seconds is refreshed before the request is sent, so a request never reaches a service with a token that dies in flight (a module that forwards the bearer to another service would otherwise answer 503, which no 401 retry can recover).

    refreshAccessToken?: () => Promise<string | null | undefined>

    Called on a 401 response. Should perform (or await an in-flight) token refresh and return the new access token, or null/undefined if refresh failed. The client retries the request exactly once when this resolves to a token — never more (avoids refresh loops on a persistently-401ing endpoint). Session single-flight refresh coordination lives in auth/session.ts; this hook just needs to return a fresh token.