Skip to content

Commit 0d57e1f

Browse files
authored
docs(relay): add API documentation for RelayClient and its methods (#6970)
Add detailed Rust doc comments to `RelayClient`, `RelayAddress`, and all public methods to clarify usage, parameters, authentication, and known server limitations for the Relay API client.
1 parent f7cdd27 commit 0d57e1f

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

components/relay/src/lib.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,33 @@ use serde::{Deserialize, Serialize};
1313
use url::Url;
1414
use viaduct::{header_names, Method, Request};
1515

16+
/// Represents a client for the Relay API.
17+
///
18+
/// Use this struct to connect and authenticate with a Relay server,
19+
/// managing authorization to call protected endpoints.
20+
///
21+
/// # Authorization
22+
/// - Clients should use the [fxa_client::FirefoxAccount::getAccessToken()] function
23+
/// to obtain a relay-scoped access token (scope: `https://identity.mozilla.com/apps/relay`).
24+
/// - Then, construct the [`RelayClient`] with the access token.
25+
/// All requests will then be authenticated to the Relay server via `Authorization: Bearer {fxa-access-token}`.
26+
/// - The Relay server verifies this token with the FxA OAuth `/verify` endpoint.
27+
/// - Clients are responsible for getting a new access token when needed.
1628
#[derive(uniffi::Object)]
1729
pub struct RelayClient {
30+
/// Base URL for the Relay server.
1831
server_url: String,
32+
/// Optional authentication token for API requests.
1933
auth_token: Option<String>,
2034
}
2135

36+
/// Represents a Relay email address object returned by the Relay API.
37+
///
38+
/// Includes metadata and statistics for an alias, such as its status,
39+
/// usage stats, and identifying information.
40+
///
41+
/// See:
42+
/// https://mozilla.github.io/fx-private-relay/api_docs.html
2243
#[derive(Debug, Deserialize, uniffi::Record)]
2344
pub struct RelayAddress {
2445
pub mask_type: String,
@@ -71,6 +92,14 @@ impl RelayClient {
7192

7293
#[uniffi::export]
7394
impl RelayClient {
95+
/// Creates a new `RelayClient` instance.
96+
///
97+
/// # Parameters
98+
/// - `server_url`: Base URL for the Relay API.
99+
/// - `auth_token`: Optional relay-scoped access token (see struct docs).
100+
///
101+
/// # Returns
102+
/// A new [`RelayClient`] configured for the specified server and token.
74103
#[uniffi::constructor]
75104
#[handle_error(Error)]
76105
pub fn new(server_url: String, auth_token: Option<String>) -> ApiResult<Self> {
@@ -80,6 +109,13 @@ impl RelayClient {
80109
})
81110
}
82111

112+
/// Retrieves all Relay addresses associated with the current account.
113+
///
114+
/// Returns a vector of [`RelayAddress`] objects on success, or an error if the request fails.
115+
///
116+
/// ## Known Limitations
117+
/// - Will return an error if the Relay user record doesn't exist yet (see [`accept_terms`]).
118+
/// - Error variants are subject to server-side changes.
83119
#[handle_error(Error)]
84120
pub fn fetch_addresses(&self) -> ApiResult<Vec<RelayAddress>> {
85121
let url = self.build_url("/api/v1/relayaddresses/")?;
@@ -96,6 +132,11 @@ impl RelayClient {
96132
Ok(addresses)
97133
}
98134

135+
/// Creates a Relay user record in the Relay service database.
136+
///
137+
/// This function was originally used to signal acceptance of terms and privacy notices,
138+
/// but now primarily serves to provision (create) the Relay user record if one does not exist.
139+
/// Returns `Ok(())` on success, or an error if the server call fails.
99140
#[handle_error(Error)]
100141
pub fn accept_terms(&self) -> ApiResult<()> {
101142
let url = self.build_url("/api/v1/terms-accepted-user/")?;
@@ -110,6 +151,19 @@ impl RelayClient {
110151
Ok(())
111152
}
112153

154+
/// Creates a new Relay mask (alias) with the specified metadata.
155+
///
156+
/// This is used to generate a new alias for use in an email field.
157+
///
158+
/// - `description`: A label shown in the Relay dashboard; defaults to `generated_for`, user-editable later.
159+
/// - `generated_for`: The website for which the address is generated.
160+
/// - `used_on`: Comma-separated list of all websites where this address is used. Only updated by some clients.
161+
///
162+
/// ## Open Questions
163+
/// - See the spike doc and project Jira for clarifications on field semantics.
164+
/// - Returned error codes are not fully documented.
165+
///
166+
/// Returns the newly created [`RelayAddress`] on success, or an error.
113167
#[handle_error(Error)]
114168
pub fn create_address(
115169
&self,

0 commit comments

Comments
 (0)