xbx 2 роки тому
батько
коміт
ff7360ac63
18 змінених файлів з 244 додано та 68 видалено
  1. 0 41
      .prettierrc.js
  2. 9 0
      .prettierrc.json
  3. 0 2
      lib/main.d.ts
  4. 0 8
      lib/main.js
  5. 0 1
      lib/main.js.map
  6. 0 5
      lib/main.ts
  7. 1 1
      package.json
  8. 4 0
      src/config/index.ts
  9. 24 0
      src/global.d.ts
  10. 64 0
      src/helper/enum.ts
  11. 2 0
      src/index.ts
  12. 0 1
      src/main.d.ts
  13. 0 5
      src/main.js
  14. 0 1
      src/main.js.map
  15. 0 3
      src/main.ts
  16. 138 0
      src/types/common.ts
  17. 2 0
      src/types/index.ts
  18. 0 0
      src/types/options

+ 0 - 41
.prettierrc.js

@@ -1,41 +0,0 @@
-module.exports = {
-	// 一行最多多少个字符
-	printWidth: 150,
-	// 指定每个缩进级别的空格数
-	tabWidth: 2,
-	// 使用制表符而不是空格缩进行
-	useTabs: true,
-	// 在语句末尾是否需要分号
-	semi: true,
-	// 是否使用单引号
-	singleQuote: true,
-	// 更改引用对象属性的时间 可选值"<as-needed|consistent|preserve>"
-	quoteProps: 'as-needed',
-	// 在JSX中使用单引号而不是双引号
-	jsxSingleQuote: false,
-	// 多行时尽可能打印尾随逗号。(例如,单行数组永远不会出现逗号结尾。) 可选值"<none|es5|all>",默认none
-	trailingComma: 'es5',
-	// 在对象文字中的括号之间打印空格
-	bracketSpacing: true,
-	// jsx 标签的反尖括号需要换行
-	jsxBracketSameLine: false,
-	// 在单独的箭头函数参数周围包括括号 always:(x) => x \ avoid:x => x
-	arrowParens: 'always',
-	// 这两个选项可用于格式化以给定字符偏移量(分别包括和不包括)开始和结束的代码
-	rangeStart: 0,
-	rangeEnd: Infinity,
-	// 指定要使用的解析器,不需要写文件开头的 @prettier
-	requirePragma: false,
-	// 不需要自动在文件开头插入 @prettier
-	insertPragma: false,
-	// 使用默认的折行标准 always\never\preserve
-	proseWrap: 'preserve',
-	// 指定HTML文件的全局空格敏感度 css\strict\ignore
-	htmlWhitespaceSensitivity: 'css',
-
-	//在 windows 操作系统中换行符通常是回车 (CR) 加换行分隔符 (LF),也就是回车换行(CRLF),
-	//然而在 Linux 和 Unix 中只使用简单的换行分隔符 (LF)。
-	//对应的控制字符为 "\n" (LF) 和 "\r\n"(CRLF)。auto意为保持现有的行尾
-	// 换行符使用 lf 结尾是 可选值"<auto|lf|crlf|cr>"
-	endOfLine: 'auto',
-}; 

+ 9 - 0
.prettierrc.json

@@ -0,0 +1,9 @@
+{
+	"printWidth": 100,
+	"tabWidth": 2,
+	"useTabs": false,
+	"semi": true,
+	"singleQuote": true,
+	"arrowParens": "avoid"
+  }
+  

+ 0 - 2
lib/main.d.ts

@@ -1,2 +0,0 @@
-declare const aaa: (cc: string) => void;
-export { aaa };

+ 0 - 8
lib/main.js

@@ -1,8 +0,0 @@
-"use strict";
-Object.defineProperty(exports, "__esModule", { value: true });
-exports.aaa = void 0;
-var aaa = function (cc) {
-    console.log(cc);
-};
-exports.aaa = aaa;
-//# sourceMappingURL=main.js.map

+ 0 - 1
lib/main.js.map

@@ -1 +0,0 @@
-{"version":3,"file":"main.js","sourceRoot":"","sources":["main.ts"],"names":[],"mappings":";;;AAAA,IAAM,GAAG,GAAG,UAAC,EAAS;IACpB,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAClB,CAAC,CAAC;AAEO,kBAAG"}

+ 0 - 5
lib/main.ts

@@ -1,5 +0,0 @@
-const aaa = (cc:string) => {
-  console.log(cc);
-};
-
-export { aaa };

+ 1 - 1
package.json

