Skip to main content

jacquard_api/com_atproto/server/
create_account.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: com.atproto.server.createAccount
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 CreateAccount<S: BosStr = DefaultStr> {
26    ///Pre-existing atproto DID, being imported to a new account.
27    #[serde(skip_serializing_if = "Option::is_none")]
28    pub did: Option<Did<S>>,
29    #[serde(skip_serializing_if = "Option::is_none")]
30    pub email: Option<S>,
31    ///Requested handle for the account.
32    pub handle: Handle<S>,
33    #[serde(skip_serializing_if = "Option::is_none")]
34    pub invite_code: Option<S>,
35    ///Initial account password. May need to meet instance-specific password strength requirements.
36    #[serde(skip_serializing_if = "Option::is_none")]
37    pub password: Option<S>,
38    ///A signed DID PLC operation to be submitted as part of importing an existing account to this instance. NOTE: this optional field may be updated when full account migration is implemented.
39    #[serde(skip_serializing_if = "Option::is_none")]
40    pub plc_op: Option<Data<S>>,
41    ///DID PLC rotation key (aka, recovery key) to be included in PLC creation operation.
42    #[serde(skip_serializing_if = "Option::is_none")]
43    pub recovery_key: Option<S>,
44    #[serde(skip_serializing_if = "Option::is_none")]
45    pub verification_code: Option<S>,
46    #[serde(skip_serializing_if = "Option::is_none")]
47    pub verification_phone: Option<S>,
48    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
49    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
50}
51
52#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
53#[serde(
54    rename_all = "camelCase",
55    bound(deserialize = "S: Deserialize<'de> + BosStr")
56)]
57pub struct CreateAccountOutput<S: BosStr = DefaultStr> {
58    pub access_jwt: S,
59    ///The DID of the new account.
60    pub did: Did<S>,
61    ///Complete DID document.
62    #[serde(skip_serializing_if = "Option::is_none")]
63    pub did_doc: Option<Data<S>>,
64    pub handle: Handle<S>,
65    pub refresh_jwt: S,
66    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
67    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
68}
69
70#[derive(
71    Serialize, Deserialize, Debug, Clone, PartialEq, Eq, thiserror::Error, miette::Diagnostic,
72)]
73#[serde(tag = "error", content = "message")]
74pub enum CreateAccountError {
75    #[serde(rename = "InvalidHandle")]
76    InvalidHandle(Option<SmolStr>),
77    #[serde(rename = "InvalidPassword")]
78    InvalidPassword(Option<SmolStr>),
79    #[serde(rename = "InvalidInviteCode")]
80    InvalidInviteCode(Option<SmolStr>),
81    #[serde(rename = "HandleNotAvailable")]
82    HandleNotAvailable(Option<SmolStr>),
83    #[serde(rename = "UnsupportedDomain")]
84    UnsupportedDomain(Option<SmolStr>),
85    #[serde(rename = "UnresolvableDid")]
86    UnresolvableDid(Option<SmolStr>),
87    #[serde(rename = "IncompatibleDidDoc")]
88    IncompatibleDidDoc(Option<SmolStr>),
89    /// Catch-all for unknown error codes.
90    #[serde(untagged)]
91    Other {
92        error: SmolStr,
93        message: Option<SmolStr>,
94    },
95}
96
97impl core::fmt::Display for CreateAccountError {
98    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
99        match self {
100            Self::InvalidHandle(msg) => {
101                write!(f, "InvalidHandle")?;
102                if let Some(msg) = msg {
103                    write!(f, ": {}", msg)?;
104                }
105                Ok(())
106            }
107            Self::InvalidPassword(msg) => {
108                write!(f, "InvalidPassword")?;
109                if let Some(msg) = msg {
110                    write!(f, ": {}", msg)?;
111                }
112                Ok(())
113            }
114            Self::InvalidInviteCode(msg) => {
115                write!(f, "InvalidInviteCode")?;
116                if let Some(msg) = msg {
117                    write!(f, ": {}", msg)?;
118                }
119                Ok(())
120            }
121            Self::HandleNotAvailable(msg) => {
122                write!(f, "HandleNotAvailable")?;
123                if let Some(msg) = msg {
124                    write!(f, ": {}", msg)?;
125                }
126                Ok(())
127            }
128            Self::UnsupportedDomain(msg) => {
129                write!(f, "UnsupportedDomain")?;
130                if let Some(msg) = msg {
131                    write!(f, ": {}", msg)?;
132                }
133                Ok(())
134            }
135            Self::UnresolvableDid(msg) => {
136                write!(f, "UnresolvableDid")?;
137                if let Some(msg) = msg {
138                    write!(f, ": {}", msg)?;
139                }
140                Ok(())
141            }
142            Self::IncompatibleDidDoc(msg) => {
143                write!(f, "IncompatibleDidDoc")?;
144                if let Some(msg) = msg {
145                    write!(f, ": {}", msg)?;
146                }
147                Ok(())
148            }
149            Self::Other { error, message } => {
150                write!(f, "{}", error)?;
151                if let Some(msg) = message {
152                    write!(f, ": {}", msg)?;
153                }
154                Ok(())
155            }
156        }
157    }
158}
159
160/** Response marker for the `com.atproto.server.createAccount` procedure.
161
162Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `CreateAccountOutput<S>` for this endpoint.*/
163pub struct CreateAccountResponse;
164impl jacquard_common::xrpc::XrpcResp for CreateAccountResponse {
165    const NSID: &'static str = "com.atproto.server.createAccount";
166    const ENCODING: &'static str = "application/json";
167    type Output<S: BosStr> = CreateAccountOutput<S>;
168    type Err = CreateAccountError;
169}
170
171impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for CreateAccount<S> {
172    const NSID: &'static str = "com.atproto.server.createAccount";
173    const METHOD: jacquard_common::xrpc::XrpcMethod =
174        jacquard_common::xrpc::XrpcMethod::Procedure("application/json");
175    type Response = CreateAccountResponse;
176}
177
178/** Endpoint marker for the `com.atproto.server.createAccount` procedure.
179
180Path: `/xrpc/com.atproto.server.createAccount`. The request payload type is `CreateAccount<S>`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
181pub struct CreateAccountRequest;
182impl jacquard_common::xrpc::XrpcEndpoint for CreateAccountRequest {
183    const PATH: &'static str = "/xrpc/com.atproto.server.createAccount";
184    const METHOD: jacquard_common::xrpc::XrpcMethod =
185        jacquard_common::xrpc::XrpcMethod::Procedure("application/json");
186    type Request<S: BosStr> = CreateAccount<S>;
187    type Response = CreateAccountResponse;
188}
189
190pub mod create_account_state {
191
192    pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
193    #[allow(unused)]
194    use ::core::marker::PhantomData;
195    mod sealed {
196        pub trait Sealed {}
197    }
198    /// State trait tracking which required fields have been set
199    pub trait State: sealed::Sealed {
200        type Handle;
201    }
202    /// Empty state - all required fields are unset
203    pub struct Empty(());
204    impl sealed::Sealed for Empty {}
205    impl State for Empty {
206        type Handle = Unset;
207    }
208    ///State transition - sets the `handle` field to Set
209    pub struct SetHandle<St: State = Empty>(PhantomData<fn() -> St>);
210    impl<St: State> sealed::Sealed for SetHandle<St> {}
211    impl<St: State> State for SetHandle<St> {
212        type Handle = Set<members::handle>;
213    }
214    /// Marker types for field names
215    #[allow(non_camel_case_types)]
216    pub mod members {
217        ///Marker type for the `handle` field
218        pub struct handle(());
219    }
220}
221
222/// Builder for constructing an instance of this type.
223pub struct CreateAccountBuilder<St: create_account_state::State, S: BosStr = DefaultStr> {
224    _state: PhantomData<fn() -> St>,
225    _fields: (
226        Option<Did<S>>,
227        Option<S>,
228        Option<Handle<S>>,
229        Option<S>,
230        Option<S>,
231        Option<Data<S>>,
232        Option<S>,
233        Option<S>,
234        Option<S>,
235    ),
236    _type: PhantomData<fn() -> S>,
237}
238
239impl CreateAccount<DefaultStr> {
240    /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed
241    pub fn new() -> CreateAccountBuilder<create_account_state::Empty, DefaultStr> {
242        CreateAccountBuilder::new()
243    }
244}
245
246impl<S: BosStr> CreateAccount<S> {
247    /// Create a new builder for this type
248    pub fn builder() -> CreateAccountBuilder<create_account_state::Empty, S> {
249        CreateAccountBuilder::builder()
250    }
251}
252
253impl CreateAccountBuilder<create_account_state::Empty, DefaultStr> {
254    /// Create a new builder with all fields unset, using the default string type, if needed
255    pub fn new() -> Self {
256        CreateAccountBuilder {
257            _state: PhantomData,
258            _fields: (None, None, None, None, None, None, None, None, None),
259            _type: PhantomData,
260        }
261    }
262}
263
264impl<S: BosStr> CreateAccountBuilder<create_account_state::Empty, S> {
265    /// Create a new builder with all fields unset
266    pub fn builder() -> Self {
267        CreateAccountBuilder {
268            _state: PhantomData,
269            _fields: (None, None, None, None, None, None, None, None, None),
270            _type: PhantomData,
271        }
272    }
273}
274
275impl<St: create_account_state::State, S: BosStr> CreateAccountBuilder<St, S> {
276    /// Set the `did` field (optional)
277    pub fn did(mut self, value: impl Into<Option<Did<S>>>) -> Self {
278        self._fields.0 = value.into();
279        self
280    }
281    /// Set the `did` field to an Option value (optional)
282    pub fn maybe_did(mut self, value: Option<Did<S>>) -> Self {
283        self._fields.0 = value;
284        self
285    }
286}
287
288impl<St: create_account_state::State, S: BosStr> CreateAccountBuilder<St, S> {
289    /// Set the `email` field (optional)
290    pub fn email(mut self, value: impl Into<Option<S>>) -> Self {
291        self._fields.1 = value.into();
292        self
293    }
294    /// Set the `email` field to an Option value (optional)
295    pub fn maybe_email(mut self, value: Option<S>) -> Self {
296        self._fields.1 = value;
297        self
298    }
299}
300
301impl<St, S: BosStr> CreateAccountBuilder<St, S>
302where
303    St: create_account_state::State,
304    St::Handle: create_account_state::IsUnset,
305{
306    /// Set the `handle` field (required)
307    pub fn handle(
308        mut self,
309        value: impl Into<Handle<S>>,
310    ) -> CreateAccountBuilder<create_account_state::SetHandle<St>, S> {
311        self._fields.2 = Option::Some(value.into());
312        CreateAccountBuilder {
313            _state: PhantomData,
314            _fields: self._fields,
315            _type: PhantomData,
316        }
317    }
318}
319
320impl<St: create_account_state::State, S: BosStr> CreateAccountBuilder<St, S> {
321    /// Set the `inviteCode` field (optional)
322    pub fn invite_code(mut self, value: impl Into<Option<S>>) -> Self {
323        self._fields.3 = value.into();
324        self
325    }
326    /// Set the `inviteCode` field to an Option value (optional)
327    pub fn maybe_invite_code(mut self, value: Option<S>) -> Self {
328        self._fields.3 = value;
329        self
330    }
331}
332
333impl<St: create_account_state::State, S: BosStr> CreateAccountBuilder<St, S> {
334    /// Set the `password` field (optional)
335    pub fn password(mut self, value: impl Into<Option<S>>) -> Self {
336        self._fields.4 = value.into();
337        self
338    }
339    /// Set the `password` field to an Option value (optional)
340    pub fn maybe_password(mut self, value: Option<S>) -> Self {
341        self._fields.4 = value;
342        self
343    }
344}
345
346impl<St: create_account_state::State, S: BosStr> CreateAccountBuilder<St, S> {
347    /// Set the `plcOp` field (optional)
348    pub fn plc_op(mut self, value: impl Into<Option<Data<S>>>) -> Self {
349        self._fields.5 = value.into();
350        self
351    }
352    /// Set the `plcOp` field to an Option value (optional)
353    pub fn maybe_plc_op(mut self, value: Option<Data<S>>) -> Self {
354        self._fields.5 = value;
355        self
356    }
357}
358
359impl<St: create_account_state::State, S: BosStr> CreateAccountBuilder<St, S> {
360    /// Set the `recoveryKey` field (optional)
361    pub fn recovery_key(mut self, value: impl Into<Option<S>>) -> Self {
362        self._fields.6 = value.into();
363        self
364    }
365    /// Set the `recoveryKey` field to an Option value (optional)
366    pub fn maybe_recovery_key(mut self, value: Option<S>) -> Self {
367        self._fields.6 = value;
368        self
369    }
370}
371
372impl<St: create_account_state::State, S: BosStr> CreateAccountBuilder<St, S> {
373    /// Set the `verificationCode` field (optional)
374    pub fn verification_code(mut self, value: impl Into<Option<S>>) -> Self {
375        self._fields.7 = value.into();
376        self
377    }
378    /// Set the `verificationCode` field to an Option value (optional)
379    pub fn maybe_verification_code(mut self, value: Option<S>) -> Self {
380        self._fields.7 = value;
381        self
382    }
383}
384
385impl<St: create_account_state::State, S: BosStr> CreateAccountBuilder<St, S> {
386    /// Set the `verificationPhone` field (optional)
387    pub fn verification_phone(mut self, value: impl Into<Option<S>>) -> Self {
388        self._fields.8 = value.into();
389        self
390    }
391    /// Set the `verificationPhone` field to an Option value (optional)
392    pub fn maybe_verification_phone(mut self, value: Option<S>) -> Self {
393        self._fields.8 = value;
394        self
395    }
396}
397
398impl<St, S: BosStr> CreateAccountBuilder<St, S>
399where
400    St: create_account_state::State,
401    St::Handle: create_account_state::IsSet,
402{
403    /// Build the final struct.
404    pub fn build(self) -> CreateAccount<S> {
405        CreateAccount {
406            did: self._fields.0,
407            email: self._fields.1,
408            handle: self._fields.2.unwrap(),
409            invite_code: self._fields.3,
410            password: self._fields.4,
411            plc_op: self._fields.5,
412            recovery_key: self._fields.6,
413            verification_code: self._fields.7,
414            verification_phone: self._fields.8,
415            extra_data: Default::default(),
416        }
417    }
418    /// Build the final struct with custom extra_data.
419    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> CreateAccount<S> {
420        CreateAccount {
421            did: self._fields.0,
422            email: self._fields.1,
423            handle: self._fields.2.unwrap(),
424            invite_code: self._fields.3,
425            password: self._fields.4,
426            plc_op: self._fields.5,
427            recovery_key: self._fields.6,
428            verification_code: self._fields.7,
429            verification_phone: self._fields.8,
430            extra_data: Some(extra_data),
431        }
432    }
433}