Repository Public
1//2// SP Chat iOS3// File: SPChat-iOS/App/AppConfiguration.swift4// Description: Static configuration of the app: backend origin, WebAuthn relying party, cookie names, identifiers.5//6// Author: Simon-Pierre Boucher7// Contact: contact@spboucher.ai8//910import Foundation11import UIKit1213struct AppConfiguration: Sendable, Equatable {14 /// Public origin of the SP Chat backend, shared with the web app and the future macOS app.15 var baseURL: URL16 var userAgent: String1718 /// `scheme://host[:port]` — sent as the Origin header and expected by the server in WebAuthn client data.19 var origin: String {20 var s = "\(baseURL.scheme ?? "https")://\(baseURL.host() ?? "")"21 if let p = baseURL.port { s += ":\(p)" }22 return s23 }24 /// WebAuthn relying-party identifier (the server uses the host of its public URL).25 var relyingParty: String { baseURL.host() ?? "chat.spboucher.ai" }26 var isSecure: Bool { baseURL.scheme == "https" }27 /// The server prefixes its cookies with `__Host-` on HTTPS origins only.28 var sessionCookieName: String { isSecure ? "__Host-csa_session" : "csa_session" }29 var transientCookieNames: Set<String> { isSecure ? ["__Host-csa_ceremony", "__Host-csa_setup"] : ["csa_ceremony", "csa_setup"] }3031 static let productionURL = URL(string: "https://chat.spboucher.ai")!32 static let bundleIdentifier = "ai.spboucher.spchat"33 static let backgroundSyncTaskIdentifier = "ai.spboucher.spchat.sync"34 static let urlScheme = "spchat"3536 @MainActor static func current(processInfo: ProcessInfo = .processInfo) -> AppConfiguration {37 var url = (Bundle.main.object(forInfoDictionaryKey: "SPChatBaseURL") as? String).flatMap(URL.init(string:)) ?? productionURL38 #if DEBUG39 // Debug builds may point at the backend development server (tests, UI tests): SPCHAT_BASE_URL=http://localhost:851040 if let override = processInfo.environment["SPCHAT_BASE_URL"], let u = URL(string: override) { url = u }41 #endif42 let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "1.0"43 let device = UIDevice.current.userInterfaceIdiom == .pad ? "iPad" : "iPhone"44 // "iPhone"/"iPad" makes the server label sessions and passkeys of this app by device type.45 let ua = "SPChat/\(version) (\(device); iOS \(UIDevice.current.systemVersion); native)"46 return AppConfiguration(baseURL: url, userAgent: ua)47 }48}49