AniLink - v3.0.0
    Preparing search index...

    Class TokenRefresher<TToken>

    Coordinates the automatic token-refresh lifecycle for one client.

    The wiring seam constructs one coordinator per provider facade when refresh credentials are present and wraps every facade method with TokenRefresher.executeWithRefresh. The coordinator owns the mutable refresh state (the current refresh token, honoring the provider's rotation semantics) and deduplicates concurrent 401s into a single refresh call.

    Type Parameters

    Index
    • Runs one operation attempt under the automatic refresh lifecycle.

      A 401 from the first attempt, or an AniLinkAuthError raised before any request because no access token is configured, which lets a persisted refresh token bootstrap the client, triggers exactly one refresh (concurrent failures share the in-flight refresh) followed by a single replay with the new auth material. Any other failure, a non-401 first attempt, a failed refresh, or a replay that fails again, surfaces unchanged. A failed refresh grant is reported to onHookError (under the coordinator's hookName) before the sanitized error rethrows, so the grant failure is observable through the same channel as every other lifecycle failure. The onTokenRefreshError callback (when configured) fires once per failed grant with the same sanitized error.

      Type Parameters

      • T

      Parameters

      • operation: () => Promise<T>

        A closure performing one request attempt; called at most twice.

      Returns Promise<T>

      The first successful attempt's result.

      The sanitized refresh error when the token endpoint rejects the grant, or the operation's own error otherwise.