wellfriend-document-sdk 1.0.0

Official async Rust SDK for the Wellfriend document API: typed document tools, pipelines, streaming uploads and downloads, retries and webhook verification.
Documentation
//! The official async Rust SDK for the [Wellfriend](https://wellfriend.dev) document API.
//!
//! ```no_run
//! use wellfriend::Wellfriend;
//!
//! # async fn run() -> wellfriend::Result<()> {
//! let wf = Wellfriend::new();
//! wf.tools().compress_pdf("in.pdf", None).await?.save("out.pdf").await?;
//! # Ok(())
//! # }
//! ```
//!
//! # What is in the box
//!
//! * [`Wellfriend::tools`]: one typed method per document tool. Each method uploads the input,
//!   starts the operation, waits for it and returns a [`ToolResult`] you can save or stream.
//! * [`Wellfriend::pipeline`]: several tools on one file, each step reading the previous output.
//! * Typed resources for every endpoint, for example [`Wellfriend::documents`] and
//!   [`Wellfriend::document_operations`]. List calls return a [`Page`]; the matching `stream`
//!   method pages through everything.
//! * Streaming uploads (direct up to 100 MiB, resumable multipart above) and streaming downloads.
//! * Automatic retries with exponential backoff and idempotency keys, per-request
//!   [`RequestOptions`], and one [`Error`] type.
//! * [`verify_webhook`] for signed webhook deliveries, returning a typed [`WebhookEvent`].
//!
//! # Configuration
//!
//! [`Wellfriend::new`] reads `WELLFRIEND_API_KEY` (and optionally `WELLFRIEND_BASE_URL`) from the
//! environment. Use [`Wellfriend::builder`] to set the key, base URL, timeout, retries, wait limit
//! or your own `reqwest::Client`.
//!
//! # Cancellation
//!
//! Every call is a future: dropping it cancels the request. Wrap a call in
//! `tokio::time::timeout` to bound the whole call, including waiting for an operation.

#![forbid(unsafe_code)]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![warn(missing_docs, rust_2018_idioms, unreachable_pub)]

#[macro_use]
mod macros;

mod client;
mod download;
mod embed;
mod error;
mod file_input;
mod models;
mod operations;
mod pagination;
mod pipeline;
mod retry;
mod tools;
mod uploads;
mod util;
mod webhooks;

pub mod generated;

pub use client::{RequestOptions, Wellfriend, WellfriendBuilder, DEFAULT_BASE_URL, VERSION};
pub use download::Download;
pub use embed::ToolEmbedSession;
pub use error::{ApiError, Error, OperationFailure, Result};
pub use file_input::{FileInput, ToolInput};
pub use models::*;
pub use pagination::{Page, PageStream};
pub use pipeline::{DefinedWorkflow, Pipeline, Step, MAX_PIPELINE_STEPS};
pub use tools::{Asset, ToolParameters, ToolRequest, ToolResult, ToolUsage, Tools};
pub use uploads::{CHECKSUM_REQUIRED_ABOVE_BYTES, SINGLE_REQUEST_MAX_BYTES};
pub use webhooks::{
    verify_webhook, WebhookEvent, WebhookEventMeta, WebhookHeaders, WebhookVerifier, Webhooks,
    DEFAULT_TOLERANCE as WEBHOOK_TOLERANCE,
};

pub use generated::events::WebhookEventData;
pub use generated::models::*;
pub use generated::resources::*;
pub use generated::tools::*;

/// Every model in one place: tool parameters (for example [`types::CompressPdfParams`]) and
/// their choice enums, request and response types, the core resources and webhook payloads.
/// The same items are also exported at the crate root.
pub mod types {
    pub use crate::generated::events::*;
    pub use crate::generated::models::*;
    pub use crate::generated::tools::*;
    pub use crate::models::*;
}

/// A JSON object, used where the API document does not describe a response in detail.
pub type Object = serde_json::Map<String, serde_json::Value>;

/// Re-exported so callers can match on JSON values without adding `serde_json` themselves.
pub use serde_json::Value;