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