@deppon/deppon-monitor-utils 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -0
- package/es/_virtual/_rollup-plugin-inject-process-env.js +11 -0
- package/es/index.d.ts +76 -0
- package/es/index.js +206 -0
- package/package.json +34 -0
package/LICENSE
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
(function() {
|
|
2
|
+
const env = {};
|
|
3
|
+
try {
|
|
4
|
+
if (process) {
|
|
5
|
+
process.env = Object.assign({}, process.env);
|
|
6
|
+
Object.assign(process.env, env);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
} catch (e) {} // avoid ReferenceError: process is not defined
|
|
10
|
+
globalThis.process = { env:env };
|
|
11
|
+
})();
|
package/es/index.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import UAParser from 'ua-parser-js';
|
|
2
|
+
import { ErrorLevelEnum, ErrorTypeEnum, ReportDataType } from '@deppon/deppon-monitor-shared';
|
|
3
|
+
declare function GetDeviceInfo(): {
|
|
4
|
+
os: UAParser.IOS;
|
|
5
|
+
browser: UAParser.IBrowser;
|
|
6
|
+
device: {
|
|
7
|
+
vendor: string;
|
|
8
|
+
type: string;
|
|
9
|
+
model: string;
|
|
10
|
+
};
|
|
11
|
+
engine: UAParser.IEngine;
|
|
12
|
+
userAgent: string;
|
|
13
|
+
};
|
|
14
|
+
export declare const nativeToString: () => string;
|
|
15
|
+
/**
|
|
16
|
+
* 检测变量类型
|
|
17
|
+
* @param type
|
|
18
|
+
*/
|
|
19
|
+
export declare const variableTypeDetection: {
|
|
20
|
+
isNumber: (value: any) => boolean;
|
|
21
|
+
isString: (value: any) => boolean;
|
|
22
|
+
isBoolean: (value: any) => boolean;
|
|
23
|
+
isNull: (value: any) => boolean;
|
|
24
|
+
isUndefined: (value: any) => boolean;
|
|
25
|
+
isSymbol: (value: any) => boolean;
|
|
26
|
+
isFunction: (value: any) => boolean;
|
|
27
|
+
isObject: (value: any) => boolean;
|
|
28
|
+
isArray: (value: any) => boolean;
|
|
29
|
+
isProcess: (value: any) => boolean;
|
|
30
|
+
isWindow: (value: any) => boolean;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* 检查是否是空对象
|
|
34
|
+
* @param obj 待检测的对象
|
|
35
|
+
*/
|
|
36
|
+
export declare function isEmptyObject(obj: Record<string, any>): boolean;
|
|
37
|
+
export declare function isEmpty(wat: any): boolean;
|
|
38
|
+
export declare function isInstanceOf(wat: any, base: any): boolean;
|
|
39
|
+
export declare function isExistProperty(obj: Record<string, any>, key: string | number | symbol): boolean;
|
|
40
|
+
export declare function isError(wat: any): boolean;
|
|
41
|
+
export declare function getBigVersion(version: string): number;
|
|
42
|
+
export declare function generateUUID(): string;
|
|
43
|
+
export declare function getLines(stack: string): string;
|
|
44
|
+
export declare function getNetworkType(): string;
|
|
45
|
+
export declare function getHref(): string;
|
|
46
|
+
export declare function getTimestamp(): number;
|
|
47
|
+
export declare function unknownToString(target: unknown): string;
|
|
48
|
+
export declare function handleNotErrorInstance(message: string, filename: string, lineno: number, colno: number): {
|
|
49
|
+
url: string;
|
|
50
|
+
name: ErrorLevelEnum;
|
|
51
|
+
message: string;
|
|
52
|
+
time: number;
|
|
53
|
+
stack: {
|
|
54
|
+
url: string;
|
|
55
|
+
func: ErrorTypeEnum;
|
|
56
|
+
args: ErrorTypeEnum;
|
|
57
|
+
line: number;
|
|
58
|
+
col: number;
|
|
59
|
+
}[];
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* 解析error的stack,并返回args、column、line、func、url:
|
|
63
|
+
* @param ex
|
|
64
|
+
*/
|
|
65
|
+
export declare function extractErrorStack(ex: any): ReportDataType;
|
|
66
|
+
export declare class Queue {
|
|
67
|
+
private stack;
|
|
68
|
+
private isFlushing;
|
|
69
|
+
private micro;
|
|
70
|
+
constructor();
|
|
71
|
+
addFn(fn: (...arg: any) => any): void;
|
|
72
|
+
clear(): void;
|
|
73
|
+
getStack(): any[];
|
|
74
|
+
flushStack(): void;
|
|
75
|
+
}
|
|
76
|
+
export { GetDeviceInfo };
|
package/es/index.js
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import './_virtual/_rollup-plugin-inject-process-env.js';
|
|
2
|
+
import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
|
|
3
|
+
import _createClass from '@babel/runtime/helpers/createClass';
|
|
4
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
5
|
+
import UAParser from 'ua-parser-js';
|
|
6
|
+
import { ErrorLevelEnum, JS_ERROR_TYPE_REG, ErrorTypeEnum } from '@deppon/deppon-monitor-shared';
|
|
7
|
+
import ErrorStackParser from 'error-stack-parser';
|
|
8
|
+
|
|
9
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
10
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
11
|
+
function GetDeviceInfo() {
|
|
12
|
+
var parser = new UAParser().getResult();
|
|
13
|
+
return {
|
|
14
|
+
os: parser.os,
|
|
15
|
+
browser: parser.browser,
|
|
16
|
+
device: _objectSpread(_objectSpread({}, parser.device), {}, {
|
|
17
|
+
vendor: parser.device.vendor || 'Desktop',
|
|
18
|
+
type: parser.device.vendor || 'unknown',
|
|
19
|
+
model: parser.device.vendor || 'unknown'
|
|
20
|
+
}),
|
|
21
|
+
engine: parser.engine,
|
|
22
|
+
userAgent: parser.ua
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
var nativeToString = Object.prototype.toString;
|
|
26
|
+
function isType(type) {
|
|
27
|
+
return function (value) {
|
|
28
|
+
return nativeToString.call(value) === "[object ".concat(type, "]");
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 检测变量类型
|
|
34
|
+
* @param type
|
|
35
|
+
*/
|
|
36
|
+
var variableTypeDetection = {
|
|
37
|
+
isNumber: isType('Number'),
|
|
38
|
+
isString: isType('String'),
|
|
39
|
+
isBoolean: isType('Boolean'),
|
|
40
|
+
isNull: isType('Null'),
|
|
41
|
+
isUndefined: isType('Undefined'),
|
|
42
|
+
isSymbol: isType('Symbol'),
|
|
43
|
+
isFunction: isType('Function'),
|
|
44
|
+
isObject: isType('Object'),
|
|
45
|
+
isArray: isType('Array'),
|
|
46
|
+
isProcess: isType('process'),
|
|
47
|
+
isWindow: isType('Window')
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 检查是否是空对象
|
|
52
|
+
* @param obj 待检测的对象
|
|
53
|
+
*/
|
|
54
|
+
function isEmptyObject(obj) {
|
|
55
|
+
return variableTypeDetection.isObject(obj) && Object.keys(obj).length === 0;
|
|
56
|
+
}
|
|
57
|
+
function isEmpty(wat) {
|
|
58
|
+
return variableTypeDetection.isString(wat) && wat.trim() === '' || wat === undefined || wat === null;
|
|
59
|
+
}
|
|
60
|
+
function isInstanceOf(wat, base) {
|
|
61
|
+
try {
|
|
62
|
+
return wat instanceof base;
|
|
63
|
+
} catch (e) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function isExistProperty(obj, key) {
|
|
68
|
+
return obj.hasOwnProperty(key);
|
|
69
|
+
}
|
|
70
|
+
function isError(wat) {
|
|
71
|
+
switch (nativeToString.call(wat)) {
|
|
72
|
+
case '[object Error]':
|
|
73
|
+
return true;
|
|
74
|
+
case '[object Exception]':
|
|
75
|
+
return true;
|
|
76
|
+
case '[object DOMException]':
|
|
77
|
+
return true;
|
|
78
|
+
default:
|
|
79
|
+
return isInstanceOf(wat, Error);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function getBigVersion(version) {
|
|
83
|
+
return Number(version.split('.')[0]);
|
|
84
|
+
}
|
|
85
|
+
function generateUUID() {
|
|
86
|
+
var d = new Date().getTime();
|
|
87
|
+
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
88
|
+
var r = (d + Math.random() * 16) % 16 | 0;
|
|
89
|
+
return (c == 'x' ? r : r & 0x3 | 0x8).toString(16);
|
|
90
|
+
});
|
|
91
|
+
return uuid;
|
|
92
|
+
}
|
|
93
|
+
function getLines(stack) {
|
|
94
|
+
return stack.split('\n').slice(1).map(function (item) {
|
|
95
|
+
return item.replace(/^\s+at\s+/g, '');
|
|
96
|
+
}).join('^');
|
|
97
|
+
}
|
|
98
|
+
function getNetworkType() {
|
|
99
|
+
var connection = navigator.connection;
|
|
100
|
+
return connection ? connection.effectiveType || '' : '';
|
|
101
|
+
}
|
|
102
|
+
function getHref() {
|
|
103
|
+
return window.location.href;
|
|
104
|
+
}
|
|
105
|
+
function getTimestamp() {
|
|
106
|
+
return Date.now();
|
|
107
|
+
}
|
|
108
|
+
function unknownToString(target) {
|
|
109
|
+
if (variableTypeDetection.isString(target)) {
|
|
110
|
+
return target;
|
|
111
|
+
}
|
|
112
|
+
if (variableTypeDetection.isUndefined(target)) {
|
|
113
|
+
return 'undefined';
|
|
114
|
+
}
|
|
115
|
+
return JSON.stringify(target);
|
|
116
|
+
}
|
|
117
|
+
function handleNotErrorInstance(message, filename, lineno, colno) {
|
|
118
|
+
var name = ErrorLevelEnum.UNKNOWN;
|
|
119
|
+
var url = filename || getHref();
|
|
120
|
+
var msg = message;
|
|
121
|
+
var matches = message.match(JS_ERROR_TYPE_REG);
|
|
122
|
+
if (matches !== null && matches !== void 0 && matches[1]) {
|
|
123
|
+
name = matches[1];
|
|
124
|
+
msg = matches[2];
|
|
125
|
+
}
|
|
126
|
+
var element = {
|
|
127
|
+
url: url,
|
|
128
|
+
func: ErrorTypeEnum.UNKNOWN_FUNCTION,
|
|
129
|
+
args: ErrorTypeEnum.UNKNOWN,
|
|
130
|
+
line: lineno,
|
|
131
|
+
col: colno
|
|
132
|
+
};
|
|
133
|
+
return {
|
|
134
|
+
url: url,
|
|
135
|
+
name: name,
|
|
136
|
+
message: msg,
|
|
137
|
+
time: getTimestamp(),
|
|
138
|
+
stack: [element]
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* 解析error的stack,并返回args、column、line、func、url:
|
|
144
|
+
* @param ex
|
|
145
|
+
*/
|
|
146
|
+
function extractErrorStack(ex) {
|
|
147
|
+
var normal = {
|
|
148
|
+
time: getTimestamp(),
|
|
149
|
+
url: getHref(),
|
|
150
|
+
name: ex === null || ex === void 0 ? void 0 : ex.name,
|
|
151
|
+
message: ex === null || ex === void 0 ? void 0 : ex.message
|
|
152
|
+
};
|
|
153
|
+
return _objectSpread(_objectSpread({}, normal), {}, {
|
|
154
|
+
stack: ErrorStackParser.parse(ex)
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
var Queue = /*#__PURE__*/function () {
|
|
158
|
+
function Queue() {
|
|
159
|
+
_classCallCheck(this, Queue);
|
|
160
|
+
_defineProperty(this, "stack", []);
|
|
161
|
+
_defineProperty(this, "isFlushing", false);
|
|
162
|
+
_defineProperty(this, "micro", Promise.resolve());
|
|
163
|
+
if (!('Promise' in window)) return;
|
|
164
|
+
this.micro = Promise.resolve();
|
|
165
|
+
}
|
|
166
|
+
return _createClass(Queue, [{
|
|
167
|
+
key: "addFn",
|
|
168
|
+
value: function addFn(fn) {
|
|
169
|
+
var _this = this;
|
|
170
|
+
if (typeof fn !== 'function') return;
|
|
171
|
+
if (!('Promise' in window)) {
|
|
172
|
+
fn();
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
this.stack.push(fn);
|
|
176
|
+
if (!this.isFlushing) {
|
|
177
|
+
this.isFlushing = true;
|
|
178
|
+
this.micro.then(function () {
|
|
179
|
+
_this.flushStack();
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}, {
|
|
184
|
+
key: "clear",
|
|
185
|
+
value: function clear() {
|
|
186
|
+
this.stack = [];
|
|
187
|
+
}
|
|
188
|
+
}, {
|
|
189
|
+
key: "getStack",
|
|
190
|
+
value: function getStack() {
|
|
191
|
+
return this.stack;
|
|
192
|
+
}
|
|
193
|
+
}, {
|
|
194
|
+
key: "flushStack",
|
|
195
|
+
value: function flushStack() {
|
|
196
|
+
var temp = this.stack.slice(0);
|
|
197
|
+
this.stack.length = 0;
|
|
198
|
+
this.isFlushing = false;
|
|
199
|
+
for (var i = 0; i < temp.length; i++) {
|
|
200
|
+
temp[i]();
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}]);
|
|
204
|
+
}();
|
|
205
|
+
|
|
206
|
+
export { GetDeviceInfo, Queue, extractErrorStack, generateUUID, getBigVersion, getHref, getLines, getNetworkType, getTimestamp, handleNotErrorInstance, isEmpty, isEmptyObject, isError, isExistProperty, isInstanceOf, nativeToString, unknownToString, variableTypeDetection };
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@deppon/deppon-monitor-utils",
|
|
3
|
+
"version": "2.1.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "es/index.js",
|
|
6
|
+
"module": "es/index.js",
|
|
7
|
+
"typings": "es/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"es"
|
|
10
|
+
],
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"registry": "https://devrepo.devcloud.cn-east-3.huaweicloud.com/artgalaxy/api/npm/cn-east-3_8a2e1f0ee52d4adb9a0a6998d78d0dda_npm_1/"
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"dev": "rollup -w -c",
|
|
16
|
+
"build": "rimraf es && rimraf lib && rollup -c && tsc --project tsconfig.json",
|
|
17
|
+
"publish:auto": "npm publish"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [],
|
|
20
|
+
"author": {
|
|
21
|
+
"name": "",
|
|
22
|
+
"email": ""
|
|
23
|
+
},
|
|
24
|
+
"license": "ISC",
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@deppon/deppon-monitor-shared": "2.1.1",
|
|
27
|
+
"error-stack-parser": "^2.1.4",
|
|
28
|
+
"ua-parser-js": "^1.0.32"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/ua-parser-js": "^0.7.36"
|
|
32
|
+
},
|
|
33
|
+
"gitHead": "1f329a64567c2e22df7860b0918ebe3427718945"
|
|
34
|
+
}
|