korzen_bot_protection/lib.rs
1//! Korzen Bot Protection for Rust.
2//!
3//! Asks [Korzen Bot Protection](https://korzen.dev/bot-protection) about a request before a
4//! protected action (`POST /v1/decide`), on API v1, and **fails open**: when Bot Protection is slow,
5//! down, refuses the key or answers anything but a decision, the visitor goes through.
6//!
7//! ```no_run
8//! use axum::{Extension, Router, routing::post};
9//! use korzen_bot_protection::{Client, Decision, Ip, Options};
10//!
11//! # async fn run() -> std::io::Result<()> {
12//! let korzen = Client::new(std::env::var("KORZEN_API_KEY").unwrap_or_default());
13//! let app = Router::new()
14//! .route("/signup", post(signup))
15//! .layer(korzen.layer(Options::new().ip(Ip::LastForwarded).protected_action(true)));
16//! let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await?;
17//! axum::serve(listener, app).await
18//! # }
19//!
20//! async fn signup(decision: Option<Extension<Decision>>) -> &'static str {
21//! "welcome"
22//! }
23//! ```
24
25mod address;
26mod bounds;
27mod call;
28mod client;
29mod context;
30mod exchange;
31mod first_party;
32mod options;
33mod protect;
34mod ratelimit;
35mod readers;
36mod request;
37mod routes;
38mod wire;
39
40pub use address::region_url;
41pub use call::{ALLOW, BLOCK, Error, ErrorKind};
42pub use client::{
43 BoxError, Client, ClientBuilder, DEFAULT_TIMEOUT, DEFAULT_URL, MAX_HOOKS, MAX_TIMEOUT,
44 Transport, TransportFuture, new_transport,
45};
46pub use context::{Context, PhoneType, WireContext, normal_email, normal_phone};
47pub use first_party::DEFAULT_FIRST_PARTY_PATH;
48pub use options::{Hook, Options};
49pub use protect::{Protect, ProtectLayer};
50pub use ratelimit::parse_rate_limit;
51pub use readers::{Cdn, Ip, Reader, Scheme};
52pub use request::{
53 FORWARDED, SIGNED, TOKEN_COOKIE, TOKEN_HEADER, allow_rule_headers, cdn_fields, from_parts,
54 read_token,
55};
56pub use wire::{Answer, Decision, Problem, RateLimit, Request};
57
58/// The SDK's version, which every call names in its Korzen-Sdk header as `rust/<version>`.
59pub const VERSION: &str = env!("CARGO_PKG_VERSION");