@wapri/ghermes 0.0.0-stage → 3.0.0-beta.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.
Files changed (50) hide show
  1. package/README.md +16 -3
  2. package/dist/base.d.ts +46 -0
  3. package/dist/base.js +165 -0
  4. package/dist/constants/domain.d.ts +44 -0
  5. package/dist/constants/domain.js +80 -0
  6. package/dist/constants/index.d.ts +2 -0
  7. package/dist/constants/index.js +2 -0
  8. package/dist/constants/resultCode.d.ts +13 -0
  9. package/dist/constants/resultCode.js +14 -0
  10. package/dist/demo/custom-interceptor.d.ts +3 -0
  11. package/dist/demo/custom-interceptor.js +69 -0
  12. package/dist/demo/index.d.ts +3 -0
  13. package/dist/demo/index.js +65 -0
  14. package/dist/hermes.d.ts +25 -0
  15. package/dist/hermes.js +107 -0
  16. package/dist/index.d.ts +4 -0
  17. package/dist/index.js +4 -0
  18. package/dist/interceptors/index.d.ts +4 -0
  19. package/dist/interceptors/index.js +298 -0
  20. package/dist/interceptors/interceptorAddSnowflake.d.ts +7 -0
  21. package/dist/interceptors/interceptorAddSnowflake.js +35 -0
  22. package/dist/interceptors/interceptorAddToken.d.ts +7 -0
  23. package/dist/interceptors/interceptorAddToken.js +46 -0
  24. package/dist/interceptors/interceptorAddTrace.d.ts +8 -0
  25. package/dist/interceptors/interceptorAddTrace.js +34 -0
  26. package/dist/interceptors/interceptorRepeatSubmit.d.ts +8 -0
  27. package/dist/interceptors/interceptorRepeatSubmit.js +78 -0
  28. package/dist/modules/auth/dto/account.d.ts +56 -0
  29. package/dist/modules/auth/dto/account.js +1 -0
  30. package/dist/modules/auth/dto/ticket.d.ts +13 -0
  31. package/dist/modules/auth/dto/ticket.js +1 -0
  32. package/dist/modules/auth/index.d.ts +36 -0
  33. package/dist/modules/auth/index.js +121 -0
  34. package/dist/modules/file/dto/tos.d.ts +6 -0
  35. package/dist/modules/file/dto/tos.js +1 -0
  36. package/dist/modules/file/index.d.ts +8 -0
  37. package/dist/modules/file/index.js +28 -0
  38. package/dist/types/common.d.ts +170 -0
  39. package/dist/types/common.js +38 -0
  40. package/dist/types/index.d.ts +2 -0
  41. package/dist/types/index.js +2 -0
  42. package/dist/types/interceptor.d.ts +13 -0
  43. package/dist/types/interceptor.js +1 -0
  44. package/dist/utils/error.d.ts +40 -0
  45. package/dist/utils/error.js +66 -0
  46. package/dist/utils/index.d.ts +2 -0
  47. package/dist/utils/index.js +2 -0
  48. package/dist/utils/snowflake.d.ts +26 -0
  49. package/dist/utils/snowflake.js +79 -0
  50. package/package.json +25 -3
