1use std::sync::Arc;
12
13use async_trait::async_trait;
14#[cfg(feature = "mockall")]
15use mockall::automock;
16use reqwest;
17use serde::{Deserialize, Serialize, de::Error as _};
18
19use super::{Error, configuration};
20use crate::{
21 apis::{AuthRequired, ContentType, ResponseContent},
22 models,
23};
24
25#[cfg_attr(feature = "mockall", automock)]
26#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
27#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
28pub trait DevicesApi: Send + Sync {
29 async fn deactivate<'a>(&self, id: &'a str) -> Result<(), Error<DeactivateError>>;
31
32 async fn get<'a>(&self, id: &'a str) -> Result<models::DeviceResponseModel, Error<GetError>>;
34
35 async fn get_all(
37 &self,
38 ) -> Result<models::DeviceAuthRequestResponseModelListResponseModel, Error<GetAllError>>;
39
40 async fn get_by_identifier<'a>(
42 &self,
43 identifier: &'a str,
44 ) -> Result<models::DeviceResponseModel, Error<GetByIdentifierError>>;
45
46 async fn get_by_identifier_query<'a>(
48 &self,
49 x_request_email: &'a str,
50 x_device_identifier: &'a str,
51 ) -> Result<bool, Error<GetByIdentifierQueryError>>;
52
53 async fn post<'a>(
55 &self,
56 device_request_model: Option<models::DeviceRequestModel>,
57 ) -> Result<models::DeviceResponseModel, Error<PostError>>;
58
59 async fn post_lost_trust(&self) -> Result<(), Error<PostLostTrustError>>;
61
62 async fn post_untrust<'a>(
64 &self,
65 untrust_devices_request_model: Option<models::UntrustDevicesRequestModel>,
66 ) -> Result<(), Error<PostUntrustError>>;
67
68 async fn post_update_trust<'a>(
70 &self,
71 update_devices_trust_request_model: Option<models::UpdateDevicesTrustRequestModel>,
72 ) -> Result<(), Error<PostUpdateTrustError>>;
73
74 async fn put<'a>(
76 &self,
77 id: &'a str,
78 device_request_model: Option<models::DeviceRequestModel>,
79 ) -> Result<models::DeviceResponseModel, Error<PutError>>;
80
81 async fn put_clear_token<'a>(
83 &self,
84 identifier: &'a str,
85 ) -> Result<(), Error<PutClearTokenError>>;
86
87 async fn put_keys<'a>(
89 &self,
90 identifier: &'a str,
91 device_keys_request_model: Option<models::DeviceKeysRequestModel>,
92 ) -> Result<models::DeviceResponseModel, Error<PutKeysError>>;
93
94 async fn put_token<'a>(
96 &self,
97 identifier: &'a str,
98 device_token_request_model: Option<models::DeviceTokenRequestModel>,
99 ) -> Result<(), Error<PutTokenError>>;
100
101 async fn put_web_push_auth<'a>(
103 &self,
104 identifier: &'a str,
105 web_push_auth_request_model: Option<models::WebPushAuthRequestModel>,
106 ) -> Result<(), Error<PutWebPushAuthError>>;
107}
108
109pub struct DevicesApiClient {
110 configuration: Arc<configuration::Configuration>,
111}
112
113impl DevicesApiClient {
114 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
115 Self { configuration }
116 }
117}
118
119#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
120#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
121impl DevicesApi for DevicesApiClient {
122 async fn deactivate<'a>(&self, id: &'a str) -> Result<(), Error<DeactivateError>> {
123 let local_var_configuration = &self.configuration;
124
125 let local_var_client = &local_var_configuration.client;
126
127 let local_var_uri_str = format!(
128 "{}/devices/{id}",
129 local_var_configuration.base_path,
130 id = crate::apis::urlencode(id)
131 );
132 let mut local_var_req_builder =
133 local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
134
135 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
136
137 bitwarden_api_base::process_with_empty_response(local_var_req_builder).await
138 }
139
140 async fn get<'a>(&self, id: &'a str) -> Result<models::DeviceResponseModel, Error<GetError>> {
141 let local_var_configuration = &self.configuration;
142
143 let local_var_client = &local_var_configuration.client;
144
145 let local_var_uri_str = format!(
146 "{}/devices/{id}",
147 local_var_configuration.base_path,
148 id = crate::apis::urlencode(id)
149 );
150 let mut local_var_req_builder =
151 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
152
153 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
154
155 bitwarden_api_base::process_with_json_response(local_var_req_builder).await
156 }
157
158 async fn get_all(
159 &self,
160 ) -> Result<models::DeviceAuthRequestResponseModelListResponseModel, Error<GetAllError>> {
161 let local_var_configuration = &self.configuration;
162
163 let local_var_client = &local_var_configuration.client;
164
165 let local_var_uri_str = format!("{}/devices", local_var_configuration.base_path);
166 let mut local_var_req_builder =
167 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
168
169 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
170
171 bitwarden_api_base::process_with_json_response(local_var_req_builder).await
172 }
173
174 async fn get_by_identifier<'a>(
175 &self,
176 identifier: &'a str,
177 ) -> Result<models::DeviceResponseModel, Error<GetByIdentifierError>> {
178 let local_var_configuration = &self.configuration;
179
180 let local_var_client = &local_var_configuration.client;
181
182 let local_var_uri_str = format!(
183 "{}/devices/identifier/{identifier}",
184 local_var_configuration.base_path,
185 identifier = crate::apis::urlencode(identifier)
186 );
187 let mut local_var_req_builder =
188 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
189
190 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
191
192 bitwarden_api_base::process_with_json_response(local_var_req_builder).await
193 }
194
195 async fn get_by_identifier_query<'a>(
196 &self,
197 x_request_email: &'a str,
198 x_device_identifier: &'a str,
199 ) -> Result<bool, Error<GetByIdentifierQueryError>> {
200 let local_var_configuration = &self.configuration;
201
202 let local_var_client = &local_var_configuration.client;
203
204 let local_var_uri_str =
205 format!("{}/devices/knowndevice", local_var_configuration.base_path);
206 let mut local_var_req_builder =
207 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
208
209 local_var_req_builder =
210 local_var_req_builder.header("x-Request-Email", x_request_email.to_string());
211 local_var_req_builder =
212 local_var_req_builder.header("x-Device-Identifier", x_device_identifier.to_string());
213 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
214
215 bitwarden_api_base::process_with_json_response(local_var_req_builder).await
216 }
217
218 async fn post<'a>(
219 &self,
220 device_request_model: Option<models::DeviceRequestModel>,
221 ) -> Result<models::DeviceResponseModel, Error<PostError>> {
222 let local_var_configuration = &self.configuration;
223
224 let local_var_client = &local_var_configuration.client;
225
226 let local_var_uri_str = format!("{}/devices", local_var_configuration.base_path);
227 let mut local_var_req_builder =
228 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
229
230 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
231 local_var_req_builder = local_var_req_builder.json(&device_request_model);
232
233 bitwarden_api_base::process_with_json_response(local_var_req_builder).await
234 }
235
236 async fn post_lost_trust(&self) -> Result<(), Error<PostLostTrustError>> {
237 let local_var_configuration = &self.configuration;
238
239 let local_var_client = &local_var_configuration.client;
240
241 let local_var_uri_str = format!("{}/devices/lost-trust", local_var_configuration.base_path);
242 let mut local_var_req_builder =
243 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
244
245 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
246
247 bitwarden_api_base::process_with_empty_response(local_var_req_builder).await
248 }
249
250 async fn post_untrust<'a>(
251 &self,
252 untrust_devices_request_model: Option<models::UntrustDevicesRequestModel>,
253 ) -> Result<(), Error<PostUntrustError>> {
254 let local_var_configuration = &self.configuration;
255
256 let local_var_client = &local_var_configuration.client;
257
258 let local_var_uri_str = format!("{}/devices/untrust", local_var_configuration.base_path);
259 let mut local_var_req_builder =
260 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
261
262 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
263 local_var_req_builder = local_var_req_builder.json(&untrust_devices_request_model);
264
265 bitwarden_api_base::process_with_empty_response(local_var_req_builder).await
266 }
267
268 async fn post_update_trust<'a>(
269 &self,
270 update_devices_trust_request_model: Option<models::UpdateDevicesTrustRequestModel>,
271 ) -> Result<(), Error<PostUpdateTrustError>> {
272 let local_var_configuration = &self.configuration;
273
274 let local_var_client = &local_var_configuration.client;
275
276 let local_var_uri_str =
277 format!("{}/devices/update-trust", local_var_configuration.base_path);
278 let mut local_var_req_builder =
279 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
280
281 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
282 local_var_req_builder = local_var_req_builder.json(&update_devices_trust_request_model);
283
284 bitwarden_api_base::process_with_empty_response(local_var_req_builder).await
285 }
286
287 async fn put<'a>(
288 &self,
289 id: &'a str,
290 device_request_model: Option<models::DeviceRequestModel>,
291 ) -> Result<models::DeviceResponseModel, Error<PutError>> {
292 let local_var_configuration = &self.configuration;
293
294 let local_var_client = &local_var_configuration.client;
295
296 let local_var_uri_str = format!(
297 "{}/devices/{id}",
298 local_var_configuration.base_path,
299 id = crate::apis::urlencode(id)
300 );
301 let mut local_var_req_builder =
302 local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
303
304 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
305 local_var_req_builder = local_var_req_builder.json(&device_request_model);
306
307 bitwarden_api_base::process_with_json_response(local_var_req_builder).await
308 }
309
310 async fn put_clear_token<'a>(
311 &self,
312 identifier: &'a str,
313 ) -> Result<(), Error<PutClearTokenError>> {
314 let local_var_configuration = &self.configuration;
315
316 let local_var_client = &local_var_configuration.client;
317
318 let local_var_uri_str = format!(
319 "{}/devices/identifier/{identifier}/clear-token",
320 local_var_configuration.base_path,
321 identifier = crate::apis::urlencode(identifier)
322 );
323 let mut local_var_req_builder =
324 local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
325
326 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
327
328 bitwarden_api_base::process_with_empty_response(local_var_req_builder).await
329 }
330
331 async fn put_keys<'a>(
332 &self,
333 identifier: &'a str,
334 device_keys_request_model: Option<models::DeviceKeysRequestModel>,
335 ) -> Result<models::DeviceResponseModel, Error<PutKeysError>> {
336 let local_var_configuration = &self.configuration;
337
338 let local_var_client = &local_var_configuration.client;
339
340 let local_var_uri_str = format!(
341 "{}/devices/{identifier}/keys",
342 local_var_configuration.base_path,
343 identifier = crate::apis::urlencode(identifier)
344 );
345 let mut local_var_req_builder =
346 local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
347
348 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
349 local_var_req_builder = local_var_req_builder.json(&device_keys_request_model);
350
351 bitwarden_api_base::process_with_json_response(local_var_req_builder).await
352 }
353
354 async fn put_token<'a>(
355 &self,
356 identifier: &'a str,
357 device_token_request_model: Option<models::DeviceTokenRequestModel>,
358 ) -> Result<(), Error<PutTokenError>> {
359 let local_var_configuration = &self.configuration;
360
361 let local_var_client = &local_var_configuration.client;
362
363 let local_var_uri_str = format!(
364 "{}/devices/identifier/{identifier}/token",
365 local_var_configuration.base_path,
366 identifier = crate::apis::urlencode(identifier)
367 );
368 let mut local_var_req_builder =
369 local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
370
371 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
372 local_var_req_builder = local_var_req_builder.json(&device_token_request_model);
373
374 bitwarden_api_base::process_with_empty_response(local_var_req_builder).await
375 }
376
377 async fn put_web_push_auth<'a>(
378 &self,
379 identifier: &'a str,
380 web_push_auth_request_model: Option<models::WebPushAuthRequestModel>,
381 ) -> Result<(), Error<PutWebPushAuthError>> {
382 let local_var_configuration = &self.configuration;
383
384 let local_var_client = &local_var_configuration.client;
385
386 let local_var_uri_str = format!(
387 "{}/devices/identifier/{identifier}/web-push-auth",
388 local_var_configuration.base_path,
389 identifier = crate::apis::urlencode(identifier)
390 );
391 let mut local_var_req_builder =
392 local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
393
394 local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
395 local_var_req_builder = local_var_req_builder.json(&web_push_auth_request_model);
396
397 bitwarden_api_base::process_with_empty_response(local_var_req_builder).await
398 }
399}
400
401#[derive(Debug, Clone, Serialize, Deserialize)]
403#[serde(untagged)]
404pub enum DeactivateError {
405 UnknownValue(serde_json::Value),
406}
407#[derive(Debug, Clone, Serialize, Deserialize)]
409#[serde(untagged)]
410pub enum GetError {
411 UnknownValue(serde_json::Value),
412}
413#[derive(Debug, Clone, Serialize, Deserialize)]
415#[serde(untagged)]
416pub enum GetAllError {
417 UnknownValue(serde_json::Value),
418}
419#[derive(Debug, Clone, Serialize, Deserialize)]
421#[serde(untagged)]
422pub enum GetByIdentifierError {
423 UnknownValue(serde_json::Value),
424}
425#[derive(Debug, Clone, Serialize, Deserialize)]
427#[serde(untagged)]
428pub enum GetByIdentifierQueryError {
429 UnknownValue(serde_json::Value),
430}
431#[derive(Debug, Clone, Serialize, Deserialize)]
433#[serde(untagged)]
434pub enum PostError {
435 UnknownValue(serde_json::Value),
436}
437#[derive(Debug, Clone, Serialize, Deserialize)]
439#[serde(untagged)]
440pub enum PostLostTrustError {
441 UnknownValue(serde_json::Value),
442}
443#[derive(Debug, Clone, Serialize, Deserialize)]
445#[serde(untagged)]
446pub enum PostUntrustError {
447 UnknownValue(serde_json::Value),
448}
449#[derive(Debug, Clone, Serialize, Deserialize)]
451#[serde(untagged)]
452pub enum PostUpdateTrustError {
453 UnknownValue(serde_json::Value),
454}
455#[derive(Debug, Clone, Serialize, Deserialize)]
457#[serde(untagged)]
458pub enum PutError {
459 UnknownValue(serde_json::Value),
460}
461#[derive(Debug, Clone, Serialize, Deserialize)]
463#[serde(untagged)]
464pub enum PutClearTokenError {
465 UnknownValue(serde_json::Value),
466}
467#[derive(Debug, Clone, Serialize, Deserialize)]
469#[serde(untagged)]
470pub enum PutKeysError {
471 UnknownValue(serde_json::Value),
472}
473#[derive(Debug, Clone, Serialize, Deserialize)]
475#[serde(untagged)]
476pub enum PutTokenError {
477 UnknownValue(serde_json::Value),
478}
479#[derive(Debug, Clone, Serialize, Deserialize)]
481#[serde(untagged)]
482pub enum PutWebPushAuthError {
483 UnknownValue(serde_json::Value),
484}