xet-data 1.5.2

Data processing pipeline for chunking, deduplication, and file reconstruction; used in the Hugging Face Xet client tools. Intended to be used through the API in the hf-xet package.
Documentation
use std::sync::Arc;

use xet_client::cas_client::auth::{AuthError, TokenInfo, TokenRefresher};
use xet_client::hub_client::{HubClient, Operation};

pub struct HubClientTokenRefresher {
    pub operation: Operation,
    pub client: Arc<HubClient>,
}

#[cfg_attr(not(target_family = "wasm"), async_trait::async_trait)]
#[cfg_attr(target_family = "wasm", async_trait::async_trait(?Send))]
impl TokenRefresher for HubClientTokenRefresher {
    async fn refresh(&self) -> std::result::Result<TokenInfo, AuthError> {
        let jwt_info = self
            .client
            .get_cas_jwt(self.operation)
            .await
            .map_err(AuthError::token_refresh_failure)?;

        Ok((jwt_info.access_token, jwt_info.exp))
    }
}