import Foundation /// An active public share for one session (`SessionShare`, /// `shared/src/apiTypes.ts`). The access code is never returned by list/get /// endpoints — only when the share is created or regenerated. public struct SessionShare: Codable, Equatable, Sendable, Identifiable { public var id: String public var sessionId: String public var shareToken: String public var createdAt: Int public var updatedAt: Int public init( id: String, sessionId: String, shareToken: String, createdAt: Int, updatedAt: Int ) { self.id = id self.sessionId = sessionId self.shareToken = shareToken self.createdAt = createdAt self.updatedAt = updatedAt } } /// `POST /api/session-shares` — the raw access code is shown exactly once. public struct SessionShareCreateResponse: Codable, Equatable, Sendable { public var share: SessionShare public var accessCode: String public init(share: SessionShare, accessCode: String) { self.share = share self.accessCode = accessCode } } /// `GET /api/session-shares/session/:id` (null when no share is active). public struct SessionShareEnvelope: Codable, Equatable, Sendable { public var share: SessionShare? public init(share: SessionShare?) { self.share = share } } /// The browser-facing share URL: the hub origin plus the web app's /// `/shared-session/` route (web `buildSessionShareUrl`). A native /// client has no PWA origin of its own, so the hub origin is the share host. public enum SessionShareLink { public static func url(baseURL: URL, shareToken: String) -> URL? { guard let scheme = baseURL.scheme, let host = baseURL.host else { return nil } let token = shareToken.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? shareToken var components = URLComponents() components.scheme = scheme components.host = host components.port = baseURL.port components.path = "/shared-session/\(token)" return components.url } }