mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
Updated report schemas. Removed yup.
This commit is contained in:
parent
edd72cd6e3
commit
f3e733dea3
13 changed files with 37 additions and 146 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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({
|
||||
|
|
|
|||
|
|
@ -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({
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
}),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
);
|
||||
Loading…
Add table
Add a link
Reference in a new issue