The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
fix #468
Steven Tey22e656640bfc
diff --git a/apps/web/app/api/route.ts b/apps/web/app/api/route.tsindex 9c7f4f66c8..5cde5350e0 100644--- a/apps/web/app/api/route.ts+++ b/apps/web/app/api/route.ts@@ -633,7 +633,8 @@ export function GET(): NextResponse<OpenAPIV3.Document> {expiresAt: {type: "string",format: "date-time",- description: "The date and time when the short link will expire.",+ description:+ "The date and time when the short link will expire in ISO-8601 format. Must be in the future.",default: null,nullable: true,},diff --git a/apps/web/lib/api/links.ts b/apps/web/lib/api/links.tsindex 4ab0a41dee..a0f1863471 100644--- a/apps/web/lib/api/links.ts+++ b/apps/web/lib/api/links.ts@@ -21,6 +21,7 @@ import cloudinary from "cloudinary";import { isIframeable } from "../middleware/utils";import { LinkProps, ProjectProps } from "../types";import { Session } from "../auth";+import { SetCommandOptions } from "@upstash/redis";export async function getLinksForProject({projectId,@@ -234,6 +235,25 @@ export async function processLink({status: 400,};}+ if (payload.expiresAt) {+ // check if expiresAt is a valid+ const date = new Date(payload.expiresAt);+ if (isNaN(date.getTime())) {+ return {+ link: payload,+ error: "Invalid expiry date. Expiry date must be in ISO-8601 format.",+ status: 422,+ };+ }+ // check if expiresAt is in the future+ if (new Date(payload.expiresAt) < new Date()) {+ return {+ link: payload,+ error: "Expiry date must be in the future.",+ status: 422,+ };+ }+ }if (project) {if (!project.domains?.find((d) => d.slug === domain)) {@@ -388,7 +408,6 @@ export async function addLink(link: LinkProps) {geo,} = link;const hasPassword = password && password.length > 0 ? true : false;- const exat = expiresAt ? new Date(expiresAt).getTime() / 1000 : null;const uploadedImage = image && image.startsWith("data:image") ? true : false;const exists = await checkIfKeyExists(domain, key);@@ -410,6 +429,7 @@ export async function addLink(link: LinkProps) {utm_campaign,utm_term,utm_content,+ expiresAt: expiresAt ? new Date(expiresAt) : null,geo: geo || undefined,},}),@@ -429,11 +449,11 @@ export async function addLink(link: LinkProps) {},{nx: true,- // if the key has an expiry, set exat (type any cause there's a type error in the @types)- ...(exat && { exat: exat as any }),- },+ ...(expiresAt && { exat: new Date(expiresAt).getTime() / 1000 }),+ } as SetCommandOptions,),]);+if (proxy && image) {const { secure_url } = await cloudinary.v2.uploader.upload(image, {public_id: key,@@ -457,7 +477,6 @@ export async function bulkCreateLinks(links: LinkProps[]) {const pipeline = redis.pipeline();links.forEach(({ domain, key, url, expiresAt, password }) => {const hasPassword = password && password.length > 0 ? true : false;- const exat = expiresAt ? new Date(expiresAt).getTime() / 1000 : null;pipeline.set(`${domain}:${key}`,{@@ -466,8 +485,8 @@ export async function bulkCreateLinks(links: LinkProps[]) {},{nx: true,- ...(exat && { exat: exat as any }),- },+ ...(expiresAt && { exat: new Date(expiresAt).getTime() / 1000 }),+ } as SetCommandOptions,);});@@ -485,6 +504,7 @@ export async function bulkCreateLinks(links: LinkProps[]) {utm_campaign,utm_term,utm_content,+ expiresAt: link.expiresAt ? new Date(link.expiresAt) : null,geo: link.geo || undefined,};}),@@ -536,7 +556,6 @@ export async function editLink({geo,} = updatedLink;const hasPassword = password && password.length > 0 ? true : false;- const exat = expiresAt ? new Date(expiresAt).getTime() : null;const changedKey = key !== oldKey;const changedDomain = domain !== oldDomain;const uploadedImage = image && image.startsWith("data:image") ? true : false;@@ -567,6 +586,7 @@ export async function editLink({utm_campaign,utm_term,utm_content,+ expiresAt: expiresAt ? new Date(expiresAt) : null,geo: geo || undefined,},}),@@ -595,7 +615,9 @@ export async function editLink({...(android && { android }),...(geo && { geo }),},- exat ? { exat } : {},+ {+ ...(expiresAt && { exat: new Date(expiresAt).getTime() / 1000 }),+ } as SetCommandOptions,),// if key is changed: rename resource in Cloudinary, delete the old key in Redis and change the clicks key name...(changedDomain || changedKeydiff --git a/apps/web/package.json b/apps/web/package.jsonindex 9318c125e4..c179a29224 100644--- a/apps/web/package.json+++ b/apps/web/package.json@@ -26,7 +26,7 @@"@stripe/stripe-js": "^1.44.1","@upstash/qstash": "^0.3.6","@upstash/ratelimit": "^0.3.6",- "@upstash/redis": "^1.18.0",+ "@upstash/redis": "^1.25.1","@vercel/analytics": "^1.0.0","@vercel/edge": "^0.3.1","@vercel/edge-config": "^0.4.1",diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex ba51a941b4..4e803f82d6 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -77,8 +77,8 @@ importers:specifier: ^0.3.6version: 0.3.6(@babel/[email protected])([email protected])'@upstash/redis':- specifier: ^1.18.0- version: 1.18.0+ specifier: ^1.25.1+ version: 1.25.1'@vercel/analytics':specifier: ^1.0.0version: 1.0.0([email protected])@@ -381,8 +381,8 @@ importers:specifier: ^0.3.6version: 0.3.6(@babel/[email protected])([email protected])'@upstash/redis':- specifier: ^1.18.0- version: 1.22.1+ specifier: ^1.25.1+ version: 1.25.1'@vercel/analytics':specifier: ^1.0.0version: 1.0.0([email protected])@@ -7362,14 +7362,13 @@ packages:resolution: {integrity: sha512-81kK0rCpNunSJOhr37mTufqbNE3JhssA2RQsSjNxzq2nR/FCPK3RZWvQxuZoJrfO4vPl2FfytZAy02jTyUVpjg==}engines: {node: '>=16.0.0'}dependencies:- '@upstash/redis': 1.22.1+ '@upstash/redis': 1.25.1react: 18.2.0zod: 3.22.3transitivePeerDependencies:- '@babel/core'- babel-plugin-macros- - encoding- fibers- node-sass- react-dom@@ -7380,14 +7379,13 @@ packages:resolution: {integrity: sha512-81kK0rCpNunSJOhr37mTufqbNE3JhssA2RQsSjNxzq2nR/FCPK3RZWvQxuZoJrfO4vPl2FfytZAy02jTyUVpjg==}engines: {node: '>=16.0.0'}dependencies:- '@upstash/redis': 1.22.1+ '@upstash/redis': 1.25.1react: 18.2.0zod: 3.22.3transitivePeerDependencies:- '@babel/core'- babel-plugin-macros- - encoding- fibers- node-sass- react-dom@@ -7407,7 +7405,6 @@ packages:transitivePeerDependencies:- '@babel/core'- babel-plugin-macros- - encoding- fibers- node-sass- react-dom@@ -7421,27 +7418,16 @@ packages:transitivePeerDependencies:- '@babel/core'- babel-plugin-macros- - encoding- fibers- node-sass- react-dom- sassdev: false- /@upstash/[email protected]:- resolution: {integrity: sha512-BBYz0X5EghFttYIk0vePW3/clQoAfxmPxwqc3UXem3Qp9iGFRwLN/HKvxuJQxkt18RyNPQ3fN4Eg0MG4lyu7Hw==}- dependencies:- isomorphic-fetch: 3.0.0- transitivePeerDependencies:- - encoding- dev: false-- /@upstash/[email protected]:- resolution: {integrity: sha512-7ec2eCMkVxZzuHNb+hPKonX4b/Pu0BdDeSBsEy+jKIqiweXzCs5Dpu9642vJgf57YnEsfwgXnQMVEataarvyeQ==}+ /@upstash/[email protected]:+ resolution: {integrity: sha512-ACj0GhJ4qrQyBshwFgPod6XufVEfKX2wcaihsEvSdLYnY+m+pa13kGt1RXm/yTHKf4TQi/Dy2A8z/y6WUEOmlg==}dependencies:- isomorphic-fetch: 3.0.0- transitivePeerDependencies:- - encoding+ crypto-js: 4.2.0dev: false/@vercel/[email protected]([email protected]):@@ -8778,6 +8764,10 @@ packages:shebang-command: 2.0.0which: 2.0.2+ resolution: {integrity: sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q==}+ dev: false+resolution: {integrity: sha512-2EZLisiZQ+7m4wwur/qiYJRniHX4K5Tc9w93MT3AS0WS1u5kaZ4FKXlOTBhOjc+CgEgPiGY+fX1yWD8UwpEqUA==}dev: false@@ -11140,15 +11130,6 @@ packages:engines: {node: '>=0.10.0'}dev: false- resolution: {integrity: sha512-qvUtwJ3j6qwsF3jLxkZ72qCgjMysPzDfeV240JHiGZsANBYd+EEuu35v7dfrJ9Up0Ak07D7GGSkGhCHTqg/5wA==}- dependencies:- node-fetch: 2.7.0([email protected])- whatwg-fetch: 3.6.19- transitivePeerDependencies:- - encoding- dev: false-resolution: {integrity: sha512-DR33HMMr8EzwuRL8Y9D3u2BMj8+RqSE850jfGu59kS7tbmPLzGkZmVSfyCFSDxuZiEY6Rzt3T2NA/qU+NwVj1w==}dependencies: