anys-web 1.4.1 → 2.0.2
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 +1 -1
- package/cjs/index.js +0 -42
- package/cjs/recorder-plugin.js +0 -172
package/package.json
CHANGED
|
@@ -1,40 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "anys-web",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.2",
|
|
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.2",
|
|
15
|
+
"anys-shared": "^2.0.2",
|
|
16
|
+
"anys-web-plugin-identify": "^2.0.2",
|
|
17
|
+
"anys-web-plugin-monitor-ajax": "^2.0.2",
|
|
18
|
+
"anys-web-plugin-monitor-dom-mutation": "^2.0.2",
|
|
19
|
+
"anys-web-plugin-monitor-input-event": "^2.0.2",
|
|
20
|
+
"anys-web-plugin-monitor-mouse-event": "^2.0.2",
|
|
21
|
+
"anys-web-plugin-monitor-scroll-event": "^2.0.2",
|
|
22
|
+
"anys-web-plugin-monitor-touch-event": "^2.0.2",
|
|
23
|
+
"anys-web-plugin-monitor-url": "^2.0.2",
|
|
24
|
+
"anys-web-plugin-monitor-window-activity": "^2.0.2",
|
|
25
|
+
"anys-web-plugin-monitor-window-size": "^2.0.2",
|
|
26
|
+
"anys-web-plugin-send-by-ajax": "^2.0.2",
|
|
27
|
+
"anys-web-plugin-store-offline": "^2.0.2"
|
|
35
28
|
},
|
|
36
29
|
"publishConfig": {
|
|
37
30
|
"registry": "https://registry.npmjs.org/"
|
|
38
31
|
},
|
|
39
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "770b25b2806007cc96cc206e30ffdb3e4dc207c5"
|
|
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
|
};
|
package/cjs/index.js
DELETED
|
@@ -1,42 +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 ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
10
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
11
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
12
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
13
|
-
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
14
|
-
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
|
|
15
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
16
|
-
let RecorderAnys = /*#__PURE__*/function (_Anys) {
|
|
17
|
-
_inheritsLoose(RecorderAnys, _Anys);
|
|
18
|
-
function RecorderAnys() {
|
|
19
|
-
return _Anys.apply(this, arguments) || this;
|
|
20
|
-
}
|
|
21
|
-
var _proto = RecorderAnys.prototype;
|
|
22
|
-
/**
|
|
23
|
-
* patch auth info into reportParams
|
|
24
|
-
* @param {object} info
|
|
25
|
-
*/
|
|
26
|
-
_proto.auth = function auth(info) {
|
|
27
|
-
this.options.reportParams = Object.assign(this.options.reportParams || {}, info);
|
|
28
|
-
};
|
|
29
|
-
return RecorderAnys;
|
|
30
|
-
}(_anys.Anys);
|
|
31
|
-
const create = function () {
|
|
32
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
33
|
-
return new RecorderAnys(_objectSpread(_objectSpread({
|
|
34
|
-
namespace: 'AnysTracer',
|
|
35
|
-
autoReport: false
|
|
36
|
-
}, options), {}, {
|
|
37
|
-
plugins: _objectSpread(_objectSpread({}, options.plugins || {}), {}, {
|
|
38
|
-
recorder: _recorderPlugin.AnysRecorderPlugin
|
|
39
|
-
})
|
|
40
|
-
}));
|
|
41
|
-
};
|
|
42
|
-
exports.create = create;
|
package/cjs/recorder-plugin.js
DELETED
|
@@ -1,172 +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
|
-
const _excluded = ["_id"];
|
|
20
|
-
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
21
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
22
|
-
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
|
|
23
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
24
|
-
let AnysRecorderPlugin = /*#__PURE__*/function (_AnysPlugin) {
|
|
25
|
-
_inheritsLoose(AnysRecorderPlugin, _AnysPlugin);
|
|
26
|
-
function AnysRecorderPlugin(anys, _ref) {
|
|
27
|
-
var _this;
|
|
28
|
-
let [offlineStore, urlMonitor, windowSizeMonitor, DOMMutationMonitor] = _ref;
|
|
29
|
-
_this = _AnysPlugin.call(this, anys) || this;
|
|
30
|
-
_this.offlineStore = offlineStore;
|
|
31
|
-
_this.urlMonitor = urlMonitor;
|
|
32
|
-
_this.windowSizeMonitor = windowSizeMonitor;
|
|
33
|
-
_this.DOMMutationMonitor = DOMMutationMonitor;
|
|
34
|
-
// cache for trace logs to be send by beacon
|
|
35
|
-
_this.cache = {};
|
|
36
|
-
return _this;
|
|
37
|
-
}
|
|
38
|
-
var _proto = AnysRecorderPlugin.prototype;
|
|
39
|
-
_proto.options = function options() {
|
|
40
|
-
const isSupportTouch = ('ontouchend' in document);
|
|
41
|
-
return {
|
|
42
|
-
touch: isSupportTouch,
|
|
43
|
-
mouse: !isSupportTouch,
|
|
44
|
-
click: false,
|
|
45
|
-
mousedown: true,
|
|
46
|
-
mousemove: true,
|
|
47
|
-
mouseup: true,
|
|
48
|
-
autoReport: false,
|
|
49
|
-
reportUrl: new Error('[Anys]: options.reportUrl is required!'),
|
|
50
|
-
reportInterval: 10000,
|
|
51
|
-
reportParams: null
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
_proto.registerAutoReport = function registerAutoReport() {
|
|
55
|
-
var _this2 = this;
|
|
56
|
-
const {
|
|
57
|
-
clientId
|
|
58
|
-
} = this.anys;
|
|
59
|
-
const autoReportWhenRefreshTraceId = function (_ref2) {
|
|
60
|
-
let {
|
|
61
|
-
prev
|
|
62
|
-
} = _ref2;
|
|
63
|
-
// report previous trace logs
|
|
64
|
-
_this2.anys.report([{
|
|
65
|
-
key: 'client',
|
|
66
|
-
value: clientId
|
|
67
|
-
}, {
|
|
68
|
-
key: 'trace',
|
|
69
|
-
value: prev
|
|
70
|
-
}]);
|
|
71
|
-
|
|
72
|
-
// clear cache
|
|
73
|
-
_this2.cache = {};
|
|
74
|
-
|
|
75
|
-
// record new information
|
|
76
|
-
_this2.urlMonitor.recordUrl();
|
|
77
|
-
_this2.windowSizeMonitor.recordSize();
|
|
78
|
-
_this2.DOMMutationMonitor.recordSnapshot();
|
|
79
|
-
};
|
|
80
|
-
this.anys.on('refreshTraceId', autoReportWhenRefreshTraceId);
|
|
81
|
-
const timer = setInterval(function () {
|
|
82
|
-
_this2.anys.report();
|
|
83
|
-
}, this.anys.options.reportInterval);
|
|
84
|
-
let isUnloaded = 0;
|
|
85
|
-
const sendBeaconWhenBeforeUnload = function () {
|
|
86
|
-
if (isUnloaded) {
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
isUnloaded = 1;
|
|
90
|
-
const ids = Object.keys(_this2.cache);
|
|
91
|
-
const logs = Object.values(_this2.cache);
|
|
92
|
-
if (ids.length) {
|
|
93
|
-
_this2.offlineStore.remove(ids); // async may not executed
|
|
94
|
-
navigator.sendBeacon(_this2.anys.options.reportUrl, JSON.stringify(logs));
|
|
95
|
-
_this2.cache = {};
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
window.addEventListener('beforeunload', sendBeaconWhenBeforeUnload);
|
|
99
|
-
window.addEventListener('pagehide', sendBeaconWhenBeforeUnload); // 兼容微信浏览器
|
|
100
|
-
window.addEventListener('unload', sendBeaconWhenBeforeUnload);
|
|
101
|
-
const addCacheWhenWriteLog = function (_ref3) {
|
|
102
|
-
let {
|
|
103
|
-
id,
|
|
104
|
-
data
|
|
105
|
-
} = _ref3;
|
|
106
|
-
_this2.cache[id] = data;
|
|
107
|
-
};
|
|
108
|
-
this.anys.on('writeOfflineLog', addCacheWhenWriteLog);
|
|
109
|
-
return function () {
|
|
110
|
-
_this2.anys.off('refreshTraceId', autoReportWhenRefreshTraceId);
|
|
111
|
-
_this2.anys.off('writeOfflineLog', addCacheWhenWriteLog);
|
|
112
|
-
// @ts-ignore
|
|
113
|
-
clearInterval(timer);
|
|
114
|
-
window.removeEventListener('beforeunload', sendBeaconWhenBeforeUnload);
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* define read here, so that recorder will not send other plugins 'read' output
|
|
120
|
-
* @param {*} message
|
|
121
|
-
* @returns
|
|
122
|
-
*/;
|
|
123
|
-
_proto.read = function read(message) {
|
|
124
|
-
return this.offlineStore.read(message);
|
|
125
|
-
};
|
|
126
|
-
_proto.send = function send(logs) {
|
|
127
|
-
var _this3 = this;
|
|
128
|
-
const groups = [];
|
|
129
|
-
let i = 0;
|
|
130
|
-
logs.forEach(function (item) {
|
|
131
|
-
groups[i] = groups[i] || [];
|
|
132
|
-
groups[i].push(item);
|
|
133
|
-
if (groups[i].length > 200) {
|
|
134
|
-
i++;
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
const defers = groups.map(function (data) {
|
|
138
|
-
const items = [];
|
|
139
|
-
const ids = [];
|
|
140
|
-
data.forEach(function (item) {
|
|
141
|
-
const {
|
|
142
|
-
_id
|
|
143
|
-
} = item,
|
|
144
|
-
info = _objectWithoutProperties(item, _excluded);
|
|
145
|
-
ids.push(_id);
|
|
146
|
-
items.push(info);
|
|
147
|
-
});
|
|
148
|
-
if (!items.length) {
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
const {
|
|
152
|
-
reportUrl,
|
|
153
|
-
reportParams
|
|
154
|
-
} = _this3.anys.options;
|
|
155
|
-
const url = reportParams ? (0, _anysShared.replaceUrlSearch)(reportUrl, reportParams) : reportUrl;
|
|
156
|
-
return (0, _anysShared.ajaxPost)(url, {
|
|
157
|
-
data: items
|
|
158
|
-
}).then(function () {
|
|
159
|
-
ids.forEach(function (id) {
|
|
160
|
-
delete _this3.cache[id];
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
return Promise.all(defers);
|
|
165
|
-
};
|
|
166
|
-
_proto.clear = function clear() {
|
|
167
|
-
this.cache = {};
|
|
168
|
-
};
|
|
169
|
-
return AnysRecorderPlugin;
|
|
170
|
-
}(_anysShared.AnysPlugin);
|
|
171
|
-
exports.AnysRecorderPlugin = AnysRecorderPlugin;
|
|
172
|
-
AnysRecorderPlugin.dependencies = [_anysWebPluginStoreOffline.AnysStoreOfflinePlugin, _anysWebPluginMonitorUrl.AnysMonitorUrlPlugin, _anysWebPluginMonitorWindowSize.AnysMonitorWindowSizePlugin, _anysWebPluginMonitorDomMutation.AnysMonitorDOMMutationPlugin, _anysWebPluginIdentify.AnysIdentifyPlugin, _anysWebPluginMonitorAjax.AnysMonitorAjaxPlugin, _anysWebPluginMonitorInputEvent.AnysMonitorInputEventPlugin, _anysWebPluginMonitorMouseEvent.AnysMonitorMouseEventPlugin, _anysWebPluginMonitorWindowActivity.AnysMonitorWindowActivityPlugin, _anysWebPluginMonitorTouchEvent.AnysMonitorTouchEventPlugin, _anysWebPluginMonitorScrollEvent.AnysMonitorScrollEventPlugin];
|