wellfriend/lib.rs
1//! The official async Rust SDK for the [Wellfriend](https://wellfriend.dev) document API.
2//!
3//! ```no_run
4//! use wellfriend::Wellfriend;
5//!
6//! # async fn run() -> wellfriend::Result<()> {
7//! let wf = Wellfriend::new();
8//! wf.tools().compress_pdf("in.pdf", None).await?.save("out.pdf").await?;
9//! # Ok(())
10//! # }
11//! ```
12//!
13//! # What is in the box
14//!
15//! * [`Wellfriend::tools`]: one typed method per document tool. Each method uploads the input,
16//! starts the operation, waits for it and returns a [`ToolResult`] you can save or stream.
17//! * [`Wellfriend::pipeline`]: several tools on one file, each step reading the previous output.
18//! * Typed resources for every endpoint, for example [`Wellfriend::documents`] and
19//! [`Wellfriend::document_operations`]. List calls return a [`Page`]; the matching `stream`
20//! method pages through everything.
21//! * Streaming uploads (direct up to 100 MiB, resumable multipart above) and streaming downloads.
22//! * Automatic retries with exponential backoff and idempotency keys, per-request
23//! [`RequestOptions`], and one [`Error`] type.
24//! * [`verify_webhook`] for signed webhook deliveries, returning a typed [`WebhookEvent`].
25//!
26//! # Configuration
27//!
28//! [`Wellfriend::new`] reads `WELLFRIEND_API_KEY` (and optionally `WELLFRIEND_BASE_URL`) from the
29//! environment. Use [`Wellfriend::builder`] to set the key, base URL, timeout, retries, wait limit
30//! or your own `reqwest::Client`.
31//!
32//! # Cancellation
33//!
34//! Every call is a future: dropping it cancels the request. Wrap a call in
35//! `tokio::time::timeout` to bound the whole call, including waiting for an operation.
36
37#![forbid(unsafe_code)]
38#![cfg_attr(docsrs, feature(doc_cfg))]
39#![warn(missing_docs, rust_2018_idioms, unreachable_pub)]
40
41#[macro_use]
42mod macros;
43
44mod client;
45mod download;
46mod embed;
47mod error;
48mod file_input;
49mod models;
50mod operations;
51mod pagination;
52mod pipeline;
53mod retry;
54mod tools;
55mod uploads;
56mod util;
57mod webhooks;
58
59pub mod generated;
60
61pub use client::{RequestOptions, Wellfriend, WellfriendBuilder, DEFAULT_BASE_URL, VERSION};
62pub use download::Download;
63pub use embed::ToolEmbedSession;
64pub use error::{ApiError, Error, OperationFailure, Result};
65pub use file_input::{FileInput, ToolInput};
66pub use models::*;
67pub use pagination::{Page, PageStream};
68pub use pipeline::{DefinedWorkflow, Pipeline, Step, MAX_PIPELINE_STEPS};
69pub use tools::{Asset, ToolParameters, ToolRequest, ToolResult, ToolUsage, Tools};
70pub use uploads::{CHECKSUM_REQUIRED_ABOVE_BYTES, SINGLE_REQUEST_MAX_BYTES};
71pub use webhooks::{
72 verify_webhook, WebhookEvent, WebhookEventMeta, WebhookHeaders, WebhookVerifier, Webhooks,
73 DEFAULT_TOLERANCE as WEBHOOK_TOLERANCE,
74};
75
76pub use generated::events::WebhookEventData;
77pub use generated::models::*;
78pub use generated::resources::*;
79pub use generated::tools::*;
80
81/// Every model in one place: tool parameters (for example [`types::CompressPdfParams`]) and
82/// their choice enums, request and response types, the core resources and webhook payloads.
83/// The same items are also exported at the crate root.
84pub mod types {
85 pub use crate::generated::events::*;
86 pub use crate::generated::models::*;
87 pub use crate::generated::tools::*;
88 pub use crate::models::*;
89}
90
91/// A JSON object, used where the API document does not describe a response in detail.
92pub type Object = serde_json::Map<String, serde_json::Value>;
93
94/// Re-exported so callers can match on JSON values without adding `serde_json` themselves.
95pub use serde_json::Value;