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