@pisell/core 1.0.6 → 1.0.8

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 (80) hide show
  1. package/es/app/app.d.ts +11 -7
  2. package/es/app/app.js +8 -0
  3. package/es/app/index.d.ts +1 -1
  4. package/es/applicationManager/application.d.ts +2 -2
  5. package/es/aws/index.d.ts +16 -0
  6. package/es/aws/index.js +76 -0
  7. package/es/cmd/const.d.ts +11 -0
  8. package/es/cmd/const.js +13 -0
  9. package/es/cmd/index.d.ts +13 -0
  10. package/es/cmd/index.js +91 -0
  11. package/es/cmd/type.d.ts +5 -0
  12. package/es/cmd/type.js +1 -0
  13. package/es/hooks/useStore/index.d.ts +1 -1
  14. package/es/locales/type.d.ts +3 -3
  15. package/es/logger/index.d.ts +14 -2
  16. package/es/logger/index.js +276 -125
  17. package/es/models/index.d.ts +4 -4
  18. package/es/pubsub/index.d.ts +1 -1
  19. package/es/request/cache.d.ts +1 -1
  20. package/es/request/pisell2Request.d.ts +1 -1
  21. package/es/routes/index.d.ts +2 -2
  22. package/es/socket/monitor.d.ts +1 -1
  23. package/es/socket/monitor.js +0 -1
  24. package/es/socket/reconnect.d.ts +1 -1
  25. package/es/socket/reconnect.js +1 -1
  26. package/es/socket/socket.d.ts +2 -1
  27. package/es/socket/socket.js +34 -16
  28. package/es/socket/types.d.ts +1 -2
  29. package/es/storage/index.js +3 -0
  30. package/es/tasks/index.d.ts +6 -0
  31. package/es/tasks/index.js +92 -33
  32. package/es/tasks/type.d.ts +4 -4
  33. package/es/variables/index.d.ts +3 -3
  34. package/lib/app/app.d.ts +11 -7
  35. package/lib/app/app.js +53 -21
  36. package/lib/app/index.d.ts +1 -1
  37. package/lib/applicationManager/application.d.ts +2 -2
  38. package/lib/applicationManager/application.js +9 -6
  39. package/lib/applicationManager/index.js +1 -1
  40. package/lib/aws/index.d.ts +16 -0
  41. package/lib/aws/index.js +67 -0
  42. package/lib/cmd/const.d.ts +11 -0
  43. package/lib/cmd/const.js +39 -0
  44. package/lib/cmd/index.d.ts +13 -0
  45. package/lib/cmd/index.js +96 -0
  46. package/lib/cmd/type.d.ts +5 -0
  47. package/lib/cmd/type.js +17 -0
  48. package/lib/cookie/index.js +2 -4
  49. package/lib/data/index.js +3 -0
  50. package/lib/history/index.js +24 -22
  51. package/lib/hooks/useStore/index.d.ts +1 -1
  52. package/lib/indexDB/index.js +16 -11
  53. package/lib/locales/index.js +95 -94
  54. package/lib/locales/type.d.ts +3 -3
  55. package/lib/logger/index.d.ts +14 -2
  56. package/lib/logger/index.js +104 -26
  57. package/lib/menuManager/index.js +9 -12
  58. package/lib/models/index.d.ts +4 -4
  59. package/lib/pubsub/index.d.ts +1 -1
  60. package/lib/pubsub/index.js +1 -3
  61. package/lib/request/cache.d.ts +1 -1
  62. package/lib/request/pisell2Request.d.ts +1 -1
  63. package/lib/routes/index.d.ts +2 -2
  64. package/lib/routes/index.js +3 -1
  65. package/lib/socket/components/SocketMonitorPage.js +6 -12
  66. package/lib/socket/heartbeat.js +10 -5
  67. package/lib/socket/index.js +1 -3
  68. package/lib/socket/monitor.d.ts +1 -1
  69. package/lib/socket/monitor.js +26 -24
  70. package/lib/socket/reconnect.d.ts +1 -1
  71. package/lib/socket/reconnect.js +11 -7
  72. package/lib/socket/socket.d.ts +2 -1
  73. package/lib/socket/socket.js +32 -16
  74. package/lib/socket/types.d.ts +1 -2
  75. package/lib/storage/index.js +25 -24
  76. package/lib/tasks/index.d.ts +6 -0
  77. package/lib/tasks/index.js +197 -162
  78. package/lib/tasks/type.d.ts +4 -4
  79. package/lib/variables/index.d.ts +3 -3
  80. package/package.json +2 -1
