use std::collections::BTreeMap;
use serde::{Deserialize, Serialize};
use serde_json::Value;
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct JobsRegistry {
pub bucket: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct JobsBindings {
pub namespace: String,
pub queues: BTreeMap<String, Value>,
#[serde(skip_serializing_if = "Option::is_none")]
pub registry: Option<JobsRegistry>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ResourceBindings {
#[serde(skip_serializing_if = "Option::is_none")]
pub jobs: Option<JobsBindings>,
#[serde(skip_serializing_if = "Option::is_none")]
pub kv: Option<BTreeMap<String, Value>>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct AuthenticatedIdentity {
pub identity_id: String,
pub provider: String,
pub subject: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct AuthenticatedUser {
pub active: bool,
pub capabilities: Vec<String>,
pub email: String,
pub identity: AuthenticatedIdentity,
#[serde(skip_serializing_if = "Option::is_none")]
pub image: Option<String>,
#[serde(rename = "lastLogin")]
#[serde(skip_serializing_if = "Option::is_none")]
pub last_login: Option<String>,
pub name: String,
#[serde(rename = "userId")]
pub user_id: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct SentinelCredsRecord {
pub jwt: String,
pub seed: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct ClientTransportRecord {
pub nats_servers: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct ClientTransportsRecord {
#[serde(skip_serializing_if = "Option::is_none")]
pub native: Option<ClientTransportRecord>,
#[serde(skip_serializing_if = "Option::is_none")]
pub websocket: Option<ClientTransportRecord>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct AuthStartRequest {
#[serde(skip_serializing_if = "Option::is_none")]
pub provider: Option<String>,
pub redirect_to: String,
pub session_key: String,
pub sig: String,
pub contract: BTreeMap<String, Value>,
#[serde(skip_serializing_if = "Option::is_none")]
pub context: Option<BTreeMap<String, Value>>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(tag = "status", rename_all = "snake_case")]
pub enum AuthStartResponse {
Bound {
expires: String,
#[serde(rename = "inboxPrefix")]
inbox_prefix: String,
sentinel: SentinelCredsRecord,
transports: ClientTransportsRecord,
},
FlowStarted {
#[serde(rename = "flowId")]
flow_id: String,
#[serde(rename = "loginUrl")]
login_url: String,
},
}
pub type ListIdentityGrantsRequest = crate::sdk::auth::types::AuthIdentityGrantsListRequest;
pub type IdentityGrantContractEvidenceRecord =
crate::sdk::auth::types::AuthIdentityGrantsListResponseEntriesItemContractEvidence;
pub type IdentityGrantEntryRecord =
crate::sdk::auth::types::AuthIdentityGrantsListResponseEntriesItem;
pub type RevokeIdentityGrantRequest = crate::sdk::auth::types::AuthIdentityGrantsRevokeRequest;
pub type AuthRequestsValidateRequest = crate::sdk::auth::types::AuthRequestsValidateRequest;
pub type AuthRequestsValidateResponse = crate::sdk::auth::types::AuthRequestsValidateResponse;
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub(crate) struct LogoutResponse {
pub success: bool,
}
#[cfg(test)]
mod tests {
use super::{AuthenticatedIdentity, AuthenticatedUser};
use serde_json::json;
#[test]
fn authenticated_user_uses_account_first_session_shape() {
let value = json!({
"userId": "usr_123",
"active": true,
"name": "Ada",
"email": "ada@example.com",
"image": "https://example.com/ada.png",
"identity": {
"identityId": "idn_github_123",
"provider": "github",
"subject": "123",
},
"capabilities": ["users.read"],
"lastLogin": "2026-04-10T00:00:00.000Z",
});
let user: AuthenticatedUser = serde_json::from_value(value).expect("deserialize user");
assert_eq!(user.user_id, "usr_123");
assert_eq!(
user.identity,
AuthenticatedIdentity {
identity_id: "idn_github_123".to_string(),
provider: "github".to_string(),
subject: "123".to_string(),
}
);
assert_eq!(user.last_login.as_deref(), Some("2026-04-10T00:00:00.000Z"));
}
}