Convert event-data, events, session-data, sessions routes.
This commit is contained in:
1 parent
baa3851fb4
commit
7d5556a637
47 files changed
+692
-136
No files matched your search
@@ -7,6 +7,7 @@ import { checkRequest } from 'lib/request';
|
||||
|
||||
export async function GET(request: Request, { params }: { params: Promise<{ userId: string }> }) {
|
||||
const { userId } = await params;
|
||||
|
||||
const auth = await checkAuth(request);
|
||||
|
||||
if (!auth || !(await canViewUser(auth, userId))) {
|
||||
@@ -32,6 +33,7 @@ export async function POST(request: Request, { params }: { params: Promise<{ use
|
||||
}
|
||||
|
||||
const { userId } = await params;
|
||||
|
||||
const auth = await checkAuth(request);
|
||||
|
||||
if (!auth || !(await canUpdateUser(auth, userId))) {
|
||||
|
||||
@@ -5,12 +5,10 @@ import { checkAuth } from 'lib/auth';
|
||||
import { unauthorized, badRequest, json } from 'lib/response';
|
||||
import { checkRequest } from 'lib/request';
|
||||
|
||||
const schema = z.object({
|
||||
...pagingParams,
|
||||
});
|
||||
|
||||
export async function GET(request: Request, { params }: { params: Promise<{ userId: string }> }) {
|
||||
const { userId } = await params;
|
||||
const schema = z.object({
|
||||
...pagingParams,
|
||||
});
|
||||
|
||||
const { query, error } = await checkRequest(request, schema);
|
||||
|
||||
@@ -18,6 +16,8 @@ export async function GET(request: Request, { params }: { params: Promise<{ user
|
||||
return badRequest(error);
|
||||
}
|
||||
|
||||
const { userId } = await params;
|
||||
|
||||
const auth = await checkAuth(request);
|
||||
|
||||
if (!auth || (!auth.user.isAdmin && (!userId || auth.user.id !== userId))) {
|
||||
|
||||
@@ -6,12 +6,12 @@ import { getEventDataUsage } from 'queries/analytics/events/getEventDataUsage';
|
||||
import { checkAuth } from 'lib/auth';
|
||||
import { checkRequest } from 'lib/request';
|
||||
|
||||
const schema = z.object({
|
||||
startAt: z.coerce.number(),
|
||||
endAt: z.coerce.number(),
|
||||
});
|
||||
|
||||
export async function GET(request: Request, { params }: { params: Promise<{ userId: string }> }) {
|
||||
const schema = z.object({
|
||||
startAt: z.coerce.number().int(),
|
||||
endAt: z.coerce.number().int(),
|
||||
});
|
||||
|
||||
const { query, error } = await checkRequest(request, schema);
|
||||
|
||||
if (error) {
|
||||
|
||||
@@ -5,11 +5,11 @@ import { pagingParams } from 'lib/schema';
|
||||
import { checkRequest } from 'lib/request';
|
||||
import { checkAuth } from 'lib/auth';
|
||||
|
||||
const schema = z.object({
|
||||
...pagingParams,
|
||||
});
|
||||
|
||||
export async function GET(request: Request, { params }: { params: Promise<{ userId: string }> }) {
|
||||
const schema = z.object({
|
||||
...pagingParams,
|
||||
});
|
||||
|
||||
const { query, error } = await checkRequest(request, schema);
|
||||
|
||||
if (error) {
|
||||
@@ -17,6 +17,7 @@ export async function GET(request: Request, { params }: { params: Promise<{ user
|
||||
}
|
||||
|
||||
const { userId } = await params;
|
||||
|
||||
const auth = await checkAuth(request);
|
||||
|
||||
if (!auth || (!auth.user.isAdmin && auth.user.id !== userId)) {
|
||||
|
||||
@@ -7,14 +7,14 @@ import { checkRequest } from 'lib/request';
|
||||
import { unauthorized, json, badRequest } from 'lib/response';
|
||||
import { createUser, getUserByUsername } from 'queries';
|
||||
|
||||
const schema = z.object({
|
||||
username: z.string().max(255),
|
||||
password: z.string(),
|
||||
id: z.string().uuid(),
|
||||
role: z.string().regex(/admin|user|view-only/i),
|
||||
});
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const schema = z.object({
|
||||
username: z.string().max(255),
|
||||
password: z.string(),
|
||||
id: z.string().uuid(),
|
||||
role: z.string().regex(/admin|user|view-only/i),
|
||||
});
|
||||
|
||||
const { body, error } = await checkRequest(request, schema);
|
||||
|
||||
if (error) {
|
||||
|
||||
@@ -6,15 +6,11 @@ export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string }> },
|
||||
) {
|
||||
const auth = await checkAuth(request);
|
||||
|
||||
if (!auth) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const { websiteId } = await params;
|
||||
|
||||
if (!(await canViewWebsite(auth, websiteId))) {
|
||||
const auth = await checkAuth(request);
|
||||
|
||||
if (!auth || !(await canViewWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,9 +6,10 @@ export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string }> },
|
||||
) {
|
||||
const auth = await checkAuth(request);
|
||||
const { websiteId } = await params;
|
||||
|
||||
const auth = await checkAuth(request);
|
||||
|
||||
if (!auth || !(await canViewWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import { z } from 'zod';
|
||||
import { checkRequest } from 'lib/request';
|
||||
import { badRequest, unauthorized, json } from 'lib/response';
|
||||
import { canViewWebsite, checkAuth } from 'lib/auth';
|
||||
import { getEventDataEvents } from 'queries/analytics/events/getEventDataEvents';
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string }> },
|
||||
) {
|
||||
const schema = z.object({
|
||||
startAt: z.coerce.number().int(),
|
||||
endAt: z.coerce.number().int(),
|
||||
event: z.string().optional(),
|
||||
});
|
||||
|
||||
const { query, error } = await checkRequest(request, schema);
|
||||
|
||||
if (error) {
|
||||
return badRequest(error);
|
||||
}
|
||||
|
||||
const { websiteId } = await params;
|
||||
const { startAt, endAt, event } = query;
|
||||
|
||||
const auth = await checkAuth(request);
|
||||
|
||||
if (!auth || !(await canViewWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const startDate = new Date(+startAt);
|
||||
const endDate = new Date(+endAt);
|
||||
|
||||
const data = await getEventDataEvents(websiteId, {
|
||||
startDate,
|
||||
endDate,
|
||||
event,
|
||||
});
|
||||
|
||||
return json(data);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import { z } from 'zod';
|
||||
import { checkRequest } from 'lib/request';
|
||||
import { badRequest, unauthorized, json } from 'lib/response';
|
||||
import { canViewWebsite, checkAuth } from 'lib/auth';
|
||||
import { getEventDataFields } from 'queries';
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string }> },
|
||||
) {
|
||||
const schema = z.object({
|
||||
startAt: z.coerce.number().int(),
|
||||
endAt: z.coerce.number().int(),
|
||||
});
|
||||
|
||||
const { query, error } = await checkRequest(request, schema);
|
||||
|
||||
if (error) {
|
||||
return badRequest(error);
|
||||
}
|
||||
|
||||
const { websiteId } = await params;
|
||||
const { startAt, endAt } = query;
|
||||
|
||||
const auth = await checkAuth(request);
|
||||
|
||||
if (!(await canViewWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const startDate = new Date(+startAt);
|
||||
const endDate = new Date(+endAt);
|
||||
|
||||
const data = await getEventDataFields(websiteId, {
|
||||
startDate,
|
||||
endDate,
|
||||
});
|
||||
|
||||
return json(data);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import { z } from 'zod';
|
||||
import { checkRequest } from 'lib/request';
|
||||
import { badRequest, unauthorized, json } from 'lib/response';
|
||||
import { canViewWebsite, checkAuth } from 'lib/auth';
|
||||
import { getEventDataProperties } from 'queries';
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string }> },
|
||||
) {
|
||||
const schema = z.object({
|
||||
startAt: z.coerce.number().int(),
|
||||
endAt: z.coerce.number().int(),
|
||||
propertyName: z.string().optional(),
|
||||
});
|
||||
|
||||
const { query, error } = await checkRequest(request, schema);
|
||||
|
||||
if (error) {
|
||||
return badRequest(error);
|
||||
}
|
||||
|
||||
const { websiteId } = await params;
|
||||
const { startAt, endAt, propertyName } = query;
|
||||
|
||||
const auth = await checkAuth(request);
|
||||
|
||||
if (!auth || !(await canViewWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const startDate = new Date(+startAt);
|
||||
const endDate = new Date(+endAt);
|
||||
|
||||
const data = await getEventDataProperties(websiteId, { startDate, endDate, propertyName });
|
||||
|
||||
return json(data);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import { z } from 'zod';
|
||||
import { checkRequest } from 'lib/request';
|
||||
import { badRequest, unauthorized, json } from 'lib/response';
|
||||
import { canViewWebsite, checkAuth } from 'lib/auth';
|
||||
import { getEventDataStats } from 'queries';
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string }> },
|
||||
) {
|
||||
const schema = z.object({
|
||||
startAt: z.coerce.number().int(),
|
||||
endAt: z.coerce.number().int(),
|
||||
propertyName: z.string().optional(),
|
||||
});
|
||||
|
||||
const { query, error } = await checkRequest(request, schema);
|
||||
|
||||
if (error) {
|
||||
return badRequest(error);
|
||||
}
|
||||
|
||||
const { websiteId } = await params;
|
||||
const { startAt, endAt } = query;
|
||||
|
||||
const auth = await checkAuth(request);
|
||||
|
||||
if (!auth || !(await canViewWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const startDate = new Date(+startAt);
|
||||
const endDate = new Date(+endAt);
|
||||
|
||||
const data = await getEventDataStats(websiteId, { startDate, endDate });
|
||||
|
||||
return json(data);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import { z } from 'zod';
|
||||
import { checkRequest } from 'lib/request';
|
||||
import { badRequest, unauthorized, json } from 'lib/response';
|
||||
import { canViewWebsite, checkAuth } from 'lib/auth';
|
||||
import { getEventDataValues } from 'queries';
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string }> },
|
||||
) {
|
||||
const schema = z.object({
|
||||
startAt: z.coerce.number().int(),
|
||||
endAt: z.coerce.number().int(),
|
||||
eventName: z.string().optional(),
|
||||
propertyName: z.string().optional(),
|
||||
});
|
||||
|
||||
const { query, error } = await checkRequest(request, schema);
|
||||
|
||||
if (error) {
|
||||
return badRequest(error);
|
||||
}
|
||||
|
||||
const { websiteId } = await params;
|
||||
const { startAt, endAt, eventName, propertyName } = query;
|
||||
|
||||
const auth = await checkAuth(request);
|
||||
|
||||
if (!auth || !(await canViewWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const startDate = new Date(+startAt);
|
||||
const endDate = new Date(+endAt);
|
||||
|
||||
const data = await getEventDataValues(websiteId, {
|
||||
startDate,
|
||||
endDate,
|
||||
eventName,
|
||||
propertyName,
|
||||
});
|
||||
|
||||
return json(data);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import { z } from 'zod';
|
||||
import { checkRequest } from 'lib/request';
|
||||
import { badRequest, unauthorized, json } from 'lib/response';
|
||||
import { canViewWebsite, checkAuth } from 'lib/auth';
|
||||
import { pagingParams } from 'lib/schema';
|
||||
import { getWebsiteEvents } from 'queries';
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string }> },
|
||||
) {
|
||||
const schema = z.object({
|
||||
startAt: z.coerce.number().int(),
|
||||
endAt: z.coerce.number().int(),
|
||||
...pagingParams,
|
||||
});
|
||||
|
||||
const { query, error } = await checkRequest(request, schema);
|
||||
|
||||
if (error) {
|
||||
return badRequest(error);
|
||||
}
|
||||
|
||||
const { websiteId } = await params;
|
||||
const { startAt, endAt } = query;
|
||||
|
||||
const auth = await checkAuth(request);
|
||||
|
||||
if (!auth || !(await canViewWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const startDate = new Date(+startAt);
|
||||
const endDate = new Date(+endAt);
|
||||
|
||||
const data = await getWebsiteEvents(websiteId, { startDate, endDate }, query);
|
||||
|
||||
return json(data);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import { z } from 'zod';
|
||||
import { checkRequest, getRequestDateRange, getRequestFilters } from 'lib/request';
|
||||
import { badRequest, unauthorized, json } from 'lib/response';
|
||||
import { canViewWebsite, checkAuth } from 'lib/auth';
|
||||
import { filterParams, timezoneParam, unitParam } from 'lib/schema';
|
||||
import { getEventMetrics } from 'queries';
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string }> },
|
||||
) {
|
||||
const schema = z.object({
|
||||
startAt: z.coerce.number().int(),
|
||||
endAt: z.coerce.number().int(),
|
||||
unit: unitParam,
|
||||
timezone: timezoneParam,
|
||||
...filterParams,
|
||||
});
|
||||
|
||||
const { query, error } = await checkRequest(request, schema);
|
||||
|
||||
if (error) {
|
||||
return badRequest(error);
|
||||
}
|
||||
|
||||
const { websiteId } = await params;
|
||||
const { timezone } = query;
|
||||
const { startDate, endDate, unit } = await getRequestDateRange(request);
|
||||
|
||||
const auth = await checkAuth(request);
|
||||
|
||||
if (!auth || !(await canViewWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const filters = {
|
||||
...getRequestFilters(request),
|
||||
startDate,
|
||||
endDate,
|
||||
timezone,
|
||||
unit,
|
||||
};
|
||||
|
||||
const data = await getEventMetrics(websiteId, filters);
|
||||
|
||||
return json(data);
|
||||
}
|
||||
@@ -1,49 +1,36 @@
|
||||
import { z } from 'zod';
|
||||
import { canViewWebsite, checkAuth } from 'lib/auth';
|
||||
import { SESSION_COLUMNS, EVENT_COLUMNS, FILTER_COLUMNS, OPERATORS } from 'lib/constants';
|
||||
import { getRequestFilters, getRequestDateRange, checkRequest } from 'lib/request';
|
||||
import { getPageviewMetrics, getSessionMetrics } from 'queries';
|
||||
|
||||
import { z } from 'zod';
|
||||
import { json, unauthorized, badRequest } from 'lib/response';
|
||||
|
||||
const schema = z.object({
|
||||
type: z.string(),
|
||||
startAt: z.coerce.number(),
|
||||
endAt: z.coerce.number(),
|
||||
// optional
|
||||
url: z.string().optional(),
|
||||
referrer: z.string().optional(),
|
||||
title: z.string().optional(),
|
||||
query: z.string().optional(),
|
||||
host: 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(),
|
||||
language: z.string().optional(),
|
||||
event: z.string().optional(),
|
||||
limit: z.coerce.number().optional(),
|
||||
offset: z.coerce.number().optional(),
|
||||
search: z.string().optional(),
|
||||
tag: z.string().optional(),
|
||||
});
|
||||
import { getPageviewMetrics, getSessionMetrics } from 'queries';
|
||||
import { filterParams } from 'lib/schema';
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string }> },
|
||||
) {
|
||||
const schema = z.object({
|
||||
type: z.string(),
|
||||
startAt: z.coerce.number().int(),
|
||||
endAt: z.coerce.number().int(),
|
||||
limit: z.coerce.number().optional(),
|
||||
offset: z.coerce.number().optional(),
|
||||
search: z.string().optional(),
|
||||
...filterParams,
|
||||
});
|
||||
|
||||
const { query, error } = await checkRequest(request, schema);
|
||||
|
||||
if (error) {
|
||||
return badRequest(error);
|
||||
}
|
||||
|
||||
const auth = await checkAuth(request);
|
||||
const { websiteId } = await params;
|
||||
const { type, limit, offset, search } = query;
|
||||
|
||||
const auth = await checkAuth(request);
|
||||
|
||||
if (!auth || !(await canViewWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
@@ -1,44 +1,35 @@
|
||||
import { z } from 'zod';
|
||||
import { canViewWebsite, checkAuth } from 'lib/auth';
|
||||
import { getRequestFilters, getRequestDateRange, checkRequest } from 'lib/request';
|
||||
import { unit, timezone } from 'lib/schema';
|
||||
import { unitParam, timezoneParam, filterParams } from 'lib/schema';
|
||||
import { getCompareDate } from 'lib/date';
|
||||
import { badRequest, unauthorized, json } from 'lib/response';
|
||||
import { getPageviewStats, getSessionStats } from 'queries';
|
||||
|
||||
const schema = z.object({
|
||||
startAt: z.coerce.number(),
|
||||
endAt: z.coerce.number(),
|
||||
unit,
|
||||
timezone,
|
||||
url: z.string().optional(),
|
||||
referrer: z.string().optional(),
|
||||
title: z.string().optional(),
|
||||
host: 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(),
|
||||
compare: z.string().optional(),
|
||||
});
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string }> },
|
||||
) {
|
||||
const schema = z.object({
|
||||
startAt: z.coerce.number().int(),
|
||||
endAt: z.coerce.number().int(),
|
||||
unit: unitParam,
|
||||
timezone: timezoneParam,
|
||||
compare: z.string().optional(),
|
||||
...filterParams,
|
||||
});
|
||||
|
||||
const { query, error } = await checkRequest(request, schema);
|
||||
|
||||
if (error) {
|
||||
return badRequest(error);
|
||||
}
|
||||
|
||||
const auth = await checkAuth(request);
|
||||
const { websiteId } = await params;
|
||||
const { timezone, compare } = query;
|
||||
|
||||
const auth = await checkAuth(request);
|
||||
|
||||
if (!auth || !(await canViewWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
@@ -5,24 +5,25 @@ import { pagingParams } from 'lib/schema';
|
||||
import { checkRequest } from 'lib/request';
|
||||
import { badRequest, unauthorized, json } from 'lib/response';
|
||||
|
||||
const schema = z.object({
|
||||
...pagingParams,
|
||||
});
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string }> },
|
||||
) {
|
||||
const schema = z.object({
|
||||
...pagingParams,
|
||||
});
|
||||
|
||||
const { query, error } = await checkRequest(request, schema);
|
||||
|
||||
if (error) {
|
||||
return badRequest(error);
|
||||
}
|
||||
|
||||
const auth = await checkAuth(request);
|
||||
const { websiteId } = await params;
|
||||
const { page, pageSize, search } = query;
|
||||
|
||||
const auth = await checkAuth(request);
|
||||
|
||||
if (!auth || !(await canViewWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
@@ -6,9 +6,10 @@ export async function POST(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string }> },
|
||||
) {
|
||||
const auth = await checkAuth(request);
|
||||
const { websiteId } = await params;
|
||||
|
||||
const auth = await checkAuth(request);
|
||||
|
||||
if (!auth || !(await canUpdateWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
@@ -9,15 +9,11 @@ export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string }> },
|
||||
) {
|
||||
const auth = await checkAuth(request);
|
||||
|
||||
if (!auth) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const { websiteId } = await params;
|
||||
|
||||
if (!(await canViewWebsite(auth, websiteId))) {
|
||||
const auth = await checkAuth(request);
|
||||
|
||||
if (!auth || !(await canViewWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
@@ -42,10 +38,11 @@ export async function POST(
|
||||
return badRequest(error);
|
||||
}
|
||||
|
||||
const auth = await checkAuth(request);
|
||||
const { websiteId } = await params;
|
||||
const { name, domain, shareId } = body;
|
||||
|
||||
const auth = await checkAuth(request);
|
||||
|
||||
if (!auth || !(await canUpdateWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
@@ -67,15 +64,11 @@ export async function DELETE(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string }> },
|
||||
) {
|
||||
const auth = await checkAuth(request);
|
||||
|
||||
if (!auth) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const { websiteId } = await params;
|
||||
|
||||
if (!(await canDeleteWebsite(auth, websiteId))) {
|
||||
const auth = await checkAuth(request);
|
||||
|
||||
if (!auth || !(await canDeleteWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { z } from 'zod';
|
||||
import { checkRequest } from 'lib/request';
|
||||
import { badRequest, unauthorized, json } from 'lib/response';
|
||||
import { canViewWebsite, checkAuth } from 'lib/auth';
|
||||
import { getSessionDataProperties } from 'queries';
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string }> },
|
||||
) {
|
||||
const schema = z.object({
|
||||
startAt: z.coerce.number().int(),
|
||||
endAt: z.coerce.number().int(),
|
||||
propertyName: z.string().optional(),
|
||||
});
|
||||
|
||||
const { query, error } = await checkRequest(request, schema);
|
||||
|
||||
if (error) {
|
||||
return badRequest(error);
|
||||
}
|
||||
|
||||
const { startAt, endAt, propertyName } = query;
|
||||
const { websiteId } = await params;
|
||||
|
||||
const auth = await checkAuth(request);
|
||||
|
||||
if (!auth || !(await canViewWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const startDate = new Date(+startAt);
|
||||
const endDate = new Date(+endAt);
|
||||
|
||||
const data = await getSessionDataProperties(websiteId, { startDate, endDate, propertyName });
|
||||
|
||||
return json(data);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import { z } from 'zod';
|
||||
import { checkRequest } from 'lib/request';
|
||||
import { badRequest, unauthorized, json } from 'lib/response';
|
||||
import { canViewWebsite, checkAuth } from 'lib/auth';
|
||||
import { getEventDataEvents } from 'queries/analytics/events/getEventDataEvents';
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string }> },
|
||||
) {
|
||||
const schema = z.object({
|
||||
startAt: z.coerce.number().int(),
|
||||
endAt: z.coerce.number().int(),
|
||||
propertyName: z.string().optional(),
|
||||
});
|
||||
|
||||
const { query, error } = await checkRequest(request, schema);
|
||||
|
||||
if (error) {
|
||||
return badRequest(error);
|
||||
}
|
||||
|
||||
const { startAt, endAt, event } = query;
|
||||
const { websiteId } = await params;
|
||||
|
||||
const auth = await checkAuth(request);
|
||||
|
||||
if (!auth || !(await canViewWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const startDate = new Date(+startAt);
|
||||
const endDate = new Date(+endAt);
|
||||
|
||||
const data = await getEventDataEvents(websiteId, {
|
||||
startDate,
|
||||
endDate,
|
||||
event,
|
||||
});
|
||||
|
||||
return json(data);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import { z } from 'zod';
|
||||
import { checkRequest } from 'lib/request';
|
||||
import { badRequest, unauthorized, json } from 'lib/response';
|
||||
import { canViewWebsite, checkAuth } from 'lib/auth';
|
||||
import { getSessionActivity } from 'queries';
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string; sessionId: string }> },
|
||||
) {
|
||||
const schema = z.object({
|
||||
startAt: z.coerce.number().int(),
|
||||
endAt: z.coerce.number().int(),
|
||||
});
|
||||
|
||||
const { query, error } = await checkRequest(request, schema);
|
||||
|
||||
if (error) {
|
||||
return badRequest(error);
|
||||
}
|
||||
|
||||
const { websiteId, sessionId } = await params;
|
||||
const { startAt, endAt } = query;
|
||||
|
||||
const auth = await checkAuth(request);
|
||||
|
||||
if (!auth || !(await canViewWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const startDate = new Date(+startAt);
|
||||
const endDate = new Date(+endAt);
|
||||
|
||||
const data = await getSessionActivity(websiteId, sessionId, startDate, endDate);
|
||||
|
||||
return json(data);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { unauthorized, json } from 'lib/response';
|
||||
import { canViewWebsite, checkAuth } from 'lib/auth';
|
||||
import { getSessionData } from 'queries';
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string; sessionId: string }> },
|
||||
) {
|
||||
const { websiteId, sessionId } = await params;
|
||||
|
||||
const auth = await checkAuth(request);
|
||||
|
||||
if (!auth || !(await canViewWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const data = await getSessionData(websiteId, sessionId);
|
||||
|
||||
return json(data);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { unauthorized, json } from 'lib/response';
|
||||
import { canViewWebsite, checkAuth } from 'lib/auth';
|
||||
import { getWebsiteSession } from 'queries';
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string; sessionId: string }> },
|
||||
) {
|
||||
const { websiteId, sessionId } = await params;
|
||||
|
||||
const auth = await checkAuth(request);
|
||||
|
||||
if (!auth || !(await canViewWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const data = await getWebsiteSession(websiteId, sessionId);
|
||||
|
||||
return json(data);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import { z } from 'zod';
|
||||
import { checkRequest } from 'lib/request';
|
||||
import { badRequest, unauthorized, json } from 'lib/response';
|
||||
import { canViewWebsite, checkAuth } from 'lib/auth';
|
||||
import { pagingParams } from 'lib/schema';
|
||||
import { getWebsiteSessions } from 'queries';
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string }> },
|
||||
) {
|
||||
const schema = z.object({
|
||||
startAt: z.coerce.number().int(),
|
||||
endAt: z.coerce.number().int(),
|
||||
...pagingParams,
|
||||
});
|
||||
|
||||
const { query, error } = await checkRequest(request, schema);
|
||||
|
||||
if (error) {
|
||||
return badRequest(error);
|
||||
}
|
||||
|
||||
const { websiteId } = await params;
|
||||
const { startAt, endAt } = query;
|
||||
|
||||
const auth = await checkAuth(request);
|
||||
|
||||
if (!auth || !(await canViewWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const startDate = new Date(+startAt);
|
||||
const endDate = new Date(+endAt);
|
||||
|
||||
const data = await getWebsiteSessions(websiteId, { startDate, endDate }, query);
|
||||
|
||||
return json(data);
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import { z } from 'zod';
|
||||
import { checkRequest, getRequestDateRange, getRequestFilters } from 'lib/request';
|
||||
import { badRequest, unauthorized, json } from 'lib/response';
|
||||
import { canViewWebsite, checkAuth } from 'lib/auth';
|
||||
import { filterParams } from 'lib/schema';
|
||||
import { getWebsiteSessionStats } from 'queries';
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string }> },
|
||||
) {
|
||||
const schema = z.object({
|
||||
startAt: z.coerce.number().int(),
|
||||
endAt: z.coerce.number().int(),
|
||||
...filterParams,
|
||||
});
|
||||
|
||||
const { error } = await checkRequest(request, schema);
|
||||
|
||||
if (error) {
|
||||
return badRequest(error);
|
||||
}
|
||||
|
||||
const { websiteId } = await params;
|
||||
|
||||
const auth = await checkAuth(request);
|
||||
|
||||
if (!auth || !(await canViewWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const { startDate, endDate } = await getRequestDateRange(request);
|
||||
|
||||
const filters = getRequestFilters(request);
|
||||
|
||||
const metrics = await getWebsiteSessionStats(websiteId, {
|
||||
...filters,
|
||||
startDate,
|
||||
endDate,
|
||||
});
|
||||
|
||||
const data = Object.keys(metrics[0]).reduce((obj, key) => {
|
||||
obj[key] = {
|
||||
value: Number(metrics[0][key]) || 0,
|
||||
};
|
||||
return obj;
|
||||
}, {});
|
||||
|
||||
return json(data);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import { z } from 'zod';
|
||||
import { checkRequest } from 'lib/request';
|
||||
import { badRequest, unauthorized, json } from 'lib/response';
|
||||
import { canViewWebsite, checkAuth } from 'lib/auth';
|
||||
import { pagingParams, timezoneParam } from 'lib/schema';
|
||||
import { getWebsiteSessionsWeekly } from 'queries';
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string }> },
|
||||
) {
|
||||
const schema = z.object({
|
||||
startAt: z.coerce.number().int(),
|
||||
endAt: z.coerce.number().int(),
|
||||
timezone: timezoneParam,
|
||||
...pagingParams,
|
||||
});
|
||||
|
||||
const { query, error } = await checkRequest(request, schema);
|
||||
|
||||
if (error) {
|
||||
return badRequest(error);
|
||||
}
|
||||
|
||||
const { websiteId } = await params;
|
||||
const { startAt, endAt, timezone } = query;
|
||||
|
||||
const auth = await checkAuth(request);
|
||||
|
||||
if (!auth || !(await canViewWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const startDate = new Date(+startAt);
|
||||
const endDate = new Date(+endAt);
|
||||
|
||||
const data = await getWebsiteSessionsWeekly(websiteId, { startDate, endDate, timezone });
|
||||
|
||||
return json(data);
|
||||
}
|
||||
@@ -3,42 +3,31 @@ import { checkRequest, getRequestDateRange, getRequestFilters } from 'lib/reques
|
||||
import { badRequest, unauthorized, json } from 'lib/response';
|
||||
import { checkAuth, canViewWebsite } from 'lib/auth';
|
||||
import { getCompareDate } from 'lib/date';
|
||||
import { filterParams } from 'lib/schema';
|
||||
import { getWebsiteStats } from 'queries';
|
||||
|
||||
const schema = z.object({
|
||||
startAt: z.coerce.number(),
|
||||
endAt: z.coerce.number(),
|
||||
// optional
|
||||
url: z.string().optional(),
|
||||
referrer: z.string().optional(),
|
||||
title: z.string().optional(),
|
||||
query: z.string().optional(),
|
||||
event: z.string().optional(),
|
||||
host: 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(),
|
||||
compare: z.string().optional(),
|
||||
});
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string }> },
|
||||
) {
|
||||
const schema = z.object({
|
||||
startAt: z.coerce.number().int(),
|
||||
endAt: z.coerce.number().int(),
|
||||
compare: z.string().optional(),
|
||||
...filterParams,
|
||||
});
|
||||
|
||||
const { query, error } = await checkRequest(request, schema);
|
||||
|
||||
if (error) {
|
||||
return badRequest(error);
|
||||
}
|
||||
|
||||
const auth = await checkAuth(request);
|
||||
const { websiteId } = await params;
|
||||
const { compare } = query;
|
||||
|
||||
const auth = await checkAuth(request);
|
||||
|
||||
if (!auth || !(await canViewWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
@@ -4,25 +4,26 @@ import { updateWebsite } from 'queries';
|
||||
import { checkRequest } from 'lib/request';
|
||||
import { badRequest, unauthorized, json } from 'lib/response';
|
||||
|
||||
const schema = z.object({
|
||||
userId: z.string().uuid().optional(),
|
||||
teamId: z.string().uuid().optional(),
|
||||
});
|
||||
|
||||
export async function POST(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string }> },
|
||||
) {
|
||||
const schema = z.object({
|
||||
userId: z.string().uuid().optional(),
|
||||
teamId: z.string().uuid().optional(),
|
||||
});
|
||||
|
||||
const { body, error } = await checkRequest(request, schema);
|
||||
|
||||
if (error) {
|
||||
return badRequest(error);
|
||||
}
|
||||
|
||||
const auth = await checkAuth(request);
|
||||
const { websiteId } = await params;
|
||||
const { userId, teamId } = body;
|
||||
|
||||
const auth = await checkAuth(request);
|
||||
|
||||
if (!auth) {
|
||||
return unauthorized();
|
||||
} else if (userId) {
|
||||
|
||||
@@ -5,28 +5,29 @@ import { getValues } from 'queries';
|
||||
import { checkRequest, getRequestDateRange } from 'lib/request';
|
||||
import { badRequest, json, unauthorized } from 'lib/response';
|
||||
|
||||
const schema = z.object({
|
||||
type: z.string(),
|
||||
startAt: z.coerce.number(),
|
||||
endAt: z.coerce.number(),
|
||||
search: z.string().optional(),
|
||||
});
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string }> },
|
||||
) {
|
||||
const schema = z.object({
|
||||
type: z.string(),
|
||||
startAt: z.coerce.number().int(),
|
||||
endAt: z.coerce.number().int(),
|
||||
search: z.string().optional(),
|
||||
});
|
||||
|
||||
const { query, error } = await checkRequest(request, schema);
|
||||
|
||||
if (error) {
|
||||
return badRequest(error);
|
||||
}
|
||||
|
||||
const auth = await checkAuth(request);
|
||||
const { websiteId } = await params;
|
||||
const { type, search } = query;
|
||||
const { startDate, endDate } = await getRequestDateRange(request);
|
||||
|
||||
const auth = await checkAuth(request);
|
||||
|
||||
if (!auth || !(await canViewWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
+19
-2
@@ -22,10 +22,27 @@ export const pagingParams = {
|
||||
query: z.string().optional(),
|
||||
};
|
||||
|
||||
export const timezone = z.string().refine(value => isValidTimezone(value), {
|
||||
export const timezoneParam = z.string().refine(value => isValidTimezone(value), {
|
||||
message: 'Invalid timezone',
|
||||
});
|
||||
|
||||
export const unit = z.string().refine(value => UNIT_TYPES.includes(value), {
|
||||
export const unitParam = z.string().refine(value => UNIT_TYPES.includes(value), {
|
||||
message: 'Invalid unit',
|
||||
});
|
||||
|
||||
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(),
|
||||
};
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -27,6 +27,7 @@ export * from './analytics/sessions/getSessionDataProperties';
|
||||
export * from './analytics/sessions/getSessionDataValues';
|
||||
export * from './analytics/sessions/getSessionMetrics';
|
||||
export * from './analytics/sessions/getWebsiteSessions';
|
||||
export * from './analytics/sessions/getWebsiteSessionStats';
|
||||
export * from './analytics/sessions/getWebsiteSessionsWeekly';
|
||||
export * from './analytics/sessions/getSessionActivity';
|
||||
export * from './analytics/sessions/getSessionStats';
|
||||
|
||||
Reference in new issue
Block a user