@antglobal/rlog-sdk 0.0.1779194445-dev.0 → 0.0.1781493462-dev.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/esm/lib/api.d.ts.map +1 -1
- package/dist/esm/lib/api.js +27 -16
- package/dist/esm/lib/config.d.ts +1 -1
- package/dist/esm/lib/config.d.ts.map +1 -1
- package/dist/esm/lib/config.js +2 -2
- package/dist/esm/lib/constants.d.ts +10 -2
- package/dist/esm/lib/constants.d.ts.map +1 -1
- package/dist/esm/lib/constants.js +16 -2
- package/dist/esm/lib/rrweb.d.ts.map +1 -1
- package/dist/esm/lib/rrweb.js +14 -10
- package/dist/esm/lib/sign.d.ts +36 -0
- package/dist/esm/lib/sign.d.ts.map +1 -0
- package/dist/esm/lib/sign.js +393 -0
- package/dist/esm/lib/upload-worker-manager.d.ts.map +1 -1
- package/dist/esm/lib/upload-worker-manager.js +20 -9
- package/dist/esm/lib/utils.d.ts +5 -0
- package/dist/esm/lib/utils.d.ts.map +1 -1
- package/dist/esm/lib/utils.js +10 -2
- package/dist/lib/lib/api.d.ts.map +1 -1
- package/dist/lib/lib/api.js +27 -16
- package/dist/lib/lib/config.d.ts +1 -1
- package/dist/lib/lib/config.d.ts.map +1 -1
- package/dist/lib/lib/config.js +2 -2
- package/dist/lib/lib/constants.d.ts +10 -2
- package/dist/lib/lib/constants.d.ts.map +1 -1
- package/dist/lib/lib/constants.js +17 -3
- package/dist/lib/lib/rrweb.d.ts.map +1 -1
- package/dist/lib/lib/rrweb.js +12 -10
- package/dist/lib/lib/sign.d.ts +36 -0
- package/dist/lib/lib/sign.d.ts.map +1 -0
- package/dist/lib/lib/sign.js +398 -0
- package/dist/lib/lib/upload-worker-manager.d.ts.map +1 -1
- package/dist/lib/lib/upload-worker-manager.js +20 -9
- package/dist/lib/lib/utils.d.ts +5 -0
- package/dist/lib/lib/utils.d.ts.map +1 -1
- package/dist/lib/lib/utils.js +10 -2
- package/dist/rlog-sdk.min.js +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
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); }
|
|
2
|
+
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; }
|
|
3
|
+
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; }
|
|
4
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
5
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
6
|
+
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); } }
|
|
7
|
+
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); }); }; }
|
|
8
|
+
/**
|
|
9
|
+
* 上报接口加签模块
|
|
10
|
+
*
|
|
11
|
+
* 签名算法:
|
|
12
|
+
* 1. md5 = MD5(rrweb 录制的 JSON 数据)
|
|
13
|
+
* 2. ts = Date.now()
|
|
14
|
+
* 3. secret = MD5(md5 + ts) — 一次性签名密钥
|
|
15
|
+
* 4. sign = HMAC-SHA256(encodeURIComponent(sortedParams) + md5 + ts, secret)
|
|
16
|
+
*
|
|
17
|
+
* 请求头:
|
|
18
|
+
* x-bk-sign = sign
|
|
19
|
+
* x-bk-ts = ts
|
|
20
|
+
* x-bk-dm = md5
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { HEADER_SIGN, HEADER_TIMESTAMP, HEADER_MD5 } from "./constants";
|
|
24
|
+
|
|
25
|
+
// ==================== MD5 实现 ====================
|
|
26
|
+
|
|
27
|
+
function safeAdd(x, y) {
|
|
28
|
+
var lsw = (x & 0xffff) + (y & 0xffff);
|
|
29
|
+
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
|
|
30
|
+
return msw << 16 | lsw & 0xffff;
|
|
31
|
+
}
|
|
32
|
+
function bitRotateLeft(num, cnt) {
|
|
33
|
+
return num << cnt | num >>> 32 - cnt;
|
|
34
|
+
}
|
|
35
|
+
function md5cmn(q, a, b, x, s, t) {
|
|
36
|
+
return safeAdd(bitRotateLeft(safeAdd(safeAdd(a, q), safeAdd(x, t)), s), b);
|
|
37
|
+
}
|
|
38
|
+
function md5ff(a, b, c, d, x, s, t) {
|
|
39
|
+
return md5cmn(b & c | ~b & d, a, b, x, s, t);
|
|
40
|
+
}
|
|
41
|
+
function md5gg(a, b, c, d, x, s, t) {
|
|
42
|
+
return md5cmn(b & d | c & ~d, a, b, x, s, t);
|
|
43
|
+
}
|
|
44
|
+
function md5hh(a, b, c, d, x, s, t) {
|
|
45
|
+
return md5cmn(b ^ c ^ d, a, b, x, s, t);
|
|
46
|
+
}
|
|
47
|
+
function md5ii(a, b, c, d, x, s, t) {
|
|
48
|
+
return md5cmn(c ^ (b | ~d), a, b, x, s, t);
|
|
49
|
+
}
|
|
50
|
+
function binlMD5(x, len) {
|
|
51
|
+
x[len >> 5] |= 0x80 << len % 32;
|
|
52
|
+
x[(len + 64 >>> 9 << 4) + 14] = len;
|
|
53
|
+
var a = 1732584193;
|
|
54
|
+
var b = -271733879;
|
|
55
|
+
var c = -1732584194;
|
|
56
|
+
var d = 271733878;
|
|
57
|
+
for (var i = 0; i < x.length; i += 16) {
|
|
58
|
+
var olda = a;
|
|
59
|
+
var oldb = b;
|
|
60
|
+
var oldc = c;
|
|
61
|
+
var oldd = d;
|
|
62
|
+
a = md5ff(a, b, c, d, x[i], 7, -680876936);
|
|
63
|
+
d = md5ff(d, a, b, c, x[i + 1], 12, -389564586);
|
|
64
|
+
c = md5ff(c, d, a, b, x[i + 2], 17, 606105819);
|
|
65
|
+
b = md5ff(b, c, d, a, x[i + 3], 22, -1044525330);
|
|
66
|
+
a = md5ff(a, b, c, d, x[i + 4], 7, -176418897);
|
|
67
|
+
d = md5ff(d, a, b, c, x[i + 5], 12, 1200080426);
|
|
68
|
+
c = md5ff(c, d, a, b, x[i + 6], 17, -1473231341);
|
|
69
|
+
b = md5ff(b, c, d, a, x[i + 7], 22, -45705983);
|
|
70
|
+
a = md5ff(a, b, c, d, x[i + 8], 7, 1770035416);
|
|
71
|
+
d = md5ff(d, a, b, c, x[i + 9], 12, -1958414417);
|
|
72
|
+
c = md5ff(c, d, a, b, x[i + 10], 17, -42063);
|
|
73
|
+
b = md5ff(b, c, d, a, x[i + 11], 22, -1990404162);
|
|
74
|
+
a = md5ff(a, b, c, d, x[i + 12], 7, 1804603682);
|
|
75
|
+
d = md5ff(d, a, b, c, x[i + 13], 12, -40341101);
|
|
76
|
+
c = md5ff(c, d, a, b, x[i + 14], 17, -1502002290);
|
|
77
|
+
b = md5ff(b, c, d, a, x[i + 15], 22, 1236535329);
|
|
78
|
+
a = md5gg(a, b, c, d, x[i + 1], 5, -165796510);
|
|
79
|
+
d = md5gg(d, a, b, c, x[i + 6], 9, -1069501632);
|
|
80
|
+
c = md5gg(c, d, a, b, x[i + 11], 14, 643717713);
|
|
81
|
+
b = md5gg(b, c, d, a, x[i], 20, -373897302);
|
|
82
|
+
a = md5gg(a, b, c, d, x[i + 5], 5, -701558691);
|
|
83
|
+
d = md5gg(d, a, b, c, x[i + 10], 9, 38016083);
|
|
84
|
+
c = md5gg(c, d, a, b, x[i + 15], 14, -660478335);
|
|
85
|
+
b = md5gg(b, c, d, a, x[i + 4], 20, -405537848);
|
|
86
|
+
a = md5gg(a, b, c, d, x[i + 9], 5, 568446438);
|
|
87
|
+
d = md5gg(d, a, b, c, x[i + 14], 9, -1019803690);
|
|
88
|
+
c = md5gg(c, d, a, b, x[i + 3], 14, -187363961);
|
|
89
|
+
b = md5gg(b, c, d, a, x[i + 8], 20, 1163531501);
|
|
90
|
+
a = md5gg(a, b, c, d, x[i + 13], 5, -1444681467);
|
|
91
|
+
d = md5gg(d, a, b, c, x[i + 2], 9, -51403784);
|
|
92
|
+
c = md5gg(c, d, a, b, x[i + 7], 14, 1735328473);
|
|
93
|
+
b = md5gg(b, c, d, a, x[i + 12], 20, -1926607734);
|
|
94
|
+
a = md5hh(a, b, c, d, x[i + 5], 4, -378558);
|
|
95
|
+
d = md5hh(d, a, b, c, x[i + 8], 11, -2022574463);
|
|
96
|
+
c = md5hh(c, d, a, b, x[i + 11], 16, 1839030562);
|
|
97
|
+
b = md5hh(b, c, d, a, x[i + 14], 23, -35309556);
|
|
98
|
+
a = md5hh(a, b, c, d, x[i + 1], 4, -1530992060);
|
|
99
|
+
d = md5hh(d, a, b, c, x[i + 4], 11, 1272893353);
|
|
100
|
+
c = md5hh(c, d, a, b, x[i + 7], 16, -155497632);
|
|
101
|
+
b = md5hh(b, c, d, a, x[i + 10], 23, -1094730640);
|
|
102
|
+
a = md5hh(a, b, c, d, x[i + 13], 4, 681279174);
|
|
103
|
+
d = md5hh(d, a, b, c, x[i], 11, -358537222);
|
|
104
|
+
c = md5hh(c, d, a, b, x[i + 3], 16, -722521979);
|
|
105
|
+
b = md5hh(b, c, d, a, x[i + 6], 23, 76029189);
|
|
106
|
+
a = md5hh(a, b, c, d, x[i + 9], 4, -640364487);
|
|
107
|
+
d = md5hh(d, a, b, c, x[i + 12], 11, -421815835);
|
|
108
|
+
c = md5hh(c, d, a, b, x[i + 15], 16, 530742520);
|
|
109
|
+
b = md5hh(b, c, d, a, x[i + 2], 23, -995338651);
|
|
110
|
+
a = md5ii(a, b, c, d, x[i], 6, -198630844);
|
|
111
|
+
d = md5ii(d, a, b, c, x[i + 7], 10, 1126891415);
|
|
112
|
+
c = md5ii(c, d, a, b, x[i + 14], 15, -1416354905);
|
|
113
|
+
b = md5ii(b, c, d, a, x[i + 5], 21, -57434055);
|
|
114
|
+
a = md5ii(a, b, c, d, x[i + 12], 6, 1700485571);
|
|
115
|
+
d = md5ii(d, a, b, c, x[i + 3], 10, -1894986606);
|
|
116
|
+
c = md5ii(c, d, a, b, x[i + 10], 15, -1051523);
|
|
117
|
+
b = md5ii(b, c, d, a, x[i + 1], 21, -2054922799);
|
|
118
|
+
a = md5ii(a, b, c, d, x[i + 8], 6, 1873313359);
|
|
119
|
+
d = md5ii(d, a, b, c, x[i + 15], 10, -30611744);
|
|
120
|
+
c = md5ii(c, d, a, b, x[i + 6], 15, -1560198380);
|
|
121
|
+
b = md5ii(b, c, d, a, x[i + 13], 21, 1309151649);
|
|
122
|
+
a = md5ii(a, b, c, d, x[i + 4], 6, -145523070);
|
|
123
|
+
d = md5ii(d, a, b, c, x[i + 11], 10, -1120210379);
|
|
124
|
+
c = md5ii(c, d, a, b, x[i + 2], 15, 718787259);
|
|
125
|
+
b = md5ii(b, c, d, a, x[i + 9], 21, -343485551);
|
|
126
|
+
a = safeAdd(a, olda);
|
|
127
|
+
b = safeAdd(b, oldb);
|
|
128
|
+
c = safeAdd(c, oldc);
|
|
129
|
+
d = safeAdd(d, oldd);
|
|
130
|
+
}
|
|
131
|
+
return [a, b, c, d];
|
|
132
|
+
}
|
|
133
|
+
function binl2rstr(input) {
|
|
134
|
+
var output = '';
|
|
135
|
+
for (var i = 0; i < input.length * 32; i += 8) {
|
|
136
|
+
output += String.fromCharCode(input[i >> 5] >>> i % 32 & 0xff);
|
|
137
|
+
}
|
|
138
|
+
return output;
|
|
139
|
+
}
|
|
140
|
+
function rstr2binl(input) {
|
|
141
|
+
var output = [];
|
|
142
|
+
for (var i = 0; i < input.length * 8; i += 32) {
|
|
143
|
+
output[i >> 5] = 0;
|
|
144
|
+
}
|
|
145
|
+
for (var _i = 0; _i < input.length * 8; _i += 8) {
|
|
146
|
+
output[_i >> 5] |= (input.charCodeAt(_i / 8) & 0xff) << _i % 32;
|
|
147
|
+
}
|
|
148
|
+
return output;
|
|
149
|
+
}
|
|
150
|
+
function rstrMD5(s) {
|
|
151
|
+
return binl2rstr(binlMD5(rstr2binl(s), s.length * 8));
|
|
152
|
+
}
|
|
153
|
+
function rstr2hex(input) {
|
|
154
|
+
var hexTab = '0123456789abcdef';
|
|
155
|
+
var output = '';
|
|
156
|
+
for (var i = 0; i < input.length; i++) {
|
|
157
|
+
var x = input.charCodeAt(i);
|
|
158
|
+
output += hexTab.charAt(x >>> 4 & 0x0f) + hexTab.charAt(x & 0x0f);
|
|
159
|
+
}
|
|
160
|
+
return output;
|
|
161
|
+
}
|
|
162
|
+
function str2rstrUTF8(input) {
|
|
163
|
+
return unescape(encodeURIComponent(input));
|
|
164
|
+
}
|
|
165
|
+
export function md5(str) {
|
|
166
|
+
return rstr2hex(rstrMD5(str2rstrUTF8(str)));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// ==================== SHA-256 纯 JS 实现(基于 Uint8Array) ====================
|
|
170
|
+
|
|
171
|
+
var SHA256_K = new Uint32Array([0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2]);
|
|
172
|
+
function rotr(x, n) {
|
|
173
|
+
return (x >>> n | x << 32 - n) >>> 0;
|
|
174
|
+
}
|
|
175
|
+
function sha256Bytes(data) {
|
|
176
|
+
// Pre-processing: adding padding bits
|
|
177
|
+
var len = data.length;
|
|
178
|
+
var bitLen = len * 8;
|
|
179
|
+
|
|
180
|
+
// Append 0x80, then zeros, then 64-bit big-endian length
|
|
181
|
+
var padLen = len % 64 < 56 ? 56 - len % 64 - 1 : 120 - len % 64 - 1;
|
|
182
|
+
var totalLen = len + 1 + padLen + 8;
|
|
183
|
+
var padded = new Uint8Array(totalLen);
|
|
184
|
+
padded.set(data);
|
|
185
|
+
padded[len] = 0x80;
|
|
186
|
+
|
|
187
|
+
// Big-endian 64-bit length (high 32 bits are 0 for messages < 2^32 bytes)
|
|
188
|
+
padded[totalLen - 4] = bitLen >>> 24 & 0xff;
|
|
189
|
+
padded[totalLen - 3] = bitLen >>> 16 & 0xff;
|
|
190
|
+
padded[totalLen - 2] = bitLen >>> 8 & 0xff;
|
|
191
|
+
padded[totalLen - 1] = bitLen & 0xff;
|
|
192
|
+
|
|
193
|
+
// Initialize hash values
|
|
194
|
+
var h0 = 0x6a09e667 >>> 0;
|
|
195
|
+
var h1 = 0xbb67ae85 >>> 0;
|
|
196
|
+
var h2 = 0x3c6ef372 >>> 0;
|
|
197
|
+
var h3 = 0xa54ff53a >>> 0;
|
|
198
|
+
var h4 = 0x510e527f >>> 0;
|
|
199
|
+
var h5 = 0x9b05688c >>> 0;
|
|
200
|
+
var h6 = 0x1f83d9ab >>> 0;
|
|
201
|
+
var h7 = 0x5be0cd19 >>> 0;
|
|
202
|
+
var w = new Uint32Array(64);
|
|
203
|
+
for (var offset = 0; offset < totalLen; offset += 64) {
|
|
204
|
+
// Create message schedule
|
|
205
|
+
for (var i = 0; i < 16; i++) {
|
|
206
|
+
w[i] = (padded[offset + i * 4] << 24 | padded[offset + i * 4 + 1] << 16 | padded[offset + i * 4 + 2] << 8 | padded[offset + i * 4 + 3]) >>> 0;
|
|
207
|
+
}
|
|
208
|
+
for (var _i2 = 16; _i2 < 64; _i2++) {
|
|
209
|
+
var s0 = (rotr(w[_i2 - 15], 7) ^ rotr(w[_i2 - 15], 18) ^ w[_i2 - 15] >>> 3) >>> 0;
|
|
210
|
+
var s1 = (rotr(w[_i2 - 2], 17) ^ rotr(w[_i2 - 2], 19) ^ w[_i2 - 2] >>> 10) >>> 0;
|
|
211
|
+
w[_i2] = w[_i2 - 16] + s0 + w[_i2 - 7] + s1 >>> 0;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Working variables
|
|
215
|
+
var a = h0,
|
|
216
|
+
b = h1,
|
|
217
|
+
c = h2,
|
|
218
|
+
d = h3,
|
|
219
|
+
e = h4,
|
|
220
|
+
f = h5,
|
|
221
|
+
g = h6,
|
|
222
|
+
h = h7;
|
|
223
|
+
|
|
224
|
+
// Compression
|
|
225
|
+
for (var _i3 = 0; _i3 < 64; _i3++) {
|
|
226
|
+
var S1 = (rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25)) >>> 0;
|
|
227
|
+
var ch = (e & f ^ ~e & g) >>> 0;
|
|
228
|
+
var temp1 = h + S1 + ch + SHA256_K[_i3] + w[_i3] >>> 0;
|
|
229
|
+
var S0 = (rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22)) >>> 0;
|
|
230
|
+
var maj = (a & b ^ a & c ^ b & c) >>> 0;
|
|
231
|
+
var temp2 = S0 + maj >>> 0;
|
|
232
|
+
h = g;
|
|
233
|
+
g = f;
|
|
234
|
+
f = e;
|
|
235
|
+
e = d + temp1 >>> 0;
|
|
236
|
+
d = c;
|
|
237
|
+
c = b;
|
|
238
|
+
b = a;
|
|
239
|
+
a = temp1 + temp2 >>> 0;
|
|
240
|
+
}
|
|
241
|
+
h0 = h0 + a >>> 0;
|
|
242
|
+
h1 = h1 + b >>> 0;
|
|
243
|
+
h2 = h2 + c >>> 0;
|
|
244
|
+
h3 = h3 + d >>> 0;
|
|
245
|
+
h4 = h4 + e >>> 0;
|
|
246
|
+
h5 = h5 + f >>> 0;
|
|
247
|
+
h6 = h6 + g >>> 0;
|
|
248
|
+
h7 = h7 + h >>> 0;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Produce the final hash value (big-endian)
|
|
252
|
+
var hash = new Uint8Array(32);
|
|
253
|
+
var hashView = new DataView(hash.buffer);
|
|
254
|
+
hashView.setUint32(0, h0, false);
|
|
255
|
+
hashView.setUint32(4, h1, false);
|
|
256
|
+
hashView.setUint32(8, h2, false);
|
|
257
|
+
hashView.setUint32(12, h3, false);
|
|
258
|
+
hashView.setUint32(16, h4, false);
|
|
259
|
+
hashView.setUint32(20, h5, false);
|
|
260
|
+
hashView.setUint32(24, h6, false);
|
|
261
|
+
hashView.setUint32(28, h7, false);
|
|
262
|
+
return hash;
|
|
263
|
+
}
|
|
264
|
+
function sha256Hex(data) {
|
|
265
|
+
var hash = sha256Bytes(data);
|
|
266
|
+
return Array.from(hash).map(function (b) {
|
|
267
|
+
return b.toString(16).padStart(2, '0');
|
|
268
|
+
}).join('');
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// ==================== HMAC-SHA256 ====================
|
|
272
|
+
|
|
273
|
+
function hmacSHA256Sync(key, message) {
|
|
274
|
+
// If key > 64 bytes, hash it first
|
|
275
|
+
var k;
|
|
276
|
+
if (key.length > 64) {
|
|
277
|
+
k = sha256Bytes(key);
|
|
278
|
+
var padded = new Uint8Array(64);
|
|
279
|
+
padded.set(k);
|
|
280
|
+
k = padded;
|
|
281
|
+
} else {
|
|
282
|
+
var _padded = new Uint8Array(64);
|
|
283
|
+
_padded.set(key);
|
|
284
|
+
k = _padded;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// Inner hash: SHA-256((k XOR ipad) || message)
|
|
288
|
+
var iPad = new Uint8Array(64);
|
|
289
|
+
var oPad = new Uint8Array(64);
|
|
290
|
+
for (var i = 0; i < 64; i++) {
|
|
291
|
+
iPad[i] = k[i] ^ 0x36;
|
|
292
|
+
oPad[i] = k[i] ^ 0x5c;
|
|
293
|
+
}
|
|
294
|
+
var innerData = new Uint8Array(64 + message.length);
|
|
295
|
+
innerData.set(iPad, 0);
|
|
296
|
+
innerData.set(message, 64);
|
|
297
|
+
var innerHash = sha256Bytes(innerData);
|
|
298
|
+
|
|
299
|
+
// Outer hash: SHA-256((k XOR opad) || innerHash)
|
|
300
|
+
var outerData = new Uint8Array(64 + 32);
|
|
301
|
+
outerData.set(oPad, 0);
|
|
302
|
+
outerData.set(innerHash, 64);
|
|
303
|
+
return sha256Bytes(outerData);
|
|
304
|
+
}
|
|
305
|
+
function uint8ArrayToHex(arr) {
|
|
306
|
+
return Array.from(arr).map(function (b) {
|
|
307
|
+
return b.toString(16).padStart(2, '0');
|
|
308
|
+
}).join('');
|
|
309
|
+
}
|
|
310
|
+
function stringToUint8Array(str) {
|
|
311
|
+
return new TextEncoder().encode(str);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* 计算 HMAC-SHA256
|
|
316
|
+
* 优先使用 Web Crypto API(安全上下文),降级到纯 JS 实现
|
|
317
|
+
*/
|
|
318
|
+
function hmacSHA256(message, key) {
|
|
319
|
+
var subtle = typeof crypto !== 'undefined' && crypto.subtle;
|
|
320
|
+
if (subtle) {
|
|
321
|
+
var encoder = new TextEncoder();
|
|
322
|
+
var keyData = encoder.encode(key);
|
|
323
|
+
var messageData = encoder.encode(message);
|
|
324
|
+
return subtle.importKey('raw', keyData, {
|
|
325
|
+
name: 'HMAC',
|
|
326
|
+
hash: 'SHA-256'
|
|
327
|
+
}, false, ['sign']).then(function (cryptoKey) {
|
|
328
|
+
return subtle.sign('HMAC', cryptoKey, messageData);
|
|
329
|
+
}).then(function (sig) {
|
|
330
|
+
return uint8ArrayToHex(new Uint8Array(sig));
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
// 纯 JS 降级
|
|
334
|
+
var keyBytes = stringToUint8Array(key);
|
|
335
|
+
var msgBytes = stringToUint8Array(message);
|
|
336
|
+
return Promise.resolve(uint8ArrayToHex(hmacSHA256Sync(keyBytes, msgBytes)));
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// ==================== 签名逻辑 ====================
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* 将查询参数按 key 字母序排列并拼接为字符串,过滤空值
|
|
343
|
+
* @param params 查询参数键值对
|
|
344
|
+
* @returns 排序后的参数字符串,如 "appId=xxx&deviceId=yyy&startTime=zzz"
|
|
345
|
+
*/
|
|
346
|
+
export function sortAndConcatParams(params) {
|
|
347
|
+
return Object.keys(params).filter(function (key) {
|
|
348
|
+
return params[key] !== null && params[key] !== '' && params[key] !== undefined;
|
|
349
|
+
}).sort().map(function (key) {
|
|
350
|
+
return "".concat(key, "=").concat(params[key]);
|
|
351
|
+
}).join('&');
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* 计算上报接口的签名请求头
|
|
356
|
+
*
|
|
357
|
+
* 签名流程:
|
|
358
|
+
* 1. md5 = MD5(上报数据的 JSON 字符串)
|
|
359
|
+
* 2. ts = 当前时间戳(毫秒)
|
|
360
|
+
* 3. secret = MD5(md5 + ts) — 一次性签名密钥
|
|
361
|
+
* 4. sign = HMAC-SHA256(encodeURIComponent(sortedParams) + md5 + ts, secret)
|
|
362
|
+
*
|
|
363
|
+
* @param queryParams 查询参数键值对
|
|
364
|
+
* @param jsonData 上报数据的 JSON 字符串
|
|
365
|
+
* @returns 签名请求头 { x-bk-sign, x-bk-ts, x-bk-dm }
|
|
366
|
+
*/
|
|
367
|
+
export function computeSignHeaders(_x, _x2) {
|
|
368
|
+
return _computeSignHeaders.apply(this, arguments);
|
|
369
|
+
}
|
|
370
|
+
function _computeSignHeaders() {
|
|
371
|
+
_computeSignHeaders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(queryParams, jsonData) {
|
|
372
|
+
var contentMd5, timestamp, secret, sortedParams, signContent, sign;
|
|
373
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
374
|
+
while (1) switch (_context.prev = _context.next) {
|
|
375
|
+
case 0:
|
|
376
|
+
contentMd5 = md5(jsonData);
|
|
377
|
+
timestamp = Date.now().toString();
|
|
378
|
+
secret = md5(contentMd5 + timestamp);
|
|
379
|
+
sortedParams = sortAndConcatParams(queryParams);
|
|
380
|
+
signContent = encodeURIComponent(sortedParams) + contentMd5 + timestamp;
|
|
381
|
+
_context.next = 7;
|
|
382
|
+
return hmacSHA256(signContent, secret);
|
|
383
|
+
case 7:
|
|
384
|
+
sign = _context.sent;
|
|
385
|
+
return _context.abrupt("return", _defineProperty(_defineProperty(_defineProperty({}, HEADER_SIGN, sign), HEADER_TIMESTAMP, timestamp), HEADER_MD5, contentMd5));
|
|
386
|
+
case 9:
|
|
387
|
+
case "end":
|
|
388
|
+
return _context.stop();
|
|
389
|
+
}
|
|
390
|
+
}, _callee);
|
|
391
|
+
}));
|
|
392
|
+
return _computeSignHeaders.apply(this, arguments);
|
|
393
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload-worker-manager.d.ts","sourceRoot":"","sources":["../../../src/lib/upload-worker-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAgC,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"upload-worker-manager.d.ts","sourceRoot":"","sources":["../../../src/lib/upload-worker-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAgC,MAAM,iBAAiB,CAAC;AAgDlF;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,GAAG,IAAI,CAE3E;AA8SD;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,GAAG,IAAI,CAE7E;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAwCrE;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,eAAe,UAAQ,GAAG,IAAI,CA6B3D;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,OAAO,CAE3C;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CAAC,SAAS,EAAE,OAAO,GAAG,IAAI,CAQpE;AAED;;GAEG;AACH,wBAAgB,6BAA6B,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAErE;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,IAAI,CAKtE"}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
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); }
|
|
2
2
|
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; }
|
|
3
|
+
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; }
|
|
4
|
+
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; }
|
|
5
|
+
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; }
|
|
6
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
3
8
|
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); } }
|
|
4
9
|
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); }); }; }
|
|
5
10
|
/**
|
|
@@ -19,6 +24,7 @@ import { getDeviceId, getStorageKey } from "./utils";
|
|
|
19
24
|
import { getConfig } from "./config";
|
|
20
25
|
import { buildQueryParams } from "./api";
|
|
21
26
|
import { getCustomHeaders } from "./net";
|
|
27
|
+
import { computeSignHeaders } from "./sign";
|
|
22
28
|
import { record } from 'rrweb';
|
|
23
29
|
import logger from "./logger";
|
|
24
30
|
import { STORAGE_KEY_CONSUME_ONLY, STORAGE_VALUE_CONSUME_ONLY, EVENT_UPLOAD_FAILURE, PULL_BATCH_SIZE, WORKER_READY_TIMEOUT } from "./constants";
|
|
@@ -136,7 +142,7 @@ function handleRequestBatch() {
|
|
|
136
142
|
} // 待处理的批次元数据
|
|
137
143
|
function _handleRequestBatch() {
|
|
138
144
|
_handleRequestBatch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
139
|
-
var currentConfig, isErrorMode, events, windowStart, config, consumeOnly, queryParams, customHeaders, batchId;
|
|
145
|
+
var currentConfig, isErrorMode, events, windowStart, config, consumeOnly, queryParams, customHeaders, signHeaders, batchId;
|
|
140
146
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
141
147
|
while (1) switch (_context.prev = _context.next) {
|
|
142
148
|
case 0:
|
|
@@ -205,8 +211,13 @@ function _handleRequestBatch() {
|
|
|
205
211
|
appId: currentAppId,
|
|
206
212
|
deviceId: getDeviceId(),
|
|
207
213
|
data: events
|
|
208
|
-
}); //
|
|
209
|
-
customHeaders = getCustomHeaders();
|
|
214
|
+
}); // 获取自定义请求头并合并签名头(签名在主线程计算)
|
|
215
|
+
customHeaders = getCustomHeaders();
|
|
216
|
+
_context.next = 34;
|
|
217
|
+
return computeSignHeaders(queryParams, JSON.stringify(events));
|
|
218
|
+
case 34:
|
|
219
|
+
signHeaders = _context.sent;
|
|
220
|
+
// 生成 batchId 并记录元数据(用于成功/失败回调)
|
|
210
221
|
batchId = generateBatchId(); // 将批次元数据存储起来,供回调使用
|
|
211
222
|
pendingBatches.set(batchId, {
|
|
212
223
|
events: events,
|
|
@@ -220,21 +231,21 @@ function _handleRequestBatch() {
|
|
|
220
231
|
batchId: batchId,
|
|
221
232
|
events: events,
|
|
222
233
|
queryParams: queryParams,
|
|
223
|
-
customHeaders: customHeaders
|
|
234
|
+
customHeaders: _objectSpread(_objectSpread({}, customHeaders), signHeaders)
|
|
224
235
|
});
|
|
225
236
|
isFetchingBatch = false;
|
|
226
|
-
_context.next =
|
|
237
|
+
_context.next = 45;
|
|
227
238
|
break;
|
|
228
|
-
case
|
|
229
|
-
_context.prev =
|
|
239
|
+
case 41:
|
|
240
|
+
_context.prev = 41;
|
|
230
241
|
_context.t0 = _context["catch"](8);
|
|
231
242
|
isFetchingBatch = false;
|
|
232
243
|
logger.error('Error fetching batch for Worker:', _context.t0);
|
|
233
|
-
case
|
|
244
|
+
case 45:
|
|
234
245
|
case "end":
|
|
235
246
|
return _context.stop();
|
|
236
247
|
}
|
|
237
|
-
}, _callee, null, [[8,
|
|
248
|
+
}, _callee, null, [[8, 41]]);
|
|
238
249
|
}));
|
|
239
250
|
return _handleRequestBatch.apply(this, arguments);
|
|
240
251
|
}
|
package/dist/esm/lib/utils.d.ts
CHANGED
|
@@ -64,6 +64,11 @@ export declare function isOrphanDataValid(events: any[]): boolean;
|
|
|
64
64
|
* 清理指定孤儿 session 的数据和注册信息
|
|
65
65
|
*/
|
|
66
66
|
export declare function cleanupOrphanSession(sessionId: string): void;
|
|
67
|
+
/**
|
|
68
|
+
* 判断当前设备是否为 iOS(iPhone / iPad / iPod)
|
|
69
|
+
* iOS Safari 不支持 canvas 导出 webp,需要降级为 jpeg
|
|
70
|
+
*/
|
|
71
|
+
export declare const isIOS: () => boolean;
|
|
67
72
|
/**
|
|
68
73
|
* 检查值是否为纯对象(非数组、非null)
|
|
69
74
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/lib/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/lib/utils.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,kBAAkB,cAM9B,CAAC;AAEF,eAAO,MAAM,WAAW,cAUvB,CAAC;AAgBF;;;GAGG;AAGH;;;GAGG;AACH,eAAO,MAAM,YAAY,QAAO,MAM/B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,aAAa,QAAO,MAEhC,CAAC;AAeF;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAQzD;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,IAAI,IAAI,CA0B3C;AAID;;;;GAIG;AAGH;;;;GAIG;AAGH;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,IAAI,iBAAiB,EAAE,CAkCvD;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CA0BxD;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAW5D;AAED;;;GAGG;AACH,eAAO,MAAM,KAAK,QAAO,OAExB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa,UAAW,GAAG,iCAEvC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,0CAClB,CAAC,UACD,QAAQ,CAAC,CAAC,KACjB,CAsBF,CAAC"}
|
package/dist/esm/lib/utils.js
CHANGED
|
@@ -8,7 +8,7 @@ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol
|
|
|
8
8
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
9
9
|
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; }
|
|
10
10
|
import { safeStorage } from "./drive/safe-storage";
|
|
11
|
-
import { STORAGE_KEY_DEVICE_ID,
|
|
11
|
+
import { STORAGE_KEY_DEVICE_ID, STORAGE_KEY_IWP_DEVICE_TAG, STORAGE_KEY_SESSION_REGISTRY, STORAGE_KEY_DATA_PREFIX, STORAGE_KEY_LOCK_PREFIX, SESSION_MAX_AGE, ORPHAN_DATA_MAX_SPAN, ORPHAN_SESSION_MAX_AGE } from "./constants";
|
|
12
12
|
export var generateUUIDCompat = function generateUUIDCompat() {
|
|
13
13
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
14
14
|
var r = Math.random() * 16 | 0;
|
|
@@ -20,7 +20,7 @@ export var getDeviceId = function getDeviceId() {
|
|
|
20
20
|
if (safeStorage.getItem(STORAGE_KEY_DEVICE_ID)) {
|
|
21
21
|
return safeStorage.getItem(STORAGE_KEY_DEVICE_ID);
|
|
22
22
|
}
|
|
23
|
-
var newId = safeStorage.getItem(
|
|
23
|
+
var newId = safeStorage.getItem(STORAGE_KEY_IWP_DEVICE_TAG) || generateUUIDCompat();
|
|
24
24
|
safeStorage.setItem(STORAGE_KEY_DEVICE_ID, newId);
|
|
25
25
|
return newId;
|
|
26
26
|
};
|
|
@@ -246,6 +246,14 @@ export function cleanupOrphanSession(sessionId) {
|
|
|
246
246
|
}
|
|
247
247
|
}
|
|
248
248
|
|
|
249
|
+
/**
|
|
250
|
+
* 判断当前设备是否为 iOS(iPhone / iPad / iPod)
|
|
251
|
+
* iOS Safari 不支持 canvas 导出 webp,需要降级为 jpeg
|
|
252
|
+
*/
|
|
253
|
+
export var isIOS = function isIOS() {
|
|
254
|
+
return /iPhone|iPad|iPod/i.test(navigator.userAgent);
|
|
255
|
+
};
|
|
256
|
+
|
|
249
257
|
/**
|
|
250
258
|
* 检查值是否为纯对象(非数组、非null)
|
|
251
259
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/lib/api.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/lib/api.ts"],"names":[],"mappings":"AAUA,KAAK,aAAa,GAAG;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAqBF;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,GAAG,EAAE,CAAC;CACb,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAyBzB;AAED,eAAO,MAAM,MAAM,QAAe,aAAa,kBA2C9C,CAAC"}
|