@@ -1,3 +1,4 @@
1
+ var _excluded = ["feishu"];
1
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); }
2
3
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
3
4
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
@@ -8,6 +9,8 @@ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToAr
8
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; }
9
10
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
10
11
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
12
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
13
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
11
14
  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; }
12
15
  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); } }
13
16
  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); }); }; }
@@ -27,6 +30,7 @@ import { sendWarningLog } from "./feishu";
27
30
  * 日志管理器类
28
31
  */
29
32
  var LoggerManager = /*#__PURE__*/function () {
33
+ // 日志管理器状态
30
34
  /**
31
35
  * 构造函数
32
36
  * @param prefix 日志前缀
@@ -51,6 +55,7 @@ var LoggerManager = /*#__PURE__*/function () {
51
55
  _defineProperty(this, "retentionDays", void 0);
52
56
  // 日志保留天数
53
57
  _defineProperty(this, "metadataFunction", void 0);
58
+ _defineProperty(this, "status", "running");
54
59
  this.prefix = (options === null || options === void 0 ? void 0 : options.prefix) || "app";
55
60
  this.checkInterval = (options === null || options === void 0 ? void 0 : options.checkInterval) || 5 * 60 * 1000;
56
61
  this.app = app;
@@ -61,6 +66,7 @@ var LoggerManager = /*#__PURE__*/function () {
61
66
  _createClass(LoggerManager, [{
62
67
  key: "init",
63
68
  value: function init() {
69
+ this.setStatus("running");
64
70
  this.initTimer();
65
71
  // 定期清理旧日志
66
72
  this.cleanupOldLogs();
@@ -119,6 +125,19 @@ var LoggerManager = /*#__PURE__*/function () {
119
125
  }
120
126
  }, this.checkInterval);
121
127
  }
128
+ }, {
129
+ key: "setStatus",
130
+ value: function setStatus(status) {
131
+ this.status = status;
132
+ }
133
+ }, {
134
+ key: "stop",
135
+ value: function stop() {
136
+ this.setStatus("stop");
137
+ if (this.timer) {
138
+ clearInterval(this.timer);
139
+ }
140
+ }
122
141
 
123
142
  /**
124
143
  * 添加日志
@@ -127,13 +146,23 @@ var LoggerManager = /*#__PURE__*/function () {
127
146
  }, {
128
147
  key: "addLog",
129
148
  value: function addLog(log) {
130
- var logItem = _objectSpread(_objectSpread({}, log), {}, {
149
+ if (this.status === "stop") {
150
+ return;
151
+ }
152
+ var _ref = log || {},
153
+ feishu = _ref.feishu,
154
+ restLog = _objectWithoutProperties(_ref, _excluded);
155
+ var logItem = _objectSpread(_objectSpread({}, restLog), {}, {
131
156
  date: log.date || dayjs().format("YYYY-MM-DD HH:mm:ss"),
132
- metadata: JSON.stringify(log.metadata || "{}")
157
+ metadata: JSON.stringify(log.metadata || {}),
158
+ // 以时间戳生成logId
159
+ logId: dayjs().valueOf()
133
160
  });
134
161
  console.log("---- 行为日志", logItem);
135
162
  if (log.type === "error") {
136
- this.sendFeishuNotification(logItem);
163
+ this.sendFeishuNotification(_objectSpread(_objectSpread({}, logItem || {}), {}, {
164
+ feishu: feishu
165
+ }));
137
166
  }
138
167
  this.logBuffer.push(logItem);
139
168
  }
@@ -148,21 +177,30 @@ var LoggerManager = /*#__PURE__*/function () {
148
177
  if (this.feishuConfig) {
149
178
  var _this$metadataFunctio;
150
179
  var _metadata = ((_this$metadataFunctio = this.metadataFunction) === null || _this$metadataFunctio === void 0 ? void 0 : _this$metadataFunctio.call(this)) || {};
180
+ var content = [{
181
+ key: "日志类型",
182
+ value: log.type
183
+ }, {
184
+ key: "日志时间",
185
+ value: log.date || dayjs().format("YYYY-MM-DD HH:mm:ss")
186
+ }, {
187
+ key: "日志来源",
188
+ value: JSON.stringify(_objectSpread(_objectSpread({}, this.metadata || {}), _metadata))
189
+ }];
190
+ if (log.feishu) {
191
+ content.push({
192
+ key: "日志内容",
193
+ value: JSON.stringify(log.feishu || {})
194
+ });
195
+ } else {
196
+ content.push({
197
+ key: "日志内容",
198
+ value: JSON.stringify(log.metadata || {})
199
+ });
200
+ }
151
201
  sendWarningLog({
152
202
  title: log.title,
153
- content: [{
154
- key: "日志类型",
155
- value: log.type
156
- }, {
157
- key: "日志时间",
158
- value: log.date || dayjs().format("YYYY-MM-DD HH:mm:ss")
159
- }, {
160
- key: "日志来源",
161
- value: JSON.stringify(_objectSpread(_objectSpread({}, this.metadata || {}), _metadata))
162
- }, {
163
- key: "日志内容",
164
- value: JSON.stringify(log.metadata)
165
- }],
203
+ content: content,
166
204
  webhook: this.feishuConfig.webhook
167
205
  });
168
206
  console.log("-------- 发送飞书通知", log);
@@ -181,11 +219,60 @@ var LoggerManager = /*#__PURE__*/function () {
181
219
  return fileName;
182
220
  }
183
221
 
222
+ /**
223
+ * 创建AWS日志文件名
224
+ * @param isManual 是否手动上传
225
+ * @returns 日志文件名
226
+ */
227
+ }, {
228
+ key: "createAWSFileName",
229
+ value: (function () {
230
+ var _createAWSFileName = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(isManual) {
231
+ var _JSON$parse;
232
+ var _date, _hour, shopId, deviceId, _this$app, _this$app2, language, deviceRes, device, fileName;
233
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
234
+ while (1) switch (_context2.prev = _context2.next) {
235
+ case 0:
236
+ _date = dayjs().format("YYYY-MM-DD");
237
+ _hour = dayjs().format("HH:mm");
238
+ shopId = (_JSON$parse = JSON.parse(this.app.storage.getStorage("shopInfo") || "{}")) === null || _JSON$parse === void 0 || (_JSON$parse = _JSON$parse.shop) === null || _JSON$parse === void 0 ? void 0 : _JSON$parse.id;
239
+ deviceId = ""; // 如果shopId为空,则获取设备号
240
+ if (shopId) {
241
+ _context2.next = 11;
242
+ break;
243
+ }
244
+ language = ((_this$app = this.app) === null || _this$app === void 0 || (_this$app = _this$app.locales) === null || _this$app === void 0 ? void 0 : _this$app.getLocale()) || "en";
245
+ _context2.next = 8;
246
+ return (_this$app2 = this.app) === null || _this$app2 === void 0 ? void 0 : _this$app2.getPlugin("device").getDeviceInfo({
247
+ language: language
248
+ });
249
+ case 8:
250
+ deviceRes = _context2.sent;
251
+ device = (deviceRes === null || deviceRes === void 0 ? void 0 : deviceRes.data) || null;
252
+ deviceId = (device === null || device === void 0 ? void 0 : device.number) || "";
253
+ case 11:
254
+ fileName = "logs/kds/".concat(shopId || deviceId || "pisell", "/").concat(_date, "/").concat(_hour);
255
+ if (isManual) {
256
+ fileName += "-manual";
257
+ }
258
+ return _context2.abrupt("return", "".concat(fileName, ".json"));
259
+ case 14:
260
+ case "end":
261
+ return _context2.stop();
262
+ }
263
+ }, _callee2, this);
264
+ }));
265
+ function createAWSFileName(_x) {
266
+ return _createAWSFileName.apply(this, arguments);
267
+ }
268
+ return createAWSFileName;
269
+ }()
184
270
  /**
185
271
  * 创建日志文件
186
272
  * @param _fileName 文件名
187
273
  * @returns 日志文件对象
188
274
  */
275
+ )
189
276
  }, {
190
277
  key: "createFile",
191
278
  value: function createFile(_fileName) {
@@ -207,85 +294,149 @@ var LoggerManager = /*#__PURE__*/function () {
207
294
  }, {
208
295
  key: "storeLog",
209
296
  value: (function () {
210
- var _storeLog = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
211
- var fileName, logFile;
212
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
213
- while (1) switch (_context2.prev = _context2.next) {
297
+ var _storeLog = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
298
+ var _this$logBuffer, fileName, buffer, logs;
299
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
300
+ while (1) switch (_context3.prev = _context3.next) {
214
301
  case 0:
215
302
  if (!(this.logBuffer.length === 0 || !this.db)) {
216
- _context2.next = 2;
303
+ _context3.next = 2;
217
304
  break;
218
305
  }
219
- return _context2.abrupt("return");
306
+ return _context3.abrupt("return");
220
307
  case 2:
308
+ _context3.prev = 2;
309
+ _context3.next = 5;
310
+ return this.createAWSFileName();
311
+ case 5:
312
+ fileName = _context3.sent;
313
+ console.log("-------- 存储日志到AWS 开始", fileName);
314
+
315
+ // 将buffer中的metadata转换为对象
316
+ buffer = (_this$logBuffer = this.logBuffer) === null || _this$logBuffer === void 0 ? void 0 : _this$logBuffer.map(function (item) {
317
+ item.metadata = JSON.parse(item.metadata || "{}");
318
+ return item;
319
+ });
320
+ logs = JSON.stringify(buffer, null, 2);
321
+ _context3.next = 11;
322
+ return this.app.aws.upload({
323
+ Bucket: "",
324
+ Key: fileName,
325
+ Body: logs
326
+ });
327
+ case 11:
328
+ console.log("-------- 存储日志到AWS 成功");
329
+ // 上传成功后需要清空缓冲区,避免重复上传
330
+ this.logBuffer = [];
331
+ _context3.next = 26;
332
+ break;
333
+ case 15:
334
+ _context3.prev = 15;
335
+ _context3.t0 = _context3["catch"](2);
336
+ console.error("存储日志上传AWS失败:", _context3.t0);
337
+
338
+ // 将日志存储到IndexDB
339
+ _context3.prev = 18;
340
+ _context3.next = 21;
341
+ return this.storeLogToIndexDB();
342
+ case 21:
343
+ _context3.next = 26;
344
+ break;
345
+ case 23:
346
+ _context3.prev = 23;
347
+ _context3.t1 = _context3["catch"](18);
348
+ console.error("存储日志到IndexDB也失败:", _context3.t1);
349
+ case 26:
350
+ case "end":
351
+ return _context3.stop();
352
+ }
353
+ }, _callee3, this, [[2, 15], [18, 23]]);
354
+ }));
355
+ function storeLog() {
356
+ return _storeLog.apply(this, arguments);
357
+ }
358
+ return storeLog;
359
+ }())
360
+ }, {
361
+ key: "storeLogToIndexDB",
362
+ value: function () {
363
+ var _storeLogToIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
364
+ var _this$db, _this$db3, fileName, logFile, _this$db2;
365
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
366
+ while (1) switch (_context4.prev = _context4.next) {
367
+ case 0:
368
+ _context4.prev = 0;
221
369
  fileName = this.createFileName();
222
- _context2.prev = 3;
223
- _context2.next = 6;
224
- return this.db.get("logs", fileName);
225
- case 6:
226
- logFile = _context2.sent;
370
+ console.log("storeLog", fileName);
371
+
372
+ // 获取现有日志文件
373
+ _context4.next = 5;
374
+ return (_this$db = this.db) === null || _this$db === void 0 ? void 0 : _this$db.get("logs", fileName);
375
+ case 5:
376
+ logFile = _context4.sent;
227
377
  if (logFile) {
228
- _context2.next = 11;
378
+ _context4.next = 10;
229
379
  break;
230
380
  }
231
381
  logFile = this.createFile(fileName);
232
- _context2.next = 11;
233
- return this.db.add("logs", logFile);
234
- case 11:
382
+ _context4.next = 10;
383
+ return (_this$db2 = this.db) === null || _this$db2 === void 0 ? void 0 : _this$db2.add("logs", logFile);
384
+ case 10:
235
385
  // 添加日志到文件内容
236
386
  logFile.fileContent.logs = [].concat(_toConsumableArray(logFile.fileContent.logs), _toConsumableArray(this.logBuffer));
237
387
 
238
388
  // 更新日志文件
239
- _context2.next = 14;
240
- return this.db.update("logs", logFile);
241
- case 14:
242
- console.log("-------- 存储日志", {
389
+ _context4.next = 13;
390
+ return (_this$db3 = this.db) === null || _this$db3 === void 0 ? void 0 : _this$db3.update("logs", logFile);
391
+ case 13:
392
+ console.log("-------- 存储日志到IndexDB", {
243
393
  fileName: fileName,
244
394
  logFile: logFile
245
395
  });
246
- _context2.next = 20;
396
+
397
+ // 存储成功后需要清空缓冲区,避免重复存储
398
+ this.logBuffer = [];
399
+ _context4.next = 21;
247
400
  break;
248
401
  case 17:
249
- _context2.prev = 17;
250
- _context2.t0 = _context2["catch"](3);
251
- console.error("存储日志到IndexDB失败:", _context2.t0);
252
- case 20:
253
- // 清空缓冲区
254
- this.logBuffer = [];
402
+ _context4.prev = 17;
403
+ _context4.t0 = _context4["catch"](0);
404
+ console.log("-------- 存储日志到IndexDB 失败", _context4.t0);
405
+ // 重新抛出错误,让外层 catch 能够捕获
406
+ throw _context4.t0;
255
407
  case 21:
256
408
  case "end":
257
- return _context2.stop();
409
+ return _context4.stop();
258
410
  }
259
- }, _callee2, this, [[3, 17]]);
411
+ }, _callee4, this, [[0, 17]]);
260
412
  }));
