UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

71 lines (70 loc) 2.7 kB
import { a as normalizeLowercaseStringOrEmpty } from "./string-coerce-mnp54Vah.js"; import { l as normalizeStringEntries } from "./string-normalization-WNUDCpXX.js"; import { i as resolveAllowlistMatchByCandidates } from "./allowlist-match-B04-UeMC.js"; import "./string-coerce-runtime-CEGJWkQ_.js"; import "./allow-from-DCaV3hzI.js"; //#region extensions/matrix/src/matrix/monitor/allowlist.ts function normalizeAllowList(list) { return normalizeStringEntries(list); } function normalizeMatrixUser(raw) { const value = (raw ?? "").trim(); if (!value) return ""; if (!value.startsWith("@") || !value.includes(":")) return normalizeLowercaseStringOrEmpty(value); const withoutAt = value.slice(1); const splitIndex = withoutAt.indexOf(":"); if (splitIndex === -1) return normalizeLowercaseStringOrEmpty(value); const localpart = normalizeLowercaseStringOrEmpty(withoutAt.slice(0, splitIndex)); const server = normalizeLowercaseStringOrEmpty(withoutAt.slice(splitIndex + 1)); if (!server) return normalizeLowercaseStringOrEmpty(value); return `@${localpart}:${server}`; } function normalizeMatrixUserId(raw) { const trimmed = (raw ?? "").trim(); if (!trimmed) return ""; const lowered = normalizeLowercaseStringOrEmpty(trimmed); if (lowered.startsWith("matrix:")) return normalizeMatrixUser(trimmed.slice(7)); if (lowered.startsWith("user:")) return normalizeMatrixUser(trimmed.slice(5)); return normalizeMatrixUser(trimmed); } function normalizeMatrixAllowListEntry(raw) { const trimmed = raw.trim(); if (!trimmed) return ""; if (trimmed === "*") return trimmed; const lowered = normalizeLowercaseStringOrEmpty(trimmed); if (lowered.startsWith("matrix:")) return `matrix:${normalizeMatrixUser(trimmed.slice(7))}`; if (lowered.startsWith("user:")) return `user:${normalizeMatrixUser(trimmed.slice(5))}`; return normalizeMatrixUser(trimmed); } function normalizeMatrixAllowList(list) { return normalizeAllowList(list).map((entry) => normalizeMatrixAllowListEntry(entry)); } function resolveMatrixAllowListMatch(params) { const allowList = params.allowList; if (allowList.length === 0) return { allowed: false }; if (allowList.includes("*")) return { allowed: true, matchKey: "*", matchSource: "wildcard" }; const userId = normalizeMatrixUser(params.userId); return resolveAllowlistMatchByCandidates({ allowList, candidates: [ { value: userId, source: "id" }, { value: userId ? `matrix:${userId}` : "", source: "prefixed-id" }, { value: userId ? `user:${userId}` : "", source: "prefixed-user" } ] }); } //#endregion export { normalizeMatrixUserId as n, resolveMatrixAllowListMatch as r, normalizeMatrixAllowList as t };