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