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