Skip to main content

jacquard_api/com_atproto/server/
refresh_session.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: com.atproto.server.refreshSession
4//
5// This file was automatically generated from Lexicon schemas.
6// Any manual changes will be overwritten on the next regeneration.
7
8#[allow(unused_imports)]
9use alloc::collections::BTreeMap;
10
11#[allow(unused_imports)]
12use core::marker::PhantomData;
13use jacquard_common::{CowStr, BosStr, DefaultStr, FromStaticStr};
14use jacquard_common::deps::smol_str::SmolStr;
15use jacquard_common::types::string::{Did, Handle};
16use jacquard_common::types::value::Data;
17use jacquard_derive::{IntoStatic, open_union};
18use serde::{Serialize, Deserialize};
19
20#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
21#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
22pub struct RefreshSessionOutput<S: BosStr = DefaultStr> {
23    pub access_jwt: S,
24    #[serde(skip_serializing_if = "Option::is_none")]
25    pub active: Option<bool>,
26    pub did: Did<S>,
27    #[serde(skip_serializing_if = "Option::is_none")]
28    pub did_doc: Option<Data<S>>,
29    #[serde(skip_serializing_if = "Option::is_none")]
30    pub email: Option<S>,
31    #[serde(skip_serializing_if = "Option::is_none")]
32    pub email_auth_factor: Option<bool>,
33    #[serde(skip_serializing_if = "Option::is_none")]
34    pub email_confirmed: Option<bool>,
35    pub handle: Handle<S>,
36    pub refresh_jwt: S,
37    ///Hosting status of the account. If not specified, then assume 'active'.
38    #[serde(skip_serializing_if = "Option::is_none")]
39    pub status: Option<RefreshSessionOutputStatus<S>>,
40    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
41    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
42}
43
44/// Hosting status of the account. If not specified, then assume 'active'.
45
46#[derive(Debug, Clone, PartialEq, Eq, Hash)]
47pub enum RefreshSessionOutputStatus<S: BosStr = DefaultStr> {
48    Takendown,
49    Suspended,
50    Deactivated,
51    Other(S),
52}
53
54impl<S: BosStr> RefreshSessionOutputStatus<S> {
55    pub fn as_str(&self) -> &str {
56        match self {
57            Self::Takendown => "takendown",
58            Self::Suspended => "suspended",
59            Self::Deactivated => "deactivated",
60            Self::Other(s) => s.as_ref(),
61        }
62    }
63    /// Construct from a string-like value, matching known values.
64    pub fn from_value(s: S) -> Self {
65        match s.as_ref() {
66            "takendown" => Self::Takendown,
67            "suspended" => Self::Suspended,
68            "deactivated" => Self::Deactivated,
69            _ => Self::Other(s),
70        }
71    }
72}
73
74impl<S: BosStr> core::fmt::Display for RefreshSessionOutputStatus<S> {
75    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
76        write!(f, "{}", self.as_str())
77    }
78}
79
80impl<S: BosStr> AsRef<str> for RefreshSessionOutputStatus<S> {
81    fn as_ref(&self) -> &str {
82        self.as_str()
83    }
84}
85
86impl<S: BosStr> Serialize for RefreshSessionOutputStatus<S> {
87    fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
88    where
89        Ser: serde::Serializer,
90    {
91        serializer.serialize_str(self.as_str())
92    }
93}
94
95impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de>
96for RefreshSessionOutputStatus<S> {
97    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
98    where
99        D: serde::Deserializer<'de>,
100    {
101        let s = S::deserialize(deserializer)?;
102        Ok(Self::from_value(s))
103    }
104}
105
106impl<S: BosStr + Default> Default for RefreshSessionOutputStatus<S> {
107    fn default() -> Self {
108        Self::Other(Default::default())
109    }
110}
111
112impl<S: BosStr> jacquard_common::IntoStatic for RefreshSessionOutputStatus<S>
113where
114    S: BosStr + jacquard_common::IntoStatic,
115    S::Output: BosStr,
116{
117    type Output = RefreshSessionOutputStatus<S::Output>;
118    fn into_static(self) -> Self::Output {
119        match self {
120            RefreshSessionOutputStatus::Takendown => {
121                RefreshSessionOutputStatus::Takendown
122            }
123            RefreshSessionOutputStatus::Suspended => {
124                RefreshSessionOutputStatus::Suspended
125            }
126            RefreshSessionOutputStatus::Deactivated => {
127                RefreshSessionOutputStatus::Deactivated
128            }
129            RefreshSessionOutputStatus::Other(v) => {
130                RefreshSessionOutputStatus::Other(v.into_static())
131            }
132        }
133    }
134}
135
136
137#[derive(
138    Serialize,
139    Deserialize,
140    Debug,
141    Clone,
142    PartialEq,
143    Eq,
144    thiserror::Error,
145    miette::Diagnostic
146)]
147
148#[serde(tag = "error", content = "message")]
149pub enum RefreshSessionError {
150    #[serde(rename = "AccountTakedown")]
151    AccountTakedown(Option<SmolStr>),
152    #[serde(rename = "InvalidToken")]
153    InvalidToken(Option<SmolStr>),
154    #[serde(rename = "ExpiredToken")]
155    ExpiredToken(Option<SmolStr>),
156    /// Catch-all for unknown error codes.
157    #[serde(untagged)]
158    Other { error: SmolStr, message: Option<SmolStr> },
159}
160
161impl core::fmt::Display for RefreshSessionError {
162    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
163        match self {
164            Self::AccountTakedown(msg) => {
165                write!(f, "AccountTakedown")?;
166                if let Some(msg) = msg {
167                    write!(f, ": {}", msg)?;
168                }
169                Ok(())
170            }
171            Self::InvalidToken(msg) => {
172                write!(f, "InvalidToken")?;
173                if let Some(msg) = msg {
174                    write!(f, ": {}", msg)?;
175                }
176                Ok(())
177            }
178            Self::ExpiredToken(msg) => {
179                write!(f, "ExpiredToken")?;
180                if let Some(msg) = msg {
181                    write!(f, ": {}", msg)?;
182                }
183                Ok(())
184            }
185            Self::Other { error, message } => {
186                write!(f, "{}", error)?;
187                if let Some(msg) = message {
188                    write!(f, ": {}", msg)?;
189                }
190                Ok(())
191            }
192        }
193    }
194}
195
196/** Request marker for the `com.atproto.server.refreshSession` procedure.
197
198This endpoint has no request parameters or input body; send this marker with `jacquard::Client`.*/
199
200#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Copy)]
201pub struct RefreshSession;
202/** Response marker for the `com.atproto.server.refreshSession` procedure.
203
204Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `RefreshSessionOutput<S>` for this endpoint.*/
205pub struct RefreshSessionResponse;
206impl jacquard_common::xrpc::XrpcResp for RefreshSessionResponse {
207    const NSID: &'static str = "com.atproto.server.refreshSession";
208    const ENCODING: &'static str = "application/json";
209    type Output<S: BosStr> = RefreshSessionOutput<S>;
210    type Err = RefreshSessionError;
211}
212
213impl jacquard_common::xrpc::XrpcRequest for RefreshSession {
214    const NSID: &'static str = "com.atproto.server.refreshSession";
215    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
216        "application/json",
217    );
218    type Response = RefreshSessionResponse;
219}
220
221/** Endpoint marker for the `com.atproto.server.refreshSession` procedure.
222
223Path: `/xrpc/com.atproto.server.refreshSession`. The request payload type is `RefreshSession`; use this marker with lower-level `XrpcEndpoint` APIs when you need endpoint metadata.*/
224pub struct RefreshSessionRequest;
225impl jacquard_common::xrpc::XrpcEndpoint for RefreshSessionRequest {
226    const PATH: &'static str = "/xrpc/com.atproto.server.refreshSession";
227    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
228        "application/json",
229    );
230    type Request<S: BosStr> = RefreshSession;
231    type Response = RefreshSessionResponse;
232}