export const DINGTALK_ROBOT_NOTIFICATION_CONFIG_KEY = "dingtalk_robot_notification_config"; export type DingTalkRobotNotificationConfig = { enabled: boolean; webhookUrl: string; secret: string; }; export const defaultDingTalkRobotNotificationConfig: DingTalkRobotNotificationConfig = { enabled: false, webhookUrl: "", secret: "", }; function normalizeRobotString(value: unknown) { return String(value || "") .replace(/[\u2028\u2029]/g, "") .replace(/[\u0000-\u001F\u007F]/g, "") .trim(); } export function normalizeDingTalkRobotNotificationConfig( value: unknown, ): DingTalkRobotNotificationConfig { if (!value || typeof value !== "object" || Array.isArray(value)) { return defaultDingTalkRobotNotificationConfig; } const raw = value as Partial; return { enabled: raw.enabled === true, webhookUrl: normalizeRobotString(raw.webhookUrl), secret: normalizeRobotString(raw.secret), }; }