import Foundation enum PrivacyPolicyLocation { static let defaultURL = URL(string: "http://a806b934804d0f0ab.awsglobalaccelerator.com/privacy/jokersudoku.html")! static func fromBundle(_ bundle: Bundle = .main) -> URL { guard let raw = bundle.object(forInfoDictionaryKey: "PrivacyPolicyURL") as? String, let url = ActivityURL.parse(raw) else { return defaultURL } return url.pathExtension.lowercased() == "md" ? url.deletingPathExtension().appendingPathExtension("html") : url } } protocol PrivacyPolicyFetching: Sendable { func fetchPolicy() async throws -> String } struct PrivacyPolicyClient: PrivacyPolicyFetching { enum PolicyError: Error { case invalidURL, invalidText } let url: URL? let transport: DataTransport init(url: URL?, session: URLSession? = nil) { self.url = url transport = NetworkClient(session: session, allowedHTTPHosts: url?.scheme == "http" ? Set([url?.host].compactMap { $0 }) : []) } static func fromBundle(_ bundle: Bundle = .main) -> Self { Self(url: PrivacyPolicyLocation.fromBundle(bundle)) } func fetchPolicy() async throws -> String { guard let url, ActivityURL.parse(url.absoluteString) != nil else { throw PolicyError.invalidURL } var request = URLRequest(url: url, cachePolicy: .reloadIgnoringLocalCacheData) request.httpMethod = "GET" request.setValue("text/html, text/markdown;q=0.9, text/plain;q=0.8", forHTTPHeaderField: "Accept") let data = try await transport.execute(request) guard let text = String(data: data, encoding: .utf8) else { throw PolicyError.invalidText } return text } }