use serde::{Deserialize, Serialize};
use crate::client::Client;
use crate::error::Result;
#[derive(Debug, Clone, Deserialize)]
pub struct Me {
pub id: String,
pub login: String,
pub name: Option<String>,
pub email: Option<String>,
pub role: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DeletionPreview {
pub calls: u32,
pub recordings: u32,
pub transcripts: u32,
pub shares: u32,
pub flows: u32,
pub contacts: u32,
pub prompts: u32,
pub projects: u32,
pub files: u32,
pub annotations: u32,
pub exports: u32,
pub models: u32,
}
impl Client {
pub async fn whoami(&self) -> Result<Me> {
self.get_json("/api/me").await
}
pub async fn revoke_current_token(&self) -> Result<()> {
self.post_empty("/api/auth/cli/tokens/revoke-current").await
}
pub async fn deletion_preview(&self) -> Result<DeletionPreview> {
self.get_json("/api/me/deletion-preview").await
}
pub async fn delete_account(&self) -> Result<()> {
self.delete("/api/me").await
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn deletion_preview_reads_the_platform_wire_shape() {
let json = r#"{
"accounts": 2, "calls": 6, "recordings": 1, "transcripts": 4,
"shares": 0, "flows": 3, "contacts": 9, "prompts": 2,
"projects": 1, "labelSets": 0, "files": 5, "annotations": 90,
"exports": 1, "models": 1
}"#;
let p: DeletionPreview = serde_json::from_str(json).unwrap();
assert_eq!(p.calls, 6);
assert_eq!(p.recordings, 1);
assert_eq!(p.annotations, 90);
assert_eq!(p.models, 1);
}
#[test]
fn deletion_preview_round_trips_for_a_consumer_to_forward() {
let p: DeletionPreview = serde_json::from_str(
r#"{"calls":6,"recordings":1,"transcripts":4,"shares":0,
"flows":3,"contacts":9,"prompts":2,"projects":1,"files":5,
"annotations":90,"exports":1,"models":1}"#,
)
.unwrap();
let back: DeletionPreview =
serde_json::from_str(&serde_json::to_string(&p).unwrap()).unwrap();
assert_eq!(back.calls, 6);
assert_eq!(back.annotations, 90);
}
#[test]
fn deletion_preview_needs_every_count() {
let err = serde_json::from_str::<DeletionPreview>(r#"{"calls": 6}"#);
assert!(err.is_err(), "expected a decode error, got {err:?}");
}
}