'use server' import type { WebhookResult } from './types' import { requireRole, UserRole } from '@admin/auth/middleware' import db from '@admin/db' import { webhooks } from '@admin/db/schema' import { toActionError } from '@admin/utils/error/to-action-error' import { eq } from 'drizzle-orm' import { updateTag } from 'next/cache' import { webhooksCacheTags } from './types' export async function deleteWebhook(id: string): Promise { await requireRole([UserRole.ADMIN]) try { await db.delete(webhooks).where(eq(webhooks.id, id)) updateTag(webhooksCacheTags.endpoints) updateTag(webhooksCacheTags.subscriptions) return { success: true } } catch (error) { console.error('Error deleting webhook:', error) return { success: false, error: toActionError(error, 'Failed to delete webhook') } } }