proto_blue_api/generated/com/atproto/server/
getSession.rs1use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct Output {
11 #[serde(skip_serializing_if = "Option::is_none")]
12 pub active: Option<bool>,
13 pub did: String,
14 #[serde(skip_serializing_if = "Option::is_none")]
15 pub did_doc: Option<serde_json::Value>,
16 #[serde(skip_serializing_if = "Option::is_none")]
17 pub email: Option<String>,
18 #[serde(skip_serializing_if = "Option::is_none")]
19 pub email_auth_factor: Option<bool>,
20 #[serde(skip_serializing_if = "Option::is_none")]
21 pub email_confirmed: Option<bool>,
22 pub handle: String,
23 #[serde(skip_serializing_if = "Option::is_none")]
24 pub status: Option<String>,
25}
26
27#[derive(Debug, thiserror::Error)]
29pub enum CallError {
30 #[error("{0}")]
31 Xrpc(proto_blue_xrpc::XrpcError),
32 #[error(transparent)]
33 Transport(#[from] proto_blue_xrpc::Error),
34 #[error(transparent)]
35 Json(#[from] serde_json::Error),
36}
37
38fn map_xrpc_error(err: proto_blue_xrpc::XrpcError) -> CallError {
39 CallError::Xrpc(err)
40}
41
42pub async fn call(
44 client: &proto_blue_xrpc::XrpcClient,
45 opts: Option<&proto_blue_xrpc::CallOptions>,
46) -> Result<Output, CallError> {
47 let response = match client
48 .query("com.atproto.server.getSession", None, opts)
49 .await
50 {
51 Ok(r) => r,
52 Err(proto_blue_xrpc::Error::Xrpc(x)) => return Err(map_xrpc_error(x)),
53 Err(e) => return Err(CallError::Transport(e)),
54 };
55 Ok(serde_json::from_value(response.data)?)
56}
57
58#[cfg(feature = "server")]
60pub fn register<F, Fut>(
61 server: proto_blue_xrpc::XrpcServer,
62 handler: F,
63) -> proto_blue_xrpc::XrpcServer
64where
65 F: Fn(proto_blue_xrpc::HandlerContext) -> Fut + Send + Sync + 'static,
66 Fut: std::future::Future<Output = Result<Output, proto_blue_xrpc::XrpcServerError>>
67 + Send
68 + 'static,
69{
70 let handler = std::sync::Arc::new(handler);
71 server.query("com.atproto.server.getSession", move |ctx| {
72 let handler = handler.clone();
73 async move {
74 let out = handler(ctx).await?;
75 let value = serde_json::to_value(&out).map_err(|e| {
76 proto_blue_xrpc::XrpcServerError::new(
77 proto_blue_xrpc::ResponseType::InternalServerError,
78 format!("output serialize: {e}"),
79 )
80 })?;
81 Ok::<_, proto_blue_xrpc::XrpcServerError>(value)
82 }
83 })
84}