@antglobal/rlog-sdk 0.0.1755855517-dev.8 → 1.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/README.md +192 -432
- package/dist/esm/index.d.ts +14 -41
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +92 -76
- package/dist/esm/lib/api.d.ts +10 -0
- package/dist/esm/lib/api.d.ts.map +1 -1
- package/dist/esm/lib/api.js +58 -35
- package/dist/esm/lib/config.d.ts +14 -16
- package/dist/esm/lib/config.d.ts.map +1 -1
- package/dist/esm/lib/config.js +61 -33
- package/dist/esm/lib/constants.d.ts +89 -0
- package/dist/esm/lib/constants.d.ts.map +1 -0
- package/dist/esm/lib/constants.js +145 -0
- package/dist/esm/lib/drive/indexeddb-adapt.d.ts +12 -0
- package/dist/esm/lib/drive/indexeddb-adapt.d.ts.map +1 -1
- package/dist/esm/lib/drive/indexeddb-adapt.js +190 -20
- package/dist/esm/lib/drive/localstorage-adapt.d.ts +12 -0
- package/dist/esm/lib/drive/localstorage-adapt.d.ts.map +1 -1
- package/dist/esm/lib/drive/localstorage-adapt.js +179 -36
- package/dist/esm/lib/drive/memory-adapt.d.ts +10 -2
- package/dist/esm/lib/drive/memory-adapt.d.ts.map +1 -1
- package/dist/esm/lib/drive/memory-adapt.js +118 -26
- package/dist/esm/lib/drive/safe-storage.d.ts +24 -0
- package/dist/esm/lib/drive/safe-storage.d.ts.map +1 -0
- package/dist/esm/lib/drive/safe-storage.js +96 -0
- package/dist/esm/lib/drive/storage-interface.d.ts +20 -0
- package/dist/esm/lib/drive/storage-interface.d.ts.map +1 -1
- package/dist/esm/lib/error-trigger.d.ts +73 -0
- package/dist/esm/lib/error-trigger.d.ts.map +1 -0
- package/dist/esm/lib/error-trigger.js +162 -0
- package/dist/esm/lib/error.d.ts +9 -0
- package/dist/esm/lib/error.d.ts.map +1 -1
- package/dist/esm/lib/error.js +70 -118
- package/dist/esm/lib/init.d.ts +0 -4
- package/dist/esm/lib/init.d.ts.map +1 -1
- package/dist/esm/lib/init.js +148 -47
- package/dist/esm/lib/logger.d.ts +27 -0
- package/dist/esm/lib/logger.d.ts.map +1 -0
- package/dist/esm/lib/logger.js +79 -0
- package/dist/esm/lib/net.d.ts +11 -0
- package/dist/esm/lib/net.d.ts.map +1 -1
- package/dist/esm/lib/net.js +264 -116
- package/dist/esm/lib/request.d.ts.map +1 -1
- package/dist/esm/lib/request.js +2 -2
- package/dist/esm/lib/router-monitor.d.ts.map +1 -1
- package/dist/esm/lib/router-monitor.js +135 -49
- package/dist/esm/lib/rrweb.d.ts.map +1 -1
- package/dist/esm/lib/rrweb.js +31 -24
- package/dist/esm/lib/storage-manager.d.ts +12 -0
- package/dist/esm/lib/storage-manager.d.ts.map +1 -1
- package/dist/esm/lib/storage-manager.js +129 -46
- package/dist/esm/lib/upload-worker-manager.d.ts +47 -0
- package/dist/esm/lib/upload-worker-manager.d.ts.map +1 -0
- package/dist/esm/lib/upload-worker-manager.js +559 -0
- package/dist/esm/lib/upload-worker.d.ts +58 -0
- package/dist/esm/lib/upload-worker.d.ts.map +1 -0
- package/dist/esm/lib/upload-worker.js +28 -0
- package/dist/esm/lib/uploader.d.ts +43 -0
- package/dist/esm/lib/uploader.d.ts.map +1 -1
- package/dist/esm/lib/uploader.js +464 -102
- package/dist/esm/lib/utils.d.ts +75 -0
- package/dist/esm/lib/utils.d.ts.map +1 -1
- package/dist/esm/lib/utils.js +268 -5
- package/dist/lib/index.d.ts +14 -41
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +81 -63
- package/dist/lib/lib/api.d.ts +10 -0
- package/dist/lib/lib/api.d.ts.map +1 -1
- package/dist/lib/lib/api.js +59 -35
- package/dist/lib/lib/config.d.ts +14 -16
- package/dist/lib/lib/config.d.ts.map +1 -1
- package/dist/lib/lib/config.js +63 -33
- package/dist/lib/lib/constants.d.ts +89 -0
- package/dist/lib/lib/constants.d.ts.map +1 -0
- package/dist/lib/lib/constants.js +151 -0
- package/dist/lib/lib/drive/indexeddb-adapt.d.ts +12 -0
- package/dist/lib/lib/drive/indexeddb-adapt.d.ts.map +1 -1
- package/dist/lib/lib/drive/indexeddb-adapt.js +191 -19
- package/dist/lib/lib/drive/localstorage-adapt.d.ts +12 -0
- package/dist/lib/lib/drive/localstorage-adapt.d.ts.map +1 -1
- package/dist/lib/lib/drive/localstorage-adapt.js +179 -36
- package/dist/lib/lib/drive/memory-adapt.d.ts +10 -2
- package/dist/lib/lib/drive/memory-adapt.d.ts.map +1 -1
- package/dist/lib/lib/drive/memory-adapt.js +117 -26
- package/dist/lib/lib/drive/safe-storage.d.ts +24 -0
- package/dist/lib/lib/drive/safe-storage.d.ts.map +1 -0
- package/dist/lib/lib/drive/safe-storage.js +102 -0
- package/dist/lib/lib/drive/storage-interface.d.ts +20 -0
- package/dist/lib/lib/drive/storage-interface.d.ts.map +1 -1
- package/dist/lib/lib/error-trigger.d.ts +73 -0
- package/dist/lib/lib/error-trigger.d.ts.map +1 -0
- package/dist/lib/lib/error-trigger.js +167 -0
- package/dist/lib/lib/error.d.ts +9 -0
- package/dist/lib/lib/error.d.ts.map +1 -1
- package/dist/lib/lib/error.js +73 -118
- package/dist/lib/lib/init.d.ts +0 -4
- package/dist/lib/lib/init.d.ts.map +1 -1
- package/dist/lib/lib/init.js +144 -43
- package/dist/lib/lib/logger.d.ts +27 -0
- package/dist/lib/lib/logger.d.ts.map +1 -0
- package/dist/lib/lib/logger.js +84 -0
- package/dist/lib/lib/net.d.ts +11 -0
- package/dist/lib/lib/net.d.ts.map +1 -1
- package/dist/lib/lib/net.js +268 -117
- package/dist/lib/lib/request.d.ts.map +1 -1
- package/dist/lib/lib/request.js +3 -3
- package/dist/lib/lib/router-monitor.d.ts.map +1 -1
- package/dist/lib/lib/router-monitor.js +136 -49
- package/dist/lib/lib/rrweb.d.ts.map +1 -1
- package/dist/lib/lib/rrweb.js +31 -23
- package/dist/lib/lib/storage-manager.d.ts +12 -0
- package/dist/lib/lib/storage-manager.d.ts.map +1 -1
- package/dist/lib/lib/storage-manager.js +130 -46
- package/dist/lib/lib/upload-worker-manager.d.ts +47 -0
- package/dist/lib/lib/upload-worker-manager.d.ts.map +1 -0
- package/dist/lib/lib/upload-worker-manager.js +570 -0
- package/dist/lib/lib/upload-worker.d.ts +58 -0
- package/dist/lib/lib/upload-worker.d.ts.map +1 -0
- package/dist/lib/lib/upload-worker.js +33 -0
- package/dist/lib/lib/uploader.d.ts +43 -0
- package/dist/lib/lib/uploader.d.ts.map +1 -1
- package/dist/lib/lib/uploader.js +468 -101
- package/dist/lib/lib/utils.d.ts +75 -0
- package/dist/lib/lib/utils.d.ts.map +1 -1
- package/dist/lib/lib/utils.js +276 -6
- package/dist/rlog-sdk.min.js +1 -1
- package/package.json +3 -2
package/dist/lib/lib/net.js
CHANGED
|
@@ -5,15 +5,23 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.getBlackListUrls = getBlackListUrls;
|
|
8
|
+
exports.getCustomHeaders = getCustomHeaders;
|
|
8
9
|
exports.getSdkLogEndpoint = getSdkLogEndpoint;
|
|
9
10
|
exports.getWhiteListUrls = getWhiteListUrls;
|
|
11
|
+
exports.normalizeUrl = normalizeUrl;
|
|
10
12
|
exports.restoreXhr = restoreXhr;
|
|
11
13
|
exports.setBlackListUrls = setBlackListUrls;
|
|
12
14
|
exports.setCustomHeaders = setCustomHeaders;
|
|
15
|
+
exports.setNetErrorTrigger = setNetErrorTrigger;
|
|
13
16
|
exports.setSdkLogEndpoint = setSdkLogEndpoint;
|
|
14
17
|
exports.setWhiteListUrls = setWhiteListUrls;
|
|
15
18
|
exports.shouldRecordUrl = shouldRecordUrl;
|
|
16
19
|
exports.watchXhr = watchXhr;
|
|
20
|
+
var _rrweb = require("rrweb");
|
|
21
|
+
var _config = require("./config");
|
|
22
|
+
var _logger = _interopRequireDefault(require("./logger"));
|
|
23
|
+
var _constants = require("./constants");
|
|
24
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
25
|
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
18
26
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
19
27
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
@@ -28,9 +36,17 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
28
36
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
29
37
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
30
38
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
31
|
-
//
|
|
32
|
-
var
|
|
33
|
-
|
|
39
|
+
// 错误触发器引用(错误采集模式下由 init.ts 注入)
|
|
40
|
+
var errorTriggerInstance = null;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 设置网络模块的错误触发器实例
|
|
44
|
+
*/
|
|
45
|
+
function setNetErrorTrigger(trigger) {
|
|
46
|
+
errorTriggerInstance = trigger;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// 根据业务需求配置的黑名单和需要提取的响应头字段,已从 constants.ts 导入
|
|
34
50
|
|
|
35
51
|
// 定义白名单URL列表和自定义请求头
|
|
36
52
|
// 默认白名单为空,不抓取任何请求,需要用户手动配置
|
|
@@ -45,9 +61,6 @@ var blackListUrls = [
|
|
|
45
61
|
// SDK日志上报接口地址
|
|
46
62
|
var sdkLogEndpoint = null;
|
|
47
63
|
|
|
48
|
-
// 需要提取的响应头字段
|
|
49
|
-
var HEADERS_TO_EXTRACT = ['sky_trace_id', 'antbank-traceid'];
|
|
50
|
-
|
|
51
64
|
// 辅助函数:规范化URL路径
|
|
52
65
|
function normalizeUrl(url) {
|
|
53
66
|
try {
|
|
@@ -98,9 +111,9 @@ function isUrlInBlacklist(url, blacklist) {
|
|
|
98
111
|
var urlObj = new URL(normalizedUrl);
|
|
99
112
|
var pathname = urlObj.pathname;
|
|
100
113
|
var hostname = urlObj.hostname;
|
|
101
|
-
if (BLACK_HOST_NAME.some(function (v) {
|
|
114
|
+
if (_constants.BLACK_HOST_NAME.some(function (v) {
|
|
102
115
|
return hostname.includes(v);
|
|
103
|
-
}) || BLACK_PATH_NAME.some(function (v) {
|
|
116
|
+
}) || _constants.BLACK_PATH_NAME.some(function (v) {
|
|
104
117
|
return pathname.includes(v);
|
|
105
118
|
})) {
|
|
106
119
|
return true;
|
|
@@ -141,7 +154,7 @@ function isUrlInBlacklist(url, blacklist) {
|
|
|
141
154
|
function shouldRecordUrl(url) {
|
|
142
155
|
// 如果URL在黑名单中,直接返回false
|
|
143
156
|
if (isUrlInBlacklist(url, blackListUrls)) {
|
|
144
|
-
//
|
|
157
|
+
// logger.log(`[Blacklist] ${url} - Skipped (in blacklist)`);
|
|
145
158
|
|
|
146
159
|
return false;
|
|
147
160
|
}
|
|
@@ -155,6 +168,28 @@ function shouldRecordUrl(url) {
|
|
|
155
168
|
return isUrlInWhitelist(url, whiteListUrls);
|
|
156
169
|
}
|
|
157
170
|
|
|
171
|
+
// 网络状态变化事件处理
|
|
172
|
+
function handleOnline() {
|
|
173
|
+
try {
|
|
174
|
+
_rrweb.record.addCustomEvent(_constants.EVENT_NETWORK_STATUS, {
|
|
175
|
+
type: 'NETWORK_ONLINE',
|
|
176
|
+
timestamp: Date.now()
|
|
177
|
+
});
|
|
178
|
+
} catch (error) {
|
|
179
|
+
_logger.default.warn('Failed to add NETWORK_ONLINE event (recording may have stopped)', error);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
function handleOffline() {
|
|
183
|
+
try {
|
|
184
|
+
_rrweb.record.addCustomEvent(_constants.EVENT_NETWORK_STATUS, {
|
|
185
|
+
type: 'NETWORK_OFFLINE',
|
|
186
|
+
timestamp: Date.now()
|
|
187
|
+
});
|
|
188
|
+
} catch (error) {
|
|
189
|
+
_logger.default.warn('Failed to add NETWORK_OFFLINE event (recording may have stopped)', error);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
158
193
|
// 存储原始方法
|
|
159
194
|
var origOpen = XMLHttpRequest.prototype.open;
|
|
160
195
|
var origSend = XMLHttpRequest.prototype.send;
|
|
@@ -164,164 +199,269 @@ var origFetch = window.fetch;
|
|
|
164
199
|
var isHooked = false;
|
|
165
200
|
function watchXhr(r) {
|
|
166
201
|
if (isHooked) {
|
|
167
|
-
|
|
202
|
+
_logger.default.warn('Network monitoring is already active');
|
|
168
203
|
return;
|
|
169
204
|
}
|
|
170
|
-
console.log('RLog Network monitoring is active');
|
|
171
205
|
isHooked = true;
|
|
172
206
|
// 拦截XMLHttpRequest
|
|
173
207
|
XMLHttpRequest.prototype.open = function (method, url) {
|
|
174
208
|
var async = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
175
209
|
var username = arguments.length > 3 ? arguments[3] : undefined;
|
|
176
210
|
var password = arguments.length > 4 ? arguments[4] : undefined;
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
211
|
+
try {
|
|
212
|
+
// 保存请求信息
|
|
213
|
+
this._rlogRequest = {
|
|
214
|
+
method: method,
|
|
215
|
+
url: url.toString(),
|
|
216
|
+
startTime: 0,
|
|
217
|
+
endTime: 0
|
|
218
|
+
};
|
|
219
|
+
} catch (error) {
|
|
220
|
+
_logger.default.warn('Failed to save XHR request info:', error);
|
|
221
|
+
}
|
|
184
222
|
|
|
185
|
-
// 调用原始open
|
|
223
|
+
// 调用原始open方法(不能被 SDK 异常影响)
|
|
186
224
|
return origOpen.apply(this, [method, url, async, username, password]);
|
|
187
225
|
};
|
|
188
226
|
XMLHttpRequest.prototype.send = function (body) {
|
|
189
227
|
var _this = this;
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
// 添加自定义请求头
|
|
195
|
-
Object.entries(customHeaders).forEach(function (_ref) {
|
|
196
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
|
197
|
-
key = _ref2[0],
|
|
198
|
-
value = _ref2[1];
|
|
199
|
-
_this.setRequestHeader(key, value);
|
|
200
|
-
});
|
|
228
|
+
try {
|
|
229
|
+
var requestInfo = this._rlogRequest;
|
|
230
|
+
if (requestInfo) {
|
|
231
|
+
requestInfo.startTime = Date.now();
|
|
201
232
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
var _this2 = this;
|
|
205
|
-
requestInfo.endTime = Date.now();
|
|
206
|
-
// 检查是否应该记录该URL
|
|
207
|
-
if (shouldRecordUrl(requestInfo.url)) {
|
|
208
|
-
// 提取指定响应头字段
|
|
209
|
-
var responseHeaders = {};
|
|
210
|
-
HEADERS_TO_EXTRACT.forEach(function (headerName) {
|
|
233
|
+
// 仅对白名单中的URL添加自定义请求头,避免跨域请求因非标准头触发CORS preflight失败
|
|
234
|
+
if (shouldRecordUrl(requestInfo.url)) {
|
|
211
235
|
try {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
236
|
+
Object.entries(customHeaders).forEach(function (_ref) {
|
|
237
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
238
|
+
key = _ref2[0],
|
|
239
|
+
value = _ref2[1];
|
|
240
|
+
_this.setRequestHeader(key, value);
|
|
241
|
+
});
|
|
242
|
+
} catch (error) {
|
|
243
|
+
_logger.default.warn('Failed to set custom headers on XHR:', error);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// 监听请求完成
|
|
248
|
+
this.addEventListener('load', function () {
|
|
249
|
+
var _this2 = this;
|
|
250
|
+
try {
|
|
251
|
+
requestInfo.endTime = Date.now();
|
|
252
|
+
// 检查是否应该记录该URL
|
|
253
|
+
if (shouldRecordUrl(requestInfo.url)) {
|
|
254
|
+
// 提取指定响应头字段
|
|
255
|
+
var responseHeaders = {};
|
|
256
|
+
_constants.HEADERS_TO_EXTRACT.forEach(function (headerName) {
|
|
257
|
+
try {
|
|
258
|
+
var value = _this2.getResponseHeader(headerName);
|
|
259
|
+
if (value) {
|
|
260
|
+
responseHeaders[headerName] = value;
|
|
261
|
+
}
|
|
262
|
+
} catch (error) {
|
|
263
|
+
// 忽略无法访问的响应头(如CORS限制)
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
try {
|
|
267
|
+
r.addCustomEvent(_constants.EVENT_HTTP_SUCCESS, _objectSpread(_objectSpread({}, requestInfo), {}, {
|
|
268
|
+
dur: requestInfo.endTime - requestInfo.startTime,
|
|
269
|
+
responseHeaders: responseHeaders,
|
|
270
|
+
pagePath: window.location.href
|
|
271
|
+
}));
|
|
272
|
+
} catch (error) {
|
|
273
|
+
// 忽略录制已停止时的异常
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// 错误采集模式下:检查 HTTP 状态码是否为错误
|
|
278
|
+
if (errorTriggerInstance) {
|
|
279
|
+
var _config$errorCapture$, _config$errorCapture;
|
|
280
|
+
var config = (0, _config.getConfig)();
|
|
281
|
+
var httpErrorThreshold = (_config$errorCapture$ = (_config$errorCapture = config.errorCapture) === null || _config$errorCapture === void 0 ? void 0 : _config$errorCapture.httpErrorThreshold) !== null && _config$errorCapture$ !== void 0 ? _config$errorCapture$ : 400;
|
|
282
|
+
if (this.status >= httpErrorThreshold) {
|
|
283
|
+
errorTriggerInstance.onError({
|
|
284
|
+
type: 'http',
|
|
285
|
+
message: "XHR ".concat(requestInfo.method, " ").concat(requestInfo.url, " responded with status ").concat(this.status),
|
|
286
|
+
timestamp: Date.now(),
|
|
287
|
+
detail: {
|
|
288
|
+
url: requestInfo.url,
|
|
289
|
+
method: requestInfo.method,
|
|
290
|
+
status: this.status
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
}
|
|
215
294
|
}
|
|
216
295
|
} catch (error) {
|
|
217
|
-
|
|
218
|
-
console.warn("\u65E0\u6CD5\u83B7\u53D6\u54CD\u5E94\u5934 ".concat(headerName, ":"), error);
|
|
296
|
+
_logger.default.warn('Error in XHR load handler:', error);
|
|
219
297
|
}
|
|
220
298
|
});
|
|
221
|
-
try {
|
|
222
|
-
r.addCustomEvent('http-success', _objectSpread(_objectSpread({}, requestInfo), {}, {
|
|
223
|
-
dur: requestInfo.endTime - requestInfo.startTime,
|
|
224
|
-
responseHeaders: responseHeaders,
|
|
225
|
-
pagePath: window.location.href
|
|
226
|
-
}));
|
|
227
|
-
} catch (error) {
|
|
228
|
-
// 忽略录制已停止时的异常
|
|
229
|
-
console.warn('Failed to add custom event (recording may have stopped):', error);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
299
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
300
|
+
// 监听请求错误
|
|
301
|
+
this.addEventListener('error', function () {
|
|
302
|
+
try {
|
|
303
|
+
r.addCustomEvent(_constants.EVENT_HTTP_ERROR, _objectSpread(_objectSpread({}, requestInfo), {}, {
|
|
304
|
+
dur: requestInfo.endTime - requestInfo.startTime,
|
|
305
|
+
pagePath: window.location.href
|
|
306
|
+
}));
|
|
307
|
+
} catch (error) {
|
|
308
|
+
// 忽略录制已停止时的异常
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// 错误采集模式下:XHR 网络错误触发
|
|
312
|
+
try {
|
|
313
|
+
if (errorTriggerInstance) {
|
|
314
|
+
errorTriggerInstance.onError({
|
|
315
|
+
type: 'http',
|
|
316
|
+
message: "XHR ".concat(requestInfo.method, " ").concat(requestInfo.url, " network error"),
|
|
317
|
+
timestamp: Date.now(),
|
|
318
|
+
detail: {
|
|
319
|
+
url: requestInfo.url,
|
|
320
|
+
method: requestInfo.method
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
} catch (error) {
|
|
325
|
+
_logger.default.warn('Error in XHR error trigger:', error);
|
|
326
|
+
}
|
|
327
|
+
});
|
|
244
328
|
}
|
|
245
|
-
})
|
|
329
|
+
} catch (error) {
|
|
330
|
+
_logger.default.warn('Error in XHR send hook:', error);
|
|
331
|
+
}
|
|
246
332
|
|
|
247
|
-
// 调用原始send
|
|
333
|
+
// 调用原始send方法(不能被 SDK 异常影响)
|
|
248
334
|
return origSend.apply(this, [body]);
|
|
249
335
|
};
|
|
250
336
|
|
|
251
337
|
// 拦截fetch API
|
|
252
338
|
window.fetch = /*#__PURE__*/function () {
|
|
253
339
|
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(input, init) {
|
|
254
|
-
var url, method, startTime,
|
|
340
|
+
var url, method, startTime, actualInit, response, endTime, responseHeaders, _config$errorCapture$2, _config$errorCapture2, config, httpErrorThreshold;
|
|
255
341
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
256
342
|
while (1) switch (_context.prev = _context.next) {
|
|
257
343
|
case 0:
|
|
344
|
+
_context.prev = 0;
|
|
258
345
|
url = input instanceof Request ? input.url : input.toString();
|
|
259
|
-
method = (init === null || init === void 0 ? void 0 : init.method) || (input instanceof Request ? input.method : 'GET').toUpperCase();
|
|
260
|
-
startTime = Date.now();
|
|
261
|
-
_context.prev = 3;
|
|
262
|
-
// 创建新的请求配置
|
|
263
|
-
newInit = _objectSpread({}, init); // 添加自定义请求头
|
|
264
|
-
newInit.headers = _objectSpread(_objectSpread({}, (init === null || init === void 0 ? void 0 : init.headers) || {}), customHeaders);
|
|
346
|
+
method = (init === null || init === void 0 ? void 0 : init.method) || (input instanceof Request ? input.method : 'GET').toUpperCase();
|
|
265
347
|
_context.next = 8;
|
|
266
|
-
|
|
348
|
+
break;
|
|
349
|
+
case 5:
|
|
350
|
+
_context.prev = 5;
|
|
351
|
+
_context.t0 = _context["catch"](0);
|
|
352
|
+
return _context.abrupt("return", origFetch(input, init));
|
|
267
353
|
case 8:
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
responseHeaders = {};
|
|
275
|
-
HEADERS_TO_EXTRACT.forEach(function (headerName) {
|
|
276
|
-
try {
|
|
277
|
-
var value = response.headers.get(headerName);
|
|
278
|
-
if (value) {
|
|
279
|
-
responseHeaders[headerName] = value;
|
|
280
|
-
}
|
|
281
|
-
} catch (error) {
|
|
282
|
-
// 忽略无法访问的响应头(如CORS限制)
|
|
283
|
-
console.warn("\u65E0\u6CD5\u83B7\u53D6\u54CD\u5E94\u5934 ".concat(headerName, ":"), error);
|
|
284
|
-
}
|
|
285
|
-
});
|
|
286
|
-
try {
|
|
287
|
-
r.addCustomEvent('http-success', {
|
|
288
|
-
url: url,
|
|
289
|
-
method: method,
|
|
290
|
-
dur: endTime - startTime,
|
|
291
|
-
responseHeaders: responseHeaders,
|
|
292
|
-
pagePath: window.location.href
|
|
354
|
+
startTime = Date.now(); // 构建请求参数,仅对白名单 URL 添加自定义头
|
|
355
|
+
actualInit = init;
|
|
356
|
+
try {
|
|
357
|
+
if (shouldRecordUrl(url) && Object.keys(customHeaders).length > 0) {
|
|
358
|
+
actualInit = _objectSpread(_objectSpread({}, init), {}, {
|
|
359
|
+
headers: _objectSpread(_objectSpread({}, (init === null || init === void 0 ? void 0 : init.headers) || {}), customHeaders)
|
|
293
360
|
});
|
|
294
|
-
} catch (error) {
|
|
295
|
-
// 忽略录制已停止时的异常
|
|
296
|
-
console.warn('Failed to add custom event (recording may have stopped):', error);
|
|
297
361
|
}
|
|
362
|
+
} catch (error) {
|
|
363
|
+
_logger.default.warn('Failed to add custom headers on Fetch:', error);
|
|
364
|
+
actualInit = init;
|
|
298
365
|
}
|
|
299
|
-
|
|
366
|
+
_context.prev = 11;
|
|
367
|
+
_context.next = 14;
|
|
368
|
+
return origFetch(input, actualInit);
|
|
300
369
|
case 14:
|
|
301
|
-
|
|
302
|
-
_context.
|
|
303
|
-
|
|
370
|
+
response = _context.sent;
|
|
371
|
+
_context.next = 22;
|
|
372
|
+
break;
|
|
373
|
+
case 17:
|
|
374
|
+
_context.prev = 17;
|
|
375
|
+
_context.t1 = _context["catch"](11);
|
|
376
|
+
// Fetch 网络错误:先做 SDK 记录,再原样抛出给业务
|
|
304
377
|
try {
|
|
305
|
-
r.addCustomEvent(
|
|
378
|
+
r.addCustomEvent(_constants.EVENT_HTTP_ERROR, {
|
|
306
379
|
url: url,
|
|
307
380
|
method: method,
|
|
308
381
|
pagePath: window.location.href
|
|
309
382
|
});
|
|
310
|
-
} catch (
|
|
311
|
-
//
|
|
312
|
-
console.warn('Failed to add custom event (recording may have stopped):', eventError);
|
|
383
|
+
} catch (_) {
|
|
384
|
+
// 忽略录制异常
|
|
313
385
|
}
|
|
314
|
-
|
|
315
|
-
|
|
386
|
+
try {
|
|
387
|
+
if (errorTriggerInstance) {
|
|
388
|
+
errorTriggerInstance.onError({
|
|
389
|
+
type: 'http',
|
|
390
|
+
message: "Fetch ".concat(method, " ").concat(url, " network error"),
|
|
391
|
+
timestamp: Date.now(),
|
|
392
|
+
detail: {
|
|
393
|
+
url: url,
|
|
394
|
+
method: method,
|
|
395
|
+
error: String(_context.t1)
|
|
396
|
+
}
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
} catch (_) {
|
|
400
|
+
// 忽略错误触发器异常
|
|
401
|
+
}
|
|
402
|
+
throw _context.t1;
|
|
403
|
+
case 22:
|
|
404
|
+
// 请求成功后的 SDK 记录逻辑,全部 try/catch 保护
|
|
405
|
+
try {
|
|
406
|
+
endTime = Date.now();
|
|
407
|
+
if (shouldRecordUrl(url)) {
|
|
408
|
+
responseHeaders = {};
|
|
409
|
+
_constants.HEADERS_TO_EXTRACT.forEach(function (headerName) {
|
|
410
|
+
try {
|
|
411
|
+
var value = response.headers.get(headerName);
|
|
412
|
+
if (value) {
|
|
413
|
+
responseHeaders[headerName] = value;
|
|
414
|
+
}
|
|
415
|
+
} catch (_) {
|
|
416
|
+
// 忽略无法访问的响应头
|
|
417
|
+
}
|
|
418
|
+
});
|
|
419
|
+
try {
|
|
420
|
+
r.addCustomEvent(_constants.EVENT_HTTP_SUCCESS, {
|
|
421
|
+
url: url,
|
|
422
|
+
method: method,
|
|
423
|
+
dur: endTime - startTime,
|
|
424
|
+
responseHeaders: responseHeaders,
|
|
425
|
+
pagePath: window.location.href
|
|
426
|
+
});
|
|
427
|
+
} catch (_) {
|
|
428
|
+
// 忽略录制异常
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
if (errorTriggerInstance) {
|
|
432
|
+
config = (0, _config.getConfig)();
|
|
433
|
+
httpErrorThreshold = (_config$errorCapture$2 = (_config$errorCapture2 = config.errorCapture) === null || _config$errorCapture2 === void 0 ? void 0 : _config$errorCapture2.httpErrorThreshold) !== null && _config$errorCapture$2 !== void 0 ? _config$errorCapture$2 : 400;
|
|
434
|
+
if (response.status >= httpErrorThreshold) {
|
|
435
|
+
errorTriggerInstance.onError({
|
|
436
|
+
type: 'http',
|
|
437
|
+
message: "Fetch ".concat(method, " ").concat(url, " responded with status ").concat(response.status),
|
|
438
|
+
timestamp: Date.now(),
|
|
439
|
+
detail: {
|
|
440
|
+
url: url,
|
|
441
|
+
method: method,
|
|
442
|
+
status: response.status
|
|
443
|
+
}
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
} catch (error) {
|
|
448
|
+
_logger.default.warn('Error in Fetch success handler:', error);
|
|
449
|
+
}
|
|
450
|
+
return _context.abrupt("return", response);
|
|
451
|
+
case 24:
|
|
316
452
|
case "end":
|
|
317
453
|
return _context.stop();
|
|
318
454
|
}
|
|
319
|
-
}, _callee, null, [[
|
|
455
|
+
}, _callee, null, [[0, 5], [11, 17]]);
|
|
320
456
|
}));
|
|
321
457
|
return function (_x, _x2) {
|
|
322
458
|
return _ref3.apply(this, arguments);
|
|
323
459
|
};
|
|
324
460
|
}();
|
|
461
|
+
|
|
462
|
+
// 监听网络连接状态变化
|
|
463
|
+
window.addEventListener('online', handleOnline);
|
|
464
|
+
window.addEventListener('offline', handleOffline);
|
|
325
465
|
}
|
|
326
466
|
|
|
327
467
|
// 恢复原始方法
|
|
@@ -335,8 +475,11 @@ function restoreXhr() {
|
|
|
335
475
|
if (origFetch) {
|
|
336
476
|
window.fetch = origFetch;
|
|
337
477
|
}
|
|
478
|
+
|
|
479
|
+
// 移除网络状态监听器
|
|
480
|
+
window.removeEventListener('online', handleOnline);
|
|
481
|
+
window.removeEventListener('offline', handleOffline);
|
|
338
482
|
isHooked = false;
|
|
339
|
-
console.log('RLog network monitoring restored');
|
|
340
483
|
}
|
|
341
484
|
|
|
342
485
|
// 导出配置方法
|
|
@@ -383,7 +526,7 @@ function setSdkLogEndpoint(endpoint) {
|
|
|
383
526
|
sdkLogEndpoint = endpoint;
|
|
384
527
|
|
|
385
528
|
// 规范化endpoint路径,确保相对路径也能正确匹配
|
|
386
|
-
var normalizedEndpoint = endpoint
|
|
529
|
+
var normalizedEndpoint = normalizeUrl(endpoint);
|
|
387
530
|
|
|
388
531
|
// 自动将SDK日志上报接口加入黑名单,避免循环上报
|
|
389
532
|
// 同时添加原始路径和规范化路径,确保兼容性
|
|
@@ -413,4 +556,12 @@ function getSdkLogEndpoint() {
|
|
|
413
556
|
*/
|
|
414
557
|
function setCustomHeaders(headers) {
|
|
415
558
|
Object.assign(customHeaders, headers);
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* 获取当前设置的自定义请求头
|
|
563
|
+
* @returns 当前自定义请求头的副本
|
|
564
|
+
*/
|
|
565
|
+
function getCustomHeaders() {
|
|
566
|
+
return _objectSpread({}, customHeaders);
|
|
416
567
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../../src/lib/request.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../../src/lib/request.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,GAAG,CAAC;IACV,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC;IACrB,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CACzB;AAED;;;;;GAKG;AACH,wBAAsB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAwE1F;AAED;;;;;GAKG;AACH,wBAAsB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,IAAI,CAAC,cAAc,EAAE,QAAQ,GAAG,MAAM,CAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAE/G;AAED;;;;;;GAMG;AACH,wBAAsB,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,OAAO,GAAE,IAAI,CAAC,cAAc,EAAE,QAAQ,CAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAEnH"}
|
package/dist/lib/lib/request.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.get = get;
|
|
7
7
|
exports.post = post;
|
|
8
8
|
exports.request = request;
|
|
9
|
+
var _constants = require("./constants");
|
|
9
10
|
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
11
|
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
12
|
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; }
|
|
@@ -14,8 +15,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
14
15
|
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
15
16
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
16
17
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
17
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
18
|
-
// 简单的 XMLHttpRequest 封装,提供更好的兼容性
|
|
18
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } // 简单的 XMLHttpRequest 封装,提供更好的兼容性
|
|
19
19
|
/**
|
|
20
20
|
* 发送 HTTP 请求
|
|
21
21
|
* @param url 请求地址
|
|
@@ -46,7 +46,7 @@ function _request() {
|
|
|
46
46
|
headers = _options$headers === void 0 ? {} : _options$headers,
|
|
47
47
|
body = options.body,
|
|
48
48
|
_options$timeout = options.timeout,
|
|
49
|
-
timeout = _options$timeout === void 0 ?
|
|
49
|
+
timeout = _options$timeout === void 0 ? _constants.REQUEST_TIMEOUT : _options$timeout;
|
|
50
50
|
var xhr = new XMLHttpRequest();
|
|
51
51
|
|
|
52
52
|
// 设置超时
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router-monitor.d.ts","sourceRoot":"","sources":["../../../src/lib/router-monitor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,KAAK,SAAS,EAAa,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"router-monitor.d.ts","sourceRoot":"","sources":["../../../src/lib/router-monitor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,KAAK,SAAS,EAAa,MAAM,UAAU,CAAC;AAKrD,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,cAAc,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,WAAW,GAAG,cAAc,GAAG,UAAU,GAAG,YAAY,CAAC;IACjE,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAoJD;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,SAAS,CAAC,eAAe,CAAC,GAAG,IAAI,CAuB3E;AAuFD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC,eAAe,CAAC,QA0CpE;AAED;;GAEG;AACH,wBAAgB,mBAAmB;;;;EAMlC;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,QAG1D;AAED;;GAEG;AACH,wBAAgB,iBAAiB,SA4BhC"}
|