jacquard_api/com_atproto/server/
create_session.rs1#[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, Default)]
21#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
22pub struct CreateSession<S: BosStr = DefaultStr> {
23 #[serde(skip_serializing_if = "Option::is_none")]
25 pub allow_takendown: Option<bool>,
26 #[serde(skip_serializing_if = "Option::is_none")]
27 pub auth_factor_token: Option<S>,
28 pub identifier: S,
30 pub password: S,
31 #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
32 pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
33}
34
35
36#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
37#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
38pub struct CreateSessionOutput<S: BosStr = DefaultStr> {
39 pub access_jwt: S,
40 #[serde(skip_serializing_if = "Option::is_none")]
41 pub active: Option<bool>,
42 pub did: Did<S>,
43 #[serde(skip_serializing_if = "Option::is_none")]
44 pub did_doc: Option<Data<S>>,
45 #[serde(skip_serializing_if = "Option::is_none")]
46 pub email: Option<S>,
47 #[serde(skip_serializing_if = "Option::is_none")]
48 pub email_auth_factor: Option<bool>,
49 #[serde(skip_serializing_if = "Option::is_none")]
50 pub email_confirmed: Option<bool>,
51 pub handle: Handle<S>,
52 pub refresh_jwt: S,
53 #[serde(skip_serializing_if = "Option::is_none")]
55 pub status: Option<CreateSessionOutputStatus<S>>,
56 #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
57 pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
58}
59
60#[derive(Debug, Clone, PartialEq, Eq, Hash)]
63pub enum CreateSessionOutputStatus<S: BosStr = DefaultStr> {
64 Takendown,
65 Suspended,
66 Deactivated,
67 Other(S),
68}
69
70impl<S: BosStr> CreateSessionOutputStatus<S> {
71 pub fn as_str(&self) -> &str {
72 match self {
73 Self::Takendown => "takendown",
74 Self::Suspended => "suspended",
75 Self::Deactivated => "deactivated",
76 Self::Other(s) => s.as_ref(),
77 }
78 }
79 pub fn from_value(s: S) -> Self {
81 match s.as_ref() {
82 "takendown" => Self::Takendown,
83 "suspended" => Self::Suspended,
84 "deactivated" => Self::Deactivated,
85 _ => Self::Other(s),
86 }
87 }
88}
89
90impl<S: BosStr> core::fmt::Display for CreateSessionOutputStatus<S> {
91 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
92 write!(f, "{}", self.as_str())
93 }
94}
95
96impl<S: BosStr> AsRef<str> for CreateSessionOutputStatus<S> {
97 fn as_ref(&self) -> &str {
98 self.as_str()
99 }
100}
101
102impl<S: BosStr> Serialize for CreateSessionOutputStatus<S> {
103 fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
104 where
105 Ser: serde::Serializer,
106 {
107 serializer.serialize_str(self.as_str())
108 }
109}
110
111impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de>
112for CreateSessionOutputStatus<S> {
113 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
114 where
115 D: serde::Deserializer<'de>,
116 {
117 let s = S::deserialize(deserializer)?;
118 Ok(Self::from_value(s))
119 }
120}
121
122impl<S: BosStr + Default> Default for CreateSessionOutputStatus<S> {
123 fn default() -> Self {
124 Self::Other(Default::default())
125 }
126}
127
128impl<S: BosStr> jacquard_common::IntoStatic for CreateSessionOutputStatus<S>
129where
130 S: BosStr + jacquard_common::IntoStatic,
131 S::Output: BosStr,
132{
133 type Output = CreateSessionOutputStatus<S::Output>;
134 fn into_static(self) -> Self::Output {
135 match self {
136 CreateSessionOutputStatus::Takendown => CreateSessionOutputStatus::Takendown,
137 CreateSessionOutputStatus::Suspended => CreateSessionOutputStatus::Suspended,
138 CreateSessionOutputStatus::Deactivated => {
139 CreateSessionOutputStatus::Deactivated
140 }
141 CreateSessionOutputStatus::Other(v) => {
142 CreateSessionOutputStatus::Other(v.into_static())
143 }
144 }
145 }
146}
147
148
149#[derive(
150 Serialize,
151 Deserialize,
152 Debug,
153 Clone,
154 PartialEq,
155 Eq,
156 thiserror::Error,
157 miette::Diagnostic
158)]
159
160#[serde(tag = "error", content = "message")]
161pub enum CreateSessionError {
162 #[serde(rename = "AccountTakedown")]
163 AccountTakedown(Option<SmolStr>),
164 #[serde(rename = "AuthFactorTokenRequired")]
165 AuthFactorTokenRequired(Option<SmolStr>),
166 #[serde(untagged)]
168 Other { error: SmolStr, message: Option<SmolStr> },
169}
170
171impl core::fmt::Display for CreateSessionError {
172 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
173 match self {
174 Self::AccountTakedown(msg) => {
175 write!(f, "AccountTakedown")?;
176 if let Some(msg) = msg {
177 write!(f, ": {}", msg)?;
178 }
179 Ok(())
180 }
181 Self::AuthFactorTokenRequired(msg) => {
182 write!(f, "AuthFactorTokenRequired")?;
183 if let Some(msg) = msg {
184 write!(f, ": {}", msg)?;
185 }
186 Ok(())
187 }
188 Self::Other { error, message } => {
189 write!(f, "{}", error)?;
190 if let Some(msg) = message {
191 write!(f, ": {}", msg)?;
192 }
193 Ok(())
194 }
195 }
196 }
197}
198
199pub struct CreateSessionResponse;
203impl jacquard_common::xrpc::XrpcResp for CreateSessionResponse {
204 const NSID: &'static str = "com.atproto.server.createSession";
205 const ENCODING: &'static str = "application/json";
206 type Output<S: BosStr> = CreateSessionOutput<S>;
207 type Err = CreateSessionError;
208}
209
210impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for CreateSession<S> {
211 const NSID: &'static str = "com.atproto.server.createSession";
212 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
213 "application/json",
214 );
215 type Response = CreateSessionResponse;
216}
217
218pub struct CreateSessionRequest;
222impl jacquard_common::xrpc::XrpcEndpoint for CreateSessionRequest {
223 const PATH: &'static str = "/xrpc/com.atproto.server.createSession";
224 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
225 "application/json",
226 );
227 type Request<S: BosStr> = CreateSession<S>;
228 type Response = CreateSessionResponse;
229}