2022-12-13 03:45:38 +00:00
|
|
|
import { NextApiRequest } from 'next';
|
2023-08-10 20:26:33 +00:00
|
|
|
import {
|
|
|
|
|
COLLECTION_TYPE,
|
|
|
|
|
DATA_TYPE,
|
|
|
|
|
EVENT_TYPE,
|
|
|
|
|
KAFKA_TOPIC,
|
2023-08-22 22:37:22 +00:00
|
|
|
PERMISSIONS,
|
2023-08-20 05:23:15 +00:00
|
|
|
REPORT_TYPES,
|
2023-08-10 20:26:33 +00:00
|
|
|
ROLES,
|
|
|
|
|
} from './constants';
|
2023-08-20 05:23:15 +00:00
|
|
|
import * as yup from 'yup';
|
2023-08-21 22:53:19 +00:00
|
|
|
import { TIME_UNIT } from './date';
|
2024-02-10 03:37:45 +00:00
|
|
|
import { Dispatch, SetStateAction } from 'react';
|
2023-03-03 06:48:30 +00:00
|
|
|
|
|
|
|
|
type ObjectValues<T> = T[keyof T];
|
|
|
|
|
|
2023-08-21 22:53:19 +00:00
|
|
|
export type TimeUnit = ObjectValues<typeof TIME_UNIT>;
|
2023-08-22 22:37:22 +00:00
|
|
|
export type Permission = ObjectValues<typeof PERMISSIONS>;
|
2023-08-21 22:53:19 +00:00
|
|
|
|
2023-06-01 04:46:49 +00:00
|
|
|
export type CollectionType = ObjectValues<typeof COLLECTION_TYPE>;
|
|
|
|
|
export type Role = ObjectValues<typeof ROLES>;
|
|
|
|
|
export type EventType = ObjectValues<typeof EVENT_TYPE>;
|
2023-07-02 05:02:49 +00:00
|
|
|
export type DynamicDataType = ObjectValues<typeof DATA_TYPE>;
|
2023-06-01 04:46:49 +00:00
|
|
|
export type KafkaTopic = ObjectValues<typeof KAFKA_TOPIC>;
|
2023-08-20 05:23:15 +00:00
|
|
|
export type ReportType = ObjectValues<typeof REPORT_TYPES>;
|
|
|
|
|
|
2023-09-27 06:20:29 +00:00
|
|
|
export interface WebsiteSearchFilter extends SearchFilter {
|
2023-08-10 20:26:33 +00:00
|
|
|
userId?: string;
|
|
|
|
|
teamId?: string;
|
|
|
|
|
includeTeams?: boolean;
|
2023-08-14 05:21:49 +00:00
|
|
|
onlyTeams?: boolean;
|
2023-08-10 20:26:33 +00:00
|
|
|
}
|
|
|
|
|
|
2023-09-27 06:20:29 +00:00
|
|
|
export interface UserSearchFilter extends SearchFilter {
|
2023-08-10 20:26:33 +00:00
|
|
|
teamId?: string;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-27 06:20:29 +00:00
|
|
|
export interface TeamSearchFilter extends SearchFilter {
|
2023-08-10 20:26:33 +00:00
|
|
|
userId?: string;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-30 08:10:25 +00:00
|
|
|
export interface TeamUserSearchFilter extends SearchFilter {
|
|
|
|
|
teamId?: string;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-27 06:20:29 +00:00
|
|
|
export interface ReportSearchFilter extends SearchFilter {
|
2023-08-10 20:26:33 +00:00
|
|
|
userId?: string;
|
|
|
|
|
websiteId?: string;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-27 06:20:29 +00:00
|
|
|
export interface SearchFilter {
|
2023-09-22 07:59:00 +00:00
|
|
|
query?: string;
|
|
|
|
|
page?: number;
|
|
|
|
|
pageSize?: number;
|
2023-08-10 20:26:33 +00:00
|
|
|
orderBy?: string;
|
2023-09-27 06:20:29 +00:00
|
|
|
sortDescending?: boolean;
|
2023-08-10 20:26:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface FilterResult<T> {
|
2023-12-27 22:20:36 +00:00
|
|
|
data: T;
|
2023-08-10 20:26:33 +00:00
|
|
|
count: number;
|
|
|
|
|
page: number;
|
2023-09-27 06:20:29 +00:00
|
|
|
pageSize: number;
|
2023-08-10 20:26:33 +00:00
|
|
|
orderBy?: string;
|
2023-09-27 06:20:29 +00:00
|
|
|
sortDescending?: boolean;
|
2023-08-10 20:26:33 +00:00
|
|
|
}
|
2023-06-01 04:46:49 +00:00
|
|
|
|
2024-02-10 03:37:45 +00:00
|
|
|
export interface FilterQueryResult<T> {
|
|
|
|
|
result: FilterResult<T>;
|
|
|
|
|
query: any;
|
|
|
|
|
params: SearchFilter;
|
|
|
|
|
setParams: Dispatch<SetStateAction<T | SearchFilter>>;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-01 04:46:49 +00:00
|
|
|
export interface DynamicData {
|
2024-04-09 07:37:23 +00:00
|
|
|
[key: string]: number | string | number[] | string[];
|
2023-03-23 21:01:15 +00:00
|
|
|
}
|
2023-04-02 00:38:35 +00:00
|
|
|
|
2022-12-13 03:45:38 +00:00
|
|
|
export interface Auth {
|
|
|
|
|
user?: {
|
|
|
|
|
id: string;
|
|
|
|
|
username: string;
|
|
|
|
|
role: string;
|
|
|
|
|
isAdmin: boolean;
|
|
|
|
|
};
|
2023-08-22 22:37:22 +00:00
|
|
|
grant?: Permission[];
|
2022-12-13 19:27:55 +00:00
|
|
|
shareToken?: {
|
|
|
|
|
websiteId: string;
|
|
|
|
|
};
|
2022-12-13 03:45:38 +00:00
|
|
|
}
|
|
|
|
|
|
2023-08-20 05:23:15 +00:00
|
|
|
export interface YupRequest {
|
|
|
|
|
GET?: yup.ObjectSchema<any>;
|
|
|
|
|
POST?: yup.ObjectSchema<any>;
|
|
|
|
|
PUT?: yup.ObjectSchema<any>;
|
|
|
|
|
DELETE?: yup.ObjectSchema<any>;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-13 03:45:38 +00: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 05:23:15 +00:00
|
|
|
yup: YupRequest;
|
2022-12-13 03:45:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface NextApiRequestAuth extends NextApiRequest {
|
|
|
|
|
auth?: Auth;
|
|
|
|
|
headers: any;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-28 04:03:04 +00:00
|
|
|
export interface User {
|
|
|
|
|
id: string;
|
|
|
|
|
username: string;
|
|
|
|
|
password?: string;
|
2023-04-13 19:08:53 +00:00
|
|
|
role: string;
|
2023-02-28 04:03:04 +00:00
|
|
|
createdAt?: Date;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-13 03:45:38 +00:00
|
|
|
export interface Website {
|
|
|
|
|
id: string;
|
|
|
|
|
userId: string;
|
2023-03-27 18:25:16 +00:00
|
|
|
resetAt: Date;
|
2022-12-13 03:45:38 +00: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 15:49:22 +00:00
|
|
|
export interface WebsiteEventData {
|
|
|
|
|
eventName?: string;
|
2023-08-07 20:28:32 +00:00
|
|
|
fieldName: string;
|
|
|
|
|
dataType: number;
|
|
|
|
|
fieldValue?: string;
|
2023-07-12 01:52:52 +00:00
|
|
|
total: number;
|
2023-03-23 21:01:15 +00:00
|
|
|
}
|
|
|
|
|
|
2022-12-13 03:45:38 +00: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 };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface RealtimeInit {
|
|
|
|
|
websites: Website[];
|
|
|
|
|
token: string;
|
|
|
|
|
data: RealtimeUpdate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface RealtimeUpdate {
|
|
|
|
|
pageviews: any[];
|
|
|
|
|
sessions: any[];
|
|
|
|
|
events: any[];
|
|
|
|
|
timestamp: number;
|
|
|
|
|
}
|
2023-07-26 20:42:55 +00:00
|
|
|
|
|
|
|
|
export interface DateRange {
|
2024-01-30 21:46:16 +00:00
|
|
|
value: string;
|
2023-07-26 20:42:55 +00:00
|
|
|
startDate: Date;
|
|
|
|
|
endDate: Date;
|
2023-08-21 22:53:19 +00:00
|
|
|
unit?: TimeUnit;
|
2024-01-30 21:46:16 +00:00
|
|
|
num?: number;
|
|
|
|
|
offset?: number;
|
2023-07-26 20:42:55 +00:00
|
|
|
}
|
2023-08-04 20:18:30 +00:00
|
|
|
|
|
|
|
|
export interface QueryFilters {
|
|
|
|
|
startDate?: Date;
|
|
|
|
|
endDate?: Date;
|
|
|
|
|
timezone?: string;
|
|
|
|
|
unit?: string;
|
|
|
|
|
eventType?: number;
|
|
|
|
|
url?: string;
|
|
|
|
|
referrer?: string;
|
|
|
|
|
title?: string;
|
|
|
|
|
query?: string;
|
|
|
|
|
os?: string;
|
|
|
|
|
browser?: string;
|
|
|
|
|
device?: string;
|
|
|
|
|
country?: string;
|
|
|
|
|
region?: string;
|
|
|
|
|
city?: string;
|
|
|
|
|
language?: string;
|
2023-08-07 19:43:43 +00:00
|
|
|
event?: string;
|
2024-03-05 08:45:55 +00:00
|
|
|
search?: string;
|
2023-08-04 20:18:30 +00:00
|
|
|
}
|
2023-08-04 21:23:03 +00:00
|
|
|
|
|
|
|
|
export interface QueryOptions {
|
|
|
|
|
joinSession?: boolean;
|
2023-08-07 20:28:32 +00:00
|
|
|
columns?: { [key: string]: string };
|
2023-12-13 03:00:44 +00:00
|
|
|
limit?: number;
|
2023-08-04 21:23:03 +00:00
|
|
|
}
|
2023-12-09 08:35:54 +00:00
|
|
|
|
|
|
|
|
export interface RealtimeData {
|
|
|
|
|
pageviews: any[];
|
|
|
|
|
sessions: any[];
|
|
|
|
|
events: any[];
|
|
|
|
|
timestamp: number;
|
|
|
|
|
countries?: any[];
|
|
|
|
|
visitors?: any[];
|
|
|
|
|
}
|
2024-04-18 21:23:14 +00: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;
|
|
|
|
|
ownerId: string;
|
|
|
|
|
}
|