1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
// Code generated by oagen. DO NOT EDIT.
use crate::client::Client;
#[allow(unused_imports)]
use crate::enums::*;
use crate::error::Error;
#[allow(unused_imports)]
use crate::models::*;
use serde::Serialize;
pub struct OrganizationsApi<'a> {
pub(crate) client: &'a Client,
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct ListOrganizationsParams {
/// An object ID that defines your place in the list. When the ID is not present, you are at the end of the list. For example, if you make a list request and receive 100 objects, ending with `"obj_123"`, your subsequent call can include `before="obj_123"` to fetch a new batch of objects before `"obj_123"`.
#[serde(skip_serializing_if = "Option::is_none")]
pub before: Option<String>,
/// An object ID that defines your place in the list. When the ID is not present, you are at the end of the list. For example, if you make a list request and receive 100 objects, ending with `"obj_123"`, your subsequent call can include `after="obj_123"` to fetch a new batch of objects after `"obj_123"`.
#[serde(skip_serializing_if = "Option::is_none")]
pub after: Option<String>,
/// Upper limit on the number of objects to return, between `1` and `100`.
#[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<i64>,
/// Order the results by the creation time. Supported values are `"asc"` (ascending), `"desc"` (descending), and `"normal"` (descending with reversed cursor semantics where `before` fetches older records and `after` fetches newer records). Defaults to descending.
#[serde(skip_serializing_if = "Option::is_none")]
pub order: Option<PaginationOrder>,
/// The domains of an Organization. Any Organization with a matching domain will be returned.
#[serde(skip_serializing_if = "Option::is_none")]
pub domains: Option<Vec<String>>,
/// Searchable text for an Organization. Matches against the organization name.
#[serde(skip_serializing_if = "Option::is_none")]
pub search: Option<String>,
}
#[derive(Debug, Clone, Serialize)]
pub struct CreateOrganizationParams {
/// Request body sent with this call.
///
/// Required.
#[serde(skip)]
pub body: OrganizationInput,
}
impl CreateOrganizationParams {
/// Construct a new `CreateOrganizationParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: OrganizationInput) -> Self {
Self { body }
}
}
#[derive(Debug, Clone, Serialize)]
pub struct UpdateOrganizationParams {
/// Request body sent with this call.
///
/// Required.
#[serde(skip)]
pub body: UpdateOrganization,
}
impl UpdateOrganizationParams {
/// Construct a new `UpdateOrganizationParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: UpdateOrganization) -> Self {
Self { body }
}
}
impl<'a> OrganizationsApi<'a> {
/// List Organizations
///
/// Get a list of all of your existing organizations matching the criteria specified.
pub async fn list_organizations(
&self,
params: ListOrganizationsParams,
) -> Result<OrganizationList, Error> {
self.list_organizations_with_options(params, None).await
}
/// Variant of [`Self::list_organizations`] that accepts per-request [`crate::RequestOptions`].
pub async fn list_organizations_with_options(
&self,
params: ListOrganizationsParams,
options: Option<&crate::RequestOptions>,
) -> Result<OrganizationList, Error> {
let path = "/organizations".to_string();
let method = http::Method::GET;
self.client
.request_with_query_opts(method, &path, ¶ms, options)
.await
}
/// Returns an async [`futures_util::Stream`] that yields every `Organization`
/// across all pages, advancing the `after` cursor under the hood.
///
/// ```ignore
/// use futures_util::TryStreamExt;
/// let all: Vec<Organization> = self
/// .list_organizations_auto_paging(params)
/// .try_collect()
/// .await?;
/// ```
pub fn list_organizations_auto_paging(
&self,
params: ListOrganizationsParams,
) -> impl futures_util::Stream<Item = Result<Organization, Error>> + '_ {
crate::pagination::auto_paginate_pages(move |after| {
let mut params = params.clone();
params.after = after;
async move {
let page = self.list_organizations(params).await?;
Ok((page.data, page.list_metadata.after))
}
})
}
/// Create an Organization
///
/// Creates a new organization in the current environment.
pub async fn create_organization(
&self,
params: CreateOrganizationParams,
) -> Result<Organization, Error> {
self.create_organization_with_options(params, None).await
}
/// Variant of [`Self::create_organization`] that accepts per-request [`crate::RequestOptions`].
pub async fn create_organization_with_options(
&self,
params: CreateOrganizationParams,
options: Option<&crate::RequestOptions>,
) -> Result<Organization, Error> {
let path = "/organizations".to_string();
let method = http::Method::POST;
self.client
.request_with_body_opts(method, &path, ¶ms, Some(¶ms.body), options)
.await
}
/// Get an Organization by External ID
///
/// Get the details of an existing organization by an [external identifier](https://workos.com/docs/authkit/metadata/external-identifiers).
pub async fn get_organization_by_external_id(
&self,
external_id: &str,
) -> Result<Organization, Error> {
self.get_organization_by_external_id_with_options(external_id, None)
.await
}
/// Variant of [`Self::get_organization_by_external_id`] that accepts per-request [`crate::RequestOptions`].
pub async fn get_organization_by_external_id_with_options(
&self,
external_id: &str,
options: Option<&crate::RequestOptions>,
) -> Result<Organization, Error> {
let external_id = crate::client::path_segment(external_id);
let path = format!("/organizations/external_id/{external_id}");
let method = http::Method::GET;
self.client
.request_with_query_opts(method, &path, &(), options)
.await
}
/// Get an Organization
///
/// Get the details of an existing organization.
pub async fn get_organization(&self, id: &str) -> Result<Organization, Error> {
self.get_organization_with_options(id, None).await
}
/// Variant of [`Self::get_organization`] that accepts per-request [`crate::RequestOptions`].
pub async fn get_organization_with_options(
&self,
id: &str,
options: Option<&crate::RequestOptions>,
) -> Result<Organization, Error> {
let id = crate::client::path_segment(id);
let path = format!("/organizations/{id}");
let method = http::Method::GET;
self.client
.request_with_query_opts(method, &path, &(), options)
.await
}
/// Update an Organization
///
/// Updates an organization in the current environment.
pub async fn update_organization(
&self,
id: &str,
params: UpdateOrganizationParams,
) -> Result<Organization, Error> {
self.update_organization_with_options(id, params, None)
.await
}
/// Variant of [`Self::update_organization`] that accepts per-request [`crate::RequestOptions`].
pub async fn update_organization_with_options(
&self,
id: &str,
params: UpdateOrganizationParams,
options: Option<&crate::RequestOptions>,
) -> Result<Organization, Error> {
let id = crate::client::path_segment(id);
let path = format!("/organizations/{id}");
let method = http::Method::PUT;
self.client
.request_with_body_opts(method, &path, ¶ms, Some(¶ms.body), options)
.await
}
/// Delete an Organization
///
/// Permanently deletes an organization in the current environment. It cannot be undone.
pub async fn delete_organization(&self, id: &str) -> Result<(), Error> {
self.delete_organization_with_options(id, None).await
}
/// Variant of [`Self::delete_organization`] that accepts per-request [`crate::RequestOptions`].
pub async fn delete_organization_with_options(
&self,
id: &str,
options: Option<&crate::RequestOptions>,
) -> Result<(), Error> {
let id = crate::client::path_segment(id);
let path = format!("/organizations/{id}");
let method = http::Method::DELETE;
self.client
.request_with_query_opts_empty(method, &path, &(), options)
.await
}
/// Get Audit Log Configuration
///
/// Get the unified view of audit log trail and stream configuration for an organization.
pub async fn get_audit_log_configuration(
&self,
id: &str,
) -> Result<AuditLogConfiguration, Error> {
self.get_audit_log_configuration_with_options(id, None)
.await
}
/// Variant of [`Self::get_audit_log_configuration`] that accepts per-request [`crate::RequestOptions`].
pub async fn get_audit_log_configuration_with_options(
&self,
id: &str,
options: Option<&crate::RequestOptions>,
) -> Result<AuditLogConfiguration, Error> {
let id = crate::client::path_segment(id);
let path = format!("/organizations/{id}/audit_log_configuration");
let method = http::Method::GET;
self.client
.request_with_query_opts(method, &path, &(), options)
.await
}
}