Skip to main content

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//! - **Legacy API** ([`LegacyClient`]) — Session/cookie-authenticated endpoints under
13//!   `/api/s/{site}/`. Used for data not yet exposed by the Integration API: events,
14//!   traffic stats, admin users, DPI data, system info, and real-time WebSocket events.
15//!
16//! Both clients share a common [`TransportConfig`] for reqwest-based HTTP transport
17//! with configurable TLS ([`TlsMode`]: system CA, custom PEM, or danger-accept for
18//! self-signed controllers) and timeout settings.
19//!
20//! ## Domain layer
21//!
22//! - **[`Controller`]** — Central facade managing the full lifecycle: authentication,
23//!   background refresh, and command routing.
24//!
25//! - **[`DataStore`]** — Lock-free reactive storage built on `DashMap` + `watch` channels.
26//!
27//! - **[`EntityStream<T>`]** — Subscription handle for TUI reactive rendering.
28//!
29//! - **Domain model** ([`model`]) — Canonical types (`Device`, `Client`, `Network`,
30//!   `FirewallPolicy`, `Event`, etc.) with [`EntityId`] supporting both UUID and
31//!   string-based identifiers.
32
33// ── Transport layer ──────────────────────────────────────────────
34pub mod auth;
35pub mod error;
36pub mod integration;
37pub mod legacy;
38pub mod transport;
39pub mod websocket;
40
41// ── Domain layer (merged from unifly-core) ───────────────────────
42pub mod command;
43pub mod config;
44pub mod controller;
45pub mod convert;
46pub mod core_error;
47pub mod model;
48pub mod store;
49pub mod stream;
50
51// ── Transport re-exports ─────────────────────────────────────────
52pub use auth::{AuthStrategy, ControllerPlatform, Credentials};
53pub use error::Error;
54pub use integration::IntegrationClient;
55pub use integration::types as integration_types;
56pub use legacy::LegacyClient;
57pub use legacy::models as legacy_models;
58pub use transport::{TlsMode, TransportConfig};
59
60// ── Domain re-exports ────────────────────────────────────────────
61pub use command::requests::*;
62pub use command::{Command, CommandResult};
63pub use config::{AuthCredentials, ControllerConfig, TlsVerification};
64pub use controller::{ConnectionState, Controller};
65pub use core_error::CoreError;
66pub use store::DataStore;
67pub use stream::EntityStream;
68
69pub use model::{
70    AclRule, Admin, Alarm, Client, ClientType, Country, Device, DeviceState, DeviceType,
71    DpiApplication, DpiCategory, EntityId, Event, EventCategory, EventSeverity, FirewallPolicy,
72    FirewallZone, HealthSummary, MacAddress, Network, RadiusProfile, Site, SysInfo, SystemInfo,
73    TrafficMatchingList, VpnServer, VpnTunnel, WanInterface,
74};