shipper_registry/lib.rs
1//! Registry API client for shipper.
2//!
3//! This crate provides API clients for interacting with crate registries
4//! like crates.io, supporting version existence checks, sparse-index visibility
5//! polling, ownership verification, and readiness backoff loops.
6//!
7//! # Modules
8//!
9//! - [`context`] — the primary [`RegistryClient`] that is `Registry`-aware.
10//! Accepts a full [`shipper_types::Registry`] (name, api_base, index_base)
11//! and exposes the complete registry surface used by the shipper library:
12//! API existence checks, sparse-index visibility, owner queries,
13//! `is_version_visible_with_backoff` with exponential-backoff evidence, etc.
14//! - [`http`] — a lightweight HTTP client [`http::HttpRegistryClient`] that
15//! takes a bare base-URL string. Intended for callers that do not need the
16//! full `Registry` context (e.g. the parallel engine helper crate).
17//!
18//! # Example
19//!
20//! ```no_run
21//! use shipper_registry::RegistryClient;
22//! use shipper_types::Registry;
23//!
24//! let registry = Registry::crates_io();
25//! let client = RegistryClient::new(registry).expect("client");
26//! let visible = client.version_exists("serde", "1.0.0").unwrap_or(false);
27//! ```
28
29pub mod context;
30pub mod http;
31
32// Primary public API: the canonical, Registry-aware client.
33pub use context::{Owner, OwnersResponse, RegistryClient};
34
35// Lightweight HTTP client for callers that only have a base URL.
36pub use http::HttpRegistryClient;
37
38// Additional types useful to external callers.
39pub use http::{CrateInfo, OwnersApiUser};
40
41/// Default API endpoint for crates.io
42pub const CRATES_IO_API: &str = "https://crates.io";
43
44/// Default timeout for API requests (used by [`HttpRegistryClient`]).
45pub const DEFAULT_TIMEOUT_SECS: u64 = 30;
46
47/// Default user agent for API requests.
48pub const USER_AGENT: &str = concat!("shipper/", env!("CARGO_PKG_VERSION"));
49
50/// Compute the sparse-index path for a crate name.
51pub fn sparse_index_path(crate_name: &str) -> String {
52 shipper_sparse_index::sparse_index_path(crate_name)
53}
54
55/// Check if a crate version is visible on the registry via its API.
56///
57/// Convenience wrapper that constructs an [`HttpRegistryClient`] and calls
58/// [`HttpRegistryClient::version_exists`].
59pub fn is_version_visible(base_url: &str, name: &str, version: &str) -> anyhow::Result<bool> {
60 let client = HttpRegistryClient::new(base_url);
61 client.version_exists(name, version)
62}
63
64/// Check if a crate exists on the registry via its API.
65///
66/// Convenience wrapper that constructs an [`HttpRegistryClient`] and calls
67/// [`HttpRegistryClient::crate_exists`].
68pub fn is_crate_visible(base_url: &str, name: &str) -> anyhow::Result<bool> {
69 let client = HttpRegistryClient::new(base_url);
70 client.crate_exists(name)
71}