unifly_api/lib.rs
1//! Async Rust client and reactive data layer for UniFi controller APIs.
2//!
3//! This crate provides both the HTTP transport layer and the domain model
4//! for communicating with UniFi Network controllers.
5//!
6//! ## Transport layer
7//!
8//! - **Integration API** ([`IntegrationClient`]) — RESTful OpenAPI-based interface
9//! authenticated via `X-API-KEY` header. Primary surface for CRUD operations on
10//! devices, clients, networks, firewall rules, and other managed entities.
11//!
12//! - **Session API** ([`SessionClient`]) — UniFi's internal `/api/` and `/v2/api/`
13//! surface, authenticated by session cookie + CSRF (username/password login) or
14//! by Integration `X-API-KEY` on UniFi OS. Covers data not yet exposed by the
15//! Integration API: events, traffic stats, admin users, DPI data, system info,
16//! and real-time WebSocket events (WebSocket still requires the cookie session).
17//!
18//! Both clients share a common [`TransportConfig`] for reqwest-based HTTP transport
19//! with configurable TLS ([`TlsMode`]: system CA, custom PEM, or danger-accept for
20//! self-signed controllers) and timeout settings.
21//!
22//! ## Domain layer
23//!
24//! - **[`Controller`]** — Central facade managing the full lifecycle: authentication,
25//! background refresh, and command routing.
26//!
27//! - **[`DataStore`]** — Lock-free reactive storage built on `DashMap` + `watch` channels.
28//!
29//! - **[`EntityStream<T>`]** — Subscription handle for TUI reactive rendering.
30//!
31//! - **Domain model** ([`model`]) — Canonical types (`Device`, `Client`, `Network`,
32//! `FirewallPolicy`, `Event`, etc.) with [`EntityId`] supporting both UUID and
33//! string-based identifiers.
34
35// ── Transport layer ──────────────────────────────────────────────
36pub mod auth;
37pub mod error;
38pub mod integration;
39pub mod session;
40pub mod transport;
41pub mod websocket;
42
43// ── Domain layer (merged from unifly-core) ───────────────────────
44pub mod command;
45pub mod config;
46pub mod controller;
47pub mod convert;
48pub mod core_error;
49pub mod model;
50pub mod store;
51pub mod stream;
52
53// ── Transport re-exports ─────────────────────────────────────────
54pub use auth::{AuthStrategy, ControllerPlatform, Credentials};
55pub use error::Error;
56pub use integration::IntegrationClient;
57pub use integration::types as integration_types;
58pub use session::SessionClient;
59pub use session::models as session_models;
60pub use transport::{TlsMode, TransportConfig};
61
62// ── Domain re-exports ────────────────────────────────────────────
63pub use command::requests::*;
64pub use command::{Command, CommandResult};
65pub use config::{AuthCredentials, ControllerConfig, TlsVerification};
66pub use controller::{ConnectionState, Controller};
67pub use core_error::CoreError;
68pub use store::DataStore;
69pub use stream::EntityStream;
70
71pub use model::{
72 AclRule, Admin, Alarm, Client, ClientType, Country, Device, DeviceState, DeviceType,
73 DpiApplication, DpiCategory, EntityId, Event, EventCategory, EventSeverity, FirewallPolicy,
74 FirewallZone, HealthSummary, IpsecSa, MacAddress, MagicSiteToSiteVpnConfig, NatPolicy, NatType,
75 Network, RadiusProfile, RemoteAccessVpnServer, Site, SiteToSiteVpn, SysInfo, SystemInfo,
76 TrafficMatchingList, VpnClientConnection, VpnClientProfile, VpnServer, VpnSetting, VpnTunnel,
77 WanInterface, WireGuardPeer,
78};