Skip to main content

Crate leash_sdk

Crate leash_sdk 

Source
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 caseConstructor
Request-bound (axum, actix, plain http::Request)Leash::new
Server-to-serverLeash::from_api_key
CLI / agent with a user JWTLeash::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:

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 Provider escape 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 — 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.
Leash
Unified Leash client.
LeashUser
Authenticated user extracted from a Leash JWT.

Enums§

LeashError
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§

LeashRequest
Any HTTP request the SDK can read auth context off.

Functions§

decode_user
Decode a raw leash-auth JWT into a LeashUser.
get_leash_user
Read the request’s leash-auth cookie and decode it.
is_authenticated
true when get_leash_user would succeed.

Type Aliases§

Result
Convenience: every async call site in the SDK returns this.