@sigit / si Mirror · read-only / commits / b6642d3
Fork 0

Mirror of github.com/getsigit/si.

Mirrored from https://github.com/getsigit/si.git

Synced Nov 24, 08:15 UTC

Add a client builder, optional HTTP stack and account endpoints

Client::builder(environment) accepts an injected reqwest::Client, a user agent, an explicit base URL (which skips SIGIT_HOST) and a client name that is sent in the x-sigit-client header. Client::new and with_token keep working as before. The crate now has a default `client` feature. Without it only the wire types remain (models, ErrorResponse, error::codes, Environment, CLIENT_HEADER), with no reqwest dependency, so code that serves or proxies the API can share them. ErrorResponse, AccountStatus, BillingUrl and GitCredential now implement Serialize. The TLS backend is selectable: rustls-tls-native-roots (default), rustls-tls-webpki-roots or native-tls. With none enabled and no injected client, HTTPS requests fail. New endpoints: sign_up, resend_confirmation and delete_account. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

Seto Elkahfi committed Oct 27, 2026 at 21:18 UTC b6642d3004acae56acbf18d674efe2558a82ec92
12 files changed +342 -40
Cargo.lock
+111 -2
@@ -382,6 +382,21 @@ version = "1.0.7"
382 source = "registry+https://github.com/rust-lang/crates.io-index"
383 checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
384
385 +[[package]]
386 +name = "foreign-types"
387 +version = "0.3.2"
388 +source = "registry+https://github.com/rust-lang/crates.io-index"
389 +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
390 +dependencies = [
391 + "foreign-types-shared",
392 +]
393 +
394 +[[package]]
395 +name = "foreign-types-shared"
396 +version = "0.1.1"
397 +source = "registry+https://github.com/rust-lang/crates.io-index"
398 +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
399 +
400 [[package]]
401 name = "form_urlencoded"
402 version = "1.2.2"
@@ -604,6 +619,23 @@ dependencies = [
619 "tokio",
620 "tokio-rustls",
621 "tower-service",
622 + "webpki-roots",
623 +]
624 +
625 +[[package]]
626 +name = "hyper-tls"
627 +version = "0.6.0"
628 +source = "registry+https://github.com/rust-lang/crates.io-index"
629 +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0"
630 +dependencies = [
631 + "bytes",
632 + "http-body-util",
633 + "hyper",
634 + "hyper-util",
635 + "native-tls",
636 + "tokio",
637 + "tokio-native-tls",
638 + "tower-service",
639 ]
640
641 [[package]]
@@ -928,6 +960,23 @@ dependencies = [
960 "windows-sys 0.61.2",
961 ]
962
963 +[[package]]
964 +name = "native-tls"
965 +version = "0.2.18"
966 +source = "registry+https://github.com/rust-lang/crates.io-index"
967 +checksum = "465500e14ea162429d264d44189adc38b199b62b1c21eea9f69e4b73cb03bbf2"
968 +dependencies = [
969 + "libc",
970 + "log",
971 + "openssl",
972 + "openssl-probe",
973 + "openssl-sys",
974 + "schannel",
975 + "security-framework",
976 + "security-framework-sys",
977 + "tempfile",
978 +]
979 +
980 [[package]]
981 name = "nu-ansi-term"
982 version = "0.50.3"
@@ -968,12 +1017,49 @@ dependencies = [
1017 "libc",
1018 ]
1019
1020 +[[package]]
1021 +name = "openssl"
1022 +version = "0.10.81"
1023 +source = "registry+https://github.com/rust-lang/crates.io-index"
1024 +checksum = "77823a27f0babb03091cb9ed9ef80af3b39dbc82f97e8fa530374b7dafd87a45"
1025 +dependencies = [
1026 + "bitflags",
1027 + "cfg-if",
1028 + "foreign-types",
1029 + "libc",
1030 + "openssl-macros",
1031 + "openssl-sys",
1032 +]
1033 +
1034 +[[package]]
1035 +name = "openssl-macros"
1036 +version = "0.1.1"
1037 +source = "registry+https://github.com/rust-lang/crates.io-index"
1038 +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
1039 +dependencies = [
1040 + "proc-macro2",
1041 + "quote",
1042 + "syn 2.0.119",
1043 +]
1044 +
1045 [[package]]
1046 name = "openssl-probe"
1047 version = "0.2.1"
1048 source = "registry+https://github.com/rust-lang/crates.io-index"
1049 checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe"
1050
1051 +[[package]]
1052 +name = "openssl-sys"
1053 +version = "0.9.117"
1054 +source = "registry+https://github.com/rust-lang/crates.io-index"
1055 +checksum = "b47e7e6bb2c38cd930d25a23b40fa52e068c10e85f3e03a7f5ba5aaca5713695"
1056 +dependencies = [
1057 + "cc",
1058 + "libc",
1059 + "pkg-config",
1060 + "vcpkg",
1061 +]
1062 +
1063 [[package]]
1064 name = "option-ext"
1065 version = "0.2.0"
@@ -1192,9 +1278,11 @@ dependencies = [
1278 "http-body-util",
1279 "hyper",
1280 "hyper-rustls",
1281 + "hyper-tls",
1282 "hyper-util",
1283 "js-sys",
1284 "log",
1285 + "native-tls",
1286 "percent-encoding",
1287 "pin-project-lite",
1288 "quinn",
@@ -1206,6 +1294,7 @@ dependencies = [
1294 "serde_urlencoded",
1295 "sync_wrapper",
1296 "tokio",
1297 + "tokio-native-tls",
1298 "tokio-rustls",
1299 "tower",
1300 "tower-http",
@@ -1214,6 +1303,7 @@ dependencies = [
1303 "wasm-bindgen",
1304 "wasm-bindgen-futures",
1305 "web-sys",
1306 + "webpki-roots",
1307 ]
1308
1309 [[package]]
@@ -1491,7 +1581,7 @@ checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
1581
1582 [[package]]
1583 name = "sigit-si-api"
1494 -version = "1.1.0"
1584 +version = "1.2.0"
1585 dependencies = [
1586 "chrono",
1587 "reqwest",
@@ -1503,7 +1593,7 @@ dependencies = [
1593
1594 [[package]]
1595 name = "sigit-si-cli"
1506 -version = "1.1.0"
1596 +version = "1.2.0"
1597 dependencies = [
1598 "anyhow",
1599 "chrono",
@@ -1740,6 +1830,16 @@ dependencies = [
1830 "syn 3.0.3",
1831 ]
1832
1833 +[[package]]
1834 +name = "tokio-native-tls"
1835 +version = "0.3.1"
1836 +source = "registry+https://github.com/rust-lang/crates.io-index"
1837 +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2"
1838 +dependencies = [
1839 + "native-tls",
1840 + "tokio",
1841 +]
1842 +
1843 [[package]]
1844 name = "tokio-rustls"
1845 version = "0.26.4"
@@ -2031,6 +2131,15 @@ dependencies = [
2131 "wasm-bindgen",
2132 ]
2133
2134 +[[package]]
2135 +name = "webpki-roots"
2136 +version = "1.0.11"
2137 +source = "registry+https://github.com/rust-lang/crates.io-index"
2138 +checksum = "f5f280bbb2b287bc8e7de7e3852945a0ff50d1bbcb5ed42b6c7a568c546df171"
2139 +dependencies = [
2140 + "rustls-pki-types",
2141 +]
2142 +
2143 [[package]]
2144 name = "windows-core"
2145 version = "0.62.2"
Cargo.toml
+5 -8
@@ -3,11 +3,11 @@ resolver = "2"
3 members = ["crates/cli", "crates/sigit-si-api"]
4
5 # The workspace exists for one reason: `sigit-si-api` is a standalone, typed
6 -# client for the sigit.si JSON API that the desktop app (sigit-app) can depend
7 -# on without pulling in clap, dialoguer, and the rest of the terminal surface.
6 +# client for the sigit.si JSON API that other Rust programs can depend on
7 +# without pulling in clap, dialoguer, and the rest of the terminal surface.
8 # `cli` is the thin `si` binary on top of it.
9 [workspace.package]
10 -version = "1.1.0"
10 +version = "1.2.0"
11 edition = "2021"
12 authors = ["Seto Elkahfi <seto@sigit.si>"]
13 license = "Apache-2.0"
@@ -23,10 +23,7 @@ dialoguer = "0.11"
23 dirs = "6.0"
24 git2 = { version = "0.20", default-features = false }
25 open = "5.3"
26 -reqwest = { version = "0.12", default-features = false, features = [
27 - "json",
28 - "rustls-tls-native-roots",
29 -] }
26 +reqwest = { version = "0.12", default-features = false, features = ["json"] }
27 rmcp = { version = "3.2", features = [
28 "server",
29 "macros",
@@ -36,7 +33,7 @@ rmcp = { version = "3.2", features = [
33 schemars = "1"
34 serde = { version = "1", features = ["derive"] }
35 serde_json = "1"
39 -sigit-si-api = { version = "1.1.0", path = "crates/sigit-si-api" }
36 +sigit-si-api = { version = "1.2.0", path = "crates/sigit-si-api" }
37 tabled = { version = "0.20", default-features = false, features = ["std"] }
38 thiserror = "2.0"
39 # `io-std` is what the MCP stdio transport binds to.
README.md
+1 -1
@@ -87,7 +87,7 @@ CI authenticates without an interactive login.
87
88 - **`crates/sigit-si-api`** — a standalone, typed Rust client for the sigit.si
89 JSON API. No CLI dependencies (clap, dialoguer, …); usable from any Rust
90 - project that wants to talk to sigit.si, including the desktop app.
90 + project that wants to talk to sigit.si.
91 - **`crates/cli`** — the `si` binary: command parsing, terminal rendering, git
92 remote resolution, and credential storage, built on top of `sigit-si-api`.
93
crates/cli/Cargo.toml
+1 -1
@@ -24,7 +24,7 @@ dialoguer = { workspace = true }
24 dirs = { workspace = true }
25 git2 = { workspace = true }
26 open = { workspace = true }
27 -reqwest = { workspace = true }
27 +reqwest = { workspace = true, features = ["rustls-tls-native-roots"] }
28 rmcp = { workspace = true }
29 schemars = { workspace = true }
30 serde = { workspace = true }
crates/sigit-si-api/Cargo.toml
+14 -3
@@ -13,8 +13,19 @@ readme = "README.md"
13
14 [dependencies]
15 chrono = { workspace = true }
16 -reqwest = { workspace = true }
16 +reqwest = { workspace = true, optional = true }
17 serde = { workspace = true }
18 serde_json = { workspace = true }
19 -thiserror = { workspace = true }
20 -tracing = { workspace = true }
19 +thiserror = { workspace = true, optional = true }
20 +tracing = { workspace = true, optional = true }
21 +
22 +[features]
23 +default = ["client", "rustls-tls-native-roots"]
24 +# The HTTP client and endpoint modules. Without it the crate is just the wire
25 +# types (`models`, `ErrorResponse`, `error::codes`, `Environment`, `CLIENT_HEADER`).
26 +client = ["dep:reqwest", "dep:thiserror", "dep:tracing"]
27 +# TLS backend for the client the crate builds itself. Pick one, or disable them
28 +# all and inject a `reqwest::Client` through `Client::builder`.
29 +rustls-tls-native-roots = ["client", "reqwest/rustls-tls-native-roots"]
30 +rustls-tls-webpki-roots = ["client", "reqwest/rustls-tls-webpki-roots"]
31 +native-tls = ["client", "reqwest/native-tls"]
crates/sigit-si-api/README.md
+1 -1
@@ -2,7 +2,7 @@
2
3 A typed Rust client for the [sigit.si](https://sigit.si) JSON API. Used by the
4 `si` CLI (`crates/cli` in this workspace) and usable standalone by any Rust
5 -project — the desktop app included.
5 +project.
6
7 ```rust
8 use sigit_si_api::{Client, Environment};
crates/sigit-si-api/src/account.rs
+29
@@ -5,6 +5,7 @@ use crate::{
5 error::Result,
6 models::{AccountStatus, User},
7 };
8 +use reqwest::Method;
9
10 impl Client {
11 /// `POST /api/v1/auth/sign_in`
@@ -24,6 +25,34 @@ impl Client {
25 self.delete("auth/sign_out").await
26 }
27
28 + /// `POST /api/v1/auth/sign_up` — creates an account and sends the
29 + /// confirmation email. The answer is the sign-up result as the server sent
30 + /// it (`code`, `message`, `data`), so it is returned untyped.
31 + pub async fn sign_up(&self, email: &str, password: &str) -> Result<serde_json::Value> {
32 + let body = serde_json::json!({
33 + "email": email.trim().to_ascii_lowercase(),
34 + "password": password,
35 + });
36 + self.post("auth/sign_up", &body).await
37 + }
38 +
39 + /// `POST /api/v1/auth/confirmation/resend` — sends the confirmation email
40 + /// again. The server answers the same way whether or not the address has an
41 + /// account.
42 + pub async fn resend_confirmation(&self, email: &str) -> Result<()> {
43 + let body = serde_json::json!({ "email": email.trim().to_ascii_lowercase() });
44 + self.send_empty(
45 + self.request(Method::POST, "auth/confirmation/resend")
46 + .json(&body),
47 + )
48 + .await
49 + }
50 +
51 + /// `DELETE /api/v1/me` — permanently deletes the signed-in account.
52 + pub async fn delete_account(&self) -> Result<()> {
53 + self.delete("me").await
54 + }
55 +
56 /// `GET /api/v1/user` — the signed-in user's profile.
57 pub async fn user(&self) -> Result<User> {
58 self.get("user").await
crates/sigit-si-api/src/client.rs
+139 -14
@@ -2,8 +2,9 @@
2
3 use {
4 crate::{
5 - environment::Environment,
5 + environment::{normalize_host, Environment},
6 error::{ApiError, ErrorResponse, Result},
7 + CLIENT_HEADER,
8 },
9 reqwest::{Method, RequestBuilder, StatusCode},
10 serde::{de::DeserializeOwned, Serialize},
@@ -22,28 +23,107 @@ pub struct Client {
23 environment: Environment,
24 api_url: String,
25 base_url: String,
26 + client_name: Option<String>,
27 token: Option<String>,
28 }
29
30 +/// Builds a [`Client`]. Get one from [`Client::builder`].
31 +#[derive(Debug)]
32 +pub struct ClientBuilder {
33 + environment: Environment,
34 + http: Option<reqwest::Client>,
35 + user_agent: Option<String>,
36 + base_url: Option<String>,
37 + client_name: Option<String>,
38 + token: Option<String>,
39 +}
40 +
41 +impl ClientBuilder {
42 + /// Use this `reqwest::Client` (and so its connection pool, TLS backend and
43 + /// user agent) instead of building one. Required for HTTPS when the crate
44 + /// is compiled without a TLS feature.
45 + pub fn http_client(mut self, http: reqwest::Client) -> Self {
46 + self.http = Some(http);
47 + self
48 + }
49 +
50 + /// The `User-Agent` of the client the crate builds. Ignored when
51 + /// [`ClientBuilder::http_client`] is set.
52 + pub fn user_agent(mut self, user_agent: &str) -> Self {
53 + self.user_agent = Some(user_agent.to_string());
54 + self
55 + }
56 +
57 + /// An explicit origin such as `https://sigit.si` or `localhost:4000`. A
58 + /// missing scheme takes the environment's default and a trailing slash is
59 + /// dropped. It takes the place of the environment's defaults, so
60 + /// `SIGIT_HOST` has no effect.
61 + pub fn base_url(mut self, base_url: impl Into<String>) -> Self {
62 + self.base_url = Some(base_url.into());
63 + self
64 + }
65 +
66 + /// Name this client in the [`CLIENT_HEADER`] header on every request.
67 + pub fn client_name(mut self, name: &str) -> Self {
68 + self.client_name = Some(name.to_string());
69 + self
70 + }
71 +
72 + /// The bearer token sent on every request.
73 + pub fn token(mut self, token: impl Into<String>) -> Self {
74 + self.token = Some(token.into());
75 + self
76 + }
77 +
78 + pub fn build(self) -> Result<Client> {
79 + let environment = self.environment;
80 + let base_url = match self.base_url {
81 + Some(url) => normalize_host(url.trim(), environment.default_scheme()),
82 + None => environment.base_url(),
83 + };
84 +
85 + let http = match self.http {
86 + Some(http) => http,
87 + None => reqwest::Client::builder()
88 + .user_agent(self.user_agent.as_deref().unwrap_or(USER_AGENT))
89 + .build()
90 + .map_err(|source| ApiError::Transport {
91 + host: base_url.clone(),
92 + source,
93 + })?,
94 + };
95 +
96 + Ok(Client {
97 + http,
98 + environment,
99 + api_url: format!("{base_url}/api/v1"),
100 + base_url,
101 + client_name: self.client_name,
102 + token: self.token,
103 + })
104 + }
105 +}
106 +
107 impl Client {
108 /// An unauthenticated client. Every endpoint on this API needs a token, so
109 /// this is mostly a starting point for [`Client::with_token`].
110 + ///
111 + /// Shorthand for `Client::builder(environment).build()`.
112 pub fn new(environment: Environment) -> Result<Self> {
32 - let http = reqwest::Client::builder()
33 - .user_agent(USER_AGENT)
34 - .build()
35 - .map_err(|source| ApiError::Transport {
36 - host: environment.base_url(),
37 - source,
38 - })?;
113 + Self::builder(environment).build()
114 + }
115
40 - Ok(Self {
41 - http,
116 + /// Start configuring a client: base URL, user agent, client name, or your
117 + /// own `reqwest::Client`.
118 + pub fn builder(environment: Environment) -> ClientBuilder {
119 + ClientBuilder {
120 environment,
43 - api_url: environment.api_url(),
44 - base_url: environment.base_url(),
121 + http: None,
122 + user_agent: None,
123 + base_url: None,
124 + client_name: None,
125 token: None,
46 - })
126 + }
127 }
128
129 /// Attach the bearer token sent on every subsequent request.
@@ -123,7 +203,10 @@ impl Client {
203 /// Build a request against `<api_url>/<path>`, carrying the bearer token.
204 pub fn request(&self, method: Method, path: &str) -> RequestBuilder {
205 let url = format!("{}/{}", self.api_url, path.trim_start_matches('/'));
126 - let builder = self.http.request(method, url);
206 + let mut builder = self.http.request(method, url);
207 + if let Some(name) = &self.client_name {
208 + builder = builder.header(CLIENT_HEADER, name);
209 + }
210 match &self.token {
211 Some(token) => builder.bearer_auth(token),
212 None => builder,
@@ -215,6 +298,48 @@ fn truncate_for_message(body: &str) -> String {
298 mod tests {
299 use super::*;
300
301 + #[test]
302 + fn an_explicit_base_url_replaces_the_environment_default() {
303 + let client = Client::builder(Environment::Production)
304 + .base_url("127.0.0.1:3000/")
305 + .build()
306 + .unwrap();
307 +
308 + assert_eq!(client.base_url(), "https://127.0.0.1:3000");
309 + assert_eq!(client.api_url(), "https://127.0.0.1:3000/api/v1");
310 + }
311 +
312 + #[test]
313 + fn a_bare_base_url_takes_the_environment_scheme() {
314 + let client = Client::builder(Environment::Dev)
315 + .base_url("127.0.0.1:3000")
316 + .build()
317 + .unwrap();
318 + assert_eq!(client.api_url(), "http://127.0.0.1:3000/api/v1");
319 + }
320 +
321 + #[test]
322 + fn requests_carry_the_client_name_and_token() {
323 + let client = Client::builder(Environment::Production)
324 + .base_url("https://sigit.si")
325 + .client_name("example.app")
326 + .token("tok")
327 + .build()
328 + .unwrap();
329 + let request = client.request(Method::DELETE, "/me").build().unwrap();
330 + assert_eq!(request.url().as_str(), "https://sigit.si/api/v1/me");
331 + assert_eq!(request.method(), Method::DELETE);
332 + assert_eq!(request.headers()[CLIENT_HEADER], "example.app");
333 + assert_eq!(request.headers()["authorization"], "Bearer tok");
334 + }
335 +
336 + #[test]
337 + fn requests_omit_the_client_header_by_default() {
338 + let client = Client::new(Environment::Production).unwrap();
339 + let request = client.request(Method::GET, "user").build().unwrap();
340 + assert!(request.headers().get(CLIENT_HEADER).is_none());
341 + }
342 +
343 #[test]
344 fn unauthorized_maps_to_the_dedicated_variant() {
345 let error = Client::error_from(StatusCode::UNAUTHORIZED, r#"{"error_code":100,"m":"x"}"#);
crates/sigit-si-api/src/environment.rs
+2 -2
@@ -50,7 +50,7 @@ impl Environment {
50 }
51 }
52
53 - fn default_scheme(&self) -> &'static str {
53 + pub(crate) fn default_scheme(&self) -> &'static str {
54 match self {
55 Environment::Dev => "http",
56 Environment::Production => "https",
@@ -59,7 +59,7 @@ impl Environment {
59 }
60
61 /// Accept `SIGIT_HOST` with or without a scheme, and strip any trailing slash.
62 -fn normalize_host(host: &str, default_scheme: &str) -> String {
62 +pub(crate) fn normalize_host(host: &str, default_scheme: &str) -> String {
63 let with_scheme = if host.contains("://") {
64 host.to_string()
65 } else {
crates/sigit-si-api/src/error.rs
+4 -1
@@ -2,7 +2,7 @@
2
3 /// The API's error body — `Api::BaseController#render_error` renders every
4 /// failure as `{ "error_code": <i32>, "message": <string> }`.
5 -#[derive(Debug, Clone, serde::Deserialize)]
5 +#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
6 pub struct ErrorResponse {
7 pub error_code: i32,
8 pub message: String,
@@ -16,8 +16,10 @@ pub mod codes {
16 pub const INVALID: i32 = 101;
17 }
18
19 +#[cfg(feature = "client")]
20 pub type Result<T> = std::result::Result<T, ApiError>;
21
22 +#[cfg(feature = "client")]
23 #[derive(Debug, thiserror::Error)]
24 pub enum ApiError {
25 /// The token is missing, expired, or rejected. Callers treat this as
@@ -56,6 +58,7 @@ pub enum ApiError {
58 Parse(String),
59 }
60
61 +#[cfg(feature = "client")]
62 impl ApiError {
63 /// True when the caller should discard the stored credentials.
64 pub fn is_auth_failure(&self) -> bool {
crates/sigit-si-api/src/lib.rs
+30 -2
@@ -19,23 +19,51 @@
19 //! JSON-RPC MCP endpoint at `/api/v1/mcp` — that split is invisible at the call
20 //! site, and can disappear later without breaking callers.
21
22 +//!
23 +//! # Features
24 +//!
25 +//! - `client` (default): the HTTP [`Client`] and the endpoint modules.
26 +//! - `rustls-tls-native-roots` (default), `rustls-tls-webpki-roots`,
27 +//! `native-tls`: the TLS backend of the `reqwest::Client` the crate builds
28 +//! itself. With none of them enabled, HTTPS requests fail unless you pass
29 +//! your own client to [`client::ClientBuilder::http_client`].
30 +//!
31 +//! With `default-features = false` only the wire types remain ([`models`],
32 +//! [`ErrorResponse`], [`error::codes`], [`Environment`], [`CLIENT_HEADER`]),
33 +//! with no HTTP stack. That suits code that serves or proxies this API.
34 +
35 +#[cfg(feature = "client")]
36 pub mod account;
37 +#[cfg(feature = "client")]
38 pub mod billing;
39 +#[cfg(feature = "client")]
40 pub mod client;
41 +#[cfg(feature = "client")]
42 pub mod code;
43 pub mod environment;
44 pub mod error;
45 +#[cfg(feature = "client")]
46 pub mod issues;
47 +#[cfg(feature = "client")]
48 pub mod mcp;
49 pub mod models;
50 +#[cfg(feature = "client")]
51 pub mod pulls;
52 +#[cfg(feature = "client")]
53 pub mod repos;
54 +#[cfg(feature = "client")]
55 pub mod sessions;
56
57 +/// Request header a client uses to name itself. [`client::ClientBuilder::client_name`]
58 +/// sends it on every request.
59 +pub const CLIENT_HEADER: &str = "x-sigit-client";
60 +
61 +pub use {environment::Environment, error::ErrorResponse};
62 +
63 +#[cfg(feature = "client")]
64 pub use {
65 client::Client,
37 - environment::Environment,
38 - error::{ApiError, ErrorResponse, Result},
66 + error::{ApiError, Result},
67 issues::State,
68 repos::NewRepository,
69 };
crates/sigit-si-api/src/models.rs
+5 -5
@@ -23,10 +23,10 @@ pub struct User {
23 pub created_at: DateTime<Utc>,
24 }
25
26 -/// The result of `POST /api/v1/auth/sign_in`, matching the desktop app's
27 -/// `AccountStatus` enum: the bare string `"NotFound"`, `{"Ready":{…}}`, or
26 +/// The result of `POST /api/v1/auth/sign_in`, shaped as an
27 +/// externally tagged enum: the bare string `"NotFound"`, `{"Ready":{…}}`, or
28 /// `{"Incomplete":{…}}`.
29 -#[derive(Debug, Clone, Deserialize)]
29 +#[derive(Debug, Clone, Deserialize, Serialize)]
30 pub enum AccountStatus {
31 NotFound,
32 Ready { access_token: String },
@@ -124,7 +124,7 @@ pub struct Billing {
124 }
125
126 /// `POST /api/v1/billing/checkout`, `POST /api/v1/billing/portal`
127 -#[derive(Debug, Clone, Deserialize)]
127 +#[derive(Debug, Clone, Deserialize, Serialize)]
128 pub struct BillingUrl {
129 pub url: String,
130 }
@@ -132,7 +132,7 @@ pub struct BillingUrl {
132 // ── Git credentials ─────────────────────────────────────────────────────────
133
134 /// `POST /api/v1/git_credentials` — a short-lived, read-scoped git password.
135 -#[derive(Debug, Clone, Deserialize)]
135 +#[derive(Debug, Clone, Deserialize, Serialize)]
136 pub struct GitCredential {
137 pub git_token: String,
138 pub username: String,