From 9d7113c74c59c9a8f8f02372bceb2193e6f62fee Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 15 Feb 2026 13:43:53 +0000 Subject: [PATCH] refactor(channels): share allowlist config patch helper --- src/channels/allowlists/resolve-utils.ts | 25 ++++++++++++++++++++++++ src/discord/monitor/provider.ts | 24 +++++------------------ src/slack/monitor/provider.ts | 24 +++++------------------ 3 files changed, 35 insertions(+), 38 deletions(-) diff --git a/src/channels/allowlists/resolve-utils.ts b/src/channels/allowlists/resolve-utils.ts index 640194399f2..a4a747f77dd 100644 --- a/src/channels/allowlists/resolve-utils.ts +++ b/src/channels/allowlists/resolve-utils.ts @@ -63,6 +63,31 @@ export function resolveAllowlistIdAdditions, +>(params: { entries: TEntries; resolvedMap: Map }): TEntries { + const nextEntries: Record = { ...params.entries }; + for (const [entryKey, entryConfig] of Object.entries(params.entries)) { + if (!entryConfig || typeof entryConfig !== "object") { + continue; + } + const users = (entryConfig as { users?: Array }).users; + if (!Array.isArray(users) || users.length === 0) { + continue; + } + const additions = resolveAllowlistIdAdditions({ + existing: users, + resolvedMap: params.resolvedMap, + }); + nextEntries[entryKey] = { + ...entryConfig, + users: mergeAllowlist({ existing: users, additions }), + }; + } + return nextEntries as TEntries; +} + export function summarizeMapping( label: string, mapping: string[], diff --git a/src/discord/monitor/provider.ts b/src/discord/monitor/provider.ts index 6624ff70902..a52f8c911cb 100644 --- a/src/discord/monitor/provider.ts +++ b/src/discord/monitor/provider.ts @@ -11,6 +11,7 @@ import { buildAllowlistResolutionSummary, mergeAllowlist, resolveAllowlistIdAdditions, + patchAllowlistUsersInConfigEntries, summarizeMapping, } from "../../channels/allowlists/resolve-utils.js"; import { @@ -352,25 +353,10 @@ export async function monitorDiscordProvider(opts: MonitorDiscordOpts = {}) { } const channels = (guildConfig as { channels?: Record }).channels ?? {}; if (channels && typeof channels === "object") { - const nextChannels: Record = { ...channels }; - for (const [channelKey, channelConfig] of Object.entries(channels)) { - if (!channelConfig || typeof channelConfig !== "object") { - continue; - } - const channelUsers = (channelConfig as { users?: Array }).users; - if (!Array.isArray(channelUsers) || channelUsers.length === 0) { - continue; - } - const additions = resolveAllowlistIdAdditions({ - existing: channelUsers, - resolvedMap, - }); - nextChannels[channelKey] = { - ...channelConfig, - users: mergeAllowlist({ existing: channelUsers, additions }), - }; - } - nextGuild.channels = nextChannels; + nextGuild.channels = patchAllowlistUsersInConfigEntries({ + entries: channels, + resolvedMap, + }); } nextGuilds[guildKey] = nextGuild; } diff --git a/src/slack/monitor/provider.ts b/src/slack/monitor/provider.ts index 454bf89dfcd..a5c3a38b22f 100644 --- a/src/slack/monitor/provider.ts +++ b/src/slack/monitor/provider.ts @@ -7,7 +7,7 @@ import { DEFAULT_GROUP_HISTORY_LIMIT } from "../../auto-reply/reply/history.js"; import { buildAllowlistResolutionSummary, mergeAllowlist, - resolveAllowlistIdAdditions, + patchAllowlistUsersInConfigEntries, summarizeMapping, } from "../../channels/allowlists/resolve-utils.js"; import { loadConfig } from "../../config/config.js"; @@ -330,24 +330,10 @@ export async function monitorSlackProvider(opts: MonitorSlackOpts = {}) { const { resolvedMap, mapping, unresolved } = buildAllowlistResolutionSummary(resolvedUsers); - const nextChannels = { ...channelsConfig }; - for (const [channelKey, channelConfig] of Object.entries(channelsConfig)) { - if (!channelConfig || typeof channelConfig !== "object") { - continue; - } - const channelUsers = (channelConfig as { users?: Array }).users; - if (!Array.isArray(channelUsers) || channelUsers.length === 0) { - continue; - } - const additions = resolveAllowlistIdAdditions({ - existing: channelUsers, - resolvedMap, - }); - nextChannels[channelKey] = { - ...channelConfig, - users: mergeAllowlist({ existing: channelUsers, additions }), - }; - } + const nextChannels = patchAllowlistUsersInConfigEntries({ + entries: channelsConfig, + resolvedMap, + }); channelsConfig = nextChannels; ctx.channelsConfig = nextChannels; summarizeMapping("slack channel users", mapping, unresolved, runtime);