vylth-flow 0.2.0

Official Rust SDK for Vylth Flow — self-custody crypto payment processing
Documentation
use std::sync::Arc;
use serde::Serialize;
use crate::error::FlowResult;
use crate::http::HttpClient;

pub struct TeamService {
    pub(crate) http: Arc<HttpClient>,
}

#[derive(Serialize)]
struct InviteParams {
    email: String,
    role: String,
}

#[derive(Serialize)]
struct RoleParams {
    role: String,
}

impl TeamService {
    pub async fn get_team(&self) -> FlowResult<serde_json::Value> {
        let data = self.http.get("/merchants/me/team", None).await?;
        Ok(serde_json::from_slice(&data).map_err(|e| crate::error::FlowError::Other(e.to_string()))?)
    }

    pub async fn get_my_role(&self) -> FlowResult<serde_json::Value> {
        let data = self.http.get("/merchants/me/team/my-role", None).await?;
        Ok(serde_json::from_slice(&data).map_err(|e| crate::error::FlowError::Other(e.to_string()))?)
    }

    pub async fn invite(&self, email: &str, role: &str) -> FlowResult<serde_json::Value> {
        let params = InviteParams { email: email.to_string(), role: role.to_string() };
        let data = self.http.post("/merchants/me/team/invite", Some(&params)).await?;
        Ok(serde_json::from_slice(&data).map_err(|e| crate::error::FlowError::Other(e.to_string()))?)
    }

    pub async fn revoke_invite(&self, invite_id: &str) -> FlowResult<serde_json::Value> {
        let data = self.http.post::<()>(&format!("/merchants/me/team/invite/{}/revoke", invite_id), None).await?;
        Ok(serde_json::from_slice(&data).map_err(|e| crate::error::FlowError::Other(e.to_string()))?)
    }

    pub async fn update_role(&self, member_id: &str, role: &str) -> FlowResult<serde_json::Value> {
        let params = RoleParams { role: role.to_string() };
        let data = self.http.patch(&format!("/merchants/me/team/{}/role", member_id), Some(&params)).await?;
        Ok(serde_json::from_slice(&data).map_err(|e| crate::error::FlowError::Other(e.to_string()))?)
    }

    pub async fn remove(&self, member_id: &str) -> FlowResult<()> {
        self.http.delete(&format!("/merchants/me/team/{}", member_id)).await?;
        Ok(())
    }
}