openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
41 lines (40 loc) • 1.85 kB
JavaScript
import { m as parseCanonicalIpAddress, p as normalizeIpAddress } from "./ip-CSwXvcih.mjs";
//#region packages/gateway-client/src/client-address-utils.ts
function isGatewayClientStoppedError(e) {
const t = e instanceof Error ? e.message : String(e);
return t === "gateway client stopped" || t === "Error: gateway client stopped";
}
function formatGatewayClientErrorForLog(e) {
return String(e).replace(/\/\/([^@/?#\s]+)@/g, "//***:***@").replace(/(Authorization:\s*Bearer\s+)[^\s]+/giu, "$1***").replace(/([?&])([^=&\s]+)=([^&#\s"'<>)]*)/g, (e, t, n) => /(?:token|password|secret|key|auth|credential)/iu.test(n) ? `${t}${n}=***` : e);
}
const SHA256_HEX_FINGERPRINT = /^[a-fA-F0-9]{64}$/u;
const SHA256_COLON_FINGERPRINT = /^(?:[a-fA-F0-9]{2}:){31}[a-fA-F0-9]{2}$/u;
function normalizeTlsFingerprint(e) {
const t = (e ?? "").trim().replace(/^sha256:/iu, "");
if (SHA256_HEX_FINGERPRINT.test(t)) return t.toLowerCase();
return SHA256_COLON_FINGERPRINT.test(t) ? t.replaceAll(":", "").toLowerCase() : "";
}
function requireTlsFingerprint(e) {
const t = normalizeTlsFingerprint(e);
if (!t) throw new Error("Invalid TLS fingerprint; expected a SHA-256 certificate fingerprint.");
return t;
}
function parseHostForAddressChecks(e) {
if (!e) return null;
const t = e.toLowerCase().trim();
const n = t.replace(/\.+$/, "");
if (n === "localhost") return {
isLocalhost: true,
unbracketedHost: n
};
return {
isLocalhost: false,
unbracketedHost: t.startsWith("[") && t.endsWith("]") ? t.slice(1, -1) : t
};
}
function parseGatewayIpAddress(e) {
const t = normalizeIpAddress(e);
return t ? parseCanonicalIpAddress(t) : void 0;
}
//#endregion
export { parseHostForAddressChecks as a, parseGatewayIpAddress as i, isGatewayClientStoppedError as n, requireTlsFingerprint as o, normalizeTlsFingerprint as r, formatGatewayClientErrorForLog as t };