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