Skip to main content

uarp_sdk/generated/api/
users.rs

1// Code generated by @uarp/codegen from spec/openapi.json. DO NOT EDIT.
2//!
3//! User management, invites, roles
4
5#![allow(unused_imports, clippy::too_many_arguments)]
6
7use reqwest::Method;
8use serde::{Deserialize, Serialize};
9
10use crate::client::{Client, Request, NO_BODY, NO_QUERY};
11use crate::error::Result;
12use crate::generated::models;
13use crate::multipart::{field_text, FilePart};
14use crate::util::encode_path;
15
16/// User management, invites, roles
17#[derive(Debug, Clone)]
18pub struct UsersApi {
19    pub(crate) client: Client,
20}
21
22impl Client {
23    /// User management, invites, roles
24    pub fn users(&self) -> UsersApi {
25        UsersApi { client: self.clone() }
26    }
27}
28
29impl UsersApi {
30    /// Accept an invite from its email link
31    ///
32    /// The email-link flow. The invite is resolved against the CALLER'S ACTIVE TENANT, which is
33    /// what makes this route unusable from the tenant picker — a cross-tenant invitee is not a
34    /// member of the inviting tenant yet. `POST /api/v1/me/invites/{tenantId}/{inviteId}/accept`
35    /// exists for that case and takes the tenant in the path.
36    ///
37    /// Same two gates as its sibling, in the same order: the presented `token` is compared
38    /// constant-time to the invite's secret, and the caller's email must match the invite's,
39    /// compared case-insensitively. The email check is what stops a member who knows another
40    /// invitee's id from burning that invite — which would create the user record with the
41    /// invitee's email while the audit trail named the wrong actor, and leave the real invitee
42    /// facing an unexplained "already accepted".
43    ///
44    /// `POST /api/v1/users/invites/{inviteId}/accept`
45    ///
46    /// Required scopes: `users:write`.
47    pub async fn accept_invite(&self, invite_id: &str, body: &models::AcceptInviteRequest) -> Result<models::AcceptInviteResponse> {
48        self.client
49            .request_json(Request {
50                method: Method::POST,
51                path: format!("/api/v1/users/invites/{}/accept", encode_path(invite_id)),
52                query: NO_QUERY,
53                body: Some(body),
54                headers: Vec::new(),
55                idempotent: true,
56            })
57            .await
58    }
59
60    /// Delete user
61    ///
62    /// `DELETE /api/v1/users/{userId}`
63    ///
64    /// Required scopes: `users:write`.
65    pub async fn delete(&self, user_id: &str) -> Result<models::DeleteUserResponse> {
66        self.client
67            .request_json(Request {
68                method: Method::DELETE,
69                path: format!("/api/v1/users/{}", encode_path(user_id)),
70                query: NO_QUERY,
71                body: NO_BODY,
72                headers: Vec::new(),
73                idempotent: true,
74            })
75            .await
76    }
77
78    /// Revoke a pending user invite
79    ///
80    /// `DELETE /api/v1/users/invites/{inviteId}`
81    ///
82    /// Required scopes: `users:write`.
83    pub async fn delete_invite(&self, invite_id: &str) -> Result<models::DeleteInviteResponse> {
84        self.client
85            .request_json(Request {
86                method: Method::DELETE,
87                path: format!("/api/v1/users/invites/{}", encode_path(invite_id)),
88                query: NO_QUERY,
89                body: NO_BODY,
90                headers: Vec::new(),
91                idempotent: true,
92            })
93            .await
94    }
95
96    /// Get user
97    ///
98    /// `GET /api/v1/users/{userId}`
99    ///
100    /// Required scopes: `users:read`.
101    pub async fn get(&self, user_id: &str) -> Result<serde_json::Map<String, serde_json::Value>> {
102        self.client
103            .request_json(Request {
104                method: Method::GET,
105                path: format!("/api/v1/users/{}", encode_path(user_id)),
106                query: NO_QUERY,
107                body: NO_BODY,
108                headers: Vec::new(),
109                idempotent: false,
110            })
111            .await
112    }
113
114    /// Invite user
115    ///
116    /// `POST /api/v1/users/invites`
117    ///
118    /// Required scopes: `users:write`.
119    pub async fn invite_user(&self, body: &models::InviteUserRequest) -> Result<models::InviteUserResponse> {
120        self.client
121            .request_json(Request {
122                method: Method::POST,
123                path: "/api/v1/users/invites".to_string(),
124                query: NO_QUERY,
125                body: Some(body),
126                headers: Vec::new(),
127                idempotent: true,
128            })
129            .await
130    }
131
132    /// List users
133    ///
134    /// `GET /api/v1/users`
135    ///
136    /// Required scopes: `users:read`.
137    pub async fn list(&self) -> Result<models::ListUsersResponse> {
138        self.client
139            .request_json(Request {
140                method: Method::GET,
141                path: "/api/v1/users".to_string(),
142                query: NO_QUERY,
143                body: NO_BODY,
144                headers: Vec::new(),
145                idempotent: false,
146            })
147            .await
148    }
149
150    /// List invites
151    ///
152    /// `GET /api/v1/users/invites`
153    ///
154    /// Required scopes: `users:read`.
155    pub async fn list_invites(&self) -> Result<models::ListInvitesResponse> {
156        self.client
157            .request_json(Request {
158                method: Method::GET,
159                path: "/api/v1/users/invites".to_string(),
160                query: NO_QUERY,
161                body: NO_BODY,
162                headers: Vec::new(),
163                idempotent: false,
164            })
165            .await
166    }
167
168    /// Resend the invite email
169    ///
170    /// `POST /api/v1/users/invites/{inviteId}/resend`
171    ///
172    /// Required scopes: `users:write`.
173    pub async fn resend_invite(&self, invite_id: &str) -> Result<models::ResendInviteResponse> {
174        self.client
175            .request_json(Request {
176                method: Method::POST,
177                path: format!("/api/v1/users/invites/{}/resend", encode_path(invite_id)),
178                query: NO_QUERY,
179                body: NO_BODY,
180                headers: Vec::new(),
181                idempotent: true,
182            })
183            .await
184    }
185
186    /// Set user role
187    ///
188    /// `PUT /api/v1/users/{userId}/role`
189    ///
190    /// Required scopes: `users:write`.
191    pub async fn set_user_role(&self, user_id: &str, body: &models::SetUserRoleRequest) -> Result<models::SetUserRoleResponse> {
192        self.client
193            .request_json(Request {
194                method: Method::PUT,
195                path: format!("/api/v1/users/{}/role", encode_path(user_id)),
196                query: NO_QUERY,
197                body: Some(body),
198                headers: Vec::new(),
199                idempotent: true,
200            })
201            .await
202    }
203
204    /// Suspend user
205    ///
206    /// `PUT /api/v1/users/{userId}/suspend`
207    ///
208    /// Required scopes: `users:write`.
209    pub async fn suspend_user(&self, user_id: &str) -> Result<models::SuspendUserResponse> {
210        self.client
211            .request_json(Request {
212                method: Method::PUT,
213                path: format!("/api/v1/users/{}/suspend", encode_path(user_id)),
214                query: NO_QUERY,
215                body: NO_BODY,
216                headers: Vec::new(),
217                idempotent: true,
218            })
219            .await
220    }
221
222    /// Transfer tenant ownership to this user
223    ///
224    /// Demotes the calling owner to admin and promotes the target user to owner. Irreversible
225    /// without a counter-transfer.
226    ///
227    /// `POST /api/v1/users/{userId}/transfer-ownership`
228    ///
229    /// Required scopes: `users:write`.
230    pub async fn transfer_tenant_ownership(&self, user_id: &str) -> Result<models::TransferTenantOwnershipResponse> {
231        self.client
232            .request_json(Request {
233                method: Method::POST,
234                path: format!("/api/v1/users/{}/transfer-ownership", encode_path(user_id)),
235                query: NO_QUERY,
236                body: NO_BODY,
237                headers: Vec::new(),
238                idempotent: true,
239            })
240            .await
241    }
242
243    /// Reverse a suspension and restore the user
244    ///
245    /// `PUT /api/v1/users/{userId}/unsuspend`
246    ///
247    /// Required scopes: `users:write`.
248    pub async fn unsuspend_user(&self, user_id: &str) -> Result<models::UnsuspendUserResponse> {
249        self.client
250            .request_json(Request {
251                method: Method::PUT,
252                path: format!("/api/v1/users/{}/unsuspend", encode_path(user_id)),
253                query: NO_QUERY,
254                body: NO_BODY,
255                headers: Vec::new(),
256                idempotent: true,
257            })
258            .await
259    }
260}