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
//! # leash-sdk
//!
//! Rust SDK for the [Leash](https://leash.build) platform — one unified async
//! client for authentication, runtime env vars, and integrations.
//!
//! ## Quick start
//!
//! ```no_run
//! use leash_sdk::{Leash, GmailListParams};
//!
//! # async fn example(req: http::Request<()>) -> leash_sdk::Result<()> {
//! // Construct from any framework request (axum, actix-web, plain http::Request,
//! // anything implementing `LeashRequest`).
//! let leash = Leash::new(&req)?;
//!
//! // Identity
//! let user = leash.auth().user().await?;
//!
//! // Runtime env vars (60s TTL cache, dedicated get_fresh for cache-bypass)
//! let openai_key = leash.env().get("OPENAI_API_KEY").await?;
//!
//! // Integrations
//! let msgs = leash.integrations().gmail().list_messages(GmailListParams {
//! max_results: Some(5),
//! ..Default::default()
//! }).await?;
//! # let _ = (user, openai_key, msgs);
//! # Ok(()) }
//! ```
//!
//! ## Constructors
//!
//! | Use case | Constructor |
//! |---|---|
//! | Request-bound (axum, actix, plain http::Request) | [`Leash::new`] |
//! | Server-to-server | [`Leash::from_api_key`] |
//! | CLI / agent with a user JWT | [`Leash::from_token`] |
//!
//! ## Auth precedence
//!
//! 1. `LEASH_API_KEY` env var (or [`Leash::with_api_key`])
//! 2. `Authorization: Bearer <jwt>` header — used for identity and, when no
//! API key is configured, as a fallback for env-fetch. **Never** forwarded
//! on integration POSTs.
//! 3. `leash-auth` cookie — forwarded to the platform for integration calls.
//!
//! ## Errors
//!
//! [`LeashError`] is a structured enum with convenience predicates:
//!
//! ```no_run
//! # fn handle(err: leash_sdk::LeashError) {
//! if err.is_plan_block() { /* show upgrade UI */ }
//! if err.is_connection_required() { /* show "connect Gmail" CTA */ }
//! if err.is_unauthorized() { /* re-auth */ }
//! # }
//! ```
// ---------------------------------------------------------------------------
// Public surface — kept flat so consumers can `use leash_sdk::{Leash, Result, ...}`
// ---------------------------------------------------------------------------
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use LeashRequest;
// Re-export integration types at the crate root so callers can write
// `use leash_sdk::GmailListParams;` instead of going through the submodule.
pub use ;
/// Convenience marker for callers who want to write
/// `leash.env().get(key, EnvFresh)` style code — see [`Env::get_fresh`] for
/// the actual cache-bypass entry point. Kept as a unit struct for parity with
/// the brief and to give docs a single anchor.
;