import { Milliseconds } from '@kameleoon/javascript-sdk-core'; import { CredentialsType } from './types'; export declare const SILENCE_PERIOD: number; export declare const TOKEN_EXPIRATION_GAP = Milliseconds.Minute; export declare const TOKEN_OBSOLESCENCE_GAP: number; export type AccessTokenResponseType = { accessToken: string; expiresIn: number; }; /** * Performs one access token request with the given `Authorization` header value; * must reject on any failure (network error, abort, non-2xx status, malformed body) */ export type FetchAccessTokenType = (basicAuthToken: string, signal: AbortSignal) => Promise; /** * Caches the OAuth access token and refreshes it in the background before it expires. * Concurrent callers share one in-flight request, which is bounded by `requestTimeout` * independently of the callers. After a failed request the token is not requested for * `SILENCE_PERIOD`; callers get `null` and proceed without it. */ export declare class AccessTokenSource { private readonly basicAuthToken; private readonly fetchAccessToken; private readonly requestTimeout; private cachedToken; private silentAfterFetchFailureUntil; private fetching; constructor({ clientId, clientSecret }: CredentialsType, fetchAccessToken: FetchAccessTokenType, requestTimeout: number); /** * @param signal - the caller's own signal; once it aborts the caller gets `null` * while the shared fetch carries on for the other waiters and the cache */ getToken(signal: AbortSignal | null): Promise; discardToken(token: string | null): void; private fetchToken; private waitForFetch; private performFetch; private newExpiringToken; } export declare class ExpiringToken { readonly value: string; readonly expirationTime: number; readonly obsolescenceTime: number; constructor(value: string, expirationTime: number, obsolescenceTime: number); isExpired(now: number): boolean; isObsolete(now: number): boolean; }