2022-12-13 04:45:38 +01:00
|
|
|
import { NextApiRequest } from 'next';
|
2023-08-10 22:26:33 +02:00
|
|
|
import {
|
|
|
|
COLLECTION_TYPE,
|
|
|
|
DATA_TYPE,
|
|
|
|
EVENT_TYPE,
|
|
|
|
KAFKA_TOPIC,
|
2023-08-23 00:37:22 +02:00
|
|
|
PERMISSIONS,
|
2023-08-20 07:23:15 +02:00
|
|
|
REPORT_TYPES,
|
2023-08-10 22:26:33 +02:00
|
|
|
ROLES,
|
|
|
|
} from './constants';
|
2023-08-20 07:23:15 +02:00
|
|
|
import * as yup from 'yup';
|
2023-08-22 00:53:19 +02:00
|
|
|
import { TIME_UNIT } from './date';
|
2024-02-10 04:37:45 +01:00
|
|
|
import { Dispatch, SetStateAction } from 'react';
|
2023-03-03 07:48:30 +01:00
|
|
|
|
|
|
|
type ObjectValues<T> = T[keyof T];
|
|
|
|
|
2023-08-22 00:53:19 +02:00
|
|
|
export type TimeUnit = ObjectValues<typeof TIME_UNIT>;
|
2023-08-23 00:37:22 +02:00
|
|
|
export type Permission = ObjectValues<typeof PERMISSIONS>;
|
2023-08-22 00:53:19 +02:00
|
|
|
|
2023-06-01 06:46:49 +02:00
|
|
|
export type CollectionType = ObjectValues<typeof COLLECTION_TYPE>;
|
|
|
|
export type Role = ObjectValues<typeof ROLES>;
|
|
|
|
export type EventType = ObjectValues<typeof EVENT_TYPE>;
|
2023-07-02 07:02:49 +02:00
|
|
|
export type DynamicDataType = ObjectValues<typeof DATA_TYPE>;
|
2023-06-01 06:46:49 +02:00
|
|
|
export type KafkaTopic = ObjectValues<typeof KAFKA_TOPIC>;
|
2023-08-20 07:23:15 +02:00
|
|
|
export type ReportType = ObjectValues<typeof REPORT_TYPES>;
|
|
|
|
|
2024-04-29 07:45:58 +02:00
|
|
|
export interface PageParams {
|
2023-09-22 09:59:00 +02:00
|
|
|
query?: string;
|
|
|
|
page?: number;
|
|
|
|
pageSize?: number;
|
2023-08-10 22:26:33 +02:00
|
|
|
orderBy?: string;
|
2023-09-27 08:20:29 +02:00
|
|
|
sortDescending?: boolean;
|
2023-08-10 22:26:33 +02:00
|
|
|
}
|
|
|
|
|
2024-04-29 07:45:58 +02:00
|
|
|
export interface PageResult<T> {
|
2023-12-27 23:20:36 +01:00
|
|
|
data: T;
|
2023-08-10 22:26:33 +02:00
|
|
|
count: number;
|
|
|
|
page: number;
|
2023-09-27 08:20:29 +02:00
|
|
|
pageSize: number;
|
2023-08-10 22:26:33 +02:00
|
|
|
orderBy?: string;
|
2023-09-27 08:20:29 +02:00
|
|
|
sortDescending?: boolean;
|
2023-08-10 22:26:33 +02:00
|
|
|
}
|
2023-06-01 06:46:49 +02:00
|
|
|
|
2024-08-07 09:10:25 +02:00
|
|
|
export interface PagedQueryResult<T> {
|
2024-04-29 07:45:58 +02:00
|
|
|
result: PageResult<T>;
|
2024-02-10 04:37:45 +01:00
|
|
|
query: any;
|
2024-04-29 07:45:58 +02:00
|
|
|
params: PageParams;
|
|
|
|
setParams: Dispatch<SetStateAction<T | PageParams>>;
|
2024-02-10 04:37:45 +01:00
|
|
|
}
|
|
|
|
|
2023-06-01 06:46:49 +02:00
|
|
|
export interface DynamicData {
|
2024-04-09 09:37:23 +02:00
|
|
|
[key: string]: number | string | number[] | string[];
|
2023-03-23 22:01:15 +01:00
|
|
|
}
|
2023-04-02 02:38:35 +02:00
|
|
|
|
2022-12-13 04:45:38 +01:00
|
|
|
export interface Auth {
|
|
|
|
user?: {
|
|
|
|
id: string;
|
|
|
|
username: string;
|
|
|
|
role: string;
|
|
|
|
isAdmin: boolean;
|
|
|
|
};
|
2023-08-23 00:37:22 +02:00
|
|
|
grant?: Permission[];
|
2022-12-13 20:27:55 +01:00
|
|
|
shareToken?: {
|
|
|
|
websiteId: string;
|
|
|
|
};
|
2022-12-13 04:45:38 +01:00
|
|
|
}
|
|
|
|
|
2023-08-20 07:23:15 +02:00
|
|
|
export interface YupRequest {
|
|
|
|
GET?: yup.ObjectSchema<any>;
|
|
|
|
POST?: yup.ObjectSchema<any>;
|
|
|
|
PUT?: yup.ObjectSchema<any>;
|
|
|
|
DELETE?: yup.ObjectSchema<any>;
|
|
|
|
}
|
|
|
|
|
2022-12-13 04:45:38 +01:00
|
|
|
export interface NextApiRequestQueryBody<TQuery = any, TBody = any> extends NextApiRequest {
|
|
|
|
auth?: Auth;
|
|
|
|
query: TQuery & { [key: string]: string | string[] };
|
|
|
|
body: TBody;
|
|
|
|
headers: any;
|
2023-08-20 07:23:15 +02:00
|
|
|
yup: YupRequest;
|
2022-12-13 04:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface NextApiRequestAuth extends NextApiRequest {
|
|
|
|
auth?: Auth;
|
|
|
|
headers: any;
|
|
|
|
}
|
|
|
|
|
2023-02-28 05:03:04 +01:00
|
|
|
export interface User {
|
|
|
|
id: string;
|
|
|
|
username: string;
|
|
|
|
password?: string;
|
2023-04-13 21:08:53 +02:00
|
|
|
role: string;
|
2023-02-28 05:03:04 +01:00
|
|
|
createdAt?: Date;
|
|
|
|
}
|
|
|
|
|
2022-12-13 04:45:38 +01:00
|
|
|
export interface Website {
|
|
|
|
id: string;
|
|
|
|
userId: string;
|
2023-03-27 20:25:16 +02:00
|
|
|
resetAt: Date;
|
2022-12-13 04:45:38 +01:00
|
|
|
name: string;
|
|
|
|
domain: string;
|
|
|
|
shareId: string;
|
|
|
|
createdAt: Date;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface Share {
|
|
|
|
id: string;
|
|
|
|
token: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface WebsiteActive {
|
|
|
|
x: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface WebsiteMetric {
|
|
|
|
x: string;
|
|
|
|
y: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface WebsiteEventMetric {
|
|
|
|
x: string;
|
|
|
|
t: string;
|
|
|
|
y: number;
|
|
|
|
}
|
|
|
|
|
2023-08-16 17:49:22 +02:00
|
|
|
export interface WebsiteEventData {
|
|
|
|
eventName?: string;
|
2024-08-09 10:09:54 +02:00
|
|
|
propertyName: string;
|
2023-08-07 22:28:32 +02:00
|
|
|
dataType: number;
|
2024-08-09 10:09:54 +02:00
|
|
|
propertyValue?: string;
|
2023-07-12 03:52:52 +02:00
|
|
|
total: number;
|
2023-03-23 22:01:15 +01:00
|
|
|
}
|
|
|
|
|
2022-12-13 04:45:38 +01:00
|
|
|
export interface WebsitePageviews {
|
|
|
|
pageviews: {
|
|
|
|
t: string;
|
|
|
|
y: number;
|
|
|
|
};
|
|
|
|
sessions: {
|
|
|
|
t: string;
|
|
|
|
y: number;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface WebsiteStats {
|
|
|
|
pageviews: { value: number; change: number };
|
|
|
|
uniques: { value: number; change: number };
|
|
|
|
bounces: { value: number; change: number };
|
|
|
|
totalTime: { value: number; change: number };
|
|
|
|
}
|
|
|
|
|
2023-07-26 22:42:55 +02:00
|
|
|
export interface DateRange {
|
2024-01-30 22:46:16 +01:00
|
|
|
value: string;
|
2023-07-26 22:42:55 +02:00
|
|
|
startDate: Date;
|
|
|
|
endDate: Date;
|
2023-08-22 00:53:19 +02:00
|
|
|
unit?: TimeUnit;
|
2024-01-30 22:46:16 +01:00
|
|
|
num?: number;
|
|
|
|
offset?: number;
|
2023-07-26 22:42:55 +02:00
|
|
|
}
|
2023-08-04 22:18:30 +02:00
|
|
|
|
|
|
|
export interface QueryFilters {
|
|
|
|
startDate?: Date;
|
|
|
|
endDate?: Date;
|
|
|
|
timezone?: string;
|
|
|
|
unit?: string;
|
|
|
|
eventType?: number;
|
|
|
|
url?: string;
|
|
|
|
referrer?: string;
|
|
|
|
title?: string;
|
|
|
|
query?: string;
|
2024-06-19 18:50:39 +02:00
|
|
|
host?: string;
|
2023-08-04 22:18:30 +02:00
|
|
|
os?: string;
|
|
|
|
browser?: string;
|
|
|
|
device?: string;
|
|
|
|
country?: string;
|
|
|
|
region?: string;
|
|
|
|
city?: string;
|
|
|
|
language?: string;
|
2023-08-07 21:43:43 +02:00
|
|
|
event?: string;
|
2024-03-05 09:45:55 +01:00
|
|
|
search?: string;
|
2023-08-04 22:18:30 +02:00
|
|
|
}
|
2023-08-04 23:23:03 +02:00
|
|
|
|
|
|
|
export interface QueryOptions {
|
|
|
|
joinSession?: boolean;
|
2023-08-07 22:28:32 +02:00
|
|
|
columns?: { [key: string]: string };
|
2023-12-13 04:00:44 +01:00
|
|
|
limit?: number;
|
2023-08-04 23:23:03 +02:00
|
|
|
}
|
2023-12-09 09:35:54 +01:00
|
|
|
|
|
|
|
export interface RealtimeData {
|
2024-06-20 06:47:27 +02:00
|
|
|
countries: { [key: string]: number };
|
2023-12-09 09:35:54 +01:00
|
|
|
events: any[];
|
2024-06-20 06:47:27 +02:00
|
|
|
pageviews: any[];
|
|
|
|
referrers: { [key: string]: number };
|
2023-12-09 09:35:54 +01:00
|
|
|
timestamp: number;
|
2024-06-20 06:47:27 +02:00
|
|
|
series: {
|
|
|
|
views: any[];
|
|
|
|
visitors: any[];
|
|
|
|
};
|
|
|
|
totals: {
|
|
|
|
views: number;
|
|
|
|
visitors: number;
|
|
|
|
events: number;
|
|
|
|
countries: number;
|
|
|
|
};
|
|
|
|
urls: { [key: string]: number };
|
|
|
|
visitors: any[];
|
2023-12-09 09:35:54 +01:00
|
|
|
}
|
2024-04-18 23:23:14 +02:00
|
|
|
|
|
|
|
export interface SessionData {
|
|
|
|
id: string;
|
|
|
|
websiteId: string;
|
|
|
|
visitId: string;
|
|
|
|
hostname: string;
|
|
|
|
browser: string;
|
|
|
|
os: string;
|
|
|
|
device: string;
|
|
|
|
screen: string;
|
|
|
|
language: string;
|
|
|
|
country: string;
|
|
|
|
subdivision1: string;
|
|
|
|
subdivision2: string;
|
|
|
|
city: string;
|
|
|
|
}
|