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 site_manager;
41pub mod transport;
42pub mod websocket;
43
44// ── Domain layer (merged from unifly-core) ───────────────────────
45pub mod command;
46pub mod config;
47pub mod controller;
48pub mod convert;
49pub mod core_error;
50pub mod model;
51pub mod store;
52pub mod stream;
53
54// ── Transport re-exports ─────────────────────────────────────────
55pub use auth::{AuthStrategy, ControllerPlatform, Credentials};
56pub use error::Error;
57pub use integration::IntegrationClient;
58pub use integration::types as integration_types;
59pub use session::SessionClient;
60pub use session::models as session_models;
61pub use site_manager::SiteManagerClient;
62pub use site_manager::types as site_manager_types;
63pub use transport::{TlsMode, TransportConfig};
64
65// ── Domain re-exports ────────────────────────────────────────────
66pub use command::requests::*;
67pub use command::{Command, CommandResult};
68pub use config::{AuthCredentials, ControllerConfig, TlsVerification};
69pub use controller::{ApplyPortsSummary, ConnectionState, Controller, PortProfileUpdate};
70pub use core_error::{CoreError, SiteHint};
71pub use store::DataStore;
72pub use stream::EntityStream;
73
74pub use model::{
75 AclRule, Admin, Alarm, Client, ClientType, Country, Device, DeviceState, DeviceType,
76 DpiApplication, DpiCategory, EntityId, Event, EventCategory, EventSeverity, FirewallGroup,
77 FirewallGroupType, FirewallPolicy, FirewallZone, HealthSummary, IpsecSa, MacAddress,
78 MagicSiteToSiteVpnConfig, NatPolicy, NatType, Network, PoeMode, PortMode, PortProfile,
79 PortSpeedSetting, PortState, RadiusProfile, RemoteAccessVpnServer, Site, SiteToSiteVpn,
80 StpState, SysInfo, SystemInfo, TrafficMatchingList, VpnClientConnection, VpnClientProfile,
81 VpnServer, VpnSetting, VpnTunnel, WanInterface, WireGuardPeer,
82};