umami/src/lib/types.ts

210 lines
4.0 KiB
TypeScript
Raw Normal View History

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';
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
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>;
export type KafkaTopic = ObjectValues<typeof KAFKA_TOPIC>;
2023-08-20 07:23:15 +02:00
export type ReportType = ObjectValues<typeof REPORT_TYPES>;
export interface WebsiteSearchFilter extends SearchFilter {
2023-08-10 22:26:33 +02:00
userId?: string;
teamId?: string;
includeTeams?: boolean;
2023-08-14 07:21:49 +02:00
onlyTeams?: boolean;
2023-08-10 22:26:33 +02:00
}
export interface UserSearchFilter extends SearchFilter {
2023-08-10 22:26:33 +02:00
teamId?: string;
}
export interface TeamSearchFilter extends SearchFilter {
2023-08-10 22:26:33 +02:00
userId?: string;
}
export interface ReportSearchFilter extends SearchFilter {
2023-08-10 22:26:33 +02:00
userId?: string;
websiteId?: string;
2023-08-14 07:21:49 +02:00
includeTeams?: boolean;
2023-08-10 22:26:33 +02:00
}
export interface SearchFilter {
2023-09-22 09:59:00 +02:00
query?: string;
page?: number;
pageSize?: number;
2023-08-10 22:26:33 +02:00
orderBy?: string;
sortDescending?: boolean;
2023-08-10 22:26:33 +02:00
}
export interface FilterResult<T> {
data: T;
count: number;
page: number;
pageSize: number;
2023-08-10 22:26:33 +02:00
orderBy?: string;
sortDescending?: boolean;
2023-08-10 22:26:33 +02:00
}
export interface DynamicData {
[key: string]: number | string | DynamicData | number[] | string[] | DynamicData[];
}
2023-04-02 02:38:35 +02: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;
};
}
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>;
}
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;
}
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;
}
export interface Website {
id: string;
userId: string;
resetAt: Date;
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;
fieldName: string;
dataType: number;
fieldValue?: string;
2023-07-12 03:52:52 +02:00
total: number;
}
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;
}
export interface DateRange {
startDate: Date;
endDate: Date;
value: string;
2023-08-22 00:53:19 +02:00
unit?: TimeUnit;
selectedUnit?: TimeUnit;
}
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;
os?: string;
browser?: string;
device?: string;
country?: string;
region?: string;
city?: string;
language?: string;
2023-08-07 21:43:43 +02:00
event?: string;
2023-08-04 22:18:30 +02:00
}
2023-08-04 23:23:03 +02:00
export interface QueryOptions {
joinSession?: boolean;
columns?: { [key: string]: string };
2023-08-04 23:23:03 +02:00
}