Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

Updated report schemas. Removed yup.

Mike Caof3e733dea32e
diff --git a/package.json b/package.json
index 1b81c5143..afab156b6 100644
--- a/package.json
+++ b/package.json
@@ -118,7 +118,6 @@
"serialize-error": "^12.0.0",
"thenby": "^1.3.4",
"uuid": "^9.0.0",
- "yup": "^0.32.11",
"zod": "^3.24.1",
"zustand": "^4.5.5"
},
diff --git a/src/app/api/reports/funnel/route.ts b/src/app/api/reports/funnel/route.ts
index 9a0cfd65c..23a05014a 100644
--- a/src/app/api/reports/funnel/route.ts
+++ b/src/app/api/reports/funnel/route.ts
@@ -3,10 +3,12 @@ import { canViewWebsite } from 'lib/auth';
import { unauthorized, json } from 'lib/response';
import { parseRequest } from 'lib/request';
import { getFunnel } from 'queries';
+import { reportParms } from 'lib/schema';
export async function POST(request: Request) {
const schema = z.object({
- websiteId: z.string().uuid(),
+ ...reportParms,
+ window: z.number().positive(),
steps: z
.array(
z.object({
@@ -15,11 +17,6 @@ export async function POST(request: Request) {
}),
)
.min(2),
- window: z.number().positive(),
- dateRange: z.object({
- startDate: z.date(),
- endDate: z.date(),
- }),
});
const { auth, body, error } = await parseRequest(request, schema);
diff --git a/src/app/api/reports/goals/route.ts b/src/app/api/reports/goals/route.ts
index ee102bc64..cad774bd1 100644
--- a/src/app/api/reports/goals/route.ts
+++ b/src/app/api/reports/goals/route.ts
@@ -3,14 +3,11 @@ import { canViewWebsite } from 'lib/auth';
import { unauthorized, json } from 'lib/response';
import { parseRequest } from 'lib/request';
import { getGoals } from 'queries/analytics/reports/getGoals';
+import { reportParms } from 'lib/schema';
export async function POST(request: Request) {
const schema = z.object({
- websiteId: z.string().uuid(),
- dateRange: z.object({
- startDate: z.date(),
- endDate: z.date(),
- }),
+ ...reportParms,
goals: z
.array(
z.object({
diff --git a/src/app/api/reports/insights/route.ts b/src/app/api/reports/insights/route.ts
index f622de6aa..a7ed1c155 100644
--- a/src/app/api/reports/insights/route.ts
+++ b/src/app/api/reports/insights/route.ts
@@ -3,6 +3,7 @@ import { canViewWebsite } from 'lib/auth';
import { unauthorized, json } from 'lib/response';
import { parseRequest } from 'lib/request';
import { getInsights } from 'queries';
+import { reportParms } from 'lib/schema';
function convertFilters(filters: any[]) {
return filters.reduce((obj, filter) => {
@@ -14,11 +15,7 @@ function convertFilters(filters: any[]) {
export async function POST(request: Request) {
const schema = z.object({
- websiteId: z.string().uuid(),
- dateRange: z.object({
- startDate: z.coerce.date(),
- endDate: z.coerce.date(),
- }),
+ ...reportParms,
fields: z
.array(
z.object({
diff --git a/src/app/api/reports/journey/route.ts b/src/app/api/reports/journey/route.ts
index 50b64952f..f5121fdc6 100644
--- a/src/app/api/reports/journey/route.ts
+++ b/src/app/api/reports/journey/route.ts
@@ -3,14 +3,11 @@ import { canViewWebsite } from 'lib/auth';
import { unauthorized, json } from 'lib/response';
import { parseRequest } from 'lib/request';
import { getJourney } from 'queries';
+import { reportParms } from 'lib/schema';
export async function POST(request: Request) {
const schema = z.object({
- websiteId: z.string().uuid(),
- dateRange: z.object({
- startDate: z.date(),
- endDate: z.date(),
- }),
+ ...reportParms,
steps: z.number().min(3).max(7),
startStep: z.string(),
endStep: z.string(),
diff --git a/src/app/api/reports/retention/route.ts b/src/app/api/reports/retention/route.ts
index 794ebbe48..8e854fa96 100644
--- a/src/app/api/reports/retention/route.ts
+++ b/src/app/api/reports/retention/route.ts
@@ -3,15 +3,11 @@ import { canViewWebsite } from 'lib/auth';
import { unauthorized, json } from 'lib/response';
import { parseRequest } from 'lib/request';
import { getRetention } from 'queries';
-import { timezoneParam } from 'lib/schema';
+import { reportParms, timezoneParam } from 'lib/schema';
export async function POST(request: Request) {
const schema = z.object({
- websiteId: z.string().uuid(),
- dateRange: z.object({
- startDate: z.date(),
- endDate: z.date(),
- }),
+ ...reportParms,
timezone: timezoneParam,
});
diff --git a/src/app/api/reports/revenue/route.ts b/src/app/api/reports/revenue/route.ts
index 0f8f7d55a..d3c21b9cc 100644
--- a/src/app/api/reports/revenue/route.ts
+++ b/src/app/api/reports/revenue/route.ts
@@ -2,17 +2,13 @@ import { z } from 'zod';
import { canViewWebsite } from 'lib/auth';
import { unauthorized, json } from 'lib/response';
import { parseRequest } from 'lib/request';
-import { timezoneParam, unitParam } from 'lib/schema';
+import { reportParms, timezoneParam, unitParam } from 'lib/schema';
import { getRevenue } from 'queries/analytics/reports/getRevenue';
import { getRevenueValues } from 'queries/analytics/reports/getRevenueValues';
export async function GET(request: Request) {
const schema = z.object({
- websiteId: z.string().uuid(),
- dateRange: z.object({
- startDate: z.date(),
- endDate: z.date(),
- }),
+ ...reportParms,
});
const { auth, query, error } = await parseRequest(request, schema);
diff --git a/src/app/api/reports/utm/route.ts b/src/app/api/reports/utm/route.ts
index 0af8b4199..2412134d2 100644
--- a/src/app/api/reports/utm/route.ts
+++ b/src/app/api/reports/utm/route.ts
@@ -3,16 +3,11 @@ import { canViewWebsite } from 'lib/auth';
import { unauthorized, json } from 'lib/response';
import { parseRequest } from 'lib/request';
import { getUTM } from 'queries';
-import { timezoneParam } from 'lib/schema';
+import { reportParms } from 'lib/schema';
export async function POST(request: Request) {
const schema = z.object({
- websiteId: z.string().uuid(),
- dateRange: z.object({
- startDate: z.date(),
- endDate: z.date(),
- timezone: timezoneParam,
- }),
+ ...reportParms,
});
const { auth, body, error } = await parseRequest(request, schema);
diff --git a/src/lib/detect.ts b/src/lib/detect.ts
index 835040958..89e73a0bb 100644
--- a/src/lib/detect.ts
+++ b/src/lib/detect.ts
@@ -148,7 +148,7 @@ export async function getClientInfo(request: Request, payload: Record<string, an
const userAgent = payload?.userAgent || request.headers.get('user-agent');
const ip = payload?.ip || getIpAddress(request.headers);
const location = await getLocation(ip, request.headers);
- const country = location?.country;
+ const country = payload?.userAgent || location?.country;
const subdivision1 = location?.subdivision1;
const subdivision2 = location?.subdivision2;
const city = location?.city;
diff --git a/src/lib/schema.ts b/src/lib/schema.ts
index 80be76913..9978d9e5e 100644
--- a/src/lib/schema.ts
+++ b/src/lib/schema.ts
@@ -1,18 +1,22 @@
import { z } from 'zod';
-import * as yup from 'yup';
import { isValidTimezone } from 'lib/date';
import { UNIT_TYPES } from './constants';
-export const dateRange = {
- startAt: yup.number().integer().required(),
- endAt: yup.number().integer().min(yup.ref('startAt')).required(),
-};
-
-export const pageInfo = {
- query: yup.string(),
- page: yup.number().integer().positive(),
- pageSize: yup.number().integer().positive().min(1).max(200),
- orderBy: yup.string(),
+export const filterParams = {
+ url: z.string().optional(),
+ referrer: z.string().optional(),
+ title: z.string().optional(),
+ query: z.string().optional(),
+ os: z.string().optional(),
+ browser: z.string().optional(),
+ device: z.string().optional(),
+ country: z.string().optional(),
+ region: z.string().optional(),
+ city: z.string().optional(),
+ tag: z.string().optional(),
+ host: z.string().optional(),
+ language: z.string().optional(),
+ event: z.string().optional(),
};
export const pagingParams = {
@@ -42,19 +46,10 @@ export const reportTypeParam = z.enum([
'revenue',
]);
-export const filterParams = {
- url: z.string().optional(),
- referrer: z.string().optional(),
- title: z.string().optional(),
- query: z.string().optional(),
- os: z.string().optional(),
- browser: z.string().optional(),
- device: z.string().optional(),
- country: z.string().optional(),
- region: z.string().optional(),
- city: z.string().optional(),
- tag: z.string().optional(),
- host: z.string().optional(),
- language: z.string().optional(),
- event: z.string().optional(),
+export const reportParms = {
+ websiteId: z.string().uuid(),
+ dateRange: z.object({
+ startDate: z.coerce.date(),
+ endDate: z.coerce.date(),
+ }),
};
diff --git a/src/lib/types.ts b/src/lib/types.ts
index 5c397d5ec..3f7697992 100644
--- a/src/lib/types.ts
+++ b/src/lib/types.ts
@@ -1,4 +1,3 @@
-import { NextApiRequest } from 'next';
import {
COLLECTION_TYPE,
DATA_TYPE,
@@ -8,7 +7,6 @@ import {
REPORT_TYPES,
ROLES,
} from './constants';
-import * as yup from 'yup';
import { TIME_UNIT } from './date';
import { Dispatch, SetStateAction } from 'react';
@@ -65,26 +63,6 @@ export interface Auth {
};
}
-export interface YupRequest {
- GET?: yup.ObjectSchema<any>;
- POST?: yup.ObjectSchema<any>;
- PUT?: yup.ObjectSchema<any>;
- DELETE?: yup.ObjectSchema<any>;
-}
-
-export interface NextApiRequestQueryBody<TQuery = any, TBody = any> extends NextApiRequest {
- auth?: Auth;
- query: TQuery & { [key: string]: string | string[] };
- body: TBody;
- headers: any;
- yup: YupRequest;
-}
-
-export interface NextApiRequestAuth extends NextApiRequest {
- auth?: Auth;
- headers: any;
-}
-
export interface User {
id: string;
username: string;
diff --git a/src/lib/yup.ts b/src/lib/yup.ts
deleted file mode 100644
index d2652eda1..000000000
--- a/src/lib/yup.ts
+++ /dev/null
@@ -1,18 +0,0 @@
-import * as yup from 'yup';
-import { isValidTimezone } from 'lib/date';
-import { UNIT_TYPES } from './constants';
-
-export const TimezoneTest = yup
- .string()
- .default('UTC')
- .test(
- 'timezone',
- () => `Invalid timezone`,
- value => isValidTimezone(value),
- );
-
-export const UnitTypeTest = yup.string().test(
- 'unit',
- () => `Invalid unit`,
- value => UNIT_TYPES.includes(value),
-);
diff --git a/yarn.lock b/yarn.lock
index fb7399103..91546c342 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2968,11 +2968,6 @@
resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee"
integrity sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==
-"@types/lodash@^4.14.175":
- version "4.14.200"
- resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.200.tgz#435b6035c7eba9cdf1e039af8212c9e9281e7149"
- integrity sha512-YI/M/4HRImtNf3pJgbF+W6FrXovqj+T+/HpENLTooK9PnkacBsDpeP3IpHab40CClUfhNmdM2WTNP2sa2dni5Q==
-
"@types/minimatch@*":
version "5.1.2"
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-5.1.2.tgz#07508b45797cb81ec3f273011b054cd0755eddca"
@@ -7610,11 +7605,6 @@ locate-path@^6.0.0:
dependencies:
p-locate "^5.0.0"
-lodash-es@^4.17.21:
- version "4.17.21"
- resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.21.tgz#43e626c46e6591b7750beb2b50117390c609e3ee"
- integrity sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==
-
lodash.camelcase@^4.3.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz#b28aa6288a2b9fc651035c7711f65ab6190331a6"
@@ -8042,11 +8032,6 @@ ms@^2.1.1, ms@^2.1.3:
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2"
integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==
-nanoclone@^0.2.1:
- version "0.2.1"
- resolved "https://registry.yarnpkg.com/nanoclone/-/nanoclone-0.2.1.tgz#dd4090f8f1a110d26bb32c49ed2f5b9235209ed4"
- integrity sha512-wynEP02LmIbLpcYw8uBKpcfF6dmg2vcpKqxeH5UcoKEYdExslsdUA4ugFauuaeYdTB76ez6gJW8XAZ6CgkXYxA==
-
nanoid@^3.3.6, nanoid@^3.3.7:
version "3.3.8"
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.8.tgz#b1be3030bee36aaff18bacb375e5cce521684baf"
@@ -9164,11 +9149,6 @@ prop-types@^15.7.2, prop-types@^15.8.1:
object-assign "^4.1.1"
react-is "^16.13.1"
-property-expr@^2.0.4:
- version "2.0.6"
- resolved "https://registry.yarnpkg.com/property-expr/-/property-expr-2.0.6.tgz#f77bc00d5928a6c748414ad12882e83f24aec1e8"
- integrity sha512-SVtmxhRE/CGkn3eZY1T6pC8Nln6Fr/lu1mKSgRud0eC73whjGfoAogbn78LkD8aFL0zz3bAFerKSnOl7NlErBA==
-
version "1.0.0"
resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.0.0.tgz#33c50398f70ea7eb96d21f7b817630a55791c7ee"
@@ -10592,11 +10572,6 @@ topojson-client@^3.1.0:
dependencies:
commander "2"
-toposort@^2.0.2:
- version "2.0.2"
- resolved "https://registry.yarnpkg.com/toposort/-/toposort-2.0.2.tgz#ae21768175d1559d48bef35420b2f4962f09c330"
- integrity sha512-0a5EOkAUp8D4moMi2W8ZF8jcga7BgZd91O/yabJCFY8az+XSzeGyTKs0Aoo897iV1Nj6guFq8orWDS96z91oGg==
-
tough-cookie@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-5.0.0.tgz#6b6518e2b5c070cf742d872ee0f4f92d69eac1af"
@@ -11197,19 +11172,6 @@ yocto-queue@^0.1.0:
resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b"
integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==
-yup@^0.32.11:
- version "0.32.11"
- resolved "https://registry.yarnpkg.com/yup/-/yup-0.32.11.tgz#d67fb83eefa4698607982e63f7ca4c5ed3cf18c5"
- integrity sha512-Z2Fe1bn+eLstG8DRR6FTavGD+MeAwyfmouhHsIUgaADz8jvFKbO/fXc2trJKZg+5EBjh4gGm3iU/t3onKlXHIg==
- dependencies:
- "@babel/runtime" "^7.15.4"
- "@types/lodash" "^4.14.175"
- lodash "^4.17.21"
- lodash-es "^4.17.21"
- nanoclone "^0.2.1"
- property-expr "^2.0.4"
- toposort "^2.0.2"
-
zod@^3.24.1:
version "3.24.1"
resolved "https://registry.yarnpkg.com/zod/-/zod-3.24.1.tgz#27445c912738c8ad1e9de1bea0359fa44d9d35ee"