Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Add auto-renew support for registered domains

Kiran Kc3914ebc7e65
diff --git a/apps/web/app/api/domains/[domain]/route.ts b/apps/web/app/api/domains/[domain]/route.ts
index a1eb46a22e..7bb2e89a3a 100644
--- a/apps/web/app/api/domains/[domain]/route.ts
+++ b/apps/web/app/api/domains/[domain]/route.ts
@@ -16,6 +16,11 @@ import { prisma } from "@dub/prisma";
import { combineWords, nanoid, R2_URL } from "@dub/utils";
import { waitUntil } from "@vercel/functions";
import { NextResponse } from "next/server";
+import { z } from "zod";
+
+const extendedUpdateDomainBodySchema = updateDomainBodySchema.extend({
+ autoRenew: z.boolean().nullish(),
+});
// GET /api/domains/[domain] – get a workspace's domain
export const GET = withWorkspace(
@@ -56,7 +61,12 @@ export const PATCH = withWorkspace(
archived,
assetLinks,
appleAppSiteAssociation,
- } = await updateDomainBodySchema.parseAsync(await parseRequestBody(req));
+ autoRenew,
+ } = await extendedUpdateDomainBodySchema.parseAsync(
+ await parseRequestBody(req),
+ );
+
+ console.log({ autoRenew });
if (workspace.plan === "free") {
if (
@@ -93,6 +103,7 @@ export const PATCH = withWorkspace(
message: "You cannot update a Dub-provisioned domain.",
});
}
+
const validDomain = await validateDomain(newDomain);
if (validDomain.error && validDomain.code) {
throw new DubApiError({
@@ -100,6 +111,7 @@ export const PATCH = withWorkspace(
message: validDomain.error,
});
}
+
const vercelResponse = await addDomainToVercel(newDomain);
if (vercelResponse.error) {
throw new DubApiError({
@@ -137,6 +149,26 @@ export const PATCH = withWorkspace(
},
});
+ // Sync the autoRenew setting with the registered domain
+ if (registeredDomain && autoRenew !== undefined) {
+ const { autoRenewDisabledAt } = registeredDomain;
+
+ const shouldUpdate =
+ (autoRenew === false && autoRenewDisabledAt === null) ||
+ (autoRenew === true && autoRenewDisabledAt !== null);
+
+ if (shouldUpdate) {
+ await prisma.registeredDomain.update({
+ where: {
+ domainId: domainId,
+ },
+ data: {
+ autoRenewDisabledAt: autoRenew ? null : new Date(),
+ },
+ });
+ }
+ }
+
waitUntil(
(async () => {
// remove old logo
diff --git a/apps/web/lib/zod/schemas/domains.ts b/apps/web/lib/zod/schemas/domains.ts
index cb6d710e73..7928726d65 100644
--- a/apps/web/lib/zod/schemas/domains.ts
+++ b/apps/web/lib/zod/schemas/domains.ts
@@ -9,6 +9,10 @@ import { parseUrlSchemaAllowEmpty } from "./utils";
export const RegisteredDomainSchema = z.object({
id: z.string().describe("The ID of the registered domain record."),
+ autoRenewDisabledAt: z
+ .date()
+ .nullable()
+ .describe("The date the domain auto-renew is disabled."),
createdAt: z.date().describe("The date the domain was created."),
expiresAt: z.date().describe("The date the domain expires."),
});
@@ -66,7 +70,6 @@ export const DomainSchema = z.object({
.describe(
"apple-app-site-association configuration file (for deep link support on iOS).",
),
-
logo: z.string().nullable().describe("The logo of the domain."),
createdAt: z.date().describe("The date the domain was created."),
updatedAt: z.date().describe("The date the domain was last updated."),
diff --git a/apps/web/ui/domains/add-edit-domain-form.tsx b/apps/web/ui/domains/add-edit-domain-form.tsx
index 6a85bf6c35..bd68d1d4ad 100644
--- a/apps/web/ui/domains/add-edit-domain-form.tsx
+++ b/apps/web/ui/domains/add-edit-domain-form.tsx
@@ -27,6 +27,7 @@ import {
Crown,
Milestone,
QrCode,
+ RefreshCw,
TextCursorInput,
} from "lucide-react";
import posthog from "posthog-js";
@@ -579,12 +580,18 @@ export function AddEditDomainForm({
}
const DOMAIN_OPTIONS: {
- id: keyof FormData;
+ id: keyof FormData | "autoRenew";
title: string;
description: string;
icon: any;
proFeature?: boolean;
}[] = [
+ {
+ id: "autoRenew",
+ title: "Domain auto-renew",
+ description: "Automatically renew your domain registration",
+ icon: RefreshCw,
+ },
{
id: "logo",
title: "Custom QR code logo",
diff --git a/packages/prisma/schema/domain.prisma b/packages/prisma/schema/domain.prisma
index 2aaade8c74..343507f05f 100644
--- a/packages/prisma/schema/domain.prisma
+++ b/packages/prisma/schema/domain.prisma
@@ -1,41 +1,42 @@
model Domain {
- id String @id @default(cuid())
- slug String @unique
- verified Boolean @default(false)
+ id String @id @default(cuid())
+ slug String @unique
+ verified Boolean @default(false)
placeholder String?
- expiredUrl String? @db.LongText // URL to redirect to for expired links
- notFoundUrl String? @db.LongText // URL to redirect to for links that don't exist
- primary Boolean @default(false)
- archived Boolean @default(false)
- lastChecked DateTime @default(now())
+ expiredUrl String? @db.LongText // URL to redirect to for expired links
+ notFoundUrl String? @db.LongText // URL to redirect to for links that don't exist
+ primary Boolean @default(false)
+ archived Boolean @default(false)
+ lastChecked DateTime @default(now())
logo String?
linkRetentionDays Int? // default is null (links are retained forever)
appleAppSiteAssociation Json?
assetLinks Json?
- project Project? @relation(fields: [projectId], references: [id], onDelete: Cascade)
projectId String?
- registeredDomain RegisteredDomain?
- programs Program[]
-
// these attributes will exist on both Link and Domain models
- createdAt DateTime @default(now())
- updatedAt DateTime @updatedAt
+ createdAt DateTime @default(now())
+ updatedAt DateTime @updatedAt
+
+ project Project? @relation(fields: [projectId], references: [id], onDelete: Cascade)
+ registeredDomain RegisteredDomain?
+ programs Program[]
@@index(projectId)
@@index(lastChecked(sort: Asc))
}
model RegisteredDomain {
- id String @id @default(cuid())
- slug String
- createdAt DateTime @default(now())
- updatedAt DateTime @updatedAt
- expiresAt DateTime
+ id String @id @default(cuid())
+ slug String
+ projectId String
+ domainId String? @unique
+ autoRenewDisabledAt DateTime?
+ expiresAt DateTime
+ createdAt DateTime @default(now())
+ updatedAt DateTime @updatedAt
- project Project @relation(fields: [projectId], references: [id])
- projectId String
- domain Domain? @relation(fields: [domainId], references: [id], onDelete: SetNull)
- domainId String? @unique
+ project Project @relation(fields: [projectId], references: [id])
+ domain Domain? @relation(fields: [domainId], references: [id], onDelete: SetNull)
@@index(projectId)
@@index(expiresAt(sort: Asc))
diff --git a/packages/prisma/schema/partner.prisma b/packages/prisma/schema/partner.prisma
index f1905a703a..06cbd8ff31 100644
--- a/packages/prisma/schema/partner.prisma
+++ b/packages/prisma/schema/partner.prisma
@@ -56,6 +56,7 @@ model Partner {
payouts Payout[]
commissions Commission[]
}
+
model PartnerInvite {
email String
expires DateTime
@@ -85,12 +86,13 @@ model PartnerUser {
@@unique([userId, partnerId])
@@index([partnerId])
}
+
model PartnerNotificationPreferences {
- id String @id @default(cuid())
- partnerUserId String @unique
+ id String @id @default(cuid())
+ partnerUserId String @unique
- commissionCreated Boolean @default(true)
- applicationApproved Boolean @default(true)
+ commissionCreated Boolean @default(true)
+ applicationApproved Boolean @default(true)
partnerUser PartnerUser @relation(fields: [partnerUserId], references: [id], onDelete: Cascade)
}