261
- function storeLog() {
262
- return _storeLog.apply(this, arguments);
413
+ function storeLogToIndexDB() {
414
+ return _storeLogToIndexDB.apply(this, arguments);
263
415
  }
264
- return storeLog;
416
+ return storeLogToIndexDB;
265
417
  }()
266
418
  /**
267
419
  * 清理旧日志,只保留最近指定天数的日志
268
420
  */
269
- )
270
421
  }, {
271
422
  key: "cleanupOldLogs",
272
423
  value: (function () {
273
- var _cleanupOldLogs = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
424
+ var _cleanupOldLogs = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
274
425
  var logFiles, cutoffDate, filesToDelete, _iterator, _step, file;
275
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
276
- while (1) switch (_context3.prev = _context3.next) {
426
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
427
+ while (1) switch (_context5.prev = _context5.next) {
277
428
  case 0:
278
429
  if (this.db) {
279
- _context3.next = 2;
430
+ _context5.next = 2;
280
431
  break;
281
432
  }
282
- return _context3.abrupt("return");
433
+ return _context5.abrupt("return");
283
434
  case 2:
284
- _context3.prev = 2;
285
- _context3.next = 5;
435
+ _context5.prev = 2;
436
+ _context5.next = 5;
286
437
  return this.getLogFiles();
287
438
  case 5:
288
- logFiles = _context3.sent;
439
+ logFiles = _context5.sent;
289
440
  // 计算保留日志的截止日期
290
441
  cutoffDate = dayjs().subtract(this.retentionDays, "day").format("YYYY-MM-DD"); // 筛选出需要删除的日志文件
291
442
  filesToDelete = logFiles.filter(function (file) {
@@ -295,47 +446,47 @@ var LoggerManager = /*#__PURE__*/function () {
295
446
 
296
447
  // 删除旧日志文件
297
448
  _iterator = _createForOfIteratorHelper(filesToDelete);
298
- _context3.prev = 10;
449
+ _context5.prev = 10;
299
450
  _iterator.s();
300
451
  case 12:
301
452
  if ((_step = _iterator.n()).done) {
302
- _context3.next = 19;
453
+ _context5.next = 19;
303
454
  break;
304
455
  }
305
456
  file = _step.value;
306
- _context3.next = 16;
457
+ _context5.next = 16;
307
458
  return this.db.delete("logs", file.fileName);
308
459
  case 16:
309
460
  console.log("-------- \u5220\u9664\u65E7\u65E5\u5FD7\u6587\u4EF6: ".concat(file.fileName, ", \u65E5\u671F: ").concat(file.date));
310
461
  case 17:
311
- _context3.next = 12;
462
+ _context5.next = 12;
312
463
  break;
313
464
  case 19:
314
- _context3.next = 24;
465
+ _context5.next = 24;
315
466
  break;
316
467
  case 21:
317
- _context3.prev = 21;
318
- _context3.t0 = _context3["catch"](10);
319
- _iterator.e(_context3.t0);
468
+ _context5.prev = 21;
469
+ _context5.t0 = _context5["catch"](10);
470
+ _iterator.e(_context5.t0);
320
471
  case 24:
321
- _context3.prev = 24;
472
+ _context5.prev = 24;
322
473
  _iterator.f();
323
- return _context3.finish(24);
474
+ return _context5.finish(24);
324
475
  case 27:
325
476
  if (filesToDelete.length > 0) {
326
477
  console.log("-------- \u5171\u6E05\u7406 ".concat(filesToDelete.length, " \u4E2A\u65E7\u65E5\u5FD7\u6587\u4EF6"));
327
478
  }
328
- _context3.next = 33;
479
+ _context5.next = 33;
329
480
  break;
330
481
  case 30:
331
- _context3.prev = 30;
332
- _context3.t1 = _context3["catch"](2);
333
- console.error("清理旧日志失败:", _context3.t1);
482
+ _context5.prev = 30;
483
+ _context5.t1 = _context5["catch"](2);
484
+ console.error("清理旧日志失败:", _context5.t1);
334
485
  case 33:
335
486
  case "end":
336
- return _context3.stop();
487
+ return _context5.stop();
337
488
  }
338
- }, _callee3, this, [[2, 30], [10, 21, 24, 27]]);
489
+ }, _callee5, this, [[2, 30], [10, 21, 24, 27]]);
339
490
  }));
