jacquard_api/com_atproto/server/
get_service_auth.rs1#[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, Nsid};
15use jacquard_derive::{IntoStatic, lexicon, open_union};
16use serde::{Serialize, Deserialize};
17
18#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
19#[serde(rename_all = "camelCase")]
20pub struct GetServiceAuth<'a> {
21 #[serde(borrow)]
22 pub aud: Did<'a>,
23 #[serde(skip_serializing_if = "Option::is_none")]
24 pub exp: Option<i64>,
25 #[serde(skip_serializing_if = "Option::is_none")]
26 #[serde(borrow)]
27 pub lxm: Option<Nsid<'a>>,
28}
29
30
31#[lexicon]
32#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
33#[serde(rename_all = "camelCase")]
34pub struct GetServiceAuthOutput<'a> {
35 #[serde(borrow)]
36 pub token: CowStr<'a>,
37}
38
39
40#[open_union]
41#[derive(
42 Serialize,
43 Deserialize,
44 Debug,
45 Clone,
46 PartialEq,
47 Eq,
48 thiserror::Error,
49 miette::Diagnostic,
50 IntoStatic
51)]
52
53#[serde(tag = "error", content = "message")]
54#[serde(bound(deserialize = "'de: 'a"))]
55pub enum GetServiceAuthError<'a> {
56 #[serde(rename = "BadExpiration")]
58 BadExpiration(Option<CowStr<'a>>),
59}
60
61impl core::fmt::Display for GetServiceAuthError<'_> {
62 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
63 match self {
64 Self::BadExpiration(msg) => {
65 write!(f, "BadExpiration")?;
66 if let Some(msg) = msg {
67 write!(f, ": {}", msg)?;
68 }
69 Ok(())
70 }
71 Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
72 }
73 }
74}
75
76pub struct GetServiceAuthResponse;
78impl jacquard_common::xrpc::XrpcResp for GetServiceAuthResponse {
79 const NSID: &'static str = "com.atproto.server.getServiceAuth";
80 const ENCODING: &'static str = "application/json";
81 type Output<'de> = GetServiceAuthOutput<'de>;
82 type Err<'de> = GetServiceAuthError<'de>;
83}
84
85impl<'a> jacquard_common::xrpc::XrpcRequest for GetServiceAuth<'a> {
86 const NSID: &'static str = "com.atproto.server.getServiceAuth";
87 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
88 type Response = GetServiceAuthResponse;
89}
90
91pub struct GetServiceAuthRequest;
93impl jacquard_common::xrpc::XrpcEndpoint for GetServiceAuthRequest {
94 const PATH: &'static str = "/xrpc/com.atproto.server.getServiceAuth";
95 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
96 type Request<'de> = GetServiceAuth<'de>;
97 type Response = GetServiceAuthResponse;
98}
99
100pub mod get_service_auth_state {
101
102 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
103 #[allow(unused)]
104 use ::core::marker::PhantomData;
105 mod sealed {
106 pub trait Sealed {}
107 }
108 pub trait State: sealed::Sealed {
110 type Aud;
111 }
112 pub struct Empty(());
114 impl sealed::Sealed for Empty {}
115 impl State for Empty {
116 type Aud = Unset;
117 }
118 pub struct SetAud<S: State = Empty>(PhantomData<fn() -> S>);
120 impl<S: State> sealed::Sealed for SetAud<S> {}
121 impl<S: State> State for SetAud<S> {
122 type Aud = Set<members::aud>;
123 }
124 #[allow(non_camel_case_types)]
126 pub mod members {
127 pub struct aud(());
129 }
130}
131
132pub struct GetServiceAuthBuilder<'a, S: get_service_auth_state::State> {
134 _state: PhantomData<fn() -> S>,
135 _fields: (Option<Did<'a>>, Option<i64>, Option<Nsid<'a>>),
136 _lifetime: PhantomData<&'a ()>,
137}
138
139impl<'a> GetServiceAuth<'a> {
140 pub fn new() -> GetServiceAuthBuilder<'a, get_service_auth_state::Empty> {
142 GetServiceAuthBuilder::new()
143 }
144}
145
146impl<'a> GetServiceAuthBuilder<'a, get_service_auth_state::Empty> {
147 pub fn new() -> Self {
149 GetServiceAuthBuilder {
150 _state: PhantomData,
151 _fields: (None, None, None),
152 _lifetime: PhantomData,
153 }
154 }
155}
156
157impl<'a, S> GetServiceAuthBuilder<'a, S>
158where
159 S: get_service_auth_state::State,
160 S::Aud: get_service_auth_state::IsUnset,
161{
162 pub fn aud(
164 mut self,
165 value: impl Into<Did<'a>>,
166 ) -> GetServiceAuthBuilder<'a, get_service_auth_state::SetAud<S>> {
167 self._fields.0 = Option::Some(value.into());
168 GetServiceAuthBuilder {
169 _state: PhantomData,
170 _fields: self._fields,
171 _lifetime: PhantomData,
172 }
173 }
174}
175
176impl<'a, S: get_service_auth_state::State> GetServiceAuthBuilder<'a, S> {
177 pub fn exp(mut self, value: impl Into<Option<i64>>) -> Self {
179 self._fields.1 = value.into();
180 self
181 }
182 pub fn maybe_exp(mut self, value: Option<i64>) -> Self {
184 self._fields.1 = value;
185 self
186 }
187}
188
189impl<'a, S: get_service_auth_state::State> GetServiceAuthBuilder<'a, S> {
190 pub fn lxm(mut self, value: impl Into<Option<Nsid<'a>>>) -> Self {
192 self._fields.2 = value.into();
193 self
194 }
195 pub fn maybe_lxm(mut self, value: Option<Nsid<'a>>) -> Self {
197 self._fields.2 = value;
198 self
199 }
200}
201
202impl<'a, S> GetServiceAuthBuilder<'a, S>
203where
204 S: get_service_auth_state::State,
205 S::Aud: get_service_auth_state::IsSet,
206{
207 pub fn build(self) -> GetServiceAuth<'a> {
209 GetServiceAuth {
210 aud: self._fields.0.unwrap(),
211 exp: self._fields.1,
212 lxm: self._fields.2,
213 }
214 }
215}