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