340
491
  function cleanupOldLogs() {
341
492
  return _cleanupOldLogs.apply(this, arguments);
@@ -350,31 +501,31 @@ var LoggerManager = /*#__PURE__*/function () {
350
501
  }, {
351
502
  key: "getLogFiles",
352
503
  value: (function () {
353
- var _getLogFiles = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
354
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
355
- while (1) switch (_context4.prev = _context4.next) {
504
+ var _getLogFiles = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
505
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
506
+ while (1) switch (_context6.prev = _context6.next) {
356
507
  case 0:
357
508
  if (this.db) {
358
- _context4.next = 2;
509
+ _context6.next = 2;
359
510
  break;
360
511
  }
361
- return _context4.abrupt("return", []);
512
+ return _context6.abrupt("return", []);
362
513
  case 2:
363
- _context4.prev = 2;
364
- _context4.next = 5;
514
+ _context6.prev = 2;
515
+ _context6.next = 5;
365
516
  return this.db.getAll("logs");
366
517
  case 5:
367
- return _context4.abrupt("return", _context4.sent);
518
+ return _context6.abrupt("return", _context6.sent);
368
519
  case 8:
369
- _context4.prev = 8;
370
- _context4.t0 = _context4["catch"](2);
371
- console.error("获取日志文件列表失败:", _context4.t0);
372
- return _context4.abrupt("return", []);
520
+ _context6.prev = 8;
521
+ _context6.t0 = _context6["catch"](2);
522
+ console.error("获取日志文件列表失败:", _context6.t0);
523
+ return _context6.abrupt("return", []);
373
524
  case 12:
374
525
  case "end":
375
- return _context4.stop();
526
+ return _context6.stop();
376
527
  }
377
- }, _callee4, this, [[2, 8]]);
528
+ }, _callee6, this, [[2, 8]]);
378
529
  }));
