The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
edit callbacks
Steven Teye66579b897f4
diff --git a/apps/web/app/api/callback/flodesk/route.ts b/apps/web/app/api/callback/flodesk/route.tsnew file mode 100644index 0000000000..8ea1dc66cb--- /dev/null+++ b/apps/web/app/api/callback/flodesk/route.ts@@ -0,0 +1,39 @@+import prisma from "@/lib/prisma";+import { log } from "@dub/utils";+import { NextRequest, NextResponse } from "next/server";++export async function POST(req: NextRequest) {+ const { searchParams } = new URL(req.url);++ const token = searchParams.get("token") as string;++ if (token !== process.env.FLODESK_WEBHOOK_SECRET) {+ return new Response("Unauthorized", { status: 401 });+ }++ const payload = await req.json();++ // parse the payload+ const { subscriber } = payload;++ if (!subscriber.email) {+ return new Response("Invalid payload", { status: 400 });+ }++ await Promise.all([+ prisma.user.update({+ where: {+ email: subscriber.email,+ },+ data: {+ subscribed: false,+ },+ }),+ log({+ message: `*${subscriber.email}* unsubscribed from the newsletter (*Flodesk*).`,+ type: "subscribers",+ }),+ ]);++ return NextResponse.json({ success: true });+}diff --git a/apps/web/app/api/callback/postmark/route.ts b/apps/web/app/api/callback/postmark/route.tsindex 281e23918b..bf922c82d5 100644--- a/apps/web/app/api/callback/postmark/route.ts+++ b/apps/web/app/api/callback/postmark/route.ts@@ -24,12 +24,14 @@ export async function POST(req: NextRequest) {subscribed: !unsub,},}),- unsub- ? unsubscribe(email)- : log({- message: `*${email}* resubscribed to the newsletter. Manual addition required.`,- type: "alerts",- }),+ unsub && unsubscribe(email),+ log({+ message: `*${email}* ${+ unsub ? "unsubscribed" : "subscribed"+ } to the newsletter (*Postmark*). ${!unsub ? "Manual addition required." : ""}`,+ type: "subscribers",+ mention: !unsub,+ }),]);return NextResponse.json({ success: true });diff --git a/packages/utils/src/functions/log.ts b/packages/utils/src/functions/log.tsindex 64967726cd..a80154f464 100644--- a/packages/utils/src/functions/log.ts+++ b/packages/utils/src/functions/log.ts@@ -2,6 +2,7 @@ const logTypeToEnv = {alerts: process.env.DUB_SLACK_HOOK_ALERTS,cron: process.env.DUB_SLACK_HOOK_CRON,links: process.env.DUB_SLACK_HOOK_LINKS,+ subscribers: process.env.DUB_SLACK_HOOK_SUBSCRIBERS,errors: process.env.DUB_SLACK_HOOK_ERRORS,};@@ -11,7 +12,7 @@ export const log = async ({mention = false,}: {message: string;- type: "alerts" | "cron" | "links" | "errors";+ type: "alerts" | "cron" | "links" | "subscribers" | "errors";mention?: boolean;}) => {if (@@ -19,6 +20,7 @@ export const log = async ({!process.env.DUB_SLACK_HOOK_ALERTS ||!process.env.DUB_SLACK_HOOK_CRON ||!process.env.DUB_SLACK_HOOK_LINKS ||+ !process.env.DUB_SLACK_HOOK_SUBSCRIBERS ||!process.env.DUB_SLACK_HOOK_ERRORS) {console.log(message);