@@ -0,0 +1,34 @@
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 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
+ 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
+ /**
6
+ * 日志请求拦截器:
7
+ * 1. 为所有HTTP请求添加 x-request-trace-url 请求头,用于日志上报记录
8
+ * 2. 注意,服务端在获取不到这个值时,使用referrer作为的默认值
9
+ */
10
+ var interceptorAddTrace = /*#__PURE__*/function () {
11
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(config) {
12
+ var returnConfig;
13
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
14
+ while (1) switch (_context.prev = _context.next) {
15
+ case 0:
16
+ if (config) {
17
+ _context.next = 2;
18
+ break;
19
+ }
20
+ return _context.abrupt("return", config);
21
+ case 2:
22
+ returnConfig = config;
23
+ returnConfig.headers['x-request-trace-url'] = "".concat(location.pathname).concat(location.search);
24
+ case 4:
25
+ case "end":
26
+ return _context.stop();
27
+ }
28
+ }, _callee);
29
+ }));
30
+ return function interceptorAddTrace(_x) {
31
+ return _ref.apply(this, arguments);
32
+ };
33
+ }();
34
+ export default interceptorAddTrace;
@@ -0,0 +1,8 @@
1
+ import { HermesInterceptorFunc } from '../types';
2
+ /**
3
+ * 防重复提交请求拦截器:
4
+ * 仅对 post / put 生效,以「url + data + time」为指纹缓存到 @wapri/gbase 的 session,
5
+ * 窗口(interval)内相同请求直接 reject,避免用户重复提交。
6
+ */
7
+ declare const interceptorRepeatSubmit: HermesInterceptorFunc;
8
+ export default interceptorRepeatSubmit;
@@ -0,0 +1,78 @@
1
+ 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; }
2
+ 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); }
3
+ 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
+ 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
+ import { session } from '@wapri/gbase';
6
+ var SESSION_KEY = '__hermes_repeat_submit__';
7
+
8
+ /**
9
+ * 防重复提交请求拦截器:
10
+ * 仅对 post / put 生效,以「url + data + time」为指纹缓存到 @wapri/gbase 的 session,
11
+ * 窗口(interval)内相同请求直接 reject,避免用户重复提交。
12
+ */
13
+ var interceptorRepeatSubmit = /*#__PURE__*/function () {
14
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(config, other) {
15
+ var _other$hermes;
16
+ var repeatSubmit, headers, method, interval, requestObj, raw, sessionObj;
17
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
18
+ while (1) switch (_context.prev = _context.next) {
19
+ case 0:
20
+ if (config) {
21
+ _context.next = 2;
22
+ break;
23
+ }
24
+ return _context.abrupt("return");
25
+ case 2:
26
+ repeatSubmit = other === null || other === void 0 || (_other$hermes = other.hermes) === null || _other$hermes === void 0 ? void 0 : _other$hermes.repeatSubmit;
27
+ if (repeatSubmit !== null && repeatSubmit !== void 0 && repeatSubmit.open) {
28
+ _context.next = 5;
29
+ break;
30
+ }
31
+ return _context.abrupt("return");
32
+ case 5:
33
+ headers = config.headers || {}; // 兼容 admin-frontend:单个请求可声明跳过防重,或自定义判定窗口
34
+ if (!(headers.repeatSubmit === false)) {
35
+ _context.next = 8;
36
+ break;
37
+ }
38
+ return _context.abrupt("return");
39
+ case 8:
40
+ method = (config.method || '').toLowerCase();
41
+ if (!(method !== 'post' && method !== 'put')) {
42
+ _context.next = 11;
43
+ break;
44
+ }
45
+ return _context.abrupt("return");
46
+ case 11:
47
+ interval = headers.interval || repeatSubmit.interval;
48
+ requestObj = {
49
+ url: config.url,
50
+ data: _typeof(config.data) === 'object' ? JSON.stringify(config.data) : config.data,
51
+ time: Date.now()
52
+ };
53
+ _context.prev = 13;
54
+ raw = session.getItem(SESSION_KEY);
55
+ sessionObj = raw ? JSON.parse(raw) : null;
56
+ if (!(sessionObj && sessionObj.data === requestObj.data && requestObj.time - sessionObj.time < interval && sessionObj.url === requestObj.url)) {
57
+ _context.next = 18;
58
+ break;
59
+ }
60
+ return _context.abrupt("return", Promise.reject(new Error('数据正在处理,请勿重复提交')));
61
+ case 18:
62
+ session.setItem(SESSION_KEY, JSON.stringify(requestObj));
63
+ _context.next = 23;
64
+ break;
65
+ case 21:
66
+ _context.prev = 21;
67
+ _context.t0 = _context["catch"](13);
68
+ case 23:
69
+ case "end":
70
+ return _context.stop();
71
+ }
72
+ }, _callee, null, [[13, 21]]);
73
+ }));
74
+ return function interceptorRepeatSubmit(_x, _x2) {
75
+ return _ref.apply(this, arguments);
76
+ };
77
+ }();
78
+ export default interceptorRepeatSubmit;
@@ -0,0 +1,56 @@
1
+ /** 认证中心登录请求。 */
2
+ export interface AccountLoginRequest {
3
+ loginType: string;
4
+ clientType: string;
5
+ userType?: string;
6
+ deviceId?: string;
7
+ deviceName?: string;
8
+ mobile?: string;
9
+ password?: string;
10
+ captchaKey?: string;
11
+ captchaCode?: string;
12
+ smsCode?: string;
13
+ }
14
+ /** 认证中心登录响应。 */
15
+ export interface AccountLoginResponse {
16
+ accessToken: string;
17
+ refreshToken?: string;
18
+ tokenType?: string;
19
+ expiresIn?: number;
20
+ refreshExpiresIn?: number;
21
+ userId?: number | string;
22
+ userType?: string;
23
+ tenantId?: number | string;
24
+ merchantId?: number | string;
25
+ loginId?: string;
26
+ }
27
+ /** 图形验证码响应。 */
28
+ export interface AccountCaptchaResponse {
29
+ captchaImage: string;
30
+ captchaKey: string;
31
+ }
32
+ /** 发送短信验证码请求。 */
33
+ export interface AccountSmsSendRequest {
34
+ mobile: string;
35
+ scene?: string;
36
+ captchaKey?: string;
37
+ captchaCode?: string;
38
+ }
39
+ /** 第三方 OAuth 回调请求。 */
40
+ export interface AccountOAuthCallbackRequest {
41
+ provider: string;
42
+ code: string;
43
+ state: string;
44
+ }
45
+ /** 签发短时票据请求。 */
46
+ export interface TicketIssueRequest {
47
+ scene?: string;
48
+ clientType?: string;
49
+ bizRef?: Record<string, string>;
50
+ }
51
+ /** 签发短时票据响应。 */
52
+ export interface TicketIssueDto {
53
+ ticket: string;
54
+ expireSeconds?: number;
55
+ scene?: string;
56
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ export type TicketExchangeDto = Partial<{
2
+ accessToken: string;
3
+ expiresIn: number;
4
+ loginId: string;
5
+ merchantId: number;
6
+ refreshExpiresIn: number;
7
+ refreshToken: string;
8
+ tenantId: number;
9
+ /** Token 类型,固定为 Bearer */
10
+ tokenType: string;
11
+ userId: number;
12
+ userType: string;
13
+ }>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,36 @@
1
+ import { Hermes } from '../../hermes';
2
+ import type { AccountCaptchaResponse, AccountLoginRequest, AccountLoginResponse, AccountOAuthCallbackRequest, AccountSmsSendRequest, TicketIssueDto, TicketIssueRequest } from './dto/account';
3
+ export declare class HermesModuleAuth {
4
+ private hermes?;
5
+ private baseUrl;
6
+ constructor(hermes: Hermes);
7
+ /** 认证中心统一登录。 */
8
+ login(data: AccountLoginRequest): Promise<AccountLoginResponse> | undefined;
9
+ /** 获取图形验证码。 */
10
+ getCaptcha(): Promise<AccountCaptchaResponse> | undefined;
11
+ /** 发送短信验证码。 */
12
+ sendSmsCode(data: AccountSmsSendRequest): Promise<unknown> | undefined;
13
+ /** 第三方 OAuth 回调登录。 */
14
+ oauthCallback(params: AccountOAuthCallbackRequest): Promise<AccountLoginResponse> | undefined;
15
+ /** 退出登录。 */
16
+ logout(): Promise<unknown> | undefined;
17
+ /** 签发短时一次性票据(scene / clientType 由业务按认证中心约定传入)。 */
18
+ getTicket(data?: TicketIssueRequest): Promise<TicketIssueDto> | undefined;
19
+ /** 用票据兑换登录态。 */
20
+ ticketGetToken(data: {
21
+ ticket: string;
22
+ /** 可选设备标识 */
23
+ deviceId?: string;
24
+ }): Promise<Partial<{
25
+ accessToken: string;
26
+ expiresIn: number;
27
+ loginId: string;
28
+ merchantId: number;
29
+ refreshExpiresIn: number;
30
+ refreshToken: string;
31
+ tenantId: number;
32
+ tokenType: string;
33
+ userId: number;
34
+ userType: string;
35
+ }>> | undefined;
36
+ }
@@ -0,0 +1,121 @@
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 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; }
3
+ 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; }
4
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
6
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
7
+ 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; }
8
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
9
+ 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); }
10
+ import { SERVICE_PATHS } from "../../constants";
11
+ export var HermesModuleAuth = /*#__PURE__*/function () {
12
+ function HermesModuleAuth(hermes) {
13
+ _classCallCheck(this, HermesModuleAuth);
14
+ _defineProperty(this, "hermes", void 0);
15
+ _defineProperty(this, "baseUrl", '');
16
+ this.hermes = hermes;
17
+ this.baseUrl = "".concat(hermes.servicePrefix).concat(SERVICE_PATHS.auth);
18
+ }
19
+
20
+ /** 认证中心统一登录。 */
21
+ _createClass(HermesModuleAuth, [{
22
+ key: "login",
23
+ value: function login(data) {
24
+ var _this$hermes;
25
+ return (_this$hermes = this.hermes) === null || _this$hermes === void 0 ? void 0 : _this$hermes.instance.request({
26
+ method: 'post',
27
+ url: "".concat(this.baseUrl, "/login"),
28
+ data: data,
29
+ headers: {
30
+ isToken: false
31
+ }
32
+ });
33
+ }
34
+
35
+ /** 获取图形验证码。 */
36
+ }, {
37
+ key: "getCaptcha",
38
+ value: function getCaptcha() {
39
+ var _this$hermes2;
40
+ return (_this$hermes2 = this.hermes) === null || _this$hermes2 === void 0 ? void 0 : _this$hermes2.instance.request({
41
+ method: 'get',
42
+ url: "".concat(this.baseUrl, "/captcha/generate"),
43
+ headers: {
44
+ isToken: false
45
+ },
46
+ timeout: 20000
47
+ });
48
+ }
49
+
50
+ /** 发送短信验证码。 */
51
+ }, {
52
+ key: "sendSmsCode",
53
+ value: function sendSmsCode(data) {
54
+ var _this$hermes3;
55
+ return (_this$hermes3 = this.hermes) === null || _this$hermes3 === void 0 ? void 0 : _this$hermes3.instance.request({
56
+ method: 'post',
57
+ url: "".concat(this.baseUrl, "/sms/send"),
58
+ data: _objectSpread({
59
+ scene: 'LOGIN'
60
+ }, data),
61
+ headers: {
62
+ isToken: false
63
+ }
64
+ });
65
+ }
66
+
67
+ /** 第三方 OAuth 回调登录。 */
68
+ }, {
69
+ key: "oauthCallback",
70
+ value: function oauthCallback(params) {
71
+ var _this$hermes4;
72
+ return (_this$hermes4 = this.hermes) === null || _this$hermes4 === void 0 ? void 0 : _this$hermes4.instance.request({
73
+ method: 'get',
74
+ url: "".concat(this.baseUrl, "/oauth/callback"),
75
+ params: params,
76
+ headers: {
77
+ isToken: false
78
+ }
79
+ });
80
+ }
81
+
82
+ /** 退出登录。 */
83
+ }, {
84
+ key: "logout",
85
+ value: function logout() {
86
+ var _this$hermes5;
87
+ return (_this$hermes5 = this.hermes) === null || _this$hermes5 === void 0 ? void 0 : _this$hermes5.instance.request({
88
+ method: 'post',
89
+ url: "".concat(this.baseUrl, "/logout")
90
+ });
91
+ }
92
+
93
+ /** 签发短时一次性票据(scene / clientType 由业务按认证中心约定传入)。 */
94
+ }, {
95
+ key: "getTicket",
96
+ value: function getTicket(data) {
97
+ var _this$hermes6;
98
+ return (_this$hermes6 = this.hermes) === null || _this$hermes6 === void 0 ? void 0 : _this$hermes6.instance.request({
99
+ method: 'post',
100
+ url: "".concat(this.baseUrl, "/ticket/issue"),
101
+ data: _objectSpread({}, data || {})
102
+ });
103
+ }
104
+
105
+ /** 用票据兑换登录态。 */
106
+ }, {
107
+ key: "ticketGetToken",
108
+ value: function ticketGetToken(data) {
109
+ var _this$hermes7;
110
+ return (_this$hermes7 = this.hermes) === null || _this$hermes7 === void 0 ? void 0 : _this$hermes7.instance.request({
111
+ method: 'post',
112
+ url: "".concat(this.baseUrl, "/ticket/exchange"),
113
+ data: _objectSpread({}, data || {}),
114
+ headers: {
115
+ isToken: false
116
+ }
117
+ });
118
+ }
119
+ }]);
120
+ return HermesModuleAuth;
121
+ }();
@@ -0,0 +1,6 @@
1
+ export type TosStsDto = {
2
+ accessKeyId: string;
3
+ secretAccessKey: string;
4
+ sessionToken: string;
5
+ expiredTime: string;
6
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ import { Hermes } from '../../hermes';
2
+ import { TosStsDto } from './dto/tos';
3
+ export declare class HermesModuleFile {
4
+ private hermes?;
5
+ private baseUrl;
6
+ constructor(hermes: Hermes);
7
+ tosGetSts(): Promise<TosStsDto> | undefined;
8
+ }
@@ -0,0 +1,28 @@
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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
4
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
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); }
8
+ import { SERVICE_PATHS } from "../../constants";
9
+ export var HermesModuleFile = /*#__PURE__*/function () {
10
+ function HermesModuleFile(hermes) {
11
+ _classCallCheck(this, HermesModuleFile);
12
+ _defineProperty(this, "hermes", void 0);
13
+ _defineProperty(this, "baseUrl", '');
14
+ this.hermes = hermes;
15
+ this.baseUrl = "".concat(hermes.servicePrefix).concat(SERVICE_PATHS.file);
16
+ }
17
+ _createClass(HermesModuleFile, [{
18
+ key: "tosGetSts",
19
+ value: function tosGetSts() {
20
+ var _this$hermes;
21
+ return (_this$hermes = this.hermes) === null || _this$hermes === void 0 ? void 0 : _this$hermes.instance.request({
22
+ method: 'get',
23
+ url: "".concat(this.baseUrl, "/get-sts")
24
+ });
25
+ }
26
+ }]);
27
+ return HermesModuleFile;
28
+ }();
@@ -0,0 +1,170 @@
1
+ import { AxiosResponse, CreateAxiosDefaults, InternalAxiosRequestConfig } from 'axios';
2
+ import { Hermes } from '../hermes';
3
+ import { Env } from '@wapri/gbase';
4
+ import { ServerDomainKey } from '../constants/domain';
5
+ export type HermesInterceptorFunc = (config: InternalAxiosRequestConfig<unknown>, other?: {
6
+ hermes?: Hermes;
7
+ }) => Promise<void>;
8
+ type CustomAxiosConfigs = Omit<CreateAxiosDefaults, 'baseURL'>;
9
+ /**
10
+ * 请求库插件
11
+ * */
12
+ export type RequestInterceptorPlugin =
13
+ /** 添加日志路径上报 */
14
+ 'trace'
15
+ /** 请求侧雪花 ID 字段转字符串,避免 JSON 序列化丢精度 */
16
+ | 'snowflake'
17
+ /** 防重复提交(post/put,@wapri/gbase session 指纹 + 时间窗口) */
18
+ | 'repeatSubmit';
19
+ export type RequestCommon = {
20
+ /** 环境标记 */
21
+ env: Env;
22
+ /** 强指baseUrl */
23
+ baseUrl?: string;
24
+ /**
25
+ * 服务端模块
26
+ * @default usedCar
27
+ * */
28
+ module?: ServerDomainKey;
29
+ /**
30
+ * 网关前缀,业务中心地址统一是 `${servicePrefix}${SERVICE_PATHS[key]}`。
31
+ * @default '/api'
32
+ */
33
+ servicePrefix?: string;
34
+ };
35
+ /**
36
+ * 业务自定义请求拦截器:在内置拦截器(token + plugin)执行后追加调用,可继续修改 config
37
+ * */
38
+ export type HermesCustomRequestInterceptor = (config: InternalAxiosRequestConfig<unknown>, other?: {
39
+ hermes?: Hermes;
40
+ }) => void | Promise<void>;
41
+ /**
42
+ * 业务自定义响应拦截器:在内置响应处理(业务成功判定 + unwrap)后追加调用
43
+ * */
44
+ export type HermesCustomResponseInterceptor = (res: AxiosResponse, other?: {
45
+ hermes?: Hermes;
46
+ }) => void | Promise<void>;
47
+ /**
48
+ * 业务自定义错误拦截器:在内置错误处理(重试、401、错误包装 + onError)后追加调用。
49
+ * 正常返回时保留 Hermes 错误;reject/throw 的值会作为最终错误继续向外抛出,便于兼容旧版错误值。
50
+ * */
51
+ export type HermesCustomErrorInterceptor = (error: unknown, other?: {
52
+ hermes?: Hermes;
53
+ }) => void | Promise<unknown>;
54
+ export type HermesBaseInterceptor = {
55
+ /**
56
+ * 强指拦截器,request与response都在这个维度
57
+ * @default ["trace", "deviceInfo"]
58
+ */
59
+ plugin?: RequestInterceptorPlugin[];
60
+ /**
61
+ * 业务自定义请求拦截器,在内置拦截器基础上追加
62
+ */
63
+ request?: HermesCustomRequestInterceptor;
64
+ /**
65
+ * 业务自定义响应拦截器,在内置拦截器基础上追加
66
+ */
67
+ response?: HermesCustomResponseInterceptor;
68
+ /**
69
+ * 业务自定义错误拦截器,在内置拦截器基础上追加
70
+ */
71
+ error?: HermesCustomErrorInterceptor;
72
+ };
73
+ export type HermesRetry = {
74
+ /**
75
+ * 重试次数
76
+ * @default 0
77
+ * */
78
+ num?: number;
79
+ /**
80
+ * 重试间隔
81
+ * @default 1000
82
+ * */
83
+ delay?: number;
84
+ /**
85
+ * 重试场景
86
+ * @default ['ECONNABORTED', 'ERR_NETWORK']
87
+ * */
88
+ codes?: string[];
89
+ };
90
+ export type RepeatSubmitConfig = {
91
+ /**
92
+ * 判定窗口,单位毫秒
93
+ * @default 1000
94
+ * */
95
+ interval?: number;
96
+ };
97
+ export type HermesBaseConfig = RequestCommon & {
98
+ axiosConfig?: CustomAxiosConfigs;
99
+ interceptor?: HermesBaseInterceptor;
100
+ /** 重试配置 */
101
+ retry?: HermesRetry;
102
+ /**
103
+ * 雪花 Long 精度保护:响应侧 transformResponse + 请求侧 ID 字段转字符串
104
+ * @default true
105
+ */
106
+ snowflake?: boolean;
107
+ /**
108
+ * 防重复提交:true / 对象开启(需在 interceptor.plugin 中挂 repeatSubmit),false 关闭
109
+ * @default true
110
+ */
111
+ repeatSubmit?: boolean | RepeatSubmitConfig;
112
+ /**
113
+ * 业务 401 瞬时重试次数:网关后多实例权限中心部分节点未兼容 JWT 时,
114
+ * 先重试打到健康节点,达到上限后再触发 onUnauthorized。
115
+ * @default 2
116
+ */
117
+ unauthorizedRetry?: number;
118
+ /**
119
+ * 登录态失效时是否自动移除 token
120
+ * @default true
121
+ */
122
+ removeToken?: boolean;
123
+ /**
124
+ * 是否在响应拦截器中自动 unwrap 业务 data(即返回 response.data.data)。
125
+ * 关闭后返回完整业务响应体(response.data),便于业务层自行解包。
126
+ * @default true
127
+ */
128
+ unwrapResponse?: boolean;
129
+ /** 登录态失效(401)钩子,由业务层实现重登录弹窗 / 跳转 */
130
+ onUnauthorized?: () => void;
131
+ /** 请求/业务错误回调,由业务层决定提示方式(保持 hermes 无 UI 依赖) */
132
+ onError?: (error: unknown) => void;
133
+ };
134
+ export type HermesRequestInstanceConfig = Pick<HermesBaseConfig, 'baseUrl'> & CustomAxiosConfigs;
135
+ export type TableResponse<DataType extends object> = {
136
+ current: number;
137
+ pages: number;
138
+ total: number;
139
+ size: number;
140
+ records: DataType[];
141
+ };
142
+ export type TableParams<T extends object> = {
143
+ current: number;
144
+ size?: number;
145
+ } & T;
146
+ /**
147
+ * 标准逻辑分支
148
+ * - 1 是
149
+ * - 2 否
150
+ * */
151
+ export declare enum TruthValueStandard {
152
+ true = 1,
153
+ false = 2
154
+ }
155
+ /**
156
+ * 怪异逻辑分支
157
+ * - 1 否
158
+ * - 2 是
159
+ * */
160
+ export declare enum TruthValueWeird {
161
+ false = "1",
162
+ true = "2"
163
+ }
164
+ export type Option = {
165
+ key?: string | number;
166
+ label: string;
167
+ value: string | number;
168
+ [x: string]: unknown;
169
+ };
170
+ export {};
@@ -0,0 +1,38 @@
1
+ /**
2
+ * 请求库插件
3
+ * */
4
+
5
+ /**
6
+ * 业务自定义请求拦截器:在内置拦截器(token + plugin)执行后追加调用,可继续修改 config
7
+ * */
8
+
9
+ /**
10
+ * 业务自定义响应拦截器:在内置响应处理(业务成功判定 + unwrap)后追加调用
11
+ * */
12
+
13
+ /**
14
+ * 业务自定义错误拦截器:在内置错误处理(重试、401、错误包装 + onError)后追加调用。
15
+ * 正常返回时保留 Hermes 错误;reject/throw 的值会作为最终错误继续向外抛出,便于兼容旧版错误值。
16
+ * */
17
+
18
+ /**
19
+ * 标准逻辑分支
20
+ * - 1 是
21
+ * - 2 否
22
+ * */
23
+ export var TruthValueStandard = /*#__PURE__*/function (TruthValueStandard) {
24
+ TruthValueStandard[TruthValueStandard["true"] = 1] = "true";
25
+ TruthValueStandard[TruthValueStandard["false"] = 2] = "false";
26
+ return TruthValueStandard;
27
+ }({});
28
+
29
+ /**
30
+ * 怪异逻辑分支
31
+ * - 1 否
32
+ * - 2 是
33
+ * */
34
+ export var TruthValueWeird = /*#__PURE__*/function (TruthValueWeird) {
35
+ TruthValueWeird["false"] = "1";
36
+ TruthValueWeird["true"] = "2";
37
+ return TruthValueWeird;
38
+ }({});