import Foundation 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 { let url = (bundle.object(forInfoDictionaryKey: "PrivacyPolicyURL") as? String).flatMap(ActivityURL.parse) return Self(url: url) } 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/markdown, text/plain;q=0.9", forHTTPHeaderField: "Accept") let data = try await transport.execute(request) guard let text = String(data: data, encoding: .utf8) else { throw PolicyError.invalidText } return text } }