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.

upgrade prisma, fixed domain

Steven Teyd447d33911d9
diff --git a/apps/web/app/api/domains/[domain]/route.ts b/apps/web/app/api/domains/[domain]/route.ts
index cf1c581851..88d75feff3 100644
--- a/apps/web/app/api/domains/[domain]/route.ts
+++ b/apps/web/app/api/domains/[domain]/route.ts
@@ -42,6 +42,14 @@ export const PATCH = withWorkspace(
const { slug: newDomain, placeholder, expiredUrl, archived } = payload;
+ if (workspace.plan === "free" && expiredUrl) {
+ throw new DubApiError({
+ code: "forbidden",
+ message:
+ "You can only use Default Expiration URLs on a Pro plan and above. Upgrade to Pro to use these features.",
+ });
+ }
+
const domainUpdated =
newDomain && newDomain.toLowerCase() !== domain.toLowerCase();
diff --git a/apps/web/app/api/domains/route.ts b/apps/web/app/api/domains/route.ts
index cab868ff2b..9feff4987b 100644
--- a/apps/web/app/api/domains/route.ts
+++ b/apps/web/app/api/domains/route.ts
@@ -37,6 +37,14 @@ export const POST = withWorkspace(async ({ req, workspace }) => {
);
}
+ if (workspace.plan === "free" && expiredUrl) {
+ throw new DubApiError({
+ code: "forbidden",
+ message:
+ "You can only use Default Expiration URLs on a Pro plan and above. Upgrade to Pro to use these features.",
+ });
+ }
+
const validDomain = await validateDomain(slug);
if (validDomain.error && validDomain.code) {
diff --git a/apps/web/lib/api/links/process-link.ts b/apps/web/lib/api/links/process-link.ts
index f34e2c2485..f0b9d6eca4 100644
--- a/apps/web/lib/api/links/process-link.ts
+++ b/apps/web/lib/api/links/process-link.ts
@@ -91,12 +91,12 @@ export async function processLink<T extends Record<string, any>>({
(!workspace || workspace.plan === "free") &&
(!createdAt || new Date(createdAt) > new Date("2024-01-19"))
) {
- if (key === "_root") {
+ if (key === "_root" && url) {
return {
link: payload,
error:
- "You can only create root links on a Pro plan and above. Upgrade to Pro to use this feature.",
- code: "unprocessable_entity",
+ "You can only set a redirect for a root domain link on a Pro plan and above. Upgrade to Pro to use this feature.",
+ code: "forbidden",
};
}
@@ -316,16 +316,9 @@ export async function processLink<T extends Record<string, any>>({
delete payload["qrCode"];
delete payload["prefix"];
- // Use domain ID for root links
- let linkId =
- key === "_root"
- ? workspace?.domains.find((d) => d.slug === domain)?.id
- : null;
-
return {
link: {
...payload,
- ...(linkId && { id: linkId }),
domain,
key,
// we're redefining these fields because they're processed in the function
diff --git a/apps/web/lib/zod/schemas/domains.ts b/apps/web/lib/zod/schemas/domains.ts
index 49370ff3cf..56f3b25723 100644
--- a/apps/web/lib/zod/schemas/domains.ts
+++ b/apps/web/lib/zod/schemas/domains.ts
@@ -1,4 +1,5 @@
import z from "@/lib/zod";
+import { getUrlFromString } from "@dub/utils";
import { parseUrlSchema } from "./utils";
export const DomainSchema = z.object({
@@ -21,6 +22,7 @@ export const DomainSchema = z.object({
.default(false),
placeholder: z
.string()
+ .transform((v) => getUrlFromString(v))
.describe(
"Provide context to your teammates in the link creation modal by showing them an example of a link to be shortened.",
)
@@ -28,6 +30,7 @@ export const DomainSchema = z.object({
.openapi({ example: "https://dub.co/help/article/what-is-dub" }),
expiredUrl: z
.string()
+ .transform((v) => getUrlFromString(v))
.nullish()
.describe(
"The URL to redirect to when a link under this domain has expired.",
diff --git a/apps/web/package.json b/apps/web/package.json
index 61b67f1acc..95d033f88e 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -23,7 +23,7 @@
"@next-auth/prisma-adapter": "^1.0.5",
"@planetscale/database": "^1.18.0",
"@prisma/adapter-planetscale": "^5.13.0",
- "@prisma/client": "^5.13.0",
+ "@prisma/client": "^5.15.1",
"@react-email/components": "^0.0.14",
"@react-email/render": "^0.0.12",
"@sindresorhus/slugify": "^2.2.1",
@@ -79,7 +79,7 @@
"openapi-types": "^12.1.3",
"openapi3-ts": "^4.2.1",
"postmark": "^4.0.2",
- "prisma": "^5.13.0",
+ "prisma": "^5.15.1",
"react": "^18.2.0",
"react-colorful": "^5.6.1",
"react-dom": "^18.2.0",
diff --git a/apps/web/ui/domains/domain-card.tsx b/apps/web/ui/domains/domain-card.tsx
index 72f31c437d..01b864f228 100644
--- a/apps/web/ui/domains/domain-card.tsx
+++ b/apps/web/ui/domains/domain-card.tsx
@@ -340,7 +340,7 @@ export default function DomainCard({ props }: { props: DomainProps }) {
? linkProps.url
? `Redirects to`
: `No redirect configured`
- : `Checking link status`}
+ : `Checking Link Status`}
</p>
{linkProps && (
<a
diff --git a/apps/web/ui/modals/add-edit-domain-modal/index.tsx b/apps/web/ui/modals/add-edit-domain-modal/index.tsx
index 6b8540cc31..04ab1d022c 100644
--- a/apps/web/ui/modals/add-edit-domain-modal/index.tsx
+++ b/apps/web/ui/modals/add-edit-domain-modal/index.tsx
@@ -2,6 +2,7 @@ import useWorkspace from "@/lib/swr/use-workspace";
import { DomainProps } from "@/lib/types";
import { Lock } from "@/ui/shared/icons";
import { ProBadgeTooltip } from "@/ui/shared/pro-badge-tooltip";
+import { UpgradeRequiredToast } from "@/ui/shared/upgrade-required-toast";
import {
BlurImage,
Button,
@@ -150,16 +151,21 @@ function AddEditDomainModal({
]);
setShowAddEditDomainModal(false);
toast.success(endpoint.successMessage);
- // TODO: Remove after links dashboard is refactored to use new filter UX
- if (!props) {
- router.push(`/${slug}/domains`);
- }
} else {
const { error } = await res.json();
- toast.error(error.message);
if (res.status === 422) {
setDomainError(error.message);
}
+ if (error.message.includes("Upgrade to Pro")) {
+ toast.custom(() => (
+ <UpgradeRequiredToast
+ title="You've discovered a Pro feature!"
+ message={error.message}
+ />
+ ));
+ } else {
+ toast.error(error.message);
+ }
}
setSaving(false);
});
@@ -238,7 +244,6 @@ function AddEditDomainModal({
</label>
<div className="relative mt-2 rounded-md shadow-sm">
<input
- type="url"
name="expiredUrl"
id="expiredUrl"
className="block w-full rounded-md border-gray-300 text-gray-900 placeholder-gray-400 focus:border-gray-500 focus:outline-none focus:ring-gray-500 sm:text-sm"
@@ -283,7 +288,6 @@ function AddEditDomainModal({
</label>
<div className="relative mt-2 rounded-md shadow-sm">
<input
- type="url"
name="placeholder"
id="placeholder"
className="block w-full rounded-md border-gray-300 text-gray-900 placeholder-gray-400 focus:border-gray-500 focus:outline-none focus:ring-gray-500 sm:text-sm"
diff --git a/apps/web/ui/modals/add-edit-link-modal/index.tsx b/apps/web/ui/modals/add-edit-link-modal/index.tsx
index 5dbc618113..b29d3fdb96 100644
--- a/apps/web/ui/modals/add-edit-link-modal/index.tsx
+++ b/apps/web/ui/modals/add-edit-link-modal/index.tsx
@@ -283,12 +283,10 @@ function AddEditLinkModal({
- saving is in progress
- key is invalid
- url is invalid
- - metatags is being generated
- for an existing link, there's no changes
*/
if (
!showAddEditLinkModal ||
- generatingMetatags ||
saving ||
keyError ||
urlError ||
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 82cec80592..721d93b175 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -60,7 +60,7 @@ importers:
version: link:../../packages/utils
'@next-auth/prisma-adapter':
specifier: ^1.0.5
- version: 1.0.5(@prisma/[email protected])([email protected])
+ version: 1.0.5(@prisma/[email protected])([email protected])
'@planetscale/database':
specifier: ^1.18.0
version: 1.18.0
@@ -68,8 +68,8 @@ importers:
specifier: ^5.13.0
version: 5.13.0(@planetscale/[email protected])
'@prisma/client':
- specifier: ^5.13.0
- version: 5.13.0([email protected])
+ specifier: ^5.15.1
+ version: 5.15.1([email protected])
'@react-email/components':
specifier: ^0.0.14
version: 0.0.14(@types/[email protected])([email protected])
@@ -236,8 +236,8 @@ importers:
specifier: ^4.0.2
version: 4.0.2
prisma:
- specifier: ^5.13.0
- version: 5.13.0
+ specifier: ^5.15.1
+ version: 5.15.1
react:
specifier: ^18.2.0
version: 18.2.0
@@ -4298,13 +4298,13 @@ packages:
sparse-bitfield: 3.0.3
dev: false
resolution: {integrity: sha512-VqMS11IxPXrPGXw6Oul6jcyS/n8GLOWzRMrPr3EMdtD6eOalM6zz05j08PcNiis8QzkfuYnCv49OvufTuaEwYQ==}
peerDependencies:
'@prisma/client': '>=2.26.0 || >=3'
next-auth: ^4
dependencies:
- '@prisma/client': 5.13.0([email protected])
+ '@prisma/client': 5.15.1([email protected])
dev: false
@@ -4753,8 +4753,8 @@ packages:
'@prisma/driver-adapter-utils': 5.13.0
dev: false
- resolution: {integrity: sha512-uYdfpPncbZ/syJyiYBwGZS8Gt1PTNoErNYMuqHDa2r30rNSFtgTA/LXsSk55R7pdRTMi5pHkeP9B14K6nHmwkg==}
+ resolution: {integrity: sha512-fmZRGmsUJ9+VwC/AvfP/PwdpD0xAEyPvNsD9/B3+GYpETq9VejVRT3PiqNvl76q1uYYzNZeo8u/LmzzTetHSEg==}
engines: {node: '>=16.13'}
requiresBuild: true
peerDependencies:
@@ -4763,45 +4763,49 @@ packages:
prisma:
optional: true
dependencies:
- prisma: 5.13.0
+ prisma: 5.15.1
dev: false
resolution: {integrity: sha512-699iqlEvzyCj9ETrXhs8o8wQc/eVW+FigSsHpiskSFydhjVuwTJEfj/nIYqTaWFYuxiWQRfm3r01meuW97SZaQ==}
dev: false
+ /@prisma/[email protected]:
+ resolution: {integrity: sha512-NQjdEplhXEcPvf84ghxExC+LD+iTimbg3sZvA3BhybVQIocBEBxFf9GTHhmRVPmjrWoBaYJBVgEEBXZT27JTbQ==}
+ dev: false
+
resolution: {integrity: sha512-SaimwvGuvXJTsWH+FOfl7PlkZZlPiRGeMEchC0kvB08Xw9B3CLYo/Q7zaY5Fp+u5D8asrpcFQmCjXEgDvOmPkg==}
dependencies:
'@prisma/debug': 5.13.0
dev: false
- /@prisma/engines-version@5.13.0-23.b9a39a7ee606c28e3455d0fd60e78c3ba82b1a2b:
- resolution: {integrity: sha512-AyUuhahTINGn8auyqYdmxsN+qn0mw3eg+uhkp8zwknXYIqoT3bChG4RqNY/nfDkPvzWAPBa9mrDyBeOnWSgO6A==}
+ /@prisma/engines-version@5.15.1-1.5675a3182f972f1a8f31d16eee6abf4fd54910e3:
+ resolution: {integrity: sha512-7csphKGCG6n/cN1MkT1mJvQ78Ir18IknlYZ8eyEoLKdQBb0HscR/6TyPmzqrMA7Rz01K1KeXqctwAqxtA/lKQg==}
dev: false
- /@prisma/[email protected]:
- resolution: {integrity: sha512-hIFLm4H1boj6CBZx55P4xKby9jgDTeDG0Jj3iXtwaaHmlD5JmiDkZhh8+DYWkTGchu+rRF36AVROLnk0oaqhHw==}
+ /@prisma/[email protected]:
+ resolution: {integrity: sha512-1iTRxJEFvpBpEWf2bYiMG6LBBQhX7X+GA5piH+tmPWgc/v+/ElxQf2kjQxby8AErmZqtZkdoKJ7FSRjNjBPE9Q==}
requiresBuild: true
dependencies:
- '@prisma/debug': 5.13.0
- '@prisma/engines-version': 5.13.0-23.b9a39a7ee606c28e3455d0fd60e78c3ba82b1a2b
- '@prisma/fetch-engine': 5.13.0
- '@prisma/get-platform': 5.13.0
+ '@prisma/debug': 5.15.1
+ '@prisma/engines-version': 5.15.1-1.5675a3182f972f1a8f31d16eee6abf4fd54910e3
+ '@prisma/fetch-engine': 5.15.1
+ '@prisma/get-platform': 5.15.1
dev: false
- /@prisma/[email protected]:
- resolution: {integrity: sha512-Yh4W+t6YKyqgcSEB3odBXt7QyVSm0OQlBSldQF2SNXtmOgMX8D7PF/fvH6E6qBCpjB/yeJLy/FfwfFijoHI6sA==}
+ /@prisma/[email protected]:
+ resolution: {integrity: sha512-mj0wfsJ+mAdDp1ynT2JKxAXa+CoYMT267qF7g2Uv+oaVTI2CMfGWouMARht8T2QLTgl+gpXSFTwIYbcR+oWEtw==}
dependencies:
- '@prisma/debug': 5.13.0
- '@prisma/engines-version': 5.13.0-23.b9a39a7ee606c28e3455d0fd60e78c3ba82b1a2b
- '@prisma/get-platform': 5.13.0
+ '@prisma/debug': 5.15.1
+ '@prisma/engines-version': 5.15.1-1.5675a3182f972f1a8f31d16eee6abf4fd54910e3
+ '@prisma/get-platform': 5.15.1
dev: false
- /@prisma/[email protected]:
- resolution: {integrity: sha512-B/WrQwYTzwr7qCLifQzYOmQhZcFmIFhR81xC45gweInSUn2hTEbfKUPd2keAog+y5WI5xLAFNJ3wkXplvSVkSw==}
+ /@prisma/[email protected]:
+ resolution: {integrity: sha512-oFccp7bYys+ZYkmtYzjR+0cRrGKvSuF+h5QhSkyEsYQ9kzJzQRvuWt2SiHRPt8xOQ4MTmujM+bP5uOexnnAHdQ==}
dependencies:
- '@prisma/debug': 5.13.0
+ '@prisma/debug': 5.15.1
dev: false
/@protobufjs/[email protected]:
@@ -16286,13 +16290,13 @@ packages:
react: 18.2.0
dev: false
- resolution: {integrity: sha512-kGtcJaElNRAdAGsCNykFSZ7dBKpL14Cbs+VaQ8cECxQlRPDjBlMHNFYeYt0SKovAVy2Y65JXQwB3A5+zIQwnTg==}
+ resolution: {integrity: sha512-pYsUVpTlYvZ6mWvZKDv9rKdUa7tlfSUJY1CVtgb8Had1pHbIm9fr1MBASccr5XnSuCUrjnvKhWNwgSYy6aCajA==}
engines: {node: '>=16.13'}
hasBin: true
requiresBuild: true
dependencies:
- '@prisma/engines': 5.13.0
+ '@prisma/engines': 5.15.1
dev: false