⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
refactor(api): share telegram event schema and sanitize logs
Tin58355dc2eabf
diff --git a/apps/api/src/plugins/telegram/config.ts b/apps/api/src/plugins/telegram/config.tsindex 58022b8e4..7b4f4c492 100644--- a/apps/api/src/plugins/telegram/config.ts+++ b/apps/api/src/plugins/telegram/config.ts@@ -11,6 +11,15 @@ export const telegramEventKeys = [export type TelegramEventKey = (typeof telegramEventKeys)[number];+export const telegramEventsSchema = v.object(+ Object.fromEntries(+ telegramEventKeys.map((key) => [key, v.optional(v.boolean())]),+ ) as Record<+ TelegramEventKey,+ v.OptionalSchema<v.BooleanSchema<undefined>, never>+ >,+);+const telegramBotTokenSchema = v.pipe(v.string(),v.regex(/^\d{8,10}:[A-Za-z0-9_-]{35}$/, "Enter a valid Telegram bot token"),@@ -27,16 +36,7 @@ export const telegramConfigSchema = v.object({chatId: telegramChatIdSchema,threadId: v.optional(v.pipe(v.number(), v.integer(), v.minValue(1))),chatLabel: v.optional(v.string()),- events: v.optional(- v.object({- taskCreated: v.optional(v.boolean()),- taskStatusChanged: v.optional(v.boolean()),- taskPriorityChanged: v.optional(v.boolean()),- taskTitleChanged: v.optional(v.boolean()),- taskDescriptionChanged: v.optional(v.boolean()),- taskCommentCreated: v.optional(v.boolean()),- }),- ),+ events: v.optional(telegramEventsSchema),});export type TelegramConfig = v.InferOutput<typeof telegramConfigSchema>;@@ -67,9 +67,10 @@ export function normalizeTelegramConfig(};}-export async function validateTelegramConfig(- config: unknown,-): Promise<{ valid: boolean; errors?: string[] }> {+export function validateTelegramConfig(config: unknown): {+ valid: boolean;+ errors?: string[];+} {try {const parsed = v.parse(telegramConfigSchema, config);normalizeTelegramConfig(parsed);diff --git a/apps/api/src/plugins/telegram/events.ts b/apps/api/src/plugins/telegram/events.tsindex 077c08a94..38d0ba802 100644--- a/apps/api/src/plugins/telegram/events.ts+++ b/apps/api/src/plugins/telegram/events.ts@@ -206,7 +206,7 @@ async function runTelegramHandler(featureKey: TelegramEventKey,buildMessage: () => TelegramMessageContent,): Promise<void> {- const validation = await validateTelegramConfig(context.config);+ const validation = validateTelegramConfig(context.config);if (!validation.valid) {console.error("Invalid Telegram plugin config; skipping event dispatch", {errors: validation.errors,diff --git a/apps/api/src/telegram-integration/controllers/telegram-controller.ts b/apps/api/src/telegram-integration/controllers/telegram-controller.tsindex 5933ad543..9ccb5b60e 100644--- a/apps/api/src/telegram-integration/controllers/telegram-controller.ts+++ b/apps/api/src/telegram-integration/controllers/telegram-controller.ts@@ -21,6 +21,18 @@ function maskBotToken(value: string): string {return `${prefix}:${maskedSuffix}`;}+function sanitizeTelegramConfigForLog(rawConfig: string): string {+ try {+ const parsed = JSON.parse(rawConfig) as Record<string, unknown>;+ if ("botToken" in parsed) {+ parsed.botToken = "[REDACTED]";+ }+ return JSON.stringify(parsed);+ } catch {+ return "[UNPARSEABLE]";+ }+}+type TelegramIntegrationRecord = {id: string;projectId: string;@@ -44,7 +56,7 @@ export function parseTelegramIntegrationConfig(error,integrationId: integration.id,projectId: integration.projectId,- rawConfig: integration.config,+ sanitizedConfig: sanitizeTelegramConfigForLog(integration.config),});throw new HTTPException(500, {message: "Stored Telegram integration configuration is invalid",diff --git a/apps/api/src/telegram-integration/index.ts b/apps/api/src/telegram-integration/index.tsindex e41a8e1c6..466565ae8 100644--- a/apps/api/src/telegram-integration/index.ts+++ b/apps/api/src/telegram-integration/index.ts@@ -7,6 +7,7 @@ import db from "../database";import { integrationTable } from "../database/schema";import {normalizeTelegramConfig,+ telegramEventsSchema,validateTelegramConfig,} from "../plugins/telegram/config";import { telegramIntegrationSchema } from "../schemas";@@ -28,15 +29,6 @@ const telegramIntegration = new Hono<{};}>();-const telegramEventsSchema = v.object({- taskCreated: v.optional(v.boolean()),- taskStatusChanged: v.optional(v.boolean()),- taskPriorityChanged: v.optional(v.boolean()),- taskTitleChanged: v.optional(v.boolean()),- taskDescriptionChanged: v.optional(v.boolean()),- taskCommentCreated: v.optional(v.boolean()),-});-telegramIntegration.get("/project/:projectId",@@ -108,7 +100,7 @@ telegramIntegrationevents: body.events,});- const validation = await validateTelegramConfig(config);+ const validation = validateTelegramConfig(config);if (!validation.valid) {throw new HTTPException(400, {message: validation.errors?.join(", ") ?? "Invalid config",@@ -205,7 +197,7 @@ telegramIntegration},});- const validation = await validateTelegramConfig(nextConfig);+ const validation = validateTelegramConfig(nextConfig);if (!validation.valid) {throw new HTTPException(400, {message: validation.errors?.join(", ") ?? "Invalid config",