Skip to main content

jacquard_api/com_atproto/server/
create_session.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: com.atproto.server.createSession
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;
14use jacquard_common::types::string::{Did, Handle};
15use jacquard_common::types::value::Data;
16use jacquard_derive::{IntoStatic, lexicon, open_union};
17use serde::{Serialize, Deserialize};
18
19#[lexicon]
20#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
21#[serde(rename_all = "camelCase")]
22pub struct CreateSession<'a> {
23    ///When true, instead of throwing error for takendown accounts, a valid response with a narrow scoped token will be returned
24    #[serde(skip_serializing_if = "Option::is_none")]
25    pub allow_takendown: Option<bool>,
26    #[serde(skip_serializing_if = "Option::is_none")]
27    #[serde(borrow)]
28    pub auth_factor_token: Option<CowStr<'a>>,
29    ///Handle or other identifier supported by the server for the authenticating user.
30    #[serde(borrow)]
31    pub identifier: CowStr<'a>,
32    #[serde(borrow)]
33    pub password: CowStr<'a>,
34}
35
36
37#[lexicon]
38#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
39#[serde(rename_all = "camelCase")]
40pub struct CreateSessionOutput<'a> {
41    #[serde(borrow)]
42    pub access_jwt: CowStr<'a>,
43    #[serde(skip_serializing_if = "Option::is_none")]
44    pub active: Option<bool>,
45    #[serde(borrow)]
46    pub did: Did<'a>,
47    #[serde(skip_serializing_if = "Option::is_none")]
48    #[serde(borrow)]
49    pub did_doc: Option<Data<'a>>,
50    #[serde(skip_serializing_if = "Option::is_none")]
51    #[serde(borrow)]
52    pub email: Option<CowStr<'a>>,
53    #[serde(skip_serializing_if = "Option::is_none")]
54    pub email_auth_factor: Option<bool>,
55    #[serde(skip_serializing_if = "Option::is_none")]
56    pub email_confirmed: Option<bool>,
57    #[serde(borrow)]
58    pub handle: Handle<'a>,
59    #[serde(borrow)]
60    pub refresh_jwt: CowStr<'a>,
61    ///If active=false, this optional field indicates a possible reason for why the account is not active. If active=false and no status is supplied, then the host makes no claim for why the repository is no longer being hosted.
62    #[serde(skip_serializing_if = "Option::is_none")]
63    #[serde(borrow)]
64    pub status: Option<CreateSessionOutputStatus<'a>>,
65}
66
67/// If active=false, this optional field indicates a possible reason for why the account is not active. If active=false and no status is supplied, then the host makes no claim for why the repository is no longer being hosted.
68
69#[derive(Debug, Clone, PartialEq, Eq, Hash)]
70pub enum CreateSessionOutputStatus<'a> {
71    Takendown,
72    Suspended,
73    Deactivated,
74    Other(CowStr<'a>),
75}
76
77impl<'a> CreateSessionOutputStatus<'a> {
78    pub fn as_str(&self) -> &str {
79        match self {
80            Self::Takendown => "takendown",
81            Self::Suspended => "suspended",
82            Self::Deactivated => "deactivated",
83            Self::Other(s) => s.as_ref(),
84        }
85    }
86}
87
88impl<'a> From<&'a str> for CreateSessionOutputStatus<'a> {
89    fn from(s: &'a str) -> Self {
90        match s {
91            "takendown" => Self::Takendown,
92            "suspended" => Self::Suspended,
93            "deactivated" => Self::Deactivated,
94            _ => Self::Other(CowStr::from(s)),
95        }
96    }
97}
98
99impl<'a> From<String> for CreateSessionOutputStatus<'a> {
100    fn from(s: String) -> Self {
101        match s.as_str() {
102            "takendown" => Self::Takendown,
103            "suspended" => Self::Suspended,
104            "deactivated" => Self::Deactivated,
105            _ => Self::Other(CowStr::from(s)),
106        }
107    }
108}
109
110impl<'a> core::fmt::Display for CreateSessionOutputStatus<'a> {
111    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
112        write!(f, "{}", self.as_str())
113    }
114}
115
116impl<'a> AsRef<str> for CreateSessionOutputStatus<'a> {
117    fn as_ref(&self) -> &str {
118        self.as_str()
119    }
120}
121
122impl<'a> serde::Serialize for CreateSessionOutputStatus<'a> {
123    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
124    where
125        S: serde::Serializer,
126    {
127        serializer.serialize_str(self.as_str())
128    }
129}
130
131impl<'de, 'a> serde::Deserialize<'de> for CreateSessionOutputStatus<'a>
132where
133    'de: 'a,
134{
135    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
136    where
137        D: serde::Deserializer<'de>,
138    {
139        let s = <&'de str>::deserialize(deserializer)?;
140        Ok(Self::from(s))
141    }
142}
143
144impl<'a> Default for CreateSessionOutputStatus<'a> {
145    fn default() -> Self {
146        Self::Other(Default::default())
147    }
148}
149
150impl jacquard_common::IntoStatic for CreateSessionOutputStatus<'_> {
151    type Output = CreateSessionOutputStatus<'static>;
152    fn into_static(self) -> Self::Output {
153        match self {
154            CreateSessionOutputStatus::Takendown => CreateSessionOutputStatus::Takendown,
155            CreateSessionOutputStatus::Suspended => CreateSessionOutputStatus::Suspended,
156            CreateSessionOutputStatus::Deactivated => {
157                CreateSessionOutputStatus::Deactivated
158            }
159            CreateSessionOutputStatus::Other(v) => {
160                CreateSessionOutputStatus::Other(v.into_static())
161            }
162        }
163    }
164}
165
166
167#[open_union]
168#[derive(
169    Serialize,
170    Deserialize,
171    Debug,
172    Clone,
173    PartialEq,
174    Eq,
175    thiserror::Error,
176    miette::Diagnostic,
177    IntoStatic
178)]
179
180#[serde(tag = "error", content = "message")]
181#[serde(bound(deserialize = "'de: 'a"))]
182pub enum CreateSessionError<'a> {
183    #[serde(rename = "AccountTakedown")]
184    AccountTakedown(Option<CowStr<'a>>),
185    #[serde(rename = "AuthFactorTokenRequired")]
186    AuthFactorTokenRequired(Option<CowStr<'a>>),
187}
188
189impl core::fmt::Display for CreateSessionError<'_> {
190    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
191        match self {
192            Self::AccountTakedown(msg) => {
193                write!(f, "AccountTakedown")?;
194                if let Some(msg) = msg {
195                    write!(f, ": {}", msg)?;
196                }
197                Ok(())
198            }
199            Self::AuthFactorTokenRequired(msg) => {
200                write!(f, "AuthFactorTokenRequired")?;
201                if let Some(msg) = msg {
202                    write!(f, ": {}", msg)?;
203                }
204                Ok(())
205            }
206            Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
207        }
208    }
209}
210
211/// Response type for com.atproto.server.createSession
212pub struct CreateSessionResponse;
213impl jacquard_common::xrpc::XrpcResp for CreateSessionResponse {
214    const NSID: &'static str = "com.atproto.server.createSession";
215    const ENCODING: &'static str = "application/json";
216    type Output<'de> = CreateSessionOutput<'de>;
217    type Err<'de> = CreateSessionError<'de>;
218}
219
220impl<'a> jacquard_common::xrpc::XrpcRequest for CreateSession<'a> {
221    const NSID: &'static str = "com.atproto.server.createSession";
222    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
223        "application/json",
224    );
225    type Response = CreateSessionResponse;
226}
227
228/// Endpoint type for com.atproto.server.createSession
229pub struct CreateSessionRequest;
230impl jacquard_common::xrpc::XrpcEndpoint for CreateSessionRequest {
231    const PATH: &'static str = "/xrpc/com.atproto.server.createSession";
232    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
233        "application/json",
234    );
235    type Request<'de> = CreateSession<'de>;
236    type Response = CreateSessionResponse;
237}