const LOOPBACK_HOSTS = new Set(['127.0.0.1', 'localhost', '[::1]']);
function parseLocalExcelHttpUrl(httpUrl) {
    let parsed;
    try {
        parsed = new URL(httpUrl);
    }
    catch {
        throw new Error(`Invalid EXCEL_HTTP_URL: ${httpUrl}`);
    }
    if (parsed.protocol !== 'http:') {
        throw new Error(`EXCEL_HTTP_URL must use http: ${httpUrl}`);
    }
    if (!LOOPBACK_HOSTS.has(parsed.hostname)) {
        throw new Error(`EXCEL_HTTP_URL must target loopback only: ${httpUrl}`);
    }
    return parsed;
}
function toLocalExcelHttpUrl(httpUrl) {
    return httpUrl;
}
/**
 * Normalize the Excel XLL base URL and reject anything that is not loopback HTTP.
 * Returning `origin` strips any path/query/fragment before callers append fixed endpoints.
 */
export function requireLocalExcelHttpUrl(httpUrl) {
    return toLocalExcelHttpUrl(parseLocalExcelHttpUrl(httpUrl).origin);
}
/**
 * Normalize a full Excel XLL request URL and reject anything that is not loopback HTTP.
 * Unlike `requireLocalExcelHttpUrl`, this preserves the request path/query/fragment.
 */
export function requireLocalExcelHttpRequestUrl(httpUrl) {
    return toLocalExcelHttpUrl(parseLocalExcelHttpUrl(httpUrl).toString());
}
export function parseExcelHttpPort(value) {
    const port = typeof value === 'number' ? value : Number.parseInt(value, 10);
    if (!Number.isInteger(port) || port < 1 || port > 65535) {
        throw new Error(`Invalid EXCEL_HTTP_PORT: ${value}`);
    }
    return port;
}
export function buildLocalExcelHttpUrl(port) {
    return toLocalExcelHttpUrl(`http://127.0.0.1:${parseExcelHttpPort(port)}`);
}
//# sourceMappingURL=http-url.js.map