refactor: share open allowFrom config checks

This commit is contained in:
Peter Steinberger
2026-03-14 02:00:38 +00:00
parent 38b09866b8
commit 55ebdce9c3
4 changed files with 46 additions and 22 deletions

View File

@@ -0,0 +1,25 @@
import type { z } from "zod";
type RequireOpenAllowFromFn = (params: {
policy: unknown;
allowFrom: unknown;
ctx: z.RefinementCtx;
path: string[];
message: string;
}) => void;
export function requireChannelOpenAllowFrom(params: {
channel: string;
policy: unknown;
allowFrom: unknown;
ctx: z.RefinementCtx;
requireOpenAllowFrom: RequireOpenAllowFromFn;
}) {
params.requireOpenAllowFrom({
policy: params.policy,
allowFrom: params.allowFrom,
ctx: params.ctx,
path: ["allowFrom"],
message: `channels.${params.channel}.dmPolicy="open" requires channels.${params.channel}.allowFrom to include "*"`,
});
}