anys-web 1.4.0 → 2.0.0
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/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +18 -25
- package/src/recorder-plugin.js +2 -2
- package/cjs/index.js +0 -35
- package/cjs/recorder-plugin.js +0 -162
package/package.json
CHANGED
|
@@ -1,40 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "anys-web",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "",
|
|
5
|
-
"main": "
|
|
6
|
-
"module": "src/index.js",
|
|
5
|
+
"main": "src/index.js",
|
|
7
6
|
"type": "module",
|
|
8
|
-
"exports": {
|
|
9
|
-
"import": "./src/index.js",
|
|
10
|
-
"require": "./cjs/index.js"
|
|
11
|
-
},
|
|
12
7
|
"scripts": {
|
|
13
|
-
"build
|
|
14
|
-
"build:dist": "rimraf dist && webpack --config ../../webpack.config.js",
|
|
15
|
-
"build": "npm run build:cjs && npm run build:dist"
|
|
8
|
+
"build": "rimraf dist && webpack --config ../../webpack.config.js"
|
|
16
9
|
},
|
|
17
10
|
"keywords": [],
|
|
18
11
|
"author": "tangshuang",
|
|
19
12
|
"license": "Apache-2.0",
|
|
20
13
|
"dependencies": {
|
|
21
|
-
"anys": "^
|
|
22
|
-
"anys-shared": "^
|
|
23
|
-
"anys-web-plugin-identify": "^
|
|
24
|
-
"anys-web-plugin-monitor-ajax": "^
|
|
25
|
-
"anys-web-plugin-monitor-dom-mutation": "^
|
|
26
|
-
"anys-web-plugin-monitor-input-event": "^
|
|
27
|
-
"anys-web-plugin-monitor-mouse-event": "^
|
|
28
|
-
"anys-web-plugin-monitor-scroll-event": "^
|
|
29
|
-
"anys-web-plugin-monitor-touch-event": "^
|
|
30
|
-
"anys-web-plugin-monitor-url": "^
|
|
31
|
-
"anys-web-plugin-monitor-window-activity": "^
|
|
32
|
-
"anys-web-plugin-monitor-window-size": "^
|
|
33
|
-
"anys-web-plugin-send-by-ajax": "^
|
|
34
|
-
"anys-web-plugin-store-offline": "^
|
|
14
|
+
"anys": "^2.0.0",
|
|
15
|
+
"anys-shared": "^2.0.0",
|
|
16
|
+
"anys-web-plugin-identify": "^2.0.0",
|
|
17
|
+
"anys-web-plugin-monitor-ajax": "^2.0.0",
|
|
18
|
+
"anys-web-plugin-monitor-dom-mutation": "^2.0.0",
|
|
19
|
+
"anys-web-plugin-monitor-input-event": "^2.0.0",
|
|
20
|
+
"anys-web-plugin-monitor-mouse-event": "^2.0.0",
|
|
21
|
+
"anys-web-plugin-monitor-scroll-event": "^2.0.0",
|
|
22
|
+
"anys-web-plugin-monitor-touch-event": "^2.0.0",
|
|
23
|
+
"anys-web-plugin-monitor-url": "^2.0.0",
|
|
24
|
+
"anys-web-plugin-monitor-window-activity": "^2.0.0",
|
|
25
|
+
"anys-web-plugin-monitor-window-size": "^2.0.0",
|
|
26
|
+
"anys-web-plugin-send-by-ajax": "^2.0.0",
|
|
27
|
+
"anys-web-plugin-store-offline": "^2.0.0"
|
|
35
28
|
},
|
|
36
29
|
"publishConfig": {
|
|
37
30
|
"registry": "https://registry.npmjs.org/"
|
|
38
31
|
},
|
|
39
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "4264c187b83f68eb7095c1f27eb644a21fd7df54"
|
|
40
33
|
}
|
package/src/recorder-plugin.js
CHANGED
|
@@ -46,7 +46,7 @@ export class AnysRecorderPlugin extends AnysPlugin {
|
|
|
46
46
|
mousemove: true,
|
|
47
47
|
mouseup: true,
|
|
48
48
|
autoReport: false,
|
|
49
|
-
reportUrl: new Error('
|
|
49
|
+
reportUrl: new Error('options.reportUrl is required!'),
|
|
50
50
|
reportInterval: 10000,
|
|
51
51
|
reportParams: null,
|
|
52
52
|
};
|
|
@@ -145,7 +145,7 @@ export class AnysRecorderPlugin extends AnysPlugin {
|
|
|
145
145
|
|
|
146
146
|
const { reportUrl, reportParams } = this.anys.options;
|
|
147
147
|
const url = reportParams ? replaceUrlSearch(reportUrl, reportParams) : reportUrl;
|
|
148
|
-
return ajaxPost(url, items).then(() => {
|
|
148
|
+
return ajaxPost(url, { data: items }).then(() => {
|
|
149
149
|
ids.forEach((id) => {
|
|
150
150
|
delete this.cache[id];
|
|
151
151
|
});
|
package/cjs/index.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.create = void 0;
|
|
7
|
-
var _anys = require("anys");
|
|
8
|
-
var _recorderPlugin = require("./recorder-plugin.js");
|
|
9
|
-
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
|
|
10
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
11
|
-
let RecorderAnys = /*#__PURE__*/function (_Anys) {
|
|
12
|
-
_inheritsLoose(RecorderAnys, _Anys);
|
|
13
|
-
function RecorderAnys() {
|
|
14
|
-
return _Anys.apply(this, arguments) || this;
|
|
15
|
-
}
|
|
16
|
-
var _proto = RecorderAnys.prototype;
|
|
17
|
-
/**
|
|
18
|
-
* patch auth info into reportParams
|
|
19
|
-
* @param {object} info
|
|
20
|
-
*/
|
|
21
|
-
_proto.auth = function auth(info) {
|
|
22
|
-
this.options.reportParams = Object.assign(this.options.reportParams || {}, info);
|
|
23
|
-
};
|
|
24
|
-
return RecorderAnys;
|
|
25
|
-
}(_anys.Anys);
|
|
26
|
-
const create = (options = {}) => new RecorderAnys({
|
|
27
|
-
namespace: 'AnysTracer',
|
|
28
|
-
autoReport: false,
|
|
29
|
-
...options,
|
|
30
|
-
plugins: {
|
|
31
|
-
...(options.plugins || {}),
|
|
32
|
-
recorder: _recorderPlugin.AnysRecorderPlugin
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
exports.create = create;
|
package/cjs/recorder-plugin.js
DELETED
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.AnysRecorderPlugin = void 0;
|
|
7
|
-
var _anysShared = require("anys-shared");
|
|
8
|
-
var _anysWebPluginMonitorAjax = require("anys-web-plugin-monitor-ajax");
|
|
9
|
-
var _anysWebPluginIdentify = require("anys-web-plugin-identify");
|
|
10
|
-
var _anysWebPluginMonitorInputEvent = require("anys-web-plugin-monitor-input-event");
|
|
11
|
-
var _anysWebPluginMonitorMouseEvent = require("anys-web-plugin-monitor-mouse-event");
|
|
12
|
-
var _anysWebPluginMonitorWindowActivity = require("anys-web-plugin-monitor-window-activity");
|
|
13
|
-
var _anysWebPluginMonitorUrl = require("anys-web-plugin-monitor-url");
|
|
14
|
-
var _anysWebPluginMonitorTouchEvent = require("anys-web-plugin-monitor-touch-event");
|
|
15
|
-
var _anysWebPluginStoreOffline = require("anys-web-plugin-store-offline");
|
|
16
|
-
var _anysWebPluginMonitorDomMutation = require("anys-web-plugin-monitor-dom-mutation");
|
|
17
|
-
var _anysWebPluginMonitorWindowSize = require("anys-web-plugin-monitor-window-size");
|
|
18
|
-
var _anysWebPluginMonitorScrollEvent = require("anys-web-plugin-monitor-scroll-event");
|
|
19
|
-
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
|
|
20
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
21
|
-
let AnysRecorderPlugin = /*#__PURE__*/function (_AnysPlugin) {
|
|
22
|
-
_inheritsLoose(AnysRecorderPlugin, _AnysPlugin);
|
|
23
|
-
function AnysRecorderPlugin(anys, [offlineStore, urlMonitor, windowSizeMonitor, DOMMutationMonitor]) {
|
|
24
|
-
var _this;
|
|
25
|
-
_this = _AnysPlugin.call(this, anys) || this;
|
|
26
|
-
_this.offlineStore = offlineStore;
|
|
27
|
-
_this.urlMonitor = urlMonitor;
|
|
28
|
-
_this.windowSizeMonitor = windowSizeMonitor;
|
|
29
|
-
_this.DOMMutationMonitor = DOMMutationMonitor;
|
|
30
|
-
// cache for trace logs to be send by beacon
|
|
31
|
-
_this.cache = {};
|
|
32
|
-
return _this;
|
|
33
|
-
}
|
|
34
|
-
var _proto = AnysRecorderPlugin.prototype;
|
|
35
|
-
_proto.options = function options() {
|
|
36
|
-
const isSupportTouch = ('ontouchend' in document);
|
|
37
|
-
return {
|
|
38
|
-
touch: isSupportTouch,
|
|
39
|
-
mouse: !isSupportTouch,
|
|
40
|
-
click: false,
|
|
41
|
-
mousedown: true,
|
|
42
|
-
mousemove: true,
|
|
43
|
-
mouseup: true,
|
|
44
|
-
autoReport: false,
|
|
45
|
-
reportUrl: new Error('[Anys]: options.reportUrl is required!'),
|
|
46
|
-
reportInterval: 10000,
|
|
47
|
-
reportParams: null
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
_proto.registerAutoReport = function registerAutoReport() {
|
|
51
|
-
const {
|
|
52
|
-
clientId
|
|
53
|
-
} = this.anys;
|
|
54
|
-
const autoReportWhenRefreshTraceId = ({
|
|
55
|
-
prev
|
|
56
|
-
}) => {
|
|
57
|
-
// report previous trace logs
|
|
58
|
-
this.anys.report([{
|
|
59
|
-
key: 'client',
|
|
60
|
-
value: clientId
|
|
61
|
-
}, {
|
|
62
|
-
key: 'trace',
|
|
63
|
-
value: prev
|
|
64
|
-
}]);
|
|
65
|
-
|
|
66
|
-
// clear cache
|
|
67
|
-
this.cache = {};
|
|
68
|
-
|
|
69
|
-
// record new information
|
|
70
|
-
this.urlMonitor.recordUrl();
|
|
71
|
-
this.windowSizeMonitor.recordSize();
|
|
72
|
-
this.DOMMutationMonitor.recordSnapshot();
|
|
73
|
-
};
|
|
74
|
-
this.anys.on('refreshTraceId', autoReportWhenRefreshTraceId);
|
|
75
|
-
const timer = setInterval(() => {
|
|
76
|
-
this.anys.report();
|
|
77
|
-
}, this.anys.options.reportInterval);
|
|
78
|
-
let isUnloaded = 0;
|
|
79
|
-
const sendBeaconWhenBeforeUnload = () => {
|
|
80
|
-
if (isUnloaded) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
isUnloaded = 1;
|
|
84
|
-
const ids = Object.keys(this.cache);
|
|
85
|
-
const logs = Object.values(this.cache);
|
|
86
|
-
if (ids.length) {
|
|
87
|
-
this.offlineStore.remove(ids); // async may not executed
|
|
88
|
-
navigator.sendBeacon(this.anys.options.reportUrl, JSON.stringify(logs));
|
|
89
|
-
this.cache = {};
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
window.addEventListener('beforeunload', sendBeaconWhenBeforeUnload);
|
|
93
|
-
window.addEventListener('pagehide', sendBeaconWhenBeforeUnload); // 兼容微信浏览器
|
|
94
|
-
window.addEventListener('unload', sendBeaconWhenBeforeUnload);
|
|
95
|
-
const addCacheWhenWriteLog = ({
|
|
96
|
-
id,
|
|
97
|
-
data
|
|
98
|
-
}) => {
|
|
99
|
-
this.cache[id] = data;
|
|
100
|
-
};
|
|
101
|
-
this.anys.on('writeOfflineLog', addCacheWhenWriteLog);
|
|
102
|
-
return () => {
|
|
103
|
-
this.anys.off('refreshTraceId', autoReportWhenRefreshTraceId);
|
|
104
|
-
this.anys.off('writeOfflineLog', addCacheWhenWriteLog);
|
|
105
|
-
// @ts-ignore
|
|
106
|
-
clearInterval(timer);
|
|
107
|
-
window.removeEventListener('beforeunload', sendBeaconWhenBeforeUnload);
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* define read here, so that recorder will not send other plugins 'read' output
|
|
113
|
-
* @param {*} message
|
|
114
|
-
* @returns
|
|
115
|
-
*/;
|
|
116
|
-
_proto.read = function read(message) {
|
|
117
|
-
return this.offlineStore.read(message);
|
|
118
|
-
};
|
|
119
|
-
_proto.send = function send(logs) {
|
|
120
|
-
const groups = [];
|
|
121
|
-
let i = 0;
|
|
122
|
-
logs.forEach(item => {
|
|
123
|
-
groups[i] = groups[i] || [];
|
|
124
|
-
groups[i].push(item);
|
|
125
|
-
if (groups[i].length > 200) {
|
|
126
|
-
i++;
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
const defers = groups.map(data => {
|
|
130
|
-
const items = [];
|
|
131
|
-
const ids = [];
|
|
132
|
-
data.forEach(item => {
|
|
133
|
-
const {
|
|
134
|
-
_id,
|
|
135
|
-
...info
|
|
136
|
-
} = item;
|
|
137
|
-
ids.push(_id);
|
|
138
|
-
items.push(info);
|
|
139
|
-
});
|
|
140
|
-
if (!items.length) {
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
const {
|
|
144
|
-
reportUrl,
|
|
145
|
-
reportParams
|
|
146
|
-
} = this.anys.options;
|
|
147
|
-
const url = reportParams ? (0, _anysShared.replaceUrlSearch)(reportUrl, reportParams) : reportUrl;
|
|
148
|
-
return (0, _anysShared.ajaxPost)(url, items).then(() => {
|
|
149
|
-
ids.forEach(id => {
|
|
150
|
-
delete this.cache[id];
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
return Promise.all(defers);
|
|
155
|
-
};
|
|
156
|
-
_proto.clear = function clear() {
|
|
157
|
-
this.cache = {};
|
|
158
|
-
};
|
|
159
|
-
return AnysRecorderPlugin;
|
|
160
|
-
}(_anysShared.AnysPlugin);
|
|
161
|
-
exports.AnysRecorderPlugin = AnysRecorderPlugin;
|
|
162
|
-
AnysRecorderPlugin.dependencies = [_anysWebPluginStoreOffline.AnysStoreOfflinePlugin, _anysWebPluginMonitorUrl.AnysMonitorUrlPlugin, _anysWebPluginMonitorWindowSize.AnysMonitorWindowSizePlugin, _anysWebPluginMonitorDomMutation.AnysMonitorDOMMutationPlugin, _anysWebPluginIdentify.AnysIdentifyPlugin, _anysWebPluginMonitorAjax.AnysMonitorAjaxPlugin, _anysWebPluginMonitorInputEvent.AnysMonitorInputEventPlugin, _anysWebPluginMonitorMouseEvent.AnysMonitorMouseEventPlugin, _anysWebPluginMonitorWindowActivity.AnysMonitorWindowActivityPlugin, _anysWebPluginMonitorTouchEvent.AnysMonitorTouchEventPlugin, _anysWebPluginMonitorScrollEvent.AnysMonitorScrollEventPlugin];
|