From 4224a38ac4a151ecc8756019a5a7be044ca2a572 Mon Sep 17 00:00:00 2001 From: Henry Date: Fri, 27 Feb 2026 15:14:10 +0000 Subject: [PATCH] fix: types --- packages/api/src/utils/webhook.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/api/src/utils/webhook.ts b/packages/api/src/utils/webhook.ts index c13d928b..f1fb2f37 100644 --- a/packages/api/src/utils/webhook.ts +++ b/packages/api/src/utils/webhook.ts @@ -2,8 +2,8 @@ import crypto from "crypto"; import { z } from "zod"; import type { dbClient } from "@kan/db/client"; -import * as webhookRepo from "@kan/db/repository/webhook.repo"; import type { WebhookEvent } from "@kan/db/schema"; +import * as webhookRepo from "@kan/db/repository/webhook.repo"; export type WebhookEventType = WebhookEvent; @@ -92,7 +92,7 @@ export const webhookUrlSchema = z (url) => { try { const hostname = new URL(url).hostname.toLowerCase(); - const ipv4Match = hostname.match(/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/); + const ipv4Match = /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/.exec(hostname); if (ipv4Match) { const [, a, b] = ipv4Match.map(Number); if ( @@ -185,15 +185,16 @@ export async function sendWebhooksForWorkspace( payload: WebhookPayload, ): Promise { try { - // Get active webhooks for this workspace, pre-filtered by event at the DB level - const webhooks = await webhookRepo.getActiveByWorkspaceId( - db, - workspaceId, - payload.event, + // Get active webhooks for this workspace + const webhooks = await webhookRepo.getActiveByWorkspaceId(db, workspaceId); + + // Filter webhooks that are subscribed to this specific event + const webhooksForEvent = webhooks.filter((webhook) => + webhook.events.includes(payload.event), ); - // Send to all webhooks in parallel (fire and forget) - const promises = webhooks.map((webhook) => + // Send to all subscribed webhooks in parallel (fire and forget) + const promises = webhooksForEvent.map((webhook) => sendWebhookToUrl(webhook.url, webhook.secret ?? undefined, payload).then( (result) => { if (!result.success) {