The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Re-provision codes after non-equivalent remaps and allow detach redrive
Kiran K0902be51169c
diff --git a/apps/web/app/(ee)/api/stripe/integration/webhook/coupon-deleted.ts b/apps/web/app/(ee)/api/stripe/integration/webhook/coupon-deleted.tsindex edbd52c58f..e6929945ad 100644--- a/apps/web/app/(ee)/api/stripe/integration/webhook/coupon-deleted.ts+++ b/apps/web/app/(ee)/api/stripe/integration/webhook/coupon-deleted.ts@@ -78,7 +78,6 @@ export async function couponDeleted({},options: {label: discountId,- deduplicationId: `detach-discount-${discountId}`,},})),);diff --git a/apps/web/lib/actions/partners/delete-discount.ts b/apps/web/lib/actions/partners/delete-discount.tsindex d45ead809c..1decb19dc1 100644--- a/apps/web/lib/actions/partners/delete-discount.ts+++ b/apps/web/lib/actions/partners/delete-discount.ts@@ -62,7 +62,6 @@ export const deleteDiscountAction = authActionClient},options: {label: discountId,- deduplicationId: `detach-discount-${discountId}`,},});diff --git a/apps/web/lib/api/groups/delete-group.ts b/apps/web/lib/api/groups/delete-group.tsindex 5405108f36..74dc2570f5 100644--- a/apps/web/lib/api/groups/delete-group.ts+++ b/apps/web/lib/api/groups/delete-group.ts@@ -114,7 +114,6 @@ export async function deletePartnerGroup(},options: {label: discount.id,- deduplicationId: `detach-discount-${discount.id}`,},})),);diff --git a/apps/web/lib/api/partners/update-partner-link.ts b/apps/web/lib/api/partners/update-partner-link.tsindex 549fb57c47..0d536bb1e6 100644--- a/apps/web/lib/api/partners/update-partner-link.ts+++ b/apps/web/lib/api/partners/update-partner-link.ts@@ -154,17 +154,15 @@ export async function updatePartnerLink({});}+ if (body.discountId !== undefined) {+ await syncDiscountCodes({+ programId,+ partnerIds: [link.partnerId],+ });+ }+waitUntil(Promise.allSettled([- ...(body.discountId !== undefined- ? [- syncDiscountCodes({- programId,- partnerIds: [link.partnerId],- }),- ]- : []),-linkCache.expireMany([link]),trackLinkRewardOverrideLog({diff --git a/apps/web/lib/discounts/remap-discount-code.ts b/apps/web/lib/discounts/remap-discount-code.tsindex 31a7701aed..bbe050647f 100644--- a/apps/web/lib/discounts/remap-discount-code.ts+++ b/apps/web/lib/discounts/remap-discount-code.ts@@ -1,6 +1,7 @@import { prisma } from "@/lib/prisma";import { deleteDiscountCodes } from "./delete-discount-code";import { isDiscountEquivalent } from "./is-discount-equivalent";+import { enqueueMissingDiscountCodes } from "./sync-discount-codes";// Remap a single discount code to the partner's current enrollment/link discountexport async function remapDiscountCode({@@ -92,6 +93,17 @@ export async function remapDiscountCode({return;}- // The discounts are different, delete the discount code+ // The discounts are different, delete the discount code then provision a new+ // one on default links when the destination discount has auto-provision on.await deleteDiscountCodes([discountCode]);++ await enqueueMissingDiscountCodes({+ programId: discountCode.programId,+ enrollments: [+ {+ partnerId: discountCode.partnerId,+ discount: programEnrollment.discount,+ },+ ],+ });}diff --git a/apps/web/lib/discounts/sync-discount-codes.ts b/apps/web/lib/discounts/sync-discount-codes.tsindex 79bd160b8c..50be0334b8 100644--- a/apps/web/lib/discounts/sync-discount-codes.ts+++ b/apps/web/lib/discounts/sync-discount-codes.ts@@ -72,7 +72,7 @@ export async function syncDiscountCodes({}// Find default links that do not have a discount code assigned to them and enqueue a job to create one-async function enqueueMissingDiscountCodes({+export async function enqueueMissingDiscountCodes({programId,enrollments,}: {