@@ -1,7 +1,7 @@
 {
   "name": "zw_monitor",
   "private": true,
-  "version": "0.0.0",
+  "version": "1.0.0",
   "type": "module",
   "files": [
     "dist",

+ 4 - 0
src/config/index.ts

@@ -0,0 +1,4 @@
+import pkg from '../../package.json';
+
+export const SDK_NAME = 'zw-monitor';
+export const SDK_VERSION = pkg.version;

+ 24 - 0
src/global.d.ts

@@ -0,0 +1,24 @@
+declare interface Performance extends Performance {
+    memory?: {
+      jsHeapSizeLimit: number;
+      totalJSHeapSize: number;
+      usedJSHeapSize: number;
+    };
+  }
+  
+  declare module '*.json' {
+    const value: any;
+    export default value;
+  }
+  
+  declare interface Window {
+    chrome?: {
+      app: {
+        [key: string]: any;
+      };
+    };
+    __monitor__: {
+      [key: string]: any;
+    };
+  }
+  

+ 64 - 0
src/helper/enum.ts

@@ -0,0 +1,64 @@
+//接口错误状态
+export enum HttpStatus {
+  SUCCESS = 'success', //成功
+  UNAUTHORIZED = 'unauthorized', //未授权
+  FORBIDDEN = 'forbidden', //禁止请求
+  NOTFOUND = 'notfound', //服务器找不到请求的网页
+  INVALIDARGUMENT = 'invalidargument', //其他4xx错误 代表接口错误
+  INTELNETERROR = 'interneterror', // 5xx代表服务端错误
+  UNIMPLEMENT = 'unimplement', //不具备请求功能
+  BADGATEWAY = 'badgetway', //502网关错误
+  UNAVAILABLE = 'unavailable', //服务不可用
+  OTHERRROR = 'othererror', //其他类型错误
+}
+
+//请求类型
+export enum HTTPTYPE {
+  XHR = 'xhr',
+  FETCH = 'fetch',
+}
+
+//错误码
+export enum HTTP_CODE {
+  BAD_REQUEST = 400,
+  UNAUTHORIZED = 401,
+}
+
+//请求方式
+export enum METHODS {
+  Get = 'GET',
+  Post = 'POST',
+  Put = 'PUT',
+  Delete = 'DELETE',
+}
+
+//所有事件
+export enum EVENTTYPES {
+  XHR = 'xhr', //xhr请求
+  FETCH = 'fetch', //fetch 请求
+  CLICK = 'click', //点击事件
+  HISTORY = 'history', //h5 history事件
+  ERROR = 'error', //错误
+  HASHCHANGE = 'hashchange', //url hash change事件
+  UNHANDLEDREJECTION = 'unhandledrejection', //捕获promise reject
+  RESOURCE = 'resource', //资源加载错误
+  DOM = 'dom', //dom渲染错误
+  VUE = 'vue', //vue 错误
+  REACT = 'react', //react 错误
+  CUSTOM = 'custom', //自定义上报事件
+  PERFORMANCE = 'performance', //浏览器性能指标
+  RECORDSCREEN = 'recordScreen', //录屏
+  WHITESCREEN = 'whiteScreen', //白屏
+}
+
+/**
+ * 用户行为
+ */
+export enum USERTYPES {
+  HTTP = 'http', //发起请求
+  CLICK = 'click', //点击事件
+  RESOURCE = 'resource_Error', //资源加载
+  CODEERROR = 'code_Error', //错误码
+  ROUTE = 'router', //路由跳转
+  CUSTOM = 'custom', //自定义
+}

+ 2 - 0
src/index.ts

@@ -0,0 +1,2 @@
+
+aaa("cc");

+ 0 - 1
src/main.d.ts

@@ -1 +0,0 @@
-export {};

+ 0 - 5
src/main.js

@@ -1,5 +0,0 @@
-"use strict";
-Object.defineProperty(exports, "__esModule", { value: true });
-var main_1 = require("../lib/main");
-(0, main_1.aaa)("cc");
-//# sourceMappingURL=main.js.map

+ 0 - 1
src/main.js.map

@@ -1 +0,0 @@
-{"version":3,"file":"main.js","sourceRoot":"","sources":["main.ts"],"names":[],"mappings":";;AAAA,oCAAkC;AAElC,IAAA,UAAG,EAAC,IAAI,CAAC,CAAC"}

+ 0 - 3
src/main.ts

@@ -1,3 +0,0 @@
-import { aaa } from "../lib/main";
-
-aaa("cc");

+ 138 - 0
src/types/common.ts

@@ -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
+  };
+}

+ 2 - 0
src/types/index.ts

@@ -0,0 +1,2 @@
+export * from './option';
+export * from './common';

+ 0 - 0
src/types/options