379
530
  function getLogFiles() {
380
531
  return _getLogFiles.apply(this, arguments);
@@ -390,33 +541,33 @@ var LoggerManager = /*#__PURE__*/function () {
390
541
  }, {
391
542
  key: "getLogFile",
392
543
  value: (function () {
393
- var _getLogFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(fileName) {
394
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
395
- while (1) switch (_context5.prev = _context5.next) {
544
+ var _getLogFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(fileName) {
545
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
546
+ while (1) switch (_context7.prev = _context7.next) {
396
547
  case 0:
397
548
  if (this.db) {
398
- _context5.next = 2;
549
+ _context7.next = 2;
399
550
  break;
400
551
  }
401
- return _context5.abrupt("return", null);
552
+ return _context7.abrupt("return", null);
402
553
  case 2:
403
- _context5.prev = 2;
404
- _context5.next = 5;
554
+ _context7.prev = 2;
555
+ _context7.next = 5;
405
556
  return this.db.get("logs", fileName);
406
557
  case 5:
407
- return _context5.abrupt("return", _context5.sent);
558
+ return _context7.abrupt("return", _context7.sent);
408
559
  case 8:
409
- _context5.prev = 8;
410
- _context5.t0 = _context5["catch"](2);
411
- console.error("获取日志文件内容失败:", _context5.t0);
412
- return _context5.abrupt("return", null);
560
+ _context7.prev = 8;
561
+ _context7.t0 = _context7["catch"](2);
562
+ console.error("获取日志文件内容失败:", _context7.t0);
563
+ return _context7.abrupt("return", null);
413
564
  case 12:
414
565
  case "end":
415
- return _context5.stop();
566
+ return _context7.stop();
416
567
  }
417
- }, _callee5, this, [[2, 8]]);
568
+ }, _callee7, this, [[2, 8]]);
418
569
  }));
