The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Code style conformed with prettier
UsmanDev09180e119da23d
diff --git a/apps/web/app/api/analytics/[endpoint]/route.ts b/apps/web/app/api/analytics/[endpoint]/route.tsindex bbe189181b..ab89f130b9 100644--- a/apps/web/app/api/analytics/[endpoint]/route.ts+++ b/apps/web/app/api/analytics/[endpoint]/route.ts@@ -17,11 +17,15 @@ export const GET = withWorkspace(const { domain, key, interval, startDate, endDate } = parsedParams;// Either interval can be provided, or both start and end date- if((interval && (startDate && endDate)) || (startDate && !endDate) || (!startDate && endDate)) {+ if (+ (interval && startDate && endDate) ||+ (startDate && !endDate) ||+ (!startDate && endDate)+ ) {throw new DubApiError({code: "unprocessable_entity",- message: "Either provide interval or start and end date, not both"- })+ message: "Either provide interval or start and end date, not both",+ });}// return 403 if workspace is on the free plan and interval is 90d or allI dodiff --git a/apps/web/lib/analytics.ts b/apps/web/lib/analytics.tsindex fe1a115c9c..1cfd3ebf24 100644--- a/apps/web/lib/analytics.ts+++ b/apps/web/lib/analytics.ts@@ -165,20 +165,14 @@ export const getAnalytics = async ({url.searchParams.append("granularity", intervalData[interval].granularity);}- if(startDate && endDate) {+ if (startDate && endDate) {url.searchParams.append("start",- startDate- .toString()- .replace("T", " ")- .replace("Z", ""),+ startDate.toString().replace("T", " ").replace("Z", ""),);url.searchParams.append("end",- endDate- .toString()- .replace("T", " ")- .replace("Z", ""),+ endDate.toString().replace("T", " ").replace("Z", ""),);}diff --git a/apps/web/lib/zod/schemas/analytics.ts b/apps/web/lib/zod/schemas/analytics.tsindex cd97ca3ad4..03d415935d 100644--- a/apps/web/lib/zod/schemas/analytics.ts+++ b/apps/web/lib/zod/schemas/analytics.ts@@ -3,7 +3,6 @@ import z from "@/lib/zod";import { COUNTRY_CODES } from "@dub/utils";import { booleanQuerySchema } from "./misc";-export const getAnalyticsQuerySchema = z.object({domain: z.string().optional().describe("The domain of the short link."),key: z.string().optional().describe("The short link slug."),@@ -14,26 +13,31 @@ export const getAnalyticsQuerySchema = z.object({startDate: z.string().datetime()- .refine(value => {- const inputDate = new Date(value);- const foundingDate = new Date("2022-09-22T00:00:00.000Z"); // Dub.co founding date- return inputDate >= foundingDate;- },- {- message: "The start date cannot be earlier than September 22, 2022."- })+ .refine(+ (value) => {+ const inputDate = new Date(value);+ const foundingDate = new Date("2022-09-22T00:00:00.000Z"); // Dub.co founding date+ return inputDate >= foundingDate;+ },+ {+ message: "The start date cannot be earlier than September 22, 2022.",+ },+ ).optional().describe("The start date and time when to retrieve analytics from."),endDate: z.string().datetime()- .refine(value => {- const todaysDate = new Date();- const inputDate = new Date(value);- return inputDate <= todaysDate;- }, {- message: "The end date cannot be in future."- })+ .refine(+ (value) => {+ const todaysDate = new Date();+ const inputDate = new Date(value);+ return inputDate <= todaysDate;+ },+ {+ message: "The end date cannot be in future.",+ },+ ).optional().describe("The end date and time when to retrieve analytics from."),country: z