import { redactValue } from "./redaction.js";
export function attachRouteInventoryLogger(config, logger, request, response, decision, outcome) {
    if (!config.routeInventoryEnabled) {
        return;
    }
    response.once("finish", () => {
        logger.info("desktop route inventory", {
            method: request.method ?? "GET",
            path: redactValue(decision.path),
            contentType: headerValue(request.headers["content-type"]),
            status: response.statusCode,
            framing: framingForContentType(request.headers["content-type"]),
            policy: decision.policy,
            outcome: outcome(),
        });
    });
}
export function framingForContentType(value) {
    const contentType = headerValue(value).toLowerCase();
    if (contentType.includes("application/connect+proto")) {
        return "connect-proto";
    }
    if (contentType.includes("application/proto")) {
        return "proto";
    }
    if (contentType.includes("application/json")) {
        return "json";
    }
    if (contentType.length === 0) {
        return "none";
    }
    return "other";
}
function headerValue(value) {
    if (value === undefined) {
        return "";
    }
    return Array.isArray(value) ? value.join(", ") : value;
}
