initial commit

This commit is contained in:
Jon Vanvik 2026-05-31 14:11:29 +02:00
commit 8de962eeb8
44 changed files with 4843 additions and 0 deletions

69
MCMSConnection.swift Normal file
View file

@ -0,0 +1,69 @@
import Foundation
/// Builds and holds the networking stack for one MCMS connection. Construct this
/// once you have a host + trust policy, then hand the repositories to your view
/// models. Re-create it (or call `reset`) when the host/config changes.
@MainActor
final class MCMSConnection {
let config: APIConfiguration
let session: SessionStore
let client: APIClient
let auth: AuthRepository
let onu: ONURepository
let olt: OLTRepository
let controller: ControllerRepository
init(config: APIConfiguration) {
self.config = config
let session = SessionStore(config: config)
let client = APIClient(config: config, session: session)
self.session = session
self.client = client
self.auth = AuthRepository(client: client, session: session, config: config)
self.onu = ONURepository(client: client)
self.olt = OLTRepository(client: client)
self.controller = ControllerRepository(client: client)
}
/// Fired when any request fails with 401/403 so the app can route back to
/// login. Forwarded to the underlying `APIClient`.
var onAuthExpired: (@MainActor () -> Void)? {
get { client.onAuthExpired }
set { client.onAuthExpired = newValue }
}
}
/*
USAGE SKETCH (delete once real views exist)
// Direct access to the appliance with a self-signed cert on a controlled net:
let url = URL(string: "https://10.2.10.29/api")!
let config = APIConfiguration(
baseURL: url,
apiVersion: "v1", // confirm /api/v1 vs /v1 from openapi.json
databaseId: nil, // or a specific DB id
trustPolicy: .allowSelfSignedForHost("10.2.10.29")
)
// Behind a reverse proxy with a real cert change ONLY the URL + trust:
// let config = APIConfiguration(baseURL: URL(string: "https://mcms.example.com")!,
// trustPolicy: .system)
let connection = MCMSConnection(config: config)
// Login (creds pulled from Keychain in real code):
try await connection.auth.login(email: email, password: password)
// Dashboard data:
let onus = try await connection.onu.allStates()
let counts = Dictionary(grouping: onus, by: { $0.lifecycle }).mapValues(\.count)
// ONU detail:
let stats = try await connection.onu.stats(id: "BFWS00123193", lastHours: 24)
// An operation (gate behind a confirm dialog):
try await connection.onu.reset(id: "BFWS00123193")
try await connection.auth.logout()
*/