refactor(onboarding): reuse allowlist merge across channels

This commit is contained in:
Peter Steinberger
2026-02-16 22:53:55 +00:00
parent 486b7379d4
commit 64f5e4a424
4 changed files with 28 additions and 29 deletions

View File

@@ -11,7 +11,7 @@ import {
import { normalizeIMessageHandle } from "../../../imessage/targets.js"; import { normalizeIMessageHandle } from "../../../imessage/targets.js";
import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "../../../routing/session-key.js"; import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "../../../routing/session-key.js";
import { formatDocsLink } from "../../../terminal/links.js"; import { formatDocsLink } from "../../../terminal/links.js";
import { addWildcardAllowFrom, promptAccountId } from "./helpers.js"; import { addWildcardAllowFrom, mergeAllowFromEntries, promptAccountId } from "./helpers.js";
const channel = "imessage" as const; const channel = "imessage" as const;
@@ -138,7 +138,7 @@ async function promptIMessageAllowFrom(params: {
}, },
}); });
const parts = parseIMessageAllowFromInput(String(entry)); const parts = parseIMessageAllowFromInput(String(entry));
const unique = [...new Set(parts)]; const unique = mergeAllowFromEntries(undefined, parts);
return setIMessageAllowFrom(params.cfg, accountId, unique); return setIMessageAllowFrom(params.cfg, accountId, unique);
} }

View File

@@ -13,7 +13,7 @@ import {
} from "../../../signal/accounts.js"; } from "../../../signal/accounts.js";
import { formatDocsLink } from "../../../terminal/links.js"; import { formatDocsLink } from "../../../terminal/links.js";
import { normalizeE164 } from "../../../utils.js"; import { normalizeE164 } from "../../../utils.js";
import { addWildcardAllowFrom, promptAccountId } from "./helpers.js"; import { addWildcardAllowFrom, mergeAllowFromEntries, promptAccountId } from "./helpers.js";
const channel = "signal" as const; const channel = "signal" as const;
const MIN_E164_DIGITS = 5; const MIN_E164_DIGITS = 5;
@@ -153,21 +153,22 @@ async function promptSignalAllowFrom(params: {
}, },
}); });
const parts = parseSignalAllowFromInput(String(entry)); const parts = parseSignalAllowFromInput(String(entry));
const normalized = parts const normalized = parts.map((part) => {
.map((part) => { if (part === "*") {
if (part === "*") { return "*";
return "*"; }
} if (part.toLowerCase().startsWith("uuid:")) {
if (part.toLowerCase().startsWith("uuid:")) { return `uuid:${part.slice(5).trim()}`;
return `uuid:${part.slice(5).trim()}`; }
} if (isUuidLike(part)) {
if (isUuidLike(part)) { return `uuid:${part}`;
return `uuid:${part}`; }
} return normalizeE164(part);
return normalizeE164(part); });
}) const unique = mergeAllowFromEntries(
.filter(Boolean); undefined,
const unique = [...new Set(normalized)]; normalized.filter((part): part is string => typeof part === "string" && part.trim().length > 0),
);
return setSignalAllowFrom(params.cfg, accountId, unique); return setSignalAllowFrom(params.cfg, accountId, unique);
} }

View File

@@ -10,7 +10,7 @@ import {
resolveTelegramAccount, resolveTelegramAccount,
} from "../../../telegram/accounts.js"; } from "../../../telegram/accounts.js";
import { formatDocsLink } from "../../../terminal/links.js"; import { formatDocsLink } from "../../../terminal/links.js";
import { addWildcardAllowFrom, promptAccountId } from "./helpers.js"; import { addWildcardAllowFrom, mergeAllowFromEntries, promptAccountId } from "./helpers.js";
const channel = "telegram" as const; const channel = "telegram" as const;
@@ -133,11 +133,7 @@ async function promptTelegramAllowFrom(params: {
resolvedIds = results.filter(Boolean) as string[]; resolvedIds = results.filter(Boolean) as string[];
} }
const merged = [ const unique = mergeAllowFromEntries(existingAllowFrom, resolvedIds);
...existingAllowFrom.map((item) => String(item).trim()).filter(Boolean),
...resolvedIds,
];
const unique = [...new Set(merged)];
if (accountId === DEFAULT_ACCOUNT_ID) { if (accountId === DEFAULT_ACCOUNT_ID) {
return { return {

View File

@@ -15,7 +15,7 @@ import {
resolveDefaultWhatsAppAccountId, resolveDefaultWhatsAppAccountId,
resolveWhatsAppAuthDir, resolveWhatsAppAuthDir,
} from "../../../web/accounts.js"; } from "../../../web/accounts.js";
import { promptAccountId } from "./helpers.js"; import { mergeAllowFromEntries, promptAccountId } from "./helpers.js";
const channel = "whatsapp" as const; const channel = "whatsapp" as const;
@@ -72,10 +72,10 @@ async function promptWhatsAppOwnerAllowFrom(params: {
...existingAllowFrom ...existingAllowFrom
.filter((item) => item !== "*") .filter((item) => item !== "*")
.map((item) => normalizeE164(item)) .map((item) => normalizeE164(item))
.filter(Boolean), .filter((item): item is string => typeof item === "string" && item.trim().length > 0),
normalized, normalized,
]; ];
const allowFrom = [...new Set(merged.filter(Boolean))]; const allowFrom = mergeAllowFromEntries(undefined, merged);
return { normalized, allowFrom }; return { normalized, allowFrom };
} }
@@ -234,8 +234,10 @@ async function promptWhatsAppAllowFrom(
.split(/[\n,;]+/g) .split(/[\n,;]+/g)
.map((p) => p.trim()) .map((p) => p.trim())
.filter(Boolean); .filter(Boolean);
const normalized = parts.map((part) => (part === "*" ? "*" : normalizeE164(part))); const normalized = parts
const unique = [...new Set(normalized.filter(Boolean))]; .map((part) => (part === "*" ? "*" : normalizeE164(part)))
.filter((part): part is string => typeof part === "string" && part.trim().length > 0);
const unique = mergeAllowFromEntries(undefined, normalized);
next = setWhatsAppAllowFrom(next, unique); next = setWhatsAppAllowFrom(next, unique);
} }