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