Skip to main content

agentmail/types/
accounts.rs

1use serde::{Deserialize, Serialize};
2
3use crate::util::QueryBuilder;
4
5/// A human account (an app connection): who signed in to which app, through
6/// which inbox, and when.
7#[derive(Clone, Debug, Deserialize)]
8pub struct Account {
9    /// Unique account id (UUID).
10    pub account_id: String,
11    /// The app the account signed in to (UUID).
12    pub app_id: String,
13    /// The app's display name, when known.
14    #[serde(default)]
15    pub app_name: Option<String>,
16    /// The inbox backing the connection.
17    pub inbox_id: String,
18    /// Owning pod.
19    pub pod_id: String,
20    /// Owning organization.
21    pub organization_id: String,
22    /// First sign-in (RFC 3339).
23    pub first_signed_in_at: String,
24    /// Most recent sign-in (RFC 3339).
25    pub last_signed_in_at: String,
26    /// Total sign-ins.
27    pub sign_in_count: u64,
28    /// `disabled`, when the account has been cut off.
29    #[serde(default)]
30    pub status: Option<String>,
31    /// When the account was disabled (RFC 3339), when it was.
32    #[serde(default)]
33    pub disabled_at: Option<String>,
34}
35
36/// List filters for `list_accounts` (includes pagination, like the other
37/// filter structs).
38#[derive(Clone, Debug, Default)]
39pub struct AccountsListFilters {
40    /// Maximum accounts per page.
41    pub limit: Option<u32>,
42    /// Cursor from a previous response's `next_page_token`.
43    pub page_token: Option<String>,
44    /// Sort by sign-in time, newest first.
45    pub ascending: Option<bool>,
46}
47
48impl AccountsListFilters {
49    pub(crate) fn query(&self) -> Vec<(&'static str, String)> {
50        QueryBuilder::new()
51            .opt("limit", self.limit.as_ref())
52            .opt("page_token", self.page_token.as_ref())
53            .opt("ascending", self.ascending.as_ref())
54            .build()
55    }
56}
57
58/// Body for `update_account`. Fields left `None` stay unchanged.
59#[derive(Clone, Debug, Default, Serialize)]
60pub struct UpdateAccount {
61    /// `enabled` to restore sign-ins, `disabled` to cut the account off.
62    #[serde(skip_serializing_if = "Option::is_none")]
63    pub status: Option<String>,
64}
65
66/// One page of accounts from `list_accounts`.
67#[derive(Clone, Debug, Deserialize)]
68pub struct AccountList {
69    /// Total accounts (not just this page).
70    pub count: u64,
71    /// This page of accounts.
72    #[serde(default)]
73    pub accounts: Vec<Account>,
74    /// Cursor for the next page; `None` on the last page.
75    #[serde(default)]
76    pub next_page_token: Option<String>,
77}