Skip to main content

proto_blue_api/generated/com/atproto/server/
describeServer.rs

1// Generated by atproto-codegen. Do not edit.
2//! Lexicon: com.atproto.server.describeServer
3#![allow(clippy::pedantic, clippy::nursery, clippy::all)]
4
5use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
8#[serde(rename_all = "camelCase")]
9pub struct Contact {
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub email: Option<String>,
12}
13
14#[derive(Debug, Clone, Serialize, Deserialize)]
15#[serde(rename_all = "camelCase")]
16pub struct Links {
17    #[serde(skip_serializing_if = "Option::is_none")]
18    pub privacy_policy: Option<String>,
19    #[serde(skip_serializing_if = "Option::is_none")]
20    pub terms_of_service: Option<String>,
21}
22
23/// Describes the server's account creation requirements and capabilities. Implemented by PDS.
24/// XRPC Query: com.atproto.server.describeServer
25#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(rename_all = "camelCase")]
27pub struct Output {
28    pub available_user_domains: Vec<String>,
29    #[serde(skip_serializing_if = "Option::is_none")]
30    pub contact: Option<Contact>,
31    pub did: proto_blue_syntax::Did,
32    #[serde(skip_serializing_if = "Option::is_none")]
33    pub invite_code_required: Option<bool>,
34    #[serde(skip_serializing_if = "Option::is_none")]
35    pub links: Option<Links>,
36    #[serde(skip_serializing_if = "Option::is_none")]
37    pub phone_verification_required: Option<bool>,
38}
39
40/// Errors a `call()` on this method can return.
41#[derive(Debug, thiserror::Error)]
42pub enum CallError {
43    #[error("{0}")]
44    Xrpc(proto_blue_xrpc::XrpcError),
45    #[error(transparent)]
46    Transport(#[from] proto_blue_xrpc::Error),
47    #[error(transparent)]
48    Json(#[from] serde_json::Error),
49}
50
51fn map_xrpc_error(err: proto_blue_xrpc::XrpcError) -> CallError {
52    CallError::Xrpc(err)
53}
54
55/// Execute the query.
56pub async fn call(
57    client: &proto_blue_xrpc::XrpcClient,
58    opts: Option<&proto_blue_xrpc::CallOptions>,
59) -> Result<Output, CallError> {
60    let response = match client
61        .query("com.atproto.server.describeServer", None, opts)
62        .await
63    {
64        Ok(r) => r,
65        Err(proto_blue_xrpc::Error::Xrpc(x)) => return Err(map_xrpc_error(x)),
66        Err(e) => return Err(CallError::Transport(e)),
67    };
68    Ok(serde_json::from_value(response.data)?)
69}
70
71/// Register a typed handler for this method on an [`proto_blue_xrpc::XrpcServer`].
72#[cfg(feature = "server")]
73pub fn register<F, Fut>(
74    server: proto_blue_xrpc::XrpcServer,
75    handler: F,
76) -> proto_blue_xrpc::XrpcServer
77where
78    F: Fn(proto_blue_xrpc::HandlerContext) -> Fut + Send + Sync + 'static,
79    Fut: std::future::Future<Output = Result<Output, proto_blue_xrpc::XrpcServerError>>
80        + Send
81        + 'static,
82{
83    let handler = std::sync::Arc::new(handler);
84    server.query("com.atproto.server.describeServer", move |ctx| {
85        let handler = handler.clone();
86        async move {
87            let out = handler(ctx).await?;
88            let value = serde_json::to_value(&out).map_err(|e| {
89                proto_blue_xrpc::XrpcServerError::new(
90                    proto_blue_xrpc::ResponseType::InternalServerError,
91                    format!("output serialize: {e}"),
92                )
93            })?;
94            Ok::<_, proto_blue_xrpc::XrpcServerError>(value)
95        }
96    })
97}