The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
disabled -> disabledAt
Kiran Kd54de01048d1
diff --git a/apps/web/app/api/stripe/webhook/customer-subscription-deleted.ts b/apps/web/app/api/stripe/webhook/customer-subscription-deleted.tsindex 955b3413a4..0c370b4a7b 100644--- a/apps/web/app/api/stripe/webhook/customer-subscription-deleted.ts+++ b/apps/web/app/api/stripe/webhook/customer-subscription-deleted.ts@@ -152,7 +152,16 @@ export async function customerSubscriptionDeleted(event: Stripe.Event) {projectId: workspace.id,},data: {- disabled: true,+ disabledAt: new Date(),+ },+ }),++ prisma.project.update({+ where: {+ id: workspace.id,+ },+ data: {+ webhookEnabled: false,},}),]);diff --git a/apps/web/app/api/stripe/webhook/customer-subscription-updated.ts b/apps/web/app/api/stripe/webhook/customer-subscription-updated.tsindex 60b4bcf188..3df44949d2 100644--- a/apps/web/app/api/stripe/webhook/customer-subscription-updated.ts+++ b/apps/web/app/api/stripe/webhook/customer-subscription-updated.ts@@ -92,7 +92,16 @@ export async function customerSubscriptionUpdated(event: Stripe.Event) {? [prisma.webhook.updateMany({where: { projectId: workspace.id },- data: { disabled: true },+ data: { disabledAt: new Date() },+ }),++ prisma.project.update({+ where: {+ id: workspace.id,+ },+ data: {+ webhookEnabled: false,+ },}),]: []),diff --git a/apps/web/app/api/webhooks/[webhookId]/route.ts b/apps/web/app/api/webhooks/[webhookId]/route.tsindex 6d36d79e13..6de6d7789a 100644--- a/apps/web/app/api/webhooks/[webhookId]/route.ts+++ b/apps/web/app/api/webhooks/[webhookId]/route.ts@@ -26,7 +26,7 @@ export const GET = withWorkspace(url: true,secret: true,triggers: true,- disabled: true,+ disabledAt: true,links: true,},});@@ -51,8 +51,9 @@ export const PATCH = withWorkspace(async ({ workspace, params, req }) => {const { webhookId } = params;- const { name, url, triggers, linkIds, disabled } =- updateWebhookSchema.parse(await parseRequestBody(req));+ const { name, url, triggers, linkIds } = updateWebhookSchema.parse(+ await parseRequestBody(req),+ );if (url) {const webhookUrlExists = await prisma.webhook.findFirst({@@ -111,7 +112,6 @@ export const PATCH = withWorkspace(...(name && { name }),...(url && { url }),...(triggers && { triggers }),- disabled,...(linkIds && {links: {deleteMany: {},@@ -127,7 +127,7 @@ export const PATCH = withWorkspace(url: true,secret: true,triggers: true,- disabled: true,+ disabledAt: true,links: {select: {linkId: true,diff --git a/apps/web/app/api/webhooks/route.ts b/apps/web/app/api/webhooks/route.tsindex 4eb9842dc4..2cd5ce1e47 100644--- a/apps/web/app/api/webhooks/route.ts+++ b/apps/web/app/api/webhooks/route.ts@@ -23,7 +23,7 @@ export const GET = withWorkspace(url: true,secret: true,triggers: true,- disabled: true,+ disabledAt: true,links: true,},orderBy: {diff --git a/apps/web/lib/tinybird/record-click.ts b/apps/web/lib/tinybird/record-click.tsindex 23a4633794..94d949d3be 100644--- a/apps/web/lib/tinybird/record-click.ts+++ b/apps/web/lib/tinybird/record-click.ts@@ -157,8 +157,8 @@ export async function recordClick({const linkWebhooks = webhooks.filter((webhook) =>+ webhook.disabledAt === null &&webhook.triggers &&- !webhook.disabled &&Array.isArray(webhook.triggers) &&webhook.triggers.includes("link.clicked"),);diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.tsindex caf69b24cf..3a2f0279e1 100644--- a/apps/web/lib/types.ts+++ b/apps/web/lib/types.ts@@ -251,7 +251,7 @@ export type WebhookEventProps = z.infer<typeof webhookEventSchemaTB>;export type WebhookCacheProps = Pick<Webhook,- "id" | "url" | "secret" | "triggers" | "disabled"+ "id" | "url" | "secret" | "triggers" | "disabledAt">;export type TrackCustomerResponse = z.infer<typeof trackCustomerResponseSchema>;diff --git a/apps/web/lib/webhook/api.ts b/apps/web/lib/webhook/api.tsindex fc902536b6..dde9fa53f8 100644--- a/apps/web/lib/webhook/api.ts+++ b/apps/web/lib/webhook/api.ts@@ -52,7 +52,7 @@ export async function addWebhook({secret: true,triggers: true,links: true,- disabled: true,+ disabledAt: true,},});diff --git a/apps/web/lib/webhook/cache.ts b/apps/web/lib/webhook/cache.tsindex e91481d6c2..cb8070b61d 100644--- a/apps/web/lib/webhook/cache.ts+++ b/apps/web/lib/webhook/cache.ts@@ -36,7 +36,7 @@ class WebhookCache {url: webhook.url,secret: webhook.secret,triggers: webhook.triggers,- disabled: webhook.disabled,+ disabledAt: webhook.disabledAt,};}}diff --git a/apps/web/lib/webhook/failure.ts b/apps/web/lib/webhook/failure.tsindex 361dd8b7e1..af002fa54b 100644--- a/apps/web/lib/webhook/failure.ts+++ b/apps/web/lib/webhook/failure.ts@@ -17,27 +17,29 @@ export const handleWebhookFailure = async (webhookId: string) => {url: true,secret: true,triggers: true,- disabled: true,+ disabledAt: true,consecutiveFailures: true,lastFailedAt: true,projectId: true,},});- if (webhook.disabled) {+ if (webhook.disabledAt) {return;}const failureThresholdReached =webhook.consecutiveFailures >= WEBHOOK_FAILURE_NOTIFY_THRESHOLD;+ const disabledAt = new Date();+if (failureThresholdReached) {await Promise.allSettled([// Disable the webhookprisma.webhook.update({where: { id: webhookId },data: {- disabled: true,+ disabledAt,},}),@@ -45,7 +47,7 @@ export const handleWebhookFailure = async (webhookId: string) => {sendFailureNotification(webhook),// Update the webhook cache- webhookCache.set({ ...webhook, disabled: true }),+ webhookCache.set({ ...webhook, disabledAt }),]);}};@@ -61,7 +63,7 @@ export const resetWebhookFailureCount = async (webhookId: string) => {};const sendFailureNotification = async (- webhook: Pick<Webhook, "id" | "url" | "triggers" | "disabled" | "projectId">,+ webhook: Pick<Webhook, "id" | "url" | "projectId">,) => {const workspaceOwners = await prisma.projectUsers.findFirst({where: { projectId: webhook.projectId, role: "owner" },diff --git a/apps/web/lib/webhook/publish-edge.ts b/apps/web/lib/webhook/publish-edge.tsindex dd9c4aed32..39bb6918eb 100644--- a/apps/web/lib/webhook/publish-edge.ts+++ b/apps/web/lib/webhook/publish-edge.ts@@ -20,7 +20,7 @@ export const sendWorkspaceWebhookOnEdge = async ({const webhooks = await prismaEdge.webhook.findMany({where: {projectId: workspace.id,- disabled: false,+ disabledAt: null,triggers: {array_contains: [trigger],},diff --git a/apps/web/lib/webhook/publish.ts b/apps/web/lib/webhook/publish.tsindex 29ab31b25e..9ee5bf1510 100644--- a/apps/web/lib/webhook/publish.ts+++ b/apps/web/lib/webhook/publish.ts@@ -24,7 +24,7 @@ export const sendWorkspaceWebhook = async ({const webhooks = await prisma.webhook.findMany({where: {projectId: workspace.id,- disabled: false,+ disabledAt: null,triggers: {array_contains: [trigger],},diff --git a/apps/web/lib/webhook/transform.ts b/apps/web/lib/webhook/transform.tsindex 0c655365d4..8541e1ee14 100644--- a/apps/web/lib/webhook/transform.ts+++ b/apps/web/lib/webhook/transform.ts@@ -15,7 +15,7 @@ import { leadWebhookEventSchema, saleWebhookEventSchema } from "./schemas";interface TransformWebhookPropsextends Pick<Webhook,- "id" | "name" | "url" | "secret" | "triggers" | "disabled"+ "id" | "name" | "url" | "secret" | "triggers" | "disabledAt"> {links: { linkId: string }[];}diff --git a/apps/web/lib/zod/schemas/webhooks.ts b/apps/web/lib/zod/schemas/webhooks.tsindex a2dace7543..1f6c58281a 100644--- a/apps/web/lib/zod/schemas/webhooks.ts+++ b/apps/web/lib/zod/schemas/webhooks.ts@@ -7,7 +7,7 @@ export const webhookSchema = z.object({url: z.string(),secret: z.string(),triggers: z.array(z.enum(WEBHOOK_TRIGGERS)),- disabled: z.boolean().optional(),+ disabledAt: z.date().nullable().optional(),linkIds: z.array(z.string()).optional(),});@@ -19,9 +19,7 @@ export const createWebhookSchema = z.object({linkIds: z.array(z.string()).optional(),});-export const updateWebhookSchema = createWebhookSchema.partial().extend({- disabled: z.boolean().optional(),-});+export const updateWebhookSchema = createWebhookSchema.partial();// Schema of response sent to the webhook callback URL by QStashexport const webhookCallbackSchema = z.object({diff --git a/apps/web/prisma/schema/webhook.prisma b/apps/web/prisma/schema/webhook.prismaindex fe875aa380..0d672bdbfe 100644--- a/apps/web/prisma/schema/webhook.prisma+++ b/apps/web/prisma/schema/webhook.prisma@@ -12,10 +12,10 @@ model Webhook {name Stringurl Stringsecret String- disabled Boolean @default(false)triggers JsonconsecutiveFailures Int @default(0)lastFailedAt DateTime?+ disabledAt DateTime?createdAt DateTime @default(now())updatedAt DateTime @updatedAtdiff --git a/apps/web/ui/webhooks/add-edit-webhook-form.tsx b/apps/web/ui/webhooks/add-edit-webhook-form.tsxindex 87fd9a2556..47487dd553 100644--- a/apps/web/ui/webhooks/add-edit-webhook-form.tsx+++ b/apps/web/ui/webhooks/add-edit-webhook-form.tsx@@ -170,7 +170,7 @@ export default function AddEditWebhookForm({{secret}</p><div className="flex flex-col gap-2">- <CopyButton value={secret} className="rounded-md" />+ <CopyButton value={secret!} className="rounded-md" /></div></div></div>diff --git a/apps/web/ui/webhooks/webhook-card.tsx b/apps/web/ui/webhooks/webhook-card.tsxindex 9db3020980..3f41e7a4a8 100644--- a/apps/web/ui/webhooks/webhook-card.tsx+++ b/apps/web/ui/webhooks/webhook-card.tsx@@ -2,7 +2,7 @@ import useWorkspace from "@/lib/swr/use-workspace";import { WebhookProps } from "@/lib/types";import { TokenAvatar } from "@dub/ui";import Link from "next/link";-import { WebhookDeliveryStatus } from "./webhook-delivery-status";+import { WebhookStatus } from "./webhook-status";export default function WebhookCard(webhook: WebhookProps) {const { slug } = useWorkspace();@@ -19,7 +19,7 @@ export default function WebhookCard(webhook: WebhookProps) {<div><div className="flex items-center gap-1"><span className="font-semibold text-gray-700">{webhook.name}</span>- <WebhookDeliveryStatus disabled={webhook.disabled} />+ <WebhookStatus webhook={webhook} /></div><div className="flex items-center gap-1 text-sm text-gray-500">{webhook.url}diff --git a/apps/web/ui/webhooks/webhook-delivery-status.tsx b/apps/web/ui/webhooks/webhook-delivery-status.tsxdeleted file mode 100644index 334cc66df6..0000000000--- a/apps/web/ui/webhooks/webhook-delivery-status.tsx+++ /dev/null@@ -1,16 +0,0 @@-import { WebhookProps } from "@/lib/types";-import { cn } from "@dub/utils";--export const WebhookDeliveryStatus = ({- disabled,-}: Pick<WebhookProps, "disabled">) => {- return (- <span- className={cn(- "inline-flex items-center justify-center rounded-full p-1.5 text-xs font-medium",- disabled ? "bg-red-500 text-white" : "bg-green-500 text-black",- )}- title={disabled ? "Disabled" : "Enabled"}- />- );-};diff --git a/apps/web/ui/webhooks/webhook-header.tsx b/apps/web/ui/webhooks/webhook-header.tsxindex 48bd72fc09..dd32a13000 100644--- a/apps/web/ui/webhooks/webhook-header.tsx+++ b/apps/web/ui/webhooks/webhook-header.tsx@@ -20,7 +20,7 @@ import { toast } from "sonner";import useSWR from "swr";import { useDeleteWebhookModal } from "../modals/delete-webhook-modal";import { useSendTestWebhookModal } from "../modals/send-test-webhook-modal";-import { WebhookDeliveryStatus } from "./webhook-delivery-status";+import { WebhookStatus } from "./webhook-status";export default function WebhookHeader({ webhookId }: { webhookId: string }) {const router = useRouter();@@ -111,7 +111,7 @@ export default function WebhookHeader({ webhookId }: { webhookId: string }) {<span className="font-semibold text-gray-700">{webhook.name}</span>- <WebhookDeliveryStatus disabled={webhook.disabled} />+ <WebhookStatus webhook={webhook} /></div><ahref={webhook.url}@@ -140,11 +140,11 @@ export default function WebhookHeader({ webhookId }: { webhookId: string }) {<Buttontext={- webhook?.disabled ? "Enable webhook" : "Disable webhook"+ webhook?.disabledAt ? "Enable webhook" : "Disable webhook"}variant="outline"icon={- webhook?.disabled ? (+ webhook?.disabledAt ? (<CircleX className="size-4" />) : (<CircleCheck className="size-4" />@@ -152,7 +152,7 @@ export default function WebhookHeader({ webhookId }: { webhookId: string }) {}className="h-9 justify-start px-2"onClick={async () => {- toggleWebhookStatus(!webhook?.disabled);+ toggleWebhookStatus(!webhook?.disabledAt);setOpenPopover(false);}}disabled={!!permissionsError}diff --git a/apps/web/ui/webhooks/webhook-status.tsx b/apps/web/ui/webhooks/webhook-status.tsxnew file mode 100644index 0000000000..65148590a1--- /dev/null+++ b/apps/web/ui/webhooks/webhook-status.tsx@@ -0,0 +1,20 @@+import { WebhookProps } from "@/lib/types";+import { cn } from "@dub/utils";++export const WebhookStatus = ({+ webhook,+}: {+ webhook: Pick<WebhookProps, "disabledAt">;+}) => {+ const { disabledAt } = webhook;++ return (+ <span+ className={cn(+ "inline-flex items-center justify-center rounded-full p-1.5 text-xs font-medium",+ disabledAt ? "bg-red-500 text-white" : "bg-green-500 text-black",+ )}+ title={disabledAt ? "Disabled" : "Enabled"}+ />+ );+};