beyondigital_auth_sdk/api/mod.rs
1//! A typed client for the service's public and management HTTP API (WP-21 R-21.1).
2//!
3//! Every operation is generated from the service's OpenAPI contract
4//! (`sdk/auth/tools/generate_clients.py` reads `backends/rust/auth_service/api/v1/openapi.json`), so paths,
5//! parameters, bodies and result types cannot drift from the server. The hand-written part is the transport
6//! ([`transport`]: credentials, encoding, errors) and the small support types in [`runtime`]. Token verification and
7//! PKCE helpers stay in the crate root.
8//!
9//! ```ignore
10//! use beyondigital_auth_sdk::api::{ApiClientOptions, ApiCredentials, AuthApiClient};
11//! use beyondigital_auth_sdk::api::generated::types::ConnectionsListPath;
12//!
13//! let api = AuthApiClient::new(
14//! ApiClientOptions::new("https://auth.example.com").with_credentials(ApiCredentials::bearer("token")),
15//! )?;
16//! let connections = api
17//! .connections()
18//! .list(&ConnectionsListPath { account_id, directory_id })
19//! .await?;
20//! ```
21//!
22//! Methods are grouped by the service handler module that answers them (`api.connections()`, `api.oauth()`). Each
23//! takes the parameter groups the operation declares (path, query, headers, body) as references to the structs in
24//! `generated::types`. The generated items are hidden from the rendered reference because there are hundreds of them;
25//! `generated::operations::OPERATIONS` lists every operation by key.
26
27pub mod runtime;
28pub mod transport;
29
30// The generated files own their layout and cover the whole contract, so neither rustfmt nor the lints that guide
31// hand-written code apply to them, and rustdoc leaves them out.
32#[doc(hidden)]
33#[rustfmt::skip]
34#[allow(clippy::all, unused_qualifications, missing_docs)]
35pub mod generated;
36
37pub use generated::client::AuthApiClient;
38pub use runtime::{Maybe, NdjsonPage};
39pub use transport::{
40 ApiClientOptions, ApiCredentials, ApiError, ApiResponseError, CallOptions,
41 ClientBasicCredential, ClientBasicSource, ClientErrorCode, OperationDescriptor, TokenSource,
42 Transport,
43};
44
45impl AuthApiClient {
46 /// Build the client. The base URL must be https, or http to a loopback host.
47 pub fn new(options: ApiClientOptions) -> Result<Self, ApiError> {
48 Ok(Self {
49 transport: std::sync::Arc::new(Transport::new(&options)?),
50 options: CallOptions::default(),
51 })
52 }
53
54 /// The same client with per-call settings (timeout, extra headers, replacement credentials) applied to every call
55 /// made through the returned value.
56 pub fn with_options(&self, options: CallOptions) -> Self {
57 Self {
58 transport: self.transport.clone(),
59 options,
60 }
61 }
62}