|
@@ -0,0 +1,138 @@
|
|
|
+import { EVENTTYPES, HTTP_CODE, USERTYPES } from '../helper/enum';
|
|
|
+
|
|
|
+//定义排除类型:将U从T中剔除, keyof 会取出T与U的所有键, 限定P的取值范围为T中的所有键, 并将其类型设为可选的never
|
|
|
+//示例1 type obj = { [P in "a" | "b" | "c"]?: string }; ==> obj = {a?:string;b:string;c:string}
|
|
|
+//示例2 type A = type P = Exclude<"a" | "b" | "c" | "d", "b" | "c"> // "a" | "d"
|
|
|
+
|
|
|
+export type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never };
|
|
|
+
|
|
|
+//定义互斥类型,T或U只有一个能出现(互相剔除时,被剔除方必须存在)
|
|
|
+//type A = {name: string;}; type B = {title: string;}; type AOrB = XOR<A, B>;
|
|
|
+export type XOR<T, U> = (Without<T, U> & U) | (Without<U, T> & T);
|
|
|
+
|
|
|
+//取交集
|
|
|
+export type Intersection<T, U> = Pick<T, Extract<keyof T, keyof U> & Extract<keyof U, keyof T>>;
|
|
|
+
|
|
|
+//取差集
|
|
|
+export type Diff<T extends object, U extends object> = Pick<T, Exclude<keyof T, keyof U>>;
|
|
|
+
|
|
|
+//取并集
|
|
|
+type Compute<A extends any> = A extends Function ? A : { [K in keyof A]: A[K] };
|
|
|
+export type Merge<O1 extends object, O2 extends object> = Compute<O1 & Omit<O2, keyof O1>>;
|
|
|
+
|
|
|
+export interface RouteHistory {
|
|
|
+ from: string;
|
|
|
+ to: string;
|
|
|
+}
|
|
|
+
|
|
|
+export interface BreadcrumbData {
|
|
|
+ type: EVENTTYPES; // 事件类型
|
|
|
+ category: USERTYPES; // 用户行为类型
|
|
|
+ status: HTTP_CODE; // 行为状态
|
|
|
+ time: number; // 发生时间
|
|
|
+ data: any;
|
|
|
+}
|
|
|
+
|
|
|
+// http请求
|
|
|
+export interface HttpData {
|
|
|
+ type?: string; //类型
|
|
|
+ method?: string; //方法
|
|
|
+ time: number; //请求时间
|
|
|
+ url: string; // 接口地址
|
|
|
+ elapsedTime: number; // 接口时长
|
|
|
+ message: string; // 接口信息
|
|
|
+ status?: number | string; // 接口状态编码
|
|
|
+ requestData?: {
|
|
|
+ httpType: string; // 请求类型 xhr fetch
|
|
|
+ method: string; // 请求方式
|
|
|
+ data: any;
|
|
|
+ };
|
|
|
+ response?: {
|
|
|
+ status: number | string; // 接口状态
|
|
|
+ };
|
|
|
+}
|
|
|
+
|
|
|
+//资源加载失败
|
|
|
+export interface ResouceError {
|
|
|
+ time: number;
|
|
|
+ message: string; // 加载失败的信息
|
|
|
+ name: string; // 脚本类型:js脚本
|
|
|
+}
|
|
|
+
|
|
|
+//性能指标
|
|
|
+export interface PerformanceData {
|
|
|
+ name: string; // FCP
|
|
|
+ value: number; // 数值
|
|
|
+ rating: string; // 等级
|
|
|
+}
|
|
|
+
|
|
|
+//内存占用信息
|
|
|
+export interface MemoryData {
|
|
|
+ name: string; // memory
|
|
|
+ memory: {
|
|
|
+ jsHeapSizeLimit: number;
|
|
|
+ totalJSHeapSize: number;
|
|
|
+ usedJSHeapSize: number;
|
|
|
+ };
|
|
|
+}
|
|
|
+
|
|
|
+//代码错误
|
|
|
+export interface CodeError {
|
|
|
+ column: number;
|
|
|
+ line: number;
|
|
|
+ message: string;
|
|
|
+ fileName: string; // 发出错误的文件
|
|
|
+}
|
|
|
+
|
|
|
+//用户行为
|
|
|
+export interface Behavior {
|
|
|
+ type: EVENTTYPES;
|
|
|
+ category: any;
|
|
|
+ status: HTTP_CODE;
|
|
|
+ time: number;
|
|
|
+ data: XOR<HttpData, XOR<CodeError, RouteHistory>>;
|
|
|
+ message: string;
|
|
|
+ name?: string;
|
|
|
+}
|
|
|
+
|
|
|
+//常任务查询
|
|
|
+export interface LongTask {
|
|
|
+ time: number;
|
|
|
+ name: string; // longTask
|
|
|
+ longTask: any; // 长任务详情
|
|
|
+}
|
|
|
+
|
|
|
+//录屏信息
|
|
|
+export interface RecordScreen {
|
|
|
+ recordScreenId: string; // 录屏id
|
|
|
+ events: string; // 录屏内容
|
|
|
+}
|
|
|
+
|
|
|
+export interface ReportData
|
|
|
+ extends HttpData,
|
|
|
+ ResouceError,
|
|
|
+ LongTask,
|
|
|
+ PerformanceData,
|
|
|
+ MemoryData,
|
|
|
+ CodeError,
|
|
|
+ RecordScreen {
|
|
|
+ type: string; // 事件类型
|
|
|
+ pageUrl: string; // 页面地址
|
|
|
+ time: number; // 发生时间
|
|
|
+ uuid: string; // 页面唯一标识
|
|
|
+ apikey: string; // 项目id
|
|
|
+ status: string; // 事件状态
|
|
|
+ sdkVersion: string; // 版本信息
|
|
|
+ breadcrumb?: BreadcrumbData[]; // 用户行为
|
|
|
+
|
|
|
+ // 设备信息
|
|
|
+ deviceInfo: {
|
|
|
+ browserVersion: string | number; // 版本号
|
|
|
+ browser: string; // Chrome
|
|
|
+ osVersion: string | number; // 电脑系统 10
|
|
|
+ os: string; // 设备系统
|
|
|
+ ua: string; // 设备详情
|
|
|
+ device: string; // 设备种类描述
|
|
|
+ device_type: string; // 设备种类,如pc
|
|
|
+ };
|
|
|
+}
|