The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
wip sending hook
Kiran K3b1dea770c02
diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.tsindex 739b0db48c..c7d7f7deb4 100644--- a/apps/web/lib/types.ts+++ b/apps/web/lib/types.ts@@ -230,3 +230,10 @@ export type InstalledIntegrationInfoProps = Pick<};export type WebhookTrigger = (typeof webhookTrigger)[number];++export type WebhookEventPayload = {+ id: string;+ event: WebhookTrigger;+ createdAt: string;+ data: any; // FIXME: add type+};diff --git a/apps/web/lib/webhook/publish.ts b/apps/web/lib/webhook/publish.tsnew file mode 100644index 0000000000..2f38aa9474--- /dev/null+++ b/apps/web/lib/webhook/publish.ts@@ -0,0 +1,27 @@+import { qstash } from "@/lib/cron";+import { APP_DOMAIN_WITH_NGROK } from "@dub/utils";+import { WebhookTrigger } from "../types";+import { clickEventSchemaTB } from "../zod/schemas/clicks";+import { LinkSchema } from "../zod/schemas/links";++export const publishWebhookEvent = async () => {+ const payload = transformPayload({}, "link.created");++ await qstash.publishJSON({+ url: `${APP_DOMAIN_WITH_NGROK}/api/webhooks/publish`,+ body: {+ //+ },+ });+};++// Transform payload to match the webhook event schema+export const transformPayload = (payload: any, event: WebhookTrigger) => {+ if (event === "link.created") {+ return LinkSchema.parse(payload);+ }++ if (event === "link.clicked") {+ return clickEventSchemaTB.parse(payload);+ }+};diff --git a/apps/web/lib/zod/schemas/webhooks.ts b/apps/web/lib/zod/schemas/webhooks.tsindex 0097e9e09a..3508a2288f 100644--- a/apps/web/lib/zod/schemas/webhooks.ts+++ b/apps/web/lib/zod/schemas/webhooks.ts@@ -1,5 +1,7 @@import { webhookTrigger } from "@/lib/webhook/constants";import { z } from "zod";+import { clickEventSchemaTB } from "./clicks";+import { LinkSchema } from "./links";export const webhookSchema = z.object({id: z.string(),@@ -26,7 +28,5 @@ export const webhookEventSchema = z.object({id: z.string(),event: z.string(),createdAt: z.string(),- data: z.object({- //- }),+ data: z.union([LinkSchema, clickEventSchemaTB]),});