419
- function getLogFile(_x) {
570
+ function getLogFile(_x2) {
420
571
  return _getLogFile.apply(this, arguments);
421
572
  }
422
573
  return getLogFile;
@@ -430,43 +581,43 @@ var LoggerManager = /*#__PURE__*/function () {
430
581
  }, {
431
582
  key: "clearLogs",
432
583
  value: (function () {
433
- var _clearLogs = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(fileName) {
434
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
435
- while (1) switch (_context6.prev = _context6.next) {
584
+ var _clearLogs = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(fileName) {
585
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
586
+ while (1) switch (_context8.prev = _context8.next) {
436
587
  case 0:
437
588
  if (this.db) {
438
- _context6.next = 2;
589
+ _context8.next = 2;
439
590
  break;
440
591
  }
441
- return _context6.abrupt("return", false);
592
+ return _context8.abrupt("return", false);
442
593
  case 2:
443
- _context6.prev = 2;
594
+ _context8.prev = 2;
444
595
  if (!fileName) {
445
- _context6.next = 8;
596
+ _context8.next = 8;
446
597
  break;
447
598
  }
448
- _context6.next = 6;
599
+ _context8.next = 6;
449
600
  return this.db.delete("logs", fileName);
450
601
  case 6:
451
- _context6.next = 10;
602
+ _context8.next = 10;
452
603
  break;
453
604
  case 8:
454
- _context6.next = 10;
605
+ _context8.next = 10;
455
606
  return this.db.clear("logs");
456
607
  case 10:
457
- return _context6.abrupt("return", true);
608
+ return _context8.abrupt("return", true);
458
609
  case 13:
459
- _context6.prev = 13;
460
- _context6.t0 = _context6["catch"](2);
461
- console.error("清空日志失败:", _context6.t0);
462
- return _context6.abrupt("return", false);
610
+ _context8.prev = 13;
611
+ _context8.t0 = _context8["catch"](2);
612
+ console.error("清空日志失败:", _context8.t0);
613
+ return _context8.abrupt("return", false);
463
614
  case 17:
464
615
  case "end":
465
- return _context6.stop();
616
+ return _context8.stop();
466
617
  }
467
- }, _callee6, this, [[2, 13]]);
618
+ }, _callee8, this, [[2, 13]]);
468
619
  }));
469
- function clearLogs(_x2) {
620
+ function clearLogs(_x3) {
470
621
  return _clearLogs.apply(this, arguments);
471
622
  }
472
623
  return clearLogs;
@@ -493,17 +644,17 @@ var LoggerManager = /*#__PURE__*/function () {
493
644
  }, {
494
645
  key: "manualCleanup",
495
646
  value: (function () {
496
- var _manualCleanup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
497
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
498
- while (1) switch (_context7.prev = _context7.next) {
647
+ var _manualCleanup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
648
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
649
+ while (1) switch (_context9.prev = _context9.next) {
499
650
  case 0:
500
- _context7.next = 2;
651
+ _context9.next = 2;
501
652
  return this.cleanupOldLogs();
502
653
  case 2:
503
654
  case "end":
504
- return _context7.stop();
655
+ return _context9.stop();
505
656
  }
506
- }, _callee7, this);
657
+ }, _callee9, this);
507
658
  }));
508
659
  function manualCleanup() {
509
660
  return _manualCleanup.apply(this, arguments);