fix: types

This commit is contained in:
Henry
2026-02-27 15:14:10 +00:00
parent 1d6825b181
commit 4224a38ac4

View File

@@ -2,8 +2,8 @@ import crypto from "crypto";
import { z } from "zod"; import { z } from "zod";
import type { dbClient } from "@kan/db/client"; import type { dbClient } from "@kan/db/client";
import * as webhookRepo from "@kan/db/repository/webhook.repo";
import type { WebhookEvent } from "@kan/db/schema"; import type { WebhookEvent } from "@kan/db/schema";
import * as webhookRepo from "@kan/db/repository/webhook.repo";
export type WebhookEventType = WebhookEvent; export type WebhookEventType = WebhookEvent;
@@ -92,7 +92,7 @@ export const webhookUrlSchema = z
(url) => { (url) => {
try { try {
const hostname = new URL(url).hostname.toLowerCase(); 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) { if (ipv4Match) {
const [, a, b] = ipv4Match.map(Number); const [, a, b] = ipv4Match.map(Number);
if ( if (
@@ -185,15 +185,16 @@ export async function sendWebhooksForWorkspace(
payload: WebhookPayload, payload: WebhookPayload,
): Promise<void> { ): Promise<void> {
try { try {
// Get active webhooks for this workspace, pre-filtered by event at the DB level // Get active webhooks for this workspace
const webhooks = await webhookRepo.getActiveByWorkspaceId( const webhooks = await webhookRepo.getActiveByWorkspaceId(db, workspaceId);
db,
workspaceId, // Filter webhooks that are subscribed to this specific event
payload.event, const webhooksForEvent = webhooks.filter((webhook) =>
webhook.events.includes(payload.event),
); );
// Send to all webhooks in parallel (fire and forget) // Send to all subscribed webhooks in parallel (fire and forget)
const promises = webhooks.map((webhook) => const promises = webhooksForEvent.map((webhook) =>
sendWebhookToUrl(webhook.url, webhook.secret ?? undefined, payload).then( sendWebhookToUrl(webhook.url, webhook.secret ?? undefined, payload).then(
(result) => { (result) => {
if (!result.success) { if (!result.success) {