import type { AuthCredentialStore } from "./store.js"; import type { AuthCredential, OAuthCredential } from "./types.js"; import type { CredentialPool } from "./pool.js"; import type { Provider } from "../types.js"; import type { UsageCredential, UsageProvider } from "../usage.js"; /** Minimum interval between non-exhausted header snapshots; used by UsageService. */ export declare const USAGE_HEADER_INGEST_INTERVAL_MS = 60000; /** * Per-credential cool-down after a usage fetch fails. While this window is * active we serve the last successful value to avoid dropping the credential * from the report; without a previous value we return null until the * cooldown expires. Report invalidation does not bypass this cooldown. */ export declare const USAGE_FAILURE_BACKOFF_MS = 10000; /** Default usage fetch timeout; used by the AuthStorage facade. */ export declare const DEFAULT_USAGE_REQUEST_TIMEOUT_MS = 10000; /** A single usage fetch target; used by usage probes and the cache. */ export type UsageRequestDescriptor = { provider: Provider; credential: UsageCredential; baseUrl?: string; }; /** Forced-refresh markers active for one reports pass; used by UsageService. */ export type ForcedUsageRefresh = { all: boolean; providers: Set; }; /** Cached value and its logical expiry; used by UsageService. */ export type UsageCacheEntry = { value: T; expiresAt: number; }; /** Convert a stored credential for usage providers; used by usage and health services. */ export declare function buildUsageCredential(credential: AuthCredential): UsageCredential; /** Build a stable usage account key; used by cache and usage probes. */ export declare function usageCacheIdentity(credential: UsageCredential): string; /** Build one provider usage request; used by usage and health services. */ export declare function usageRequest(provider: Provider, credential: UsageCredential, baseUrl?: string): UsageRequestDescriptor; /** Build an OAuth usage request; used by cache and usage services. */ export declare function oauthUsageRequest(provider: Provider, credential: OAuthCredential, baseUrl?: string): UsageRequestDescriptor; /** Store-backed usage report cache: keys, epoch, force-refresh markers, invalidation; used by AuthStorage. */ export declare class UsageCache { #private; constructor(store: AuthCredentialStore, pool: CredentialPool, usageProviders: (provider: Provider) => UsageProvider | undefined); get epoch(): number; bumpEpoch(): void; /** Identifies confirmed recoveries that supersede an in-flight failed probe. */ recoveryEpoch(provider: Provider): number; /** * Changes when a user refresh, confirmed reset, or usage-implementation swap * makes an in-flight probe too old to answer. Block marks do not change it: * they stop a racing report from being cached, never trigger a re-probe. */ refreshEpoch(provider: Provider): number; /** Failure cooldowns survive report invalidation and process restarts. */ failureKey(reportKey: string): string; get(key: string): UsageCacheEntry | undefined; getStale(key: string): UsageCacheEntry | undefined; set(key: string, entry: UsageCacheEntry): void; deletePrefix(prefix: string): boolean; markForceRefresh(provider?: Provider): void; forcedRefresh(requests: readonly UsageRequestDescriptor[]): ForcedUsageRefresh; clearForceRefresh(refresh: ForcedUsageRefresh): void; reportKey(request: UsageRequestDescriptor): string; reportsKey(requests: readonly UsageRequestDescriptor[]): string; /** * Force the next usage fetch for `provider` to bypass the 5-min cache, so * `/usage` reflects a freshly-redeemed reset instead of stale numbers. * `resetSpentCredentialId` also forgets that credential's cached saved-reset * block, so a failed follow-up reset probe cannot carry the pre-spend * inventory forward. */ invalidate(provider: string, baseUrl?: string, options?: { resetSpentCredentialId?: number; }): void; /** A confirmed reset permits one fresh probe even during a pre-reset failure cooldown. */ invalidateAfterReset(provider: Provider, baseUrl?: string, options?: { resetSpentCredentialId?: number; }): void; /** * Expire cached reports for a provider after its runtime usage implementation changes. * This keeps a newly installed extension provider from serving a built-in snapshot. */ invalidateForProvider(provider: Provider): void; /** * Drop report snapshots for a user-requested refresh so a failed probe * cannot replay the pre-invalidation last-good value. The persisted marker * makes the next same-provider refresh serial rather than a cold fan-out. */ clearReports(provider: string | undefined, collectRequests: () => Promise): Promise; invalidateProviderKey(providerKey: string): void; }