fix: block development writes to Discord channels
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
export type DiscordSharingConfig = { token: string; channelId: string; allowedUserIds?: string[] };
|
||||
export type DiscordSharingConfig = { token: string; channelId: string; allowedUserIds?: string[]; writesEnabled?: boolean };
|
||||
|
||||
/** Read only from the server entrypoint; never include credentials in public config. */
|
||||
export function readDiscordSharingConfig(env = process.env): DiscordSharingConfig {
|
||||
const allowedUserIds = (env.DISCORD_SHARING_ALLOWED_USER_IDS ?? "").split(",").map(id => id.trim()).filter(Boolean);
|
||||
if (allowedUserIds.some(id => !/^\d{17,20}$/.test(id))) throw new Error("DISCORD_SHARING_ALLOWED_USER_IDS must contain comma-separated Discord user IDs");
|
||||
return {
|
||||
// Real channel writes are production-only. Test fixtures may inject a stub config.
|
||||
writesEnabled: env.NODE_ENV === "production",
|
||||
allowedUserIds,
|
||||
token: (env.DISCORD_BOT_TOKEN ?? "").trim().replace(/^Bot\s+/i, ""),
|
||||
channelId: (env.DISCORD_SHARING_CHANNEL_ID ?? "").trim(),
|
||||
|
||||
Reference in New Issue
Block a user