import Foundation
/// The URLs the SDK talks to. Normally resolved from the app hostname and its
/// descriptor; overridable for local development against the node servers on
/// loopback (plain `http://`/`ws://` are then allowed).
public struct AppEndpoints: Sendable, Equatable {
public var descriptor: URL
public var ws: URL?
public var turnCredentials: URL?
public var mailboxMint: URL?
public var mailbox: URL?
public init(descriptor: URL, ws: URL? = nil, turnCredentials: URL? = nil, mailboxMint: URL? = nil, mailbox: URL? = nil) {
self.descriptor = descriptor
self.ws = ws
self.turnCredentials = turnCredentials
self.mailboxMint = mailboxMint
self.mailbox = mailbox
}
/// The documented paths on an app hostname.
public static func standard(host: String) -> AppEndpoints {
AppEndpoints(descriptor: URL(string: "https://\(host)/.well-known/ap2p")!)
}
/// Final URLs: explicit overrides win, then the descriptor, then the standard paths.
public func resolved(with descriptor: AppDescriptor, host: String) -> Resolved {
Resolved(
ws: ws ?? descriptor.endpoints.ws,
turnCredentials: turnCredentials ?? descriptor.endpoints.turnCredentials,
mailboxMint: mailboxMint ?? descriptor.mailbox?.mintEndpoint,
mailbox: mailbox ?? descriptor.mailbox?.endpoint
)
}
public struct Resolved: Sendable, Equatable {
public var ws: URL
public var turnCredentials: URL
public var mailboxMint: URL?
public var mailbox: URL?
}
}