refactor: share allowlist match metadata
Co-authored-by: thewilloftheshadow <thewilloftheshadow@users.noreply.github.com>
This commit is contained in:
21
src/channels/allowlist-match.ts
Normal file
21
src/channels/allowlist-match.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
export type AllowlistMatchSource =
|
||||
| "wildcard"
|
||||
| "id"
|
||||
| "name"
|
||||
| "tag"
|
||||
| "username"
|
||||
| "prefixed-id"
|
||||
| "prefixed-user"
|
||||
| "prefixed-name"
|
||||
| "slug"
|
||||
| "localpart";
|
||||
|
||||
export type AllowlistMatch<TSource extends string = AllowlistMatchSource> = {
|
||||
allowed: boolean;
|
||||
matchKey?: string;
|
||||
matchSource?: TSource;
|
||||
};
|
||||
|
||||
export function formatAllowlistMatchMeta(match?: AllowlistMatch | null): string {
|
||||
return `matchKey=${match?.matchKey ?? "none"} matchSource=${match?.matchSource ?? "none"}`;
|
||||
}
|
||||
2
src/channels/plugins/allowlist-match.ts
Normal file
2
src/channels/plugins/allowlist-match.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export type { AllowlistMatch, AllowlistMatchSource } from "../allowlist-match.js";
|
||||
export { formatAllowlistMatchMeta } from "../allowlist-match.js";
|
||||
@@ -93,4 +93,9 @@ export {
|
||||
type ChannelEntryMatch,
|
||||
type ChannelMatchSource,
|
||||
} from "./channel-config.js";
|
||||
export {
|
||||
formatAllowlistMatchMeta,
|
||||
type AllowlistMatch,
|
||||
type AllowlistMatchSource,
|
||||
} from "./allowlist-match.js";
|
||||
export type { ChannelId, ChannelPlugin } from "./types.js";
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
buildChannelKeyCandidates,
|
||||
resolveChannelEntryMatchWithFallback,
|
||||
} from "../../channels/channel-config.js";
|
||||
import type { AllowlistMatch } from "../../channels/allowlist-match.js";
|
||||
import { formatDiscordUserTag } from "./format.js";
|
||||
|
||||
export type DiscordAllowList = {
|
||||
@@ -12,11 +13,7 @@ export type DiscordAllowList = {
|
||||
names: Set<string>;
|
||||
};
|
||||
|
||||
export type DiscordAllowListMatch = {
|
||||
allowed: boolean;
|
||||
matchKey?: string;
|
||||
matchSource?: "wildcard" | "id" | "name" | "tag";
|
||||
};
|
||||
export type DiscordAllowListMatch = AllowlistMatch<"wildcard" | "id" | "name" | "tag">;
|
||||
|
||||
export type DiscordGuildEntryResolved = {
|
||||
id?: string;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import type { AllowlistMatch } from "../../channels/allowlist-match.js";
|
||||
|
||||
export function normalizeSlackSlug(raw?: string) {
|
||||
const trimmed = raw?.trim().toLowerCase() ?? "";
|
||||
if (!trimmed) return "";
|
||||
@@ -14,18 +16,9 @@ export function normalizeAllowListLower(list?: Array<string | number>) {
|
||||
return normalizeAllowList(list).map((entry) => entry.toLowerCase());
|
||||
}
|
||||
|
||||
export type SlackAllowListMatch = {
|
||||
allowed: boolean;
|
||||
matchKey?: string;
|
||||
matchSource?:
|
||||
| "wildcard"
|
||||
| "id"
|
||||
| "prefixed-id"
|
||||
| "prefixed-user"
|
||||
| "name"
|
||||
| "prefixed-name"
|
||||
| "slug";
|
||||
};
|
||||
export type SlackAllowListMatch = AllowlistMatch<
|
||||
"wildcard" | "id" | "prefixed-id" | "prefixed-user" | "name" | "prefixed-name" | "slug"
|
||||
>;
|
||||
|
||||
export function resolveSlackAllowListMatch(params: {
|
||||
allowList: string[];
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import type { AllowlistMatch } from "../channels/allowlist-match.js";
|
||||
|
||||
export type NormalizedAllowFrom = {
|
||||
entries: string[];
|
||||
entriesLower: string[];
|
||||
@@ -5,11 +7,7 @@ export type NormalizedAllowFrom = {
|
||||
hasEntries: boolean;
|
||||
};
|
||||
|
||||
export type AllowFromMatch = {
|
||||
allowed: boolean;
|
||||
matchKey?: string;
|
||||
matchSource?: "wildcard" | "id" | "username";
|
||||
};
|
||||
export type AllowFromMatch = AllowlistMatch<"wildcard" | "id" | "username">;
|
||||
|
||||
export const normalizeAllowFrom = (list?: Array<string | number>): NormalizedAllowFrom => {
|
||||
const entries = (list ?? []).map((value) => String(value).trim()).filter(Boolean);
|
||||
|
||||
Reference in New Issue
Block a user