Expand description
§leash-sdk
Rust SDK for the Leash platform — one unified async client for authentication, runtime env vars, and integrations.
§Quick start
use leash_sdk::{Leash, GmailListParams};
// 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?;§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
LEASH_API_KEYenv var (orLeash::with_api_key)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.leash-authcookie — forwarded to the platform for integration calls.
§Errors
LeashError is a structured enum with convenience predicates:
if err.is_plan_block() { /* show upgrade UI */ }
if err.is_connection_required() { /* show "connect Gmail" CTA */ }
if err.is_unauthorized() { /* re-auth */ }Re-exports§
pub use integrations::Calendar;pub use integrations::Drive;pub use integrations::Gmail;pub use integrations::Integrations;pub use integrations::Linear;pub use integrations::Provider;pub use integrations::types::CalendarAttendee;pub use integrations::types::CalendarCreateEventParams;pub use integrations::types::CalendarEvent;pub use integrations::types::CalendarEventList;pub use integrations::types::CalendarList;pub use integrations::types::CalendarListEntry;pub use integrations::types::CalendarListEventsParams;pub use integrations::types::ConnectionStatus;pub use integrations::types::DriveFile;pub use integrations::types::DriveFileList;pub use integrations::types::DriveListFilesParams;pub use integrations::types::DriveUploadFileParams;pub use integrations::types::EventDateTime;pub use integrations::types::GmailLabel;pub use integrations::types::GmailLabelList;pub use integrations::types::GmailListParams;pub use integrations::types::GmailMessage;pub use integrations::types::GmailMessageFormat;pub use integrations::types::GmailMessageList;pub use integrations::types::GmailSendMessageParams;pub use integrations::types::Headers;pub use integrations::types::LinearComment;pub use integrations::types::LinearCreateIssueInput;pub use integrations::types::LinearIssue;pub use integrations::types::LinearListIssuesFilter;pub use integrations::types::LinearListIssuesResult;pub use integrations::types::LinearListProjectsFilter;pub use integrations::types::LinearProject;pub use integrations::types::LinearStateRef;pub use integrations::types::LinearTeam;pub use integrations::types::LinearTeamRef;pub use integrations::types::LinearUpdateIssuePatch;pub use integrations::types::LinearUserRef;
Modules§
- integrations
- Typed integration namespaces — Gmail, Calendar, Drive, Linear, plus the
generic
Providerescape hatch for providers without typed wrappers yet (Slack, GitHub, HubSpot, …).
Structs§
- Auth
leash.auth()— non-throwing identity reads off the request that the client was constructed from.- Env
leash.env()— runtime env-var fetcher with an in-memory TTL cache.- EnvFresh
- Convenience marker for callers who want to write
leash.env().get(key, EnvFresh)style code — seeEnv::get_freshfor the actual cache-bypass entry point. Kept as a unit struct for parity with the brief and to give docs a single anchor. - Leash
- Unified Leash client.
- Leash
User - Authenticated user extracted from a Leash JWT.
Enums§
- Leash
Error - The structured error returned by every Leash SDK call.
Constants§
- DEFAULT_
PLATFORM_ URL - Default Leash platform URL.
- ENV_
CACHE_ TTL - Default cache window — matches TS/Python/Go.
- LEASH_
AUTH_ COOKIE - The cookie name set by the Leash platform.
Traits§
- Leash
Request - Any HTTP request the SDK can read auth context off.
Functions§
- decode_
user - Decode a raw
leash-authJWT into aLeashUser. - get_
leash_ user - Read the request’s
leash-authcookie and decode it. - is_
authenticated truewhenget_leash_userwould succeed.
Type Aliases§
- Result
- Convenience: every async call site in the SDK returns this.