Merge branch 'dev' into session-recording
This commit is contained in:
commit
d349c3aea9
381 files changed
+24834
-139358
No files matched your search
@@ -0,0 +1,64 @@
|
||||
import { z } from 'zod';
|
||||
import { uuid } from '@/lib/crypto';
|
||||
import { parseRequest } from '@/lib/request';
|
||||
import { json, unauthorized } from '@/lib/response';
|
||||
import { createBoard, getBoard, updateBoard } from '@/queries/prisma';
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const { auth, error } = await parseRequest(request);
|
||||
|
||||
if (error) {
|
||||
return error();
|
||||
}
|
||||
|
||||
const board = await getBoard(auth.user.id);
|
||||
|
||||
if (board && board.userId !== auth.user.id) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
return json(board);
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const schema = z.object({
|
||||
name: z.string().optional(),
|
||||
description: z.string().optional(),
|
||||
parameters: z.object({}).passthrough().optional(),
|
||||
});
|
||||
|
||||
const { auth, body, error } = await parseRequest(request, schema);
|
||||
|
||||
if (error) {
|
||||
return error();
|
||||
}
|
||||
|
||||
const userId = auth.user.id;
|
||||
const existing = await getBoard(userId);
|
||||
|
||||
if (existing && existing.userId !== userId) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const data = {
|
||||
name: body.name,
|
||||
description: body.description,
|
||||
parameters: body.parameters ?? {},
|
||||
};
|
||||
|
||||
if (existing) {
|
||||
const result = await updateBoard(userId, data);
|
||||
|
||||
return json(result);
|
||||
}
|
||||
|
||||
const result = await createBoard({
|
||||
id: userId,
|
||||
type: 'dashboard',
|
||||
slug: uuid(),
|
||||
userId,
|
||||
...data,
|
||||
});
|
||||
|
||||
return json(result);
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
import { z } from 'zod';
|
||||
import { getQueryFilters, parseRequest } from '@/lib/request';
|
||||
import { json, unauthorized } from '@/lib/response';
|
||||
import { dateRangeParams, filterParams } from '@/lib/schema';
|
||||
import { filterParams, withDateRange } from '@/lib/schema';
|
||||
import { canViewWebsite } from '@/permissions';
|
||||
import { getWebsiteEventStats } from '@/queries/sql/events/getWebsiteEventStats';
|
||||
|
||||
@@ -9,8 +8,7 @@ export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string }> },
|
||||
) {
|
||||
const schema = z.object({
|
||||
...dateRangeParams,
|
||||
const schema = withDateRange({
|
||||
...filterParams,
|
||||
});
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import JSZip from 'jszip';
|
||||
import Papa from 'papaparse';
|
||||
import { z } from 'zod';
|
||||
import { getQueryFilters, parseRequest } from '@/lib/request';
|
||||
import { json, unauthorized } from '@/lib/response';
|
||||
import { dateRangeParams, pagingParams } from '@/lib/schema';
|
||||
import { pagingParams, withDateRange } from '@/lib/schema';
|
||||
import { canViewWebsite } from '@/permissions';
|
||||
import { getEventMetrics, getPageviewMetrics, getSessionMetrics } from '@/queries/sql';
|
||||
|
||||
@@ -11,8 +10,7 @@ export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string }> },
|
||||
) {
|
||||
const schema = z.object({
|
||||
...dateRangeParams,
|
||||
const schema = withDateRange({
|
||||
...pagingParams,
|
||||
});
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import { z } from 'zod';
|
||||
import { EVENT_COLUMNS, EVENT_TYPE, SESSION_COLUMNS } from '@/lib/constants';
|
||||
import { getQueryFilters, parseRequest } from '@/lib/request';
|
||||
import { badRequest, json, unauthorized } from '@/lib/response';
|
||||
import { dateRangeParams, filterParams, searchParams } from '@/lib/schema';
|
||||
import { filterParams, searchParams, withDateRange } from '@/lib/schema';
|
||||
import { canViewWebsite } from '@/permissions';
|
||||
import {
|
||||
getChannelExpandedMetrics,
|
||||
@@ -15,11 +15,10 @@ export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string }> },
|
||||
) {
|
||||
const schema = z.object({
|
||||
const schema = withDateRange({
|
||||
type: z.string(),
|
||||
limit: z.coerce.number().optional(),
|
||||
offset: z.coerce.number().optional(),
|
||||
...dateRangeParams,
|
||||
...searchParams,
|
||||
...filterParams,
|
||||
});
|
||||
|
||||
@@ -2,7 +2,7 @@ import { z } from 'zod';
|
||||
import { EVENT_COLUMNS, EVENT_TYPE, SESSION_COLUMNS } from '@/lib/constants';
|
||||
import { getQueryFilters, parseRequest } from '@/lib/request';
|
||||
import { badRequest, json, unauthorized } from '@/lib/response';
|
||||
import { dateRangeParams, filterParams, searchParams } from '@/lib/schema';
|
||||
import { filterParams, searchParams, withDateRange } from '@/lib/schema';
|
||||
import { canViewWebsite } from '@/permissions';
|
||||
import {
|
||||
getChannelMetrics,
|
||||
@@ -15,11 +15,10 @@ export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string }> },
|
||||
) {
|
||||
const schema = z.object({
|
||||
const schema = withDateRange({
|
||||
type: z.string(),
|
||||
limit: z.coerce.number().optional(),
|
||||
offset: z.coerce.number().optional(),
|
||||
...dateRangeParams,
|
||||
...searchParams,
|
||||
...filterParams,
|
||||
});
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { z } from 'zod';
|
||||
import { getCompareDate } from '@/lib/date';
|
||||
import { getQueryFilters, parseRequest } from '@/lib/request';
|
||||
import { json, unauthorized } from '@/lib/response';
|
||||
import { dateRangeParams, filterParams } from '@/lib/schema';
|
||||
import { filterParams, withDateRange } from '@/lib/schema';
|
||||
import { canViewWebsite } from '@/permissions';
|
||||
import { getPageviewStats, getSessionStats } from '@/queries/sql';
|
||||
|
||||
@@ -10,8 +9,7 @@ export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string }> },
|
||||
) {
|
||||
const schema = z.object({
|
||||
...dateRangeParams,
|
||||
const schema = withDateRange({
|
||||
...filterParams,
|
||||
});
|
||||
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
import { z } from 'zod';
|
||||
import { parseRequest } from '@/lib/request';
|
||||
import { json, unauthorized } from '@/lib/response';
|
||||
import { filterParams, pagingParams } from '@/lib/schema';
|
||||
import { pagingParams, reportTypeParam } from '@/lib/schema';
|
||||
import { canViewWebsite } from '@/permissions';
|
||||
import { getReports } from '@/queries/prisma';
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string }> },
|
||||
filters: { type: string },
|
||||
) {
|
||||
const schema = z.object({
|
||||
...filterParams,
|
||||
type: reportTypeParam.optional(),
|
||||
...pagingParams,
|
||||
});
|
||||
|
||||
@@ -22,7 +21,7 @@ export async function GET(
|
||||
}
|
||||
|
||||
const { websiteId } = await params;
|
||||
const { page, pageSize, search } = query;
|
||||
const { type, page, pageSize, search } = query;
|
||||
|
||||
if (!(await canViewWebsite(auth, websiteId))) {
|
||||
return unauthorized();
|
||||
@@ -32,7 +31,7 @@ export async function GET(
|
||||
{
|
||||
where: {
|
||||
websiteId,
|
||||
type: filters.type,
|
||||
type,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { z } from 'zod';
|
||||
import { getQueryFilters, parseRequest } from '@/lib/request';
|
||||
import { json, unauthorized } from '@/lib/response';
|
||||
import { dateRangeParams, filterParams, pagingParams, searchParams } from '@/lib/schema';
|
||||
import { filterParams, pagingParams, searchParams, withDateRange } from '@/lib/schema';
|
||||
import { canViewWebsite } from '@/permissions';
|
||||
import { getWebsiteSessions } from '@/queries/sql';
|
||||
|
||||
@@ -9,8 +8,7 @@ export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string }> },
|
||||
) {
|
||||
const schema = z.object({
|
||||
...dateRangeParams,
|
||||
const schema = withDateRange({
|
||||
...filterParams,
|
||||
...pagingParams,
|
||||
...searchParams,
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { z } from 'zod';
|
||||
import { getCompareDate } from '@/lib/date';
|
||||
import { getQueryFilters, parseRequest } from '@/lib/request';
|
||||
import { json, unauthorized } from '@/lib/response';
|
||||
import { dateRangeParams, filterParams } from '@/lib/schema';
|
||||
import { filterParams, withDateRange } from '@/lib/schema';
|
||||
import { canViewWebsite } from '@/permissions';
|
||||
import { getWebsiteStats } from '@/queries/sql';
|
||||
|
||||
@@ -10,8 +9,7 @@ export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string }> },
|
||||
) {
|
||||
const schema = z.object({
|
||||
...dateRangeParams,
|
||||
const schema = withDateRange({
|
||||
...filterParams,
|
||||
});
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { z } from 'zod';
|
||||
import { EVENT_COLUMNS, FILTER_COLUMNS, SEGMENT_TYPES, SESSION_COLUMNS } from '@/lib/constants';
|
||||
import { getQueryFilters, parseRequest } from '@/lib/request';
|
||||
import { badRequest, json, unauthorized } from '@/lib/response';
|
||||
import { dateRangeParams, fieldsParam, searchParams } from '@/lib/schema';
|
||||
import { fieldsParam, searchParams, withDateRange } from '@/lib/schema';
|
||||
import { canViewWebsite } from '@/permissions';
|
||||
import { getWebsiteSegments } from '@/queries/prisma';
|
||||
import { getValues } from '@/queries/sql';
|
||||
@@ -11,9 +10,8 @@ export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ websiteId: string }> },
|
||||
) {
|
||||
const schema = z.object({
|
||||
const schema = withDateRange({
|
||||
type: fieldsParam,
|
||||
...dateRangeParams,
|
||||
...searchParams,
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user